Doxygen 1.17.0
Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN: Tasmanian v8.3
Loading...
Searching...
No Matches
TasmanianSparseGrid.hpp
1/*
2 * Copyright (c) 2017, Miroslav Stoyanov
3 *
4 * This file is part of
5 * Toolkit for Adaptive Stochastic Modeling And Non-Intrusive ApproximatioN: TASMANIAN
6 *
7 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
12 * and the following disclaimer in the documentation and/or other materials provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
20 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
21 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * UT-BATTELLE, LLC AND THE UNITED STATES GOVERNMENT MAKE NO REPRESENTATIONS AND DISCLAIM ALL WARRANTIES, BOTH EXPRESSED AND IMPLIED.
25 * THERE ARE NO EXPRESS OR IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE ANY PATENT,
26 * COPYRIGHT, TRADEMARK, OR OTHER PROPRIETARY RIGHTS, OR THAT THE SOFTWARE WILL ACCOMPLISH THE INTENDED RESULTS OR THAT THE SOFTWARE OR ITS USE WILL NOT RESULT IN INJURY OR DAMAGE.
27 * THE USER ASSUMES RESPONSIBILITY FOR ALL LIABILITIES, PENALTIES, FINES, CLAIMS, CAUSES OF ACTION, AND COSTS AND EXPENSES, CAUSED BY, RESULTING FROM OR ARISING OUT OF,
28 * IN WHOLE OR IN PART THE USE, STORAGE OR DISPOSAL OF THE SOFTWARE.
29 */
30
42
43#ifndef __TASMANIAN_SPARSE_GRID_HPP
44#define __TASMANIAN_SPARSE_GRID_HPP
45
46#include "tsgGridGlobal.hpp"
47#include "tsgGridLocalPolynomial.hpp"
48#include "tsgGridWavelet.hpp"
49#include "tsgGridFourier.hpp"
50
63
68namespace TasGrid{
69
77
294public:
303
308
310 static const char* getVersion(); // human readable
312 static int getVersionMajor();
314 static int getVersionMinor();
316 static const char* getLicense(); // human readable
318 static const char* getGitCommitHash();
320 static const char* getCmakeCxxFlags();
322 static bool isOpenMPEnabled();
324 static bool isCudaEnabled();
326 static bool isHipEnabled();
328 static bool isDpcppEnabled();
329
331 void write(const char *filename, bool binary = mode_binary) const;
342 void read(const char *filename); // auto-check if format is binary or ascii
343
345 void write(std::ostream &ofs, bool binary = mode_binary) const;
352 void read(std::istream &ifs, bool binary = mode_binary);
353
355 void write(std::string const& fname, bool binary = mode_binary) const{ write(fname.c_str(), binary); }
357 void read(std::string const& fname){ read(fname.c_str()); }
358
405 void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
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>());
415 void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
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);
423 void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, CustomTabulated &&crule,
424 std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
430 void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, CustomTabulated &&crule,
431 const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
432
450 void makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
451 std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
459 void makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
460 const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
461
488 void makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order, TypeOneDRule rule, std::vector<int> const &level_limits);
496 void makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order = 1, TypeOneDRule rule = rule_localp, const int *level_limits = nullptr);
497
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);
525
535 void makeFourierGrid(int dimensions, int outputs, int depth, TypeDepth type,
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);
545
562 void copyGrid(const TasmanianSparseGrid *source, int outputs_begin = 0, int outputs_end = -1);
569 void copyGrid(TasmanianSparseGrid const &source, int outputs_begin = 0, int outputs_end = -1){ copyGrid(&source, outputs_begin, outputs_end); }
570
585 void updateGlobalGrid(int depth, TypeDepth type, std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
591 void updateGlobalGrid(int depth, TypeDepth type, const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
592
606 void updateSequenceGrid(int depth, TypeDepth type, std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
612 void updateSequenceGrid(int depth, TypeDepth type, const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
613
627 void updateFourierGrid(int depth, TypeDepth type, std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
633 void updateFourierGrid(int depth, TypeDepth type, const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
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);
646
648 double getAlpha() const{ return (isGlobal()) ? get<GridGlobal>()->getAlpha() : 0.0; }
650 double getBeta() const{ return (isGlobal()) ? get<GridGlobal>()->getBeta() : 0.0; }
652 int getOrder() const{ return (isLocalPolynomial()) ? get<GridLocalPolynomial>()->getOrder() : ((isWavelet()) ? get<GridWavelet>()->getOrder() : -1); }
653
654
656 int getNumDimensions() const{ return makeCall<BaseMethod::getNumDimensions>(); }
658 int getNumOutputs() const{ return makeCall<BaseMethod::getNumOutputs>(); }
668 const char* getCustomRuleDescription() const; // used only for Global Grids with rule_customtabulated
669
671 int getNumLoaded() const{ return makeCall<BaseMethod::getNumLoaded>(); }
673 int getNumNeeded() const{ return makeCall<BaseMethod::getNumNeeded>(); }
675 int getNumPoints() const{ return makeCall<BaseMethod::getNumPoints>(); }
676
685 std::vector<double> getLoadedPoints() const{ std::vector<double> x; getLoadedPoints(x); return x; }
692 void getLoadedPoints(std::vector<double> &x) const{ x.resize(Utils::size_mult(getNumDimensions(), getNumLoaded())); getLoadedPoints(x.data()); }
699 void getLoadedPoints(double x[]) const;
700
709 std::vector<double> getNeededPoints() const{ std::vector<double> x; getNeededPoints(x); return x; }
716 void getNeededPoints(std::vector<double> &x) const{ x.resize(Utils::size_mult(getNumDimensions(), getNumNeeded())); getNeededPoints(x.data()); }
723 void getNeededPoints(double *x) const;
724
738 std::vector<double> getPoints() const{ std::vector<double> x; getPoints(x); return x; }
744 void getPoints(std::vector<double> &x) const{ x.resize(Utils::size_mult(getNumDimensions(), getNumPoints())); getPoints(x.data()); }
750 void getPoints(double x[]) const; // returns the loaded points unless no points are loaded, then returns the needed points
751
761 std::vector<double> getQuadratureWeights() const{ std::vector<double> w; getQuadratureWeights(w); return w; }
767 void getQuadratureWeights(std::vector<double> &weights) const{ weights.resize((size_t) getNumPoints()); getQuadratureWeights(weights.data()); }
773 void getQuadratureWeights(double weights[]) const; // static memory, assumes that weights has size getNumPoints()
774
802 std::vector<double> getInterpolationWeights(std::vector<double> const &x) const;
809 std::vector<double> getInterpolationWeights(double const x[]) const{ std::vector<double> w((size_t) getNumPoints()); getInterpolationWeights(x, w.data()); return w; }
816 void getInterpolationWeights(const std::vector<double> &x, std::vector<double> &weights) const;
823 void getInterpolationWeights(const double x[], double weights[]) const;
824
842 std::vector<double> getDifferentiationWeights(std::vector<double> const &x) const;
849 std::vector<double> getDifferentiationWeights(double const x[]) const {
850 std::vector<double> w((size_t) getNumPoints() * (size_t) getNumDimensions());
851 getDifferentiationWeights(x, w.data());
852 return w;
853 }
854
860 void getDifferentiationWeights(const std::vector<double> &x, std::vector<double> &weights) const;
868 void getDifferentiationWeights(const double x[], double weights[]) const;
869
888 void loadNeededValues(std::vector<double> const &vals); // checks if vals has size num_outputs X getNumNeeded()
894 void loadNeededValues(const double *vals);
898 void loadNeededPoints(std::vector<double> const &vals) {loadNeededValues(vals);}
904 void loadNeededPoints(const double *vals) {loadNeededValues(vals);}
913 const double* getLoadedValues() const;
914
931 void evaluate(std::vector<double> const &x, std::vector<double> &y) const;
938 void evaluate(const double x[], double y[]) const;
971 template<typename FloatType> void evaluateBatch(std::vector<FloatType> const &x, std::vector<FloatType> &y) const;
995 void evaluateBatch(const double x[], int num_x, double y[]) const;
1008 void evaluateBatch(const float x[], int num_x, float y[]) const;
1021 template<typename FloatType> void evaluateBatchGPU(const FloatType gpu_x[], int cpu_num_x, FloatType gpu_y[]) const;
1035 template<typename FloatType> void evaluateFast(const FloatType x[], FloatType y[]) const{ evaluateBatch(x, 1, y); }
1041 template<typename FloatType> void evaluateFast(std::vector<FloatType> const &x, std::vector<FloatType> &y) const{ evaluateBatch(x, y); }
1055 void integrate(std::vector<double> &q) const;
1063 void integrate(double q[]) const;
1067 std::vector<double> integrate() const{
1068 std::vector<double> result;
1069 integrate(result);
1070 return result;
1071 }
1072
1078 void differentiate(std::vector<double> const &x, std::vector<double> &jacobian) const;
1082 std::vector<double> differentiate(std::vector<double> const &x) const{
1083 std::vector<double> jacobian;
1084 differentiate(x, jacobian);
1085 return jacobian;
1086 }
1087
1092 void differentiate(const double x[], double jacobian[]) const;
1093
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); }
1105 bool isLocalPolynomial() const{ return std::holds_alternative<GridLocalPolynomial>(base); }
1107 bool isWavelet() const{ return std::holds_alternative<GridWavelet>(base); }
1108
1136 void setDomainTransform(std::vector<double> const &a, std::vector<double> const &b);
1143 void setDomainTransform(const double a[], const double b[]);
1167 void getDomainTransform(std::vector<double> &a, std::vector<double> &b) const;
1178 void getDomainTransform(double a[], double b[]) const;
1179
1199 void setConformalTransformASIN(std::vector<int> const &truncation);
1205 std::vector<int> getConformalTransformASIN() const;
1206
1214 void clearLevelLimits(){ llimits.clear(); }
1221 std::vector<int> getLevelLimits() const{ return llimits; }
1222
1251 void setAnisotropicRefinement(TypeDepth type, int min_growth, int output, const std::vector<int> &level_limits);
1258 void setAnisotropicRefinement(TypeDepth type, int min_growth, int output, const int *level_limits = nullptr);
1262 std::vector<double> getAnisotropicRefinement(TypeDepth type, int min_growth, int output, const std::vector<int> &level_limits) {
1263 setAnisotropicRefinement(type, min_growth, output, level_limits);
1264 return getNeededPoints();
1265 }
1266
1286 std::vector<int> estimateAnisotropicCoefficients(TypeDepth type, int output) const{ std::vector<int> w; estimateAnisotropicCoefficients(type, output, w); return w; }
1293 void estimateAnisotropicCoefficients(TypeDepth type, int output, std::vector<int> &weights) const;
1294
1315 void setSurplusRefinement(double tolerance, int output, std::vector<int> const &level_limits);
1317 void setSurplusRefinement(double tolerance, int output, const int *level_limits = nullptr);
1321 std::vector<double> getSurplusRefinement(double tolerance, int output, std::vector<int> const &level_limits) {
1322 setSurplusRefinement(tolerance, output, level_limits);
1323 return getNeededPoints();
1324 }
1325
1362 void setSurplusRefinement(double tolerance, TypeRefinement criteria, int output,
1363 std::vector<int> const &level_limits, std::vector<double> const &scale_correction = std::vector<double>()); // -1 indicates using all outputs
1371 void setSurplusRefinement(double tolerance, TypeRefinement criteria, int output = -1, const int *level_limits = nullptr, const double *scale_correction = nullptr);
1375 std::vector<double> getSurplusRefinement(double tolerance, TypeRefinement criteria, int output, std::vector<int> const &level_limits,
1376 std::vector<double> const &scale_correction = std::vector<double>()) {
1377 setSurplusRefinement(tolerance, criteria, output, level_limits, scale_correction);
1378 return getNeededPoints();
1379 }
1380
1397 void mergeRefinement(); // merges all points but resets all loaded values to 0.0
1398
1417 bool isUsingConstruction() const{ return using_dynamic_construction; }
1449 std::vector<double> getCandidateConstructionPoints(TypeDepth type, std::vector<int> const &anisotropic_weights = std::vector<int>(),
1450 std::vector<int> const &level_limits = std::vector<int>());
1474 std::vector<double> getCandidateConstructionPoints(TypeDepth type, int output, std::vector<int> const &level_limits = std::vector<int>());
1475
1484 std::vector<double> getCandidateConstructionPoints(double tolerance, TypeRefinement criteria, int output = -1,
1485 std::vector<int> const &level_limits = std::vector<int>(),
1486 std::vector<double> const &scale_correction = std::vector<double>());
1507 void loadConstructedPoints(std::vector<double> const &x, std::vector<double> const &y);
1513 void loadConstructedPoints(const double x[], int numx, const double y[]);
1529
1549 const double* getHierarchicalCoefficients() const;
1550
1556 void getHierarchicalCoefficientsStatic(double *coeff) const{
1558 + ((isFourier()) ? 2 : 1) * getNumOutputs() * getNumLoaded(), coeff);
1559 }
1560
1577 void setHierarchicalCoefficients(const std::vector<double> &c);
1583 void setHierarchicalCoefficients(const double c[]);
1584
1611 void evaluateHierarchicalFunctions(std::vector<double> const &x, std::vector<double> &y) const;
1617 std::vector<double> evaluateHierarchicalFunctions(std::vector<double> const &x) const{
1618 std::vector<double> y;
1620 return y;
1621 }
1622
1639 void evaluateHierarchicalFunctions(const double x[], int num_x, double y[]) const;
1640
1661 void evaluateSparseHierarchicalFunctions(const std::vector<double> &x, std::vector<int> &pntr, std::vector<int> &indx, std::vector<double> &vals) const;
1662
1680 std::vector<double> getHierarchicalSupport() const;
1681
1698 std::vector<double> integrateHierarchicalFunctions() const{
1699 std::vector<double> integrals;
1701 return integrals;
1702 }
1703
1709 void integrateHierarchicalFunctions(std::vector<double> &integrals) const{
1710 integrals.resize(getNumPoints());
1711 integrateHierarchicalFunctions(integrals.data());
1712 }
1713
1721 void integrateHierarchicalFunctions(double integrals[]) const;
1722
1740 std::vector<int> getGlobalPolynomialSpace(bool interpolation) const;
1741
1751 void printStats(std::ostream &os = std::cout) const;
1752
1774 void enableAcceleration(TypeAcceleration acc, int new_gpu_id);
1793 void favorSparseAcceleration(bool favor);
1801 void setCuBlasHandle(void *handle);
1809 void setCuSparseHandle(void *handle);
1817 void setCuSolverHandle(void *handle);
1825 void setRocBlasHandle(void *handle);
1833 void setRocSparseHandle(void *handle);
1841 void setSycleQueue(void *queue);
1848 TypeAcceleration getAccelerationType() const{ return acceleration->mode; }
1857
1868 void setGPUID(int new_gpu_id);
1874 int getGPUID() const{ return acceleration->device; }
1885 static int getNumGPUs(){ return AccelerationMeta::getNumGpuDevices(); }
1893 static int getGPUMemory(int gpu);
1902 static std::string getGPUName(int gpu);
1903
1922 template<typename FloatType>
1923 void evaluateHierarchicalFunctionsGPU(const FloatType gpu_x[], int cpu_num_x, FloatType gpu_y[]) const;
1948 template<typename FloatType>
1949 void evaluateSparseHierarchicalFunctionsGPU(const FloatType gpu_x[], int cpu_num_x, int* &gpu_pntr, int* &gpu_indx, FloatType* &gpu_vals, int &num_nz) const;
1950
1952 using EvaluateCallable = std::function<void(std::vector<double> const&, std::vector<double>&)>;
1953
1960 operator EvaluateCallable() const{
1961 return [&](std::vector<double> const &x, std::vector<double> &y)->void{ evaluateBatch(x, y); };
1962 }
1963
1965 using DomainInsideSignature = std::function<bool(std::vector<double> const &)>; // trick for Doxygen formatting purposes
1966
1974 auto rule = getRule();
1975 if ((rule == TasGrid::rule_gausshermite) || (rule == TasGrid::rule_gausshermiteodd)){ // unbounded domain
1976 return [](std::vector<double> const &)->bool{ return true; };
1977 }else if ((rule == TasGrid::rule_gausslaguerre) || (rule == TasGrid::rule_gausslaguerreodd)){ // bounded from below
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;
1981 return true;
1982 };
1983 }else{
1984 size_t dims = (size_t) getNumDimensions();
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;
1987 return true;
1988 };
1989 }
1990 }else{
1991 if (domain_transform_a.empty()){
1992 if (isFourier()){
1993 return [](std::vector<double> const &x)->bool{
1994 for(auto const &v : x) if ((v < 0.0) || (v > 1.0)) return false;
1995 return true;
1996 };
1997 }else{
1998 return [](std::vector<double> const &x)->bool{
1999 for(auto const &v : x) if ((v < -1.0) || (v > 1.0)) return false;
2000 return true;
2001 };
2002 }
2003 }else{
2004 size_t dims = (size_t) getNumDimensions();
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;
2008 return true;
2009 };
2010 }
2011 }
2012 }
2013
2030 void removePointsByHierarchicalCoefficient(double tolerance, int output = -1, const double *scale_correction = nullptr);
2043 void removePointsByHierarchicalCoefficient(int num_new_points, int output = -1, const double *scale_correction = nullptr);
2044
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;
2079
2087 template<class T> inline T* get(){
2088 return std::get_if<T>(std::addressof(base));
2089 }
2097 template<class T> inline T const* get() const{
2098 return std::get_if<T>(std::addressof(base));
2099 }
2106 AccelerationContext const* getAccelerationContext() const{ return acceleration.get(); }
2107 #endif // __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2108
2109protected:
2110 #ifndef __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2117 enum class BaseMethod {
2123 };
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();
2139 } else {
2140 return int{0};
2141 }
2142 }, base);
2143 }
2144
2152 void clear();
2153
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;
2179
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;
2205
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; // when calling get***Points()
2245
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);
2280 #endif // __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2281
2282private:
2283 // must not invalidate aliases when the grid is moved, must be destroyed last for sycl
2284 std::unique_ptr<AccelerationContext> acceleration;
2285
2286 // contains all possible sparse grids with a null-grid std::monostate as the default
2287 using grid_variant = std::variant<std::monostate,
2288 GridGlobal, // index 1
2289 GridSequence, // index 2
2290 GridFourier, // index 3
2291 GridLocalPolynomial, // index 4
2292 GridWavelet // index 5
2293 >;
2294 grid_variant base;
2295
2296 std::vector<double> domain_transform_a, domain_transform_b;
2297 std::vector<int> conformal_asin_power;
2298 std::vector<int> llimits;
2299
2300 bool using_dynamic_construction = false;
2301
2302 mutable AccelerationDomainTransform acc_domain;
2303};
2304
2317
2332inline TasmanianSparseGrid
2333makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
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);
2338 return grid;
2339}
2340
2347inline TasmanianSparseGrid
2348makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
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);
2352 return grid;
2353}
2354
2361inline TasmanianSparseGrid
2362makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order = 1, TypeOneDRule rule = rule_localp, std::vector<int> const &level_limits = std::vector<int>()){
2364 grid.makeLocalPolynomialGrid(dimensions, outputs, depth, order, rule, level_limits);
2365 return grid;
2366}
2367
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);
2378 return grid;
2379}
2380
2387inline TasmanianSparseGrid
2388makeFourierGrid(int dimensions, int outputs, int depth, TypeDepth type,
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);
2392 return grid;
2393}
2394
2405inline TasmanianSparseGrid readGrid(const char *filename){
2407 grid.read(filename);
2408 return grid;
2409}
2410
2419inline TasmanianSparseGrid readGrid(std::string const &filename){ return readGrid(filename.c_str()); }
2420
2432inline TasmanianSparseGrid copyGrid(TasmanianSparseGrid const &source, int outputs_begin = 0, int outputs_end = -1){
2434 grid.copyGrid(source, outputs_begin, outputs_end);
2435 return grid;
2436}
2437
2445
2450enum class NumDimensions : int {};
2451
2456enum class NumOutputs : int {};
2457
2462enum class DepthLevel : int {};
2463
2468enum class BasisOrder : int {};
2469
2475
2499 AnsitropicWeights(std::initializer_list<int> list) : weights(list) {}
2501 explicit AnsitropicWeights(std::vector<int> const &w) : weights(w) {}
2503 std::vector<int> weights;
2504};
2505
2514 AlphaValue() = default;
2516 explicit AlphaValue(double a) : alpha(a) {}
2518 double alpha = 0;
2519};
2520
2529 BetaValue() = default;
2531 explicit BetaValue(double b) : beta(b) {}
2533 double beta = 0;
2534};
2535
2544 explicit CustomRuleFilename(std::string_view str) : name(str) {}
2546 const char *cname() const { return name.c_str(); }
2548 std::string name;
2549};
2550
2556
2565 LevelLimits() = default;
2569 LevelLimits(std::initializer_list<int> list) : limits(list) {}
2571 explicit LevelLimits(std::vector<int> const &ll) : limits(ll) {}
2573 std::vector<int> limits;
2574};
2575
2598 AnsitropicWeights const &anisotropic_weights = IsotropicWeights{},
2599 AlphaValue alpha = AlphaValue{}, BetaValue beta = BetaValue{},
2600 CustomRuleFilename const &custom_filename = CustomRuleFilename{},
2601 LevelLimits const &level_limits = NoLevelLimits{}){
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);
2604 return grid;
2605}
2606
2626 AnsitropicWeights const &anisotropic_weights = IsotropicWeights{},
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);
2630 return grid;
2631}
2632
2651 BasisOrder order = BasisOrder{1}, TypeOneDRule rule = rule_localp,
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);
2655 return grid;
2656}
2657
2675 BasisOrder order = BasisOrder{1},
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);
2679 return grid;
2680}
2681
2699 AnsitropicWeights const &anisotropic_weights = IsotropicWeights{},
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);
2703 return grid;
2704}
2705
2706}
2707
2708#endif
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