38 const dictionary&
dict,
44 return dict.get<Type>(
"average");
60 const word& fieldName,
66 const auto& procIDs = UPstream::procID(myComm);
71 const label proci = procIDs[ranki];
79 mappedPatchBase::subRegistry
82 mapper_.sendPath(proci)
90 Pout<<
"*** STORING :" 91 <<
" field:" << fieldName
93 <<
" as:" << subObr.objectPath() <<
endl;
96 mappedPatchBase::storeField(subObr, fieldName, subFld);
106 const bool allowUnset,
107 const objectRegistry& obr,
112 const word& fieldName,
116 const auto& procIDs = UPstream::procID(myComm);
123 const label proci = procIDs[ranki];
127 auto& subObr =
const_cast<objectRegistry&
> 129 mappedPatchBase::subRegistry
132 mapper_.receivePath(proci)
138 const IOField<T>* subFldPtr = subObr.getObjectPtr<IOField<T>>
144 if (subFldPtr->size() != map.size())
157 UIndirectList<T>(
fld, map) = *subFldPtr;
161 Pout<<
"*** RETRIEVED :" 162 <<
" field:" << fieldName
164 <<
" from:" << subObr.objectPath() <<
endl;
173 <<
" field:" << fieldName
174 <<
" in:" << subObr.objectPath() <<
endl;
180 const Field<T> dummyFld(0);
182 mappedPatchBase::storeField(subObr, fieldName, dummyFld);
189 (void)subObr.lookupObject<IOField<T>>(fieldName);
206 const word& fieldName,
213 const label nProcs = Pstream::nProcs(0);
215 for (label domain = 0; domain < nProcs; domain++)
217 const labelList& constructMap = map[domain];
218 if (constructMap.
size())
222 mappedPatchBase::subRegistry
225 mapper_.receivePath(domain)
235 Pout<<
"*** STORING INITIAL :" 236 <<
" field:" << fieldName <<
" values:" 239 <<
" constructMap:" <<
flatOutput(constructMap)
240 <<
" as:" << subObr.objectPath() <<
endl;
243 mappedPatchBase::storeField(subObr, fieldName, receiveFld);
253 const word& fieldName,
256 const label constructSize,
265 patchField_.internalField().time(),
266 patchField_.patch().boundaryMesh().mesh().name(),
267 patchField_.patch().name(),
274 Field<T> work(constructSize);
275 const bool ok = retrieveField
278 patchField_.internalField().time(),
279 mapper_.sampleRegion(),
280 mapper_.samplePatch(),
291 fld.setSize(address.size());
294 const plusEqOp<T> cop;
295 const multiplyWeightedOp<T, plusEqOp<T>> mop(cop);
304 mop(
fld[facei], facei, work[slots[i]], w[i]);
324 const word& fieldName,
325 const bool setAverage,
327 const word& interpolationScheme
331 patchField_(patchField),
332 fieldName_(fieldName),
333 setAverage_(setAverage),
335 interpolationScheme_(interpolationScheme)
348 patchField_(patchField),
354 patchField_.internalField().
name()
357 setAverage_(
dict.getOrDefault(
"setAverage", false)),
358 average_(getAverage(
dict, setAverage_)),
363 mapper_.sampleDatabase()
365 mapper_.mode() != mappedPatchBase::NEARESTPATCHFACE
366 && mapper_.mode() != mappedPatchBase::NEARESTPATCHFACEAMI
371 <<
"Mapping using the database only supported for " 373 << mappedPatchBase::sampleModeNames_
375 mappedPatchBase::NEARESTPATCHFACE
378 << mappedPatchBase::sampleModeNames_
380 mappedPatchBase::NEARESTPATCHFACEAMI
385 if (mapper_.mode() == mappedPatchBase::NEARESTCELL)
387 dict.readEntry(
"interpolationScheme", interpolationScheme_);
406 if (mapper_.sampleDatabase())
408 if (mapper_.mode() == mappedPatchBase::NEARESTPATCHFACE)
413 patchField_.internalField().time(),
415 mapper_.sampleRegion(),
417 mapper_.samplePatch(),
418 mapper_.map().constructMap(),
419 patchField_.internalField().name(),
423 else if (mapper_.mode() == mappedPatchBase::NEARESTPATCHFACEAMI)
436 const mappedPatchBase& mapper,
437 const fvPatchField<Type>& patchField
441 patchField_(patchField),
442 fieldName_(patchField_.internalField().
name()),
455 mapper_(mapper.mapper_),
456 patchField_(mapper.patchField_),
457 fieldName_(mapper.fieldName_),
458 setAverage_(mapper.setAverage_),
459 average_(mapper.average_),
460 interpolationScheme_(mapper.interpolationScheme_)
473 patchField_(patchField),
474 fieldName_(base.fieldName_),
475 setAverage_(base.setAverage_),
476 average_(base.average_),
477 interpolationScheme_(base.interpolationScheme_)
484 template<
class Type2>
490 if (mapper_.sameRegion())
492 if (fieldName == patchField_.internalField().name())
496 dynamic_cast<const fieldType&
> 498 patchField_.internalField()
504 return thisMesh.template lookupObject<fieldType>(fieldName);
508 const fvMesh& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
509 return nbrMesh.template lookupObject<fieldType>(fieldName);
517 return sampleField<Type>(fieldName_);
525 const word& fieldName,
529 if (mapper_.sampleDatabase())
531 const label myComm = mapper_.getCommunicator();
533 if (mapper_.mode() != mappedPatchBase::NEARESTPATCHFACEAMI)
538 patchField_.internalField().time(),
539 patchField_.patch().boundaryMesh().mesh().name(),
540 patchField_.patch().name(),
542 mapper_.map().subMap(),
547 fld.setSize(mapper_.map().constructSize());
551 patchField_.internalField().time(),
552 mapper_.sampleRegion(),
553 mapper_.samplePatch(),
555 mapper_.map().constructMap(),
569 if (mapper_.masterWorld())
573 storeAndRetrieveField
589 storeAndRetrieveField
605 mapper_.distribute(
fld);
622 int oldTag = UPstream::msgType();
623 UPstream::msgType() = oldTag + 1;
629 auto& newValues = tnewValues.ref();
631 switch (mapper_.mode())
633 case mappedPatchBase::NEARESTCELL:
635 const fieldType&
fld = sampleField();
640 if (!mapper_.sameWorld() || mapper_.sampleDatabase())
643 <<
"Interpolating cell values from different world" 644 <<
" or database currently not supported" 649 refCast<const fvMesh>(mapper_.sampleMesh());
668 interpolationScheme_,
672 const auto& interp = *interpolator;
679 newValues[celli] = interp.interpolate
692 distribute(fieldName_, newValues);
696 case mappedPatchBase::NEARESTPATCHFACE:
697 case mappedPatchBase::NEARESTPATCHFACEAMI:
699 if (mapper_.sameWorld())
702 refCast<const fvMesh>(mapper_.sampleMesh());
703 const fieldType&
fld = sampleField();
705 const label nbrPatchID =
711 <<
"Unable to find sample patch " << mapper_.samplePatch()
712 <<
" in region " << mapper_.sampleRegion()
713 <<
" for patch " << patchField_.patch().name() <<
nl 717 const auto& nbrField =
fld;
719 newValues = nbrField.boundaryField()[nbrPatchID];
725 newValues = patchField_;
727 distribute(fieldName_, newValues);
731 case mappedPatchBase::NEARESTFACE:
734 if (mapper_.sameWorld())
737 refCast<const fvMesh>(mapper_.sampleMesh());
738 const fieldType&
fld = sampleField();
742 const auto& nbrField =
fld;
746 label faceStart = pf.patch().start();
750 allValues[faceStart++] = pf[facei];
760 const fieldType& thisFld =
dynamic_cast<const fieldType&
> 762 patchField_.internalField()
767 label faceStart = pf.patch().start();
771 allValues[faceStart++] = pf[facei];
776 distribute(fieldName_, allValues);
777 newValues.transfer(allValues);
784 <<
"Unknown sampling mode: " << mapper_.mode() <<
nl 792 gSum(patchField_.patch().magSf()*newValues)
793 /
gSum(patchField_.patch().magSf());
795 if (
mag(averagePsi) > 0.5*
mag(average_))
797 newValues *=
mag(average_)/
mag(averagePsi);
801 newValues += (average_ - averagePsi);
806 UPstream::msgType() = oldTag;
829 if (mapper_.sameWorld())
832 const label nbrPatchID = mapper_.samplePolyPatch().index();
833 const auto& nbrField = this->sampleField();
834 nbrIntFld = nbrField.boundaryField()[nbrPatchID].patchInternalField();
840 nbrIntFld = patchField_.patchInternalField();
845 int oldTag = UPstream::msgType();
846 UPstream::msgType() = oldTag+1;
848 distribute(fieldName_, nbrIntFld);
851 UPstream::msgType() = oldTag;
865 if (mapper_.sameWorld())
868 const auto& nbrMesh = refCast<const fvMesh>(this->mapper_.sampleMesh());
869 const label nbrPatchID = mapper_.samplePolyPatch().index();
870 const auto& nbrPatch = nbrMesh.
boundary()[nbrPatchID];
871 nbrKDelta = nbrPatch.deltaCoeffs();
877 nbrKDelta = patchField_.patch().deltaCoeffs();
883 const int oldTag = UPstream::msgType();
884 UPstream::msgType() = oldTag+1;
886 distribute(fieldName_ +
"_deltaCoeffs", nbrKDelta);
889 UPstream::msgType() = oldTag;
898 const word& fieldName,
903 thisWeights =
new scalarField(patchField_.patch().deltaCoeffs());
904 if (!fieldName.empty())
907 patchField_.patch().template lookupPatchField
914 ).patchInternalField();
920 if (mapper_.sameWorld())
923 const auto& nbrMesh = refCast<const fvMesh>(mapper_.sampleMesh());
924 const label nbrPatchID = mapper_.samplePolyPatch().index();
925 const auto& nbrPatch = nbrMesh.
boundary()[nbrPatchID];
927 nbrWeights =
new scalarField(nbrPatch.deltaCoeffs());
929 if (!fieldName.empty())
932 const auto& nbrWeightField =
933 nbrMesh.template lookupObject<volScalarField>(fieldName);
935 nbrWeightField.boundaryField()[nbrPatchID].patchInternalField();
947 int oldTag = UPstream::msgType();
948 UPstream::msgType() = oldTag+1;
950 distribute(fieldName_ +
"_weights", nbrWeights.
ref());
953 UPstream::msgType() = oldTag;
964 if (!isA<mappedPatchBase>(
p.patch()))
967 <<
"Incorrect patch type " <<
p.patch().type()
968 <<
" for patch " <<
p.patch().name()
969 <<
" of field " << iF.
name()
971 <<
"Type should be a mappedPatch" 974 return refCast<const mappedPatchBase>(
p.patch());
982 const word& fieldName,
986 if (mapper_.sampleDatabase())
990 if (mapper_.mode() == mappedPatchBase::NEARESTPATCHFACE)
994 patchField_.internalField().time(),
995 mapper_.sampleRegion(),
996 mapper_.samplePatch(),
997 mapper_.map().constructMap(),
1006 template<
class Type>
1010 os.writeEntryIfDifferent<word>
1013 patchField_.internalField().name(),
1019 os.writeEntry(
"setAverage",
"true");
1020 os.writeEntry(
"average", average_);
1023 if (mapper_.mode() == mappedPatchBase::NEARESTCELL)
1025 os.writeEntry(
"interpolationScheme", interpolationScheme_);
label findPatchID(const word &patchName, const bool allowNotFound=true) const
Find patch index given a name, return -1 if not found.
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
List< labelList > labelListList
A List of labelList.
void size(const label n)
Older name for setAddressableSize.
void initRetrieveField(const objectRegistry &obr, const word ®ion, const word &patch, const labelListList &map, const word &fieldName, const Field< T > &fld) const
Construct field from registered elements.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
const scalarListList & tgtWeights() const
Return const access to target patch weights.
static const mappedPatchBase & mapper(const fvPatch &p, const DimensionedField< Type, volMesh > &iF)
Check that patch is of correct type.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
virtual void write(Ostream &os) const
Write.
virtual tmp< scalarField > mappedWeightField() const
Map optional weightField onto *this patch. Default is deltaCoeffs.
const word & name() const noexcept
Return the object name.
T & ref() const
Return non-const reference to the contents of a non-null managed pointer.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
const mapDistribute & srcMap() const
Source map pointer - valid only if singlePatchProc = -1 This gets source data into a form to be consu...
constexpr char nl
The newline '\n' character (0x0a)
const labelListList & tgtAddress() const
Return const access to target patch addressing.
scalarField samples(nIntervals, Zero)
Ostream & endl(Ostream &os)
Add newline and flush stream.
tmp< GeometricField< Type, faPatchField, areaMesh > > average(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Area-weighted average a edgeField creating a areaField.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
A traits class, which is primarily used for primitives.
virtual tmp< Field< Type > > mappedInternalField() const
Map internal of sampleField onto *this patch.
label constructSize() const noexcept
Constructed data size.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Generic GeometricField class.
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.
const GeometricField< Type, fvPatchField, volMesh > & sampleField() const
Field to sample. Either on my or nbr mesh.
label nFaces() const noexcept
Number of mesh faces.
fileName objectPath() const
The complete path + object name.
#define forAll(list, i)
Loop across all elements in list.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
void setSize(const label n)
Alias for resize()
Type gSum(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
const polyMesh & mesh() const noexcept
Return the mesh reference.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
List< scalar > scalarList
A List of scalars.
Determines a mapping between patch face centres and mesh cell or face centres and processors they're ...
errorManip< error > abort(error &err)
void reverseDistribute(const label constructSize, List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
bool storeAndRetrieveField(const word &fieldName, const label myComm, const labelListList &subMap, const label constructSize, const labelListList &constructMap, const labelListList &address, const scalarListList &weights, Field< T > &fld) const
Helper : storeField and retrieveField and interpolate. Leaves fld.
const scalarListList & srcWeights() const
Return const access to source patch weights.
int debug
Static debugging option.
virtual tmp< Field< Type > > mappedField() const
Map sampleField onto *this patch.
OBJstream os(runTime.globalPath()/outputName)
mappedPatchFieldBase(const mappedPatchBase &mapper, const fvPatchField< Type > &patchField, const word &fieldName, const bool setAverage, const Type average, const word &interpolationScheme)
Construct from components.
Functionality for sampling fields using mappedPatchBase. Every call to mappedField() returns a sample...
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))
const labelListList & constructMap() const noexcept
From subsetted data to new reconstructed data.
void storeField(const objectRegistry &obr, const word ®ion, const word &patch, const label myComm, const labelListList &procToMap, const word &fieldName, const Field< T > &fld) const
Store elements of field onto (sub) registry.
Class containing processor-to-processor mapping information.
List< scalarList > scalarListList
A List of scalarList.
#define WarningInFunction
Report a warning using Foam::Warning.
label nCells() const noexcept
Number of mesh cells.
Mesh data needed to do the Finite Volume discretisation.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
const std::string patch
OpenFOAM patch number as a std::string.
bool retrieveField(const bool allowUnset, const objectRegistry &obr, const word ®ion, const word &patch, const label myComm, const labelListList &procToMap, const word &fieldName, Field< T > &fld) const
Construct field from registered elements.
List< label > labelList
A List of labels.
const mapDistribute & tgtMap() const
Target map pointer - valid only if singlePatchProc=-1. This gets target data into a form to be consum...
A class for managing temporary objects.
Registry of regIOobjects.
const labelListList & subMap() const noexcept
From subsetted data back to original data.
const labelListList & srcAddress() const
Return const access to source patch addressing.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
void distribute(const word &fieldName, Field< T > &newValues) const
Wrapper for mapDistribute::distribute that knows about dabase mapping.
Uses the cell value for any location within the cell.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
static constexpr const zero Zero
Global zero (0)