From 69eccc77424665e3cf82c064c8caf9d3f4da50bf Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Tue, 7 May 2019 15:58:23 +0100 Subject: [PATCH] fieldMapper: Moved distributed functionality to distributedWeightedFvPatchFieldMapper --- .../fields/Fields/fieldMapper/fieldMapper.C | 9 -- .../fields/Fields/fieldMapper/fieldMapper.H | 7 - .../Fields/fieldMapper/fieldMapperTemplates.C | 60 ++----- .../decompose/decompose/fvFieldDecomposer.H | 49 +----- src/sampling/Make/files | 1 + .../distributedWeightedFvPatchFieldMapper.C | 146 ++++++++++++++++++ .../distributedWeightedFvPatchFieldMapper.H | 129 +++++++++++----- ...butedWeightedFvPatchFieldMapperTemplates.C | 99 ++++++++++++ 8 files changed, 353 insertions(+), 147 deletions(-) create mode 100644 src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapper.C create mode 100644 src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapperTemplates.C diff --git a/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapper.C b/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapper.C index b4281e1187..7395b377c3 100644 --- a/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapper.C +++ b/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapper.C @@ -27,15 +27,6 @@ License // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -const Foam::mapDistributeBase& Foam::fieldMapper::distributeMap() const -{ - FatalErrorInFunction - << "attempt to access null distributeMap" - << abort(FatalError); - return *(new mapDistributeBase()); -} - - const Foam::labelUList& Foam::fieldMapper::directAddressing() const { FatalErrorInFunction diff --git a/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapper.H b/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapper.H index ee166b6c16..d4fdb0b713 100644 --- a/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapper.H +++ b/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapper.H @@ -75,13 +75,6 @@ public: virtual bool direct() const = 0; - virtual bool distributed() const - { - return false; - } - - virtual const mapDistributeBase& distributeMap() const; - //- Are there unmapped values? I.e. do all size() elements get // get value virtual bool hasUnmapped() const = 0; diff --git a/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapperTemplates.C b/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapperTemplates.C index 306fa2ba39..b0a8c4c9d7 100644 --- a/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapperTemplates.C +++ b/src/OpenFOAM/fields/Fields/fieldMapper/fieldMapperTemplates.C @@ -30,58 +30,22 @@ License template void Foam::fieldMapper::map(Field& f, const Field& mapF) const { - if (distributed()) + if + ( + direct() + && notNull(directAddressing()) + && directAddressing().size() + ) { - // Fetch remote parts of mapF - const mapDistributeBase& distMap = distributeMap(); - Field newMapF(mapF); - - // Moved flux "flip" functionality to higher level - // if (applyFlip) - // { - // distMap.distribute(newMapF); - // } - // else - { - distMap.distribute(newMapF, noOp()); - } - - if (direct() && notNull(directAddressing())) - { - f.map(newMapF, directAddressing()); - } - else if (!direct()) - { - f.map(newMapF, addressing(), weights()); - } - else if (direct() && isNull(directAddressing())) - { - // Special case, no local Assume ordering already correct - // from distribution. Note: this behaviour is different compared - // to local - f.transfer(newMapF); - f.setSize(size()); - } + f.map(mapF, directAddressing()); + } + else if (!direct() && addressing().size()) + { + f.map(mapF, addressing(), weights()); } else { - if - ( - direct() - && notNull(directAddressing()) - && directAddressing().size() - ) - { - f.map(mapF, directAddressing()); - } - else if (!direct() && addressing().size()) - { - f.map(mapF, addressing(), weights()); - } - else - { - f.setSize(size()); - } + f.setSize(size()); } } diff --git a/src/parallel/decompose/decompose/fvFieldDecomposer.H b/src/parallel/decompose/decompose/fvFieldDecomposer.H index d1604d2299..408e40e542 100644 --- a/src/parallel/decompose/decompose/fvFieldDecomposer.H +++ b/src/parallel/decompose/decompose/fvFieldDecomposer.H @@ -53,6 +53,7 @@ class IOobjectList; class fvFieldDecomposer { + public: //- Patch field decomposer class @@ -147,54 +148,6 @@ public: }; - //- Processor patch field decomposer class. Surface field is assumed - // to have direction (so manipulates sign when mapping) - class processorSurfacePatchFieldDecomposer - : - public fvPatchFieldMapper - { - labelListList addressing_; - scalarListList weights_; - - public: - - //- Construct given addressing - processorSurfacePatchFieldDecomposer - ( - const labelUList& addressingSlice - ); - - - // Member functions - - label size() const - { - return addressing_.size(); - } - - bool direct() const - { - return false; - } - - //- Are there unmapped values - bool hasUnmapped() const - { - return false; - } - - const labelListList& addressing() const - { - return addressing_; - } - - const scalarListList& weights() const - { - return weights_; - } - }; - - private: // Private data diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 1c30823efc..99bafc9da9 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -53,6 +53,7 @@ graphField/makeGraph.C meshToMesh/meshToMesh.C meshToMesh/meshToMeshParallelOps.C +meshToMesh/distributedWeightedFvPatchFieldMapper.C meshToMeshMethods = meshToMesh/calcMethod $(meshToMeshMethods)/meshToMeshMethod/meshToMeshMethod.C $(meshToMeshMethods)/meshToMeshMethod/meshToMeshMethodNew.C diff --git a/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapper.C b/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapper.C new file mode 100644 index 0000000000..396f8d6ce9 --- /dev/null +++ b/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapper.C @@ -0,0 +1,146 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2019 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 "distributedWeightedFvPatchFieldMapper.H" + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +const Foam::labelListList& +Foam::distributedWeightedFvPatchFieldMapper::addressing() const +{ + return addressing_; +} + + +const Foam::scalarListList& +Foam::distributedWeightedFvPatchFieldMapper::weights() const +{ + return weights_; +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +Foam::tmp> +Foam::distributedWeightedFvPatchFieldMapper::operator() +( + const Field& mapF +) const +{ + return map(mapF); +} + + +Foam::tmp> +Foam::distributedWeightedFvPatchFieldMapper::operator() +( + const Field& mapF +) const +{ + return map(mapF); +} + + +Foam::tmp> +Foam::distributedWeightedFvPatchFieldMapper::operator() +( + const Field& mapF +) const +{ + return map(mapF); +} + + +Foam::tmp> +Foam::distributedWeightedFvPatchFieldMapper::operator() +( + const Field& mapF +) const +{ + return map(mapF); +} + + +Foam::tmp> +Foam::distributedWeightedFvPatchFieldMapper::operator() +( + const Field& mapF +) const +{ + return map(mapF); +} + + +void Foam::distributedWeightedFvPatchFieldMapper::operator() +( + Field& f, + const Field& mapF +) const +{ + return map(f, mapF); +} + + +void Foam::distributedWeightedFvPatchFieldMapper::operator() +( + Field& f, + const Field& mapF +) const +{ + return map(f, mapF); +} + + +void Foam::distributedWeightedFvPatchFieldMapper::operator() +( + Field& f, + const Field& mapF +) const +{ + return map(f, mapF); +} + + +void Foam::distributedWeightedFvPatchFieldMapper::operator() +( + Field& f, + const Field& mapF +) const +{ + return map(f, mapF); +} + + +void Foam::distributedWeightedFvPatchFieldMapper::operator() +( + Field& f, + const Field& mapF +) const +{ + return map(f, mapF); +} + + +// ************************************************************************* // diff --git a/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapper.H b/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapper.H index 73db0b8391..987b1741bb 100644 --- a/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapper.H +++ b/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapper.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2015-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2015-2019 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,15 +48,27 @@ class distributedWeightedFvPatchFieldMapper : public fvPatchFieldMapper { - const label singlePatchProc_; + // Private member data - const mapDistributeBase* distMapPtr_; + const label singlePatchProc_; - const labelListList& addressing_; + const mapDistributeBase* distMapPtr_; - const scalarListList& weights_; + const labelListList& addressing_; + + const scalarListList& weights_; + + bool hasUnmapped_; + + + // Private member functions + + template + void map(Field& f, const Field& mapF) const; + + template + tmp> map(const Field& f) const; - bool hasUnmapped_; public: @@ -99,6 +111,7 @@ public: } } + //- Destructor virtual ~distributedWeightedFvPatchFieldMapper() {} @@ -108,9 +121,9 @@ public: virtual label size() const { - if (distributed()) + if (singlePatchProc_ == -1) { - return distributeMap().constructSize(); + return distMapPtr_->constructSize(); } else { @@ -123,48 +136,94 @@ public: return false; } - virtual bool distributed() const - { - return singlePatchProc_ == -1; - } - - virtual const mapDistributeBase& distributeMap() const - { - if (!distMapPtr_) - { - FatalErrorIn - ( - "distributedWeightedFvPatchFieldMapper::" - "distributeMap()" - ) << "Cannot ask for distributeMap on a non-distributed" - << " mapper" << exit(FatalError); - } - return *distMapPtr_; - } - virtual bool hasUnmapped() const { return hasUnmapped_; } - virtual const labelListList& addressing() const - { - return addressing_; - } + virtual const labelListList& addressing() const; - virtual const scalarListList& weights() const - { - return weights_; - } + virtual const scalarListList& weights() const; + + // Member Operators + + virtual void operator() + ( + Field& f, + const Field& mapF + ) const; + + virtual void operator() + ( + Field& f, + const Field& mapF + ) const; + + virtual void operator() + ( + Field& f, + const Field& mapF + ) const; + + virtual void operator() + ( + Field& f, + const Field& mapF + ) const; + + virtual void operator() + ( + Field& f, + const Field& mapF + ) const; + + template + void operator()(Field& f, const tmp>& tmapF) const; + + + virtual tmp> operator() + ( + const Field& mapF + ) const; + + virtual tmp> operator() + ( + const Field& mapF + ) const; + + virtual tmp> operator() + ( + const Field& mapF + ) const; + + virtual tmp> operator() + ( + const Field& mapF + ) const; + + virtual tmp> operator() + ( + const Field& mapF + ) const; + + template + tmp> operator()(const tmp>& tmapF) const; }; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#ifdef NoRepository + #include "distributedWeightedFvPatchFieldMapperTemplates.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + #endif // ************************************************************************* // diff --git a/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapperTemplates.C b/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapperTemplates.C new file mode 100644 index 0000000000..a4d9b0148f --- /dev/null +++ b/src/sampling/meshToMesh/distributedWeightedFvPatchFieldMapperTemplates.C @@ -0,0 +1,99 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2019 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 "distributedWeightedFvPatchFieldMapper.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template +void Foam::distributedWeightedFvPatchFieldMapper::map +( + Field& f, + const Field& mapF +) const +{ + if (singlePatchProc_ == -1) + { + // Fetch remote parts of mapF + const mapDistributeBase& distMap = *distMapPtr_; + Field newMapF(mapF); + + // Moved flux "flip" functionality to higher level + // if (applyFlip) + // { + // distMap.distribute(newMapF); + // } + // else + { + distMap.distribute(newMapF, noOp()); + } + + f.map(newMapF, addressing(), weights()); + } + else + { + f.map(mapF, addressing(), weights()); + } +} + + +template +Foam::tmp> Foam::distributedWeightedFvPatchFieldMapper::map +( + const Field& mapF +) const +{ + tmp> tf(new Field(size())); + map(tf.ref(), mapF); + return tf; +} + + +template +void Foam::distributedWeightedFvPatchFieldMapper::operator() +( + Field& f, + const tmp>& tmapF +) const +{ + map(f, tmapF()); + tmapF.clear(); +} + + +template +Foam::tmp> +Foam::distributedWeightedFvPatchFieldMapper::operator() +( + const tmp>& tmapF +) const +{ + tmp> tf(map(tmapF())); + tmapF.clear(); + return tf; +} + + +// ************************************************************************* //