mappedFilmPressureFvPatchScalarField: New film BC to map the neighbouring fluid pressure to the film

mappedFilmPressureFvPatchScalarField is derived from the new mappedFvPatchField
base-class for mapped patch fields including mappedValueFvPatchField.

Class
    Foam::mappedFilmPressureFvPatchScalarField

Description
    Film pressure boundary condition which maps the neighbouring fluid patch
    pressure to both the surface patch and internal film pressure field.
This commit is contained in:
Henry Weller
2023-03-03 22:26:58 +00:00
parent 9df3600f11
commit 12decc028d
16 changed files with 817 additions and 206 deletions

View File

@ -18,6 +18,7 @@ patches/mappedFilmSurface/mappedFilmSurfaceFvPatch/mappedFilmSurfaceFvPatch.C
derivedFvPatchFields/alphaOne/alphaOneFvPatchScalarField.C
derivedFvPatchFields/filmContactAngle/filmContactAngleFvPatchScalarField.C
derivedFvPatchFields/mappedFilmPressure/mappedFilmPressureFvPatchScalarField.C
filmGaussGrad/filmGaussGrads.C

View File

@ -0,0 +1,145 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "mappedFilmPressureFvPatchScalarField.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::mappedFilmPressureFvPatchScalarField::mappedFilmPressureFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
zeroGradientFvPatchField<scalar>(p, iF),
mappedFvPatchField<scalar>(p, iF)
{}
Foam::mappedFilmPressureFvPatchScalarField::mappedFilmPressureFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
zeroGradientFvPatchField<scalar>(p, iF, dict),
mappedFvPatchField<scalar>(p, iF, dict)
{}
Foam::mappedFilmPressureFvPatchScalarField::mappedFilmPressureFvPatchScalarField
(
const mappedFilmPressureFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
zeroGradientFvPatchField<scalar>(ptf, p, iF, mapper),
mappedFvPatchField<scalar>(ptf, p, iF, mapper)
{}
Foam::mappedFilmPressureFvPatchScalarField::mappedFilmPressureFvPatchScalarField
(
const mappedFilmPressureFvPatchScalarField& ptf,
const DimensionedField<scalar, volMesh>& iF
)
:
zeroGradientFvPatchField<scalar>(ptf, iF),
mappedFvPatchField<scalar>(ptf, iF)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::mappedFilmPressureFvPatchScalarField::map
(
const fvPatchField<scalar>& ptf,
const fvPatchFieldMapper& mapper
)
{
zeroGradientFvPatchField<scalar>::map(ptf, mapper);
mappedFvPatchField<scalar>::clearOut();
}
void Foam::mappedFilmPressureFvPatchScalarField::reset
(
const fvPatchField<scalar>& ptf
)
{
zeroGradientFvPatchField<scalar>::reset(ptf);
mappedFvPatchField<scalar>::clearOut();
}
void Foam::mappedFilmPressureFvPatchScalarField::updateCoeffs()
{
if (this->updated())
{
return;
}
// Map the neighbouring fluid patch pressure field to this patch
this->operator==(this->mappedValues(this->nbrPatchField()));
// Map the patch pressure to the internal field
UIndirectList<scalar>
(
const_cast<Field<scalar>&>(this->primitiveField()),
this->patch().faceCells()
) = *this;
zeroGradientFvPatchField<scalar>::updateCoeffs();
}
void Foam::mappedFilmPressureFvPatchScalarField::write(Ostream& os) const
{
fvPatchField<scalar>::write(os);
mappedFvPatchField<scalar>::write(os);
writeEntry(os, "value", *this);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchScalarField,
mappedFilmPressureFvPatchScalarField
);
}
// ************************************************************************* //

View File

@ -0,0 +1,151 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::mappedFilmPressureFvPatchScalarField
Description
Film pressure boundary condition which maps the neighbouring fluid patch
pressure to both the surface patch and internal film pressure field.
SourceFiles
mappedFilmPressureFvPatchScalarField.C
\*---------------------------------------------------------------------------*/
#ifndef mappedFilmPressureFvPatchScalarField_H
#define mappedFilmPressureFvPatchScalarField_H
#include "zeroGradientFvPatchFields.H"
#include "mappedFvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class mappedFilmPressureFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class mappedFilmPressureFvPatchScalarField
:
public zeroGradientFvPatchField<scalar>,
public mappedFvPatchField<scalar>
{
public:
//- Runtime type information
TypeName("mappedFilmPressure");
// Constructors
//- Construct from patch and internal field
mappedFilmPressureFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&
);
//- Construct from patch, internal field and dictionary
mappedFilmPressureFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const dictionary&
);
//- Construct by mapping given mappedFilmPressureFvPatchScalarField
// onto a new patch
mappedFilmPressureFvPatchScalarField
(
const mappedFilmPressureFvPatchScalarField&,
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const fvPatchFieldMapper&
);
//- Disallow copy without setting internal field reference
mappedFilmPressureFvPatchScalarField
(
const mappedFilmPressureFvPatchScalarField&
) = delete;
//- Copy constructor setting internal field reference
mappedFilmPressureFvPatchScalarField
(
const mappedFilmPressureFvPatchScalarField&,
const DimensionedField<scalar, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchField<scalar>> clone
(
const DimensionedField<scalar, volMesh>& iF
) const
{
return tmp<fvPatchField<scalar>>
(
new mappedFilmPressureFvPatchScalarField(*this, iF)
);
}
// Member Functions
// Mapping functions
//- Map the given fvPatchField onto this fvPatchField
virtual void map
(
const fvPatchField<scalar>&,
const fvPatchFieldMapper&
);
//- Reset the fvPatchField to the given fvPatchField
// Used for mesh to mesh mapping
virtual void reset(const fvPatchField<scalar>&);
// Evaluation functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -240,6 +240,7 @@ Foam::solvers::isothermalFilm::isothermalFilm
thermo_(thermoPtr),
thermo(thermo_()),
p(thermo.p()),
rho(thermo.rho()),
nHat

View File

@ -98,6 +98,9 @@ protected:
//- Reference to the fluid thermophysical properties
fluidThermo& thermo;
//- The thermodynamic pressure field
volScalarField& p;
//- The thermodynamic density field
const volScalarField& rho;

View File

@ -66,13 +66,10 @@ Foam::solvers::isothermalFilm::pc(const volScalarField& sigma) const
Foam::tmp<Foam::volScalarField>
Foam::solvers::isothermalFilm::pe() const
{
// Currently there is no transfer of pressure from the adjacent fluid
return volScalarField::New
(
"pExternal",
mesh,
dimensionedScalar(dimPressure, 0)
);
// Update the pressure, mapping from the fluid region as required
p.correctBoundaryConditions();
return p;
}

View File

@ -192,6 +192,7 @@ $(derivedFvPatchFields)/inletOutlet/inletOutletFvPatchFields.C
$(derivedFvPatchFields)/inletOutletTotalTemperature/inletOutletTotalTemperatureFvPatchScalarField.C
$(derivedFvPatchFields)/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C
$(derivedFvPatchFields)/mappedInternalValue/mappedInternalValueFvPatchFields.C
$(derivedFvPatchFields)/mapped/mappedFvPatchFields.C
$(derivedFvPatchFields)/mappedValue/mappedValueFvPatchFields.C
$(derivedFvPatchFields)/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFields.C
$(derivedFvPatchFields)/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C

View File

@ -0,0 +1,247 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "mappedFvPatchField.H"
#include "mappedPolyPatch.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
const Foam::mappedPatchBase&
Foam::mappedFvPatchField<Type>::mapper() const
{
return
mapperPtr_.valid()
? mapperPtr_()
: mappedPatchBase::getMap(p_.patch());
}
template<class Type>
const Foam::fvPatchField<Type>&
Foam::mappedFvPatchField<Type>::nbrPatchField() const
{
const fvMesh& nbrMesh =
refCast<const fvMesh>(this->mapper().nbrMesh());
const VolField<Type>& nbrField =
this->mapper().sameRegion()
&& this->fieldName_ == iF_.name()
? refCast<const VolField<Type>>(iF_)
: nbrMesh.template lookupObject<VolField<Type>>(this->fieldName_);
const label nbrPatchi = this->mapper().nbrPolyPatch().index();
return nbrField.boundaryField()[nbrPatchi];
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::mappedFvPatchField<Type>::mappedValues
(
const Field<Type>& nbrPatchField
) const
{
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
// Map values
tmp<Field<Type>> tResult = this->mapper().distribute(nbrPatchField);
// Set the average, if necessary
if (setAverage_)
{
const Type nbrAverageValue =
gSum(p_.magSf()*tResult())
/gSum(p_.magSf());
if (mag(nbrAverageValue)/mag(average_) > 0.5)
{
tResult.ref() *= mag(average_)/mag(nbrAverageValue);
}
else
{
tResult.ref() += average_ - nbrAverageValue;
}
}
// Restore tag
UPstream::msgType() = oldTag;
return tResult;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::mappedFvPatchField<Type>::mappedFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF
)
:
p_(p),
iF_(iF),
fieldName_(iF.name()),
setAverage_(false),
average_(Zero),
mapperPtr_(nullptr)
{}
template<class Type>
Foam::mappedFvPatchField<Type>::mappedFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
)
:
p_(p),
iF_(iF),
fieldName_(dict.lookupOrDefault<word>("field", iF.name())),
setAverage_
(
dict.lookupOrDefault<bool>("setAverage", dict.found("average"))
),
average_(setAverage_ ? dict.lookup<Type>("average") : Zero),
mapperPtr_
(
mappedPatchBase::specified(dict)
? new mappedPatchBase(p.patch(), dict, false)
: nullptr
)
{
if (!mapperPtr_.valid() && !isA<mappedPatchBase>(p.patch()))
{
OStringStream str;
str << "Field " << iF.name() << " of type "
<< type() << " on patch " << p.patch().name()
<< " of type " << p.patch().type() << " does not "
<< "have mapping specified (i.e., neighbourPatch, and/or "
<< "neighbourRegion entries) nor is the patch of "
<< mappedPolyPatch::typeName << " type";
FatalIOErrorInFunction(dict)
<< stringOps::breakIntoIndentedLines(str.str()).c_str()
<< exit(FatalIOError);
}
this->mapper().validateForField
(
*this,
iF,
dict,
this->mapper().sameUntransformedPatch()
&& this->fieldName_ == iF.name()
? mappedPatchBase::from::differentPatch
: mappedPatchBase::from::any
);
}
template<class Type>
Foam::mappedFvPatchField<Type>::mappedFvPatchField
(
const mappedFvPatchField<Type>& ptf,
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
p_(p),
iF_(iF),
fieldName_(ptf.fieldName_),
setAverage_(ptf.setAverage_),
average_(ptf.average_),
mapperPtr_
(
ptf.mapperPtr_.valid()
? new mappedPatchBase(p.patch(), ptf.mapperPtr_())
: nullptr
)
{}
template<class Type>
Foam::mappedFvPatchField<Type>::mappedFvPatchField
(
const mappedFvPatchField<Type>& ptf,
const DimensionedField<Type, volMesh>& iF
)
:
p_(ptf.p_),
iF_(iF),
fieldName_(ptf.fieldName_),
setAverage_(ptf.setAverage_),
average_(ptf.average_),
mapperPtr_
(
ptf.mapperPtr_.valid()
? new mappedPatchBase(ptf.p_.patch(), ptf.mapperPtr_())
: nullptr
)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::mappedFvPatchField<Type>::clearOut()
{
if (mapperPtr_.valid())
{
mapperPtr_->clearOut();
}
}
template<class Type>
void Foam::mappedFvPatchField<Type>::write(Ostream& os) const
{
writeEntryIfDifferent
(
os,
"field",
iF_.name(),
fieldName_
);
if (setAverage_)
{
writeEntry(os, "average", average_);
}
if (mapperPtr_.valid())
{
mapperPtr_->write(os);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,187 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::mappedFvPatchField
Description
Base class for mapped patch fields
Usage
\table
Property | Description | Required | Default value
field | name of field to be mapped | no | this field name
setAverage | set the average value? | no | yes if average \\
is specified, \\
no otherwise
average | average value to apply | if setAverage is true |
\endtable
This boundary condition will usually be applied to a patch which is of
mappedPatchBase type, and which holds all the necessary mapping
information. It can also create its own mapping data which overrides that
in the mapped patch, or so that it can be applied to a non-mapped patch.
This is triggered by the presence of controls relating to mappedPatchBase
(i.e., neighbourRegion, neighbourPatch, etc ...).
See also
Foam::mappedValueFvPatchField
Foam::mappedPatchBase
Foam::mappedPolyPatch
Foam::mappedFvPatch
SourceFiles
mappedFvPatchField.C
\*---------------------------------------------------------------------------*/
#ifndef mappedFvPatchField_H
#define mappedFvPatchField_H
#include "mappedPatchBase.H"
#include "fvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class mappedFvPatchField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class mappedFvPatchField
{
protected:
// Protected Member Data
//- Reference to the patch
const fvPatch& p_;
//- Reference to the internal field
const DimensionedField<Type, volMesh>& iF_;
//- The field to map
const word fieldName_;
//- If true adjust the sampled field to maintain an average value
const bool setAverage_;
//- Average value the sampled field is adjusted to
const Type average_;
//- The mapping engine
autoPtr<mappedPatchBase> mapperPtr_;
// Protected Member Functions
//- Return the mapping engine
const mappedPatchBase& mapper() const;
//- Return the neighbouring patch field
const fvPatchField<Type>& nbrPatchField() const;
//- Return the mapped values, given the neighbouring field
tmp<Field<Type>> mappedValues(const Field<Type>& nbrPatchField) const;
public:
//- Runtime type information
TypeName("mappedValue");
// Constructors
//- Construct from patch and internal field
mappedFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&
);
//- Construct from patch, internal field and dictionary
mappedFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const dictionary&
);
//- Construct by mapping given mappedFvPatchField
// onto a new patch
mappedFvPatchField
(
const mappedFvPatchField<Type>&,
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const fvPatchFieldMapper&
);
//- Disallow copy without setting internal field reference
mappedFvPatchField
(
const mappedFvPatchField<Type>&
) = delete;
//- Copy constructor setting internal field reference
mappedFvPatchField
(
const mappedFvPatchField<Type>&,
const DimensionedField<Type, volMesh>&
);
//- Destructor
virtual ~mappedFvPatchField()
{}
// Member Functions
//- Clear the mapper if present
virtual void clearOut();
//- Write
virtual void write(Ostream&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "mappedFvPatchField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "mappedFvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchTypeFieldTypedefs(mapped);
makePatchFieldTypeNames(mapped);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -62,6 +62,7 @@ mappedFlowRateVelocityFvPatchVectorField
mappedPatchBase::validateMapForField
(
*this,
iF,
dict,
mappedPatchBase::from::differentPatch
);

View File

@ -27,77 +27,6 @@ License
#include "mappedPolyPatch.H"
#include "volFields.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
const Foam::mappedPatchBase&
Foam::mappedValueFvPatchField<Type>::mapper() const
{
return
mapperPtr_.valid()
? mapperPtr_()
: mappedPatchBase::getMap(this->patch().patch());
}
template<class Type>
const Foam::fvPatchField<Type>&
Foam::mappedValueFvPatchField<Type>::nbrPatchField() const
{
const fvMesh& nbrMesh =
refCast<const fvMesh>(this->mapper().nbrMesh());
const VolField<Type>& nbrField =
this->mapper().sameRegion()
&& this->fieldName_ == this->internalField().name()
? refCast<const VolField<Type>>(this->internalField())
: nbrMesh.template lookupObject<VolField<Type>>(this->fieldName_);
const label nbrPatchi = this->mapper().nbrPolyPatch().index();
return nbrField.boundaryField()[nbrPatchi];
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::mappedValueFvPatchField<Type>::mappedValues
(
const Field<Type>& nbrPatchField
) const
{
// Since we're inside initEvaluate/evaluate there might be processor
// comms underway. Change the tag we use.
int oldTag = UPstream::msgType();
UPstream::msgType() = oldTag + 1;
// Map values
tmp<Field<Type>> tResult = this->mapper().distribute(nbrPatchField);
// Set the average, if necessary
if (setAverage_)
{
const Type nbrAverageValue =
gSum(this->patch().magSf()*tResult())
/gSum(this->patch().magSf());
if (mag(nbrAverageValue)/mag(average_) > 0.5)
{
tResult.ref() *= mag(average_)/mag(nbrAverageValue);
}
else
{
tResult.ref() += average_ - nbrAverageValue;
}
}
// Restore tag
UPstream::msgType() = oldTag;
return tResult;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
@ -108,10 +37,7 @@ Foam::mappedValueFvPatchField<Type>::mappedValueFvPatchField
)
:
fixedValueFvPatchField<Type>(p, iF),
fieldName_(iF.name()),
setAverage_(false),
average_(Zero),
mapperPtr_(nullptr)
mappedFvPatchField<Type>(p, iF)
{}
@ -124,43 +50,8 @@ Foam::mappedValueFvPatchField<Type>::mappedValueFvPatchField
)
:
fixedValueFvPatchField<Type>(p, iF, dict),
fieldName_(dict.lookupOrDefault<word>("field", iF.name())),
setAverage_
(
dict.lookupOrDefault<bool>("setAverage", dict.found("average"))
),
average_(setAverage_ ? dict.lookup<Type>("average") : Zero),
mapperPtr_
(
mappedPatchBase::specified(dict)
? new mappedPatchBase(p.patch(), dict, false)
: nullptr
)
{
if (!mapperPtr_.valid() && !isA<mappedPatchBase>(p.patch()))
{
OStringStream str;
str << "Field " << this->internalField().name() << " of type "
<< type() << " on patch " << this->patch().name()
<< " of type " << p.patch().type() << " does not "
<< "have mapping specified (i.e., neighbourPatch, and/or "
<< "neighbourRegion entries) nor is the patch of "
<< mappedPolyPatch::typeName << " type";
FatalIOErrorInFunction(dict)
<< stringOps::breakIntoIndentedLines(str.str()).c_str()
<< exit(FatalIOError);
}
this->mapper().validateForField
(
*this,
dict,
this->mapper().sameUntransformedPatch()
&& this->fieldName_ == this->internalField().name()
? mappedPatchBase::from::differentPatch
: mappedPatchBase::from::any
);
}
mappedFvPatchField<Type>(p, iF, dict)
{}
template<class Type>
@ -173,15 +64,7 @@ Foam::mappedValueFvPatchField<Type>::mappedValueFvPatchField
)
:
fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
fieldName_(ptf.fieldName_),
setAverage_(ptf.setAverage_),
average_(ptf.average_),
mapperPtr_
(
ptf.mapperPtr_.valid()
? new mappedPatchBase(p.patch(), ptf.mapperPtr_())
: nullptr
)
mappedFvPatchField<Type>(ptf, p, iF, mapper)
{}
@ -193,15 +76,7 @@ Foam::mappedValueFvPatchField<Type>::mappedValueFvPatchField
)
:
fixedValueFvPatchField<Type>(ptf, iF),
fieldName_(ptf.fieldName_),
setAverage_(ptf.setAverage_),
average_(ptf.average_),
mapperPtr_
(
ptf.mapperPtr_.valid()
? new mappedPatchBase(ptf.patch().patch(), ptf.mapperPtr_())
: nullptr
)
mappedFvPatchField<Type>(ptf, iF)
{}
@ -215,11 +90,7 @@ void Foam::mappedValueFvPatchField<Type>::map
)
{
fixedValueFvPatchField<Type>::map(ptf, mapper);
if (mapperPtr_.valid())
{
mapperPtr_->clearOut();
}
mappedFvPatchField<Type>::clearOut();
}
@ -230,11 +101,7 @@ void Foam::mappedValueFvPatchField<Type>::reset
)
{
fixedValueFvPatchField<Type>::reset(ptf);
if (mapperPtr_.valid())
{
mapperPtr_->clearOut();
}
mappedFvPatchField<Type>::clearOut();
}
@ -246,7 +113,7 @@ void Foam::mappedValueFvPatchField<Type>::updateCoeffs()
return;
}
this->operator==(mappedValues(nbrPatchField()));
this->operator==(this->mappedValues(this->nbrPatchField()));
fixedValueFvPatchField<Type>::updateCoeffs();
}
@ -257,23 +124,7 @@ void Foam::mappedValueFvPatchField<Type>::write(Ostream& os) const
{
fvPatchField<Type>::write(os);
writeEntryIfDifferent
(
os,
"field",
this->internalField().name(),
fieldName_
);
if (setAverage_)
{
writeEntry(os, "average", average_);
}
if (mapperPtr_.valid())
{
mapperPtr_->write(os);
}
mappedFvPatchField<Type>::write(os);
writeEntry(os, "value", *this);
}

View File

@ -71,7 +71,7 @@ SourceFiles
#define mappedValueFvPatchField_H
#include "fixedValueFvPatchFields.H"
#include "mappedPatchBase.H"
#include "mappedFvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -85,36 +85,9 @@ namespace Foam
template<class Type>
class mappedValueFvPatchField
:
public fixedValueFvPatchField<Type>
public fixedValueFvPatchField<Type>,
public mappedFvPatchField<Type>
{
protected:
// Protected Member Data
//- The field to map
const word fieldName_;
//- If true adjust the sampled field to maintain an average value
const bool setAverage_;
//- Average value the sampled field is adjusted to
const Type average_;
//- The mapping engine
autoPtr<mappedPatchBase> mapperPtr_;
// Protected Member Functions
//- Return the mapping engine
const mappedPatchBase& mapper() const;
//- Return the neighbouring patch field
const fvPatchField<Type>& nbrPatchField() const;
//- Return the mapped values, given the neighbouring field
tmp<Field<Type>> mappedValues(const Field<Type>& nbrPatchField) const;
public:

View File

@ -56,6 +56,7 @@ Foam::mappedVelocityFluxFvPatchField::mappedVelocityFluxFvPatchField
mappedPatchBase::validateMapForField
(
*this,
iF,
dict,
mappedPatchBase::from::differentPatch
);

View File

@ -220,20 +220,22 @@ public:
//- Validate that the map exists and is appropriate for the given
// set of permitted configurations
template<class PatchField>
template<class PatchFieldType, class FieldType>
static void validateMapForField
(
const PatchField& field,
const PatchFieldType& field,
const FieldType& iF,
const dictionary& context,
const label froms = from::any
);
//- Validate that the map is appropriate for the given
// set of permitted configurations
template<class PatchField>
template<class PatchFieldType, class FieldType>
void validateForField
(
const PatchField& field,
const PatchFieldType& field,
const FieldType& iF,
const dictionary& context,
const label froms = from::any
) const;

View File

@ -28,10 +28,11 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class PatchField>
template<class PatchFieldType, class FieldType>
void Foam::mappedPatchBase::validateMapForField
(
const PatchField& field,
const PatchFieldType& field,
const FieldType& iF,
const dictionary& context,
const label froms
)
@ -41,7 +42,7 @@ void Foam::mappedPatchBase::validateMapForField
if (!isA<mappedPatchBase>(pp))
{
OStringStream str;
str << "Field " << field.internalField().name() << " of type "
str << "Field " << iF.name() << " of type "
<< field.type() << " cannot apply to patch " << pp.name()
<< " because the patch is not of " << typeName << " type";
FatalIOErrorInFunction(context)
@ -49,14 +50,21 @@ void Foam::mappedPatchBase::validateMapForField
<< exit(FatalIOError);
}
refCast<const mappedPatchBase>(pp).validateForField(field, context, froms);
refCast<const mappedPatchBase>(pp).validateForField
(
field,
iF,
context,
froms
);
}
template<class PatchField>
template<class PatchFieldType, class FieldType>
void Foam::mappedPatchBase::validateForField
(
const PatchField& field,
const PatchFieldType& field,
const FieldType& iF,
const dictionary& context,
const label froms
) const
@ -69,7 +77,7 @@ void Foam::mappedPatchBase::validateForField
if (isNotRegion || isRegion || isPatch)
{
str << "Field " << field.internalField().name() << " of type "
str << "Field " << iF.name() << " of type "
<< field.type() << " cannot apply to patch " << patch_.name()
<< " because values are mapped from ";
}