51 GetPot command_line(argc,argv);
53 if( !command_line.have_variable(
"input") )
55 std::cerr <<
"ERROR: Must specify input file on command line with input=<file>." << std::endl;
59 if( !command_line.have_variable(
"soln-data") )
61 std::cerr <<
"ERROR: Must specify solution data on command line with soln-data=<file>." << std::endl;
65 if( !command_line.have_variable(
"gold-data") )
67 std::cerr <<
"ERROR: Must specify gold data on command line with gold-data=<file>." << std::endl;
71 if( !command_line.have_variable(
"vars") )
73 std::cerr <<
"ERROR: Must specify variables on command line with vars='var1 var2'" << std::endl;
77 if( !command_line.have_variable(
"norms") )
79 std::cerr <<
"ERROR: Must specify error norms on command line with norms='L2 H1'" << std::endl;
83 if( !command_line.have_variable(
"tol") )
85 std::cerr <<
"ERROR: Must specify test tolerance on command line with tol=<tol>" << std::endl;
89 if( command_line.have_variable(
"gold-qoi-names") && !command_line.have_variable(
"qoi-data") )
91 std::cerr <<
"ERROR: Must specify QoI data file on command line with qoi-data=<file>" << std::endl;
95 if( command_line.have_variable(
"gold-qoi-names") && !command_line.have_variable(
"gold-qoi-values") )
97 std::cerr << std::string(
"ERROR: Must specify QoI gold values on command line with gold-qoi-values='qoi1 qoi2'")+
98 std::string(
" in the same order as given in gold-qoi-names") << std::endl;
102 if( command_line.have_variable(
"gold-qoi-names") )
105 unsigned int n_qoi_names = command_line.vector_variable_size(
"gold-qoi-names");
106 unsigned int n_qoi_values = command_line.vector_variable_size(
"gold-qoi-values");
108 if( n_qoi_names != n_qoi_values )
110 std::cerr <<
"ERROR: Must have the same number of gold-qoi-names and gold-qoi-values!" << std::endl;
118 unsigned int n_vars = command_line.vector_variable_size(
"vars");
119 std::vector<std::string> vars(n_vars);
120 for(
unsigned int v = 0; v < n_vars; v++ )
121 vars[v] = command_line(
"vars",
"DIE!", v);
124 unsigned int n_norms = command_line.vector_variable_size(
"norms");
125 std::vector<std::string> norms(n_norms);
126 for(
unsigned int n = 0; n < n_norms; n++ )
128 norms[n] = command_line(
"norms",
"DIE!", n);
129 if( norms[n] != std::string(
"L2") &&
130 norms[n] != std::string(
"H1") )
132 std::cerr <<
"ERROR: Invalid norm input " << norms[n] << std::endl
133 <<
" Valid values are: L2" << std::endl
134 <<
" H1" << std::endl;
139 std::vector<std::string> qoi_names;
140 std::vector<libMesh::Real> qoi_data_values;
141 std::vector<libMesh::Real> qoi_gold_values;
143 if( command_line.have_variable(
"gold-qoi-names") )
145 unsigned int n_qoi_names = command_line.vector_variable_size(
"gold-qoi-names");
146 qoi_names.reserve(n_qoi_names);
147 for(
unsigned int i = 0; i < n_qoi_names; i++ )
148 qoi_names.push_back( command_line(
"gold-qoi-names",
"DIE!") );
151 parse_qoi_data( qoi_names, command_line, qoi_data_values, qoi_gold_values );
154 std::string input_filename = command_line(
"input",
"DIE!");
157 std::ifstream i(input_filename.c_str());
160 std::cerr <<
"Error: Could not read from libMesh input file "
161 << input_filename << std::endl;
167 GetPot input( input_filename );
170 input.parse_command_line(argc, argv);
173 input.have_variable(
"input");
174 input.have_variable(
"soln-data");
175 input.have_variable(
"gold-data");
176 input.have_variable(
"vars");
177 input.have_variable(
"norms");
178 input.have_variable(
"tol");
179 input.have_variable(
"gold-qoi-names");
180 input.have_variable(
"qoi-data");
181 input.have_variable(
"gold-qoi-values");
184 libMesh::LibMeshInit libmesh_init(argc, argv);
187 GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = mesh_builder.
build(input,libmesh_init.comm());
189 libMesh::EquationSystems es(*mesh);
192 std::string soln_data = command_line(
"soln-data",
"DIE!" );
195 std::ifstream i(soln_data.c_str());
198 std::cerr <<
"Error: Could not read from soln_data file "
199 << soln_data << std::endl;
205 libMesh::EquationSystems::READ_HEADER |
206 libMesh::EquationSystems::READ_DATA |
207 libMesh::EquationSystems::READ_ADDITIONAL_DATA);
209 std::string system_name =
"GRINS-TEST";
212 libMesh::EquationSystems es_ref(*mesh);
215 std::string gold_file = command_line(
"gold-data",
"DIE!");
216 es_ref.read( gold_file );
219 libMesh::ExactSolution exact_sol(es);
220 exact_sol.attach_reference_solution( &es_ref );
223 for(
unsigned int v = 0; v < n_vars; v++ )
224 exact_sol.compute_error(system_name, vars[v]);
228 double tol = command_line(
"tol", 1.0e-10);
231 for(
unsigned int v = 0; v < n_vars; v++ )
232 for(
unsigned int n = 0; n < n_norms; n++ )
233 test_error_norm( exact_sol, system_name, vars[v], norms[n], tol, return_flag );
236 unsigned int n_qois = qoi_names.size();
238 for(
unsigned int n = 0; n < n_qois; n++ )
241 std::cout <<
"==========================================================" << std::endl
242 <<
"Checking qoi " << qoi_names[n] <<
" with tol " << tol <<
"...";
244 libMesh::Number gold_qoi = qoi_gold_values[n];
246 libMesh::Number computed_qoi = qoi_data_values[n];
248 double error = computed_qoi - gold_qoi;
250 if (std::abs(error) > tol)
252 std::cerr <<
"Tolerance exceeded for generic regression test!" << std::endl
253 <<
"tolerance = " << tol << std::endl
254 <<
"error = " << error << std::endl
255 <<
"qoi index = " << n << std::endl;
259 std::cout <<
"PASSED!" << std::endl
260 <<
"==========================================================" << std::endl;
void parse_qoi_data(const std::vector< std::string > &qoi_names, const GetPot &command_line, std::vector< libMesh::Real > &qoi_data_values, std::vector< libMesh::Real > &qoi_gold_values)
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)
SharedPtr< libMesh::UnstructuredMesh > build(const GetPot &input, const libMesh::Parallel::Communicator &comm LIBMESH_CAN_DEFAULT_TO_COMMWORLD)
Builds the libMesh::Mesh according to input options.