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: DataResponses
10 //- Description:
11 //-
12 //-
13 //- Owner: Mike Eldred
14 //- Version: $Id: DataResponses.hpp 6731 2010-04-16 03:42:16Z wjbohnh $
15
16 #ifndef DATA_RESPONSES_H
17 #define DATA_RESPONSES_H
18
19 #include "dakota_system_defs.hpp"
20 #include "dakota_data_types.hpp"
21 #include "MPIPackBuffer.hpp"
22
23 namespace Dakota {
24
25 /// special values for derived Response type
26 enum { BASE_RESPONSE=0, SIMULATION_RESPONSE, EXPERIMENT_RESPONSE };
27
28 /// values for primary response types
29 enum {GENERIC_FNS = 0, OBJECTIVE_FNS, CALIB_TERMS };
30
31 /// Body class for responses specification data.
32
33 /** The DataResponsesRep class is used to contain the data from a
34 responses keyword specification. Default values are managed in
35 the DataResponsesRep constructor. Data is public to avoid
36 maintaining set/get functions, but is still encapsulated within
37 ProblemDescDB since ProblemDescDB::dataResponsesList is private. */
38
39 class DataResponsesRep
40 {
41 //
42 //- Heading: Friends
43 //
44
45 /// the handle class can access attributes of the body class directly
46 friend class DataResponses;
47
48 public:
49
50 ~DataResponsesRep(); ///< destructor
51
52 //
53 //- Heading: Data
54 //
55
56 /// string identifier for the responses specification data set
57 /// (from the \c id_responses specification in \ref RespSetId)
58 String idResponses;
59 /// the response labels array (from the \c response_descriptors
60 /// specification in \ref RespLabels)
61 StringArray responseLabels;
62
63 // counts
64
65 /// number of objective functions (from the \c
66 /// num_objective_functions specification in \ref RespFnOpt)
67 size_t numObjectiveFunctions;
68 /// number of least squares terms (from the \c
69 /// num_calibration_terms specification in \ref RespFnLS)
70 size_t numLeastSqTerms;
71 /// number of nonlinear inequality constraints (from the \c
72 /// num_nonlinear_inequality_constraints specification in \ref RespFnOpt)
73 size_t numNonlinearIneqConstraints;
74 /// number of nonlinear equality constraints (from the \c
75 /// num_nonlinear_equality_constraints specification in \ref RespFnOpt)
76 size_t numNonlinearEqConstraints;
77 /// number of generic response functions (from the \c
78 /// num_response_functions specification in \ref RespFnGen)
79 size_t numResponseFunctions;
80
81 /// scalar_objectives: number of objective functions which are scalar
82 size_t numScalarObjectiveFunctions;
83 /// scalar_calibration_terms: number of calibration terms which are scalar
84 size_t numScalarLeastSqTerms;
85 /// number of scalar nonlinear inequality constraints (from the \c
86 /// num_scalar_nonlinear_inequality_constraints specification in
87 /// \ref RespFnOpt)
88 size_t numScalarNonlinearIneqConstraints;
89 /// number of scalar nonlinear equality constraints (from the \c
90 /// num_scalar_nonlinear_equality_constraints specification in \ref RespFnOpt)
91 size_t numScalarNonlinearEqConstraints;
92 /// scalar_responses: number of response functions which are scalar
93 size_t numScalarResponseFunctions;
94
95 /// field_objectives: number of objective functions which are field-valued
96 size_t numFieldObjectiveFunctions;
97 /// field_calibration_terms: number of calibration terms which are
98 /// field-valued
99 size_t numFieldLeastSqTerms;
100 /// number of field nonlinear inequality constraints (from the \c
101 /// num_scalar_nonlinear_inequality_constraints specification in
102 /// \ref RespFnOpt)
103 size_t numFieldNonlinearIneqConstraints;
104 /// number of field nonlinear equality constraints (from the \c
105 /// num_scalar_nonlinear_equality_constraints specification in \ref RespFnOpt)
106 size_t numFieldNonlinearEqConstraints;
107 /// field_responses: number of response functions which are field-valued
108 size_t numFieldResponseFunctions;
109
110 // response set weights, bounds, targets
111
112 /// optimization sense for each objective function: minimize or maximize
113 StringArray primaryRespFnSense;
114 /// vector of weightings for multiobjective optimization or weighted
115 /// nonlinear least squares (from the \c multi_objective_weights
116 /// specification in \ref RespFnOpt and the \c least_squares_weights
117 /// specification in \ref RespFnLS)
118 RealVector primaryRespFnWeights;
119 /// vector of nonlinear inequality constraint lower bounds (from the \c
120 /// nonlinear_inequality_lower_bounds specification in \ref RespFnOpt)
121 RealVector nonlinearIneqLowerBnds;
122 /// vector of nonlinear inequality constraint upper bounds (from the \c
123 /// nonlinear_inequality_upper_bounds specification in \ref RespFnOpt)
124 RealVector nonlinearIneqUpperBnds;
125 /// vector of nonlinear equality constraint targets (from the \c
126 /// nonlinear_equality_targets specification in \ref RespFnOpt)
127 RealVector nonlinearEqTargets;
128
129 // scaling data
130
131 /// vector of primary response function scaling types (from the \c
132 /// objective_function_scale_types specification in \ref RespFnOpt and
133 /// the \c least_squares_term_scale_types specification in \ref RespFnLS)
134 StringArray primaryRespFnScaleTypes;
135 /// vector of primary response function scaling factors (from the \c
136 /// objective_function_scales specification in \ref RespFnOpt and
137 /// the \c least_squares_term_scales specification in \ref RespFnLS)
138 RealVector primaryRespFnScales;
139 /// vector of nonlinear inequality constraint scaling types (from the \c
140 /// nonlinear_inequality_scale_types specification in \ref RespFnOpt)
141 StringArray nonlinearIneqScaleTypes;
142 /// vector of nonlinear inequality constraint scaling factors (from the \c
143 /// nonlinear_inequality_scales specification in \ref RespFnOpt)
144 RealVector nonlinearIneqScales;
145 /// vector of nonlinear equality constraint scaling types (from the \c
146 /// nonlinear_equality_scale_types specification in \ref RespFnOpt)
147 StringArray nonlinearEqScaleTypes;
148 /// vector of nonlinear equality constraint scaling factors (from the \c
149 /// nonlinear_equality_scales specification in \ref RespFnOpt)
150 RealVector nonlinearEqScales;
151
152 // experimental data (for least squares and Bayesian algorithms)
153
154 /// whether calibration data was specified
155 bool calibrationDataFlag;
156 /// number of distinct experiments in experimental data
157 size_t numExperiments;
158 /// number of experimental configuration vars (state variables) in
159 /// each row of data
160 size_t numExpConfigVars;
161 /// list of num_experiments x num_config_vars configuration variable values
162 RealVector expConfigVars;
163 /// list of variances of errors to be added to simulation responses
164 RealVector simVariance;
165 /// whether one should interpolate between the experiment and simulation field data
166 bool interpolateFlag;
167
168 // next two can be retired?
169 /// list of num_calibration_terms observation data
170 RealVector expObservations;
171 /// list of 1 or num_calibration_terms observation standard deviations
172 RealVector expStdDeviations;
173
174 /// name of experimental data file containing response data (with
175 /// optional state variable and sigma data) to read
176 String scalarDataFileName;
177 /// tabular format of the scalar data file
178 unsigned short scalarDataFormat;
179
180 // derivative settings
181
182 /// gradient type: none, numerical, analytic, or mixed (from the \c
183 /// no_gradients, \c numerical_gradients, \c analytic_gradients, and
184 /// \c mixed_gradients specifications in \ref RespGrad)
185 String gradientType;
186 /// Hessian type: none, numerical, quasi, analytic, or mixed (from
187 /// the \c no_hessians, \c numerical_hessians, \c quasi_hessians,
188 /// \c analytic_hessians, and \c mixed_hessians specifications in
189 /// \ref RespHess)
190 String hessianType;
191 /// option to ignore bounds when doing finite differences (default
192 /// is to honor bounds)
193 bool ignoreBounds;
194 /// Temporary(?) option to use old 2nd-order diffs when computing
195 /// finite-difference Hessians; default is forward differences.
196 bool centralHess;
197 /// quasi-Hessian type: bfgs, damped_bfgs, or sr1 (from the \c bfgs
198 /// and \c sr1 specifications in \ref RespHess)
199 String quasiHessianType;
200 /// numerical gradient method source: dakota or vendor (from the \c
201 /// method_source specification in \ref RespGradNum and \ref RespGradMixed)
202 String methodSource;
203 /// numerical gradient interval type: forward or central (from the \c
204 /// interval_type specification in \ref RespGradNum and \ref RespGradMixed)
205 String intervalType;
206 /// vector of finite difference step sizes for numerical gradients, one step
207 /// size per active continuous variable, used in computing 1st-order forward
208 /// or central differences (from the \c fd_gradient_step_size
209 /// specification in \ref RespGradNum and \ref RespGradMixed)
210 RealVector fdGradStepSize;
211 /// type of finite difference step to use for numerical gradient:
212 /// relative - step length is relative to x
213 /// absolute - step length is what is specified
214 /// bounds - step length is relative to range of x
215 String fdGradStepType;
216 /// vector of finite difference step sizes for numerical Hessians, one step
217 /// size per active continuous variable, used in computing 1st-order
218 /// gradient-based differences and 2nd-order function-based differences
219 /// (from the \c fd_hessian_step_size specification in \ref RespHessNum and
220 /// \ref RespHessMixed)
221 RealVector fdHessStepSize;
222 /// type of finite difference step to use for numerical Hessian:
223 /// relative - step length is relative to x
224 /// absolute - step length is what is specified
225 /// bounds - step length is relative to range of x
226 String fdHessStepType;
227 /// mixed gradient numerical identifiers (from the \c id_numerical_gradients
228 /// specification in \ref RespGradMixed)
229 IntSet idNumericalGrads;
230 /// mixed gradient analytic identifiers (from the \c id_analytic_gradients
231 /// specification in \ref RespGradMixed)
232 IntSet idAnalyticGrads;
233 /// mixed Hessian numerical identifiers (from the \c id_numerical_hessians
234 /// specification in \ref RespHessMixed)
235 IntSet idNumericalHessians;
236 /// mixed Hessian quasi identifiers (from the \c id_quasi_hessians
237 /// specification in \ref RespHessMixed)
238 IntSet idQuasiHessians;
239 /// mixed Hessian analytic identifiers (from the \c id_analytic_hessians
240 /// specification in \ref RespHessMixed)
241 IntSet idAnalyticHessians;
242
243 // Field Data specification
244
245 /// number of entries in each field
246 IntVector fieldLengths;
247 /// number of coordinates per field
248 IntVector numCoordsPerField;
249 /// Field data related storage: whether to read simulation field coordinates
250 bool readFieldCoords;
251 /// Array which specifies the sigma type per response (none, one
252 /// constant value, one per response (vector) or a full covariance matrix
253 StringArray varianceType;
254
255 private:
256
257 //
258 //- Heading: Constructors, destructor, operators
259 //
260
261 DataResponsesRep(); ///< constructor
262
263 //
264 //- Heading: Member methods
265 //
266
267 /// write a DataResponsesRep object to an std::ostream
268 void write(std::ostream& s) const;
269
270 /// read a DataResponsesRep object from a packed MPI buffer
271 void read(MPIUnpackBuffer& s);
272 /// write a DataResponsesRep object to a packed MPI buffer
273 void write(MPIPackBuffer& s) const;
274
275 //
276 //- Heading: Private data members
277 //
278
279 };
280
281
~DataResponsesRep()282 inline DataResponsesRep::~DataResponsesRep()
283 { }
284
285
286 /// Handle class for responses specification data.
287
288 /** The DataResponses class is used to provide a memory management
289 handle for the data in DataResponsesRep. It is populated by
290 IDRProblemDescDB::responses_kwhandler() and is queried by the
291 ProblemDescDB::get_<datatype>() functions. A list of
292 DataResponses objects is maintained in
293 ProblemDescDB::dataResponsesList, one for each responses
294 specification in an input file. */
295
296 class DataResponses
297 {
298 //
299 //- Heading: Friends
300 //
301
302 // the problem description database
303 friend class ProblemDescDB;
304 // the NIDR derived problem description database
305 friend class NIDRProblemDescDB;
306
307 public:
308
309 /// compares the idResponses attribute of DataResponses objects
id_compare(const DataResponses & dr,const std::string & id)310 static bool id_compare(const DataResponses& dr, const std::string& id)
311 { return id == dr.dataRespRep->idResponses; }
312
313 //
314 //- Heading: Constructors, destructor, operators
315 //
316
317 DataResponses(); ///< constructor
318 DataResponses(const DataResponses&); ///< copy constructor
319 ~DataResponses(); ///< destructor
320
321 DataResponses& operator=(const DataResponses&); ///< assignment operator
322
323 //
324 //- Heading: Member methods
325 //
326
327 /// write a DataResponses object to an std::ostream
328 void write(std::ostream& s) const;
329
330 /// read a DataResponses object from a packed MPI buffer
331 void read(MPIUnpackBuffer& s);
332 /// write a DataResponses object to a packed MPI buffer
333 void write(MPIPackBuffer& s) const;
334
335 /// return dataRespRep
336 std::shared_ptr<DataResponsesRep> data_rep();
337
338 private:
339
340 //
341 //- Heading: Data
342 //
343
344 /// pointer to the body (handle-body idiom)
345 std::shared_ptr<DataResponsesRep> dataRespRep;
346 };
347
348
data_rep()349 inline std::shared_ptr<DataResponsesRep> DataResponses::data_rep()
350 {return dataRespRep; }
351
352
353 /// MPIPackBuffer insertion operator for DataResponses
operator <<(MPIPackBuffer & s,const DataResponses & data)354 inline MPIPackBuffer& operator<<(MPIPackBuffer& s, const DataResponses& data)
355 { data.write(s); return s;}
356
357
358 /// MPIUnpackBuffer extraction operator for DataResponses
operator >>(MPIUnpackBuffer & s,DataResponses & data)359 inline MPIUnpackBuffer& operator>>(MPIUnpackBuffer& s, DataResponses& data)
360 { data.read(s); return s;}
361
362
363 /// std::ostream insertion operator for DataResponses
operator <<(std::ostream & s,const DataResponses & data)364 inline std::ostream& operator<<(std::ostream& s, const DataResponses& data)
365 { data.write(s); return s;}
366
write(std::ostream & s) const367 inline void DataResponses::write(std::ostream& s) const
368 { dataRespRep->write(s); }
369
370
read(MPIUnpackBuffer & s)371 inline void DataResponses::read(MPIUnpackBuffer& s)
372 { dataRespRep->read(s); }
373
374
write(MPIPackBuffer & s) const375 inline void DataResponses::write(MPIPackBuffer& s) const
376 { dataRespRep->write(s); }
377
378 } // namespace Dakota
379
380 #endif
381