2012-02-20 06:23:01 -06:00
|
|
|
/*
|
|
|
|
Copyright 2012 SINTEF ICT, Applied Mathematics.
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <opm/core/pressure/IncompTpfa.hpp>
|
|
|
|
#include <opm/core/pressure/tpfa/ifs_tpfa.h>
|
|
|
|
#include <opm/core/pressure/tpfa/trans_tpfa.h>
|
|
|
|
#include <opm/core/pressure/mimetic/mimetic.h>
|
2012-02-21 14:45:04 -06:00
|
|
|
#include <opm/core/linalg/LinearSolverInterface.hpp>
|
2012-02-20 06:39:40 -06:00
|
|
|
#include <opm/core/utility/ErrorMacros.hpp>
|
2012-02-20 06:23:01 -06:00
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Construct solver.
|
|
|
|
/// \param[in] g A 2d or 3d grid.
|
|
|
|
/// \param[in] permeability Array of permeability tensors, the array
|
|
|
|
/// should have size N*D^2, if D == g.dimensions
|
|
|
|
/// and N == g.number_of_cells.
|
|
|
|
/// \param[in] gravity Gravity vector. If nonzero, the array should
|
|
|
|
/// have D elements.
|
|
|
|
IncompTpfa::IncompTpfa(const UnstructuredGrid& g,
|
|
|
|
const double* permeability,
|
2012-02-21 14:45:04 -06:00
|
|
|
const double* gravity,
|
|
|
|
const LinearSolverInterface& linsolver)
|
2012-02-20 06:23:01 -06:00
|
|
|
: grid_(g),
|
2012-02-21 14:45:04 -06:00
|
|
|
linsolver_(linsolver),
|
2012-02-20 06:23:01 -06:00
|
|
|
htrans_(g.cell_facepos[ g.number_of_cells ]),
|
2012-02-20 06:39:40 -06:00
|
|
|
trans_ (g.number_of_faces)
|
2012-02-20 06:23:01 -06:00
|
|
|
{
|
|
|
|
UnstructuredGrid* gg = const_cast<UnstructuredGrid*>(&grid_);
|
|
|
|
tpfa_htrans_compute(gg, permeability, &htrans_[0]);
|
|
|
|
if (gravity) {
|
2012-02-20 06:39:40 -06:00
|
|
|
gpress_.resize(g.cell_facepos[ g.number_of_cells ], 0.0);
|
|
|
|
|
2012-02-20 06:23:01 -06:00
|
|
|
mim_ip_compute_gpress(gg->number_of_cells, gg->dimensions, gravity,
|
|
|
|
gg->cell_facepos, gg->cell_faces,
|
|
|
|
gg->face_centroids, gg->cell_centroids,
|
|
|
|
&gpress_[0]);
|
|
|
|
}
|
2012-02-20 10:05:28 -06:00
|
|
|
// gpress_omegaweighted_ is sent to assembler always, and it dislikes
|
|
|
|
// getting a zero pointer.
|
|
|
|
gpress_omegaweighted_.resize(g.cell_facepos[ g.number_of_cells ], 0.0);
|
2012-02-20 06:23:01 -06:00
|
|
|
h_ = ifs_tpfa_construct(gg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Destructor.
|
|
|
|
IncompTpfa::~IncompTpfa()
|
|
|
|
{
|
|
|
|
ifs_tpfa_destroy(h_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Assemble and solve pressure system.
|
|
|
|
/// \param[in] totmob Must contain N total mobility values (one per cell).
|
|
|
|
/// totmob = \sum_{p} kr_p/mu_p.
|
2012-02-20 06:39:40 -06:00
|
|
|
/// \param[in] omega Must be empty if constructor gravity argument was null.
|
|
|
|
/// Otherwise must contain N mobility-weighted density values (one per cell).
|
2012-02-20 06:23:01 -06:00
|
|
|
/// omega = \frac{\sum_{p} mob_p rho_p}{\sum_p rho_p}.
|
2012-02-20 06:39:40 -06:00
|
|
|
/// \param[in] src Must contain N source rates (one per cell).
|
2012-02-20 06:23:01 -06:00
|
|
|
/// Positive values represent total inflow rates,
|
|
|
|
/// negative values represent total outflow rates.
|
|
|
|
/// \param[out] pressure Will contain N cell-pressure values.
|
|
|
|
/// \param[out] faceflux Will contain F signed face flux values.
|
|
|
|
void IncompTpfa::solve(const std::vector<double>& totmob,
|
|
|
|
const std::vector<double>& omega,
|
|
|
|
const std::vector<double>& src,
|
|
|
|
std::vector<double>& pressure,
|
|
|
|
std::vector<double>& faceflux)
|
|
|
|
{
|
|
|
|
UnstructuredGrid* gg = const_cast<UnstructuredGrid*>(&grid_);
|
|
|
|
tpfa_eff_trans_compute(gg, &totmob[0], &htrans_[0], &trans_[0]);
|
|
|
|
|
|
|
|
if (!omega.empty()) {
|
2012-02-20 06:39:40 -06:00
|
|
|
if (gpress_.empty()) {
|
|
|
|
THROW("Nozero omega argument given, but gravity was null in constructor.");
|
|
|
|
}
|
2012-02-20 06:23:01 -06:00
|
|
|
mim_ip_density_update(gg->number_of_cells, gg->cell_facepos,
|
|
|
|
&omega[0],
|
|
|
|
&gpress_[0], &gpress_omegaweighted_[0]);
|
2012-02-20 06:39:40 -06:00
|
|
|
} else {
|
|
|
|
if (!gpress_.empty()) {
|
|
|
|
THROW("Empty omega argument given, but gravity was non-null in constructor.");
|
|
|
|
}
|
2012-02-20 06:23:01 -06:00
|
|
|
}
|
|
|
|
|
2012-03-06 07:00:34 -06:00
|
|
|
ifs_tpfa_forces F;
|
|
|
|
F.src = &src[0];
|
|
|
|
|
|
|
|
ifs_tpfa_assemble(gg, &F, &trans_[0], &gpress_omegaweighted_[0], h_);
|
2012-02-20 06:23:01 -06:00
|
|
|
|
2012-02-21 14:45:04 -06:00
|
|
|
linsolver_.solve(h_->A, h_->b, h_->x);
|
2012-02-20 06:23:01 -06:00
|
|
|
|
|
|
|
pressure.resize(grid_.number_of_cells);
|
|
|
|
faceflux.resize(grid_.number_of_faces);
|
|
|
|
|
|
|
|
ifs_tpfa_press_flux(gg, &trans_[0], h_,
|
|
|
|
&pressure[0],
|
|
|
|
&faceflux[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace Opm
|