OGS
WellboreCompensateNeumannBoundaryConditionLocalAssembler.h
Go to the documentation of this file.
1
11#pragma once
12
13#include <Eigen/LU>
14#include <limits>
15
25
26namespace ProcessLib
27{
29{
33
34 // Used for mapping boundary nodes to bulk nodes.
35 std::unique_ptr<NumLib::LocalToGlobalIndexMap> dof_table_boundary_pressure;
36 std::unique_ptr<NumLib::LocalToGlobalIndexMap> dof_table_boundary_velocity;
37 std::unique_ptr<NumLib::LocalToGlobalIndexMap> dof_table_boundary_enthalpy;
38
40};
41
42template <typename ShapeFunction, int GlobalDim>
45 GlobalDim>
46{
47 using Base =
51
52public:
56 MeshLib::Element const& e,
57 std::size_t const local_matrix_size,
58 NumLib::GenericIntegrationMethod const& integration_method,
59 bool const is_axially_symmetric,
61 : Base(e, is_axially_symmetric, integration_method),
62 _element(e),
63 _data(data),
64 _local_matrix_size(local_matrix_size)
65 {
66 }
67
68 void assemble(std::size_t const mesh_item_id,
69 NumLib::LocalToGlobalIndexMap const& dof_table_boundary,
70 double const /*t*/, std::vector<GlobalVector*> const& x,
71 int const process_id, GlobalMatrix* /*K*/, GlobalVector& b,
72 GlobalMatrix* /*Jac*/) override
73 {
75 _local_rhs.setZero();
76
77 unsigned const n_integration_points =
79
80 auto const indices_current_variable =
81 NumLib::getIndices(mesh_item_id, dof_table_boundary);
82 auto const indices_pressure = NumLib::getIndices(
83 mesh_item_id, *_data.dof_table_boundary_pressure);
84 auto const indices_velocity = NumLib::getIndices(
85 mesh_item_id, *_data.dof_table_boundary_velocity);
86 auto const indices_enthalpy = NumLib::getIndices(
87 mesh_item_id, *_data.dof_table_boundary_enthalpy);
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
96 auto const& medium = *_data.media_map.getMedium(_element.getID());
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 {
107 auto const& n_and_weight = Base::_ns_and_weights[ip];
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
115 NumLib::shapeFunctionInterpolate(local_pressure, N,
116 pressure_int_pt);
117 NumLib::shapeFunctionInterpolate(local_velocity, N,
118 velocity_int_pt);
119 NumLib::shapeFunctionInterpolate(local_enthalpy, N,
120 enthalpy_int_pt);
121
122 vars.liquid_phase_pressure = pressure_int_pt;
123 vars.enthalpy = enthalpy_int_pt;
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
161 saturation_temperature)
162 .template value<double>(vars, pos, 0, 0);
163
164 vars.temperature = T_int_pt;
165
166 // For the calculation of the void fraction of vapour,
167 // see Rohuani, Z., and E. Axelsson. "Calculation of volume void
168 // fraction in a subcooled and quality region." International
169 // Journal of Heat and Mass Transfer 17 (1970): 383-393.
170
171 // Profile parameter of drift flux
172 double const C_0 = 1 + 0.12 * (1 - dryness);
173
174 // For the surface tension calculation, see
175 // Cooper, J. R., and R. B. Dooley. "IAPWS release on surface
176 // tension of ordinary water substance." International Association
177 // for the Properties of Water and Steam (1994).
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 // drift flux velocity
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 // solving void fraction of vapour using local Newton
190 // iteration.
191 double alpha = 0;
192 if (dryness != 0)
193 {
194 // Local Newton solver
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 // increment solution vectors
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
246 auto newton_solver = NumLib::NewtonRaphson(
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 {
256 WARN(
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 // slip parameter between two phases
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 =
283 _data.pressure_coefficient * mix_density * velocity_int_pt +
285 (mix_density * velocity_int_pt * velocity_int_pt + gamma) +
286 _data.enthalpy_coefficient * mix_density * velocity_int_pt *
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 }
293
294private:
298};
299
300} // namespace ProcessLib
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Phase const & phase(std::size_t index) const
Definition Medium.cpp:33
Global vector based on Eigen vector.
Definition EigenVector.h:25
void add(IndexType rowId, double v)
add entry
Definition EigenVector.h:76
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:89
std::optional< int > solve(JacobianMatrix &jacobian) const
void setElementID(std::size_t element_id)
std::vector< NAndWeight, Eigen::aligned_allocator< NAndWeight > > const _ns_and_weights
WellboreCompensateNeumannBoundaryConditionLocalAssembler(MeshLib::Element const &e, std::size_t const local_matrix_size, NumLib::GenericIntegrationMethod const &integration_method, bool const is_axially_symmetric, WellboreCompensateNeumannBoundaryConditionData const &data)
void assemble(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table_boundary, double const, std::vector< GlobalVector * > const &x, int const process_id, GlobalMatrix *, GlobalVector &b, GlobalMatrix *) override
void shapeFunctionInterpolate(const NodalValues &, const ShapeMatrix &)
std::vector< GlobalIndexType > getIndices(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)