PRISMS-PF  v2.1
test_NonlinearSolverParameters.h
Go to the documentation of this file.
1 // Unit tests for the class "nonlinearSolverParameters"
2 #include "../../include/SolverParameters.h"
3 
4 template <int dim,typename T>
6 
7  char buffer[100];
8 
9  std::cout << "\nTesting 'NonlinearSolverParameters'... " << std::endl;
10 
11  // Create a nonlinearSolverParameters object
12  NonlinearSolverParameters test_object;
13 
14  test_object.setMaxIterations(123);
15  test_object.loadParameters(2,ABSOLUTE_RESIDUAL,1.0e-3,true,0.5,1.0,1.0,false);
16  test_object.loadParameters(5,RELATIVE_RESIDUAL_CHANGE,1.0e-4,false,0.5,1.0,0.5,false);
17 
18  // Subtests
19  unsigned int subtest_index = 0;
20  bool result;
21  bool pass = true;
22 
23  // Subtest 1
24  subtest_index++;
25  result = false;
26  if (test_object.getMaxIterations() == 123){
27  result = true;
28  }
29  std::cout << "Subtest " << subtest_index << " result for 'getMaxIterations': " << result << std::endl;
30 
31  pass = pass && result;
32 
33  //Subtest 2
34  subtest_index++;
35  result = false;
36  if (test_object.getToleranceType(2) == ABSOLUTE_RESIDUAL && test_object.getToleranceType(5) == RELATIVE_RESIDUAL_CHANGE){
37  result = true;
38  }
39  std::cout << "Subtest " << subtest_index << " result for 'getToleranceType': " << result << std::endl;
40 
41  pass = pass && result;
42 
43  //Subtest 3
44  subtest_index++;
45  result = false;
46  if (std::abs(test_object.getToleranceValue(2) - 1.0e-3) < 1.0e-12 && std::abs(test_object.getToleranceValue(5) - 1.0e-4) < 1.0e-12){
47  result = true;
48  }
49  std::cout << "Subtest " << subtest_index << " result for 'getToleranceValue': " << result << std::endl;
50 
51  pass = pass && result;
52 
53  //Subtest 4
54  subtest_index++;
55  result = false;
56  if (test_object.getBacktrackDampingFlag(2) == true && test_object.getBacktrackDampingFlag(5) == false){
57  result = true;
58  }
59  std::cout << "Subtest " << subtest_index << " result for 'getBacktraceDampingFlag': " << result << std::endl;
60 
61  pass = pass && result;
62 
63  //Subtest 5
64  subtest_index++;
65  result = false;
66  if (std::abs(test_object.getDefaultDampingCoefficient(2) - 1.0) < 1.0e-12 && std::abs(test_object.getDefaultDampingCoefficient(5) - 0.5) < 1.0e-12){
67  result = true;
68  }
69  std::cout << "Subtest " << subtest_index << " result for 'getDefaultDampingCoefficient': " << result << std::endl;
70 
71  pass = pass && result;
72 
73  sprintf (buffer, "Test result for 'NonlinearSolverParameters': %u\n", pass);
74  std::cout << buffer;
75 
76  return pass;
77 }
SolverToleranceType getToleranceType(unsigned int index)
double getDefaultDampingCoefficient(unsigned int index)
bool getBacktrackDampingFlag(unsigned int index)
void loadParameters(unsigned int _var_index, SolverToleranceType _tolerance_type, double _tolerance_value, bool _backtrack_damping_flag, double _backtrack_step_modifier, double _backtrack_residual_decrease_coeff, double _default_dampling_coefficient, bool _laplace_for_initial_guess)
void setMaxIterations(unsigned int _max_iterations)
double getToleranceValue(unsigned int index)