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: DataInterface
10 //- Description:
11 //-
12 //-
13 //- Owner: Mike Eldred
14 //- Version: $Id: DataInterface.hpp 6959 2010-09-09 19:10:51Z briadam $
15
16 #ifndef DATA_INTERFACE_H
17 #define DATA_INTERFACE_H
18
19 #include "dakota_system_defs.hpp"
20 #include "dakota_data_types.hpp"
21 #include "dakota_global_defs.hpp"
22 #include "MPIPackBuffer.hpp"
23
24 namespace Dakota {
25
26
27 /// offset for external process interface types
28 #define PROCESS_INTERFACE_BIT 8
29 /// offset for direct coupled interface types
30 #define DIRECT_INTERFACE_BIT 16
31
32 /// special values for interface type
33 enum {
34 // default is for algebraic-only and all other interface types
35 DEFAULT_INTERFACE=0, APPROX_INTERFACE,
36 // external process interfaces
37 FORK_INTERFACE=PROCESS_INTERFACE_BIT, SYSTEM_INTERFACE, GRID_INTERFACE,
38 // direct coupled interfaces
39 TEST_INTERFACE=DIRECT_INTERFACE_BIT,
40 MATLAB_INTERFACE, PYTHON_INTERFACE, SCILAB_INTERFACE
41 };
42
43 // put this helper function here to encourage sync with enum above
interface_enum_to_string(unsigned short interface_type)44 inline String interface_enum_to_string(unsigned short interface_type)
45 {
46 switch (interface_type) {
47 case DEFAULT_INTERFACE: return String("default"); break;
48 case APPROX_INTERFACE: return String("approximation"); break;
49 case FORK_INTERFACE: return String("fork"); break;
50 case SYSTEM_INTERFACE: return String("system"); break;
51 case GRID_INTERFACE: return String("grid"); break;
52 case TEST_INTERFACE: return String("direct"); break;
53 case MATLAB_INTERFACE: return String("matlab"); break;
54 case PYTHON_INTERFACE: return String("python"); break;
55 case SCILAB_INTERFACE: return String("scilab"); break;
56 default:
57 Cerr << "\nError: Unknown interface enum " << interface_type << std::endl;
58 abort_handler(-1);
59 return String();
60 break;
61 }
62 }
63
64
65 /// interface synchronization types
66 enum { SYNCHRONOUS_INTERFACE, ASYNCHRONOUS_INTERFACE };
67
68 /// define algebraic function types
69 enum { OBJECTIVE, INEQUALITY_CONSTRAINT, EQUALITY_CONSTRAINT };
70
71
72 /// Body class for interface specification data.
73
74 /** The DataInterfaceRep class is used to contain the data from a
75 interface keyword specification. Default values are managed in
76 the DataInterfaceRep constructor. Data is public to avoid
77 maintaining set/get functions, but is still encapsulated within
78 ProblemDescDB since ProblemDescDB::dataInterfaceList is private. */
79
80 class DataInterface;
81
82 class DataInterfaceRep
83 {
84 //
85 //- Heading: Friends
86 //
87
88 /// the handle class can access attributes of the body class directly
89 friend class DataInterface;
90
91 public:
92
93 ~DataInterfaceRep(); ///< destructor
94
95 //
96 //- Heading: Data
97 //
98
99 /// string identifier for an interface specification data set
100 /// (from the id_interface specification in \ref InterfIndControl)
101 String idInterface;
102 /// the interface selection: system, fork, direct, or grid
103 unsigned short interfaceType;
104 /// defines the subset of the parameter to response mapping that is
105 /// explicit and algebraic. This is typically a stub.nl filename
106 /// (AMPL format) from JAGUAR.
107 String algebraicMappings;
108 /// the set of analysis drivers for a simulation-based interface
109 /// (from the \c analysis_drivers specification in \ref InterfIndControl)
110 StringArray analysisDrivers;
111 /// the set of analysis components for a simulation-based interface
112 /// (from the \c analysis_components specification in \ref InterfIndControl)
113 String2DArray analysisComponents;
114 /// the input filter for a simulation-based interface (from the \c
115 /// input_filter specification in \ref InterfIndControl)
116 String inputFilter;
117 /// the output filter for a simulation-based interface (from the \c
118 /// output_filter specification in \ref InterfIndControl)
119 String outputFilter;
120 /// the parameters filename for system call and fork interfaces
121 /// (from the \c parameters_file specification in \ref InterfApplicSC
122 /// and \ref InterfApplicF)
123 String parametersFile;
124 /// the results filename for system call and fork interfaces (from
125 /// the \c results_file specification in \ref InterfApplicSC and
126 /// \ref InterfApplicF)
127 String resultsFile;
128 /// currently: when true, don't delete existing results files
129 /// later: when true, also check existing files before doing fork/system call
130 bool allowExistingResultsFlag;
131 /// flag for suppressing command line augmentation of the specified
132 /// analysis_drivers/input_filter/output_filter syntax (from the \c
133 /// verbatim specification in \ref InterfApplicSC and \ref InterfApplicF)
134 bool verbatimFlag;
135 /// flag for aprepro format usage in the parameters file for
136 /// system call and fork interfaces (from the \c aprepro
137 /// specification in \ref InterfApplicSC and \ref InterfApplicF)
138 bool apreproFlag;
139 /// Expected format of results file
140 unsigned short resultsFileFormat;
141 /// flag for file tagging of parameters and results files for
142 /// system call and fork interfaces (from the \c file_tag
143 /// specification in \ref InterfApplicSC and \ref InterfApplicF)
144 bool fileTagFlag;
145 /// flag for saving of parameters and results files for
146 /// system call and fork interfaces (from the \c file_save
147 /// specification in \ref InterfApplicSC and \ref InterfApplicF)
148 bool fileSaveFlag;
149 // names of host machines for a grid interface (from the
150 // \c hostnames specification in \ref InterfApplicG)
151 //StringArray gridHostNames;
152 // processors per host machine for a grid interface (from the \c
153 // processors_per_host specification in \ref InterfApplicG)
154 //IntArray gridProcsPerHost;
155 /// Batch or sequential evaluation mode (true for batch)
156 bool batchEvalFlag;
157 /// parallel mode for a simulation-based interface: true for
158 /// asynchronous (from the \c asynchronous specification in \ref
159 /// InterfIndControl)
160 bool asynchFlag;
161 /// evaluation concurrency for asynchronous simulation-based interfaces (from
162 /// the \c evaluation_concurrency specification in \ref InterfIndControl)
163 int asynchLocalEvalConcurrency;
164 /// scheduling approach for asynchronous local evaluations:
165 /// {DEFAULT,DYNAMIC,STATIC}_SCHEDULING (from the \c
166 /// local_evaluation_scheduling specification in \ref InterfIndControl)
167 short asynchLocalEvalScheduling;
168 /// analysis concurrency for asynchronous simulation-based interfaces
169 /// (from the \c analysis_concurrency specification in \ref InterfIndControl)
170 int asynchLocalAnalysisConcurrency;
171 /// number of evaluation servers to be used in the parallel configuration
172 /// (from the \c evaluation_servers specification in \ref InterfIndControl)
173 int evalServers;
174 /// the scheduling approach to be used for concurrent evaluations
175 /// within an iterator: {DEFAULT,MASTER,PEER_DYNAMIC,PEER_STATIC}_SCHEDULING
176 /// (from the \c evaluation_scheduling specification in \ref InterfIndControl)
177 short evalScheduling;
178 /// processors per parallel evaluation within the parallel configuration
179 /// (from the \c processors_per_evaluation spec in \ref InterfIndControl)
180 int procsPerEval;
181 /// number of analysis servers to be used in the parallel configuration
182 /// (from the \c analysis_servers specification in \ref InterfIndControl)
183 int analysisServers;
184 /// the scheduling approach to be used for concurrent analyses within
185 /// a function evaluation: {DEFAULT,MASTER,PEER}_SCHEDULING (from the
186 /// \c analysis_scheduling specification in \ref InterfIndControl)
187 short analysisScheduling;
188 /// processors per parallel analysis for a direct interface (from the
189 /// \c processors_per_analysis specification in \ref InterfApplicDF)
190 int procsPerAnalysis;
191 /// the selected action upon capture of a simulation failure:
192 /// abort, retry, recover, or continuation (from the \c failure_capture
193 /// specification in \ref InterfIndControl)
194 String failAction;
195 /// the limit on retries for captured simulation failures (from the
196 /// \c retry specification in \ref InterfIndControl)
197 int retryLimit;
198 /// the function values to be returned in a recovery operation for
199 /// captured simulation failures (from the \c recover specification
200 /// in \ref InterfIndControl)
201 RealVector recoveryFnVals;
202 /// active set vector: 1=active (ASV control on), 0=inactive (ASV control
203 /// off) (from the \c deactivate \c active_set_vector specification in
204 /// \ref InterfIndControl)
205 bool activeSetVectorFlag;
206 /// flag for deactivating lookups within the function evaluation
207 /// cache (from the \c deactivate \c evaluation_cache specification
208 /// in \ref InterfIndControl)
209 bool evalCacheFlag;
210 /// flag enabling use of tolerance-based evaluation cache lookups
211 /// (from the \c deactivate \c strict_cache_equality specification
212 /// in \ref InterfIndControl)
213 bool nearbyEvalCacheFlag;
214 /// numerical tolerance for nearby evaluation cache lookups
215 Real nearbyEvalCacheTol;
216 /// function evaluation cache: 1=active (all new evaluations written to
217 /// restart), 0=inactive (no records written to restart) (from the
218 /// \c deactivate \c restart_file specification in \ref InterfIndControl)
219 bool restartFileFlag;
220 /// whether to use a new or specified work_directory
221 bool useWorkdir;
222 /// its name, if specified...
223 String workDir;
224 /// whether to tag the working_directory
225 bool dirTag;
226 /// whether dir_save was specified
227 bool dirSave;
228 /// files to link into work directories
229 StringArray linkFiles;
230 /// files to copy into work directories
231 StringArray copyFiles;
232 /// whether to replace / overwrite existing files
233 bool templateReplace;
234 /// Python interface: use NumPy data structures (default is list data)
235 bool numpyFlag;
236
237 private:
238
239 //
240 //- Heading: Constructors, destructor, operators
241 //
242
243 DataInterfaceRep(); ///< constructor
244
245 //
246 //- Heading: Member methods
247 //
248
249 /// write a DataInterfaceRep object to an std::ostream
250 void write(std::ostream& s) const;
251
252 /// read a DataInterfaceRep object from a packed MPI buffer
253 void read(MPIUnpackBuffer& s);
254 /// write a DataInterfaceRep object to a packed MPI buffer
255 void write(MPIPackBuffer& s) const;
256
257 //
258 //- Heading: Private data members
259 //
260
261 };
262
263
~DataInterfaceRep()264 inline DataInterfaceRep::~DataInterfaceRep()
265 { }
266
267
268 /// Handle class for interface specification data.
269
270 /** The DataInterface class is used to provide a memory management
271 handle for the data in DataInterfaceRep. It is populated by
272 IDRProblemDescDB::interface_kwhandler() and is queried by the
273 ProblemDescDB::get_<datatype>() functions. A list of
274 DataInterface objects is maintained in
275 ProblemDescDB::dataInterfaceList, one for each interface
276 specification in an input file. */
277
278 class DataInterface
279 {
280 //
281 //- Heading: Friends
282 //
283
284 // the problem description database
285 friend class ProblemDescDB;
286 // the NIDR derived problem description database
287 friend class NIDRProblemDescDB;
288
289 public:
290
291 /// compares the idInterface attribute of DataInterface objects
id_compare(const DataInterface & di,const std::string & id)292 static bool id_compare(const DataInterface& di, const std::string& id)
293 { return id == di.dataIfaceRep->idInterface; }
294
295 //
296 //- Heading: Constructors, destructor, operators
297 //
298
299 DataInterface(); ///< constructor
300 DataInterface(const DataInterface&); ///< copy constructor
301 ~DataInterface(); ///< destructor
302
303 DataInterface& operator=(const DataInterface&); ///< assignment operator
304
305 //
306 //- Heading: Member methods
307 //
308
309 /// write a DataInterface object to an std::ostream
310 void write(std::ostream& s) const;
311
312 /// read a DataInterface object from a packed MPI buffer
313 void read(MPIUnpackBuffer& s);
314 /// write a DataInterface object to a packed MPI buffer
315 void write(MPIPackBuffer& s) const;
316
317 /// return dataIfaceRep
318 std::shared_ptr<DataInterfaceRep> data_rep();
319
320 private:
321
322 //
323 //- Heading: Data
324 //
325
326 /// pointer to the body (handle-body idiom)
327 std::shared_ptr<DataInterfaceRep> dataIfaceRep;
328 };
329
330
data_rep()331 inline std::shared_ptr<DataInterfaceRep> DataInterface::data_rep()
332 {return dataIfaceRep; }
333
334
335 /// MPIPackBuffer insertion operator for DataInterface
operator <<(MPIPackBuffer & s,const DataInterface & data)336 inline MPIPackBuffer& operator<<(MPIPackBuffer& s, const DataInterface& data)
337 { data.write(s); return s;}
338
339
340 /// MPIUnpackBuffer extraction operator for DataInterface
operator >>(MPIUnpackBuffer & s,DataInterface & data)341 inline MPIUnpackBuffer& operator>>(MPIUnpackBuffer& s, DataInterface& data)
342 { data.read(s); return s;}
343
344
345 /// std::ostream insertion operator for DataInterface
operator <<(std::ostream & s,const DataInterface & data)346 inline std::ostream& operator<<(std::ostream& s, const DataInterface& data)
347 { data.write(s); return s;}
348
349
write(std::ostream & s) const350 inline void DataInterface::write(std::ostream& s) const
351 { dataIfaceRep->write(s); }
352
353
read(MPIUnpackBuffer & s)354 inline void DataInterface::read(MPIUnpackBuffer& s)
355 { dataIfaceRep->read(s); }
356
357
write(MPIPackBuffer & s) const358 inline void DataInterface::write(MPIPackBuffer& s) const
359 { dataIfaceRep->write(s); }
360
361 } // namespace Dakota
362
363 #endif
364