adding FluidSystem as a template parameter

for CompWellState and also SingleCompWellState.
This commit is contained in:
Kai Bao committed 2025-04-23 16:02:41 +02:00
1 parent 24779684cd
commit dd3441d9fe
11 files changed
+74 -69

No files matched your search

+14 -12
View File
@@ -51,6 +51,8 @@ public:
using VectorBlockType = Dune::FieldVector<Scalar, Indices::numEq>;
using BVector = Dune::BlockVector<VectorBlockType>;
using SingleWellState = typename Base::SingleWellState;
using CompConnectionData = PerforationData<Scalar>;
template <typename T>
@@ -91,28 +93,28 @@ public:
void init() override;
void calculateExplicitQuantities(const Simulator& simulator,
const SingleCompWellState<Scalar>& well_state) override;
const SingleWellState& well_state) override;
void updatePrimaryVariables(const Simulator& simulator,
const SingleCompWellState<Scalar>& well_state) override;
const SingleWellState& well_state) override;
void updateSecondaryQuantities(const Simulator& simulator);
// TODO: control should be passed in later
void assembleWellEq(const Simulator& simulator,
const SingleCompWellState<Scalar>& well_state,
const SingleWellState& well_state,
const double dt);
bool iterateWellEq(const Simulator& simulator,
const Scalar dt,
SingleCompWellState<Scalar>& well_state) override;
SingleWellState& well_state) override;
void solveEqAndUpdateWellState(SingleCompWellState<Scalar>& well_state);
void solveEqAndUpdateWellState(SingleWellState& well_state);
void apply(BVector& r) const override;
void recoverWellSolutionAndUpdateWellState(const BVector& x,
SingleCompWellState<Scalar>& well_state) override;
SingleWellState& well_state) override;
bool getConvergence() const override;
@@ -155,27 +157,27 @@ private:
// TODO: the following assembling functions will be moved to a separate assmeble class
void assembleSourceTerm(const Scalar dt);
void assembleControlEq(const SingleCompWellState<Scalar>& well_state,
void assembleControlEq(const SingleWellState& well_state,
const SummaryState& summary_state);
void assembleControlEqProd(const SingleCompWellState<Scalar>& well_state,
void assembleControlEqProd(const SingleWellState& well_state,
const Well::ProductionControls& prod_controls,
EvalWell& control_eq) const;
void assembleControlEqInj(const SingleCompWellState<Scalar>& well_state,
void assembleControlEqInj(const SingleWellState& well_state,
const Well::InjectionControls& inj_controls,
EvalWell& control_eq) const;
void updatePrimaryVariablesNewton(const BVectorWell& dwells);
// with passing in the SurfaceCondition, we should be able to do this in the primary variable class
void updateWellStateFromPrimaryVariables(SingleCompWellState<Scalar>& well_state) const;
void updateWellStateFromPrimaryVariables(SingleWellState& well_state) const;
void updateWellState(const BVectorWell& dwells,
SingleCompWellState<Scalar>& well_state);
SingleWellState& well_state);
void updateWellControl(const SummaryState& summary_state,
SingleCompWellState<Scalar>& well_state) const;
SingleWellState& well_state) const;
template <typename T>
void
@@ -43,6 +43,7 @@ public:
using VectorBlockType = Dune::FieldVector<Scalar, Indices::numEq>;
using BVector = Dune::BlockVector<VectorBlockType>;
using CompConnectionData = PerforationData<Scalar>;
using SingleWellState = SingleCompWellState<FluidSystem, Scalar>;
CompWellInterface(const Well& well,
const int index_of_well,
@@ -55,14 +56,14 @@ public:
const std::string& name() const;
virtual void calculateExplicitQuantities(const Simulator& simulator,
const SingleCompWellState<Scalar>& well_state) = 0;
const SingleWellState& well_state) = 0;
virtual void updatePrimaryVariables(const Simulator& simulator,
const SingleCompWellState<Scalar>& well_state) = 0;
const SingleWellState& well_state) = 0;
virtual bool iterateWellEq(const Simulator& simulator,
const Scalar dt,
SingleCompWellState<Scalar>& well_state) = 0;
SingleWellState& well_state) = 0;
void addCellRates(RateVector& rates, unsigned cellIdx) const;
@@ -73,7 +74,7 @@ public:
/// using the solution x to recover the solution xw for wells and applying
/// xw to update Well State
virtual void recoverWellSolutionAndUpdateWellState(const BVector& x,
SingleCompWellState<Scalar>& well_state) = 0;
SingleWellState& well_state) = 0;
virtual bool getConvergence() const = 0;
virtual void addWellContributions(SparseMatrixAdapter&) const = 0;
@@ -28,7 +28,7 @@
namespace Opm {
template <typename Scalar>
template <typename FluidSystem, typename Scalar>
class SingleCompWellState;
template <typename FluidSystem, typename Indices>
@@ -56,6 +56,7 @@ public:
using Eval = DenseAd::Evaluation<Scalar, numResEq>;
using BVectorWell = typename CompWellEquations<Scalar, numWellEq, numResEq>::BVectorWell;
using SingleWellState = SingleCompWellState<FluidSystem, Scalar>;
template <typename T>
using FluidState = CompositionalFluidState<T, FluidSystem>;
@@ -63,7 +64,7 @@ public:
template <typename T>
FluidState<T> toFluidState() const;
void update(const SingleCompWellState<Scalar>& well_state);
void update(const SingleWellState& well_state);
void updateEvaluation();
@@ -27,7 +27,7 @@ namespace Opm {
template <typename FluidSystem, typename Indices>
void
CompWellPrimaryVariables<FluidSystem, Indices>::
update(const SingleCompWellState<Scalar>& well_state)
update(const SingleWellState& well_state)
{
value_[QTotal] = well_state.get_total_surface_rate();
// the mole fractions of the first n-1 component
@@ -35,11 +35,12 @@
namespace Opm {
template <typename Scalar>
template <typename FluidSystem, typename Scalar>
class CompWellState
{
public:
using CompConnectionData = PerforationData<Scalar>;
using SingleWellState = SingleCompWellState<FluidSystem, Scalar>;
CompWellState(const PhaseUsage& phase_usage,
const CompositionalConfig& comp_config);
@@ -52,14 +53,14 @@ public:
const SummaryState& sumary_state,
const CompWellState* prev_well_state = nullptr);
const SingleCompWellState<Scalar>& operator[](const std::string& well_name) const;
const SingleWellState& operator[](const std::string& well_name) const;
SingleCompWellState<Scalar>& operator[](const std::string& well_name);
SingleWellState& operator[](const std::string& well_name);
data::Wells report() const;
private:
WellContainer<SingleCompWellState<Scalar>> wells_;
WellContainer<SingleWellState> wells_;
const PhaseUsage& phase_usage_;
@@ -19,8 +19,8 @@
namespace Opm {
template <typename Scalar>
CompWellState<Scalar>::
template <typename FluidSystem, typename Scalar>
CompWellState<FluidSystem, Scalar>::
CompWellState(const PhaseUsage& phase_usage,
const CompositionalConfig& comp_config)
: phase_usage_(phase_usage)
@@ -29,8 +29,8 @@ CompWellState(const PhaseUsage& phase_usage,
}
template <typename Scalar>
void CompWellState<Scalar>::
template <typename FluidSystem, typename Scalar>
void CompWellState<FluidSystem, Scalar>::
init(const std::vector<Well>& wells_ecl,
const std::vector<Scalar>& cell_pressures,
const Scalar temperature,
@@ -45,8 +45,8 @@ init(const std::vector<Well>& wells_ecl,
// let us see how we gonna use it though
}
template <typename Scalar>
void CompWellState<Scalar>::
template <typename FluidSystem, typename Scalar>
void CompWellState<FluidSystem, Scalar>::
base_init(const std::vector<Well>& wells_ecl,
const std::vector<Scalar>& cell_pressures,
const Scalar temperature,
@@ -66,8 +66,8 @@ base_init(const std::vector<Well>& wells_ecl,
}
template <typename Scalar>
void CompWellState<Scalar>::
template <typename FluidSystem, typename Scalar>
void CompWellState<FluidSystem, Scalar>::
initSingleWell(const Well& well,
const std::vector<Scalar>& cell_pressures,
const Scalar tempearture,
@@ -83,8 +83,8 @@ initSingleWell(const Well& well,
}
template <typename Scalar>
void CompWellState<Scalar>::
template <typename FluidSystem, typename Scalar>
void CompWellState<FluidSystem, Scalar>::
initSingleInjector(const Well& well,
const std::vector<Scalar>& /* cell_pressures */,
const Scalar temperature,
@@ -92,7 +92,7 @@ initSingleInjector(const Well& well,
const SummaryState& summary_state)
{
auto& ws = this->wells_.add(well.name(),
SingleCompWellState<Scalar>(well.name(),
SingleWellState(well.name(),
this->comp_config_,
this->phase_usage_,
temperature,
@@ -101,8 +101,8 @@ initSingleInjector(const Well& well,
ws.update_injector_targets(well, summary_state);
}
template <typename Scalar>
void CompWellState<Scalar>::
template <typename FluidSystem, typename Scalar>
void CompWellState<FluidSystem, Scalar>::
initSingleProducer(const Well& well,
const std::vector<Scalar>& /* cell_pressures */,
const Scalar temperature,
@@ -111,7 +111,7 @@ initSingleProducer(const Well& well,
const SummaryState& summary_state)
{
auto& ws = this->wells_.add(well.name(),
SingleCompWellState<Scalar>(well.name(),
SingleWellState(well.name(),
this->comp_config_,
this->phase_usage_,
temperature,
@@ -120,25 +120,25 @@ initSingleProducer(const Well& well,
ws.update_producer_targets(well, cell_mole_fractions, summary_state);
}
template <typename Scalar>
const SingleCompWellState<Scalar>&
CompWellState<Scalar>::
template <typename FluidSystem, typename Scalar>
const typename CompWellState<FluidSystem, Scalar>::SingleWellState&
CompWellState<FluidSystem, Scalar>::
operator[](const std::string& well_name) const
{
return this->wells_[well_name];
}
template <typename Scalar>
SingleCompWellState<Scalar>&
CompWellState<Scalar>::
template <typename FluidSystem, typename Scalar>
typename CompWellState<FluidSystem, Scalar>::SingleWellState&
CompWellState<FluidSystem, Scalar>::
operator[](const std::string& well_name)
{
return this->wells_[well_name];
}
template <typename Scalar>
template <typename FluidSystem, typename Scalar>
data::Wells
CompWellState<Scalar>::
CompWellState<FluidSystem, Scalar>::
report() const
{
if (this->wells_.empty()) {
+12 -12
View File
@@ -49,7 +49,7 @@ template <typename TypeTag>
void
CompWell<TypeTag>::
calculateExplicitQuantities(const Simulator& simulator,
const SingleCompWellState<Scalar>& well_state)
const SingleWellState& well_state)
{
updatePrimaryVariables(simulator, well_state);
{
@@ -82,7 +82,7 @@ template <typename TypeTag>
void
CompWell<TypeTag>::
updatePrimaryVariables(const Simulator& /* simulator */,
const SingleCompWellState<Scalar>& well_state)
const SingleWellState& well_state)
{
this->primary_variables_.update(well_state);
}
@@ -227,7 +227,7 @@ template <typename TypeTag>
void
CompWell<TypeTag>::
assembleWellEq(const Simulator& simulator,
const SingleCompWellState<Scalar>& well_state,
const SingleWellState& well_state,
const double dt)
{
this->well_equations_.clear();
@@ -273,7 +273,7 @@ assembleWellEq(const Simulator& simulator,
template <typename TypeTag>
void
CompWell<TypeTag>::
assembleControlEq(const SingleCompWellState<Scalar>& well_state,
assembleControlEq(const SingleWellState& well_state,
const SummaryState& summary_state)
{
EvalWell control_eq;
@@ -294,7 +294,7 @@ assembleControlEq(const SingleCompWellState<Scalar>& well_state,
template <typename TypeTag>
void
CompWell<TypeTag>::
assembleControlEqProd(const SingleCompWellState<Scalar>& well_state,
assembleControlEqProd(const SingleWellState& well_state,
const Well::ProductionControls& prod_controls,
EvalWell& control_eq) const
{
@@ -331,7 +331,7 @@ assembleControlEqProd(const SingleCompWellState<Scalar>& well_state,
template <typename TypeTag>
void
CompWell<TypeTag>::
assembleControlEqInj(const SingleCompWellState<Scalar>& well_state,
assembleControlEqInj(const SingleWellState& well_state,
const Well::InjectionControls& inj_controls,
EvalWell& control_eq) const
{
@@ -385,7 +385,7 @@ bool
CompWell<TypeTag>::
iterateWellEq(const Simulator& simulator,
const Scalar dt,
SingleCompWellState<Scalar>& well_state)
SingleWellState& well_state)
{
constexpr int max_iter = 200;
@@ -414,7 +414,7 @@ iterateWellEq(const Simulator& simulator,
template <typename TypeTag>
void
CompWell<TypeTag>::
solveEqAndUpdateWellState(SingleCompWellState<Scalar>& well_state)
solveEqAndUpdateWellState(SingleWellState& well_state)
{
BVectorWell dx_well(1);
@@ -435,7 +435,7 @@ template <typename TypeTag>
void
CompWell<TypeTag>::
recoverWellSolutionAndUpdateWellState(const BVector& x,
SingleCompWellState<Scalar>& well_state)
SingleWellState& well_state)
{
BVectorWell xw(1);
@@ -456,7 +456,7 @@ template <typename TypeTag>
void
CompWell<TypeTag>::
updateWellState(const CompWell::BVectorWell& xw,
SingleCompWellState<Scalar>& well_state)
SingleWellState& well_state)
{
updatePrimaryVariablesNewton(xw);
updateWellStateFromPrimaryVariables(well_state);
@@ -465,7 +465,7 @@ updateWellState(const CompWell::BVectorWell& xw,
template <typename TypeTag>
void
CompWell<TypeTag>::
updateWellStateFromPrimaryVariables(SingleCompWellState<Scalar>& well_state) const
updateWellStateFromPrimaryVariables(SingleWellState& well_state) const
{
well_state.bhp = this->primary_variables_.getBhp().value();
@@ -511,7 +511,7 @@ template <typename TypeTag>
void
CompWell<TypeTag>::
updateWellControl(const SummaryState& summary_state,
SingleCompWellState<Scalar>& well_state) const
SingleWellState& well_state) const
{
std::string from;
if (this->well_ecl_.isInjector()) {
@@ -147,7 +147,7 @@ private:
const CompositionalConfig& comp_config_;
// we will need two to handle the changes between time stepping
CompWellState<Scalar> comp_well_states_;
CompWellState<FluidSystem, Scalar> comp_well_states_;
// this is needed for parallel running, not all the wells will be in the same process
std::vector<Well> wells_ecl_;
@@ -146,10 +146,10 @@ initWellState()
// TODO: not sure the following is correct
const auto pressIx = [this]()
{
if (phase_usage_.phase_used[FluidSystem::oilPhaseIdx]) {
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) ) {
return FluidSystem::oilPhaseIdx;
}
if (phase_usage_.phase_used[FluidSystem::gasPhaseIdx]) {
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) ) {
return FluidSystem::gasPhaseIdx;
}
assert(false && "the usage of oil and gas phase is not correct");
@@ -53,7 +53,7 @@ public:
std::vector<std::size_t> ecl_index {};
};
template <typename Scalar>
template <typename FluidSystem, typename Scalar>
class SingleCompWellState
{
public:
@@ -49,8 +49,8 @@ CompConnectionData(const std::vector<PerforationData<Scalar>>& connections,
}
}
template <class Scalar>
SingleCompWellState<Scalar>::
template <typename FluidSystem, class Scalar>
SingleCompWellState<FluidSystem, Scalar>::
SingleCompWellState(const std::string& well_name,
const CompositionalConfig& comp_config,
const PhaseUsage& phase_usage_input,
@@ -69,8 +69,8 @@ SingleCompWellState(const std::string& well_name,
{
}
template <typename Scalar>
void SingleCompWellState<Scalar>::
template <typename FluidSystem, class Scalar>
void SingleCompWellState<FluidSystem, Scalar>::
update_injector_targets(const Well& well,
const SummaryState& st)
{
@@ -115,8 +115,8 @@ update_injector_targets(const Well& well,
}
}
template <typename Scalar>
void SingleCompWellState<Scalar>::
template <typename FluidSystem, class Scalar>
void SingleCompWellState<FluidSystem, Scalar>::
update_producer_targets(const Well& well,
const std::vector<std::vector<Scalar>>& cell_mole_fractions,
const SummaryState& st)
@@ -149,9 +149,9 @@ update_producer_targets(const Well& well,
}
}
template <typename Scalar>
template <typename FluidSystem, class Scalar>
Scalar
SingleCompWellState<Scalar>::
SingleCompWellState<FluidSystem, Scalar>::
get_total_surface_rate() const
{
return std::accumulate(surface_phase_rates.begin(), surface_phase_rates.end(), Scalar(0));