make the coupled tutorial compile again, clean up the interface between the problem and the model

This commit is contained in:
Andreas Lauser 2009-06-10 12:08:28 +00:00 committed by Andreas Lauser
parent f0c2b59779
commit 74b2d5bd23
6 changed files with 613 additions and 0 deletions

13
examples/CMakeLists.txt Normal file
View File

@ -0,0 +1,13 @@
add_definitions(-DYASPGRID -DGRIDDIM=2 -DENABLE_UG)
# add build targets
ADD_EXECUTABLE("tutorial_decoupled" tutorial_decoupled.cc)
TARGET_LINK_LIBRARIES("tutorial_decoupled" ${DumuxLinkLibraries})
ADD_EXECUTABLE("tutorial_coupled" tutorial_coupled.cc)
TARGET_LINK_LIBRARIES("tutorial_coupled" ${DumuxLinkLibraries})
# add required libraries and includes to the build flags
LINK_DIRECTORIES(${DumuxLinkDirectories})
INCLUDE_DIRECTORIES(${DumuxIncludeDirectories})

25
examples/Makefile.am Normal file
View File

@ -0,0 +1,25 @@
# tests where program to build and program to run are equal
NORMALTESTS = tutorial_decoupled tutorial_coupled
# list of tests to run
#TESTS = $(NORMALTESTS)
# programs just to build when "make check" is used
bin_PROGRAMS = $(NORMALTESTS)
dist_noinst_DATA = tutorial_decoupled.cc tutorial_coupled.cc
tutorial_decoupleddir = $(EXTRA_DIST=CMakeLists.txt
includedir)/dumux/tutorial
tutorial_decoupled_HEADERS = tutorial_soilproperties_decoupled.hh \
tutorialproblem_decoupled.hh
tutorial_decoupled_SOURCES = tutorial_decoupled.cc
tutorial_coupleddir = $(EXTRA_DIST=CMakeLists.txt
includedir)/dumux/tutorial
tutorial_coupled_HEADERS = tutorial_soilproperties_coupled.hh \
tutorialproblem_coupled.hh
tutorial_coupled_SOURCES = tutorial_coupled.cc
EXTRA_DIST=CMakeLists.txt
include $(top_srcdir)/am/global-rules

View File

@ -0,0 +1,117 @@
/*****************************************************************************
* Copyright (C) 2007-2008 by Klaus Mosthaf *
* Copyright (C) 2007-2008 by Bernd Flemisch *
* Copyright (C) 2008-2009 by Andreas Lauser *
* Institute of Hydraulic Engineering *
* University of Stuttgart, Germany *
* email: <givenname>.<name>@iws.uni-stuttgart.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version, as long as this copyright notice *
* is included in its original form. *
* *
* This program is distributed WITHOUT ANY WARRANTY. *
*****************************************************************************/
#include "config.h" /*@\label{tutorial-coupled:include-config-h}@*/
#include "tutorialproblem_coupled.hh" /*@\label{tutorial-coupled:include-problem-header}@*/
#include <dune/common/mpihelper.hh>
#include <dune/common/exceptions.hh>
#include <iostream>
void usage(const char *progname)
{
std::cout << "usage: " << progname << "[--restart restartTime] gridFile.dgf tEnd dt\n";
exit(1);
};
int main(int argc, char** argv)
{
try {
// Specify the type tag of the problem to be solved. All the
// other information can then be retrieved by the property
// system.
typedef TTAG(TutorialProblemCoupled) TypeTag; /*@\label{tutorial-coupled:set-type-tag}@*/
typedef GET_PROP_TYPE(TypeTag, PTAG(Scalar)) Scalar; /*@\label{tutorial-coupled:retrieve-scalar-type}@*/
typedef GET_PROP_TYPE(TypeTag, PTAG(Grid)) Grid; /*@\label{tutorial-coupled:retrieve-grid-type}@*/
typedef GET_PROP_TYPE(TypeTag, PTAG(Problem)) Problem; /*@\label{tutorial-coupled:retrieve-problem-type}@*/
typedef Dune::GridPtr<Grid> GridPointer; /*@\label{tutorial-coupled:set-grid-pointer}@*/
typedef Dune::FieldVector<Grid::ctype, Grid::dimensionworld> GlobalPosition;
// Initialize the message passing interface using DUNE's
// MPIHelper. This line is essential if you would like to run
// your problem on more than one processor at the same
// time. If MPI should not be used, MPIHelper does nothing.
Dune::MPIHelper::instance(argc, argv); /*@\label{tutorial-coupled:init-mpi}@*/
////////////////////////////////////////////////////////////
// parse the command line arguments
////////////////////////////////////////////////////////////
if (argc < 4)
usage(argv[0]);
// parse restart time if restart is requested
int argPos = 1;
bool restart = false;
double restartTime = 0;
if (std::string("--restart") == argv[argPos]) { /*@\label{tutorial-coupled:parse-restart-time}@*/
restart = true;
++argPos;
std::istringstream(argv[argPos++]) >> restartTime;
}
// read the file name of the DGF file, the initial time step
// and the end time
if (argc - argPos != 3) {
usage(argv[0]);
}
const char *dgfFileName = argv[argPos++]; /*@\label{tutorial-coupled:parse-dgf-filename}@*/
double tEnd, dt; /*@\label{tutorial-coupled:parse-tEn-and-dt}@*/
std::istringstream(argv[argPos++]) >> tEnd;
std::istringstream(argv[argPos++]) >> dt;
////////////////////////////////////////////////////////////
// create the grid
////////////////////////////////////////////////////////////
// Load the grid from a DGF file
GridPointer gridPtr = GridPointer(dgfFileName); /*@\label{tutorial-coupled:create-grid}@*/
////////////////////////////////////////////////////////////
// instantiate and run the simulation
////////////////////////////////////////////////////////////
// instantiate the problem
Problem problem(gridPtr->leafView()); /*@\label{tutorial-coupled:instantiate-problem}@*/
// restore the simulation's state from the hard-disk if a
// restart was requested
if (restart) /*@\label{tutorial-coupled:restart}@*/
problem.deserialize(restartTime);
// run the simulation
if (!problem.simulate(dt, tEnd)) /*@\label{tutorial-coupled:execute}@*/
return 2;
return 0;
}
catch (Dune::Exception &e) { /*@\label{tutorial-coupled:catch-dune-exceptions}@*/
// Catch exceptions thrown somewhere in DUNE
std::cerr << "Dune reported error: " << e << std::endl;
}
catch (...) { /*@\label{tutorial-coupled:catch-other-exceptions}@*/
// Catch exceptions thrown elsewhere
std::cerr << "Unknown exception thrown!\n";
throw;
}
return 3;
}

View File

@ -0,0 +1,95 @@
#include "config.h"
#include <iostream>
#include <iomanip>
#include <dune/grid/sgrid.hh> /*@\label{tutorial-decoupled:include-begin}@*/
#include <dune/grid/io/file/vtk/vtkwriter.hh>
#include <dune/istl/io.hh>
#include <dune/common/timer.hh>
#include "dumux/fractionalflow/variableclass2p.hh"
#include "dumux/material/fluids/water.hh"
#include "dumux/material/fluids/oil.hh"
#include "tutorial_soilproperties_decoupled.hh"
#include "dumux/material/twophaserelations.hh"
#include "tutorialproblem_decoupled.hh"
#include "dumux/diffusion/fv/fvtotalvelocity2p.hh"
#include "dumux/transport/fv/fvsaturationwetting2p.hh"
#include "dumux/fractionalflow/impes/impes.hh"
#include "dumux/timedisc/timeloop.hh" /*@\label{tutorial-decoupled:include-end}@*/
int main(int argc, char** argv)
{
try{
// define the problem dimensions
const int dim=2; /*@\label{tutorial-decoupled:dim}@*/
// create a grid object
typedef double NumberType; /*@\label{tutorial-decoupled:grid-begin}@*/
typedef Dune::SGrid<dim,dim> GridType;
typedef GridType::LevelGridView GridView;
typedef Dune::FieldVector<GridType::ctype,dim> FieldVector;
Dune::FieldVector<int,dim> N(10); N[0] = 30;
FieldVector L(0);
FieldVector H(300); H[0] = 600;
GridType grid(N,L,H);
GridView gridView(grid.levelView(0));/*@\label{tutorial-decoupled:grid-end}@*/
// define fluid and solid properties and constitutive relationships
Dune::Water wettingfluid; /*@\label{tutorial-decoupled:water}@*/
Dune::Oil nonwettingfluid; /*@\label{tutorial-decoupled:oil}@*/
Dune::TutorialSoil<GridType, NumberType> soil; /*@\label{tutorial-decoupled:soil}@*/
Dune::TwoPhaseRelations<GridType, NumberType> materialLaw(soil, wettingfluid, nonwettingfluid);/*@\label{tutorial-decoupled:twophaserelations}@*/
// create object containing the variables
typedef Dune::VariableClass<GridView, NumberType> VariableType;
VariableType variables(gridView);
// create object including the problem definition
typedef Dune::TutorialProblemDecoupled<GridView, NumberType, VariableType> Problem;
Problem problem(variables, wettingfluid, nonwettingfluid, soil, materialLaw,L, H); /*@\label{tutorial-decoupled:problem}@*/
// create object including the discretisation of the pressure equation
typedef Dune::FVTotalVelocity2P<GridView, NumberType, VariableType, Problem> DiffusionType;
DiffusionType diffusion(gridView, problem, "pw"); /*@\label{tutorial-decoupled:diffusion}@*/
// create object including the space discretisation of the saturation equation
typedef Dune::FVSaturationWetting2P<GridView, NumberType, VariableType, Problem> TransportType;
TransportType transport(gridView, problem, "vt"); /*@\label{tutorial-decoupled:transport}@*/
// some parameters used in the IMPES-object
int iterFlag = 2;
int nIter = 30;
double maxDefect = 1e-5;
// create object including the IMPES (IMplicit Pressure Explicit Saturation) algorithm
typedef Dune::IMPES<GridView, DiffusionType, TransportType, VariableType> IMPESType;
IMPESType impes(diffusion, transport, iterFlag, nIter, maxDefect); /*@\label{tutorial-decoupled:impes}@*/
// some parameters needed for the TimeLoop-object
double tStart = 0; // start simulation at t = tStart
double tEnd = 1e8; // stop simulation at t = tEnd
const char* fileName = "tutorial_decoupled"; // name of the output files
int modulo = 1; // define time step interval in which output files are generated
double cFLFactor = 0.9; // security factor for the Courant-Friedrichs-Lewy-Criterion
// create TimeLoop-object
Dune::TimeLoop<GridType, IMPESType > timeloop(tStart, tEnd, fileName, modulo, cFLFactor); /*@\label{tutorial-decoupled:timeloop}@*/
Dune::Timer timer;
timer.reset();
// start simulation
timeloop.execute(impes); /*@\label{tutorial-decoupled:execute}@*/
return 0;
}
catch (Dune::Exception &e){
std::cerr << "Dune reported error: " << e << std::endl;
return 1;
}
catch (...){
std::cerr << "Unknown exception thrown!" << std::endl;
return 1;
}
}

View File

@ -0,0 +1,251 @@
// $Id$
/*****************************************************************************
* Copyright (C) 2008-2009 by Melanie Darcis *
* Copyright (C) 2009 by Andreas Lauser *
* Institute of Hydraulic Engineering *
* University of Stuttgart, Germany *
* email: <givenname>.<name>@iws.uni-stuttgart.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version, as long as this copyright notice *
* is included in its original form. *
* *
* This program is distributed WITHOUT ANY WARRANTY. *
*****************************************************************************/
#ifndef DUNE_TUTORIALPROBLEM_COUPLED_HH
#define DUNE_TUTORIALPROBLEM_COUPLED_HH
// fluid properties
#include <dumux/material/fluids/water.hh>
#include <dumux/material/fluids/oil.hh>
// the numerical model
#include <dumux/boxmodels/2p/2pboxmodel.hh>
// the grid used
#include <dune/grid/yaspgrid.hh>
#include <dune/grid/io/file/dgfparser/dgfyasp.hh>
// the soil to be used
#include "tutorialsoil_coupled.hh"
namespace Dune
{
// forward declaration of the problem class
template <class TypeTag>
class TutorialProblemCoupled;
//////////
// Specify the properties of the problem
//////////
namespace Properties
{
// create a new type tag for the problem
NEW_TYPE_TAG(TutorialProblemCoupled, INHERITS_FROM(BoxTwoP));
// Set the "Problem" property
SET_PROP(TutorialProblemCoupled, Problem)
{
typedef Dune::TutorialProblemCoupled<TTAG(TutorialProblemCoupled)> type;
};
// Set the grid type
SET_TYPE_PROP(TutorialProblemCoupled, Grid, Dune::YaspGrid<2>);
// Set the wetting phase
SET_TYPE_PROP(TutorialProblemCoupled, WettingPhase, Dune::Water);
// Set the non-wetting phase
SET_TYPE_PROP(TutorialProblemCoupled, NonwettingPhase, Dune::Oil);
// Set the soil properties
SET_PROP(TutorialProblemCoupled, Soil)
{
private:
typedef typename GET_PROP_TYPE(TypeTag, PTAG(Grid)) Grid;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(Scalar)) Scalar;
public:
typedef Dune::TutorialSoil<Grid, Scalar> type;
};
// Enable gravity
SET_BOOL_PROP(TutorialProblemCoupled, EnableGravity, true);
}
/*!
* \ingroup TwoPBoxProblems
* \brief The problem used for the tutorial of the coupled models
*/
template <class TypeTag = TTAG(TutorialProblemCoupled) >
class TutorialProblemCoupled : public TwoPBoxProblem<TypeTag,
TutorialProblemCoupled<TypeTag> >
{
typedef TutorialProblemCoupled<TypeTag> ThisType;
typedef TwoPBoxProblem<TypeTag, ThisType> ParentType;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(GridView)) GridView;
// Grid and world dimension
enum {
dim = GridView::dimension,
dimWorld = GridView::dimensionworld,
};
typedef typename GridView::Grid::ctype CoordScalar;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(Scalar)) Scalar;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(TwoPIndices)) Indices;
typedef typename GridView::template Codim<0>::Entity Element;
typedef typename GridView::template Codim<dim>::Entity Vertex;
typedef typename GridView::IntersectionIterator IntersectionIterator;
typedef Dune::FieldVector<CoordScalar, dim> LocalPosition;
typedef Dune::FieldVector<CoordScalar, dimWorld> GlobalPosition;
typedef typename GET_PROP(TypeTag, PTAG(SolutionTypes)) SolutionTypes;
typedef typename SolutionTypes::PrimaryVarVector PrimaryVarVector;
typedef typename SolutionTypes::BoundaryTypeVector BoundaryTypeVector;
typedef typename GET_PROP_TYPE(TypeTag, PTAG(FVElementGeometry)) FVElementGeometry;
public:
TutorialProblemCoupled(const GridView &gridView)
: ParentType(gridView)
{
}
/*!
* \name Problem parameters
*/
// \{
/*!
* \brief Returns the temperature within the domain.
*
* We use 10°C...
*/
Scalar temperature() const
{ return 283.15; };
// \}
/*!
* \name Boundary conditions
*/
// \{
/*!
* \brief Specifies which kind of boundary condition should be
* used for which equation on a given boundary segment.
*/
void boundaryTypes(BoundaryTypeVector &values,
const Element &element,
const FVElementGeometry &fvElemGeom,
const IntersectionIterator &isIt,
int scvIdx,
int boundaryFaceIdx) const
{
const GlobalPosition &pos = element.geometry().corner(scvIdx);
if (pos[0] < eps_)
// dirichlet conditions on left boundary
values = BoundaryConditions::dirichlet;
else
// neuman for the remaining boundaries
values = BoundaryConditions::neumann;
}
/*!
* \brief Evaluate the boundary conditions for a dirichlet
* boundary segment.
*
* For this method, the \a values parameter stores primary variables.
*/
void dirichlet(PrimaryVarVector &values,
const Element &element,
const FVElementGeometry &fvElemGeom,
const IntersectionIterator &isIt,
int scvIdx,
int boundaryFaceIdx) const
{
values[Indices::pW] = 200.0e3; // 200 000 Pa = 2 bar
values[Indices::sN] = 1.0; // 100 % oil saturation
}
/*!
* \brief Evaluate the boundary conditions for a neumann
* boundary segment.
*
* For this method, the \a values parameter stores the mass flux
* in normal direction of each phase. Negative values mean influx.
*/
void neumann(PrimaryVarVector &values,
const Element &element,
const FVElementGeometry &fvElemGeom,
const IntersectionIterator &isIt,
int scvIdx,
int boundaryFaceIdx) const
{
const GlobalPosition &pos = element.geometry().corner(scvIdx);
if (pos[0]> right_ - eps_) {
// outflow of 0.3 g/(m * s) oil on the right boundary of the
// domain
values[Indices::phase2Mass(Indices::wPhase)] = 0;
values[Indices::phase2Mass(Indices::nPhase)] = 0.3e-3;
} else {
// no-flow on the remaining neumann-boundaries
values[Indices::phase2Mass(Indices::wPhase)] = 0;
values[Indices::phase2Mass(Indices::nPhase)] = 0;
}
}
// \}
/*!
* \name Volume terms
*/
// \{
/*!
* \brief Evaluate the initial value for a control volume.
*
* For this method, the \a values parameter stores primary
* variables.
*/
void initial(PrimaryVarVector &values,
const Element &element,
const FVElementGeometry &fvElemGeom,
int scvIdx) const
{
values[Indices::pW] = 200.0e3; // 200 000 Pa = 2 bar
values[Indices::sN] = 1.0;
}
/*!
* \brief Evaluate the source term for all phases within a given
* sub-control-volume.
*
* 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(PrimaryVarVector &values,
const Element &element,
const FVElementGeometry &,
int subControlVolumeIdx) const
{
values[Indices::phase2Mass(Indices::wPhase)] = 0.0;
values[Indices::phase2Mass(Indices::nPhase)] = 0.0;
}
// \}
private:
static const Scalar eps_ = 3e-6;
static const Scalar right_ = 5.0;
};
} //end namespace
#endif

View File

@ -0,0 +1,112 @@
#ifndef TUTORIALPROBLEM_DECOUPLED_HH
#define TUTORIALPROBLEM_DECOUPLED_HH
#include "dumux/fractionalflow/fractionalflowproblem.hh"
namespace Dune
{
/** \todo Please doc me! */
template<class GridView, class Scalar, class VC> class TutorialProblemDecoupled /*@\label{tutorial-decoupled:tutorialproblem}@*/
: public FractionalFlowProblem<GridView, Scalar, VC>
{
enum
{dim=GridView::dimension, dimWorld = GridView::dimensionworld};
typedef typename GridView::Grid Grid;
typedef typename GridView::Traits::template Codim<0>::Entity Element;
typedef Dune::FieldVector<Scalar,dim> LocalPosition;
typedef Dune::FieldVector<Scalar,dimWorld> GlobalPosition;
public:
TutorialProblemDecoupled(VC& variables, Fluid& wettingphase, Fluid& nonwettingphase, Matrix2p<Grid, Scalar>& soil,
TwoPhaseRelations<Grid, Scalar>& materialLaw = *(new TwoPhaseRelations<Grid,Scalar>),
const FieldVector<Scalar,dim> Left = 0, const FieldVector<Scalar,dim> Right = 0)
: FractionalFlowProblem<GridView, Scalar, VC>(variables, wettingphase, nonwettingphase, soil, materialLaw),
Left_(Left[0]), Right_(Right[0]), eps_(1e-8)
{}
// function returning source/sink terms for the pressure equation
// depending on the position within the domain
virtual Scalar sourcePress (const GlobalPosition& globalPos, const Element& e, /*@\label{tutorial-decoupled:qpress}@*/
const LocalPosition& localPos)
{
return 0;
}
// function returning the boundary condition type for solution
// of the pressure equation depending on the position within the domain
typename BoundaryConditions::Flags bctypePress(const GlobalPosition& globalPos, const Element& e, /*@\label{tutorial-decoupled:bctypepress}@*/
const LocalPosition& localPos) const
{
if (globalPos[0] < eps_)
{
return BoundaryConditions::dirichlet;
}
// all other boundaries
return BoundaryConditions::neumann;
}
// function returning the boundary condition type for solution
// of the saturation equation depending on the position within the domain
BoundaryConditions::Flags bctypeSat (const GlobalPosition& globalPos, const Element& e, /*@\label{tutorial-decoupled:bctypesat}@*/
const LocalPosition& localPos) const
{
if (globalPos[0]> (Right_ - eps_) || globalPos[0] < eps_)
{
return Dune::BoundaryConditions::dirichlet;
}
// all other boundaries
return Dune::BoundaryConditions::neumann;
}
// function returning the Dirichlet boundary condition for the solution
// of the pressure equation depending on the position within the domain
Scalar dirichletPress(const GlobalPosition& globalPos, const Element& e, /*@\label{tutorial-decoupled:gpress}@*/
const LocalPosition& localPos) const
{
return 2e5;
}
// function returning the Dirichlet boundary condition for the solution
// of the saturation equation depending on the position within the domain
Scalar dirichletSat(const GlobalPosition& globalPos, const Element& e, /*@\label{tutorial-decoupled:gsat}@*/
const LocalPosition& localPos) const
{
if (globalPos[0] < eps_)
{
return 1;
}
// all other boundaries
return 0;
}
// function returning the Neumann boundary condition for the solution
// of the pressure equation depending on the position within the domain
Scalar neumannPress(const GlobalPosition& globalPos, const Element& e, /*@\label{tutorial-decoupled:jpress}@*/
const LocalPosition& localPos) const
{
if (globalPos[0]> Right_ - eps_)
{
return 3e-7;
}
// all other boundaries
return 0;
}
// function returning the initial saturation
// depending on the position within the domain
Scalar initSat (const GlobalPosition& globalPos, const Element& e, /*@\label{tutorial-decoupled:initsat}@*/
const FieldVector<Scalar,dim>& xi) const
{
return 0;
}
private:
Scalar Left_;
Scalar Right_;
Scalar eps_;
};
} // end namespace
#endif