renamed functions and added const keywords where needed

parent 8917df20
#ifndef DUNE_DORIE_BASE_SIMULATION_HH
#define DUNE_DORIE_BASE_SIMULATION_HH
#ifndef DUNE_DORIE_SIMULATION_BASE_HH
#define DUNE_DORIE_SIMULATION_BASE_HH
#include "util.hh"
......@@ -17,43 +17,52 @@ class SimulationBase
public:
/**
* @brief Constructs the object.
* @brief Constructs the SimulationBase.
*
* @param[in] output_policy The output policy
* @param[in] adapt_policy The adapt policy
* @param[in] outputpolicy The output policy
* @param[in] adaptpolicy The adapt policy
*/
SimulationBase(OutputPolicy output_policy, AdaptivityPolicy adapt_policy)
: _output_policy(output_policy)
, _adapt_policy(adapt_policy)
SimulationBase(OutputPolicy outputpolicy, AdaptivityPolicy adaptpolicy)
: _outputpolicy(outputpolicy)
, _adaptpolicy(adaptpolicy)
{}
/**
* @brief Constructs the object.
* @brief Constructs the SimulationBase.
*
* @param[in] outputpolicy The output policy
*/
SimulationBase(OutputPolicy outputpolicy)
: SimulationBase( outputpolicy, AdaptivityPolicy::None )
{}
/**
* @brief Constructs the SimulationBase.
*/
SimulationBase()
: SimulationBase(OutputPolicy::None,AdaptivityPolicy::None)
: SimulationBase( OutputPolicy::None, AdaptivityPolicy::None )
{}
/**
* @brief Sets the output policy.
*
* @param[in] output_policy The output policy,
* @param[in] outputpolicy The output policy,
*/
void setPolicy(OutputPolicy output_policy) {_output_policy = output_policy;}
void set_policy(OutputPolicy outputpolicy) {_outputpolicy = outputpolicy;}
/**
* @brief Sets the adaptivity policy.
*
* @param[in] adapt_policy The adaptivity policy.
* @param[in] adaptpolicy The adaptivity policy.
*/
void setPolicy(AdaptivityPolicy adapt_policy) {_adapt_policy = adapt_policy;}
void set_policy(AdaptivityPolicy adaptpolicy) {_adaptpolicy = adaptpolicy;}
/**
* @brief Returns the current output policy.
*
* @return The current output policy.
*/
OutputPolicy outputPolicy() {return _output_policy;}
OutputPolicy output_policy() const {return _outputpolicy;}
/**
......@@ -61,122 +70,127 @@ public:
*
* @return The current adaptivity policy.
*/
AdaptivityPolicy adaptivityPolicy() {return _adapt_policy;}
AdaptivityPolicy adaptivity_policy() const {return _adaptpolicy;}
/**
* @brief Writes the data.
*/
void virtual writeData()
void virtual write_data() const
{
if (_output_policy != OutputPolicy::None)
if (_outputpolicy != OutputPolicy::None)
DUNE_THROW(Dune::IOError,"Simulation can't write data!");
}
/**
* @brief Mark the grid in order to improve the current model.
*/
virtual void markGrid()
virtual void mark_grid()
{
DUNE_THROW(Dune::NotImplemented,"Simulation can't mark the grid for adaptivity!");
DUNE_THROW(Dune::NotImplemented,
"Simulation can't mark the grid for adaptivity!");
}
/**
* @brief Operations before adaptation of the grid
*/
virtual void preAdaptGrid() {};
virtual void pre_adapt_grid() {};
/**
* @brief Adapt the grid together it every dependency of the
* grid (e.g. solution vector and grid function spaces).
*/
virtual void adaptGrid()
virtual void adapt_grid()
{
if (_adapt_policy != AdaptivityPolicy::None)
if (_adaptpolicy != AdaptivityPolicy::None)
DUNE_THROW(Dune::NotImplemented,"Simulation can't be adapted!");
else
DUNE_THROW(Dune::InvalidStateException,
"Simulation uses adaptivity policy None. Method adapt() must not be called!");
"Simulation uses adaptivity policy None.
Method adapt() must not be called!");
}
/**
* @brief Operations after adaptation of the grid
*/
virtual void postAdaptGrid() {};
virtual void post_adapt_grid() {};
/**
* @brief Method that provides the begin time of the model.
*
* @return Begin time of the model.
*/
virtual double beginTime() = 0;
virtual double begin_time() const = 0;
/**
* @brief Method that provides the end time of the model.
*
* @return End time of the model.
*/
virtual double endTime() = 0;
virtual double end_time() const = 0;
/**
* @brief Method that provides the current time of the model.
*
* @return Current time of the model.
*/
virtual double currentTime() = 0;
virtual double current_time() const = 0;
/**
* @brief Suggest a time step to the model.
*
* @param[in] suggestion for the internal time step of the model.
*/
virtual void suggestTimestep(double dt) = 0;
virtual void suggest_timestep(double dt) = 0;
/**
* @brief Operations before step of the simulation.
*/
virtual void preStep() {};
virtual void pre_step() {};
/**
* @brief Performs one steps in direction to endTime(). The time-step
* @brief Performs one steps in direction to end_time(). The time-step
* should never result on a bigger step than the one suggested
* in suggestTimestep().
* in suggest_timestep().
*/
virtual void step() = 0;
/**
* @brief Operations after step of the simulation.
*/
virtual void postStep() {};
virtual void post_step() {};
/**
* @brief Runs the model performing steps until currentTime() equals endTime()
* @brief Runs the model performing steps until current_time() equals
* end_time()
*/
virtual void run()
{
if (outputPolicy() != OutputPolicy::None)
writeData();
while( Dune::FloatCmp::lt(currentTime(),endTime()) )
if (output_policy() != OutputPolicy::None)
write_data();
while( Dune::FloatCmp::lt( current_time(), end_time()) )
{
pre_step();
step();
post_step();
if (adaptivityPolicy() != AdaptivityPolicy::None)
if ( Dune::FloatCmp::lt(currentTime(),endTime()) )
if (adaptivity_policy() != AdaptivityPolicy::None)
if ( Dune::FloatCmp::lt( current_time(), end_time()) )
{
markGrid();
preAdaptGrid();
adaptGrid();
postAdaptGrid();
mark_grid();
pre_adapt_grid();
adapt_grid();
post_adapt_grid();
}
}
}
private:
OutputPolicy _output_policy;
AdaptivityPolicy _adapt_policy;
OutputPolicy _outputpolicy;
AdaptivityPolicy _adaptpolicy;
};
} // namespace Dorie
} // namespace Dune
#endif // DUNE_DORIE_BASE_SIMULATION_HH
\ No newline at end of file
#endif // DUNE_DORIE_SIMULATION_BASE_HH
\ No newline at end of file
......@@ -2,7 +2,7 @@
#include "config.h"
#endif
#include <dune/dorie/interface/base_simulation.hh>
#include <dune/dorie/interface/simulation_base.hh>
#include <dune/common/parallel/mpihelper.hh>
......@@ -10,16 +10,21 @@ class DummyModel : public Dune::Dorie::SimulationBase
{
public:
DummyModel()
: Dune::Dorie::SimulationBase()
: Dune::Dorie::SimulationBase(Dune::Dorie::OutputPolicy::EndOfStep)
, _dt(.1)
, _current_time(beginTime())
, _current_time(begin_time())
{}
double beginTime() override {return 0.;}
double endTime() override {return 1.;}
double currentTime() override {return _current_time;}
void suggestTimestep(double dt) override {}
double begin_time() const override {return 0.;}
double end_time() const override {return 1.;}
double current_time() const override {return _current_time;}
void suggest_timestep(double dt) override {_dt = std::min(dt,_dt);}
void step() override {_current_time+=_dt;}
void write_data() const override
{
std::cout << "current time: " << _current_time << std::endl;
}
private:
double _dt;
......
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