CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   Accessing fields and dictionaries from within a BC implementation (http://www.cfd-online.com/Forums/openfoam-solving/60401-accessing-fields-dictionaries-within-bc-implementation.html)

alberto December 5, 2005 16:09

How can a field defined in the
 
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

woody July 16, 2010 03:29

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"
);

deepsterblue July 16, 2010 09:24

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).

woody July 16, 2010 09:56

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

andrea July 16, 2010 10:05

eaxmple
 
Hi,
this should be an example:

Code:

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

Abdrea

woody July 19, 2010 03:55

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... :rolleyes:

deji July 26, 2010 17:47

Reading alpha and alphaEff
 
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 July 26, 2010 17:51

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")
);

ozgur September 14, 2010 10:14

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 (Post 267666)
Hi,
this should be an example:

Code:

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

Abdrea


woody January 4, 2011 08:08

Access Data from same bc but different parameter
 
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

woody January 7, 2011 08:36

Quote:

Originally Posted by deepsterblue (Post 267661)
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?

robbirobocop December 6, 2011 08:39

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 December 6, 2011 10:30

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...


All times are GMT -4. The time now is 11:21.