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

Adding thermophysical model to chemistryType runtime table

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 4, 2014, 22:00
Default Adding thermophysical model to chemistryType runtime table
  #1
Member
 
Chris
Join Date: Aug 2012
Location: Calgary, Alberta, Canada
Posts: 77
Rep Power: 13
ChrisA is on a distinguished road
I'm attempting to add a thermophysical model (myGasThermoPhysics) to the chemistry model runtime selection table so I can use my own Cp and viscosity in my reacting simulations. I've managed to get it added to the selection table as evidenced by:

Code:
ode                psi              hollis      myJanaf      perfectGas                specie  sensibleEnthalpy
When I error out the thermoType. However, when I attempt to run the simulations I get the following error:

Code:
Selecting combustion model PaSR<psiChemistryCombustion>
Selecting chemistry type 
{
    chemistrySolver ode;
    chemistryThermo psi;
}

Selecting thermodynamics package 
{
    type            hePsiThermo;
    mixture         massAveragedMixture;
    transport       hollis;
    thermo          myJanaf;
    energy          sensibleEnthalpy;
    equationOfState perfectGas;
    specie          specie;
}

terminate called after throwing an instance of 'std::bad_cast'
  what():  std::bad_cast
Aborted (core dumped)
which basically means I've missed something. The steps I've taken to get this far are the following:

In my custom library where the custom Cp, viscosity and mixtures are defined I created 3 files with the following code sections:

Code:
#include "makeChemistrySolverTypes.H"
#include "speciesPhysicsTypes.H"
//#include "thermoPhysicsTypes.H"
#include "psiChemistryModel.H"
#include "rhoChemistryModel.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
    // Chemistry solvers based on sensibleEnthalpy
    makeChemistrySolverTypes(psiChemistryModel, myGasThermoPhysics);

}
Code:
#ifndef reactionTypes_H
#define reactionTypes_H

//#include "thermoPhysicsTypes.H"
#include "Reaction.H"
#include "speciesPhysicsTypes.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

    typedef Reaction<myGasThermoPhysics> myGasReaction;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif
Code:
#include "makeChemistryModel.H"
#include "speciesPhysicsTypes.H"
#include "psiChemistryModel.H"
#include "chemistryModel.H"
//#include "thermoPhysicsTypes.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
    // Chemistry moldels based on sensibleEnthalpy
    makeChemistryModel
    (
        chemistryModel,
        psiChemistryModel,
        myGasThermoPhysics
    );

}
where speciesPhysicsTypes.H defines myGasThermoPhysics

I then of course added them as make targets in the Make/files file and added the proper lnInclude folders in the Make/options file.

As far as I can tell from the source this is all I need to do to add a thermophysical model to the runtime selection for the chemistry, but I seem to be missing something given the error. Can anyone shed some light on this?
ChrisA is offline   Reply With Quote

Old   February 10, 2014, 21:56
Default
  #2
Member
 
Chris
Join Date: Aug 2012
Location: Calgary, Alberta, Canada
Posts: 77
Rep Power: 13
ChrisA is on a distinguished road
So I figured out part of the issue. It seems the mixture model I want to use isn't compatible (not sure if thats the right word) with the reaction bits. I attempted to create a reaction compatible bit of code based on the reactingMixture code (basically replacing references to multiComponentMixture, which my mixture model replaces, with the mixture model.) but I'm getting the following error upon compilation: (working in 2.2.x btw)

Code:
Make/linux64GccDPOpt/speciesThermos.o
In file included from /opt/openfoam221/src/thermophysicalModels/basic/lnInclude/hePsiThermo.H:97:0,
                 from speciesThermos.C:30:
/opt/openfoam221/src/thermophysicalModels/basic/lnInclude/hePsiThermo.C: In member function \u2018void Foam::hePsiThermo<BasicPsiThermo, MixtureType>::calculate() [with BasicPsiThermo = Foam::psiReactionThermo, MixtureType = Foam::SpecieMixture<Foam::massAveragedReactingMixture<Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > > >]\u2019:
/opt/openfoam221/src/thermophysicalModels/basic/lnInclude/basicThermo.H:108:5:   recursively instantiated from \u2018static Foam::autoPtr<Foam::basicThermo> Foam::basicThermo::addfvMeshConstructorToTable<basicThermoType>::New(const Foam::fvMesh&, const Foam::word&) [with basicThermoType = Foam::hePsiThermo<Foam::psiReactionThermo, Foam::SpecieMixture<Foam::massAveragedReactingMixture<Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > > > >]\u2019
/opt/openfoam221/src/thermophysicalModels/basic/lnInclude/basicThermo.H:108:5:   instantiated from \u2018Foam::basicThermo::addfvMeshConstructorToTable<basicThermoType>::addfvMeshConstructorToTable(const Foam::word&) [with basicThermoType = Foam::hePsiThermo<Foam::psiReactionThermo, Foam::SpecieMixture<Foam::massAveragedReactingMixture<Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > > > >]\u2019
speciesThermos.C:141:1:   instantiated from here
/opt/openfoam221/src/thermophysicalModels/basic/lnInclude/hePsiThermo.C:44:36: error: invalid initialization of reference of type \u2018const thermoType& {aka const Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >&}\u2019 from expression of type \u2018const Foam::massAveragedTransport<Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > >\u2019
/opt/openfoam221/src/thermophysicalModels/basic/lnInclude/basicThermo.H:108:5:   recursively instantiated from \u2018static Foam::autoPtr<Foam::basicThermo> Foam::basicThermo::addfvMeshConstructorToTable<basicThermoType>::New(const Foam::fvMesh&, const Foam::word&) [with basicThermoType = Foam::hePsiThermo<Foam::psiReactionThermo, Foam::SpecieMixture<Foam::massAveragedReactingMixture<Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > > > >]\u2019
/opt/openfoam221/src/thermophysicalModels/basic/lnInclude/basicThermo.H:108:5:   instantiated from \u2018Foam::basicThermo::addfvMeshConstructorToTable<basicThermoType>::addfvMeshConstructorToTable(const Foam::word&) [with basicThermoType = Foam::hePsiThermo<Foam::psiReactionThermo, Foam::SpecieMixture<Foam::massAveragedReactingMixture<Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > > > >]\u2019
speciesThermos.C:141:1:   instantiated from here
/opt/openfoam221/src/thermophysicalModels/basic/lnInclude/hePsiThermo.C:75:57: error: invalid initialization of reference of type \u2018const thermoType& {aka const Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >&}\u2019 from expression of type \u2018const Foam::massAveragedTransport<Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > >\u2019
/opt/openfoam221/src/thermophysicalModels/basic/lnInclude/hePsiThermo.C:89:57: error: invalid initialization of reference of type \u2018const thermoType& {aka const Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> >&}\u2019 from expression of type \u2018const Foam::massAveragedTransport<Foam::hollisTransport<Foam::species::thermo<Foam::myJanafThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleEnthalpy> > >\u2019
My source files are as follows:

massAveragedReactingMixture.H

Code:
#ifndef massAveragedReactingMixture_H
#define massAveragedReactingMixture_H

#include "speciesTable.H"
#include "chemistryReader.H"
#include "massAveragedMixture.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

/*---------------------------------------------------------------------------*\
                      Class reactingMixture Declaration
\*---------------------------------------------------------------------------*/

template<class ThermoType>
class massAveragedReactingMixture
:
    public speciesTable,
    public autoPtr<chemistryReader<ThermoType> >,
    public massAveragedMixture<ThermoType>,
    public PtrList<Reaction<ThermoType> >
{
    // Private Member Functions

        //- Disallow default bitwise copy construct
        massAveragedReactingMixture(const massAveragedReactingMixture&);

        //- Disallow default bitwise assignment
        void operator=(const massAveragedReactingMixture&);


public:

    //- The type of thermo package this mixture is instantiated for
    typedef ThermoType thermoType;


    // Constructors

        //- Construct from dictionary and mesh
        massAveragedReactingMixture(const dictionary&, const fvMesh&);


    //- Destructor
    virtual ~massAveragedReactingMixture()
    {}


    // Member functions

        //- Read dictionary
        void read(const dictionary&);

        label size() const
        {
            return PtrList<Reaction<ThermoType> >::size();
        }

        Reaction<ThermoType>& operator [] (const label i)
        {
            return PtrList<Reaction<ThermoType> >::operator[](i);
        }
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#ifdef NoRepository
#   include "massAveragedReactingMixture.C"
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //
massAveragedReactingMixture.C

Code:
#include "massAveragedReactingMixture.H"
#include "fvMesh.H"

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

template<class ThermoType>
Foam::massAveragedReactingMixture<ThermoType>::massAveragedReactingMixture
(
    const dictionary& thermoDict,
    const fvMesh& mesh
)
:
    speciesTable(),
    autoPtr<chemistryReader<ThermoType> >
    (
        chemistryReader<ThermoType>::New(thermoDict, *this)
    ),
    massAveragedMixture<ThermoType>
    (
        thermoDict,
        *this,
        autoPtr<chemistryReader<ThermoType> >::operator()().speciesThermo(),
        mesh
    ),
    PtrList<Reaction<ThermoType> >
    (
        autoPtr<chemistryReader<ThermoType> >::operator()().reactions()
    )
{
    autoPtr<chemistryReader<ThermoType> >::clear();
}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

template<class ThermoType>
void Foam::massAveragedReactingMixture<ThermoType>::read(const dictionary& thermoDict)
{}


// ************************************************************************* //
and finally the declaration of the thermotype:

Code:
makeReactionMixtureThermo
(
    psiThermo,
    psiReactionThermo,
    hePsiThermo,
    massAveragedReactingMixture,
    myGasThermoPhysics
);
I'm stumped, any advice?

Last edited by ChrisA; February 11, 2014 at 12:51.
ChrisA is offline   Reply With Quote

Old   February 11, 2014, 18:16
Default
  #3
Member
 
Chris
Join Date: Aug 2012
Location: Calgary, Alberta, Canada
Posts: 77
Rep Power: 13
ChrisA is on a distinguished road
Well, I got it to compile. Turns out the typedef in the massAveragedReactingMixture should have been:

typedef massAveragedTransport<ThermoType> thermoType;

rather than just ThermoType (didn't match the thermotype definition in my massAveragedMixture model)

However, at runtime it still has a bad_cast error. Something else is missing to make this fully compatible with the chemistryModel... I think I've found where things are going bad in chemistryModel.C:

Code:
template<class CompType, class ThermoType>
Foam::chemistryModel<CompType, ThermoType>::chemistryModel
(
    const fvMesh& mesh
)
:
    CompType(mesh),
    ODE(),
    Y_(this->thermo().composition().Y()),
    reactions_
    (
        dynamic_cast<const reactingMixture<ThermoType>&>(this->thermo())
    ),
    specieThermo_
    (
        dynamic_cast<const reactingMixture<ThermoType>&>
            (this->thermo()).speciesData()
    ),
Seems like everything is very general up till this point and it's causing some issues... In the interests of time im going to copy and re-hardcode the library to use my model. Hopefully that works... and hopefully me documenting this saga helps someone else out at some point in the future.
ChrisA is offline   Reply With Quote

Old   March 10, 2014, 09:37
Default
  #4
Senior Member
 
Olivier
Join Date: Jun 2009
Location: France, grenoble
Posts: 272
Rep Power: 17
olivierG is on a distinguished road
hello Chris,

I try do to the same, i.e add a new equationOfState and transport to heRhoThermo type, but i don't see how to add a custom lib without altering the source in the install dir.

Do you succeed to create a custom lib ?
Is possible to just add new transport and eOS to a thermoType ?

NB: i use OpenFOAM-2.3.x

regards,
olivierG 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
Adding a Turbulence Model doug OpenFOAM Running, Solving & CFD 11 May 21, 2018 13:54
Problem in3D model processing mebinitap OpenFOAM 2 December 12, 2014 04:40
Adding a turbulence model into my own CFD code quarkz Main CFD Forum 3 November 23, 2013 22:53
DPM model w/ Wave model - errors in documentation HS FLUENT 0 April 12, 2006 04:37
Advanced Turbulence Modeling in Fluent, Realizable k-epsilon Model Jonas Larsson FLUENT 5 March 13, 2000 03:27


All times are GMT -4. The time now is 12:44.