37 const bool dictConstructed,
39 const word& entryName,
40 const dictionary&
dict,
41 const word& fieldTableName,
45 PatchFunction1<Type>(
pp, entryName,
dict, faceValues),
46 dictConstructed_(dictConstructed),
47 setAverage_(
dict.getOrDefault(
"setAverage", false)),
48 perturb_(
dict.getOrDefault<scalar>(
"perturb", 1
e-5)),
49 fieldTableName_(fieldTableName),
50 pointsName_(
dict.getOrDefault<word>(
"points",
"points")),
52 filterRadius_(
dict.getOrDefault<scalar>(
"filterRadius", 0)),
53 filterSweeps_(
dict.getOrDefault<label>(
"filterSweeps", 0)),
54 filterFieldPtr_(nullptr),
65 Function1<Type>::NewIfPresent
69 patchFunction1Base::whichDb()
73 if (fieldTableName_.empty())
79 if ((filterSweeps_ < 1) || (filterRadius_ <= VSMALL))
85 if (
dict.readIfPresent(
"sampleFormat", readerFormat_))
87 dict.readEntry(
"sampleFile", readerFile_);
89 fileName fName(readerFile_);
102 Info<<
"mappedFile:" <<
nl;
103 if (readerFormat_.empty())
105 Info<<
" boundary format" <<
nl;
109 Info<<
" format:" << readerFormat_
110 <<
" file:" << readerFile_ <<
nl;
113 Info<<
" filter radius=" << filterRadius_
114 <<
" sweeps=" << filterSweeps_ <<
endl;
119 dict.readIfPresent(
"mapMethod", mapMethod_)
120 && !mapMethod_.empty()
121 && mapMethod_ !=
"nearest" 126 <<
"Unknown mapMethod type " << mapMethod_
127 <<
"\n\nValid mapMethod types :\n" 128 <<
"(nearest planar)" <<
nl 138 const word& redirectType,
139 const word& entryName,
141 const bool faceValues
150 dict.getOrDefault<
word>(
"fieldTable", entryName),
160 const word& entryName,
162 const word& fieldTableName,
163 const bool faceValues
186 dictConstructed_(rhs.dictConstructed_),
187 setAverage_(rhs.setAverage_),
188 perturb_(rhs.perturb_),
189 fieldTableName_(rhs.fieldTableName_),
190 pointsName_(rhs.pointsName_),
191 mapMethod_(rhs.mapMethod_),
192 filterRadius_(rhs.filterRadius_),
193 filterSweeps_(rhs.filterSweeps_),
194 filterFieldPtr_(nullptr),
195 readerFormat_(rhs.readerFormat_),
196 readerFile_(rhs.readerFile_),
198 mapperPtr_(rhs.mapperPtr_.clone()),
199 sampleTimes_(rhs.sampleTimes_),
200 sampleIndex_(rhs.sampleIndex_),
201 sampleAverage_(rhs.sampleAverage_),
202 sampleValues_(rhs.sampleValues_),
203 offset_(rhs.offset_.clone())
205 if (!readerFormat_.empty() && !readerFile_.empty())
218 const MappedFile<Type>& rhs
221 MappedFile<Type>(rhs, rhs.
patch())
235 if (sampleValues_.first().size())
237 sampleValues_.first().autoMap(mapper);
239 if (sampleValues_.second().size())
241 sampleValues_.second().autoMap(mapper);
245 filterFieldPtr_.reset(
nullptr);
246 mapperPtr_.reset(
nullptr);
261 refCast<const PatchFunction1Types::MappedFile<Type>>(pf1);
263 if (tiptf.sampleValues_.first().size())
265 sampleValues_.first().resize(this->size());
266 sampleValues_.first().rmap(tiptf.sampleValues_.first(), addr);
269 if (tiptf.sampleValues_.second().size())
271 sampleValues_.second().resize(this->size());
272 sampleValues_.second().rmap(tiptf.sampleValues_.second(), addr);
276 filterFieldPtr_.reset(
nullptr);
277 mapperPtr_.reset(
nullptr);
285 const label sampleIndex,
290 tmp<Field<Type>> tvalues;
295 wordList fieldNames = readerPtr_->fieldNames(sampleIndex);
297 label fieldIndex = fieldNames.
find(fieldTableName_);
302 <<
"Sample field='" << fieldTableName_
303 <<
"' not found. Known field names: " 310 Pout<<
"checkTable : Update index=" << sampleIndex
311 <<
" field=" << fieldNames[fieldIndex] <<
endl;
314 tvalues = readerPtr_->field
321 if (tvalues().size() != mapperPtr_().sourceSize())
324 <<
"Number of values (" << tvalues().size()
325 <<
") differs from the number of points (" 326 << mapperPtr_().sourceSize() <<
")" 332 const polyMesh&
mesh = this->patch_.boundaryMesh().mesh();
333 const Time& time =
mesh.time();
337 Pout<<
"checkTable : Update index=" << sampleIndex
338 <<
" Reading values from " 342 / this->patch_.name()
343 / sampleTimes_[sampleIndex].name()
349 const fileName valsFile
356 /sampleTimes_[sampleIndex].name()
370 rawIOField<Type> vals(
io, setAverage_);
372 if (vals.hasAverage())
374 avg = vals.average();
377 if (vals.size() != mapperPtr_().sourceSize())
380 <<
"Number of values (" << vals.size()
381 <<
") differs from the number of points (" 382 << mapperPtr_().sourceSize()
383 <<
") in file " << valsFile
387 tvalues = tmp<Field<Type>>
::New(std::move(vals.field()));
393 <<
"apply " << filterSweeps_ <<
" filter sweeps" <<
endl;
395 tvalues = filterFieldPtr_().evaluate(tvalues, filterSweeps_);
399 field = mapperPtr_().interpolate(tvalues);
409 const polyMesh&
mesh = this->patch_.boundaryMesh().mesh();
410 const Time& time =
mesh.time();
413 if (!mapperPtr_ && readerPtr_)
417 auto& reader = readerPtr_();
421 sampleTimes_ = reader.times();
428 geom.nFaces() ? geom.faceCentres() : geom.points()
432 <<
"Read " << samplePoints.size() <<
" sample points from " 433 << readerFile_ <<
endl 436 <<
"... in " << timing.timeIncrement() <<
's' <<
endl;
439 const bool nearestOnly =
441 !mapMethod_.empty() && !mapMethod_.starts_with(
"planar")
445 if (this->faceValues())
449 new pointToPointPlanarInterpolation
452 this->localPosition(this->patch_.faceCentres()),
462 new pointToPointPlanarInterpolation
465 this->localPosition(this->patch_.localPoints()),
473 <<
"Created point/point planar interpolation" 474 <<
" - in " << timing.timeIncrement() <<
's' <<
endl;
478 if (filterSweeps_ > 0)
480 filterFieldPtr_.reset(
new FilterField(geom, filterRadius_));
483 <<
"Calculated field-filter" 484 <<
" - in " << timing.timeIncrement() <<
's' <<
endl;
488 filterFieldPtr_.reset(
nullptr);
491 else if (!mapperPtr_)
496 const fileName samplePointsFile
517 const rawIOField<point> samplePoints(
io);
523 <<
"Read " << samplePoints.size() <<
" sample points from " 524 << samplePointsFile <<
endl 527 <<
"... in " << timing.timeIncrement() <<
's' <<
endl;
531 const bool nearestOnly =
533 !mapMethod_.empty() && !mapMethod_.starts_with(
"planar")
537 if (this->faceValues())
541 new pointToPointPlanarInterpolation
544 this->localPosition(this->patch_.faceCentres()),
554 new pointToPointPlanarInterpolation
557 this->localPosition(this->patch_.localPoints()),
565 <<
"Created point/point planar interpolation" 566 <<
" - in " << timing.timeIncrement() <<
's' <<
endl;
570 if (filterSweeps_ > 0)
572 filterFieldPtr_.reset(
new FilterField(samplePoints, filterRadius_));
575 <<
"Calculated field-filter" 576 <<
" - in " << timing.timeIncrement() <<
's' <<
endl;
580 filterFieldPtr_.reset(
nullptr);
593 if (timeIndices.first() < 0)
596 <<
"Cannot find starting sampling values for index " 598 <<
"Have sampling values for " 601 << time.constant()/
mesh.dbDir()/
"boundaryData"/this->patch_.name()
602 <<
"\n on patch " << this->patch_.name()
603 <<
" of field " << fieldTableName_
610 if (sampleIndex_.first() != timeIndices.first())
612 sampleIndex_.first() = timeIndices.first();
614 if (sampleIndex_.first() == sampleIndex_.second())
617 sampleValues_.first() = sampleValues_.second();
618 sampleAverage_.first() = sampleAverage_.second();
623 this->updateSampledValues
625 sampleIndex_.first(),
626 sampleValues_.first(),
627 sampleAverage_.first()
632 if (sampleIndex_.second() != timeIndices.second())
634 sampleIndex_.second() = timeIndices.second();
636 if (sampleIndex_.second() == -1)
639 sampleValues_.second().clear();
644 this->updateSampledValues
646 sampleIndex_.second(),
647 sampleValues_.second(),
648 sampleAverage_.second()
666 auto&
fld = tfld.ref();
669 if (sampleIndex_.second() == -1)
672 fld = sampleValues_.first();
673 wantedAverage = sampleAverage_.first();
677 const scalar beg = sampleTimes_[sampleIndex_.first()].value();
678 const scalar
end = sampleTimes_[sampleIndex_.second()].value();
679 const scalar
s = (
x - beg)/(
end - beg);
681 fld = (1 -
s)*sampleValues_.first() +
s*sampleValues_.second();
684 = (1 -
s)*sampleAverage_.first() +
s*sampleAverage_.second();
687 <<
"MappedFile<Type>::value : " 688 <<
"Sampled, interpolated values" 690 << sampleTimes_[sampleIndex_.first()].name()
691 <<
" and time:" << sampleTimes_[sampleIndex_.second()].name()
692 <<
" with weight:" <<
s <<
endl;
701 if (this->faceValues())
713 Pout<<
"MappedFile<Type>::value :" 714 <<
" actual average:" << averagePsi
715 <<
" wanted average:" << wantedAverage
719 if (
mag(averagePsi) < VSMALL)
722 const Type offset = wantedAverage - averagePsi;
725 Pout<<
"MappedFile<Type>::value :" 726 <<
" offsetting with:" << offset <<
endl;
732 const scalar scale =
mag(wantedAverage)/
mag(averagePsi);
736 Pout<<
"MappedFile<Type>::value :" 737 <<
" scaling with:" << scale <<
endl;
746 fld += offset_->value(
x);
751 Pout<<
"MappedFile<Type>::value : set fixedValue to min:" <<
gMin(
fld)
779 if (!readerFormat_.empty() && !readerFile_.empty())
781 os.writeEntry(
"readerFormat", readerFormat_);
782 os.writeEntry(
"readerFile", readerFile_);
785 os.writeEntryIfDifferent
792 if (!pointsName_.empty())
794 os.writeEntryIfDifferent<
word>(
"points",
"points", pointsName_);
797 if (!mapMethod_.empty() && !mapMethod_.starts_with(
"planar"))
799 os.writeEntry(
"mapMethod", mapMethod_);
804 os.writeEntry(
"setAverage", setAverage_);
807 os.writeEntryIfDifferent<scalar>(
"perturb", 1
e-5, perturb_);
809 if (filterSweeps_ >= 1)
811 os.writeEntry(
"filterRadius", filterRadius_);
812 os.writeEntry(
"filterSweeps", filterSweeps_);
817 offset_->writeData(
os);
832 if (dictConstructed_)
Patch value mapping from a set of values stored in a file and a set of unstructured points using the ...
static wordList timeNames(const instantList ×)
Helper: extract words of times.
A class for handling file names.
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...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Type gMin(const FieldField< Field, Type > &f)
static Pair< label > findRange(const UList< instant > ×, const scalar timeVal, const label start=-1)
Find lower/upper indices for given time value in list of instances (linear search) continuing after t...
constexpr char nl
The newline '\n' character (0x0a)
Ostream & endl(Ostream &os)
Add newline and flush stream.
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.
virtual tmp< Field< Type > > value(const scalar) const
Return MappedFile value.
Ignore writing from objectRegistry::writeObject()
const polyPatch const word const word const dictionary & dict
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
vectorField pointField
pointField is a vectorField.
const dimensionedScalar e
Elementary charge.
Type gSum(const FieldField< Field, Type > &f)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Abstract base class to hold the Field mapping addressing and weights.
A class for handling words, derived from Foam::string.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
MeshedSurface< face > meshedSurface
virtual void rmap(const PatchFunction1< Type > &pf1, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
label find(const T &val) const
Find index of the first occurrence of the value.
const polyPatch const word const word & entryName
#define DebugInfo
Report an information message using Foam::Info.
virtual void writeData(Ostream &os) const
Write in dictionary format.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
int debug
Static debugging option.
Pair< label > labelPair
A pair of labels.
Type gMax(const FieldField< Field, Type > &f)
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
OBJstream os(runTime.globalPath()/outputName)
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
static dictionary formatOptions(const dictionary &dict, const word &formatName, const word &entryName="formatOptions")
Same as fileFormats::getFormatOptions.
static instantList findTimes(const fileName &directory, const word &constantDirName="constant")
Search a given directory for valid time directories.
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))
List< word > wordList
List of word.
bool starts_with(char c) const
True if string starts with given character (cf. C++20)
static autoPtr< surfaceReader > New(const word &readType, const fileName &fName, const dictionary &options=dictionary())
Return a reference to the selected surfaceReader.
virtual void autoMap(const FieldMapper &mapper)
Map (and resize as needed) from self given a mapping object.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Type gAverage(const FieldField< Field, Type > &f)
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
A patch is a list of labels that address the faces in the global face list.
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;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
virtual void rmap(const PatchFunction1< Type > &rhs, const labelList &addr)
Reverse map the given PatchFunction1 onto this PatchFunction1.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Do not request registration (bool: false)
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0)
virtual void writeData(Ostream &os) const
Write in dictionary format.