diff --git a/dumux/decoupled/1p/1pproperties.hh b/dumux/decoupled/1p/1pproperties.hh index 4adca903e8c11b20bdd94c7a51e01f25e6d4ea93..5987dab68d2d959728bda4ba36ce193bf7bf8ca2 100644 --- a/dumux/decoupled/1p/1pproperties.hh +++ b/dumux/decoupled/1p/1pproperties.hh @@ -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 diff --git a/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh b/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh index d338dec1adfda07426d948aa342c3143928ed564..307542b226ce534179bbd6912fa44bbd4be2f135 100644 --- a/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh +++ b/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh @@ -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; diff --git a/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh b/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh index 2ff701d11ac7cd9633db7ccaab5e6ca168984bc5..6ce7e61ee6bde20298b127ccc91100d990711727 100644 --- a/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh +++ b/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh @@ -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; diff --git a/dumux/decoupled/2p/transport/transportproblem2p.hh b/dumux/decoupled/2p/transport/transportproblem2p.hh index 8dfd165ae91b0bba13f48cc2a95a776c7fd2ee18..352013830b40c94dbf25e95aa47500a215af79e9 100644 --- a/dumux/decoupled/2p/transport/transportproblem2p.hh +++ b/dumux/decoupled/2p/transport/transportproblem2p.hh @@ -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 */ diff --git a/dumux/decoupled/2p/transport/transportproperties.hh b/dumux/decoupled/2p/transport/transportproperties.hh index 76156471c8a1325294fb6989f1153b7fff02620b..7a08d75184fbf4e86122f4bf7b107ee986ab660c 100644 --- a/dumux/decoupled/2p/transport/transportproperties.hh +++ b/dumux/decoupled/2p/transport/transportproperties.hh @@ -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>); diff --git a/dumux/decoupled/2p2c/2p2cproperties.hh b/dumux/decoupled/2p2c/2p2cproperties.hh index d0dabfe67a270821e2c03ad584dff8c5290c5194..fd0910230371683fbc71677199b745f706a79e7f 100644 --- a/dumux/decoupled/2p2c/2p2cproperties.hh +++ b/dumux/decoupled/2p2c/2p2cproperties.hh @@ -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 diff --git a/dumux/decoupled/common/onemodelproblem.hh b/dumux/decoupled/common/onemodelproblem.hh index 766302c03176cd7af23eb512ac25e072569087ba..cecc5170b180bae2bd315fcfb9623cb26f28c2c1 100644 --- a/dumux/decoupled/common/onemodelproblem.hh +++ b/dumux/decoupled/common/onemodelproblem.hh @@ -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