Examples and tutorials follow change to IncompTpfa interface.

This commit is contained in:
Atgeirr Flø Rasmussen 2012-06-12 15:28:53 +02:00
parent 1a4e7e3065
commit f01622bd09
3 changed files with 76 additions and 127 deletions

View File

@ -39,11 +39,14 @@
#include <iostream>
#include <fstream>
#include <vector>
#include <opm/core/fluid/IncompPropertiesBasic.hpp>
#include <opm/core/linalg/LinearSolverUmfpack.hpp>
#include <opm/core/pressure/IncompTpfa.hpp>
#include <opm/core/pressure/FlowBCManager.hpp>
#include <opm/core/utility/miscUtilities.hpp>
#include <opm/core/utility/Units.hpp>
#include <opm/core/simulator/TwophaseState.hpp>
#include <opm/core/simulator/WellState.hpp>
/// \page tutorial2
/// \section commentedcode2 Program walkthrough.
@ -68,16 +71,21 @@ int main()
int num_cells = grid.c_grid()->number_of_cells;
int num_faces = grid.c_grid()->number_of_faces;
/// \endcode
/// \page tutorial2
/// \details
/// We define a fluid viscosity equal to 1 cP.
/// We define a fluid viscosity equal to 1 cP and density equal
/// to 1000 kg/m^3.
/// The <opm/core/utility/Units.hpp> header contains support
/// for common units and prefixes, in the namespaces Opm::unit
/// and Opm::prefix.
/// \code
using namespace Opm::unit;
using namespace Opm::prefix;
double mu = 1.0*centi*Poise;
int num_phases = 1;
std::vector<double> mu(num_phases, 1.0*centi*Poise);
std::vector<double> rho(num_phases, 1000.0*kilogram/cubic(meter));
/// \endcode
/// \page tutorial2
/// \details
@ -87,17 +95,13 @@ int main()
/// \endcode
/// \page tutorial2
/// \details
/// We set up a diagonal permeability tensor and compute the mobility for each cell.
/// The resulting permeability matrix is flattened in a vector.
/// \page tutorial2
/// \details
/// We set up a simple property object for a single-phase situation.
/// \code
std::vector<double> permeability(num_cells*dim*dim, 0.);
std::vector<double> mob(num_cells);
for (int cell = 0; cell < num_cells; ++cell) {
permeability[9*cell + 0] = k;
permeability[9*cell + 4] = k;
permeability[9*cell + 8] = k;
mob[cell] = 1/mu;
}
Opm::IncompPropertiesBasic props(1, Opm::SaturationPropsBasic::Constant, rho,
mu, 1.0, k, dim, num_cells);
/// \endcode
/// \page tutorial2
@ -109,14 +113,6 @@ int main()
/// \endcode
/// \page tutorial2
/// We set up a pressure solver for the incompressible problem,
/// using the two-point flux approximation discretization. The
/// third argument which corresponds to gravity is set to a null
/// pointer (no gravity). The final argument would be a pointer to
/// a Wells data structure, again we use a null pointer to
/// indicate that we have no wells.
/// \code
Opm::IncompTpfa psolver(*grid.c_grid(), &permeability[0], 0, linsolver, 0);
/// \endcode
/// \page tutorial2
/// We define the source term.
@ -132,39 +128,33 @@ int main()
Opm::FlowBCManager bcs;
/// \endcode
/// We set up a pressure solver for the incompressible problem,
/// using the two-point flux approximation discretization. The
/// null pointers correspond to arguments for gravity, wells and
/// boundary conditions, which are all defaulted (to zero gravity,
/// no wells, and no-flow boundaries).
/// \code
Opm::IncompTpfa psolver(*grid.c_grid(), props, linsolver, NULL, NULL, src, NULL);
/// \page tutorial2
/// We declare the solution vectors, i.e., the pressure and face
/// flux vectors we are going to compute. The well solution
/// vectors are needed for interface compatibility with the
/// We declare the state object, that will contain the pressure and face
/// flux vectors we are going to compute. The well state
/// object is needed for interface compatibility with the
/// <CODE>solve()</CODE> method of class
/// <CODE>Opm::IncompTPFA</CODE>.
/// \code
std::vector<double> pressure(num_cells);
std::vector<double> faceflux(num_faces);
std::vector<double> well_bhp;
std::vector<double> well_flux;
/// \endcode
/// \page tutorial2
/// \details
/// We declare the gravity term which is required by the pressure solver (see
/// Opm::IncompTpfa.solve()). In the absence of gravity, an empty vector is required.
/// \code
std::vector<double> omega;
/// \endcode
/// \page tutorial2
/// \details
/// We declare the wdp term which is required by the pressure solver (see
/// Opm::IncompTpfa.solve()). In the absence of wells, an empty vector is required.
/// \code
std::vector<double> wdp;
Opm::TwophaseState state;
state.pressure().resize(num_cells);
state.faceflux().resize(num_faces);
Opm::WellState well_state;
/// \endcode
/// \page tutorial2
/// We call the pressure solver.
/// The first (timestep) argument does not matter for this
/// incompressible case.
/// \code
psolver.solve(mob, omega, src, wdp, bcs.c_bcs(),
pressure, faceflux, well_bhp, well_flux);
psolver.solve(1.0*day, state, well_state);
/// \endcode
/// \page tutorial2
@ -175,9 +165,9 @@ int main()
/// \code
std::ofstream vtkfile("tutorial2.vtu");
Opm::DataMap dm;
dm["pressure"] = &pressure;
dm["pressure"] = &state.pressure();
std::vector<double> cell_velocity;
Opm::estimateCellVelocity(*grid.c_grid(), faceflux, cell_velocity);
Opm::estimateCellVelocity(*grid.c_grid(), state.faceflux(), cell_velocity);
dm["velocity"] = &cell_velocity;
Opm::writeVtkData(*grid.c_grid(), dm, vtkfile);
}

View File

@ -38,6 +38,7 @@
#include <opm/core/transport/reorder/TransportModelTwophase.hpp>
#include <opm/core/simulator/TwophaseState.hpp>
#include <opm/core/simulator/WellState.hpp>
#include <opm/core/utility/miscUtilities.hpp>
#include <opm/core/utility/Units.hpp>
@ -161,16 +162,6 @@ int main ()
std::vector<double> omega;
/// \endcode
/// \page tutorial3
/// \details We may now set up the pressure solver. At this point,
/// unchanging parameters such as transmissibility are computed
/// and stored internally by the IncompTpfa class. The final (null pointer)
/// constructor argument is for wells, which are now used in this tutorial.
/// \code
LinearSolverUmfpack linsolver;
IncompTpfa psolver(grid, props.permeability(), grav, linsolver, 0);
/// \endcode
/// \page tutorial3
/// \details We set up the source term. Positive numbers indicate that the cell is a source,
/// while negative numbers indicate a sink.
@ -181,14 +172,28 @@ int main ()
/// \endcode
/// \page tutorial3
/// \details We set up data vectors for the wells. Here, there are
/// no wells and we let them be empty dummies.
/// \details We set up the boundary conditions. Letting bcs be empty is equivalent
/// to no-flow boundary conditions.
/// \code
std::vector<double> empty_wdp;
std::vector<double> empty_well_bhp;
std::vector<double> empty_well_flux;
FlowBCManager bcs;
/// \endcode
/// \page tutorial3
/// \details We may now set up the pressure solver. At this point,
/// unchanging parameters such as transmissibility are computed
/// and stored internally by the IncompTpfa class. The null pointer
/// constructor argument is for wells, which are not used in this tutorial.
/// \code
LinearSolverUmfpack linsolver;
IncompTpfa psolver(grid, props, linsolver, grav, NULL, src, bcs.c_bcs());
/// \endcode
/// \page tutorial3
/// \details We set up a state object for the wells. Here, there are
/// no wells and we let it remain empty.
/// \code
WellState well_state;
/// \endcode
/// \page tutorial3
/// \details We compute the pore volume
@ -223,14 +228,6 @@ int main ()
}
/// \endcode
/// \page tutorial3
/// \details We set up the boundary conditions. Letting bcs be empty is equivalent
/// to no-flow boundary conditions.
/// \code
FlowBCManager bcs;
/// \endcode
/// \page tutorial3
/// \details
/// We set up a two-phase state object, and
@ -240,13 +237,6 @@ int main ()
state.init(grid, 2);
state.setFirstSat(allcells, props, TwophaseState::MinSat);
/// \endcode
/// \page tutorial3
/// \details We introduce a vector which contains the total mobility
/// on all cells.
/// \code
std::vector<double> totmob;
/// \endcode
/// \page tutorial3
/// \details This string stream will be used to construct a new
@ -263,18 +253,11 @@ int main ()
/// \endcode
/// \page tutorial3
/// \details Compute the total mobility. It is needed by the
/// pressure solver and must be recomputed every time step
/// since it depends on the saturation.
/// \code
computeTotalMobility(props, allcells, state.saturation(), totmob);
/// \endcode
/// \page tutorial3
/// \details Solve the pressure equation
/// \code
psolver.solve(totmob, omega, src, empty_wdp, bcs.c_bcs(),
state.pressure(), state.faceflux(), empty_well_bhp,
empty_well_flux);
psolver.solve(dt, state, well_state);
/// \endcode
/// \page tutorial3
/// \details Solve the transport equation.

View File

@ -38,6 +38,7 @@
#include <opm/core/transport/reorder/TransportModelTwophase.hpp>
#include <opm/core/simulator/TwophaseState.hpp>
#include <opm/core/simulator/WellState.hpp>
#include <opm/core/utility/miscUtilities.hpp>
#include <opm/core/utility/Units.hpp>
@ -120,20 +121,6 @@ int main ()
std::vector<double> omega;
/// \endcode
/// \page tutorial4
/// \details We set up necessary information for the wells
/// \code
std::vector<double> wdp;
std::vector<double> well_bhp;
std::vector<double> well_flux;
std::vector<double> well_resflowrates_phase;
std::vector<double> well_surflowrates_phase;
std::vector<double> fractional_flows;
/// \endcode
/// \page tutorial4
/// \details We set up the source term. Positive numbers indicate that the cell is a source,
/// while negative numbers indicate a sink.
@ -192,13 +179,6 @@ int main ()
state.setFirstSat(allcells, props, TwophaseState::MinSat);
/// \endcode
/// \page tutorial4
/// \details We introduce a vector which contains the total mobility
/// on all cells.
/// \code
std::vector<double> totmob;
/// \endcode
/// \page tutorial4
/// \details This string will contain the name of a VTK output vector.
/// \code
@ -299,11 +279,21 @@ int main ()
///\endcode
/// \page tutorial4
/// \details We set up the pressure solver. We need to pass the wells pointer as the
/// last argument.
/// \details We set up necessary information for the wells
/// \code
WellState well_state;
well_state.init(wells, state);
std::vector<double> well_resflowrates_phase;
std::vector<double> well_surflowrates_phase;
std::vector<double> fractional_flows;
/// \endcode
/// \page tutorial4
/// \details We set up the pressure solver.
/// \code
LinearSolverUmfpack linsolver;
IncompTpfa psolver(grid, props.permeability(), grav, linsolver, wells);
IncompTpfa psolver(grid, props, linsolver,
grav, wells, src, bcs.c_bcs());
/// \endcode
@ -312,18 +302,6 @@ int main ()
/// \code
for (int i = 0; i < num_time_steps; ++i) {
/// \endcode
/// \page tutorial4
/// \details Compute the total mobility. It is needed by the pressure solver
/// \code
computeTotalMobility(props, allcells, state.saturation(), totmob);
/// \endcode
/// \endcode
/// \page tutorial4
/// \details In order to use the well controls, we need to generate the WDP for each well.
/// \code
Opm::computeWDP(*wells, grid, state.saturation(), props.density(), gravity, true, wdp);
/// \endcode
/// \page tutorial4
/// \details We're solving the pressure until the well conditions are met
@ -338,31 +316,29 @@ int main ()
/// \page tutorial4
/// \details Solve the pressure equation
/// \code
psolver.solve(totmob, omega, src, wdp, bcs.c_bcs(),
state.pressure(), state.faceflux(), well_bhp,
well_flux);
psolver.solve(dt, state, well_state);
/// \endcode
/// \page tutorial4
/// \details We compute the new well rates. Notice that we approximate (wrongly) surfflowsrates := resflowsrate
Opm::computeFractionalFlow(props, allcells, state.saturation(), fractional_flows);
Opm::computePhaseFlowRatesPerWell(*wells, well_flux, fractional_flows, well_resflowrates_phase);
Opm::computePhaseFlowRatesPerWell(*wells, well_flux, fractional_flows, well_surflowrates_phase);
Opm::computePhaseFlowRatesPerWell(*wells, well_state.perfRates(), fractional_flows, well_resflowrates_phase);
Opm::computePhaseFlowRatesPerWell(*wells, well_state.perfRates(), fractional_flows, well_surflowrates_phase);
/// \endcode
/// \page tutorial4
/// \details We check if the well conditions are met.
well_conditions_met = well_collection.conditionsMet(well_bhp, well_resflowrates_phase, well_surflowrates_phase);
well_conditions_met = well_collection.conditionsMet(well_state.bhp(), well_resflowrates_phase, well_surflowrates_phase);
++well_iter;
if (!well_conditions_met && well_iter == max_well_iterations) {
THROW("Conditions not met within " << max_well_iterations<< " iterations.");
}
}
/// \endcode
/// \page tutorial4
/// \details Transport solver
/// \TODO We must call computeTransportSource() here, since we have wells.
/// \code
transport_solver.solve(&state.faceflux()[0], &porevol[0], &src[0], dt, state.saturation());
/// \endcode