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/)
-   -   lookup a scalar (https://www.cfd-online.com/Forums/openfoam-programming-development/92104-lookup-scalar.html)

ds-gti September 2, 2011 08:38

lookup a scalar
 
Hi,

I would like to insert a scalar into the for-loop condition which is looked up in any datafile like controlDict or fvSolution.

I tried to use these two examples located in the main funtion of myFoam.C
Code:

dictionary outerloop = mesh.solutionDict().subDict("OUTERLOOP");
int nOuterCorr(readInt(outerloop.lookup("nOuterCorrectors")));
//or
scalar mIt = readScalar(solutionDict.lookup("mIt"));

to call it
Code:

for (int m=0; m<nOuterCorr; m++)
...
//or
for (int m=0; m<mIt; m++)
...

in fvSolution I added:
Code:

OUTERLOOP
{
    nOuterCorrectors 3;
}
//or
mIt            3;

None of them works, where are I am mistaken?

Thanks for advise!
David

romant September 2, 2011 10:00

what does not work? do you get an error upon compiling? do you get an error at all? does it run without complaining and just not read the value?

ds-gti September 5, 2011 06:44

Thank you for your reply Roman.

It does not read the scalar mIt and in the second case the compiling-report tells: unused parameter nOuterCorr (but it should be used in the for-condition).

Do you use the same or similar code successfully?

romant September 5, 2011 06:53

hej,

if you dfine your scalar before as for example

Code:

scalar mIt_;  // in the header
// and then use just
mIt_(outerLoop.lookup("mIt")) ; // in the C file

or just

Code:

outerLoop.lookup("mIt") >> mIt ;

ds-gti September 5, 2011 07:13

thank you so much, I will try it!

What is the meaning of the _ (underline) and does the >> perform a shift?

romant September 5, 2011 07:15

underlines like "_" are usually appended to a variable in order to show that we speak about a private variable in a class

the ">>" gives the stream into a variable. It is part of the standard IO package of c++

ds-gti September 5, 2011 07:44

Hi,

I am sorry, it returns:

Code:

TPlusLTest.C: In function âint main(int, char**)â:
TPlusLTest.C:65: error: âmItâ was not declared in this scope
make: *** [Make/linux64GccDPOpt/TPlusLTest.o] Error 1

my corrections:

Code:

#include "fvCFD.H"

scalar mIt_;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
...
dictionary outerLoop = mesh.solutionDict().subDict("OUTERLOOP");
    outerLoop.lookup("mIt") >> mIt; //line 65!
...
for (int m=0; m<mIt; m++)

Did I missunderstood your advise?

romant September 5, 2011 07:47

Quote:

Originally Posted by ds-gti (Post 322925)
Hi,

I am sorry, it returns:

Code:

TPlusLTest.C: In function âint main(int, char**)â:
TPlusLTest.C:65: error: âouterLoopâ was not declared in this scope
TPlusLTest.C:65: error: âmItâ was not declared in this scope
make: *** [Make/linux64GccDPOpt/TPlusLTest.o] Error 1

my corrections:

Code:

#include "fvCFD.H"

scalar mIt_;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
...
dictionary outerloop = mesh.solutionDict().subDict("OUTERLOOP");
    outerLoop.lookup("mIt") >> mIt; //line 65!
...
for (int m=0; m<mIt; m++)

Did I missunderstood your advise?

you are missing the underline at all the other parts in the code, either you write the variable with underline or without underline, but don't mix it

ds-gti September 5, 2011 08:21

It works finally, thanks a lot!


All times are GMT -4. The time now is 16:47.