Loading...
Searching...
No Matches
MultisegmentWellPrimaryVariables.hpp
/*
Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
Copyright 2017 Statoil ASA.
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/>.
*/
#ifndef OPM_MULTISEGMENTWELL_PRIMARY_VARIABLES_HEADER_INCLUDED
#define OPM_MULTISEGMENTWELL_PRIMARY_VARIABLES_HEADER_INCLUDED
#include <opm/material/densead/Evaluation.hpp>
#include <opm/simulators/wells/MultisegmentWellEquations.hpp>
#include <opm/input/eclipse/Schedule/SummaryState.hpp>
#include <opm/input/eclipse/Units/Units.hpp>
#include <array>
#include <cstddef>
#include <vector>
namespace Opm
{
class DeferredLogger;
template <typename Scalar, typename IndexTraits> class MultisegmentWellGeneric;
template<class FluidSystem, class Indices> class WellInterfaceIndices;
template<typename Scalar, typename IndexTraits> class WellState;
template<class FluidSystem, class Indices>
class MultisegmentWellPrimaryVariables
{
public:
// TODO: for now, not considering the polymer, solvent and so on to simplify the development process.
// TODO: we need to have order for the primary variables and also the order for the well equations.
// sometimes, they are similar, while sometimes, they can have very different forms.
// Table showing the primary variable indices, depending on what phases are present:
//
// WOG OG WG WO W/O/G (single phase)
// WQTotal 0 0 0 0 0
// WFrac 1 -1000 -1000 1 -1000
// GFrac 2 1 1 -1000 -1000
// Spres 3 2 2 2 1
static constexpr bool has_wfrac_variable = Indices::waterEnabled && Indices::oilEnabled;
static constexpr bool has_gfrac_variable = Indices::gasEnabled && Indices::numPhases > 1;
static constexpr int WQTotal = 0;
static constexpr int WFrac = has_wfrac_variable ? 1 : -1000;
static constexpr int GFrac = has_gfrac_variable ? has_wfrac_variable + 1 : -1000;
static constexpr int SPres = has_wfrac_variable + has_gfrac_variable + 1;
// the number of well equations TODO: it should have a more general strategy for it
static constexpr int numWellEq = Indices::numPhases + 1;
using Scalar = typename FluidSystem::Scalar;
using IndexTraits = typename FluidSystem::IndexTraitsType;
using EvalWell = DenseAd::Evaluation<Scalar, /*size=*/Indices::numEq + numWellEq>;
using Equations = MultisegmentWellEquations<Scalar,IndexTraits,numWellEq,Indices::numEq>;
using BVectorWell = typename Equations::BVectorWell;
explicit MultisegmentWellPrimaryVariables(const WellInterfaceIndices<FluidSystem,Indices>& well)
: well_(well)
{}
void resize(const int numSegments);
void update(const WellState<Scalar, IndexTraits>& well_state,
const bool stop_or_zero_rate_target);
void updateNewton(const BVectorWell& dwells,
const Scalar relaxation_factor,
const Scalar DFLimit,
const bool stop_or_zero_rate_target,
const Scalar max_pressure_change);
void copyToWellState(const MultisegmentWellGeneric<Scalar, IndexTraits>& mswell,
const Scalar rho,
WellState<Scalar, IndexTraits>& well_state,
const SummaryState& summary_state,
DeferredLogger& deferred_logger) const;
EvalWell volumeFractionScaled(const int seg,
const int compIdx) const;
EvalWell surfaceVolumeFraction(const int seg,
const int compIdx) const;
EvalWell getSegmentRateUpwinding(const int seg,
const int seg_upwind,
const int comp_idx) const;
EvalWell getBhp() const;
EvalWell getSegmentPressure(const int seg) const;
EvalWell getSegmentRate(const int seg,
const int comp_idx) const;
EvalWell getQs(const int comp_idx) const;
EvalWell getWQTotal() const;
const std::array<EvalWell, numWellEq>& eval(const int idx) const
{ return evaluation_[idx]; }
const std::array<Scalar, numWellEq>& value(const int idx) const
{ return value_[idx]; }
void setValue(const int idx, const std::array<Scalar, numWellEq>& val)
{ value_[idx] = val; }
void outputLowLimitPressureSegments(DeferredLogger& deferred_logger) const;
private:
void setEvaluationsFromValues();
void processFractions(const int seg);
EvalWell volumeFraction(const int seg,
const int compIdx) const;
std::vector<std::array<Scalar, numWellEq>> value_;
std::vector<std::array<EvalWell, numWellEq>> evaluation_;
const WellInterfaceIndices<FluidSystem,Indices>& well_;
static constexpr double bhp_lower_limit = 1. * unit::barsa - 1. * unit::Pascal;
static constexpr double seg_pres_lower_limit = 0.;
};
}
#endif // OPM_MULTISEGMENTWELL_PRIMARY_VARIABLES_HEADER_INCLUDED
Opm::DeferredLogger
Definition DeferredLogger.hpp:57
Opm::MultisegmentWellEquations
Definition MultisegmentWellEquations.hpp:52
Opm::MultisegmentWellGeneric
Definition MultisegmentWellGeneric.hpp:39
Opm::MultisegmentWellPrimaryVariables::resize
void resize(const int numSegments)
Resize values and evaluations.
Definition MultisegmentWellPrimaryVariables.cpp:49
Opm::MultisegmentWellPrimaryVariables::copyToWellState
void copyToWellState(const MultisegmentWellGeneric< Scalar, IndexTraits > &mswell, const Scalar rho, WellState< Scalar, IndexTraits > &well_state, const SummaryState &summary_state, DeferredLogger &deferred_logger) const
Copy values to well state.
Definition MultisegmentWellPrimaryVariables.cpp:222
Opm::MultisegmentWellPrimaryVariables::update
void update(const WellState< Scalar, IndexTraits > &well_state, const bool stop_or_zero_rate_target)
Copy values from well state.
Definition MultisegmentWellPrimaryVariables.cpp:70
Opm::MultisegmentWellPrimaryVariables::volumeFractionScaled
EvalWell volumeFractionScaled(const int seg, const int compIdx) const
Returns scaled volume fraction for a component in a segment.
Definition MultisegmentWellPrimaryVariables.cpp:573
Opm::MultisegmentWellPrimaryVariables::outputLowLimitPressureSegments
void outputLowLimitPressureSegments(DeferredLogger &deferred_logger) const
output the segments with pressure close to lower pressure limit for debugging purpose
Definition MultisegmentWellPrimaryVariables.cpp:687
Opm::MultisegmentWellPrimaryVariables::getSegmentRate
EvalWell getSegmentRate(const int seg, const int comp_idx) const
Get rate for a component in a segment.
Definition MultisegmentWellPrimaryVariables.cpp:662
Opm::MultisegmentWellPrimaryVariables::getSegmentRateUpwinding
EvalWell getSegmentRateUpwinding(const int seg, const int seg_upwind, const int comp_idx) const
Returns upwinding rate for a component in a segment.
Definition MultisegmentWellPrimaryVariables.cpp:606
Opm::MultisegmentWellPrimaryVariables::getWQTotal
EvalWell getWQTotal() const
Get WQTotal.
Definition MultisegmentWellPrimaryVariables.cpp:679
Opm::MultisegmentWellPrimaryVariables::eval
const std::array< EvalWell, numWellEq > & eval(const int idx) const
Returns a const ref to an array of evaluations.
Definition MultisegmentWellPrimaryVariables.hpp:135
Opm::MultisegmentWellPrimaryVariables::getBhp
EvalWell getBhp() const
Get bottomhole pressure.
Definition MultisegmentWellPrimaryVariables.cpp:654
Opm::MultisegmentWellPrimaryVariables::surfaceVolumeFraction
EvalWell surfaceVolumeFraction(const int seg, const int compIdx) const
Returns surface volume fraction for a component in a segment.
Definition MultisegmentWellPrimaryVariables.cpp:590
Opm::MultisegmentWellPrimaryVariables::setValue
void setValue(const int idx, const std::array< Scalar, numWellEq > &val)
Set a value array. Note that this does not also set the corresponding evaluation.
Definition MultisegmentWellPrimaryVariables.hpp:143
Opm::MultisegmentWellPrimaryVariables::getQs
EvalWell getQs(const int comp_idx) const
Returns scaled rate for a component.
Definition MultisegmentWellPrimaryVariables.cpp:671
Opm::MultisegmentWellPrimaryVariables::getSegmentPressure
EvalWell getSegmentPressure(const int seg) const
Get pressure for a segment.
Definition MultisegmentWellPrimaryVariables.cpp:646
Opm::MultisegmentWellPrimaryVariables::updateNewton
void updateNewton(const BVectorWell &dwells, const Scalar relaxation_factor, const Scalar DFLimit, const bool stop_or_zero_rate_target, const Scalar max_pressure_change)
Update values from newton update vector.
Definition MultisegmentWellPrimaryVariables.cpp:165
Opm::MultisegmentWellPrimaryVariables::value
const std::array< Scalar, numWellEq > & value(const int idx) const
Returns a value array.
Definition MultisegmentWellPrimaryVariables.hpp:139
Opm::WellInterfaceIndices
Definition WellInterfaceIndices.hpp:34
Opm::WellState
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition WellState.hpp:66
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43