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

How the boundary conditions are called in the OpenFOAM solvers?

Register Blogs Community New Posts Updated Threads Search

Like Tree35Likes
  • 4 Post By openfoammaofnepo
  • 22 Post By hjasak
  • 2 Post By openfoammaofnepo
  • 1 Post By openfoammaofnepo
  • 2 Post By hjasak
  • 1 Post By openfoammaofnepo
  • 3 Post By abtinansari

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 1, 2014, 10:05
Question How the boundary conditions are called in the OpenFOAM solvers?
  #1
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
Dear All,

I was wondering how the boundary conditions subroutines are called ?

Let us take an example:

Code:
OpenFOAM/OpenFOAM-2.1.1/tutorials/compressible/rhoPimpleFoam/les/pitzDaily
In the file:

Code:
U/0
we have the following boundary conditions for the inlet:

Code:
    inlet
    {
        type            turbulentInlet;
        referenceField  uniform (10 0 0);
        fluctuationScale (0.02 0.01 0.01);
        value           uniform (10 0 0);
    }
Does anybody know in which part of the solver is calling the turbulentInlet's subroutine? I am asking this questions because I would like to implement my own BC type in openfoam.

Thank you in advance!
Annier, minh khang, lpz456 and 1 others like this.
openfoammaofnepo is offline   Reply With Quote

Old   February 3, 2014, 01:54
Default
  #2
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Easy:
- on correctBoundaryConditions() for a field
- on updateCoeffs() at matrix creation

correctBoundaryConditions is also called after the linear solver call automatically.


Enjoy,

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

Old   February 3, 2014, 12:16
Default
  #3
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
Thank you so much, Hrvoje!

About the first one, I get it in the
Code:
src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.C
I can get the following lines of codes:
Code:
// Correct the boundary conditions
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::
correctBoundaryConditions()
{
    this->setUpToDate();
    storeOldTimes();
    boundaryField_.evaluate();
}
Here about the function evaluation(), I cannot find where it is defined. In the following source file:

Code:
src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H
It is declared as

Code:
            //- Evaluate boundary conditions
            void evaluate();
But it is virtual function here. Could you please give me some hints about where it is defined assuming we are still talking about the turbulentInlet? Thank you very much.
abtinansari and TeddyL like this.
openfoammaofnepo is offline   Reply With Quote

Old   February 3, 2014, 12:21
Default
  #4
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
About the updateCoeffs in the turbulentInlet boundary conditions

Code:
OpenFOAM/OpenFOAM-2.1.1/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet
It has the following specific forms:
Code:
template<class Type>
void turbulentInletFvPatchField<Type>::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    if (curTimeIndex_ != this->db().time().timeIndex())
    {
        Field<Type>& patchField = *this;

        Field<Type> randomField(this->size());

        forAll(patchField, facei)
        {
            ranGen_.randomise(randomField[facei]);
        }

        // Correction-factor to compensate for the loss of RMS fluctuation
        // due to the temporal correlation introduced by the alpha parameter.
        scalar rmsCorr = sqrt(12*(2*alpha_ - sqr(alpha_)))/alpha_;

        patchField =
            (1 - alpha_)*patchField
          + alpha_*
            (
                referenceField_
              + rmsCorr*cmptMultiply
                (
                    randomField - 0.5*pTraits<Type>::one,
                    fluctuationScale_
                )*mag(referenceField_)
            );

        curTimeIndex_ = this->db().time().timeIndex();
    }

    fixedValueFvPatchField<Type>::updateCoeffs();
}
In the above mentioned codes, the updateCoeffs() from the fixedValue boundary conditions type is used

Code:
fixedValueFvPatchField<Type>::updateCoeffs();
What is the role of this line? in the source files for fixedValue, I did not find any information about the relevant definitions there. Could anybody share some information about this problem? Thank you so much.

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++
As a record how I understand this, I put the answer here:

evaluate() is defined in

Code:
src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C
The structure is:

Code:
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
evaluate()
{
    if (debug)
    {
        Info<< "GeometricField<Type, PatchField, GeoMesh>::"
               "GeometricBoundaryField::"
               "evaluate()" << endl;
    }

    if
    (
        Pstream::defaultCommsType == Pstream::blocking
     || Pstream::defaultCommsType == Pstream::nonBlocking
    )
    {
        label nReq = Pstream::nRequests();

        forAll(*this, patchi)
        {
            this->operator[](patchi).initEvaluate(Pstream::defaultCommsType);
        }

        // Block for any outstanding requests
        if
        (
            Pstream::parRun()
         && Pstream::defaultCommsType == Pstream::nonBlocking
        )
        {
            Pstream::waitRequests(nReq);
        }

        forAll(*this, patchi)
        {
            this->operator[](patchi).evaluate(Pstream::defaultCommsType);
        }
    }
    else if (Pstream::defaultCommsType == Pstream::scheduled)
    {
        const lduSchedule& patchSchedule =
            bmesh_.mesh().globalData().patchSchedule();

        forAll(patchSchedule, patchEvali)
        {
            if (patchSchedule[patchEvali].init)
            {
                this->operator[](patchSchedule[patchEvali].patch)
                    .initEvaluate(Pstream::scheduled);
            }
            else
            {
                this->operator[](patchSchedule[patchEvali].patch)
                    .evaluate(Pstream::scheduled);
            }
        }
    }
    else
    {
        FatalErrorIn("GeometricBoundaryField::evaluate()")
            << "Unsuported communications type "
            << Pstream::commsTypeNames[Pstream::defaultCommsType]
            << exit(FatalError);
    }
}
fumiya likes this.
openfoammaofnepo is offline   Reply With Quote

Old   February 5, 2014, 07:50
Default
  #5
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
No Body also interested in this issue?
openfoammaofnepo is offline   Reply With Quote

Old   February 5, 2014, 10:27
Default
  #6
New Member
 
Y
Join Date: Feb 2013
Location: The Earth
Posts: 25
Rep Power: 13
peteryuan is on a distinguished road
As a newbie I asked a similar question in my latest post:
http://www.cfd-online.com/Forums/ope...tempratur.html
Quote:
"In externalCoupledMixedFvPatchField.C line 698 there is this evaluate() function defined. I supose that is the function at the top level and would do all the actual works for this class, like readData, writeData and so on. Now for example an object of this class is created with /0/T file and during runtime this evaluate() function is executed (I think). Could anyone tell me where is this function called during runtime? I use chtMultiRegionFoam, searched a lot in the code but still do not have a clue where this or any of the functions from that class is called. "
Here I find my key word "evaluate()":
Code:
correctBoundaryConditions() {
     this->setUpToDate();
     storeOldTimes();
     boundaryField_.evaluate(); }
I guess that all classes for BC have this .evaluate() member function... During runtime of a solver, after an object being created, the evaluate() functions are called with this correctBoundaryConditions(). Each BC class has a different .evaluate().
Am I right?
peteryuan is offline   Reply With Quote

Old   February 5, 2014, 18:33
Default
  #7
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
Yes, I agree with you. I also did some digging into the source files. But do you know the role of the following lines:
Code:
fixedValueFvPatchField<Type>::updateCoeffs();
openfoammaofnepo is offline   Reply With Quote

Old   February 20, 2014, 16:46
Default
  #8
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
I did not find this function in the source:

fixedValueFvPatchField.H

Sorry for my limit C++ skills. Does anybody know where I can find this function,
Code:
fixedValueFvPatchField<Type>::updateCoeffs();
?


Quote:
Originally Posted by openfoammaofnepo View Post
Yes, I agree with you. I also did some digging into the source files. But do you know the role of the following lines:
Code:
fixedValueFvPatchField<Type>::updateCoeffs();
openfoammaofnepo is offline   Reply With Quote

Old   February 20, 2014, 17:02
Default
  #9
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
Please read up on virtual functions - this is basic C++

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

Old   April 10, 2014, 07:30
Default
  #10
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
For my record, actually, the following lines:

Code:
fixedValueFvPatchField<Type>::updateCoeffs();
did nothing but just to set the bool variable update() to be true.

The function updateCoeffs is defined in:

Code:
fvPatchField.H
Quote:
Originally Posted by openfoammaofnepo View Post
About the updateCoeffs in the turbulentInlet boundary conditions

Code:
OpenFOAM/OpenFOAM-2.1.1/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet
It has the following specific forms:
Code:
template<class Type>
void turbulentInletFvPatchField<Type>::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    if (curTimeIndex_ != this->db().time().timeIndex())
    {
        Field<Type>& patchField = *this;

        Field<Type> randomField(this->size());

        forAll(patchField, facei)
        {
            ranGen_.randomise(randomField[facei]);
        }

        // Correction-factor to compensate for the loss of RMS fluctuation
        // due to the temporal correlation introduced by the alpha parameter.
        scalar rmsCorr = sqrt(12*(2*alpha_ - sqr(alpha_)))/alpha_;

        patchField =
            (1 - alpha_)*patchField
          + alpha_*
            (
                referenceField_
              + rmsCorr*cmptMultiply
                (
                    randomField - 0.5*pTraits<Type>::one,
                    fluctuationScale_
                )*mag(referenceField_)
            );

        curTimeIndex_ = this->db().time().timeIndex();
    }

    fixedValueFvPatchField<Type>::updateCoeffs();
}
In the above mentioned codes, the updateCoeffs() from the fixedValue boundary conditions type is used

Code:
fixedValueFvPatchField<Type>::updateCoeffs();
What is the role of this line? in the source files for fixedValue, I did not find any information about the relevant definitions there. Could anybody share some information about this problem? Thank you so much.

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++
As a record how I understand this, I put the answer here:

evaluate() is defined in

Code:
src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C
The structure is:

Code:
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
evaluate()
{
    if (debug)
    {
        Info<< "GeometricField<Type, PatchField, GeoMesh>::"
               "GeometricBoundaryField::"
               "evaluate()" << endl;
    }

    if
    (
        Pstream::defaultCommsType == Pstream::blocking
     || Pstream::defaultCommsType == Pstream::nonBlocking
    )
    {
        label nReq = Pstream::nRequests();

        forAll(*this, patchi)
        {
            this->operator[](patchi).initEvaluate(Pstream::defaultCommsType);
        }

        // Block for any outstanding requests
        if
        (
            Pstream::parRun()
         && Pstream::defaultCommsType == Pstream::nonBlocking
        )
        {
            Pstream::waitRequests(nReq);
        }

        forAll(*this, patchi)
        {
            this->operator[](patchi).evaluate(Pstream::defaultCommsType);
        }
    }
    else if (Pstream::defaultCommsType == Pstream::scheduled)
    {
        const lduSchedule& patchSchedule =
            bmesh_.mesh().globalData().patchSchedule();

        forAll(patchSchedule, patchEvali)
        {
            if (patchSchedule[patchEvali].init)
            {
                this->operator[](patchSchedule[patchEvali].patch)
                    .initEvaluate(Pstream::scheduled);
            }
            else
            {
                this->operator[](patchSchedule[patchEvali].patch)
                    .evaluate(Pstream::scheduled);
            }
        }
    }
    else
    {
        FatalErrorIn("GeometricBoundaryField::evaluate()")
            << "Unsuported communications type "
            << Pstream::commsTypeNames[Pstream::defaultCommsType]
            << exit(FatalError);
    }
}
lpz456 likes this.
openfoammaofnepo is offline   Reply With Quote

Old   April 10, 2014, 07:32
Default
  #11
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
Dear Dr Jasak,

The second item you mentioned:

Code:
updateCoeffs()
is just to set the bool quantity update() to be true, no any math manipulations are done in this function. Is my understanding correct?

OFFO


Quote:
Originally Posted by hjasak View Post
Easy:
- on correctBoundaryConditions() for a field
- on updateCoeffs() at matrix creation

correctBoundaryConditions is also called after the linear solver call automatically.


Enjoy,

Hrv
openfoammaofnepo is offline   Reply With Quote

Old   April 16, 2014, 18:54
Default
  #12
New Member
 
Y
Join Date: Feb 2013
Location: The Earth
Posts: 25
Rep Power: 13
peteryuan is on a distinguished road
my understanding so far is:

Those BC types that need updating and evaluation at each time step, they either have updateCoeffs() or evaluate() in the class definition, virtual of course.
When a fvMatrix<type> Eqn is created, the updateCoeffs() is called in its constructor. Then in Eqn().solve() the function correctBoundaryConditions() is called, which contains evaluate().
Now the two functions are implemented differently in every BC, and the solver would also execute different things out according to each BC type defined.

Thanks for corrections and improvement.
peter
peteryuan is offline   Reply With Quote

Old   December 19, 2014, 02:26
Default
  #13
New Member
 
Abtin Ansari
Join Date: Oct 2014
Posts: 2
Rep Power: 0
abtinansari is on a distinguished road
My understanding is that functions like updateCoeffs() and evaluate() are defined first in the upper code level virtually like in GeometricBoundaryField.C and overloaded(redefined) later in specific derived classes where actual math manipulation is done. For example lets look at fixedGradientFvPatchField.C in /src/finiteVolume/fields/fvPatchFields/basic/fixedGradient :

template<class Type>
void fixedGradientFvPatchField<Type>::evaluate(const Pstream::commsTypes)
{
if (!this->updated())
{
this->updateCoeffs();
}

Field<Type>:perator=
(
this->patchInternalField() + gradient_/this->patch().deltaCoeffs()
);

fvPatchField<Type>::evaluate();
}

Here , the value is updated based on specified gradient in BC file. Can somebody please verify since I'm I also new to C++?
D.R., Annier and lpz456 like this.
abtinansari is offline   Reply With Quote

Old   December 19, 2014, 13:38
Default
  #14
Senior Member
 
Join Date: Jan 2013
Posts: 372
Rep Power: 14
openfoammaofnepo is on a distinguished road
I think what you said is correct.

Quote:
Originally Posted by abtinansari View Post
My understanding is that functions like updateCoeffs() and evaluate() are defined first in the upper code level virtually like in GeometricBoundaryField.C and overloaded(redefined) later in specific derived classes where actual math manipulation is done. For example lets look at fixedGradientFvPatchField.C in /src/finiteVolume/fields/fvPatchFields/basic/fixedGradient :

template<class Type>
void fixedGradientFvPatchField<Type>::evaluate(const Pstream::commsTypes)
{
if (!this->updated())
{
this->updateCoeffs();
}

Field<Type>:perator=
(
this->patchInternalField() + gradient_/this->patch().deltaCoeffs()
);

fvPatchField<Type>::evaluate();
}

Here , the value is updated based on specified gradient in BC file. Can somebody please verify since I'm I also new to C++?
openfoammaofnepo is offline   Reply With Quote

Old   April 2, 2019, 13:30
Default
  #15
New Member
 
-- Country other than USA or Canada --
Join Date: Mar 2019
Posts: 3
Rep Power: 7
kkamau is on a distinguished road
How to call updateCoeff on UEqn. I tried UEqn.updateCoeff() but openfoam returned a compiler error
kkamau is offline   Reply With Quote

Old   February 11, 2020, 05:28
Default
  #16
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16
gaza is on a distinguished road
Quote:
Originally Posted by openfoammaofnepo View Post
About the updateCoeffs in the turbulentInlet boundary conditions

Code:
OpenFOAM/OpenFOAM-2.1.1/src/finiteVolume/fields/fvPatchFields/derived/turbulentInlet
It has the following specific forms:
Code:
template<class Type>
void turbulentInletFvPatchField<Type>::updateCoeffs()
{
    if (this->updated())
    {
        return;
    }

    if (curTimeIndex_ != this->db().time().timeIndex())
    {
        Field<Type>& patchField = *this;

        Field<Type> randomField(this->size());

        forAll(patchField, facei)
        {
            ranGen_.randomise(randomField[facei]);
        }

        // Correction-factor to compensate for the loss of RMS fluctuation
        // due to the temporal correlation introduced by the alpha parameter.
        scalar rmsCorr = sqrt(12*(2*alpha_ - sqr(alpha_)))/alpha_;

        patchField =
            (1 - alpha_)*patchField
          + alpha_*
            (
                referenceField_
              + rmsCorr*cmptMultiply
                (
                    randomField - 0.5*pTraits<Type>::one,
                    fluctuationScale_
                )*mag(referenceField_)
            );

        curTimeIndex_ = this->db().time().timeIndex();
    }

    fixedValueFvPatchField<Type>::updateCoeffs();
}
In the above mentioned codes, the updateCoeffs() from the fixedValue boundary conditions type is used

Code:
fixedValueFvPatchField<Type>::updateCoeffs();
What is the role of this line? in the source files for fixedValue, I did not find any information about the relevant definitions there. Could anybody share some information about this problem? Thank you so much.

++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++
As a record how I understand this, I put the answer here:

evaluate() is defined in

Code:
src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C
The structure is:

Code:
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricBoundaryField::
evaluate()
{
    if (debug)
    {
        Info<< "GeometricField<Type, PatchField, GeoMesh>::"
               "GeometricBoundaryField::"
               "evaluate()" << endl;
    }

    if
    (
        Pstream::defaultCommsType == Pstream::blocking
     || Pstream::defaultCommsType == Pstream::nonBlocking
    )
    {
        label nReq = Pstream::nRequests();

        forAll(*this, patchi)
        {
            this->operator[](patchi).initEvaluate(Pstream::defaultCommsType);
        }

        // Block for any outstanding requests
        if
        (
            Pstream::parRun()
         && Pstream::defaultCommsType == Pstream::nonBlocking
        )
        {
            Pstream::waitRequests(nReq);
        }

        forAll(*this, patchi)
        {
            this->operator[](patchi).evaluate(Pstream::defaultCommsType);
        }
    }
    else if (Pstream::defaultCommsType == Pstream::scheduled)
    {
        const lduSchedule& patchSchedule =
            bmesh_.mesh().globalData().patchSchedule();

        forAll(patchSchedule, patchEvali)
        {
            if (patchSchedule[patchEvali].init)
            {
                this->operator[](patchSchedule[patchEvali].patch)
                    .initEvaluate(Pstream::scheduled);
            }
            else
            {
                this->operator[](patchSchedule[patchEvali].patch)
                    .evaluate(Pstream::scheduled);
            }
        }
    }
    else
    {
        FatalErrorIn("GeometricBoundaryField::evaluate()")
            << "Unsuported communications type "
            << Pstream::commsTypeNames[Pstream::defaultCommsType]
            << exit(FatalError);
    }
}

Hi
I am trying to see a value of a variable inside BC.
I tried standard Info statement:
Code:
Info<< "variable = " << variable << endl;
but it does not give any output in log file.
I tried also
Code:
if (debug) 

{ 
  Info<< "GeometricField<Type, PatchField, GeoMesh>::"              
    "GeometricBoundaryField::"
    "evaluate()" << endl; 
}
but it does not work either. Can anybody help?
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Reply

Tags
boundary condition


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
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28
[Commercial meshers] exporting boundary conditions with pointwise -> openFoam ebah6 OpenFOAM Meshing & Mesh Conversion 2 September 16, 2012 17:57
CFX13 Post Periodic interface EtaEta CFX 7 December 8, 2011 18:15
New OpenFOAM Forum Structure jola OpenFOAM 2 October 19, 2011 07:55
RPM in Wind Turbine Pankaj CFX 9 November 23, 2009 05:05


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