Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
dumux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dumux-repositories
dumux
Commits
dff7ab52
Commit
dff7ab52
authored
7 years ago
by
Dennis Gläser
Browse files
Options
Downloads
Patches
Plain Diff
[params] fix loggingparameter tree test
parent
90d8d347
Loading
Loading
Loading
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/common/parameters/params.input
+3
-0
3 additions, 0 deletions
test/common/parameters/params.input
test/common/parameters/test_loggingparametertree.cc
+23
-54
23 additions, 54 deletions
test/common/parameters/test_loggingparametertree.cc
with
26 additions
and
54 deletions
test/common/parameters/params.input
+
3
−
0
View file @
dff7ab52
[TimeLoop]
TEnd = 1e6
[Bulk.TimeLoop]
TEnd = 1e5
[Grid]
Cells = 100 100
Bells = 10 10
This diff is collapsed.
Click to expand it.
test/common/parameters/test_loggingparametertree.cc
+
23
−
54
View file @
dff7ab52
#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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment