Skip to content

Commit

Permalink
Merge pull request #2600 from jperryhouts/simple_prm_validation
Browse files Browse the repository at this point in the history
Add basic parameter file validation mode.
  • Loading branch information
gassmoeller committed Aug 24, 2018
2 parents ddaf6af + 60809e1 commit edfa6b7
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions source/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ void print_help()
<< " -j, --threads (to use multi-threading)\n"
<< " --output-xml (print parameters in xml format to standard output and exit)\n"
<< " --output-plugin-graph (write a representation of all plugins to standard output and exit)\n"
<< " --validate (parse parameter file and exit or report errors)\n"
<< " --test (run the unit tests from unit_tests/, run --test -h for more info)\n"
<< std::endl;
}
Expand Down Expand Up @@ -550,13 +551,36 @@ template<int dim>
void
run_simulator(const std::string &input_as_string,
const bool output_xml,
const bool output_plugin_graph)
const bool output_plugin_graph,
const bool validate_only)
{
using namespace dealii;

ParameterHandler prm;
const bool i_am_proc_0 = (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0);
aspect::Simulator<dim>::declare_parameters(prm);

if (validate_only)
{
try
{
parse_parameters (input_as_string, prm);
}
catch (...)
{
throw aspect::QuietException();
}
if (i_am_proc_0)
std::cout << "The provided parameter file is valid.\n\n"
<< "Note: This validation only checks high level "
<< "parameter file errors, like typos in keywords or "
<< "parameter names. It may miss more nuanced errors "
<< "that aren't encountered until the model actually "
<< "begins running."
<< std::endl;
return;
}

parse_parameters (input_as_string, prm);

if (output_xml)
Expand Down Expand Up @@ -601,6 +625,7 @@ int main (int argc, char *argv[])
bool output_help = false;
bool use_threads = false;
bool run_unittests = false;
bool validate_only = false;
int current_argument = 1;

// Loop over all command line arguments. Handle a number of special ones
Expand Down Expand Up @@ -642,6 +667,10 @@ int main (int argc, char *argv[])
run_unittests = true;
break;
}
else if (arg == "--validate")
{
validate_only = true;
}
else
{
// Not a special argument, so we assume that this is the .prm
Expand Down Expand Up @@ -690,7 +719,7 @@ int main (int argc, char *argv[])
if (i_am_proc_0)
{
// Output header, except for a clean output for xml or plugin graph
if (!output_xml && !output_plugin_graph)
if (!output_xml && !output_plugin_graph && !validate_only)
print_aspect_header(std::cout);

if (output_help)
Expand Down Expand Up @@ -754,12 +783,12 @@ int main (int argc, char *argv[])
{
case 2:
{
run_simulator<2>(input_as_string,output_xml,output_plugin_graph);
run_simulator<2>(input_as_string,output_xml,output_plugin_graph,validate_only);
break;
}
case 3:
{
run_simulator<3>(input_as_string,output_xml,output_plugin_graph);
run_simulator<3>(input_as_string,output_xml,output_plugin_graph,validate_only);
break;
}
default:
Expand Down

0 comments on commit edfa6b7

Please sign in to comment.