Hello everyone, I've come across the need to read specific values from a parameter file before I know which values I will be reading later. I can get the code to compile and run, but it shoots out a lot of warnings saying parameters have not been declared.
I've mocked up a small example of this. (attached) I was wondering if there was a way to prevent these warnings from occurring, or a different way I should be calling the parameter file to avoid the issue. -- -Jason Sheldon
#include <base/parsed_function.h>
#include <base/logstream.h>
using namespace dealii;
using namespace dealii::Functions;
int main (int argc, char* argv[])
{
std::string prm_file_name;
std::string system_type;
bool prm_foo;
bool prm_bar;
ParameterHandler prm;
if(argc < 2) {
deallog << "No Parameter File Specified!!!" << std::endl;
deallog << "Using Default Filename: Parameters.prm" << std::endl;
prm_file_name = "parameters.prm";
} else {
prm_file_name = argv[1];
dealii::deallog << "Using Specified Parameter File: "
<< prm_file_name
<< std::endl;
}
prm.declare_entry ("System Type","Error", Patterns::Anything(),"The type of system being solved: eg. foo, bar, etc.");
prm.read_input(prm_file_name);
system_type = prm.get("System Type");
if (system_type == "foo")
{
prm.declare_entry ("prm foo","false", Patterns::Bool(),"Some Boolean: true or false");
prm.read_input(prm_file_name);
prm_foo = prm.get_bool("prm foo");
deallog<<"Code reached foo case and properly set prm foo to "<<prm_foo<<"."<<std::endl;
}
else if (system_type == "bar")
{
prm.declare_entry ("prm bar","false", Patterns::Bool(),"Some other Boolean: true or false");
prm.read_input(prm_file_name);
prm_bar = prm.get_bool("prm bar");
deallog<<"Code reached bar case and properly set prm bar to "<<prm_bar<<"."<<std::endl;
}
else //add more as relevant
{
std::cout <<"Error: You did not specify a valid system type."<<std::endl;
std::exit(EXIT_FAILURE);
}
deallog<<"Output to show code successfully reached the end."<<std::endl;
return 0;
}
PRMTest.prm
Description: Binary data
_______________________________________________ dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii
