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);
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);
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 auto tresult = tmp<Field<Type>>
::New(tgtToSrcCellAddr_.size(),
Zero);
223 mapSrcToTgt(srcField, cop, tresult.ref());
229 template<
class Type,
class CombineOp>
236 return mapSrcToTgt(tsrcField(), cop);
256 return mapSrcToTgt(tsrcField());
260 template<
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);
326 template<
class Type,
class CombineOp>
329 const UList<Type>& tgtField,
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()
345 multiplyWeightedOp<Type, CombineOp> cbop(cop);
352 mapTgtToSrc(tgtField, cop, result);
356 const mapDistribute& map = tgtMapPtr_();
358 List<Type> work(tgtField);
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);
412 template<
class Type,
class CombineOp>
415 const Field<Type>& tgtField,
419 auto tresult = tmp<Field<Type>>
::New(srcToTgtCellAddr_.size(),
Zero);
421 mapTgtToSrc(tgtField, cop, tresult.ref());
427 template<
class Type,
class CombineOp>
434 return mapTgtToSrc(ttgtField(), cop);
458 template<
class Type,
class CombineOp>
459 void Foam::meshToMesh::mapInternalSrcToTgt
461 const VolumeField<Type>&
field,
462 const CombineOp& cop,
463 VolumeField<Type>& result,
464 const bool secondOrder
474 result.primitiveFieldRef()
479 mapSrcToTgt(
field, cop, result.primitiveFieldRef());
484 template<
class Type,
class CombineOp>
485 void Foam::meshToMesh::mapAndOpSrcToTgt
488 const Field<Type>& srcField,
489 Field<Type>& tgtField,
493 tgtField = Type(
Zero);
495 AMI.interpolateToTarget
498 multiplyWeightedOp<Type, CombineOp>(cop),
505 template<
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();
565 template<
class Type,
class CombineOp>
569 const VolumeField<Type>&
field,
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],
629 tmp<VolumeField<Type>>
::New 636 "interpolate(" +
field.name() +
")" 641 Field<Type>(tgtMesh.nCells(),
Zero),
645 mapSrcToTgt(
field, cop, tresult.ref(), secondOrder);
651 template<
class Type,
class CombineOp>
656 const CombineOp& cop,
657 const bool secondOrder
660 return mapSrcToTgt(tfield(), cop, secondOrder);
669 const bool secondOrder
681 const bool secondOrder
688 template<
class Type,
class CombineOp>
689 void Foam::meshToMesh::mapInternalTgtToSrc
691 const VolumeField<Type>&
field,
692 const CombineOp& cop,
693 VolumeField<Type>& result,
694 const bool secondOrder
704 result.primitiveFieldRef()
709 mapTgtToSrc(
field, cop, result.primitiveFieldRef());
714 template<
class Type,
class CombineOp>
715 void Foam::meshToMesh::mapAndOpTgtToSrc
718 Field<Type>& srcField,
719 const Field<Type>& tgtField,
723 srcField = Type(
Zero);
725 AMI.interpolateToSource
728 multiplyWeightedOp<Type, CombineOp>(cop),
735 template<
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();
792 template<
class Type,
class CombineOp>
796 const VolumeField<Type>&
field,
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],
856 tmp<VolumeField<Type>>
::New 863 "interpolate(" +
field.name() +
")" 868 Field<Type>(srcMesh.nCells(),
Zero),
872 mapTgtToSrc(
field, cop, tresult.ref(), secondOrder);
878 template<
class Type,
class CombineOp>
883 const CombineOp& cop,
884 const bool secondOrder
887 return mapTgtToSrc(tfield(), cop, secondOrder);
896 const bool secondOrder
908 const bool secondOrder
List< scalar > scalarList
List of scalar.
static const this_type & null() noexcept
Return a null DimensionedField (reference to a nullObject).
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.
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.
AMIInterpolation AMIPatchToPatchInterpolation
Patch-to-patch interpolation == Foam::AMIInterpolation.
constexpr char nl
The newline '\n' character (0x0a)
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.
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.
DirectFieldMapper< fvPatchFieldMapper > directFvPatchFieldMapper
A fvPatchFieldMapper with direct mapping.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1, const label comm)
#define forAll(list, i)
Loop across all elements in list.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
static word scopedName(const std::string &scope, const word &name)
Create scope:name or scope_name string.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Calculate the gradient of the given field.
bool returnReduceAnd(const bool value, const int communicator=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
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...
static const word & calculatedType() noexcept
The type name for calculated patch fields.
Boundary & boundaryFieldRef(const bool updateAccessTime=true)
Return a reference to the boundary field.
List< point > pointList
List of point.
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.
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...
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)