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

Reading OpenFOAM Variables

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 26, 2012, 10:19
Default Reading OpenFOAM Variables
  #1
New Member
 
sandip
Join Date: Jan 2012
Posts: 20
Rep Power: 14
vmsandip2011 is on a distinguished road
Hi all,
I am new to OpenFOAM source code.
I wanted to know where in OpenFOAM code the variables are read.
e.g. if you open the createFields.H for icoFoam you will find

Info<< "Reading transportProperties\n" << endl;
IOdictionary transportProperties
(
IOobject
(
"transportProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
);

dimensionedScalar nu
(
transportProperties.lookup("nu")
);

Info<< "Reading field p\n" << endl;
volScalarField p
(
IOobject
(
"p",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);


I hope these lines are reading the P, U and transportProperties directory.
I tried to debug in createFields.h file but I am not able to reach in source files
where the P,U and nu and their respective dimensions are read.
Can anybody tell me about the source files where OpenFoAM reads its variables.

with regards.
vmsandip2011 is offline   Reply With Quote

Old   April 26, 2012, 10:32
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 21
marupio is on a distinguished road
OpenFOAM reinvents the wheel... it has its own input and output stream classes defined. Not sure why you want to go that deep into the OpenFOAM library.

The two objects you list above are different. transportProperties is an IOdictionary, p is a volScalarField, which is actually a typedef of GeometricField. If you look through these two classes, you will see they have many constructors defined. The ones being used above are "read constructors", although it may not be explicitly mentioned in the source. These constructors find a file in your case directory and look up all the information they need from this file. So, the constructors only require the information necessary to locate the file, and possible references to other objects they may need, such as volScalarField needs the mesh object. I believe most read constructors use operator>>, so you could look at this operator in each class.

You might want to read up on the objectRegistry to find out more.
http://openfoamwiki.net/index.php/Op...objectRegistry
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   June 5, 2012, 12:16
Default
  #3
Senior Member
 
Join Date: Apr 2010
Posts: 151
Rep Power: 16
flowris is on a distinguished road
Hello,

I am trying to use the forces class to write a mesh motion class. When initializing a forces object, one needs the objectRegistry. The constructor is
Code:
        forces
        (
            const word& name,
            const objectRegistry&,
            const dictionary&,
            const bool loadFromFiles = false
        );
But I don't know how I can refer to this . Any help?
flowris is offline   Reply With Quote

Old   June 6, 2012, 09:42
Default
  #4
Member
 
Frederic Collonval
Join Date: Apr 2009
Location: Technische Universitaet Munich - Lehrstuhl fuer Thermodynamik
Posts: 53
Rep Power: 17
fcollonv is on a distinguished road
Hello,

The "mesh" object inherits from objectRegistry. So just pass the object "mesh".

Actually in
Quote:
volScalarField p
(
IOobject
(
"p",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);
The third argument of IOobject (i.e. "mesh") is a constant reference to the objectRegistry; the constructor called is:
IOobject ( const word& name, const fileName& instance, const objectRegistry& registry, readOption r=NO_READ, writeOption w=NO_WRITE, bool registerObject=true );Good luck
__________________
Frederic Collonval
Technische Universität München
Thermodynamics Dpt.
fcollonv is offline   Reply With Quote

Old   June 6, 2012, 11:20
Default
  #5
Senior Member
 
Join Date: Apr 2010
Posts: 151
Rep Power: 16
flowris is on a distinguished road
Thank you very much for this tip. I cannot pass mesh as argument, because it is not (yet) in my class. When I do
Code:
    forces f("forces", mesh, forcesDict);
I get
Code:
hppGgiFvMesh.C:358: error: ‘mesh’ was not declared in this scope
make: *** [Make/linux64GccDPOpt/hppGgiFvMesh.o] Error 1
From which file did you quote?
flowris 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
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 17:51
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 wyldckat OpenFOAM Announcements from Other Sources 3 September 8, 2010 06:25
reading "global" variables in a UDF macro? bawfuls Fluent UDF and Scheme Programming 1 July 1, 2010 21:22
openfoam 1.5-dev on opensuse10.3-64bit anon_c OpenFOAM 2 December 4, 2009 00:33
Modified OpenFOAM Forum Structure and New Mailing-List pete Site News & Announcements 0 June 29, 2009 05:56


All times are GMT -4. The time now is 14:57.