Skip to content
Snippets Groups Projects
Commit dff7ab52 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[params] fix loggingparameter tree test

parent 90d8d347
Loading
[TimeLoop]
TEnd = 1e6
[Bulk.TimeLoop]
TEnd = 1e5
[Grid]
Cells = 100 100
Bells = 10 10
#include <config.h>
#include <iostream>
#include <dune/common/parametertreeparser.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/exceptions.hh>
#include <dumux/common/propertysystem.hh>
#include <dumux/common/parameters.hh>
#include <dumux/common/parameterparser.hh>
namespace Dumux {
namespace Properties
{
NEW_TYPE_TAG(Bla);
NEW_PROP_TAG(TimeLoopTLEnd);
NEW_PROP_TAG(Scalar);
SET_TYPE_PROP(Bla, Scalar, double);
SET_SCALAR_PROP(Bla, TimeLoopTLEnd, 2.0);
}
}
int main (int argc, char *argv[]) try
{
using namespace Dumux;
using TypeTag = TTAG(Bla);
// maybe initialize mpi
Dune::MPIHelper::instance(argc, argv);
// parse the input file into the parameter tree
// Dune::ParameterTree tree;
// Dumux::ParameterParser::parseInputFile(argc, argv, tree, "params.input");
//
// // attach the tree to the logging tree
// Dumux::LoggingParameterTree params(tree);
//
// // use some default parameters
// bool DUNE_UNUSED(enableGravity) = params.get<bool>("Problem.EnableGravity", true);
//
// // use some given parameters
// const auto DUNE_UNUSED(cells) = params.get<std::array<int, 2>>("Grid.Cells", {1, 1});
// const auto DUNE_UNUSED(tEnd) = params.get<double>("TimeLoop.TEnd");
//
// // check the unused keys
// const auto unused = params.getUnusedKeys();
// if (unused.size() != 1)
// DUNE_THROW(Dune::InvalidStateException, "There should be exactly one unused key!");
// else if (unused[0] != "Grid.Bells")
// DUNE_THROW(Dune::InvalidStateException, "Unused key \"Grid.Bells\" not found!");
//
// params.reportAll();
// initialize parameter tree
Parameters::init(argc, argv, "params.input");
// use some default parameters
bool enableGravity = getParam<bool>("Problem.EnableGravity", false); // used user default
std::cout << enableGravity << std::endl;
if (enableGravity) DUNE_THROW(Dune::InvalidStateException, "Gravity should be false!");
enableGravity = getParam<bool>("Problem.EnableGravity"); // uses the Dumux default value
std::cout << enableGravity << std::endl;
if (!enableGravity) DUNE_THROW(Dune::InvalidStateException, "Gravity should be true!");
// use some given parameters
const auto DUNE_UNUSED(cells) = getParam<std::array<int, 2>>("Grid.Cells", std::array<int, 2>{{1, 1}});
if (cells[0] != 100 || cells[1] != 100) DUNE_THROW(Dune::InvalidStateException, "Cells should be 100 100!");
auto tEnd = getParam<double>("TimeLoop.TEnd");
if (tEnd != 1e6) DUNE_THROW(Dune::InvalidStateException, "TEnd should be 1e6!");
tEnd = getParam<double>("TimeLoop.TEnd", 1.0);
// const auto tEnd = getParamFromGroup<double>("Bulk", "TimeLoop.TEnd", 1.0, Parameters::simpleLookup);
tEnd = getParamFromGroup<double>("Bulk", "TimeLoop.TEnd", 1.0, ParamLookup::tree);
// tEnd = GET_PARAM(TypeTag, double, TimeLoop.TEnd);
tEnd = GET_PARAM_FROM_GROUP(TypeTag, double, TimeLoop, TLEnd);
std::cout << tEnd << std::endl;
tEnd = GET_RUNTIME_PARAM(TypeTag, double, TimeLoop.TEnd);
tEnd = GET_RUNTIME_PARAM_CSTRING(TypeTag, double, "TimeLoop.TEnd");
tEnd = GET_RUNTIME_PARAM_FROM_GROUP(TypeTag, double, TimeLoop, TEnd);
tEnd = GET_RUNTIME_PARAM_FROM_GROUP_CSTRING(TypeTag, double, "TimeLoop", TEnd);
std::cout << tEnd << std::endl;
reportParams();
if (tEnd != 1e6) DUNE_THROW(Dune::InvalidStateException, "TEnd should be 1e6!");
tEnd = getParamFromGroup<double>("Bulk", "TimeLoop.TEnd", 1.0);
if (tEnd != 1e5) DUNE_THROW(Dune::InvalidStateException, "TEnd should be 1e5!");
tEnd = getParamFromGroup<double>("Bulk", "TimeLoop.TEnd");
if (tEnd != 1e5) DUNE_THROW(Dune::InvalidStateException, "TEnd should be 1e5!");
tEnd = getParamFromGroup<double>("Hulk", "TimeLoop.TEnd", 1.0);
if (tEnd != 1e6) DUNE_THROW(Dune::InvalidStateException, "TEnd should be 1e6!");
tEnd = getParamFromGroup<double>("Hulk", "TimeLoop.TEnd");
if (tEnd != 1e6) DUNE_THROW(Dune::InvalidStateException, "TEnd should be 1e6!");
Parameters::print();
// check the unused keys
const auto unused = Parameters::getTree().getUnusedKeys();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment