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

Read in a new constant to solver

Register Blogs Community New Posts Updated Threads Search

Like Tree11Likes
  • 2 Post By hjasak
  • 9 Post By hjasak

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 4, 2005, 22:09
Default Hi, I would like to read a
  #1
Senior Member
 
Pei-Ying Hsieh
Join Date: Mar 2009
Posts: 317
Rep Power: 18
hsieh is on a distinguished road
Hi,

I would like to read a new constant into the solver from a data file. Say, I want to scale the body force of the momentum equation with this new constant. In stead of putting this constant in the main solver, I would like to read it in from a data file so that I do not have to re-compile the solver every time I change the constant. What is the easiest way to do this? Many thanks!

pei-Ying
hsieh is offline   Reply With Quote

Old   November 5, 2005, 05:30
Default Take a look at how icoFoam rea
  #2
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Take a look at how icoFoam reads nu and do it in the same way. You've got a choice of dictionaries to do it from, so make sure you put it into the right one.

Enjoy,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   November 5, 2005, 10:48
Default Hi, Hrv, I already tried it
  #3
Senior Member
 
Pei-Ying Hsieh
Join Date: Mar 2009
Posts: 317
Rep Power: 18
hsieh is on a distinguished road
Hi, Hrv,

I already tried it the way you suggested, but, failed. I declared the new constant, say amplitude, as double. I think nu is a field variable (tie to mesh?). I will give it a try again.

Pei-Ying
hsieh is offline   Reply With Quote

Old   November 5, 2005, 10:56
Default This is not hard: 1) Open y
  #4
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
This is not hard:

1) Open your favourite dictionary, or find one already open:

IOdictionary environmentalProperties
(
IOobject
(
"environmentalProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);


2) read the thing:

scalar amp(readScalar(environmentalProperties.lookup("amp litude")));

3) there's no 3! :-)

Enjoy,

Hrv

P.S. Any news on the topo tutorials we talked about?
maetlg and wht like this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   November 5, 2005, 22:13
Default Hi, Hrv, Thank you very muc
  #5
Senior Member
 
Pei-Ying Hsieh
Join Date: Mar 2009
Posts: 317
Rep Power: 18
hsieh is on a distinguished road
Hi, Hrv,

Thank you very much for the kind answer.

I must missed something and still cannot get it to work. The following is what I did:

in file readEnvironmentalProperties.H I have:
-------------------
Info << "\nReading environmentalProperties" << endl;

IOdictionary environmentalProperties
(
IOobject
(
"environmentalProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);

scalar amp(readScalar(environmentalProperties.lookup("amp litude")));
----------------------

in the main code (turbFoam.C in this case), I have
------------------------
..
float amplitude;

# include "readEnvironmentalProperties.H"
----------------

in environmentalProperties file, I have:
--------------

amp amplitude 1.0;

----------------

Everything compiled without a problem. But, I got an error when I run the case:
-----------
Reading environmentalProperties


--> FOAM FATAL IO ERROR : keyword amplitude is undefined in dictionary "/home/phsieh/OpenFOAM/phsieh-1.2/run/turbFoamVibration/CP-S-vibration/constant/ environmentalProperties"

file: /home/phsieh/OpenFOAM/phsieh-1.2/run/turbFoamVibration/CP-S-vibration/constant/e nvironmentalProperties from line 25 to line 25.

From function dictionary::lookupEntry(const word& keyword) const
in file db/dictionary/dictionary.C at line 152.

FOAM exiting
--------------------

Unfortunately, the topo tutorials are going slowly. I updated the attachDetach stuff to OpenFOAM-1.1, but, I cannot get it to run under OpenFOAM-1.2 just yet. Also, after attaching/detaching, the flow field seemed odd. I need to do some more checking. But, 3 tutorials will be done just after Thanksgiving. I apologize for draging this so long. I wondered into some other areas of OpenFOAM (and enjoyed it too much).

Pei-Ying
hsieh is offline   Reply With Quote

Old   November 6, 2005, 06:03
Default The environmentalProperties fi
  #6
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
The environmentalProperties file is wrong: it should say just:

amplitude 1.0;

Pls try again,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   November 6, 2005, 06:05
Default Try changing in the dictionary
  #7
Member
 
Niklas Wikstrom
Join Date: Mar 2009
Posts: 86
Rep Power: 17
wikstrom is on a distinguished road
Try changing in the dictionary file:

from
amp amplitude 1.0;

to
amplitude 1.0;


/Niklas
wikstrom is offline   Reply With Quote

Old   November 6, 2005, 19:33
Default Thanks a lot Hrv and Niklas!
  #8
Senior Member
 
Pei-Ying Hsieh
Join Date: Mar 2009
Posts: 317
Rep Power: 18
hsieh is on a distinguished road
Thanks a lot Hrv and Niklas!

I had to make 3 changes to get it to work:

1. changed the environmentalProperties file:
amplitude 1.0;

2. in the main code (turbFoam.C):
only added #include "readEnvironmentalProperties.H"
(should not add: float amplitude;)

3. in the readEnvironmentalProperties.H:
scalar amplitude(readScalar(environmentalProperties.looku p("amplitude")));
---------------------

If in readEnvironmentalProperties.H, I used
scalar amp(readScalar(environmentalProperties.lookup("amp litude")));
Then, it failed to read amplitude correctly.

Pei-ying
hsieh is offline   Reply With Quote

Old   November 7, 2005, 05:29
Default OK, here's a little C++/FOAM l
  #9
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
OK, here's a little C++/FOAM lesson for you:

- when you look up a keyword from a dictionary, you use:

ITstream& lookup(const word&) const;

This returns and Input Token Stream, ITstream, which is derived from Istream.

- the statement like

dimensionedScalar a1(readScalar(environmentalProperties.lookup("ampl itude")));

calls the constructor for a dimensionedScalar from an Istream and all is well.

- however, doing the same with a scalar (= typedef double) does not work! This is because double is NOT a class, but a primitive type and therefore does not have a constructor from Istream. for this reason, you need a helper function readScalar, which takes an Istream and returns a scalar, right? Thus:

scalar readScalar(Istream& is)
{
scalar rs;
is >> rs;

return rs;
}

and

scalar amp(readScalar(environmentalProperties.lookup("amp litude")));

Enjoy,

Hrv
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Reply


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
How to keep K constant ??? Ameya Durve FLUENT 3 February 25, 2009 13:00
use GAMBIT then read the coord by fortran solver A. Chehhat FLUENT 1 June 12, 2008 14:59
Constant pressure! Mann CFX 7 January 16, 2008 18:09
Which solver I should use when density of the fluid is not a constant dbxmcf OpenFOAM Running, Solving & CFD 0 March 25, 2007 05:26
how read Gambit data into my solver wang dong FLUENT 3 April 23, 2001 21:18


All times are GMT -4. The time now is 15:17.