CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

lookup a scalar

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 2, 2011, 08:38
Default lookup a scalar
  #1
New Member
 
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15
ds-gti is on a distinguished road
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
ds-gti is offline   Reply With Quote

Old   September 2, 2011, 10:00
Default
  #2
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 20
romant is on a distinguished road
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
romant is offline   Reply With Quote

Old   September 5, 2011, 06:44
Default
  #3
New Member
 
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15
ds-gti is on a distinguished road
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?
ds-gti is offline   Reply With Quote

Old   September 5, 2011, 06:53
Default
  #4
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 20
romant is on a distinguished road
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 ;
__________________
~roman
romant is offline   Reply With Quote

Old   September 5, 2011, 07:13
Default
  #5
New Member
 
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15
ds-gti is on a distinguished road
thank you so much, I will try it!

What is the meaning of the _ (underline) and does the >> perform a shift?
ds-gti is offline   Reply With Quote

Old   September 5, 2011, 07:15
Default
  #6
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 20
romant is on a distinguished road
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
romant is offline   Reply With Quote

Old   September 5, 2011, 07:44
Default
  #7
New Member
 
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15
ds-gti is on a distinguished road
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?
ds-gti is offline   Reply With Quote

Old   September 5, 2011, 07:47
Default
  #8
Senior Member
 
romant's Avatar
 
Roman Thiele
Join Date: Aug 2009
Location: Eindhoven, NL
Posts: 374
Rep Power: 20
romant is on a distinguished road
Quote:
Originally Posted by ds-gti View Post
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
__________________
~roman
romant is offline   Reply With Quote

Old   September 5, 2011, 08:21
Default
  #9
New Member
 
David S
Join Date: Nov 2010
Posts: 9
Rep Power: 15
ds-gti is on a distinguished road
It works finally, thanks a lot!
ds-gti is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 09:22.