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: NIDRProblemDescDB
10 //- Description: Problem description database populated by new IDR parser
11 //- Owner: David M. Gay
12
13 #ifndef NIDR_PROBLEM_DESC_DB_H
14 #define NIDR_PROBLEM_DESC_DB_H
15
16 #include "ProblemDescDB.hpp"
17 #include <external/nidr/nidr.h>
18
19 namespace Dakota {
20
21 class ParallelLibrary;
22
23 /// The derived input file database utilizing the new IDR parser.
24
25 /** The NIDRProblemDescDB class is derived from ProblemDescDB for use
26 by the NIDR parser in processing DAKOTA input file data.
27 For information on modifying the NIDR input parsing procedures,
28 refer to Dakota/docs/Dev_Spec_Change.dox. For more on the parsing
29 technology, see "Specifying and Reading Program Input with NIDR"
30 by David M. Gay (report SAND2008-2261P, which is available in PDF
31 form as http://dakota.sandia.gov/papers/nidr08.pdf). Source for the
32 routines declared herein is NIDRProblemDescDB.cpp, in which most
33 routines are so short that a description seems unnecessary. */
34
35 class NIDRProblemDescDB: public ProblemDescDB
36 {
37 public:
38
39 //
40 //- Heading: Constructors and Destructor
41 //
42
43 /// constructor
44 NIDRProblemDescDB(ParallelLibrary& parallel_lib);
45 /// destructor
46 ~NIDRProblemDescDB();
47
48 //
49 //- Heading: Member methods
50 //
51
52 /// parses the input file and populates the problem description
53 /// database using NIDR.
54 void derived_parse_inputs(const std::string& dakota_input_file,
55 const std::string& dakota_input_string,
56 const std::string& parser_options);
57 /// perform any data processing that must be coordinated with DB buffer
58 /// broadcasting (performed prior to broadcasting the DB buffer on rank 0
59 /// and after receiving the DB buffer on other processor ranks)
60 void derived_broadcast();
61 /// perform any additional data post-processing
62 void derived_post_process();
63
64 //
65 //- Heading: Data
66 //
67
68 /// Pointer to the active object instance used within the static
69 /// kwhandler functions in order to avoid the need for static data.
70 /// Only initialized when parsing an input file; will be NULL for
71 /// cases of direct DB population only.
72 static NIDRProblemDescDB* pDDBInstance;
73
74 private:
75
76 /// List of Var_Info pointers, one per Variables instance
77 std::list<void*> VIL;
78
79 /// check a single variables node; input argument v is Var_Info*
80 static void check_variables_node(void* v);
81
82 /// tokenize and try to validate the presence of an analysis driver,
83 /// potentially included in the linked or copied template files
84 static int check_driver(const String& an_driver,
85 const StringArray& link_files,
86 const StringArray& copy_files);
87
88 public:
89
90 /// number of parse error encountered
91 static int nerr;
92 /// print and error message and immediately abort
93 static void botch(const char *fmt, ...);
94 /// check each node in a list of DataVariables, first mapping
95 /// DataVariables members back to flat NIDR arrays if needed.
96 static void check_variables(std::list<DataVariables>*);
97 static void check_responses(std::list<DataResponses>*);
98 /// Validate format user-supplied descriptors
99 static void check_descriptor_format(const StringArray &labels);
100 /// Ensure no response descriptors are repeated
101 static void check_descriptors_for_repeats(const StringArray &labels);
102 /// Ensure no variable descriptors are repeated
103 static void check_descriptors_for_repeats(
104 const StringArray &cd_labels,
105 const StringArray &ddr_labels,
106 const StringArray &ddsi_labels,
107 const StringArray &ddss_labels,
108 const StringArray &ddsr_labels,
109 const StringArray &cs_labels,
110 const StringArray &dsr_labels,
111 const StringArray &dssi_labels,
112 const StringArray &dsss_labels,
113 const StringArray &dssr_labels,
114 const StringArray &cau_labels,
115 const StringArray &diau_labels,
116 const StringArray &dsau_labels,
117 const StringArray &drau_labels,
118 const StringArray &ceu_labels,
119 const StringArray &dieu_labels,
120 const StringArray &dseu_labels,
121 const StringArray &dreu_labels);
122 /// Bounds and initial point check and inferred bounds generation
123 static void make_variable_defaults(std::list<DataVariables>*);
124 static void make_response_defaults(std::list<DataResponses>*);
125 /// print an error message and increment nerr, but continue
126 static void squawk(const char *fmt, ...);
127 /// print a warning
128 static void warn(const char *fmt, ...);
129
130 //
131 //- Heading: Keyword handlers called by nidr
132 //
133
134 // Suppress Doxygen warnings for these known undocumented macros
135 // (would probably have to enable preprocessor in Doxygen)
136 /// /cond
137
138 #define KWH(x) static void x(const char *keyname, Values *val, void **g, void *v)
139
140 KWH(iface_Real);
141 KWH(iface_Rlit);
142 KWH(iface_false);
143 KWH(iface_ilit);
144 KWH(iface_int);
145 KWH(iface_lit);
146 KWH(iface_start);
147 KWH(iface_stop);
148 KWH(iface_str);
149 KWH(iface_str2D);
150 KWH(iface_strL);
151 KWH(iface_true);
152 KWH(iface_type);
153
154 KWH(method_Ii);
155 KWH(method_Real);
156 KWH(method_Real01);
157 KWH(method_RealDL);
158 KWH(method_RealLlit);
159 KWH(method_Realp);
160 KWH(method_Realz);
161 KWH(method_Ri);
162 KWH(method_false);
163 KWH(method_szarray);
164 KWH(method_ilit2);
165 KWH(method_ilit2p);
166 KWH(method_int);
167 KWH(method_ivec);
168 KWH(method_lit);
169 KWH(method_litc);
170 KWH(method_liti);
171 KWH(method_litp);
172 KWH(method_litr);
173 KWH(method_litz);
174 KWH(method_order);
175 KWH(method_num_resplevs);
176 KWH(method_piecewise);
177 KWH(method_resplevs);
178 KWH(method_resplevs01);
179 KWH(method_shint);
180 KWH(method_sizet);
181 KWH(method_slit2);
182 KWH(method_start);
183 KWH(method_stop);
184 KWH(method_str);
185 KWH(method_strL);
186 KWH(method_true);
187 KWH(method_tr_final);
188 KWH(method_type);
189 KWH(method_usharray);
190 KWH(method_ushint);
191 KWH(method_utype);
192 KWH(method_augment_utype);
193 KWH(method_utype_lit);
194
195 KWH(model_Real);
196 KWH(model_RealDL);
197 KWH(model_ivec);
198 KWH(model_false);
199 KWH(model_int);
200 KWH(model_intsetm1);
201 KWH(model_lit);
202 KWH(model_order);
203 KWH(model_shint);
204 KWH(model_sizet);
205 KWH(model_start);
206 KWH(model_stop);
207 KWH(model_str);
208 KWH(model_strL);
209 KWH(model_true);
210 KWH(model_type);
211 KWH(model_usharray);
212 KWH(model_ushint);
213 KWH(model_utype);
214 KWH(model_augment_utype);
215
216 KWH(resp_RealDL);
217 KWH(resp_RealL);
218 KWH(resp_false);
219 KWH(resp_intset);
220 KWH(resp_ivec);
221 KWH(resp_lit);
222 KWH(resp_sizet);
223 KWH(resp_start);
224 KWH(resp_stop);
225 KWH(resp_str);
226 KWH(resp_strL);
227 KWH(resp_true);
228 KWH(resp_utype);
229 KWH(resp_augment_utype);
230
231 //KWH(env_Real);
232 //KWH(env_RealL);
233 KWH(env_int);
234 //KWH(env_lit);
235 KWH(env_start);
236 KWH(env_str);
237 KWH(env_strL);
238 KWH(env_true);
239 KWH(env_utype);
240 KWH(env_augment_utype);
241
242 KWH(var_RealLb);
243 KWH(var_RealUb);
244 KWH(var_IntLb);
245 KWH(var_categorical);
246 KWH(var_caulbl);
247 KWH(var_dauilbl);
248 KWH(var_dauslbl);
249 KWH(var_daurlbl);
250 KWH(var_ceulbl);
251 KWH(var_deuilbl);
252 KWH(var_deuslbl);
253 KWH(var_deurlbl);
254 KWH(var_sizet);
255 KWH(var_start);
256 KWH(var_stop);
257 KWH(var_str);
258 KWH(var_strL);
259 KWH(var_true);
260 KWH(var_newiarray);
261 KWH(var_newsarray);
262 KWH(var_newivec);
263 KWH(var_newrvec);
264 KWH(var_ivec);
265 KWH(var_svec);
266 KWH(var_rvec);
267 KWH(var_type);
268
269 #undef KWH
270
271 // Suppress Doxygen warnings for these known undocumented macros
272 // (would probably have to enable preprocessor in Doxygen)
273 /// /endcond
274 };
275
276
277 /// Free convenience function that flatten sizes of an array of std
278 /// containers; takes an array of containers and returns an IntArray
279 /// containing the sizes of each container in the input array. Note:
280 /// Did not specialize for vector<RealVector> as no current use cases.
281 template <class ContainerT>
282 inline void
flatten_num_array(const std::vector<ContainerT> & input_array,IntArray ** pia)283 flatten_num_array(const std::vector<ContainerT>& input_array, IntArray** pia)
284 {
285 size_t input_len = input_array.size();
286 IntArray *ia;
287
288 *pia = ia = new IntArray(input_len);
289 for(size_t i = 0; i < input_len; ++i)
290 (*ia)[i] = input_array[i].size();
291 }
292
293
294 } // namespace Dakota
295
296 #endif
297