Doxygen 1.9.1
Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN: Tasmanian v8.1
Static Load Model Values
Collaboration diagram for Static Load Model Values:

Functions

template<bool parallel_construction = true, bool overwrite_loaded = false>
void TasGrid::loadNeededValues (std::function< void(double const x[], double y[], size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads)
 Loads the current grid with model values, does not perform any refinement. More...
 
template<bool parallel_construction = true, bool overwrite_loaded = false>
void TasGrid::loadNeededValues (std::function< void(std::vector< double > const &x, std::vector< double > &y, size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads)
 Overload that uses vectors for the model inputs and outputs. More...
 
template<bool parallel_construction = true, bool overwrite_loaded = false>
void TasGrid::loadNeededPoints (std::function< void(double const x[], double y[], size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads)
 Alias to loadNeededValues(), array variant.
 
template<bool parallel_construction = true, bool overwrite_loaded = false>
void TasGrid::loadNeededPoints (std::function< void(std::vector< double > const &x, std::vector< double > &y, size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads)
 Alias to loadNeededValues(), vector variant.
 

Detailed Description

Handy templates to automate the common use case of evaluating a model at the needed (or loaded) points and feeding the values to the grid.

Function Documentation

◆ loadNeededValues() [1/2]

template<bool parallel_construction = true, bool overwrite_loaded = false>
void TasGrid::loadNeededValues ( std::function< void(double const x[], double y[], size_t thread_id)>  model,
TasmanianSparseGrid grid,
size_t  num_threads 
)

Loads the current grid with model values, does not perform any refinement.

Loads model values into the grid using the provided lambda function, the model can be computed either sequentially or in parallel. This is a non-adaptive procedure, i.e., the points will not be changes only the associated model values will be modified.

Template Parameters
parallel_constructiondefines whether to run in parallel or sequential mode.
overwrite_loadeddefines whether to overwrite the currently loaded model values or to assign values to the needed points.
Parameters
modelis the lambda representation of a model with inputs x and outputs y, the lambda must accept arrays with size equal to the grid dimensions and outputs. For each x, the y must be overwritten with the corresponding model values. If parallel sampling is uses, then thread_id will be a unique number between 0 and num_threads-1 associated with the running thread. The id can help associate each thread with additional external resources, e.g., a separate CUDA device can be associated with each thread.
gridis the sparse grid that will be loaded. The grid must not be set for construction and the number of inputs must be positive. The method grid.loadNeededValues() will be called with values corresponding to the model outputs at either the loaded or the needed points.
num_threadsis the number of parallel calls to the model lambda. If set to zero, sequential mode will be used without launching any threads, the number is ignored in sequential mode. Note that this is using the C++ native std::thread as opposed to OpenMP.
Exceptions
std::runtime_errorif grid.isUsingConstruction() is true or if grid.getNumOutputs() is zero.

Example:

// construct a grid for 10-th order global polynomials
// note that the grid is set to 4 inputs and 1 output, the model function should be the same
auto model = [](double const x[], double y[], size_t)->void{
y[0] = std::exp(x[0] + x[1] + x[2] + x[3]);
}
loadNeededValues(model, grid, 4); // using parallel sampling with 4 threads
// at this point, grid is a 10-th order polynomial approximation to exp(x0 + x2 + x3 + x4)
@ rule_leja
Classic sequence rule, moderate Lebesgue constant growth (empirical result only).
Definition: tsgEnumerates.hpp:299
@ type_iptotal
Total degree polynomial space for interpolation, i.e., the span of .
Definition: tsgEnumerates.hpp:221
void loadNeededValues(std::function< void(double const x[], double y[], size_t thread_id)> model, TasmanianSparseGrid &grid, size_t num_threads)
Loads the current grid with model values, does not perform any refinement.
Definition: tsgLoadNeededValues.hpp:104
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:2272

◆ loadNeededValues() [2/2]

template<bool parallel_construction = true, bool overwrite_loaded = false>
void TasGrid::loadNeededValues ( std::function< void(std::vector< double > const &x, std::vector< double > &y, size_t thread_id)>  model,
TasmanianSparseGrid grid,
size_t  num_threads 
)

Overload that uses vectors for the model inputs and outputs.

The template will accept the array inputs from the main implementation and copy those to the vectors. Thus, there is an extra copy of data, which is unavoidable since TasGrid::TasmanianSparseGrid returns contiguous vectors that cannot be split without copy.