38 const dictionary&
dict,
44 return dict.get<Type>(
"average");
59 const word& fieldName,
65 const label nProcs = Pstream::nProcs(0);
67 for (label domain = 0; domain < nProcs; domain++)
77 mapper_.sendPath(domain)
84 Pout<<
"*** STORING :"
85 <<
" field:" << fieldName
90 mappedPatchBase::storeField
105 const bool allowUnset,
110 const word& fieldName,
116 const label nProcs = Pstream::nProcs(0);
118 for (label domain = 0; domain < nProcs; domain++)
120 const labelList& map = procToMap[domain];
126 mapper_.receivePath(domain)
145 Pout<<
"*** RETRIEVED :"
146 <<
" field:" << fieldName
154 <<
" field:" << fieldName
175 const word& fieldName,
181 const label nProcs = Pstream::nProcs(0);
183 for (label domain = 0; domain < nProcs; domain++)
186 if (constructMap.size())
191 mapper_.receivePath(domain)
200 Pout<<
"*** STORING INITIAL :"
201 <<
" field:" << fieldName <<
" values:"
204 <<
" constructMap:" <<
flatOutput(constructMap)
208 mappedPatchBase::storeField
226 const word& fieldName,
227 const bool setAverage,
229 const word& interpolationScheme
233 patchField_(patchField),
234 fieldName_(fieldName),
235 setAverage_(setAverage),
237 interpolationScheme_(interpolationScheme)
250 patchField_(patchField),
253 dict.template getOrDefault<word>
256 patchField_.internalField().name()
259 setAverage_(
dict.getOrDefault(
"setAverage",
false)),
260 average_(getAverage(
dict, setAverage_)),
265 mapper_.sampleDatabase()
266 && mapper_.mode() != mappedPatchBase::NEARESTPATCHFACE
270 <<
"Mapping using the database only supported for "
272 << mappedPatchBase::sampleModeNames_
274 mappedPatchBase::NEARESTPATCHFACE
279 if (mapper_.mode() == mappedPatchBase::NEARESTCELL)
281 dict.readEntry(
"interpolationScheme", interpolationScheme_);
302 mapper_.mode() == mappedPatchBase::NEARESTPATCHFACE
303 && mapper_.sampleDatabase()
309 patchField_.internalField().time(),
310 patchField_.patch().boundaryMesh().mesh().name(),
311 patchField_.patch().name(),
313 patchField_.internalField().name(),
328 patchField_(patchField),
329 fieldName_(patchField_.internalField().name()),
360 patchField_(patchField),
371 template<
class Type2>
377 if (mapper_.sameRegion())
379 if (fieldName == patchField_.internalField().name())
383 dynamic_cast<const fieldType&
>
385 patchField_.internalField()
391 return thisMesh.template lookupObject<fieldType>(fieldName);
395 const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
396 return nbrMesh.template lookupObject<fieldType>(fieldName);
404 return sampleField<Type>(fieldName_);
412 const word& fieldName,
416 if (mapper_.sampleDatabase())
421 patchField_.internalField().time(),
422 patchField_.patch().boundaryMesh().mesh().name(),
423 patchField_.patch().name(),
424 mapper_.map().subMap(),
429 newValues.setSize(mapper_.map().constructSize());
433 patchField_.internalField().time(),
434 mapper_.sampleRegion(),
435 mapper_.samplePatch(),
436 mapper_.map().constructMap(),
443 mapper_.distribute(newValues);
460 int oldTag = UPstream::msgType();
461 UPstream::msgType() = oldTag + 1;
467 auto& newValues = tnewValues.ref();
469 switch (mapper_.mode())
471 case mappedPatchBase::NEARESTCELL:
473 const fieldType&
fld = sampleField();
478 if (!mapper_.sameWorld() || mapper_.sampleDatabase())
481 <<
"Interpolating cell values from different world"
482 <<
" or database currently not supported"
487 refCast<const fvMesh>(mapper_.sampleMesh());
506 interpolationScheme_,
510 const auto& interp = *interpolator;
517 newValues[celli] = interp.interpolate
530 distribute(fieldName_, newValues);
534 case mappedPatchBase::NEARESTPATCHFACE:
535 case mappedPatchBase::NEARESTPATCHFACEAMI:
537 if (mapper_.sameWorld())
540 refCast<const fvMesh>(mapper_.sampleMesh());
541 const fieldType&
fld = sampleField();
543 const label nbrPatchID =
549 <<
"Unable to find sample patch " << mapper_.samplePatch()
550 <<
" in region " << mapper_.sampleRegion()
551 <<
" for patch " << patchField_.patch().name() <<
nl
555 const auto& nbrField =
fld;
557 newValues = nbrField.boundaryField()[nbrPatchID];
563 newValues = patchField_;
565 distribute(fieldName_, newValues);
569 case mappedPatchBase::NEARESTFACE:
572 if (mapper_.sameWorld())
575 refCast<const fvMesh>(mapper_.sampleMesh());
576 const fieldType&
fld = sampleField();
580 const auto& nbrField =
fld;
584 label faceStart = pf.patch().start();
588 allValues[faceStart++] = pf[facei];
598 const fieldType& thisFld =
dynamic_cast<const fieldType&
>
600 patchField_.internalField()
605 label faceStart = pf.patch().start();
609 allValues[faceStart++] = pf[facei];
614 distribute(fieldName_, allValues);
615 newValues.transfer(allValues);
622 <<
"Unknown sampling mode: " << mapper_.mode() <<
nl
630 gSum(patchField_.patch().magSf()*newValues)
631 /
gSum(patchField_.patch().magSf());
633 if (
mag(averagePsi)/
mag(average_) > 0.5)
635 newValues *=
mag(average_)/
mag(averagePsi);
639 newValues += (average_ - averagePsi);
644 UPstream::msgType() = oldTag;
667 if (mapper_.sameWorld())
670 const label nbrPatchID = mapper_.samplePolyPatch().index();
671 const auto& nbrField = this->sampleField();
672 nbrIntFld = nbrField.boundaryField()[nbrPatchID].patchInternalField();
678 nbrIntFld = patchField_.patchInternalField();
683 int oldTag = UPstream::msgType();
684 UPstream::msgType() = oldTag+1;
686 distribute(fieldName_, nbrIntFld);
689 UPstream::msgType() = oldTag;
703 if (mapper_.sameWorld())
706 const auto& nbrMesh = refCast<const fvMesh>(this->mapper_.sampleMesh());
707 const label nbrPatchID = mapper_.samplePolyPatch().index();
708 const auto& nbrPatch = nbrMesh.boundary()[nbrPatchID];
709 nbrKDelta = nbrPatch.deltaCoeffs();
715 nbrKDelta = patchField_.patch().deltaCoeffs();
721 const int oldTag = UPstream::msgType();
722 UPstream::msgType() = oldTag+1;
724 distribute(fieldName_ +
"_deltaCoeffs", nbrKDelta);
727 UPstream::msgType() = oldTag;
736 const word& fieldName,
741 thisWeights =
new scalarField(patchField_.patch().deltaCoeffs());
742 if (!fieldName.empty())
745 patchField_.patch().template lookupPatchField
752 ).patchInternalField();
758 if (mapper_.sameWorld())
761 const auto& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
762 const label nbrPatchID = mapper_.samplePolyPatch().index();
763 const auto& nbrPatch = nbrMesh.boundary()[nbrPatchID];
765 nbrWeights =
new scalarField(nbrPatch.deltaCoeffs());
767 if (!fieldName.empty())
770 const auto& nbrWeightField =
771 nbrMesh.template lookupObject<volScalarField>(fieldName);
773 nbrWeightField.boundaryField()[nbrPatchID].patchInternalField();
785 int oldTag = UPstream::msgType();
786 UPstream::msgType() = oldTag+1;
788 distribute(fieldName_ +
"_weights", nbrWeights.
ref());
791 UPstream::msgType() = oldTag;
802 if (!isA<mappedPatchBase>(
p.patch()))
805 <<
"Incorrect patch type " <<
p.patch().type()
806 <<
" for patch " <<
p.patch().name()
807 <<
" of field " << iF.name()
808 <<
" in file " << iF.objectPath() <<
nl
809 <<
"Type should be a mappedPatch"
812 return refCast<const mappedPatchBase>(
p.patch());
820 const word& fieldName,
824 if (mapper_.sampleDatabase())
830 patchField_.internalField().time(),
831 mapper_.sampleRegion(),
832 mapper_.samplePatch(),
852 if (mapper_.mode() == mappedPatchBase::NEARESTCELL)
854 os.
writeEntry(
"interpolationScheme", interpolationScheme_);