32 template<
class Type,
class Function1Type>
36 if (interpolatorPtr_.empty())
39 tableSamplesPtr_.reset(
new scalarField(table_.size()));
43 tableSamples[i] = table_[i].
first();
52 return interpolatorPtr_();
56 template<
class Type,
class Function1Type>
62 <<
"Table for entry " << this->name_ <<
" is invalid (empty)" 67 scalar prevValue = table_[0].first();
69 for (
label i = 1; i <
n; ++i)
71 const scalar currValue = table_[i].first();
74 if (currValue <= prevValue)
77 <<
"out-of-order value: " << currValue <<
" at index " << i
80 prevValue = currValue;
85 template<
class Type,
class Function1Type>
91 const bool under = x < table_.first().first();
92 const bool over = x > table_.last().first();
94 auto errorMessage = [&]()
96 return "value (" +
name(x) +
") " + (under ?
"under" :
"over") +
"flow";
101 switch (boundsHandling_)
103 case tableBase::boundsHandling::error:
109 case tableBase::boundsHandling::warn:
112 << errorMessage() <<
nl <<
endl;
115 case tableBase::boundsHandling::clamp:
119 case tableBase::boundsHandling::repeat:
121 const scalar t0 = table_.first().first();
122 const scalar t1 = table_.last().first();
123 const scalar dt = t1 - t0;
124 const label n = floor((x - t0)/dt);
136 template<
class Type,
class Function1Type>
148 dict.
found(
"outOfBounds")
149 ? tableBase::boundsHandlingNames_.read(dict.
lookup(
"outOfBounds"))
150 : tableBase::boundsHandling::clamp
156 "interpolationScheme",
157 linearInterpolationWeights::typeName
164 template<
class Type,
class Function1Type>
169 const word& interpolationScheme,
176 boundsHandling_(boundsHandling),
177 interpolationScheme_(interpolationScheme),
182 template<
class Type,
class Function1Type>
201 template<
class Type,
class Function1Type>
208 template<
class Type,
class Function1Type>
214 const scalar bx =
bound(x);
218 interpolator().valueWeights(bx, indices_, weights_);
221 y += weights_[i]*table_[indices_[i]].second();
228 template<
class Type,
class Function1Type>
235 const scalar bx1 =
bound(x1), bx2 =
bound(x2);
239 interpolator().integrationWeights(bx1, bx2, indices_, weights_);
242 sumY += weights_[i]*table_[indices_[i]].second();
245 if (boundsHandling_ == tableBase::boundsHandling::repeat)
247 const scalar t0 = table_.first().first();
248 const scalar t1 = table_.last().first();
249 const scalar dt = t1 - t0;
250 const label n = floor((x2 - t0)/dt) - floor((x1 - t0)/dt);
256 interpolator().integrationWeights(t0, t1, indices_, weights_);
260 sumY01 += weights_[i]*table_[indices_[i]].second();
270 template<
class Type,
class Function1Type>
279 fld[i] = table_[i].first();
286 template<
class Type,
class Function1Type>
295 fld[i] = table_[i].second();
302 template<
class Type,
class Function1Type>
312 tableBase::boundsHandlingNames_[tableBase::boundsHandling::clamp],
313 tableBase::boundsHandlingNames_[boundsHandling_]
319 "interpolationScheme",
320 linearInterpolationWeights::typeName,
326 template<
class Type,
class Function1Type>
333 os << token::END_STATEMENT <<
nl;
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
#define forAll(list, i)
Loop across all elements in list.
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 & indent(Ostream &os)
Indent stream.
errorManipArg< error, int > exit(error &err, const int errNo=1)
List< Tuple2< scalar, Type > > table_
Table data.
A list of keyword definitions, which are a keyword followed by any number of values (e...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 2-tuple for storing two objects of different types.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
T & ref() const
Return non-const reference or generate a fatal error.
void writeEntryIfDifferent(Ostream &os, const word &entryName, const EntryType &value1, const EntryType &value2)
Helper function to write the keyword and entry only if the.
Ostream & endl(Ostream &os)
Add newline and flush stream.
virtual Type value(const scalar x) const
Return Table value.
T & first()
Return the first element of the list.
Abstract base class for interpolating in 1D.
const word interpolationScheme_
Interpolation type.
const tableBase::boundsHandling boundsHandling_
Enumeration for handling out-of-bound values.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
A class for handling words, derived from string.
scalar bound(const scalar x) const
Bound the argument to the table. Errors or warns, or shifts the.
virtual ~TableBase()
Destructor.
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
volScalarField scalarField(fieldObject, mesh)
boundsHandling
Enumeration for handling out-of-bound values.
const bool writeData(readBool(pdfDictionary.lookup("writeData")))
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
word name(const complex &)
Return a string representation of a complex.
const word name_
Table name.
volScalarField & bound(volScalarField &, const dimensionedScalar &lowerBound)
Bound the given scalar field if it has gone unbounded.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
#define WarningInFunction
Report a warning using Foam::Warning.
virtual tmp< Field< Type > > y() const
Return the dependent values.
TableBase(const word &name, const dictionary &dict)
Construct from dictionary. Table is not populated.
virtual tmp< scalarField > x() const
Return the reference values.
A class for managing temporary objects.
const interpolationWeights & interpolator() const
Return (demand driven) interpolator.
autoPtr< interpolationWeights > interpolatorPtr_
Interpolator method.
virtual void writeEntries(Ostream &os) const
Write entries only in dictionary format.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
autoPtr< scalarField > tableSamplesPtr_
Extracted values.
Base class for table with bounds handling, interpolation and integration.
virtual void writeData(Ostream &os) const
Write all table data in dictionary format.
void check() const
Check the table for size and consistency.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.