|
[Sponsors] |
July 27, 2017, 11:20 |
dynamic_cast operation in chemistryModel.C
|
#1 |
New Member
Join Date: Jun 2014
Posts: 4
Rep Power: 12 |
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_) 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_) 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 |
|
August 1, 2017, 05:14 |
small corrections
|
#2 |
New Member
Join Date: Jun 2014
Posts: 4
Rep Power: 12 |
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. |
|
Tags |
chemistrymodel, construction, dynamic_cast, openfoam, thermophysicalmodels |
|
|
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 |