[Richards&Transport] Cache flux reconstruction

parent 510cac44
......@@ -231,6 +231,9 @@ void RichardsSimulation<Traits>::step()
step_succeed = controller->validate(exception);
}
// invalidate cache for water flux reconstruction
cache_water_flux_gf_rt.reset();
if (this->output_policy() == OutputPolicy::EndOfRichardsStep)
write_data();
}
......@@ -251,6 +254,9 @@ void RichardsSimulation<Traits>::adapt_grid()
this->_log->error("The grid type does not support adaptation");
DUNE_THROW(NotImplemented, "Grid does not support adaptation");
}
// invalidate cache for water flux reconstruction
cache_water_flux_gf_rt.reset();
}
template<typename Traits>
......
......@@ -316,6 +316,8 @@ protected:
std::unique_ptr<Writer> vtkwriter;
std::unique_ptr<AdaptivityHandler> adaptivity;
mutable std::shared_ptr<GFFluxReconstruction> cache_water_flux_gf_rt;
RF time_before;
RF dt_before;
......@@ -527,24 +529,33 @@ public:
*/
std::shared_ptr<GFFluxReconstruction> get_water_flux_reconstructed(ConstState state) const
{
std::shared_ptr<GFFluxReconstruction> gf_ptr;
if constexpr (enable_rt_engine)
{
// create a flux reconstruction grid function
gf_ptr = std::make_shared<GFFluxReconstruction>(this->_log,
gv,inifile.sub("fluxReconstruction"));
slop->setTime(state.time);
// update it with the state
gf_ptr->update(*(state.coefficients),*(state.grid_function_space),*slop);
slop->setTime(current_time());
// use cache if possible
if (not cache_water_flux_gf_rt) {
// create a flux reconstruction grid function
cache_water_flux_gf_rt
= std::make_shared<GFFluxReconstruction>(this->_log,
gv,inifile.sub("fluxReconstruction"));
assert(fboundary);
assert(slop);
slop->setTime(state.time);
// update it with the state
cache_water_flux_gf_rt->update(*(state.coefficients),
*(state.grid_function_space),
*slop);
slop->setTime(current_time());
}
} else {
DUNE_THROW(NotImplemented,
"Flux reconstruction is not implemented for the selected "
<< "configuration");
}
return gf_ptr;
return cache_water_flux_gf_rt;
}
/*------------------------------------------------------------------------*//**
......
......@@ -215,6 +215,9 @@ void TransportSimulation<Traits>::step()
step_succeed = controller->validate(exception);
}
// invalidate cache for solute flux reconstruction
cache_solute_flux_gf_rt.reset();
time_steps++;
if (this->output_policy() == OutputPolicy::EndOfTransportStep)
......
......@@ -291,6 +291,8 @@ protected:
std::unique_ptr<Writer> vtkwriter;
mutable std::shared_ptr<GFFluxReconstruction> cache_solute_flux_gf_rt;
unsigned int time_steps;
bool do_operator_setup;
......@@ -462,19 +464,19 @@ public:
std::shared_ptr<GFFluxReconstruction>
get_solute_flux_reconstructed(ConstState state) const
{
std::shared_ptr<GFFluxReconstruction> gf_ptr;
if constexpr (enable_rt_engine)
{
// create a flux reconstruction grid function
gf_ptr = std::make_shared<GFFluxReconstruction>(this->_log,
gv,inifile.sub("fluxReconstruction"));
// use cache if possible
if (not cache_solute_flux_gf_rt) {
// create a flux reconstruction grid function
cache_solute_flux_gf_rt
= std::make_shared<GFFluxReconstruction>(this->_log,
gv,inifile.sub("fluxReconstruction"));
if (not FloatCmp::eq(state.time,current_time()) or
not (state.grid_function_space == gfs) or
not slop) {
assert(water_content_gf);
assert(water_flux_gf);
assert(sboundary);
assert(slop);
// set time in local operator
try {
......@@ -487,24 +489,19 @@ public:
"Local operator not able to set time at " << state.time);
}
// update flux reconstruction (use current local operator)
gf_ptr->update( *(state.coefficients),
*(state.grid_function_space),
*slop);
cache_solute_flux_gf_rt->update(*(state.coefficients),
*(state.grid_function_space),
*slop);
// reset time in local operator
slop->setTime(current_time());
} else {
// update flux reconstruction
gf_ptr->update( *(state.coefficients),
*(state.grid_function_space),
*slop);
}
} else {
DUNE_THROW(NotImplemented,
"Flux reconstruction is not implemented for the selected "
<< "configuration");
}
return gf_ptr;
return cache_solute_flux_gf_rt;
}
/*------------------------------------------------------------------------*//**
......
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