GRINS-0.6.0
Functions
generic_solution_regression.C File Reference
#include "grins_config.h"
#include "grins/mesh_builder.h"
#include "grins/simulation.h"
#include "grins/simulation_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 43 of file generic_solution_regression.C.

References GRINS::Simulation::run(), and test_error_norm().

44 {
45  GetPot command_line(argc,argv);
46 
47  if( !command_line.have_variable("input") )
48  {
49  std::cerr << "ERROR: Must specify input file on command line with input=<file>." << std::endl;
50  exit(1);
51  }
52 
53  if( !command_line.have_variable("soln-data") )
54  {
55  std::cerr << "ERROR: Must specify solution data on command line with soln-data=<file>." << std::endl;
56  exit(1);
57  }
58 
59  if( !command_line.have_variable("vars") )
60  {
61  std::cerr << "ERROR: Must specify variables on command line with vars='var1 var2'" << std::endl;
62  exit(1);
63  }
64 
65  if( !command_line.have_variable("norms") )
66  {
67  std::cerr << "ERROR: Must specify error norms on command line with norms='L2 H1'" << std::endl;
68  exit(1);
69  }
70 
71  if( !command_line.have_variable("tol") )
72  {
73  std::cerr << "ERROR: Must specify test tolerance on command line with tol=<tol>" << std::endl;
74  exit(1);
75  }
76 
77  // libMesh input file should be first argument
78  std::string libMesh_input_filename = command_line("input", "DIE!");
79 
80  {
81  std::ifstream i(libMesh_input_filename.c_str());
82  if (!i)
83  {
84  std::cerr << "Error: Could not read from libMesh input file "
85  << libMesh_input_filename << std::endl;
86  exit(1);
87  }
88  }
89 
90  // Create our GetPot object.
91  GetPot libMesh_inputfile( libMesh_input_filename );
92 
93  // Initialize libMesh library.
94  libMesh::LibMeshInit libmesh_init(argc, argv);
95 
96  GRINS::SimulationBuilder sim_builder;
97 
98  GRINS::Simulation grins( libMesh_inputfile,
99  command_line,
100  sim_builder,
101  libmesh_init.comm() );
102 
103  // Do solve here
104  grins.run();
105 
106  // Get equation systems to create ExactSolution object
107  std::tr1::shared_ptr<libMesh::EquationSystems> es = grins.get_equation_system();
108 
109  // Create Exact solution object and attach exact solution quantities
110  libMesh::ExactSolution exact_sol(*es);
111 
112  libMesh::EquationSystems es_ref( es->get_mesh() );
113 
114  // Filename of file where comparison solution is stashed
115  std::string solution_file = command_line("soln-data", "DIE!");
116  es_ref.read( solution_file );
117 
118  exact_sol.attach_reference_solution( &es_ref );
119 
120  // Now grab the variables for which we want to compare
121  unsigned int n_vars = command_line.vector_variable_size("vars");
122  std::vector<std::string> vars(n_vars);
123  for( unsigned int v = 0; v < n_vars; v++ )
124  {
125  vars[v] = command_line("vars", "DIE!", v);
126  }
127 
128  // Now grab the norms to compute for each variable error
129  unsigned int n_norms = command_line.vector_variable_size("norms");
130  std::vector<std::string> norms(n_norms);
131  for( unsigned int n = 0; n < n_norms; n++ )
132  {
133  norms[n] = command_line("norms", "DIE!", n);
134  if( norms[n] != std::string("L2") &&
135  norms[n] != std::string("H1") )
136  {
137  std::cerr << "ERROR: Invalid norm input " << norms[n] << std::endl
138  << " Valid values are: L2" << std::endl
139  << " H1" << std::endl;
140  }
141  }
142 
143  const std::string& system_name = grins.get_multiphysics_system_name();
144 
145  // Now compute error for each variable
146  for( unsigned int v = 0; v < n_vars; v++ )
147  {
148  exact_sol.compute_error(system_name, vars[v]);
149  }
150 
151  int return_flag = 0;
152 
153  double tol = command_line("tol", 1.0e-10);
154 
155  // Now test error for each variable, for each norm
156  for( unsigned int v = 0; v < n_vars; v++ )
157  {
158  for( unsigned int n = 0; n < n_norms; n++ )
159  {
160  test_error_norm( exact_sol, system_name, vars[v], norms[n], tol, return_flag );
161  }
162  }
163 
164  return return_flag;
165 }
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 167 of file generic_solution_regression.C.

Referenced by main().

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

Generated on Mon Jun 22 2015 21:32:21 for GRINS-0.6.0 by  doxygen 1.8.9.1