opm-simulators/examples/tutorial_decoupled.cc
2012-07-11 23:28:17 +02:00

118 lines
5.6 KiB
C++

// $Id$
/*****************************************************************************
* Copyright (C) 2008-2009 by Markus Wolff *
* 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"
#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/fractionalflow/define2pmodel.hh"
#include "dumux/material/fluids/water.hh"
#include "dumux/material/fluids/lowviscosityoil.hh"
#include "tutorial_soilproperties_decoupled.hh"
#include "dumux/material/twophaserelations.hh"
#include "tutorialproblem_decoupled.hh"
#include "dumux/diffusion/fv/fvvelocity2p.hh"
#include "dumux/transport/fv/fvsaturation2p.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 Scalar; /*@\label{tutorial-decoupled:grid-begin}@*/
typedef Dune::SGrid<dim,dim> Grid;
typedef Grid::LevelGridView GridView;
typedef Dune::FieldVector<Grid::ctype,dim> FieldVector;
Dune::FieldVector<int,dim> N(10); N[0] = 30;
FieldVector L(0);
FieldVector H(60); H[0] = 300;
Grid 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::LowViscosityOil nonwettingfluid; /*@\label{tutorial-decoupled:oil}@*/
Dune::TutorialSoil<Grid, Scalar> soil; /*@\label{tutorial-decoupled:soil}@*/
Dune::TwoPhaseRelations<Grid, Scalar> materialLaw(soil, wettingfluid, nonwettingfluid);/*@\label{tutorial-decoupled:twophaserelations}@*/
// create object containing the variables
typedef Dune::VariableClass<GridView, Scalar> VariableClass;
VariableClass variables(gridView);
//choose kind of two-phase model. Default: pw, Sw, vtotal
struct Dune::DefineModel modelDef;
// modelDef.pressureType = modelDef.pressureW;
// modelDef.saturationType = modelDef.saturationW;
// modelDef.velocityType = modelDef.velocityTotal;
// create object including the problem definition
typedef Dune::TutorialProblemDecoupled<GridView, Scalar, VariableClass> 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::FVVelocity2P<GridView, Scalar, VariableClass, Problem> Diffusion;
Diffusion diffusion(gridView, problem, modelDef); /*@\label{tutorial-decoupled:diffusion}@*/
// create object including the space discretisation of the saturation equation
typedef Dune::FVSaturation2P<GridView, Scalar, VariableClass, Problem> Transport;
Transport transport(gridView, problem, modelDef); /*@\label{tutorial-decoupled:transport}@*/
// some parameters used in the IMPES-object
int iterFlag = 0;
int nIter = 2;
double maxDefect = 1e-5;
// create object including the IMPES (IMplicit Pressure Explicit Saturation) algorithm
typedef Dune::IMPES<GridView, Diffusion, Transport, VariableClass> IMPES;
IMPES 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 = 4e7; // 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<GridView, IMPES> timeloop(gridView, 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;
}
}