CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How to read in vectors (https://www.cfd-online.com/Forums/openfoam-programming-development/74932-how-read-vectors.html)

gruber April 12, 2010 09:03

How to read in vectors
 
Hello,

I'm trying to read in a vector, eg. the gravity, from a dictionary and to initialize it as constant of a class, eg. A. With bool variables it is possible to programm the constructor like this:

A::A()
:
dict_(IOobject(
"dict",
U.time().constant(),
U.db(),
IOobject::MUST_READ,
IOobject::NO_WRITE)),
a_(readBool(dict_.lookup("a")))
{}

Does there exist a readVector command similar to the readBool like:
b_(readVector(dict_.lookup("b")))
or how could this be done?

Thanks,
Michael

ngj April 12, 2010 09:13

Hi Michael

It depends on what format the vector is given in the dictionary. If it is merely a vector, you can read it as

vector(dict.lookup("a"))

however if it is a dimensioned vector in the dict, then you should type

dimensionedVector(dict.lookup("a"))

Hope it helps,

Niels

s_braendli April 12, 2010 09:17

Hi Michael

I use something like this:

environmentalProperties_
(
IOobject
(
"environmentalProperties",
runTime_.constant(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
),
g_(environmentalProperties_.lookup("g")),

with g_ being:
dimensionedVector g_;

Hope this helps

Silvan

gruber April 12, 2010 09:57

Thank you for your replies. They helped me quite a lot.

louvel December 3, 2015 07:26

how to read vector for user-difined Dict Openfoam
 
I'm trying to read in a vector, eg. the point of the rotating center, from a dictionary and to initialize it as constant of a application, eg. A.I have susscceful to define a scaler

scalar omega=0;
omega=readScalar(myDict.lookup("omega");

And now i want to do the same thing for a vector, but when i use readVector instead of readScaler, the error is that: the readVector is not declared, so i do not know how to declare it ?

And I know there is also a dimensionedVecotr , so I try
const vector r (0,0,0)
dimensionedVector(myDict.looup("r");

in the case ,i can compile it but in the result ,the real value of r in myDIct is not read, it just use the (0,0,0) .so could you tell me the reasons or give me some suggestion.

Thank you so much

Best regards

Lu

babakflame September 26, 2017 13:21

It might be a litlle late and the topic is very easy. However, still some people might find it helpful.

It should be declared as:

Code:


        vector ExtElec = elPropDict.lookup("ExtElec");



All times are GMT -4. The time now is 10:37.