The TS-GitLab will have to shut down towards the end of the year — please think about migrating your projects to GitLab.com or GitHub.
(This is still a very early message, meant to keep you informed. There will be more urgent ones in the future.)

Apply clang format to .hh files in DORiE

parent a6e1e7c2
#ifndef DUNE_DORIE_RAVIART_THOMAS_DG_FEM_HH
#define DUNE_DORIE_RAVIART_THOMAS_DG_FEM_HH
#include <dune/pdelab/finiteelementmap/finiteelementmap.hh>
#include <dune/pdelab/finiteelement/l2orthonormal.hh>
#include <dune/pdelab/finiteelementmap/finiteelementmap.hh>
#include <dune/dorie/common/finite_element/raviart_thomas_dg/local_finite_element.hh>
......
......@@ -9,8 +9,8 @@
#include <dune/dorie/common/typedefs.hh>
namespace Dune{
namespace Dorie{
namespace Dune {
namespace Dorie {
/**
* @brief Base class for models.
......@@ -24,7 +24,6 @@ namespace Dorie{
class ModelBase
{
public:
/**
* @brief Constructs the ModelBase.
*
......@@ -36,26 +35,27 @@ public:
* @param[in] adapt_policy The adapt policy.
* Defaults to AdaptiviyPolicy::None.
*/
ModelBase(
const std::string log_name,
const std::string log_level,
const Dune::MPIHelper& helper,
OutputPolicy output_policy=OutputPolicy::None,
AdaptivityPolicy adapt_policy=AdaptivityPolicy::None
)
ModelBase(const std::string log_name,
const std::string log_level,
const Dune::MPIHelper& helper,
OutputPolicy output_policy = OutputPolicy::None,
AdaptivityPolicy adapt_policy = AdaptivityPolicy::None)
: _output_policy(output_policy)
, _adapt_policy(adapt_policy)
, _time(0.0)
, _log(create_logger(log_name, helper, spdlog::level::from_str(log_level)))
{ }
{}
virtual ~ModelBase () = default;
virtual ~ModelBase() = default;
/**
* @brief Sets the output policy.
*
* @param[in] output_policy The output policy,
*/
void set_policy(OutputPolicy output_policy) {_output_policy = output_policy;}
void set_policy(OutputPolicy output_policy)
{
_output_policy = output_policy;
}
/**
* @brief Sets the adaptivity policy.
......@@ -72,20 +72,19 @@ public:
*
* @return The current output policy.
*/
OutputPolicy output_policy() const {return _output_policy;}
OutputPolicy output_policy() const { return _output_policy; }
/**
* @brief Returns the current adaptivity policy.
*
* @return The current adaptivity policy.
*/
AdaptivityPolicy adaptivity_policy() const {return _adapt_policy;}
AdaptivityPolicy adaptivity_policy() const { return _adapt_policy; }
/// Set the logger for this model
/** @param logger The new logger
*/
void set_logger (const std::shared_ptr<spdlog::logger> logger)
void set_logger(const std::shared_ptr<spdlog::logger> logger)
{
_log = logger;
}
......@@ -119,7 +118,7 @@ public:
/**
* @brief Operations before adaptation of the grid
*/
virtual void pre_adapt_grid() {};
virtual void pre_adapt_grid(){};
/**
* @brief Adapt the grid together it every dependency of the grid (e.g.
......@@ -131,8 +130,7 @@ public:
_log->error("This model does not implement a grid adaptation "
"algorithm.");
DUNE_THROW(Dune::NotImplemented, "'adapt_grid' not implemented");
}
else {
} else {
_log->error("Calling 'adapt_grid' on a model with "
"AdaptivityPolicy::None. Grid adaptation refused");
DUNE_THROW(Dune::InvalidStateException, "Invalid adaptation policy");
......@@ -142,7 +140,7 @@ public:
/**
* @brief Operations after adaptation of the grid
*/
virtual void post_adapt_grid() {};
virtual void post_adapt_grid(){};
/**
* @brief Method that provides the begin time of the model.
......@@ -189,13 +187,11 @@ public:
if (output_policy() != OutputPolicy::None)
write_data();
while( Dune::FloatCmp::lt( current_time(), end_time()) )
{
while (Dune::FloatCmp::lt(current_time(), end_time())) {
step();
if (adaptivity_policy() != AdaptivityPolicy::None)
if ( Dune::FloatCmp::lt( current_time(), end_time()) )
{
if (Dune::FloatCmp::lt(current_time(), end_time())) {
mark_grid();
pre_adapt_grid();
adapt_grid();
......@@ -205,8 +201,8 @@ public:
}
private:
OutputPolicy _output_policy;
AdaptivityPolicy _adapt_policy;
OutputPolicy _output_policy;
AdaptivityPolicy _adapt_policy;
protected:
/// The current time of the model
......@@ -222,28 +218,28 @@ protected:
## Base class for models
### Stepping:
The method `step()` must be an abstract method that always has to be
implemented by the derived class. The step must succeed always, otherwise,
it should throw a `ModelStepException`. It means that time adaptivity
The method `step()` must be an abstract method that always has to be
implemented by the derived class. The step must succeed always, otherwise,
it should throw a `ModelStepException`. It means that time adaptivity
must be done internally so that the time step succeeds.
### Writing data:
The method `step()` must be able to decide whether to write data or not.
(Say that in one case one wants that transport writes that every step and in
another case one wants that it writes at the end of the Richards step. The
first case can't be covered writing data in the `run()` method of the
coupled model.) Then, enum class called `OutputPolicy` must decide
whether to call the method `write_data()`. This policy can be set and be
extracted by the methods `set_policy(OutputPolicy)` and `output_policy()`
The method `step()` must be able to decide whether to write data or not.
(Say that in one case one wants that transport writes that every step and in
another case one wants that it writes at the end of the Richards step. The
first case can't be covered writing data in the `run()` method of the
coupled model.) Then, enum class called `OutputPolicy` must decide
whether to call the method `write_data()`. This policy can be set and be
extracted by the methods `set_policy(OutputPolicy)` and `output_policy()`
respectively.
The method `write_data()` should be in charge of writing the data.
In principle, this method should be only used following the `OutputPolicy`.
Usually called at the end of each step and at the beginning of the
model. Since the `step()` method is in charge of it, it is assumed that
this method writes the *current* state of the model (e.g. intermediate
The method `write_data()` should be in charge of writing the data.
In principle, this method should be only used following the `OutputPolicy`.
Usually called at the end of each step and at the beginning of the
model. Since the `step()` method is in charge of it, it is assumed that
this method writes the *current* state of the model (e.g. intermediate
results of the coupled model for the transport state).
### Adaptivity:
......@@ -270,19 +266,19 @@ protected:
A minimal interface is only providing `begin_time()`, `end_time()` and
`current_time()`.
In order to keep solution vectors minimal at the time of adaptivity, DORiE
expect the several models synchronized in time. Therefore, a good and still
minimal interface is only suggesting the timestep to the model via
`suggest_timestep(double dt)`. Such suggestion has to be taken into account
within the model, and the model must ensure that the timestep is done in
`step()` is never bigger than the suggested one so that coupled models can
achieve synchronization. Naturally, models have to ensure that
In order to keep solution vectors minimal at the time of adaptivity, DORiE
expect the several models synchronized in time. Therefore, a good and still
minimal interface is only suggesting the timestep to the model via
`suggest_timestep(double dt)`. Such suggestion has to be taken into account
within the model, and the model must ensure that the timestep is done in
`step()` is never bigger than the suggested one so that coupled models can
achieve synchronization. Naturally, models have to ensure that
`begin_time()` \f$=\f$ `current_time()` when they are constructed.
### Local Operator Setup:
Since adaptivity can modify the complete setup of the model, and since
the method `adapt_grid()` is not necessarily called by the model.
Since adaptivity can modify the complete setup of the model, and since
the method `adapt_grid()` is not necessarily called by the model.
There is a need for the method `post_adapt_grid()` which is in charge of
setup everything again to the new grid. Same argument holds for
`pre_adapt_grid()`.
......
......@@ -10,8 +10,8 @@
#include <gtest/gtest.h>
#endif
namespace Dune{
namespace Dorie{
namespace Dune {
namespace Dorie {
/**
* @brief Traits for the class ModelRichardsTransportCoupling.
......@@ -29,38 +29,42 @@ namespace Dorie{
* @tparam TransportOrder Order of the polynomial degree used for the basis
* functions in the Transport DG/FV method.
*/
template<class BaseTraits, unsigned int RichardsOrder, unsigned int TransportOrder>
template<class BaseTraits,
unsigned int RichardsOrder,
unsigned int TransportOrder>
struct ModelRichardsTransportCouplingTraits : public BaseTraits
{
private:
using ModelRichardsTraits = Dune::Dorie::ModelRichardsTraits<BaseTraits,RichardsOrder>;
using ModelRichardsTraits =
Dune::Dorie::ModelRichardsTraits<BaseTraits, RichardsOrder>;
public:
static_assert(ModelRichardsTraits::enable_rt_engine,
"Flux reconstruction is not available in the Richards model!");
"Flux reconstruction is not available in the Richards model!");
/// Container for the water content grid function
/** \note Interpolates linearly between time steps.
* \see GridFunctionContainerPolicy
*/
using GFWaterContentContainer = GridFunctionContainer<
const typename ModelRichardsTraits::GFWaterContent,
double,
GridFunctionContainerPolicy::LinearInterpolation
>;
using GFWaterContentContainer =
GridFunctionContainer<const typename ModelRichardsTraits::GFWaterContent,
double,
GridFunctionContainerPolicy::LinearInterpolation>;
/// Container for the water flux grid function
/** \note Returns the next future value
* \see GridFunctionContainerPolicy
*/
using GFWaterFluxContainer = GridFunctionContainer<const typename ModelRichardsTraits::GFFluxReconstruction>;
using GFWaterFluxContainer = GridFunctionContainer<
const typename ModelRichardsTraits::GFFluxReconstruction>;
private:
using ModelTransportTraits = Dune::Dorie::ModelTransportTraits<
BaseTraits,
GFWaterFluxContainer,
GFWaterContentContainer,
TransportOrder
>;
using ModelTransportTraits =
Dune::Dorie::ModelTransportTraits<BaseTraits,
GFWaterFluxContainer,
GFWaterContentContainer,
TransportOrder>;
public:
using ModelRichards = Dune::Dorie::ModelRichards<ModelRichardsTraits>;
using ModelTransport = Dune::Dorie::ModelTransport<ModelTransportTraits>;
......@@ -70,7 +74,6 @@ public:
using GridCreator = Dune::Dorie::GridCreator<typename BaseTraits::Grid>;
};
/**
* @brief Class for richards transport coupling model.
* @details For given ModelRichardsTransportCouplingTraits, this class
......@@ -91,31 +94,31 @@ class ModelRichardsTransportCoupling : public ModelBase
{
public:
using Traits = T;
private:
using ModelRichards = typename Traits::ModelRichards;
using ModelRichards = typename Traits::ModelRichards;
using ModelTransport = typename Traits::ModelTransport;
using ModelRichardsTraits = typename ModelRichards::Traits;
using ModelRichardsTraits = typename ModelRichards::Traits;
using ModelTransportTraits = typename ModelTransport::Traits;
using GFWaterContentContainer = typename Traits::GFWaterContentContainer;
using GFWaterContentContainer = typename Traits::GFWaterContentContainer;
using GFWaterFluxContainer = typename Traits::GFWaterFluxContainer;
using GridCreator = typename Traits::GridCreator;
using TimeField = typename Traits::TimeField;
using RichardsState = typename ModelRichardsTraits::State;
std::shared_ptr<typename Traits::BaseTraits::Grid> _grid;
Dune::ParameterTree _inifile_richards, _inifile_transport;
std::unique_ptr<ModelRichards> _richards;
std::unique_ptr<ModelRichards> _richards;
std::unique_ptr<ModelTransport> _transport;
RichardsState richards_state_before_step, richards_state_after_step;
public:
/**
* @brief Construct Coupled model.
*
......@@ -126,21 +129,19 @@ public:
*
* @todo Fix logger warning.
*/
ModelRichardsTransportCoupling (
Dune::ParameterTree& inifile_richards,
Dune::ParameterTree& inifile_transport,
const GridCreator& _grid_creator,
Dune::MPIHelper& helper
);
ModelRichardsTransportCoupling(Dune::ParameterTree& inifile_richards,
Dune::ParameterTree& inifile_transport,
const GridCreator& _grid_creator,
Dune::MPIHelper& helper);
~ModelRichardsTransportCoupling() = default;
/*------------------------------------------------------------------------*//**
* @brief Compute a time step. Models the time step requirement of
* ModelBase
*
* @throws Dune::Exception Fatal error occurs during computation
*/
/*------------------------------------------------------------------------*/ /**
* @brief Compute a time step. Models the time step requirement of
* ModelBase
*
* @throws Dune::Exception Fatal error occurs during computation
*/
void step() override;
/**
......@@ -149,30 +150,27 @@ public:
void mark_grid() override
{
// select model and mark the grid
if (adaptivity_policy() == AdaptivityPolicy::WaterFlux)
{
if (adaptivity_policy() == AdaptivityPolicy::WaterFlux) {
_richards->set_policy(adaptivity_policy());
_richards->mark_grid();
}
else if (adaptivity_policy() == AdaptivityPolicy::SoluteFlux)
{
} else if (adaptivity_policy() == AdaptivityPolicy::SoluteFlux) {
_transport->set_policy(adaptivity_policy());
_transport->mark_grid();
} else if (adaptivity_policy() != AdaptivityPolicy::None)
DUNE_THROW(Dune::NotImplemented,"Not known adaptivity policy!");
DUNE_THROW(Dune::NotImplemented, "Not known adaptivity policy!");
}
/**
* @brief Operations before adaptation of the grid
*/
void pre_adapt_grid() override
void pre_adapt_grid() override
{
_richards->pre_adapt_grid();
_transport->pre_adapt_grid();
};
/**
* @brief Adapt the grid together it every dependency of the
* @brief Adapt the grid together it every dependency of the
* grid (e.g. solution vector and grid function spaces).
*/
void adapt_grid() override;
......@@ -182,44 +180,35 @@ public:
*/
void post_adapt_grid() override;
/*------------------------------------------------------------------------*//**
* @brief Method that provides the begin time of the model.
*
* @return Begin time of the model.
*/
double begin_time() const override
{
return _richards->begin_time();
}
/*------------------------------------------------------------------------*//**
* @brief Method that provides the end time of the model.
*
* @return End time of the model.
*/
double end_time() const override
{
return _richards->end_time();
}
/*------------------------------------------------------------------------*//**
* @brief Suggest a time step to the model.
*
* @param[in] dt Suggestion for the internal time step of the model. The
* new internal time step shall not be bigger than dt
*/
void suggest_timestep(double dt) override
{
_richards->suggest_timestep(dt);
}
/*------------------------------------------------------------------------*//**
* @brief Write the data using the VTKWriter. VTKWriters is always
* cleared after used.
*
* @param[in] time The time to print in th pvd file.
*/
void write_data () const override
/*------------------------------------------------------------------------*/ /**
* @brief Method that provides the begin time of the model.
*
* @return Begin time of the model.
*/
double begin_time() const override { return _richards->begin_time(); }
/*------------------------------------------------------------------------*/ /**
* @brief Method that provides the end time of the model.
*
* @return End time of the model.
*/
double end_time() const override { return _richards->end_time(); }
/*------------------------------------------------------------------------*/ /**
* @brief Suggest a time step to the model.
*
* @param[in] dt Suggestion for the internal time step of the model. The
* new internal time step shall not be bigger than dt
*/
void suggest_timestep(double dt) override { _richards->suggest_timestep(dt); }
/*------------------------------------------------------------------------*/ /**
* @brief Write the data using the VTKWriter. VTKWriters is always
* cleared after used.
*
* @param[in] time The time to print in th pvd file.
*/
void write_data() const override
{
if (_richards->output_policy() != OutputPolicy::None)
_richards->write_data();
......@@ -228,13 +217,11 @@ public:
}
private:
#ifdef GTEST
FRIEND_TEST(ModelCoupling, TimeSteps);
#endif
};
} // namespace Dorie
} // namespace Dune
......
#ifndef DUNE_DORIE_MODEL_FACTORY_HH
#define DUNE_DORIE_MODEL_FACTORY_HH
#ifndef DORIE_DIM
#error DORIE_DIM macro must be defined for factory builds
#error DORIE_DIM macro must be defined for factory builds
#else
static_assert(DORIE_DIM == 2 or DORIE_DIM == 3,
"DORiE can only be built in 2D or 3D");
static_assert(DORIE_DIM == 2 or DORIE_DIM == 3,
"DORiE can only be built in 2D or 3D");
#endif
#include <memory>
#include <utility>
#include <dune/common/parametertree.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/parametertree.hh>
#include <dune/geometry/type.hh>
#include <dune/grid/uggrid.hh>
#include <dune/grid/yaspgrid.hh>
#include <dune/dorie/common/setup.hh>
#include <dune/dorie/common/logging.hh>
#include <dune/dorie/common/utility.hh>
#include <dune/dorie/common/grid_creator.hh>
#include <dune/dorie/common/logging.hh>
#include <dune/dorie/common/setup.hh>
#include <dune/dorie/common/utility.hh>
#include <dune/dorie/model/base.hh>
......@@ -42,87 +40,75 @@ namespace Dorie {
struct ModelFactory
{
protected:
/// An unstructured grid (simplices & rectangles, adaptive)
template<int dim>
using UnstructuredGrid = Dune::UGGrid<dim>;
/// A structured grid (rectangles only)
template<int dim>
using StructuredGrid = Dune::YaspGrid<dim>;
template<class Grid>
using BaseTraitsSimplex
= BaseTraits<Grid,
Dune::GeometryType::BasicType::simplex>;
template<class Grid>
using BaseTraitsCube
= BaseTraits<Grid,
Dune::GeometryType::BasicType::cube>;
/// Return the grid settings
/** \return Pair: Grid type/mode setting, bool if adaptivity is enabled
*/
static std::pair<GridMode, bool> get_grid_config (
const Dune::ParameterTree& config
)
{
const auto log = get_logger(log_base);
// check if adaptivity is enabled
const auto policy = config.get<std::string>("adaptivity.policy");
const bool adaptivity_enbaled = not is_none(policy);
// check grid type
GridMode grid_mode;
const auto grid_type = config.get<std::string>("grid.gridType");
if (grid_type == "gmsh") {
grid_mode = GridMode::gmsh;
}
else if (grid_type == "rectangular") {
grid_mode = GridMode::rectangular;
}
else {
log->error("Unknown grid type: {}",
grid_type);
DUNE_THROW(IOError, "Unknown grid type");
}
return {grid_mode, adaptivity_enbaled};
}
/// Return the adaptivity policy read from a config tree
static AdaptivityPolicy get_adaptivity_policy (
const Dune::ParameterTree& config
)
{
std::string adapt_policy_str
= config.get<std::string>("adaptivity.policy");
if (adapt_policy_str == "waterFlux") {
return AdaptivityPolicy::WaterFlux;
}
else if (adapt_policy_str == "soluteFlux") {
return AdaptivityPolicy::SoluteFlux;
}
else if (is_none(adapt_policy_str)) {
return AdaptivityPolicy::None;
}
else {
const auto log = get_logger(log_base);
log->error("Unknown adaptivity policy: {}", adapt_policy_str);
DUNE_THROW(IOError, "Unknown adaptivity policy");
}
/// An unstructured grid (simplices & rectangles, adaptive)
template<int dim>
using UnstructuredGrid = Dune::UGGrid<dim>;
/// A structured grid (rectangles only)
template<int dim>
using StructuredGrid = Dune::YaspGrid<dim>;
template<class Grid>
using BaseTraitsSimplex =