73 {
75 _local_rhs.setZero();
76
77 unsigned const n_integration_points =
79
80 auto const indices_current_variable =
88
89 std::vector<double> const local_pressure =
90 x[process_id]->get(indices_pressure);
91 std::vector<double> const local_velocity =
92 x[process_id]->get(indices_velocity);
93 std::vector<double> const local_enthalpy =
94 x[process_id]->get(indices_enthalpy);
95
97 auto const& liquid_phase = medium.
phase(
"AqueousLiquid");
98 auto const& gas_phase = medium.phase("Gas");
99
102
104
105 for (unsigned ip = 0; ip < n_integration_points; ip++)
106 {
108 auto const&
N = n_and_weight.N;
109 auto const& w = n_and_weight.weight;
110
111 double pressure_int_pt = 0.0;
112 double velocity_int_pt = 0.0;
113 double enthalpy_int_pt = 0.0;
114
116 pressure_int_pt);
118 velocity_int_pt);
120 enthalpy_int_pt);
121
124
125 double liquid_water_density =
126 liquid_phase
127 .property(
129 .template value<double>(vars, pos, 0, 0);
130
131 double const vapour_water_density =
132 gas_phase
133 .property(
135 .template value<double>(vars, pos, 0, 0);
136
137 double const h_sat_liq_w =
138 liquid_phase
139 .property(
141 .template value<double>(vars, pos, 0, 0);
142
143 double const h_sat_vap_w =
144 gas_phase
145 .property(
147 .template value<double>(vars, pos, 0, 0);
148
149 double const dryness =
150 std::max(0., (enthalpy_int_pt - h_sat_liq_w) /
151 (h_sat_vap_w - h_sat_liq_w));
152
153 double const T_int_pt =
154 (dryness == 0)
155 ? liquid_phase
156 .property(
158 .template value<double>(vars, pos, 0, 0)
159 : gas_phase
162 .template value<double>(vars, pos, 0, 0);
163
165
166
167
168
169
170
171
172 double const C_0 = 1 + 0.12 * (1 - dryness);
173
174
175
176
177
178 double const sigma_gl = 0.2358 *
179 std::pow((1 - T_int_pt / 647.096), 1.256) *
180 (1 - 0.625 * (1 - T_int_pt / 647.096));
181
182 double const u_gu =
183 1.18 * (1 - dryness) *
184 std::pow((9.81) * sigma_gl *
185 (liquid_water_density - vapour_water_density),
186 0.25) /
187 std::pow(liquid_water_density, 0.5);
188
189
190
192 if (dryness != 0)
193 {
194
195 using LocalJacobianMatrix =
196 Eigen::Matrix<double, 1, 1, Eigen::RowMajor>;
197 using LocalResidualVector = Eigen::Matrix<double, 1, 1>;
198 using LocalUnknownVector = Eigen::Matrix<double, 1, 1>;
199 LocalJacobianMatrix J_loc;
200
201 Eigen::PartialPivLU<LocalJacobianMatrix> linear_solver(1);
202
203 auto const update_residual = [&](LocalResidualVector& residual)
204 {
205 residual(0) = dryness * liquid_water_density *
206 (
alpha * vapour_water_density +
207 (1 -
alpha) * liquid_water_density) *
208 velocity_int_pt -
209 alpha * C_0 * dryness * liquid_water_density *
210 (alpha * vapour_water_density +
211 (1 - alpha) * liquid_water_density) *
212 velocity_int_pt -
213 alpha * C_0 * (1 - dryness) *
214 vapour_water_density *
215 (alpha * vapour_water_density +
216 (1 - alpha) * liquid_water_density) *
217 velocity_int_pt -
218 alpha * vapour_water_density *
219 liquid_water_density * u_gu;
220 };
221
222 auto const update_jacobian = [&](LocalJacobianMatrix& jacobian)
223 {
224 jacobian(0) =
225 dryness * liquid_water_density * velocity_int_pt *
226 (vapour_water_density - liquid_water_density) -
227 (C_0 * dryness * liquid_water_density +
228 C_0 * (1 - dryness) * vapour_water_density) *
229 (2 *
alpha * vapour_water_density +
230 (1 - 2 *
alpha) * liquid_water_density) *
231 velocity_int_pt -
232 vapour_water_density * liquid_water_density * u_gu;
233 };
234
235 auto const update_solution =
236 [&](LocalUnknownVector const& increment)
237 {
238
239 alpha += increment[0];
240 };
241
242 const int maximum_iterations(20);
243 const double residuum_tolerance(1.e-10);
244 const double increment_tolerance(0);
245
247 linear_solver, update_jacobian, update_residual,
248 update_solution,
249 {maximum_iterations, residuum_tolerance,
250 increment_tolerance});
251
252 auto const success_iterations = newton_solver.
solve(J_loc);
253
254 if (!success_iterations)
255 {
257 "Attention! Steam void fraction has not been correctly "
258 "calculated!");
259 }
260 }
261
262 if (alpha == 0)
263 {
264 liquid_water_density =
265 liquid_phase
267 .template value<double>(vars, pos, 0, 0);
268 }
269
270 double const mix_density = vapour_water_density *
alpha +
271 liquid_water_density * (1 -
alpha);
272
273
274 double const gamma =
275 alpha * liquid_water_density * vapour_water_density *
276 mix_density / (1 -
alpha) /
277 std::pow((alpha * C_0 * vapour_water_density +
278 (1 - alpha * C_0) * liquid_water_density),
279 2) *
280 std::pow((C_0 - 1) * velocity_int_pt + u_gu, 2);
281
282 double const neumann_ip_values =
285 (mix_density * velocity_int_pt * velocity_int_pt + gamma) +
287 velocity_int_pt * velocity_int_pt * 0.5;
288 _local_rhs.noalias() +=
N.transpose() * neumann_ip_values * w;
289 }
290
291 b.
add(indices_current_variable, _local_rhs);
292 }
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Medium * getMedium(std::size_t element_id)
Phase const & phase(std::size_t index) const
double liquid_phase_pressure
void add(IndexType rowId, double v)
add entry
std::size_t getID() const
Returns the ID of the element.
unsigned getNumberOfPoints() const
std::optional< int > solve(JacobianMatrix &jacobian) const
void setElementID(std::size_t element_id)
NumLib::GenericIntegrationMethod const & _integration_method
std::vector< NAndWeight, Eigen::aligned_allocator< NAndWeight > > const _ns_and_weights
typename Base::NodalVectorType NodalVectorType
void shapeFunctionInterpolate(const NodalValues &, const ShapeMatrix &)
std::vector< GlobalIndexType > getIndices(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
std::unique_ptr< NumLib::LocalToGlobalIndexMap > dof_table_boundary_enthalpy
double const pressure_coefficient
std::unique_ptr< NumLib::LocalToGlobalIndexMap > dof_table_boundary_velocity
double const velocity_coefficient
std::unique_ptr< NumLib::LocalToGlobalIndexMap > dof_table_boundary_pressure
double const enthalpy_coefficient
MaterialPropertyLib::MaterialSpatialDistributionMap media_map