35 if (interpolatorPtr_.empty())
38 tableSamplesPtr_.reset(
new scalarField(values_.size()));
42 tableSamples[i] = values_[i].first();
51 return interpolatorPtr_();
61 <<
"Table for entry " << this->
name() <<
" is invalid (empty)"
65 label n = values_.size();
66 scalar prevValue = values_[0].first();
68 for (
label i = 1; i <
n; ++i)
70 const scalar currValue = values_[i].first();
73 if (currValue <= prevValue)
76 <<
"out-of-order value: " << currValue <<
" at index " << i
79 prevValue = currValue;
87 const bool under =
x < values_.first().first();
88 const bool over =
x > values_.last().first();
90 auto errorMessage = [&]()
92 return "value (" +
name(
x) +
") " + (under ?
"under" :
"over") +
"flow";
97 switch (boundsHandling_)
99 case tableBase::boundsHandling::error:
105 case tableBase::boundsHandling::warn:
108 << errorMessage() <<
nl <<
endl;
127 const word& interpolationScheme,
134 interpolationScheme_(interpolationScheme),
135 reader_(reader, false),
159 "interpolationScheme",
194 reader_(new TableReaders::Embedded<Type>()),
195 values_(TableReaders::Embedded<Type>().
read(
units, is))
205 boundsHandling_(tbl.boundsHandling_),
206 interpolationScheme_(tbl.interpolationScheme_),
207 reader_(tbl.reader_, false),
208 values_(tbl.values_),
209 tableSamplesPtr_(tbl.tableSamplesPtr_),
210 interpolatorPtr_(tbl.interpolatorPtr_)
233 const scalar x0 = values_.first().first();
234 const scalar x1 = values_.last().first();
238 switch (boundsHandling_)
240 case tableBase::boundsHandling::clamp:
245 case tableBase::boundsHandling::zero:
248 if (x <= x0 || x >= x1)
257 const scalar
n = floor((
x - x0)/(x1 - x0));
268 interpolator().valueWeights(
x, indices_, weights_);
271 y += weights_[i]*values_[indices_[i]].second();
285 scalar xA(xAarg), xB(xBarg);
290 const scalar x0 = values_.first().first();
291 const scalar x1 = values_.last().first();
295 switch (boundsHandling_)
297 case tableBase::boundsHandling::clamp:
302 case tableBase::boundsHandling::zero:
305 xA =
min(
max(xA, x0), x1);
306 xB =
min(
max(xB, x0), x1);
313 const scalar nA = floor((xA - x0)/(x1 - x0));
314 const scalar nB = floor((xB - x0)/(x1 - x0));
317 interpolator().integrationWeights(x0, x1, indices_, weights_);
320 sumY += (nB - nA)*weights_[i]*values_[indices_[i]].
second();
334 interpolator().integrationWeights(xA, xB, indices_, weights_);
337 sumY += weights_[i]*values_[indices_[i]].second();
353 fld[i] = values_[i].first();
369 fld[i] = values_[i].second();
387 tableBase::boundsHandlingNames[tableBase::boundsHandling::clamp],
388 tableBase::boundsHandlingNames[boundsHandling_]
394 "interpolationScheme",
395 linearInterpolationWeights::typeName,
399 reader_->write(os,
units, values_);
#define forAll(list, i)
Loop across all elements in list.
Templated interpolated tabulated data Function1.
virtual Type integral(const scalar xA, const scalar xB) const
Integrate between two scalars.
virtual tmp< scalarField > x() const
Return the reference values.
Table(const word &name, const tableBase::boundsHandling boundsHandling, const word &interpolationScheme, const autoPtr< TableReader< Type >> &reader, const List< Tuple2< scalar, Type >> &table)
Construct from components.
virtual void write(Ostream &os, const unitConversions &units) const
Write data to dictionary stream.
virtual tmp< Field< Type > > y() const
Return the dependent values.
virtual Type value(const scalar x) const
Return Table value as a function of scalar x.
virtual ~Table()
Destructor.
boundsHandling
Enumeration for handling out-of-bound values.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Base class to read table data for tables.
A 2-tuple for storing two objects of different types.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Abstract base class for interpolating in 1D.
A class for managing temporary objects.
T & ref() const
Return non-const reference or generate a fatal error.
Unit conversion structure. Contains the associated dimensions and the multiplier with which to conver...
A class for handling words, derived from string.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
volScalarField scalarField(fieldObject, mesh)
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(lagrangian::Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), lagrangian::cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define WarningInFunction
Report a warning using Foam::Warning.
autoPtr< CompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const viscosity &viscosity)
errorManipArg< error, int > exit(error &err, const int errNo=1)
bool read(const char *, int32_t &)
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
labelList second(const UList< labelPair > &p)
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
const HashTable< unitConversion > & units()
Get the table of unit conversions.
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
List< Type > repeat(const UList< Type > &a, const UList< Type > &b)
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)