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 != 2 || num_fns != 1) {
52 std::cerr << "Error: wrong number of inputs/outputs in steel_section." << 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 Haldar & Mahadevan, 2000.
70 // g = F_y * Z - 1140.
71 // "A W16x31 steel section made of A36 steel is suggested to carry an
72 // applied deterministic bending moment of 1140 kip-in"
73
74 double Z = x[0], F_y = x[1];
75
76 // **** g (limit state = portal frame response):
77 if (ASV[0] & 1)
78 fout << " " << F_y * Z - 1140. << " 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 << F_y << ' '; // dg/dZ
88 break;
89 case 1:
90 fout << Z << ' '; // dg/dF_y
91 break;
92 }
93 }
94 fout << "]\n";
95 }
96
97 // **** d^2g/dx^2: (SORM)
98 if (ASV[0] & 4) {
99 fout << "[[ ";
100 for (i=0; i<num_deriv_vars; i++) {
101 int var_index_i = DVV[i] - 1;
102 for (j=0; j<num_deriv_vars; j++) {
103 int var_index_j = DVV[j] - 1;
104 if ( (var_index_i == 0 && var_index_j == 1) ||
105 (var_index_i == 1 && var_index_j == 0) ) // d^2g/dF_ydZ
106 fout << "1. ";
107 else
108 fout << "0. ";
109 }
110 }
111 fout << "]]\n";
112 }
113
114 fout.flush();
115 fout.close();
116 return 0;
117 }
118