20 #ifndef GEOS_FUNCTIONS_TABLEFUNCTION_HPP_
21 #define GEOS_FUNCTIONS_TABLEFUNCTION_HPP_
26 #include "LvArray/src/tensorOps.hpp"
85 m_coordinates = std::move( other.m_coordinates );
86 m_values = std::move( other.m_values );
87 m_interpolationMethod = other.m_interpolationMethod;
99 template<
typename IN_ARRAY >
109 template<
typename IN_ARRAY,
typename OUT_ARRAY >
120 void move( LvArray::MemorySpace
const space,
bool const touch )
122 m_coordinates.move( space, touch );
123 m_values.move( space, touch );
150 template<
typename IN_ARRAY >
153 interpolateLinear( IN_ARRAY
const & input )
const;
161 template<
typename IN_ARRAY,
typename OUT_ARRAY >
164 interpolateLinear( IN_ARRAY
const & input, OUT_ARRAY && derivatives )
const;
171 template<
typename IN_ARRAY >
174 interpolateRound( IN_ARRAY
const & input )
const;
182 template<
typename IN_ARRAY,
typename OUT_ARRAY >
185 interpolateRound( IN_ARRAY
const & input, OUT_ARRAY && derivatives )
const;
233 FunctionBase::evaluateT< TableFunction, parallelHostPolicy >( group, time,
set, result );
291 return size_t(dim) < m_dimUnits.size() ? m_dimUnits[dim] : units::Unknown;
306 std::vector< units::Unit >
const & dimUnits = {} );
314 m_dimUnits = dimUnits;
396 std::vector< units::Unit > m_dimUnits;
406 template<
typename IN_ARRAY >
412 if( m_interpolationMethod == TableFunction::InterpolationType::Linear )
414 return interpolateLinear( input );
418 return interpolateRound( input );
422 template<
typename IN_ARRAY >
426 TableFunction::KernelWrapper::interpolateLinear( IN_ARRAY
const & input )
const
435 arraySlice1d< real64 const >
const coords = m_coordinates[dim];
436 if( input[dim] <= coords[0] )
441 weights[dim][0] = 0.0;
442 weights[dim][1] = 1.0;
444 else if( input[dim] >= coords[coords.size() - 1] )
447 bounds[dim][0] = coords.size() - 1;
448 bounds[dim][1] = bounds[dim][0];
449 weights[dim][0] = 1.0;
450 weights[dim][1] = 0.0;
458 auto const lower = LvArray::sortedArrayManipulation::find( coords.begin(), coords.size(), input[dim] );
459 bounds[dim][1] = LvArray::integerConversion< localIndex >( lower );
460 bounds[dim][0] = bounds[dim][1] - 1;
462 real64 const dx = coords[bounds[dim][1]] - coords[bounds[dim][0]];
463 weights[dim][0] = 1.0 - ( input[dim] - coords[bounds[dim][0]]) / dx;
464 weights[dim][1] = 1.0 - weights[dim][0];
471 for(
integer point = 0; point < numCorners; ++point )
478 integer const corner = (point >> dim) & 1;
479 tableIndex += bounds[dim][corner] * stride;
480 stride *= m_coordinates.sizeOfArray( dim );
484 real64 cornerValue = m_values[tableIndex];
487 integer const corner = (point >> dim) & 1;
488 cornerValue *= weights[dim][corner];
490 value += cornerValue;
495 template<
typename IN_ARRAY >
499 TableFunction::KernelWrapper::interpolateRound( IN_ARRAY
const & input )
const
508 arraySlice1d< real64 const >
const coords = m_coordinates[dim];
511 if( input[dim] <= coords[0] )
516 else if( input[dim] >= coords[coords.size() - 1] )
519 subIndex = coords.size() - 1;
525 auto const lower = LvArray::sortedArrayManipulation::find( coords.begin(), coords.size(), input[dim] );
526 subIndex = LvArray::integerConversion< localIndex >( lower );
532 if( m_interpolationMethod == TableFunction::InterpolationType::Nearest )
534 if( ( input[dim] - coords[subIndex - 1]) <= ( coords[subIndex] - input[dim]) )
539 else if( m_interpolationMethod == TableFunction::InterpolationType::Lower )
549 tableIndex += subIndex * stride;
550 stride *= coords.size();
554 return m_values[tableIndex];
557 template<
typename IN_ARRAY,
typename OUT_ARRAY >
564 if( m_interpolationMethod == TableFunction::InterpolationType::Linear )
566 return interpolateLinear( input, derivatives );
571 return interpolateRound( input, derivatives );
575 template<
typename IN_ARRAY,
typename OUT_ARRAY >
579 TableFunction::KernelWrapper::interpolateLinear( IN_ARRAY
const & input, OUT_ARRAY && derivatives )
const
590 arraySlice1d< real64 const >
const coords = m_coordinates[dim];
591 if( input[dim] <= coords[0] )
598 dWeights_dInput[dim][0] = 0;
599 dWeights_dInput[dim][1] = 0;
601 else if( input[dim] >= coords[coords.size() - 1] )
604 bounds[dim][0] = coords.size() - 1;
605 bounds[dim][1] = bounds[dim][0];
608 dWeights_dInput[dim][0] = 0;
609 dWeights_dInput[dim][1] = 0;
617 auto lower = LvArray::sortedArrayManipulation::find( coords.begin(), coords.size(), input[dim] );
618 bounds[dim][1] = LvArray::integerConversion< localIndex >( lower );
619 bounds[dim][0] = bounds[dim][1] - 1;
621 real64 const dx = coords[bounds[dim][1]] - coords[bounds[dim][0]];
622 weights[dim][0] = 1.0 - ( input[dim] - coords[bounds[dim][0]]) / dx;
623 weights[dim][1] = 1.0 - weights[dim][0];
624 dWeights_dInput[dim][0] = -1.0 / dx;
625 dWeights_dInput[dim][1] = -dWeights_dInput[dim][0];
633 derivatives[dim] = 0.0;
637 for(
integer point = 0; point < numCorners; ++point )
644 integer const corner = (point >> dim) & 1;
645 tableIndex += bounds[dim][corner] * stride;
646 stride *= m_coordinates.sizeOfArray( dim );
650 real64 cornerValue = m_values[tableIndex];
654 dCornerValue_dInput[dim] = cornerValue;
659 integer const corner = (point >> dim) & 1;
660 cornerValue *= weights[dim][corner];
663 dCornerValue_dInput[kk] *= ( dim == kk ) ? dWeights_dInput[dim][corner] : weights[dim][corner];
669 derivatives[dim] += dCornerValue_dInput[dim];
671 value += cornerValue;
676 template<
typename IN_ARRAY,
typename OUT_ARRAY >
680 TableFunction::KernelWrapper::interpolateRound( IN_ARRAY
const & input, OUT_ARRAY && derivatives )
const
683 GEOS_ERROR(
"Rounding interpolation with derivatives not implemented" );
702 string TableTextFormatter::toString< TableFunction >(
TableFunction const & tableData )
const;
710 string TableCSVFormatter::toString< TableFunction >(
TableFunction const & tableData )
const;
#define GEOS_HOST_DEVICE
Marks a host-device function.
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
#define GEOS_FORCE_INLINE
Marks a function or lambda for inlining.
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Enumerates the Units that are in use in GEOS and regroups useful conversion and formatting functions.
Unit
Enumerator of available unit types. Units are in SI by default.
Class describing a file Path.
GEOS_HOST_DEVICE real64 compute(IN_ARRAY const &input, OUT_ARRAY &&derivatives) const
Interpolate in the table with derivatives.
void move(LvArray::MemorySpace const space, bool const touch)
Move the KernelWrapper to the given execution space, optionally touching it.
GEOS_HOST_DEVICE real64 compute(IN_ARRAY const &input) const
Interpolate in the table.
InterpolationType
Enumerator of available interpolation types.
void setTableValues(real64_array values, units::Unit unit=units::Unknown)
Set the table values.
array1d< real64 > & getValues()
Get the table values.
arrayView1d< real64 const > getValues() const
Get the table values.
void checkCoord(real64 coord, localIndex dim) const
Check if the given coordinate is in the bounds of the table coordinates in the specified dimension,...
virtual void evaluate(dataRepository::Group const &group, real64 const time, SortedArrayView< localIndex const > const &set, arrayView1d< real64 > const &result) const override final
Method to evaluate a function on a target object.
ArrayOfArraysView< real64 > getCoordinates()
Get the table axes definitions.
void outputPVTTableData(OutputOptions const pvtOutputOpts) const
Print the table(s) in the log and/or CSV files when requested by the user.
void setTableCoordinates(array1d< real64_array > const &coordinates, std::vector< units::Unit > const &dimUnits={})
Set the table coordinates.
void setValueUnits(units::Unit unit)
Set the table value units.
void setDimUnits(std::vector< units::Unit > const &dimUnits)
Set the units of each dimension.
void reInitializeFunction()
Build the maps used to evaluate the table function.
KernelWrapper createKernelWrapper() const
Create an instance of the kernel wrapper.
TableFunction(const string &name, dataRepository::Group *const parent)
The constructor.
units::Unit getValueUnit() const
void setInterpolationMethod(InterpolationType const method)
Set the interpolation method.
static constexpr integer maxDimensions
maximum dimensions for the coordinates in the table
virtual real64 evaluate(real64 const *const input) const override final
Method to evaluate a function.
static string catalogName()
The catalog name interface.
virtual void initializeFunction() override
Initialize the table function.
ArrayOfArraysView< real64 const > getCoordinates() const
Get the table axes definitions.
integer numDimensions() const
units::Unit getDimUnit(localIndex const dim) const
InterpolationType getInterpolationMethod() const
Get the interpolation method.
Group & operator=(Group const &)=delete
Deleted copy assignment operator.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
ENUM_STRINGS(LinearSolverParameters::SolverType, "direct", "cg", "gmres", "fgmres", "bicgstab", "preconditioner")
Declare strings associated with enumeration values.
LvArray::ArrayOfArraysView< T, INDEX_TYPE const, CONST_SIZES, LvArray::ChaiBuffer > ArrayOfArraysView
View of array of variable-sized arrays. See LvArray::ArrayOfArraysView for details.
array1d< Path > path_array
A 1-dimensional array of geos::Path types.
std::set< T > set
A set of local indices.
double real64
64-bit floating point type.
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
std::int32_t integer
Signed integer type.
array1d< real64 > real64_array
A 1-dimensional array of geos::real64 types.
std::size_t size_t
Unsigned size type.
LvArray::SortedArrayView< T, localIndex, LvArray::ChaiBuffer > SortedArrayView
A sorted array view of local indices.
Array< T, 1 > array1d
Alias for 1D array.
LvArray::ArrayOfArrays< T, INDEX_TYPE, LvArray::ChaiBuffer > ArrayOfArrays
Array of variable-sized arrays. See LvArray::ArrayOfArrays for details.
Struct containing output options.
bool writeInLog
Output PVT in log.
bool writeCSV
Output PVT in CSV file.
Struct containing lookup keys for data repository wrappers.
static constexpr char const * coordinatesString()
static constexpr char const * interpolationString()
static constexpr char const * valuesString()
static constexpr char const * voxelFileString()
static constexpr char const * coordinateFilesString()