Doxygen 1.9.8
Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN: Tasmanian v8.2
 
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
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
68namespace TasGrid{
69
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;
333 void read(const char *filename); // auto-check if format is binary or ascii
334
336 void write(std::ostream &ofs, bool binary = mode_binary) const;
338 void read(std::istream &ifs, bool binary = mode_binary);
339
341 void write(std::string const& fname, bool binary = mode_binary) const{ write(fname.c_str(), binary); }
343 void read(std::string const& fname){ read(fname.c_str()); }
344
391 void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
392 std::vector<int> const &anisotropic_weights, double alpha = 0.0, double beta = 0.0,
393 const char* custom_filename = nullptr, std::vector<int> const &level_limits = std::vector<int>());
401 void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
402 const int *anisotropic_weights = nullptr, double alpha = 0.0, double beta = 0.0,
403 const char* custom_filename = nullptr, const int *level_limits = nullptr);
409 void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, CustomTabulated &&crule,
410 std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
416 void makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, CustomTabulated &&crule,
417 const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
418
436 void makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
437 std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
445 void makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
446 const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
447
474 void makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order, TypeOneDRule rule, std::vector<int> const &level_limits);
482 void makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order = 1, TypeOneDRule rule = rule_localp, const int *level_limits = nullptr);
483
502 void makeWaveletGrid(int dimensions, int outputs, int depth, int order, std::vector<int> const &level_limits);
510 void makeWaveletGrid(int dimensions, int outputs, int depth, int order = 1, const int *level_limits = nullptr);
511
521 void makeFourierGrid(int dimensions, int outputs, int depth, TypeDepth type,
522 std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
530 void makeFourierGrid(int dimensions, int outputs, int depth, TypeDepth type, const int* anisotropic_weights = nullptr, const int* level_limits = nullptr);
531
548 void copyGrid(const TasmanianSparseGrid *source, int outputs_begin = 0, int outputs_end = -1);
555 void copyGrid(TasmanianSparseGrid const &source, int outputs_begin = 0, int outputs_end = -1){ copyGrid(&source, outputs_begin, outputs_end); }
556
571 void updateGlobalGrid(int depth, TypeDepth type, std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
577 void updateGlobalGrid(int depth, TypeDepth type, const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
578
592 void updateSequenceGrid(int depth, TypeDepth type, std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
598 void updateSequenceGrid(int depth, TypeDepth type, const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
599
613 void updateFourierGrid(int depth, TypeDepth type, std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
619 void updateFourierGrid(int depth, TypeDepth type, const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
625 void updateGrid(int depth, TypeDepth type, std::vector<int> const &anisotropic_weights, std::vector<int> const &level_limits = std::vector<int>());
631 void updateGrid(int depth, TypeDepth type, const int *anisotropic_weights = nullptr, const int *level_limits = nullptr);
632
634 double getAlpha() const{ return (isGlobal()) ? get<GridGlobal>()->getAlpha() : 0.0; }
636 double getBeta() const{ return (isGlobal()) ? get<GridGlobal>()->getBeta() : 0.0; }
638 int getOrder() const{ return (isLocalPolynomial()) ? get<GridLocalPolynomial>()->getOrder() : ((isWavelet()) ? get<GridWavelet>()->getOrder() : -1); }
639
640
642 int getNumDimensions() const{ return (base) ? base->getNumDimensions() : 0; }
644 int getNumOutputs() const{ return (base) ? base->getNumOutputs() : 0; }
654 const char* getCustomRuleDescription() const; // used only for Global Grids with rule_customtabulated
655
657 int getNumLoaded() const{ return (base) ? base->getNumLoaded() : 0; }
659 int getNumNeeded() const{ return (base) ? base->getNumNeeded() : 0; }
661 int getNumPoints() const{ return (base) ? base->getNumPoints() : 0; }
662
671 std::vector<double> getLoadedPoints() const{ std::vector<double> x; getLoadedPoints(x); return x; }
678 void getLoadedPoints(std::vector<double> &x) const{ x.resize(Utils::size_mult(getNumDimensions(), getNumLoaded())); getLoadedPoints(x.data()); }
685 void getLoadedPoints(double x[]) const;
686
695 std::vector<double> getNeededPoints() const{ std::vector<double> x; getNeededPoints(x); return x; }
702 void getNeededPoints(std::vector<double> &x) const{ x.resize(Utils::size_mult(getNumDimensions(), getNumNeeded())); getNeededPoints(x.data()); }
709 void getNeededPoints(double *x) const;
710
724 std::vector<double> getPoints() const{ std::vector<double> x; getPoints(x); return x; }
730 void getPoints(std::vector<double> &x) const{ x.resize(Utils::size_mult(getNumDimensions(), getNumPoints())); getPoints(x.data()); }
736 void getPoints(double x[]) const; // returns the loaded points unless no points are loaded, then returns the needed points
737
747 std::vector<double> getQuadratureWeights() const{ std::vector<double> w; getQuadratureWeights(w); return w; }
753 void getQuadratureWeights(std::vector<double> &weights) const{ weights.resize((size_t) getNumPoints()); getQuadratureWeights(weights.data()); }
759 void getQuadratureWeights(double weights[]) const; // static memory, assumes that weights has size getNumPoints()
760
788 std::vector<double> getInterpolationWeights(std::vector<double> const &x) const;
795 std::vector<double> getInterpolationWeights(double const x[]) const{ std::vector<double> w((size_t) getNumPoints()); getInterpolationWeights(x, w.data()); return w; }
802 void getInterpolationWeights(const std::vector<double> &x, std::vector<double> &weights) const;
809 void getInterpolationWeights(const double x[], double weights[]) const;
810
828 std::vector<double> getDifferentiationWeights(std::vector<double> const &x) const;
835 std::vector<double> getDifferentiationWeights(double const x[]) const {
836 std::vector<double> w((size_t) getNumPoints() * (size_t) getNumDimensions());
837 getDifferentiationWeights(x, w.data());
838 return w;
839 }
846 void getDifferentiationWeights(const std::vector<double> &x, std::vector<double> &weights) const;
854 void getDifferentiationWeights(const double x[], double weights[]) const;
855
874 void loadNeededValues(std::vector<double> const &vals); // checks if vals has size num_outputs X getNumNeeded()
880 void loadNeededValues(const double *vals);
884 void loadNeededPoints(std::vector<double> const &vals) {loadNeededValues(vals);}
890 void loadNeededPoints(const double *vals) {loadNeededValues(vals);}
899 const double* getLoadedValues() const{ return (empty()) ? nullptr : base->getLoadedValues(); }
900
917 void evaluate(std::vector<double> const &x, std::vector<double> &y) const;
924 void evaluate(const double x[], double y[]) const;
957 template<typename FloatType> void evaluateBatch(std::vector<FloatType> const &x, std::vector<FloatType> &y) const;
981 void evaluateBatch(const double x[], int num_x, double y[]) const;
994 void evaluateBatch(const float x[], int num_x, float y[]) const;
1007 template<typename FloatType> void evaluateBatchGPU(const FloatType gpu_x[], int cpu_num_x, FloatType gpu_y[]) const;
1021 template<typename FloatType> void evaluateFast(const FloatType x[], FloatType y[]) const{ evaluateBatch(x, 1, y); }
1027 template<typename FloatType> void evaluateFast(std::vector<FloatType> const &x, std::vector<FloatType> &y) const{ evaluateBatch(x, y); }
1041 void integrate(std::vector<double> &q) const;
1049 void integrate(double q[]) const;
1053 std::vector<double> integrate() const{
1054 std::vector<double> result;
1055 integrate(result);
1056 return result;
1057 }
1064 void differentiate(std::vector<double> const &x, std::vector<double> &jacobian) const;
1068 std::vector<double> differentiate(std::vector<double> const &x) const{
1069 std::vector<double> jacobian;
1070 differentiate(x, jacobian);
1071 return jacobian;
1072 }
1078 void differentiate(const double x[], double jacobian[]) const;
1079
1081 bool isGlobal() const{ return base && base->isGlobal(); }
1083 bool isSequence() const{ return base && base->isSequence(); }
1085 bool isLocalPolynomial() const{ return base && base->isLocalPolynomial(); }
1087 bool isWavelet() const{ return base && base->isWavelet(); }
1089 bool isFourier() const{ return base && base->isFourier(); }
1091 bool isEmpty() const{ return !base; }
1093 bool empty() const{ return !base; }
1094
1122 void setDomainTransform(std::vector<double> const &a, std::vector<double> const &b);
1129 void setDomainTransform(const double a[], const double b[]);
1153 void getDomainTransform(std::vector<double> &a, std::vector<double> &b) const;
1164 void getDomainTransform(double a[], double b[]) const;
1165
1185 void setConformalTransformASIN(std::vector<int> const &truncation);
1191 std::vector<int> getConformalTransformASIN() const;
1192
1200 void clearLevelLimits(){ llimits.clear(); }
1207 std::vector<int> getLevelLimits() const{ return llimits; }
1208
1237 void setAnisotropicRefinement(TypeDepth type, int min_growth, int output, const std::vector<int> &level_limits);
1244 void setAnisotropicRefinement(TypeDepth type, int min_growth, int output, const int *level_limits = nullptr);
1248 std::vector<double> getAnisotropicRefinement(TypeDepth type, int min_growth, int output, const std::vector<int> &level_limits) {
1249 setAnisotropicRefinement(type, min_growth, output, level_limits);
1250 return getNeededPoints();
1251 }
1252
1272 std::vector<int> estimateAnisotropicCoefficients(TypeDepth type, int output) const{ std::vector<int> w; estimateAnisotropicCoefficients(type, output, w); return w; }
1279 void estimateAnisotropicCoefficients(TypeDepth type, int output, std::vector<int> &weights) const;
1280
1301 void setSurplusRefinement(double tolerance, int output, std::vector<int> const &level_limits);
1303 void setSurplusRefinement(double tolerance, int output, const int *level_limits = nullptr);
1307 std::vector<double> getSurplusRefinement(double tolerance, int output, std::vector<int> const &level_limits) {
1308 setSurplusRefinement(tolerance, output, level_limits);
1309 return getNeededPoints();
1310 }
1311
1348 void setSurplusRefinement(double tolerance, TypeRefinement criteria, int output,
1349 std::vector<int> const &level_limits, std::vector<double> const &scale_correction = std::vector<double>()); // -1 indicates using all outputs
1357 void setSurplusRefinement(double tolerance, TypeRefinement criteria, int output = -1, const int *level_limits = nullptr, const double *scale_correction = nullptr);
1361 std::vector<double> getSurplusRefinement(double tolerance, TypeRefinement criteria, int output, std::vector<int> const &level_limits,
1362 std::vector<double> const &scale_correction = std::vector<double>()) {
1363 setSurplusRefinement(tolerance, criteria, output, level_limits, scale_correction);
1364 return getNeededPoints();
1365 }
1366
1383 void mergeRefinement(); // merges all points but resets all loaded values to 0.0
1384
1403 bool isUsingConstruction() const{ return using_dynamic_construction; }
1435 std::vector<double> getCandidateConstructionPoints(TypeDepth type, std::vector<int> const &anisotropic_weights = std::vector<int>(),
1436 std::vector<int> const &level_limits = std::vector<int>());
1460 std::vector<double> getCandidateConstructionPoints(TypeDepth type, int output, std::vector<int> const &level_limits = std::vector<int>());
1461
1470 std::vector<double> getCandidateConstructionPoints(double tolerance, TypeRefinement criteria, int output = -1,
1471 std::vector<int> const &level_limits = std::vector<int>(),
1472 std::vector<double> const &scale_correction = std::vector<double>());
1493 void loadConstructedPoints(std::vector<double> const &x, std::vector<double> const &y);
1499 void loadConstructedPoints(const double x[], int numx, const double y[]);
1515
1535 const double* getHierarchicalCoefficients() const;
1536
1542 void getHierarchicalCoefficientsStatic(double *coeff) const{
1544 + ((isFourier()) ? 2 : 1) * getNumOutputs() * getNumLoaded(), coeff);
1545 }
1546
1563 void setHierarchicalCoefficients(const std::vector<double> &c);
1569 void setHierarchicalCoefficients(const double c[]){ base->setHierarchicalCoefficients(c); }
1570
1597 void evaluateHierarchicalFunctions(std::vector<double> const &x, std::vector<double> &y) const;
1603 std::vector<double> evaluateHierarchicalFunctions(std::vector<double> const &x) const{
1604 std::vector<double> y;
1606 return y;
1607 }
1625 void evaluateHierarchicalFunctions(const double x[], int num_x, double y[]) const;
1626
1647 void evaluateSparseHierarchicalFunctions(const std::vector<double> &x, std::vector<int> &pntr, std::vector<int> &indx, std::vector<double> &vals) const;
1648
1666 std::vector<double> getHierarchicalSupport() const;
1667
1684 std::vector<double> integrateHierarchicalFunctions() const{
1685 std::vector<double> integrals;
1687 return integrals;
1688 }
1695 void integrateHierarchicalFunctions(std::vector<double> &integrals) const{
1696 integrals.resize(getNumPoints());
1697 integrateHierarchicalFunctions(integrals.data());
1698 }
1707 void integrateHierarchicalFunctions(double integrals[]) const;
1708
1726 std::vector<int> getGlobalPolynomialSpace(bool interpolation) const;
1727
1737 void printStats(std::ostream &os = std::cout) const;
1738
1760 void enableAcceleration(TypeAcceleration acc, int new_gpu_id);
1779 void favorSparseAcceleration(bool favor);
1787 void setCuBlasHandle(void *handle);
1795 void setCuSparseHandle(void *handle);
1803 void setCuSolverHandle(void *handle);
1811 void setRocBlasHandle(void *handle);
1819 void setRocSparseHandle(void *handle);
1827 void setSycleQueue(void *queue);
1834 TypeAcceleration getAccelerationType() const{ return acceleration->mode; }
1843
1854 void setGPUID(int new_gpu_id);
1860 int getGPUID() const{ return acceleration->device; }
1871 static int getNumGPUs(){ return AccelerationMeta::getNumGpuDevices(); }
1879 static int getGPUMemory(int gpu);
1888 static std::string getGPUName(int gpu);
1889
1908 template<typename FloatType>
1909 void evaluateHierarchicalFunctionsGPU(const FloatType gpu_x[], int cpu_num_x, FloatType gpu_y[]) const;
1934 template<typename FloatType>
1935 void evaluateSparseHierarchicalFunctionsGPU(const FloatType gpu_x[], int cpu_num_x, int* &gpu_pntr, int* &gpu_indx, FloatType* &gpu_vals, int &num_nz) const;
1936
1938 using EvaluateCallable = std::function<void(std::vector<double> const&, std::vector<double>&)>;
1939
1946 operator EvaluateCallable() const{
1947 return [&](std::vector<double> const &x, std::vector<double> &y)->void{ evaluateBatch(x, y); };
1948 }
1949
1951 using DomainInsideSignature = std::function<bool(std::vector<double> const &)>; // trick for Doxygen formatting purposes
1952
1960 auto rule = getRule();
1961 if ((rule == TasGrid::rule_gausshermite) || (rule == TasGrid::rule_gausshermiteodd)){ // unbounded domain
1962 return [](std::vector<double> const &)->bool{ return true; };
1963 }else if ((rule == TasGrid::rule_gausslaguerre) || (rule == TasGrid::rule_gausslaguerreodd)){ // bounded from below
1964 if (domain_transform_a.empty()){
1965 return [](std::vector<double> const &x)->bool{
1966 for(auto const &v : x) if (v < 0.0) return false;
1967 return true;
1968 };
1969 }else{
1970 size_t dims = (size_t) getNumDimensions();
1971 #if __cplusplus > 201103L
1972 return [dta=domain_transform_a, dims](std::vector<double> const &x)->bool{
1973 for(size_t i=0; i<dims; i++) if (x[i] < dta[i]) return false;
1974 return true;
1975 };
1976 #else
1977 return [=](std::vector<double> const &x)->bool{
1978 for(size_t i=0; i<dims; i++) if (x[i] < domain_transform_a[i]) return false;
1979 return true;
1980 };
1981 #endif
1982 }
1983 }else{
1984 if (domain_transform_a.empty()){
1985 if (isFourier()){
1986 return [](std::vector<double> const &x)->bool{
1987 for(auto const &v : x) if ((v < 0.0) || (v > 1.0)) return false;
1988 return true;
1989 };
1990 }else{
1991 return [](std::vector<double> const &x)->bool{
1992 for(auto const &v : x) if ((v < -1.0) || (v > 1.0)) return false;
1993 return true;
1994 };
1995 }
1996 }else{
1997 size_t dims = (size_t) getNumDimensions();
1998 #if __cplusplus > 201103L
1999 return [dta=domain_transform_a, dtb=domain_transform_b, dims](std::vector<double> const &x)->bool{
2000 for(size_t i=0; i<dims; i++)
2001 if (x[i] < dta[i] or x[i] > dtb[i]) return false;
2002 return true;
2003 };
2004 #else
2005 return [=](std::vector<double> const &x)->bool{
2006 for(size_t i=0; i<dims; i++)
2007 if (x[i] < domain_transform_a[i] or x[i] > domain_transform_b[i]) return false;
2008 return true;
2009 };
2010 #endif
2011 }
2012 }
2013 }
2014
2031 void removePointsByHierarchicalCoefficient(double tolerance, int output = -1, const double *scale_correction = nullptr);
2044 void removePointsByHierarchicalCoefficient(int num_new_points, int output = -1, const double *scale_correction = nullptr);
2045
2046 #ifndef __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2055 int evaluateSparseHierarchicalFunctionsGetNZ(const double x[], int num_x) const;
2063 void evaluateSparseHierarchicalFunctionsStatic(const double x[], int num_x, int pntr[], int indx[], double vals[]) const;
2071 const int* getPointsIndexes() const;
2079 const int* getNeededIndexes() const;
2080
2088 template<class T> inline T* get(){ return dynamic_cast<T*>(base.get()); }
2096 template<class T> inline T const* get() const{ return dynamic_cast<T const*>(base.get()); }
2103 AccelerationContext const* getAccelerationContext() const{ return acceleration.get(); }
2104 #endif // __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2105
2106protected:
2107 #ifndef __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2115 void clear();
2116
2125 void mapCanonicalToTransformed(int num_dimensions, int num_points, TypeOneDRule rule, double x[]) const;
2133 template<typename FloatType> void mapTransformedToCanonical(int num_dimensions, int num_points, TypeOneDRule rule, FloatType x[]) const;
2141 double getQuadratureScale(int num_dimensions, TypeOneDRule rule) const;
2142
2151 void mapConformalCanonicalToTransformed(int num_dimensions, int num_points, double x[]) const;
2159 template<typename FloatType> void mapConformalTransformedToCanonical(int num_dimensions, int num_points, Data2D<FloatType> &x) const;
2167 void mapConformalWeights(int num_dimensions, int num_points, double weights[]) const;
2168
2179 template<typename FloatType> const FloatType* formCanonicalPoints(const FloatType *x, Data2D<FloatType> &x_temp, int num_x) const;
2188 template<typename T>
2189 const T* formCanonicalPointsGPU(const T *gpu_x, int num_x, GpuVector<T> &gpu_x_temp) const;
2198 template<typename FloatType> std::vector<double> diffCanonicalTransform() const;
2207 void formTransformedPoints(int num_points, double x[]) const; // when calling get***Points()
2208
2216 void writeAscii(std::ostream &ofs) const;
2225 void readAscii(std::istream &ifs);
2233 void writeBinary(std::ostream &ofs) const;
2242 void readBinary(std::istream &ifs);
2243 #endif // __TASMANIAN_DOXYGEN_SKIP_INTERNAL
2244
2245private:
2246 std::unique_ptr<AccelerationContext> acceleration; // must be destroyed last for sycl
2247
2248 std::unique_ptr<BaseCanonicalGrid> base;
2249
2250 std::vector<double> domain_transform_a, domain_transform_b;
2251 std::vector<int> conformal_asin_power;
2252 std::vector<int> llimits;
2253
2254 bool using_dynamic_construction;
2255
2256 mutable std::unique_ptr<AccelerationDomainTransform> acc_domain;
2257};
2258
2271
2286inline TasmanianSparseGrid
2287makeGlobalGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
2288 std::vector<int> const &anisotropic_weights = std::vector<int>(), double alpha = 0.0, double beta = 0.0,
2289 const char* custom_filename = nullptr, std::vector<int> const &level_limits = std::vector<int>()){
2291 grid.makeGlobalGrid(dimensions, outputs, depth, type, rule, anisotropic_weights, alpha, beta, custom_filename, level_limits);
2292 return grid;
2293}
2294
2301inline TasmanianSparseGrid
2302makeSequenceGrid(int dimensions, int outputs, int depth, TypeDepth type, TypeOneDRule rule,
2303 std::vector<int> const &anisotropic_weights = std::vector<int>(), std::vector<int> const &level_limits = std::vector<int>()){
2305 grid.makeSequenceGrid(dimensions, outputs, depth, type, rule, anisotropic_weights, level_limits);
2306 return grid;
2307}
2308
2315inline TasmanianSparseGrid
2316makeLocalPolynomialGrid(int dimensions, int outputs, int depth, int order = 1, TypeOneDRule rule = rule_localp, std::vector<int> const &level_limits = std::vector<int>()){
2318 grid.makeLocalPolynomialGrid(dimensions, outputs, depth, order, rule, level_limits);
2319 return grid;
2320}
2321
2328inline TasmanianSparseGrid
2329makeWaveletGrid(int dimensions, int outputs, int depth, int order = 1, std::vector<int> const &level_limits = std::vector<int>()){
2331 grid.makeWaveletGrid(dimensions, outputs, depth, order, level_limits);
2332 return grid;
2333}
2334
2341inline TasmanianSparseGrid
2342makeFourierGrid(int dimensions, int outputs, int depth, TypeDepth type,
2343 std::vector<int> const &anisotropic_weights = std::vector<int>(), std::vector<int> const &level_limits = std::vector<int>()){
2345 grid.makeFourierGrid(dimensions, outputs, depth, type, anisotropic_weights, level_limits);
2346 return grid;
2347}
2348
2357inline TasmanianSparseGrid readGrid(const char *filename){
2359 grid.read(filename);
2360 return grid;
2361}
2362
2369inline TasmanianSparseGrid readGrid(std::string const &filename){ return readGrid(filename.c_str()); }
2370
2382inline TasmanianSparseGrid copyGrid(TasmanianSparseGrid const &source, int outputs_begin = 0, int outputs_end = -1){
2384 grid.copyGrid(source, outputs_begin, outputs_end);
2385 return grid;
2386}
2387
2388}
2389
2390#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:1081
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:1272
int getGPUID() const
Returns the currently set CUDA device.
Definition TasmanianSparseGrid.hpp:1860
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:695
int getNumPoints() const
Returns getNumLoaded() if positive, otherwise returns getNumNeeded(), see getPoints().
Definition TasmanianSparseGrid.hpp:661
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:678
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:644
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.
Definition TasmanianSparseGrid.hpp:899
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:636
void getNeededPoints(std::vector< double > &x) const
Overload that accepts the vector as a parameter.
Definition TasmanianSparseGrid.hpp:702
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:1021
std::vector< int > getLevelLimits() const
Return the currently set level limits.
Definition TasmanianSparseGrid.hpp:1207
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.
Definition TasmanianSparseGrid.hpp:1569
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:747
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:1248
void getQuadratureWeights(std::vector< double > &weights) const
Overload that accepts the vector as a parameter.
Definition TasmanianSparseGrid.hpp:753
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:341
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:730
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:1695
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:1053
int getNumNeeded() const
Return the number of points that should be provided to the next call of loadNeededValues().
Definition TasmanianSparseGrid.hpp:659
void read(std::string const &fname)
Overload that works directly with std::string.
Definition TasmanianSparseGrid.hpp:343
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:1361
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:724
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:1834
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:1200
int getNumLoaded() const
Return the number of points already associated with model values via loadNeededValues().
Definition TasmanianSparseGrid.hpp:657
void evaluateFast(std::vector< FloatType > const &x, std::vector< FloatType > &y) const
Alias to evaluateBatch().
Definition TasmanianSparseGrid.hpp:1027
std::function< void(std::vector< double > const &, std::vector< double > &)> EvaluateCallable
Signature compatible with TasDREAM::DreamPDF, TasDREAM::DreamModel amd TasDREAM::DreamMergedLikelyMod...
Definition TasmanianSparseGrid.hpp:1938
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:1068
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:1871
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:1307
bool isSequence() const
Returns true if the grid is of type sequence, false otherwise.
Definition TasmanianSparseGrid.hpp:1083
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:1089
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:1684
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:890
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:835
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:555
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:795
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:634
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:1959
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:1403
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:1093
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:884
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:671
std::function< bool(std::vector< double > const &)> DomainInsideSignature
Signature of the domain inside lambda, identical to TasDREAM::DreamDomain.
Definition TasmanianSparseGrid.hpp:1951
int getNumDimensions() const
Return the dimensions of the grid, i.e., number of model inputs.
Definition TasmanianSparseGrid.hpp:642
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:1085
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:1091
bool isWavelet() const
Returns true if the grid is of type wavelet, false otherwise.
Definition TasmanianSparseGrid.hpp:1087
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:1603
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:638
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:285
TypeAcceleration
Modes of acceleration.
Definition tsgEnumerates.hpp:551
TypeDepth
Used by Global Sequence and Fourier grids, indicates the selection criteria.
Definition tsgEnumerates.hpp:203
TypeRefinement
Refinement strategy for local polynomial and wavelet grids.
Definition tsgEnumerates.hpp:425
@ rule_gausshermite
Non-nested rule optimized for integral of the form .
Definition tsgEnumerates.hpp:355
@ rule_gausslaguerreodd
Same as rule_gausslaguerre but using only odd levels, partially mitigates the non-nested issues.
Definition tsgEnumerates.hpp:353
@ rule_localp
Nested rule with a hierarchy of uniformly distributed nodes and functions with compact support.
Definition tsgEnumerates.hpp:362
@ rule_gausslaguerre
Non-nested rule optimized for integral of the form .
Definition tsgEnumerates.hpp:351
@ rule_gausshermiteodd
Same as rule_gausshermite but using only odd levels, partially mitigates the non-nested issues.
Definition tsgEnumerates.hpp:357
TasmanianSparseGrid makeEmpty()
Returns an empty sparse grid.
Definition TasmanianSparseGrid.hpp:2270
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:2329
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:2302
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:2287
TasmanianSparseGrid readGrid(const char *filename)
Factory method, creates a new grid and calls TasmanianSparseGrid::read().
Definition TasmanianSparseGrid.hpp:2357
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:2342
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:2316
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:2382
Encapsulates the Tasmanian Sparse Grid module.
Definition TasmanianSparseGrid.hpp:68