Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
HPCAPPs
OpenFOAM-GPU-v2.0
Commits
55e5a777
Commit
55e5a777
authored
Oct 17, 2024
by
shunbo
Browse files
initial commit
parents
Changes
677
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1242 additions
and
0 deletions
+1242
-0
OpenFOAM-v2112/applications/test/dictionary/testDictEval1
OpenFOAM-v2112/applications/test/dictionary/testDictEval1
+51
-0
OpenFOAM-v2112/applications/test/dictionary/testDictEval2
OpenFOAM-v2112/applications/test/dictionary/testDictEval2
+97
-0
OpenFOAM-v2112/applications/test/dictionary/testDictEval3
OpenFOAM-v2112/applications/test/dictionary/testDictEval3
+75
-0
OpenFOAM-v2112/applications/test/dictionary/testDictEval4
OpenFOAM-v2112/applications/test/dictionary/testDictEval4
+121
-0
OpenFOAM-v2112/applications/test/dictionary/testDictInc
OpenFOAM-v2112/applications/test/dictionary/testDictInc
+6
-0
OpenFOAM-v2112/applications/test/dictionary/testDictList
OpenFOAM-v2112/applications/test/dictionary/testDictList
+54
-0
OpenFOAM-v2112/applications/test/dictionary/testDictRegex
OpenFOAM-v2112/applications/test/dictionary/testDictRegex
+36
-0
OpenFOAM-v2112/applications/test/dictionary/testPrimitiveEntry
...OAM-v2112/applications/test/dictionary/testPrimitiveEntry
+49
-0
OpenFOAM-v2112/applications/test/dictionary/testSubkeyword
OpenFOAM-v2112/applications/test/dictionary/testSubkeyword
+119
-0
OpenFOAM-v2112/applications/test/dictionary/value
OpenFOAM-v2112/applications/test/dictionary/value
+2
-0
OpenFOAM-v2112/applications/test/dictionary2/Make/files
OpenFOAM-v2112/applications/test/dictionary2/Make/files
+3
-0
OpenFOAM-v2112/applications/test/dictionary2/Make/options
OpenFOAM-v2112/applications/test/dictionary2/Make/options
+1
-0
OpenFOAM-v2112/applications/test/dictionary2/Test-dictionary2.C
...AM-v2112/applications/test/dictionary2/Test-dictionary2.C
+446
-0
OpenFOAM-v2112/applications/test/dictionary3/Make/files
OpenFOAM-v2112/applications/test/dictionary3/Make/files
+3
-0
OpenFOAM-v2112/applications/test/dictionary3/Make/options
OpenFOAM-v2112/applications/test/dictionary3/Make/options
+2
-0
OpenFOAM-v2112/applications/test/dictionary3/Test-dictionary3.C
...AM-v2112/applications/test/dictionary3/Test-dictionary3.C
+78
-0
OpenFOAM-v2112/applications/test/dictionary4/Make/files
OpenFOAM-v2112/applications/test/dictionary4/Make/files
+3
-0
OpenFOAM-v2112/applications/test/dictionary4/Make/options
OpenFOAM-v2112/applications/test/dictionary4/Make/options
+1
-0
OpenFOAM-v2112/applications/test/dictionary4/Test-dictionary4.C
...AM-v2112/applications/test/dictionary4/Test-dictionary4.C
+92
-0
OpenFOAM-v2112/applications/test/dictionaryCopy/Make/files
OpenFOAM-v2112/applications/test/dictionaryCopy/Make/files
+3
-0
No files found.
Too many changes to show.
To preserve performance only
677 of 677+
files are displayed.
Plain diff
Email patch
OpenFOAM-v2112/applications/test/dictionary/testDictEval1
0 → 100644
View file @
55e5a777
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
eval1 #eval #{ degToRad() *
pi() *
cos(100) * mag(19) + 1 * pi()
+
// Skip comments
pi() * 15 + hypot(3,4) #};
eval2 #eval{ degToRad() *
pi() *
cos(100) * mag(19) + 1 * pi()
+
// Skip comments
pi() * 15 + hypot(3,4) };
eval3 (#eval{hypot(3,4)}, #eval{sqrt(2)}, #eval{pi()});
noeval3 (5, 1.41421, 3.14159);
eval4 #eval{$eval1 * 10};
pi() #eval{pi()};
rand() #eval{100*rand(123456)};
sinh(0.1) #eval{sinh(0.1)};
cosh(0.1) #eval{cosh(0.1)};
sqrt100 #eval{((sqrt(100)))};
float 12.345;
ceil #eval{ ceil($float) };
floor #eval{ floor($float) };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OpenFOAM-v2112/applications/test/dictionary/testDictEval2
0 → 100644
View file @
55e5a777
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
expr1 "hypot(3,4)";
expr2 hypot(3,4);
expr3 #{ hypot(3,4) #};
eval1 #eval " pi() * 2 * $expr1";
eval2 #eval " pi() * 2 * $expr2";
eval3 #eval " pi() * 2 * $expr3";
factor "pi()";
factor10 10;
hypot_a 3;
hypot_b 4;
eval4 #eval "$factor * 2 * hypot(${hypot_xx:-0}, $hypot_b)";
//eval5 #eval " pi() * 2 * ${{ hypot(3,4) * 100 }}";
eval6 #eval " pi() * 2 * ${{ ${factor:-0} * ${{ 15 * 3 }} }} + 5";
eval6a #eval " pi() * 2 * ${{ ${factor:+-$factor} * ${{ 15 * 3 }} }} + 5";
eval6b #eval " pi() * 2 * ${{ ${unknown:-0} * ${{ 15 * 3 }} }} + 5";
eval6c #eval " pi() * 2 * ${{ -${unknown:-0} * ${{ 15 * 3 }} }} + 5";
// Even this work
eval7a #eval " pi() * 1 * ${factor${{2*5}}:-100}";
// Even this work
eval7b #eval " pi() * 1 * ${factorXYZ${{2*5}}:-100}";
index 10;
eval8a #eval " pi() * 2 * ${{ ${factor$index} + ${factor10} }}";
eval8b #eval " pi() * 2 * $factor * ${{ 100 }}";
eval10a #eval "vector(1,2,3) * 5";
// Slightly stranger ideas:
axis1 (1 0 0);
axis2 (0 1 0);
axis3 (0 0 1);
index 100;
location #eval #{
400 *
// Numerator: use the index to get relevant suffix [1,2,3]
// to form the lookup of axis1,axis2,...
// Treat the lookup as a vector within the expression evaluation
$[(vector) axis${{
($index % 3) + 1 /* Evaluates: 1,2,3 from index */ }}
]
// Denominator: divide by index with zero-division protection
/ ${{max(1, $index)}}
// Same thing, but using expressions-syntax for variable lookup
/ ${{max(1, $[index])}}
#};
// This is still a rather clunky syntax
length #eval{ cbrt(mag($[(vector) location])) };
// Remove evidence of some variables
#remove ("axis[0-9]*" index)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OpenFOAM-v2112/applications/test/dictionary/testDictEval3
0 → 100644
View file @
55e5a777
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
expr1 "hypot(3,4)";
expr2 hypot(6,8);
eval1 #eval
#{
(
${FOAM_API} >= 1812 && !${FOAM_API} > 2100
? $expr1
: $expr2
)
#};
eval2 #eval
#{
(false ? pi() * 2 * $expr1 : pi() * 2 * $expr2)
#};
eval3 #eval
#{
(bool(0.1) ? 10 : 0)
#};
eval4 #eval
#{
2 * mag(true) * pi()
#};
eval4b #eval
#{
2 * mag(!false) * pi()
#};
eval5 #eval
#{
2 * mag(${FOAM_API} >= 1909) * pi()
#};
// Can use round or floor for this:
apiYear #eval{ round($FOAM_API / 100) };
// Should not need round or floor:
apiMonth #eval{ ($FOAM_API % 100) };
// Could flag as an input error or treat as zero
empty #eval "";
// Field of specified length
random #eval 4 { vector(rand(), 0, 0) ; /* trailing rubbish */ ; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OpenFOAM-v2112/applications/test/dictionary/testDictEval4
0 → 100644
View file @
55e5a777
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / 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] }};
}
}
// ************************************************************************* //
OpenFOAM-v2112/applications/test/dictionary/testDictInc
0 → 100644
View file @
55e5a777
inlet_4
{
type inletOutlet;
inletValue $internalField;
value $internalField;
}
OpenFOAM-v2112/applications/test/dictionary/testDictList
0 → 100644
View file @
55e5a777
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Test some parsing
// #default
internalField uniform 10;
// #default
dimensions [ 0 2 -2 0 0 0 0 ];
active
{
type turbulentIntensityKineticEnergyInlet;
intensity 0.1;
value $internalField;
}
// #inputMode error
active
{
type turbulentIntensityKineticEnergyInlet;
intensity 0.1;
value 100;
}
(U|k|epsilon|omega)
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-6;
relTol 0;
}
/*
;
*/
(rho) smoothSolver
//OK smoothSolver // <- missing ';' as well
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OpenFOAM-v2112/applications/test/dictionary/testDictRegex
0 → 100644
View file @
55e5a777
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#inputMode merge
".*" parentValue1;
"[n-z].*" parentValue2;
"f.*" parentValue3;
keyX parentValue4;
keyY parentValue5;
"(.*)Dict"
{
foo subdictValue0;
//bar $f.*; // should this really match 'foo'?
// result is dependent on insert order!
"a.*c" subdictValue3;
"ab.*" subdictValue2;
"a.*" subdictValue1;
abcd \1;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OpenFOAM-v2112/applications/test/dictionary/testPrimitiveEntry
0 → 100644
View file @
55e5a777
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Test parsing of primitive entry
// Can pass through foamDictionary -expand for test
dict1
{
entry1 no brackets;
entry2 balanced ( set of { brackets } in the ) entry;
entry3a mismatch ( set of { brackets ) in the } entry;
entry3b mismatch ( set of { brackets } in the } entry;
// Runs on
// entry3c too many ( set of ) brackets ) in ) entry;
//entry4 missing closing ( set of { brackets } in entry;
}
dict2
{
entry1 no brackets;
entry2 no brackets but missing semi-colon
}
dict3
{
entry1 anything;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OpenFOAM-v2112/applications/test/dictionary/testSubkeyword
0 → 100644
View file @
55e5a777
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dictionary;
note "test with foamDictionary -expand";
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// #inputMode overwrite
key1 val1;
val1 val1;
val2 val2;
subdict
{
key1 a;
key2 b;
}
// This parses as a variable without a name (== plain word)
// followed by a string
keyXYZ $"test";
update
{
key1 val1b;
key2 val2;
subdict
{
key2 $key1;
key3 val3;
key2b ${..key2};
key3b $^key1;
key100 100;
key200 200;
key300 300;
key400 400;
}
}
// expands update into top-level
$update
_cleanup
{
#remove "/subdict/key300"
"/subdict/key400" 400000;
// Self-destruct not possible
// #remove "/_cleanup"
}
#remove "/_cleanup"
// Can use a leading '^' or ':' as anchor for scoping, but slashes are clearer
key3dot ${^subdict.key1};
key3slash ${/subdict/key1};
key3 ${^update.subdict.key3};
key4 ${:update.subdict...subdict.key1};
key3_a ${/subdict/key1};
key3_b $/subdict/key1;
// This will not work, but globs would be interesting:
#remove "/update/subdict/key*"
// This is okay, uses a regexp directly
#remove "val.*"
#remove "/update/subdict/key100"
"/subdict/key2" overridden;
active
{
type turbulentIntensityKineticEnergyInlet;
intensity 0.1;
value 100;
}
// Some more with scoping
"/active/value(pwd)" 200;
"/active/'(pwd|foo)'" 200; // Can use single or double quotes
"/active/intensity" 0.05;
// Auto-vivify intermediate dictionaries
"/active/subdict/type" anotherType;
"/active/subdict/value/type" anotherType;
// This is an error - cannot change type of intermediate dictionaries!
// "active/value/type/of/things" newType;
"/active/subdict/value" change;
"/active/subdict/value" { entry1 value1; entry2 value2; }
// Handle remove as per changeDictionary? TBD
// Removal:
// "~/active/subdict/value"
// "~active"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
OpenFOAM-v2112/applications/test/dictionary/value
0 → 100644
View file @
55e5a777
// the trailing ';' shouldn't actually be there, but shouldn't cause problems
uniform 2;
OpenFOAM-v2112/applications/test/dictionary2/Make/files
0 → 100644
View file @
55e5a777
Test-dictionary2.C
EXE = $(FOAM_USER_APPBIN)/Test-dictionary2
OpenFOAM-v2112/applications/test/dictionary2/Make/options
0 → 100644
View file @
55e5a777
EXE_INC = -DCOMPAT_OPENFOAM_ORG
OpenFOAM-v2112/applications/test/dictionary2/Test-dictionary2.C
0 → 100644
View file @
55e5a777
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017-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 <http://www.gnu.org/licenses/>.
Application
Test-dictionary2
Description
Test dictionary insertion and some reading functionality.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "IOstreams.H"
#include "IOobject.H"
#include "IFstream.H"
#include "dictionary.H"
#include "ops.H"
#include "scalarRange.H"
#include "stringOps.H"
using
namespace
Foam
;
void
entryInfo
(
entry
*
e
)
{
if
(
e
)
{
Info
<<
"added "
<<
e
->
keyword
()
<<
": "
<<
typeid
(
e
).
name
()
<<
nl
;
}
}
// Try with readScalar
scalar
try_readScalar
(
const
dictionary
&
dict
,
const
word
&
k
)
{
scalar
val
(
-
GREAT
);
const
bool
oldThrowingError
=
FatalError
.
throwing
(
true
);
const
bool
oldThrowingIOerr
=
FatalIOError
.
throwing
(
true
);
try
{
val
=
readScalar
(
dict
.
lookup
(
k
));
Info
<<
"readScalar("
<<
k
<<
") = "
<<
val
<<
nl
;
}
catch
(
const
Foam
::
IOerror
&
err
)
{
Info
<<
"readScalar("
<<
k
<<
") Caught FatalIOError "
<<
err
<<
nl
<<
endl
;
}
catch
(
const
Foam
::
error
&
err
)
{
Info
<<
"readScalar("
<<
k
<<
") Caught FatalError "
<<
err
<<
nl
<<
endl
;
}
FatalError
.
throwing
(
oldThrowingError
);
FatalIOError
.
throwing
(
oldThrowingIOerr
);
return
val
;
}
// Try with get<scalar>
scalar
try_getScalar
(
const
dictionary
&
dict
,
const
word
&
k
)
{
scalar
val
(
-
GREAT
);
const
bool
oldThrowingError
=
FatalError
.
throwing
(
true
);
const
bool
oldThrowingIOerr
=
FatalIOError
.
throwing
(
true
);
try
{
val
=
dict
.
get
<
scalar
>
(
k
);
Info
<<
"get<scalar>("
<<
k
<<
") = "
<<
val
<<
nl
;
}
catch
(
const
Foam
::
IOerror
&
err
)
{
Info
<<
"get<scalar>("
<<
k
<<
") Caught FatalIOError "
<<
err
<<
nl
<<
endl
;
}
catch
(
const
Foam
::
error
&
err
)
{
Info
<<
"get<scalar>("
<<
k
<<
") Caught FatalError "
<<
err
<<
nl
<<
endl
;
}
FatalError
.
throwing
(
oldThrowingError
);
FatalIOError
.
throwing
(
oldThrowingIOerr
);
return
val
;
}
// Try with getCheck<scalar>
template
<
class
Predicate
>
scalar
try_getCheckScalar
(
const
dictionary
&
dict
,
const
word
&
k
,
const
Predicate
&
pred
)
{
scalar
val
(
-
GREAT
);
const
bool
oldThrowingError
=
FatalError
.
throwing
(
true
);
const
bool
oldThrowingIOerr
=
FatalIOError
.
throwing
(
true
);
try
{
val
=
dict
.
getCheck
<
scalar
>
(
k
,
pred
);
Info
<<
"getCheck<scalar>("
<<
k
<<
") = "
<<
val
<<
nl
;
}
catch
(
const
Foam
::
IOerror
&
err
)
{
Info
<<
"getCheck<scalar>("
<<
k
<<
") Caught FatalIOError "
<<
err
<<
nl
<<
endl
;
}
catch
(
const
Foam
::
error
&
err
)
{
Info
<<
"getCheck<scalar>("
<<
k
<<
") Caught FatalError "
<<
err
<<
nl
<<
endl
;
}
FatalError
.
throwing
(
oldThrowingError
);
FatalIOError
.
throwing
(
oldThrowingIOerr
);
return
val
;
}
// Try with *entry (from findEntry) and get<scalar>
scalar
try_getScalar
(
const
entry
*
eptr
,
const
word
&
k
)
{
scalar
val
(
-
GREAT
);
if
(
!
eptr
)
{
Info
<<
"No entry"
<<
k
<<
nl
;
return
val
;
}
const
bool
oldThrowingError
=
FatalError
.
throwing
(
true
);
const
bool
oldThrowingIOerr
=
FatalIOError
.
throwing
(
true
);
try
{
val
=
eptr
->
get
<
scalar
>
();
Info
<<
"entry get<scalar>("
<<
k
<<
") = "
<<
val
<<
nl
;
}
catch
(
const
Foam
::
IOerror
&
err
)
{
Info
<<
"entry get<scalar>("
<<
k
<<
") Caught FatalIOError "
<<
err
<<
nl
<<
endl
;
}
catch
(
const
Foam
::
error
&
err
)
{
Info
<<
"entry get<scalar>("
<<
k
<<
") Caught FatalError "
<<
err
<<
nl
<<
endl
;
}
FatalError
.
throwing
(
oldThrowingError
);
FatalIOError
.
throwing
(
oldThrowingIOerr
);
return
val
;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int
main
(
int
argc
,
char
*
argv
[])
{
argList
::
noBanner
();
argList
::
noParallel
();
argList
args
(
argc
,
argv
);
dictionary
dict1
;
for
(
label
i
=
0
;
i
<
5
;
++
i
)
{
dictionary
tmpdict
;
{
entry
*
e
=
dict1
.
add
(
word
::
printf
(
"entry%d"
,
i
),
string
(
"entry"
+
Foam
::
name
(
i
))
);
entryInfo
(
e
);
}
{
entry
*
e
=
tmpdict
.
add
(
word
::
printf
(
"subentry%d"
,
i
),
string
(
"subentry"
+
Foam
::
name
(
i
))
);
entryInfo
(
e
);
}
{
entry
*
e
=
dict1
.
add
(
word
::
printf
(
"dict%d"
,
i
),
tmpdict
);
entryInfo
(
e
);
}
}
// Insert new dictionary or merge into existing one
for
(
auto
k
:
{
"dict1"
,
"dict10"
})
{
const
word
key
(
k
);
entry
*
e
=
dict1
.
add
(
key
,
dictionary
(),
true
);
if
(
e
&&
e
->
isDict
())
{
e
->
dict
().
add
(
word
(
"sub1"
+
key
),
10
);
e
->
dict
().
add
(
word
(
"sub2"
+
key
),
20
);
e
->
dict
().
add
(
word
(
"sub3"
+
key
),
30
);
e
->
dict
().
add
(
word
(
"sub4"
+
key
),
40
);
e
->
dict
().
add
(
word
(
"sub5"
+
key
),
50
);
e
->
dict
().
add
(
word
(
"sub6"
+
key
),
60
);
}
}
// overwrite existing
{
dict1
.
set
(
"entry3"
,
1000
);
// overwrite
entry
*
e
=
dict1
.
set
(
word
(
"dict3"
),
1000
);
// overwrite
entryInfo
(
e
);
}
// merge into existing dictionary: returns pointer to existing dict
{
dictionary
tmpdict
;
tmpdict
.
add
(
word
(
"something"
),
3
.
14159
);
entry
*
e
=
dict1
.
add
(
word
(
"dict4"
),
tmpdict
,
true
);
// merge
entryInfo
(
e
);
if
(
e
)
Info
<<
nl
<<
"=> "
<<
*
e
<<
nl
;
tmpdict
.
clear
();
tmpdict
.
add
(
word
(
"other"
),
2
.
718281
);
dict1
.
add
(
word
(
"dict1"
),
tmpdict
,
true
);
// merge
}
Info
<<
nl
<<
"dictionary"
<<
nl
<<
nl
;
dict1
.
write
(
Info
,
false
);
{
dict1
.
foundCompat
(
"newEntry"
,
{{
"entry1"
,
1612
},
{
"entry15"
,
1606
}}
);
dict1
.
foundCompat
(
"newEntry"
,
{{
"entry15"
,
1612
},
{
"entry2"
,
1606
}}
);
dict1
.
foundCompat
(
"newEntry"
,
{{
"entry3"
,
240
},
{
"entry2"
,
1606
}}
);
// And some success
dict1
.
foundCompat
(
"entry4"
,
{{
"none"
,
240
},
{
"entry2"
,
1606
}}
);
}
{
label
lval
=
readLabel
(
dict1
.
lookupCompat
(
"entry400"
,
{{
"none"
,
240
},
{
"entry3"
,
1606
}}
)
);
Info
<<
"int value: "
<<
lval
<<
nl
;
}
// Could have different dictionary names and different entries names etc.
// Quite ugly!
{
scalar
sval
=
readScalar
(
dict1
.
csearchCompat
(
"newdictName"
,
{{
"dict4"
,
1706
},
{
"dict1"
,
1606
}}
)
.
dict
()
.
lookupCompat
(
"newval"
,
{{
"something"
,
1606
},
{
"other"
,
1612
}}
)
);
Info
<<
"scalar value: "
<<
sval
<<
nl
;
sval
=
readScalar
(
dict1
.
csearchCompat
(
"newdictName"
,
{{
"dict1"
,
1606
},
{
"dict4"
,
1706
}}
)
.
dict
()
.
lookupCompat
(
"newval"
,
{{
"something"
,
1606
},
{
"other"
,
1612
}}
)
);
Info
<<
"scalar value = "
<<
sval
<<
nl
;
}
Info
<<
nl
<<
"dictionary"
<<
nl
<<
nl
;
dict1
.
write
(
Info
,
false
);
{
Info
<<
nl
<<
"Test reading good/bad/empty scalar entries"
<<
nl
;
dictionary
dict2
(
IStringStream
(
"good 3.14159;
\n
"
"negative -3.14159;
\n
"
"neg2 -3.14159;
\n
"
"empty;
\n
"
// "bad text;\n" // always fails
// "bad 3.14159 1234;\n" // fails for readScalar
)()
);
dict2
.
write
(
Info
);
// With readScalar
{
Info
<<
nl
<<
"Test some bad input with readScalar()"
<<
nl
;
try_readScalar
(
dict2
,
"good"
);
// try_readScalar(dict2, "bad");
try_readScalar
(
dict2
,
"empty"
);
}
// With get<scalar>
{
Info
<<
nl
<<
"Test some bad input with get<scalar>()"
<<
nl
;
try_getScalar
(
dict2
,
"good"
);
// try_getScalar(dict2, "bad");
try_getScalar
(
dict2
,
"empty"
);
}
// With getCheck<scalar>
{
Info
<<
nl
<<
"Test some input with getCheck<scalar>()"
<<
nl
;
try_getCheckScalar
(
dict2
,
"good"
,
scalarRange
::
gt0
());
try_getCheckScalar
(
dict2
,
"negative"
,
scalarRange
::
gt0
());
try_getCheckScalar
(
dict2
,
"neg2"
,
scalarRange
::
gt0
());
try_getCheckScalar
(
dict2
,
"good"
,
greaterOp1
<
scalar
>
(
0
));
try_getCheckScalar
(
dict2
,
"negative"
,
greaterOp1
<
scalar
>
(
0
));
Info
<<
nl
<<
"with lambda"
<<
nl
;
try_getCheckScalar
(
dict2
,
"good"
,
[](
const
scalar
x
)
{
return
x
>
0
;
}
);
}
// With findEntry and get<scalar>
{
Info
<<
nl
<<
"Test some bad input with findEntry + get<scalar>()"
<<
nl
;
try_getScalar
(
dict2
.
findEntry
(
"good"
),
"good"
);
// try_getScalar(dict2.findEntry("bad"), "bad");
try_getScalar
(
dict2
.
findEntry
(
"empty"
),
"empty"
);
}
#ifdef COMPAT_OPENFOAM_ORG
{
Info
<<
nl
<<
"Test openfoam.org compatibility"
<<
nl
;
dictionary
mydict
(
IStringStream
(
"scalar 3.14159;
\n
"
"label 10;
\n
"
)()
);
Info
<<
"get<scalar> : "
<<
mydict
.
get
<
scalar
>
(
"scalar"
)
<<
nl
;
Info
<<
"get<label> : "
<<
mydict
.
get
<
label
>
(
"label"
)
<<
nl
;
Info
<<
"lookup<scalar> : "
<<
mydict
.
lookup
<
scalar
>
(
"scalar"
)
<<
nl
;
Info
<<
"lookup<label> : "
<<
mydict
.
lookup
<
label
>
(
"label"
)
<<
nl
;
}
#else
Info
<<
"No openfoam.org compatibility methods"
<<
nl
;
#endif
}
Info
<<
"
\n
Done
\n
"
<<
endl
;
return
0
;
}
// ************************************************************************* //
OpenFOAM-v2112/applications/test/dictionary3/Make/files
0 → 100644
View file @
55e5a777
Test-dictionary3.C
EXE = $(FOAM_USER_APPBIN)/Test-dictionary3
OpenFOAM-v2112/applications/test/dictionary3/Make/options
0 → 100644
View file @
55e5a777
/* EXE_INC = */
/* EXE_LIBS = */
OpenFOAM-v2112/applications/test/dictionary3/Test-dictionary3.C
0 → 100644
View file @
55e5a777
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
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
<
scalar
>
(
"value"
)
<<
nl
;
Info
<<
"scalar1: "
<<
dict
.
get
<
scalar
>
(
"scalar1"
)
<<
nl
;
Info
<<
"scalar2: "
<<
dict
.
get
<
scalar
>
(
"scalar2"
)
<<
nl
;
Info
<<
"vector1: "
<<
dict
.
get
<
vector
>
(
"vector1"
)
<<
nl
;
Info
<<
"vector2: "
<<
dict
.
get
<
vector
>
(
"vector2"
)
<<
nl
;
}
return
0
;
}
// ************************************************************************* //
OpenFOAM-v2112/applications/test/dictionary4/Make/files
0 → 100644
View file @
55e5a777
Test-dictionary4.C
EXE = $(FOAM_USER_APPBIN)/Test-dictionary4
OpenFOAM-v2112/applications/test/dictionary4/Make/options
0 → 100644
View file @
55e5a777
EXE_INC =
OpenFOAM-v2112/applications/test/dictionary4/Test-dictionary4.C
0 → 100644
View file @
55e5a777
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
Application
Test-dictionary4
Description
Test expansion
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "IOstreams.H"
#include "IOobject.H"
#include "IFstream.H"
#include "dictionary.H"
#include "Pair.H"
#include "stringOps.H"
using
namespace
Foam
;
void
addToDict
(
dictionary
&
dict
,
std
::
initializer_list
<
Pair
<
std
::
string
>>
entries
)
{
for
(
const
Pair
<
std
::
string
>&
e
:
entries
)
{
dict
.
add
(
word
(
e
.
first
()),
string
(
e
.
second
()));
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int
main
(
int
argc
,
char
*
argv
[])
{
// Test expansion
{
dictionary
dict
;
addToDict
(
dict
,
{
{
"fileDir"
,
"<case>/triSurface"
},
{
"fileBase"
,
"input"
},
{
"fileExt"
,
".stl"
},
{
"fileName"
,
"${fileDir}/${fileBase}$fileExt"
}
}
);
Info
<<
"dict"
<<
dict
<<
nl
;
string
str
(
"fileName = <$fileName>"
);
Info
<<
str
.
c_str
()
<<
nl
;
stringOps
::
inplaceExpand
(
str
,
dict
,
true
,
true
);
Info
<<
str
.
c_str
()
<<
nl
;
}
return
0
;
}
// ************************************************************************* //
OpenFOAM-v2112/applications/test/dictionaryCopy/Make/files
0 → 100644
View file @
55e5a777
Test-dictionaryCopy.C
EXE = $(FOAM_USER_APPBIN)/Test-dictionaryCopy
Prev
1
…
20
21
22
23
24
25
26
27
28
…
34
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment