35Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
37 const bool dictConstructed,
39 const word& entryName,
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),
61 sampleAverage_(Zero, Zero),
65 Function1<Type>::NewIfPresent
69 patchFunction1Base::whichDb()
73 if (fieldTableName_.empty())
75 fieldTableName_ = entryName;
79 if ((filterSweeps_ < 1) || (filterRadius_ <= VSMALL))
85 if (
dict.readIfPresent(
"sampleFormat", readerFormat_))
87 dict.readEntry(
"sampleFile", readerFile_);
89 fileName fName(readerFile_);
92 readerPtr_ = surfaceReader::New
96 surfaceReader::formatOptions(dict, readerFormat_,
"readOptions")
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"
122 && !mapMethod_.starts_with(
"planar")
125 FatalIOErrorInFunction(dict)
126 <<
"Unknown mapMethod type " << mapMethod_
127 <<
"\n\nValid mapMethod types :\n"
128 <<
"(nearest planar)" << nl
129 << exit(FatalIOError);
135Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
138 const word& redirectType,
139 const word& entryName,
141 const bool faceValues
157Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
160 const word& entryName,
162 const word& fieldTableName,
163 const bool faceValues
179Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
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())
207 fileName fName(readerFile_);
210 readerPtr_ = surfaceReader::New(readerFormat_, fName);
216Foam::PatchFunction1Types::MappedFile<Type>::MappedFile
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);
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);
283void Foam::PatchFunction1Types::MappedFile<Type>::updateSampledValues
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();
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);
404void Foam::PatchFunction1Types::MappedFile<Type>::checkTable
413 if (!mapperPtr_ && readerPtr_)
417 auto& reader = readerPtr_();
421 sampleTimes_ = reader.times();
432 <<
"Read " << samplePoints.
size() <<
" sample points from "
433 << readerFile_ <<
endl
439 const bool nearestOnly =
441 !mapMethod_.empty() && !mapMethod_.starts_with(
"planar")
445 if (this->faceValues())
465 this->localPosition(this->patch_.localPoints()),
473 <<
"Created point/point planar interpolation"
478 if (filterSweeps_ > 0)
480 filterFieldPtr_.reset(
new FilterField(geom, filterRadius_));
483 <<
"Calculated field-filter"
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()
665 auto tfld = tmp<Field<Type>>
::New();
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())
712 Pout<<
"MappedFile<Type>::value :"
713 <<
" actual average:" << averagePsi
714 <<
" wanted average:" << wantedAverage
718 if (
mag(averagePsi) < VSMALL)
721 const Type offset = wantedAverage - averagePsi;
724 Pout<<
"MappedFile<Type>::value :"
725 <<
" offsetting with:" << offset <<
endl;
731 const scalar scale =
mag(wantedAverage)/
mag(averagePsi);
735 Pout<<
"MappedFile<Type>::value :"
736 <<
" scaling with:" << scale <<
endl;
745 fld += offset_->value(
x);
753 Pout<<
"MappedFile<Type>::value : set fixedValue to min:"
755 <<
" max:" <<
limits.max()
756 <<
" avg:" << avg <<
endl;
782 if (!readerFormat_.empty() && !readerFile_.empty())
784 os.writeEntry(
"readerFormat", readerFormat_);
785 os.writeEntry(
"readerFile", readerFile_);
788 os.writeEntryIfDifferent
795 if (!pointsName_.empty())
797 os.writeEntryIfDifferent<
word>(
"points",
"points", pointsName_);
800 if (!mapMethod_.empty() && !mapMethod_.starts_with(
"planar"))
802 os.writeEntry(
"mapMethod", mapMethod_);
807 os.writeEntry(
"setAverage", setAverage_);
810 os.writeEntryIfDifferent<scalar>(
"perturb", 1
e-5, perturb_);
812 if (filterSweeps_ >= 1)
814 os.writeEntry(
"filterRadius", filterRadius_);
815 os.writeEntry(
"filterSweeps", filterSweeps_);
820 offset_->writeData(
os);
835 if (dictConstructed_)
if(maxValue - minValue< SMALL)
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))
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
Abstract base class to hold the Field mapping addressing and weights.
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
@ NO_REGISTER
Do not request registration (bool: false).
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
The FilterField helper class provides a multi-sweep median filter for a Field of data associated with...
Patch value mapping from a set of values stored in a file and a set of unstructured points using the ...
virtual tmp< Field< Type > > integrate(const scalar x1, const scalar x2) const
Integrate between two values.
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.
virtual void writeData(Ostream &os) const
Write in dictionary format.
virtual tmp< PatchFunction1< Type > > clone() const
Return a clone.
virtual void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
virtual tmp< Field< Type > > value(const scalar) const
Return MappedFile value.
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
const polyPatch const word const word & entryName
virtual void rmap(const PatchFunction1< Type > &rhs, 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.
virtual void writeData(Ostream &os) const
Write in dictionary format.
const polyPatch const word const word const dictionary & dict
virtual tmp< pointField > localPosition(const pointField &globalPos) const
const polyPatch const word const word const dictionary const bool faceValues
label nFaces() const noexcept
Number of faces in the patch.
const Field< point_type > & points() const noexcept
Return reference to global points.
const Field< point_type > & faceCentres() const
Return face centres for patch.
const word & constant() const noexcept
Return constant name.
static instantList findTimes(const fileName &directory, const word &constantDirName="constant")
Search a given directory for valid time directories.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
fileName globalPath() const
The global path for the case = rootPath/globalCaseName.
void size(const label n)
Older name for setAddressableSize.
label find(const T &val) const
Find index of the first occurrence of the value.
Starts timing and returns elapsed time from start. Uses std::chrono::high_resolution_clock for better...
double timeIncrement() const
The time [seconds] since the last call to elapsedTime(), timeIncrement() or resetTime(),...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
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...
const Time & time() const noexcept
Return time registry.
const Time & time() const
Return false: function not created with time database.
const polyPatch & patch_
Reference to the patch.
const polyPatch & patch() const noexcept
Reference to the patch.
label size() const
Number of faces or points on the patch.
Interpolates between two sets of unstructured points using 2D Delaunay triangulation....
static wordList timeNames(const instantList ×)
Helper: extract words of times.
Mesh consisting of general polyhedral cells.
A patch is a list of labels that address the faces in the global face list.
A class for managing temporary objects.
A class for handling words, derived from Foam::string.
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
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))
#define DebugInfo
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Pair< label > labelPair
A pair of labels.
List< word > wordList
List of word.
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.
Type gWeightedAverage(const UList< scalar > &weights, const UList< Type > &fld, const label comm)
The global weighted average of a field, using the mag() of the weights.
List< label > labelList
A List of labels.
refinementData transform(const tensor &, const refinementData val)
No-op rotational transform for base types.
messageStream Info
Information stream (stdout output on master, null elsewhere).
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
MeshedSurface< face > meshedSurface
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
MinMax< Type > gMinMax(const FieldField< Field, Type > &f)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).