39 void Foam::meshToMesh::add
52 template<
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()
70 multiplyWeightedOp<Type, CombineOp> cbop(cop);
72 if (singleMeshProc_ == -1)
74 const mapDistribute& map = srcMapPtr_();
76 List<Type> work(srcField);
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);
120 template<
class Type,
class CombineOp>
123 const UList<Type>& srcField,
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()
139 multiplyWeightedOp<Type, CombineOp> cbop(cop);
141 if (singleMeshProc_ == -1)
146 mapSrcToTgt(srcField, cop, result);
150 const mapDistribute& map = srcMapPtr_();
152 List<Type> work(srcField);
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);
214 template<
class Type,
class CombineOp>
217 const Field<Type>& srcField,
221 tmp<Field<Type>> tresult
225 tgtToSrcCellAddr_.size(),
230 mapSrcToTgt(srcField, cop, tresult.ref());
236 template<
class Type,
class CombineOp>
243 return mapSrcToTgt(tsrcField(), cop);
263 return mapSrcToTgt(tsrcField());
267 template<
class Type,
class CombineOp>
271 const CombineOp& cop,
275 if (result.
size() != srcToTgtCellAddr_.size())
278 <<
"Supplied field size is not equal to source mesh size" <<
nl 279 <<
" source mesh = " << srcToTgtCellAddr_.size() <<
nl 280 <<
" target mesh = " << tgtToSrcCellAddr_.size() <<
nl 281 <<
" supplied field = " << result.
size()
285 multiplyWeightedOp<Type, CombineOp> cbop(cop);
287 if (singleMeshProc_ == -1)
289 const mapDistribute& map = tgtMapPtr_();
291 List<Type> work(tgtField);
292 map.distribute(work);
296 const labelList& tgtAddress = srcToTgtCellAddr_[celli];
297 const scalarList& tgtWeight = srcToTgtCellWght_[celli];
299 if (tgtAddress.size())
301 result[celli] *= (1.0 -
sum(tgtWeight));
304 label tgtI = tgtAddress[i];
305 scalar w = tgtWeight[i];
306 cbop(result[celli], celli, work[tgtI], w);
315 const labelList& tgtAddress = srcToTgtCellAddr_[celli];
316 const scalarList& tgtWeight = srcToTgtCellWght_[celli];
318 if (tgtAddress.size())
320 result[celli] *= (1.0 -
sum(tgtWeight));
323 label tgtI = tgtAddress[i];
324 scalar w = tgtWeight[i];
325 cbop(result[celli], celli, tgtField[tgtI], w);
333 template<
class Type,
class CombineOp>
336 const UList<Type>& tgtField,
338 const CombineOp& cop,
342 if (result.size() != srcToTgtCellAddr_.size())
345 <<
"Supplied field size is not equal to source mesh size" <<
nl 346 <<
" source mesh = " << srcToTgtCellAddr_.size() <<
nl 347 <<
" target mesh = " << tgtToSrcCellAddr_.size() <<
nl 348 <<
" supplied field = " << result.size()
352 multiplyWeightedOp<Type, CombineOp> cbop(cop);
354 if (singleMeshProc_ == -1)
359 mapTgtToSrc(tgtField, cop, result);
363 const mapDistribute& map = tgtMapPtr_();
365 List<Type> work(tgtField);
366 map.distribute(work);
372 map.distribute(workGrad);
376 const labelList& tgtAddress = srcToTgtCellAddr_[cellI];
377 const scalarList& tgtWeight = srcToTgtCellWght_[cellI];
378 const pointList& tgtVec = srcToTgtCellVec_[cellI];
380 if (tgtAddress.size())
382 result[cellI] *= (1.0 -
sum(tgtWeight));
385 label tgtI = tgtAddress[i];
386 scalar w = tgtWeight[i];
387 const vector& v = tgtVec[i];
388 const Type tgtVal = work[tgtI]+(workGrad[tgtI]&v);
389 cbop(result[cellI], cellI, tgtVal, w);
398 const labelList& tgtAddress = srcToTgtCellAddr_[cellI];
399 const scalarList& tgtWeight = srcToTgtCellWght_[cellI];
400 const pointList& tgtVec = srcToTgtCellVec_[cellI];
402 if (tgtAddress.size())
404 result[cellI] *= (1.0 -
sum(tgtWeight));
407 label tgtI = tgtAddress[i];
408 scalar w = tgtWeight[i];
409 const vector& v = tgtVec[i];
410 const Type tgtVal = tgtField[tgtI]+(tgtGradField[tgtI]&v);
411 cbop(result[cellI], cellI, tgtVal, w);
419 template<
class Type,
class CombineOp>
422 const Field<Type>& tgtField,
426 tmp<Field<Type>> tresult
430 srcToTgtCellAddr_.size(),
435 mapTgtToSrc(tgtField, cop, tresult.ref());
441 template<
class Type,
class CombineOp>
448 return mapTgtToSrc(ttgtField(), cop);
472 template<
class Type,
class CombineOp>
473 void Foam::meshToMesh::mapInternalSrcToTgt
475 const VolumeField<Type>&
field,
476 const CombineOp& cop,
477 VolumeField<Type>& result,
478 const bool secondOrder
488 result.primitiveFieldRef()
493 mapSrcToTgt(
field, cop, result.primitiveFieldRef());
498 template<
class Type,
class CombineOp>
499 void Foam::meshToMesh::mapAndOpSrcToTgt
502 const Field<Type>& srcField,
503 Field<Type>& tgtField,
507 tgtField = Type(
Zero);
509 AMI.interpolateToTarget
512 multiplyWeightedOp<Type, CombineOp>(cop),
519 template<
class Type,
class CombineOp>
523 const CombineOp& cop,
525 const bool secondOrder
528 mapInternalSrcToTgt(
field, cop, result, secondOrder);
536 label srcPatchi = srcPatchID_[i];
537 label tgtPatchi = tgtPatchID_[i];
552 AMIList[i].singlePatchProc(),
554 AMIList[i].singlePatchProc() == -1
555 ? &AMIList[i].srcMap()
558 AMIList[i].tgtAddress(),
559 AMIList[i].tgtWeights()
570 mapAndOpSrcToTgt(AMIList[i], srcField, tgtField, cop);
573 forAll(cuttingPatches_, i)
575 label patchi = cuttingPatches_[i];
576 fvPatchField<Type>& pf = resultBf[patchi];
577 pf == pf.patchInternalField();
582 template<
class Type,
class CombineOp>
586 const VolumeField<Type>&
field,
587 const CombineOp& cop,
588 const bool secondOrder
591 const fvMesh& tgtMesh =
static_cast<const fvMesh&
>(tgtRegion_);
593 const fvBoundaryMesh& tgtBm = tgtMesh.boundary();
594 const auto& srcBfld =
field.boundaryField();
596 PtrList<fvPatchField<Type>> tgtPatchFields(tgtBm.size());
603 label srcPatchi = srcPatchID_[i];
604 label tgtPatchi = tgtPatchID_[i];
606 if (!tgtPatchFields.set(tgtPatchi))
614 tgtMesh.boundary()[tgtPatchi],
618 labelList(tgtMesh.boundary()[tgtPatchi].size(), -1)
626 forAll(tgtPatchFields, tgtPatchi)
628 if (!tgtPatchFields.set(tgtPatchi))
638 tgtMesh.boundary()[tgtPatchi],
646 tmp<VolumeField<Type>>
::New 650 type() +
":interpolate(" +
field.name() +
")",
651 tgtMesh.time().timeName(),
658 Field<Type>(tgtMesh.nCells(),
Zero),
662 mapSrcToTgt(
field, cop, tresult.ref(), secondOrder);
668 template<
class Type,
class CombineOp>
673 const CombineOp& cop,
674 const bool secondOrder
677 return mapSrcToTgt(tfield(), cop, secondOrder);
686 const bool secondOrder
698 const bool secondOrder
705 template<
class Type,
class CombineOp>
706 void Foam::meshToMesh::mapInternalTgtToSrc
708 const VolumeField<Type>&
field,
709 const CombineOp& cop,
710 VolumeField<Type>& result,
711 const bool secondOrder
721 result.primitiveFieldRef()
726 mapTgtToSrc(
field, cop, result.primitiveFieldRef());
731 template<
class Type,
class CombineOp>
732 void Foam::meshToMesh::mapAndOpTgtToSrc
735 Field<Type>& srcField,
736 const Field<Type>& tgtField,
740 srcField = Type(
Zero);
742 AMI.interpolateToSource
745 multiplyWeightedOp<Type, CombineOp>(cop),
752 template<
class Type,
class CombineOp>
756 const CombineOp& cop,
758 const bool secondOrder
761 mapInternalTgtToSrc(
field, cop, result, secondOrder);
767 label srcPatchi = srcPatchID_[i];
768 label tgtPatchi = tgtPatchID_[i];
784 AMIList[i].singlePatchProc(),
786 AMIList[i].singlePatchProc() == -1
787 ? &AMIList[i].tgtMap()
790 AMIList[i].srcAddress(),
791 AMIList[i].srcWeights()
801 mapAndOpTgtToSrc(AMIList[i], srcField, tgtField, cop);
804 forAll(cuttingPatches_, i)
806 label patchi = cuttingPatches_[i];
808 pf == pf.patchInternalField();
813 template<
class Type,
class CombineOp>
817 const VolumeField<Type>&
field,
818 const CombineOp& cop,
819 const bool secondOrder
822 const fvMesh& srcMesh =
static_cast<const fvMesh&
>(srcRegion_);
824 const fvBoundaryMesh& srcBm = srcMesh.boundary();
825 const auto& tgtBfld =
field.boundaryField();
827 PtrList<fvPatchField<Type>> srcPatchFields(srcBm.size());
834 label srcPatchi = srcPatchID_[i];
835 label tgtPatchi = tgtPatchID_[i];
837 if (!srcPatchFields.set(tgtPatchi))
845 srcMesh.boundary()[tgtPatchi],
849 labelList(srcMesh.boundary()[srcPatchi].size(), -1)
857 forAll(srcPatchFields, srcPatchi)
859 if (!srcPatchFields.set(srcPatchi))
869 srcMesh.boundary()[srcPatchi],
877 tmp<VolumeField<Type>>
::New 881 type() +
":interpolate(" +
field.name() +
")",
882 srcMesh.time().timeName(),
889 Field<Type>(srcMesh.nCells(),
Zero),
893 mapTgtToSrc(
field, cop, tresult.ref(), secondOrder);
899 template<
class Type,
class CombineOp>
904 const CombineOp& cop,
905 const bool secondOrder
908 return mapTgtToSrc(tfield(), cop, secondOrder);
917 const bool secondOrder
929 const bool secondOrder
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
void size(const label n)
Older name for setAddressableSize.
FieldMapper with weighted mapping from (optionally remote) quantities.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
const fvPatch & patch() const noexcept
Return the patch.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
constexpr char nl
The newline '\n' character (0x0a)
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Generic GeometricField class.
Ignore writing from objectRegistry::writeObject()
List< point > pointList
A List of points.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
DirectFieldMapper< fvPatchFieldMapper > directFvPatchFieldMapper
A fvPatchFieldMapper with direct mapping.
AMIInterpolation AMIPatchToPatchInterpolation
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
#define forAll(list, i)
Loop across all elements in list.
static const char *const typeName
Typename for Field.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
static const DimensionedField< Type, GeoMesh > & null()
Return a NullObjectRef DimensionedField.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Generic templated field type.
Calculate the gradient of the given field.
List< scalar > scalarList
A List of scalars.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
errorManip< error > abort(error &err)
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
List< label > labelList
A List of labels.
A class for managing temporary objects.
void mapSrcToTgt(const UList< Type > &srcFld, const CombineOp &cop, List< Type > &result) const
Map field from src to tgt mesh with defined operation.
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
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.
void mapTgtToSrc(const UList< Type > &tgtFld, const CombineOp &cop, List< Type > &result) const
Map field from tgt to src mesh with defined operation.
static constexpr const zero Zero
Global zero (0)