34template<
class Type,
class CombineOp>
53 result[facei] = defaultValues[facei];
62 cop(result[facei], facei,
fld[slots[i]], weights[i]);
76 cop(result[facei], facei,
fld[slots[i]], weights[i]);
96 (toSource ? srcAddress_ : tgtAddress_),
97 (toSource ? srcWeights_ : tgtWeights_),
98 (toSource ? srcWeightsSum_ : tgtWeightsSum_),
107template<
class Type,
class CombineOp,
class InterpolateOp>
112 const CombineOp& cop,
113 const InterpolateOp& iop,
127 cache_.setDirection(toSource);
129 auto checkSizes = [&](
137 if (
fld.size() != tgtAddr.
size())
140 <<
"Supplied field size is not equal to "
141 << (toSource ?
"target" :
"source") <<
" patch size" <<
nl
142 <<
" source patch = " << srcAddr.
size() <<
nl
143 <<
" target patch = " << tgtAddr.
size() <<
nl
144 <<
" supplied field = " <<
fld.size()
148 if (result.
size() != srcAddr.
size())
151 <<
"Result field size is not equal to "
152 << (toSource ?
"target" :
"source") <<
" patch size" <<
nl
153 <<
" source patch = " << srcAddr.
size() <<
nl
154 <<
" target patch = " << tgtAddr.
size() <<
nl
155 <<
" result field = " << result.
size()
159 if ((lowWeightCorrection_ > 0) && (defVals.
size() != srcAddr.
size()))
162 <<
"Employing default values when sum of weights falls below "
163 << lowWeightCorrection_
164 <<
" but number of default values is not equal to "
165 << (toSource ?
"source" :
"target") <<
" patch size" <<
nl
166 <<
" default values = " << defVals.
size() <<
nl
167 <<
" source patch = " << srcAddr.
size() <<
nl
176 if (cache_.index0() != -1)
180 const auto& srcAddress = cache_.cSrcAddress0();
181 const auto& srcWeights = cache_.cSrcWeights0();
182 const auto& srcWeightsSum = cache_.cSrcWeightsSum0();
183 const auto& tgtAddress = cache_.cTgtAddress0();
185 checkSizes(
fld, srcAddress, tgtAddress, defaultValues, result0);
187 if (distributed() && cache_.cTgtMapPtr0())
191 if (map.comm() == -1)
196 work.resize_nocopy(map.constructSize());
198 map.distribute(work);
208 lowWeightCorrection_,
212 (distributed() ? work :
fld),
220 if (cache_.index1() != -1)
224 const auto& srcAddress = cache_.cSrcAddress1();
225 const auto& srcWeights = cache_.cSrcWeights1();
226 const auto& srcWeightsSum = cache_.cSrcWeightsSum1();
227 const auto& tgtAddress = cache_.cTgtAddress1();
229 checkSizes(
fld, srcAddress, tgtAddress, defaultValues, result1);
231 if (distributed() && cache_.cTgtMapPtr1())
235 if (map.comm() == -1)
240 work.resize_nocopy(map.constructSize());
242 map.distribute(work);
252 lowWeightCorrection_,
256 (distributed() ? work :
fld),
263 if (cache_.applyLower())
267 else if (cache_.applyUpper())
271 else if (cache_.applyInterpolate())
275 iop(result[i], i, i, result0[i], i, result1[i], cache_.weight());
282 const auto& srcAddress = (toSource ? srcAddress_ : tgtAddress_);
283 const auto& srcWeights = (toSource ? srcWeights_ : tgtWeights_);
284 const auto& srcWeightsSum =
285 (toSource ? srcWeightsSum_ : tgtWeightsSum_);
286 const auto& tgtAddress = (toSource ? tgtAddress_ : srcAddress_);
288 checkSizes(
fld, srcAddress, tgtAddress, defaultValues, result);
290 if (distributed() && tgtMapPtr_)
299 if (map.comm() == -1)
304 work.resize_nocopy(map.constructSize());
306 map.distribute(work);
318 lowWeightCorrection_,
322 (distributed() ? work :
fld),
332template<
class Type,
class CombineOp>
335 const UList<Type>&
fld,
336 const CombineOp& cop,
338 const UList<Type>& defaultValues
343 addProfiling(ami,
"AMIInterpolation::interpolateToTarget");
358 res = (scalar{1}-w)*a + w*
b;
373template<
class Type,
class CombineOp>
377 const CombineOp& cop,
384 addProfiling(ami,
"AMIInterpolation::interpolateToSource");
399 res = (scalar{1}-w)*a + w*
b;
415template<
class Type,
class CombineOp>
419 const CombineOp& cop,
437template<
class Type,
class CombineOp>
441 const CombineOp& cop,
449template<
class Type,
class CombineOp>
453 const CombineOp& cop,
471template<
class Type,
class CombineOp>
475 const CombineOp& cop,
523 return interpolateToTarget(tFld(),
plusEqOp<Type>(), defaultValues);
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))
const scalarField & srcWeightsSum() const
Return const access to normalisation factor of source patch weights (i.e. the sum before normalisatio...
labelListList srcAddress_
Addresses of target faces per source face.
bool distributed() const noexcept
Distributed across processors (singlePatchProc == -1).
const labelListList & srcAddress() const
Return const access to source patch addressing.
autoPtr< mapDistribute > srcMapPtr_
Source map pointer - parallel running only.
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Interpolate from target to source with supplied op to combine existing value with remote value and we...
autoPtr< mapDistribute > tgtMapPtr_
Target map pointer - parallel running only.
const scalarListList & srcWeights() const
Return const access to source patch weights.
labelListList tgtAddress_
Addresses of source faces per target face.
const scalar lowWeightCorrection_
Threshold weight below which interpolation is deactivated.
scalar lowWeightCorrection() const
Threshold weight below which interpolation is deactivated.
scalarField srcWeightsSum_
Sum of weights of target faces per source face.
scalarListList tgtWeights_
Weights of source faces per target face.
static void weightedSum(const scalar lowWeightCorrection, const labelListList &allSlots, const scalarListList &allWeights, const scalarField &weightsSum, const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues)
Weighted sum of contributions. Note: cop operates on single Type only.
void interpolate(const bool toSource, const UList< Type > &fld, const CombineOp &cop, const InterpolateOp &iop, List< Type > &result, const UList< Type > &defaultValues) const
Weighted sum of (potentially distributed) contributions and apply caching+interpolation....
scalarListList srcWeights_
Weights of target faces per source face.
scalarField tgtWeightsSum_
Sum of weights of source faces per target face.
const labelListList & tgtAddress() const
Return const access to target patch addressing.
void interpolateToTarget(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Interpolate from source to target with supplied op to combine existing value with remote value and we...
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
A non-owning sub-view of a List (allocated or unallocated storage).
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
void size(const label n)
Older name for setAddressableSize.
label comm() const noexcept
The communicator used.
label constructSize() const noexcept
Constructed data size.
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.
A class for managing temporary objects.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
List< scalarList > scalarListList
List of scalarList.
Type weightedSum(const UList< scalar > &weights, const UList< Type > &fld)
The local weighted sum (integral) of a field, using the mag() of the weights.
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.
List< labelList > labelListList
List of labelList.
List< label > labelList
A List of labels.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0).
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
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 addProfiling(Name,...)
Define profiling trigger with specified name and description string. The description is generated by ...
#define forAll(list, i)
Loop across all elements in list.