Loading...
Searching...
No Matches
multiphasebaseproblem.hh
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
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 2 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/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef EWOMS_MULTI_PHASE_BASE_PROBLEM_HH
#define EWOMS_MULTI_PHASE_BASE_PROBLEM_HH
#include <dune/common/fmatrix.hh>
#include <dune/common/fvector.hh>
#include <dune/grid/common/partitionset.hh>
#include <opm/material/fluidmatrixinteractions/NullMaterial.hpp>
#include <opm/material/common/Means.hpp>
#include <opm/material/densead/Evaluation.hpp>
#include <opm/models/common/directionalmobility.hh>
#include <opm/models/common/multiphasebaseparameters.hh>
#include <opm/models/common/multiphasebaseproperties.hh>
#include <opm/models/discretization/common/fvbaseproblem.hh>
#include <opm/models/discretization/common/fvbaseproperties.hh>
#include <opm/utility/CopyablePtr.hpp>
#include <algorithm>
#include <array>
#include <stdexcept>
namespace Opm {
template<class TypeTag>
class MultiPhaseBaseProblem
: public FvBaseProblem<TypeTag>
, public GetPropType<TypeTag, Properties::FluxModule>::FluxBaseProblem
{
using ParentType = FvBaseProblem<TypeTag>;
using Implementation = GetPropType<TypeTag, Properties::Problem>;
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using Evaluation = GetPropType<TypeTag, Properties::Evaluation>;
using GridView = GetPropType<TypeTag, Properties::GridView>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
using SolidEnergyLawParams = GetPropType<TypeTag, Properties::SolidEnergyLawParams>;
using ThermalConductionLawParams = GetPropType<TypeTag, Properties::ThermalConductionLawParams>;
using MaterialLawParams = typename GetPropType<TypeTag, Properties::MaterialLaw>::Params;
using DirectionalMobilityPtr = Utility::CopyablePtr<DirectionalMobility<TypeTag>>;
enum { dimWorld = GridView::dimensionworld };
enum { numPhases = getPropValue<TypeTag, Properties::NumPhases>() };
using DimVector = Dune::FieldVector<Scalar, dimWorld>;
using DimMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
public:
explicit MultiPhaseBaseProblem(Simulator& simulator)
: ParentType(simulator)
{ init_(); }
static void registerParameters()
{
ParentType::registerParameters();
Parameters::Register<Parameters::EnableGravity>
("Use the gravity correction for the pressure gradients.");
}
template <class Context>
void intersectionIntrinsicPermeability(DimMatrix& result,
const Context& context,
unsigned intersectionIdx,
unsigned timeIdx) const
{
const auto& scvf = context.stencil(timeIdx).interiorFace(intersectionIdx);
const DimMatrix& K1 = asImp_().intrinsicPermeability(context, scvf.interiorIndex(), timeIdx);
const DimMatrix& K2 = asImp_().intrinsicPermeability(context, scvf.exteriorIndex(), timeIdx);
// entry-wise harmonic mean. this is almost certainly wrong if
// you have off-main diagonal entries in your permeabilities!
for (unsigned i = 0; i < dimWorld; ++i) {
for (unsigned j = 0; j < dimWorld; ++j) {
result[i][j] = harmonicMean(K1[i][j], K2[i][j]);
}
}
}
// \{
template <class Context>
const DimMatrix& intrinsicPermeability(const Context&,
unsigned,
unsigned) const
{
throw std::logic_error("Not implemented: Problem::intrinsicPermeability()");
}
template <class Context>
Scalar porosity(const Context&,
unsigned,
unsigned) const
{
throw std::logic_error("Not implemented: Problem::porosity()");
}
template <class Context>
const SolidEnergyLawParams&
solidEnergyParams(const Context&,
unsigned,
unsigned) const
{
throw std::logic_error("Not implemented: Problem::solidEnergyParams()");
}
template <class Context>
const ThermalConductionLawParams&
thermalConductionParams(const Context&,
unsigned,
unsigned) const
{
throw std::logic_error("Not implemented: Problem::thermalConductionParams()");
}
template <class Context>
Scalar tortuosity(const Context&,
unsigned,
unsigned) const
{
throw std::logic_error("Not implemented: Problem::tortuosity()");
}
template <class Context>
Scalar dispersivity(const Context&,
unsigned,
unsigned) const
{
throw std::logic_error("Not implemented: Problem::dispersivity()");
}
template <class Context>
const MaterialLawParams &
materialLawParams(const Context&,
unsigned,
unsigned) const
{
static MaterialLawParams dummy;
return dummy;
}
template <class FluidState>
void updateRelperms([[maybe_unused]] std::array<Evaluation,numPhases>& mobility,
[[maybe_unused]] DirectionalMobilityPtr& dirMob,
[[maybe_unused]] FluidState& fluidState,
[[maybe_unused]] unsigned globalSpaceIdx) const
{}
template <class Context>
Scalar temperature(const Context&,
unsigned,
unsigned) const
{ return asImp_().temperature(); }
Scalar temperature() const
{ throw std::logic_error("Not implemented:temperature() method not implemented by the actual problem"); }
template <class Context>
const DimVector& gravity(const Context&,
unsigned,
unsigned) const
{ return asImp_().gravity(); }
const DimVector& gravity() const
{ return gravity_; }
unsigned markForGridAdaptation()
{
using Toolbox = MathToolbox<Evaluation>;
unsigned numMarked = 0;
ElementContext elemCtx( this->simulator() );
auto gridView = this->simulator().vanguard().gridView();
auto& grid = this->simulator().vanguard().grid();
for (const auto& element : elements(gridView, Dune::Partitions::interior)) {
elemCtx.updateAll(element);
// HACK: this should better be part of an AdaptionCriterion class
for (unsigned phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx) {
Scalar minSat = 1e100 ;
Scalar maxSat = -1e100;
size_t nDofs = elemCtx.numDof(/*timeIdx=*/0);
for (unsigned dofIdx = 0; dofIdx < nDofs; ++dofIdx) {
const auto& intQuant = elemCtx.intensiveQuantities( dofIdx, /*timeIdx=*/0);
minSat = std::min(minSat,
Toolbox::value(intQuant.fluidState().saturation(phaseIdx)));
maxSat = std::max(maxSat,
Toolbox::value(intQuant.fluidState().saturation(phaseIdx)));
}
const Scalar indicator =
(maxSat - minSat) / (std::max<Scalar>(0.01, maxSat + minSat) / 2);
if (indicator > 0.2 && element.level() < 2) {
grid.mark(1, element);
++numMarked;
}
else if (indicator < 0.025) {
grid.mark(-1, element);
++numMarked;
}
else {
grid.mark(0, element);
}
}
}
// get global sum so that every proc is on the same page
return this->simulator().vanguard().grid().comm().sum(numMarked);
}
// \}
protected:
DimMatrix toDimMatrix_(Scalar val) const
{
DimMatrix ret(0.0);
for (unsigned i = 0; i < DimMatrix::rows; ++i) {
ret[i][i] = val;
}
return ret;
}
DimVector gravity_;
private:
Implementation& asImp_()
{ return *static_cast<Implementation *>(this); }
const Implementation& asImp_() const
{ return *static_cast<const Implementation *>(this); }
void init_()
{
gravity_ = 0.0;
if (Parameters::Get<Parameters::EnableGravity>()) {
gravity_[dimWorld-1] = -9.81;
}
}
};
} // namespace Opm
#endif
Opm::FvBaseProblem::simulator
Simulator & simulator()
Returns Simulator object used by the simulation.
Definition fvbaseproblem.hh:692
Opm::FvBaseProblem::gridView
const GridView & gridView() const
The GridView which used by the problem.
Definition fvbaseproblem.hh:660
Opm::MultiPhaseBaseProblem::intersectionIntrinsicPermeability
void intersectionIntrinsicPermeability(DimMatrix &result, const Context &context, unsigned intersectionIdx, unsigned timeIdx) const
Returns the intrinsic permeability of an intersection.
Definition multiphasebaseproblem.hh:116
Opm::MultiPhaseBaseProblem::thermalConductionParams
const ThermalConductionLawParams & thermalConductionParams(const Context &, unsigned, unsigned) const
Returns the parameter object for the thermal conductivity law in a sub-control volume.
Definition multiphasebaseproblem.hh:202
Opm::MultiPhaseBaseProblem::materialLawParams
const MaterialLawParams & materialLawParams(const Context &, unsigned, unsigned) const
Returns the material law parameters within a control volume.
Definition multiphasebaseproblem.hh:256
Opm::MultiPhaseBaseProblem::toDimMatrix_
DimMatrix toDimMatrix_(Scalar val) const
Converts a Scalar value to an isotropic Tensor.
Definition multiphasebaseproblem.hh:384
Opm::MultiPhaseBaseProblem::temperature
Scalar temperature() const
Returns the temperature for an isothermal problem.
Definition multiphasebaseproblem.hh:292
Opm::MultiPhaseBaseProblem::tortuosity
Scalar tortuosity(const Context &, unsigned, unsigned) const
Define the tortuosity.
Definition multiphasebaseproblem.hh:218
Opm::MultiPhaseBaseProblem::temperature
Scalar temperature(const Context &, unsigned, unsigned) const
Returns the temperature within a control volume.
Definition multiphasebaseproblem.hh:280
Opm::MultiPhaseBaseProblem::gravity
const DimVector & gravity() const
Returns the acceleration due to gravity .
Definition multiphasebaseproblem.hh:319
Opm::MultiPhaseBaseProblem::gravity
const DimVector & gravity(const Context &, unsigned, unsigned) const
Returns the acceleration due to gravity .
Definition multiphasebaseproblem.hh:305
Opm::MultiPhaseBaseProblem::porosity
Scalar porosity(const Context &, unsigned, unsigned) const
Returns the porosity [] of the porous medium for a given control volume.
Definition multiphasebaseproblem.hh:166
Opm::MultiPhaseBaseProblem::MultiPhaseBaseProblem
MultiPhaseBaseProblem(Simulator &simulator)
Definition multiphasebaseproblem.hh:91
Opm::MultiPhaseBaseProblem::solidEnergyParams
const SolidEnergyLawParams & solidEnergyParams(const Context &, unsigned, unsigned) const
Returns the parameter object for the energy storage law of the solid in a sub-control volume.
Definition multiphasebaseproblem.hh:184
Opm::MultiPhaseBaseProblem::dispersivity
Scalar dispersivity(const Context &, unsigned, unsigned) const
Define the dispersivity.
Definition multiphasebaseproblem.hh:234
Opm::MultiPhaseBaseProblem::intrinsicPermeability
const DimMatrix & intrinsicPermeability(const Context &, unsigned, unsigned) const
Returns the intrinsic permeability tensor at a given position.
Definition multiphasebaseproblem.hh:149
Opm::MultiPhaseBaseProblem::markForGridAdaptation
unsigned markForGridAdaptation()
Mark grid cells for refinement or coarsening.
Definition multiphasebaseproblem.hh:327
Opm::MultiPhaseBaseProblem::registerParameters
static void registerParameters()
Register all run-time parameters for the problem and the model.
Definition multiphasebaseproblem.hh:98
directionalmobility.hh
This file contains definitions related to directional mobilities.
fvbaseproblem.hh
Base class for all problems which use a finite volume spatial discretization.
fvbaseproperties.hh
Declare the properties used by the infrastructure code of the finite volume discretizations.
multiphasebaseparameters.hh
Defines the common parameters for the porous medium multi-phase models.
multiphasebaseproperties.hh
Defines the common properties required by the porous medium multi-phase models.
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::GetPropType
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition propertysystem.hh:233
Opm::getPropValue
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240
Opm::Parameters::Register
void Register(const char *usageString)
Register a run-time parameter.
Definition parametersystem.hpp:292