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

implementing dictionary and using values therefrom

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

Like Tree1Likes
  • 1 Post By marupio

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 7, 2011, 13:15
Default implementing dictionary and using values therefrom
  #1
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 15
Linse is on a distinguished road
Hello All,

I would like to implement an additional computation into some solvers. Basically, an additional action should be taken if a certain testvalue has been passed.
Basically it works, but only with the threshold value hardcoded within the code.

In order to avoid recompiling the specific solver every time the threshold value is changed, I would like to make a dictionary file such as the "transportProperties" residing in the constant-folder.

How can I get the values inside such files into my solver for comparison reason?

For example it works to write:

if (p[celli] > scalar(12))
{
action that is desired;
}

What do I have to write instead of "scalar(12)" for the routine to take over the value "testvalue" from the dictionary?

What I have working by now (in simplefied form) are following entries:

Within the solver I have:
Code:
forAll(mesh.cells(),celli)
{
if (p[celli] > scalar(12))
{action1;}
else
{action2;}
}
Within my createFields.H I have
Code:
IOdictionary dictionaryName
(
    IOobject
    (
        "dictionaryName",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ,
        IOobject::NO_WRITE
    )
);

dimensionedScalar  testvalue(dictionaryName.lookup("testvalue"));

As I said: The first snippet works fine, the second complains if there is no file "dictionaryName" within the constant-folder and is fine if that is there. But all my tries in taking over a value from the dictionary-file failed so far.
Compilation is fine, though...
Linse is offline   Reply With Quote

Old   January 8, 2012, 05:08
Default
  #2
Member
 
Andreas Ruopp
Join Date: Aug 2009
Location: Stuttgart / Germany
Posts: 31
Rep Power: 16
andyru is on a distinguished road
Hi,

for example put in constant/myProperties
put in there:
myconst myconst [0 0 0 0 0 0 0] 1.0;

and read in with:
Info<< "\nReading myProperites" << endl;

IOdictionary myProperties
(
IOobject
(
"myProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
const dimensionedScalar myconst(myProperties.lookup("myconst"));

hope, this helps!
andyru is offline   Reply With Quote

Old   January 8, 2012, 17:09
Default
  #3
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 15
Linse is on a distinguished road
Hi Andyru!

Thanks for the tip, but up to now that did not succeed...
What I had in the createFields.H is:

IOdictionary evaluationProperties
(
IOobject
(
"evaluationProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
const dimensionedScalar evalp(evaluationProperties.lookup("evalp"));

This far it compiles fine.

But as soon as I put in the evaluation-routine where it should check if the pressure is higher as evalp, it throws a compilation error as below:

forAll(mesh.cells(),celli)
{
if (p[celli] > evalp )
{action1;}
else
{action2;}
}

throws:
error: no match for 'operator>' in 'p.Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::<anonymous>.Foam:imensionedField <double, Foam::volMesh>::anonymous>.Foam::Field<double>::<a nonymous>,Foam::List<double>::<anonymous>.Foam::UL ist<T>:perator[] [with T = double, Foam::label = int] (celli) > evalp'

I would have guesse it is a simple thing just to find my mistake, but I guess I am always again missing to take the wheel before pushing down the accelerator in front of the wall...

Thanks for any further suggestions!
Linse is offline   Reply With Quote

Old   January 8, 2012, 17:56
Default
  #4
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 21
marupio is on a distinguished road
if (p[celli] > evalp.value() )
Linse likes this.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 9, 2012, 04:32
Default
  #5
Senior Member
 
Bernhard Linseisen
Join Date: May 2010
Location: Heilbronn
Posts: 183
Blog Entries: 1
Rep Power: 15
Linse is on a distinguished road
Thank you, David!
That did the trick! :-)
Linse 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



All times are GMT -4. The time now is 18:58.