I wanted to read the viscosity variable "nu" of "transportProperties" dictionary in the inlet boundary in 0/U as follows:
boundaryField
{
inlet
{
type codedFixedValue;
value uniform (0.006 0 0);
name parabolicInlet;
code
#{
// ... some lines of code ...
scalar nu = readScalar(this->db().lookupObject<IOdictionary>("transportProperties").lookup("nu"));
// ... some lines of code ...
#};
}
}
and I got this this wrong token type error:
--> FOAM FATAL IO ERROR:
wrong token type - expected Scalar, found on line 22 the punctuation token '['
file: /home/behzadb/research/Simulations/ConfinedCylinder2D/TestCase-01/constant/transportProperties/nu at line 22.
From function Foam::Istream& Foam::operator>>(Foam::Istream&, Foam::doubleScalar&)
in file lnInclude/Scalar.C at line 101.
FOAM exiting
I would appreciate knowing how I should call the dictionary and read that dimensioned scalar variable "nu" from it to use for some calculations (like the Reynolds number)?
Thanks a lot, BB
Try the following:
boundaryField
{
inlet
{
type codedFixedValue;
value uniform (0.006 0 0);
name parabolicInlet;
code
#{
// ... some lines of code ...
dimensionedScalar nu
(
"nu",
dimViscosity,
this->db().lookupObject<IOdictionary>("transportProperties").lookup("nu")
);
// ... some lines of code ...
#};
}
}
You are getting that error because you're trying to read the kinematic viscosity as a scalar
. Instead, use a dimensionedScalar
.
If you would like to use the scalar value of nu
, you can access it with:
scalar nu_value = nu.value();