[Richards] Add const and non-const test to parameterization

parent ee72e166
......@@ -88,8 +88,8 @@ bool compare_maps (const MapA& map_a, const MapB& map_b)
* \param grid Shared pointer to the grid
*/
template<class FlowParameters, class Grid>
void test_new_parameters (FlowParameters& fparam,
std::shared_ptr<Grid> grid)
void test_new_parameters (const FlowParameters& fparam,
std::shared_ptr<Grid> grid)
{
// define parameter sets to check against
const auto param_sand = get_parameter_map("sand");
......@@ -102,7 +102,7 @@ void test_new_parameters (FlowParameters& fparam,
// bind parameterization to cell and fetch parameters
fparam.bind(cell);
using RP = Dune::Dorie::RichardsParameterization<Traits<2>>;
auto par = std::get<std::shared_ptr<RP>>(fparam.cache());
auto par = std::get<std::shared_ptr<const RP>>(fparam.cache());
auto parameters = par->parameters();
// compare values to defined parameter sets
......@@ -156,6 +156,31 @@ void test_parameter_manipulation (FlowParameters& fparam,
assert(par_mvg._alpha.value = -10.0);
}
template<class FlowParameters, class Grid>
bool compare_parameters (const FlowParameters& fparam1,
const FlowParameters& fparam2,
std::shared_ptr<Grid> grid)
{
// iterate over grid cells and verify parameterization
auto level_gv = grid->leafGridView();
for (auto&& cell: elements(level_gv))
{
// bind parameterization to cell and fetch parameters
fparam1.bind(cell);
fparam2.bind(cell);
using RP = Dune::Dorie::RichardsParameterization<Traits<2>>;
auto par1 = std::get<const std::shared_ptr<const RP>>(fparam1.cache());
auto par2 = std::get<const std::shared_ptr<const RP>>(fparam2.cache());
auto parameters1 = par1->parameters();
auto parameters2 = par2->parameters();
// compare values between the two parameterizations
if (not compare_maps(parameters1, parameters2))
return false;
}
return true;
}
int main (int argc, char** argv)
{
try{
......@@ -175,13 +200,18 @@ int main (int argc, char** argv)
helper,
spdlog::level::from_str(log_level));
Dune::Dorie::FlowParameters<Traits<2>> param(inifile,
grid,
index_map);
const Dune::Dorie::FlowParameters<Traits<2>> const_param(inifile,
grid,
index_map);
Dune::Dorie::FlowParameters<Traits<2>> param(const_param);
// perform the actual tests
test_new_parameters(const_param, grid);
test_new_parameters(param, grid);
assert(compare_parameters(const_param, param, grid));
test_parameter_manipulation(param, grid);
assert(not compare_parameters(const_param, param, grid));
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment