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 != 6 || num_fns != 1) {
52     std::cerr << "Error: wrong number of inputs/outputs in portal_frame." << 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   // Verification test for second-order integration in reliability methods.
69   // Taken from Tvedt (1990), Hong (1999), etc.
70   //   g = x1 + 2*x2 + 2*x3 + x4 - 5*x5 - 5*x6
71   // "one plastic collapse mechanism of a simple portal frame"
72   // Note: the limit state is linear in x-space, but the u-space transformation
73   // for lognormals introduces curvature.
74 
75   // **** g (limit state = portal frame response):
76   if (ASV[0] & 1)
77     fout << "                     "
78 	 << x[0] + 2.*x[1] + 2.*x[2] + x[3] - 5.*x[4] - 5.*x[5] << " g\n";
79 
80   // **** dg/dx (w.r.t. active/uncertain variables):
81   if (ASV[0] & 2) {
82     fout << "[ ";
83     for (i=0; i<num_deriv_vars; i++) {
84       int var_index = DVV[i] - 1;
85       switch (var_index) {
86       case 0:
87 	fout << "1. ";
88 	break;
89       case 1:
90 	fout << "2. ";
91 	break;
92       case 2:
93 	fout << "2. ";
94 	break;
95       case 3:
96 	fout << "1. ";
97 	break;
98       case 4:
99 	fout << "-5. ";
100 	break;
101       case 5:
102 	fout << "-5. ";
103 	break;
104       }
105     }
106     fout << "]\n";
107   }
108 
109   // **** d^2g/dx^2: (SORM)
110   if (ASV[0] & 4) {
111     fout << "[[ ";
112     for (i=0; i<num_deriv_vars; i++)
113       for (j=0; j<num_deriv_vars; j++)
114 	fout << "0. ";
115     fout << "]]\n";
116   }
117 
118   fout.flush();
119   fout.close();
120   return 0;
121 }
122