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

dynamic_cast operation in chemistryModel.C

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 27, 2017, 11:20
Default dynamic_cast operation in chemistryModel.C
  #1
New Member
 
Join Date: Jun 2014
Posts: 4
Rep Power: 12
zbtlfd is on a distinguished road
Hello everyone,

hopefully a more experienced OpenFOAM/C++ developer can answer my question regarding the dynamic_cast operation used in the thermophysicalModels library, and specifically in the chemistryModel class, which extends the basicChemistryModel class. In the constructor in chemistryModel.C, the dynamic_cast operation is used to downcast from a basicMultiComponentMixture to a reactingMixture:

Code:
template<class CompType, class ThermoType>
Foam::chemistryModel<CompType, ThermoType>::chemistryModel
(
    const fvMesh& mesh,
    const word& phaseName
)
:
    CompType(mesh, phaseName),
    ODESystem(),
    Y_(this->thermo().composition().Y()),
    reactions_
    (
        dynamic_cast<const reactingMixture<ThermoType>&>(this->thermo())
    ),
    specieThermo_
    (
        dynamic_cast<const reactingMixture<ThermoType>&>
            (this->thermo()).speciesData()
    ),

    nSpecie_(Y_.size()),
    nReaction_(reactions_.size()),
    Treact_(CompType::template lookupOrDefault<scalar>("Treact", 0.0)),
    RR_(nSpecie_)
However, this->thermo() actually points to either the class rhoReactionThermo or psiReactionThermo, which in itself contains the method composition(), which returns a reference to basicMultiComponentMixture. Therefore from my understanding of this method, the data members, specifically the ones using dynamic_cast,should be initialized like this in the constructor:

Code:
template<class CompType, class ThermoType>
Foam::chemistryModel<CompType, ThermoType>::chemistryModel
(
    const fvMesh& mesh,
    const word& phaseName
)
:
    CompType(mesh, phaseName),
    ODESystem(),
    Y_(this->thermo().composition().Y()),
    reactions_
    (
        dynamic_cast<const reactingMixture<ThermoType>&>(this->thermo().composition())
    ),
    specieThermo_
    (
        dynamic_cast<const reactingMixture<ThermoType>&>
            (this->thermo().composition()).speciesData()
    ),

    nSpecie_(Y_.size()),
    nReaction_(reactions_.size()),
    Treact_(CompType::template lookupOrDefault<scalar>("Treact", 0.0)),
    RR_(nSpecie_)
Obviously the original version works as well, however I don't understand why. I stumbled over this, when I tried to extend the basicMultiComponentMixture class with a couple of new member variables for my model extension. The code still compiled, but trying to access specieThermo_ fails because it is empty. It seems like I could fix it with my updated version.
Could somebody provide more insights or explanations here, if my understanding of the operation is correct and why it was implemented the way it is now in OpenFOAM?

Thank you very much!
Lukas

Last edited by zbtlfd; July 28, 2017 at 04:51. Reason: restating the question and fixing bug
zbtlfd is offline   Reply With Quote

Old   August 1, 2017, 05:14
Default small corrections
  #2
New Member
 
Join Date: Jun 2014
Posts: 4
Rep Power: 12
zbtlfd is on a distinguished road
Actually this->thermo() does not return a reference to rhoReactionThermo or psiReactionThermo, since they're just the abstract base classes, but rather heThermo, which seems to be inheriting from rho/psiReactionThermo.

Still, it seems much more logical to directly cast from the returned reference (basicMultiComponentMixture) of the composition() method to the reactingMixture instead of casting from the heThermo object to reactingMixture.
zbtlfd is offline   Reply With Quote

Reply

Tags
chemistrymodel, construction, dynamic_cast, openfoam, thermophysicalmodels


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
loading issue libraries:libsimpleFunctionObjects.so libsimpleSwakFunctionObjects.so immortality OpenFOAM Pre-Processing 15 April 7, 2024 13:35
complex number operation in udf? hongxiao FLUENT 5 June 14, 2017 15:11
reduce an equal operation T.D. OpenFOAM Programming & Development 1 September 6, 2016 13:00
Incompatible dimensions for operation ruben23 OpenFOAM Running, Solving & CFD 2 June 12, 2015 05:14
operation pressure and pressure outlet BC Lilly FLUENT 4 May 8, 2013 10:57


All times are GMT -4. The time now is 20:35.