29 double const t,
double const dt, std::vector<double>
const& local_x,
30 std::vector<double>
const& local_x_prev, std::vector<double>& local_M_data,
31 std::vector<double>& local_K_data, std::vector<double>& local_b_data)
33 auto const local_matrix_size = local_x.size();
35 assert(local_matrix_size == ShapeFunction::NPOINTS *
NUM_NODAL_DOF);
38 local_M_data, local_matrix_size, local_matrix_size);
40 local_K_data, local_matrix_size, local_matrix_size);
42 local_b_data, local_matrix_size);
45 auto Mvv = local_M.template block<velocity_size, velocity_size>(
46 velocity_index, velocity_index);
48 auto Mhp = local_M.template block<enthalpy_size, pressure_size>(
49 enthalpy_index, pressure_index);
50 auto Mhh = local_M.template block<enthalpy_size, enthalpy_size>(
51 enthalpy_index, enthalpy_index);
53 auto Kpv = local_K.template block<pressure_size, velocity_size>(
54 pressure_index, velocity_index);
56 auto Kvp = local_K.template block<velocity_size, pressure_size>(
57 velocity_index, pressure_index);
58 auto Kvv = local_K.template block<velocity_size, velocity_size>(
59 velocity_index, velocity_index);
61 auto Khh = local_K.template block<enthalpy_size, enthalpy_size>(
62 enthalpy_index, enthalpy_index);
64 auto Bp = local_b.template segment<pressure_size>(pressure_index);
65 auto Bv = local_b.template segment<velocity_size>(velocity_index);
66 auto Bh = local_b.template segment<enthalpy_size>(enthalpy_index);
68 unsigned const n_integration_points =
69 _integration_method.getNumberOfPoints();
74 auto const& b = _process_data.specific_body_force;
79 auto const& medium = *_process_data.media_map.getMedium(_element.getID());
80 auto const& liquid_phase = medium.phase(
"AqueousLiquid");
81 auto const& gas_phase = medium.phase(
"Gas");
85 auto const t_ca = _process_data.wellbore.casing_thickness(t, pos)[0];
87 auto const r_w = _process_data.wellbore.diameter(t, pos)[0] / 2;
90 auto const t_p = _process_data.wellbore.pipe_thickness(t, pos)[0];
93 auto const xi = _process_data.wellbore.roughness(t, pos)[0];
95 auto const r_o = r_w - t_ca;
97 auto const r_i = r_o - t_p;
101 _process_data.reservoir_properties.
temperature.getNodalValuesOnElement(
104 _process_data.reservoir_properties.pressure.getNodalValuesOnElement(
107 _process_data.productivity_index.getNodalValuesOnElement(_element, t);
109 _process_data.reservoir_properties.thermal_conductivity(t, pos)[0];
110 auto const rho_r = _process_data.reservoir_properties.density(t, pos)[0];
112 _process_data.reservoir_properties.specific_heat_capacity(t, pos)[0];
114 for (
unsigned ip(0); ip < n_integration_points; ip++)
116 auto& ip_data = _ip_data[ip];
117 auto const& N = ip_data.N;
118 auto const& dNdx = ip_data.dNdx;
119 auto const& w = ip_data.integration_weight;
120 auto& mix_density = ip_data.mix_density;
121 auto& temperature = ip_data.temperature;
122 auto& steam_mass_frac = ip_data.dryness;
123 auto& vapor_volume_frac = ip_data.vapor_volume_fraction;
124 auto& vapor_mass_flowrate = ip_data.vapor_mass_flow_rate;
125 auto& liquid_mass_flowrate = ip_data.liquid_mass_flow_rate;
127 double p_int_pt = 0.0;
128 double v_int_pt = 0.0;
129 double h_int_pt = 0.0;
134 double p_prev_int_pt = 0.0;
135 double v_prev_int_pt = 0.0;
136 double h_prev_int_pt = 0.0;
139 v_prev_int_pt, h_prev_int_pt);
141 double vdot_int_pt = (v_int_pt - v_prev_int_pt) / dt;
145 const double pi = std::numbers::pi;
150 double liquid_water_density =
153 .template value<double>(vars, pos, t, dt);
154 double const vapour_water_density =
157 .template value<double>(vars, pos, t, dt);
159 double const h_sat_liq_w =
163 .template value<double>(vars, pos, t, dt);
164 double const h_sat_vap_w =
168 .template value<double>(vars, pos, t, dt);
172 double const dryness = std::max(
173 0., (h_int_pt - h_sat_liq_w) / (h_sat_vap_w - h_sat_liq_w));
174 steam_mass_frac = dryness;
176 double const T_int_pt =
180 .template value<double>(vars, pos, t, dt)
183 saturation_temperature)
184 .template value<double>(vars, pos, t, dt);
185 temperature = T_int_pt;
194 double C_0 = 1 + 0.12 * (1 - dryness);
200 double const sigma_gl = 0.2358 *
201 std::pow((1 - T_int_pt / 647.096), 1.256) *
202 (1 - 0.625 * (1 - T_int_pt / 647.096));
205 1.18 * (1 - dryness) *
206 std::pow((9.81) * sigma_gl *
207 (liquid_water_density - vapour_water_density),
209 std::pow(liquid_water_density, 0.5);
216 using LocalJacobianMatrix =
217 Eigen::Matrix<double, 1, 1, Eigen::RowMajor>;
218 using LocalResidualVector = Eigen::Matrix<double, 1, 1>;
219 using LocalUnknownVector = Eigen::Matrix<double, 1, 1>;
220 LocalJacobianMatrix J_loc;
222 Eigen::PartialPivLU<LocalJacobianMatrix> linear_solver(1);
224 auto const update_residual = [&](LocalResidualVector& residual)
226 calculateResidual(alpha, vapour_water_density,
227 liquid_water_density, v_int_pt, dryness, C_0,
231 auto const update_jacobian = [&](LocalJacobianMatrix& jacobian)
234 alpha, vapour_water_density, liquid_water_density, v_int_pt,
239 auto const update_solution =
240 [&](LocalUnknownVector
const& increment)
243 alpha += increment[0];
246 const int maximum_iterations(20);
247 const double residuum_tolerance(1.e-10);
248 const double increment_tolerance(0);
251 linear_solver, update_jacobian, update_residual,
253 {maximum_iterations, residuum_tolerance, increment_tolerance});
255 auto const success_iterations = newton_solver.
solve(J_loc);
257 if (!success_iterations)
260 "Attention! Steam void fraction has not been correctly "
265 vapor_volume_frac = alpha;
269 liquid_water_density =
272 .template value<double>(vars, pos, t, dt);
276 vapour_water_density * alpha + liquid_water_density * (1 - alpha);
278 auto& mix_density_prev = ip_data.mix_density_prev;
281 auto const rho_dot = (mix_density - mix_density_prev) / dt;
283 double const liquid_water_velocity_act =
284 (alpha == 0) ? v_int_pt
285 : (1 - dryness) * mix_density * v_int_pt /
286 (1 - alpha) / liquid_water_density;
287 double const vapor_water_velocity_act =
289 : dryness * mix_density * v_int_pt /
290 (alpha * vapour_water_density);
292 vapor_mass_flowrate = vapor_water_velocity_act * vapour_water_density *
293 pi * r_i * r_i * alpha;
295 liquid_mass_flowrate = liquid_water_velocity_act *
296 liquid_water_density * pi * r_i * r_i *
304 alpha * liquid_water_density * vapour_water_density * mix_density /
306 std::pow((alpha * C_0 * vapour_water_density +
307 (1 - alpha * C_0) * liquid_water_density),
309 std::pow((C_0 - 1) * v_int_pt + u_gu, 2);
313 .template value<double>(vars, pos, t, dt);
314 double const Re = mix_density * v_int_pt * 2 * r_i / miu;
322 if (Re > 10 && Re <= 2400)
325 f = std::pow(std::log(xi / 3.7 / r_i) -
326 5.02 / Re * std::log(xi / 3.7 / r_i + 13 / Re),
331 double const T_r_int_pt = N.dot(T_r);
333 if (_process_data.has_heat_exchange_with_formation)
338 const double alpha_r = k_r / rho_r / c_r;
339 const double t_d = alpha_r * t / (r_i * r_i);
343 beta = std::pow((pi * t_d), -0.5) + 0.5 -
344 0.25 * std::pow((t_d / pi), 0.5) + 0.125 * t_d;
346 beta = 2 * (1 / (std::log(4 * t_d) - 2 * 0.57722) -
348 std::pow((std::log(4 * t_d) - 2 * 0.57722), 2));
350 const double P_c = 2 * pi * r_i;
351 Q_hx = P_c * k_r * (T_r_int_pt - T_int_pt) / r_i * beta;
355 double const p_r_int_pt = N.dot(p_r);
356 double const PI_int_pt = N.dot(
PI);
357 double Q_mx = PI_int_pt * (p_int_pt - p_r_int_pt);
365 Q_mom = Q_mx * v_int_pt;
370 double const h_fres =
373 .template value<double>(vars, pos, t, dt);
374 Q_ene = Q_mx * h_fres;
378 Mvv.noalias() += w * N.transpose() * mix_density * N;
380 Mhp.noalias() += -w * N.transpose() * N;
381 Mhh.noalias() += w * N.transpose() * mix_density * N;
384 Kpv.noalias() += w * dNdx.transpose() * N * mix_density;
386 Kvp.noalias() += w * N.transpose() * dNdx;
387 Kvv.noalias() += w * N.transpose() * rho_dot * N;
389 Khh.noalias() += w * N.transpose() * mix_density * v_int_pt * dNdx;
392 Bp.noalias() += w * N.transpose() * rho_dot + w * N.transpose() * Q_mx;
395 w * dNdx.transpose() * mix_density * v_int_pt * v_int_pt +
396 w * dNdx.transpose() * gamma -
397 w * N.transpose() * f * mix_density * std::abs(v_int_pt) *
398 v_int_pt / (4 * r_i) -
399 w * N.transpose() * Q_mom;
402 -1 / 2 * w * N.transpose() * rho_dot * v_int_pt * v_int_pt -
403 w * N.transpose() * mix_density * v_int_pt * vdot_int_pt +
404 1 / 2 * w * dNdx.transpose() * mix_density * v_int_pt * v_int_pt *
406 w * N.transpose() * (Q_hx / pi / r_i / r_i) -
407 w * N.transpose() * Q_ene;
409 if (_process_data.has_gravity)
412 N.transpose() * b * w * _element_direction[2];
414 Bv.noalias() += gravity_operator * mix_density;
415 Bh.noalias() += gravity_operator * mix_density * v_int_pt;