39void Foam::meshToMesh::add
52template<
class Type,
class CombineOp>
55 const UList<Type>& srcField,
60 if (result.size() != tgtToSrcCellAddr_.size())
63 <<
"Supplied field size is not equal to target mesh size" <<
nl
64 <<
" source mesh = " << srcToTgtCellAddr_.size() <<
nl
65 <<
" target mesh = " << tgtToSrcCellAddr_.size() <<
nl
66 <<
" supplied field = " << result.size()
81 const labelList& srcAddress = tgtToSrcCellAddr_[celli];
82 const scalarList& srcWeight = tgtToSrcCellWght_[celli];
84 if (srcAddress.size())
87 result[celli] *= (1.0 -
sum(srcWeight));
90 label srcI = srcAddress[i];
91 scalar w = srcWeight[i];
92 cbop(result[celli], celli, work[srcI], w);
101 const labelList& srcAddress = tgtToSrcCellAddr_[celli];
102 const scalarList& srcWeight = tgtToSrcCellWght_[celli];
104 if (srcAddress.size())
107 result[celli] *= (1.0 -
sum(srcWeight));
110 label srcI = srcAddress[i];
111 scalar w = srcWeight[i];
112 cbop(result[celli], celli, srcField[srcI], w);
120template<
class Type,
class CombineOp>
125 const CombineOp& cop,
129 if (result.size() != tgtToSrcCellAddr_.size())
132 <<
"Supplied field size is not equal to target mesh size" <<
nl
133 <<
" source mesh = " << srcToTgtCellAddr_.size() <<
nl
134 <<
" target mesh = " << tgtToSrcCellAddr_.size() <<
nl
135 <<
" supplied field = " << result.size()
146 mapSrcToTgt(srcField, cop, result);
153 map.distribute(work);
159 map.distribute(workGrad);
163 const labelList& srcAddress = tgtToSrcCellAddr_[cellI];
164 const scalarList& srcWeight = tgtToSrcCellWght_[cellI];
165 const pointList& srcVec = tgtToSrcCellVec_[cellI];
167 if (srcAddress.size())
169 result[cellI] *= (1.0 -
sum(srcWeight));
172 label srcI = srcAddress[i];
173 scalar w = srcWeight[i];
174 const vector& v = srcVec[i];
175 const Type srcVal = work[srcI]+(workGrad[srcI]&v);
176 cbop(result[cellI], cellI, srcVal, w);
183 if (tgtToSrcCellVec_.empty())
186 mapSrcToTgt(srcField, cop, result);
192 const labelList& srcAddress = tgtToSrcCellAddr_[cellI];
193 const scalarList& srcWeight = tgtToSrcCellWght_[cellI];
194 const pointList& srcVec = tgtToSrcCellVec_[cellI];
196 if (srcAddress.size())
199 result[cellI] *= (1.0 -
sum(srcWeight));
202 label srcI = srcAddress[i];
203 scalar w = srcWeight[i];
204 const vector& v = srcVec[i];
205 const Type srcVal = srcField[srcI]+(srcGradField[srcI]&v);
206 cbop(result[cellI], cellI, srcVal, w);
214template<
class Type,
class CombineOp>
229template<
class Type,
class CombineOp>
260template<
class Type,
class CombineOp>
264 const CombineOp& cop,
268 if (result.
size() != srcToTgtCellAddr_.size())
271 <<
"Supplied field size is not equal to source mesh size" <<
nl
272 <<
" source mesh = " << srcToTgtCellAddr_.size() <<
nl
273 <<
" target mesh = " << tgtToSrcCellAddr_.size() <<
nl
274 <<
" supplied field = " << result.
size()
278 multiplyWeightedOp<Type, CombineOp> cbop(cop);
282 const mapDistribute& map = tgtMapPtr_();
284 List<Type> work(tgtField);
285 map.distribute(work);
289 const labelList& tgtAddress = srcToTgtCellAddr_[celli];
290 const scalarList& tgtWeight = srcToTgtCellWght_[celli];
292 if (tgtAddress.size())
294 result[celli] *= (1.0 -
sum(tgtWeight));
297 label tgtI = tgtAddress[i];
298 scalar w = tgtWeight[i];
299 cbop(result[celli], celli, work[tgtI], w);
308 const labelList& tgtAddress = srcToTgtCellAddr_[celli];
309 const scalarList& tgtWeight = srcToTgtCellWght_[celli];
311 if (tgtAddress.size())
313 result[celli] *= (1.0 -
sum(tgtWeight));
316 label tgtI = tgtAddress[i];
317 scalar w = tgtWeight[i];
318 cbop(result[celli], celli, tgtField[tgtI], w);
326template<
class Type,
class CombineOp>
331 const CombineOp& cop,
335 if (result.size() != srcToTgtCellAddr_.size())
338 <<
"Supplied field size is not equal to source mesh size" <<
nl
339 <<
" source mesh = " << srcToTgtCellAddr_.size() <<
nl
340 <<
" target mesh = " << tgtToSrcCellAddr_.size() <<
nl
341 <<
" supplied field = " << result.size()
352 mapTgtToSrc(tgtField, cop, result);
359 map.distribute(work);
365 map.distribute(workGrad);
369 const labelList& tgtAddress = srcToTgtCellAddr_[cellI];
370 const scalarList& tgtWeight = srcToTgtCellWght_[cellI];
371 const pointList& tgtVec = srcToTgtCellVec_[cellI];
373 if (tgtAddress.size())
375 result[cellI] *= (1.0 -
sum(tgtWeight));
378 label tgtI = tgtAddress[i];
379 scalar w = tgtWeight[i];
380 const vector& v = tgtVec[i];
381 const Type tgtVal = work[tgtI]+(workGrad[tgtI]&v);
382 cbop(result[cellI], cellI, tgtVal, w);
391 const labelList& tgtAddress = srcToTgtCellAddr_[cellI];
392 const scalarList& tgtWeight = srcToTgtCellWght_[cellI];
393 const pointList& tgtVec = srcToTgtCellVec_[cellI];
395 if (tgtAddress.size())
397 result[cellI] *= (1.0 -
sum(tgtWeight));
400 label tgtI = tgtAddress[i];
401 scalar w = tgtWeight[i];
402 const vector& v = tgtVec[i];
403 const Type tgtVal = tgtField[tgtI]+(tgtGradField[tgtI]&v);
404 cbop(result[cellI], cellI, tgtVal, w);
412template<
class Type,
class CombineOp>
427template<
class Type,
class CombineOp>
458template<
class Type,
class CombineOp>
459void Foam::meshToMesh::mapInternalSrcToTgt
462 const CombineOp& cop,
464 const bool secondOrder
474 result.primitiveFieldRef()
479 mapSrcToTgt(
field, cop, result.primitiveFieldRef());
484template<
class Type,
class CombineOp>
485void Foam::meshToMesh::mapAndOpSrcToTgt
493 tgtField = Type(
Zero);
495 AMI.interpolateToTarget
505template<
class Type,
class CombineOp>
509 const CombineOp& cop,
511 const bool secondOrder
514 mapInternalSrcToTgt(
field, cop, result, secondOrder);
522 label srcPatchi = srcPatchID_[i];
523 label tgtPatchi = tgtPatchID_[i];
538 AMIList[i].singlePatchProc(),
540 AMIList[i].hasSrcMap(),
541 AMIList[i].tgtAddress(),
542 AMIList[i].tgtWeights()
553 mapAndOpSrcToTgt(AMIList[i], srcField, tgtField, cop);
556 forAll(cuttingPatches_, i)
558 label patchi = cuttingPatches_[i];
559 fvPatchField<Type>& pf = resultBf[patchi];
560 pf == pf.patchInternalField();
565template<
class Type,
class CombineOp>
570 const CombineOp& cop,
571 const bool secondOrder
574 const fvMesh& tgtMesh =
static_cast<const fvMesh&
>(tgtRegion_);
576 const fvBoundaryMesh& tgtBm = tgtMesh.boundary();
577 const auto& srcBfld =
field.boundaryField();
579 PtrList<fvPatchField<Type>> tgtPatchFields(tgtBm.size());
586 label srcPatchi = srcPatchID_[i];
587 label tgtPatchi = tgtPatchID_[i];
589 if (!tgtPatchFields.set(tgtPatchi))
597 tgtMesh.boundary()[tgtPatchi],
601 labelList(tgtMesh.boundary()[tgtPatchi].size(), -1)
609 forAll(tgtPatchFields, tgtPatchi)
611 if (!tgtPatchFields.set(tgtPatchi))
621 tgtMesh.boundary()[tgtPatchi],
636 "interpolate(" +
field.name() +
")"
645 mapSrcToTgt(
field, cop, tresult.ref(), secondOrder);
651template<
class Type,
class CombineOp>
656 const CombineOp& cop,
657 const bool secondOrder
669 const bool secondOrder
681 const bool secondOrder
688template<
class Type,
class CombineOp>
689void Foam::meshToMesh::mapInternalTgtToSrc
692 const CombineOp& cop,
694 const bool secondOrder
704 result.primitiveFieldRef()
709 mapTgtToSrc(
field, cop, result.primitiveFieldRef());
714template<
class Type,
class CombineOp>
715void Foam::meshToMesh::mapAndOpTgtToSrc
723 srcField = Type(
Zero);
725 AMI.interpolateToSource
735template<
class Type,
class CombineOp>
739 const CombineOp& cop,
741 const bool secondOrder
744 mapInternalTgtToSrc(
field, cop, result, secondOrder);
750 label srcPatchi = srcPatchID_[i];
751 label tgtPatchi = tgtPatchID_[i];
766 AMIList[i].singlePatchProc(),
768 AMIList[i].hasTgtMap(),
769 AMIList[i].srcAddress(),
770 AMIList[i].srcWeights()
780 mapAndOpTgtToSrc(AMIList[i], srcField, tgtField, cop);
783 forAll(cuttingPatches_, i)
785 label patchi = cuttingPatches_[i];
787 pf == pf.patchInternalField();
792template<
class Type,
class CombineOp>
797 const CombineOp& cop,
798 const bool secondOrder
801 const fvMesh& srcMesh =
static_cast<const fvMesh&
>(srcRegion_);
803 const fvBoundaryMesh& srcBm = srcMesh.boundary();
804 const auto& tgtBfld =
field.boundaryField();
806 PtrList<fvPatchField<Type>> srcPatchFields(srcBm.size());
813 label srcPatchi = srcPatchID_[i];
814 label tgtPatchi = tgtPatchID_[i];
816 if (!srcPatchFields.set(srcPatchi))
824 srcMesh.boundary()[srcPatchi],
828 labelList(srcMesh.boundary()[srcPatchi].size(), -1)
836 forAll(srcPatchFields, srcPatchi)
838 if (!srcPatchFields.set(srcPatchi))
848 srcMesh.boundary()[srcPatchi],
863 "interpolate(" +
field.name() +
")"
872 mapTgtToSrc(
field, cop, tresult.ref(), secondOrder);
878template<
class Type,
class CombineOp>
883 const CombineOp& cop,
884 const bool secondOrder
896 const bool secondOrder
908 const bool secondOrder
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
static const this_type & null() noexcept
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Internal::FieldType & primitiveFieldRef(const bool updateAccessTime=true)
Return a reference to the internal field values.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie,...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
static const UList< T > & null() noexcept
Return a null UList (reference to a nullObject). Behaves like an empty UList.
void size(const label n)
Older name for setAddressableSize.
label size() const noexcept
The number of entries in the list.
FieldMapper with weighted mapping from (optionally remote) quantities.
A fvBoundaryMesh is a fvPatch list with a reference to the associated fvMesh, with additional search ...
Mesh data needed to do the Finite Volume discretisation.
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
static const word & calculatedType() noexcept
The type name for calculated patch fields.
const fvPatch & patch() const noexcept
Return the patch.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
static tmp< fvPatchField< Type > > New(const word &patchFieldType, const fvPatch &, const DimensionedField< Type, volMesh > &)
Return a pointer to a new patchField created on freestore given.
virtual tmp< Field< Type > > patchInternalField() const
Return internal field next to patch.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
Class containing processor-to-processor mapping information.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute List data using default commsType, default flip/negate operator.
bool distributed() const noexcept
Distributed across processors (singleMeshProc == -1).
const mapDistribute * hasTgtMap() const noexcept
Pointer to the target map (if distributed). Can be checked as a bool.
Foam::tmp< Foam::Field< Type > > mapTgtToSrc(const tmp< Field< Type > > &ttgtField, const CombineOp &cop) const
const PtrList< AMIPatchToPatchInterpolation > & patchAMIs() const
Return the list of AMIs between source and target patches.
const mapDistribute * hasSrcMap() const noexcept
Pointer to the source map (if distributed). Can be checked as a bool.
Foam::tmp< Foam::Field< Type > > mapSrcToTgt(const tmp< Field< Type > > &tsrcField, const CombineOp &cop) const
void mapTgtToSrc(const UList< Type > &tgtFld, const CombineOp &cop, List< Type > &result) const
Map field from tgt to src mesh with defined operation.
void mapSrcToTgt(const UList< Type > &srcFld, const CombineOp &cop, List< Type > &result) const
Map field from src to tgt mesh with defined operation.
IOobject newIOobject(const word &name, IOobjectOption ioOpt) const
Create an IOobject at the current time instance (timeName) with the specified options.
typeOfRank< typenamepTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank)>::type type
label nCells() const noexcept
Number of mesh cells.
A class for managing temporary objects.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Calculate the gradient of the given field.
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
GeometricField< Type, fvPatchField, volMesh > VolumeField
A volume field for a given type.
List< label > labelList
A List of labels.
DirectFieldMapper< fvPatchFieldMapper > directFvPatchFieldMapper
A fvPatchFieldMapper with direct mapping.
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
List< point > pointList
List of point.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
AMIInterpolation AMIPatchToPatchInterpolation
Patch-to-patch interpolation == Foam::AMIInterpolation.
errorManip< error > abort(error &err)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
List< scalar > scalarList
List of scalar.
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.