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:        ProblemDescDB
10 //- Description: Implementation code for the ProblemDescDB class.
11 //-              It provides storage for problem description database entries
12 //-              and defines the keyword handlers that yacc calls to populate
13 //-              the database based on the parsed input.
14 //- Owner:       Mike Eldred
15 //- Checked by:
16 
17 #include "dakota_system_defs.hpp"
18 #include "dakota_preproc_util.hpp"
19 #include "ProblemDescDB.hpp"
20 #include "ParallelLibrary.hpp"
21 #include "NIDRProblemDescDB.hpp"
22 #include "ProgramOptions.hpp"
23 #include "DakotaIterator.hpp"
24 #include "DakotaInterface.hpp"
25 #include "WorkdirHelper.hpp"  // bfs utils and prepend_preferred_env_path
26 #include <boost/bind.hpp>
27 #include <boost/function.hpp>
28 #include <string>
29 
30 //#define DEBUG
31 //#define MPI_DEBUG
32 
33 static const char rcsId[]="@(#) $Id: ProblemDescDB.cpp 7007 2010-10-06 15:54:39Z wjbohnh $";
34 
35 
36 namespace Dakota {
37 
38 extern ParallelLibrary dummy_lib; // defined in dakota_global_defs.cpp
39 extern ProblemDescDB *Dak_pddb;	  // defined in dakota_global_defs.cpp
40 
41 
42 /** This constructor is the one which must build the base class data for all
43     derived classes.  get_db() instantiates a derived class letter and the
44     derived constructor selects this base class constructor in its
45     initialization list (to avoid the recursion of the base class constructor
46     calling get_db() again).  Since the letter IS the representation, its
47     representation pointer is set to NULL. */
ProblemDescDB(BaseConstructor,ParallelLibrary & parallel_lib)48 ProblemDescDB::ProblemDescDB(BaseConstructor, ParallelLibrary& parallel_lib):
49   parallelLib(parallel_lib), environmentCntr(0), methodDBLocked(true),
50   modelDBLocked(true), variablesDBLocked(true), interfaceDBLocked(true),
51   responsesDBLocked(true)
52 { /* empty ctor */ }
53 
54 
55 /** The default constructor: dbRep is NULL in this case.  This makes
56     it necessary to check for NULL in the copy constructor, assignment
57     operator, and destructor. */
ProblemDescDB()58 ProblemDescDB::ProblemDescDB(): parallelLib(dummy_lib)
59 { /* empty ctor */ }
60 
61 
62 /** This is the envelope constructor which uses problem_db to build a
63     fully populated db object.  It only needs to extract enough data
64     to properly execute get_db(problem_db), since the constructor
65     overloaded with BaseConstructor builds the actual base class data
66     inherited by the derived classes. */
ProblemDescDB(ParallelLibrary & parallel_lib)67 ProblemDescDB::ProblemDescDB(ParallelLibrary& parallel_lib):
68   parallelLib(parallel_lib),
69   // Set the rep pointer to the appropriate db type
70   dbRep(get_db(parallel_lib))
71 
72 {
73   if (!dbRep) // bad settings or insufficient memory
74     abort_handler(-1);
75 }
76 
77 
78 /** Initializes dbRep to the appropriate derived type.  The standard
79     derived class constructors are invoked.  */
80 std::shared_ptr<ProblemDescDB>
get_db(ParallelLibrary & parallel_lib)81 ProblemDescDB::get_db(ParallelLibrary& parallel_lib)
82 {
83   Dak_pddb = this;	// for use in abort_handler()
84 
85   //if (xml_flag)
86   //  return new XMLProblemDescDB(parallel_lib);
87   //else
88   return std::make_shared<NIDRProblemDescDB>(parallel_lib);
89 }
90 
91 
92 /** Copy constructor manages sharing of dbRep */
ProblemDescDB(const ProblemDescDB & db)93 ProblemDescDB::ProblemDescDB(const ProblemDescDB& db):
94   parallelLib(db.parallel_library()),
95   dbRep(db.dbRep)
96 { /* empty ctor */ }
97 
98 
99 /** Assignment operator shares the dbRep. */
operator =(const ProblemDescDB & db)100 ProblemDescDB ProblemDescDB::operator=(const ProblemDescDB& db)
101 {
102   dbRep = db.dbRep;
103   return *this; // calls copy constructor since returned by value
104 }
105 
106 
107 /** dbRep only deleted when its reference count reaches zero. */
~ProblemDescDB()108 ProblemDescDB::~ProblemDescDB()
109 {
110   if (this == Dak_pddb)
111     Dak_pddb = NULL;
112 }
113 
114 
115 /** DB setup phase 1: parse the input file and execute callback
116     functions if present.  Rank 0 only.
117 
118     DB setup phase 2: optionally insert additional data via late sets.
119     Rank 0 only. */
120 void ProblemDescDB::
parse_inputs(ProgramOptions & prog_opts,DbCallbackFunctionPtr callback,void * callback_data)121 parse_inputs(ProgramOptions& prog_opts,
122 	     DbCallbackFunctionPtr callback, void *callback_data)
123 {
124   if (dbRep) {
125     dbRep->parse_inputs(prog_opts, callback, callback_data);
126     // BMA TODO: Temporary workaround; can't get callback to work on
127     // letter yet. Need to replace Null_rep* with forward to letter
128     // and remove dbRep->, but initial cut didn't work.
129     if (callback && dbRep->parallelLib.world_rank() == 0)
130       (*callback)(this, callback_data);
131   }
132   else {
133 
134     // Only the master parses the input file.
135     if (parallelLib.world_rank() == 0) {
136 
137       if ( !prog_opts.input_file().empty() &&
138 	   !prog_opts.input_string().empty() ) {
139 	Cerr << "\nError: parse_inputs called with both input file and input "
140 	     << "string." << std::endl;
141 	abort_handler(PARSE_ERROR);
142       }
143 
144       // Read the input from stdin if the user provided "-" as the filename
145       if(prog_opts.input_file() == "-") {
146         Cout << "Reading Dakota input from standard input" << std::endl;
147         String stdin_string;
148         char in = std::cin.get();
149         while(std::cin.good()) {
150           stdin_string.push_back(in);
151           in = std::cin.get();
152         }
153         prog_opts.input_string(stdin_string);
154       }
155 
156       if (prog_opts.preproc_input()) {
157 
158 	if (prog_opts.echo_input())
159 	  echo_input_file(prog_opts.input_file(), prog_opts.input_string(),
160 			  " template");
161 
162 	std::string tmpl_file = prog_opts.input_file();
163 	if (!prog_opts.input_string().empty())
164 	  // must generate to file on disk for pyprepro
165 	  tmpl_file = string_to_tmpfile(prog_opts.input_string());
166 
167 	// run the pre-processor on the file
168 	std::string preproc_file = pyprepro_input(tmpl_file,
169 						  prog_opts.preproc_cmd());
170 
171 	if (prog_opts.echo_input())
172 	  echo_input_file(preproc_file, "");
173 
174 	// Parse the input file using one of the derived parser-specific classes
175 	derived_parse_inputs(preproc_file, "", prog_opts.parser_options());
176 
177 	boost::filesystem::remove(preproc_file);
178 	if (!prog_opts.input_string().empty())
179 	  boost::filesystem::remove(tmpl_file);
180       }
181       else {
182 
183 	if (prog_opts.echo_input())
184 	  echo_input_file(prog_opts.input_file(), prog_opts.input_string());
185 
186 	// Parse the input file using one of the derived parser-specific classes
187 	derived_parse_inputs(prog_opts.input_file(), prog_opts.input_string(),
188 			     prog_opts.parser_options());
189 
190       }
191 
192       // Allow user input by callback function.
193 
194       // BMA TODO: Is this comment true?
195       // Note: the DB is locked and the list iterators are not defined.  Thus,
196       // the user function must do something to put the DB in a usable set/get
197       // state (e.g., resolve_top_method() or set_db_list_nodes()).
198 
199       // if (callback)
200       // 	(*callback)(this, callback_data);
201 
202     }
203 
204   }
205 }
206 
207 
208 /** DB setup phase 3: perform basic checks on keywords counts in
209     current DB state, then sync to all processors. */
check_and_broadcast(const ProgramOptions & prog_opts)210 void ProblemDescDB::check_and_broadcast(const ProgramOptions& prog_opts) {
211 
212   if (dbRep)
213     dbRep->check_and_broadcast(prog_opts);
214   else {
215 
216     // Check to make sure at least one of each of the keywords was found
217     // in the problem specification file; checks only happen on Dakota rank 0
218     if (parallelLib.world_rank() == 0)
219       check_input();
220 
221     // bcast a minimal MPI buffer containing the input specification
222     // data prior to post-processing
223     broadcast();
224 
225     // After broadcast, perform post-processing on all processors to
226     // size default variables/responses specification vectors (avoid
227     // sending large vectors over an MPI buffer).
228     post_process();
229 
230   }
231 }
232 
233 
234 
broadcast()235 void ProblemDescDB::broadcast()
236 {
237   if (dbRep)
238     dbRep->broadcast();
239   else {
240     // DAKOTA's old design for reading the input file was for the master to get
241     // the input filename from cmd_line_handler (after MPI_Init) and broadcast
242     // the character buffer to all other processors (having every processor
243     // query the cmd_line_handler was failing because of the effect of MPI_Init
244     // on argc and argv).  Then every processor yyparsed.  This worked fine but
245     // was not scalable for MP machines with a limited number of I/O devices.
246 
247     // Now, rank 0 yyparse's and sends all the parsed data in a single buffer
248     // to all other ranks.
249     if (parallelLib.world_size() > 1) {
250       if (parallelLib.world_rank() == 0) {
251 	enforce_unique_ids();
252 	derived_broadcast(); // pre-processor
253 	send_db_buffer();
254 #ifdef MPI_DEBUG
255 	Cout << "DB buffer to send on world rank " << parallelLib.world_rank()
256 	     << ":\n" << environmentSpec << dataMethodList << dataVariablesList
257 	     << dataInterfaceList << dataResponsesList << std::endl;
258 #endif // MPI_DEBUG
259       }
260       else {
261 	receive_db_buffer();
262 #ifdef MPI_DEBUG
263 	Cout << "DB buffer received on world rank " << parallelLib.world_rank()
264 	     << ":\n" << environmentSpec << dataMethodList << dataVariablesList
265 	     << dataInterfaceList << dataResponsesList << std::endl;
266 #endif // MPI_DEBUG
267 	//derived_broadcast(); // post-processor
268       }
269     }
270     else {
271 #ifdef DEBUG
272       Cout << "DB parsed data:\n" << environmentSpec << dataMethodList
273 	   << dataVariablesList << dataInterfaceList << dataResponsesList
274 	   << std::endl;
275 #endif // DEBUG
276       enforce_unique_ids();
277       derived_broadcast();
278     }
279   }
280 }
281 
282 
283 /** When using library mode in a parallel application, post_process()
284     should be called on all processors following broadcast() of a
285     minimal problem specification. */
post_process()286 void ProblemDescDB::post_process()
287 {
288   // no base class post-processing operations to perform
289   if (dbRep)
290     dbRep->derived_post_process();
291   else
292     derived_post_process();
293 }
294 
295 
296 void ProblemDescDB::
derived_parse_inputs(const std::string & dakota_input_file,const std::string & dakota_input_string,const std::string & parser_options)297 derived_parse_inputs(const std::string& dakota_input_file,
298 		     const std::string& dakota_input_string,
299 		     const std::string& parser_options)
300 {
301   if (dbRep)
302     dbRep->derived_parse_inputs(dakota_input_file, dakota_input_string,
303 				parser_options);
304   else { // this fn must be redefined
305     Cerr << "Error: Letter lacking redefinition of virtual derived_parse_inputs"
306 	 << " function.\n       No default defined at base class." << std::endl;
307     abort_handler(-1);
308   }
309 }
310 
311 
derived_broadcast()312 void ProblemDescDB::derived_broadcast()
313 {
314   if (dbRep)
315     dbRep->derived_broadcast();
316   // else do nothing: this fn is optional
317 }
318 
319 
derived_post_process()320 void ProblemDescDB::derived_post_process()
321 {
322   if (dbRep)
323     dbRep->derived_post_process();
324   // else do nothing: this fn is optional
325 }
326 
327 
328 /** NOTE: when using library mode in a parallel application,
329     check_input() should either be called only on worldRank 0, or it
330     should follow a matched send_db_buffer()/receive_db_buffer() pair. */
check_input()331 void ProblemDescDB::check_input()
332 {
333   if (dbRep)
334     dbRep->check_input();
335   else {
336 
337     int num_errors = 0;
338     //if (!environmentCntr) { // Allow environment omission
339     //  Cerr << "No environment specification found in input file.\n";
340     //  ++num_errors;
341     //}
342     if (environmentCntr > 1) {
343       Cerr << "Multiple environment specifications not allowed in input "
344 	   << "file.\n";
345       ++num_errors;
346     }
347     if (dataMethodList.empty()) {
348       Cerr << "No method specification found in input file.\n";
349       ++num_errors;
350     }
351     if (dataVariablesList.empty()) {
352       Cerr << "No variables specification found in input file.\n";
353       ++num_errors;
354     }
355     if (dataInterfaceList.empty()) {
356       // interface spec may be omitted in case of global data fits
357       bool interface_reqd = true;
358       // global surrogate with data reuse from either restart or points_file
359       for (std::list<DataModel>::iterator dm_iter = dataModelList.begin();
360 	   dm_iter!=dataModelList.end(); ++dm_iter)
361 	if ( strbegins(dm_iter->dataModelRep->surrogateType, "global_") &&
362 	     ( ( !dm_iter->dataModelRep->approxPointReuse.empty() &&
363 		  dm_iter->dataModelRep->approxPointReuse != "none" ) ||
364 	       !dm_iter->dataModelRep->importBuildPtsFile.empty() ) )
365 	  interface_reqd = false;
366       if (interface_reqd)
367 	for (std::list<DataMethod>::iterator dm_iter = dataMethodList.begin();
368 	     dm_iter != dataMethodList.end(); ++dm_iter)
369 	  if (!dm_iter->dataMethodRep->importBuildPtsFile.empty())
370 	    interface_reqd = false;
371       if (interface_reqd) {
372 	Cerr << "No interface specification found in input file.\n";
373 	++num_errors;
374       }
375       else {
376 	// needed for setting DB interface node to something; prevents errors
377 	// in any interface spec data lookups (e.g., Interface base class ctor
378 	// called from ApproximationInterface ctor)
379 	DataInterface data_interface; // use defaults
380 	dataInterfaceList.push_back(data_interface);
381       }
382     }
383     if (dataResponsesList.empty()) {
384       Cerr << "No responses specification found in input file.\n";
385       ++num_errors;
386     }
387     if (dataModelList.empty()) { // Allow model omission
388       DataModel data_model; // use defaults: modelType == "simulation"
389       dataModelList.push_back(data_model);
390     }
391 
392     if (parallelLib.command_line_user_modes()) {
393 
394       if (!parallelLib.command_line_pre_run_input().empty())
395 	Cerr << "Warning: pre-run input not implemented; ignored.\n";
396 
397       if (!parallelLib.command_line_pre_run_output().empty()) {
398 	if (dataMethodList.size() > 1) {
399 	  Cerr << "Error: pre-run output only allowed for single method.\n";
400 	  ++num_errors;
401 	}
402 	else if (!dataMethodList.empty()) {
403 	  // exactly one method
404 	  // TODO: Test for iterator concurrency
405 	  std::list<DataMethod>::iterator dm = dataMethodList.begin();
406 	  unsigned short method_name = dm->dataMethodRep->methodName;
407 	  if ( !(method_name & PSTUDYDACE_BIT) &&
408 	       !(method_name == RANDOM_SAMPLING) ) {
409 	    Cerr << "Error: pre-run output not supported for method "
410 		 << method_name << "\n       (supported for sampling, "
411 		 << "parameter study, DDACE, FSUDACE, and PSUADE methods)\n";
412 	    ++num_errors;
413 	  }
414 	}
415       }
416 
417       if (!parallelLib.command_line_run_input().empty())
418 	Cerr << "Warning: run input not implemented; ignored.\n";
419 
420       if (!parallelLib.command_line_run_output().empty())
421 	Cerr << "Warning: run output not implemented; ignored.\n";
422 
423       if (!parallelLib.command_line_post_run_input().empty()) {
424 	if (dataMethodList.size() > 1) {
425 	  Cerr << "Error: post-run input only allowed for single method.\n";
426 	  ++num_errors;
427 	}
428 	else if (!dataMethodList.empty()) {
429 	  // exactly one method
430 	  // TODO: Test for iterator concurrency
431 	  std::list<DataMethod>::iterator dm = dataMethodList.begin();
432 	  unsigned short method_name = dm->dataMethodRep->methodName;
433 	  if ( !(method_name & PSTUDYDACE_BIT) &&
434 	       !(method_name == RANDOM_SAMPLING) ) {
435 	    Cerr << "Error: post-run input not supported for method "
436 		 << method_name << "\n       (supported for sampling, "
437 		 << "parameter study, DDACE, FSUDACE, and PSUADE methods)\n";
438 	    ++num_errors;
439 	  }
440 	}
441       }
442 
443       if (!parallelLib.command_line_post_run_output().empty())
444 	Cerr << "Warning: post-run output not implemented; ignored.\n";
445 
446     }
447 
448     if (num_errors) {
449       Cerr << num_errors << " input specification errors detected." <<std::endl;
450       abort_handler(PARSE_ERROR);
451     }
452   }
453 }
454 
455 
set_db_list_nodes(const String & method_tag)456 void ProblemDescDB::set_db_list_nodes(const String& method_tag)
457 {
458   if (dbRep)
459     dbRep->set_db_list_nodes(method_tag);
460   // for simplicity in client logic, allow NO_SPECIFICATION case to fall
461   // through: do not update iterators or locks, such that previous
462   // specification settings remain active (NO_SPECIFICATION instances
463   // within a recursion do not alter list node sequencing).
464   else if (!strbegins(method_tag, "NOSPEC_METHOD_ID_")) {
465     set_db_method_node(method_tag);
466     if (methodDBLocked) {
467       modelDBLocked = variablesDBLocked = interfaceDBLocked
468 	= responsesDBLocked = true;
469       // ensure consistency in get_db_{method,model}_node():
470       //dataModelIter = dataModelList.end();
471     }
472     else
473       set_db_model_nodes(dataMethodIter->dataMethodRep->modelPointer);
474   }
475 }
476 
477 
set_db_list_nodes(size_t method_index)478 void ProblemDescDB::set_db_list_nodes(size_t method_index)
479 {
480   if (dbRep)
481     dbRep->set_db_list_nodes(method_index);
482   else {
483     // Set the correct Index values for all Data class lists.
484     set_db_method_node(method_index);
485     if (methodDBLocked) {
486       modelDBLocked = variablesDBLocked = interfaceDBLocked
487 	= responsesDBLocked = true;
488       // ensure consistency in get_db_{method,model}_node():
489       //dataModelIter = dataModelList.end();
490     }
491     else
492       set_db_model_nodes(dataMethodIter->dataMethodRep->modelPointer);
493   }
494 }
495 
496 
resolve_top_method(bool set_model_nodes)497 void ProblemDescDB::resolve_top_method(bool set_model_nodes)
498 {
499   if (dbRep)
500     dbRep->resolve_top_method(set_model_nodes);
501   else { // deduce which method spec sits on top
502     String& top_meth_ptr = environmentSpec.dataEnvRep->topMethodPointer;
503     size_t num_method_spec = dataMethodList.size();
504     if (num_method_spec == 1)
505       dataMethodIter = dataMethodList.begin();
506     else if (!top_meth_ptr.empty())
507       dataMethodIter =
508 	std::find_if( dataMethodList.begin(), dataMethodList.end(),
509 		      boost::bind(DataMethod::id_compare, _1, top_meth_ptr) );
510     else { // identify which id_method does not appear in a method_pointer
511       // Collect list of all method id's (including empty ids)
512       StringList method_ids;
513       for (std::list<DataMethod>::iterator it=dataMethodList.begin();
514 	   it!=dataMethodList.end(); it++)
515 	method_ids.push_back(it->dataMethodRep->idMethod);
516       // Eliminate sub-method pointers from method specs
517       for (std::list<DataMethod>::iterator it=dataMethodList.begin();
518 	   it!=dataMethodList.end(); it++)
519 	if (!it->dataMethodRep->subMethodPointer.empty()) {
520           StringList::iterator slit
521             = std::find(method_ids.begin(), method_ids.end(),
522                         it->dataMethodRep->subMethodPointer);
523           if (slit != method_ids.end()) method_ids.erase(slit);
524 	}
525       // Eliminate method_pointers from model specs
526       for (std::list<DataModel>::iterator it=dataModelList.begin();
527 	   it!=dataModelList.end(); it++)
528 	if (!it->dataModelRep->subMethodPointer.empty()) {
529           StringList::iterator slit
530             = std::find(method_ids.begin(), method_ids.end(),
531                         it->dataModelRep->subMethodPointer);
532           if (slit != method_ids.end()) method_ids.erase(slit);
533 	}
534       // by process of elimination, select the top method
535       if (method_ids.empty() || method_ids.size() > 1) {
536 	Cerr << "\nError: ProblemDescDB::resolve_top_method() failed to "
537 	     << "determine active method specification.\n       Please resolve "
538 	     << "method pointer ambiguities." << std::endl;
539 	abort_handler(PARSE_ERROR);
540       }
541       else {
542 	const String& method_id = *method_ids.begin();
543 	dataMethodIter
544 	  = std::find_if( dataMethodList.begin(), dataMethodList.end(),
545               boost::bind(DataMethod::id_compare, _1, method_id) );
546       }
547     }
548     methodDBLocked = false; // unlock
549 
550     // set all subordinate list nodes for this method
551     if (set_model_nodes)
552       set_db_model_nodes(dataMethodIter->dataMethodRep->modelPointer);
553   }
554 }
555 
556 
set_db_method_node(const String & method_tag)557 void ProblemDescDB::set_db_method_node(const String& method_tag)
558 {
559   if (dbRep)
560     dbRep->set_db_method_node(method_tag);
561   // for simplicity in client logic, allow NO_SPECIFICATION case to fall
562   // through: do not update dataMethodIter or methodDBLocked, such that
563   // previous specification settings remain active (NO_SPECIFICATION
564   // instances within a recursion do not alter list node sequencing).
565   else if (!strbegins(method_tag, "NOSPEC_METHOD_ID_")) {
566     // set the correct Index values for all Data class lists.
567     if (method_tag.empty()) { // no pointer specification
568       if (dataMethodList.size() == 1) // no ambiguity if only one spec
569 	dataMethodIter = dataMethodList.begin();
570       else { // try to match to a method without an id
571 	dataMethodIter
572 	  = std::find_if( dataMethodList.begin(), dataMethodList.end(),
573               boost::bind(DataMethod::id_compare, _1, method_tag) );
574 	if (dataMethodIter == dataMethodList.end()) {
575 	  if (parallelLib.world_rank() == 0)
576 	    Cerr << "\nWarning: empty method id string not found.\n         "
577 		 << "Last method specification parsed will be used.\n";
578 	  --dataMethodIter; // last entry in list
579 	}
580 	else if (parallelLib.world_rank() == 0 &&
581 		 std::count_if(dataMethodList.begin(), dataMethodList.end(),
582                    boost::bind(DataMethod::id_compare, _1, method_tag)) > 1)
583 	  Cerr << "\nWarning: empty method id string is ambiguous.\n         "
584 	       << "First matching method specification will be used.\n";
585       }
586       methodDBLocked = false; // unlock
587     }
588     else {
589       std::list<DataMethod>::iterator dm_it
590 	= std::find_if( dataMethodList.begin(), dataMethodList.end(),
591             boost::bind(DataMethod::id_compare, _1, method_tag) );
592       if (dm_it == dataMethodList.end()) {
593 	methodDBLocked = true; // lock (moot)
594 	Cerr << "\nError: " << method_tag
595 	     << " is not a valid method identifier string." << std::endl;
596 	abort_handler(PARSE_ERROR);
597       }
598       else {
599 	methodDBLocked = false; // unlock
600 	dataMethodIter = dm_it;
601 	if (parallelLib.world_rank() == 0 &&
602 	    std::count_if(dataMethodList.begin(), dataMethodList.end(),
603 			  boost::bind(DataMethod::id_compare,_1,method_tag))>1)
604 	  Cerr << "\nWarning: method id string " << method_tag
605 	       << " is ambiguous.\n         First matching method "
606 	       << "specification will be used.\n";
607       }
608     }
609   }
610 }
611 
612 
set_db_method_node(size_t method_index)613 void ProblemDescDB::set_db_method_node(size_t method_index)
614 {
615   if (dbRep)
616     dbRep->set_db_method_node(method_index);
617   else if (method_index == _NPOS)
618     methodDBLocked = true;
619   else {
620     size_t num_meth_spec = dataMethodList.size();
621     // allow advancement up to but not past end()
622     if (method_index > num_meth_spec) {
623       Cerr << "\nError: method_index sent to set_db_method_node is out of "
624 	   << "range." << std::endl;
625       abort_handler(PARSE_ERROR);
626     }
627     dataMethodIter = dataMethodList.begin();
628     std::advance(dataMethodIter, method_index);
629     // unlock if not advanced to end()
630     methodDBLocked = (method_index == num_meth_spec);
631   }
632 }
633 
634 
set_db_model_nodes(size_t model_index)635 void ProblemDescDB::set_db_model_nodes(size_t model_index)
636 {
637   if (dbRep)
638     dbRep->set_db_model_nodes(model_index);
639   else if (model_index == _NPOS)
640     modelDBLocked = variablesDBLocked = interfaceDBLocked
641       = responsesDBLocked = true;
642   else {
643     size_t num_model_spec = dataModelList.size();
644     // allow advancement up to but not past end()
645     if (model_index > num_model_spec) {
646       Cerr << "\nError: model_index sent to set_db_model_nodes is out of range."
647 	   << std::endl;
648       abort_handler(PARSE_ERROR);
649     }
650     dataModelIter = dataModelList.begin();
651     std::advance(dataModelIter, model_index);
652     // unlock if not advanced to end()
653     if (model_index == num_model_spec)
654       modelDBLocked = variablesDBLocked = interfaceDBLocked = responsesDBLocked
655 	= true;
656     else {
657       const DataModelRep& MoRep = *dataModelIter->dataModelRep;
658       set_db_variables_node(MoRep.variablesPointer);
659       if (model_has_interface(MoRep))
660 	set_db_interface_node(MoRep.interfacePointer);
661       else
662 	interfaceDBLocked = true;
663       set_db_responses_node(MoRep.responsesPointer);
664     }
665   }
666 }
667 
668 
set_db_model_nodes(const String & model_tag)669 void ProblemDescDB::set_db_model_nodes(const String& model_tag)
670 {
671   if (dbRep)
672     dbRep->set_db_model_nodes(model_tag);
673   // for simplicity in client logic, allow NO_SPECIFICATION case to fall
674   // through: do not update model iterators or locks, such that previous
675   // specification settings remain active (NO_SPECIFICATION instances
676   // within a recursion do not alter list node sequencing).
677   else if (! (model_tag == "NO_SPECIFICATION" ||
678         strbegins(model_tag, "NOSPEC_MODEL_ID_") ||
679         strbegins(model_tag, "RECAST_"))) {
680     // set dataModelIter from model_tag
681     if (model_tag.empty() || model_tag == "NO_MODEL_ID") { // no pointer specification
682       if (dataModelList.empty()) { // Note: check_input() prevents this
683 	DataModel data_model; // for library mode
684 	dataModelList.push_back(data_model);
685       }
686       if (dataModelList.size() == 1) // no ambiguity if only one spec
687 	dataModelIter = dataModelList.begin();
688       else { // try to match to a model without an id
689 	dataModelIter
690 	  = std::find_if( dataModelList.begin(), dataModelList.end(),
691               boost::bind(DataModel::id_compare, _1, model_tag) );
692 	if (dataModelIter == dataModelList.end()) {
693 	  if (parallelLib.world_rank() == 0)
694 	    Cerr << "\nWarning: empty model id string not found.\n         "
695 		 << "Last model specification parsed will be used.\n";
696 	  --dataModelIter; // last entry in list
697 	}
698 	else if (parallelLib.world_rank() == 0 &&
699 		 std::count_if(dataModelList.begin(), dataModelList.end(),
700                    boost::bind(DataModel::id_compare, _1, model_tag)) > 1)
701 	  Cerr << "\nWarning: empty model id string is ambiguous.\n         "
702 	       << "First matching model specification will be used.\n";
703       }
704       modelDBLocked = false; // unlock
705     }
706     else {
707       std::list<DataModel>::iterator dm_it
708 	= std::find_if( dataModelList.begin(), dataModelList.end(),
709             boost::bind(DataModel::id_compare, _1, model_tag) );
710       if (dm_it == dataModelList.end()) {
711 	modelDBLocked = true; // lock (moot)
712 	Cerr << "\nError: " << model_tag
713 	     << " is not a valid model identifier string." << std::endl;
714 	abort_handler(PARSE_ERROR);
715       }
716       else {
717 	modelDBLocked = false; // unlock
718 	dataModelIter = dm_it;
719 	if (parallelLib.world_rank() == 0 &&
720 	    std::count_if(dataModelList.begin(), dataModelList.end(),
721 			  boost::bind(DataModel::id_compare, _1, model_tag))>1)
722 	  Cerr << "\nWarning: model id string " << model_tag << " is ambiguous."
723 	       << "\n         First matching model specification will be used."
724 	       << '\n';
725       }
726     }
727 
728     if (modelDBLocked)
729       variablesDBLocked = interfaceDBLocked = responsesDBLocked	= true;
730     else {
731       const DataModelRep& MoRep = *dataModelIter->dataModelRep;
732       set_db_variables_node(MoRep.variablesPointer);
733       if (model_has_interface(MoRep))
734 	set_db_interface_node(MoRep.interfacePointer);
735       else
736 	interfaceDBLocked = true;
737       set_db_responses_node(MoRep.responsesPointer);
738     }
739   }
740 }
741 
742 
set_db_variables_node(const String & variables_tag)743 void ProblemDescDB::set_db_variables_node(const String& variables_tag)
744 {
745   if (dbRep)
746     dbRep->set_db_variables_node(variables_tag);
747   // for simplicity in client logic, allow NO_SPECIFICATION case to fall
748   // through: do not update dataVariablesIter or variablesDBLocked, such
749   // that previous specification remains active (NO_SPECIFICATION
750   // instances within a recursion do not alter list node sequencing).
751   else if (variables_tag != "NO_SPECIFICATION") { // not currently in use
752     // set dataVariablesIter from variables_tag
753     if (variables_tag.empty()) { // no pointer specification
754       if (dataVariablesList.size() == 1) // no ambiguity if only one spec
755 	dataVariablesIter = dataVariablesList.begin();
756       else { // try to match to a variables without an id
757 	dataVariablesIter
758 	  = std::find_if( dataVariablesList.begin(), dataVariablesList.end(),
759               boost::bind(DataVariables::id_compare, _1, variables_tag) );
760 	if (dataVariablesIter == dataVariablesList.end()) {
761 	  if (parallelLib.world_rank() == 0)
762 	    Cerr << "\nWarning: empty variables id string not found.\n         "
763 		 << "Last variables specification parsed will be used.\n";
764 	  --dataVariablesIter; // last entry in list
765 	}
766 	else if (parallelLib.world_rank() == 0 &&
767 		 std::count_if(dataVariablesList.begin(),
768 			       dataVariablesList.end(),
769 			       boost::bind(DataVariables::id_compare, _1,
770 					   variables_tag)) > 1)
771 	  Cerr << "\nWarning: empty variables id string is ambiguous."
772 	       << "\n         First matching variables specification will be "
773 	       << "used.\n";
774       }
775       variablesDBLocked = false; // unlock
776     }
777     else {
778       std::list<DataVariables>::iterator dv_it
779 	= std::find_if( dataVariablesList.begin(), dataVariablesList.end(),
780             boost::bind(DataVariables::id_compare, _1, variables_tag) );
781       if (dv_it == dataVariablesList.end()) {
782 	variablesDBLocked = true; // lock (moot)
783 	Cerr << "\nError: " << variables_tag
784 	     << " is not a valid variables identifier string." << std::endl;
785 	abort_handler(PARSE_ERROR);
786       }
787       else {
788 	variablesDBLocked = false; // unlock
789 	dataVariablesIter = dv_it;
790 	if (parallelLib.world_rank() == 0 &&
791 	    std::count_if(dataVariablesList.begin(), dataVariablesList.end(),
792 			  boost::bind(DataVariables::id_compare, _1,
793 				      variables_tag)) > 1)
794 	  Cerr << "\nWarning: variables id string " << variables_tag
795 	       << " is ambiguous.\n         First matching variables "
796 	       << "specification will be used.\n";
797       }
798     }
799   }
800 }
801 
802 
set_db_interface_node(const String & interface_tag)803 void ProblemDescDB::set_db_interface_node(const String& interface_tag)
804 {
805   if (dbRep)
806     dbRep->set_db_interface_node(interface_tag);
807   // for simplicity in client logic, allow NO_SPECIFICATION case to fall
808   // through: do not update dataInterfaceIter or interfaceDBLocked, such
809   // that previous specification remains active (NO_SPECIFICATION
810   // instances within a recursion do not alter list node sequencing).
811   else if (!strbegins(interface_tag, "NOSPEC_INTERFACE_ID_")) {
812     const DataModelRep& MoRep = *dataModelIter->dataModelRep;
813     // set dataInterfaceIter from interface_tag
814     if (interface_tag.empty() || interface_tag == "NO_ID") { // no pointer specification
815       if (dataInterfaceList.size() == 1) // no ambiguity if only one spec
816 	dataInterfaceIter = dataInterfaceList.begin();
817       else { // try to match to a interface without an id
818 	dataInterfaceIter
819 	  = std::find_if( dataInterfaceList.begin(), dataInterfaceList.end(),
820               boost::bind(DataInterface::id_compare, _1, interface_tag) );
821 	// echo warning if a default interface list entry will be used and more
822 	// than 1 interface specification is present.  Currently this can only
823 	// happen for simulation models, since surrogate model specifications
824 	// do not contain interface ptrs and the omission of an optional
825 	// interface ptr in nested models indicates the omission of an optional
826 	// interface (rather than the presence of an unidentified interface).
827 	if (dataInterfaceIter == dataInterfaceList.end()) {
828 	  if (parallelLib.world_rank() == 0 &&
829 	      MoRep.modelType == "simulation")
830 	    Cerr << "\nWarning: empty interface id string not found.\n         "
831 		 << "Last interface specification parsed will be used.\n";
832 	  --dataInterfaceIter; // last entry in list
833 	}
834 	else if (parallelLib.world_rank() == 0 &&
835 		 MoRep.modelType == "simulation"  &&
836 		 std::count_if(dataInterfaceList.begin(),
837 			       dataInterfaceList.end(),
838 			       boost::bind(DataInterface::id_compare, _1,
839 					   interface_tag)) > 1)
840 	  Cerr << "\nWarning: empty interface id string is ambiguous."
841 	       << "\n         First matching interface specification will be "
842 	       << "used.\n";
843       }
844       interfaceDBLocked = false; // unlock
845     }
846     else {
847       std::list<DataInterface>::iterator di_it
848 	= std::find_if( dataInterfaceList.begin(), dataInterfaceList.end(),
849             boost::bind(DataInterface::id_compare, _1, interface_tag) );
850       if (di_it == dataInterfaceList.end()) {
851 	interfaceDBLocked = true; // lock (moot)
852 	Cerr << "\nError: " << interface_tag
853 	     << " is not a valid interface identifier string." << std::endl;
854 	abort_handler(PARSE_ERROR);
855       }
856       else {
857 	interfaceDBLocked = false; // unlock
858 	dataInterfaceIter = di_it;
859 	if (parallelLib.world_rank() == 0 &&
860 	    std::count_if(dataInterfaceList.begin(), dataInterfaceList.end(),
861 			  boost::bind(DataInterface::id_compare, _1,
862 				      interface_tag)) > 1)
863 	  Cerr << "\nWarning: interface id string " << interface_tag
864 	       << " is ambiguous.\n         First matching interface "
865 	       << "specification will be used.\n";
866       }
867     }
868   }
869 }
870 
871 
set_db_responses_node(const String & responses_tag)872 void ProblemDescDB::set_db_responses_node(const String& responses_tag)
873 {
874   if (dbRep)
875     dbRep->set_db_responses_node(responses_tag);
876   // for simplicity in client logic, allow NO_SPECIFICATION case to fall
877   // through: do not update dataResponsesIter or responsesDBLocked,
878   // such that previous specification remains active (NO_SPECIFICATION
879   // instances within a recursion do not alter list node sequencing).
880   else if (responses_tag != "NO_SPECIFICATION") {
881     // set dataResponsesIter from responses_tag
882     if (responses_tag.empty()) { // no pointer specification
883       if (dataResponsesList.size() == 1) // no ambiguity if only one spec
884 	dataResponsesIter = dataResponsesList.begin();
885       else { // try to match to a responses without an id
886 	dataResponsesIter
887 	  = std::find_if( dataResponsesList.begin(), dataResponsesList.end(),
888               boost::bind(DataResponses::id_compare, _1, responses_tag) );
889 	if (dataResponsesIter == dataResponsesList.end()) {
890 	  if (parallelLib.world_rank() == 0)
891 	    Cerr << "\nWarning: empty responses id string not found.\n         "
892 		 << "Last responses specification parsed will be used.\n";
893 	  --dataResponsesIter; // last entry in list
894 	}
895 	else if (parallelLib.world_rank() == 0 &&
896 		 std::count_if(dataResponsesList.begin(),
897 			       dataResponsesList.end(),
898 			       boost::bind(DataResponses::id_compare, _1,
899 					   responses_tag)) > 1)
900 	  Cerr << "\nWarning: empty responses id string is ambiguous."
901 	       << "\n         First matching responses specification will be "
902 	       << "used.\n";
903       }
904       responsesDBLocked = false; // unlock
905     }
906     else {
907       std::list<DataResponses>::iterator dr_it
908 	= std::find_if( dataResponsesList.begin(), dataResponsesList.end(),
909             boost::bind(DataResponses::id_compare, _1, responses_tag) );
910       if (dr_it == dataResponsesList.end()) {
911 	responsesDBLocked = true; // lock (moot)
912 	Cerr << "\nError: " << responses_tag
913 	     << " is not a valid responses identifier string." << std::endl;
914 	abort_handler(PARSE_ERROR);
915       }
916       else {
917 	responsesDBLocked = false; // unlock
918 	dataResponsesIter = dr_it;
919 	if (parallelLib.world_rank() == 0 &&
920 	    std::count_if(dataResponsesList.begin(), dataResponsesList.end(),
921 			  boost::bind(DataResponses::id_compare, _1,
922 				      responses_tag)) > 1)
923 	  Cerr << "\nWarning: responses id string " << responses_tag
924 	       << " is ambiguous.\n         First matching responses "
925 	       << "specification will be used.\n";
926       }
927     }
928   }
929 }
930 
931 
send_db_buffer()932 void ProblemDescDB::send_db_buffer()
933 {
934   MPIPackBuffer send_buffer;
935   send_buffer << environmentSpec   << dataMethodList    << dataModelList
936 	      << dataVariablesList << dataInterfaceList << dataResponsesList;
937 
938   // Broadcast length of buffer so that slaves can allocate MPIUnpackBuffer
939   int buffer_len = send_buffer.size();
940   parallelLib.bcast_w(buffer_len);
941 
942   // Broadcast actual buffer
943   parallelLib.bcast_w(send_buffer);
944 }
945 
946 
receive_db_buffer()947 void ProblemDescDB::receive_db_buffer()
948 {
949   // receive length of incoming buffer and allocate space for MPIUnpackBuffer
950   int buffer_len;
951   parallelLib.bcast_w(buffer_len);
952 
953   // receive incoming buffer
954   MPIUnpackBuffer recv_buffer(buffer_len);
955   parallelLib.bcast_w(recv_buffer);
956   recv_buffer >> environmentSpec   >> dataMethodList    >> dataModelList
957 	      >> dataVariablesList >> dataInterfaceList >> dataResponsesList;
958 }
959 
960 
get_iterator()961 const Iterator& ProblemDescDB::get_iterator()
962 {
963   // ProblemDescDB::get_<object> functions operate at the envelope level
964   // so that any passing of *this provides the envelope object.
965   if (!dbRep) {
966     Cerr << "Error: ProblemDescDB::get_iterator() called for letter object."
967 	 << std::endl;
968     abort_handler(PARSE_ERROR);
969   }
970 
971   // In general, have to worry about loss of encapsulation and use of context
972   // _above_ this specification.  However, any dependence on the environment
973   // specification is OK since there is only one.  All other specifications
974   // are identified via model_pointer.
975 
976   // The DB list nodes are set prior to calling get_iterator():
977   // >    method_ptr spec -> id_method must be defined
978   // > no method_ptr spec -> id_method is ignored, method spec is last parsed
979   // Reuse logic works in both cases -> only a single unreferenced iterator
980   // may exist, which corresponds to the last method spec and is reused for
981   // all untagged instantiations.
982   String id_method = dbRep->dataMethodIter->dataMethodRep->idMethod;
983   if(id_method.empty())
984     id_method = "NO_METHOD_ID";
985   IterLIter i_it
986     = std::find_if(dbRep->iteratorList.begin(), dbRep->iteratorList.end(),
987                    boost::bind(&Iterator::method_id, _1) == id_method);
988   if (i_it == dbRep->iteratorList.end()) {
989     Iterator new_iterator(*this);
990     dbRep->iteratorList.push_back(new_iterator);
991     i_it = --dbRep->iteratorList.end();
992   }
993   return *i_it;
994 }
995 
996 
get_iterator(Model & model)997 const Iterator& ProblemDescDB::get_iterator(Model& model)
998 {
999   // ProblemDescDB::get_<object> functions operate at the envelope level
1000   // so that any passing of *this provides the envelope object.
1001   if (!dbRep) {
1002     Cerr << "Error: ProblemDescDB::get_iterator() called for letter object."
1003 	 << std::endl;
1004     abort_handler(PARSE_ERROR);
1005   }
1006 
1007   String id_method = dbRep->dataMethodIter->dataMethodRep->idMethod;
1008   if(id_method.empty())
1009     id_method = "NO_METHOD_ID";
1010   IterLIter i_it
1011     = std::find_if(dbRep->iteratorList.begin(), dbRep->iteratorList.end(),
1012                    boost::bind(&Iterator::method_id, _1) == id_method);
1013   // if Iterator does not already exist, then create it
1014   if (i_it == dbRep->iteratorList.end()) {
1015     Iterator new_iterator(*this, model);
1016     dbRep->iteratorList.push_back(new_iterator);
1017     i_it = --dbRep->iteratorList.end();
1018   }
1019   // idMethod already exists, but check for same model.  If !same, instantiate
1020   // new rather than update (i_it->iterated_model(model)) all shared instances.
1021   else if (model != i_it->iterated_model()) {
1022     Iterator new_iterator(*this, model);
1023     dbRep->iteratorList.push_back(new_iterator);
1024     i_it = --dbRep->iteratorList.end();
1025   }
1026   return *i_it;
1027 }
1028 
1029 
1030 const Iterator& ProblemDescDB::
get_iterator(const String & method_name,Model & model)1031 get_iterator(const String& method_name, Model& model)
1032 {
1033   // ProblemDescDB::get_<object> functions operate at the envelope level
1034   // so that any passing of *this provides the envelope object.
1035   if (!dbRep) {
1036     Cerr << "Error: ProblemDescDB::get_iterator() called for letter object."
1037 	 << std::endl;
1038     abort_handler(PARSE_ERROR);
1039   }
1040 
1041   IterLIter i_it
1042     = std::find_if(dbRep->iteratorByNameList.begin(),
1043 		   dbRep->iteratorByNameList.end(),
1044                    boost::bind(&Iterator::method_string, _1) == method_name);
1045   // if Iterator does not already exist, then create it
1046   if (i_it == dbRep->iteratorByNameList.end()) {
1047     Iterator new_iterator(method_name, model);
1048     dbRep->iteratorByNameList.push_back(new_iterator);
1049     i_it = --dbRep->iteratorByNameList.end();
1050   }
1051   // method_name already exists, but check for same model. If !same, instantiate
1052   // new rather than update (i_it->iterated_model(model)) all shared instances.
1053   else if (model != i_it->iterated_model()) {
1054     Iterator new_iterator(method_name, model);
1055     dbRep->iteratorByNameList.push_back(new_iterator);
1056     i_it = --dbRep->iteratorByNameList.end();
1057   }
1058   return *i_it;
1059 }
1060 
1061 
get_model()1062 const Model& ProblemDescDB::get_model()
1063 {
1064   // ProblemDescDB::get_<object> functions operate at the envelope level
1065   // so that any passing of *this provides the envelope object.
1066   if (!dbRep) {
1067     Cerr << "Error: ProblemDescDB::get_model() called for letter object."
1068          << std::endl;
1069     abort_handler(PARSE_ERROR);
1070   }
1071 
1072   // A model specification identifies its variables, interface, and responses.
1073   // Have to worry about loss of encapsulation and use of context _above_ this
1074   // specification, i.e., any dependence on an iterator specification
1075   // (dependence on the environment spec is OK since there is only one).
1076   // > method.output
1077   // > Constraints: variables view
1078 
1079   // The DB list nodes are set prior to calling get_model():
1080   // >    model_ptr spec -> id_model must be defined
1081   // > no model_ptr spec -> id_model is ignored, model spec is last parsed
1082   String id_model = dbRep->dataModelIter->dataModelRep->idModel;
1083   if(id_model.empty())
1084     id_model = "NO_MODEL_ID";
1085   ModelLIter m_it
1086     = std::find_if(dbRep->modelList.begin(), dbRep->modelList.end(),
1087                    boost::bind(&Model::model_id, _1) == id_model);
1088   if (m_it == dbRep->modelList.end()) {
1089     Model new_model(*this);
1090     dbRep->modelList.push_back(new_model);
1091     m_it = --dbRep->modelList.end();
1092   }
1093   return *m_it;
1094 }
1095 
1096 
get_variables()1097 const Variables& ProblemDescDB::get_variables()
1098 {
1099   // ProblemDescDB::get_<object> functions operate at the envelope level
1100   // so that any passing of *this provides the envelope object.
1101   if (!dbRep) {
1102     Cerr << "Error: ProblemDescDB::get_variables() called for letter object."
1103 	 << std::endl;
1104     abort_handler(PARSE_ERROR);
1105   }
1106 
1107   // Have to worry about loss of encapsulation and use of context _above_ this
1108   // specification, i.e., any dependence on iterator/model/interface/responses
1109   // specifications (dependence on the environment specification is OK since
1110   // there is only one).
1111   // > variables view is method dependent
1112 
1113   // The DB list nodes are set prior to calling get_variables():
1114   // >    variables_ptr spec -> id_variables must be defined
1115   // > no variables_ptr spec -> id_variables ignored, vars spec = last parsed
1116   //const String& id_variables = dbRep->dataVariablesIter->idVariables;
1117 
1118   // Turn off variables reuse for now, since it is problematic with surrogates:
1119   // a top level variables set followed by a subModel eval which sets subModel
1120   // vars (where the subModel vars object is reused) results in a top level
1121   // eval with the wrong vars (e.g., surrogate auto-build in
1122   // dakota_textbook_lhs_approx.in).
1123   //
1124   // In general, variables object reuse should be fine for objects with peer
1125   // relationships, but are questionable for use among nested/layered levels.
1126   // Need a way to detect peer vs. nested/layered relationships.
1127   VarsLIter v_it;
1128   // = dbRep->variablesList.find(variables_id_compare, &id_variables);
1129   //if ( v_it == dbRep->variablesList.end() ||
1130   //     v_it->view() != v_it->get_view(*this) ) {
1131     Variables new_variables(*this);
1132     dbRep->variablesList.push_back(new_variables);
1133     v_it = --dbRep->variablesList.end();
1134   //}
1135   return *v_it;
1136 }
1137 
1138 
get_interface()1139 const Interface& ProblemDescDB::get_interface()
1140 {
1141   // ProblemDescDB::get_<object> functions operate at the envelope level
1142   // so that any passing of *this provides the envelope object.
1143   if (!dbRep) {
1144     Cerr << "Error: ProblemDescDB::get_interface() called for letter object."
1145 	 << std::endl;
1146     abort_handler(PARSE_ERROR);
1147   }
1148 
1149   // Have to worry about loss of encapsulation and use of context _above_ this
1150   // specification, i.e., any dependence on iterator/model/variables/responses
1151   // specifications (dependence on the environment specification is OK since
1152   // there is only one):
1153   // > Interface: method.output
1154   // > ApplicationInterface: responses.gradient_type, responses.hessian_type,
1155   //     responses.gradients.mixed.id_analytic
1156   // > DakotaInterface: responses.labels
1157 
1158   // ApproximationInterfaces and related classes are OK, since they are
1159   // instantiated with assign_rep() for each unique DataFitSurrModel instance:
1160   // > ApproximationInterface: model.surrogate.function_ids
1161   // > Approximation: method.output, model.surrogate.type,
1162   //     model.surrogate.derivative_usage
1163   // > SurfpackApproximation: model.surrogate.polynomial_order,
1164   //     model.surrogate.kriging_correlations
1165   // > TaylorApproximation: model.surrogate.actual_model_pointer,
1166   //     responses.hessian_type
1167   // > OrthogPolyApproximation: method.nond.expansion_{terms,order}
1168 
1169   // The DB list nodes are set prior to calling get_interface():
1170   // >    interface_ptr spec -> id_interface must be defined
1171   // > no interface_ptr spec -> id_interf ignored, interf spec = last parsed
1172   String id_interface
1173     = dbRep->dataInterfaceIter->dataIfaceRep->idInterface;
1174   if(id_interface.empty())
1175     id_interface = "NO_ID";
1176 
1177   InterfLIter i_it
1178     = std::find_if(dbRep->interfaceList.begin(), dbRep->interfaceList.end(),
1179                    boost::bind(&Interface::interface_id, _1) == id_interface);
1180   if (i_it == dbRep->interfaceList.end()) {
1181     Interface new_interface(*this);
1182     dbRep->interfaceList.push_back(new_interface);
1183     i_it = --dbRep->interfaceList.end();
1184   }
1185   return *i_it;
1186 }
1187 
1188 
get_response(short type,const Variables & vars)1189 const Response& ProblemDescDB::get_response(short type, const Variables& vars)
1190 {
1191   // ProblemDescDB::get_<object> functions operate at the envelope level
1192   // so that any passing of *this provides the envelope object.
1193   if (!dbRep) {
1194     Cerr << "Error: ProblemDescDB::get_response() called for letter object."
1195 	 << std::endl;
1196     abort_handler(PARSE_ERROR);
1197   }
1198 
1199   // Have to worry about loss of encapsulation and use of context _above_ this
1200   // specification, i.e., any dependence on iterator/model/variables/interface
1201   // specifications (dependence on the environment specification is OK since
1202   // there is only one).
1203   // > mismatch in vars attributes (cv(),continuous_variable_ids()) should be OK
1204   //   since derivative arrays are dynamically resized based on current active
1205   //   set content
1206 
1207   // The DB list nodes are set prior to calling get_response():
1208   // >    responses_ptr spec -> id_responses must be defined
1209   // > no responses_ptr spec -> id_responses ignored, resp spec = last parsed
1210   //const String& id_responses
1211   //  = dbRep->dataResponsesIter->dataRespRep->idResponses;
1212 
1213   // Turn off response reuse for now, even though it has not yet been
1214   // problematic.  In general, response object reuse should be fine for objects
1215   // with peer relationships, but are questionable for use among nested/layered
1216   // levels.  Need a way to detect peer vs. nested/layered relationships.
1217   RespLIter r_it;
1218   // = dbRep->responseList.find(responses_id_compare, &id_responses);
1219   //if (r_it == dbRep->responseList.end()) { // ||
1220     //r_it->active_set_derivative_vector() != vars.continuous_variable_ids()) {
1221     Response new_response(type, vars, *this);
1222     dbRep->responseList.push_back(new_response);
1223     r_it = --dbRep->responseList.end();
1224   //}}
1225   return *r_it;
1226 }
1227 
1228 
min_procs_per_ea()1229 inline int ProblemDescDB::min_procs_per_ea()
1230 {
1231   // Note: get_*() requires envelope execution (throws error if !dbRep)
1232 
1233   // Note: DataInterfaceRep::procsPerAnalysis defaults to zero, which is used
1234   // when the processors_per_analysis spec is unreachable (system/fork/spawn)
1235   return min_procs_per_level(1, // min_ppa
1236     get_int("interface.direct.processors_per_analysis"), // 0 for non-direct
1237     get_int("interface.analysis_servers"));
1238 }
1239 
1240 
max_procs_per_ea()1241 int ProblemDescDB::max_procs_per_ea()
1242 {
1243   // Note: get_*() requires envelope execution (throws error if !dbRep)
1244 
1245   // TO DO: can we be more fine grained on parallel testers?
1246   //        default tester could get hidden by plug-in...
1247 
1248   int max_ppa = (get_ushort("interface.type") & DIRECT_INTERFACE_BIT) ?
1249     parallelLib.world_size() : 1; // system/fork/spawn
1250   // Note: DataInterfaceRep::procsPerAnalysis defaults to zero, which is used
1251   // when the processors_per_analysis spec is unreachable (system/fork/spawn)
1252   return max_procs_per_level(max_ppa,
1253     get_int("interface.direct.processors_per_analysis"), // 0 for non-direct
1254     get_int("interface.analysis_servers"),
1255     get_short("interface.analysis_scheduling"),
1256     get_int("interface.asynch_local_analysis_concurrency"),
1257     false, // peer dynamic not supported
1258     std::max(1, (int)get_sa("interface.application.analysis_drivers").size()));
1259 }
1260 
1261 
min_procs_per_ie()1262 int ProblemDescDB::min_procs_per_ie()
1263 {
1264   // Note: get_*() requires envelope execution (throws error if !dbRep)
1265 
1266   return min_procs_per_level(min_procs_per_ea(),
1267 			     get_int("interface.processors_per_evaluation"),
1268 			     get_int("interface.evaluation_servers"));
1269 			   //get_short("interface.evaluation_scheduling"));
1270 }
1271 
1272 
max_procs_per_ie(int max_eval_concurrency)1273 int ProblemDescDB::max_procs_per_ie(int max_eval_concurrency)
1274 {
1275   // Note: get_*() requires envelope execution (throws error if !dbRep)
1276 
1277   // Define max_procs_per_iterator to estimate maximum processor usage
1278   // from all lower levels.  With default_config = PUSH_DOWN, this is
1279   // important to avoid pushing down more resources than can be utilized.
1280   // The primary input is algorithmic concurrency, but we also incorporate
1281   // explicit user overrides for _lower_ levels (user overrides for the
1282   // current level can be managed by resolve_inputs()).
1283 
1284   int max_ea   = max_procs_per_ea(),
1285       ppe_spec = get_int("interface.processors_per_evaluation"),
1286       max_pps  = (ppe_spec) ? ppe_spec : max_ea;
1287   // for peer dynamic, max_pps == 1 is imperfect in that it does not capture
1288   // all possibilities, but this is conservative and hopefully close enough
1289   // for this context (an upper bound estimate).
1290   bool peer_dynamic_avail = (get_short("interface.local_evaluation_scheduling")
1291 			     != STATIC_SCHEDULING && max_pps == 1);
1292 
1293   return max_procs_per_level(max_ea, ppe_spec,
1294     get_int("interface.evaluation_servers"),
1295     get_short("interface.evaluation_scheduling"),
1296     get_int("interface.asynch_local_evaluation_concurrency"),
1297     peer_dynamic_avail, max_eval_concurrency);
1298 }
1299 
1300 
1301  static void*
binsearch(void * kw,size_t kwsize,size_t n,const char * key)1302 binsearch(void *kw, size_t kwsize, size_t n, const char* key)
1303 {
1304 	/* Binary search, based loosely on b_search.c in the */
1305 	/* AMPL/solver interface library. */
1306 	char *ow, *ow1, *s;
1307 	int c;
1308 	size_t n1;
1309 
1310 	ow = (char*)kw;
1311 	while(n > 0) {
1312 		ow1 = ow + (n1 = n >> 1)*kwsize;
1313 		s = *(char **)ow1;
1314         if ((c = std::strcmp(key, s)) == 0)
1315 			return ow1;
1316 		if (c < 0)
1317 			n = n1;
1318 		else {
1319 			n -= n1 + 1;
1320 			ow = ow1 + kwsize;
1321 			}
1322 		}
1323 	return 0;
1324 	}
1325 
1326  static const char*
Begins(const String & entry_name,const char * s)1327 Begins(const String &entry_name, const char *s)
1328 {
1329 	const char *t, *t0;
1330 	t = entry_name.data();
1331 	while(*t++ == *s++)
1332 		if (!*s)
1333 			return t;
1334 	return 0;
1335 	}
1336 
1337 template<typename T, class A> struct KW {const char*key; T A::* p;};
1338 #define Binsearch(t,s) binsearch(t, sizeof(t[0]), sizeof(t)/sizeof(t[0]), s)
1339 // L is the length of the prefix already tested, e.g., 7 for "method."
1340 
Bad_name(String entry_name,const char * where)1341 static void Bad_name(String entry_name, const char *where)
1342 {
1343   Cerr << "\nBad entry_name in ProblemDescDB::" << where << ":  "
1344        << entry_name << std::endl;
1345   abort_handler(PARSE_ERROR);
1346 }
1347 
Locked_db()1348 static void Locked_db()
1349 {
1350   Cerr << "\nError: database is locked.  You must first unlock the database\n"
1351        << "       by setting the list nodes." << std::endl;
1352   abort_handler(PARSE_ERROR);
1353 }
1354 
Null_rep(const char * who)1355 static void Null_rep(const char *who)
1356 {
1357   Cerr << "\nError: ProblemDescDB::" << who
1358        << "() called with NULL representation." << std::endl;
1359   abort_handler(PARSE_ERROR);
1360 }
1361 
Null_rep1(const char * who)1362 static void Null_rep1(const char *who)
1363 {
1364   Cerr << "\nError: ProblemDescDB::" << who
1365        << " called with NULL representation." << std::endl;
1366   abort_handler(PARSE_ERROR);
1367 }
1368 
get_rma(const String & entry_name) const1369 const RealMatrixArray& ProblemDescDB::get_rma(const String& entry_name) const
1370 {
1371   const char *L;
1372 
1373   if (!dbRep)
1374 	Null_rep("get_rma");
1375   if ((L = Begins(entry_name, "variables."))) {
1376     if (dbRep->variablesDBLocked)
1377 	Locked_db();
1378     #define P &DataVariablesRep::
1379     static KW<RealMatrixArray, DataVariablesRep> RMAdv[] = {
1380       // must be sorted by string (key)
1381 	{"discrete_design_set_int.adjacency_matrix", P discreteDesignSetIntAdj},
1382 	{"discrete_design_set_real.adjacency_matrix", P discreteDesignSetRealAdj},
1383 	{"discrete_design_set_str.adjacency_matrix", P discreteDesignSetStrAdj}
1384 	};
1385     #undef P
1386     KW<RealMatrixArray, DataVariablesRep> *kw;
1387     if ((kw = (KW<RealMatrixArray, DataVariablesRep>*)Binsearch(RMAdv, L)))
1388 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1389   }
1390   Bad_name(entry_name, "get_rma");
1391   return abort_handler_t<const RealMatrixArray&>(PARSE_ERROR);
1392 }
1393 
1394 
get_rv(const String & entry_name) const1395 const RealVector& ProblemDescDB::get_rv(const String& entry_name) const
1396 {
1397   const char *L;
1398 
1399   if (!dbRep)
1400 	Null_rep("get_rv");
1401   if ((L = Begins(entry_name, "method."))) {
1402     if (dbRep->methodDBLocked)
1403 	Locked_db();
1404 
1405     #define P &DataMethodRep::
1406     static KW<RealVector, DataMethodRep> RVdme[] = {
1407       // must be sorted by string (key)
1408 	{"concurrent.parameter_sets", P concurrentParameterSets},
1409 	{"jega.distance_vector", P distanceVector},
1410 	{"jega.niche_vector", P nicheVector},
1411 	{"nond.data_dist_covariance", P dataDistCovariance},
1412 	{"nond.data_dist_means", P dataDistMeans},
1413 	{"nond.dimension_preference", P anisoDimPref},
1414 	{"nond.hyperprior_alphas", P hyperPriorAlphas},
1415 	{"nond.hyperprior_betas", P hyperPriorBetas},
1416 	{"nond.prediction_configs", P predictionConfigList},
1417 	{"nond.proposal_covariance_data", P proposalCovData},
1418 	{"nond.regression_noise_tolerance", P regressionNoiseTol},
1419 	{"parameter_study.final_point", P finalPoint},
1420 	{"parameter_study.list_of_points", P listOfPoints},
1421 	{"parameter_study.step_vector", P stepVector},
1422 	{"trust_region.initial_size", P trustRegionInitSize}};
1423     #undef P
1424 
1425     KW<RealVector, DataMethodRep> *kw;
1426     if ((kw = (KW<RealVector, DataMethodRep>*)Binsearch(RVdme, L)))
1427       return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
1428   }
1429   else if ((L = Begins(entry_name, "model."))) {
1430     if (dbRep->methodDBLocked)
1431 	Locked_db();
1432 
1433     #define P &DataModelRep::
1434     static KW<RealVector, DataModelRep> RVdmo[] = {
1435       // must be sorted by string (key)
1436 	{"nested.primary_response_mapping", P primaryRespCoeffs},
1437 	{"nested.secondary_response_mapping", P secondaryRespCoeffs},
1438 	{"simulation.solution_level_cost", P solutionLevelCost},
1439 	{"surrogate.kriging_correlations", P krigingCorrelations},
1440 	{"surrogate.kriging_max_correlations", P krigingMaxCorrelations},
1441 	{"surrogate.kriging_min_correlations", P krigingMinCorrelations}};
1442     #undef P
1443 
1444     KW<RealVector, DataModelRep> *kw;
1445     if ((kw = (KW<RealVector, DataModelRep>*)Binsearch(RVdmo, L)))
1446 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
1447   }
1448   else if ((L = Begins(entry_name, "variables."))) {
1449 
1450     #define P &DataVariablesRep::
1451     static KW<RealVector, DataVariablesRep> RVdv[] = {
1452       // must be sorted by string (key)
1453 	{"beta_uncertain.alphas", P betaUncAlphas},
1454 	{"beta_uncertain.betas", P betaUncBetas},
1455 	{"beta_uncertain.lower_bounds", P betaUncLowerBnds},
1456 	{"beta_uncertain.upper_bounds", P betaUncUpperBnds},
1457 	{"binomial_uncertain.prob_per_trial", P binomialUncProbPerTrial},
1458 	{"continuous_aleatory_uncertain.initial_point",
1459 	 P continuousAleatoryUncVars},
1460 	{"continuous_aleatory_uncertain.lower_bounds",
1461 	 P continuousAleatoryUncLowerBnds},
1462 	{"continuous_aleatory_uncertain.upper_bounds",
1463 	 P continuousAleatoryUncUpperBnds},
1464 	{"continuous_design.initial_point", P continuousDesignVars},
1465 	{"continuous_design.lower_bounds", P continuousDesignLowerBnds},
1466 	{"continuous_design.scales", P continuousDesignScales},
1467 	{"continuous_design.upper_bounds", P continuousDesignUpperBnds},
1468 	{"continuous_epistemic_uncertain.initial_point",
1469 	 P continuousEpistemicUncVars},
1470 	{"continuous_epistemic_uncertain.lower_bounds",
1471 	 P continuousEpistemicUncLowerBnds},
1472 	{"continuous_epistemic_uncertain.upper_bounds",
1473 	 P continuousEpistemicUncUpperBnds},
1474 	{"continuous_state.initial_state", P continuousStateVars},
1475 	{"continuous_state.lower_bounds", P continuousStateLowerBnds},
1476 	{"continuous_state.upper_bounds", P continuousStateUpperBnds},
1477 	{"discrete_aleatory_uncertain_real.initial_point",
1478 	 P discreteRealAleatoryUncVars},
1479 	{"discrete_aleatory_uncertain_real.lower_bounds",
1480 	 P discreteRealAleatoryUncLowerBnds},
1481 	{"discrete_aleatory_uncertain_real.upper_bounds",
1482 	 P discreteRealAleatoryUncUpperBnds},
1483 	{"discrete_design_set_real.initial_point", P discreteDesignSetRealVars},
1484 	{"discrete_design_set_real.lower_bounds",
1485 	 P discreteDesignSetRealLowerBnds},
1486 	{"discrete_design_set_real.upper_bounds",
1487 	 P discreteDesignSetRealUpperBnds},
1488 	{"discrete_epistemic_uncertain_real.initial_point",
1489 	 P discreteRealEpistemicUncVars},
1490 	{"discrete_epistemic_uncertain_real.lower_bounds",
1491 	 P discreteRealEpistemicUncLowerBnds},
1492 	{"discrete_epistemic_uncertain_real.upper_bounds",
1493 	 P discreteRealEpistemicUncUpperBnds},
1494 	{"discrete_state_set_real.initial_state", P discreteStateSetRealVars},
1495 	{"discrete_state_set_real.lower_bounds",
1496 	 P discreteStateSetRealLowerBnds},
1497 	{"discrete_state_set_real.upper_bounds",
1498 	 P discreteStateSetRealUpperBnds},
1499 	{"exponential_uncertain.betas", P exponentialUncBetas},
1500 	{"frechet_uncertain.alphas", P frechetUncAlphas},
1501 	{"frechet_uncertain.betas", P frechetUncBetas},
1502 	{"gamma_uncertain.alphas", P gammaUncAlphas},
1503 	{"gamma_uncertain.betas", P gammaUncBetas},
1504 	{"geometric_uncertain.prob_per_trial", P geometricUncProbPerTrial},
1505 	{"gumbel_uncertain.alphas", P gumbelUncAlphas},
1506 	{"gumbel_uncertain.betas", P gumbelUncBetas},
1507 	{"linear_equality_constraints", P linearEqConstraintCoeffs},
1508 	{"linear_equality_scales", P linearEqScales},
1509 	{"linear_equality_targets", P linearEqTargets},
1510 	{"linear_inequality_constraints", P linearIneqConstraintCoeffs},
1511 	{"linear_inequality_lower_bounds", P linearIneqLowerBnds},
1512 	{"linear_inequality_scales", P linearIneqScales},
1513 	{"linear_inequality_upper_bounds", P linearIneqUpperBnds},
1514 	{"lognormal_uncertain.error_factors", P lognormalUncErrFacts},
1515 	{"lognormal_uncertain.lambdas", P lognormalUncLambdas},
1516 	{"lognormal_uncertain.lower_bounds", P lognormalUncLowerBnds},
1517 	{"lognormal_uncertain.means", P lognormalUncMeans},
1518 	{"lognormal_uncertain.std_deviations", P lognormalUncStdDevs},
1519 	{"lognormal_uncertain.upper_bounds", P lognormalUncUpperBnds},
1520 	{"lognormal_uncertain.zetas", P lognormalUncZetas},
1521 	{"loguniform_uncertain.lower_bounds", P loguniformUncLowerBnds},
1522 	{"loguniform_uncertain.upper_bounds", P loguniformUncUpperBnds},
1523 	{"negative_binomial_uncertain.prob_per_trial",
1524 	 P negBinomialUncProbPerTrial},
1525 	{"normal_uncertain.lower_bounds", P normalUncLowerBnds},
1526 	{"normal_uncertain.means", P normalUncMeans},
1527 	{"normal_uncertain.std_deviations", P normalUncStdDevs},
1528 	{"normal_uncertain.upper_bounds", P normalUncUpperBnds},
1529 	{"poisson_uncertain.lambdas", P poissonUncLambdas},
1530 	{"triangular_uncertain.lower_bounds", P triangularUncLowerBnds},
1531 	{"triangular_uncertain.modes", P triangularUncModes},
1532 	{"triangular_uncertain.upper_bounds", P triangularUncUpperBnds},
1533 	{"uniform_uncertain.lower_bounds", P uniformUncLowerBnds},
1534 	{"uniform_uncertain.upper_bounds", P uniformUncUpperBnds},
1535 	{"weibull_uncertain.alphas", P weibullUncAlphas},
1536 	{"weibull_uncertain.betas", P weibullUncBetas}};
1537     #undef P
1538 
1539     KW<RealVector, DataVariablesRep> *kw;
1540     if ((kw = (KW<RealVector, DataVariablesRep>*)Binsearch(RVdv, L)))
1541 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1542   }
1543   else if (strbegins(entry_name, "interface.")) {
1544     if (dbRep->interfaceDBLocked)
1545 	Locked_db();
1546     else if (strends(entry_name, "failure_capture.recovery_fn_vals"))
1547       return dbRep->dataInterfaceIter->dataIfaceRep->recoveryFnVals;
1548   }
1549   else if ((L = Begins(entry_name, "responses."))) {
1550     if (dbRep->responsesDBLocked)
1551 	Locked_db();
1552 
1553     #define P &DataResponsesRep::
1554     static KW<RealVector, DataResponsesRep> RVdr[] = {
1555       // must be sorted by string (key)
1556 	{"exp_config_variables", P expConfigVars},
1557 	{"exp_observations", P expObservations},
1558 	{"exp_std_deviations", P expStdDeviations},
1559 	{"fd_gradient_step_size", P fdGradStepSize},
1560 	{"fd_hessian_step_size", P fdHessStepSize},
1561 	{"nonlinear_equality_scales", P nonlinearEqScales},
1562 	{"nonlinear_equality_targets", P nonlinearEqTargets},
1563 	{"nonlinear_inequality_lower_bounds", P nonlinearIneqLowerBnds},
1564 	{"nonlinear_inequality_scales", P nonlinearIneqScales},
1565 	{"nonlinear_inequality_upper_bounds", P nonlinearIneqUpperBnds},
1566 	{"primary_response_fn_scales", P primaryRespFnScales},
1567 	{"primary_response_fn_weights", P primaryRespFnWeights},
1568         {"simulation_variance", P simVariance}};
1569     #undef P
1570 
1571     KW<RealVector, DataResponsesRep> *kw;
1572     if ((kw = (KW<RealVector, DataResponsesRep>*)Binsearch(RVdr, L)))
1573 	return dbRep->dataResponsesIter->dataRespRep.get()->*kw->p;
1574   }
1575   Bad_name(entry_name, "get_rv");
1576   return abort_handler_t<const RealVector&>(PARSE_ERROR);
1577 }
1578 
1579 
get_iv(const String & entry_name) const1580 const IntVector& ProblemDescDB::get_iv(const String& entry_name) const
1581 {
1582   const char *L;
1583 
1584   if (!dbRep)
1585 	Null_rep("get_iv");
1586   if ((L = Begins(entry_name, "variables."))) {
1587     if (dbRep->variablesDBLocked)
1588 	Locked_db();
1589     #define P &DataVariablesRep::
1590     static KW<IntVector, DataVariablesRep> IVdv[] = {
1591       // must be sorted by string (key)
1592 	{"binomial_uncertain.num_trials", P binomialUncNumTrials},
1593 	{"discrete_aleatory_uncertain_int.initial_point",
1594 	 P discreteIntAleatoryUncVars},
1595 	{"discrete_aleatory_uncertain_int.lower_bounds",
1596 	 P discreteIntAleatoryUncLowerBnds},
1597 	{"discrete_aleatory_uncertain_int.upper_bounds",
1598 	 P discreteIntAleatoryUncUpperBnds},
1599 	{"discrete_design_range.initial_point", P discreteDesignRangeVars},
1600 	{"discrete_design_range.lower_bounds", P discreteDesignRangeLowerBnds},
1601 	{"discrete_design_range.upper_bounds", P discreteDesignRangeUpperBnds},
1602 	{"discrete_design_set_int.initial_point", P discreteDesignSetIntVars},
1603 	{"discrete_design_set_int.lower_bounds",
1604 	 P discreteDesignSetIntLowerBnds},
1605 	{"discrete_design_set_int.upper_bounds",
1606 	 P discreteDesignSetIntUpperBnds},
1607 	{"discrete_epistemic_uncertain_int.initial_point",
1608 	 P discreteIntEpistemicUncVars},
1609 	{"discrete_epistemic_uncertain_int.lower_bounds",
1610 	 P discreteIntEpistemicUncLowerBnds},
1611 	{"discrete_epistemic_uncertain_int.upper_bounds",
1612 	 P discreteIntEpistemicUncUpperBnds},
1613 	{"discrete_state_range.initial_state", P discreteStateRangeVars},
1614 	{"discrete_state_range.lower_bounds", P discreteStateRangeLowerBnds},
1615 	{"discrete_state_range.upper_bounds", P discreteStateRangeUpperBnds},
1616 	{"discrete_state_set_int.initial_state", P discreteStateSetIntVars},
1617 	{"discrete_state_set_int.lower_bounds", P discreteStateSetIntLowerBnds},
1618 	{"discrete_state_set_int.upper_bounds", P discreteStateSetIntUpperBnds},
1619 	{"hypergeometric_uncertain.num_drawn", P hyperGeomUncNumDrawn},
1620 	{"hypergeometric_uncertain.selected_population",
1621 	 P hyperGeomUncSelectedPop},
1622 	{"hypergeometric_uncertain.total_population", P hyperGeomUncTotalPop},
1623 	{"negative_binomial_uncertain.num_trials", P negBinomialUncNumTrials}};
1624     #undef P
1625 
1626     KW<IntVector, DataVariablesRep> *kw;
1627     if ((kw = (KW<IntVector, DataVariablesRep>*)Binsearch(IVdv, L)))
1628 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1629   }
1630   else if ((L = Begins(entry_name, "method."))) {
1631 	if (dbRep->methodDBLocked)
1632 		Locked_db();
1633     #define P &DataMethodRep::
1634     static KW<IntVector, DataMethodRep> IVdme[] = {
1635       // must be sorted by string (key)
1636 	{"fsu_quasi_mc.primeBase", P primeBase},
1637 	{"fsu_quasi_mc.sequenceLeap", P sequenceLeap},
1638 	{"fsu_quasi_mc.sequenceStart", P sequenceStart},
1639 	{"nond.refinement_samples", P refineSamples},
1640 	{"parameter_study.steps_per_variable", P stepsPerVariable}};
1641     #undef P
1642     KW<IntVector, DataMethodRep> *kw;
1643     if ((kw = (KW<IntVector, DataMethodRep>*)Binsearch(IVdme, L)))
1644 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
1645   }
1646   else if ((L = Begins(entry_name, "model."))) {
1647     if (dbRep->modelDBLocked)
1648       Locked_db();
1649     #define P &DataModelRep::
1650     static KW<IntVector, DataModelRep> IVdr[] = {
1651       // must be sorted by string (key)
1652       {"refinement_samples", P refineSamples}};
1653     #undef P
1654     KW<IntVector, DataModelRep> *kw;
1655     if ((kw = (KW<IntVector, DataModelRep>*)Binsearch(IVdr, L)))
1656       return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
1657   }
1658   else if ((L = Begins(entry_name, "responses."))) {
1659     if (dbRep->responsesDBLocked)
1660       Locked_db();
1661     #define P &DataResponsesRep::
1662     static KW<IntVector, DataResponsesRep> IVdr[] = {
1663       // must be sorted by string (key)
1664 	{"lengths", P fieldLengths},
1665 	{"num_coordinates_per_field", P numCoordsPerField}};
1666     #undef P
1667     KW<IntVector, DataResponsesRep> *kw;
1668     if ((kw = (KW<IntVector, DataResponsesRep>*)Binsearch(IVdr, L)))
1669       return dbRep->dataResponsesIter->dataRespRep.get()->*kw->p;
1670   }
1671   Bad_name(entry_name, "get_iv");
1672   return abort_handler_t<const IntVector&>(PARSE_ERROR);
1673 }
1674 
1675 
get_ba(const String & entry_name) const1676 const BitArray& ProblemDescDB::get_ba(const String& entry_name) const
1677 {
1678   const char *L;
1679 
1680   if (!dbRep)
1681   	Null_rep("get_ba");
1682   if ((L = Begins(entry_name, "variables."))) {
1683     if (dbRep->variablesDBLocked)
1684 	Locked_db();
1685     #define P &DataVariablesRep::
1686     static KW<BitArray, DataVariablesRep> BAdv[] = {
1687       // must be sorted by string (key)
1688 	{"binomial_uncertain.categorical", P binomialUncCat},
1689 	{"discrete_design_range.categorical", P discreteDesignRangeCat},
1690 	{"discrete_design_set_int.categorical", P discreteDesignSetIntCat},
1691 	{"discrete_design_set_real.categorical", P discreteDesignSetRealCat},
1692 	{"discrete_interval_uncertain.categorical", P discreteIntervalUncCat},
1693 	{"discrete_state_range.categorical", P discreteStateRangeCat},
1694 	{"discrete_state_set_int.categorical", P discreteStateSetIntCat},
1695 	{"discrete_state_set_real.categorical", P discreteStateSetRealCat},
1696 	{"discrete_uncertain_set_int.categorical", P discreteUncSetIntCat},
1697 	{"discrete_uncertain_set_real.categorical", P discreteUncSetRealCat},
1698 	{"geometric_uncertain.categorical", P geometricUncCat},
1699 	{"histogram_uncertain.point_int.categorical",
1700          P histogramUncPointIntCat},
1701 	{"histogram_uncertain.point_real.categorical",
1702          P histogramUncPointRealCat},
1703 	{"hypergeometric_uncertain.categorical", P hyperGeomUncCat},
1704 	{"negative_binomial_uncertain.categorical", P negBinomialUncCat},
1705 	{"poisson_uncertain.categorical", P poissonUncCat}};
1706     #undef P
1707 
1708     KW<BitArray, DataVariablesRep> *kw;
1709     if ((kw = (KW<BitArray, DataVariablesRep>*)Binsearch(BAdv, L)))
1710 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1711   }
1712 
1713   Bad_name(entry_name, "get_ba");
1714   return abort_handler_t<const BitArray&>(PARSE_ERROR);
1715 }
1716 
1717 
get_sza(const String & entry_name) const1718 const SizetArray& ProblemDescDB::get_sza(const String& entry_name) const
1719 {
1720   const char *L;
1721 
1722   if (!dbRep)
1723   	Null_rep("get_sza");
1724   if ((L = Begins(entry_name, "method."))) {
1725     if (dbRep->methodDBLocked)
1726 	Locked_db();
1727     #define P &DataMethodRep::
1728     static KW<SizetArray, DataMethodRep> SZAdme[] = {
1729       // must be sorted by string (key)
1730       {"nond.c3function_train.start_rank_sequence", P startRankSeq},
1731       {"nond.collocation_points", P collocationPointsSeq},
1732       {"nond.expansion_samples", P expansionSamplesSeq},
1733       {"nond.pilot_samples", P pilotSamples},
1734       {"random_seed_sequence", P randomSeedSeq}};
1735     #undef P
1736 
1737     KW<SizetArray, DataMethodRep> *kw;
1738     if ((kw = (KW<SizetArray, DataMethodRep>*)Binsearch(SZAdme, L)))
1739 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
1740   }
1741 
1742   Bad_name(entry_name, "get_sza");
1743   return abort_handler_t<const SizetArray&>(PARSE_ERROR);
1744 }
1745 
1746 
get_usa(const String & entry_name) const1747 const UShortArray& ProblemDescDB::get_usa(const String& entry_name) const
1748 {
1749   const char *L;
1750 
1751   if (!dbRep)
1752   	Null_rep("get_usa");
1753   if ((L = Begins(entry_name, "method."))) {
1754     if (dbRep->methodDBLocked)
1755 	Locked_db();
1756     #define P &DataMethodRep::
1757     static KW<UShortArray, DataMethodRep> USAdme[] = {
1758       // must be sorted by string (key)
1759 	{"nond.c3function_train.start_order_sequence", P startOrderSeq},
1760 	{"nond.expansion_order", P expansionOrderSeq},
1761 	{"nond.quadrature_order", P quadratureOrderSeq},
1762 	{"nond.sparse_grid_level", P sparseGridLevelSeq},
1763 	{"nond.tensor_grid_order", P tensorGridOrder},
1764 	{"partitions", P varPartitions}};
1765     #undef P
1766 
1767     KW<UShortArray, DataMethodRep> *kw;
1768     if ((kw = (KW<UShortArray, DataMethodRep>*)Binsearch(USAdme, L)))
1769 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
1770   }
1771 
1772   Bad_name(entry_name, "get_usa");
1773   return abort_handler_t<const UShortArray&>(PARSE_ERROR);
1774 }
1775 
1776 
get_rsm(const String & entry_name) const1777 const RealSymMatrix& ProblemDescDB::get_rsm(const String& entry_name) const
1778 {
1779   if (!dbRep)
1780 	Null_rep("get_rsm");
1781   if (strbegins(entry_name, "variables.")) {
1782     if (dbRep->variablesDBLocked)
1783 	Locked_db();
1784     if (strends(entry_name, "uncertain.correlation_matrix"))
1785       return dbRep->dataVariablesIter->dataVarsRep->uncertainCorrelations;
1786   }
1787   Bad_name(entry_name, "get_rsm");
1788   return abort_handler_t<const RealSymMatrix&>(PARSE_ERROR);
1789 }
1790 
1791 
get_rva(const String & entry_name) const1792 const RealVectorArray& ProblemDescDB::get_rva(const String& entry_name) const
1793 {
1794   const char *L;
1795 
1796   if (!dbRep)
1797     Null_rep("get_rva");
1798   if ((L = Begins(entry_name, "method."))) {
1799     if (dbRep->methodDBLocked)
1800 	Locked_db();
1801     #define P &DataMethodRep::
1802     static KW<RealVectorArray, DataMethodRep> RVAdme[] = {
1803       // must be sorted by string (key)
1804 	{"nond.gen_reliability_levels", P genReliabilityLevels},
1805 	{"nond.probability_levels", P probabilityLevels},
1806 	{"nond.reliability_levels", P reliabilityLevels},
1807 	{"nond.response_levels", P responseLevels}};
1808     #undef P
1809 
1810     KW<RealVectorArray, DataMethodRep> *kw;
1811     if ((kw = (KW<RealVectorArray, DataMethodRep>*)Binsearch(RVAdme, L)))
1812 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
1813   }
1814 
1815   Bad_name(entry_name, "get_rva");
1816   return abort_handler_t<const RealVectorArray&>(PARSE_ERROR);
1817 }
1818 
1819 
get_iva(const String & entry_name) const1820 const IntVectorArray& ProblemDescDB::get_iva(const String& entry_name) const
1821 {
1822   const char *L;
1823 
1824   if (!dbRep)
1825     Null_rep("get_iva");
1826   // BMA: no current use cases
1827   Bad_name(entry_name, "get_iva");
1828   return abort_handler_t<const IntVectorArray&>(PARSE_ERROR);
1829 }
1830 
1831 
get_is(const String & entry_name) const1832 const IntSet& ProblemDescDB::get_is(const String& entry_name) const
1833 {
1834   const char *L;
1835 
1836   if (!dbRep)
1837 	Null_rep("get_is");
1838   if (strbegins(entry_name, "model.")) {
1839     if (dbRep->modelDBLocked)
1840 	Locked_db();
1841     if (strends(entry_name, "surrogate.function_indices"))
1842       return dbRep->dataModelIter->dataModelRep->surrogateFnIndices;
1843   }
1844   else if ((L = Begins(entry_name, "responses."))) {
1845     if (dbRep->responsesDBLocked)
1846 	Locked_db();
1847     #define P &DataResponsesRep::
1848     static KW<IntSet, DataResponsesRep> ISdr[] = {
1849       // must be sorted by string (key)
1850 	{"gradients.mixed.id_analytic", P idAnalyticGrads},
1851 	{"gradients.mixed.id_numerical", P idNumericalGrads},
1852 	{"hessians.mixed.id_analytic", P idAnalyticHessians},
1853 	{"hessians.mixed.id_numerical", P idNumericalHessians},
1854 	{"hessians.mixed.id_quasi", P idQuasiHessians}};
1855     #undef P
1856 
1857     KW<IntSet, DataResponsesRep> *kw;
1858     if ((kw = (KW<IntSet, DataResponsesRep>*)Binsearch(ISdr, L)))
1859 	return dbRep->dataResponsesIter->dataRespRep.get()->*kw->p;
1860   }
1861   Bad_name(entry_name, "get_is");
1862   return abort_handler_t<const IntSet&>(PARSE_ERROR);
1863 }
1864 
1865 
get_isa(const String & entry_name) const1866 const IntSetArray& ProblemDescDB::get_isa(const String& entry_name) const
1867 {
1868   const char *L;
1869 
1870   if (!dbRep)
1871 	Null_rep("get_isa");
1872   if ((L = Begins(entry_name, "variables."))) {
1873     if (dbRep->variablesDBLocked)
1874 	Locked_db();
1875     #define P &DataVariablesRep::
1876     static KW<IntSetArray, DataVariablesRep> ISAdv[] = {
1877       // must be sorted by string (key)
1878 	{"discrete_design_set_int.values", P discreteDesignSetInt},
1879 	{"discrete_state_set_int.values", P discreteStateSetInt}};
1880     #undef P
1881 
1882     KW<IntSetArray, DataVariablesRep> *kw;
1883     if ((kw = (KW<IntSetArray, DataVariablesRep>*)Binsearch(ISAdv, L)))
1884 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1885   }
1886   Bad_name(entry_name, "get_isa");
1887   return abort_handler_t<const IntSetArray&>(PARSE_ERROR);
1888 }
1889 
get_ssa(const String & entry_name) const1890 const StringSetArray& ProblemDescDB::get_ssa(const String& entry_name) const
1891 {
1892   const char *L;
1893 
1894   if (!dbRep)
1895 	Null_rep("get_ssa");
1896   if ((L = Begins(entry_name, "variables."))) {
1897     if (dbRep->variablesDBLocked)
1898 	Locked_db();
1899     #define P &DataVariablesRep::
1900     static KW<StringSetArray, DataVariablesRep> SSAdv[] = {
1901       // must be sorted by string (key)
1902       {"discrete_design_set_string.values", P discreteDesignSetStr},
1903       {"discrete_state_set_string.values", P discreteStateSetStr}};
1904     #undef P
1905 
1906     KW<StringSetArray, DataVariablesRep> *kw;
1907     if ((kw = (KW<StringSetArray, DataVariablesRep>*)Binsearch(SSAdv, L)))
1908 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1909   }
1910   Bad_name(entry_name, "get_ssa");
1911   return abort_handler_t<const StringSetArray&>(PARSE_ERROR);
1912 }
1913 
1914 
get_rsa(const String & entry_name) const1915 const RealSetArray& ProblemDescDB::get_rsa(const String& entry_name) const
1916 {
1917   const char *L;
1918 
1919   if (!dbRep)
1920 	Null_rep("get_rsa()");
1921   if ((L = Begins(entry_name, "variables."))) {
1922     if (dbRep->variablesDBLocked)
1923 	Locked_db();
1924     #define P &DataVariablesRep::
1925     static KW<RealSetArray, DataVariablesRep> RSAdv[] = {
1926       // must be sorted by string (key)
1927 	{"discrete_design_set_real.values", P discreteDesignSetReal},
1928 	{"discrete_state_set_real.values", P discreteStateSetReal}};
1929     #undef P
1930 
1931     KW<RealSetArray, DataVariablesRep> *kw;
1932     if ((kw = (KW<RealSetArray, DataVariablesRep>*)Binsearch(RSAdv, L)))
1933 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1934   }
1935   Bad_name(entry_name, "get_rsa");
1936   return abort_handler_t<const RealSetArray&>(PARSE_ERROR);
1937 }
1938 
1939 
get_irma(const String & entry_name) const1940 const IntRealMapArray& ProblemDescDB::get_irma(const String& entry_name) const
1941 {
1942   const char *L;
1943 
1944   if (!dbRep)
1945 	Null_rep("get_irma");
1946   if ((L = Begins(entry_name, "variables."))) {
1947     if (dbRep->variablesDBLocked)
1948 	Locked_db();
1949     #define P &DataVariablesRep::
1950     static KW<IntRealMapArray, DataVariablesRep> IRMAdv[] = {
1951       // must be sorted by string (key)
1952 	{"discrete_uncertain_set_int.values_probs",
1953 	 P discreteUncSetIntValuesProbs},
1954 	{"histogram_uncertain.point_int_pairs", P histogramUncPointIntPairs}};
1955     #undef P
1956 
1957     KW<IntRealMapArray, DataVariablesRep> *kw;
1958     if ((kw = (KW<IntRealMapArray, DataVariablesRep>*)Binsearch(IRMAdv, L)))
1959 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1960   }
1961   Bad_name(entry_name, "get_irma");
1962   return abort_handler_t<const IntRealMapArray&>(PARSE_ERROR);
1963 }
1964 
get_srma(const String & entry_name) const1965 const StringRealMapArray& ProblemDescDB::get_srma(const String& entry_name) const
1966 {
1967   const char *L;
1968 
1969   if (!dbRep)
1970 	Null_rep("get_srma");
1971   if ((L = Begins(entry_name, "variables."))) {
1972     if (dbRep->variablesDBLocked)
1973 	Locked_db();
1974     #define P &DataVariablesRep::
1975     static KW<StringRealMapArray, DataVariablesRep> SRMAdv[] = {
1976       // must be sorted by string (key)
1977 	{"discrete_uncertain_set_string.values_probs",
1978 	 P discreteUncSetStrValuesProbs},
1979 	{"histogram_uncertain.point_string_pairs", P histogramUncPointStrPairs}};
1980     #undef P
1981 
1982     KW<StringRealMapArray, DataVariablesRep> *kw;
1983     if ((kw = (KW<StringRealMapArray, DataVariablesRep>*)Binsearch(SRMAdv, L)))
1984 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
1985   }
1986   Bad_name(entry_name, "get_srma");
1987   return abort_handler_t<const StringRealMapArray&>(PARSE_ERROR);
1988 }
1989 
1990 
get_rrma(const String & entry_name) const1991 const RealRealMapArray& ProblemDescDB::get_rrma(const String& entry_name) const
1992 {
1993   const char *L;
1994 
1995   if (!dbRep)
1996 	Null_rep("get_rrma()");
1997   if ((L = Begins(entry_name, "variables."))) {
1998     if (dbRep->variablesDBLocked)
1999 	Locked_db();
2000     #define P &DataVariablesRep::
2001     static KW<RealRealMapArray, DataVariablesRep> RRMAdv[] = {
2002       // must be sorted by string (key)
2003 	{"discrete_uncertain_set_real.values_probs",
2004 	 P discreteUncSetRealValuesProbs},
2005 	{"histogram_uncertain.bin_pairs",   P histogramUncBinPairs},
2006 	{"histogram_uncertain.point_real_pairs", P histogramUncPointRealPairs}};
2007     #undef P
2008 
2009     KW<RealRealMapArray, DataVariablesRep> *kw;
2010     if ((kw = (KW<RealRealMapArray, DataVariablesRep>*)Binsearch(RRMAdv, L)))
2011 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
2012   }
2013   Bad_name(entry_name, "get_rrma");
2014   return abort_handler_t<const RealRealMapArray&>(PARSE_ERROR);
2015 }
2016 
2017 
2018 const RealRealPairRealMapArray& ProblemDescDB::
get_rrrma(const String & entry_name) const2019 get_rrrma(const String& entry_name) const
2020 {
2021   const char *L;
2022 
2023   if (!dbRep)
2024 	Null_rep("get_rrrma()");
2025   if ((L = Begins(entry_name, "variables."))) {
2026     if (dbRep->variablesDBLocked)
2027 	Locked_db();
2028     #define P &DataVariablesRep::
2029     static KW<RealRealPairRealMapArray, DataVariablesRep> RRRMAdv[] = {
2030 
2031       // must be sorted by string (key)
2032       {"continuous_interval_uncertain.basic_probs",
2033        P continuousIntervalUncBasicProbs}};
2034     #undef P
2035 
2036     KW<RealRealPairRealMapArray, DataVariablesRep> *kw;
2037     if ((kw = (KW<RealRealPairRealMapArray, DataVariablesRep>*)
2038 	 Binsearch(RRRMAdv, L)))
2039 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
2040   }
2041   Bad_name(entry_name, "get_rrrma");
2042   return abort_handler_t<const RealRealPairRealMapArray&>(PARSE_ERROR);
2043 }
2044 
2045 
2046 const IntIntPairRealMapArray& ProblemDescDB::
get_iirma(const String & entry_name) const2047 get_iirma(const String& entry_name) const
2048 {
2049   const char *L;
2050 
2051   if (!dbRep)
2052 	Null_rep("get_iirma()");
2053   if ((L = Begins(entry_name, "variables."))) {
2054     if (dbRep->variablesDBLocked)
2055 	Locked_db();
2056     #define P &DataVariablesRep::
2057     static KW<IntIntPairRealMapArray, DataVariablesRep> IIRMAdv[] = {
2058 
2059       // must be sorted by string (key)
2060       {"discrete_interval_uncertain.basic_probs",
2061        P discreteIntervalUncBasicProbs}};
2062     #undef P
2063 
2064     KW<IntIntPairRealMapArray, DataVariablesRep> *kw;
2065     if ((kw = (KW<IntIntPairRealMapArray, DataVariablesRep>*)
2066 	 Binsearch(IIRMAdv, L)))
2067 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
2068   }
2069   Bad_name(entry_name, "get_iirma");
2070   return abort_handler_t<const IntIntPairRealMapArray&>(PARSE_ERROR);
2071 }
2072 
2073 
get_sa(const String & entry_name) const2074 const StringArray& ProblemDescDB::get_sa(const String& entry_name) const
2075 {
2076   const char *L;
2077 
2078   if (!dbRep)
2079 	Null_rep("get_sa");
2080   // if ((L = Begins(entry_name, "environment."))) {
2081   //   #define P &DataEnvironmentRep::
2082   //   static KW<StringArray, DataEnvironmentRep> SAenv[] = {
2083   //     // must be sorted by string (key)
2084   //     {"env_options", P envOptions}};
2085   //   #undef P
2086 
2087   //   KW<StringArray, DataEnvironmentRep> *kw;
2088   //   if ((kw = (KW<StringArray, DataEnvironmentRep>*)Binsearch(SAenv, L)))
2089   // 	return dbRep->environmentSpec.dataEnvRep.get()->*kw->p;
2090   // }
2091   // else
2092   if ((L = Begins(entry_name, "method."))) {
2093     if (dbRep->methodDBLocked)
2094 	Locked_db();
2095     #define P &DataMethodRep::
2096     static KW<StringArray, DataMethodRep> SAds[] = {
2097       // must be sorted by string (key)
2098 	{"coliny.misc_options", P miscOptions},
2099 	{"hybrid.method_names", P hybridMethodNames},
2100 	{"hybrid.method_pointers", P hybridMethodPointers},
2101 	{"hybrid.model_pointers", P hybridModelPointers}};
2102     #undef P
2103 
2104     KW<StringArray, DataMethodRep> *kw;
2105     if ((kw = (KW<StringArray, DataMethodRep>*)Binsearch(SAds, L)))
2106 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
2107   }
2108   else if ((L = Begins(entry_name, "model."))) {
2109     if (dbRep->modelDBLocked)
2110 	Locked_db();
2111     #define P &DataModelRep::
2112     static KW<StringArray, DataModelRep> SAdmo[] = {
2113       // must be sorted by string (key)
2114 	{"metrics", P diagMetrics},
2115 	{"nested.primary_variable_mapping", P primaryVarMaps},
2116 	{"nested.secondary_variable_mapping", P secondaryVarMaps},
2117 	{"surrogate.ordered_model_pointers", P orderedModelPointers}};
2118     #undef P
2119 
2120     KW<StringArray, DataModelRep> *kw;
2121     if ((kw = (KW<StringArray, DataModelRep>*)Binsearch(SAdmo, L)))
2122 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
2123   }
2124   else if ((L = Begins(entry_name, "variables."))) {
2125     if (dbRep->variablesDBLocked)
2126 	Locked_db();
2127     #define P &DataVariablesRep::
2128     static KW<StringArray, DataVariablesRep> SAdv[] = {
2129       // must be sorted by string (key)
2130 	{"continuous_aleatory_uncertain.labels", P continuousAleatoryUncLabels},
2131 	{"continuous_design.labels", P continuousDesignLabels},
2132 	{"continuous_design.scale_types", P continuousDesignScaleTypes},
2133 	{"continuous_epistemic_uncertain.labels",
2134 	 P continuousEpistemicUncLabels},
2135 	{"continuous_state.labels", P continuousStateLabels},
2136 	{"discrete_aleatory_uncertain_int.labels",
2137 	 P discreteIntAleatoryUncLabels},
2138 	{"discrete_aleatory_uncertain_real.labels",
2139 	 P discreteRealAleatoryUncLabels},
2140 	{"discrete_aleatory_uncertain_string.initial_point",
2141 	 P discreteStrAleatoryUncVars},
2142 	{"discrete_aleatory_uncertain_string.labels",
2143 	 P discreteStrAleatoryUncLabels},
2144 	{"discrete_aleatory_uncertain_string.lower_bounds",
2145 	 P discreteStrAleatoryUncLowerBnds},
2146 	{"discrete_aleatory_uncertain_string.upper_bounds",
2147 	 P discreteStrAleatoryUncUpperBnds},
2148 	{"discrete_design_range.labels", P discreteDesignRangeLabels},
2149 	{"discrete_design_set_int.labels", P discreteDesignSetIntLabels},
2150 	{"discrete_design_set_real.labels", P discreteDesignSetRealLabels},
2151 	{"discrete_design_set_string.initial_point", P discreteDesignSetStrVars},
2152 	{"discrete_design_set_string.labels", P discreteDesignSetStrLabels},
2153 	{"discrete_design_set_string.lower_bounds", P discreteDesignSetStrLowerBnds},
2154 	{"discrete_design_set_string.upper_bounds", P discreteDesignSetStrUpperBnds},
2155 	{"discrete_epistemic_uncertain_int.labels",
2156 	 P discreteIntEpistemicUncLabels},
2157 	{"discrete_epistemic_uncertain_real.labels",
2158 	 P discreteRealEpistemicUncLabels},
2159 	{"discrete_epistemic_uncertain_string.initial_point",
2160 	 P discreteStrEpistemicUncVars},
2161 	{"discrete_epistemic_uncertain_string.labels",
2162 	 P discreteStrEpistemicUncLabels},
2163 	{"discrete_epistemic_uncertain_string.lower_bounds",
2164 	 P discreteStrEpistemicUncLowerBnds},
2165 	{"discrete_epistemic_uncertain_string.upper_bounds",
2166 	 P discreteStrEpistemicUncUpperBnds},
2167 	{"discrete_state_range.labels", P discreteStateRangeLabels},
2168 	{"discrete_state_set_int.labels", P discreteStateSetIntLabels},
2169 	{"discrete_state_set_real.labels", P discreteStateSetRealLabels},
2170 	{"discrete_state_set_string.initial_state", P discreteStateSetStrVars},
2171 	{"discrete_state_set_string.labels", P discreteStateSetStrLabels},
2172 	{"discrete_state_set_string.lower_bounds", P discreteStateSetStrLowerBnds},
2173 	{"discrete_state_set_string.upper_bounds", P discreteStateSetStrUpperBnds},
2174 	{"discrete_uncertain_set_string.initial_point", P discreteUncSetStrVars},
2175 	{"linear_equality_scale_types", P linearEqScaleTypes},
2176 	{"linear_inequality_scale_types", P linearIneqScaleTypes}};
2177     #undef P
2178 
2179     KW<StringArray, DataVariablesRep> *kw;
2180     if ((kw = (KW<StringArray, DataVariablesRep>*)Binsearch(SAdv, L)))
2181 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
2182   }
2183   else if ((L = Begins(entry_name, "interface."))) {
2184     if (dbRep->interfaceDBLocked)
2185 	Locked_db();
2186     #define P &DataInterfaceRep::
2187     static KW<StringArray, DataInterfaceRep> SAdi[] = {
2188       // must be sorted by string (key)
2189 	{ "application.analysis_drivers", P analysisDrivers},
2190 	{ "copyFiles", P copyFiles},
2191 	{ "linkFiles", P linkFiles}};
2192     #undef P
2193 
2194     KW<StringArray, DataInterfaceRep> *kw;
2195     if ((kw = (KW<StringArray, DataInterfaceRep>*)Binsearch(SAdi, L)))
2196 	return dbRep->dataInterfaceIter->dataIfaceRep.get()->*kw->p;
2197   }
2198   else if ((L = Begins(entry_name, "responses."))) {
2199     if (dbRep->responsesDBLocked)
2200 	Locked_db();
2201     #define P &DataResponsesRep::
2202     static KW<StringArray, DataResponsesRep> SAdr[] = {
2203       // must be sorted by string (key)
2204 	{ "labels", P responseLabels},
2205 	{ "nonlinear_equality_scale_types", P nonlinearEqScaleTypes},
2206 	{ "nonlinear_inequality_scale_types", P nonlinearIneqScaleTypes},
2207 	{ "primary_response_fn_scale_types", P primaryRespFnScaleTypes},
2208 	{ "primary_response_fn_sense", P primaryRespFnSense},
2209 	{ "variance_type", P varianceType}};
2210     #undef P
2211 
2212     KW<StringArray, DataResponsesRep> *kw;
2213     if ((kw = (KW<StringArray, DataResponsesRep>*)Binsearch(SAdr, L)))
2214 	return dbRep->dataResponsesIter->dataRespRep.get()->*kw->p;
2215   }
2216   Bad_name(entry_name, "get_sa");
2217   return abort_handler_t<const StringArray&>(PARSE_ERROR);
2218 }
2219 
2220 
get_s2a(const String & entry_name) const2221 const String2DArray& ProblemDescDB::get_s2a(const String& entry_name) const
2222 {
2223   if (!dbRep)
2224 	Null_rep("get_2sa");
2225   if (strbegins(entry_name, "interface.")) {
2226     if (dbRep->interfaceDBLocked)
2227 	Locked_db();
2228     if (strends(entry_name, "application.analysis_components"))
2229       return dbRep->dataInterfaceIter->dataIfaceRep->analysisComponents;
2230   }
2231   Bad_name(entry_name, "get_s2a");
2232   return abort_handler_t<const String2DArray&>(PARSE_ERROR);
2233 }
2234 
2235 
get_string(const String & entry_name) const2236 const String& ProblemDescDB::get_string(const String& entry_name) const
2237 {
2238   const char *L;
2239 
2240   if (!dbRep)
2241 	Null_rep("get_string");
2242   if ((L = Begins(entry_name, "environment."))) {
2243     #define P &DataEnvironmentRep::
2244     static KW<String, DataEnvironmentRep> Sde[] = {
2245       // must be sorted by string (key)
2246 	{"error_file", P errorFile},
2247 	{"output_file", P outputFile},
2248 	{"post_run_input", P postRunInput},
2249 	{"post_run_output", P postRunOutput},
2250 	{"pre_run_input", P preRunInput},
2251 	{"pre_run_output", P preRunOutput},
2252 	{"read_restart", P readRestart},
2253 	{"results_output_file", P resultsOutputFile},
2254 	{"run_input", P runInput},
2255 	{"run_output", P runOutput},
2256 	{"tabular_graphics_file", P tabularDataFile},
2257 	{"top_method_pointer", P topMethodPointer},
2258 	{"write_restart", P writeRestart}};
2259     #undef P
2260 
2261     KW<String, DataEnvironmentRep> *kw;
2262     if ((kw = (KW<String, DataEnvironmentRep>*)Binsearch(Sde, L)))
2263       return dbRep->environmentSpec.dataEnvRep.get()->*kw->p;
2264   }
2265   else if ((L = Begins(entry_name, "method."))) {
2266     if (dbRep->methodDBLocked)
2267 	Locked_db();
2268     #define P &DataMethodRep::
2269     static KW<String, DataMethodRep> Sdme[] = {
2270       // must be sorted by string (key)
2271 	{"advanced_options_file", P advancedOptionsFilename},
2272 	{"asynch_pattern_search.merit_function", P meritFunction},
2273 	{"batch_selection", P batchSelectionType},
2274 	{"coliny.beta_solver_name", P betaSolverName},
2275 	{"coliny.division", P boxDivision},
2276 	{"coliny.exploratory_moves", P exploratoryMoves},
2277 	{"coliny.pattern_basis", P patternBasis},
2278 	{"crossover_type", P crossoverType},
2279 	{"dl_solver.dlDetails", P dlDetails},
2280 	{"export_approx_points_file", P exportApproxPtsFile},
2281 	{"fitness_metric", P fitnessMetricType},
2282 	{"fitness_type", P fitnessType},
2283 	{"flat_file", P flatFile},
2284 	{"hybrid.global_method_name", P hybridGlobalMethodName},
2285 	{"hybrid.global_method_pointer", P hybridGlobalMethodPointer},
2286 	{"hybrid.global_model_pointer", P hybridGlobalModelPointer},
2287 	{"hybrid.local_method_name", P hybridLocalMethodName},
2288 	{"hybrid.local_method_pointer", P hybridLocalMethodPointer},
2289 	{"hybrid.local_model_pointer", P hybridLocalModelPointer},
2290 	{"id", P idMethod},
2291 	{"import_approx_points_file", P importApproxPtsFile},
2292 	{"import_build_points_file", P importBuildPtsFile},
2293 	{"import_candidate_points_file", P importCandPtsFile},
2294 	{"import_prediction_configs", P importPredConfigs},
2295 	{"initialization_type", P initializationType},
2296 	{"jega.convergence_type", P convergenceType},
2297 	{"jega.niching_type", P nichingType},
2298 	{"jega.postprocessor_type", P postProcessorType},
2299 	{"lipschitz", P lipschitzType},
2300 	{"log_file", P logFile},
2301 	{"low_fidelity_model_pointer", P lowFidModelPointer},
2302 	{"mesh_adaptive_search.display_format", P displayFormat},
2303 	{"mesh_adaptive_search.history_file", P historyFile},
2304 	{"mesh_adaptive_search.use_surrogate", P useSurrogate},
2305 	{"model_export_prefix", P modelExportPrefix},
2306 	{"model_pointer", P modelPointer},
2307 	{"mutation_type", P mutationType},
2308 	{"nond.data_dist_cov_type", P dataDistCovInputType},
2309         {"nond.data_dist_filename", P dataDistFile},
2310 	{"nond.data_dist_type", P dataDistType},
2311 	{"nond.discrepancy_type", P modelDiscrepancyType},
2312       //{"nond.expansion_sample_type", P expansionSampleType},
2313 	{"nond.export_corrected_model_file", P exportCorrModelFile},
2314 	{"nond.export_corrected_variance_file", P exportCorrVarFile},
2315 	{"nond.export_discrepancy_file", P exportDiscrepFile},
2316 	{"nond.export_expansion_file", P exportExpansionFile},
2317 	{"nond.export_mcmc_points_file", P exportMCMCPtsFile},
2318 	{"nond.import_expansion_file", P importExpansionFile},
2319 	{"nond.mcmc_type", P mcmcType},
2320 	{"nond.point_reuse", P pointReuse},
2321 	{"nond.posterior_density_export_file", P posteriorDensityExportFilename},
2322 	{"nond.posterior_samples_export_file", P posteriorSamplesExportFilename},
2323 	{"nond.posterior_samples_import_file", P posteriorSamplesImportFilename},
2324 	{"nond.proposal_covariance_filename", P proposalCovFile},
2325 	{"nond.proposal_covariance_input_type", P proposalCovInputType},
2326 	{"nond.proposal_covariance_type", P proposalCovType},
2327 	{"nond.reliability_integration", P reliabilityIntegration},
2328 	{"optpp.search_method", P searchMethod},
2329 	{"pattern_search.synchronization", P evalSynchronize},
2330 	{"pstudy.import_file", P pstudyFilename},
2331 	{"random_number_generator", P rngName},
2332 	{"replacement_type", P replacementType},
2333 	{"sub_method_name", P subMethodName},
2334 	{"sub_method_pointer", P subMethodPointer},
2335 	{"sub_model_pointer", P subModelPointer},
2336 	{"trial_type", P trialType}};
2337     #undef P
2338 
2339     KW<String, DataMethodRep> *kw;
2340     if ((kw = (KW<String, DataMethodRep>*)Binsearch(Sdme, L)))
2341 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
2342   }
2343   else if ((L = Begins(entry_name, "model."))) {
2344     if (dbRep->modelDBLocked)
2345 	Locked_db();
2346     #define P &DataModelRep::
2347     static KW<String, DataModelRep> Sdmo[] = {
2348       // must be sorted by string (key)
2349 	{"advanced_options_file", P advancedOptionsFilename},
2350 	{"dace_method_pointer", P subMethodPointer},
2351 	{"id", P idModel},
2352 	{"interface_pointer", P interfacePointer},
2353 	{"nested.sub_method_pointer", P subMethodPointer},
2354 	{"optional_interface_responses_pointer", P optionalInterfRespPointer},
2355 	{"rf.propagation_model_pointer", P propagationModelPointer},
2356 	{"rf_data_file", P rfDataFileName},
2357 	{"simulation.solution_level_control", P solutionLevelControl},
2358 	{"surrogate.actual_model_pointer", P actualModelPointer},
2359 	{"surrogate.challenge_points_file", P importChallengePtsFile},
2360 	{"surrogate.decomp_cell_type", P decompCellType},
2361 	{"surrogate.export_approx_points_file", P exportApproxPtsFile},
2362 	{"surrogate.export_approx_variance_file", P exportApproxVarianceFile},
2363 	{"surrogate.import_build_points_file", P importBuildPtsFile},
2364 	{"surrogate.kriging_opt_method", P krigingOptMethod},
2365 	{"surrogate.mars_interpolation", P marsInterpolation},
2366 	{"surrogate.model_export_prefix", P modelExportPrefix},
2367 	{"surrogate.point_reuse", P approxPointReuse},
2368 	{"surrogate.refine_cv_metric", P refineCVMetric},
2369         {"surrogate.trend_order", P trendOrder},
2370 	{"surrogate.type", P surrogateType},
2371 	{"type", P modelType}};
2372     #undef P
2373 
2374     KW<String, DataModelRep> *kw;
2375     if ((kw = (KW<String, DataModelRep>*)Binsearch(Sdmo, L)))
2376 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
2377   }
2378   else if (strbegins(entry_name, "variables.")) {
2379     if (dbRep->variablesDBLocked)
2380 	Locked_db();
2381     if (strends(entry_name, "id"))
2382       return dbRep->dataVariablesIter->dataVarsRep->idVariables;
2383   }
2384   else if ((L = Begins(entry_name, "interface."))) {
2385     if (dbRep->interfaceDBLocked)
2386 	Locked_db();
2387     #define P &DataInterfaceRep::
2388     static KW<String, DataInterfaceRep> Sdi[] = {
2389       // must be sorted by string (key)
2390 	{"algebraic_mappings", P algebraicMappings},
2391 	{"application.input_filter", P inputFilter},
2392 	{"application.output_filter", P outputFilter},
2393 	{"application.parameters_file", P parametersFile},
2394 	{"application.results_file", P resultsFile},
2395 	{"failure_capture.action", P failAction},
2396 	{"id", P idInterface},
2397 	{"workDir", P workDir}};
2398     #undef P
2399 
2400     KW<String, DataInterfaceRep> *kw;
2401     if ((kw = (KW<String, DataInterfaceRep>*)Binsearch(Sdi, L)))
2402 	return dbRep->dataInterfaceIter->dataIfaceRep.get()->*kw->p;
2403   }
2404   else if ((L = Begins(entry_name, "responses."))) {
2405     if (dbRep->responsesDBLocked)
2406 	Locked_db();
2407     #define P &DataResponsesRep::
2408     static KW<String, DataResponsesRep> Sdr[] = {
2409       // must be sorted by string (key)
2410 	{"fd_gradient_step_type", P fdGradStepType},
2411 	{"fd_hessian_step_type", P fdHessStepType},
2412 	{"gradient_type", P gradientType},
2413 	{"hessian_type", P hessianType},
2414 	{"id", P idResponses},
2415 	{"interval_type", P intervalType},
2416 	{"method_source", P methodSource},
2417 	{"quasi_hessian_type", P quasiHessianType},
2418 	{"scalar_data_filename", P scalarDataFileName}};
2419     #undef P
2420 
2421     KW<String, DataResponsesRep> *kw;
2422     if ((kw = (KW<String, DataResponsesRep>*)Binsearch(Sdr, L)))
2423 	return dbRep->dataResponsesIter->dataRespRep.get()->*kw->p;
2424 
2425   }
2426   Bad_name(entry_name, "get_string");
2427   return abort_handler_t<const String&>(PARSE_ERROR);
2428 }
2429 
2430 
get_real(const String & entry_name) const2431 const Real& ProblemDescDB::get_real(const String& entry_name) const
2432 {
2433   const char *L;
2434 
2435   if (!dbRep)
2436 	Null_rep("get_real");
2437   if ((L = Begins(entry_name, "method."))) {
2438     if (dbRep->methodDBLocked)
2439 	Locked_db();
2440     #define P &DataMethodRep::
2441     static KW<Real, DataMethodRep> Rdme[] = {
2442       // must be sorted by string (key)
2443       {"asynch_pattern_search.constraint_penalty", P constrPenalty},
2444       {"asynch_pattern_search.contraction_factor", P contractStepLength},
2445       {"asynch_pattern_search.initial_delta", P initStepLength},
2446       {"asynch_pattern_search.smoothing_factor", P smoothFactor},
2447       {"asynch_pattern_search.solution_target", P solnTarget},
2448       {"coliny.contraction_factor", P contractFactor},
2449       {"coliny.global_balance_parameter", P globalBalanceParam},
2450       {"coliny.initial_delta", P initDelta},
2451       {"coliny.local_balance_parameter", P localBalanceParam},
2452       {"coliny.max_boxsize_limit", P maxBoxSize},
2453       {"coliny.variable_tolerance", P threshDelta},
2454       {"confidence_level", P wilksConfidenceLevel},
2455       {"constraint_penalty", P constraintPenalty},
2456       {"constraint_tolerance", P constraintTolerance},
2457       {"convergence_tolerance", P convergenceTolerance},
2458       {"crossover_rate", P crossoverRate},
2459       {"dream.gr_threshold", P grThreshold},
2460       {"function_precision", P functionPrecision},
2461       {"gradient_tolerance", P gradientTolerance},
2462       {"hybrid.local_search_probability", P hybridLSProb},
2463       {"jega.fitness_limit", P fitnessLimit},
2464       {"jega.percent_change", P convergenceTolerance},
2465       {"jega.shrinkage_percentage", P shrinkagePercent},
2466       {"mesh_adaptive_search.initial_delta", P initMeshSize},
2467       {"mesh_adaptive_search.variable_neighborhood_search", P vns},
2468       {"mesh_adaptive_search.variable_tolerance", P minMeshSize},
2469       {"min_boxsize_limit", P minBoxSize},
2470       {"mutation_rate", P mutationRate},
2471       {"mutation_scale", P mutationScale},
2472       {"nl2sol.absolute_conv_tol", P absConvTol},
2473       {"nl2sol.false_conv_tol", P falseConvTol},
2474       {"nl2sol.initial_trust_radius", P initTRRadius},
2475       {"nl2sol.singular_conv_tol", P singConvTol},
2476       {"nl2sol.singular_radius", P singRadius},
2477       {"nond.c3function_train.solver_rounding_tolerance", P solverRoundingTol},
2478       {"nond.c3function_train.solver_tolerance", P solverTol},
2479       {"nond.c3function_train.stats_rounding_tolerance", P statsRoundingTol},
2480       {"nond.collocation_ratio", P collocationRatio},
2481       {"nond.collocation_ratio_terms_order", P collocRatioTermsOrder},
2482       {"nond.multilevel_estimator_rate", P multilevEstimatorRate},
2483       {"nond.regression_penalty", P regressionL2Penalty},
2484       {"npsol.linesearch_tolerance", P lineSearchTolerance},
2485       {"optpp.centering_parameter", P centeringParam},
2486       {"optpp.max_step", P maxStep},
2487       {"optpp.steplength_to_boundary", P stepLenToBoundary},
2488       {"percent_variance_explained", P percentVarianceExplained},
2489       {"prior_prop_cov_mult", P priorPropCovMult},
2490       {"solution_target", P solnTarget},
2491       {"trust_region.contract_threshold", P trustRegionContractTrigger},
2492       {"trust_region.contraction_factor", P trustRegionContract},
2493       {"trust_region.expand_threshold", P trustRegionExpandTrigger},
2494       {"trust_region.expansion_factor", P trustRegionExpand},
2495       {"trust_region.minimum_size", P trustRegionMinSize},
2496       {"variable_tolerance", P threshStepLength},
2497       {"vbd_drop_tolerance", P vbdDropTolerance},
2498       {"verification.refinement_rate", P refinementRate},
2499       {"volume_boxsize_limit", P volBoxSize},
2500       {"x_conv_tol", P xConvTol}};
2501     #undef P
2502 
2503     KW<Real, DataMethodRep> *kw;
2504     if ((kw = (KW<Real, DataMethodRep>*)Binsearch(Rdme, L)))
2505 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
2506   }
2507   else if ((L = Begins(entry_name, "model."))) {
2508     if (dbRep->modelDBLocked)
2509 	Locked_db();
2510     #define P &DataModelRep::
2511     static KW<Real, DataModelRep> Rdmo[] = {
2512       // must be sorted by string (key)
2513       {"active_subspace.cv.decrease_tolerance", P decreaseTolerance},
2514       {"active_subspace.cv.relative_tolerance", P relTolerance},
2515       {"active_subspace.truncation_method.energy.truncation_tolerance",
2516        P truncationTolerance},
2517       {"adapted_basis.collocation_ratio", P adaptedBasisCollocRatio},
2518       {"c3function_train.collocation_ratio", P collocationRatio},
2519       {"c3function_train.solver_rounding_tolerance", P solverRoundingTol},
2520       {"c3function_train.solver_tolerance", P solverTol},
2521       {"c3function_train.stats_rounding_tolerance", P statsRoundingTol},
2522       {"convergence_tolerance", P convergenceTolerance},
2523       {"surrogate.discont_grad_thresh", P discontGradThresh},
2524       {"surrogate.discont_jump_thresh", P discontJumpThresh},
2525       {"surrogate.neural_network_range", P annRange},
2526       {"surrogate.nugget", P krigingNugget},
2527       {"surrogate.percent", P percentFold},
2528       {"surrogate.regression_penalty", P regressionL2Penalty},
2529       {"truncation_tolerance", P truncationTolerance}};
2530     #undef P
2531 
2532     KW<Real, DataModelRep> *kw;
2533     if ((kw = (KW<Real, DataModelRep>*)Binsearch(Rdmo, L)))
2534 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
2535   }
2536   else if (strbegins(entry_name, "interface.")) {
2537     if (strends(entry_name, "nearby_evaluation_cache_tolerance"))
2538       return dbRep->dataInterfaceIter->dataIfaceRep->nearbyEvalCacheTol;
2539   }
2540   Bad_name(entry_name, "get_real");
2541   return abort_handler_t<const Real&>(PARSE_ERROR);
2542 }
2543 
2544 
get_int(const String & entry_name) const2545 int ProblemDescDB::get_int(const String& entry_name) const
2546 {
2547   const char *L;
2548 
2549   if (!dbRep)
2550 	Null_rep("get_int");
2551   if ((L = Begins(entry_name, "environment."))) {
2552     #define P &DataEnvironmentRep::
2553     static KW<int, DataEnvironmentRep> Ide[] = {
2554       // must be sorted by string (key)
2555         {"output_precision", P outputPrecision},
2556         {"stop_restart", P stopRestart}};
2557     #undef P
2558 
2559     KW<int, DataEnvironmentRep> *kw;
2560     if ((kw = (KW<int, DataEnvironmentRep>*)Binsearch(Ide, L)))
2561       return dbRep->environmentSpec.dataEnvRep.get()->*kw->p;
2562   }
2563   else if ((L = Begins(entry_name, "method."))) {
2564     if (dbRep->methodDBLocked)
2565 	Locked_db();
2566     #define P &DataMethodRep::
2567     static KW<int, DataMethodRep> Idme[] = {
2568       // must be sorted by string (key)
2569 	{"batch_size", P batchSize},
2570 	{"batch_size.exploration", P batchSizeExplore},
2571 	{"build_samples", P buildSamples},
2572 	{"burn_in_samples", P burnInSamples},
2573 	{"coliny.contract_after_failure", P contractAfterFail},
2574 	{"coliny.expand_after_success", P expandAfterSuccess},
2575 	{"coliny.mutation_range", P mutationRange},
2576 	{"coliny.new_solutions_generated", P newSolnsGenerated},
2577 	{"coliny.number_retained", P numberRetained},
2578 	{"coliny.total_pattern_size", P totalPatternSize},
2579 	{"concurrent.random_jobs", P concurrentRandomJobs},
2580 	{"dream.crossover_chain_pairs", P crossoverChainPairs},
2581 	{"dream.jump_step", P jumpStep},
2582 	{"dream.num_chains", P numChains},
2583 	{"dream.num_cr", P numCR},
2584 	{"evidence_samples", P evidenceSamples},
2585 	{"fsu_cvt.num_trials", P numTrials},
2586 	{"iterator_servers", P iteratorServers},
2587 	{"max_function_evaluations", P maxFunctionEvaluations},
2588 	{"max_hifi_evaluations", P maxHifiEvals},
2589 	{"max_iterations", P maxIterations},
2590 	{"mesh_adaptive_search.neighbor_order", P neighborOrder},
2591 	{"nl2sol.covariance", P covarianceType},
2592         {"nond.c3function_train.max_cross_iterations", P maxCrossIterations},
2593 	{"nond.chain_samples", P chainSamples},
2594 	{"nond.max_refinement_iterations", P maxRefineIterations},
2595 	{"nond.max_solver_iterations", P maxSolverIterations},
2596 	{"nond.prop_cov_update_period", P proposalCovUpdatePeriod},
2597 	{"nond.pushforward_samples", P numPushforwardSamples},
2598 	{"nond.samples_on_emulator", P samplesOnEmulator},
2599   {"nond.surrogate_order", P emulatorOrder},
2600 	{"npsol.verify_level", P verifyLevel},
2601 	{"optpp.search_scheme_size", P searchSchemeSize},
2602 	{"parameter_study.num_steps", P numSteps},
2603 	{"population_size", P populationSize},
2604 	{"processors_per_iterator", P procsPerIterator},
2605 	{"random_seed", P randomSeed},
2606 	{"samples", P numSamples},
2607 	{"sub_sampling_period", P subSamplingPeriod},
2608 	{"symbols", P numSymbols}};
2609     #undef P
2610 
2611     KW<int, DataMethodRep> *kw;
2612     if ((kw = (KW<int, DataMethodRep>*)Binsearch(Idme, L)))
2613 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
2614   }
2615   else if ((L = Begins(entry_name, "model."))) {
2616     if (dbRep->modelDBLocked)
2617 	Locked_db();
2618     #define P &DataModelRep::
2619     static KW<int, DataModelRep> Idmo[] = {
2620       // must be sorted by string (key)
2621         {"active_subspace.bootstrap_samples", P numReplicates},
2622         {"active_subspace.cv.max_rank", P subspaceCVMaxRank},
2623         {"c3function_train.max_cross_iterations", P maxCrossIterations},
2624         {"initial_samples", P initialSamples},
2625         {"max_function_evals", P maxFunctionEvals},
2626         {"max_iterations", P maxIterations},
2627 	{"max_solver_iterations", P maxSolverIterations},
2628         {"nested.iterator_servers", P subMethodServers},
2629         {"nested.processors_per_iterator", P subMethodProcs},
2630         {"rf.expansion_bases", P subspaceDimension},
2631         {"soft_convergence_limit", P softConvergenceLimit},
2632         {"subspace.dimension", P subspaceDimension},
2633         {"surrogate.decomp_support_layers", P decompSupportLayers},
2634         {"surrogate.folds", P numFolds},
2635         {"surrogate.num_restarts", P numRestarts},
2636         {"surrogate.points_total", P pointsTotal},
2637         {"surrogate.refine_cv_folds", P refineCVFolds}};
2638     #undef P
2639 
2640     KW<int, DataModelRep> *kw;
2641     if ((kw = (KW<int, DataModelRep>*)Binsearch(Idmo, L)))
2642 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
2643   }
2644   else if ((L = Begins(entry_name, "interface."))) {
2645     if (dbRep->interfaceDBLocked)
2646 	Locked_db();
2647     #define P &DataInterfaceRep::
2648     static KW<int, DataInterfaceRep> Idi[] = {
2649       // must be sorted by string (key)
2650 	{"analysis_servers", P analysisServers},
2651 	{"asynch_local_analysis_concurrency", P asynchLocalAnalysisConcurrency},
2652 	{"asynch_local_evaluation_concurrency", P asynchLocalEvalConcurrency},
2653 	{"direct.processors_per_analysis", P procsPerAnalysis},
2654 	{"evaluation_servers", P evalServers},
2655 	{"failure_capture.retry_limit", P retryLimit},
2656 	{"processors_per_evaluation", P procsPerEval}};
2657     #undef P
2658 
2659     KW<int, DataInterfaceRep> *kw;
2660     if ((kw = (KW<int, DataInterfaceRep>*)Binsearch(Idi, L)))
2661 	return dbRep->dataInterfaceIter->dataIfaceRep.get()->*kw->p;
2662   }
2663   Bad_name(entry_name, "get_int");
2664   return abort_handler_t<int>(PARSE_ERROR);
2665 }
2666 
2667 
get_short(const String & entry_name) const2668 short ProblemDescDB::get_short(const String& entry_name) const
2669 {
2670   const char *L;
2671 
2672   if (!dbRep)
2673 	Null_rep("get_short");
2674   if ((L = Begins(entry_name, "method."))) {
2675     if (dbRep->methodDBLocked)
2676 	Locked_db();
2677     #define P &DataMethodRep::
2678     static KW<short, DataMethodRep> Shdme[] = {
2679       // must be sorted by string (key)
2680 	{"iterator_scheduling", P iteratorScheduling},
2681 	{"nond.allocation_target", P allocationTarget},
2682         {"nond.c3function_train.advancement_type", P c3AdvanceType},
2683 	{"nond.correction_order", P approxCorrectionOrder},
2684 	{"nond.covariance_control", P covarianceControl},
2685 	{"nond.distribution", P distributionType},
2686 	{"nond.emulator", P emulatorType},
2687 	{"nond.expansion_basis_type", P expansionBasisType},
2688 	{"nond.expansion_refinement_control", P refinementControl},
2689 	{"nond.expansion_refinement_type", P refinementType},
2690 	{"nond.expansion_type", P expansionType},
2691 	{"nond.final_moments", P finalMomentsType},
2692 	{"nond.growth_override", P growthOverride},
2693 	{"nond.least_squares_regression_type", P lsRegressionType},
2694 	{"nond.multilevel_allocation_control", P multilevAllocControl},
2695 	{"nond.multilevel_discrepancy_emulation", P multilevDiscrepEmulation},
2696 	{"nond.nesting_override", P nestingOverride},
2697 	{"nond.qoi_aggregation", P qoiAggregation},
2698 	{"nond.refinement_statistics_mode", P statsMetricMode},
2699 	{"nond.regression_type", P regressionType},
2700 	{"nond.response_level_target", P responseLevelTarget},
2701 	{"nond.response_level_target_reduce", P responseLevelTargetReduce},
2702 	{"optpp.merit_function", P meritFn},
2703 	{"output", P methodOutput},
2704 	{"sbl.acceptance_logic", P surrBasedLocalAcceptLogic},
2705 	{"sbl.constraint_relax", P surrBasedLocalConstrRelax},
2706 	{"sbl.merit_function", P surrBasedLocalMeritFn},
2707 	{"sbl.subproblem_constraints", P surrBasedLocalSubProbCon},
2708 	{"sbl.subproblem_objective", P surrBasedLocalSubProbObj},
2709 	{"wilks.sided_interval", P wilksSidedInterval}};
2710     #undef P
2711 
2712     KW<short, DataMethodRep> *kw;
2713     if ((kw = (KW<short, DataMethodRep>*)Binsearch(Shdme, L)))
2714 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
2715   }
2716   else if ((L = Begins(entry_name, "model."))) {
2717     if (dbRep->modelDBLocked)
2718 	Locked_db();
2719     #define P &DataModelRep::
2720     static KW<short, DataModelRep> Shdmo[] = {
2721       // must be sorted by string (key)
2722         {"c3function_train.advancement_type", P c3AdvanceType},
2723       //{"c3function_train.refinement_control", P refinementControl},
2724       //{"c3function_train.refinement_type", P refinementType},
2725 	{"nested.iterator_scheduling", P subMethodScheduling},
2726 	{"surrogate.correction_order", P approxCorrectionOrder},
2727 	{"surrogate.correction_type", P approxCorrectionType},
2728 	{"surrogate.find_nugget", P krigingFindNugget},
2729 	{"surrogate.kriging_max_trials", P krigingMaxTrials},
2730 	{"surrogate.mars_max_bases", P marsMaxBases},
2731 	{"surrogate.mls_weight_function", P mlsWeightFunction},
2732 	{"surrogate.neural_network_nodes", P annNodes},
2733 	{"surrogate.neural_network_random_weight", P annRandomWeight},
2734 	{"surrogate.points_management", P pointsManagement},
2735 	{"surrogate.polynomial_order", P polynomialOrder},
2736 	{"surrogate.rbf_bases", P rbfBases},
2737 	{"surrogate.rbf_max_pts", P rbfMaxPts},
2738 	{"surrogate.rbf_max_subsets", P rbfMaxSubsets},
2739 	{"surrogate.rbf_min_partition", P rbfMinPartition},
2740 	{"surrogate.regression_type", P regressionType}
2741     };
2742     #undef P
2743 
2744     KW<short, DataModelRep> *kw;
2745     if ((kw = (KW<short, DataModelRep>*)Binsearch(Shdmo, L)))
2746 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
2747   }
2748   else if ((L = Begins(entry_name, "variables."))) {
2749     if (dbRep->variablesDBLocked)
2750 	Locked_db();
2751     #define P &DataVariablesRep::
2752     static KW<short, DataVariablesRep> Shdv[] = {
2753       // must be sorted by string (key)
2754 	{"domain", P varsDomain},
2755 	{"view", P varsView}};
2756     #undef P
2757 
2758     KW<short, DataVariablesRep> *kw;
2759     if ((kw = (KW<short, DataVariablesRep>*)Binsearch(Shdv, L)))
2760 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
2761   }
2762   else if ((L = Begins(entry_name, "interface."))) {
2763     if (dbRep->interfaceDBLocked)
2764 	Locked_db();
2765     #define P &DataInterfaceRep::
2766     static KW<short, DataInterfaceRep> Shdi[] = {
2767       // must be sorted by string (key)
2768 	{"analysis_scheduling", P analysisScheduling},
2769 	{"evaluation_scheduling", P evalScheduling},
2770 	{"local_evaluation_scheduling", P asynchLocalEvalScheduling}};
2771     #undef P
2772 
2773     KW<short, DataInterfaceRep> *kw;
2774     if ((kw = (KW<short, DataInterfaceRep>*)Binsearch(Shdi, L)))
2775 	return dbRep->dataInterfaceIter->dataIfaceRep.get()->*kw->p;
2776   }
2777   Bad_name(entry_name, "get_short");
2778   return abort_handler_t<short>(PARSE_ERROR);
2779 }
2780 
2781 
get_ushort(const String & entry_name) const2782 unsigned short ProblemDescDB::get_ushort(const String& entry_name) const
2783 {
2784   const char *L;
2785 
2786   if (!dbRep)
2787 	Null_rep("get_ushort");
2788   if ((L = Begins(entry_name, "environment."))) {
2789     #define P &DataEnvironmentRep::
2790     static KW<unsigned short, DataEnvironmentRep> UShde[] = {
2791       // must be sorted by string (key)
2792         {"interface_evals_selection", P interfEvalsSelection},
2793         {"model_evals_selection", P modelEvalsSelection},
2794         {"post_run_input_format", P postRunInputFormat},
2795         {"pre_run_output_format", P preRunOutputFormat},
2796         {"results_output_format", P resultsOutputFormat},
2797         {"tabular_format", P tabularFormat}};
2798     #undef P
2799 
2800     KW<unsigned short, DataEnvironmentRep> *kw;
2801     if ((kw = (KW<unsigned short, DataEnvironmentRep>*)Binsearch(UShde, L)))
2802       return dbRep->environmentSpec.dataEnvRep.get()->*kw->p;
2803   }
2804   else if ((L = Begins(entry_name, "method."))) {
2805     if (dbRep->methodDBLocked)
2806 	Locked_db();
2807     #define P &DataMethodRep::
2808     static KW<unsigned short, DataMethodRep> UShdme[] = {
2809       // must be sorted by string (key)
2810 	{"algorithm", P methodName},
2811 	{"export_approx_format", P exportApproxFormat},
2812 	{"import_approx_format", P importApproxFormat},
2813 	{"import_build_format", P importBuildFormat},
2814 	{"import_candidate_format", P importCandFormat},
2815 	{"import_prediction_configs_format", P importPredConfigFormat},
2816 	{"model_export_format", P modelExportFormat},
2817 	{"nond.adapted_basis.advancements", P adaptedBasisAdvancements},
2818       //{"nond.adapted_basis.initial_level", P adaptedBasisInitLevel},
2819         {"nond.c3function_train.kick_order", P kickOrder},
2820         {"nond.c3function_train.max_order", P maxOrder},
2821         {"nond.c3function_train.start_order", P startOrder},
2822 	{"nond.calibrate_error_mode", P calibrateErrorMode},
2823 	{"nond.cubature_integrand", P cubIntOrder},
2824 	{"nond.expansion_order", P expansionOrder},
2825 	{"nond.export_corrected_model_format", P exportCorrModelFormat},
2826 	{"nond.export_corrected_variance_format", P exportCorrVarFormat},
2827 	{"nond.export_discrep_format", P exportDiscrepFormat},
2828 	{"nond.export_samples_format", P exportSamplesFormat},
2829 	{"nond.integration_refinement", P integrationRefine},
2830 	{"nond.pre_solve_method", P preSolveMethod},
2831 	{"nond.quadrature_order", P quadratureOrder},
2832 	{"nond.reliability_search_type", P reliabilitySearchType},
2833 	{"nond.sparse_grid_level", P sparseGridLevel},
2834 	{"nond.vbd_interaction_order", P vbdOrder},
2835 	{"order", P wilksOrder},
2836 	{"pstudy.import_format", P pstudyFileFormat},
2837 	{"sample_type", P sampleType},
2838 	{"soft_convergence_limit", P softConvLimit},
2839 	{"sub_method", P subMethod}};
2840     #undef P
2841 
2842     KW<unsigned short, DataMethodRep> *kw;
2843     if ((kw = (KW<unsigned short, DataMethodRep>*)Binsearch(UShdme, L)))
2844 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
2845   }
2846   else if ((L = Begins(entry_name, "model."))) {
2847     if (dbRep->modelDBLocked)
2848 	Locked_db();
2849     #define P &DataModelRep::
2850     static KW<unsigned short, DataModelRep> UShdmo[] = {
2851       // must be sorted by string (key)
2852 	{"active_subspace.cv.id_method", P subspaceIdCVMethod},
2853 	{"active_subspace.normalization", P subspaceNormalization},
2854 	{"active_subspace.sample_type", P subspaceSampleType},
2855 	{"adapted_basis.expansion_order", P adaptedBasisExpOrder},
2856 	{"adapted_basis.sparse_grid_level", P adaptedBasisSparseGridLev},
2857         {"c3function_train.kick_order", P kickOrder},
2858         {"c3function_train.max_order", P maxOrder},
2859         {"c3function_train.start_order", P startOrder},
2860 	{"rf.analytic_covariance", P analyticCovIdForm},
2861 	{"rf.expansion_form", P randomFieldIdForm},
2862 	{"surrogate.challenge_points_file_format", P importChallengeFormat},
2863 	{"surrogate.export_approx_format", P exportApproxFormat},
2864 	{"surrogate.export_approx_variance_format", P exportApproxVarianceFormat},
2865 	{"surrogate.import_build_format", P importBuildFormat},
2866 	{"surrogate.model_export_format", P modelExportFormat}};
2867     #undef P
2868 
2869     KW<unsigned short, DataModelRep> *kw;
2870     if ((kw = (KW<unsigned short, DataModelRep>*)Binsearch(UShdmo, L)))
2871 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
2872   }
2873   else if ((L = Begins(entry_name, "interface."))) {
2874     if (dbRep->interfaceDBLocked)
2875 	Locked_db();
2876     #define P &DataInterfaceRep::
2877     static KW<unsigned short, DataInterfaceRep> UShdi[] = {
2878       // must be sorted by string (key)
2879 	{"application.results_file_format", P resultsFileFormat},
2880         {"type", P interfaceType}};
2881     #undef P
2882 
2883     KW<unsigned short, DataInterfaceRep> *kw;
2884     if ((kw = (KW<unsigned short, DataInterfaceRep>*)Binsearch(UShdi, L)))
2885 	return dbRep->dataInterfaceIter->dataIfaceRep.get()->*kw->p;
2886   }
2887   else if ((L = Begins(entry_name, "responses."))) {
2888     if (dbRep->responsesDBLocked)
2889 	Locked_db();
2890     #define P &DataResponsesRep::
2891     static KW<unsigned short, DataResponsesRep> UShdr[] = {
2892       // must be sorted by string (key)
2893         {"scalar_data_format", P scalarDataFormat}};
2894     #undef P
2895 
2896     KW<unsigned short, DataResponsesRep> *kw;
2897     if ((kw = (KW<unsigned short, DataResponsesRep>*)Binsearch(UShdr, L)))
2898 	return dbRep->dataResponsesIter->dataRespRep.get()->*kw->p;
2899   }
2900   Bad_name(entry_name, "get_ushort");
2901   return abort_handler_t<unsigned short>(PARSE_ERROR);
2902 }
2903 
2904 
get_sizet(const String & entry_name) const2905 size_t ProblemDescDB::get_sizet(const String& entry_name) const
2906 {
2907   const char *L;
2908 
2909   if (!dbRep)
2910 	Null_rep("get_sizet");
2911   if ((L = Begins(entry_name, "method."))) {
2912     if (dbRep->methodDBLocked)
2913 	Locked_db();
2914     #define P &DataMethodRep::
2915     static KW<size_t, DataMethodRep> Szdmo[] = {
2916       // must be sorted by string (key)
2917 	{"final_solutions", P numFinalSolutions},
2918 	{"jega.num_cross_points", P numCrossPoints},
2919 	{"jega.num_designs", P numDesigns},
2920 	{"jega.num_generations", P numGenerations},
2921 	{"jega.num_offspring", P numOffspring},
2922 	{"jega.num_parents", P numParents},
2923         {"nond.c3function_train.kick_rank", P kickRank},
2924       	{"nond.c3function_train.max_rank", P maxRank},
2925         {"nond.c3function_train.start_rank", P startRank},
2926 	{"nond.collocation_points", P collocationPoints},
2927 	{"nond.expansion_samples", P expansionSamples},
2928 	{"num_candidate_designs", P numCandidateDesigns},
2929 	{"num_candidates", P numCandidates},
2930 	{"num_prediction_configs", P numPredConfigs}
2931     };
2932     #undef P
2933 
2934     KW<size_t, DataMethodRep> *kw;
2935     if ((kw = (KW<size_t, DataMethodRep>*)Binsearch(Szdmo, L)))
2936 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
2937   }
2938   else if ((L = Begins(entry_name, "model."))) {
2939     if (dbRep->modelDBLocked)
2940 	Locked_db();
2941     #define P &DataModelRep::
2942     static KW<size_t, DataModelRep> Szmo[] = {
2943       // must be sorted by string (key)
2944       // must be sorted by string (key)
2945 	{"c3function_train.collocation_points", P collocationPoints},
2946         {"c3function_train.kick_rank", P kickRank},
2947       	{"c3function_train.max_rank", P maxRank},
2948         {"c3function_train.start_rank", P startRank}//,
2949       //{"c3function_train.verbosity", P verbosity}
2950     };
2951     #undef P
2952 
2953     KW<size_t, DataModelRep> *kw;
2954     if ((kw = (KW<size_t, DataModelRep>*)Binsearch(Szmo, L)))
2955 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
2956   }
2957   else if ((L = Begins(entry_name, "variables."))) {
2958     if (dbRep->variablesDBLocked)
2959 	Locked_db();
2960     std::list<DataVariables>::iterator v_iter = dbRep->dataVariablesIter;
2961     DataVariablesRep* VRep = v_iter->dataVarsRep.get();
2962 
2963     // DataVariables helper functions
2964     struct HelperFcn { const char *name; int no; };
2965     static HelperFcn hf[] = {
2966 	{"aleatory_uncertain", 0},
2967 	{"continuous", 1},
2968 	{"design", 2},
2969 	{"discrete", 3},
2970 	{"epistemic_uncertain", 4},
2971 	{"state", 5},
2972 	{"total", 6},
2973 	{"uncertain", 7}};
2974 
2975     // normal DB lookups
2976     #define P &DataVariablesRep::
2977     static KW<size_t, DataVariablesRep> Szdv[] = {
2978       // must be sorted by string (key)
2979 	{"beta_uncertain", P numBetaUncVars},
2980 	{"binomial_uncertain", P numBinomialUncVars},
2981 	{"continuous_design", P numContinuousDesVars},
2982 	{"continuous_interval_uncertain", P numContinuousIntervalUncVars},
2983 	{"continuous_state", P numContinuousStateVars},
2984 	{"discrete_design_range", P numDiscreteDesRangeVars},
2985 	{"discrete_design_set_int", P numDiscreteDesSetIntVars},
2986 	{"discrete_design_set_real", P numDiscreteDesSetRealVars},
2987 	{"discrete_design_set_string", P numDiscreteDesSetStrVars},
2988 	{"discrete_interval_uncertain", P numDiscreteIntervalUncVars},
2989 	{"discrete_state_range", P numDiscreteStateRangeVars},
2990 	{"discrete_state_set_int", P numDiscreteStateSetIntVars},
2991 	{"discrete_state_set_real", P numDiscreteStateSetRealVars},
2992 	{"discrete_state_set_string", P numDiscreteStateSetStrVars},
2993 	{"discrete_uncertain_set_int", P numDiscreteUncSetIntVars},
2994 	{"discrete_uncertain_set_real", P numDiscreteUncSetRealVars},
2995 	{"discrete_uncertain_set_string", P numDiscreteUncSetStrVars},
2996 	{"exponential_uncertain", P numExponentialUncVars},
2997 	{"frechet_uncertain", P numFrechetUncVars},
2998 	{"gamma_uncertain", P numGammaUncVars},
2999 	{"geometric_uncertain", P numGeometricUncVars},
3000 	{"gumbel_uncertain", P numGumbelUncVars},
3001 	{"histogram_uncertain.bin", P numHistogramBinUncVars},
3002 	{"histogram_uncertain.point_int", P numHistogramPtIntUncVars},
3003 	{"histogram_uncertain.point_real", P numHistogramPtRealUncVars},
3004 	{"histogram_uncertain.point_string", P numHistogramPtStrUncVars},
3005 	{"hypergeometric_uncertain", P numHyperGeomUncVars},
3006 	{"lognormal_uncertain", P numLognormalUncVars},
3007 	{"loguniform_uncertain", P numLoguniformUncVars},
3008 	{"negative_binomial_uncertain", P numNegBinomialUncVars},
3009 	{"normal_uncertain", P numNormalUncVars},
3010 	{"poisson_uncertain", P numPoissonUncVars},
3011 	{"triangular_uncertain", P numTriangularUncVars},
3012 	{"uniform_uncertain", P numUniformUncVars},
3013 	{"weibull_uncertain", P numWeibullUncVars}};
3014     #undef P
3015 
3016     HelperFcn *kwh;
3017     KW<size_t, DataVariablesRep> *kw;
3018 
3019     if ((kwh = (HelperFcn*)Binsearch(hf, L)))
3020 	switch(kwh->no) {
3021 	  case 0: return v_iter->aleatory_uncertain();
3022 	  case 1: return v_iter->continuous_variables();
3023 	  case 2: return v_iter->design();
3024 	  case 3: return v_iter->discrete_variables();
3025 	  case 4: return v_iter->epistemic_uncertain();
3026 	  case 5: return v_iter->state();
3027 	  case 6: return v_iter->total_variables();
3028 	  case 7: return v_iter->uncertain();
3029 	  }
3030     else if ((kw = (KW<size_t, DataVariablesRep>*)Binsearch(Szdv, L)))
3031 	return VRep->*kw->p;
3032   }
3033   else if ((L = Begins(entry_name, "responses.num_"))) {
3034     if (dbRep->responsesDBLocked)
3035 	Locked_db();
3036     #define P &DataResponsesRep::
3037     static KW<size_t, DataResponsesRep> Szdr[] = {
3038       // must be sorted by string (key)
3039 	{"calibration_terms", P numLeastSqTerms},
3040 	{"config_vars", P numExpConfigVars},
3041 	{"experiments", P numExperiments},
3042 	{"field_calibration_terms", P numFieldLeastSqTerms},
3043 	{"field_nonlinear_equality_constraints",
3044 	 P numFieldNonlinearEqConstraints},
3045 	{"field_nonlinear_inequality_constraints",
3046 	 P numFieldNonlinearIneqConstraints},
3047 	{"field_objectives", P numFieldObjectiveFunctions},
3048 	{"field_responses", P numFieldResponseFunctions},
3049 	{"nonlinear_equality_constraints", P numNonlinearEqConstraints},
3050 	{"nonlinear_inequality_constraints", P numNonlinearIneqConstraints},
3051 	{"objective_functions", P numObjectiveFunctions},
3052 	{"response_functions", P numResponseFunctions},
3053 	{"scalar_calibration_terms", P numScalarLeastSqTerms},
3054 	{"scalar_nonlinear_equality_constraints",
3055 	 P numScalarNonlinearEqConstraints},
3056 	{"scalar_nonlinear_inequality_constraints",
3057 	 P numScalarNonlinearIneqConstraints},
3058 	{"scalar_objectives", P numScalarObjectiveFunctions},
3059 	{"scalar_responses", P numScalarResponseFunctions}};
3060     #undef P
3061 
3062     KW<size_t, DataResponsesRep> *kw;
3063     if ((kw = (KW<size_t, DataResponsesRep>*)Binsearch(Szdr, L)))
3064 	return dbRep->dataResponsesIter->dataRespRep.get()->*kw->p;
3065   }
3066   Bad_name(entry_name, "get_sizet");
3067   return abort_handler_t<size_t>(PARSE_ERROR);
3068 }
3069 
3070 
get_bool(const String & entry_name) const3071 bool ProblemDescDB::get_bool(const String& entry_name) const
3072 {
3073   const char *L;
3074   if (!dbRep)
3075 	Null_rep("get_bool");
3076   if ((L = Begins(entry_name, "environment."))) {
3077     #define P &DataEnvironmentRep::
3078     static KW<bool, DataEnvironmentRep> Bde[] = {
3079       // must be sorted by string (key)
3080 	{"check", P checkFlag},
3081 	{"graphics", P graphicsFlag},
3082 	{"post_run", P postRunFlag},
3083 	{"pre_run", P preRunFlag},
3084 	{"results_output", P resultsOutputFlag},
3085 	{"run", P runFlag},
3086 	{"tabular_graphics_data", P tabularDataFlag}};
3087     #undef P
3088 
3089     KW<bool, DataEnvironmentRep> *kw;
3090     if ((kw = (KW<bool, DataEnvironmentRep>*)Binsearch(Bde, L)))
3091       return dbRep->environmentSpec.dataEnvRep.get()->*kw->p;
3092   }
3093   else if ((L = Begins(entry_name, "method."))) {
3094     if (dbRep->methodDBLocked)
3095 	Locked_db();
3096     #define P &DataMethodRep::
3097     static KW<bool, DataMethodRep> Bdme[] = {
3098       // must be sorted by string (key)
3099 	{"backfill", P backfillFlag},
3100         {"chain_diagnostics", P chainDiagnostics},
3101         {"chain_diagnostics.confidence_intervals", P chainDiagnosticsCI},
3102 	{"coliny.constant_penalty", P constantPenalty},
3103 	{"coliny.expansion", P expansionFlag},
3104 	{"coliny.randomize", P randomizeOrderFlag},
3105 	{"coliny.show_misc_options", P showMiscOptions},
3106 	{"derivative_usage", P methodUseDerivsFlag},
3107 	{"export_surrogate", P exportSurrogate},
3108 	{"fixed_seed", P fixedSeedFlag},
3109 	{"fsu_quasi_mc.fixed_sequence", P fixedSequenceFlag},
3110 	{"import_approx_active_only", P importApproxActive},
3111 	{"import_build_active_only", P importBuildActive},
3112         {"laplace_approx", P modelEvidLaplace},
3113 	{"latinize", P latinizeFlag},
3114 	{"main_effects", P mainEffectsFlag},
3115         {"mc_approx", P modelEvidMC},
3116 	{"mesh_adaptive_search.display_all_evaluations", P showAllEval},
3117         {"model_evidence", P modelEvidence},
3118 	{"mutation_adaptive", P mutationAdaptive},
3119 	{"nl2sol.regression_diagnostics", P regressDiag},
3120 	{"nond.adapt_exp_design", P adaptExpDesign},
3121 	{"nond.adaptive_posterior_refinement", P adaptPosteriorRefine},
3122 	{"nond.allocation_target.variance.optimization", P useTargetVarianceOptimizationFlag},
3123 	{"nond.c3function_train.adapt_order", P adaptOrder},
3124 	{"nond.c3function_train.adapt_rank", P adaptRank},
3125 	{"nond.cross_validation", P crossValidation},
3126 	{"nond.cross_validation.noise_only", P crossValidNoiseOnly},
3127 	{"nond.d_optimal", P dOptimal},
3128 	{"nond.evaluate_posterior_density", P evaluatePosteriorDensity},
3129 	{"nond.export_sample_sequence", P exportSampleSeqFlag},
3130 	{"nond.generate_posterior_samples", P generatePosteriorSamples},
3131 	{"nond.gpmsa_normalize", P gpmsaNormalize},
3132 	{"nond.logit_transform", P logitTransform},
3133 	{"nond.model_discrepancy", P calModelDiscrepancy},
3134 	{"nond.mutual_info_ksg2", P mutualInfoKSG2},
3135 	{"nond.normalized", P normalizedCoeffs},
3136 	{"nond.piecewise_basis", P piecewiseBasis},
3137 	{"nond.relative_convergence_metric", P relativeConvMetric},
3138 	{"nond.standardized_space", P standardizedSpace},
3139 	{"nond.tensor_grid", P tensorGridFlag},
3140 	{"posterior_stats.kde", P posteriorStatsKDE},
3141 	{"posterior_stats.kl_divergence", P posteriorStatsKL},
3142 	{"posterior_stats.mutual_info", P posteriorStatsMutual},
3143 	{"principal_components", P pcaFlag},
3144 	{"print_each_pop", P printPopFlag},
3145 	{"pstudy.import_active_only", P pstudyFileActive},
3146 	{"quality_metrics", P volQualityFlag},
3147 	{"sbg.replace_points", P surrBasedGlobalReplacePts},
3148 	{"sbl.truth_surrogate_bypass", P surrBasedLocalLayerBypass},
3149 	{"scaling", P methodScaling},
3150 	{"speculative", P speculativeFlag},
3151 	{"variance_based_decomp", P vbdFlag},
3152 	{"wilks", P wilksFlag}};
3153     #undef P
3154 
3155     KW<bool, DataMethodRep> *kw;
3156     if ((kw = (KW<bool, DataMethodRep>*)Binsearch(Bdme, L)))
3157 	return dbRep->dataMethodIter->dataMethodRep.get()->*kw->p;
3158   }
3159   else if ((L = Begins(entry_name, "model."))) {
3160     if (dbRep->modelDBLocked)
3161 	Locked_db();
3162     #define P &DataModelRep::
3163     static KW<bool, DataModelRep> Bdmo[] = {
3164       // must be sorted by string (key)
3165 	{"active_subspace.build_surrogate", P subspaceBuildSurrogate},
3166 	{"active_subspace.cv.incremental", P subspaceCVIncremental},
3167 	{"active_subspace.truncation_method.bing_li", P subspaceIdBingLi},
3168 	{"active_subspace.truncation_method.constantine", P subspaceIdConstantine},
3169 	{"active_subspace.truncation_method.cv", P subspaceIdCV},
3170 	{"active_subspace.truncation_method.energy", P subspaceIdEnergy},
3171         {"c3function_train.adapt_order", P adaptOrder},
3172         {"c3function_train.adapt_rank", P adaptRank},
3173 	{"c3function_train.tensor_grid", P tensorGridFlag},
3174 	{"hierarchical_tags", P hierarchicalTags},
3175 	{"nested.identity_resp_map", P identityRespMap},
3176 	{"surrogate.auto_refine", P autoRefine},
3177 	{"surrogate.challenge_points_file_active", P importChallengeActive},
3178 	{"surrogate.challenge_use_variable_labels", P importChalUseVariableLabels},
3179 	{"surrogate.cross_validate", P crossValidateFlag},
3180 	{"surrogate.decomp_discont_detect", P decompDiscontDetect},
3181 	{"surrogate.derivative_usage", P modelUseDerivsFlag},
3182 	{"surrogate.domain_decomp", P domainDecomp},
3183 	{"surrogate.export_surrogate", P exportSurrogate},
3184 	{"surrogate.import_build_active_only", P importBuildActive},
3185 	{"surrogate.import_use_variable_labels", P importUseVariableLabels},
3186 	{"surrogate.point_selection", P pointSelection},
3187 	{"surrogate.press", P pressFlag}};
3188     #undef P
3189 
3190     KW<bool, DataModelRep> *kw;
3191     if ((kw = (KW<bool, DataModelRep>*)Binsearch(Bdmo, L)))
3192 	return dbRep->dataModelIter->dataModelRep.get()->*kw->p;
3193   }
3194   else if ((L = Begins(entry_name, "variables."))) {
3195     if (dbRep->variablesDBLocked)
3196 	Locked_db();
3197     #define P &DataVariablesRep::
3198     static KW<bool, DataVariablesRep> Bdv[] = {
3199       // must be sorted by string (key)
3200 	{"uncertain.initial_point_flag", P uncertainVarsInitPt}};
3201     #undef P
3202 
3203     KW<bool, DataVariablesRep> *kw;
3204     if ((kw = (KW<bool, DataVariablesRep>*)Binsearch(Bdv, L)))
3205 	return dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p;
3206   }
3207   else if ((L = Begins(entry_name, "interface."))) {
3208     if (dbRep->interfaceDBLocked)
3209 	Locked_db();
3210     #define P &DataInterfaceRep::
3211     static KW<bool, DataInterfaceRep> Bdi[] = {
3212       // must be sorted by string (key)
3213 	{"active_set_vector", P activeSetVectorFlag},
3214 	{"allow_existing_results", P allowExistingResultsFlag},
3215 	{"application.aprepro", P apreproFlag},
3216 	{"application.file_save", P fileSaveFlag},
3217 	{"application.file_tag", P fileTagFlag},
3218 	{"application.verbatim", P verbatimFlag},
3219         {"asynch", P asynchFlag},
3220         {"batch", P batchEvalFlag},
3221 	{"dirSave", P dirSave},
3222 	{"dirTag", P dirTag},
3223 	{"evaluation_cache", P evalCacheFlag},
3224 	{"nearby_evaluation_cache", P nearbyEvalCacheFlag},
3225 	{"python.numpy", P numpyFlag},
3226 	{"restart_file", P restartFileFlag},
3227 	{"templateReplace", P templateReplace},
3228 	{"useWorkdir", P useWorkdir}};
3229     #undef P
3230 
3231     KW<bool, DataInterfaceRep> *kw;
3232     if ((kw = (KW<bool, DataInterfaceRep>*)Binsearch(Bdi, L)))
3233 	return dbRep->dataInterfaceIter->dataIfaceRep.get()->*kw->p;
3234   }
3235   else if ((L = Begins(entry_name, "responses."))) {
3236     if (dbRep->responsesDBLocked)
3237 	Locked_db();
3238     #define P &DataResponsesRep::
3239     static KW<bool, DataResponsesRep> Bdr[] = {
3240       // must be sorted by string (key)
3241 	{"calibration_data", P calibrationDataFlag},
3242 	{"central_hess", P centralHess},
3243 	{"ignore_bounds", P ignoreBounds},
3244 	{"interpolate", P interpolateFlag},
3245 	{"read_field_coordinates", P readFieldCoords}};
3246     #undef P
3247 
3248     KW<bool, DataResponsesRep> *kw;
3249     if ((kw = (KW<bool, DataResponsesRep>*)Binsearch(Bdr, L)))
3250 	return dbRep->dataResponsesIter->dataRespRep.get()->*kw->p;
3251   }
3252   Bad_name(entry_name, "get_bool");
3253   return abort_handler_t<bool>(PARSE_ERROR);
3254 }
3255 
get_voidss(const String & entry_name) const3256 void** ProblemDescDB::get_voidss(const String& entry_name) const
3257 {
3258 	if (entry_name == "method.dl_solver.dlLib") {
3259 		if (dbRep->methodDBLocked)
3260 			Locked_db();
3261 		return &dbRep->dataMethodIter->dataMethodRep->dlLib;
3262 		}
3263 	Bad_name(entry_name, "get_voidss");
3264 	return abort_handler_t<void**>(PARSE_ERROR);
3265 	}
3266 
set(const String & entry_name,const RealVector & rv)3267 void ProblemDescDB::set(const String& entry_name, const RealVector& rv)
3268 {
3269   const char *L;
3270   if (!dbRep)
3271 	Null_rep1("set(RealVector&)");
3272   if ((L = Begins(entry_name, "model.nested."))) {
3273     if (dbRep->modelDBLocked)
3274 	Locked_db();
3275     #define P &DataModelRep::
3276     static KW<RealVector, DataModelRep> RVdmo[] = {
3277       // must be sorted by string (key)
3278 	{"primary_response_mapping", P primaryRespCoeffs},
3279 	{"secondary_response_mapping", P secondaryRespCoeffs}};
3280     #undef P
3281 
3282     KW<RealVector, DataModelRep> *kw;
3283     if ((kw = (KW<RealVector, DataModelRep>*)Binsearch(RVdmo, L))) {
3284 	dbRep->dataModelIter->dataModelRep.get()->*kw->p = rv;
3285 	return;
3286 	}
3287   }
3288   else if ((L = Begins(entry_name, "variables."))) {
3289     if (dbRep->variablesDBLocked)
3290 	Locked_db();
3291     #define P &DataVariablesRep::
3292     static KW<RealVector, DataVariablesRep> RVdv[] = {
3293       // must be sorted by string (key)
3294 	{"beta_uncertain.alphas", P betaUncAlphas},
3295 	{"beta_uncertain.betas", P betaUncBetas},
3296 	{"beta_uncertain.lower_bounds", P betaUncLowerBnds},
3297 	{"beta_uncertain.upper_bounds", P betaUncUpperBnds},
3298 	{"binomial_uncertain.prob_per_trial", P binomialUncProbPerTrial},
3299 	{"continuous_aleatory_uncertain.initial_point",
3300 	 P continuousAleatoryUncVars},
3301 	{"continuous_aleatory_uncertain.lower_bounds",
3302 	 P continuousAleatoryUncLowerBnds},
3303 	{"continuous_aleatory_uncertain.upper_bounds",
3304 	 P continuousAleatoryUncUpperBnds},
3305 	{"continuous_design.initial_point", P continuousDesignVars},
3306 	{"continuous_design.initial_point", P continuousDesignVars},
3307 	{"continuous_design.lower_bounds", P continuousDesignLowerBnds},
3308 	{"continuous_design.lower_bounds", P continuousDesignLowerBnds},
3309 	{"continuous_design.scales", P continuousDesignScales},
3310 	{"continuous_design.upper_bounds", P continuousDesignUpperBnds},
3311 	{"continuous_design.upper_bounds", P continuousDesignUpperBnds},
3312 	{"continuous_epistemic_uncertain.initial_point",
3313 	 P continuousEpistemicUncVars},
3314 	{"continuous_epistemic_uncertain.lower_bounds",
3315 	 P continuousEpistemicUncLowerBnds},
3316 	{"continuous_epistemic_uncertain.upper_bounds",
3317 	 P continuousEpistemicUncUpperBnds},
3318 	{"continuous_state.initial_state", P continuousStateVars},
3319 	{"continuous_state.lower_bounds", P continuousStateLowerBnds},
3320 	{"continuous_state.upper_bounds", P continuousStateUpperBnds},
3321 	{"discrete_aleatory_uncertain_real.initial_point",
3322 	 P discreteRealAleatoryUncVars},
3323 	{"discrete_aleatory_uncertain_real.lower_bounds",
3324 	 P discreteRealAleatoryUncLowerBnds},
3325 	{"discrete_aleatory_uncertain_real.upper_bounds",
3326 	 P discreteRealAleatoryUncUpperBnds},
3327 	{"discrete_design_set_real.initial_point", P discreteDesignSetRealVars},
3328 	{"discrete_design_set_real.initial_point", P discreteDesignSetRealVars},
3329 	{"discrete_epistemic_uncertain_real.initial_point",
3330 	 P discreteRealEpistemicUncVars},
3331 	{"discrete_epistemic_uncertain_real.lower_bounds",
3332 	 P discreteRealEpistemicUncLowerBnds},
3333 	{"discrete_epistemic_uncertain_real.upper_bounds",
3334 	 P discreteRealEpistemicUncUpperBnds},
3335 	{"discrete_state_set_real.initial_state", P discreteStateSetRealVars},
3336 	{"exponential_uncertain.betas", P exponentialUncBetas},
3337 	{"frechet_uncertain.alphas", P frechetUncAlphas},
3338 	{"frechet_uncertain.betas", P frechetUncBetas},
3339 	{"gamma_uncertain.alphas", P gammaUncAlphas},
3340 	{"gamma_uncertain.betas", P gammaUncBetas},
3341 	{"geometric_uncertain.prob_per_trial", P geometricUncProbPerTrial},
3342 	{"gumbel_uncertain.alphas", P gumbelUncAlphas},
3343 	{"gumbel_uncertain.betas", P gumbelUncBetas},
3344 	{"linear_equality_constraints", P linearEqConstraintCoeffs},
3345 	{"linear_equality_scales", P linearEqScales},
3346 	{"linear_equality_targets", P linearEqTargets},
3347 	{"linear_inequality_constraints", P linearIneqConstraintCoeffs},
3348 	{"linear_inequality_lower_bounds", P linearIneqLowerBnds},
3349 	{"linear_inequality_scales", P linearIneqScales},
3350 	{"linear_inequality_upper_bounds", P linearIneqUpperBnds},
3351 	{"lognormal_uncertain.error_factors", P lognormalUncErrFacts},
3352 	{"lognormal_uncertain.lambdas", P lognormalUncLambdas},
3353 	{"lognormal_uncertain.lower_bounds", P lognormalUncLowerBnds},
3354 	{"lognormal_uncertain.means", P lognormalUncMeans},
3355 	{"lognormal_uncertain.std_deviations", P lognormalUncStdDevs},
3356 	{"lognormal_uncertain.upper_bounds", P lognormalUncUpperBnds},
3357 	{"lognormal_uncertain.zetas", P lognormalUncZetas},
3358 	{"loguniform_uncertain.lower_bounds", P loguniformUncLowerBnds},
3359 	{"loguniform_uncertain.upper_bounds", P loguniformUncUpperBnds},
3360 	{"negative_binomial_uncertain.prob_per_trial",
3361 	 P negBinomialUncProbPerTrial},
3362 	{"normal_uncertain.lower_bounds", P normalUncLowerBnds},
3363 	{"normal_uncertain.means", P normalUncMeans},
3364 	{"normal_uncertain.std_deviations", P normalUncStdDevs},
3365 	{"normal_uncertain.upper_bounds", P normalUncUpperBnds},
3366 	{"poisson_uncertain.lambdas", P poissonUncLambdas},
3367 	{"triangular_uncertain.lower_bounds", P triangularUncLowerBnds},
3368 	{"triangular_uncertain.modes", P triangularUncModes},
3369 	{"triangular_uncertain.upper_bounds", P triangularUncUpperBnds},
3370 	{"uniform_uncertain.lower_bounds", P uniformUncLowerBnds},
3371 	{"uniform_uncertain.upper_bounds", P uniformUncUpperBnds},
3372 	{"weibull_uncertain.alphas", P weibullUncAlphas},
3373 	{"weibull_uncertain.betas", P weibullUncBetas}};
3374     #undef P
3375 
3376     KW<RealVector, DataVariablesRep> *kw;
3377     if ((kw = (KW<RealVector, DataVariablesRep>*)Binsearch(RVdv, L))) {
3378 	dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = rv;
3379 	return;
3380 	}
3381   }
3382   else if ((L = Begins(entry_name, "responses."))) {
3383     if (dbRep->responsesDBLocked)
3384 	Locked_db();
3385     #define P &DataResponsesRep::
3386     static KW<RealVector, DataResponsesRep> RVdr[] = {
3387       // must be sorted by string (key)
3388 	{"nonlinear_equality_scales", P nonlinearEqScales},
3389 	{"nonlinear_equality_targets", P nonlinearEqTargets},
3390 	{"nonlinear_inequality_lower_bounds", P nonlinearIneqLowerBnds},
3391 	{"nonlinear_inequality_scales", P nonlinearIneqScales},
3392 	{"nonlinear_inequality_upper_bounds", P nonlinearIneqUpperBnds},
3393 	{"primary_response_fn_scales", P primaryRespFnScales},
3394 	{"primary_response_fn_weights", P primaryRespFnWeights}};
3395     #undef P
3396 
3397     KW<RealVector, DataResponsesRep> *kw;
3398     if ((kw = (KW<RealVector, DataResponsesRep>*)Binsearch(RVdr, L))) {
3399 	dbRep->dataResponsesIter->dataRespRep.get()->*kw->p = rv;
3400 	return;
3401 	}
3402   }
3403   Bad_name(entry_name, "set(RealVector&)");
3404 }
3405 
3406 
set(const String & entry_name,const IntVector & iv)3407 void ProblemDescDB::set(const String& entry_name, const IntVector& iv)
3408 {
3409   const char *L;
3410   if (!dbRep)
3411 	Null_rep1("set(IntVector&)");
3412   if ((L = Begins(entry_name, "variables."))) {
3413     if (dbRep->variablesDBLocked)
3414 	Locked_db();
3415     #define P &DataVariablesRep::
3416     static KW<IntVector, DataVariablesRep> IVdv[] = {
3417       // must be sorted by string (key)
3418 	{"binomial_uncertain.num_trials", P binomialUncNumTrials},
3419 	{"discrete_aleatory_uncertain_int.initial_point",
3420 	 P discreteIntAleatoryUncVars},
3421 	{"discrete_aleatory_uncertain_int.lower_bounds",
3422 	 P discreteIntAleatoryUncLowerBnds},
3423 	{"discrete_aleatory_uncertain_int.upper_bounds",
3424 	 P discreteIntAleatoryUncUpperBnds},
3425 	{"discrete_design_range.initial_point", P discreteDesignRangeVars},
3426 	{"discrete_design_range.lower_bounds", P discreteDesignRangeLowerBnds},
3427 	{"discrete_design_range.upper_bounds", P discreteDesignRangeUpperBnds},
3428 	{"discrete_design_set_int.initial_point", P discreteDesignSetIntVars},
3429 	{"discrete_epistemic_uncertain_int.initial_point",
3430 	 P discreteIntEpistemicUncVars},
3431 	{"discrete_epistemic_uncertain_int.lower_bounds",
3432 	 P discreteIntEpistemicUncLowerBnds},
3433 	{"discrete_epistemic_uncertain_int.upper_bounds",
3434 	 P discreteIntEpistemicUncUpperBnds},
3435 	{"discrete_state_range.initial_state", P discreteStateRangeVars},
3436 	{"discrete_state_range.lower_bounds", P discreteStateRangeLowerBnds},
3437 	{"discrete_state_range.upper_bounds", P discreteStateRangeUpperBnds},
3438 	{"discrete_state_set_int.initial_state", P discreteStateSetIntVars},
3439 	{"hypergeometric_uncertain.num_drawn", P hyperGeomUncNumDrawn},
3440 	{"hypergeometric_uncertain.selected_population",
3441 	 P hyperGeomUncSelectedPop},
3442 	{"hypergeometric_uncertain.total_population", P hyperGeomUncTotalPop},
3443 	{"negative_binomial_uncertain.num_trials", P negBinomialUncNumTrials}};
3444     #undef P
3445 
3446     KW<IntVector, DataVariablesRep> *kw;
3447     if ((kw = (KW<IntVector, DataVariablesRep>*)Binsearch(IVdv, L))) {
3448 	dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = iv;
3449 	return;
3450 	}
3451   }
3452   Bad_name(entry_name, "set(IntVector&)");
3453 }
3454 
3455 
set(const String & entry_name,const BitArray & ba)3456 void ProblemDescDB::set(const String& entry_name, const BitArray& ba)
3457 {
3458   const char *L;
3459   if (!dbRep)
3460 	Null_rep1("set(BitArray&)");
3461   if ((L = Begins(entry_name, "variables."))) {
3462     if (dbRep->variablesDBLocked)
3463 	Locked_db();
3464     #define P &DataVariablesRep::
3465     static KW<BitArray, DataVariablesRep> BAdv[] = {
3466       // must be sorted by string (key)
3467 	{"binomial_uncertain.categorical", P binomialUncCat},
3468 	{"discrete_design_range.categorical", P discreteDesignRangeCat},
3469 	{"discrete_design_set_int.categorical", P discreteDesignSetIntCat},
3470 	{"discrete_design_set_real.categorical", P discreteDesignSetRealCat},
3471 	{"discrete_interval_uncertain.categorical", P discreteIntervalUncCat},
3472 	{"discrete_state_range.categorical", P discreteStateRangeCat},
3473 	{"discrete_state_set_int.categorical", P discreteStateSetIntCat},
3474 	{"discrete_state_set_real.categorical", P discreteStateSetRealCat},
3475 	{"discrete_uncertain_set_int.categorical", P discreteUncSetIntCat},
3476 	{"discrete_uncertain_set_real.categorical", P discreteUncSetRealCat},
3477 	{"geometric_uncertain.categorical", P geometricUncCat},
3478 	{"histogram_uncertain.point_int.categorical",
3479          P histogramUncPointIntCat},
3480 	{"histogram_uncertain.point_real.categorical",
3481          P histogramUncPointRealCat},
3482 	{"hypergeometric_uncertain.categorical", P hyperGeomUncCat},
3483 	{"negative_binomial_uncertain.categorical", P negBinomialUncCat},
3484 	{"poisson_uncertain.categorical", P poissonUncCat}};
3485     #undef P
3486 
3487     KW<BitArray, DataVariablesRep> *kw;
3488     if ((kw = (KW<BitArray, DataVariablesRep>*)Binsearch(BAdv, L))) {
3489 	dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = ba;
3490 	return;
3491 	}
3492   }
3493   Bad_name(entry_name, "set(BitArray&)");
3494 }
3495 
3496 
set(const String & entry_name,const RealSymMatrix & rsm)3497 void ProblemDescDB::set(const String& entry_name, const RealSymMatrix& rsm)
3498 {
3499   if (!dbRep)
3500 	Null_rep1("set(RealSymMatrix&)");
3501   if (strbegins(entry_name, "variables.")) {
3502     if (dbRep->variablesDBLocked)
3503 	Locked_db();
3504     if (strends(entry_name, "uncertain.correlation_matrix")) {
3505 	dbRep->dataVariablesIter->dataVarsRep->uncertainCorrelations = rsm;
3506 	return;
3507 	}
3508   }
3509   Bad_name(entry_name, "set(RealSymMatrix&)");
3510 }
3511 
3512 
set(const String & entry_name,const RealVectorArray & rva)3513 void ProblemDescDB::set(const String& entry_name, const RealVectorArray& rva)
3514 {
3515   const char *L;
3516   if (!dbRep)
3517     Null_rep1("set(RealVectorArray&)");
3518   if ((L = Begins(entry_name, "method.nond."))) {
3519     if (dbRep->methodDBLocked)
3520       Locked_db();
3521     #define P &DataMethodRep::
3522     static KW<RealVectorArray, DataMethodRep> RVAdme[] = {
3523       // must be sorted by string (key)
3524 	{"gen_reliability_levels", P genReliabilityLevels},
3525 	{"probability_levels", P probabilityLevels},
3526 	{"reliability_levels", P reliabilityLevels},
3527 	{"response_levels", P responseLevels}};
3528     #undef P
3529 
3530     KW<RealVectorArray, DataMethodRep> *kw;
3531     if ((kw = (KW<RealVectorArray, DataMethodRep>*)Binsearch(RVAdme, L))) {
3532       dbRep->dataMethodIter->dataMethodRep.get()->*kw->p = rva;
3533       return;
3534     }
3535   }
3536   Bad_name(entry_name, "set(RealVectorArray&)");
3537 }
3538 
3539 
set(const String & entry_name,const IntVectorArray & iva)3540 void ProblemDescDB::set(const String& entry_name, const IntVectorArray& iva)
3541 {
3542   const char *L;
3543   if (!dbRep)
3544     Null_rep1("set(IntVectorArray&)");
3545   // BMA: No current use cases
3546   Bad_name(entry_name, "set(IntVectorArray&)");
3547 }
3548 
3549 
set(const String & entry_name,const IntSetArray & isa)3550 void ProblemDescDB::set(const String& entry_name, const IntSetArray& isa)
3551 {
3552   const char *L;
3553   if (!dbRep)
3554     Null_rep1("set(IntSetArray&)");
3555   if ((L = Begins(entry_name, "variables."))) {
3556     if (dbRep->variablesDBLocked)
3557       Locked_db();
3558     #define P &DataVariablesRep::
3559     static KW<IntSetArray, DataVariablesRep> ISAdv[] = {
3560       // must be sorted by string (key)
3561 	{"discrete_design_set_int.values", P discreteDesignSetInt},
3562 	{"discrete_state_set_int.values",  P discreteStateSetInt}};
3563     #undef P
3564 
3565     KW<IntSetArray, DataVariablesRep> *kw;
3566     if ((kw = (KW<IntSetArray, DataVariablesRep>*)Binsearch(ISAdv, L))) {
3567       dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = isa;
3568       return;
3569     }
3570   }
3571   Bad_name(entry_name, "set(IntSetArray&)");
3572 }
3573 
3574 
set(const String & entry_name,const RealSetArray & rsa)3575 void ProblemDescDB::set(const String& entry_name, const RealSetArray& rsa)
3576 {
3577   const char *L;
3578   if (!dbRep)
3579     Null_rep1("set(RealSetArray&)");
3580   if ((L = Begins(entry_name, "variables."))) {
3581     if (dbRep->variablesDBLocked)
3582       Locked_db();
3583     #define P &DataVariablesRep::
3584     static KW<RealSetArray, DataVariablesRep> RSAdv[] = {
3585       // must be sorted by string (key)
3586 	{"discrete_design_set_real.values", P discreteDesignSetReal},
3587 	{"discrete_state_set_real.values",  P discreteStateSetReal}};
3588     #undef P
3589 
3590     KW<RealSetArray, DataVariablesRep> *kw;
3591     if ((kw = (KW<RealSetArray, DataVariablesRep>*)Binsearch(RSAdv, L))) {
3592       dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = rsa;
3593       return;
3594     }
3595   }
3596   Bad_name(entry_name, "set(RealSetArray&)");
3597 }
3598 
3599 
set(const String & entry_name,const IntRealMapArray & irma)3600 void ProblemDescDB::set(const String& entry_name, const IntRealMapArray& irma)
3601 {
3602   const char *L;
3603   if (!dbRep)
3604     Null_rep1("set(IntRealMapArray&)");
3605   if ((L = Begins(entry_name, "variables."))) {
3606     if (dbRep->variablesDBLocked)
3607       Locked_db();
3608     #define P &DataVariablesRep::
3609     static KW<IntRealMapArray, DataVariablesRep> IRMAdv[] = {
3610       // must be sorted by string (key)
3611 	{"discrete_uncertain_set_int.values_probs",
3612 	 P discreteUncSetIntValuesProbs},
3613 	{"histogram_uncertain.point_int_pairs", P histogramUncPointIntPairs}};
3614     #undef P
3615 
3616     KW<IntRealMapArray, DataVariablesRep> *kw;
3617     if ((kw = (KW<IntRealMapArray, DataVariablesRep>*)Binsearch(IRMAdv, L))) {
3618       dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = irma;
3619       return;
3620     }
3621   }
3622   Bad_name(entry_name, "set(IntRealMapArray&)");
3623 }
3624 
3625 
set(const String & entry_name,const StringRealMapArray & srma)3626 void ProblemDescDB::set(const String& entry_name, const StringRealMapArray& srma)
3627 {
3628   const char *L;
3629   if (!dbRep)
3630     Null_rep1("set(StringRealMapArray&)");
3631   if ((L = Begins(entry_name, "variables."))) {
3632     if (dbRep->variablesDBLocked)
3633       Locked_db();
3634     #define P &DataVariablesRep::
3635     static KW<StringRealMapArray, DataVariablesRep> SRMAdv[] = {
3636       // must be sorted by string (key)
3637 	{"histogram_uncertain.point_string_pairs", P histogramUncPointStrPairs}};
3638     #undef P
3639 
3640     KW<StringRealMapArray, DataVariablesRep> *kw;
3641     if ((kw = (KW<StringRealMapArray, DataVariablesRep>*)Binsearch(SRMAdv, L))) {
3642       dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = srma;
3643       return;
3644     }
3645   }
3646   Bad_name(entry_name, "set(StringRealMapArray&)");
3647 }
3648 
3649 
set(const String & entry_name,const RealRealMapArray & rrma)3650 void ProblemDescDB::set(const String& entry_name, const RealRealMapArray& rrma)
3651 {
3652   const char *L;
3653   if (!dbRep)
3654     Null_rep1("set(RealRealMapArray&)");
3655   if ((L = Begins(entry_name, "variables."))) {
3656     if (dbRep->variablesDBLocked)
3657       Locked_db();
3658     #define P &DataVariablesRep::
3659     static KW<RealRealMapArray, DataVariablesRep> RRMAdv[] = {
3660       // must be sorted by string (key)
3661 	{"discrete_uncertain_set_real.values_probs",
3662 	 P discreteUncSetRealValuesProbs}};
3663     #undef P
3664 
3665     KW<RealRealMapArray, DataVariablesRep> *kw;
3666     if ((kw = (KW<RealRealMapArray, DataVariablesRep>*)Binsearch(RRMAdv, L))) {
3667       dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = rrma;
3668       return;
3669     }
3670   }
3671   Bad_name(entry_name, "set(RealRealMapArray&)");
3672 }
3673 
3674 void ProblemDescDB::
set(const String & entry_name,const RealRealPairRealMapArray & rrrma)3675 set(const String& entry_name, const RealRealPairRealMapArray& rrrma)
3676 {
3677   const char *L;
3678   if (!dbRep)
3679     Null_rep1("set(RealRealPairRealMapArray&)");
3680   if ((L = Begins(entry_name, "variables."))) {
3681     if (dbRep->variablesDBLocked)
3682       Locked_db();
3683     #define P &DataVariablesRep::
3684     static KW<RealRealPairRealMapArray, DataVariablesRep> RRRMAdv[] = {
3685       // must be sorted by string (key)
3686 	{"continuous_interval_uncertain.basic_probs",
3687 	 P continuousIntervalUncBasicProbs}};
3688     #undef P
3689 
3690     KW<RealRealPairRealMapArray, DataVariablesRep> *kw;
3691     if ((kw = (KW<RealRealPairRealMapArray, DataVariablesRep>*)Binsearch(RRRMAdv, L))) {
3692       dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = rrrma;
3693       return;
3694     }
3695   }
3696   Bad_name(entry_name, "set(RealRealPairRealMapArray&)");
3697 }
3698 
3699 void ProblemDescDB::
set(const String & entry_name,const IntIntPairRealMapArray & iirma)3700 set(const String& entry_name, const IntIntPairRealMapArray& iirma)
3701 {
3702   const char *L;
3703   if (!dbRep)
3704     Null_rep1("set(IntIntPairRealMapArray&)");
3705   if ((L = Begins(entry_name, "variables."))) {
3706     if (dbRep->variablesDBLocked)
3707       Locked_db();
3708     #define P &DataVariablesRep::
3709     static KW<IntIntPairRealMapArray, DataVariablesRep> IIRMAdv[] = {
3710       // must be sorted by string (key)
3711 	{"discrete_interval_uncertain.basic_probs",
3712 	 P discreteIntervalUncBasicProbs}};
3713     #undef P
3714 
3715     KW<IntIntPairRealMapArray, DataVariablesRep> *kw;
3716     if ((kw = (KW<IntIntPairRealMapArray, DataVariablesRep>*)Binsearch(IIRMAdv, L))) {
3717       dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = iirma;
3718       return;
3719     }
3720   }
3721   Bad_name(entry_name, "set(IntIntPairRealMapArray&)");
3722 }
3723 
3724 
set(const String & entry_name,const StringArray & sa)3725 void ProblemDescDB::set(const String& entry_name, const StringArray& sa)
3726 {
3727   const char *L;
3728   if (!dbRep)
3729 	Null_rep1("set(StringArray&)");
3730   if ((L = Begins(entry_name, "model."))) {
3731     if (dbRep->modelDBLocked)
3732 	Locked_db();
3733     #define P &DataModelRep::
3734     static KW<StringArray, DataModelRep> SAdmo[] = {
3735       // must be sorted by string (key)
3736 	{"diagnostics", P diagMetrics},
3737 	{"nested.primary_variable_mapping", P primaryVarMaps},
3738 	{"nested.secondary_variable_mapping", P secondaryVarMaps}};
3739     #undef P
3740 
3741     KW<StringArray, DataModelRep> *kw;
3742     if ((kw = (KW<StringArray, DataModelRep>*)Binsearch(SAdmo, L))) {
3743 	dbRep->dataModelIter->dataModelRep.get()->*kw->p = sa;
3744 	return;
3745 	}
3746   }
3747   else if ((L = Begins(entry_name, "variables."))) {
3748     if (dbRep->variablesDBLocked)
3749 	Locked_db();
3750     #define P &DataVariablesRep::
3751     static KW<StringArray, DataVariablesRep> SAdv[] = {
3752       // must be sorted by string (key)
3753 	{"continuous_aleatory_uncertain.labels", P continuousAleatoryUncLabels},
3754 	{"continuous_design.labels", P continuousDesignLabels},
3755 	{"continuous_design.scale_types", P continuousDesignScaleTypes},
3756 	{"continuous_epistemic_uncertain.labels",
3757 	 P continuousEpistemicUncLabels},
3758 	{"continuous_state.labels", P continuousStateLabels},
3759 	{"discrete_aleatory_uncertain_int.labels",
3760 	 P discreteIntAleatoryUncLabels},
3761 	{"discrete_aleatory_uncertain_real.labels",
3762 	 P discreteRealAleatoryUncLabels},
3763 	{"discrete_design_range.labels", P discreteDesignRangeLabels},
3764 	{"discrete_design_set_int.labels", P discreteDesignSetIntLabels},
3765 	{"discrete_design_set_real.labels", P discreteDesignSetRealLabels},
3766 	{"discrete_epistemic_uncertain_int.labels",
3767 	 P discreteIntEpistemicUncLabels},
3768 	{"discrete_epistemic_uncertain_real.labels",
3769 	 P discreteRealEpistemicUncLabels},
3770 	{"discrete_state_range.labels", P discreteStateRangeLabels},
3771 	{"discrete_state_set_int.labels", P discreteStateSetIntLabels},
3772 	{"discrete_state_set_real.labels", P discreteStateSetRealLabels},
3773 	{"discrete_state_set_string.labels", P discreteStateSetStrLabels},
3774 	{"linear_equality_scale_types", P linearEqScaleTypes},
3775 	{"linear_inequality_scale_types", P linearIneqScaleTypes}};
3776     #undef P
3777 
3778     KW<StringArray, DataVariablesRep> *kw;
3779     if ((kw = (KW<StringArray, DataVariablesRep>*)Binsearch(SAdv, L))) {
3780 	dbRep->dataVariablesIter->dataVarsRep.get()->*kw->p = sa;
3781 	return;
3782 	}
3783   }
3784   else if ((L = Begins(entry_name, "responses."))) {
3785     if (dbRep->responsesDBLocked)
3786 	Locked_db();
3787     #define P &DataResponsesRep::
3788     static KW<StringArray, DataResponsesRep> SAdr[] = {
3789       // must be sorted by string (key)
3790 	{"labels", P responseLabels },
3791 	{"nonlinear_equality_scale_types", P nonlinearEqScaleTypes },
3792 	{"nonlinear_inequality_scale_types", P nonlinearIneqScaleTypes },
3793 	{"primary_response_fn_scale_types", P primaryRespFnScaleTypes }};
3794     #undef P
3795 
3796     KW<StringArray, DataResponsesRep> *kw;
3797     if ((kw = (KW<StringArray, DataResponsesRep>*)Binsearch(SAdr, L))) {
3798 	dbRep->dataResponsesIter->dataRespRep.get()->*kw->p = sa;
3799 	return;
3800 	}
3801   }
3802   Bad_name(entry_name, "set(StringArray&)");
3803 }
3804 
3805 
echo_input_file(const std::string & dakota_input_file,const std::string & dakota_input_string,const std::string & tmpl_qualifier)3806 void ProblemDescDB::echo_input_file(const std::string& dakota_input_file,
3807 				    const std::string& dakota_input_string,
3808 				    const std::string& tmpl_qualifier)
3809 {
3810   if (!dakota_input_string.empty()) {
3811     size_t header_len = 23;
3812     std::string header(header_len, '-');
3813     Cout << header << '\n';
3814     Cout << "Begin DAKOTA input file" << tmpl_qualifier << "\n";
3815     if(dakota_input_file == "-")
3816       Cout << "(from standard input)\n";
3817     else
3818       Cout << "(from string)\n";
3819     Cout << header << std::endl;
3820     Cout << dakota_input_string << std::endl;
3821     Cout << "---------------------\n";
3822     Cout << "End DAKOTA input file\n";
3823     Cout << "---------------------\n" << std::endl;
3824   } else if(!dakota_input_file.empty()) {
3825       std::ifstream inputstream(dakota_input_file.c_str());
3826       if (!inputstream.good()) {
3827 	Cerr << "\nError: Could not open input file '" << dakota_input_file
3828 	     << "' for reading." << std::endl;
3829 	abort_handler(IO_ERROR);
3830       }
3831 
3832       // BMA TODO: could enable this now
3833       // want to output FQ path, but only valid in BFS v3; need wrapper
3834       //boost::filesystem::path bfs_file(dakota_input_file);
3835       //boost::filesystem::path bfs_abs_path = bfs_file.absolute();
3836 
3837       // header to span the potentially long filename
3838       size_t header_len = std::max((size_t) 23,
3839 				   dakota_input_file.size());
3840       std::string header(header_len, '-');
3841       Cout << header << '\n';
3842       Cout << "Begin DAKOTA input file" << tmpl_qualifier << "\n";
3843       Cout << dakota_input_file << "\n";
3844       Cout << header << std::endl;
3845       int inputchar = inputstream.get();
3846       while (inputstream.good()) {
3847 	Cout << (char) inputchar;
3848 	inputchar = inputstream.get();
3849       }
3850       Cout << "---------------------\n";
3851       Cout << "End DAKOTA input file\n";
3852       Cout << "---------------------\n" << std::endl;
3853   }
3854 }
3855 
3856 /** Require string idenfitiers id_* to be unique across all blocks of
3857     each type (method, model, variables, interface, responses
3858 
3859     For now, this allows duplicate empty ID strings. Would be better
3860     to require unique IDs when more than one block of a given type
3861     appears in the input file (instead of use-the-last-parsed)
3862 */
enforce_unique_ids()3863 void ProblemDescDB::enforce_unique_ids()
3864 {
3865   bool found_error = false;
3866   std::multiset<String> block_ids;
3867 
3868   // Lambda to detect duplicate for the passed id, issuing error
3869   // message for the specified block_type. Modifies set of block_ids
3870   // and found_error status.
3871   auto check_unique = [&block_ids, &found_error] (String block_type, String id) {
3872     if (!id.empty()) {
3873       block_ids.insert(id);
3874       // (Only warn once per unique ID name)
3875       if (block_ids.count(id) == 2) {
3876 	Cerr << "Error: id_" << block_type << " '" << id
3877 	     << "' appears more than once.\n";
3878 	found_error = true;
3879       }
3880     }
3881   };
3882 
3883   // This could be written more generically if the member was always
3884   // called idString instead of a different name (idMethod, idModel,
3885   // etc.) for each Data* class...; then the same code could apply to
3886   // all data*List
3887   for (auto data_cont : dataMethodList)
3888     check_unique("method", data_cont.data_rep()->idMethod);
3889   block_ids.clear();
3890 
3891   for (auto data_cont : dataModelList)
3892     check_unique("model", data_cont.data_rep()->idModel);
3893   block_ids.clear();
3894 
3895   for (auto data_cont : dataVariablesList)
3896     check_unique("variables", data_cont.data_rep()->idVariables);
3897   block_ids.clear();
3898 
3899   for (auto data_cont : dataInterfaceList)
3900     check_unique("interface", data_cont.data_rep()->idInterface);
3901   block_ids.clear();
3902 
3903   for (auto data_cont : dataResponsesList)
3904     check_unique("responses", data_cont.data_rep()->idResponses);
3905   block_ids.clear();
3906 
3907   if (found_error)
3908     abort_handler(PARSE_ERROR);
3909 }
3910 
3911 } // namespace Dakota
3912