42#include "error_handlers.h"
47#include <cvode/cvode.h>
49#include <nvector/nvector_serial.h>
50#include <sunmatrix/sunmatrix_dense.h>
51#include <sunlinsol/sunlinsol_dense.h>
53#include <sundials/sundials_types.h>
54#include <sundials/sundials_context.h>
55#include <sundials/sundials_dense.h>
82 PCSet(
const string sp_type,
const int order,
const int n_dim,
const string pc_type,
83 const double alpha=0.0,
const double betta=1.0);
95 PCSet(
const string sp_type,
const int order,
const int n_dim,
const string pc_type,
const string pc_seq,
96 const double alpha=0.0,
const double betta=1.0);
105 PCSet(
const string sp_type,
const Array1D<int>& maxOrders,
const int n_dim,
const string pc_type,
106 const double alpha=0.0,
const double betta=1.0);
115 PCSet(
const string sp_type,
const Array2D<int>& customMultiIndex,
const string pc_type,
116 const double alpha=0.0,
const double betta=1.0);
161 void SetQuadRule(
const string grid_type,
const string fs_type,
int param);
276 void InitMeanStDv(
const double& m,
const double& s,
double* p)
const;
289 void Copy(
double* p1,
const double* p2)
const;
299 void Add(
const double* p1,
const double* p2,
double* p3)
const;
308 void AddInPlace(
double* p1,
const double* p2)
const;
317 void Multiply(
const double* p1,
const double& a,
double* p2)
const;
335 void Subtract(
const double* p1,
const double* p2,
double* p3)
const;
353 void Prod(
const double* p1,
const double* p2,
double* p3)
const;
362 void Prod3(
const double* p1,
const double* p2,
const double* p3,
double* p4)
const;
374 void Polyn(
const double* polycf,
int npoly,
const double* p1,
double* p2)
const;
409 void Exp(
const double* p1,
double* p2)
const;
420 void Log(
const double* p1,
double* p2)
const;
431 void Log10(
const double* p1,
double* p2)
const;
443 void RPow(
const double* p1,
double* p2,
const double& a)
const;
452 void IPow(
const double* p1,
double* p2,
const int& ia)
const;
462 void Inv(
const double* p1,
double* p2)
const;
481 void Div(
const double* p1,
const double* p2,
double* p3)
const;
491 double StDv(
const double* p)
const;
516 void Derivative(
const double* p1,
double* p2)
const;
528 void GetTripleProd(
int *nTriple,
int *iProd,
int *jProd,
double *Cijk)
const;
534 void GetQuadProd(
int *nQuad,
int *iProd,
int *jProd,
int *kProd,
double *Cijkl)
const;
557 void DrawSampleSet(
const double* p,
double* samples,
const int& nSamples);
562 void DrawSampleVar(
double *samples,
const int &nS,
const int &nD)
const;
584 double EvalPC(
const double* p,
const double* randVarSamples);
693 void EvalNormSq(
double* normsq,
const int npc);
750 int* ia,
int* ja,
double* a,
int* obj) {
752 OMap_t::iterator it =
omap_->find(*obj);
753 if(it ==
omap_->end()) {
754 string err_message = (string)
"GMRESMatrixVectorProdWrapper():"
755 +
" the callback object is not a valid entry in the map";
756 throw Tantrum(err_message);
759 it->second->GMRESMatrixVectorProd(x, a, y);
773 int* ia,
int* ja,
double* a,
int* obj,
774 double* rwork,
int* iwork) { };
795 void LogTaylor(
const double* p1,
double* p2)
const;
799 void LogInt(
const double* p1,
double* p2)
const;
807 double indxobj = ((
double*) f_data)[0] ;
809 OMap_t::iterator it =
omap_->find((
int) indxobj);
811 if (it ==
omap_->end())
813 string err_message = (string)
"LogIntRhsWrapper():"
814 +
" the callback object is not a valid entry in the map";
815 throw Tantrum(err_message);
819 it->second->LogIntRhs(t,y,ydot,f_data);
826 int LogIntRhs(sunrealtype t, N_Vector y, N_Vector ydot,
void *f_data)
const;
950 int Check_CVflag(
void *flagvalue,
const char *funcname,
int opt)
const;
1D Array class for any type T
2D Array class for any type T
LogCompMethod
Definition PCSet.h:67
@ TaylorSeries
Definition PCSet.h:67
@ Integration
Definition PCSet.h:67
Stores data of any type T in a 1D array.
Definition Array1D.h:61
Stores data of any type T in a 2D array.
Definition Array2D.h:60
Contains all basis type specific definitions and operations needed to generate a PCSet.
Definition PCBasis.h:47
Defines and initializes PC basis function set and provides functions to manipulate PC expansions defi...
Definition PCSet.h:73
Array2D< double > quadPoints_
Array to store quadrature points.
Definition PCSet.h:887
Array1D< int > maxOrders_
Array of maximum orders requested if custom(HDMR) ordering is requested.
Definition PCSet.h:851
void GetPsi(Array2D< double > &psi) const
Get the values of the basis polynomials evaluated at the quadrature points.
Definition PCSet.h:229
int nQuadPoints_
Number of quadrature points used.
Definition PCSet.h:860
void GalerkProjection(const Array1D< double > &fcn, Array1D< double > &ck)
Galerkin projection functionalities.
Definition PCSet.cpp:2584
void EvalNormSq(Array1D< double > &normsq)
Evaluate norms-squared of all bases and return in the array normsq.
Definition PCSet.cpp:2962
Array2D< double > psi_
Array to store basis functions evaluated at quadrature points for each order: psi_(iqp,...
Definition PCSet.h:880
void Prod(const double *p1, const double *p2, double *p3) const
Multiply two PC expansions given by double* arguments p1 and p2, and return the result in p3.
Definition PCSet.cpp:1083
Array1D< Array1D< double > > psiIJKProd2_
<\Psi_i \Psi_j \Psi_k> terms that are not zero, for all k
Definition PCSet.h:910
void SetGMRESDivTolerance(const double &rTol)
Set the relative tolerance for GMRES in Div routine.
Definition PCSet.h:263
double rTolGMRESDiv_
GMRES tolerance in Div()
Definition PCSet.h:875
string GetPCType() const
Get and set variables/arrays inline.
Definition PCSet.h:182
void GetQuadWeights(Array1D< double > &wghts) const
Get the quadrature weights.
Definition PCSet.h:222
void AddInPlace(double *p1, const double *p2) const
Add PC expansions given by double* argument p2 to p1 and return the result in p1.
Definition PCSet.cpp:947
void GetNormSq(Array1D< double > &normsq) const
Get the norm-squared.
Definition PCSet.h:198
double GetGMRESDivTolerance() const
Get relative tolerance for GMRES in Div routine.
Definition PCSet.h:260
bool IsInDomain(double x)
Check if the point x is in the PC domain.
Definition PCSet.cpp:3019
void Polyn(const double *polycf, int npoly, const double *p1, double *p2) const
Evaluates a polynomial of PC that is given in double* argument p1. Polynomial coefficients are given ...
Definition PCSet.cpp:1172
void EvalPCAtCustPoints(Array1D< double > &xch, Array2D< double > &custPoints, Array1D< double > &p)
Evaluate the given PC expansion at given set of points with given coefficient vector and return the v...
Definition PCSet.cpp:2453
void Prod3(const double *p1, const double *p2, const double *p3, double *p4) const
Multiply three PC expansions given by double* arguments p1, p2, and p3, and return the result in p4.
Definition PCSet.cpp:1127
void SeedBasisRandNumGen(const int &seed) const
Random sample generator functions.
Definition PCSet.cpp:2319
void GalerkProjectionMC(const Array2D< double > &x, const Array1D< double > &fcn, Array1D< double > &ck)
Galerkin Projection via Monte-Carlo integration.
Definition PCSet.cpp:2635
void GetPsiSq(double *psisq) const
Get the basis polynomial norms-squared in a double* array psisq.
Definition PCSet.h:239
void PolynMulti(const Array1D< double > &polycf, const Array2D< int > &mindex, const Array2D< double > &p1, Array1D< double > &p2) const
Evaluates a multivariate polynomial of a set of PC inputs given by Array2D argument p1 (each column o...
Definition PCSet.cpp:1210
void EvalNormSqExact(Array1D< double > &normsq)
Evaluate norms-squared analytically of all bases and return in the array normsq.
Definition PCSet.cpp:2999
void IPow(const double *p1, double *p2, const int &ia) const
Evaluate power ia (an integer number) of PC expansion given by double* argument p1,...
Definition PCSet.cpp:1547
double GetModesRMS(const double *p) const
Compute the rms average of the PC coefficients (i.e. the square root of the average of the square of ...
Definition PCSet.cpp:1910
PCSet()
Dummy default constructor, which should not be used as it is not well defined Therefore we make it pr...
Definition PCSet.h:709
double SMALL_
Tolerance to avoid floating-point errors.
Definition PCSet.h:872
double rTolTaylor_
Relative tolerance for Taylor series approximations.
Definition PCSet.h:866
double GetBeta() const
Get the value of the parameter beta.
Definition PCSet.h:188
double ComputeVarFrac(const double *coef, double *varfrac)
Compute the variance fractions of each basis term given coefficients in double *coef; returns the var...
Definition PCSet.cpp:2832
std::map< int, PCSet * > OMap_t
Definition of a map to connect integer indexes with pointers to this class.
Definition PCSet.h:964
void EvalBasisProd3()
Evaluate the expectation of product of three basis functions.
Definition PCSet.cpp:450
void GetMultiIndex(Array2D< int > &mindex) const
Get the multiindex (return Array2D)
Definition PCSet.h:191
int narg_
Number of free parameters to specify the basis.
Definition PCSet.h:956
double CVinitstep_
CVODE parameter: initial step size.
Definition PCSet.h:938
int Check_CVflag(void *flagvalue, const char *funcname, int opt) const
Check cvode return for errors.
Definition PCSet.cpp:2287
void SetQd1d(Array1D< double > &qdpts1d, Array1D< double > &wghts1d, int nqd)
Set the quadrature rule.
Definition PCSet.cpp:725
void Log(const double *p1, double *p2) const
Take the natural logarithm log() of the PC expansion given by double* argument p1,...
Definition PCSet.cpp:1427
void ComputeTotSens(Array1D< double > &coef, Array1D< double > &totsens)
Compute total effect sensitivity (Sobol) indices given coefficient array coeff; returns the indices i...
Definition PCSet.cpp:2911
Array1D< Array1D< int > > iProd2_
i-indices of <\Psi_i \Psi_j \Psi_k> terms that are not zero, for all k
Definition PCSet.h:902
Array1D< Array1D< int > > jProd3_
j-indices of <\Psi_i \Psi_j \Psi_k \Psi_l> terms that are not zero, for all l
Definition PCSet.h:918
void GetQuadProd(int *nQuad, int *iProd, int *jProd, int *kProd, double *Cijkl) const
Returns quad products indices (int*/double* version)
Definition PCSet.cpp:686
void GetQuadWeights(double *wghts) const
Get the quadrature weights folded into a one-dimensional array wghts.
Definition PCSet.h:225
void GetPsi(double *psi) const
Get the polynomials evaluated at the quadrature points folded into a one-dimensional array psi.
Definition PCSet.h:233
void Derivative(const double *p1, double *p2) const
Computes derivatives of univariate PC given by coefficients p1 returns coefficient vector of the deri...
Definition PCSet.cpp:2202
void SubtractInPlace(double *p1, const double *p2) const
Subtract PC expansion p2 from p1, and return the result in p1, with all arguments given as double*.
Definition PCSet.cpp:1057
static OMap_t * omap_
Map to connect integer indexes with pointers to this class.
Definition PCSet.h:968
Array1D< Array1D< int > > jProd2_
j-indices of <\Psi_i \Psi_j \Psi_k> terms that are not zero, for all k
Definition PCSet.h:906
Array1D< Array1D< int > > iProd3_
i-indices of <\Psi_i \Psi_j \Psi_k \Psi_l> terms that are not zero, for all l
Definition PCSet.h:914
void InitNISP()
Initialize variables that are needed only in non-intrusive computations.
Definition PCSet.cpp:420
void EvalBasisProd4()
Evaluate the expectation of product of four basis functions.
Definition PCSet.cpp:580
void Subtract(const double *p1, const double *p2, double *p3) const
Subtract PC expansion p2 from p1, and return the result in p3, with all arguments given as double*.
Definition PCSet.cpp:1027
int order_
Order of the PC representation.
Definition PCSet.h:845
void Div(const double *p1, const double *p2, double *p3) const
Divide the PC expansion p1 by p2, and return the result in p3 (All arguments in double* format)
Definition PCSet.cpp:1695
int GetNQuadPoints() const
Get the number of quadrature points.
Definition PCSet.h:210
void PrintMultiIndexNormSquared() const
For all terms, print their multi-index and norm^2 on the screen.
Definition PCSet.cpp:805
double beta_
Parameter beta for PCs that require two parameters (SW,JB)
Definition PCSet.h:961
Array1D< int > maxOrdPerDim_
Array of maximum orders per dimension.
Definition PCSet.h:854
void Exp(const double *p1, double *p2) const
Take the exp() of the PC expansion given by double* argument p1, and return the result in p2.
Definition PCSet.cpp:1299
int ComputeEffDims(int *effdim)
Computes the effective dimensionality of each basis term, i.e., the number of dimensions that enter w...
Definition PCSet.cpp:2711
Array1D< double > psiSq_
Array with the norms squared of the basis functions, corresponding to each term in the PC expansion.
Definition PCSet.h:884
void SetVerbosity(int verbosity)
Other.
Definition PCSet.h:688
void PrintMultiIndex() const
Print information on the screen.
Definition PCSet.cpp:778
void Log10(const double *p1, double *p2) const
Take the logarithm to base 10 of the PC expansion given by double* argument p1, and return the result...
Definition PCSet.cpp:1468
Array2D< int > quadIndices_
Array to store quadrature point indexing; useful for nested rules.
Definition PCSet.h:893
double CVmaxstep_
CVODE parameter: maximal step size.
Definition PCSet.h:941
int GetOrder() const
Get the PC order.
Definition PCSet.h:207
double EvalPC(const Array1D< double > &p, Array1D< double > &randVarSamples)
PC evaluation functionalities.
Definition PCSet.cpp:2409
void GetPsiSq(Array1D< double > &psisq) const
Get the basis polynomial norms-squared in an array class object psisq.
Definition PCSet.h:236
void Initialize(const string ordertype)
Initialization of the appropriate variables.
Definition PCSet.cpp:165
int nPCTerms_
Total number of terms in the PC expansions.
Definition PCSet.h:863
string pcType_
String indicator of PC type.
Definition PCSet.h:836
int GetNumTripleProd() const
Returns number of triple products.
Definition PCSet.cpp:536
void ComputeMaxOrdPerDim()
Compute maximal order per dimension and fill in the array maxOrdPerDim_.
Definition PCSet.cpp:151
void MultiplyInPlace(double *p1, const double &a) const
Multiply PC expansions given by double* argument p1 with scalar a and return the result in p1.
Definition PCSet.cpp:1002
double GetTaylorTolerance() const
Get relative tolerance for Taylor series approximations.
Definition PCSet.h:242
void EvalBasisAtCustPts(const Array2D< double > &custPoints, Array2D< double > &psi)
Evaluate Basis Functions at given points custPoints and return in the array psi.
Definition PCSet.cpp:2491
void dPhi(Array1D< double > &x, Array2D< int > &mindex, Array1D< double > &grad, Array1D< double > &ck)
Evaluate Gradient at a single d-dim point.
Definition PCSet.cpp:266
void ComputeJointSens(Array1D< double > &coef, Array2D< double > &jointsens)
Compute joint effect sensitivity (Sobol) indices given coefficient array coeff; returns the indices i...
Definition PCSet.cpp:2934
void GetTripleProd(int *nTriple, int *iProd, int *jProd, double *Cijk) const
Returns triple products indices (int*/double* version)
Definition PCSet.cpp:544
void SetQuadRule(const string grid_type, const string fs_type, int param)
Set the quadrature points by specifying a grid type, a full/sparse indicator, and an integer paramete...
Definition PCSet.cpp:742
int ComputeOrders(Array1D< int > &orders)
Multiindex parsing functionalities.
Definition PCSet.cpp:2689
double ComputeMean(const double *coef)
Moment/sensitivity extraction given coefficients.
Definition PCSet.cpp:2794
void LogInt(const double *p1, double *p2) const
Computes natural logarithm by numerical integration: calculate p2=ln(p1) by integrating du=dx/x to ge...
Definition PCSet.cpp:2044
Array1D< Array1D< int > > kProd3_
k-indices of <\Psi_i \Psi_j \Psi_k \Psi_l> terms that are not zero, for all l
Definition PCSet.h:922
void Inv(const double *p1, double *p2) const
Evaluate the inverse of PC expansion given by double* argument p1, and return the result in p2....
Definition PCSet.cpp:1646
int uqtkverbose_
Verbosity level.
Definition PCSet.h:830
int my_index_
Index of this class.
Definition PCSet.h:953
PCSet(const PCSet &obj)
Dummy copy constructor, which should not be used as it is currently not well defined....
Definition PCSet.h:717
void GMRESMatrixVectorProd(const double *x, const double *a, double *y) const
Actual C++ implementation of the matric vector multiplication for GMRES for the division operation.
Definition PCSet.cpp:1687
void GetQuadPointsWeights(Array2D< double > &quad, Array1D< double > &wghts) const
Get the quadrature points and weights.
Definition PCSet.h:216
void ddPhi_alpha(Array1D< double > &x, Array1D< int > &alpha, Array2D< double > &grad)
Evaluate Hessian at a single d-dim point and d-dim basis polynomial.
Definition PCSet.cpp:319
void Add(const double *p1, const double *p2, double *p3) const
Add two PC expansions given by double* arguments p1 and p2, and return the result in p3.
Definition PCSet.cpp:917
static int LogIntRhsWrapper(sunrealtype t, N_Vector y, N_Vector ydot, void *f_data)
Wrapper for LogIntRhs. The first component of f_data pointer carries an integer handle identifying th...
Definition PCSet.h:805
double StDv(const double *p) const
Returns the standard deviation of PC expansion p in a double* format.
Definition PCSet.cpp:1873
int CVmaxnumsteps_
CVODE parameter: maximal number of steps.
Definition PCSet.h:935
PCBasis * p_basis_
Pointer to the class that defines the basis type and functions.
Definition PCSet.h:842
void Copy(double *p1, const double *p2) const
Copy PC expansion p2 into p1 (i.e. p1 = p2).
Definition PCSet.cpp:888
Array1D< double > quadWeights_
Array to store quadrature weights.
Definition PCSet.h:890
int maxTermTaylor_
Max number of terms in Taylor series approximations.
Definition PCSet.h:869
void ComputeMainSens(Array1D< double > &coef, Array1D< double > &mainsens)
Compute main effect sensitivity (Sobol) indices given coefficient array coef; returns the indices in ...
Definition PCSet.cpp:2882
void DrawSampleSet(const Array1D< double > &p, Array1D< double > &samples)
Draw a set of samples from the PC expansion p, and return the result in the array samples....
Definition PCSet.cpp:2327
~PCSet()
Destructor: cleans up all memory and destroys object.
Definition PCSet.cpp:127
int GetTaylorTermsMax() const
Get maximum number of terms in Taylor series approximations.
Definition PCSet.h:248
void dPhi_alpha(Array1D< double > &x, Array1D< int > &alpha, Array1D< double > &grad)
Set Gradient and Hessian operators.
Definition PCSet.cpp:244
void RPow(const double *p1, double *p2, const double &a) const
Evaluate power a (a real number) of PC expansion given by double* argument p1, and return the result ...
Definition PCSet.cpp:1505
double GetAlpha() const
Get the value of the parameter alpha.
Definition PCSet.h:185
string pcSeq_
String indicator of multiindex ordering.
Definition PCSet.h:839
void Multiply(const double *p1, const double &a, double *p2) const
Multiply PC expansion p1 with scalar a and return the result in p2. All PCEs are in double* format.
Definition PCSet.cpp:973
Array1D< Array1D< double > > psiIJKLProd3_
<\Psi_i \Psi_j \Psi_k \Psi_l> terms that are not zero, for all l
Definition PCSet.h:926
LogCompMethod logMethod_
Flag for method to compute log: TaylorSeries or Integration.
Definition PCSet.h:929
void EncodeMindex(Array1D< Array2D< int > > &sp_mindex)
Encode multiIndex into a 'sparse' format where the bases are ordered by their effective dimensionalit...
Definition PCSet.cpp:2745
void LogTaylor(const double *p1, double *p2) const
Computes natural logarithm using Taylor expansion: N p2 = ln(p1) = ln(p1Mean) + sum d n=1 n.
Definition PCSet.cpp:1936
const int nDim_
Number of stochastic dimensions (degrees of freedom) in the PC representation.
Definition PCSet.h:857
static void GMRESPreCondWrapper(int *n, double *r, double *z, int *nelt, int *ia, int *ja, double *a, int *obj, double *rwork, int *iwork)
Wrapper for preconditioner routine to be called by GMRES.
Definition PCSet.h:772
double CVrelt_
CVODE parameter: relative tolerance.
Definition PCSet.h:944
void SetLogCompMethod(const LogCompMethod &logMethod)
Set method of computing the log function.
Definition PCSet.h:257
void DrawSampleVar(Array2D< double > &samples) const
Draw a set of samples of the underlying germ random variable.
Definition PCSet.cpp:2360
int LogIntRhs(sunrealtype t, N_Vector y, N_Vector ydot, void *f_data) const
Evaluates rhs necessary to compute natural logarithm via integration.
Definition PCSet.cpp:2176
static void GMRESMatrixVectorProdWrapper(int *n, double *x, double *y, int *nelt, int *ia, int *ja, double *a, int *obj)
Wrapper for Matrix-vector multiplication routine to be called by GMRES.
Definition PCSet.h:749
void SetTaylorTolerance(const double &rTol)
Set relative tolerance for Taylor series approximations.
Definition PCSet.h:245
double alpha_
Parameter alpha for PCs that require a parameter (LG,SW,JB)
Definition PCSet.h:959
double CVabst_
CVODE parameter: absolute tolerance.
Definition PCSet.h:947
void ddPhi(Array1D< double > &x, Array2D< int > &mindex, Array2D< double > &grad, Array1D< double > &ck)
Evaluate Gradient at a single d-dim point.
Definition PCSet.cpp:358
int CVmaxord_
CVODE parameter: maximal order.
Definition PCSet.h:932
void SetTaylorTermsMax(const int &maxTerm)
Set maximum number of terms in Taylor series approximations.
Definition PCSet.h:251
string spType_
String indicator of ISP or NISP implementation type.
Definition PCSet.h:833
int GetNumberPCTerms() const
Get the number of terms in a PC expansion of this order and dimension.
Definition PCSet.h:201
static int next_index_
index of next object in map
Definition PCSet.h:966
void GetQuadPoints(double *quad) const
Get the quadrature points folded into a one-dimensional array quad.
Definition PCSet.h:219
int GetNDim() const
Get the PC dimensionality.
Definition PCSet.h:204
int maxorddim_
Maximal order within all dimensions.
Definition PCSet.h:848
void InitMeanStDv(const double &m, const double &s, double *p) const
Intrusive arithmetics.
Definition PCSet.cpp:833
void InitISP()
Initialize quadrature for computing triple products(ISP) and orthogonal projection(NISP)
Definition PCSet.cpp:394
Array2D< int > multiIndex_
Array to store multi-index: multiIndex_(ipc,idim) contains the order of the basis function associated...
Definition PCSet.h:898
void GetQuadPoints(Array2D< double > &quad) const
Get the quadrature points.
Definition PCSet.h:213
int GetNumQuadProd() const
Returns number of quad products.
Definition PCSet.cpp:677
Generates quadrature rules.
Definition quad.h:54
Header file for the quadrature class.