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

List of chemical species from a boundary condition

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By zhangyan
  • 1 Post By zhangyan
  • 1 Post By zhangyan
  • 1 Post By Benben

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 30, 2018, 07:06
Unhappy List of chemical species from a boundary condition
  #1
Member
 
benoit favier
Join Date: Jun 2017
Posts: 64
Rep Power: 8
Benben is on a distinguished road
Hello,

I am coding a new boundary condition in OpenFoam 6. This boundary condition is to be used with the "reactingFoam" solver.
I want to acces the list of chemical species defined from this boundary condition.

I can access the mass fraction of a single specie using :
Code:
const Foam::fvPatchField<scalar>& W_N2 = this->patch().lookupPatchField<volScalarField, scalar>("N2");
However, i would like to have access to the complete list of species mass fractions. Just like in the reactingFoam solver :

Code:
const PtrList<volScalarField>& Y = thermo.composition().Y();
This doesnt work as thermo is only defined in the solver's "createFields.H" file.
Is there anyway to get access to it from the boundary condition ?

Last edited by Benben; August 31, 2018 at 05:35.
Benben is offline   Reply With Quote

Old   August 30, 2018, 21:34
Default
  #2
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12
zhangyan is on a distinguished road
Maybe you can get thermo by lookupObject?
Benben likes this.
zhangyan is offline   Reply With Quote

Old   August 31, 2018, 02:53
Default
  #3
Member
 
benoit favier
Join Date: Jun 2017
Posts: 64
Rep Power: 8
Benben is on a distinguished road
Hello, thank you for your interest in my problem.
It seems like it worked.

To create a "psiReactionThermo" object (which is the type of thermo), i have to include "psiReactionThermo.H" in my boundary condition header file, and add the lines :
Code:
-I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \
-I$(LIB_SRC)/transportModels/compressible/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude \
-I$(LIB_SRC)/ODE/lnInclude \
-I$(LIB_SRC)/combustionModels/lnInclude
to the "Make/options" file.

Then in the code of my boundary condition, i add :
Code:
const psiReactionThermo& thermo = this->db().lookupObject<psiReactionThermo>("thermophysicalProperties");
const PtrList<volScalarField>& Y = thermo.composition().Y();
It compiles and i yet have to try to use it.

However i have no clue on why i have access to it from the "ObjectRegistry". I am not very familiar with this class. In the declaration of "thermo", nothing is done to add it to a registry. What other variables do we have access to from there ? every variable created ?

Last edited by Benben; August 31, 2018 at 04:19. Reason: error in the code
Benben is offline   Reply With Quote

Old   August 31, 2018, 03:03
Default
  #4
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12
zhangyan is on a distinguished road
https://openfoam.top/en/thermodynamicLIB/
You can have a look at this UML, and you'll find that IOdictionary is the topmost base class of psiReactionThermo.
Since IOdictionary is often registried to the mesh, so will psiReactionThermo.
Benben likes this.
zhangyan is offline   Reply With Quote

Old   August 31, 2018, 04:35
Default
  #5
Member
 
benoit favier
Join Date: Jun 2017
Posts: 64
Rep Power: 8
Benben is on a distinguished road
I have another issue :

when calling
Code:
thermo.composition()
the program crashes and prints to the console
Code:
pure virtual method called
It seems that "psiReactionThermo" doesnt implement "composition()" (see documentation here).
How should i proceed to get the composition object ?
Benben is offline   Reply With Quote

Old   August 31, 2018, 04:50
Default
  #6
Member
 
benoit favier
Join Date: Jun 2017
Posts: 64
Rep Power: 8
Benben is on a distinguished road
It's probable that i should define it as an "hePsiThermo" (documentation here) as this is what i am asking openfoam to use in my dictionnary in "constant/thermophysicalProperties":
Code:
thermoType
{
    type            hePsiThermo;
    mixture         reactingMixture;
    transport       sutherland;
    thermo          janaf;
    energy          sensibleEnthalpy;
    equationOfState perfectGas;
    specie          specie;
}
I will try it.
Benben is offline   Reply With Quote

Old   August 31, 2018, 05:13
Default
  #7
Member
 
benoit favier
Join Date: Jun 2017
Posts: 64
Rep Power: 8
Benben is on a distinguished road
"hePsiThermo" takes two templates class, and i can't manage to declare a instance of the class :/

i Tried :

Code:
const hePsiThermo<psiReactionThermo, reactingMixture<psiReactionThermo>>& thermo = this->db().lookupObject<hePsiThermo<psiReactionThermo, reactingMixture<psiReactionThermo>>("t");
And it gave me :

Code:
/opt/openfoam6/src/thermophysicalModels/reactionThermo/lnInclude/multiComponentMixture.H:61:28: error: cannot declare field 'Foam::multiComponentMixture<Foam::psiReactionThermo>::mixture_' to be of abstract type 'Foam::psiReactionThermo'
         mutable ThermoType mixture_;
                            ^
In file included from evaporatingZinc_RDMP/evaporatingZinc_RDMPFvPatchScalarField.H:81:0,
                 from evaporatingZinc_RDMP/evaporatingZinc_RDMPFvPatchScalarField.C:26:
/opt/openfoam6/src/thermophysicalModels/reactionThermo/lnInclude/psiReactionThermo.H:52:7: note:   because the following virtual functions are pure within 'Foam::psiReactionThermo':
 class psiReactionThermo
I must be doing things wrong, i will try to look for examples in the code of "thermo = lookupObject("
Benben is offline   Reply With Quote

Old   August 31, 2018, 06:37
Default
  #8
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12
zhangyan is on a distinguished road
Try this?
Code:
const PtrList<volScalarField>& Y = 
dynamic_cast<hePsiThermo<psiReactionThermo,SpecieMixture<reactingMixture<gasHThermoPhysics>>>&>
(this->db().lookupObject<psiReactionThermo>("thermo")).composition().Y();
Benben likes this.
zhangyan is offline   Reply With Quote

Old   August 31, 2018, 10:29
Default
  #9
Member
 
benoit favier
Join Date: Jun 2017
Posts: 64
Rep Power: 8
Benben is on a distinguished road
I tried as you proposed :

Code:
const psiReactionThermo& hepsi_thermo = this->db().lookupObject<psiReactionThermo>("thermophysicalProperties");
const hePsiThermo<psiReactionThermo,SpecieMixture<reactingMixture<gasHThermoPhysics>>>& thermo 
    = 
    dynamic_cast<const hePsiThermo<psiReactionThermo,SpecieMixture<reactingMixture<gasHThermoPhysics>>>&>(hepsi_thermo);
but it raised me
Code:
terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
If I understand correctly, "hePsiThermo<psiReactionThermo,SpecieMixture<react ingMixture<gasHThermoPhysics>>>" is not derived from "psiReactionThermo".

How did you know what types should be used for the cast ? In the code I only found the definition of "thermo" in "createFields.H". And it is defined as a psiReactionThermo :
Code:
autoPtr<psiReactionThermo> pThermo(psiReactionThermo::New(mesh));
psiReactionThermo& thermo = pThermo();
Is it "psiReactionThermo::New(mesh)" that would actually return an object of a type derived from "psiReactionThermo" ?
Benben is offline   Reply With Quote

Old   August 31, 2018, 10:54
Default
  #10
Member
 
benoit favier
Join Date: Jun 2017
Posts: 64
Rep Power: 8
Benben is on a distinguished road
I tried by cheating with pointers :

Code:
const psiReactionThermo& hepsi_thermo = this->db().lookupObject<psiReactionThermo>("thermophysicalProperties");
    hePsiThermo<psiReactionThermo,SpecieMixture<reactingMixture<gasHThermoPhysics>>> 
* thermo = & hepsi_thermo;
It fails at compile, and displays :

Code:
error: cannot convert 
'const Foam::psiReactionThermo*'
to
'Foam::hePsiThermo<Foam::psiReactionThermo, Foam::SpecieMixture<Foam::reactingMixture<Foam::sutherlandTransport<Foam::species::thermo<Foam::janafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > > > >*'
in initialization
    hePsiThermo<psiReactionThermo,SpecieMixture<reactingMixture<gasHThermoPhysics>>> * thermo = & hepsi_thermo;
Benben is offline   Reply With Quote

Old   September 3, 2018, 10:41
Default
  #11
Member
 
benoit favier
Join Date: Jun 2017
Posts: 64
Rep Power: 8
Benben is on a distinguished road
I managed to solve my problem.

The right way to do it was to define

Code:
#include "psiReactionThermo.H"
const psiReactionThermo& thermo = this->db().lookupObject<psiReactionThermo>("thermophysicalProperties");
const PtrList<volScalarField>& Y = thermo.composition().Y();
and add
Code:
    -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \
    -I$(LIB_SRC)/transportModels/compressible/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude
To the "Make/options" file.

However, the first call of the boundary conditions is made when thermo is beeing built (as mass fractions, rho, and T are initialized by thermo). So, when the boundary condition is called for the first time, thermo is not completly initialized yet. So i had to implement a bypass so that the first call to the boundary condition initializes to some garbage, and doesnt call "thermo.composition()".

The boundary condition is still updated before solving the first time step, so no problem for the resolution (i verified this by outputing some text in the console). The only thing is that paraFoam will show some garbage for the boundary condition at time t=0.
zhangyan likes this.
Benben 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
Wind turbine simulation Saturn CFX 58 July 3, 2020 01:13
Centrifugal fan-reverse flow in outlet lesds to a mass in flow field xiexing CFX 3 March 29, 2017 10:00
Error finding variable "THERMX" sunilpatil CFX 8 April 26, 2013 07:00
External Radiation Boundary Condition (Two sided wall), Grid Interface CFD XUE FLUENT 0 July 8, 2010 06:49
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08


All times are GMT -4. The time now is 05:43.