22 double const t,
double const dt, std::vector<double>
const& local_x,
23 std::vector<double>
const& local_x_prev, std::vector<double>& local_M_data,
24 std::vector<double>& local_K_data, std::vector<double>& local_b_data)
26 auto const local_matrix_size = local_x.size();
28 assert(local_matrix_size == ShapeFunction::NPOINTS *
NUM_NODAL_DOF);
31 local_M_data, local_matrix_size, local_matrix_size);
33 local_K_data, local_matrix_size, local_matrix_size);
35 local_b_data, local_matrix_size);
38 auto Mvv = local_M.template block<velocity_size, velocity_size>(
41 auto Mhp = local_M.template block<enthalpy_size, pressure_size>(
43 auto Mhh = local_M.template block<enthalpy_size, enthalpy_size>(
46 auto Kpv = local_K.template block<pressure_size, velocity_size>(
49 auto Kvp = local_K.template block<velocity_size, pressure_size>(
51 auto Kvv = local_K.template block<velocity_size, velocity_size>(
54 auto Khh = local_K.template block<enthalpy_size, enthalpy_size>(
61 unsigned const n_integration_points =
73 auto const& liquid_phase = medium.phase(
"AqueousLiquid");
74 auto const& gas_phase = medium.phase(
"Gas");
78 auto const t_ca =
_process_data.wellbore.casing_thickness(t, pos)[0];
80 auto const r_w =
_process_data.wellbore.diameter(t, pos)[0] / 2;
83 auto const t_p =
_process_data.wellbore.pipe_thickness(t, pos)[0];
88 auto const r_o = r_w - t_ca;
90 auto const r_i = r_o - t_p;
94 _process_data.reservoir_properties.temperature.getNodalValuesOnElement(
97 _process_data.reservoir_properties.pressure.getNodalValuesOnElement(
102 _process_data.reservoir_properties.thermal_conductivity(t, pos)[0];
103 auto const rho_r =
_process_data.reservoir_properties.density(t, pos)[0];
105 _process_data.reservoir_properties.specific_heat_capacity(t, pos)[0];
107 for (
unsigned ip(0); ip < n_integration_points; ip++)
110 auto const& N = ip_data.N;
111 auto const& dNdx = ip_data.dNdx;
112 auto const& w = ip_data.integration_weight;
113 auto& mix_density = ip_data.mix_density;
114 auto& temperature = ip_data.temperature;
115 auto& steam_mass_frac = ip_data.dryness;
116 auto& vapor_volume_frac = ip_data.vapor_volume_fraction;
117 auto& vapor_mass_flowrate = ip_data.vapor_mass_flow_rate;
118 auto& liquid_mass_flowrate = ip_data.liquid_mass_flow_rate;
126 double p_int_pt = 0.0;
127 double v_int_pt = 0.0;
128 double h_int_pt = 0.0;
133 double p_prev_int_pt = 0.0;
134 double v_prev_int_pt = 0.0;
135 double h_prev_int_pt = 0.0;
138 v_prev_int_pt, h_prev_int_pt);
140 double vdot_int_pt = (v_int_pt - v_prev_int_pt) / dt;
144 const double pi = std::numbers::pi;
149 double liquid_water_density =
152 .template value<double>(vars, pos, t, dt);
153 double const vapour_water_density =
156 .template value<double>(vars, pos, t, dt);
158 double const h_sat_liq_w =
162 .template value<double>(vars, pos, t, dt);
163 double const h_sat_vap_w =
167 .template value<double>(vars, pos, t, dt);
171 double const dryness = std::max(
172 0., (h_int_pt - h_sat_liq_w) / (h_sat_vap_w - h_sat_liq_w));
173 steam_mass_frac = dryness;
175 double const T_int_pt =
179 .template value<double>(vars, pos, t, dt)
182 saturation_temperature)
183 .template value<double>(vars, pos, t, dt);
184 temperature = T_int_pt;
193 double C_0 = 1 + 0.12 * (1 - dryness);
199 double const sigma_gl = 0.2358 *
200 std::pow((1 - T_int_pt / 647.096), 1.256) *
201 (1 - 0.625 * (1 - T_int_pt / 647.096));
204 1.18 * (1 - dryness) *
205 std::pow((9.81) * sigma_gl *
206 (liquid_water_density - vapour_water_density),
208 std::pow(liquid_water_density, 0.5);
215 using LocalJacobianMatrix =
216 Eigen::Matrix<double, 1, 1, Eigen::RowMajor>;
217 using LocalResidualVector = Eigen::Matrix<double, 1, 1>;
218 using LocalUnknownVector = Eigen::Matrix<double, 1, 1>;
219 LocalJacobianMatrix J_loc;
221 Eigen::PartialPivLU<LocalJacobianMatrix> linear_solver(1);
223 auto const update_residual = [&](LocalResidualVector& residual)
226 liquid_water_density, v_int_pt, dryness, C_0,
230 auto const update_jacobian = [&](LocalJacobianMatrix& jacobian)
233 alpha, vapour_water_density, liquid_water_density, v_int_pt,
238 auto const update_solution =
239 [&](LocalUnknownVector
const& increment)
242 alpha += increment[0];
245 const int maximum_iterations(20);
246 const double residuum_tolerance(1.e-10);
247 const double increment_tolerance(0);
250 linear_solver, update_jacobian, update_residual,
252 {maximum_iterations, residuum_tolerance, increment_tolerance});
254 auto const success_iterations = newton_solver.
solve(J_loc);
256 if (!success_iterations)
259 "Attention! Steam void fraction has not been correctly "
264 vapor_volume_frac = alpha;
268 liquid_water_density =
271 .template value<double>(vars, pos, t, dt);
275 vapour_water_density * alpha + liquid_water_density * (1 - alpha);
277 auto& mix_density_prev = ip_data.mix_density_prev;
280 auto const rho_dot = (mix_density - mix_density_prev) / dt;
282 double const liquid_water_velocity_act =
283 (alpha == 0) ? v_int_pt
284 : (1 - dryness) * mix_density * v_int_pt /
285 (1 - alpha) / liquid_water_density;
286 double const vapor_water_velocity_act =
288 : dryness * mix_density * v_int_pt /
289 (alpha * vapour_water_density);
291 vapor_mass_flowrate = vapor_water_velocity_act * vapour_water_density *
292 pi * r_i * r_i * alpha;
294 liquid_mass_flowrate = liquid_water_velocity_act *
295 liquid_water_density * pi * r_i * r_i *
303 alpha * liquid_water_density * vapour_water_density * mix_density /
305 std::pow((alpha * C_0 * vapour_water_density +
306 (1 - alpha * C_0) * liquid_water_density),
308 std::pow((C_0 - 1) * v_int_pt + u_gu, 2);
312 .template value<double>(vars, pos, t, dt);
313 double const Re = mix_density * v_int_pt * 2 * r_i / miu;
321 if (Re > 10 && Re <= 2400)
324 f = std::pow(std::log(xi / 3.7 / r_i) -
325 5.02 / Re * std::log(xi / 3.7 / r_i + 13 / Re),
330 double const T_r_int_pt = N.dot(T_r);
337 const double alpha_r = k_r / rho_r / c_r;
338 const double t_d = alpha_r * t / (r_i * r_i);
342 beta = std::pow((pi * t_d), -0.5) + 0.5 -
343 0.25 * std::pow((t_d / pi), 0.5) + 0.125 * t_d;
345 beta = 2 * (1 / (std::log(4 * t_d) - 2 * 0.57722) -
347 std::pow((std::log(4 * t_d) - 2 * 0.57722), 2));
349 const double P_c = 2 * pi * r_i;
350 Q_hx = P_c * k_r * (T_r_int_pt - T_int_pt) / r_i * beta;
354 double const p_r_int_pt = N.dot(p_r);
355 double const PI_int_pt = N.dot(
PI);
356 double Q_mx = PI_int_pt * (p_int_pt - p_r_int_pt);
364 Q_mom = Q_mx * v_int_pt;
369 double const h_fres =
372 .template value<double>(vars, pos, t, dt);
373 Q_ene = Q_mx * h_fres;
377 Mvv.noalias() += w * N.transpose() * mix_density * N;
379 Mhp.noalias() += -w * N.transpose() * N;
380 Mhh.noalias() += w * N.transpose() * mix_density * N;
383 Kpv.noalias() += w * dNdx.transpose() * N * mix_density;
385 Kvp.noalias() += w * N.transpose() * dNdx;
386 Kvv.noalias() += w * N.transpose() * rho_dot * N;
388 Khh.noalias() += w * N.transpose() * mix_density * v_int_pt * dNdx;
391 Bp.noalias() += w * N.transpose() * rho_dot + w * N.transpose() * Q_mx;
394 w * dNdx.transpose() * mix_density * v_int_pt * v_int_pt +
395 w * dNdx.transpose() * gamma -
396 w * N.transpose() * f * mix_density * std::abs(v_int_pt) *
397 v_int_pt / (4 * r_i) -
398 w * N.transpose() * Q_mom;
401 -1 / 2 * w * N.transpose() * rho_dot * v_int_pt * v_int_pt -
402 w * N.transpose() * mix_density * v_int_pt * vdot_int_pt +
403 1 / 2 * w * dNdx.transpose() * mix_density * v_int_pt * v_int_pt *
405 w * N.transpose() * (Q_hx / pi / r_i / r_i) -
406 w * N.transpose() * Q_ene;
413 Bv.noalias() += gravity_operator * mix_density;
414 Bh.noalias() += gravity_operator * mix_density * v_int_pt;