diff --git a/applications/utilities/mesh/generation/extrudeToRegionMesh/extrudeToRegionMesh.C b/applications/utilities/mesh/generation/extrudeToRegionMesh/extrudeToRegionMesh.C index 334b481dce..db5f41543a 100644 --- a/applications/utilities/mesh/generation/extrudeToRegionMesh/extrudeToRegionMesh.C +++ b/applications/utilities/mesh/generation/extrudeToRegionMesh/extrudeToRegionMesh.C @@ -646,7 +646,7 @@ void addCouplingPatches const fvMesh& mesh, const bool isShellMesh, const word& regionName, - const word& sampleRegionName, + const word& nbrRegionName, const wordList& zoneNames, const wordList& zoneShadowNames, const boolList& zoneIsInternal, @@ -664,48 +664,42 @@ void addCouplingPatches zoneBottomPatch.setSize(zoneNames.size(), -1); dictionary patchDict; - patchDict.add - ( - "sampleMode", - mappedPatchBase::sampleModeNames_[mappedPatchBase::NEARESTPATCHFACE] - ); - patchDict.add("sampleRegion", sampleRegionName); + patchDict.add("neighbourRegion", nbrRegionName); label nOldPatches = newPatches.size(); forAll(zoneNames, zonei) { const word patchNamePrefix = - regionName + "_to_" + sampleRegionName + '_'; - const word samplePatchNamePrefix = - sampleRegionName + "_to_" + regionName + '_'; + regionName + "_to_" + nbrRegionName + '_'; + const word nbrPatchNamePrefix = + nbrRegionName + "_to_" + regionName + '_'; - word bottomPatchName, bottomSamplePatchName; - word topPatchName, topSamplePatchName; + word bottomPatchName, bottomNbrPatchName; + word topPatchName, topNbrPatchName; if (zoneIsInternal[zonei]) { bottomPatchName = patchNamePrefix + zoneNames[zonei] + "_bottom"; - bottomSamplePatchName = - samplePatchNamePrefix + zoneNames[zonei] + "_bottom"; + bottomNbrPatchName = + nbrPatchNamePrefix + zoneNames[zonei] + "_bottom"; topPatchName = patchNamePrefix + zoneNames[zonei] + "_top"; - topSamplePatchName = - samplePatchNamePrefix + zoneNames[zonei] + "_top"; + topNbrPatchName = nbrPatchNamePrefix + zoneNames[zonei] + "_top"; } else if (!zoneShadowNames[zonei].empty()) { bottomPatchName = patchNamePrefix + zoneNames[zonei]; - bottomSamplePatchName = samplePatchNamePrefix + zoneNames[zonei]; + bottomNbrPatchName = nbrPatchNamePrefix + zoneNames[zonei]; topPatchName = patchNamePrefix + zoneShadowNames[zonei]; - topSamplePatchName = samplePatchNamePrefix + zoneShadowNames[zonei]; + topNbrPatchName = nbrPatchNamePrefix + zoneShadowNames[zonei]; } else { bottomPatchName = patchNamePrefix + zoneNames[zonei]; - bottomSamplePatchName = samplePatchNamePrefix + zoneNames[zonei]; + bottomNbrPatchName = nbrPatchNamePrefix + zoneNames[zonei]; topPatchName = zoneNames[zonei] + "_top"; } dictionary bottomPatchDict(patchDict); - bottomPatchDict.add("samplePatch", bottomSamplePatchName); + bottomPatchDict.add("neighbourPatch", bottomNbrPatchName); zoneBottomPatch[zonei] = addPatch @@ -724,7 +718,7 @@ void addCouplingPatches if (zoneIsInternal[zonei] || !zoneShadowNames[zonei].empty()) { dictionary topPatchDict(patchDict); - topPatchDict.add("samplePatch", topSamplePatchName); + topPatchDict.add("neighbourPatch", topNbrPatchName); if (isShellMesh) { topPatchDict.add("bottomPatch", bottomPatchName); diff --git a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C index 49d7c8fbf4..430f43be01 100644 --- a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C +++ b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C @@ -1038,9 +1038,8 @@ labelList addRegionPatches 0, // overridden 0, // overridden 0, // overridden - regionNames[e[1]], // sampleRegion - mappedPatchBase::NEARESTPATCHFACE, - names[1], // samplePatch + regionNames[e[1]], // neighbourRegion + names[1], // neighbourPatch mesh.boundaryMesh() ); @@ -1059,11 +1058,11 @@ labelList addRegionPatches 0, 0, 0, - regionNames[e[0]], // sampleRegion - mappedPatchBase::NEARESTPATCHFACE, + regionNames[e[0]], // neighbourRegion names[0], mesh.boundaryMesh() ); + fvMeshTools::addPatch ( mesh, diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C index 7ace3854d0..b4b8309145 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicPolyPatch.C @@ -296,7 +296,7 @@ const Foam::word& Foam::cyclicPolyPatch::nbrPatchName() const { if (nbrPatchName_.empty()) { - // Try and use patchGroup to find samplePatch and sampleRegion + // Try and use patchGroup to find neighbourPatch and neighbourRegion label patchID = coupleGroup_.findOtherPatchID(*this); nbrPatchName_ = boundaryMesh()[patchID].name(); diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicTransform.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicTransform.C index 1de2aea97c..db55c06487 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicTransform.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicTransform.C @@ -27,6 +27,34 @@ License #include "unitConversion.H" #include "IOmanip.H" +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +template +Type sum(const Type& x, const bool global) +{ + return global ? returnReduce(x, sumOp()) : x; +} + +template +Type sum(const Field& x, const bool global) +{ + return global ? gSum(x) : sum(x); +} + +template +Type sum(const tmp>& x, const bool global) +{ + const Type s = sum(x(), global); + x.clear(); + return s; +} + +} + + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam @@ -279,13 +307,14 @@ Foam::cyclicTransform::cyclicTransform const cyclicTransform& transform, const word& nbrName, const cyclicTransform& nbrTransform, - const scalar matchTolerance + const scalar matchTolerance, + const bool global ) : cyclicTransform(transform) { // Calculate the total (vector) areas for the supplied patch data - const vector area = sum(areas); + const vector area = sum(areas, global); // Calculate patch length scales const scalar lengthScale = sqrt(mag(area)); @@ -335,7 +364,8 @@ Foam::cyclicTransform::cyclicTransform const pointField& nbrCtrs, const vectorField& nbrAreas, const cyclicTransform& nbrTransform, - const scalar matchTolerance + const scalar matchTolerance, + const bool global ) : cyclicTransform @@ -350,20 +380,25 @@ Foam::cyclicTransform::cyclicTransform { // If there is no geometry from which to calculate the transform then // nothing can be calculated - if (areas.size() == 0 || nbrAreas.size() == 0) return; + if (sum(areas.size(), global) == 0 || sum(nbrAreas.size(), global) == 0) + { + return; + } // Calculate the total (vector) areas for the supplied patch data - const vector area = sum(areas); - const vector nbrArea = sum(nbrAreas); + const vector area = sum(areas, global); + const vector nbrArea = sum(nbrAreas, global); // Calculate the centroids for the supplied patch data const scalarField magAreas(mag(areas)); const scalarField magNbrAreas(mag(nbrAreas)); - const point ctr = sum(ctrs*magAreas)/sum(magAreas); - const point nbrCtr = sum(nbrCtrs*magNbrAreas)/sum(magNbrAreas); + const scalar sumMagAreas = sum(magAreas, global); + const scalar sumMagNbrAreas = sum(magNbrAreas, global); + const point ctr = sum(ctrs*magAreas, global)/sumMagAreas; + const point nbrCtr = sum(nbrCtrs*magNbrAreas, global)/sumMagNbrAreas; // Calculate patch length scales - const scalar lengthScale = sqrt(sum(magAreas)); + const scalar lengthScale = sqrt(sumMagAreas); // Calculate the transformation from the patch geometry if (!transformComplete_) diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicTransform.H b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicTransform.H index f9b9835f58..672caab269 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicTransform.H +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/cyclic/cyclicTransform.H @@ -133,7 +133,8 @@ public: const cyclicTransform& transform, const word& nbrName, const cyclicTransform& nbrTransform, - const scalar matchTolerance + const scalar matchTolerance, + const bool global = false ); //- Construct from coupled patch data. Copies from the supplied @@ -150,7 +151,8 @@ public: const pointField& nbrCtrs, const vectorField& nbrAreas, const cyclicTransform& nbrTransform, - const scalar matchTolerance + const scalar matchTolerance, + const bool global = false ); diff --git a/src/ThermophysicalTransportModels/derivedFvPatchFields/thermalBaffle1D/thermalBaffle1DFvPatchScalarField.C b/src/ThermophysicalTransportModels/derivedFvPatchFields/thermalBaffle1D/thermalBaffle1DFvPatchScalarField.C index 397dce7744..dc464d0dcd 100644 --- a/src/ThermophysicalTransportModels/derivedFvPatchFields/thermalBaffle1D/thermalBaffle1DFvPatchScalarField.C +++ b/src/ThermophysicalTransportModels/derivedFvPatchFields/thermalBaffle1D/thermalBaffle1DFvPatchScalarField.C @@ -187,7 +187,7 @@ bool thermalBaffle1DFvPatchScalarField::owner() const << exit(FatalError); } - return patch().patch().index() < mpp.samplePolyPatch().index(); + return patch().patch().index() < mpp.nbrPolyPatch().index(); } @@ -197,10 +197,10 @@ thermalBaffle1DFvPatchScalarField::nbrField() const { const mappedPatchBase& mpp = refCast(patch().patch()); - const polyMesh& nbrMesh = mpp.sampleMesh(); - const label samplePatchi = mpp.samplePolyPatch().index(); + const polyMesh& nbrMesh = mpp.nbrMesh(); + const label nbrPatchi = mpp.nbrPolyPatch().index(); const fvPatch& nbrPatch = - refCast(nbrMesh).boundary()[samplePatchi]; + refCast(nbrMesh).boundary()[nbrPatchi]; return refCast diff --git a/src/ThermophysicalTransportModels/derivedFvPatchFields/thermalBaffle1D/thermalBaffle1DFvPatchScalarField.H b/src/ThermophysicalTransportModels/derivedFvPatchFields/thermalBaffle1D/thermalBaffle1DFvPatchScalarField.H index c2357a88b7..6ddeb352ad 100644 --- a/src/ThermophysicalTransportModels/derivedFvPatchFields/thermalBaffle1D/thermalBaffle1DFvPatchScalarField.H +++ b/src/ThermophysicalTransportModels/derivedFvPatchFields/thermalBaffle1D/thermalBaffle1DFvPatchScalarField.H @@ -41,7 +41,7 @@ Usage { type compressible::thermalBaffle1D; - samplePatch ; + neighbourPatch ; thickness uniform 0.005; // Thickness [m] qs uniform 100; // Source heat flux [W/m^2] @@ -75,7 +75,7 @@ Usage { type compressible::thermalBaffle1D; - samplePatch ; + neighbourPatch ; qr none; relaxation 1; diff --git a/src/ThermophysicalTransportModels/derivedFvPatchFields/turbulentTemperatureCoupledBaffleMixed/turbulentTemperatureCoupledBaffleMixedFvPatchScalarField.C b/src/ThermophysicalTransportModels/derivedFvPatchFields/turbulentTemperatureCoupledBaffleMixed/turbulentTemperatureCoupledBaffleMixedFvPatchScalarField.C index 894b24ef53..4c4a84678c 100644 --- a/src/ThermophysicalTransportModels/derivedFvPatchFields/turbulentTemperatureCoupledBaffleMixed/turbulentTemperatureCoupledBaffleMixedFvPatchScalarField.C +++ b/src/ThermophysicalTransportModels/derivedFvPatchFields/turbulentTemperatureCoupledBaffleMixed/turbulentTemperatureCoupledBaffleMixedFvPatchScalarField.C @@ -193,10 +193,10 @@ void turbulentTemperatureCoupledBaffleMixedFvPatchScalarField::updateCoeffs() // Get the coupling information from the mappedPatchBase const mappedPatchBase& mpp = refCast(patch().patch()); - const polyMesh& nbrMesh = mpp.sampleMesh(); - const label samplePatchi = mpp.samplePolyPatch().index(); + const polyMesh& nbrMesh = mpp.nbrMesh(); + const label nbrPatchi = mpp.nbrPolyPatch().index(); const fvPatch& nbrPatch = - refCast(nbrMesh).boundary()[samplePatchi]; + refCast(nbrMesh).boundary()[nbrPatchi]; // Calculate the temperature by harmonic averaging // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/ThermophysicalTransportModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C b/src/ThermophysicalTransportModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C index 044f0061c9..813178ab78 100644 --- a/src/ThermophysicalTransportModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C +++ b/src/ThermophysicalTransportModels/derivedFvPatchFields/turbulentTemperatureRadCoupledMixed/turbulentTemperatureRadCoupledMixedFvPatchScalarField.C @@ -177,10 +177,10 @@ void turbulentTemperatureRadCoupledMixedFvPatchScalarField::updateCoeffs() // Get the coupling information from the mappedPatchBase const mappedPatchBase& mpp = refCast(patch().patch()); - const polyMesh& nbrMesh = mpp.sampleMesh(); - const label samplePatchi = mpp.samplePolyPatch().index(); + const polyMesh& nbrMesh = mpp.nbrMesh(); + const label nbrPatchi = mpp.nbrPolyPatch().index(); const fvPatch& nbrPatch = - refCast(nbrMesh).boundary()[samplePatchi]; + refCast(nbrMesh).boundary()[nbrPatchi]; scalarField Tc(patchInternalField()); scalarField& Tp = *this; diff --git a/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.H b/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.H index 4947e94778..a5dbb14901 100644 --- a/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.H +++ b/src/dynamicMesh/extrudePatchMesh/extrudePatchMesh.H @@ -46,10 +46,7 @@ Description { name "bottom"; type mappedWall; - sampleMode nearestPatchFace; - samplePatch fixedWalls; - offsetMode uniform; - offset (0 0 0); + neighbourPatch fixedWalls; } topCoeffs diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 2984a98c51..3dc264550f 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -40,6 +40,7 @@ $(derivedFvPatches)/wall/wallFvPatch.C $(derivedFvPatches)/mapped/mappedFvPatch.C $(derivedFvPatches)/mapped/mappedWallFvPatch.C $(derivedFvPatches)/mapped/mappedExtrudedWallFvPatch.C +$(derivedFvPatches)/mapped/mappedInternalFvPatch.C meshWave = algorithms/FvFaceCellWave @@ -194,11 +195,11 @@ $(derivedFvPatchFields)/freestreamVelocity/freestreamVelocityFvPatchVectorField. $(derivedFvPatchFields)/freestreamPressure/freestreamPressureFvPatchScalarField.C $(derivedFvPatchFields)/inletOutlet/inletOutletFvPatchFields.C $(derivedFvPatchFields)/inletOutletTotalTemperature/inletOutletTotalTemperatureFvPatchScalarField.C -$(derivedFvPatchFields)/mappedField/mappedFieldFvPatchFields.C -$(derivedFvPatchFields)/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFields.C -$(derivedFvPatchFields)/mappedFixedValue/mappedFixedValueFvPatchFields.C -$(derivedFvPatchFields)/mappedFlowRate/mappedFlowRateFvPatchVectorField.C -$(derivedFvPatchFields)/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C +$(derivedFvPatchFields)/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C +$(derivedFvPatchFields)/mappedInternalValue/mappedInternalValueFvPatchFields.C +$(derivedFvPatchFields)/mappedValue/mappedValueFvPatchFields.C +$(derivedFvPatchFields)/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFields.C +$(derivedFvPatchFields)/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C $(derivedFvPatchFields)/matchedFlowRateOutletVelocity/matchedFlowRateOutletVelocityFvPatchVectorField.C $(derivedFvPatchFields)/noSlip/noSlipFvPatchVectorField.C $(derivedFvPatchFields)/movingWallVelocity/movingWallVelocityFvPatchVectorField.C diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.C deleted file mode 100644 index 87677ceaf8..0000000000 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.C +++ /dev/null @@ -1,157 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 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 "mappedFieldFvPatchField.H" -#include "volFields.H" -#include "interpolationCell.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::mappedFieldFvPatchField::mappedFieldFvPatchField -( - const fvPatch& p, - const DimensionedField& iF -) -: - fixedValueFvPatchField(p, iF), - mappedPatchBase(p.patch()), - mappedPatchFieldBase(*this, *this) -{} - - -template -Foam::mappedFieldFvPatchField::mappedFieldFvPatchField -( - const fvPatch& p, - const DimensionedField& iF, - const dictionary& dict -) -: - fixedValueFvPatchField(p, iF, dict), - mappedPatchBase(p.patch(), dict), - mappedPatchFieldBase(*this, *this, dict) -{} - - -template -Foam::mappedFieldFvPatchField::mappedFieldFvPatchField -( - const mappedFieldFvPatchField& ptf, - const fvPatch& p, - const DimensionedField& iF, - const fvPatchFieldMapper& mapper -) -: - fixedValueFvPatchField(ptf, p, iF, mapper), - mappedPatchBase(p.patch(), ptf), - mappedPatchFieldBase(*this, *this, ptf) -{} - - -template -Foam::mappedFieldFvPatchField::mappedFieldFvPatchField -( - const mappedFieldFvPatchField& ptf, - const DimensionedField& iF -) -: - fixedValueFvPatchField(ptf, iF), - mappedPatchBase(ptf.patch().patch(), ptf), - mappedPatchFieldBase(*this, *this, ptf) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::mappedFieldFvPatchField::autoMap -( - const fvPatchFieldMapper& m -) -{ - fixedValueFvPatchField::autoMap(m); - mappedPatchBase::clearOut(); -} - - -template -void Foam::mappedFieldFvPatchField::rmap -( - const fvPatchField& ptf, - const labelList& addr -) -{ - fixedValueFvPatchField::rmap(ptf, addr); - mappedPatchBase::clearOut(); -} - - -template -void Foam::mappedFieldFvPatchField::reset -( - const fvPatchField& ptf -) -{ - fixedValueFvPatchField::reset(ptf); - mappedPatchBase::clearOut(); -} - - -template -void Foam::mappedFieldFvPatchField::updateCoeffs() -{ - if (this->updated()) - { - return; - } - - this->operator==(this->mappedField()); - - if (debug) - { - Info<< "operating on field:" << this->internalField().name() - << " patch:" << this->patch().name() - << " avg:" << gAverage(*this) - << " min:" << gMin(*this) - << " max:" << gMax(*this) - << endl; - } - - fixedValueFvPatchField::updateCoeffs(); -} - - -template -void Foam::mappedFieldFvPatchField::write(Ostream& os) const -{ - fvPatchField::write(os); - mappedPatchBase::write(os); - mappedPatchFieldBase::write(os); - writeEntry(os, "value", *this); -} - - -// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C deleted file mode 100644 index 97533573e0..0000000000 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.C +++ /dev/null @@ -1,323 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2013-2022 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 "mappedPatchFieldBase.H" -#include "mappedPatchBase.H" -#include "interpolationCell.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -mappedPatchFieldBase::mappedPatchFieldBase -( - const mappedPatchBase& mapper, - const fvPatchField& patchField, - const word& fieldName, - const bool setAverage, - const Type average, - const word& interpolationScheme -) -: - mapper_(mapper), - patchField_(patchField), - fieldName_(fieldName), - setAverage_(setAverage), - average_(average), - interpolationScheme_(interpolationScheme) -{} - - -template -mappedPatchFieldBase::mappedPatchFieldBase -( - const mappedPatchBase& mapper, - const fvPatchField& patchField, - const dictionary& dict -) -: - mapper_(mapper), - patchField_(patchField), - fieldName_ - ( - dict.template lookupOrDefault - ( - "field", - patchField_.internalField().name() - ) - ), - setAverage_(readBool(dict.lookup("setAverage"))), - average_(pTraits(dict.lookup("average"))), - interpolationScheme_(interpolationCell::typeName) -{ - if (mapper_.mode() == mappedPatchBase::NEARESTCELL) - { - dict.lookup("interpolationScheme") >> interpolationScheme_; - } -} - - -template -mappedPatchFieldBase::mappedPatchFieldBase -( - const mappedPatchBase& mapper, - const fvPatchField& patchField -) -: - mapper_(mapper), - patchField_(patchField), - fieldName_(patchField_.internalField().name()), - setAverage_(false), - average_(Zero), - interpolationScheme_(interpolationCell::typeName) -{} - - -template -mappedPatchFieldBase::mappedPatchFieldBase -( - const mappedPatchFieldBase& mapper -) -: - mapper_(mapper.mapper_), - patchField_(mapper.patchField_), - fieldName_(mapper.fieldName_), - setAverage_(mapper.setAverage_), - average_(mapper.average_), - interpolationScheme_(mapper.interpolationScheme_) -{} - - -template -mappedPatchFieldBase::mappedPatchFieldBase -( - const mappedPatchBase& mapper, - const fvPatchField& patchField, - const mappedPatchFieldBase& base -) -: - mapper_(mapper), - patchField_(patchField), - fieldName_(base.fieldName_), - setAverage_(base.setAverage_), - average_(base.average_), - interpolationScheme_(base.interpolationScheme_) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -const GeometricField& -mappedPatchFieldBase::sampleField() const -{ - typedef GeometricField fieldType; - - const fvMesh& nbrMesh = refCast(mapper_.sampleMesh()); - - if (mapper_.sameRegion()) - { - if (fieldName_ == patchField_.internalField().name()) - { - // Optimisation: bypass field lookup - return dynamic_cast(patchField_.internalField()); - } - else - { - const fvMesh& thisMesh = patchField_.patch().boundaryMesh().mesh(); - return thisMesh.template lookupObject(fieldName_); - } - } - else - { - return nbrMesh.template lookupObject(fieldName_); - } -} - - -template -tmp> mappedPatchFieldBase::mappedField() const -{ - typedef GeometricField fieldType; - - const fvMesh& nbrMesh = refCast(mapper_.sampleMesh()); - - // 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; - - // Result of obtaining remote values - tmp> tnewValues(new Field(0)); - Field& newValues = tnewValues.ref(); - - switch (mapper_.mode()) - { - case mappedPatchBase::NEARESTCELL: - { - if (interpolationScheme_ != interpolationCell::typeName) - { - // Create an interpolation - autoPtr> interpolatorPtr - ( - interpolation::New - ( - interpolationScheme_, - sampleField() - ) - ); - const interpolation& interpolator = interpolatorPtr(); - - // Cells on which samples are generated - const labelList& sampleCells = mapper_.mapIndices(); - - // Send the patch points to the cells - pointField samplePoints(mapper_.samplePoints()); - mapper_.map().reverseDistribute - ( - sampleCells.size(), - samplePoints - ); - - // Interpolate values - Field sampleValues(sampleCells.size()); - forAll(sampleCells, i) - { - if (sampleCells[i] != -1) - { - sampleValues[i] = - interpolator.interpolate - ( - samplePoints[i], - sampleCells[i] - ); - } - } - - // Send the values back to the patch - newValues = sampleValues; - mapper_.map().distribute(newValues); - } - else - { - newValues = mapper_.distribute(sampleField()); - } - - break; - } - case mappedPatchBase::NEARESTPATCHFACE: - case mappedPatchBase::NEARESTPATCHFACEAMI: - { - const label nbrPatchID = - nbrMesh.boundaryMesh().findPatchID(mapper_.samplePatch()); - - if (nbrPatchID < 0) - { - FatalErrorInFunction - << "Unable to find sample patch " << mapper_.samplePatch() - << " in region " << mapper_.sampleRegion() - << " for patch " << patchField_.patch().name() << nl - << abort(FatalError); - } - - const fieldType& nbrField = sampleField(); - - newValues = - mapper_.distribute(nbrField.boundaryField()[nbrPatchID]); - - break; - } - case mappedPatchBase::NEARESTFACE: - { - Field allValues(nbrMesh.nFaces(), Zero); - - const fieldType& nbrField = sampleField(); - - forAll(nbrField.boundaryField(), patchi) - { - const fvPatchField& pf = - nbrField.boundaryField()[patchi]; - label faceStart = pf.patch().start(); - - forAll(pf, facei) - { - allValues[faceStart++] = pf[facei]; - } - } - - newValues = mapper_.distribute(allValues); - - break; - } - default: - { - FatalErrorInFunction - << "Unknown sampling mode: " << mapper_.mode() - << nl << abort(FatalError); - } - } - - if (setAverage_) - { - Type averagePsi = - gSum(patchField_.patch().magSf()*newValues) - /gSum(patchField_.patch().magSf()); - - if (mag(averagePsi)/mag(average_) > 0.5) - { - newValues *= mag(average_)/mag(averagePsi); - } - else - { - newValues += (average_ - averagePsi); - } - } - - // Restore tag - UPstream::msgType() = oldTag; - - return tnewValues; -} - - -template -void mappedPatchFieldBase::write(Ostream& os) const -{ - writeEntry(os, "field", fieldName_); - writeEntry(os, "setAverage", setAverage_); - writeEntry(os, "average", average_); - writeEntry(os, "interpolationScheme", interpolationScheme_); -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.H deleted file mode 100644 index 3866fa83a3..0000000000 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedPatchFieldBase.H +++ /dev/null @@ -1,169 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2013-2020 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::mappedPatchFieldBase - -Description - Functionality for sampling fields using mappedPatchBase. Every call to - mappedField() returns a sampled field, optionally scaled to maintain an - area-weighted average. - - Example usage: - - { - fieldName T; // default is same as fvPatchField - setAverage false; - average 1.0; // only if setAverage=true - interpolationScheme cellPoint; // default is cell - } - -SourceFiles - mappedPatchFieldBase.C - -\*---------------------------------------------------------------------------*/ - -#ifndef mappedPatchFieldBase_H -#define mappedPatchFieldBase_H - -#include "fixedValueFvPatchFields.H" -#include "volFieldsFwd.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -class mappedPatchBase; -template class interpolation; - -/*---------------------------------------------------------------------------*\ - Class mappedPatchFieldBase Declaration -\*---------------------------------------------------------------------------*/ - -template -class mappedPatchFieldBase -{ - -protected: - - // Protected data - - //- Mapping engine - const mappedPatchBase& mapper_; - - //- Underlying patch field - const fvPatchField& patchField_; - - //- Name of field to sample - word fieldName_; - - //- If true adjust the mapped field to maintain average value average_ - const bool setAverage_; - - //- Average value the mapped field is adjusted to maintain if - // setAverage_ is set true - const Type average_; - - //- Interpolation scheme to use for nearestcell mode - word interpolationScheme_; - - -public: - - // Constructors - - //- Construct from components - mappedPatchFieldBase - ( - const mappedPatchBase& mapper, - const fvPatchField& patchField, - const word& fieldName, - const bool setAverage, - const Type average, - const word& interpolationScheme - ); - - //- Construct from dictionary - mappedPatchFieldBase - ( - const mappedPatchBase& mapper, - const fvPatchField& patchField, - const dictionary& dict - ); - - //- Construct empty - mappedPatchFieldBase - ( - const mappedPatchBase& mapper, - const fvPatchField& patchField - ); - - //- Construct copy - mappedPatchFieldBase - ( - const mappedPatchFieldBase& mapper - ); - - //- Construct copy, resetting patch and field - mappedPatchFieldBase - ( - const mappedPatchBase& mapper, - const fvPatchField& patchField, - const mappedPatchFieldBase& base - ); - - - //- Destructor - virtual ~mappedPatchFieldBase() - {} - - - // Member Functions - - //- Field to sample. Either on my or nbr mesh - const GeometricField& sampleField() const; - - //- Map sampleField onto *this patch - virtual tmp> mappedField() const; - - //- Write - virtual void write(Ostream&) const; -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "mappedPatchFieldBase.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.C deleted file mode 100644 index 5c05e44267..0000000000 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.C +++ /dev/null @@ -1,185 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 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 "mappedFixedInternalValueFvPatchField.H" -#include "UIndirectList.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::mappedFixedInternalValueFvPatchField:: -mappedFixedInternalValueFvPatchField -( - const fvPatch& p, - const DimensionedField& iF -) -: - mappedFixedValueFvPatchField(p, iF) -{} - - -template -Foam::mappedFixedInternalValueFvPatchField:: -mappedFixedInternalValueFvPatchField -( - const fvPatch& p, - const DimensionedField& iF, - const dictionary& dict -) -: - mappedFixedValueFvPatchField(p, iF, dict) -{} - - -template -Foam::mappedFixedInternalValueFvPatchField:: -mappedFixedInternalValueFvPatchField -( - const mappedFixedInternalValueFvPatchField& ptf, - const fvPatch& p, - const DimensionedField& iF, - const fvPatchFieldMapper& mapper -) -: - mappedFixedValueFvPatchField(ptf, p, iF, mapper) -{} - - -template -Foam::mappedFixedInternalValueFvPatchField:: -mappedFixedInternalValueFvPatchField -( - const mappedFixedInternalValueFvPatchField& ptf, - const DimensionedField& iF -) -: - mappedFixedValueFvPatchField(ptf, iF) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -void Foam::mappedFixedInternalValueFvPatchField::updateCoeffs() -{ - typedef GeometricField FieldType; - - if (this->updated()) - { - return; - } - - // 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; - - // Retrieve the neighbour values and assign to this patch boundary field - mappedFixedValueFvPatchField::updateCoeffs(); - - // Get the coupling information from the mappedPatchBase - const mappedPatchBase& mpp = - refCast(this->patch().patch()); - const fvMesh& nbrMesh = refCast(mpp.sampleMesh()); - - Field nbrIntFld; - - switch (mpp.mode()) - { - case mappedPatchBase::NEARESTCELL: - { - FatalErrorInFunction - << "Cannot apply " - << mappedPatchBase::sampleModeNames_ - [ - mappedPatchBase::NEARESTCELL - ] - << " mapping mode for patch " << this->patch().name() - << exit(FatalError); - - break; - } - case mappedPatchBase::NEARESTPATCHFACE: - case mappedPatchBase::NEARESTPATCHFACEAMI: - { - const label samplePatchi = mpp.samplePolyPatch().index(); - const fvPatchField& nbrPatchField = - this->sampleField().boundaryField()[samplePatchi]; - - nbrIntFld = mpp.distribute(nbrPatchField.patchInternalField()); - - break; - } - case mappedPatchBase::NEARESTFACE: - { - Field allValues(nbrMesh.nFaces(), Zero); - - const FieldType& nbrField = this->sampleField(); - - forAll(nbrField.boundaryField(), patchi) - { - const fvPatchField& pf = nbrField.boundaryField()[patchi]; - const Field pif(pf.patchInternalField()); - - label faceStart = pf.patch().start(); - - forAll(pf, facei) - { - allValues[faceStart++] = pif[facei]; - } - } - - nbrIntFld = mpp.distribute(allValues); - - break; - } - default: - { - FatalErrorInFunction - << "Unknown sampling mode: " << mpp.mode() - << abort(FatalError); - } - } - - // Restore tag - UPstream::msgType() = oldTag; - - // Assign to (this) patch internal field its neighbour values - Field& intFld = const_cast&>(this->primitiveField()); - UIndirectList(intFld, this->patch().faceCells()) = nbrIntFld; -} - - -template -void Foam::mappedFixedInternalValueFvPatchField::write -( - Ostream& os -) const -{ - mappedFixedValueFvPatchField::write(os); -} - - -// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.C deleted file mode 100644 index 5d6c72c70e..0000000000 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.C +++ /dev/null @@ -1,138 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 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 "mappedFixedValueFvPatchField.H" -#include "volFields.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -template -Foam::mappedFixedValueFvPatchField::mappedFixedValueFvPatchField -( - const fvPatch& p, - const DimensionedField& iF -) -: - fixedValueFvPatchField(p, iF), - mappedPatchFieldBase(this->mapper(p, iF), *this) -{} - - -template -Foam::mappedFixedValueFvPatchField::mappedFixedValueFvPatchField -( - const fvPatch& p, - const DimensionedField& iF, - const dictionary& dict -) -: - fixedValueFvPatchField(p, iF, dict), - mappedPatchFieldBase(this->mapper(p, iF), *this, dict) -{} - - -template -Foam::mappedFixedValueFvPatchField::mappedFixedValueFvPatchField -( - const mappedFixedValueFvPatchField& ptf, - const fvPatch& p, - const DimensionedField& iF, - const fvPatchFieldMapper& mapper -) -: - fixedValueFvPatchField(ptf, p, iF, mapper), - mappedPatchFieldBase(this->mapper(p, iF), *this, ptf) -{} - - -template -Foam::mappedFixedValueFvPatchField::mappedFixedValueFvPatchField -( - const mappedFixedValueFvPatchField& ptf, - const DimensionedField& iF -) -: - fixedValueFvPatchField(ptf, iF), - mappedPatchFieldBase(this->mapper(this->patch(), iF), *this, ptf) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -template -const Foam::mappedPatchBase& Foam::mappedFixedValueFvPatchField::mapper -( - const fvPatch& p, - const DimensionedField& iF -) -{ - if (!isA(p.patch())) - { - FatalErrorInFunction - << "' not type '" << mappedPatchBase::typeName << "'" - << "\n for patch " << p.patch().name() - << " of field " << iF.name() - << " in file " << iF.objectPath() - << exit(FatalError); - } - return refCast(p.patch()); -} - - -template -void Foam::mappedFixedValueFvPatchField::updateCoeffs() -{ - if (this->updated()) - { - return; - } - - this->operator==(this->mappedField()); - - if (debug) - { - Info<< "mapped on field:" - << this->internalField().name() - << " patch:" << this->patch().name() - << " avg:" << gAverage(*this) - << " min:" << gMin(*this) - << " max:" << gMax(*this) - << endl; - } - - fixedValueFvPatchField::updateCoeffs(); -} - - -template -void Foam::mappedFixedValueFvPatchField::write(Ostream& os) const -{ - fvPatchField::write(os); - mappedPatchFieldBase::write(os); - writeEntry(os, "value", *this); -} - - -// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRate/mappedFlowRateFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C similarity index 70% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRate/mappedFlowRateFvPatchVectorField.C rename to src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C index d5329da5a8..9ce0e88f69 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRate/mappedFlowRateFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.C @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "mappedFlowRateFvPatchVectorField.H" +#include "mappedFlowRateVelocityFvPatchVectorField.H" #include "volFields.H" #include "addToRunTimeSelectionTable.H" #include "fvPatchFieldMapper.H" @@ -32,7 +32,8 @@ License // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField +Foam::mappedFlowRateVelocityFvPatchVectorField:: +mappedFlowRateVelocityFvPatchVectorField ( const fvPatch& p, const DimensionedField& iF @@ -45,7 +46,8 @@ Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField {} -Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField +Foam::mappedFlowRateVelocityFvPatchVectorField:: +mappedFlowRateVelocityFvPatchVectorField ( const fvPatch& p, const DimensionedField& iF, @@ -59,9 +61,10 @@ Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField {} -Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField +Foam::mappedFlowRateVelocityFvPatchVectorField:: +mappedFlowRateVelocityFvPatchVectorField ( - const mappedFlowRateFvPatchVectorField& ptf, + const mappedFlowRateVelocityFvPatchVectorField& ptf, const fvPatch& p, const DimensionedField& iF, const fvPatchFieldMapper& mapper @@ -74,9 +77,10 @@ Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField {} -Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField +Foam::mappedFlowRateVelocityFvPatchVectorField:: +mappedFlowRateVelocityFvPatchVectorField ( - const mappedFlowRateFvPatchVectorField& ptf, + const mappedFlowRateVelocityFvPatchVectorField& ptf, const DimensionedField& iF ) : @@ -89,7 +93,7 @@ Foam::mappedFlowRateFvPatchVectorField::mappedFlowRateFvPatchVectorField // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::mappedFlowRateFvPatchVectorField::updateCoeffs() +void Foam::mappedFlowRateVelocityFvPatchVectorField::updateCoeffs() { if (updated()) { @@ -101,57 +105,39 @@ void Foam::mappedFlowRateFvPatchVectorField::updateCoeffs() int oldTag = UPstream::msgType(); UPstream::msgType() = oldTag+1; - // Get the coupling information from the mappedPatchBase - const mappedPatchBase& mpp = refCast - ( - patch().patch() - ); - const polyMesh& nbrMesh = mpp.sampleMesh(); - const fvPatch& nbrPatch = refCast - ( - nbrMesh - ).boundary()[mpp.samplePolyPatch().index()]; + const mappedPatchBase& mapper = + refCast(patch().patch()); + const fvMesh& nbrMesh = refCast(mapper.nbrMesh()); + const label nbrPatchi = mapper.nbrPolyPatch().index(); + const fvPatch& nbrPatch = nbrMesh.boundary()[nbrPatchi]; - const scalarField phi + const surfaceScalarField& phi = + db().lookupObject(phiName_); + + const scalarField phip ( - mpp.distribute + mapper.distribute ( nbrPatch.lookupPatchField(nbrPhiName_) ) ); - const surfaceScalarField& phiName = - db().lookupObject(phiName_); + const scalarField Unp(-phip/patch().magSf()); - scalarField U(-phi/patch().magSf()); + const vectorField np(patch().nf()); - vectorField n(patch().nf()); - - if (phiName.dimensions() == dimFlux) + if (phi.dimensions() == dimFlux) { // volumetric flow-rate - operator==(n*U); + operator==(np*Unp); } - else if (phiName.dimensions() == dimMassFlux) + else if (phi.dimensions() == dimMassFlux) { const fvPatchField& rhop = patch().lookupPatchField(rhoName_); // mass flow-rate - operator==(n*U/rhop); - - if (debug) - { - scalar phi = gSum(rhop*(*this) & patch().Sf()); - Info<< patch().boundaryMesh().mesh().name() << ':' - << patch().name() << ':' - << this->internalField().name() << " <- " - << nbrMesh.name() << ':' - << nbrPatch.name() << ':' - << this->internalField().name() << " :" - << " mass flux[Kg/s]:" << -phi - << endl; - } + operator==(np*Unp/rhop); } else { @@ -170,7 +156,7 @@ void Foam::mappedFlowRateFvPatchVectorField::updateCoeffs() } -void Foam::mappedFlowRateFvPatchVectorField::write +void Foam::mappedFlowRateVelocityFvPatchVectorField::write ( Ostream& os ) const @@ -190,7 +176,7 @@ namespace Foam makePatchTypeField ( fvPatchVectorField, - mappedFlowRateFvPatchVectorField + mappedFlowRateVelocityFvPatchVectorField ); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRate/mappedFlowRateFvPatchVectorField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.H similarity index 71% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRate/mappedFlowRateFvPatchVectorField.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.H index 7ab3b95995..3abbf052e8 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRate/mappedFlowRateFvPatchVectorField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedFlowRateVelocity/mappedFlowRateVelocityFvPatchVectorField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -22,45 +22,46 @@ License along with OpenFOAM. If not, see . Class - Foam::mappedFlowRateFvPatchVectorField + Foam::mappedFlowRateVelocityFvPatchVectorField Description - Describes a volumetric/mass flow normal vector boundary condition by its - magnitude as an integral over its area. - - The inlet mass flux is taken from the neighbour region. - - The basis of the patch (volumetric or mass) is determined by the - dimensions of the flux, phi. The current density is used to correct the - velocity when applying the mass basis. + This boundary condition maps the flow rate from a neighbouring patch to + this patch, then uses it to set a corresponding velocity in a direction + normal to the patch. Usage \table Property | Description | Required | Default value + nbrPhi | name of flux field on neighbour mesh | no | phi phi | flux field name | no | phi rho | density field name | no | rho - neigPhi | name of flux field on neighbour mesh | yes | \endtable Example of the boundary condition specification: \verbatim { - type mappedFlowRate; - phi phi; - rho rho; - neigPhi phi; - value uniform (0 0 0); // placeholder + type mappedFlowRateVelocity; + value uniform (0 0 0); } \endverbatim + This boundary condition can only be applied to patches that are of + mappedPatchBase type. + +See also + Foam::mappedPatchBase + Foam::mappedPolyPatch + Foam::mappedFvPatch + Foam::fixedValueFvPatchVectorField + SourceFiles - mappedFlowRateFvPatchVectorField.C + mappedFlowRateVelocityFvPatchVectorField.C \*---------------------------------------------------------------------------*/ -#ifndef mappedFlowRateFvPatchVectorField_H -#define mappedFlowRateFvPatchVectorField_H +#ifndef mappedFlowRateVelocityFvPatchVectorField_H +#define mappedFlowRateVelocityFvPatchVectorField_H #include "fixedValueFvPatchFields.H" @@ -69,10 +70,10 @@ SourceFiles namespace Foam { /*---------------------------------------------------------------------------*\ - Class flowRateInletVelocityFvPatch Declaration + Class mappedFlowRateVelocityFvPatchVectorField Declaration \*---------------------------------------------------------------------------*/ -class mappedFlowRateFvPatchVectorField +class mappedFlowRateVelocityFvPatchVectorField : public fixedValueFvPatchVectorField { @@ -91,20 +92,20 @@ class mappedFlowRateFvPatchVectorField public: //- Runtime type information - TypeName("mappedFlowRate"); + TypeName("mappedFlowRateVelocity"); // Constructors //- Construct from patch and internal field - mappedFlowRateFvPatchVectorField + mappedFlowRateVelocityFvPatchVectorField ( const fvPatch&, const DimensionedField& ); //- Construct from patch, internal field and dictionary - mappedFlowRateFvPatchVectorField + mappedFlowRateVelocityFvPatchVectorField ( const fvPatch&, const DimensionedField&, @@ -112,26 +113,26 @@ public: ); //- Construct by mapping given - // mappedFlowRateFvPatchVectorField + // mappedFlowRateVelocityFvPatchVectorField // onto a new patch - mappedFlowRateFvPatchVectorField + mappedFlowRateVelocityFvPatchVectorField ( - const mappedFlowRateFvPatchVectorField&, + const mappedFlowRateVelocityFvPatchVectorField&, const fvPatch&, const DimensionedField&, const fvPatchFieldMapper& ); //- Disallow copy without setting internal field reference - mappedFlowRateFvPatchVectorField + mappedFlowRateVelocityFvPatchVectorField ( - const mappedFlowRateFvPatchVectorField& + const mappedFlowRateVelocityFvPatchVectorField& ) = delete; //- Copy constructor setting internal field reference - mappedFlowRateFvPatchVectorField + mappedFlowRateVelocityFvPatchVectorField ( - const mappedFlowRateFvPatchVectorField&, + const mappedFlowRateVelocityFvPatchVectorField&, const DimensionedField& ); @@ -143,7 +144,7 @@ public: { return tmp ( - new mappedFlowRateFvPatchVectorField(*this, iF) + new mappedFlowRateVelocityFvPatchVectorField(*this, iF) ); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchField.C new file mode 100644 index 0000000000..b8e0149c7c --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchField.C @@ -0,0 +1,325 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 "mappedInternalValueFvPatchField.H" +#include "volFields.H" +#include "interpolationCell.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +const Foam::mappedInternalPatchBase& +Foam::mappedInternalValueFvPatchField::mapper() const +{ + if (mapperPtr_.valid()) + { + return mapperPtr_(); + } + + if (isA(this->patch().patch())) + { + return refCast(this->patch().patch()); + } + + FatalErrorInFunction + << "Field " << this->internalField().name() << " on patch " + << this->patch().name() << " in file " + << this->internalField().objectPath() + << " has neither a mapper specified nor is the patch of " + << mappedInternalPatchBase::typeName << " type" + << exit(FatalError); + + return NullObjectRef(); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::mappedInternalValueFvPatchField:: +mappedInternalValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchField(p, iF), + fieldName_(iF.name()), + setAverage_(false), + average_(Zero), + interpolationScheme_(interpolationCell::typeName), + mapperPtr_(nullptr) +{} + + +template +Foam::mappedInternalValueFvPatchField:: +mappedInternalValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + fixedValueFvPatchField(p, iF, dict), + fieldName_(dict.lookupOrDefault("field", iF.name())), + setAverage_ + ( + dict.lookupOrDefault("setAverage", dict.found("average")) + ), + average_(setAverage_ ? dict.lookup("average") : Zero), + interpolationScheme_(dict.lookup("interpolationScheme")), + mapperPtr_ + ( + mappedInternalPatchBase::specified(dict) + ? new mappedInternalPatchBase(p.patch(), dict) + : nullptr + ) +{} + + +template +Foam::mappedInternalValueFvPatchField:: +mappedInternalValueFvPatchField +( + const mappedInternalValueFvPatchField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + fixedValueFvPatchField(ptf, p, iF, mapper), + fieldName_(ptf.fieldName_), + setAverage_(ptf.setAverage_), + average_(ptf.average_), + interpolationScheme_(ptf.interpolationScheme_), + mapperPtr_ + ( + ptf.mapperPtr_.valid() + ? new mappedInternalPatchBase(p.patch(), ptf.mapperPtr_()) + : nullptr + ) +{} + + +template +Foam::mappedInternalValueFvPatchField:: +mappedInternalValueFvPatchField +( + const mappedInternalValueFvPatchField& ptf, + const DimensionedField& iF +) +: + fixedValueFvPatchField(ptf, iF), + fieldName_(ptf.fieldName_), + setAverage_(ptf.setAverage_), + average_(ptf.average_), + interpolationScheme_(ptf.interpolationScheme_), + mapperPtr_ + ( + ptf.mapperPtr_.valid() + ? new mappedInternalPatchBase(ptf.patch().patch(), ptf.mapperPtr_()) + : nullptr + ) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::mappedInternalValueFvPatchField::autoMap +( + const fvPatchFieldMapper& m +) +{ + fixedValueFvPatchField::autoMap(m); + + if (mapperPtr_.valid()) + { + mapperPtr_->clearOut(); + } +} + + +template +void Foam::mappedInternalValueFvPatchField::rmap +( + const fvPatchField& ptf, + const labelList& addr +) +{ + fixedValueFvPatchField::rmap(ptf, addr); + + if (mapperPtr_.valid()) + { + mapperPtr_->clearOut(); + } +} + + +template +void Foam::mappedInternalValueFvPatchField::reset +( + const fvPatchField& ptf +) +{ + fixedValueFvPatchField::reset(ptf); + + if (mapperPtr_.valid()) + { + mapperPtr_->clearOut(); + } +} + + +template +void Foam::mappedInternalValueFvPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + // 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; + + 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_); + + // Construct mapped values + Field sampleValues; + + if (interpolationScheme_ != interpolationCell::typeName) + { + // Create an interpolation + autoPtr> interpolatorPtr + ( + interpolation::New + ( + interpolationScheme_, + nbrField + ) + ); + const interpolation& interpolator = interpolatorPtr(); + + // Cells on which samples are generated + const labelList& sampleCells = mapper().cellIndices(); + + // Send the patch points to the cells + pointField samplePoints(mapper().samplePoints()); + mapper().map().reverseDistribute + ( + sampleCells.size(), + samplePoints + ); + + // Interpolate values + sampleValues.resize(sampleCells.size()); + forAll(sampleCells, i) + { + if (sampleCells[i] != -1) + { + sampleValues[i] = + interpolator.interpolate + ( + samplePoints[i], + sampleCells[i] + ); + } + } + + // Send the values back to the patch + mapper().map().distribute(sampleValues); + } + else + { + // No interpolation. Just sample cell values directly. + sampleValues = mapper().distribute(nbrField); + } + + // Set the average, if necessary + if (setAverage_) + { + const Type sampleAverageValue = + gSum(this->patch().magSf()*sampleValues) + /gSum(this->patch().magSf()); + + if (mag(sampleAverageValue)/mag(average_) > 0.5) + { + sampleValues *= mag(average_)/mag(sampleAverageValue); + } + else + { + sampleValues += average_ - sampleAverageValue; + } + } + + // Assign sampled patch values + this->operator==(sampleValues); + + // Restore tag + UPstream::msgType() = oldTag; + + fixedValueFvPatchField::updateCoeffs(); +} + + +template +void Foam::mappedInternalValueFvPatchField::write(Ostream& os) const +{ + fvPatchField::write(os); + + writeEntryIfDifferent + ( + os, + "field", + this->internalField().name(), + fieldName_ + ); + + if (setAverage_) + { + writeEntry(os, "average", average_); + } + + writeEntry(os, "interpolationScheme", interpolationScheme_); + + if (mapperPtr_.valid()) + { + mapperPtr_->write(os); + } + + writeEntry(os, "value", *this); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchField.H similarity index 51% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchField.H index b32ab83211..6e93e847e7 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -22,65 +22,57 @@ License along with OpenFOAM. If not, see . Class - Foam::mappedFixedValueFvPatchField + Foam::mappedInternalValueFvPatchField Description - This boundary condition maps the value at a set of cells or patch faces - back to *this. - - The sample mode is set by the underlying mapping engine, provided by the - mappedPatchBase class. + This boundary condition maps the values from a internal cells to this + patch. Usage \table - Property | Description | Required | Default value + Property | Description | Required | Default value fieldName | name of field to be mapped | no | this field name - setAverage | flag to activate setting of average value | yes | - average | average value to apply if \c setAverage = yes | yes | - interpolationScheme | type of interpolation scheme | no | + setAverage | set the average value? | no | yes if average \\ + is specified, \\ + no otherwise + average | average value to apply | if setAverage is true | + interplolationScheme | the interpolation scheme to use | yes | \endtable Example of the boundary condition specification: \verbatim { - type mapped; + type mappedInternal; fieldName T; - setAverage no; - average 0; - interpolationScheme cell; - value uniform 0; + average 300; + interpolationScheme cellPoint; + value uniform 300; } \endverbatim - When employing the \c nearestCell sample mode, the user must also specify - the interpolation scheme using the \c interpolationScheme entry. - - In case of interpolation (where scheme != cell) the limitation is that - there is only one value per cell. For example, if you have a cell with two - boundary faces and both faces sample into the cell, both faces will get the - same value. - - Note: - It is not possible to sample internal faces since volume fields are not - defined on faces. + This boundary condition will usually be applied to a patch which is of + mappedInternalPatchBase 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 + mappedInternalPatchBase (i.e., neighbourRegion, offset, distance, etc ...). See also - Foam::mappedPatchBase + Foam::mappedInternalPatchBase Foam::interpolation Foam::fixedValueFvPatchField SourceFiles - mappedFixedValueFvPatchField.C + mappedInternalValueFvPatchField.C \*---------------------------------------------------------------------------*/ -#ifndef mappedFixedValueFvPatchField_H -#define mappedFixedValueFvPatchField_H +#ifndef mappedInternalValueFvPatchField_H +#define mappedInternalValueFvPatchField_H #include "fixedValueFvPatchFields.H" -//#include "interpolation.H" -#include "mappedPatchFieldBase.H" +#include "mappedInternalPatchBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -88,70 +80,83 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class mappedFixedValueFvPatchField Declaration + Class mappedInternalValueFvPatchField Declaration \*---------------------------------------------------------------------------*/ template -class mappedFixedValueFvPatchField +class mappedInternalValueFvPatchField : - public fixedValueFvPatchField, - public mappedPatchFieldBase + public fixedValueFvPatchField { - protected: + // Protected Member Data + + //- Name of the field to map + const word fieldName_; + + //- If true adjust the mapped field to maintain an average value + const bool setAverage_; + + //- Average value the mapped field is adjusted to + const Type average_; + + //- Interpolation scheme to use + const word interpolationScheme_; + + //- Sampling engine + autoPtr mapperPtr_; + + // Protected Member Functions - const mappedPatchBase& mapper - ( - const fvPatch& p, - const DimensionedField& iF - ); + //- Return the mapping engine + const mappedInternalPatchBase& mapper() const; public: //- Runtime type information - TypeName("mapped"); + TypeName("mappedInternalValue"); // Constructors //- Construct from patch and internal field - mappedFixedValueFvPatchField + mappedInternalValueFvPatchField ( const fvPatch&, const DimensionedField& ); //- Construct from patch, internal field and dictionary - mappedFixedValueFvPatchField + mappedInternalValueFvPatchField ( const fvPatch&, const DimensionedField&, const dictionary& ); - //- Construct by mapping given mappedFixedValueFvPatchField + //- Construct by mapping given mappedInternalValueFvPatchField // onto a new patch - mappedFixedValueFvPatchField + mappedInternalValueFvPatchField ( - const mappedFixedValueFvPatchField&, + const mappedInternalValueFvPatchField&, const fvPatch&, const DimensionedField&, const fvPatchFieldMapper& ); //- Disallow copy without setting internal field reference - mappedFixedValueFvPatchField + mappedInternalValueFvPatchField ( - const mappedFixedValueFvPatchField& + const mappedInternalValueFvPatchField& ) = delete; //- Copy constructor setting internal field reference - mappedFixedValueFvPatchField + mappedInternalValueFvPatchField ( - const mappedFixedValueFvPatchField&, + const mappedInternalValueFvPatchField&, const DimensionedField& ); @@ -163,18 +168,34 @@ public: { return tmp> ( - new mappedFixedValueFvPatchField(*this, iF) + new mappedInternalValueFvPatchField(*this, iF) ); } // Member Functions + // Mapping functions + + //- Map (and resize as needed) from self given a mapping object + // Used to update fields following mesh topology change + virtual void autoMap(const fvPatchFieldMapper&); + + //- Reverse map the given fvPatchField onto this fvPatchField + // Used to reconstruct fields + virtual void rmap(const fvPatchField&, const labelList&); + + //- 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; }; @@ -187,7 +208,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository - #include "mappedFixedValueFvPatchField.C" + #include "mappedInternalValueFvPatchField.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFields.C similarity index 90% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFields.C rename to src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFields.C index 41b2fb2f17..7eafeb8d9e 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "mappedFixedValueFvPatchFields.H" +#include "mappedInternalValueFvPatchFields.H" #include "volMesh.H" #include "addToRunTimeSelectionTable.H" @@ -34,7 +34,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -makePatchFields(mappedFixedValue); +makePatchFields(mappedInternalValue); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFields.H similarity index 86% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFields.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFields.H index 022ebd8dda..628b99a4f1 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFields.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,10 +23,10 @@ License \*---------------------------------------------------------------------------*/ -#ifndef mappedFixedValueFvPatchFields_H -#define mappedFixedValueFvPatchFields_H +#ifndef mappedInternalValueFvPatchFields_H +#define mappedInternalValueFvPatchFields_H -#include "mappedFixedValueFvPatchField.H" +#include "mappedInternalValueFvPatchField.H" #include "fieldTypes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -36,7 +36,7 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -makePatchTypeFieldTypedefs(mappedFixedValue); +makePatchTypeFieldTypedefs(mappedInternalValue); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFieldsFwd.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFieldsFwd.H similarity index 85% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFieldsFwd.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFieldsFwd.H index 92e7150af4..1e380f2317 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedValue/mappedFixedValueFvPatchFieldsFwd.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedInternalValue/mappedInternalValueFvPatchFieldsFwd.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,8 +23,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef mappedFixedValueFvPatchFieldsFwd_H -#define mappedFixedValueFvPatchFieldsFwd_H +#ifndef mappedInternalValueFvPatchFieldsFwd_H +#define mappedInternalValueFvPatchFieldsFwd_H #include "fieldTypes.H" @@ -35,9 +35,9 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template class mappedFixedValueFvPatchField; +template class mappedInternalValueFvPatchField; -makePatchTypeFieldTypedefs(mappedFixedValue); +makePatchTypeFieldTypedefs(mappedInternalValue); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.C new file mode 100644 index 0000000000..0cc0083fc8 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.C @@ -0,0 +1,287 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2022 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 "mappedValueFvPatchField.H" +#include "volFields.H" + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +template +const Foam::mappedPatchBase& +Foam::mappedValueFvPatchField::mapper() const +{ + if (mapperPtr_.valid()) + { + return mapperPtr_(); + } + + if (isA(this->patch().patch())) + { + return refCast(this->patch().patch()); + } + + FatalErrorInFunction + << "Field " << this->internalField().name() << " on patch " + << this->patch().name() << " in file " + << this->internalField().objectPath() + << " has neither a mapper specified nor is the patch of " + << mappedPatchBase::typeName << " type" + << exit(FatalError); + + return NullObjectRef(); +} + + +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 +Foam::mappedValueFvPatchField::mappedValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF +) +: + fixedValueFvPatchField(p, iF), + fieldName_(iF.name()), + setAverage_(false), + average_(Zero), + mapperPtr_(nullptr) +{} + + +template +Foam::mappedValueFvPatchField::mappedValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + 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 + ) +{} + + +template +Foam::mappedValueFvPatchField::mappedValueFvPatchField +( + const mappedValueFvPatchField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + 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 + ) +{} + + +template +Foam::mappedValueFvPatchField::mappedValueFvPatchField +( + const mappedValueFvPatchField& ptf, + const DimensionedField& iF +) +: + fixedValueFvPatchField(ptf, iF), + fieldName_(ptf.fieldName_), + setAverage_(ptf.setAverage_), + average_(ptf.average_), + mapperPtr_ + ( + ptf.mapperPtr_.valid() + ? new mappedPatchBase(ptf.patch().patch(), ptf.mapperPtr_()) + : nullptr + ) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::mappedValueFvPatchField::autoMap +( + const fvPatchFieldMapper& m +) +{ + fixedValueFvPatchField::autoMap(m); + + if (mapperPtr_.valid()) + { + mapperPtr_->clearOut(); + } +} + + +template +void Foam::mappedValueFvPatchField::rmap +( + const fvPatchField& ptf, + const labelList& addr +) +{ + fixedValueFvPatchField::rmap(ptf, addr); + + if (mapperPtr_.valid()) + { + mapperPtr_->clearOut(); + } +} + + +template +void Foam::mappedValueFvPatchField::reset +( + const fvPatchField& ptf +) +{ + fixedValueFvPatchField::reset(ptf); + + if (mapperPtr_.valid()) + { + mapperPtr_->clearOut(); + } +} + + +template +void Foam::mappedValueFvPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + this->operator==(mappedValues(nbrPatchField())); + + fixedValueFvPatchField::updateCoeffs(); +} + + +template +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); + } + + writeEntry(os, "value", *this); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.H similarity index 61% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.H index 9dc43daf3f..68137734fe 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchField.H @@ -22,58 +22,56 @@ License along with OpenFOAM. If not, see . Class - Foam::mappedFieldFvPatchField + Foam::mappedValueFvPatchField Description - This boundary condition provides a self-contained version of the \c mapped - condition. It does not use information on the patch; instead it holds - thr data locally. + This boundary condition maps the values from a neighbouring patch to this + patch. Usage \table - Property | Description | Required | Default value + Property | Description | Required | Default value fieldName | name of field to be mapped | no | this field name - setAverage | flag to activate setting of average value | yes | - average | average value to apply if \c setAverage = yes | yes | + setAverage | set the average value? | no | yes if average \\ + is specified, \\ + no otherwise + average | average value to apply | if setAverage is true | \endtable Example of the boundary condition specification: \verbatim { - type mappedField; - fieldName T; // optional field name - setAverage no; // apply an average value - average 0; // average to apply if setAverage - value uniform 0; // place holder + type mapped; + fieldName T; + average 300; + value uniform 300; } \endverbatim - Note: - Since this condition can be applied on a per-field and per-patch basis, - it is possible to duplicate the mapping information. If possible, - employ the \c mapped condition in preference to avoid this situation, - and only employ this condition if it is not possible to change the - underlying geometric (poly) patch type to \c mapped. + 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::mappedPatchBase Foam::mappedPolyPatch Foam::mappedFvPatch - Foam::fixedValueFvPatchField + Foam::mappedValueFvPatchField SourceFiles - mappedFieldFvPatchField.C + mappedValueFvPatchField.C \*---------------------------------------------------------------------------*/ -#ifndef mappedFieldFvPatchField_H -#define mappedFieldFvPatchField_H +#ifndef mappedValueFvPatchField_H +#define mappedValueFvPatchField_H -#include "mappedPatchBase.H" -#include "mappedPatchFieldBase.H" #include "fixedValueFvPatchFields.H" -#include "interpolation.H" +#include "mappedPatchBase.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -81,56 +79,86 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class mappedFieldFvPatchField Declaration + Class mappedValueFvPatchField Declaration \*---------------------------------------------------------------------------*/ template -class mappedFieldFvPatchField +class mappedValueFvPatchField : - public fixedValueFvPatchField, - public mappedPatchBase, - public mappedPatchFieldBase + public fixedValueFvPatchField { +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: //- Runtime type information - TypeName("mappedField"); + TypeName("mappedValue"); // Constructors //- Construct from patch and internal field - mappedFieldFvPatchField + mappedValueFvPatchField ( const fvPatch&, const DimensionedField& ); //- Construct from patch, internal field and dictionary - mappedFieldFvPatchField + mappedValueFvPatchField ( const fvPatch&, const DimensionedField&, const dictionary& ); - //- Construct by mapping given mappedFieldFvPatchField onto a new patch - mappedFieldFvPatchField + //- Construct by mapping given mappedValueFvPatchField + // onto a new patch + mappedValueFvPatchField ( - const mappedFieldFvPatchField&, + const mappedValueFvPatchField&, const fvPatch&, const DimensionedField&, const fvPatchFieldMapper& ); //- Disallow copy without setting internal field reference - mappedFieldFvPatchField(const mappedFieldFvPatchField&) = delete; + mappedValueFvPatchField + ( + const mappedValueFvPatchField& + ) = delete; //- Copy constructor setting internal field reference - mappedFieldFvPatchField + mappedValueFvPatchField ( - const mappedFieldFvPatchField&, + const mappedValueFvPatchField&, const DimensionedField& ); @@ -142,11 +170,7 @@ public: { return tmp> ( - new mappedFieldFvPatchField - ( - *this, - iF - ) + new mappedValueFvPatchField(*this, iF) ); } @@ -186,7 +210,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository - #include "mappedFieldFvPatchField.C" + #include "mappedValueFvPatchField.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFields.C similarity index 92% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFields.C rename to src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFields.C index 4463181ace..e2be46a9c3 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "mappedFieldFvPatchFields.H" +#include "mappedValueFvPatchFields.H" #include "volMesh.H" #include "addToRunTimeSelectionTable.H" @@ -34,7 +34,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -makePatchFields(mappedField); +makePatchFields(mappedValue); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFields.H similarity index 88% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFields.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFields.H index 8f58ee4e4d..f5b34652ca 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFields.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,10 +23,10 @@ License \*---------------------------------------------------------------------------*/ -#ifndef mappedFieldFvPatchFields_H -#define mappedFieldFvPatchFields_H +#ifndef mappedValueFvPatchFields_H +#define mappedValueFvPatchFields_H -#include "mappedFieldFvPatchField.H" +#include "mappedValueFvPatchField.H" #include "fieldTypes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -36,7 +36,7 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -makePatchTypeFieldTypedefs(mappedField) +makePatchTypeFieldTypedefs(mappedValue); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFieldsFwd.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFieldsFwd.H similarity index 87% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFieldsFwd.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFieldsFwd.H index 1aca32c92e..a5771dad91 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedField/mappedFieldFvPatchFieldsFwd.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValue/mappedValueFvPatchFieldsFwd.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,8 +23,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef mappedFieldFvPatchFieldsFwd_H -#define mappedFieldFvPatchFieldsFwd_H +#ifndef mappedValueFvPatchFieldsFwd_H +#define mappedValueFvPatchFieldsFwd_H #include "fieldTypes.H" @@ -35,9 +35,9 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template class mappedFieldFvPatchField; +template class mappedValueFvPatchField; -makePatchTypeFieldTypedefs(mappedField) +makePatchTypeFieldTypedefs(mappedValue); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchField.C new file mode 100644 index 0000000000..e55651a6b4 --- /dev/null +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchField.C @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2022 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 "mappedValueAndPatchInternalValueFvPatchField.H" +#include "UIndirectList.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::mappedValueAndPatchInternalValueFvPatchField:: +mappedValueAndPatchInternalValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF +) +: + mappedValueFvPatchField(p, iF) +{} + + +template +Foam::mappedValueAndPatchInternalValueFvPatchField:: +mappedValueAndPatchInternalValueFvPatchField +( + const fvPatch& p, + const DimensionedField& iF, + const dictionary& dict +) +: + mappedValueFvPatchField(p, iF, dict) +{} + + +template +Foam::mappedValueAndPatchInternalValueFvPatchField:: +mappedValueAndPatchInternalValueFvPatchField +( + const mappedValueAndPatchInternalValueFvPatchField& ptf, + const fvPatch& p, + const DimensionedField& iF, + const fvPatchFieldMapper& mapper +) +: + mappedValueFvPatchField(ptf, p, iF, mapper) +{} + + +template +Foam::mappedValueAndPatchInternalValueFvPatchField:: +mappedValueAndPatchInternalValueFvPatchField +( + const mappedValueAndPatchInternalValueFvPatchField& ptf, + const DimensionedField& iF +) +: + mappedValueFvPatchField(ptf, iF) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +void Foam::mappedValueAndPatchInternalValueFvPatchField::updateCoeffs() +{ + if (this->updated()) + { + return; + } + + this->operator==(this->mappedValues(this->nbrPatchField())); + + UIndirectList + ( + const_cast&>(this->primitiveField()), + this->patch().faceCells() + ) = this->mappedValues(this->nbrPatchField().patchInternalField()); + + fixedValueFvPatchField::updateCoeffs(); +} + + +template +void Foam::mappedValueAndPatchInternalValueFvPatchField::write +( + Ostream& os +) const +{ + mappedValueFvPatchField::write(os); +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchField.H similarity index 60% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchField.H index f11bfe8732..4acd0959ad 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchField.H @@ -22,50 +22,55 @@ License along with OpenFOAM. If not, see . Class - Foam::mappedFixedInternalValueFvPatchField + Foam::mappedValueAndPatchInternalValueFvPatchField Description - This boundary condition maps the boundary and internal values of a - neighbour patch field to the boundary and internal values of *this. + This boundary condition maps the boundary and internal values from a + neighbouring patch field to the boundary and internal values of this patch. Usage \table - Property | Description | Required | Default value + Property | Description | Required | Default value fieldName | name of field to be mapped | no | this field name - setAverage | flag to activate setting of average value | yes | - average | average value to apply if \c setAverage = yes | yes | + setAverage | set the average value? | no | yes if average \\ + is specified, \\ + no otherwise + average | average value to apply | if setAverage is true | \endtable + Example of the boundary condition specification: \verbatim { - type mappedFixedInternalValue; + type mappedValueAndPatchInternalValue; fieldName T; - setAverage no; - average 0; - value uniform 0; + average 300; + value uniform 300; } \endverbatim - Note: - This boundary condition can only be applied to patches that are of - the \c mappedPolyPatch type. + 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::mappedPatchBase Foam::mappedPolyPatch Foam::mappedFvPatch - Foam::mappedFixedValueFvPatchField + Foam::mappedValueFvPatchField SourceFiles - mappedFixedInternalValueFvPatchField.C + mappedValueAndPatchInternalValue.C \*---------------------------------------------------------------------------*/ -#ifndef mappedFixedInternalValueFvPatchField_H -#define mappedFixedInternalValueFvPatchField_H +#ifndef mappedValueAndPatchInternalValueFvPatchField_H +#define mappedValueAndPatchInternalValueFvPatchField_H -#include "mappedFixedValueFvPatchField.H" +#include "mappedValueFvPatchField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -73,32 +78,32 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class mappedFixedInternalValueFvPatchField Declaration + Class mappedValueAndPatchInternalValueFvPatchField Declaration \*---------------------------------------------------------------------------*/ template -class mappedFixedInternalValueFvPatchField +class mappedValueAndPatchInternalValueFvPatchField : - public mappedFixedValueFvPatchField + public mappedValueFvPatchField { public: //- Runtime type information - TypeName("mappedFixedInternalValue"); + TypeName("mappedValueAndPatchInternalValue"); // Constructors //- Construct from patch and internal field - mappedFixedInternalValueFvPatchField + mappedValueAndPatchInternalValueFvPatchField ( const fvPatch&, const DimensionedField& ); //- Construct from patch, internal field and dictionary - mappedFixedInternalValueFvPatchField + mappedValueAndPatchInternalValueFvPatchField ( const fvPatch&, const DimensionedField&, @@ -106,25 +111,25 @@ public: ); //- Construct by mapping given - // mappedFixedInternalValueFvPatchField onto a new patch - mappedFixedInternalValueFvPatchField + // mappedValueAndPatchInternalValue onto a new patch + mappedValueAndPatchInternalValueFvPatchField ( - const mappedFixedInternalValueFvPatchField&, + const mappedValueAndPatchInternalValueFvPatchField&, const fvPatch&, const DimensionedField&, const fvPatchFieldMapper& ); //- Disallow copy without setting internal field reference - mappedFixedInternalValueFvPatchField + mappedValueAndPatchInternalValueFvPatchField ( - const mappedFixedInternalValueFvPatchField& + const mappedValueAndPatchInternalValueFvPatchField& ) = delete; //- Copy constructor setting internal field reference - mappedFixedInternalValueFvPatchField + mappedValueAndPatchInternalValueFvPatchField ( - const mappedFixedInternalValueFvPatchField&, + const mappedValueAndPatchInternalValueFvPatchField&, const DimensionedField& ); @@ -136,7 +141,11 @@ public: { return tmp> ( - new mappedFixedInternalValueFvPatchField(*this, iF) + new mappedValueAndPatchInternalValueFvPatchField + ( + *this, + iF + ) ); } @@ -160,7 +169,7 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #ifdef NoRepository - #include "mappedFixedInternalValueFvPatchField.C" + #include "mappedValueAndPatchInternalValueFvPatchField.C" #endif // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFields.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFields.C similarity index 89% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFields.C rename to src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFields.C index 0b7bb916f9..7630e853c3 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFields.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFields.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,7 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#include "mappedFixedInternalValueFvPatchFields.H" +#include "mappedValueAndPatchInternalValueFvPatchFields.H" #include "volMesh.H" #include "addToRunTimeSelectionTable.H" @@ -34,7 +34,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // -makePatchFields(mappedFixedInternalValue); +makePatchFields(mappedValueAndPatchInternalValue); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFields.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFields.H similarity index 84% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFields.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFields.H index 20f3d9ef54..3379444176 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFields.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFields.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,10 +23,10 @@ License \*---------------------------------------------------------------------------*/ -#ifndef mappedFixedInternalValueFvPatchFields_H -#define mappedFixedInternalValueFvPatchFields_H +#ifndef mappedValueAndPatchInternalValueFvPatchFields_H +#define mappedValueAndPatchInternalValueFvPatchFields_H -#include "mappedFixedInternalValueFvPatchField.H" +#include "mappedValueAndPatchInternalValueFvPatchField.H" #include "fieldTypes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -36,7 +36,7 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -makePatchTypeFieldTypedefs(mappedFixedInternalValue) +makePatchTypeFieldTypedefs(mappedValueAndPatchInternalValue) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFieldsFwd.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFieldsFwd.H similarity index 83% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFieldsFwd.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFieldsFwd.H index eb29c66a92..207a9602f8 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedFixedInternalValue/mappedFixedInternalValueFvPatchFieldsFwd.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedValueAndPatchInternalValue/mappedValueAndPatchInternalValueFvPatchFieldsFwd.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -23,8 +23,8 @@ License \*---------------------------------------------------------------------------*/ -#ifndef mappedFixedInternalValueFvPatchFieldsFwd_H -#define mappedFixedInternalValueFvPatchFieldsFwd_H +#ifndef mappedValueAndPatchInternalValueFvPatchFieldsFwd_H +#define mappedValueAndPatchInternalValueFvPatchFieldsFwd_H #include "fieldTypes.H" @@ -35,9 +35,9 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template class mappedFixedInternalValueFvPatchField; +template class mappedValueAndPatchInternalValueFvPatchField; -makePatchTypeFieldTypedefs(mappedFixedInternalValue) +makePatchTypeFieldTypedefs(mappedValueAndPatchInternalValue) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C similarity index 54% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C rename to src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C index 3ccf4677f7..767242f9de 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.C @@ -23,18 +23,16 @@ License \*---------------------------------------------------------------------------*/ -#include "mappedVelocityFluxFixedValueFvPatchField.H" +#include "mappedVelocityFluxFvPatchField.H" #include "fvPatchFieldMapper.H" #include "mappedPatchBase.H" #include "volFields.H" #include "surfaceFields.H" #include "addToRunTimeSelectionTable.H" - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -Foam::mappedVelocityFluxFixedValueFvPatchField:: -mappedVelocityFluxFixedValueFvPatchField +Foam::mappedVelocityFluxFvPatchField::mappedVelocityFluxFvPatchField ( const fvPatch& p, const DimensionedField& iF @@ -45,8 +43,7 @@ mappedVelocityFluxFixedValueFvPatchField {} -Foam::mappedVelocityFluxFixedValueFvPatchField:: -mappedVelocityFluxFixedValueFvPatchField +Foam::mappedVelocityFluxFvPatchField::mappedVelocityFluxFvPatchField ( const fvPatch& p, const DimensionedField& iF, @@ -66,28 +63,12 @@ mappedVelocityFluxFixedValueFvPatchField << " in file " << internalField().objectPath() << exit(FatalError); } - - const mappedPatchBase& mpp = refCast - ( - this->patch().patch() - ); - if (mpp.mode() == mappedPolyPatch::NEARESTCELL) - { - FatalErrorInFunction - << "Patch " << p.name() - << " of type '" << p.type() - << "' can not be used in 'nearestCell' mode" - << " of field " << internalField().name() - << " in file " << internalField().objectPath() - << exit(FatalError); - } } -Foam::mappedVelocityFluxFixedValueFvPatchField:: -mappedVelocityFluxFixedValueFvPatchField +Foam::mappedVelocityFluxFvPatchField::mappedVelocityFluxFvPatchField ( - const mappedVelocityFluxFixedValueFvPatchField& ptf, + const mappedVelocityFluxFvPatchField& ptf, const fvPatch& p, const DimensionedField& iF, const fvPatchFieldMapper& mapper @@ -109,10 +90,9 @@ mappedVelocityFluxFixedValueFvPatchField } -Foam::mappedVelocityFluxFixedValueFvPatchField:: -mappedVelocityFluxFixedValueFvPatchField +Foam::mappedVelocityFluxFvPatchField::mappedVelocityFluxFvPatchField ( - const mappedVelocityFluxFixedValueFvPatchField& ptf, + const mappedVelocityFluxFvPatchField& ptf, const DimensionedField& iF ) : @@ -123,7 +103,7 @@ mappedVelocityFluxFixedValueFvPatchField // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs() +void Foam::mappedVelocityFluxFvPatchField::updateCoeffs() { if (updated()) { @@ -135,70 +115,19 @@ void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs() int oldTag = UPstream::msgType(); UPstream::msgType() = oldTag+1; - // Get the mappedPatchBase - const mappedPatchBase& mpp = refCast - ( - mappedVelocityFluxFixedValueFvPatchField::patch().patch() - ); - const fvMesh& nbrMesh = refCast(mpp.sampleMesh()); - const word& fieldName = internalField().name(); - const volVectorField& UField = - nbrMesh.lookupObject(fieldName); + const mappedPatchBase& mapper = + refCast(patch().patch()); + const fvMesh& nbrMesh = refCast(mapper.nbrMesh()); + const label nbrPatchi = mapper.nbrPolyPatch().index(); + const volVectorField& UField = + refCast(internalField()); surfaceScalarField& phiField = nbrMesh.lookupObjectRef(phiName_); - vectorField newUValues; - scalarField newPhiValues; - - switch (mpp.mode()) - { - case mappedPolyPatch::NEARESTFACE: - { - vectorField allUValues(nbrMesh.nFaces(), Zero); - scalarField allPhiValues(nbrMesh.nFaces(), 0.0); - - forAll(UField.boundaryField(), patchi) - { - const fvPatchVectorField& Upf = UField.boundaryField()[patchi]; - const scalarField& phipf = phiField.boundaryField()[patchi]; - - label faceStart = Upf.patch().start(); - - forAll(Upf, facei) - { - allUValues[faceStart + facei] = Upf[facei]; - allPhiValues[faceStart + facei] = phipf[facei]; - } - } - - newUValues = mpp.distribute(allUValues); - newPhiValues = mpp.distribute(allPhiValues); - - break; - } - case mappedPolyPatch::NEARESTPATCHFACE: - case mappedPolyPatch::NEARESTPATCHFACEAMI: - { - const label nbrPatchID = - nbrMesh.boundaryMesh().findPatchID(mpp.samplePatch()); - - newUValues = mpp.distribute(UField.boundaryField()[nbrPatchID]); - newPhiValues = mpp.distribute(phiField.boundaryField()[nbrPatchID]); - - break; - } - default: - { - FatalErrorInFunction - << "patch can only be used in NEARESTPATCHFACE, " - << "NEARESTPATCHFACEAMI or NEARESTFACE mode" << nl - << abort(FatalError); - } - } - - operator==(newUValues); - phiField.boundaryFieldRef()[patch().index()] == newPhiValues; + operator==(mapper.distribute(UField.boundaryField()[nbrPatchi])); + phiField.boundaryFieldRef()[patch().index()] == + mapper.distribute(phiField.boundaryField()[nbrPatchi]); // Restore tag UPstream::msgType() = oldTag; @@ -207,7 +136,7 @@ void Foam::mappedVelocityFluxFixedValueFvPatchField::updateCoeffs() } -void Foam::mappedVelocityFluxFixedValueFvPatchField::write +void Foam::mappedVelocityFluxFvPatchField::write ( Ostream& os ) const @@ -225,7 +154,7 @@ namespace Foam makePatchTypeField ( fvPatchVectorField, - mappedVelocityFluxFixedValueFvPatchField + mappedVelocityFluxFvPatchField ); } diff --git a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.H similarity index 76% rename from src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.H rename to src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.H index d376429867..bde05ef5a0 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFluxFixedValue/mappedVelocityFluxFixedValueFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/derived/mappedVelocityFlux/mappedVelocityFluxFvPatchField.H @@ -22,11 +22,11 @@ License along with OpenFOAM. If not, see . Class - Foam::mappedVelocityFluxFixedValueFvPatchField + Foam::mappedVelocityFluxFvPatchField Description - This boundary condition maps the velocity and flux from a neighbour patch - to this patch + This boundary condition maps the velocity and flux from a neighbouring + patch to this patch. Usage \table @@ -39,17 +39,12 @@ Usage { type mappedVelocityFlux; - phi phi; - value uniform 0; // place holder + value uniform (0 0 0); } \endverbatim - The underlying sample mode should be set to \c nearestPatchFace or - \c nearestFace - - Note: - This boundary condition can only be applied to patches that are of - the \c mappedPolyPatch type. + This boundary condition can only be applied to patches that are of + mappedPatchBase type. See also Foam::mappedPatchBase @@ -58,12 +53,12 @@ See also Foam::fixedValueFvPatchVectorField SourceFiles - mappedVelocityFluxFixedValueFvPatchField.C + mappedVelocityFluxFvPatchField.C \*---------------------------------------------------------------------------*/ -#ifndef mappedVelocityFluxFixedValueFvPatchField_H -#define mappedVelocityFluxFixedValueFvPatchField_H +#ifndef mappedVelocityFluxFvPatchField_H +#define mappedVelocityFluxFvPatchField_H #include "fixedValueFvPatchFields.H" #include "mappedFvPatch.H" @@ -74,10 +69,10 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class mappedVelocityFluxFixedValueFvPatch Declaration + Class mappedVelocityFluxFvPatch Declaration \*---------------------------------------------------------------------------*/ -class mappedVelocityFluxFixedValueFvPatchField +class mappedVelocityFluxFvPatchField : public fixedValueFvPatchVectorField { @@ -95,14 +90,14 @@ public: // Constructors //- Construct from patch and internal field - mappedVelocityFluxFixedValueFvPatchField + mappedVelocityFluxFvPatchField ( const fvPatch&, const DimensionedField& ); //- Construct from patch, internal field and dictionary - mappedVelocityFluxFixedValueFvPatchField + mappedVelocityFluxFvPatchField ( const fvPatch&, const DimensionedField&, @@ -110,26 +105,26 @@ public: ); //- Construct by mapping given - // mappedVelocityFluxFixedValueFvPatchField + // mappedVelocityFluxFvPatchField // onto a new patch - mappedVelocityFluxFixedValueFvPatchField + mappedVelocityFluxFvPatchField ( - const mappedVelocityFluxFixedValueFvPatchField&, + const mappedVelocityFluxFvPatchField&, const fvPatch&, const DimensionedField&, const fvPatchFieldMapper& ); //- Disallow copy without setting internal field reference - mappedVelocityFluxFixedValueFvPatchField + mappedVelocityFluxFvPatchField ( - const mappedVelocityFluxFixedValueFvPatchField& + const mappedVelocityFluxFvPatchField& ) = delete; //- Copy constructor setting internal field reference - mappedVelocityFluxFixedValueFvPatchField + mappedVelocityFluxFvPatchField ( - const mappedVelocityFluxFixedValueFvPatchField&, + const mappedVelocityFluxFvPatchField&, const DimensionedField& ); @@ -141,7 +136,7 @@ public: { return tmp ( - new mappedVelocityFluxFixedValueFvPatchField(*this, iF) + new mappedVelocityFluxFvPatchField(*this, iF) ); } diff --git a/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedFvPatch.H b/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedFvPatch.H index 7709b6cdab..57ae61e633 100644 --- a/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedFvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedFvPatch.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,9 +24,6 @@ License Class Foam::mappedFvPatch -Description - Foam::mappedFvPatch - SourceFiles mappedFvPatch.C diff --git a/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedInternalFvPatch.C b/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedInternalFvPatch.C new file mode 100644 index 0000000000..b0170847e9 --- /dev/null +++ b/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedInternalFvPatch.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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 "mappedInternalFvPatch.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(mappedInternalFvPatch, 0); + addToRunTimeSelectionTable(fvPatch, mappedInternalFvPatch, polyPatch); +} + +// ************************************************************************* // diff --git a/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedInternalFvPatch.H b/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedInternalFvPatch.H new file mode 100644 index 0000000000..0a837beed8 --- /dev/null +++ b/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedInternalFvPatch.H @@ -0,0 +1,76 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2022 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::mappedInternalFvPatch + +SourceFiles + mappedInternalFvPatch.C + +\*---------------------------------------------------------------------------*/ + +#ifndef mappedInternalFvPatch_H +#define mappedInternalFvPatch_H + +#include "fvPatch.H" +#include "mappedInternalPolyPatch.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class mappedInternalFvPatch Declaration +\*---------------------------------------------------------------------------*/ + +class mappedInternalFvPatch +: + public fvPatch +{ + +public: + + //- Runtime type information + TypeName(mappedInternalPolyPatch::typeName_()); + + + // Constructors + + //- Construct from components + mappedInternalFvPatch(const polyPatch& patch, const fvBoundaryMesh& bm) + : + fvPatch(patch, bm) + {} +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedWallFvPatch.H b/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedWallFvPatch.H index 0a25ca0621..5fd6a4c7d5 100644 --- a/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedWallFvPatch.H +++ b/src/finiteVolume/fvMesh/fvPatches/derived/mapped/mappedWallFvPatch.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,9 +24,6 @@ License Class Foam::mappedWallFvPatch -Description - Foam::mappedWallFvPatch - SourceFiles mappedWallFvPatch.C diff --git a/src/meshTools/Make/files b/src/meshTools/Make/files index 07c31357ec..360e61d5fe 100644 --- a/src/meshTools/Make/files +++ b/src/meshTools/Make/files @@ -256,6 +256,10 @@ mappedPatches/mappedPointPatch/mappedPointPatch.C mappedPatches/mappedPointPatch/mappedWallPointPatch.C mappedPatches/mappedPointPatch/mappedExtrudedWallPointPatch.C +mappedPatches/mappedInternalPatchBase/mappedInternalPatchBase.C +mappedPatches/mappedInternalPolyPatch/mappedInternalPolyPatch.C +mappedPatches/mappedInternalPointPatch/mappedInternalPointPatch.C + meshStructure/meshStructure.C meshStructure/topoDistanceData.C meshStructure/pointTopoDistanceData.C diff --git a/src/meshTools/layerInfo/LayerInfoDataI.H b/src/meshTools/layerInfo/LayerInfoDataI.H index 247d0b8f2a..101d93c444 100644 --- a/src/meshTools/layerInfo/LayerInfoDataI.H +++ b/src/meshTools/layerInfo/LayerInfoDataI.H @@ -68,7 +68,12 @@ inline void Foam::LayerInfoData::transform TrackingData& td ) { - data_ = transform.transform(data_); + if (transform.transformsPosition()) + { + FatalErrorInFunction + << "Cannot have a transform within a set of mesh layers" + << exit(FatalError); + } } diff --git a/src/meshTools/mappedPatches/mappedInternalPatchBase/mappedInternalPatchBase.C b/src/meshTools/mappedPatches/mappedInternalPatchBase/mappedInternalPatchBase.C new file mode 100644 index 0000000000..d188845157 --- /dev/null +++ b/src/meshTools/mappedPatches/mappedInternalPatchBase/mappedInternalPatchBase.C @@ -0,0 +1,501 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2011-2022 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 "mappedInternalPatchBase.H" +#include "SubField.H" +#include "Time.H" +#include "triPointRef.H" +#include "treeDataCell.H" +#include "indexedOctree.H" +#include "globalIndex.H" +#include "RemoteData.H" +#include "OBJstream.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(mappedInternalPatchBase, 0); + + template<> + const char* Foam::NamedEnum + < + Foam::mappedInternalPatchBase::offsetMode, + 2 + >::names[] = + { + "normal", + "direction" + }; +} + + +const Foam::NamedEnum + Foam::mappedInternalPatchBase::offsetModeNames_; + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::mappedInternalPatchBase::offsetMode +Foam::mappedInternalPatchBase::readOffsetMode +( + const dictionary& dict +) const +{ + if (dict.found("offsetMode")) + { + return offsetModeNames_.read(dict.lookup("offsetMode")); + } + else + { + const bool haveDistance = dict.found("distance"); + const bool haveOffset = dict.found("offset"); + + if (haveDistance == haveOffset) + { + // Error. Demand "offsetMode" setting to disambiguate. + return offsetModeNames_.read(dict.lookup("offsetMode")); + } + else if (haveDistance) + { + return NORMAL; + } + else + { + return DIRECTION; + } + } +} + + +void Foam::mappedInternalPatchBase::calcMapping() const +{ + if (mapPtr_.valid()) + { + FatalErrorInFunction + << "Mapping already calculated" << exit(FatalError); + } + + const polyMesh& nbrMesh = this->nbrMesh(); + + const globalIndex patchGlobalIndex(patch_.size()); + + // Find processor and cell/face indices of samples + labelList sampleGlobalPatchFaces, sampleIndices; + { + // Gather the sample points into a single globally indexed list + List allPoints(patchGlobalIndex.size()); + { + List procSamplePoints(Pstream::nProcs()); + procSamplePoints[Pstream::myProcNo()] = this->samplePoints(); + Pstream::gatherList(procSamplePoints); + Pstream::scatterList(procSamplePoints); + + forAll(procSamplePoints, proci) + { + forAll(procSamplePoints[proci], procSamplei) + { + allPoints + [ + patchGlobalIndex.toGlobal(proci, procSamplei) + ] = procSamplePoints[proci][procSamplei]; + } + } + } + + // List of possibly remote sampling cells + List> allNearest(patchGlobalIndex.size()); + + // Find containing cell for every sampling point + const indexedOctree& tree = nbrMesh.cellTree(); + forAll(allPoints, alli) + { + const point& p = allPoints[alli]; + + const label celli = tree.findInside(p); + + if (celli != -1) + { + const point& cc = nbrMesh.cellCentres()[celli]; + + allNearest[alli].proci = Pstream::myProcNo(); + allNearest[alli].elementi = celli; + allNearest[alli].data = magSqr(cc - p); + } + } + + // Find nearest. Combine on master. + Pstream::listCombineGather + ( + allNearest, + RemoteData::smallestEqOp() + ); + Pstream::listCombineScatter(allNearest); + + // Determine the number of missing samples (no reduction necessary as + // this is computed from synchronised data) + label nNotFound = 0; + forAll(allPoints, alli) + { + if (allNearest[alli].proci == -1) + { + nNotFound ++; + } + } + + // If any points were not found within cells then re-search for them + // using a nearest test, which should not fail. Warn that this is + // happening. If any points were not found for some other method, then + // fail. + if (nNotFound) + { + WarningInFunction + << "Did not find a containing cell for " << nNotFound + << " out of " << returnReduce(patch_.size(), sumOp