/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::meshToMesh
Description
Class to calculate the cell-addressing between two overlapping meshes
Mapping is performed using a run-time selectable interpolation mothod
SeeAlso
meshToMeshMethod
SourceFiles
meshToMesh.C
meshToMeshParallelOps.C
meshToMeshTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef Foam_meshToMesh_H
#define Foam_meshToMesh_H
#include "polyMesh.H"
#include "treeBoundBox.H"
#include "mapDistribute.H"
#include "volFieldsFwd.H"
#include "Enum.H"
#include "AMIPatchToPatchInterpolation.H"
#include "pointList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class meshToMesh Declaration
\*---------------------------------------------------------------------------*/
class meshToMesh
{
public:
// Public data types
//- Enumeration specifying interpolation method
enum class interpolationMethod
{
imDirect,
imMapNearest,
imCellVolumeWeight,
imCorrectedCellVolumeWeight
};
static const Enum interpolationMethodNames_;
//- Enumeration specifying processor parallel map construction method
enum class procMapMethod
{
pmAABB,
pmLOD
};
static const Enum procMapMethodNames_;
private:
// Private data
//- Reference to the source mesh
const polyMesh& srcRegion_;
//- Reference to the target mesh
const polyMesh& tgtRegion_;
//- Processor parallel map construction method
procMapMethod procMapMethod_;
//- List of target patch IDs per source patch (local index)
List srcPatchID_;
//- List of source patch IDs per target patch (local index)
List tgtPatchID_;
//- List of AMIs between source and target patches
PtrList patchAMIs_;
//- Cutting patches whose values are set using a zero-gradient condition
List cuttingPatches_;
//- Source to target cell addressing
labelListList srcToTgtCellAddr_;
//- Target to source cell addressing
labelListList tgtToSrcCellAddr_;
//- Source to target cell interpolation weights
scalarListList srcToTgtCellWght_;
//- Target to source cell interpolation weights
scalarListList tgtToSrcCellWght_;
// Vectors from cell centre to overlap volume for 2nd order correction
// (only set for corrected methods)
//- Source to target cell offset vectors
pointListList srcToTgtCellVec_;
//- Target to source cell offset vectors
pointListList tgtToSrcCellVec_;
//- Cell total volume in overlap region [m3]
scalar V_;
//- Index of processor that holds all of both sides.
//- The value is -1 for distributed cases
label singleMeshProc_;
//- Source map pointer - parallel running only
autoPtr srcMapPtr_;
//- Target map pointer - parallel running only
autoPtr tgtMapPtr_;
// Private Member Functions
//- Helper function to add a constant offset to a list
template
void add(UList& fld, const label offset) const;
//- Helper function to interpolate internal field. Optionally uses
// gradient. Template specialisations for tensor types below
template
void mapInternalSrcToTgt
(
const VolumeField& field,
const CombineOp& cop,
VolumeField& result,
const bool secondOrder
) const;
//- Helper function to interpolate internal field. Optionally uses
// gradient. Template specialisations for tensor types below
template
void mapInternalTgtToSrc
(
const VolumeField& field,
const CombineOp& cop,
VolumeField& result,
const bool secondOrder
) const;
//- Helper function to interpolate patch field. Template
// specialisations below
template
void mapAndOpSrcToTgt
(
const AMIPatchToPatchInterpolation& AMI,
const Field& srcField,
Field& tgtField,
const CombineOp& cop
) const;
//- Helper function to interpolate patch field. Template
// specialisations below
template
void mapAndOpTgtToSrc
(
const AMIPatchToPatchInterpolation& AMI,
Field& srcField,
const Field& tgtField,
const CombineOp& cop
) const;
//- Return src cell IDs for the overlap region
labelList maskCells(const polyMesh& src, const polyMesh& tgt) const;
//- Normalise the interpolation weights
void normaliseWeights
(
const word& descriptor,
const labelListList& addr,
scalarListList& wght
) const;
//- Calculate the addressing between overlapping regions of src and tgt
// meshes
void calcAddressing
(
const word& methodName,
const polyMesh& src,
const polyMesh& tgt
);
//- Calculate - main driver function
void calculate(const word& methodName, const bool normalise);
//- Calculate patch overlap
void calculatePatchAMIs(const word& amiMethodName);
//- Constructor helper
void constructNoCuttingPatches
(
const word& methodName,
const word& AMIMethodName,
const bool interpAllPatches
);
//- Constructor helper
void constructFromCuttingPatches
(
const word& methodName,
const word& AMIMethodName,
const HashTable& patchMap,
const wordList& cuttingPatches,
const bool normalise
);
// Parallel operations
//- Determine whether the meshes are split across multiple
//- processors
label calcDistribution
(
const polyMesh& src,
const polyMesh& tgt
) const;
//- Determine which processor bounding-boxes overlap
label calcOverlappingProcs
(
const List& procBb,
const boundBox& bb,
boolList& overlaps
) const;
//- Calculate the mapping between processors
autoPtr calcProcMap
(
const polyMesh& src,
const polyMesh& tgt
) const;
//- Distribute mesh info from 'my' processor to others
void distributeCells
(
const mapDistribute& map,
const polyMesh& tgtMesh,
const globalIndex& globalI,
List& points,
List& nInternalFaces,
List& faces,
List& faceOwner,
List& faceNeighbour,
List& cellIDs,
List& nbrProcIDs,
List& procLocalFaceIDs
) const;
//- Collect pieces of tgt mesh from other processors and restructure
void distributeAndMergeCells
(
const mapDistribute& map,
const polyMesh& tgt,
const globalIndex& globalI,
pointField& tgtPoints,
faceList& tgtFaces,
labelList& tgtFaceOwners,
labelList& tgtFaceNeighbours,
labelList& tgtCellIDs
) const;
//- No copy construct
meshToMesh(const meshToMesh&) = delete;
//- No copy assignment
void operator=(const meshToMesh&) = delete;
public:
//- Run-time type information
TypeName("meshToMesh");
//- Construct from source and target meshes
meshToMesh
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod method,
const procMapMethod mapMethod = procMapMethod::pmAABB,
const bool interpAllPatches = true
);
//- Construct from source and target meshes, generic mapping methods
meshToMesh
(
const polyMesh& src,
const polyMesh& tgt,
const word& methodName, // internal mapping
const word& AMIMethodName, // boundary mapping
const procMapMethod mapMethod = procMapMethod::pmAABB,
const bool interpAllPatches = true
);
//- Construct from source and target meshes
meshToMesh
(
const polyMesh& src,
const polyMesh& tgt,
const interpolationMethod method,
const HashTable& patchMap,
const wordList& cuttingPatches,
const procMapMethod mapMethod = procMapMethod::pmAABB,
const bool normalise = true
);
//- Construct from source and target meshes, generic mapping methods
meshToMesh
(
const polyMesh& src,
const polyMesh& tgt,
const word& methodName, // internal mapping
const word& AMIMethodName, // boundary mapping
const HashTable& patchMap,
const wordList& cuttingPatches,
const procMapMethod mapMethod = procMapMethod::pmAABB,
const bool normalise = true
);
//- Destructor
virtual ~meshToMesh();
// Member Functions
// Access
//- Return const access to the source mesh
inline const polyMesh& srcRegion() const;
//- Return const access to the target mesh
inline const polyMesh& tgtRegion() const;
//- Return const access to the source to target cell addressing
inline const labelListList& srcToTgtCellAddr() const;
//- Return const access to the target to source cell addressing
inline const labelListList& tgtToSrcCellAddr() const;
//- Return const access to the source to target cell weights
inline const scalarListList& srcToTgtCellWght() const;
//- Return const access to the target to source cell weights
inline const scalarListList& tgtToSrcCellWght() const;
//- Return const access to the source to target offset vectors
inline const pointListList& srcToTgtCellVec() const;
//- Return const access to the target to source offset vectors
inline const pointListList& tgtToSrcCellVec() const;
//- Return const access to the overlap volume
inline scalar V() const;
//- Conversion between mesh and patch interpolation methods
static word interpolationMethodAMI
(
const interpolationMethod method
);
//- Return the list of AMIs between source and target patches
inline const PtrList&
patchAMIs() const;
// Mapping
//- Distributed across processors (singleMeshProc == -1)
inline bool distributed() const noexcept;
//- Pointer to the source map (if distributed).
//- Can be checked as a bool.
inline const mapDistribute* hasSrcMap() const noexcept;
//- Pointer to the target map (if distributed).
//- Can be checked as a bool.
inline const mapDistribute* hasTgtMap() const noexcept;
//- Source map pointer - valid if no singleMeshProc
inline const autoPtr& srcMap() const noexcept;
//- Target map pointer - valid if no singleMeshProc
inline const autoPtr& tgtMap() const noexcept;
// Evaluation
// Source-to-target field mapping
//- Map field from src to tgt mesh with defined operation.
// Values passed in via 'result' are used to initialise the
// return value
template
void mapSrcToTgt
(
const UList& srcFld,
const CombineOp& cop,
List& result
) const;
//- Map extrapolated field (using gradient) from src to tgt
// mesh with defined operation. Falls back to non-extrapolated
// mapping (above) if not constructed with method that supports
// getting offset vectors. Extrapolation only for internal
// values. Values passed in via 'result' are used to
// initialise the return value.
template
void mapSrcToTgt
(
const UList& srcField,
const UList::type>&,
const CombineOp& cop,
List& result
) const;
//- Return the src field mapped to the tgt mesh with a defined
// operation. Initial values of the result are set to zero
template
tmp> mapSrcToTgt
(
const Field& srcFld,
const CombineOp& cop
) const;
//- Convenience function to map a tmp field to the tgt mesh
// with a defined operation
template
tmp> mapSrcToTgt
(
const tmp>& tsrcFld,
const CombineOp& cop
) const;
//- Convenience function to map a field to the tgt mesh with a
// default operation (plusEqOp)
template
tmp> mapSrcToTgt
(
const Field& srcFld
) const;
//- Convenience function to map a tmp field to the tgt mesh
// with a default operation (plusEqOp)
template
tmp> mapSrcToTgt
(
const tmp>& tsrcFld
) const;
// Target-to-source field mapping
//- Map field from tgt to src mesh with defined operation
// Values passed in via 'result' are used to initialise the
// return value
template
void mapTgtToSrc
(
const UList& tgtFld,
const CombineOp& cop,
List& result
) const;
//- Map extrapolated field (using gradient) from tgt to src
// mesh with defined operation. Falls back to non-extrapolated
// mapping (above) if not constructed with method that supports
// getting offset vectors. Extrapolation only for internal
// values. Values passed in via 'result' are used to
// initialise the return value
template
void mapTgtToSrc
(
const UList& srcField,
const UList::type>&,
const CombineOp& cop,
List& result
) const;
//- Return the tgt field mapped to the src mesh with a defined
// operation. Initial values of the result are set to zero
template
tmp> mapTgtToSrc
(
const Field& tgtFld,
const CombineOp& cop
) const;
//- Convenience function to map a tmp field to the src mesh
// with a defined operation
template
tmp> mapTgtToSrc
(
const tmp>& ttgtFld,
const CombineOp& cop
) const;
//- Convenience function to map a field to the src mesh with a
// default operation (plusEqOp)
template
tmp> mapTgtToSrc
(
const Field& tgtFld
) const;
//- Convenience function to map a tmp field to the src mesh
// with a default operation (plusEqOp)
template
tmp> mapTgtToSrc
(
const tmp>& ttgtFld
) const;
// Source-to-target volume field mapping
//- Interpolate a field with a defined operation. Values
// passed in via 'result' are used to initialise the return
// value. Optionally uses gradient correction (internal
// field only) if interpolationMethod supports it
template
void mapSrcToTgt
(
const VolumeField& field,
const CombineOp& cop,
VolumeField& result,
const bool secondOrder = true
) const;
//- Interpolate a field with a defined operation. The initial
// values of the result are set to zero
template
tmp> mapSrcToTgt
(
const VolumeField& field,
const CombineOp& cop,
const bool secondOrder = true
) const;
//- Interpolate a tmp field with a defined operation. The
// initial values of the result are set to zero
template
tmp> mapSrcToTgt
(
const tmp>& tfield,
const CombineOp& cop,
const bool secondOrder = true
) const;
//- Convenience function to map a field with a default
// operation (plusEqOp)
template
tmp> mapSrcToTgt
(
const VolumeField& field,
const bool secondOrder = true
) const;
//- Convenience function to map a tmp field with a default
// operation (plusEqOp)
template
tmp> mapSrcToTgt
(
const tmp>& tfield,
const bool secondOrder = true
) const;
// Target-to-source volume field mapping
//- Interpolate a field with a defined operation. Values
// passed in via 'result' are used to initialise the return
// value. Optionally uses gradient correction (internal
// field only) if interpolationMethod supports it
template
void mapTgtToSrc
(
const VolumeField& field,
const CombineOp& cop,
VolumeField& result,
const bool secondOrder = true
) const;
//- Interpolate a field with a defined operation. The initial
// values of the result are set to zero
template
tmp> mapTgtToSrc
(
const VolumeField& field,
const CombineOp& cop,
const bool secondOrder = true
) const;
//- Interpolate a tmp field with a defined operation. The
// initial values of the result are set to zero
template
tmp> mapTgtToSrc
(
const tmp>&
tfield,
const CombineOp& cop,
const bool secondOrder = true
) const;
//- Convenience function to map a field with a default
// operation (plusEqOp)
template
tmp> mapTgtToSrc
(
const VolumeField& field,
const bool secondOrder = true
) const;
//- Convenience function to map a tmp field with a default
// operation (plusEqOp)
template
tmp> mapTgtToSrc
(
const tmp>& tfield,
const bool secondOrder = true
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Disable gradient 2nd order correction for tensor types
template<>
void meshToMesh::mapInternalSrcToTgt
(
const VolumeField&,
const plusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalSrcToTgt
(
const VolumeField&,
const minusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalSrcToTgt
(
const VolumeField&,
const plusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalSrcToTgt
(
const VolumeField&,
const minusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalSrcToTgt
(
const VolumeField&,
const plusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalSrcToTgt
(
const VolumeField&,
const minusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalTgtToSrc
(
const VolumeField&,
const plusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalTgtToSrc
(
const VolumeField&,
const minusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalTgtToSrc
(
const VolumeField&,
const plusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalTgtToSrc
(
const VolumeField&,
const minusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalTgtToSrc
(
const VolumeField&,
const plusEqOp&,
VolumeField&,
const bool
) const;
template<>
void meshToMesh::mapInternalTgtToSrc
(
const VolumeField&,
const minusEqOp&,
VolumeField&,
const bool
) const;
// Disable fvPatchField value override after rmap
template<>
void meshToMesh::mapAndOpSrcToTgt
(
const AMIPatchToPatchInterpolation& AMI,
const Field& srcField,
Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpSrcToTgt
(
const AMIPatchToPatchInterpolation& AMI,
const Field& srcField,
Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpSrcToTgt
(
const AMIPatchToPatchInterpolation& AMI,
const Field& srcField,
Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpSrcToTgt
(
const AMIPatchToPatchInterpolation& AMI,
const Field& srcField,
Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpSrcToTgt
(
const AMIPatchToPatchInterpolation& AMI,
const Field& srcField,
Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpTgtToSrc
(
const AMIPatchToPatchInterpolation& AMI,
Field& srcField,
const Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpTgtToSrc
(
const AMIPatchToPatchInterpolation& AMI,
Field& srcField,
const Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpTgtToSrc
(
const AMIPatchToPatchInterpolation& AMI,
Field& srcField,
const Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpTgtToSrc
(
const AMIPatchToPatchInterpolation& AMI,
Field& srcField,
const Field& tgtField,
const plusEqOp& cop
) const;
template<>
void meshToMesh::mapAndOpTgtToSrc
(
const AMIPatchToPatchInterpolation& AMI,
Field& srcField,
const Field& tgtField,
const plusEqOp& cop
) const;
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "meshToMeshI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "meshToMeshTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //