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

Accessing fields and dictionaries from within a BC implementation

Register Blogs Community New Posts Updated Threads Search

Like Tree20Likes
  • 3 Post By alberto
  • 4 Post By woody
  • 8 Post By deepsterblue
  • 1 Post By woody
  • 4 Post By andrea

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 5, 2005, 16:09
Default How can a field defined in the
  #1
Senior Member
 
Alberto Passalacqua
Join Date: Mar 2009
Location: Ames, Iowa, United States
Posts: 1,912
Rep Power: 36
alberto will become famous soon enoughalberto will become famous soon enough
How can a field defined in the solver code be accessed from within the code of a boundary condition?

As explained here http://www.cfd-online.com/OpenFOAM_D...tml?1133622442, I'm trying to add Johnson and Jackson's BCs to the twoPhaseEulerFoam solver, but I can't have access to the solver fields. I get the error:

/*---------------------------------------------------------------------------*\
| ========= | |
| \ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \ / O peration | Version: 1.2 |
| \ / A nd | Web: http://www.openfoam.org |
| \/ M anipulation | |
\*---------------------------------------------------------------------------*/


Exec : twoPhaseEulerFoam . Rhodes2D
Date : Dec 05 2005
Time : 21:06:15
Host : dimension4400
PID : 13204
Root : /home/alberto/OpenFOAM/alberto-1.2/run/FluidBeds
Case : Rhodes2D
Nprocs : 1
Create time

Create mesh for time = 0


Reading environmentalProperties
Reading transportProperties



--> FOAM FATAL ERROR :
request for volScalarField alpha from objectRegistry region0 failed
available objects of type volScalarField are

0
(
)


From function objectRegistry::lookupObject<type>(const word&) const
in file /home/dm2/henry/OpenFOAM/OpenFOAM-1.2/src/OpenFOAM/lnInclude/objectRegistryTempl ates.C at line 122.

FOAM aborting

I try to read the alpha field as follows:

const fvPatchField<scalar>& alpha = lookupPatchField<volScalarField,
scalar >
(
"alpha"
);

Also, how can I have access to the kineticTheoryProperties dictionary from the BC code? I get an error message which tells me the dictionary can't be found if I try to read from it.

Thanks in advance,
Alberto
atulkjoy, Zhiheng Wang and TeddyL like this.
__________________
Alberto Passalacqua

GeekoCFD - A free distribution based on openSUSE 64 bit with CFD tools, including OpenFOAM. Available as in both physical and virtual formats (current status: http://albertopassalacqua.com/?p=1541)
OpenQBMM - An open-source implementation of quadrature-based moment methods.

To obtain more accurate answers, please specify the version of OpenFOAM you are using.
alberto is offline   Reply With Quote

Old   July 16, 2010, 04:29
Default
  #2
Member
 
Tobias Holzinger
Join Date: Mar 2009
Location: Munich, Germany
Posts: 46
Rep Power: 17
woody is on a distinguished road
Hi Alberto,

I had a similar problem: if you want to access the kineticTheoryProperties
from the constant folder you can get it by
Quote:
IOdictionary kineticTheoryProperties
(
IOobject
(
"kineticTheoryProperties",
this->db().time().constant(),
this->db(),
IOobject::MUST_READ,
IOobject::AUTO_WRITE
)
);
and then
Quote:
scalar Whatever =
readScalar
(
kineticTheoryProperties.lookup("Whatever")
);
For your second problem, you need to crate a mesh:

Quote:
Foam::fvMesh mesh
(
Foam::IOobject
(
Foam::fvMesh::defaultRegion,
this->db().time().timeName(),
this->db().time(),
Foam::IOobject::MUST_READ
)
);
if you want to extract at some characteristic point...

otherwise, the whole mesh vol<Type>Field can be read by eg.

Quote:
const GeometricField<scalar, fvPatchField, volMesh>& rhofield =
this->db().objectRegistry::
lookupObject<GeometricField<scalar, fvPatchField, volMesh> >
(
"rho"
);
or
Quote:
const GeometricField<vector, fvPatchField, volMesh>& Ufield =
this->db().objectRegistry::
lookupObject<GeometricField<vector, fvPatchField, volMesh> >
(
"U"
);
woody is offline   Reply With Quote

Old   July 16, 2010, 10:24
Default
  #3
Senior Member
 
Sandeep Menon
Join Date: Mar 2009
Location: Amherst, MA
Posts: 403
Rep Power: 25
deepsterblue will become famous soon enough
Goodness, no! Do NOT create a mesh every time you want to access something related to it..

You can access the objectRegistry using the fvPatch db() function:

Code:
template<class Type>
const Foam::objectRegistry& Foam::fvPatchField<Type>::db() const
{
    return patch_.boundaryMesh().mesh();
}
You can then use this to lookup whatever you like (dictionaries, volFields, and their associated boundaries).
__________________
Sandeep Menon
University of Massachusetts Amherst
https://github.com/smenon
deepsterblue is offline   Reply With Quote

Old   July 16, 2010, 10:56
Default
  #4
Member
 
Tobias Holzinger
Join Date: Mar 2009
Location: Munich, Germany
Posts: 46
Rep Power: 17
woody is on a distinguished road
Hey Sandeep,


Thanks for your advice...
I already realized it but did it like:
Quote:
this->dimensionedInternalField().mesh()
Do you also have a hint of how to acces the Cp value in an easier way as

Quote:
#include "basicThermo.H"

const basicThermo& thermo=this->db().objectRegistry::lookupObject<basicThermo>("t hermophysicalProperties");

const scalarField Cpw = thermo.Cp();
thx in advance

Tobi
fumiya likes this.
woody is offline   Reply With Quote

Old   July 16, 2010, 11:05
Default eaxmple
  #5
Member
 
Andrea Petronio
Join Date: Mar 2009
Location: Trieste, Italy
Posts: 43
Rep Power: 17
andrea is on a distinguished road
Hi,
this should be an example:

Code:
const dimensionedScalar& readNu = db().lookupObject<IOdictionary>("transportProperties").lookup("nu");
should it be correct

Abdrea
andrea is offline   Reply With Quote

Old   July 19, 2010, 04:55
Thumbs up
  #6
Member
 
Tobias Holzinger
Join Date: Mar 2009
Location: Munich, Germany
Posts: 46
Rep Power: 17
woody is on a distinguished road
Hi Andrea.

thanks for the quick reply, but there are two things...


1. your code does not work on my BC :

Quote:
mybc.C: In member function ‘void Foam::mybc<Type>::myfunction()’:
mybc.C:165: error: expected primary-expression before ‘>’ token
mybc.C:165: error: request for member ‘lookup’ in ‘("transportProperties")’, which is of non-class type ‘const char [20]’
I think it is due to the fact, that ‘lookup’ doesnt work here...

2. I don't want to read a dictionary IO but call a member function called Cp()....

thx altough... my version works anyway...
woody is offline   Reply With Quote

Old   July 26, 2010, 18:47
Default Reading alpha and alphaEff
  #7
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 199
Rep Power: 17
deji is on a distinguished road
Hello everyone. I have a similar question to what has being asked. I think mine is easier to answer . Well, I am writing a post-processor to an LES simulation I performed and I am trying to read the thermal diffusivity and effective-thermal diffusivity, alpha and alphaEff. Is what I am doing correct:

IOdictionary LESProperties
(
IOobject
(
"LESProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
dimensionScalar alphaEff
(
LESProperties.lookup("alphaEff")
);
dimensionScalar alpha
(
LESProperties.lookup("alpha")
);
deji is offline   Reply With Quote

Old   July 26, 2010, 18:51
Default
  #8
Senior Member
 
n/a
Join Date: Sep 2009
Posts: 199
Rep Power: 17
deji is on a distinguished road
Hello everyone. I have a similar question. I am trying to write a post-processor and I need the values from the LESProperties and thermophysicalProperties, and I am not sure if the code I have here is correct. I am just working my way around OpenFOAM and trying to get comfortable with the code. Thanks.





// Read LESProperties & thermophysicalProperties
IOdictionary LESProperties
(
IOobject
(
"LESProperties",
runTime.constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
dimensionScalar alphaEff
(
LESProperties.lookup("alphaEff")
);
dimensionScalar alpha
(
LESProperties.lookup("alpha")
);
deji is offline   Reply With Quote

Old   September 14, 2010, 11:14
Default
  #9
New Member
 
Ozgur Kirlangic
Join Date: May 2009
Location: Istanbul
Posts: 16
Rep Power: 17
ozgur is on a distinguished road
Hello,

I have got a question about the "use of IOdictionary for this purpose"..

Does this mean that at every time step when the boundary condition is updated (or called), a disk I/O operation is performed for the value of "nu" ?? Does the name "IOdictionary" stand for that??

It is very important for me.

Thank you,

Ozgur



Quote:
Originally Posted by andrea View Post
Hi,
this should be an example:

Code:
const dimensionedScalar& readNu = db().lookupObject<IOdictionary>("transportProperties").lookup("nu");
should it be correct

Abdrea
ozgur is offline   Reply With Quote

Old   January 4, 2011, 08:08
Angry Access Data from same bc but different parameter
  #10
Member
 
Tobias Holzinger
Join Date: Mar 2009
Location: Munich, Germany
Posts: 46
Rep Power: 17
woody is on a distinguished road
Hi All!

New Year, new problems, i am trying to figure out how to access a variable from a different parameter for the same patch at each timestep e.g., read the amplitude and frequency values from the velocity oscillatingFixedValue BC at the current time step and use them as input parameters for the pressure boundary condition.

So far I manage to get:
Code:
//load the internal velocity field
    const GeometricField<vector, fvPatchField, volMesh>& Ufield =
    this->db().objectRegistry::
    lookupObject<GeometricField<vector, fvPatchField, volMesh> >
    (
    "U"
    );

   label patchi=this->patch().index();
Info << "Ufield Boundary" <<  Ufield.boundaryField()[patchi] << endl;
Somehow it should work with sandeeps version, but I don't manage to code it right...

Looking forward for quick reply...

Tobias
__________________
Tobias Holzinger

Chair of Thermodynamics, TU München
woody is offline   Reply With Quote

Old   January 7, 2011, 08:36
Default
  #11
Member
 
Tobias Holzinger
Join Date: Mar 2009
Location: Munich, Germany
Posts: 46
Rep Power: 17
woody is on a distinguished road
Quote:
Originally Posted by deepsterblue View Post
Goodness, no! Do NOT create a mesh every time you want to access something related to it..

You can access the objectRegistry using the fvPatch db() function:

Code:
template<class Type>
const Foam::objectRegistry& Foam::fvPatchField<Type>::db() const
{
    return patch_.boundaryMesh().mesh();
}
You can then use this to lookup whatever you like (dictionaries, volFields, and their associated boundaries).


Sorry I can't handle your code ... can you give a more detailed example?
__________________
Tobias Holzinger

Chair of Thermodynamics, TU München
woody is offline   Reply With Quote

Old   December 6, 2011, 08:39
Default
  #12
Member
 
Rob
Join Date: Sep 2011
Posts: 55
Rep Power: 15
robbirobocop is on a distinguished road
I have a similar problem.

In every loop I write out a constant scalar to "scalarDict" which is inside of the constant directory. The entry for the scalar is: fluxIn 0.21;

Now I want to import this value and assign it to a boundary condition, e.g. flowRateInletvelocity. However, this does not work with any of the above posted hints.

scalarDict is of type "IOdictionary" and is located in "createFields.H".
The scalarDict.set(name, value) is inside the "solver.C" file.
Compiling the solver via "wmake" works well without any error message.

So, what kind of "lines" do I have to put inside my "U" file to successfully import the flowRate I need for my BC?

Any kind of help would be appreciated.
robbirobocop is offline   Reply With Quote

Old   December 6, 2011, 10:30
Default
  #13
Member
 
Rob
Join Date: Sep 2011
Posts: 55
Rep Power: 15
robbirobocop is on a distinguished road
Alright, I fixed it myself.

Since the scalarDict is updated on every timestep ( the value is just overwritten ).
How can I manage to reload the value in my BC?

For now the BC flowRate value is 3.8E-05 (the starting value) all the time.
So it is not updated...
robbirobocop 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
RhoSimpleFoam tutorial test case system dictionaries flavio_pergolesi OpenFOAM Running, Solving & CFD 2 April 17, 2014 09:41
Using wildcards regexes in dictionaries chtrapp OpenFOAM Pre-Processing 4 July 18, 2012 12:37
Passing parameters from dictionaries ngj OpenFOAM Running, Solving & CFD 0 June 29, 2008 12:25
Thermo dictionaries grtabor OpenFOAM Running, Solving & CFD 0 July 7, 2005 14:07
Dictionaries written by FoamX Mattijs Janssens (Mattijs) OpenFOAM Pre-Processing 1 January 3, 2005 14:44


All times are GMT -4. The time now is 16:27.