1 /* _______________________________________________________________________
2
3 DAKOTA: Design Analysis Kit for Optimization and Terascale Applications
4 Copyright 2014-2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
5 This software is distributed under the GNU Lesser General Public License.
6 For more information, see the README file in the top Dakota directory.
7 _______________________________________________________________________ */
8
9 //- Class: global_defs
10 //- Description: Encapsulates global objects and functions.
11 //-
12 //- Owner: Mike Eldred
13 //- Version: $Id: global_defs.h 6492 2009-12-19 00:04:28Z briadam $
14
15 #ifndef DAKOTA_GLOBAL_DEFS_H
16 #define DAKOTA_GLOBAL_DEFS_H
17
18 #include "dakota_system_defs.hpp"
19 #include <stdexcept>
20
21 namespace Dakota {
22
23 // --------------
24 // Special values
25 // --------------
26 /// special value returned by index() when entry not found
27 const size_t _NPOS = ~(size_t)0; // one's complement
28 /// bound beyond which constraints are considered inactive
29 const double BIG_REAL_BOUND = 1.0e+30;
30 /// constant pi
31 extern double PI;
32 /// constant log(2*pi)/2.0
33 extern double HALF_LOG_2PI;
34
35 // --------------
36 // Global objects
37 // --------------
38
39 // define Cout/Cerr, use them to dereference dakota_cout/dakota_cerr
40 #define Cout (*Dakota::dakota_cout)
41 #define Cerr (*Dakota::dakota_cerr)
42
43 // externs
44 // Note: Dakota class externs are declared elsewhere in order to maintain a
45 // clear hierarchy of dependencies.
46 //extern PRPCache data_pairs;
47 //extern ParallelLibrary dummy_lib;
48
49 /// enum for Dakota abort reasons; using negative numbers to
50 /// distinguish Dakota exit states from signals / uncaught signals.
51 /// These need to be in range [-63, -1], so exit code (256+enum) is in
52 /// [193, 255]. See RATIONALE in dakota_global_defs.cpp.
53 enum {
54 VARS_ERROR = -10, // error with Variables
55 RESP_ERROR = -9, // error with Response
56 APPROX_ERROR = -8, // error with Approximation
57 METHOD_ERROR = -7, // error with Iterator/MetaIterator
58 MODEL_ERROR = -6, // error within Model
59 IO_ERROR = -5, // error with core file I/O
60 INTERFACE_ERROR = -4, // error with map invocation (user workflow/driver):
61 // analysis driver, if/of
62 CONSTRUCT_ERROR = -3,
63 PARSE_ERROR = -2,
64 OTHER_ERROR = -1 // the historical Dakota default error
65 };
66
67 /// enum for selecting the models that store evaluations
68 enum {
69 MODEL_EVAL_STORE_TOP_METHOD = 0,
70 MODEL_EVAL_STORE_NONE,
71 MODEL_EVAL_STORE_ALL,
72 MODEL_EVAL_STORE_ALL_METHODS};
73
74 /// enum for selecting the interfaces that store evaluations
75 enum {
76 INTERF_EVAL_STORE_SIMULATION = 0,
77 INTERF_EVAL_STORE_NONE,
78 INTERF_EVAL_STORE_ALL};
79
80
81 /// enum for dakota abort behaviors
82 enum {ABORT_EXITS, ABORT_THROWS};
83
84 /// enum for active subspace cross validation identification
85 enum {CV_ID_DEFAULT = 0, MINIMUM_METRIC, RELATIVE_TOLERANCE, DECREASE_TOLERANCE};
86
87 /// whether dakota exits/aborts or throws on errors
88 extern short abort_mode;
89
90 /// throw or exit depending on abort_mode
91 void abort_throw_or_exit(int dakota_code);
92
93
94 /// base class for Dakota file read exceptions (to allow catching both
95 /// tabular and general file truncation issues)
96 class FileReadException: public std::runtime_error
97 {
98 public:
FileReadException(const std::string & msg)99 FileReadException(const std::string& msg): std::runtime_error(msg)
100 { /* empty ctor */ }
101 };
102
103 /// exception thrown when data read truncated
104 class TabularDataTruncated: public FileReadException
105 {
106 public:
TabularDataTruncated(const std::string & msg)107 TabularDataTruncated(const std::string& msg): FileReadException(msg)
108 { /* empty ctor */ }
109 };
110
111 /// exception throw for other results file read error
112 class ResultsFileError: public FileReadException
113 {
114 public:
ResultsFileError(const std::string & msg)115 ResultsFileError(const std::string& msg): FileReadException(msg)
116 { /* empty ctor */ }
117 };
118
119
120 /// exception class for function evaluation failures
121 class FunctionEvalFailure: public std::runtime_error
122 {
123 public:
FunctionEvalFailure(const std::string & msg)124 FunctionEvalFailure(const std::string& msg): std::runtime_error(msg)
125 { /* empty ctor */ }
126 };
127
128
129
130 extern std::ostream* dakota_cout;
131 extern std::ostream* dakota_cerr;
132 extern int write_precision;
133
134 /// options for tabular columns
135 enum { TABULAR_NONE = 0, TABULAR_HEADER = 1,
136 TABULAR_EVAL_ID = 2, TABULAR_IFACE_ID = 4,
137 // experiment data annotated has header and exp_id
138 TABULAR_EXPER_ANNOT = TABULAR_HEADER | TABULAR_EVAL_ID,
139 // default for tabular files is fully annotated as of Dakota 6.1
140 TABULAR_ANNOTATED = TABULAR_HEADER | TABULAR_EVAL_ID | TABULAR_IFACE_ID };
141
142 /// Results output format
143 enum { RESULTS_OUTPUT_TEXT = 1, RESULTS_OUTPUT_HDF5 = 2};
144
145 /// options for results file format
146 enum {FLEXIBLE_RESULTS, LABELED_RESULTS};
147
148 /// define special values for surrogateExportFormats
149 enum { NO_MODEL_FORMAT=0, TEXT_ARCHIVE=1, BINARY_ARCHIVE=2, ALGEBRAIC_FILE=4,
150 ALGEBRAIC_CONSOLE=8 };
151
152
153 #ifdef DAKOTA_MODELCENTER
154 extern int mc_ptr_int;
155 extern int dc_ptr_int;
156 #endif // DAKOTA_MODELCENTER
157
158 /// Dummy struct for overloading letter-envelope constructors.
159 /** BaseConstructor is used to overload the constructor for the base class
160 portion of letter objects. It avoids infinite recursion (Coplien p.139)
161 in the letter-envelope idiom by preventing the letter from instantiating
162 another envelope. Putting this struct here avoids circular dependencies. */
163 struct BaseConstructor {
BaseConstructorDakota::BaseConstructor164 BaseConstructor(int = 0) {} ///< C++ structs can have constructors
165 };
166
167 /// Dummy struct for overloading constructors used in on-the-fly
168 /// instantiations without ProblemDescDB support.
169 /** NoDBBaseConstructor is used to overload the constructor used for
170 on-the-fly instantiations in which ProblemDescDB queries cannot be
171 used. Putting this struct here avoids circular dependencies. */
172 struct NoDBBaseConstructor {
NoDBBaseConstructorDakota::NoDBBaseConstructor173 NoDBBaseConstructor(int = 0) {} ///< C++ structs can have constructors
174 };
175
176 /// Dummy struct for overloading constructors used in on-the-fly Model
177 /// instantiations.
178 /** LightWtBaseConstructor is used to overload the constructor used for
179 on-the-fly Model instantiations. Putting this struct here avoids
180 circular dependencies. */
181 struct LightWtBaseConstructor {
LightWtBaseConstructorDakota::LightWtBaseConstructor182 LightWtBaseConstructor(int = 0) {} ///< C++ structs can have constructors
183 };
184
185 // ----------------
186 // Global functions
187 // ----------------
188
189 /// global function which handles serial or parallel aborts
190 void abort_handler(int code);
191
192 /** Templatized abort_handler_t method that allows for convenient return from
193 methods that otherwise have no sensible return from error clauses. Usage:
194 MyType& method() { return abort_handler<MyType&>(-1); } */
195 template <typename T>
abort_handler_t(int code)196 T abort_handler_t(int code)
197 {
198 abort_handler(code);
199 throw code;
200 }
201
202 /// Global function to register signal handlers at top-level
203 void register_signal_handlers();
204
205 /// Global function to hold Dakota processes to help with MPI debugging.
206 void mpi_debug_hold();
207
208 } // namespace Dakota
209
210 /// Return type for EvaluationStore::model_allocate and interface_allocate
211 /// UNITIALIZED: Model constructor has this as its default
212 /// ACTIVE: The database is open and this model or interface should write to it
213 /// INACTIVE: The database is either closed, or this model or interface should not
214 /// write to it.
215 enum class EvaluationsDBState {UNINITIALIZED, ACTIVE, INACTIVE};
216
217 #endif // DAKOTA_GLOBAL_DEFS_H
218