Commit edaa1503 authored by Markus Wolff's avatar Markus Wolff
Browse files

next step to converge to common interfaces of box models and decoupled

models

   - change extended to OneModelProblem and derived classes



git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@6295 2fb0f335-1f38-0410-981e-8018bf24f1b0
parent 6b1ec3b3
......@@ -81,6 +81,8 @@ NEW_PROP_TAG( LinearSolver );//!< Type of linear solver
// Properties
//////////////////////////////////////////////////////////////////
SET_INT_PROP(DecoupledOneP, NumEq, 1);
SET_INT_PROP(DecoupledOneP, NumPhases, 1)//!< Single phase system
;
SET_INT_PROP(DecoupledOneP, NumComponents, 1); //!< Each phase consists of 1 pure component
......
......@@ -41,13 +41,15 @@ namespace Dumux
* @tparam Implementation The Problem implementation
*/
template<class TypeTag, class Implementation>
class DiffusionProblem1P: public OneModelProblem<TypeTag, Implementation>
class DiffusionProblem1P: public OneModelProblem<TypeTag>
{
typedef OneModelProblem<TypeTag, Implementation> ParentType;
typedef OneModelProblem<TypeTag> ParentType;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(GridView)) GridView;
typedef typename GridView::Grid Grid;typedef typename GET_PROP_TYPE(TypeTag, PTAG(Scalar)) Scalar;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(TimeManager)) TimeManager;
// material properties
typedef typename GET_PROP_TYPE(TypeTag, PTAG(Fluid)) Fluid;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(SpatialParameters)) SpatialParameters;
......@@ -66,8 +68,41 @@ public:
* \param gridView The grid view
* \param verbose Output flag for the time manager.
*/
DiffusionProblem1P(const GridView &gridView, bool verbose = true) :
ParentType(gridView, verbose), gravity_(0)
DiffusionProblem1P(const GridView &gridView, bool verbose = true)
DUNE_DEPRECATED // use DiffusionProblem1P(TimeManager&, const GridView&)
: ParentType(gridView, verbose), gravity_(0)
{
spatialParameters_ = new SpatialParameters(gridView);
newSpatialParams_ = true;
gravity_ = 0;
if (GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)))
gravity_[dim - 1] = -9.81;
}
/*!
* \brief The constructor
*
* \param gridView The grid view
* \param spatialParameters SpatialParameters instantiation
* \param verbose Output flag for the time manager.
*/
DiffusionProblem1P(const GridView &gridView, SpatialParameters &spatialParameters, bool verbose = true)
DUNE_DEPRECATED // use DiffusionProblem1P(TimeManager&, const GridView&, SpatialParameters&)
: ParentType(gridView, verbose), gravity_(0), spatialParameters_(&spatialParameters)
{
newSpatialParams_ = false;
gravity_ = 0;
if (GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)))
gravity_[dim - 1] = -9.81;
}
/*!
* \brief The constructor
*
* \param gridView The grid view
* \param verbose Output flag for the time manager.
*/
DiffusionProblem1P(TimeManager &timeManager, const GridView &gridView) :
ParentType(timeManager, gridView), gravity_(0)
{
spatialParameters_ = new SpatialParameters(gridView);
newSpatialParams_ = true;
......@@ -82,8 +117,8 @@ public:
* \param spatialParameters SpatialParameters instantiation
* \param verbose Output flag for the time manager.
*/
DiffusionProblem1P(const GridView &gridView, SpatialParameters &spatialParameters, bool verbose = true) :
ParentType(gridView, verbose), gravity_(0), spatialParameters_(&spatialParameters)
DiffusionProblem1P(TimeManager &timeManager, const GridView &gridView, SpatialParameters &spatialParameters) :
ParentType(timeManager, gridView), gravity_(0), spatialParameters_(&spatialParameters)
{
newSpatialParams_ = false;
gravity_ = 0;
......
......@@ -42,13 +42,15 @@ namespace Dumux
* @tparam Implementation The Problem implementation
*/
template<class TypeTag, class Implementation>
class DiffusionProblem2P: public OneModelProblem<TypeTag, Implementation>
class DiffusionProblem2P: public OneModelProblem<TypeTag>
{
typedef OneModelProblem<TypeTag, Implementation> ParentType;
typedef OneModelProblem<TypeTag> ParentType;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(GridView)) GridView;
typedef typename GridView::Grid Grid;typedef typename GET_PROP_TYPE(TypeTag, PTAG(Scalar)) Scalar;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(TimeManager)) TimeManager;
// material properties
typedef typename GET_PROP_TYPE(TypeTag, PTAG(FluidSystem)) FluidSystem;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(SpatialParameters)) SpatialParameters;
......@@ -71,8 +73,40 @@ public:
* \param gridView The grid view
* \param verbose Output flag for the time manager
*/
DiffusionProblem2P(const GridView &gridView, bool verbose = true) :
ParentType(gridView, verbose), gravity_(0)
DiffusionProblem2P(TimeManager &timeManager, const GridView &gridView) :
ParentType(timeManager, gridView), gravity_(0)
{
spatialParameters_ = new SpatialParameters(gridView);
newSpatialParams_ = true;
gravity_ = 0;
if (GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)))
gravity_[dim - 1] = -9.81;
}
/*!
* \brief The constructor
*
* \param gridView The grid view
* \param spatialParameters SpatialParameters instantiation
* \param verbose Output flag for the time manager.
*/
DiffusionProblem2P(TimeManager &timeManager, const GridView &gridView, SpatialParameters &spatialParameters)
:ParentType(timeManager, gridView), gravity_(0), spatialParameters_(&spatialParameters)
{
newSpatialParams_ = false;
gravity_ = 0;
if (GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)))
gravity_[dim - 1] = -9.81;
}
/*!
* \brief The constructor
*
* \param gridView The grid view
* \param verbose Output flag for the time manager
*/
DiffusionProblem2P(const GridView &gridView, bool verbose = true)
DUNE_DEPRECATED // use DiffusionProblem2P(TimeManager&, const GridView&)
: ParentType(gridView, verbose), gravity_(0)
{
spatialParameters_ = new SpatialParameters(gridView);
newSpatialParams_ = true;
......@@ -87,8 +121,9 @@ public:
* \param spatialParameters SpatialParameters instantiation
* \param verbose Output flag for the time manager.
*/
DiffusionProblem2P(const GridView &gridView, SpatialParameters &spatialParameters, bool verbose = true) :
ParentType(gridView, verbose), gravity_(0), spatialParameters_(&spatialParameters)
DiffusionProblem2P(const GridView &gridView, SpatialParameters &spatialParameters, bool verbose = true)
DUNE_DEPRECATED // use DiffusionProblem2P(TimeManager&, const GridView&, SpatialParameters&)
: ParentType(gridView, verbose), gravity_(0), spatialParameters_(&spatialParameters)
{
newSpatialParams_ = false;
gravity_ = 0;
......
......@@ -43,14 +43,16 @@ namespace Dumux
* @tparam Implementation The Problem implementation
*/
template<class TypeTag, class Implementation>
class TransportProblem2P : public OneModelProblem<TypeTag, Implementation>
class TransportProblem2P : public OneModelProblem<TypeTag>
{
typedef OneModelProblem<TypeTag, Implementation> ParentType;
typedef OneModelProblem<TypeTag> ParentType;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(GridView)) GridView;
typedef typename GridView::Grid Grid;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(Scalar)) Scalar;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(TimeManager)) TimeManager;
// material properties
typedef typename GET_PROP_TYPE(TypeTag, PTAG(FluidSystem)) FluidSystem;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(SpatialParameters)) SpatialParameters;
......@@ -77,6 +79,7 @@ public:
* \param gridView The grid view
*/
TransportProblem2P(const GridView &gridView)
DUNE_DEPRECATED // use TransportProblem2P(TimeManager&, const GridView&)
: ParentType(gridView),
gravity_(0),spatialParameters_(gridView)
{
......@@ -85,6 +88,20 @@ public:
gravity_[dim - 1] = - 9.81;
}
/*!
* \brief The constructor
*
* \param gridView The grid view
*/
TransportProblem2P(TimeManager &timeManager, const GridView &gridView)
: ParentType(timeManager, gridView),
gravity_(0),spatialParameters_(gridView)
{
gravity_ = 0;
if (GET_PROP_VALUE(TypeTag, PTAG(EnableGravity)))
gravity_[dim - 1] = - 9.81;
}
/*!
* \name Problem parameters
*/
......
......@@ -85,6 +85,7 @@ NEW_PROP_TAG( CFLFactor );
SET_TYPE_PROP(Transport, DiffusivePart, DiffusivePart<TypeTag>);
SET_TYPE_PROP(Transport, ConvectivePart, ConvectivePart<TypeTag>);
SET_TYPE_PROP(Transport, Variables, VariableClass2P<TypeTag>);
SET_INT_PROP(Transport, NumEq, 1);
SET_INT_PROP(Transport, NumPhases, 2);
SET_INT_PROP(Transport, NumComponents, 1);
SET_TYPE_PROP(Transport, TwoPIndices, TwoPCommonIndicesDecoupled<TypeTag>);
......
......@@ -90,7 +90,7 @@ SET_PROP(DecoupledTwoPTwoC, TwoPTwoCIndices)
typedef TwoPTwoCIndices<TypeTag> type;
};
SET_INT_PROP(DecoupledTwoP, NumEq, 2);
SET_INT_PROP(DecoupledTwoPTwoC, NumEq, 2);
// set fluid/component information
SET_PROP(DecoupledTwoPTwoC, NumPhases) //!< The number of phases in the 2p model is 2
......
......@@ -23,7 +23,6 @@
#define DUMUX_ONE_MODEL_PROBLEM_HH
#include <dumux/decoupled/common/decoupledproperties.hh>
#include <dumux/common/timemanager.hh>
#include <dumux/io/vtkmultiwriter.hh>
#include <dumux/io/restart.hh>
......@@ -43,13 +42,14 @@ namespace Dumux
*
* @tparam TypeTag The Type Tag
*/
template<class TypeTag, class Implementation>
template<class TypeTag>
class OneModelProblem
{
private:
typedef typename GET_PROP_TYPE(TypeTag, PTAG(Problem)) Implementation;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(GridView)) GridView;
typedef Dumux::TimeManager<TypeTag> TimeManager;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(TimeManager)) TimeManager;
typedef Dumux::VtkMultiWriter<GridView> VtkMultiWriter;
......@@ -72,9 +72,13 @@ private:
wetting = 0, nonwetting = 1
};
typedef Dune::FieldVector<Scalar,dim> LocalPosition;
typedef Dune::FieldVector<Scalar,dimWorld> GlobalPosition;
typedef typename GridView::template Codim<dim>::Iterator VertexIterator;
typedef typename GridView::Traits::template Codim<0>::Entity Element;
typedef typename GridView::Intersection Intersection;
typedef typename SolutionTypes::PrimaryVariables PrimaryVariables;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(BoundaryTypes)) BoundaryTypes;
// private!! copy constructor
OneModelProblem(const OneModelProblem&)
......@@ -88,10 +92,10 @@ public:
* \tparam verbose Output level for Dumux::TimeManager
*/
OneModelProblem(const GridView &gridView, bool verbose = true)
DUNE_DEPRECATED // use OneModelProblem(TimeManager&, const GridView&)
: gridView_(gridView),
bboxMin_(std::numeric_limits<double>::max()),
bboxMax_(-std::numeric_limits<double>::max()),
timeManager_(verbose),
variables_(gridView),
outputInterval_(1)
{
......@@ -105,6 +109,38 @@ public:
}
}
timeManager_ = new TimeManager(verbose);
deleteTimeManager_ = true;
model_ = new Model(asImp_()) ;
resultWriter_ = NULL;
}
//! Constructs an object of type OneModelProblemProblem
/*!
* \tparam TypeTag The TypeTag
* \tparam verbose Output level for Dumux::TimeManager
*/
OneModelProblem(TimeManager &timeManager, const GridView &gridView)
: gridView_(gridView),
bboxMin_(std::numeric_limits<double>::max()),
bboxMax_(-std::numeric_limits<double>::max()),
timeManager_(&timeManager),
variables_(gridView),
outputInterval_(1),
deleteTimeManager_(false)
{
// calculate the bounding box of the grid view
VertexIterator vIt = gridView.template begin<dim>();
const VertexIterator vEndIt = gridView.template end<dim>();
for (; vIt!=vEndIt; ++vIt) {
for (int i=0; i<dim; i++) {
bboxMin_[i] = std::min(bboxMin_[i], vIt->geometry().center()[i]);
bboxMax_[i] = std::max(bboxMax_[i], vIt->geometry().center()[i]);
}
}
model_ = new Model(asImp_()) ;
resultWriter_ = NULL;
......@@ -115,6 +151,183 @@ public:
{
delete model_;
delete resultWriter_;
if (deleteTimeManager_)
delete timeManager_;
}
/*!
* \brief Specifies which kind of boundary condition should be
* used for which equation on a given boundary segment.
*
* \param bcTypes The boundary types for the conservation equations
* \param intersection The intersection for which the boundary type is set
*/
void boundaryTypes(BoundaryTypes &bcTypes,
const Intersection &intersection) const
{
// forward it to the method which only takes the global coordinate
asImp_().generalBoundaryTypes(bcTypes, intersection.geometry().center());
}
/*!
* \brief Specifies which kind of boundary condition should be
* used for which equation on a given boundary segment.
*
* \param bcTypes The boundary types for the conservation equations
* \param globalPos The position of the center of the boundary intersection
*/
void generalBoundaryTypes(BoundaryTypes &bcTypes,
const GlobalPosition &globalPos) const
{
// Throw an exception (there is no reasonable default value
// for Dirichlet conditions)
DUNE_THROW(Dune::InvalidStateException,
"The problem does not provide "
"a generalBoundaryTypes() method.");
}
/*!
* \brief Evaluate the boundary conditions for a dirichlet
* control volume.
*
* \param values The dirichlet values for the primary variables
* \param intersection The boundary intersection
*
* For this method, the \a values parameter stores primary variables.
*/
void dirichlet(PrimaryVariables &values,
const Intersection &intersection) const
{
// forward it to the method which only takes the global coordinate
asImp_().generalDirichlet(values, intersection.geometry().center());
}
/*!
* \brief Evaluate the boundary conditions for a dirichlet
* control volume.
*
* \param values The dirichlet values for the primary variables
* \param globalPos The position of the center of the boundary intersection
*
* For this method, the \a values parameter stores primary variables.
*/
void generalDirichlet(PrimaryVariables &values,
const GlobalPosition &globalPos) const
{
// Throw an exception (there is no reasonable default value
// for Dirichlet conditions)
DUNE_THROW(Dune::InvalidStateException,
"The problem specifies that some boundary "
"segments are dirichlet, but does not provide "
"a generalDirichlet() method.");
}
/*!
* \brief Evaluate the boundary conditions for a neumann
* boundary segment.
*
* \param values The neumann values for the conservation equations [kg / (m^2 *s )]
* \param intersection The boundary intersection
*
* For this method, the \a values parameter stores the mass flux
* in normal direction of each phase. Negative values mean influx.
*/
void neumann(PrimaryVariables &values,
const Intersection &intersection) const
{
// forward it to the interface with only the global position
asImp_().generalNeumann(values, intersection.geometry().center());
}
/*!
* \brief Evaluate the boundary conditions for a neumann
* boundary segment.
*
* \param values The neumann values for the conservation equations [kg / (m^2 *s )]
* \param globalPos The position of the center of the boundary intersection
*
* For this method, the \a values parameter stores the mass flux
* in normal direction of each phase. Negative values mean influx.
*/
void generalNeumann(PrimaryVariables &values,
const GlobalPosition &globalPos) const
{
// Throw an exception (there is no reasonable default value
// for Neumann conditions)
DUNE_THROW(Dune::InvalidStateException,
"The problem specifies that some boundary "
"segments are neumann, but does not provide "
"a neumann() method.");
}
/*!
* \brief Evaluate the source term
*
* \param values The source and sink values for the conservation equations
* \param element The element
*
* For this method, the \a values parameter stores the rate mass
* generated or annihilate per volume unit. Positive values mean
* that mass is created, negative ones mean that it vanishes.
*/
void source(PrimaryVariables &values,
const Element &element) const
{
// forward to generic interface
asImp_().generalSource(values, element.geometry().center());
}
/*!
* \brief Evaluate the source term for all phases within a given
* sub-control-volume.
*
* \param values The source and sink values for the conservation equations
* \param globalPos The position of the center of the finite volume
* for which the source term ought to be
* specified in global coordinates
*
* For this method, the \a values parameter stores the rate mass
* generated or annihilate per volume unit. Positive values mean
* that mass is created, negative ones mean that it vanishes.
*/
void generalSource(PrimaryVariables &values,
const GlobalPosition &globalPos) const
{ values = Scalar(0.0); }
/*!
* \brief Evaluate the initial value for a control volume.
*
* \param values The initial values for the primary variables
* \param element The element
*
* For this method, the \a values parameter stores primary
* variables.
*/
void initial(PrimaryVariables &values,
const Element &element) const
{
// forward to generic interface
asImp_().generalInitial(values, element.geometry().center());
}
/*!
* \brief Evaluate the initial value for a control volume.
*
* \param values The dirichlet values for the primary variables
* \param globalPos The position of the center of the finite volume
* for which the initial values ought to be
* set (in global coordinates)
*
* For this method, the \a values parameter stores primary variables.
*/
void generalInitial(PrimaryVariables &values,
const GlobalPosition &globalPos) const
{
// Throw an exception (there is no initial condition)
DUNE_THROW(Dune::InvalidStateException,
"The problem does not provide "
"a initial() method.");
}
......@@ -165,13 +378,13 @@ public:
* \brief Returns the current time step size [seconds].
*/
Scalar timeStepSize() const
{ return timeManager_.timeStepSize(); }
{ return timeManager().timeStepSize(); }
/*!
* \brief Sets the current time step size [seconds].
*/
void setTimeStepSize(Scalar dt)
{ return timeManager_.setTimeStepSize(dt); }
{ return timeManager().setTimeStepSize(dt); }
/*!
* \brief Called by Dumux::TimeManager whenever a solution for a
......@@ -179,7 +392,7 @@ public:
* been updated.
*/
Scalar nextTimeStepSize(Scalar dt)
{ return timeManager_.timeStepSize();}
{ return timeManager().timeStepSize();}
/*!
* \brief Returns true if a restart file should be written to
......@@ -231,7 +444,7 @@ public:
std::cout << "Writing result file for current time step\n";
if (!resultWriter_)
resultWriter_ = new VtkMultiWriter(gridView(), asImp_().name());
resultWriter_->beginWrite(timeManager_.time() + timeManager_.timeStepSize());
resultWriter_->beginWrite(timeManager().time() + timeManager().timeStepSize());
model().addOutputVtkFields(*resultWriter_);
asImp_().addOutputVtkFields();
resultWriter_->endWrite();
......@@ -268,7 +481,7 @@ public:
* the application problem is declared! If not, the default name "sim"
* will be used.
*/
static void setName(const char *newName)
void setName(const char *newName)
{
simname_ = newName;
}
......@@ -297,13 +510,13 @@ public:
* \brief Returns TimeManager object used by the simulation
*/
TimeManager &timeManager()
{ return timeManager_; }
{ return *timeManager_; }
/*!
* \brief \copybrief Dumux::OneModelProblem::timeManager()
*/
const TimeManager &timeManager() const
{ return timeManager_; }
{ return *timeManager_; }
/*!
* \brief Returns variables object.
......@@ -353,7 +566,7 @@ public:
res.serializeBegin(asImp_());
std::cerr << "Serialize to file " << res.fileName() << "\n";
timeManager_.serialize(res);
timeManager().serialize(res);
resultWriter_->serialize(res);
model().serialize(res);
......@@ -374,7 +587,7 @@ public:
res.deserializeBegin(asImp_(), t);
std::cerr << "Deserialize from file " << res.fileName() << "\n";
timeManager_.deserialize(res);
timeManager().deserialize(res);
resultWriter_->deserialize(res);
model().deserialize(res);
......@@ -407,7 +620,7 @@ protected:
}
private:
static std::string simname_; // a string for the name of the current simulation,
std::string simname_; // a string for the name of the current simulation,
// which could be set by means of an program argument,
// for example.
const GridView gridView_;
......@@ -415,7 +628,8 @@ private:
GlobalPosition bboxMin_;
GlobalPosition bboxMax_;
TimeManager timeManager_;
TimeManager *timeManager_;
bool deleteTimeManager_;
Variables variables_;
......@@ -424,9 +638,6 @@ private:
VtkMultiWriter *resultWriter_;
int outputInterval_;
};
// definition of the static class member simname_,
// which is necessary because it is of type string.
template <class TypeTag, class Implementation>
std::string OneModelProblem<TypeTag, Implementation>::simname_="sim"; //initialized with default "sim"
}
#endif
Supports Markdown
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