diff --git a/applications/test/dictionary/testDict b/applications/test/dictionary/testDict
index 5b27ede5d7..19020de7ed 100644
--- a/applications/test/dictionary/testDict
+++ b/applications/test/dictionary/testDict
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDict;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDict2 b/applications/test/dictionary/testDict2
index 9d481de49a..52967f024d 100644
--- a/applications/test/dictionary/testDict2
+++ b/applications/test/dictionary/testDict2
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDict;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDictAPI b/applications/test/dictionary/testDictAPI
index d0ae9a9a8c..4c4d56743c 100644
--- a/applications/test/dictionary/testDictAPI
+++ b/applications/test/dictionary/testDictAPI
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDict;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDictCalc1 b/applications/test/dictionary/testDictCalc1
index 85dac5911e..5396d387c2 100644
--- a/applications/test/dictionary/testDictCalc1
+++ b/applications/test/dictionary/testDictCalc1
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDictCalc1;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDictEval1 b/applications/test/dictionary/testDictEval1
index bd94dcab6b..13491110df 100644
--- a/applications/test/dictionary/testDictEval1
+++ b/applications/test/dictionary/testDictEval1
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDictEval1;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDictEval2 b/applications/test/dictionary/testDictEval2
index d154bf7700..77cefec4c1 100644
--- a/applications/test/dictionary/testDictEval2
+++ b/applications/test/dictionary/testDictEval2
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDictEval1;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDictEval3 b/applications/test/dictionary/testDictEval3
index 79bebc9c20..6c6ffe9b61 100644
--- a/applications/test/dictionary/testDictEval3
+++ b/applications/test/dictionary/testDictEval3
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDictEval1;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testDictEval4 b/applications/test/dictionary/testDictEval4
new file mode 100644
index 0000000000..81a4563ebc
--- /dev/null
+++ b/applications/test/dictionary/testDictEval4
@@ -0,0 +1,121 @@
+/*--------------------------------*- C++ -*----------------------------------*\
+| ========= | |
+| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
+| \\ / O peration | Version: v2012 |
+| \\ / A nd | Website: www.openfoam.com |
+| \\/ M anipulation | |
+\*---------------------------------------------------------------------------*/
+FoamFile
+{
+ version 2.0;
+ format ascii;
+ class dictionary;
+ object dictionary;
+}
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// Test expansion with negative signs
+
+value 0.5;
+
+radius 3;
+
+negValue -$value;
+
+select1 10;
+
+sqrt05 #eval{ sqrt(0.5) };
+
+vector ( -10 ${{-$sqrt05}} $value );
+
+corner ( ${{ -$radius*sqrt(0.5) }} 1 0 );
+
+corner2 ${{
+ vector(-${radius}*sqrt(0.5), ${radius}*sqrt(0.5), 2)
+}};
+
+
+// Just a future idea (2021-05-14) - does not yet work!
+#if 0
+corner3 #eval #{
+ variables ( "outer = $radius*sqrt(0.5)" );
+ vector(-outer, outer, 2)
+#};
+#endif
+
+
+// The brace-bracket #eval with multi-lines failed for v2012 and earlier
+
+corner2b #eval
+{
+ vector(-${radius}*sqrt(0.5), $radius*sqrt(0.5), 2)
+};
+
+corner2c #eval
+${{
+ vector(-${radius}*sqrt(0.5), $radius*sqrt(0.5), 2)
+}};
+
+
+longSlurp #eval
+{
+ // This is actually a very simple expression
+ 1 + 2
+// With a long comment that is stripped out
+// during reading anyhow.
+};
+
+
+longVariable
+${{
+ // This is actually a very simple expression in variable syntax
+ 1 + 2
+/*
+// With a long comment that is stripped out
+// during reading anyhow.
+*/
+}};
+
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+
+// Geometric parameters
+rxo 2;
+ryo 3;
+rzo 4;
+
+// Geometric parameters
+outerRadius 1;
+innerRatio 0.75;
+
+geometry
+{
+ sphere
+ {
+ type sphere;
+ origin (0 0 0);
+ radius ($rxo $ryo $rzo);
+ }
+
+ innerSphere
+ {
+ $sphere
+
+ // Different solutions to the same problem
+ radius_v1
+ (
+ ${{ $innerRatio*$rxo }}
+ ${{ $innerRatio*$ryo }}
+ ${{ $innerRatio*$rzo }}
+ );
+
+ radius_v2 #eval{ $innerRatio*vector($rxo, $ryo, $rzo) };
+ radius_v3 ${{ $innerRatio*$[(vector) ../sphere/radius] }};
+
+ // Inplace overwrite the same value
+ radius ${{ $innerRatio*$[(vector) radius] }};
+ }
+}
+
+
+// ************************************************************************* //
diff --git a/applications/test/dictionary/testDictList b/applications/test/dictionary/testDictList
index a8c7197356..08cafe93c0 100644
--- a/applications/test/dictionary/testDictList
+++ b/applications/test/dictionary/testDictList
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDict;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Test some parsing
diff --git a/applications/test/dictionary/testDictRegex b/applications/test/dictionary/testDictRegex
index 15aae07200..3970712478 100644
--- a/applications/test/dictionary/testDictRegex
+++ b/applications/test/dictionary/testDictRegex
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDictRegex;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#inputMode merge
diff --git a/applications/test/dictionary/testPrimitiveEntry b/applications/test/dictionary/testPrimitiveEntry
index f4bffb9cf8..2596012243 100644
--- a/applications/test/dictionary/testPrimitiveEntry
+++ b/applications/test/dictionary/testPrimitiveEntry
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDict;
+ object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary/testSubkeyword b/applications/test/dictionary/testSubkeyword
index 21f3579f69..c995e0040f 100644
--- a/applications/test/dictionary/testSubkeyword
+++ b/applications/test/dictionary/testSubkeyword
@@ -10,7 +10,7 @@ FoamFile
version 2.0;
format ascii;
class dictionary;
- object testDict;
+ object dictionary;
note "test with foamDictionary -expand";
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
diff --git a/applications/test/dictionary3/Make/files b/applications/test/dictionary3/Make/files
new file mode 100644
index 0000000000..bdcfe73b04
--- /dev/null
+++ b/applications/test/dictionary3/Make/files
@@ -0,0 +1,3 @@
+Test-dictionary3.C
+
+EXE = $(FOAM_USER_APPBIN)/Test-dictionary3
diff --git a/applications/test/dictionary3/Make/options b/applications/test/dictionary3/Make/options
new file mode 100644
index 0000000000..18e6fe47af
--- /dev/null
+++ b/applications/test/dictionary3/Make/options
@@ -0,0 +1,2 @@
+/* EXE_INC = */
+/* EXE_LIBS = */
diff --git a/applications/test/dictionary3/Test-dictionary3.C b/applications/test/dictionary3/Test-dictionary3.C
new file mode 100644
index 0000000000..11c1835b28
--- /dev/null
+++ b/applications/test/dictionary3/Test-dictionary3.C
@@ -0,0 +1,78 @@
+/*---------------------------------------------------------------------------*\
+ ========= |
+ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
+ \\ / O peration |
+ \\ / A nd | www.openfoam.com
+ \\/ M anipulation |
+-------------------------------------------------------------------------------
+ Copyright (C) 2021 OpenCFD Ltd.
+-------------------------------------------------------------------------------
+License
+ This file is part of OpenFOAM.
+
+ OpenFOAM is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with OpenFOAM. If not, see .
+
+Application
+ Test-dictionary3
+
+Description
+ Test expressions and re-expansions
+
+\*---------------------------------------------------------------------------*/
+
+#include "argList.H"
+#include "IOstreams.H"
+#include "dictionary.H"
+#include "vector.H"
+#include "StringStream.H"
+
+using namespace Foam;
+
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
+// Main program:
+
+int main(int argc, char *argv[])
+{
+ argList::noParallel();
+
+ {
+ IStringStream is
+ (
+ "value 10;"
+ "scalar1 $value;"
+ "scalar2 -$value;"
+
+ // Use #eval expansion entirely
+ "vector1 ${{vector($value, -$value, $value)}};"
+ "vector2 ($value -$value $value);"
+ );
+
+ dictionary dict(is);
+
+ Info<< "input dictionary:" << dict << nl;
+
+ Info<< "value: " << dict.get("value") << nl;
+
+ Info<< "scalar1: " << dict.get("scalar1") << nl;
+ Info<< "scalar2: " << dict.get("scalar2") << nl;
+
+ Info<< "vector1: " << dict.get("vector1") << nl;
+ Info<< "vector2: " << dict.get("vector2") << nl;
+ }
+
+ return 0;
+}
+
+
+// ************************************************************************* //
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C
index eed1e261cb..f999a3f093 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.C
@@ -218,8 +218,8 @@ Foam::Istream& Foam::UIPstream::read(token& t)
case token::COLON :
case token::COMMA :
case token::ASSIGN :
- case token::ADD :
- case token::SUBTRACT :
+ case token::PLUS :
+ case token::MINUS :
case token::MULTIPLY :
case token::DIVIDE :
{
@@ -227,12 +227,12 @@ Foam::Istream& Foam::UIPstream::read(token& t)
return *this;
}
- // Word/directive
+ // The word-variants
case token::tokenType::WORD :
case token::tokenType::DIRECTIVE :
{
word val;
- if (read(val))
+ if (readStringFromBuffer(val))
{
if (token::compound::isCompound(val))
{
@@ -251,13 +251,14 @@ Foam::Istream& Foam::UIPstream::read(token& t)
return *this;
}
- // String types
+ // The string-variants
case token::tokenType::STRING :
+ case token::tokenType::EXPRESSION :
case token::tokenType::VARIABLE :
case token::tokenType::VERBATIM :
{
string val;
- if (read(val))
+ if (readStringFromBuffer(val))
{
t = std::move(val);
t.setType(token::tokenType(c));
diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C
index f550056ca0..5480f63a73 100644
--- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C
+++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.C
@@ -202,14 +202,19 @@ bool Foam::UOPstream::write(const token& tok)
return true;
}
+ // The word-variants
+ case token::tokenType::WORD :
case token::tokenType::DIRECTIVE :
{
- writeToBuffer(char(token::tokenType::DIRECTIVE));
+ writeToBuffer(char(tok.type()));
writeStringToBuffer(tok.wordToken());
return true;
}
+ // The string-variants
+ case token::tokenType::STRING :
+ case token::tokenType::EXPRESSION :
case token::tokenType::VARIABLE :
case token::tokenType::VERBATIM :
{
diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C
index d1c4adc93d..10969f20f2 100644
--- a/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C
+++ b/src/OpenFOAM/db/IOstreams/Sstreams/ISstream.C
@@ -199,8 +199,8 @@ Foam::Istream& Foam::ISstream::read(token& t)
case token::COLON :
case token::COMMA :
case token::ASSIGN :
- case token::ADD :
- // NB: token::SUBTRACT handled later as the possible start of a Number
+ case token::PLUS :
+ // NB: token::MINUS handled later as the possible start of a Number
case token::MULTIPLY :
case token::DIVIDE :
{
@@ -368,7 +368,7 @@ Foam::Istream& Foam::ISstream::read(token& t)
if (nChar == 1 && buf[0] == '-')
{
// A single '-' is punctuation
- t = token::punctuationToken(token::SUBTRACT);
+ t = token::punctuationToken(token::MINUS);
}
else if (labelVal && Foam::read(buf, labelVal))
{
diff --git a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C
index bf7e25c88a..eea67551a8 100644
--- a/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C
+++ b/src/OpenFOAM/db/IOstreams/Sstreams/OSstream.C
@@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
- Copyright (C) 2017-2020 OpenCFD Ltd.
+ Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@@ -47,27 +47,33 @@ bool Foam::OSstream::write(const token& tok)
case token::tokenType::DIRECTIVE :
{
- // The '#' sigil is already part of the wordToken
+ // Token stored with leading '#' sigil - output directly
write(tok.wordToken());
-
return true;
}
- case token::tokenType::VERBATIM :
+ case token::tokenType::EXPRESSION :
{
- // Surrounding '#{ .. #}' to be recognized as verbatim
- write(char(token::HASH));
- write(char(token::BEGIN_BLOCK));
+ // Token stored with surrounding '${{ .. }}' - output directly
writeQuoted(tok.stringToken(), false);
- write(char(token::HASH));
- write(char(token::END_BLOCK));
-
return true;
}
case token::tokenType::VARIABLE :
{
+ // Token stored with leading '$' sigil - output directly
writeQuoted(tok.stringToken(), false);
+ return true;
+ }
+
+ case token::tokenType::VERBATIM :
+ {
+ // Token stored without surrounding '#{ .. #}'. Add on output
+ write(char(token::HASH));
+ write(char(token::BEGIN_BLOCK));
+ writeQuoted(tok.stringToken(), false);
+ write(char(token::HASH));
+ write(char(token::END_BLOCK));
return true;
}
diff --git a/src/OpenFOAM/db/IOstreams/token/token.H b/src/OpenFOAM/db/IOstreams/token/token.H
index eeb0d342ef..e1ccac5e9f 100644
--- a/src/OpenFOAM/db/IOstreams/token/token.H
+++ b/src/OpenFOAM/db/IOstreams/token/token.H
@@ -71,11 +71,13 @@ class token
public:
//- Enumeration defining the types of token.
- // Since these values are also used to tag content in Pstream,
- // the maximum number of types is limited to 30.
- enum tokenType
+ // Since the enumeration is used to tag content in Pstream, it is of
+ // type \c char and shall have values that do not overlap with regular
+ // punctuation characters.
+ enum tokenType : char
{
- UNDEFINED = 0, //!< An undefined token-type
+ UNDEFINED = '\0', //!< An undefined token-type
+ ERROR = '\x80', //!< Token error encountered
// Fundamental types
FLAG, //!< stream flag (1-byte bitmask)
@@ -86,14 +88,18 @@ public:
DOUBLE, //!< double (double-precision) type
// Pointer types
- WORD, //!< A Foam::word
- STRING, //!< A string (usually double-quoted)
- DIRECTIVE, //!< A dictionary \c \#directive (word variant)
- VARIABLE, //!< A dictionary \c \$variable (string variant)
- VERBATIM, //!< Verbatim string content
+ WORD, //!< Foam::word
+ STRING, //!< Foam::string (usually double-quoted)
COMPOUND, //!< Compound type such as \c List\