GRINS-0.8.0
Functions
generic_solution_regression.C File Reference
#include "grins_config.h"
#include "grins/runner.h"
#include "grins/mesh_builder.h"
#include "grins/multiphysics_sys.h"
#include "libmesh/exact_solution.h"
Include dependency graph for generic_solution_regression.C:

Go to the source code of this file.

Functions

void test_error_norm (libMesh::ExactSolution &exact_sol, const std::string &system_name, const std::string &var, const std::string &norm, const double tol, int &return_flag)
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 42 of file generic_solution_regression.C.

References GRINS::Runner::get_command_line(), GRINS::Simulation::get_equation_system(), GRINS::Runner::get_input_file(), GRINS::Simulation::get_multiphysics_system(), GRINS::Simulation::get_multiphysics_system_name(), GRINS::Runner::get_simulation(), GRINS::Runner::init(), GRINS::Runner::run(), and test_error_norm().

43 {
44  GRINS::Runner grins(argc,argv);
45 
46  const GetPot & command_line = grins.get_command_line();
47 
48  if( !command_line.have_variable("soln-data") )
49  {
50  std::cerr << "ERROR: Must specify solution data on command line with soln-data=<file>." << std::endl;
51  exit(1);
52  }
53 
54  if( !command_line.have_variable("vars") )
55  {
56  std::cerr << "ERROR: Must specify variables on command line with vars='var1 var2'" << std::endl;
57  exit(1);
58  }
59 
60  if( !command_line.have_variable("norms") )
61  {
62  std::cerr << "ERROR: Must specify error norms on command line with norms='L2 H1'" << std::endl;
63  exit(1);
64  }
65 
66  if( !command_line.have_variable("tol") )
67  {
68  std::cerr << "ERROR: Must specify test tolerance on command line with tol=<tol>" << std::endl;
69  exit(1);
70  }
71 
72  const GetPot & inputfile = grins.get_input_file();
73 
74  // Don't flag our command-line-specific variables as UFOs later
75  inputfile.have_variable("soln-data");
76  inputfile.have_variable("vars");
77  inputfile.have_variable("norms");
78  inputfile.have_variable("tol");
79  inputfile.have_variable("qois");
80 
81  // Initialize Simulation
82  grins.init();
83 
84  // Do solve here
85  grins.run();
86 
87  GRINS::Simulation & sim = grins.get_simulation();
88 
89  // Get equation systems to create ExactSolution object
90  GRINS::SharedPtr<libMesh::EquationSystems> es = sim.get_equation_system();
91 
92  // Create Exact solution object and attach exact solution quantities
93  libMesh::ExactSolution exact_sol(*es);
94 
95  libMesh::EquationSystems es_ref( es->get_mesh() );
96 
97  // Filename of file where comparison solution is stashed
98  std::string solution_file = command_line("soln-data", "DIE!");
99  es_ref.read( solution_file );
100 
101  exact_sol.attach_reference_solution( &es_ref );
102 
103  // Now grab the variables for which we want to compare
104  unsigned int n_vars = command_line.vector_variable_size("vars");
105  std::vector<std::string> vars(n_vars);
106  for( unsigned int v = 0; v < n_vars; v++ )
107  {
108  vars[v] = command_line("vars", "DIE!", v);
109  }
110 
111  // Now grab the norms to compute for each variable error
112  unsigned int n_norms = command_line.vector_variable_size("norms");
113  std::vector<std::string> norms(n_norms);
114  for( unsigned int n = 0; n < n_norms; n++ )
115  {
116  norms[n] = command_line("norms", "DIE!", n);
117  if( norms[n] != std::string("L2") &&
118  norms[n] != std::string("H1") )
119  {
120  std::cerr << "ERROR: Invalid norm input " << norms[n] << std::endl
121  << " Valid values are: L2" << std::endl
122  << " H1" << std::endl;
123  }
124  }
125 
126  const std::string& system_name = sim.get_multiphysics_system_name();
127 
128  // Now compute error for each variable
129  for( unsigned int v = 0; v < n_vars; v++ )
130  {
131  exact_sol.compute_error(system_name, vars[v]);
132  }
133 
134  int return_flag = 0;
135 
136  double tol = command_line("tol", 1.0e-10);
137 
138  // Now test error for each variable, for each norm
139  for( unsigned int v = 0; v < n_vars; v++ )
140  {
141  for( unsigned int n = 0; n < n_norms; n++ )
142  {
143  test_error_norm( exact_sol, system_name, vars[v], norms[n], tol, return_flag );
144  }
145  }
146 
147  // Now grab any "gold" QoI values
148  unsigned int n_qoi_vals = command_line.vector_variable_size("qois");
149  for( unsigned int n = 0; n < n_qoi_vals; n++ )
150  {
151 
152  std::cout << "==========================================================" << std::endl
153  << "Checking qoi " << n << " with tol " << tol << "...";
154 
155  libMesh::Number gold_qoi = command_line("qois", libMesh::Number(0), n);
156 
157  libMesh::Number computed_qoi =
158  sim.get_multiphysics_system()->qoi[n];
159 
160  double error = computed_qoi - gold_qoi;
161 
162  if (std::abs(error) > tol)
163  {
164  std::cerr << "Tolerance exceeded for generic regression test!" << std::endl
165  << "tolerance = " << tol << std::endl
166  << "error = " << error << std::endl
167  << "qoi index = " << n << std::endl;
168  return_flag = 1;
169  }
170  else
171  std::cout << "PASSED!" << std::endl
172  << "==========================================================" << std::endl;
173 
174  }
175 
176 
177  return return_flag;
178 }
SharedPtr< libMesh::EquationSystems > get_equation_system()
Definition: simulation.C:393
MultiphysicsSystem * get_multiphysics_system()
Definition: simulation.h:179
const std::string & get_multiphysics_system_name() const
Definition: simulation.h:185
Class to encapsulate initializing and running GRINS Simulation.
Definition: runner.h:47
void test_error_norm(libMesh::ExactSolution &exact_sol, const std::string &system_name, const std::string &var, const std::string &norm, const double tol, int &return_flag)
void test_error_norm ( libMesh::ExactSolution &  exact_sol,
const std::string &  system_name,
const std::string &  var,
const std::string &  norm,
const double  tol,
int &  return_flag 
)

Definition at line 180 of file generic_solution_regression.C.

Referenced by main().

186 {
187  // We don't set return_flag unless we are setting it 1
188  // since this function gets called multiple times and we don't
189  // want to overwrite a previous "fail" (return_flag = 1) with
190  // a "pass" (return_flag = 0)
191 
192  double error = 0.0;
193 
194  std::cout << "==========================================================" << std::endl
195  << "Checking variable " << var << " using error norm " << norm << " with tol " << tol << "...";
196 
197  if( norm == std::string("L2") )
198  {
199  error = exact_sol.l2_error(system_name, var);
200  }
201  else if( norm == std::string("H1") )
202  {
203  error = exact_sol.h1_error(system_name, var);
204  }
205  else
206  {
207  std::cerr << "ERROR: Invalid norm " << norm << std::endl;
208  exit(1);
209  }
210 
211  if( error > tol )
212  {
213  return_flag = 1;
214 
215  std::cerr << "Tolerance exceeded for generic regression test!" << std::endl
216  << "tolerance = " << tol << std::endl
217  << "norm of error = " << error << std::endl
218  << "norm type = " << norm << std::endl
219  << "var = " << var << std::endl;
220  }
221  else
222  {
223  std::cout << "PASSED!" << std::endl
224  << "==========================================================" << std::endl;
225  }
226 
227  return;
228 }

Generated on Tue Dec 19 2017 12:47:29 for GRINS-0.8.0 by  doxygen 1.8.9.1