|
[Sponsors] |
September 2, 2011, 08:38 |
lookup a scalar
|
#1 |
New Member
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15 |
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")); Code:
for (int m=0; m<nOuterCorr; m++) ... //or for (int m=0; m<mIt; m++) ... Code:
OUTERLOOP { nOuterCorrectors 3; } //or mIt 3; Thanks for advise! David |
|
September 2, 2011, 10:00 |
|
#2 |
Senior Member
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 20 |
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?
__________________
~roman |
|
September 5, 2011, 06:44 |
|
#3 |
New Member
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15 |
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? |
|
September 5, 2011, 06:53 |
|
#4 |
Senior Member
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 20 |
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 Code:
outerLoop.lookup("mIt") >> mIt ;
__________________
~roman |
|
September 5, 2011, 07:13 |
|
#5 |
New Member
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15 |
thank you so much, I will try it!
What is the meaning of the _ (underline) and does the >> perform a shift? |
|
September 5, 2011, 07:15 |
|
#6 |
Senior Member
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 20 |
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++
__________________
~roman |
|
September 5, 2011, 07:44 |
|
#7 |
New Member
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15 |
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 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++) |
|
September 5, 2011, 07:47 |
|
#8 | |
Senior Member
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 20 |
Quote:
__________________
~roman |
||
September 5, 2011, 08:21 |
|
#9 |
New Member
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15 |
It works finally, thanks a lot!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Solving for an additional species CO in coalChemistryFoam | N. A. | OpenFOAM Programming & Development | 3 | February 18, 2019 05:58 |
dieselFoam problem!! trying to introduce a new heat transfer model | vivek070176 | OpenFOAM Programming & Development | 10 | December 23, 2014 23:48 |
Specifying nonuniform boundary condition | maka | OpenFOAM Running, Solving & CFD | 59 | October 22, 2014 14:52 |
Convergence on anisotropic tetahedral meshes | pbo | OpenFOAM Running, Solving & CFD | 12 | December 14, 2010 11:59 |
CFX12 rif errors | romance | CFX | 4 | October 26, 2009 13:41 |