diff --git a/applications/solvers/modules/isothermalFilm/Make/files b/applications/solvers/modules/isothermalFilm/Make/files index 0fca0c8400..a0ae4a33dd 100644 --- a/applications/solvers/modules/isothermalFilm/Make/files +++ b/applications/solvers/modules/isothermalFilm/Make/files @@ -18,6 +18,7 @@ patches/mappedFilmSurface/mappedFilmSurfaceFvPatch/mappedFilmSurfaceFvPatch.C derivedFvPatchFields/alphaOne/alphaOneFvPatchScalarField.C derivedFvPatchFields/filmContactAngle/filmContactAngleFvPatchScalarField.C +derivedFvPatchFields/mappedFilmPressure/mappedFilmPressureFvPatchScalarField.C filmGaussGrad/filmGaussGrads.C diff --git a/applications/solvers/modules/isothermalFilm/derivedFvPatchFields/mappedFilmPressure/mappedFilmPressureFvPatchScalarField.C b/applications/solvers/modules/isothermalFilm/derivedFvPatchFields/mappedFilmPressure/mappedFilmPressureFvPatchScalarField.C new file mode 100644 index 0000000000..c87dde60a9 --- /dev/null +++ b/applications/solvers/modules/isothermalFilm/derivedFvPatchFields/mappedFilmPressure/mappedFilmPressureFvPatchScalarField.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "mappedFilmPressureFvPatchScalarField.H" +#include "volFields.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::mappedFilmPressureFvPatchScalarField::mappedFilmPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF +) +: + zeroGradientFvPatchField(p, iF), + mappedFvPatchField(p, iF) +{} + + +Foam::mappedFilmPressureFvPatchScalarField::mappedFilmPressureFvPatchScalarField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + zeroGradientFvPatchField(p, iF, dict), + mappedFvPatchField(p, iF, dict) +{} + + +Foam::mappedFilmPressureFvPatchScalarField::mappedFilmPressureFvPatchScalarField +( + const mappedFilmPressureFvPatchScalarField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + zeroGradientFvPatchField(ptf, p, iF, mapper), + mappedFvPatchField(ptf, p, iF, mapper) +{} + + +Foam::mappedFilmPressureFvPatchScalarField::mappedFilmPressureFvPatchScalarField +( + const mappedFilmPressureFvPatchScalarField& ptf, + const DimensionedField& iF +) +: + zeroGradientFvPatchField(ptf, iF), + mappedFvPatchField(ptf, iF) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::mappedFilmPressureFvPatchScalarField::map +( + const fvPatchField& ptf, + const fvPatchFieldMapper& mapper +) +{ + zeroGradientFvPatchField::map(ptf, mapper); + mappedFvPatchField::clearOut(); +} + + +void Foam::mappedFilmPressureFvPatchScalarField::reset +( + const fvPatchField& ptf +) +{ + zeroGradientFvPatchField::reset(ptf); + mappedFvPatchField::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 + ( + const_cast&>(this->primitiveField()), + this->patch().faceCells() + ) = *this; + + zeroGradientFvPatchField::updateCoeffs(); +} + + +void Foam::mappedFilmPressureFvPatchScalarField::write(Ostream& os) const +{ + fvPatchField::write(os); + + mappedFvPatchField::write(os); + + writeEntry(os, "value", *this); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makePatchTypeField + ( + fvPatchScalarField, + mappedFilmPressureFvPatchScalarField + ); +} + + +// ************************************************************************* // diff --git a/applications/solvers/modules/isothermalFilm/derivedFvPatchFields/mappedFilmPressure/mappedFilmPressureFvPatchScalarField.H b/applications/solvers/modules/isothermalFilm/derivedFvPatchFields/mappedFilmPressure/mappedFilmPressureFvPatchScalarField.H new file mode 100644 index 0000000000..990d075ead --- /dev/null +++ b/applications/solvers/modules/isothermalFilm/derivedFvPatchFields/mappedFilmPressure/mappedFilmPressureFvPatchScalarField.H @@ -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 . + +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, + public mappedFvPatchField +{ + +public: + + //- Runtime type information + TypeName("mappedFilmPressure"); + + + // Constructors + + //- Construct from patch and internal field + mappedFilmPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + mappedFilmPressureFvPatchScalarField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given mappedFilmPressureFvPatchScalarField + // onto a new patch + mappedFilmPressureFvPatchScalarField + ( + const mappedFilmPressureFvPatchScalarField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Disallow copy without setting internal field reference + mappedFilmPressureFvPatchScalarField + ( + const mappedFilmPressureFvPatchScalarField& + ) = delete; + + //- Copy constructor setting internal field reference + mappedFilmPressureFvPatchScalarField + ( + const mappedFilmPressureFvPatchScalarField&, + const DimensionedField& + ); + + //- Construct and return a clone setting internal field reference + virtual tmp> clone + ( + const DimensionedField& iF + ) const + { + return tmp> + ( + new mappedFilmPressureFvPatchScalarField(*this, iF) + ); + } + + + // Member Functions + + // Mapping functions + + //- Map the given fvPatchField onto this fvPatchField + virtual void map + ( + const fvPatchField&, + const fvPatchFieldMapper& + ); + + //- Reset the fvPatchField to the given fvPatchField + // Used for mesh to mesh mapping + virtual void reset(const fvPatchField&); + + + // Evaluation functions + + //- Update the coefficients associated with the patch field + virtual void updateCoeffs(); + + + //- Write + virtual void write(Ostream&) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/applications/solvers/modules/isothermalFilm/isothermalFilm.C b/applications/solvers/modules/isothermalFilm/isothermalFilm.C index ecccf27e3f..06fe7642ac 100644 --- a/applications/solvers/modules/isothermalFilm/isothermalFilm.C +++ b/applications/solvers/modules/isothermalFilm/isothermalFilm.C @@ -240,6 +240,7 @@ Foam::solvers::isothermalFilm::isothermalFilm thermo_(thermoPtr), thermo(thermo_()), + p(thermo.p()), rho(thermo.rho()), nHat diff --git a/applications/solvers/modules/isothermalFilm/isothermalFilm.H b/applications/solvers/modules/isothermalFilm/isothermalFilm.H index b2bbded17d..861ad3943b 100644 --- a/applications/solvers/modules/isothermalFilm/isothermalFilm.H +++ b/applications/solvers/modules/isothermalFilm/isothermalFilm.H @@ -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; diff --git a/applications/solvers/modules/isothermalFilm/momentumPredictor.C b/applications/solvers/modules/isothermalFilm/momentumPredictor.C index 4930112214..7cd6f16afa 100644 --- a/applications/solvers/modules/isothermalFilm/momentumPredictor.C +++ b/applications/solvers/modules/isothermalFilm/momentumPredictor.C @@ -66,13 +66,10 @@ Foam::solvers::isothermalFilm::pc(const volScalarField& sigma) const Foam::tmp 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; } diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index b0d8605d1c..849f4d7170 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -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 diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchField.C new file mode 100644 index 0000000000..a3960ec62e --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchField.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "mappedFvPatchField.H" +#include "mappedPolyPatch.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +const Foam::mappedPatchBase& +Foam::mappedFvPatchField::mapper() const +{ + return + mapperPtr_.valid() + ? mapperPtr_() + : mappedPatchBase::getMap(p_.patch()); +} + + +template +const Foam::fvPatchField& +Foam::mappedFvPatchField::nbrPatchField() const +{ + const fvMesh& nbrMesh = + refCast(this->mapper().nbrMesh()); + + const VolField& nbrField = + this->mapper().sameRegion() + && this->fieldName_ == iF_.name() + ? refCast>(iF_) + : nbrMesh.template lookupObject>(this->fieldName_); + + const label nbrPatchi = this->mapper().nbrPolyPatch().index(); + + return nbrField.boundaryField()[nbrPatchi]; +} + + +template +Foam::tmp> +Foam::mappedFvPatchField::mappedValues +( + const Field& 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> 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 +Foam::mappedFvPatchField::mappedFvPatchField +( + const fvPatch& p, + const DimensionedField& iF +) +: + p_(p), + iF_(iF), + fieldName_(iF.name()), + setAverage_(false), + average_(Zero), + mapperPtr_(nullptr) +{} + + +template +Foam::mappedFvPatchField::mappedFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + p_(p), + iF_(iF), + fieldName_(dict.lookupOrDefault("field", iF.name())), + setAverage_ + ( + dict.lookupOrDefault("setAverage", dict.found("average")) + ), + average_(setAverage_ ? dict.lookup("average") : Zero), + mapperPtr_ + ( + mappedPatchBase::specified(dict) + ? new mappedPatchBase(p.patch(), dict, false) + : nullptr + ) +{ + if (!mapperPtr_.valid() && !isA(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 +Foam::mappedFvPatchField::mappedFvPatchField +( + const mappedFvPatchField& ptf, + const fvPatch& p, + const DimensionedField& 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 +Foam::mappedFvPatchField::mappedFvPatchField +( + const mappedFvPatchField& ptf, + const DimensionedField& 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 +void Foam::mappedFvPatchField::clearOut() +{ + if (mapperPtr_.valid()) + { + mapperPtr_->clearOut(); + } +} + + +template +void Foam::mappedFvPatchField::write(Ostream& os) const +{ + writeEntryIfDifferent + ( + os, + "field", + iF_.name(), + fieldName_ + ); + + if (setAverage_) + { + writeEntry(os, "average", average_); + } + + if (mapperPtr_.valid()) + { + mapperPtr_->write(os); + } +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchField.H new file mode 100644 index 0000000000..49b2065b3c --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchField.H @@ -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 . + +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 mappedFvPatchField +{ +protected: + + // Protected Member Data + + //- Reference to the patch + const fvPatch& p_; + + //- Reference to the internal field + const DimensionedField& 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 mapperPtr_; + + + // Protected Member Functions + + //- Return the mapping engine + const mappedPatchBase& mapper() const; + + //- Return the neighbouring patch field + const fvPatchField& nbrPatchField() const; + + //- Return the mapped values, given the neighbouring field + tmp> mappedValues(const Field& nbrPatchField) const; + + +public: + + //- Runtime type information + TypeName("mappedValue"); + + + // Constructors + + //- Construct from patch and internal field + mappedFvPatchField + ( + const fvPatch&, + const DimensionedField& + ); + + //- Construct from patch, internal field and dictionary + mappedFvPatchField + ( + const fvPatch&, + const DimensionedField&, + const dictionary& + ); + + //- Construct by mapping given mappedFvPatchField + // onto a new patch + mappedFvPatchField + ( + const mappedFvPatchField&, + const fvPatch&, + const DimensionedField&, + const fvPatchFieldMapper& + ); + + //- Disallow copy without setting internal field reference + mappedFvPatchField + ( + const mappedFvPatchField& + ) = delete; + + //- Copy constructor setting internal field reference + mappedFvPatchField + ( + const mappedFvPatchField&, + const DimensionedField& + ); + + + //- 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 + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchFields.C new file mode 100644 index 0000000000..11631da450 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/mapped/mappedFvPatchFields.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "mappedFvPatchField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +makePatchTypeFieldTypedefs(mapped); +makePatchFieldTypeNames(mapped); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C index f1f205da9c..6577aaa58b 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C @@ -62,6 +62,7 @@ mappedFlowRateVelocityFvPatchVectorField mappedPatchBase::validateMapForField ( *this, + iF, dict, mappedPatchBase::from::differentPatch ); diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.C index 1067f88470..610610ae0f 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.C @@ -27,77 +27,6 @@ License #include "mappedPolyPatch.H" #include "volFields.H" -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -template -const Foam::mappedPatchBase& -Foam::mappedValueFvPatchField::mapper() const -{ - return - mapperPtr_.valid() - ? mapperPtr_() - : mappedPatchBase::getMap(this->patch().patch()); -} - - -template -const Foam::fvPatchField& -Foam::mappedValueFvPatchField::nbrPatchField() const -{ - const fvMesh& nbrMesh = - refCast(this->mapper().nbrMesh()); - - const VolField& nbrField = - this->mapper().sameRegion() - && this->fieldName_ == this->internalField().name() - ? refCast>(this->internalField()) - : nbrMesh.template lookupObject>(this->fieldName_); - - const label nbrPatchi = this->mapper().nbrPolyPatch().index(); - - return nbrField.boundaryField()[nbrPatchi]; -} - - -template -Foam::tmp> -Foam::mappedValueFvPatchField::mappedValues -( - const Field& 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> 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 @@ -108,10 +37,7 @@ Foam::mappedValueFvPatchField::mappedValueFvPatchField ) : fixedValueFvPatchField(p, iF), - fieldName_(iF.name()), - setAverage_(false), - average_(Zero), - mapperPtr_(nullptr) + mappedFvPatchField(p, iF) {} @@ -124,43 +50,8 @@ Foam::mappedValueFvPatchField::mappedValueFvPatchField ) : fixedValueFvPatchField(p, iF, dict), - fieldName_(dict.lookupOrDefault("field", iF.name())), - setAverage_ - ( - dict.lookupOrDefault("setAverage", dict.found("average")) - ), - average_(setAverage_ ? dict.lookup("average") : Zero), - mapperPtr_ - ( - mappedPatchBase::specified(dict) - ? new mappedPatchBase(p.patch(), dict, false) - : nullptr - ) -{ - if (!mapperPtr_.valid() && !isA(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(p, iF, dict) +{} template @@ -173,15 +64,7 @@ Foam::mappedValueFvPatchField::mappedValueFvPatchField ) : fixedValueFvPatchField(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(ptf, p, iF, mapper) {} @@ -193,15 +76,7 @@ Foam::mappedValueFvPatchField::mappedValueFvPatchField ) : fixedValueFvPatchField(ptf, iF), - fieldName_(ptf.fieldName_), - setAverage_(ptf.setAverage_), - average_(ptf.average_), - mapperPtr_ - ( - ptf.mapperPtr_.valid() - ? new mappedPatchBase(ptf.patch().patch(), ptf.mapperPtr_()) - : nullptr - ) + mappedFvPatchField(ptf, iF) {} @@ -215,11 +90,7 @@ void Foam::mappedValueFvPatchField::map ) { fixedValueFvPatchField::map(ptf, mapper); - - if (mapperPtr_.valid()) - { - mapperPtr_->clearOut(); - } + mappedFvPatchField::clearOut(); } @@ -230,11 +101,7 @@ void Foam::mappedValueFvPatchField::reset ) { fixedValueFvPatchField::reset(ptf); - - if (mapperPtr_.valid()) - { - mapperPtr_->clearOut(); - } + mappedFvPatchField::clearOut(); } @@ -246,7 +113,7 @@ void Foam::mappedValueFvPatchField::updateCoeffs() return; } - this->operator==(mappedValues(nbrPatchField())); + this->operator==(this->mappedValues(this->nbrPatchField())); fixedValueFvPatchField::updateCoeffs(); } @@ -257,23 +124,7 @@ void Foam::mappedValueFvPatchField::write(Ostream& os) const { fvPatchField::write(os); - writeEntryIfDifferent - ( - os, - "field", - this->internalField().name(), - fieldName_ - ); - - if (setAverage_) - { - writeEntry(os, "average", average_); - } - - if (mapperPtr_.valid()) - { - mapperPtr_->write(os); - } + mappedFvPatchField::write(os); writeEntry(os, "value", *this); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.H index 41ce46cdca..4e16a296cd 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.H @@ -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 mappedValueFvPatchField : - public fixedValueFvPatchField + public fixedValueFvPatchField, + public mappedFvPatchField { -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 mapperPtr_; - - - // Protected Member Functions - - //- Return the mapping engine - const mappedPatchBase& mapper() const; - - //- Return the neighbouring patch field - const fvPatchField& nbrPatchField() const; - - //- Return the mapped values, given the neighbouring field - tmp> mappedValues(const Field& nbrPatchField) const; - public: diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C index 5a63c5ed3c..1b052e0828 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C @@ -56,6 +56,7 @@ Foam::mappedVelocityFluxFvPatchField::mappedVelocityFluxFvPatchField mappedPatchBase::validateMapForField ( *this, + iF, dict, mappedPatchBase::from::differentPatch ); diff --git a/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.H b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.H index 12bf86c05f..0e6f7b39c9 100644 --- a/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.H +++ b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBase.H @@ -220,20 +220,22 @@ public: //- Validate that the map exists and is appropriate for the given // set of permitted configurations - template + template 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 + template void validateForField ( - const PatchField& field, + const PatchFieldType& field, + const FieldType& iF, const dictionary& context, const label froms = from::any ) const; diff --git a/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseTemplates.C b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseTemplates.C index 6254c23ff1..bd246f7655 100644 --- a/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseTemplates.C +++ b/src/meshTools/mappedPatches/mappedPatchBase/mappedPatchBaseTemplates.C @@ -28,10 +28,11 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template +template 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(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(pp).validateForField(field, context, froms); + refCast(pp).validateForField + ( + field, + iF, + context, + froms + ); } -template +template 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 "; }