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 #include <thread>
15
main(int argc,char ** argv)16 int main(int argc, char** argv)
17 {
18
19 std::ifstream fin(argv[1]);
20 size_t i, j, k, num_vars, num_fns, num_deriv_vars;
21 std::string vars_text, fns_text, dvv_text;
22
23 // Get the parameter std::vector and ignore the labels
24 fin >> num_vars >> vars_text;
25 if (!fin) {
26 std::cerr << "\nError: failure opening " << argv[1] << std::endl;
27 exit(-1);
28 }
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 //std::this_thread::sleep_for(std::chrono::seconds(1));
52
53 // Compute the results and output them directly to argv[2] (the NO_FILTER
54 // option is used). Response tags are now optional; output them for ease
55 // of results readability.
56 std::ofstream fout(argv[2]);
57 if (!fout) {
58 std::cerr << "\nError: failure creating " << argv[2] << std::endl;
59 exit(-1);
60 }
61 fout.precision(15); // 16 total digits
62 fout.setf(std::ios::scientific);
63 fout.setf(std::ios::right);
64
65 // text_book2 calculates active c1 data & outputs 0's for active f & c2 data
66
67 // **** c1:
68 for (i=0; i<num_fns; i++) {
69 if (i==1) {
70 if (ASV[1] & 1)
71 fout << " " << x[0]*x[0] - 0.5*x[1] << " fn1\n";
72 }
73 else if (ASV[i] & 1)
74 fout << " 0.0 fn" << i << '\n';
75 }
76
77 // **** dc1/dx:
78 for (i=0; i<num_fns; i++) {
79 if (i==1) {
80 if (ASV[1] & 2) {
81 fout << "[ ";
82 for (j=0; j<num_deriv_vars; j++) {
83 int var_index = DVV[j] - 1;
84 if (var_index == 0)
85 fout << 2.*x[0] << ' ';
86 else if (var_index == 1)
87 fout << -0.5 << ' ';
88 else
89 fout << "0. ";
90 }
91 fout << "]\n";
92 }
93 }
94 else if (ASV[i] & 2) {
95 fout << "[ ";
96 for (j=0; j<num_deriv_vars; j++)
97 fout << "0. ";
98 fout << "]\n";
99 }
100 }
101
102 // **** d^2c1/dx^2: (ParamStudy testing of multiple Hessian matrices)
103 for (i=0; i<num_fns; i++) {
104 if (i==1) {
105 if (ASV[1] & 4) {
106 fout << "[[ ";
107 for (j=0; j<num_deriv_vars; j++) {
108 int var_index_j = DVV[j] - 1;
109 for (k=0; k<num_deriv_vars; k++) {
110 int var_index_k = DVV[k] - 1;
111 if (var_index_j==0 && var_index_k==0)
112 fout << 2. << ' ';
113 else
114 fout << "0. ";
115 }
116 }
117 fout << "]]\n";
118 }
119 }
120 else if (ASV[i] & 4) {
121 fout << "[[ ";
122 for (j=0; j<num_deriv_vars; j++)
123 for (k=0; k<num_deriv_vars; k++)
124 fout << "0. ";
125 fout << "]]\n";
126 }
127 }
128
129 fout.flush();
130 fout.close();
131 return 0;
132 }
133