35void Foam::interpolationTable<Type>::readTable()
39 fileName fName(fileName_);
44 reader_()(fName, *
this);
49 <<
"table read from " << fName <<
" is empty" <<
nl
64 bounding_(
bounds::repeatableBounding::WARN),
65 fileName_(
"fileNameIsUndefined"),
78 List<value_type>(values),
89 bounding_(
bounds::repeatableBounding::WARN),
103 bounds::repeatableBoundingNames.getOrDefault
107 bounds::repeatableBounding::WARN,
124 List<value_type>(tbl),
125 bounding_(tbl.bounding_),
126 fileName_(tbl.fileName_),
141 for (
const auto& item : list)
143 const scalar& currValue = item.first();
146 if (i && currValue <= prevValue)
149 <<
"out-of-order value: "
150 << currValue <<
" at index " << i <<
nl
153 prevValue = currValue;
162 os.writeEntry(
"file", fileName_);
174 const List<value_type>& list = *
this;
176 const label
n = list.size();
184 const scalar minLimit = list.first().first();
185 const scalar maxLimit = list.last().first();
187 if (lookupValue < minLimit)
194 <<
"value (" << lookupValue <<
") less than lower "
195 <<
"bound (" << minLimit <<
")\n"
202 <<
"value (" << lookupValue <<
") less than lower "
203 <<
"bound (" << minLimit <<
")\n"
204 <<
" Zero rate of change." <<
endl;
218 scalar span = maxLimit-minLimit;
219 lookupValue = fmod(lookupValue - minLimit, span) + minLimit;
224 else if (lookupValue >= maxLimit)
228 case bounds::repeatableBounding::ERROR:
231 <<
"value (" << lookupValue <<
") greater than upper "
232 <<
"bound (" << maxLimit <<
")\n"
236 case bounds::repeatableBounding::WARN:
239 <<
"value (" << lookupValue <<
") greater than upper "
240 <<
"bound (" << maxLimit <<
")\n"
241 <<
" Zero rate of change." <<
endl;
247 case bounds::repeatableBounding::CLAMP:
252 case bounds::repeatableBounding::REPEAT:
255 scalar span = maxLimit-minLimit;
256 lookupValue = fmod(lookupValue - minLimit, span) + minLimit;
266 for (label i = 0; i <
n; ++i)
268 if (lookupValue >= list[i].first())
294 (list[hi].second() - list[lo].second())
295 / (list[hi].first() + minLimit - list[lo].first())
303 (list[hi].second() - list[lo].second())
317 const label
n = list.size();
325 <<
"Cannot interpolate from zero-sized table" <<
nl
330 return list.first().second();
333 const scalar minLimit = list.first().first();
334 const scalar maxLimit = list.last().first();
336 if (lookupValue < minLimit)
340 case bounds::repeatableBounding::ERROR:
343 <<
"value (" << lookupValue <<
") less than lower "
344 <<
"bound (" << minLimit <<
")\n"
348 case bounds::repeatableBounding::WARN:
351 <<
"value (" << lookupValue <<
") less than lower "
352 <<
"bound (" << minLimit <<
")\n"
353 <<
" Continuing with the first entry" <<
endl;
356 return list.first().second();
359 case bounds::repeatableBounding::CLAMP:
361 return list.first().second();
364 case bounds::repeatableBounding::REPEAT:
367 const scalar span = maxLimit-minLimit;
368 lookupValue = fmod(lookupValue - minLimit, span) + minLimit;
373 else if (lookupValue >= maxLimit)
377 case bounds::repeatableBounding::ERROR:
380 <<
"value (" << lookupValue <<
") greater than upper "
381 <<
"bound (" << maxLimit <<
")\n"
385 case bounds::repeatableBounding::WARN:
388 <<
"value (" << lookupValue <<
") greater than upper "
389 <<
"bound (" << maxLimit <<
")\n"
390 <<
" Continuing with the last entry" <<
endl;
393 return list.last().second();
396 case bounds::repeatableBounding::CLAMP:
398 return list.last().second();
401 case bounds::repeatableBounding::REPEAT:
404 const scalar span = maxLimit-minLimit;
405 lookupValue = fmod(lookupValue - minLimit, span) + minLimit;
416 for (label i = 0; i <
n; ++i)
418 if (lookupValue >= list[i].first())
431 return list[hi].second();
445 + (list[hi].second() - list[lo].second())
446 * (lookupValue / minLimit)
455 + (list[hi].second() - list[lo].second())
480 auto&
fld = tfld.ref();
484 fld[i] = interpolateValue(vals[i]);
504 static_cast<List<value_type>&
>(*this) = rhs;
505 bounding_ = rhs.bounding_;
506 fileName_ =
rhs.fileName_;
507 reader_.reset(
rhs.reader_.clone());
516 const label
n = list.
size();
526 <<
"Cannot interpolate from zero-sized table" <<
nl
535 case bounds::repeatableBounding::ERROR:
538 <<
"index (" << idx <<
") underflow" << nl
542 case bounds::repeatableBounding::WARN:
545 <<
"index (" << idx <<
") underflow" <<
nl
546 <<
" Continuing with the first entry" <<
nl;
552 case bounds::repeatableBounding::CLAMP:
557 case bounds::repeatableBounding::REPEAT:
571 case bounds::repeatableBounding::ERROR:
574 <<
"index (" << idx <<
") overflow" <<
nl
578 case bounds::repeatableBounding::WARN:
581 <<
"index (" << idx <<
") overflow" <<
nl
582 <<
" Continuing with the last entry" <<
nl;
588 case bounds::repeatableBounding::CLAMP:
593 case bounds::repeatableBounding::REPEAT:
611 return interpolateValue(*
this, lookupValue, bounding_);
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))
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
autoPtr< List< Tuple2< scalar, Type > > > clone() const
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
T & first()
Access first element of the list, position [0].
bool get(const label i) const
void size(const label n)
Older name for setAddressableSize.
T & last()
Access last element of the list, position [size()-1].
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
A class for handling file names.
An interpolation/look-up table of scalar vs <Type> values. The reference scalar values must be monoto...
void check() const
Check that list is monotonically increasing.
interpolationTable()
Default construct.
void write(Ostream &os) const
Write.
tmp< Field< Type > > interpolateValues(const UList< scalar > &vals) const
Return multiple interpolated values.
Tuple2< scalar, Type > value_type
The element data type.
Type operator()(scalar lookupValue) const
Return an interpolated value.
static Type interpolateValue(const List< Tuple2< scalar, Type > > &list, scalar lookupValue, bounds::repeatableBounding=bounds::repeatableBounding::CLAMP)
Return an interpolated value in List.
Type rateOfChange(scalar lookupValue) const
Return the rate of change at the interpolation location for the given lookup value.
const Tuple2< scalar, Type > & operator[](label idx) const
Return an element of constant Tuple2<scalar, Type>.
Reads an interpolation table from a file - OpenFOAM-format.
Base class to read table data for the interpolationTable.
A class for managing temporary objects.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for bounding specifications. At the moment, mostly for tables.
repeatableBounding
Enumeration for handling out-of-bound values that are repeatable.
@ WARN
Issue warning and clamp value (this is a good default).
@ REPEAT
Treat as a repeating list.
@ ERROR
Exit with a FatalError.
@ CLAMP
Clamp value to the start/end value.
const Foam::Enum< repeatableBounding > repeatableBoundingNames
Strings corresponding to the repeatableBounding.
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
static constexpr const zero Zero
Global zero (0).
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.