43#ifndef __TASMANIAN_SPARSE_GRID_HPP
44#define __TASMANIAN_SPARSE_GRID_HPP
46#include "tsgGridGlobal.hpp"
47#include "tsgGridLocalPolynomial.hpp"
48#include "tsgGridWavelet.hpp"
49#include "tsgGridFourier.hpp"
342 void read(
const char *filename);
357 void read(std::string
const& fname){
read(fname.c_str()); }
406 std::vector<int>
const &anisotropic_weights,
double alpha = 0.0,
double beta = 0.0,
407 const char* custom_filename =
nullptr, std::vector<int>
const &level_limits = std::vector<int>());
416 const int *anisotropic_weights =
nullptr,
double alpha = 0.0,
double beta = 0.0,
417 const char* custom_filename =
nullptr,
const int *level_limits =
nullptr);
424 std::vector<int>
const &anisotropic_weights, std::vector<int>
const &level_limits = std::vector<int>());
431 const int *anisotropic_weights =
nullptr,
const int *level_limits =
nullptr);
451 std::vector<int>
const &anisotropic_weights, std::vector<int>
const &level_limits = std::vector<int>());
460 const int *anisotropic_weights =
nullptr,
const int *level_limits =
nullptr);
516 void makeWaveletGrid(
int dimensions,
int outputs,
int depth,
int order, std::vector<int>
const &level_limits);
524 void makeWaveletGrid(
int dimensions,
int outputs,
int depth,
int order = 1,
const int *level_limits =
nullptr);
536 std::vector<int>
const &anisotropic_weights, std::vector<int>
const &level_limits = std::vector<int>());
544 void makeFourierGrid(
int dimensions,
int outputs,
int depth,
TypeDepth type,
const int* anisotropic_weights =
nullptr,
const int* level_limits =
nullptr);
585 void updateGlobalGrid(
int depth,
TypeDepth type, std::vector<int>
const &anisotropic_weights, std::vector<int>
const &level_limits = std::vector<int>());
606 void updateSequenceGrid(
int depth,
TypeDepth type, std::vector<int>
const &anisotropic_weights, std::vector<int>
const &level_limits = std::vector<int>());
627 void updateFourierGrid(
int depth,
TypeDepth type, std::vector<int>
const &anisotropic_weights, std::vector<int>
const &level_limits = std::vector<int>());
639 void updateGrid(
int depth,
TypeDepth type, std::vector<int>
const &anisotropic_weights, std::vector<int>
const &level_limits = std::vector<int>());
645 void updateGrid(
int depth,
TypeDepth type,
const int *anisotropic_weights =
nullptr,
const int *level_limits =
nullptr);
671 int getNumLoaded()
const{
return makeCall<BaseMethod::getNumLoaded>(); }
673 int getNumNeeded()
const{
return makeCall<BaseMethod::getNumNeeded>(); }
675 int getNumPoints()
const{
return makeCall<BaseMethod::getNumPoints>(); }
931 void evaluate(std::vector<double>
const &x, std::vector<double> &y)
const;
971 template<
typename FloatType>
void evaluateBatch(std::vector<FloatType>
const &x, std::vector<FloatType> &y)
const;
1021 template<
typename FloatType>
void evaluateBatchGPU(
const FloatType gpu_x[],
int cpu_num_x, FloatType gpu_y[])
const;
1068 std::vector<double> result;
1078 void differentiate(std::vector<double>
const &x, std::vector<double> &jacobian)
const;
1083 std::vector<double> jacobian;
1095 bool isEmpty()
const{
return std::holds_alternative<std::monostate>(base); }
1097 bool empty()
const{
return std::holds_alternative<std::monostate>(base); }
1099 bool isGlobal()
const{
return std::holds_alternative<GridGlobal>(base); }
1101 bool isSequence()
const{
return std::holds_alternative<GridSequence>(base); }
1103 bool isFourier()
const{
return std::holds_alternative<GridFourier>(base); }
1107 bool isWavelet()
const{
return std::holds_alternative<GridWavelet>(base); }
1363 std::vector<int>
const &level_limits, std::vector<double>
const &scale_correction = std::vector<double>());
1376 std::vector<double>
const &scale_correction = std::vector<double>()) {
1450 std::vector<int>
const &level_limits = std::vector<int>());
1485 std::vector<int>
const &level_limits = std::vector<int>(),
1486 std::vector<double>
const &scale_correction = std::vector<double>());
1556 void getHierarchicalCoefficientsStatic(
double *coeff)
const{
1618 std::vector<double> y;
1699 std::vector<double> integrals;
1885 static int getNumGPUs(){
return AccelerationMeta::getNumGpuDevices(); }
1922 template<
typename FloatType>
1948 template<
typename FloatType>
1952 using EvaluateCallable = std::function<void(std::vector<double>
const&, std::vector<double>&)>;
1961 return [&](std::vector<double>
const &x, std::vector<double> &y)->
void{
evaluateBatch(x, y); };
1976 return [](std::vector<double>
const &)->
bool{
return true; };
1978 if (domain_transform_a.empty()){
1979 return [](std::vector<double>
const &x)->
bool{
1980 for(
auto const &v : x)
if (v < 0.0)
return false;
1985 return [dta=domain_transform_a, dims](std::vector<double>
const &x)->
bool{
1986 for(
size_t i=0; i<dims; i++)
if (x[i] < dta[i])
return false;
1991 if (domain_transform_a.empty()){
1993 return [](std::vector<double>
const &x)->
bool{
1994 for(
auto const &v : x)
if ((v < 0.0) || (v > 1.0))
return false;
1998 return [](std::vector<double>
const &x)->
bool{
1999 for(
auto const &v : x)
if ((v < -1.0) || (v > 1.0))
return false;
2005 return [dta=domain_transform_a, dtb=domain_transform_b, dims](std::vector<double>
const &x)->
bool{
2006 for(
size_t i=0; i<dims; i++)
2007 if (x[i] < dta[i] or x[i] > dtb[i])
return false;
2045 #ifndef __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2054 int evaluateSparseHierarchicalFunctionsGetNZ(
const double x[],
int num_x)
const;
2062 void evaluateSparseHierarchicalFunctionsStatic(
const double x[],
int num_x,
int pntr[],
int indx[],
double vals[])
const;
2070 const int* getPointsIndexes()
const;
2078 const int* getNeededIndexes()
const;
2087 template<
class T>
inline T* get(){
2088 return std::get_if<T>(std::addressof(base));
2097 template<
class T>
inline T
const* get()
const{
2098 return std::get_if<T>(std::addressof(base));
2106 AccelerationContext
const* getAccelerationContext()
const{
return acceleration.get(); }
2110 #ifndef __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2117 enum class BaseMethod {
2125 template<BaseMethod method>
2126 int makeCall()
const{
2127 return std::visit([](
auto const &g) ->
int {
2128 if constexpr (not std::is_same_v<std::decay_t<
decltype(g)>, std::monostate>) {
2129 if constexpr (method == BaseMethod::getNumDimensions)
2130 return g.getNumDimensions();
2131 else if constexpr (method == BaseMethod::getNumOutputs)
2132 return g.getNumOutputs();
2133 else if constexpr (method == BaseMethod::getNumLoaded)
2134 return g.getNumLoaded();
2135 else if constexpr (method == BaseMethod::getNumNeeded)
2136 return g.getNumNeeded();
2137 else if constexpr (method == BaseMethod::getNumPoints)
2138 return g.getNumPoints();
2162 void mapCanonicalToTransformed(
int num_dimensions,
int num_points,
TypeOneDRule rule,
double x[])
const;
2170 template<
typename FloatType>
void mapTransformedToCanonical(
int num_dimensions,
int num_points,
TypeOneDRule rule, FloatType x[])
const;
2178 double getQuadratureScale(
int num_dimensions,
TypeOneDRule rule)
const;
2188 void mapConformalCanonicalToTransformed(
int num_dimensions,
int num_points,
double x[])
const;
2196 template<
typename FloatType>
void mapConformalTransformedToCanonical(
int num_dimensions,
int num_points, Data2D<FloatType> &x)
const;
2204 void mapConformalWeights(
int num_dimensions,
int num_points,
double weights[])
const;
2216 template<
typename FloatType>
const FloatType* formCanonicalPoints(
const FloatType *x, Data2D<FloatType> &x_temp,
int num_x)
const;
2225 template<
typename T>
2226 const T* formCanonicalPointsGPU(
const T *gpu_x,
int num_x, GpuVector<T> &gpu_x_temp)
const;
2235 template<
typename FloatType> std::vector<double> diffCanonicalTransform()
const;
2244 void formTransformedPoints(
int num_points,
double x[])
const;
2253 void writeAscii(std::ostream &ofs)
const;
2262 void readAscii(std::istream &ifs);
2270 void writeBinary(std::ostream &ofs)
const;
2279 void readBinary(std::istream &ifs);
2284 std::unique_ptr<AccelerationContext> acceleration;
2287 using grid_variant = std::variant<std::monostate,
2291 GridLocalPolynomial,
2296 std::vector<double> domain_transform_a, domain_transform_b;
2297 std::vector<int> conformal_asin_power;
2298 std::vector<int> llimits;
2300 bool using_dynamic_construction =
false;
2302 mutable AccelerationDomainTransform acc_domain;
2332inline TasmanianSparseGrid
2334 std::vector<int>
const &anisotropic_weights = std::vector<int>(),
double alpha = 0.0,
double beta = 0.0,
2335 const char* custom_filename =
nullptr, std::vector<int>
const &level_limits = std::vector<int>()){
2337 grid.
makeGlobalGrid(dimensions, outputs, depth, type, rule, anisotropic_weights, alpha, beta, custom_filename, level_limits);
2347inline TasmanianSparseGrid
2349 std::vector<int>
const &anisotropic_weights = std::vector<int>(), std::vector<int>
const &level_limits = std::vector<int>()){
2351 grid.
makeSequenceGrid(dimensions, outputs, depth, type, rule, anisotropic_weights, level_limits);
2361inline TasmanianSparseGrid
2374inline TasmanianSparseGrid
2375makeWaveletGrid(
int dimensions,
int outputs,
int depth,
int order = 1, std::vector<int>
const &level_limits = std::vector<int>()){
2377 grid.
makeWaveletGrid(dimensions, outputs, depth, order, level_limits);
2387inline TasmanianSparseGrid
2389 std::vector<int>
const &anisotropic_weights = std::vector<int>(), std::vector<int>
const &level_limits = std::vector<int>()){
2391 grid.
makeFourierGrid(dimensions, outputs, depth, type, anisotropic_weights, level_limits);
2407 grid.
read(filename);
2434 grid.
copyGrid(source, outputs_begin, outputs_end);
2603 grid.
makeGlobalGrid(
static_cast<int>(dims),
static_cast<int>(outs),
static_cast<int>(depth), type, rule, anisotropic_weights.weights, alpha.alpha, beta.beta, custom_filename.cname(), level_limits.limits);
2627 LevelLimits
const &level_limits = NoLevelLimits{}){
2629 grid.
makeSequenceGrid(
static_cast<int>(dims),
static_cast<int>(outs),
static_cast<int>(depth), type, rule, anisotropic_weights.weights, level_limits.limits);
2652 LevelLimits
const &level_limits = NoLevelLimits{}){
2654 grid.
makeLocalPolynomialGrid(
static_cast<int>(dims),
static_cast<int>(outs),
static_cast<int>(depth),
static_cast<int>(order), rule, level_limits.limits);
2676 LevelLimits
const &level_limits = NoLevelLimits{}){
2678 grid.
makeWaveletGrid(
static_cast<int>(dims),
static_cast<int>(outs),
static_cast<int>(depth),
static_cast<int>(order), level_limits.limits);
2700 LevelLimits
const &level_limits = NoLevelLimits{}){
2702 grid.
makeFourierGrid(
static_cast<int>(dims),
static_cast<int>(outs),
static_cast<int>(depth), type, anisotropic_weights.weights, level_limits.limits);
The master-class that represents an instance of a Tasmanian sparse grid.
Definition TasmanianSparseGrid.hpp:293
bool isGlobal() const
Returns true if the grid is of type global, false otherwise.
Definition TasmanianSparseGrid.hpp:1099
void setAnisotropicRefinement(TypeDepth type, int min_growth, int output, const int *level_limits=nullptr)
Overload using raw-array.
std::vector< int > estimateAnisotropicCoefficients(TypeDepth type, int output) const
Estimate the anisotropic rates of coefficient decay for different direction.
Definition TasmanianSparseGrid.hpp:1286
int getGPUID() const
Returns the currently set CUDA device.
Definition TasmanianSparseGrid.hpp:1874
void getDifferentiationWeights(const std::vector< double > &x, std::vector< double > &weights) const
Overload that uses the vector as a parameter.
std::vector< double > getNeededPoints() const
Return the points that require model values.
Definition TasmanianSparseGrid.hpp:709
int getNumPoints() const
Returns getNumLoaded() if positive, otherwise returns getNumNeeded(), see getPoints().
Definition TasmanianSparseGrid.hpp:675
void getDomainTransform(double a[], double b[]) const
Returns the values of the two vectors used to call setDomainTransform().
void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, CustomTabulated &&crule, const int *anisotropic_weights=nullptr, const int *level_limits=nullptr)
Overload using raw-arrays.
void updateSequenceGrid(int depth, TypeDepth type, const int *anisotropic_weights=nullptr, const int *level_limits=nullptr)
Overload using raw-arrays.
void getLoadedPoints(std::vector< double > &x) const
Overload that accepts the vector as a parameter.
Definition TasmanianSparseGrid.hpp:692
TypeOneDRule getRule() const
Return the underlying TasGrid::TypeOneDRule that gives the points and basis functions.
int getNumOutputs() const
Return the outputs of the grid, i.e., number of model outputs.
Definition TasmanianSparseGrid.hpp:658
void setConformalTransformASIN(std::vector< int > const &truncation)
Set conformal transformation using truncated Maclaurin series of the arcsin() function.
void finishConstruction()
End the procedure, clears flags and unused constructed points, can go back to using regular refinemen...
static int getVersionMinor()
Return the library minor version.
void makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule, const int *anisotropic_weights=nullptr, const int *level_limits=nullptr)
Overload using raw-arrays.
void write(const char *filename, bool binary=mode_binary) const
Write the grid to the given filename using either binary or ASCII format.
void getLoadedPoints(double x[]) const
Overload using raw-array, writes the loaded points to the first getNumLoaded() times getNumDimensions...
const double * getLoadedValues() const
Returns the model values that have been loaded in the gird.
void getDifferentiationWeights(const double x[], double weights[]) const
Overload that uses raw-array, does not check the array size.
double getBeta() const
Return the beta parameter in the call to makeGlobalGrid(), or return 0 if the grid is not Global.
Definition TasmanianSparseGrid.hpp:650
void getNeededPoints(std::vector< double > &x) const
Overload that accepts the vector as a parameter.
Definition TasmanianSparseGrid.hpp:716
void makeFourierGrid(int dimensions, int outputs, int depth, TypeDepth type, std::vector< int > const &anisotropic_weights, std::vector< int > const &level_limits=std::vector< int >())
Make a Fourier grid using trigonometric basis with support over the entire domain.
static bool isAccelerationAvailable(TypeAcceleration acc)
Returns whether a specific mode can be enabled.
static bool isHipEnabled()
Returns true if compiled with HIP support, e.g., Tasmanian_ENABLE_HIP=ON.
void evaluateFast(const FloatType x[], FloatType y[]) const
Equivalent to evaluate() with enabled acceleration or evaluateBatch() with a batch of one point.
Definition TasmanianSparseGrid.hpp:1035
std::vector< int > getLevelLimits() const
Return the currently set level limits.
Definition TasmanianSparseGrid.hpp:1221
void differentiate(const double x[], double jacobian[]) const
Overload that uses a raw-array.
static bool isDpcppEnabled()
Returns true if compiled with DPC++ support, e.g., Tasmanian_ENABLE_DPCPP=ON.
void evaluate(std::vector< double > const &x, std::vector< double > &y) const
Computes the value of the interpolant (or point-wise approximation) at the given point x.
void evaluateSparseHierarchicalFunctions(const std::vector< double > &x, std::vector< int > &pntr, std::vector< int > &indx, std::vector< double > &vals) const
Constructs a sparse matrix with the values of the hierarchical basis functions.
void loadNeededValues(const double *vals)
Overload that uses a raw-array, does not check the array size.
void evaluate(const double x[], double y[]) const
Overload that uses raw-arrays, does not check the array size.
void removePointsByHierarchicalCoefficient(int num_new_points, int output=-1, const double *scale_correction=nullptr)
Keeps only the given number of points with largest scaled surpluses.
std::vector< double > getHierarchicalSupport() const
Returns the support of the hierarchical functions.
void setHierarchicalCoefficients(const double c[])
Overload that uses raw-arrays.
void differentiate(std::vector< double > const &x, std::vector< double > &jacobian) const
Computes the derivative (if available) of the surrogate model at an input point.
void makeWaveletGrid(int dimensions, int outputs, int depth, int order, std::vector< int > const &level_limits)
Make a Wavelet grid using local hierarchical wavelet basis.
std::vector< double > getQuadratureWeights() const
Returns a vector of size getNumPoints() of the quadrature weights of the grid.
Definition TasmanianSparseGrid.hpp:761
void evaluateSparseHierarchicalFunctionsGPU(const FloatType gpu_x[], int cpu_num_x, int *&gpu_pntr, int *&gpu_indx, FloatType *&gpu_vals, int &num_nz) const
Computes the values of the hierarchical function basis at the specified points (sparse/CUDA version).
void setSurplusRefinement(double tolerance, TypeRefinement criteria, int output, std::vector< int > const &level_limits, std::vector< double > const &scale_correction=std::vector< double >())
Refine the grid based on the surplus coefficients, Local-Polynomial and Wavelet grids.
TasmanianSparseGrid & operator=(TasmanianSparseGrid const &source)
Copy assignment, note that the selected acceleration mode is not copied, acceleration is reset to the...
void getNeededPoints(double *x) const
Overload using raw-array, writes the loaded points to the first getNumNeeded() times getNumDimensions...
void evaluateBatch(const float x[], int num_x, float y[]) const
Overload using single precision and GPU/CUDA acceleration.
static const char * getLicense()
Return a hard-coded character string with a brief statement of the license.
void makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order=1, TypeOneDRule rule=rule_localp, const int *level_limits=nullptr)
Overload using raw-arrays.
std::vector< double > getAnisotropicRefinement(TypeDepth type, int min_growth, int output, const std::vector< int > &level_limits)
Call setAnisotropicRefinement() and then getNeededPoints().
Definition TasmanianSparseGrid.hpp:1262
void getQuadratureWeights(std::vector< double > &weights) const
Overload that accepts the vector as a parameter.
Definition TasmanianSparseGrid.hpp:767
static bool isCudaEnabled()
Returns true if compiled with CUDA support, e.g., Tasmanian_ENABLE_CUDA=ON.
void updateGrid(int depth, TypeDepth type, const int *anisotropic_weights=nullptr, const int *level_limits=nullptr)
Overload using raw-arrays.
void integrateHierarchicalFunctions(double integrals[]) const
Overload using raw-arrays.
~TasmanianSparseGrid()=default
Destructor, releases all resources.
void write(std::ostream &ofs, bool binary=mode_binary) const
Write the grid to the given stream ofs using either binary or ASCII format.
void write(std::string const &fname, bool binary=mode_binary) const
Overload that works directly with std::string.
Definition TasmanianSparseGrid.hpp:355
void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, CustomTabulated &&crule, std::vector< int > const &anisotropic_weights, std::vector< int > const &level_limits=std::vector< int >())
Overload make a Global Grid using the provided custom rule.
void setSurplusRefinement(double tolerance, int output, std::vector< int > const &level_limits)
Refine the grid based on the surplus coefficients, Sequence grids and Global grids with a sequence ru...
void getPoints(std::vector< double > &x) const
Overload that accepts the vector as a parameter.
Definition TasmanianSparseGrid.hpp:744
void copyGrid(const TasmanianSparseGrid *source, int outputs_begin=0, int outputs_end=-1)
Replace the grid with a copy of the source, does not copy the acceleration options.
bool isSetDomainTransfrom() const
Returns true if a linear domain transformation has been set, false otherwise.
void getDomainTransform(std::vector< double > &a, std::vector< double > &b) const
Returns the two vectors used to call setDomainTransform().
void integrateHierarchicalFunctions(std::vector< double > &integrals) const
Overload where the vector is passes as a parameter.
Definition TasmanianSparseGrid.hpp:1709
void updateFourierGrid(int depth, TypeDepth type, std::vector< int > const &anisotropic_weights, std::vector< int > const &level_limits=std::vector< int >())
Construct a new grid and merge it with the current one.
std::vector< double > integrate() const
Overload that returns a vector.
Definition TasmanianSparseGrid.hpp:1067
int getNumNeeded() const
Return the number of points that should be provided to the next call of loadNeededValues().
Definition TasmanianSparseGrid.hpp:673
void read(std::string const &fname)
Overload that works directly with std::string, see note on the file integrity.
Definition TasmanianSparseGrid.hpp:357
std::vector< double > getSurplusRefinement(double tolerance, TypeRefinement criteria, int output, std::vector< int > const &level_limits, std::vector< double > const &scale_correction=std::vector< double >())
Call setSurplusRefinement() for Local-Polynomial and Wavelet grids and then getNeededPoints().
Definition TasmanianSparseGrid.hpp:1375
void clearDomainTransform()
Removes the domain transformation.
std::vector< double > getPoints() const
Returns the loaded points if any, otherwise returns the needed points.
Definition TasmanianSparseGrid.hpp:738
void evaluateHierarchicalFunctions(const double x[], int num_x, double y[]) const
Array overload, the inputs must have pre-allocated and correct size.
TypeAcceleration getAccelerationType() const
Returns the current effective acceleration mode.
Definition TasmanianSparseGrid.hpp:1848
std::vector< double > getCandidateConstructionPoints(TypeDepth type, std::vector< int > const &anisotropic_weights=std::vector< int >(), std::vector< int > const &level_limits=std::vector< int >())
Generate a sorted list of points weighted by descending importance.
void setRocSparseHandle(void *handle)
Takes a user provided cuSparse handle.
void clearLevelLimits()
Removes the currently set level limits.
Definition TasmanianSparseGrid.hpp:1214
int getNumLoaded() const
Return the number of points already associated with model values via loadNeededValues().
Definition TasmanianSparseGrid.hpp:671
void evaluateFast(std::vector< FloatType > const &x, std::vector< FloatType > &y) const
Alias to evaluateBatch().
Definition TasmanianSparseGrid.hpp:1041
std::function< void(std::vector< double > const &, std::vector< double > &)> EvaluateCallable
Signature compatible with TasDREAM::DreamPDF, TasDREAM::DreamModel amd TasDREAM::DreamMergedLikelyMod...
Definition TasmanianSparseGrid.hpp:1952
void estimateAnisotropicCoefficients(TypeDepth type, int output, std::vector< int > &weights) const
Overload that writes the result to a parameter.
std::vector< int > getConformalTransformASIN() const
Fills the array with the values of the set transformation.
void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule, const int *anisotropic_weights=nullptr, double alpha=0.0, double beta=0.0, const char *custom_filename=nullptr, const int *level_limits=nullptr)
Overload using raw-arrays.
void clearConformalTransform()
Removes any currently set transformation.
std::vector< double > differentiate(std::vector< double > const &x) const
Same as TasmanianSparseGrid::differentiate() but returns the jacobian.
Definition TasmanianSparseGrid.hpp:1082
void evaluateBatch(std::vector< FloatType > const &x, std::vector< FloatType > &y) const
Computes the value of the interpolant (or point-wise approximation) for a batch of points.
static int getNumGPUs()
Return the number of visible CUDA devices.
Definition TasmanianSparseGrid.hpp:1885
TasmanianSparseGrid(const TasmanianSparseGrid &source)
Copy constructor, note that the selected acceleration mode is not copied, acceleration is reset to th...
void beginConstruction()
Begin a dynamic construction procedure.
static std::string getGPUName(int gpu)
Return the CUDA device name.
std::vector< double > getSurplusRefinement(double tolerance, int output, std::vector< int > const &level_limits)
Call setSurplusRefinement() for Sequence and Global grids with a sequence rule and then getNeededPoin...
Definition TasmanianSparseGrid.hpp:1321
bool isSequence() const
Returns true if the grid is of type sequence, false otherwise.
Definition TasmanianSparseGrid.hpp:1101
void getQuadratureWeights(double weights[]) const
Overload that accepts the raw array as an input.
void removePointsByHierarchicalCoefficient(double tolerance, int output=-1, const double *scale_correction=nullptr)
Removes all points from the grid that have relative surplus less than the tolerance.
void setCuSolverHandle(void *handle)
Takes a user provided cuSparse handle.
std::vector< int > getGlobalPolynomialSpace(bool interpolation) const
Returns the powers of the polynomial that span the effective basis, Global and Sequence grids only.
void integrate(std::vector< double > &q) const
Computes the integral of each model output over the sparse grid domain.
bool isFourier() const
Returns true if the grid is of type Fourier, false otherwise.
Definition TasmanianSparseGrid.hpp:1103
static int getVersionMajor()
Return the library major version.
void read(std::istream &ifs, bool binary=mode_binary)
Read the grid from the given stream ifs using either binary or ASCII format.
void getInterpolationWeights(const std::vector< double > &x, std::vector< double > &weights) const
Overload that uses the vector as a parameter.
void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule, std::vector< int > const &anisotropic_weights, double alpha=0.0, double beta=0.0, const char *custom_filename=nullptr, std::vector< int > const &level_limits=std::vector< int >())
Make a Global Grid using Lagrange polynomials with support over the entire domain.
const char * getCustomRuleDescription() const
Return the character string that is the description of the user-provided tabulated rule.
static int getGPUMemory(int gpu)
Return the available device memory, in units of MB.
std::vector< double > integrateHierarchicalFunctions() const
Returns the integrals of the hierarchical basis functions.
Definition TasmanianSparseGrid.hpp:1698
void printStats(std::ostream &os=std::cout) const
Prints short human-readable text describing the grid properties.
void clearRefinement()
Remove all needed points from the grid.
void updateGlobalGrid(int depth, TypeDepth type, std::vector< int > const &anisotropic_weights, std::vector< int > const &level_limits=std::vector< int >())
Construct a new grid and merge it with the current one.
void mergeRefinement()
Merges the loaded and needed points into a single grid, resets all loaded values to zero.
void loadNeededPoints(const double *vals)
Overload that uses a raw-array, does not check the array size.
Definition TasmanianSparseGrid.hpp:904
TasmanianSparseGrid & operator=(TasmanianSparseGrid &&source)=default
Move assignment, the selected acceleration mode is also carried over.
void updateSequenceGrid(int depth, TypeDepth type, std::vector< int > const &anisotropic_weights, std::vector< int > const &level_limits=std::vector< int >())
Construct a new grid and merge it with the current one.
std::vector< double > getDifferentiationWeights(double const x[]) const
Overload that uses raw-array, does not check the array size.
Definition TasmanianSparseGrid.hpp:849
void copyGrid(TasmanianSparseGrid const &source, int outputs_begin=0, int outputs_end=-1)
Overload using pass-by-reference as opposed to a pointer.
Definition TasmanianSparseGrid.hpp:569
void updateFourierGrid(int depth, TypeDepth type, const int *anisotropic_weights=nullptr, const int *level_limits=nullptr)
Overload using raw-arrays.
std::vector< double > getCandidateConstructionPoints(TypeDepth type, int output, std::vector< int > const &level_limits=std::vector< int >())
Essentially the same as getCandidateConstructionPoints() but the weights are obtained from a call to ...
void getPoints(double x[]) const
Overload that accepts the raw array as an input.
std::vector< double > getDifferentiationWeights(std::vector< double > const &x) const
Returns the weights of the model outputs that combine to construct the approximate Jacobian matrix (d...
static const char * getGitCommitHash()
Return the git hash string, will use a placeholder if the git command was not found on compile time o...
std::vector< double > getInterpolationWeights(double const x[]) const
Overload that uses raw-array, does not check the array size.
Definition TasmanianSparseGrid.hpp:809
void enableAcceleration(TypeAcceleration acc)
Change the current acceleration mode to the one specified.
static const char * getVersion()
Return a hard-coded character string with the version in format "Major.Minor".
std::vector< double > getInterpolationWeights(std::vector< double > const &x) const
Returns the weights of the model outputs that combine to construct the approximation value at x.
void evaluateHierarchicalFunctionsGPU(const FloatType gpu_x[], int cpu_num_x, FloatType gpu_y[]) const
Computes the values of the hierarchical function basis at the specified points (CUDA version).
bool isSetConformalTransformASIN() const
Returns true if conformal transformation has been set.
void evaluateBatch(const double x[], int num_x, double y[]) const
Overload that uses raw-arrays.
void read(const char *filename)
Read the grid from the given filename, automatically detect the format.
void makeFourierGrid(int dimensions, int outputs, int depth, TypeDepth type, const int *anisotropic_weights=nullptr, const int *level_limits=nullptr)
Overload using raw-arrays.
void setAnisotropicRefinement(TypeDepth type, int min_growth, int output, const std::vector< int > &level_limits)
Set refinement using anisotropic estimate for the optimal points.
double getAlpha() const
Return the alpha parameter in the call to makeGlobalGrid(), or return 0 if the grid is not Global.
Definition TasmanianSparseGrid.hpp:648
void updateGrid(int depth, TypeDepth type, std::vector< int > const &anisotropic_weights, std::vector< int > const &level_limits=std::vector< int >())
Based on the grid type, calls updateGlobalGrid(), updateSequenceGrid() or updateFourierGrid().
void favorSparseAcceleration(bool favor)
Set the preferred back-end algorithm for Local Polynomial grids.
static bool isOpenMPEnabled()
Returns true if compiled with OpenMP support, e.g., Tasmanian_ENABLE_OPENMP=ON.
void setSurplusRefinement(double tolerance, TypeRefinement criteria, int output=-1, const int *level_limits=nullptr, const double *scale_correction=nullptr)
Overload that uses raw-arrays.
void setSycleQueue(void *queue)
Takes a user provided sycl::queue handle.
void setSurplusRefinement(double tolerance, int output, const int *level_limits=nullptr)
Overload that uses array for the level limits.
void loadConstructedPoints(const double x[], int numx, const double y[])
Same as loadConstructedPoint() but using arrays in place of vectors (array size is not checked).
static const char * getCmakeCxxFlags()
Return the CMAKE_BUILD_TYPE and CMAKE_CXX_FLAGS used in the configuration.
DomainInsideSignature getDomainInside() const
Returns a lambda object that satisfies the TasDREAM::DreamDomain signature.
Definition TasmanianSparseGrid.hpp:1973
void setDomainTransform(std::vector< double > const &a, std::vector< double > const &b)
Set a linear domain transformation.
bool isUsingConstruction() const
Returns true if the dynamic construction procedure has been initialized, false otherwise.
Definition TasmanianSparseGrid.hpp:1417
void setCuBlasHandle(void *handle)
Takes a user provided cuBlas handle.
void evaluateHierarchicalFunctions(std::vector< double > const &x, std::vector< double > &y) const
Computes the values of the hierarchical function basis at the specified points.
bool empty() const
Returns true if the grid is empty (no type), false otherwise.
Definition TasmanianSparseGrid.hpp:1097
TasmanianSparseGrid()
Default constructor, creates and empty grid.
void makeWaveletGrid(int dimensions, int outputs, int depth, int order=1, const int *level_limits=nullptr)
Overload using raw-arrays.
void loadNeededPoints(std::vector< double > const &vals)
Alias of loadNeededValues().
Definition TasmanianSparseGrid.hpp:898
void makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule, std::vector< int > const &anisotropic_weights, std::vector< int > const &level_limits=std::vector< int >())
Make Sequence Grid using Newton polynomials with support over the entire domain.
void setCuSparseHandle(void *handle)
Takes a user provided cuSparse handle.
void evaluateBatchGPU(const FloatType gpu_x[], int cpu_num_x, FloatType gpu_y[]) const
Overload that uses GPU raw-arrays.
void setHierarchicalCoefficients(const std::vector< double > &c)
Overwrites the current set of coefficients (and loaded values) with the ones provided.
void updateGlobalGrid(int depth, TypeDepth type, const int *anisotropic_weights=nullptr, const int *level_limits=nullptr)
Overload using raw-arrays.
void setDomainTransform(const double a[], const double b[])
Overload using raw-arrays.
const double * getHierarchicalCoefficients() const
Return a reference to the internal data-structure that stores the hierarchical coefficients.
TasmanianSparseGrid(TasmanianSparseGrid &&source)=default
Move constructor, the selected acceleration mode is also carried over.
std::vector< double > getLoadedPoints() const
Return the points already associated with model values.
Definition TasmanianSparseGrid.hpp:685
std::function< bool(std::vector< double > const &)> DomainInsideSignature
Signature of the domain inside lambda, identical to TasDREAM::DreamDomain.
Definition TasmanianSparseGrid.hpp:1965
int getNumDimensions() const
Return the dimensions of the grid, i.e., number of model inputs.
Definition TasmanianSparseGrid.hpp:656
void enableAcceleration(TypeAcceleration acc, int new_gpu_id)
Combines calls the enableAcceleration(), getGPUID() and allows for user provided handles.
bool isLocalPolynomial() const
Returns true if the grid is of type local polynomial, false otherwise.
Definition TasmanianSparseGrid.hpp:1105
void getInterpolationWeights(const double x[], double weights[]) const
Overload that uses raw-array, does not check the array size.
void makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order, TypeOneDRule rule, std::vector< int > const &level_limits)
Make Local Polynomial Grid using piece-wise polynomials with decreasing (compact) support.
bool isEmpty() const
Returns true if the grid is empty (no type), false otherwise.
Definition TasmanianSparseGrid.hpp:1095
bool isWavelet() const
Returns true if the grid is of type wavelet, false otherwise.
Definition TasmanianSparseGrid.hpp:1107
void setRocBlasHandle(void *handle)
Takes a user provided cuBlas handle.
void loadNeededValues(std::vector< double > const &vals)
Provides the values of the model outputs at the needed points, or overwrites the currently loaded poi...
void loadConstructedPoints(std::vector< double > const &x, std::vector< double > const &y)
Add pairs of points with associated model values.
void setGPUID(int new_gpu_id)
Select the current CUDA device.
std::vector< double > evaluateHierarchicalFunctions(std::vector< double > const &x) const
Overload that returns the result.
Definition TasmanianSparseGrid.hpp:1617
std::vector< double > getCandidateConstructionPoints(double tolerance, TypeRefinement criteria, int output=-1, std::vector< int > const &level_limits=std::vector< int >(), std::vector< double > const &scale_correction=std::vector< double >())
Returns a sorted list of points weighted by descending importance using the hierarchical surpluses.
int getOrder() const
Return the order parameter in the call to makeLocalPolynomialGrid() or makeWaveletGrid(),...
Definition TasmanianSparseGrid.hpp:652
void integrate(double q[]) const
Overload that uses a raw-array.
TypeOneDRule
Used to specify the one dimensional family of rules that induces the sparse grid.
Definition tsgEnumerates.hpp:288
TypeAcceleration
Modes of acceleration.
Definition tsgEnumerates.hpp:554
TypeDepth
Used by Global Sequence and Fourier grids, indicates the selection criteria.
Definition tsgEnumerates.hpp:206
TypeRefinement
Refinement strategy for local polynomial and wavelet grids.
Definition tsgEnumerates.hpp:428
@ rule_gausshermite
Non-nested rule optimized for integral of the form .
Definition tsgEnumerates.hpp:358
@ rule_gausslaguerreodd
Same as rule_gausslaguerre but using only odd levels, partially mitigates the non-nested issues.
Definition tsgEnumerates.hpp:356
@ rule_localp
Nested rule with a hierarchy of uniformly distributed nodes and functions with compact support.
Definition tsgEnumerates.hpp:365
@ rule_gausslaguerre
Non-nested rule optimized for integral of the form .
Definition tsgEnumerates.hpp:354
@ rule_gausshermiteodd
Same as rule_gausshermite but using only odd levels, partially mitigates the non-nested issues.
Definition tsgEnumerates.hpp:360
BasisOrder
Strong type for the maximum polynomial order of the grid.
Definition TasmanianSparseGrid.hpp:2468
NumDimensions
Strong type for the number of dimensions.
Definition TasmanianSparseGrid.hpp:2450
DepthLevel
Strong type for the depth (e.g., level/polynomial-order) of the grid.
Definition TasmanianSparseGrid.hpp:2462
NumOutputs
Strong type for the number of outputs.
Definition TasmanianSparseGrid.hpp:2456
TasmanianSparseGrid makeEmpty()
Returns an empty sparse grid.
Definition TasmanianSparseGrid.hpp:2316
TasmanianSparseGrid makeWaveletGrid(int dimensions, int outputs, int depth, int order=1, std::vector< int > const &level_limits=std::vector< int >())
Factory method, creates a new grid and calls TasmanianSparseGrid::makeWaveletGrid().
Definition TasmanianSparseGrid.hpp:2375
TasmanianSparseGrid makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule, std::vector< int > const &anisotropic_weights=std::vector< int >(), std::vector< int > const &level_limits=std::vector< int >())
Factory method, creates a new grid and calls TasmanianSparseGrid::makeSequenceGrid().
Definition TasmanianSparseGrid.hpp:2348
TasmanianSparseGrid makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule, std::vector< int > const &anisotropic_weights=std::vector< int >(), double alpha=0.0, double beta=0.0, const char *custom_filename=nullptr, std::vector< int > const &level_limits=std::vector< int >())
Factory method, creates a new grid and calls TasmanianSparseGrid::makeGlobalGrid().
Definition TasmanianSparseGrid.hpp:2333
TasmanianSparseGrid readGrid(const char *filename)
Factory method, creates a new grid and calls TasmanianSparseGrid::read().
Definition TasmanianSparseGrid.hpp:2405
TasmanianSparseGrid makeFourierGrid(int dimensions, int outputs, int depth, TypeDepth type, std::vector< int > const &anisotropic_weights=std::vector< int >(), std::vector< int > const &level_limits=std::vector< int >())
Factory method, creates a new grid and calls TasmanianSparseGrid::makeFourierGrid().
Definition TasmanianSparseGrid.hpp:2388
TasmanianSparseGrid makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order=1, TypeOneDRule rule=rule_localp, std::vector< int > const &level_limits=std::vector< int >())
Factory method, creates a new grid and calls TasmanianSparseGrid::makeLocalPolynomialGrid().
Definition TasmanianSparseGrid.hpp:2362
constexpr bool mode_binary
Constant allowing for more expressive selection of ascii and binary mode in IO methods.
Definition tsgIOHelpers.hpp:68
TasmanianSparseGrid copyGrid(TasmanianSparseGrid const &source, int outputs_begin=0, int outputs_end=-1)
Returns a grid that is a copy of the source.
Definition TasmanianSparseGrid.hpp:2432
Encapsulates the Tasmanian Sparse Grid module.
Definition TasmanianSparseGrid.hpp:68
AlphaValue()=default
Creates a zero alpha, probably will never use the value.
AlphaValue(double a)
Creates an alpha parameter.
Definition TasmanianSparseGrid.hpp:2516
double alpha
The value for the parameter.
Definition TasmanianSparseGrid.hpp:2518
Strong type for the vector of integers representing the anisotropic weighs.
Definition TasmanianSparseGrid.hpp:2493
AnsitropicWeights()=default
Creates a vector of no weights, results in isotropic grid.
AnsitropicWeights(std::vector< int > const &w)
Creates weighs from a vector.
Definition TasmanianSparseGrid.hpp:2501
std::vector< int > weights
The created weights.
Definition TasmanianSparseGrid.hpp:2503
AnsitropicWeights(IsotropicWeights)
Creates a vector of no weights, results in isotropic grid.
Definition TasmanianSparseGrid.hpp:2497
AnsitropicWeights(std::initializer_list< int > list)
Create weights from an initializer list.
Definition TasmanianSparseGrid.hpp:2499
Strong type for the beta parameter used by some rules and distributions.
Definition TasmanianSparseGrid.hpp:2527
double beta
The value for the parameter.
Definition TasmanianSparseGrid.hpp:2533
BetaValue()=default
Creates a zero alpha, probably will never use the value.
BetaValue(double b)
Creates an alpha parameter.
Definition TasmanianSparseGrid.hpp:2531
Strong type for the custom filename.
Definition TasmanianSparseGrid.hpp:2540
CustomRuleFilename(std::string_view str)
Creates a custom filename from a string view.
Definition TasmanianSparseGrid.hpp:2544
const char * cname() const
Returns null-terminated string.
Definition TasmanianSparseGrid.hpp:2546
std::string name
The created weights.
Definition TasmanianSparseGrid.hpp:2548
CustomRuleFilename()=default
Creates an empty filename.
Strong type for creating isotropic weights.
Definition TasmanianSparseGrid.hpp:2474
Strong type for the vector of integers representing the anisotropic weighs.
Definition TasmanianSparseGrid.hpp:2563
std::vector< int > limits
The created weights.
Definition TasmanianSparseGrid.hpp:2573
LevelLimits()=default
Creates a vector of no weights, results in isotropic grid.
LevelLimits(std::initializer_list< int > list)
Create weights from an initializer list.
Definition TasmanianSparseGrid.hpp:2569
LevelLimits(std::vector< int > const &ll)
Creates weighs from a vector.
Definition TasmanianSparseGrid.hpp:2571
LevelLimits(NoLevelLimits)
Creates a vector of no weights, results in isotropic grid.
Definition TasmanianSparseGrid.hpp:2567
Strong type for creating a grid with no level limits.
Definition TasmanianSparseGrid.hpp:2555