PRISMS-PF  v2.1
test_EquationDependencyParser.h
Go to the documentation of this file.
1 template <int dim,typename T>
3  char buffer[100];
4 
5  std::cout << "\nTesting 'EquationDependencyParser'... " << std::endl;
6  bool pass = true;
7 
8 
9  // Declare all of the variables that go into the function call
10  std::vector<std::string> sorted_dependencies_value_RHS, sorted_dependencies_gradient_RHS, sorted_dependencies_value_LHS, sorted_dependencies_gradient_LHS;
11 
12  // Populate the variable names and equation types
13  std::vector<std::string> var_name;
14  var_name.push_back("a");
15  var_name.push_back("bc");
16 
17  std::vector<PDEType> var_eq_type;
18  var_eq_type.push_back(EXPLICIT_TIME_DEPENDENT);
19  var_eq_type.push_back(TIME_INDEPENDENT);
20 
21 
22  // Populate the dependency strings
23  sorted_dependencies_value_RHS.push_back("a, grad(a), bc");
24  sorted_dependencies_value_RHS.push_back("hess(a),grad(bc)");
25 
26  sorted_dependencies_gradient_RHS.push_back("grad(bc), bc");
27  sorted_dependencies_gradient_RHS.push_back("a,grad(bc)");
28 
29  sorted_dependencies_value_LHS.push_back("");
30  sorted_dependencies_value_LHS.push_back("change(bc),grad(bc),grad(change(bc))");
31 
32  sorted_dependencies_gradient_LHS.push_back("");
33  sorted_dependencies_gradient_LHS.push_back("bc");
34 
35  std::vector<bool> var_nonlinear;
36 
37  EquationDependencyParser equation_dependency_parser;
38 
39  equation_dependency_parser.parse(
40  var_name,
41  var_eq_type,
42  sorted_dependencies_value_RHS,
43  sorted_dependencies_gradient_RHS,
44  sorted_dependencies_value_LHS,
45  sorted_dependencies_gradient_LHS,
46  var_nonlinear);
47 
48  // Check that the boolean vectors were generated correctly
49  bool result;
50  unsigned int subtest_index = 0;
51 
52  // Check need_value_explicit_RHS
53  subtest_index++;
54  result = false;
55  if (equation_dependency_parser.need_value_explicit_RHS.size() == 2){
56  if (equation_dependency_parser.need_value_explicit_RHS[0] == true && equation_dependency_parser.need_value_explicit_RHS[1] == true){
57  result = true;
58  }
59  }
60  std::cout << "Subtest " << subtest_index << " result for 'need_value_explicit_RHS': " << result << std::endl;
61  pass = pass && result;
62 
63  // Check need_gradient_explicit_RHS
64  subtest_index++;
65  result = false;
66  if (equation_dependency_parser.need_value_explicit_RHS.size() == 2){
67  if (equation_dependency_parser.need_gradient_explicit_RHS[0] == true && equation_dependency_parser.need_gradient_explicit_RHS[1] == true){
68  result = true;
69  }
70  }
71 
72  std::cout << "Subtest " << subtest_index << " result for 'need_gradient_explicit_RHS': " << result << std::endl;
73  pass = pass && result;
74 
75  // Check need_hessian_explicit_RHS
76  subtest_index++;
77  result = false;
78  if (equation_dependency_parser.need_value_explicit_RHS.size() == 2){
79  if (equation_dependency_parser.need_hessian_explicit_RHS[0] == false && equation_dependency_parser.need_hessian_explicit_RHS[1] == false){
80  result = true;
81  }
82  }
83 
84  std::cout << "Subtest " << subtest_index << " result for 'need_hessian_explicit_RHS': " << result << std::endl;
85  pass = pass && result;
86 
87  // Check need_value_nonexplicit_RHS
88  subtest_index++;
89  result = false;
90  if (equation_dependency_parser.need_value_nonexplicit_RHS.size() == 2){
91  if (equation_dependency_parser.need_value_nonexplicit_RHS[0] == true && equation_dependency_parser.need_value_nonexplicit_RHS[1] == false){
92  result = true;
93  }
94  }
95 
96  std::cout << "Subtest " << subtest_index << " result for 'need_value_nonexplicit_RHS': " << result << std::endl;
97  pass = pass && result;
98 
99  // Check need_gradient_nonexplicit_RHS
100  subtest_index++;
101  result = false;
102  if (equation_dependency_parser.need_gradient_nonexplicit_RHS.size() == 2){
103  if (equation_dependency_parser.need_gradient_nonexplicit_RHS[0] == false && equation_dependency_parser.need_gradient_nonexplicit_RHS[1] == true){
104  result = true;
105  }
106  }
107 
108  std::cout << "Subtest " << subtest_index << " result for 'need_gradient_nonexplicit_RHS': " << result << std::endl;
109  pass = pass && result;
110 
111  // Check need_hessian_nonexplicit_RHS
112  subtest_index++;
113  result = false;
114  if (equation_dependency_parser.need_hessian_nonexplicit_RHS.size() == 2){
115  if (equation_dependency_parser.need_hessian_nonexplicit_RHS[0] == true && equation_dependency_parser.need_hessian_nonexplicit_RHS[1] == false){
116  result = true;
117  }
118  }
119 
120  std::cout << "Subtest " << subtest_index << " result for 'need_hessian_nonexplicit_RHS': " << result << std::endl;
121  pass = pass && result;
122 
123  // Check need_value_nonexplicit_LHS
124  subtest_index++;
125  result = false;
126  if (equation_dependency_parser.need_value_nonexplicit_LHS.size() == 2){
127  if (equation_dependency_parser.need_value_nonexplicit_LHS[0] == false && equation_dependency_parser.need_value_nonexplicit_LHS[1] == true){
128  result = true;
129  }
130  }
131 
132  std::cout << "Subtest " << subtest_index << " result for 'need_value_nonexplicit_LHS': " << result << std::endl;
133  pass = pass && result;
134 
135  // Check need_gradient_nonexplicit_LHS
136  subtest_index++;
137  result = false;
138  if (equation_dependency_parser.need_gradient_nonexplicit_LHS.size() == 2){
139  if (equation_dependency_parser.need_gradient_nonexplicit_LHS[0] == false && equation_dependency_parser.need_gradient_nonexplicit_LHS[1] == true){
140  result = true;
141  }
142  }
143 
144  std::cout << "Subtest " << subtest_index << " result for 'need_gradient_nonexplicit_LHS': " << result << std::endl;
145  pass = pass && result;
146 
147  // Check need_hessian_nonexplicit_LHS
148  subtest_index++;
149  result = false;
150  if (equation_dependency_parser.need_hessian_nonexplicit_LHS.size() == 2){
151  if (equation_dependency_parser.need_hessian_nonexplicit_LHS[0] == false && equation_dependency_parser.need_hessian_nonexplicit_LHS[1] == false){
152  result = true;
153  }
154  }
155 
156  std::cout << "Subtest " << subtest_index << " result for 'need_hessian_nonexplicit_LHS': " << result << std::endl;
157  pass = pass && result;
158 
159  // Check need_value_change_nonexplicit_LHS
160  subtest_index++;
161  result = false;
162  if (equation_dependency_parser.need_value_change_nonexplicit_LHS.size() == 2){
163  if (equation_dependency_parser.need_value_change_nonexplicit_LHS[0] == false && equation_dependency_parser.need_value_change_nonexplicit_LHS[1] == true){
164  result = true;
165  }
166  }
167 
168  std::cout << "Subtest " << subtest_index << " result for 'need_value_change_nonexplicit_LHS': " << result << std::endl;
169  pass = pass && result;
170 
171  // Check need_gradient_change_nonexplicit_LHS
172  subtest_index++;
173  result = false;
174  if (equation_dependency_parser.need_gradient_change_nonexplicit_LHS.size() == 2){
175  if (equation_dependency_parser.need_gradient_change_nonexplicit_LHS[0] == false && equation_dependency_parser.need_gradient_change_nonexplicit_LHS[1] == true){
176  result = true;
177  }
178  }
179 
180  std::cout << "Subtest " << subtest_index << " result for 'need_gradient_change_nonexplicit_LHS': " << result << std::endl;
181  pass = pass && result;
182 
183  // Check need_hessian_nonexplicit_LHS
184  subtest_index++;
185  result = false;
186  if (equation_dependency_parser.need_hessian_change_nonexplicit_LHS.size() == 2){
187  if (equation_dependency_parser.need_hessian_change_nonexplicit_LHS[0] == false && equation_dependency_parser.need_hessian_change_nonexplicit_LHS[1] == false){
188  result = true;
189  }
190  }
191  std::cout << "Subtest " << subtest_index << " result for 'need_hessian_change_nonexplicit_LHS': " << result << std::endl;
192  pass = pass && result;
193 
194  // Check need_value_residual_explicit_RHS
195  subtest_index++;
196  result = false;
197  if (equation_dependency_parser.need_value_residual_explicit_RHS.size() == 2){
198  if (equation_dependency_parser.need_value_residual_explicit_RHS[0] == true && equation_dependency_parser.need_value_residual_explicit_RHS[1] == false){
199  result = true;
200  }
201  }
202  std::cout << "Subtest " << subtest_index << " result for 'need_value_residual_explicit_RHS': " << result << std::endl;
203  pass = pass && result;
204 
205  // Check need_gradient_residual_explicit_RHS
206  subtest_index++;
207  result = false;
208  if (equation_dependency_parser.need_gradient_residual_explicit_RHS.size() == 2){
209  if (equation_dependency_parser.need_gradient_residual_explicit_RHS[0] == true && equation_dependency_parser.need_gradient_residual_explicit_RHS[1] == false){
210  result = true;
211  }
212  }
213  std::cout << "Subtest " << subtest_index << " result for 'need_gradient_residual_explicit_RHS': " << result << std::endl;
214  pass = pass && result;
215 
216  // Check need_value_residual_nonexplicit_RHS
217  subtest_index++;
218  result = false;
219  if (equation_dependency_parser.need_value_residual_nonexplicit_RHS.size() == 2){
220  if (equation_dependency_parser.need_value_residual_nonexplicit_RHS[0] == false && equation_dependency_parser.need_value_residual_nonexplicit_RHS[1] == true){
221  result = true;
222  }
223  }
224  std::cout << "Subtest " << subtest_index << " result for 'need_value_residual_nonexplicit_RHS': " << result << std::endl;
225  pass = pass && result;
226 
227  // Check need_gradient_residual_nonexplicit_RHS
228  subtest_index++;
229  result = false;
230  if (equation_dependency_parser.need_gradient_residual_nonexplicit_RHS.size() == 2){
231  if (equation_dependency_parser.need_gradient_residual_nonexplicit_RHS[0] == false && equation_dependency_parser.need_gradient_residual_nonexplicit_RHS[1] == true){
232  result = true;
233  }
234  }
235  std::cout << "Subtest " << subtest_index << " result for 'need_gradient_residual_nonexplicit_RHS': " << result << std::endl;
236  pass = pass && result;
237 
238  // Check need_value_residual_nonexplicit_LHS
239  subtest_index++;
240  result = false;
241  if (equation_dependency_parser.need_value_residual_nonexplicit_LHS.size() == 2){
242  if (equation_dependency_parser.need_value_residual_nonexplicit_LHS[0] == false && equation_dependency_parser.need_value_residual_nonexplicit_LHS[1] == true){
243  result = true;
244  }
245  }
246  std::cout << "Subtest " << subtest_index << " result for 'need_value_residual_nonexplicit_LHS': " << result << std::endl;
247  pass = pass && result;
248 
249  // Check need_gradient_residual_nonexplicit_LHS
250  subtest_index++;
251  result = false;
252  if (equation_dependency_parser.need_gradient_residual_nonexplicit_LHS.size() == 2){
253  if (equation_dependency_parser.need_gradient_residual_nonexplicit_LHS[0] == false && equation_dependency_parser.need_gradient_residual_nonexplicit_LHS[1] == true){
254  result = true;
255  }
256  }
257  std::cout << "Subtest " << subtest_index << " result for 'need_gradient_residual_nonexplicit_LHS': " << result << std::endl;
258  pass = pass && result;
259 
260 
261 
262  sprintf (buffer, "Test result for 'EquationDependencyParser': %u\n", pass);
263  std::cout << buffer;
264 
265  return pass;
266 
267 }
268 
269 template <int dim,typename T>
271  char buffer[100];
272 
273  std::cout << "\nTesting 'EquationDependencyParser'... " << std::endl;
274  bool pass = true;
275 
276 
277  // Declare all of the variables that go into the function call
278  std::vector<std::string> sorted_dependencies_value_RHS, sorted_dependencies_gradient_RHS, sorted_dependencies_value_LHS, sorted_dependencies_gradient_LHS;
279 
280  // Populate the variable names and equation types
281  std::vector<std::string> var_name;
282  var_name.push_back("a");
283  var_name.push_back("bc");
284  var_name.push_back("def");
285  var_name.push_back("ghij");
286  var_name.push_back("klmno");
287 
288  std::vector<PDEType> var_eq_type;
289  var_eq_type.push_back(EXPLICIT_TIME_DEPENDENT); // Not nonlinear by definition
290  var_eq_type.push_back(TIME_INDEPENDENT); // Crafted to be nonlinear due to RHS
291  var_eq_type.push_back(TIME_INDEPENDENT); // Crafted to be nonlinear due to LHS (due to needed non-change version of governing variable)
292  var_eq_type.push_back(TIME_INDEPENDENT); // Crafted to be nonlinear due to LHS (due to needing a non-governing variable)
293  var_eq_type.push_back(TIME_INDEPENDENT); // Crafted to be linear
294 
295 
296  // Populate the dependency strings
297  sorted_dependencies_value_RHS.push_back("bc, def, grad(bc)");
298  sorted_dependencies_value_RHS.push_back("bc, def");
299  sorted_dependencies_value_RHS.push_back("def");
300  sorted_dependencies_value_RHS.push_back("a, ghij");
301  sorted_dependencies_value_RHS.push_back("a, klmno");
302 
303  sorted_dependencies_gradient_RHS.push_back("hess(def), ghij");
304  sorted_dependencies_gradient_RHS.push_back("grad(bc)");
305  sorted_dependencies_gradient_RHS.push_back("");
306  sorted_dependencies_gradient_RHS.push_back("grad(ghij)");
307  sorted_dependencies_gradient_RHS.push_back("grad(klmno)");
308 
309  sorted_dependencies_value_LHS.push_back("");
310  sorted_dependencies_value_LHS.push_back("change(bc)");
311  sorted_dependencies_value_LHS.push_back("change(def)");
312  sorted_dependencies_value_LHS.push_back("change(ghij), grad(def)");
313  sorted_dependencies_value_LHS.push_back("change(klmno), grad(a)");
314 
315  sorted_dependencies_gradient_LHS.push_back("");
316  sorted_dependencies_gradient_LHS.push_back("");
317  sorted_dependencies_gradient_LHS.push_back("grad(def)");
318  sorted_dependencies_gradient_LHS.push_back("");
319  sorted_dependencies_gradient_LHS.push_back("hess(change(klmno))");
320 
321  std::vector<bool> var_nonlinear;
322 
323  EquationDependencyParser equation_dependency_parser;
324 
325  equation_dependency_parser.parse(
326  var_name,
327  var_eq_type,
328  sorted_dependencies_value_RHS,
329  sorted_dependencies_gradient_RHS,
330  sorted_dependencies_value_LHS,
331  sorted_dependencies_gradient_LHS,
332  var_nonlinear);
333 
334  // Check that the boolean vectors were generated correctly
335  bool result;
336  unsigned int subtest_index = 0;
337 
338  // Check explicit parabolic equation
339  subtest_index++;
340  result = false;
341  if (var_nonlinear[0] == false){
342  result = true;
343  }
344  std::cout << "Subtest " << subtest_index << " result for an explicit parabolic equation: " << result << std::endl;
345  pass = pass && result;
346 
347  // Check nonlinear time independent equation w/ nonlinearity due result for nonlinearity due to needing a non-governing variable on the RHS
348  subtest_index++;
349  result = false;
350  if (var_nonlinear[1] == true){
351  result = true;
352  }
353  std::cout << "Subtest " << subtest_index << " result for nonlinearity due to needing a non-governing variable on the RHS: " << result << std::endl;
354  pass = pass && result;
355 
356  // Check nonlinear time independent equation w/ nonlinearity due to needed non-change version of governing variable on the LHS
357  subtest_index++;
358  result = false;
359  if (var_nonlinear[2] == true){
360  result = true;
361  }
362  std::cout << "Subtest " << subtest_index << " result for nonlinearity due to needed non-change version of governing variable on the LHS: " << result << std::endl;
363  pass = pass && result;
364 
365  // Check nonlinear time independent equation w/ nonlinearity due to needing a non-governing variable on the LHS
366  subtest_index++;
367  result = false;
368  if (var_nonlinear[3] == true){
369  result = true;
370  }
371  std::cout << "Subtest " << subtest_index << " result for nonlinearity due to needing a non-governing variable on the LHS: " << result << std::endl;
372  pass = pass && result;
373 
374  // Check linear time independent equation
375  subtest_index++;
376  result = false;
377  if (var_nonlinear[4] == false){
378  result = true;
379  }
380  std::cout << "Subtest " << subtest_index << " result for linear time independent: " << result << std::endl;
381  pass = pass && result;
382 
383 
384 
385  sprintf (buffer, "Test result for 'EquationDependencyParser': %u\n", pass);
386  std::cout << buffer;
387 
388  return pass;
389 
390 }
391 
392 template <int dim,typename T>
394  char buffer[100];
395 
396  std::cout << "\nTesting 'EquationDependencyParser'... " << std::endl;
397  bool pass = true;
398 
399 
400  // Declare all of the variables that go into the function call
401  std::vector<std::string> sorted_dependencies_value, sorted_dependencies_gradient;
402 
403  // Populate the variable names and equation types
404  std::vector<std::string> var_name;
405  var_name.push_back("a");
406  var_name.push_back("bc");
407 
408  std::vector<std::string> pp_var_name;
409  pp_var_name.push_back("pp1");
410  pp_var_name.push_back("pp2");
411  pp_var_name.push_back("pp3");
412 
413  // Populate the dependency strings
414  sorted_dependencies_value.push_back("bc, a, grad(bc)");
415  sorted_dependencies_value.push_back("");
416  sorted_dependencies_value.push_back("a");
417 
418  sorted_dependencies_gradient.push_back("hess(a), bc");
419  sorted_dependencies_gradient.push_back("grad(bc)");
420  sorted_dependencies_gradient.push_back("a");
421 
422  EquationDependencyParser equation_dependency_parser;
423 
424  equation_dependency_parser.pp_parse(
425  var_name,
426  pp_var_name,
427  sorted_dependencies_value,
428  sorted_dependencies_gradient);
429 
430  // Check that the boolean vectors were generated correctly
431  bool result;
432  unsigned int subtest_index = 0;
433 
434  // Check pp_need_value
435  subtest_index++;
436  result = false;
437  if (equation_dependency_parser.pp_need_value.size() == 2){
438  if (equation_dependency_parser.pp_need_value[0] == true && equation_dependency_parser.pp_need_value[1] == true){
439  result = true;
440  }
441  }
442  std::cout << "Subtest " << subtest_index << " result for 'pp_need_value': " << result << std::endl;
443  pass = pass && result;
444 
445  // Check pp_need_gradient
446  subtest_index++;
447  result = false;
448  if (equation_dependency_parser.pp_need_gradient.size() == 2){
449  if (equation_dependency_parser.pp_need_gradient[0] == false && equation_dependency_parser.pp_need_gradient[1] == true){
450  result = true;
451  }
452  }
453 
454  std::cout << "Subtest " << subtest_index << " result for 'pp_need_gradient': " << result << std::endl;
455  pass = pass && result;
456 
457  // Check pp_need_hessian
458  subtest_index++;
459  result = false;
460  if (equation_dependency_parser.pp_need_hessian.size() == 2){
461  if (equation_dependency_parser.pp_need_hessian[0] == true && equation_dependency_parser.pp_need_hessian[1] == false){
462  result = true;
463  }
464  }
465 
466  std::cout << "Subtest " << subtest_index << " result for 'pp_need_hessian': " << result << std::endl;
467  pass = pass && result;
468 
469 
470 
471  // Check pp_need_value_residual
472  subtest_index++;
473  result = false;
474  if (equation_dependency_parser.pp_need_value_residual.size() == 3){
475  if (equation_dependency_parser.pp_need_value_residual[0] == true && equation_dependency_parser.pp_need_value_residual[1] == false && equation_dependency_parser.pp_need_value_residual[2] == true){
476  result = true;
477  }
478  }
479  std::cout << "Subtest " << subtest_index << " result for 'pp_need_value_residual': " << result << std::endl;
480  pass = pass && result;
481 
482  // Check pp_need_gradient_residual
483  subtest_index++;
484  result = false;
485 
486  if (equation_dependency_parser.pp_need_gradient_residual.size() == 3){
487  if (equation_dependency_parser.pp_need_gradient_residual[0] == true && equation_dependency_parser.pp_need_gradient_residual[1] == true && equation_dependency_parser.pp_need_gradient_residual[2] == true){
488  result = true;
489  }
490  }
491  std::cout << "Subtest " << subtest_index << " result for 'pp_need_gradient_residual': " << result << std::endl;
492  pass = pass && result;
493 
494 
495  sprintf (buffer, "Test result for 'EquationDependencyParser': %u\n", pass);
496  std::cout << buffer;
497 
498  return pass;
499 
500 }
std::vector< bool > need_value_explicit_RHS
std::vector< bool > pp_need_gradient_residual
std::vector< bool > need_hessian_nonexplicit_RHS
void parse(std::vector< std::string > var_name, std::vector< PDEType > var_eq_type, std::vector< std::string > sorted_dependencies_value_RHS, std::vector< std::string > sorted_dependencies_gradient_RHS, std::vector< std::string > sorted_dependencies_value_LHS, std::vector< std::string > sorted_dependencies_gradient_LHS, std::vector< bool > &var_nonlinear)
bool test_EquationDependencyParser_postprocessing()
std::vector< bool > need_value_nonexplicit_LHS
std::vector< bool > need_value_change_nonexplicit_LHS
std::vector< bool > need_value_residual_explicit_RHS
bool test_EquationDependencyParser_nonlinear()
std::vector< bool > pp_need_hessian
std::vector< bool > need_gradient_nonexplicit_RHS
std::vector< bool > need_hessian_nonexplicit_LHS
std::vector< bool > need_hessian_change_nonexplicit_LHS
std::vector< bool > need_gradient_nonexplicit_LHS
std::vector< bool > need_gradient_change_nonexplicit_LHS
std::vector< bool > need_value_nonexplicit_RHS
std::vector< bool > need_value_residual_nonexplicit_LHS
std::vector< bool > need_hessian_explicit_RHS
std::vector< bool > pp_need_value_residual
std::vector< bool > pp_need_gradient
std::vector< bool > need_value_residual_nonexplicit_RHS
void pp_parse(std::vector< std::string > var_name, std::vector< std::string > pp_var_name, std::vector< std::string > sorted_dependencies_value, std::vector< std::string > sorted_dependencies_gradient)
std::vector< bool > need_gradient_explicit_RHS
std::vector< bool > need_gradient_residual_nonexplicit_LHS
std::vector< bool > need_gradient_residual_nonexplicit_RHS
bool test_EquationDependencyParser_variables_and_residuals_needed()
std::vector< bool > need_gradient_residual_explicit_RHS