1 /*  _______________________________________________________________________
2 
3     PECOS: Parallel Environment for Creation Of Stochastics
4     Copyright (c) 2011, Sandia National Laboratories.
5     This software is distributed under the GNU Lesser General Public License.
6     For more information, see the README file in the top Pecos directory.
7     _______________________________________________________________________ */
8 
9 #ifndef PECOS_GLOBAL_DEFS_H
10 #define PECOS_GLOBAL_DEFS_H
11 
12 #include <iostream>
13 #include <cfloat>  // for DBL_MIN, DBL_MAX
14 #include <cmath>
15 #include <cstdlib>
16 
17 #include <boost/math/constants/constants.hpp>
18 
19 namespace Pecos {
20 
21 // --------------
22 // Special values
23 // --------------
24 /// the value for PI used in various numerical routines
25 const double PI = boost::math::constants::pi<double>();
26 
27 /// special value returned by index() when entry not found
28 const size_t _NPOS = ~(size_t)0; // one's complement
29 
30 /// used in ostream data output functions
31 const int WRITE_PRECISION = 10;
32 
33 /// small value used for protecting division by zero, etc.; an alternative
34 /// to DBL_MIN that is less likely to cause underflow/overflow when numbers
35 /// larger than it are used in calculations
36 const double SMALL_NUMBER = 1.e-25;
37 /// large value used as a surrogate for infinity in error traps; an alternative
38 /// to DBL_MAX or inf that is less likely to cause underflow/overflow when used
39 /// in subsequent calculations
40 const double LARGE_NUMBER = 1.e+50;
41 
42 // define special values for vector/matrix data copying modes
43 enum { DEFAULT_COPY=0, SHALLOW_COPY, DEEP_COPY };
44 
45 // define special values for ExpansionConfigOptions::outputLevel
46 enum { SILENT_OUTPUT, QUIET_OUTPUT, NORMAL_OUTPUT, VERBOSE_OUTPUT,
47        DEBUG_OUTPUT };
48 
49 // define special values for multivariate distribution types
50 enum { NO_DIST=0, MARGINALS_CORRELATIONS, MULTIVARIATE_NORMAL, JOINT_KDE };
51      //GAUSSIAN_COPULA, ...
52 
53 // define special values for univariate RandomVariable types
54 enum { NO_TYPE=0,
55        // continuous + discrete design / state / other
56        CONTINUOUS_RANGE, DISCRETE_RANGE,
57        DISCRETE_SET_INT, DISCRETE_SET_STRING, DISCRETE_SET_REAL,
58        STOCHASTIC_EXPANSION,
59        // continuous + discrete aleatory
60        STD_NORMAL, NORMAL, BOUNDED_NORMAL, LOGNORMAL, BOUNDED_LOGNORMAL,
61        STD_UNIFORM, UNIFORM, LOGUNIFORM, TRIANGULAR, STD_EXPONENTIAL,
62        EXPONENTIAL, STD_BETA, BETA, STD_GAMMA, GAMMA, INV_GAMMA,
63        GUMBEL, FRECHET, WEIBULL, HISTOGRAM_BIN,
64        POISSON, BINOMIAL, NEGATIVE_BINOMIAL, GEOMETRIC, HYPERGEOMETRIC,
65        HISTOGRAM_PT_INT, HISTOGRAM_PT_STRING, HISTOGRAM_PT_REAL,
66        // continuous + discrete epistemic
67        // (Note: INTERVAL has multiple BPAs --> distinct from RANGE)
68        CONTINUOUS_INTERVAL_UNCERTAIN, DISCRETE_INTERVAL_UNCERTAIN,
69        DISCRETE_UNCERTAIN_SET_INT, DISCRETE_UNCERTAIN_SET_STRING,
70        DISCRETE_UNCERTAIN_SET_REAL };
71 
72 // define special values for secondaryACVarMapTargets/secondaryADVarMapTargets
73 enum { NO_TARGET=0,
74        CR_LWR_BND, CR_UPR_BND, DR_LWR_BND, DR_UPR_BND,
75        DSI_VALUES, DSS_VALUES, DSR_VALUES,
76        N_MEAN, N_STD_DEV, N_LWR_BND, N_UPR_BND, N_LOCATION, N_SCALE, N_VARIANCE,
77        LN_MEAN, LN_STD_DEV, LN_LAMBDA, LN_ZETA, LN_ERR_FACT,
78        LN_LWR_BND, LN_UPR_BND,
79        U_LWR_BND, U_UPR_BND, U_LOCATION, U_SCALE, LU_LWR_BND, LU_UPR_BND,
80        T_MODE, T_LWR_BND, T_UPR_BND, T_LOCATION, T_SCALE, E_BETA, E_SCALE,
81        BE_ALPHA, BE_BETA, BE_LWR_BND, BE_UPR_BND, JACOBI_ALPHA, JACOBI_BETA,
82        GA_ALPHA, GA_BETA, GA_SHAPE, GA_SCALE, GENLAG_ALPHA, IGA_ALPHA, IGA_BETA,
83        GU_ALPHA, GU_BETA, F_ALPHA, F_BETA, W_ALPHA, W_BETA, H_BIN_PAIRS,
84        P_LAMBDA, BI_P_PER_TRIAL, BI_TRIALS, NBI_P_PER_TRIAL, NBI_TRIALS,
85        GE_P_PER_TRIAL, HGE_TOT_POP, HGE_SEL_POP, HGE_DRAWN,
86        H_PT_INT_PAIRS, H_PT_STR_PAIRS, H_PT_REAL_PAIRS, CIU_BPA, DIU_BPA,
87        DUSI_VALUES_PROBS, DUSS_VALUES_PROBS, DUSR_VALUES_PROBS };
88 
89 /// derived basis approximation types
90 enum { NO_BASIS=0, //FOURIER_BASIS, EIGEN_BASIS,
91        GLOBAL_NODAL_INTERPOLATION_POLYNOMIAL,
92        PIECEWISE_NODAL_INTERPOLATION_POLYNOMIAL,
93        GLOBAL_HIERARCHICAL_INTERPOLATION_POLYNOMIAL,
94        PIECEWISE_HIERARCHICAL_INTERPOLATION_POLYNOMIAL,
95        GLOBAL_REGRESSION_ORTHOGONAL_POLYNOMIAL,
96        GLOBAL_PROJECTION_ORTHOGONAL_POLYNOMIAL,
97        GLOBAL_ORTHOGONAL_POLYNOMIAL };
98        //PIECEWISE_REGRESSION_ORTHOGONAL_POLYNOMIAL,
99        //PIECEWISE_PROJECTION_ORTHOGONAL_POLYNOMIAL,
100        //PIECEWISE_ORTHOGONAL_POLYNOMIAL };
101 
102 /// derived basis polynomial types (orthogonal polynomial order follows
103 /// uncertain variable spec order of normal, uniform, exponential, beta, gamma)
104 enum { NO_POLY=0, HERMITE_ORTHOG, LEGENDRE_ORTHOG, LAGUERRE_ORTHOG,
105        JACOBI_ORTHOG, GEN_LAGUERRE_ORTHOG, CHEBYSHEV_ORTHOG, NUM_GEN_ORTHOG,
106        LAGRANGE_INTERP, HERMITE_INTERP, PIECEWISE_LINEAR_INTERP,
107        PIECEWISE_QUADRATIC_INTERP, PIECEWISE_CUBIC_INTERP,
108        KRAWTCHOUK_DISCRETE, MEIXNER_DISCRETE, CHARLIER_DISCRETE,
109        HAHN_DISCRETE };
110 
111 /// integration rules within VPISparseGrid (1-12: CC through User-closed)
112 /// and beyond (GOLUB_WELSCH, NEWTON_COTES)
113 enum { NO_RULE=0, CLENSHAW_CURTIS, FEJER2, GAUSS_PATTERSON, GAUSS_LEGENDRE,
114        GAUSS_HERMITE, GEN_GAUSS_HERMITE, GAUSS_LAGUERRE, GEN_GAUSS_LAGUERRE,
115        GAUSS_JACOBI, GENZ_KEISTER, /*USER_OPEN, USER_CLOSED,*/ GOLUB_WELSCH,
116        NEWTON_COTES, GAUSS_KRAWTCHOUK, GAUSS_MEIXNER, GAUSS_CHARLIER,
117        GAUSS_HAHN };
118 
119 // growth rules within VPISparseGrid
120 //enum { DEFAULT_GROWTH=0, SLOW_LINEAR, SLOW_LINEAR_ODD, MODERATE_LINEAR,
121 //       SLOW_EXPONENTIAL, MODERATE_EXPONENTIAL, FULL_EXPONENTIAL };
122 
123 /// options for synchronizing linear and exponential growth rule settings
124 /// (consistent with slow/moderate/full growth for new level_to_growth_*
125 /// functions in sandia_rules.cpp)
126 enum { SLOW_RESTRICTED_GROWTH, MODERATE_RESTRICTED_GROWTH,
127        UNRESTRICTED_GROWTH };
128 
129 /// solution approaches for calculating the polynomial basis coefficients
130 /// (options for ExpansionConfigOptions::expCoeffsSolnApproach)
131 enum { QUADRATURE, CUBATURE, LIGHTWEIGHT_SPARSE_GRID, COMBINED_SPARSE_GRID,
132        INCREMENTAL_SPARSE_GRID, HIERARCHICAL_SPARSE_GRID, SAMPLING,
133        DEFAULT_REGRESSION, DEFAULT_LEAST_SQ_REGRESSION, SVD_LEAST_SQ_REGRESSION,
134        EQ_CON_LEAST_SQ_REGRESSION, BASIS_PURSUIT, BASIS_PURSUIT_DENOISING,
135        ORTHOG_MATCH_PURSUIT, LASSO_REGRESSION, LEAST_ANGLE_REGRESSION,
136        ORTHOG_LEAST_INTERPOLATION };
137 /// options for BasisConfigOptions::nestingOverride (inactive)
138 enum { NO_NESTING_OVERRIDE=0, NESTED, NON_NESTED };
139 /// options for overriding the default growth restriction policy
140 enum { NO_GROWTH_OVERRIDE=0, RESTRICTED, UNRESTRICTED };
141 /// options for ExpansionConfigOptions::refineType (inactive)
142 enum { NO_REFINEMENT=0, P_REFINEMENT, H_REFINEMENT };
143 /// options for ExpansionConfigOptions::refineControl
144 // Note: C3 augments UNIFORM_CONTROL with a c3AdvancementType;
145 //       could consider a similar breakout for DIMENSION_ADAPTIVE_CONTROL
146 enum { NO_CONTROL=0, UNIFORM_CONTROL, LOCAL_ADAPTIVE_CONTROL,
147        DIMENSION_ADAPTIVE_CONTROL_SOBOL, DIMENSION_ADAPTIVE_CONTROL_DECAY,
148        DIMENSION_ADAPTIVE_CONTROL_GENERALIZED };
149 /// options for ExpansionConfigOptions::refineMetric
150 enum { NO_METRIC=0, COVARIANCE_METRIC, LEVEL_STATS_METRIC, MIXED_STATS_METRIC };
151 /// options for ExpansionConfigOptions::refineStatsType
152 enum { NO_EXPANSION_STATS=0, DEFAULT_EXPANSION_STATS, ACTIVE_EXPANSION_STATS,
153        COMBINED_EXPANSION_STATS };
154 
155 /// options for expansion basis type
156 enum { DEFAULT_BASIS=0, TENSOR_PRODUCT_BASIS, TOTAL_ORDER_BASIS,
157        ADAPTED_BASIS_GENERALIZED, ADAPTED_BASIS_EXPANDING_FRONT,
158        NODAL_INTERPOLANT, HIERARCHICAL_INTERPOLANT };
159 
160 /// mode of integration driver: integration versus interpolation
161 enum { DEFAULT_MODE=0, INTEGRATION_MODE, INTERPOLATION_MODE };
162 
163 /// options for local basis functions within PiecewiseInterpPolynomial
164 enum { LINEAR_EQUIDISTANT, LINEAR, QUADRATIC_EQUIDISTANT, QUADRATIC,
165        CUBIC_EQUIDISTANT, CUBIC };
166 
167 /// special values for nodal interpolation of variance and variance gradient
168 enum { INTERPOLATION_OF_PRODUCTS, REINTERPOLATION_OF_PRODUCTS,
169        PRODUCT_OF_INTERPOLANTS_FAST, PRODUCT_OF_INTERPOLANTS_FULL };
170 
171 /// special values for polynomial expansion combination
172 enum { NO_COMBINE=0, ADD_COMBINE, MULT_COMBINE, ADD_MULT_COMBINE };
173 
174 /// special values for discrepancy emulation
175 enum { NO_DISCREP=0, DISTINCT_DISCREP, RECURSIVE_DISCREP };
176 
177 /// special values for filtering keyed SurrogateData maps
178 enum { NO_FILTER = 0, RAW_DATA_FILTER, SYNTHETIC_DATA_FILTER,
179        AGGREGATED_DATA_FILTER };
180 
181 // ----------------
182 // Standard streams
183 // ----------------
184 #define PCout std::cout
185 #define PCerr std::cerr
186 
187 
188 // --------------
189 // Global objects
190 // --------------
191 /// Dummy struct for overloading letter-envelope constructors.
192 /** BaseConstructor is used to overload the constructor for the base class
193     portion of letter objects.  It avoids infinite recursion (Coplien p.139)
194     in the letter-envelope idiom by preventing the letter from instantiating
195     another envelope.  Putting this struct here avoids circular dependencies. */
196 struct BaseConstructor {
BaseConstructorPecos::BaseConstructor197   BaseConstructor(int = 0) {} ///< C++ structs can have constructors
198 };
199 
200 
201 // ----------------
202 // Global functions
203 // ----------------
204 
205 /// global function which handles serial or parallel aborts
206 void abort_handler(int code);
207 
208 
abort_handler(int code)209 inline void abort_handler(int code)
210 { std::exit(code); } // for now, prior to use of MPI
211 
212 
213 /** Templatized abort_handler_t method that allows for convenient return from
214     methods that otherwise have no sensible return from error clauses.  Usage:
215     MyType& method() { return abort_handler<MyType&>(-1); } */
216 template <typename T>
abort_handler_t(int code)217 T abort_handler_t(int code)
218 {
219   abort_handler(code);
220   throw code;
221 }
222 
223 } // namespace Pecos
224 
225 #endif // PECOS_GLOBAL_DEFS_H
226