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].distributed()
541 ? AMIList[i].hasSrcMap()
544 AMIList[i].tgtAddress(),
545 AMIList[i].tgtWeights()
556 mapAndOpSrcToTgt(AMIList[i], srcField, tgtField, cop);
559 forAll(cuttingPatches_, i)
561 label patchi = cuttingPatches_[i];
562 fvPatchField<Type>& pf = resultBf[patchi];
563 pf == pf.patchInternalField();
568 template<
class Type,
class CombineOp>
572 const VolumeField<Type>&
field,
573 const CombineOp& cop,
574 const bool secondOrder
577 const fvMesh& tgtMesh =
static_cast<const fvMesh&
>(tgtRegion_);
579 const fvBoundaryMesh& tgtBm = tgtMesh.boundary();
580 const auto& srcBfld =
field.boundaryField();
582 PtrList<fvPatchField<Type>> tgtPatchFields(tgtBm.size());
589 label srcPatchi = srcPatchID_[i];
590 label tgtPatchi = tgtPatchID_[i];
592 if (!tgtPatchFields.set(tgtPatchi))
600 tgtMesh.boundary()[tgtPatchi],
604 labelList(tgtMesh.boundary()[tgtPatchi].size(), -1)
612 forAll(tgtPatchFields, tgtPatchi)
614 if (!tgtPatchFields.set(tgtPatchi))
624 tgtMesh.boundary()[tgtPatchi],
632 tmp<VolumeField<Type>>
::New 639 "interpolate(" +
field.name() +
")" 644 Field<Type>(tgtMesh.nCells(),
Zero),
648 mapSrcToTgt(
field, cop, tresult.ref(), secondOrder);
654 template<
class Type,
class CombineOp>
659 const CombineOp& cop,
660 const bool secondOrder
663 return mapSrcToTgt(tfield(), cop, secondOrder);
672 const bool secondOrder
684 const bool secondOrder
691 template<
class Type,
class CombineOp>
692 void Foam::meshToMesh::mapInternalTgtToSrc
694 const VolumeField<Type>&
field,
695 const CombineOp& cop,
696 VolumeField<Type>& result,
697 const bool secondOrder
707 result.primitiveFieldRef()
712 mapTgtToSrc(
field, cop, result.primitiveFieldRef());
717 template<
class Type,
class CombineOp>
718 void Foam::meshToMesh::mapAndOpTgtToSrc
721 Field<Type>& srcField,
722 const Field<Type>& tgtField,
726 srcField = Type(
Zero);
728 AMI.interpolateToSource
731 multiplyWeightedOp<Type, CombineOp>(cop),
738 template<
class Type,
class CombineOp>
742 const CombineOp& cop,
744 const bool secondOrder
747 mapInternalTgtToSrc(
field, cop, result, secondOrder);
753 label srcPatchi = srcPatchID_[i];
754 label tgtPatchi = tgtPatchID_[i];
770 AMIList[i].singlePatchProc(),
772 AMIList[i].distributed()
773 ? AMIList[i].hasTgtMap()
776 AMIList[i].srcAddress(),
777 AMIList[i].srcWeights()
787 mapAndOpTgtToSrc(AMIList[i], srcField, tgtField, cop);
790 forAll(cuttingPatches_, i)
792 label patchi = cuttingPatches_[i];
794 pf == pf.patchInternalField();
799 template<
class Type,
class CombineOp>
803 const VolumeField<Type>&
field,
804 const CombineOp& cop,
805 const bool secondOrder
808 const fvMesh& srcMesh =
static_cast<const fvMesh&
>(srcRegion_);
810 const fvBoundaryMesh& srcBm = srcMesh.boundary();
811 const auto& tgtBfld =
field.boundaryField();
813 PtrList<fvPatchField<Type>> srcPatchFields(srcBm.size());
820 label srcPatchi = srcPatchID_[i];
821 label tgtPatchi = tgtPatchID_[i];
823 if (!srcPatchFields.set(srcPatchi))
831 srcMesh.boundary()[srcPatchi],
835 labelList(srcMesh.boundary()[srcPatchi].size(), -1)
843 forAll(srcPatchFields, srcPatchi)
845 if (!srcPatchFields.set(srcPatchi))
855 srcMesh.boundary()[srcPatchi],
863 tmp<VolumeField<Type>>
::New 870 "interpolate(" +
field.name() +
")" 875 Field<Type>(srcMesh.nCells(),
Zero),
879 mapTgtToSrc(
field, cop, tresult.ref(), secondOrder);
885 template<
class Type,
class CombineOp>
890 const CombineOp& cop,
891 const bool secondOrder
894 return mapTgtToSrc(tfield(), cop, secondOrder);
903 const bool secondOrder
915 const bool secondOrder
List< scalar > scalarList
List of scalar.
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.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &f1)
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 const DimensionedField< Type, GeoMesh > & null() noexcept
Return a null DimensionedField (reference to a nullObject).
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.
#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.
bool returnReduceAnd(const bool value, const label comm=UPstream::worldComm)
Perform logical (and) MPI Allreduce on a copy. Uses UPstream::reduceAnd.
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...
Generic templated field type.
Calculate the gradient of the given field.
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...
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.
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)