ENH: refactor/centralize handling of direct and distributed mappers (#2436)

- added templating level to avoid code duplication and provide future
  extensibility
This commit is contained in:
Mark Olesen
2022-04-04 17:22:57 +02:00
parent b68193088c
commit 6e21d6f78c
23 changed files with 504 additions and 430 deletions

View File

@ -1,7 +1,9 @@
EXE_INC = \ EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/finiteArea/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/mesh/snappyHexMesh/lnInclude \ -I$(LIB_SRC)/mesh/snappyHexMesh/lnInclude \
@ -9,8 +11,11 @@ EXE_INC = \
-I$(LIB_SRC)/parallel/decompose/decompose/lnInclude \ -I$(LIB_SRC)/parallel/decompose/decompose/lnInclude \
EXE_LIBS = \ EXE_LIBS = \
-lfiniteVolume \ -lfileFormats \
-lsurfMesh \
-lmeshTools \ -lmeshTools \
-lfiniteVolume \
-lfiniteArea \
-llagrangian \ -llagrangian \
-ldynamicMesh \ -ldynamicMesh \
-lsnappyHexMesh \ -lsnappyHexMesh \

View File

@ -1,124 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2019 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 <http://www.gnu.org/licenses/>.
Class
Foam::distributedUnallocatedDirectFieldMapper
Description
FieldMapper with direct mapping from remote quantities.
\*---------------------------------------------------------------------------*/
#ifndef distributedUnallocatedDirectFieldMapper_H
#define distributedUnallocatedDirectFieldMapper_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class distributedUnallocatedDirectFieldMapper Declaration
\*---------------------------------------------------------------------------*/
class distributedUnallocatedDirectFieldMapper
:
public FieldMapper
{
const labelUList& directAddressing_;
const mapDistributeBase& distMap_;
bool hasUnmapped_;
public:
// Constructors
//- Construct given addressing
distributedUnallocatedDirectFieldMapper
(
const labelUList& directAddressing,
const mapDistributeBase& distMap
)
:
directAddressing_(directAddressing),
distMap_(distMap),
hasUnmapped_(directAddressing_.size() && min(directAddressing_) < 0)
{}
//- Destructor
virtual ~distributedUnallocatedDirectFieldMapper() = default;
// Member Functions
virtual label size() const
{
return
(
notNull(directAddressing_)
? directAddressing_.size()
: distMap_.constructSize()
);
}
virtual bool direct() const
{
return true;
}
virtual bool distributed() const
{
return true;
}
virtual const mapDistributeBase& distributeMap() const
{
return distMap_;
}
virtual bool hasUnmapped() const
{
return hasUnmapped_;
}
virtual const labelUList& directAddressing() const
{
return directAddressing_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -27,7 +27,6 @@ License
#include "parFvFieldReconstructor.H" #include "parFvFieldReconstructor.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::parFvFieldReconstructor::createPatchFaceMaps() void Foam::parFvFieldReconstructor::createPatchFaceMaps()
@ -96,9 +95,8 @@ Foam::parFvFieldReconstructor::parFvFieldReconstructor
void Foam::parFvFieldReconstructor::reconstructPoints() void Foam::parFvFieldReconstructor::reconstructPoints()
{ {
// Reconstruct the points for moving mesh cases and write // Reconstruct the points for moving mesh cases and write them out
// them out distributedFieldMapper mapper
distributedUnallocatedDirectFieldMapper mapper
( (
labelUList::null(), labelUList::null(),
distMap_.pointMap() distMap_.pointMap()

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2016-2018 OpenCFD Ltd. Copyright (C) 2016-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,9 +37,8 @@ License
#include "mapDistributePolyMesh.H" #include "mapDistributePolyMesh.H"
#include "processorFvPatch.H" #include "processorFvPatch.H"
#include "directFvPatchFieldMapper.H" #include "distributedFieldMapper.H"
#include "distributedUnallocatedDirectFieldMapper.H" #include "distributedFvPatchFieldMapper.H"
#include "distributedUnallocatedDirectFvPatchFieldMapper.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -50,7 +49,7 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeInternalField
const DimensionedField<Type, volMesh>& fld const DimensionedField<Type, volMesh>& fld
) const ) const
{ {
distributedUnallocatedDirectFieldMapper mapper distributedFieldMapper mapper
( (
labelUList::null(), labelUList::null(),
distMap_.cellMap() distMap_.cellMap()
@ -113,7 +112,7 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeField
// Create the internalField by remote mapping // Create the internalField by remote mapping
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
distributedUnallocatedDirectFieldMapper mapper distributedFieldMapper mapper
( (
labelUList::null(), labelUList::null(),
distMap_.cellMap() distMap_.cellMap()
@ -138,7 +137,7 @@ Foam::parFvFieldReconstructor::reconstructFvVolumeField
// Clone local patch field // Clone local patch field
patchFields.set(patchI, bfld[patchI].clone()); patchFields.set(patchI, bfld[patchI].clone());
distributedUnallocatedDirectFvPatchFieldMapper mapper distributedFvPatchFieldMapper mapper
( (
labelUList::null(), labelUList::null(),
patchFaceMaps_[patchI] patchFaceMaps_[patchI]
@ -256,7 +255,7 @@ Foam::parFvFieldReconstructor::reconstructFvSurfaceField
// Create the internalField by remote mapping // Create the internalField by remote mapping
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
distributedUnallocatedDirectFieldMapper mapper distributedFieldMapper mapper
( (
labelUList::null(), labelUList::null(),
distMap_.faceMap() distMap_.faceMap()
@ -301,7 +300,7 @@ Foam::parFvFieldReconstructor::reconstructFvSurfaceField
// Clone local patch field // Clone local patch field
patchFields.set(patchI, bfld[patchI].clone()); patchFields.set(patchI, bfld[patchI].clone());
distributedUnallocatedDirectFvPatchFieldMapper mapper distributedFvPatchFieldMapper mapper
( (
labelUList::null(), labelUList::null(),
patchFaceMaps_[patchI] patchFaceMaps_[patchI]

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2019 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,8 +32,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef FieldMapper_H #ifndef Foam_FieldMapper_H
#define FieldMapper_H #define Foam_FieldMapper_H
#include "mapDistributeBase.H" #include "mapDistributeBase.H"
#include "nullObject.H" #include "nullObject.H"
@ -49,14 +49,12 @@ namespace Foam
class FieldMapper class FieldMapper
{ {
public: public:
// Constructors // Constructors
//- Null constructor //- Default construct
FieldMapper() FieldMapper() = default;
{}
//- Destructor //- Destructor
@ -65,28 +63,23 @@ public:
// Member Functions // Member Functions
//- The size of the mapper
virtual label size() const = 0; virtual label size() const = 0;
//- Is it a direct (non-interpolating) mapper?
virtual bool direct() const = 0; virtual bool direct() const = 0;
//- Does the mapper have remote contributions?
virtual bool distributed() const virtual bool distributed() const
{ {
return false; return false;
} }
virtual const mapDistributeBase& distributeMap() const //- Any unmapped values?
{ // I.e. do all size() elements get value
FatalErrorInFunction
<< "attempt to access null distributeMap"
<< abort(FatalError);
return NullObjectRef<mapDistributeBase>();
}
//- Are there unmapped values? I.e. do all size() elements get
// get value
virtual bool hasUnmapped() const = 0; virtual bool hasUnmapped() const = 0;
//- Return the direct addressing values
virtual const labelUList& directAddressing() const virtual const labelUList& directAddressing() const
{ {
FatalErrorInFunction FatalErrorInFunction
@ -96,6 +89,17 @@ public:
return labelUList::null(); return labelUList::null();
} }
//- Return the distribution map
virtual const mapDistributeBase& distributeMap() const
{
FatalErrorInFunction
<< "attempt to access null distributeMap"
<< abort(FatalError);
return NullObjectRef<mapDistributeBase>();
}
//- Return the interpolation addressing
virtual const labelListList& addressing() const virtual const labelListList& addressing() const
{ {
FatalErrorInFunction FatalErrorInFunction
@ -105,6 +109,7 @@ public:
return labelListList::null(); return labelListList::null();
} }
//- Return the interpolation weights
virtual const scalarListList& weights() const virtual const scalarListList& weights() const
{ {
FatalErrorInFunction FatalErrorInFunction
@ -117,10 +122,11 @@ public:
// Member Operators // Member Operators
//- Perform mapping on the given field
template<class Type> template<class Type>
tmp<Field<Type>> operator()(const Field<Type>& f) const tmp<Field<Type>> operator()(const Field<Type>& fld) const
{ {
return tmp<Field<Type>>::New(f, *this); return tmp<Field<Type>>::New(fld, *this);
} }
}; };

View File

@ -5,8 +5,8 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2018 OpenFOAM Foundation Copyright (C) 2013 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,72 +25,129 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::directFieldMapper Foam::DirectFieldMapper
Description Description
FieldMapper with direct mapping. A templated direct mapper for the given FieldMapper type
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef directFieldMapper_H #ifndef Foam_directFieldMapper_H
#define directFieldMapper_H #define Foam_directFieldMapper_H
#include "FieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward Declarations
template<class FieldMapperType> class DirectFieldMapper;
// Standard Types
//- A FieldMapper with direct mapping
typedef DirectFieldMapper<FieldMapper> directFieldMapper;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class directFieldMapper Declaration Class DirectFieldMapper Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class directFieldMapper template<class FieldMapperType>
class DirectFieldMapper
: :
public FieldMapper public FieldMapperType
{ {
const labelUList& directAddressing_; // Private Data
bool hasUnmapped_; //- Addressing from new back to old
const labelUList& directAddressing_;
//- Does map contain any unmapped values
bool hasUnmapped_;
// Private Member Functions
//- Any negative (unmapped) values in the addressing?
static bool hasUnmappedEntry(const labelUList& directAddr)
{
for (const label val : directAddr)
{
if (val < 0) return true; // early exit
}
return false;
}
public: public:
// Public Types
//- The base mapper type
typedef FieldMapperType mapper_type;
// Constructors // Constructors
//- Construct given addressing //- Construct given addressing, check for unmapped (negative) values
directFieldMapper(const labelUList& directAddressing) explicit DirectFieldMapper
(
const labelUList& directAddr,
const bool checkUnmapped = true
)
: :
directAddressing_(directAddressing), FieldMapperType(),
hasUnmapped_(directAddressing_.size() && min(directAddressing_) < 0) directAddressing_(directAddr),
hasUnmapped_(checkUnmapped && hasUnmappedEntry(directAddr))
{} {}
//- Destructor //- Destructor
virtual ~directFieldMapper() = default; virtual ~DirectFieldMapper() = default;
// Member Functions // Member Functions
label size() const //- True if directAddressing is not the null object (unallocated)
virtual bool hasDirectAddressing() const
{
return notNull(directAddressing_);
}
//- The mapper size is given by the size of the direct addressing
virtual label size() const
{ {
return directAddressing_.size(); return directAddressing_.size();
} }
bool direct() const //- It is a direct mapper
virtual bool direct() const
{ {
return true; return true;
} }
bool hasUnmapped() const //- Any unmapped values?
virtual bool hasUnmapped() const
{ {
return hasUnmapped_; return hasUnmapped_;
} }
const labelUList& directAddressing() const //- Allow modification
virtual bool& hasUnmapped()
{
return hasUnmapped_;
}
//- Return the direct addressing values
virtual const labelUList& directAddressing() const
{ {
return directAddressing_; return directAddressing_;
} }
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -5,8 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation Copyright (C) 2019-2022 OpenCFD Ltd.
Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -25,96 +24,102 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Class
Foam::distributedUnallocatedDirectFvPatchFieldMapper Foam::DistributedFieldMapper
Description Description
FieldMapper with direct mapping from remote quantities. A templated field mapper
with direct mapping from local or remote quantities.
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef distributedUnallocatedDirectFvPatchFieldMapper_H #ifndef Foam_distributedFieldMapper_H
#define distributedUnallocatedDirectFvPatchFieldMapper_H #define Foam_distributedFieldMapper_H
#include "fvPatchFieldMapper.H" #include "directFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward Declarations
template<class DirectFieldMapperType> class DistributedFieldMapper;
// Standard Types
//- A directFieldMapper with distributed (with local or remote) quantities
typedef DistributedFieldMapper<directFieldMapper> distributedFieldMapper;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class distributedUnallocatedDirectFvPatchFieldMapper Declaration Class DistributedFieldMapper Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class distributedUnallocatedDirectFvPatchFieldMapper template<class DirectFieldMapperType>
class DistributedFieldMapper
: :
public fvPatchFieldMapper public DirectFieldMapperType
{ {
const labelUList& directAddressing_; // Private Data
const mapDistributeBase& distMap_; //- The distributed map
const mapDistributeBase& distMap_;
bool hasUnmapped_;
public: public:
// Public Types
//- The base direct mapper type
typedef DirectFieldMapperType mapper_type;
// Constructors // Constructors
//- Construct given addressing //- Construct with addressing and distribute map
distributedUnallocatedDirectFvPatchFieldMapper DistributedFieldMapper
( (
const labelUList& directAddressing, const labelUList& directAddr,
const mapDistributeBase& distMap const mapDistributeBase& distMap
) )
: :
directAddressing_(directAddressing), DirectFieldMapperType(directAddr),
distMap_(distMap), distMap_(distMap)
hasUnmapped_(directAddressing_.size() && min(directAddressing_) < 0)
{} {}
//- Destructor //- Destructor
virtual ~distributedUnallocatedDirectFvPatchFieldMapper() = default; virtual ~DistributedFieldMapper() = default;
// Member Functions // Member Functions
//- The mapper size is given by the direct addressing size (if valid)
//- or from the distributeMap construct size.
virtual label size() const virtual label size() const
{ {
return return
( (
notNull(directAddressing_) DirectFieldMapperType::hasDirectAddressing()
? directAddressing_.size() ? DirectFieldMapperType::size()
: distMap_.constructSize() : distMap_.constructSize()
); );
} }
virtual bool direct() const //- It is a distributed mapper
{
return true;
}
virtual bool distributed() const virtual bool distributed() const
{ {
return true; return true;
} }
//- Return the distribution map
virtual const mapDistributeBase& distributeMap() const virtual const mapDistributeBase& distributeMap() const
{ {
return distMap_; return distMap_;
} }
virtual bool hasUnmapped() const
{
return hasUnmapped_;
}
virtual const labelUList& directAddressing() const
{
return directAddressing_;
}
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -5,8 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013 OpenFOAM Foundation Copyright (C) 2022 OpenCFD Ltd.
Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,17 +23,18 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Typedef
Foam::directPointPatchFieldMapper Foam::directPointPatchFieldMapper
Description Description
direct pointPatchFieldMapper A direct pointPatchFieldMapper
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef directPointPatchFieldMapper_H #ifndef Foam_directPointPatchFieldMapper_H
#define directPointPatchFieldMapper_H #define Foam_directPointPatchFieldMapper_H
#include "directFieldMapper.H"
#include "pointPatchFieldMapper.H" #include "pointPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -42,65 +42,11 @@ Description
namespace Foam namespace Foam
{ {
/*---------------------------------------------------------------------------*\ typedef
Class directPointPatchFieldMapper Declaration DirectFieldMapper<pointPatchFieldMapper>
\*---------------------------------------------------------------------------*/ directPointPatchFieldMapper;
class directPointPatchFieldMapper }
:
public pointPatchFieldMapper
{
//- Addressing from new back to old
const labelUList& directAddressing_;
//- Does map contain any unmapped values
bool hasUnmapped_;
public:
// Constructors
//- Construct given addressing
directPointPatchFieldMapper(const labelUList& directAddressing)
:
directAddressing_(directAddressing),
hasUnmapped_(directAddressing_.size() && min(directAddressing_) < 0)
{}
//- Destructor
virtual ~directPointPatchFieldMapper() = default;
// Member Functions
label size() const
{
return directAddressing_.size();
}
bool direct() const
{
return true;
}
bool hasUnmapped() const
{
return hasUnmapped_;
}
const labelUList& directAddressing() const
{
return directAddressing_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,56 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
Typedef
Foam::distributedPointPatchFieldMapper
Description
A directPointPatchFieldMapper
with direct mapping from local or remote quantities.
\*---------------------------------------------------------------------------*/
#ifndef Foam_distributedPointPatchFieldMapper_H
#define Foam_distributedPointPatchFieldMapper_H
#include "distributedFieldMapper.H"
#include "directPointPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef
DistributedFieldMapper<directPointPatchFieldMapper>
distributedPointPatchFieldMapper;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -31,11 +31,10 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef pointPatchFieldMapper_H #ifndef Foam_pointPatchFieldMapper_H
#define pointPatchFieldMapper_H #define Foam_pointPatchFieldMapper_H
#include "primitiveFields.H" #include "primitiveFields.H"
#include "FieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -50,14 +49,12 @@ class pointPatchFieldMapper
: :
public FieldMapper public FieldMapper
{ {
public: public:
// Constructors // Constructors
//- Null constructor //- Default construct
pointPatchFieldMapper() pointPatchFieldMapper() = default;
{}
}; };

View File

@ -50,7 +50,15 @@ class pointBoundaryMeshMapper
: :
public PtrList<pointPatchMapper> public PtrList<pointPatchMapper>
{ {
// Private Member Functions public:
// Public Types
//- The patch mapper type
typedef pointPatchMapper mapper_type;
// Generated Methods
//- No copy construct //- No copy construct
pointBoundaryMeshMapper(const pointBoundaryMeshMapper&) = delete; pointBoundaryMeshMapper(const pointBoundaryMeshMapper&) = delete;
@ -59,8 +67,6 @@ class pointBoundaryMeshMapper
void operator=(const pointBoundaryMeshMapper&) = delete; void operator=(const pointBoundaryMeshMapper&) = delete;
public:
// Constructors // Constructors
//- Construct from components //- Construct from components

View File

@ -200,13 +200,4 @@ const Foam::scalarListList& Foam::pointPatchMapper::weights() const
} }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd. Copyright (C) 2015-2022 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -33,7 +33,7 @@ License
void Foam::mapDistributePolyMesh::calcPatchSizes() void Foam::mapDistributePolyMesh::calcPatchSizes()
{ {
oldPatchSizes_.setSize(oldPatchStarts_.size()); oldPatchSizes_.resize_nocopy(oldPatchStarts_.size());
if (oldPatchStarts_.size()) if (oldPatchStarts_.size())
{ {
@ -192,6 +192,12 @@ Foam::mapDistributePolyMesh::mapDistributePolyMesh(Istream& is)
void Foam::mapDistributePolyMesh::transfer(mapDistributePolyMesh& rhs) void Foam::mapDistributePolyMesh::transfer(mapDistributePolyMesh& rhs)
{ {
if (this == &rhs)
{
// Self-assignment is a no-op
return;
}
nOldPoints_ = rhs.nOldPoints_; nOldPoints_ = rhs.nOldPoints_;
nOldFaces_ = rhs.nOldFaces_; nOldFaces_ = rhs.nOldFaces_;
nOldCells_ = rhs.nOldCells_; nOldCells_ = rhs.nOldCells_;
@ -283,6 +289,12 @@ void Foam::mapDistributePolyMesh::distributePatchIndices(labelList& lst) const
void Foam::mapDistributePolyMesh::operator=(const mapDistributePolyMesh& rhs) void Foam::mapDistributePolyMesh::operator=(const mapDistributePolyMesh& rhs)
{ {
if (this == &rhs)
{
// Self-assignment is a no-op
return;
}
nOldPoints_ = rhs.nOldPoints_; nOldPoints_ = rhs.nOldPoints_;
nOldFaces_ = rhs.nOldFaces_; nOldFaces_ = rhs.nOldFaces_;
nOldCells_ = rhs.nOldCells_; nOldCells_ = rhs.nOldCells_;
@ -298,7 +310,11 @@ void Foam::mapDistributePolyMesh::operator=(const mapDistributePolyMesh& rhs)
void Foam::mapDistributePolyMesh::operator=(mapDistributePolyMesh&& rhs) void Foam::mapDistributePolyMesh::operator=(mapDistributePolyMesh&& rhs)
{ {
transfer(rhs); if (this != &rhs)
{
// Avoid self assignment
transfer(rhs);
}
} }
@ -327,9 +343,10 @@ Foam::Istream& Foam::operator>>(Istream& is, mapDistributePolyMesh& map)
Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributePolyMesh& map) Foam::Ostream& Foam::operator<<(Ostream& os, const mapDistributePolyMesh& map)
{ {
os << map.nOldPoints_ os << map.nOldPoints_ << token::SPACE
<< token::SPACE << map.nOldFaces_ << map.nOldFaces_ << token::SPACE
<< token::SPACE << map.nOldCells_ << token::NL << map.nOldCells_ << token::NL
<< map.oldPatchSizes_ << token::NL << map.oldPatchSizes_ << token::NL
<< map.oldPatchStarts_ << token::NL << map.oldPatchStarts_ << token::NL
<< map.oldPatchNMeshPoints_ << token::NL << map.oldPatchNMeshPoints_ << token::NL

View File

@ -41,8 +41,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef mapDistributePolyMesh_H #ifndef Foam_mapDistributePolyMesh_H
#define mapDistributePolyMesh_H #define Foam_mapDistributePolyMesh_H
#include "mapDistribute.H" #include "mapDistribute.H"
@ -51,7 +51,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations // Forward Declarations
class mapPolyMesh; class mapPolyMesh;
class polyMesh; class polyMesh;
class mapDistributePolyMesh; class mapDistributePolyMesh;
@ -66,7 +66,7 @@ Ostream& operator<<(Ostream&, const mapDistributePolyMesh&);
class mapDistributePolyMesh class mapDistributePolyMesh
{ {
// Private data // Private Data
//- Number of old live points //- Number of old live points
label nOldPoints_; label nOldPoints_;
@ -112,7 +112,7 @@ public:
// Constructors // Constructors
//- Construct null //- Default construct
mapDistributePolyMesh(); mapDistributePolyMesh();
//- Move construct //- Move construct
@ -165,7 +165,7 @@ public:
); );
//- Construct from Istream //- Construct from Istream
mapDistributePolyMesh(Istream& is); explicit mapDistributePolyMesh(Istream& is);
// Member Functions // Member Functions
@ -173,61 +173,61 @@ public:
// Access // Access
//- Number of points in mesh before distribution //- Number of points in mesh before distribution
label nOldPoints() const label nOldPoints() const noexcept
{ {
return nOldPoints_; return nOldPoints_;
} }
//- Number of faces in mesh before distribution //- Number of faces in mesh before distribution
label nOldFaces() const label nOldFaces() const noexcept
{ {
return nOldFaces_; return nOldFaces_;
} }
//- Number of cells in mesh before distribution //- Number of cells in mesh before distribution
label nOldCells() const label nOldCells() const noexcept
{ {
return nOldCells_; return nOldCells_;
} }
//- List of the old patch sizes //- List of the old patch sizes
const labelList& oldPatchSizes() const const labelList& oldPatchSizes() const noexcept
{ {
return oldPatchSizes_; return oldPatchSizes_;
} }
//- List of the old patch start labels //- List of the old patch start labels
const labelList& oldPatchStarts() const const labelList& oldPatchStarts() const noexcept
{ {
return oldPatchStarts_; return oldPatchStarts_;
} }
//- List of numbers of mesh points per old patch //- List of numbers of mesh points per old patch
const labelList& oldPatchNMeshPoints() const const labelList& oldPatchNMeshPoints() const noexcept
{ {
return oldPatchNMeshPoints_; return oldPatchNMeshPoints_;
} }
//- Point distribute map //- Point distribute map
const mapDistribute& pointMap() const const mapDistribute& pointMap() const noexcept
{ {
return pointMap_; return pointMap_;
} }
//- Face distribute map //- Face distribute map
const mapDistribute& faceMap() const const mapDistribute& faceMap() const noexcept
{ {
return faceMap_; return faceMap_;
} }
//- Cell distribute map //- Cell distribute map
const mapDistribute& cellMap() const const mapDistribute& cellMap() const noexcept
{ {
return cellMap_; return cellMap_;
} }
//- Patch distribute map //- Patch distribute map
const mapDistribute& patchMap() const const mapDistribute& patchMap() const noexcept
{ {
return patchMap_; return patchMap_;
} }
@ -240,30 +240,30 @@ public:
//- Distribute list of point data //- Distribute list of point data
template<class T> template<class T>
void distributePointData(List<T>& lst) const void distributePointData(List<T>& values) const
{ {
pointMap_.distribute(lst); pointMap_.distribute(values);
} }
//- Distribute list of face data //- Distribute list of face data
template<class T> template<class T>
void distributeFaceData(List<T>& lst) const void distributeFaceData(List<T>& values) const
{ {
faceMap_.distribute(lst); faceMap_.distribute(values);
} }
//- Distribute list of cell data //- Distribute list of cell data
template<class T> template<class T>
void distributeCellData(List<T>& lst) const void distributeCellData(List<T>& values) const
{ {
cellMap_.distribute(lst); cellMap_.distribute(values);
} }
//- Distribute list of patch data //- Distribute list of patch data
template<class T> template<class T>
void distributePatchData(List<T>& lst) const void distributePatchData(List<T>& values) const
{ {
patchMap_.distribute(lst); patchMap_.distribute(values);
} }
@ -294,12 +294,11 @@ public:
// IOstream operators // IOstream operators
//- Read dictionary from Istream //- Read content (not dictionary) from Istream
friend Istream& operator>>(Istream&, mapDistributePolyMesh&); friend Istream& operator>>(Istream&, mapDistributePolyMesh&);
//- Write dictionary to Ostream //- Write content (not dictionary) to Ostream
friend Ostream& operator<<(Ostream&, const mapDistributePolyMesh&); friend Ostream& operator<<(Ostream&, const mapDistributePolyMesh&);
}; };

View File

@ -32,8 +32,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef morphFieldMapper_H #ifndef Foam_morphFieldMapper_H
#define morphFieldMapper_H #define Foam_morphFieldMapper_H
#include "Field.H" #include "Field.H"
#include "Map.H" #include "Map.H"
@ -51,14 +51,12 @@ class morphFieldMapper
: :
public FieldMapper public FieldMapper
{ {
public: public:
// Constructors // Constructors
//- Null constructor //- Default construct
morphFieldMapper() morphFieldMapper() = default;
{}
//- Destructor //- Destructor
@ -75,7 +73,6 @@ public:
//- Return list of inserted objects //- Return list of inserted objects
virtual const labelList& insertedObjectLabels() const = 0; virtual const labelList& insertedObjectLabels() const = 0;
}; };

View File

@ -50,7 +50,15 @@ class faBoundaryMeshMapper
: :
public PtrList<faPatchMapper> public PtrList<faPatchMapper>
{ {
// Private Member Functions public:
// Public Types
//- The patch mapper type
typedef faPatchMapper mapper_type;
// Generated Methods
//- No copy construct //- No copy construct
faBoundaryMeshMapper(const faBoundaryMeshMapper&) = delete; faBoundaryMeshMapper(const faBoundaryMeshMapper&) = delete;
@ -59,8 +67,6 @@ class faBoundaryMeshMapper
void operator=(const faBoundaryMeshMapper&) = delete; void operator=(const faBoundaryMeshMapper&) = delete;
public:
// Constructors // Constructors
//- Construct from components //- Construct from components
@ -74,14 +80,14 @@ public:
{ {
const faBoundaryMesh& patches = mesh.boundary(); const faBoundaryMesh& patches = mesh.boundary();
forAll(patches, patchI) forAll(patches, patchi)
{ {
set set
( (
patchI, patchi,
new faPatchMapper new faPatchMapper
( (
patches[patchI], patches[patchi],
mpm mpm
) )
); );

View File

@ -0,0 +1,55 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
Typedef
Foam::directFaPatchFieldMapper
Description
A direct faPatchFieldMapper
\*---------------------------------------------------------------------------*/
#ifndef Foam_directFaPatchFieldMapper_H
#define Foam_directFaPatchFieldMapper_H
#include "directFieldMapper.H"
#include "faPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef
DirectFieldMapper<faPatchFieldMapper>
directFaPatchFieldMapper;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,56 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
Typedef
Foam::distributedFaPatchFieldMapper
Description
A directFaPatchFieldMapper
with direct mapping from local or remote quantities.
\*---------------------------------------------------------------------------*/
#ifndef Foam_distributedFaPatchFieldMapper_H
#define Foam_distributedFaPatchFieldMapper_H
#include "distributedFieldMapper.H"
#include "directFaPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef
DistributedFieldMapper<directFaPatchFieldMapper>
distributedFaPatchFieldMapper;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -26,10 +26,13 @@ License
Class Class
Foam::faPatchFieldMapper Foam::faPatchFieldMapper
Description
A FieldMapper for finite-area patch fields
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef faPatchFieldMapper_H #ifndef Foam_faPatchFieldMapper_H
#define faPatchFieldMapper_H #define Foam_faPatchFieldMapper_H
#include "primitiveFields.H" #include "primitiveFields.H"
@ -46,14 +49,12 @@ class faPatchFieldMapper
: :
public FieldMapper public FieldMapper
{ {
public: public:
// Constructors // Constructors
//- Null constructor //- Default construct
faPatchFieldMapper() faPatchFieldMapper() = default;
{}
}; };

View File

@ -5,8 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013 OpenFOAM Foundation Copyright (C) 2022 OpenCFD Ltd.
Copyright (C) 2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -24,17 +23,18 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class Typedef
Foam::directFvPatchFieldMapper Foam::directFvPatchFieldMapper
Description Description
direct fvPatchFieldMapper A fvPatchFieldMapper with direct mapping
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef directFvPatchFieldMapper_H #ifndef Foam_directFvPatchFieldMapper_H
#define directFvPatchFieldMapper_H #define Foam_directFvPatchFieldMapper_H
#include "directFieldMapper.H"
#include "fvPatchFieldMapper.H" #include "fvPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -42,70 +42,11 @@ Description
namespace Foam namespace Foam
{ {
/*---------------------------------------------------------------------------*\ typedef
Class directFvPatchFieldMapper Declaration DirectFieldMapper<fvPatchFieldMapper>
\*---------------------------------------------------------------------------*/ directFvPatchFieldMapper;
class directFvPatchFieldMapper }
:
public fvPatchFieldMapper
{
//- Addressing from new back to old
const labelUList& directAddressing_;
//- Does map contain any unmapped values
bool hasUnmapped_;
public:
// Constructors
//- Construct given addressing
directFvPatchFieldMapper(const labelUList& directAddressing)
:
directAddressing_(directAddressing),
hasUnmapped_(directAddressing_.size() && min(directAddressing_) < 0)
{}
//- Destructor
virtual ~directFvPatchFieldMapper() = default;
// Member Functions
label size() const
{
return directAddressing_.size();
}
bool direct() const
{
return true;
}
bool hasUnmapped() const
{
return hasUnmapped_;
}
bool& hasUnmapped()
{
return hasUnmapped_;
}
const labelUList& directAddressing() const
{
return directAddressing_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,56 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
Typedef
Foam::distributedFvPatchFieldMapper
Description
A directFvPatchFieldMapper
with direct mapping from local or remote quantities.
\*---------------------------------------------------------------------------*/
#ifndef Foam_distributedFvPatchFieldMapper_H
#define Foam_distributedFvPatchFieldMapper_H
#include "distributedFieldMapper.H"
#include "directFvPatchFieldMapper.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef
DistributedFieldMapper<directFvPatchFieldMapper>
distributedFvPatchFieldMapper;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -27,12 +27,12 @@ Class
Foam::fvPatchFieldMapper Foam::fvPatchFieldMapper
Description Description
Foam::fvPatchFieldMapper A FieldMapper for finite-volume patch fields
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef fvPatchFieldMapper_H #ifndef Foam_fvPatchFieldMapper_H
#define fvPatchFieldMapper_H #define Foam_fvPatchFieldMapper_H
#include "primitiveFields.H" #include "primitiveFields.H"
@ -49,14 +49,12 @@ class fvPatchFieldMapper
: :
public FieldMapper public FieldMapper
{ {
public: public:
// Constructors // Constructors
//- Null constructor //- Default construct
fvPatchFieldMapper() fvPatchFieldMapper() = default;
{}
}; };

View File

@ -50,7 +50,15 @@ class fvBoundaryMeshMapper
: :
public PtrList<fvPatchMapper> public PtrList<fvPatchMapper>
{ {
// Private Member Functions public:
// Public Types
//- The patch mapper type
typedef fvPatchMapper mapper_type;
// Generated Methods
//- No copy construct //- No copy construct
fvBoundaryMeshMapper(const fvBoundaryMeshMapper&) = delete; fvBoundaryMeshMapper(const fvBoundaryMeshMapper&) = delete;
@ -59,8 +67,6 @@ class fvBoundaryMeshMapper
void operator=(const fvBoundaryMeshMapper&) = delete; void operator=(const fvBoundaryMeshMapper&) = delete;
public:
// Constructors // Constructors
//- Construct from components //- Construct from components