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 #include <cstdlib>
10 #include <iostream>
11 #include <fstream>
12 #include <vector>
13 #include <string>
14
15
main(int argc,char ** argv)16 int main(int argc, char** argv)
17 {
18
19 std::ifstream fin(argv[1]);
20 if (!fin) {
21 std::cerr << "\nError: failure opening " << argv[1] << std::endl;
22 exit(-1);
23 }
24 size_t i, j, num_vars, num_fns, num_deriv_vars;
25 std::string vars_text, fns_text, dvv_text;
26
27 // Get the parameter std::vector and ignore the labels
28 fin >> num_vars >> vars_text;
29 std::vector<double> x(num_vars);
30 for (i=0; i<num_vars; i++) {
31 fin >> x[i];
32 fin.ignore(256, '\n');
33 }
34
35 // Get the ASV std::vector and ignore the labels
36 fin >> num_fns >> fns_text;
37 std::vector<int> ASV(num_fns);
38 for (i=0; i<num_fns; i++) {
39 fin >> ASV[i];
40 fin.ignore(256, '\n');
41 }
42
43 // Get the DVV std::vector and ignore the labels
44 fin >> num_deriv_vars >> dvv_text;
45 std::vector<int> DVV(num_deriv_vars);
46 for (i=0; i<num_deriv_vars; i++) {
47 fin >> DVV[i];
48 fin.ignore(256, '\n');
49 }
50
51 if (num_vars != 3 || num_fns != 1) {
52 std::cerr << "Error: wrong number of inputs/outputs in steel_column_cost."<<std::endl;
53 exit(-1);
54 }
55
56 // Compute the results and output them directly to argv[2] (the NO_FILTER
57 // option is used). Response tags are optional; output them for ease
58 // of results readability.
59 std::ofstream fout(argv[2]);
60 if (!fout) {
61 std::cerr << "\nError: failure creating " << argv[2] << std::endl;
62 exit(-1);
63 }
64 fout.precision(15); // 16 total digits
65 fout.setf(std::ios::scientific);
66 fout.setf(std::ios::right);
67
68 // In the steel column description in Kuschel & Rackwitz, Cost is _not_
69 // defined as a random variable. That is Cost is not a fn(B, D, H), but
70 // is rather defined as a fn(b, d, h). Since dCost/dX|_{X=mean} is not the
71 // same as dCost/dmean for non-normal X (jacobian_dX_dS is not 1), dCost/dX
72 // may not be used and an optional interface must be defined for Cost.
73
74 // b = x[0] = flange breadth (lognormal unc. var., mean is design var.)
75 // d = x[1] = flange thickness (lognormal unc. var., mean is design var.)
76 // h = x[2] = profile height (lognormal unc. var., mean is design var.)
77
78 double b = x[0], d = x[1], h = x[2];
79
80 // **** f (objective = bd + 5h = cost of column):
81 if (ASV[0] & 1)
82 fout << " " << b*d + 5.*h << " f\n";
83
84 // **** df/dx:
85 if (ASV[0] & 2)
86 fout << "[ " << d << ' ' << b << " 5. ]\n";
87
88 // **** d^2f/dx^2:
89 if (ASV[0] & 4)
90 fout << "[[ 0. 1. 0. 1. 0. 0. 0. 0. 0. ]]\n";
91
92 fout.flush();
93 fout.close();
94 return 0;
95 }
96