multicomponentThermo: Construct Yslicer on demand

This fixes a crash caused by the pointers to the mass fraction boundary
fields being invalidated by mesh-to-mesh mapping
This commit is contained in:
Will Bainbridge
2023-08-09 14:41:48 +01:00
parent b790a69507
commit a2314a5a23
14 changed files with 104 additions and 38 deletions

View File

@ -53,9 +53,11 @@ Foam::BasicThermo<MixtureType, BasicThermoType>::volScalarFieldProperty
volScalarField& psi = tPsi.ref();
auto Yslicer = this->Yslicer();
forAll(psi, celli)
{
auto composition = this->cellComposition(celli);
auto composition = this->cellComposition(Yslicer, celli);
psi[celli] =
((this->*mixture)(composition).*psiMethod)(args[celli] ...);
@ -67,7 +69,8 @@ Foam::BasicThermo<MixtureType, BasicThermoType>::volScalarFieldProperty
{
forAll(psiBf[patchi], patchFacei)
{
auto composition = this->patchFaceComposition(patchi, patchFacei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, patchFacei);
psiBf[patchi][patchFacei] =
((this->*mixture)(composition).*psiMethod)
@ -98,9 +101,11 @@ Foam::BasicThermo<MixtureType, BasicThermoType>::cellSetProperty
tmp<scalarField> tPsi(new scalarField(cells.size()));
scalarField& psi = tPsi.ref();
auto Yslicer = this->Yslicer();
forAll(cells, celli)
{
auto composition = this->cellComposition(cells[celli]);
auto composition = this->cellComposition(Yslicer, cells[celli]);
psi[celli] =
((this->*mixture)(composition).*psiMethod)(args[celli] ...);
@ -127,9 +132,12 @@ Foam::BasicThermo<MixtureType, BasicThermoType>::patchFieldProperty
);
scalarField& psi = tPsi.ref();
auto Yslicer = this->Yslicer();
forAll(psi, patchFacei)
{
auto composition = this->patchFaceComposition(patchi, patchFacei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, patchFacei);
psi[patchFacei] =
((this->*mixture)(composition).*psiMethod)(args[patchFacei] ...);

View File

@ -40,9 +40,11 @@ void Foam::PsiThermo<BaseThermo>::calculate()
scalarField& muCells = this->mu_.primitiveFieldRef();
scalarField& kappaCells = this->kappa_.primitiveFieldRef();
auto Yslicer = this->Yslicer();
forAll(TCells, celli)
{
auto composition = this->cellComposition(celli);
auto composition = this->cellComposition(Yslicer, celli);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);
@ -106,7 +108,8 @@ void Foam::PsiThermo<BaseThermo>::calculate()
{
forAll(pT, facei)
{
auto composition = this->patchFaceComposition(patchi, facei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, facei);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);
@ -129,7 +132,8 @@ void Foam::PsiThermo<BaseThermo>::calculate()
{
forAll(pT, facei)
{
auto composition = this->patchFaceComposition(patchi, facei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, facei);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);

View File

@ -61,12 +61,20 @@ public:
// Member Functions
//- Get the slicer
inline nil Yslicer() const;
//- Get the composition of an internal cell
inline nil cellComposition(const label celli) const;
inline nil cellComposition
(
const nil,
const label celli
) const;
//- Get the composition of a boundary face
inline nil patchFaceComposition
(
const nil,
const label patchi,
const label facei
) const;

View File

@ -27,7 +27,17 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::nil Foam::pureThermo::cellComposition(const label celli) const
inline Foam::nil Foam::pureThermo::Yslicer() const
{
return nil();
}
inline Foam::nil Foam::pureThermo::cellComposition
(
const nil,
const label celli
) const
{
return nil();
}
@ -35,6 +45,7 @@ inline Foam::nil Foam::pureThermo::cellComposition(const label celli) const
inline Foam::nil Foam::pureThermo::patchFaceComposition
(
const nil,
const label patchi,
const label facei
) const

View File

@ -41,9 +41,11 @@ void Foam::RhoFluidThermo<BaseThermo>::calculate()
scalarField& muCells = this->mu_.primitiveFieldRef();
scalarField& kappaCells = this->kappa_.primitiveFieldRef();
auto Yslicer = this->Yslicer();
forAll(TCells, celli)
{
auto composition = this->cellComposition(celli);
auto composition = this->cellComposition(Yslicer, celli);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);
@ -112,7 +114,8 @@ void Foam::RhoFluidThermo<BaseThermo>::calculate()
{
forAll(pT, facei)
{
auto composition = this->patchFaceComposition(patchi, facei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, facei);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);
@ -136,7 +139,8 @@ void Foam::RhoFluidThermo<BaseThermo>::calculate()
{
forAll(pT, facei)
{
auto composition = this->patchFaceComposition(patchi, facei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, facei);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);

View File

@ -56,6 +56,7 @@ class GeometricFieldListSlicer
// Type of the geometric field
typedef GeometricField<Type, PatchField, GeoMesh> geoFieldType;
// Private Data
//- Pointers to the internal fields

View File

@ -90,8 +90,7 @@ Foam::multicomponentThermo::implementation::implementation
: -1
),
active_(species_.size(), true),
Y_(species_.size()),
Yslicer_()
Y_(species_.size())
{
if (species_.size() && defaultSpeciei_ == -1)
{
@ -203,8 +202,6 @@ Foam::multicomponentThermo::implementation::implementation
}
}
Yslicer_.set(Y_);
correctMassFractions();
}

View File

@ -294,9 +294,6 @@ protected:
//- Species mass fractions
PtrList<volScalarField> Y_;
//- Species mass fractions slicing engine
volScalarFieldListSlicer Yslicer_;
// Protected Member Functions
@ -339,12 +336,20 @@ public:
//- Access the mass-fraction fields
virtual const PtrList<volScalarField>& Y() const;
//- Get the slicer
inline volScalarFieldListSlicer Yslicer() const;
//- Get the composition of an internal cell
inline scalarFieldListSlice cellComposition(const label celli) const;
inline scalarFieldListSlice cellComposition
(
const volScalarFieldListSlicer& Yslicer,
const label celli
) const;
//- Get the composition of a boundary face
inline scalarFieldListSlice patchFaceComposition
(
const volScalarFieldListSlicer& Yslicer,
const label patchi,
const label facei
) const;

View File

@ -104,24 +104,33 @@ inline Foam::label Foam::multicomponentThermo::specieIndex
}
inline Foam::volScalarFieldListSlicer
Foam::multicomponentThermo::implementation::Yslicer() const
{
return volScalarFieldListSlicer(Y_);
}
inline Foam::scalarFieldListSlice
Foam::multicomponentThermo::implementation::cellComposition
(
const volScalarFieldListSlicer& Yslicer,
const label celli
) const
{
return Yslicer_.slice(celli);
return Yslicer.slice(celli);
}
inline Foam::scalarFieldListSlice
Foam::multicomponentThermo::implementation::patchFaceComposition
(
const volScalarFieldListSlicer& Yslicer,
const label patchi,
const label facei
) const
{
return Yslicer_.patchSlice(patchi, facei);
return Yslicer.patchSlice(patchi, facei);
}

View File

@ -44,9 +44,11 @@ void Foam::PsiuMulticomponentThermo<BaseThermo>::calculate()
scalarField& muCells = this->mu_.primitiveFieldRef();
scalarField& kappaCells = this->kappa_.primitiveFieldRef();
auto Yslicer = this->Yslicer();
forAll(TCells, celli)
{
auto composition = this->cellComposition(celli);
auto composition = this->cellComposition(Yslicer, celli);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);
@ -125,7 +127,8 @@ void Foam::PsiuMulticomponentThermo<BaseThermo>::calculate()
{
forAll(pT, facei)
{
auto composition = this->patchFaceComposition(patchi, facei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, facei);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);
@ -147,7 +150,8 @@ void Foam::PsiuMulticomponentThermo<BaseThermo>::calculate()
{
forAll(pT, facei)
{
auto composition = this->patchFaceComposition(patchi, facei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, facei);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);

View File

@ -112,8 +112,7 @@ Foam::psiuMulticomponentThermo::implementation::implementation
)
:
species_(specieNames),
Y_(species_.size()),
Yslicer_()
Y_(species_.size())
{
forAll(species_, i)
{
@ -134,8 +133,6 @@ Foam::psiuMulticomponentThermo::implementation::implementation
)
);
}
Yslicer_.set(Y_);
}

View File

@ -223,9 +223,6 @@ protected:
//- Species mass fractions
PtrList<volScalarField> Y_;
//- Species mass fractions slicing engine
volScalarFieldListSlicer Yslicer_;
public:
@ -256,12 +253,20 @@ public:
//- Access the mass-fraction fields
virtual const PtrList<volScalarField>& Y() const;
//- Get the slicer
inline volScalarFieldListSlicer Yslicer() const;
//- Get the composition of an internal cell
inline scalarFieldListSlice cellComposition(const label celli) const;
inline scalarFieldListSlice cellComposition
(
const volScalarFieldListSlicer& Yslicer,
const label celli
) const;
//- Get the composition of a boundary face
inline scalarFieldListSlice patchFaceComposition
(
const volScalarFieldListSlicer& Yslicer,
const label patchi,
const label facei
) const;

View File

@ -55,24 +55,33 @@ inline const Foam::volScalarField& Foam::psiuMulticomponentThermo::Y
}
inline Foam::volScalarFieldListSlicer
Foam::psiuMulticomponentThermo::implementation::Yslicer() const
{
return volScalarFieldListSlicer(Y_);
}
inline Foam::scalarFieldListSlice
Foam::psiuMulticomponentThermo::implementation::cellComposition
(
const volScalarFieldListSlicer& Yslicer,
const label celli
) const
{
return Yslicer_.slice(celli);
return Yslicer.slice(celli);
}
inline Foam::scalarFieldListSlice
Foam::psiuMulticomponentThermo::implementation::patchFaceComposition
(
const volScalarFieldListSlicer& Yslicer,
const label patchi,
const label facei
) const
{
return Yslicer_.patchSlice(patchi, facei);
return Yslicer.patchSlice(patchi, facei);
}

View File

@ -42,9 +42,11 @@ void Foam::SolidThermo<BaseThermo>::calculate()
scalarField& kappaCells = this->kappa_.primitiveFieldRef();
vectorField& KappaCells = this->Kappa_.primitiveFieldRef();
auto Yslicer = this->Yslicer();
forAll(TCells, celli)
{
auto composition = this->cellComposition(celli);
auto composition = this->cellComposition(Yslicer, celli);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);
@ -115,7 +117,8 @@ void Foam::SolidThermo<BaseThermo>::calculate()
{
forAll(pT, facei)
{
auto composition = this->patchFaceComposition(patchi, facei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, facei);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);
@ -146,7 +149,8 @@ void Foam::SolidThermo<BaseThermo>::calculate()
{
forAll(pT, facei)
{
auto composition = this->patchFaceComposition(patchi, facei);
auto composition =
this->patchFaceComposition(Yslicer, patchi, facei);
const typename BaseThermo::mixtureType::thermoMixtureType&
thermoMixture = this->thermoMixture(composition);