48 GetPot command_line(argc,argv);
50 if( !command_line.have_variable(
"input") )
52 std::cerr <<
"ERROR: Must specify input file on command line with input=<file>."
57 if( !command_line.have_variable(
"test_data") )
59 std::cerr <<
"ERROR: Must specify solution test data on command line with test_data=<file>."
64 if( !command_line.have_variable(
"vars") )
66 std::cerr <<
"ERROR: Must specify variables on command line with vars='var1 var2'"
71 if( !command_line.have_variable(
"norms") )
73 std::cerr <<
"ERROR: Must specify error norms on command line with norms='L2 H1'"
78 if( !command_line.have_variable(
"tol") )
80 std::cerr <<
"ERROR: Must specify test tolerance on command line with tol=<tol>"
88 unsigned int n_vars = command_line.vector_variable_size(
"vars");
89 std::vector<std::string> vars(n_vars);
90 for(
unsigned int v = 0; v < n_vars; v++ )
92 vars[v] = command_line(
"vars",
"DIE!", v);
96 unsigned int n_norms = command_line.vector_variable_size(
"norms");
97 std::vector<std::string> norms(n_norms);
98 for(
unsigned int n = 0; n < n_norms; n++ )
100 norms[n] = command_line(
"norms",
"DIE!", n);
101 if( norms[n] != std::string(
"L2") )
103 std::cerr <<
"ERROR: Invalid norm input " << norms[n] << std::endl
104 <<
" Valid values are: L2" << std::endl;
109 std::vector<std::vector<libMesh::Real> > error_values;
110 error_values.resize(n_vars);
112 for(
unsigned int v = 0; v < n_vars; v++ )
114 std::string var = vars[v];
116 error_values[v].resize(n_norms);
118 for(
unsigned int n = 0; n < n_norms; n++ )
120 std::string norm_cli = var+
"_"+norms[n]+
"_error";
122 if( !command_line.have_variable(norm_cli) )
124 std::cerr <<
"ERROR: Must specify "+norms[n]+
" errors on command line with "+
125 var+
"_"+norms[n]+
"_error='<error>'" << std::endl;
129 error_values[v][n] = command_line( norm_cli, -1.0 );
131 if( error_values[v][n] < 0.0 )
133 std::cerr <<
"ERROR: Invalid value of error --- norms should be positive!" << std::endl
134 <<
" Found error value: " << error_values[v][n] << std::endl;
141 std::string input_filename = command_line(
"input",
"DIE!");
145 std::ifstream i(input_filename.c_str());
148 std::cerr <<
"Error: Could not read from input file "
149 << input_filename << std::endl;
155 GetPot input( input_filename );
158 libMesh::LibMeshInit libmesh_init(argc, argv);
161 GRINS::SharedPtr<libMesh::UnstructuredMesh> mesh = mesh_builder.
build(input,libmesh_init.comm());
163 libMesh::EquationSystems es(*mesh);
166 std::string test_data = command_line(
"test_data",
"DIE!" );
169 std::ifstream i(test_data.c_str());
172 std::cerr <<
"Error: Could not read from test_data file "
173 << test_data << std::endl;
179 libMesh::EquationSystems::READ_HEADER |
180 libMesh::EquationSystems::READ_DATA |
181 libMesh::EquationSystems::READ_ADDITIONAL_DATA);
183 std::string system_name =
"GRINS-TEST";
184 libMesh::System& system = es.get_system(system_name);
187 libMesh::ExactSolution exact_sol(es);
196 for(
unsigned int v = 0; v < n_vars; v++ )
198 std::string var = vars[v];
199 std::string soln_cli = var+
"_exact_soln";
201 if( !command_line.have_variable(soln_cli) )
203 std::cerr <<
"ERROR: Must specify the exact solution for the variable"+var+
"on" << std::endl
204 <<
" the command line with "+soln_cli+
"=<expression>"
209 unsigned int var_index = system.variable_number(var);
211 std::string parsed_soln = command_line(soln_cli,
"NULL");
213 std::vector<unsigned int> index_map(1,var_index);
219 exact_sol.attach_exact_value(0, &exact_sols);
223 for(
unsigned int v = 0; v < n_vars; v++ )
225 exact_sol.compute_error(system_name, vars[v]);
228 double tol = command_line(
"tol", 1.0e-10);
234 for(
unsigned int v = 0; v < n_vars; v++ )
236 for(
unsigned int n = 0; n < n_norms; n++ )
238 test_flag =
test_error_norm( exact_sol, system_name, vars[v], norms[n], error_values[v][n], tol );
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.
int test_error_norm(libMesh::ExactSolution &exact_sol, const std::string &system_name, const std::string &var, const std::string &norm, const libMesh::Real exact_error, const double tol)