20 #ifndef OPM_COMP_WELL_PRIMARY_VARIABLES_IMPL_HPP 21 #define OPM_COMP_WELL_PRIMARY_VARIABLES_IMPL_HPP 23 #include <flowexperimental/comp/wells/SingleCompWellState.hpp> 29 template <
typename Flu
idSystem,
typename Indices>
31 CompWellPrimaryVariables<FluidSystem, Indices>::
32 update(
const SingleWellState& well_state)
34 value_[QTotal] = well_state.get_total_surface_rate();
36 std::vector<Scalar> mole_fractions(FluidSystem::numComponents, 0.);
37 Scalar sum_mole_fraction = 0.;
38 for (
int i = 0; i < FluidSystem::numComponents; ++i) {
39 mole_fractions[i] = std::max(well_state.total_molar_fractions[i], 1.e-10);
40 sum_mole_fraction += mole_fractions[i];
42 assert(sum_mole_fraction != 0.);
43 for (
int i = 0; i < numWellConservationEq - 1; ++i) {
44 value_[i + 1] = mole_fractions[i] / sum_mole_fraction;
46 value_[Bhp] = well_state.bhp;
48 temperature_ = well_state.temperature;
53 template <
typename Flu
idSystem,
typename Indices>
55 CompWellPrimaryVariables<FluidSystem, Indices>::
58 for (std::size_t idx = 0; idx < numWellEq; ++idx) {
59 evaluation_[idx] = 0.;
60 evaluation_[idx].setValue(value_[idx]);
61 evaluation_[idx].setDerivative(idx + numResEq, 1.);
65 template <
typename Flu
idSystem,
typename Indices>
66 typename CompWellPrimaryVariables<FluidSystem, Indices>::EvalWell
67 CompWellPrimaryVariables<FluidSystem, Indices>::
70 return evaluation_[Bhp];
73 template <
typename Flu
idSystem,
typename Indices>
74 typename CompWellPrimaryVariables<FluidSystem, Indices>::EvalWell
75 CompWellPrimaryVariables<FluidSystem, Indices>::
78 return evaluation_[QTotal];
81 template <
typename Flu
idSystem,
typename Indices>
82 typename CompWellPrimaryVariables<FluidSystem, Indices>::EvalWell
83 CompWellPrimaryVariables<FluidSystem, Indices>::
84 extendEval(
const Eval& in)
87 out.setValue(in.value());
88 for(
int eq_idx = 0; eq_idx < Indices::numEq;++eq_idx) {
89 out.setDerivative(eq_idx, in.derivative(eq_idx));
94 template <
typename Flu
idSystem,
typename Indices>
95 typename CompWellPrimaryVariables<FluidSystem, Indices>::Eval
96 CompWellPrimaryVariables<FluidSystem, Indices>::
97 restrictEval(
const EvalWell& in)
100 out.setValue(in.value());
101 for(
int eq_idx = 0; eq_idx < Indices::numEq;++eq_idx) {
102 out.setDerivative(eq_idx, in.derivative(eq_idx));
107 template <
typename Flu
idSystem,
typename Indices>
109 CompWellPrimaryVariables<FluidSystem, Indices>::
110 updateNewton(
const BVectorWell& dwells)
112 constexpr Scalar damping = 1.0;
114 for (
unsigned i = 0; i < value_.size(); ++i) {
115 value_[i] -= damping * dwells[0][i];
121 std::vector<Scalar> mole_fractions(FluidSystem::numComponents, 0.);
122 Scalar sum_mole_fraction = 0.;
123 for (
int i = 0; i < FluidSystem::numComponents - 1; ++i) {
124 value_[i + 1] = std::clamp(value_[i + 1], 1.e-10, 1.);
125 mole_fractions[i] = value_[i + 1];
126 sum_mole_fraction += mole_fractions[i];
128 mole_fractions[FluidSystem::numComponents - 1] = std::max(1.0 - sum_mole_fraction, 1.e-10);
129 sum_mole_fraction += mole_fractions[FluidSystem::numComponents - 1];
130 assert(sum_mole_fraction != 0.);
131 for (
int i = 0; i < FluidSystem::numComponents - 1; ++i) {
132 value_[i + 1] = mole_fractions[i] / sum_mole_fraction;
138 template <
typename Flu
idSystem,
typename Indices>
139 template <
typename T>
141 CompWellPrimaryVariables<FluidSystem, Indices>::
142 getValue_(
int index)
const 144 static_assert(std::is_same_v<T, Scalar> || std::is_same_v<T, EvalWell>,
"Unsupported type in CompWellPrimaryVariables::getValue_");
146 if constexpr (std::is_same_v<T, Scalar>) {
147 return value_[index];
149 return evaluation_[index];
153 template <
typename Flu
idSystem,
typename Indices>
154 template <
typename T>
155 typename CompWellPrimaryVariables<FluidSystem, Indices>::template FluidState<T>
156 CompWellPrimaryVariables<FluidSystem, Indices>::
159 static_assert(std::is_same_v<T, Scalar> || std::is_same_v<T, EvalWell>,
"Unsupported type in CompWellPrimaryVariables::toFluidState");
161 CompositionalFluidState<T, FluidSystem> fluid_state;
162 const auto& pressure = getValue_<T>(Bhp);
163 std::array<T, FluidSystem::numComponents> total_molar_fractions;
165 for (
int i = 0; i < FluidSystem::numComponents - 1; ++i) {
166 total_molar_fractions[i] = getValue_<T>(i + 1);
167 sum += total_molar_fractions[i];
169 total_molar_fractions[FluidSystem::numComponents - 1] = 1.0 - sum;
171 for (
int i = 0; i < FluidSystem::numComponents; ++i) {
172 if constexpr (std::is_same_v<T, EvalWell>) {
173 total_molar_fractions[i].setValue(std::max(getValue(total_molar_fractions[i]), 1.e-10));
175 total_molar_fractions[i] = std::max(total_molar_fractions[i], 1.e-10);
177 fluid_state.setMoleFraction(i, total_molar_fractions[i]);
180 fluid_state.setPressure(FluidSystem::oilPhaseIdx, pressure);
181 fluid_state.setPressure(FluidSystem::gasPhaseIdx, pressure);
183 fluid_state.setTemperature(temperature_);
185 for (
int i = 0; i < FluidSystem::numComponents; ++i) {
186 fluid_state.setKvalue(i, fluid_state.wilsonK_(i));
189 fluid_state.setLvalue(-1.);
196 #endif // OPM_COMP_WELL_PRIMARY_VARIABLES_IMPL_HPP Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45