Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
navier_stokes_cls_assemblers.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/bdf.h>
6#include <core/utilities.h>
7
10
11template <int dim>
12void
14 const NavierStokesScratchData<dim> &scratch_data,
16{
17 const std::vector<double> &viscosity_for_stabilization_vector =
19
20 // Loop and quadrature information
21 const auto &JxW_vec = scratch_data.JxW;
22 const unsigned int n_q_points = scratch_data.n_q_points;
23 const unsigned int n_dofs = scratch_data.n_dofs;
24 const double h = scratch_data.cell_size;
25
26 // Copy data elements
27 auto &strong_residual_vec = copy_data.strong_residual;
28 auto &strong_jacobian_vec = copy_data.strong_jacobian;
29 auto &local_matrix = copy_data.local_matrix;
30
31 // Time steps and inverse time steps which is used for stabilization constant
32 std::vector<double> time_steps_vector =
33 this->simulation_control->get_time_steps_vector();
34 const double dt = time_steps_vector[0];
35 const double sdt = 1. / dt;
36
37 Assert(scratch_data.properties_manager.density_is_constant(),
38 RequiresConstantDensity(
39 "GLSNavierStokesCLSAssemblerCore<dim>::assemble_matrix"));
40
41 // Loop over the quadrature points
42 for (unsigned int q = 0; q < n_q_points; ++q)
43 {
44 // Gather into local variables the relevant fields
45 const Tensor<1, dim> velocity = scratch_data.velocity_values[q];
46 const Tensor<2, dim> velocity_gradient =
47 scratch_data.velocity_gradients[q];
48 const Tensor<1, dim> velocity_laplacian =
49 scratch_data.velocity_laplacians[q];
50 const Tensor<3, dim> &velocity_hessian =
51 scratch_data.velocity_hessians[q];
52
53 // From hessian, calculate grad (div (u)) term needed for CLS problems
54 Tensor<1, dim> grad_div_velocity;
55 for (int d = 0; d < dim; ++d)
56 {
57 for (int k = 0; k < dim; ++k)
58 {
59 // hessian[c][i][j] is the (i,j)th component of the matrix of
60 // second derivatives of the cth vector component of the vector
61 // field at quadrature point q of the current cell
62 grad_div_velocity[d] += velocity_hessian[k][d][k];
63 }
64 }
65
66 const Tensor<1, dim> pressure_gradient =
67 scratch_data.pressure_gradients[q];
68
69 // Forcing term
70 Tensor<1, dim> force = scratch_data.force[q];
71
72 // Calculation of the magnitude of the velocity for the
73 // stabilization parameter
74 const double u_mag = std::max(velocity.norm(), 1e-12);
75
76 // Store JxW in local variable for faster access;
77 const double JxW = JxW_vec[q];
78
79 // Calculation of the equivalent properties at the quadrature point
80 double density_eq = scratch_data.density[q];
81 const double dynamic_viscosity_eq = scratch_data.dynamic_viscosity[q];
82
83 // Calculation of the GLS stabilization parameter. The
84 // stabilization parameter used is different if the simulation
85 // is steady or unsteady. In the unsteady case it includes the
86 // value of the time step
87 const double tau =
88 this->simulation_control->get_assembly_method() ==
91 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h) :
93 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h, sdt);
94
95 // Calculate the strong residual for GLS stabilization.
96 // According to the mathematical formulation, the viscosity jump term
97 // (-dynamic_viscosity_jump * (shear_rate * filtered_phase_gradient))
98 // should be included. However, it is ill-posed for phase change cases
99 // where the solid is represented by a highly viscous fluid. Hence, we
100 // don't consider this term in the current formulation.
101 auto strong_residual = density_eq * velocity_gradient * velocity +
102 pressure_gradient -
103 dynamic_viscosity_eq * velocity_laplacian -
104 dynamic_viscosity_eq * grad_div_velocity -
105 density_eq * force + strong_residual_vec[q];
106 /*- dynamic_viscosity_jump * (shear_rate * filtered_phase_gradient);*/
107
108
109 std::vector<Tensor<1, dim>> grad_phi_u_j_x_velocity(n_dofs);
110 std::vector<Tensor<1, dim>> velocity_gradient_x_phi_u_j(n_dofs);
111
112 // Pressure scaling factor
113 const double pressure_scaling_factor =
114 scratch_data.pressure_scaling_factor;
115
116 // We loop over the column first to prevent recalculation
117 // of the strong jacobian in the inner loop
118 for (unsigned int j = 0; j < n_dofs; ++j)
119 {
120 const auto &phi_u_j = scratch_data.phi_u[q][j];
121 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
122 const auto &laplacian_phi_u_j = scratch_data.laplacian_phi_u[q][j];
123
124 const auto &grad_phi_p_j =
125 scratch_data.grad_phi_p[q][j] * pressure_scaling_factor;
126
127 strong_jacobian_vec[q][j] +=
128 (density_eq * velocity_gradient * phi_u_j +
129 density_eq * grad_phi_u_j * velocity + grad_phi_p_j -
130 dynamic_viscosity_eq * laplacian_phi_u_j);
131
132 // Store these temporary products in auxiliary variables for speed
133 grad_phi_u_j_x_velocity[j] = grad_phi_u_j * velocity;
134 velocity_gradient_x_phi_u_j[j] = velocity_gradient * phi_u_j;
135 }
136
137 for (unsigned int i = 0; i < n_dofs; ++i)
138 {
139 const int component_i = scratch_data.components[i];
140
141 const auto &phi_u_i = scratch_data.phi_u[q][i];
142 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
143 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
144 const auto &phi_p_i = scratch_data.phi_p[q][i];
145 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
146
147 // Store these temporary products in auxiliary variables for speed
148 const auto grad_phi_u_i_x_velocity = grad_phi_u_i * velocity;
149 const auto strong_residual_x_grad_phi_u_i =
150 strong_residual * grad_phi_u_i;
151
152 for (unsigned int j = 0; j < n_dofs; ++j)
153 {
154 const int component_j = scratch_data.components[j];
155
156 const auto &phi_u_j = scratch_data.phi_u[q][j];
157 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
158 // const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
159 const auto shear_rate_j = grad_phi_u_j + transpose(grad_phi_u_j);
160
161 const auto &phi_p_j =
162 scratch_data.phi_p[q][j] * pressure_scaling_factor;
163
164 const auto &strong_jac = strong_jacobian_vec[q][j];
165
166 double local_matrix_ij =
167 component_j == dim ? -div_phi_u_i * phi_p_j : 0;
168
169 if (component_i == dim)
170 {
171 const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
172
173 local_matrix_ij += phi_p_i * div_phi_u_j;
174
175 local_matrix_ij +=
176 tau / density_eq * (strong_jac * grad_phi_p_i);
177 }
178
179 if (component_i < dim && component_j < dim)
180 {
181 local_matrix_ij +=
182 dynamic_viscosity_eq *
183 scalar_product(shear_rate_j, grad_phi_u_i) +
184 density_eq * velocity_gradient_x_phi_u_j[j] * phi_u_i +
185 density_eq * grad_phi_u_j_x_velocity[j] * phi_u_i;
186 }
187
188 if (component_i < dim)
189 {
190 // Jacobian is currently incomplete
191 if (SUPG)
192 {
193 local_matrix_ij +=
194 tau * (strong_jac * grad_phi_u_i_x_velocity +
195 strong_residual_x_grad_phi_u_i * phi_u_j);
196 }
197 }
198 local_matrix_ij *= JxW;
199 local_matrix(i, j) += local_matrix_ij;
200 }
201 }
202 }
203}
204
205
206template <int dim>
207void
209 const NavierStokesScratchData<dim> &scratch_data,
211{
212 const std::vector<double> &viscosity_for_stabilization_vector =
214 // Loop and quadrature information
215 const auto &JxW_vec = scratch_data.JxW;
216 const unsigned int n_q_points = scratch_data.n_q_points;
217 const unsigned int n_dofs = scratch_data.n_dofs;
218 const double h = scratch_data.cell_size;
219
220 // Copy data elements
221 auto &strong_residual_vec = copy_data.strong_residual;
222 auto &local_rhs = copy_data.local_rhs;
223
224 // Time steps and inverse time steps which is used for stabilization constant
225 std::vector<double> time_steps_vector =
226 this->simulation_control->get_time_steps_vector();
227 const double dt = time_steps_vector[0];
228 const double sdt = 1. / dt;
229
230 Assert(scratch_data.properties_manager.density_is_constant(),
231 RequiresConstantDensity(
232 "GLSNavierStokesCLSAssemblerCore<dim>::assemble_rhs"));
233
234 // Loop over the quadrature points
235 for (unsigned int q = 0; q < n_q_points; ++q)
236 {
237 // Velocity
238 const Tensor<1, dim> velocity = scratch_data.velocity_values[q];
239 const double velocity_divergence = scratch_data.velocity_divergences[q];
240 const Tensor<2, dim> velocity_gradient =
241 scratch_data.velocity_gradients[q];
242 const Tensor<1, dim> velocity_laplacian =
243 scratch_data.velocity_laplacians[q];
244
245
246 const Tensor<3, dim> &velocity_hessian =
247 scratch_data.velocity_hessians[q];
248 // From hessian, calculate grad (div (u)) term needed for CLS problems
249 Tensor<1, dim> grad_div_velocity;
250 for (int d = 0; d < dim; ++d)
251 {
252 for (int k = 0; k < dim; ++k)
253 {
254 // hessian[c][i][j] is the (i,j)th component of the matrix of
255 // second derivatives of the cth vector component of the vector
256 // field at quadrature point q of the current cell
257 grad_div_velocity[d] += velocity_hessian[k][d][k];
258 }
259 }
260
261 // Calculate shear rate
262 const Tensor<2, dim> shear_rate =
263 velocity_gradient + transpose(velocity_gradient);
264
265 // Pressure
266 const double pressure = scratch_data.pressure_values[q];
267 const Tensor<1, dim> pressure_gradient =
268 scratch_data.pressure_gradients[q];
269
270 // Forcing term
271 Tensor<1, dim> force = scratch_data.force[q];
272
273 // Calculation of the magnitude of the
274 // velocity for the stabilization parameter
275 const double u_mag = std::max(velocity.norm(), 1e-12);
276
277 // Store JxW in local variable for faster access;
278 const double JxW = JxW_vec[q];
279
280 // Calculation of the equivalent properties at the quadrature point
281 double density_eq = scratch_data.density[q];
282 const double dynamic_viscosity_eq = scratch_data.dynamic_viscosity[q];
283
284 // Calculation of the GLS stabilization parameter. The
285 // stabilization parameter used is different if the simulation
286 // is steady or unsteady. In the unsteady case it includes the
287 // value of the time step
288 const double tau =
289 this->simulation_control->get_assembly_method() ==
292 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h) :
294 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h, sdt);
295
296
297 // Calculate the strong residual for GLS stabilization.
298 // According to the mathematical formulation, the viscosity jump term
299 // (-dynamic_viscosity_jump * (shear_rate * filtered_phase_gradient))
300 // should be included. However, it is ill-posed for phase change cases
301 // where the solid is represented by a highly viscous fluid. Hence, we
302 // don't consider this term in the current formulation.
303 auto strong_residual = density_eq * velocity_gradient * velocity +
304 pressure_gradient -
305 dynamic_viscosity_eq * velocity_laplacian -
306 dynamic_viscosity_eq * grad_div_velocity -
307 density_eq * force + strong_residual_vec[q];
308 /*- dynamic_viscosity_jump * (shear_rate * filtered_phase_gradient);*/
309
310 // Assembly of the right-hand side
311 for (unsigned int i = 0; i < n_dofs; ++i)
312 {
313 const int component_i = scratch_data.components[i];
314
315 const auto phi_u_i = scratch_data.phi_u[q][i];
316 const auto grad_phi_u_i = scratch_data.grad_phi_u[q][i];
317 const auto phi_p_i = scratch_data.phi_p[q][i];
318 const auto grad_phi_p_i = scratch_data.grad_phi_p[q][i];
319 const auto div_phi_u_i = scratch_data.div_phi_u[q][i];
320
321
322 // Navier-Stokes Residual
323 // Momentum
324 local_rhs(i) +=
325 (-dynamic_viscosity_eq * scalar_product(shear_rate, grad_phi_u_i) -
326 density_eq * velocity_gradient * velocity * phi_u_i +
327 pressure * div_phi_u_i + density_eq * force * phi_u_i) *
328 JxW;
329
330 if (component_i == dim)
331 {
332 // Continuity
333 local_rhs(i) += -(velocity_divergence * phi_p_i) * JxW;
334
335 // PSPG GLS term
336 local_rhs(i) +=
337 -tau / density_eq * (strong_residual * grad_phi_p_i) * JxW;
338 }
339 // SUPG GLS term
340 if (SUPG)
341 {
342 local_rhs(i) +=
343 -tau * (strong_residual * (grad_phi_u_i * velocity)) * JxW;
344 }
345 }
346 }
347}
348
351
352
353template <int dim>
354void
356 const NavierStokesScratchData<dim> &scratch_data,
358{
359 // Loop and quadrature information
360 const auto &JxW = scratch_data.JxW;
361 const unsigned int n_q_points = scratch_data.n_q_points;
362 const unsigned int n_dofs = scratch_data.n_dofs;
363
364 // Copy data elements
365 auto &strong_residual = copy_data.strong_residual;
366 auto &strong_jacobian = copy_data.strong_jacobian;
367 auto &local_matrix = copy_data.local_matrix;
368
369 // Time stepping information
370 const auto method = this->simulation_control->get_assembly_method();
371 // Vector for the BDF coefficients
372 const Vector<double> &bdf_coefs =
373 this->simulation_control->get_bdf_coefficients();
374 std::vector<Tensor<1, dim>> velocity(1 +
376
377 // Loop over the quadrature points
378 for (unsigned int q = 0; q < n_q_points; ++q)
379 {
380 velocity[0] = scratch_data.velocity_values[q];
381 for (unsigned int p = 0; p < number_of_previous_solutions(method); ++p)
382 velocity[p + 1] = scratch_data.previous_velocity_values[p][q];
383
384 const double density = scratch_data.density[q];
385
386 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
387 ++p)
388 {
389 strong_residual[q] += density * bdf_coefs[p] * velocity[p];
390 }
391
392 for (unsigned int j = 0; j < n_dofs; ++j)
393 {
394 strong_jacobian[q][j] +=
395 density * bdf_coefs[0] * scratch_data.phi_u[q][j];
396 }
397
398
399 for (unsigned int i = 0; i < n_dofs; ++i)
400 {
401 const Tensor<1, dim> &phi_u_i = scratch_data.phi_u[q][i];
402 for (unsigned int j = 0; j < n_dofs; ++j)
403 {
404 const Tensor<1, dim> &phi_u_j = scratch_data.phi_u[q][j];
405
406 local_matrix(i, j) +=
407 phi_u_j * phi_u_i * density * bdf_coefs[0] * JxW[q];
408 }
409 }
410 }
411}
412
413template <int dim>
414void
416 const NavierStokesScratchData<dim> &scratch_data,
418{
419 // Loop and quadrature information
420 const auto &JxW = scratch_data.JxW;
421 const unsigned int n_q_points = scratch_data.n_q_points;
422 const unsigned int n_dofs = scratch_data.n_dofs;
423
424 // Copy data elements
425 auto &strong_residual = copy_data.strong_residual;
426 auto &local_rhs = copy_data.local_rhs;
427
428 // Time stepping information
429 const auto method = this->simulation_control->get_assembly_method();
430 // Vector for the BDF coefficients
431 const Vector<double> &bdf_coefs =
432 this->simulation_control->get_bdf_coefficients();
433 std::vector<Tensor<1, dim>> velocity(1 +
435
436 // Loop over the quadrature points
437 for (unsigned int q = 0; q < n_q_points; ++q)
438 {
439 velocity[0] = scratch_data.velocity_values[q];
440 for (unsigned int p = 0; p < number_of_previous_solutions(method); ++p)
441 velocity[p + 1] = scratch_data.previous_velocity_values[p][q];
442
443 const double density = scratch_data.density[q];
444
445 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
446 ++p)
447 {
448 strong_residual[q] += (density * bdf_coefs[p] * velocity[p]);
449 }
450
451
452 for (unsigned int i = 0; i < n_dofs; ++i)
453 {
454 const auto phi_u_i = scratch_data.phi_u[q][i];
455 double local_rhs_i = 0;
456 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
457 ++p)
458 {
459 local_rhs_i -= density * bdf_coefs[p] * (velocity[p] * phi_u_i);
460 }
461 local_rhs(i) += local_rhs_i * JxW[q];
462 }
463 }
464}
465
468
469
470template <int dim>
471void
473 const NavierStokesScratchData<dim> &scratch_data,
475{
476 // Loop and quadrature information
477 const auto &JxW_vec = scratch_data.JxW;
478 const unsigned int n_q_points = scratch_data.n_q_points;
479 const unsigned int n_dofs = scratch_data.n_dofs;
480 const auto &velocities = scratch_data.velocity_values;
481 const auto &temperatures = scratch_data.temperature_values;
482 const auto &densities_0 = scratch_data.density_0;
483 const auto &densities_1 = scratch_data.density_1;
484 const auto &filtered_phase = scratch_data.filtered_phase_values;
485
486 auto &local_matrix = copy_data.local_matrix;
487 auto &strong_residual = copy_data.strong_residual;
488 auto &strong_jacobian = copy_data.strong_jacobian;
489
490 const unsigned int number_of_fluids = phase_change_parameters_vector.size();
491 std::vector<double> liquid_fractions(number_of_fluids);
492 std::vector<double> darcy_penalties(number_of_fluids);
493 // Loop over the quadrature points
494 for (unsigned int q = 0; q < n_q_points; ++q)
495 {
496 // Store JxW in local variable for faster access;
497 const double JxW = JxW_vec[q];
498 // Current temperature and density values
499 double current_temperature = temperatures[q];
500 double current_density_0 = densities_0[q];
501 double current_density_1 = densities_1[q];
502 // Loop to calculate the liquid fraction and Darcy permeability of each
503 // fluid. Calculated Darcy permeability coefficients depend on the
504 // temperature and material (fluid) properties. A min(max) approach is
505 // used to calculate the liquid fractions avoiding if conditions.
506 for (unsigned int p = 0; p < number_of_fluids; p++)
507 {
508 liquid_fractions[p] =
509 std::min(1.,
510 std::max((current_temperature -
511 phase_change_parameters_vector[p].T_solidus) /
512 (phase_change_parameters_vector[p].T_liquidus -
513 phase_change_parameters_vector[p].T_solidus),
514 0.));
515 darcy_penalties[p] =
516 phase_change_parameters_vector[p].penalty_l * liquid_fractions[p] +
517 (1. - liquid_fractions[p]) *
519 }
520
521 // For a CLS two-fluid system, the global Darcy permeability coefficient
522 // takes into account the phase change parameters in both fluids.
523 // If enabled,we also multiply by density.
524 const double darcy_penalty =
526 ((1 - filtered_phase[q]) * darcy_penalties[0] * current_density_0) +
527 (filtered_phase[q] * darcy_penalties[1] * current_density_1) :
528 ((1 - filtered_phase[q]) * darcy_penalties[0]) +
529 (filtered_phase[q] * darcy_penalties[1]);
530
531 strong_residual[q] += darcy_penalty * velocities[q];
532
533 for (unsigned int j = 0; j < n_dofs; ++j)
534 {
535 strong_jacobian[q][j] += darcy_penalty * scratch_data.phi_u[q][j];
536 }
537
538 for (unsigned int i = 0; i < n_dofs; ++i)
539 {
540 const auto &phi_u_i = scratch_data.phi_u[q][i];
541 for (unsigned int j = 0; j < n_dofs; ++j)
542 {
543 const auto &phi_u_j = scratch_data.phi_u[q][j];
544 local_matrix(i, j) += darcy_penalty * phi_u_i * phi_u_j * JxW;
545 }
546 }
547 }
548}
549
550template <int dim>
551void
553 const NavierStokesScratchData<dim> &scratch_data,
555{
556 // Loop and quadrature information
557 const auto &JxW_vec = scratch_data.JxW;
558 const unsigned int n_q_points = scratch_data.n_q_points;
559 const unsigned int n_dofs = scratch_data.n_dofs;
560 const auto &velocities = scratch_data.velocity_values;
561 const auto &temperatures = scratch_data.temperature_values;
562 const auto &densities_0 = scratch_data.density_0;
563 const auto &densities_1 = scratch_data.density_1;
564 const auto &filtered_phase = scratch_data.filtered_phase_values;
565
566 auto &local_rhs = copy_data.local_rhs;
567 auto &strong_residual = copy_data.strong_residual;
568
569 const unsigned int number_of_fluids = phase_change_parameters_vector.size();
570 std::vector<double> liquid_fractions(number_of_fluids);
571 std::vector<double> darcy_penalties(number_of_fluids);
572
573 // Loop over the quadrature points
574 for (unsigned int q = 0; q < n_q_points; ++q)
575 {
576 // Store JxW in local variable for faster access;
577 const double JxW = JxW_vec[q];
578 // Current temperature and density values
579 double current_temperature = temperatures[q];
580 double current_density_0 = densities_0[q];
581 double current_density_1 = densities_1[q];
582
583 // Loop to calculate the liquid fraction and Darcy permeability of each
584 // fluid. Calculated Darcy penalty coefficients depend on the
585 // temperature and material (fluid) properties. A min(max) approach is
586 // used to calculate the liquid fractions avoiding if conditions.
587 for (unsigned int p = 0; p < number_of_fluids; p++)
588 {
589 liquid_fractions[p] =
590 std::min(1.,
591 std::max((current_temperature -
592 phase_change_parameters_vector[p].T_solidus) /
593 (phase_change_parameters_vector[p].T_liquidus -
594 phase_change_parameters_vector[p].T_solidus),
595 0.));
596 darcy_penalties[p] =
597 phase_change_parameters_vector[p].penalty_l * liquid_fractions[p] +
598 (1. - liquid_fractions[p]) *
600 }
601
602 // For a CLS two-fluid system, the global Darcy permeability coefficient
603 // takes into account the phase change parameters in both fluids.
604 // If enabled,we also multiply by density.
605 const double darcy_penalty =
607 ((1 - filtered_phase[q]) * darcy_penalties[0] * current_density_0) +
608 (filtered_phase[q] * darcy_penalties[1] * current_density_1) :
609 ((1 - filtered_phase[q]) * darcy_penalties[0]) +
610 (filtered_phase[q] * darcy_penalties[1]);
611
612 strong_residual[q] += darcy_penalty * velocities[q];
613
614 // Assembly of the right-hand side
615 for (unsigned int i = 0; i < n_dofs; ++i)
616 {
617 const auto phi_u_i = scratch_data.phi_u[q][i];
618
619 // Laplacian on the velocity terms
620 local_rhs(i) -= darcy_penalty * velocities[q] * phi_u_i * JxW;
621 }
622 }
623}
624
627
628
629template <int dim>
630void
632 const NavierStokesScratchData<dim> &scratch_data,
634{
635 // Loop and quadrature information
636 const auto &JxW_vec = scratch_data.JxW;
637 const unsigned int n_q_points = scratch_data.n_q_points;
638 const unsigned int n_dofs = scratch_data.n_dofs;
639 const auto &velocities = scratch_data.velocity_values;
640 const auto &temperatures = scratch_data.temperature_values;
641 const auto &dynamic_viscosity_values_0 = scratch_data.dynamic_viscosity_0;
642 const auto &dynamic_viscosity_values_1 = scratch_data.dynamic_viscosity_1;
643 const auto &filtered_phase = scratch_data.filtered_phase_values;
644
645 auto &local_matrix = copy_data.local_matrix;
646 auto &strong_residual = copy_data.strong_residual;
647 auto &strong_jacobian = copy_data.strong_jacobian;
648
649 const unsigned int number_of_fluids = phase_change_parameters_vector.size();
650 std::vector<double> liquid_fraction_factors(number_of_fluids);
651
652 // Loop over the quadrature points
653 for (unsigned int q = 0; q < n_q_points; ++q)
654 {
655 // Store JxW in local variable for faster access;
656 const double JxW = JxW_vec[q];
657
658 // Current temperature and dynamic viscosity values
659 double temperature = temperatures[q];
660 double dynamic_viscosity_0 = dynamic_viscosity_values_0[q];
661 double dynamic_viscosity_1 = dynamic_viscosity_values_1[q];
662
663 // Compute the liquid fraction and compute penalty term
664 for (unsigned int p = 0; p < number_of_fluids; p++)
665 {
666 // Skip to next fluid if there is no phase change
668 {
669 liquid_fraction_factors[p] = 0;
670 continue;
671 }
672
673 // Compute the liquid fraction
674 double liquid_fraction =
675 (std::min(1.,
676 std::max((temperature -
677 phase_change_parameters_vector[p].T_solidus) /
678 (phase_change_parameters_vector[p].T_liquidus -
679 phase_change_parameters_vector[p].T_solidus),
680 0.)));
681
682 // Pre-compute the denominator inverse
683 double denominator_inv =
684 1 / (Utilities::fixed_power<3>(liquid_fraction) +
686
687 // Compute liquid fraction factor (1-alpha_{i_l})^2 * (alpha_{i,l}^3 +
688 // tol)^{-1}
689 liquid_fraction_factors[p] =
690 Utilities::fixed_power<2>(1 - liquid_fraction) * denominator_inv;
691 }
692
693 // For a CLS two-fluid system, the global Carman-Kozeny penalty term
694 // takes into account the phase change parameters in both fluids.
695 const double carman_kozeny_penalty =
696 (carman_kozeny_permeability_area_inv[0] * (1 - filtered_phase[q]) *
697 liquid_fraction_factors[0] * dynamic_viscosity_0) +
698 (carman_kozeny_permeability_area_inv[1] * filtered_phase[q] *
699 liquid_fraction_factors[1] * dynamic_viscosity_1);
700
701 strong_residual[q] += carman_kozeny_penalty * velocities[q];
702
703 for (unsigned int j = 0; j < n_dofs; ++j)
704 {
705 strong_jacobian[q][j] +=
706 carman_kozeny_penalty * scratch_data.phi_u[q][j];
707 }
708
709 for (unsigned int i = 0; i < n_dofs; ++i)
710 {
711 const auto &phi_u_i = scratch_data.phi_u[q][i];
712 for (unsigned int j = 0; j < n_dofs; ++j)
713 {
714 const auto &phi_u_j = scratch_data.phi_u[q][j];
715 local_matrix(i, j) +=
716 carman_kozeny_penalty * phi_u_i * phi_u_j * JxW;
717 }
718 }
719 }
720}
721
722template <int dim>
723void
725 const NavierStokesScratchData<dim> &scratch_data,
727{
728 // Loop and quadrature information
729 const auto &JxW_vec = scratch_data.JxW;
730 const unsigned int n_q_points = scratch_data.n_q_points;
731 const unsigned int n_dofs = scratch_data.n_dofs;
732 const auto &velocities = scratch_data.velocity_values;
733 const auto &temperatures = scratch_data.temperature_values;
734 const auto &dynamic_viscosity_values_0 = scratch_data.dynamic_viscosity_0;
735 const auto &dynamic_viscosity_values_1 = scratch_data.dynamic_viscosity_1;
736 const auto &filtered_phase = scratch_data.filtered_phase_values;
737
738 auto &local_rhs = copy_data.local_rhs;
739 auto &strong_residual = copy_data.strong_residual;
740
741 const unsigned int number_of_fluids = phase_change_parameters_vector.size();
742 std::vector<double> liquid_fraction_factors(number_of_fluids);
743
744 // Loop over the quadrature points
745 for (unsigned int q = 0; q < n_q_points; ++q)
746 {
747 // Store JxW in local variable for faster access;
748 const double JxW = JxW_vec[q];
749
750 // Current temperature and dynamic viscosity values
751 double temperature = temperatures[q];
752 double dynamic_viscosity_0 = dynamic_viscosity_values_0[q];
753 double dynamic_viscosity_1 = dynamic_viscosity_values_1[q];
754
755 // Compute the liquid fraction and compute penalty term
756 for (unsigned int p = 0; p < number_of_fluids; p++)
757 {
758 // Skip to next fluid if there is no phase change
760 {
761 liquid_fraction_factors[p] = 0;
762 continue;
763 }
764
765 // Compute the liquid fraction
766 double liquid_fraction =
767 (std::min(1.,
768 std::max((temperature -
769 phase_change_parameters_vector[p].T_solidus) /
770 (phase_change_parameters_vector[p].T_liquidus -
771 phase_change_parameters_vector[p].T_solidus),
772 0.)));
773
774 // Pre-compute the denominator inverse
775 double denominator_inv =
776 1 / (Utilities::fixed_power<3>(liquid_fraction) +
778
779 // Compute liquid fraction factor (1-alpha_{i_l})^2 * (alpha_{i,l}^3 +
780 // tol)^{-1}
781 liquid_fraction_factors[p] =
782 Utilities::fixed_power<2>(1 - liquid_fraction) * denominator_inv;
783 }
784
785 // For a CLS two-fluid system, the global Carman-Kozeny penalty term
786 // takes into account the phase change parameters in both fluids.
787 const double carman_kozeny_penalty =
788 (carman_kozeny_permeability_area_inv[0] * (1 - filtered_phase[q]) *
789 liquid_fraction_factors[0] * dynamic_viscosity_0) +
790 (carman_kozeny_permeability_area_inv[1] * filtered_phase[q] *
791 liquid_fraction_factors[1] * dynamic_viscosity_1);
792
793 strong_residual[q] += carman_kozeny_penalty * velocities[q];
794
795 // Assembly of the right-hand side
796 for (unsigned int i = 0; i < n_dofs; ++i)
797 {
798 const auto phi_u_i = scratch_data.phi_u[q][i];
799
800 // Laplacian on the velocity terms
801 local_rhs(i) -= carman_kozeny_penalty * velocities[q] * phi_u_i * JxW;
802 }
803 }
804}
805
808
809
810template <int dim>
811void
813 const NavierStokesScratchData<dim> &scratch_data,
815{
816 // The surface tension force does not depend on the velocity or the pressure,
817 // so it has no contribution to the Jacobian. However, it must still be added
818 // to the strong residual since the SUPG term of the Jacobian depends on it.
819 const unsigned int n_q_points = scratch_data.n_q_points;
820
821 auto &strong_residual = copy_data.strong_residual;
822
823 for (unsigned int q = 0; q < n_q_points; ++q)
824 {
825 const Tensor<1, dim> &phase_gradient_value_q =
826 scratch_data.phase_gradient_values[q];
827
828 const Tensor<1, dim> normalized_phase_indicator_gradient =
829 phase_gradient_value_q / (phase_gradient_value_q.norm() + 1e-15);
830
831 const Tensor<1, dim> surface_tension_force =
832 -scratch_data.surface_tension[q] * scratch_data.curvature_values[q] *
833 normalized_phase_indicator_gradient *
834 scratch_data.filtered_phase_gradient_values[q].norm();
835
836 strong_residual[q] += surface_tension_force;
837 }
838}
839
840template <int dim>
841void
843 const NavierStokesScratchData<dim> &scratch_data,
845{
846 // Loop and quadrature information
847 const auto &JxW = scratch_data.JxW;
848 const unsigned int n_q_points = scratch_data.n_q_points;
849 const unsigned int n_dofs = scratch_data.n_dofs;
850
851 // Copy data elements
852 auto &strong_residual = copy_data.strong_residual;
853 auto &local_rhs = copy_data.local_rhs;
854
855 // Loop over the quadrature points
856 for (unsigned int q = 0; q < n_q_points; ++q)
857 {
858 // Surface tension coefficient
859 const double surface_tension_coef = scratch_data.surface_tension[q];
860
861 // Gather curvature value
862 const double &curvature_value = scratch_data.curvature_values[q];
863
864 // Gather phase indicator gradient
865 const Tensor<1, dim> &phase_gradient_value_q =
866 scratch_data.phase_gradient_values[q];
867
868 // Gather filtered phase indicator gradient
869 const Tensor<1, dim> &filtered_phase_gradient_value_q =
870 scratch_data.filtered_phase_gradient_values[q];
871
872 const double phase_gradient_norm = phase_gradient_value_q.norm();
873
874 const double filtered_phase_gradient_norm =
875 filtered_phase_gradient_value_q.norm();
876
877 const Tensor<1, dim> normalized_phase_indicator_gradient =
878 phase_gradient_value_q / (phase_gradient_norm + 1e-15);
879
880 const double JxW_value = JxW[q];
881
882 const Tensor<1, dim> surface_tension_force =
883 -surface_tension_coef * curvature_value *
884 normalized_phase_indicator_gradient * filtered_phase_gradient_norm;
885
886 strong_residual[q] += surface_tension_force;
887
888 for (unsigned int i = 0; i < n_dofs; ++i)
889 {
890 const auto phi_u_i = scratch_data.phi_u[q][i];
891 double local_rhs_i = 0;
892
893 local_rhs_i -= surface_tension_force * phi_u_i;
894 local_rhs(i) += local_rhs_i * JxW_value;
895 }
896 }
897}
898
901
902
903template <int dim>
904void
906 const NavierStokesScratchData<dim> &scratch_data,
908{
909 // The surface tension and Marangoni forces do not depend on the velocity or
910 // the pressure, so they have no contribution to the Jacobian. However, they
911 // must still be added to the strong residual since the SUPG term of the
912 // Jacobian depends on it.
913 const unsigned int n_q_points = scratch_data.n_q_points;
914
915 auto &strong_residual = copy_data.strong_residual;
916
917 for (unsigned int q = 0; q < n_q_points; ++q)
918 {
919 const Tensor<1, dim> &phase_gradient_value_q =
920 scratch_data.phase_gradient_values[q];
921
922 const double filtered_phase_gradient_norm =
923 scratch_data.filtered_phase_gradient_values[q].norm();
924
925 const Tensor<1, dim> normalized_phase_indicator_gradient =
926 phase_gradient_value_q / (phase_gradient_value_q.norm() + 1e-15);
927
928 const Tensor<1, dim> &temperature_gradient =
929 scratch_data.temperature_gradients[q];
930
931 const Tensor<1, dim> surface_tension_force =
932 -scratch_data.surface_tension[q] * scratch_data.curvature_values[q] *
933 normalized_phase_indicator_gradient * filtered_phase_gradient_norm;
934
935 const Tensor<1, dim> marangoni_effect =
936 -scratch_data.surface_tension_gradient[q] *
937 (temperature_gradient -
938 normalized_phase_indicator_gradient *
939 (normalized_phase_indicator_gradient * temperature_gradient)) *
940 filtered_phase_gradient_norm;
941
942 strong_residual[q] += marangoni_effect + surface_tension_force;
943 }
944}
945
946template <int dim>
947void
949 const NavierStokesScratchData<dim> &scratch_data,
951{
952 // Densities of phases
953 Assert(scratch_data.properties_manager.density_is_constant(),
954 RequiresConstantDensity(
955 "GLSNavierStokesCLSAssemblerMarangoni<dim>::assemble_rhs"));
956
957 // Loop and quadrature information
958 const auto &JxW = scratch_data.JxW;
959 const unsigned int n_q_points = scratch_data.n_q_points;
960 const unsigned int n_dofs = scratch_data.n_dofs;
961
962 // Copy data elements
963 auto &strong_residual = copy_data.strong_residual;
964 auto &local_rhs = copy_data.local_rhs;
965
966 // Loop over the quadrature points
967 for (unsigned int q = 0; q < n_q_points; ++q)
968 {
969 // Surface tension
970 const double surface_tension = scratch_data.surface_tension[q];
971 // Surface tension gradient with respect to the temperature
972 const double surface_tension_gradient =
973 scratch_data.surface_tension_gradient[q];
974
975 const double &curvature_value = scratch_data.curvature_values[q];
976
977 // Gather phase indicator gradient
978 const Tensor<1, dim> &phase_gradient_value_q =
979 scratch_data.phase_gradient_values[q];
980
981 // Gather filtered phase indicator gradient
982 const Tensor<1, dim> &filtered_phase_gradient_value_q =
983 scratch_data.filtered_phase_gradient_values[q];
984
985 const double phase_gradient_norm = phase_gradient_value_q.norm();
986
987 const double filtered_phase_gradient_norm =
988 filtered_phase_gradient_value_q.norm();
989
990 const Tensor<1, dim> normalized_phase_indicator_gradient =
991 phase_gradient_value_q / (phase_gradient_norm + 1e-15);
992
993 // Gather temperature gradient
994 const Tensor<1, dim> temperature_gradient =
995 scratch_data.temperature_gradients[q];
996
997 const double JxW_value = JxW[q];
998
999
1000 const Tensor<1, dim> surface_tension_force =
1001 -surface_tension * curvature_value *
1002 normalized_phase_indicator_gradient * filtered_phase_gradient_norm;
1003
1004 const Tensor<1, dim> marangoni_effect =
1005 -surface_tension_gradient *
1006 (temperature_gradient -
1007 normalized_phase_indicator_gradient *
1008 (normalized_phase_indicator_gradient * temperature_gradient)) *
1009 filtered_phase_gradient_norm;
1010
1011 strong_residual[q] += marangoni_effect + surface_tension_force;
1012
1013 for (unsigned int i = 0; i < n_dofs; ++i)
1014 {
1015 const auto phi_u_i = scratch_data.phi_u[q][i];
1016 double local_rhs_i = 0;
1017
1018 local_rhs_i -= (marangoni_effect + surface_tension_force) * phi_u_i;
1019 local_rhs(i) += local_rhs_i * JxW_value;
1020 }
1021 }
1022}
1023
1026
1027
1028template <int dim>
1029void
1031 const NavierStokesScratchData<dim> &scratch_data,
1033{
1034 // The recoil pressure force does not depend on the velocity or the pressure,
1035 // so it has no contribution to the Jacobian. However, it must still be added
1036 // to the strong residual since the SUPG term of the Jacobian depends on it.
1037 const unsigned int n_q_points = scratch_data.n_q_points;
1038
1039 auto &strong_residual = copy_data.strong_residual;
1040
1041 for (unsigned int q = 0; q < n_q_points; ++q)
1042 {
1043 // Only temporary, should change if the evaporation also depends on the
1044 // species concentration
1045 std::map<field, double> field_value;
1046 if (this->evaporation_model->depends_on(field::temperature))
1047 {
1048 field_value[field::temperature] = scratch_data.temperature_values[q];
1049 }
1050
1051 const double recoil_pressure =
1052 this->evaporation_model->momentum_flux(field_value);
1053
1054 const Tensor<1, dim> &phase_gradient_value_q =
1055 scratch_data.phase_gradient_values[q];
1056
1057 const Tensor<1, dim> normalized_phase_indicator_gradient =
1058 phase_gradient_value_q / (phase_gradient_value_q.norm() + 1e-15);
1059
1060 const Tensor<1, dim> recoil_pressure_force =
1061 recoil_pressure * normalized_phase_indicator_gradient *
1062 scratch_data.filtered_phase_gradient_values[q].norm();
1063
1064 strong_residual[q] -= recoil_pressure_force;
1065 }
1066}
1067
1068template <int dim>
1069void
1071 const NavierStokesScratchData<dim> &scratch_data,
1073{
1074 // Loop and quadrature information
1075 const auto &JxW = scratch_data.JxW;
1076 const unsigned int n_q_points = scratch_data.n_q_points;
1077 const unsigned int n_dofs = scratch_data.n_dofs;
1078
1079 // Copy data elements
1080 auto &strong_residual = copy_data.strong_residual;
1081 auto &local_rhs = copy_data.local_rhs;
1082
1083 // Loop over the quadrature points
1084 for (unsigned int q = 0; q < n_q_points; ++q)
1085 {
1086 // Only temporary, should change if the evaporation also depends on the
1087 // species concentration
1088 std::map<field, double> field_value;
1089 if (this->evaporation_model->depends_on(field::temperature))
1090 {
1091 field_value[field::temperature] = scratch_data.temperature_values[q];
1092 }
1093
1094 // Recoil pressure
1095 const double recoil_pressure =
1096 this->evaporation_model->momentum_flux(field_value);
1097
1098 // Gather phase indicator gradient
1099 const Tensor<1, dim> &phase_gradient_value_q =
1100 scratch_data.phase_gradient_values[q];
1101
1102 const Tensor<1, dim> &filtered_phase_gradient_value_q =
1103 scratch_data.filtered_phase_gradient_values[q];
1104
1105 const double phase_gradient_norm = phase_gradient_value_q.norm();
1106
1107 const double filtered_phase_gradient_norm =
1108 filtered_phase_gradient_value_q.norm();
1109
1110 const Tensor<1, dim> normalized_phase_indicator_gradient =
1111 phase_gradient_value_q / (phase_gradient_norm + 1e-15);
1112
1113
1114 const double JxW_value = JxW[q];
1115
1116 const Tensor<1, dim> recoil_pressure_force =
1117 recoil_pressure * normalized_phase_indicator_gradient *
1118 filtered_phase_gradient_norm;
1119
1120 strong_residual[q] -= recoil_pressure_force;
1121
1122 for (unsigned int i = 0; i < n_dofs; ++i)
1123 {
1124 const auto phi_u_i = scratch_data.phi_u[q][i];
1125 double local_rhs_i = 0;
1126
1127 local_rhs_i += recoil_pressure_force * phi_u_i;
1128 local_rhs(i) += local_rhs_i * JxW_value;
1129 }
1130 }
1131}
1132
1135
1136
1137template <int dim>
1138void
1140 const NavierStokesScratchData<dim> &scratch_data,
1142{
1143 const std::vector<double> &viscosity_for_stabilization_vector =
1145
1146 // Loop and quadrature information
1147 const auto &JxW_vec = scratch_data.JxW;
1148 const unsigned int n_q_points = scratch_data.n_q_points;
1149 const unsigned int n_dofs = scratch_data.n_dofs;
1150 const double h = scratch_data.cell_size;
1151
1152 // Copy data elements
1153 auto &strong_residual_vec = copy_data.strong_residual;
1154 auto &strong_jacobian_vec = copy_data.strong_jacobian;
1155 auto &local_matrix = copy_data.local_matrix;
1156
1157 // Time steps and inverse time steps which is used for stabilization constant
1158 std::vector<double> time_steps_vector =
1159 this->simulation_control->get_time_steps_vector();
1160 const double dt = time_steps_vector[0];
1161 const double sdt = 1. / dt;
1162
1163 Assert(
1165 RequiresConstantDensity(
1166 "GLSNavierStokesCLSAssemblerNonNewtonianCore<dim>::assemble_matrix"));
1167
1168 // Loop over the quadrature points
1169 for (unsigned int q = 0; q < n_q_points; ++q)
1170 {
1171 // Gather into local variables the relevant fields
1172 const Tensor<1, dim> &velocity = scratch_data.velocity_values[q];
1173 const Tensor<2, dim> &velocity_gradient =
1174 scratch_data.velocity_gradients[q];
1175 const Tensor<1, dim> &velocity_laplacian =
1176 scratch_data.velocity_laplacians[q];
1177 const Tensor<3, dim> &velocity_hessian =
1178 scratch_data.velocity_hessians[q];
1179 const Tensor<1, dim> &pressure_gradient =
1180 scratch_data.pressure_gradients[q];
1181
1182 // Calculate shear rate (at each q)
1183 const Tensor<2, dim> shear_rate =
1184 velocity_gradient + transpose(velocity_gradient);
1185
1186 // Calculate the shear rate magnitude
1187 double shear_rate_magnitude = calculate_shear_rate_magnitude(shear_rate);
1188 // Set the shear rate magnitude to 1e-12 if it is too close to zero,
1189 // since the viscosity gradient is undefined for shear_rate_magnitude = 0
1190 shear_rate_magnitude =
1191 shear_rate_magnitude > 1e-12 ? shear_rate_magnitude : 1e-12;
1192
1193 // Calculate kinematic viscosity gradient
1194 const Tensor<1, dim> kinematic_viscosity_gradient =
1196 velocity_gradient,
1197 velocity_hessian,
1198 shear_rate_magnitude,
1199 scratch_data.grad_kinematic_viscosity_shear_rate[q]);
1200
1201 // Forcing term
1202 Tensor<1, dim> force = scratch_data.force[q];
1203
1204 // Calculation of the magnitude of the velocity for the
1205 // stabilization parameter
1206 const double u_mag = std::max(velocity.norm(), 1e-12);
1207
1208 // Store JxW in local variable for faster access;
1209 const double JxW = JxW_vec[q];
1210
1211 // Calculation of the equivalent properties at the quadrature point
1212 double density_eq = scratch_data.density[q];
1213 const double dynamic_viscosity_eq = scratch_data.dynamic_viscosity[q];
1214 const Tensor<1, dim> dynamic_viscosity_gradient =
1215 density_eq * kinematic_viscosity_gradient;
1216
1217 // Calculation of the GLS stabilization parameter. The
1218 // stabilization parameter used is different if the simulation
1219 // is steady or unsteady. In the unsteady case it includes the
1220 // value of the time step
1221 const double tau =
1222 this->simulation_control->get_assembly_method() ==
1225 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h) :
1227 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h, sdt);
1228
1229
1230 // Calculate the strong residual for GLS stabilization.
1231 // According to the mathematical formulation, the viscosity jump term
1232 // (-dynamic_viscosity_jump * (shear_rate * filtered_phase_gradient))
1233 // should be included. However, it is ill-posed for phase change cases
1234 // where the solid is represented by a highly viscous fluid. Hence, we
1235 // don't consider this term in the current formulation.
1236 auto strong_residual = density_eq * velocity_gradient * velocity +
1237 pressure_gradient -
1238 shear_rate * dynamic_viscosity_gradient -
1239 dynamic_viscosity_eq * velocity_laplacian -
1240 density_eq * force + strong_residual_vec[q];
1241 /*- dynamic_viscosity_jump * (shear_rate * filtered_phase_gradient);*/
1242
1243 std::vector<Tensor<1, dim>> grad_phi_u_j_x_velocity(n_dofs);
1244 std::vector<Tensor<1, dim>> velocity_gradient_x_phi_u_j(n_dofs);
1245
1246 // Pressure scaling factor
1247 const double pressure_scaling_factor =
1248 scratch_data.pressure_scaling_factor;
1249
1250 // We loop over the column first to prevent recalculation
1251 // of the strong jacobian in the inner loop
1252 for (unsigned int j = 0; j < n_dofs; ++j)
1253 {
1254 const auto &phi_u_j = scratch_data.phi_u[q][j];
1255 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
1256 const auto &laplacian_phi_u_j = scratch_data.laplacian_phi_u[q][j];
1257
1258 const auto &grad_phi_p_j =
1259 scratch_data.grad_phi_p[q][j] * pressure_scaling_factor;
1260
1261 const auto &grad_phi_u_j_non_newtonian =
1262 grad_phi_u_j + transpose(grad_phi_u_j);
1263
1264 strong_jacobian_vec[q][j] +=
1265 density_eq * velocity_gradient * phi_u_j +
1266 density_eq * grad_phi_u_j * velocity + grad_phi_p_j -
1267 dynamic_viscosity_eq * laplacian_phi_u_j -
1268 grad_phi_u_j_non_newtonian * dynamic_viscosity_gradient;
1269
1270 // Store these temporary products in auxiliary variables for speed
1271 grad_phi_u_j_x_velocity[j] = grad_phi_u_j * velocity;
1272 velocity_gradient_x_phi_u_j[j] = velocity_gradient * phi_u_j;
1273 }
1274
1275 shear_rate_magnitude =
1276 shear_rate_magnitude > 1e-3 ? shear_rate_magnitude : 1e-3;
1277
1278 for (unsigned int i = 0; i < n_dofs; ++i)
1279 {
1280 const auto &phi_u_i = scratch_data.phi_u[q][i];
1281 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
1282 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
1283 const auto &phi_p_i = scratch_data.phi_p[q][i];
1284 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
1285
1286 // Store these temporary products in auxiliary variables for speed
1287 const auto grad_phi_u_i_x_velocity = grad_phi_u_i * velocity;
1288 const auto strong_residual_x_grad_phi_u_i =
1289 strong_residual * grad_phi_u_i;
1290
1291 for (unsigned int j = 0; j < n_dofs; ++j)
1292 {
1293 const auto &phi_u_j = scratch_data.phi_u[q][j];
1294 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
1295 const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
1296
1297 const auto &grad_phi_u_j_non_newtonian =
1298 grad_phi_u_j + transpose(grad_phi_u_j);
1299
1300 const auto &phi_p_j =
1301 scratch_data.phi_p[q][j] * pressure_scaling_factor;
1302
1303 const auto &strong_jac = strong_jacobian_vec[q][j];
1304
1305 double local_matrix_ij =
1306 dynamic_viscosity_eq *
1307 scalar_product(grad_phi_u_j_non_newtonian, grad_phi_u_i) +
1308 0.5 * scratch_data.grad_kinematic_viscosity_shear_rate[q] /
1309 shear_rate_magnitude *
1310 scalar_product(grad_phi_u_j_non_newtonian, shear_rate) *
1311 scalar_product(shear_rate, grad_phi_u_i) +
1312 density_eq * velocity_gradient_x_phi_u_j[j] * phi_u_i +
1313 density_eq * grad_phi_u_j_x_velocity[j] * phi_u_i -
1314 div_phi_u_i * phi_p_j;
1315
1316 // Continuity
1317 local_matrix_ij += phi_p_i * div_phi_u_j;
1318
1319 // PSPG GLS term
1320 local_matrix_ij += tau * (strong_jac * grad_phi_p_i);
1321
1322 // The jacobian matrix for the SUPG formulation
1323 // currently does not include the jacobian of the stabilization
1324 // parameter tau. Our experience has shown that does not alter the
1325 // number of newton iteration for convergence, but greatly
1326 // simplifies assembly.
1327 if (SUPG)
1328 {
1329 local_matrix_ij +=
1330 tau * (strong_jac * grad_phi_u_i_x_velocity +
1331 strong_residual_x_grad_phi_u_i * phi_u_j);
1332 }
1333 local_matrix_ij *= JxW;
1334 local_matrix(i, j) += local_matrix_ij;
1335 }
1336 }
1337 }
1338}
1339
1340template <int dim>
1341void
1343 const NavierStokesScratchData<dim> &scratch_data,
1345{
1346 const std::vector<double> &viscosity_for_stabilization_vector =
1348
1349 // Loop and quadrature information
1350 const auto &JxW_vec = scratch_data.JxW;
1351 const unsigned int n_q_points = scratch_data.n_q_points;
1352 const unsigned int n_dofs = scratch_data.n_dofs;
1353 const double h = scratch_data.cell_size;
1354
1355 // Copy data elements
1356 auto &strong_residual_vec = copy_data.strong_residual;
1357 auto &local_rhs = copy_data.local_rhs;
1358
1359 // Time steps and inverse time steps which is used for stabilization constant
1360 std::vector<double> time_steps_vector =
1361 this->simulation_control->get_time_steps_vector();
1362 const double dt = time_steps_vector[0];
1363 const double sdt = 1. / dt;
1364
1365 Assert(scratch_data.properties_manager.density_is_constant(),
1366 RequiresConstantDensity(
1367 "GLSNavierStokesCLSAssemblerNonNewtonianCore<dim>::assemble_rhs"));
1368
1369 // Loop over the quadrature points
1370 for (unsigned int q = 0; q < n_q_points; ++q)
1371 {
1372 // Velocity
1373 const Tensor<1, dim> &velocity = scratch_data.velocity_values[q];
1374 const double velocity_divergence = scratch_data.velocity_divergences[q];
1375 const Tensor<2, dim> &velocity_gradient =
1376 scratch_data.velocity_gradients[q];
1377 const Tensor<1, dim> &velocity_laplacian =
1378 scratch_data.velocity_laplacians[q];
1379 const Tensor<3, dim> &velocity_hessian =
1380 scratch_data.velocity_hessians[q];
1381
1382 // Calculate shear rate (at each q)
1383 const Tensor<2, dim> shear_rate =
1384 velocity_gradient + transpose(velocity_gradient);
1385
1386 // Calculate the shear rate magnitude
1387 double shear_rate_magnitude = calculate_shear_rate_magnitude(shear_rate);
1388
1389 shear_rate_magnitude =
1390 shear_rate_magnitude > 1e-12 ? shear_rate_magnitude : 1e-12;
1391
1392 // Calculate kinematic viscosity gradient
1393 const Tensor<1, dim> kinematic_viscosity_gradient =
1395 velocity_gradient,
1396 velocity_hessian,
1397 shear_rate_magnitude,
1398 scratch_data.grad_kinematic_viscosity_shear_rate[q]);
1399
1400 // Pressure
1401 const double pressure = scratch_data.pressure_values[q];
1402 const Tensor<1, dim> pressure_gradient =
1403 scratch_data.pressure_gradients[q];
1404
1405 // Forcing term
1406 Tensor<1, dim> force = scratch_data.force[q];
1407
1408 // Calculation of the magnitude of the
1409 // velocity for the stabilization parameter
1410 const double u_mag = std::max(velocity.norm(), 1e-12);
1411
1412 // Store JxW in local variable for faster access;
1413 const double JxW = JxW_vec[q];
1414
1415 // Calculation of the equivalent properties at the quadrature point
1416 double density_eq = scratch_data.density[q];
1417 const double dynamic_viscosity_eq = scratch_data.dynamic_viscosity[q];
1418 const Tensor<1, dim> dynamic_viscosity_gradient =
1419 density_eq * kinematic_viscosity_gradient;
1420
1421 // Calculation of the GLS stabilization parameter. The
1422 // stabilization parameter used is different if the simulation
1423 // is steady or unsteady. In the unsteady case it includes the
1424 // value of the time step
1425 const double tau =
1426 this->simulation_control->get_assembly_method() ==
1429 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h) :
1431 u_mag, viscosity_for_stabilization_vector[q] / density_eq, h, sdt);
1432
1433 // Calculate the strong residual for GLS stabilization.
1434 // According to the mathematical formulation, the viscosity jump term
1435 // (-dynamic_viscosity_jump * (shear_rate * filtered_phase_gradient))
1436 // should be included. However, it is ill-posed for phase change cases
1437 // where the solid is represented by a highly viscous fluid. Hence, we
1438 // don't consider this term in the current formulation.
1439 auto strong_residual = density_eq * velocity_gradient * velocity +
1440 pressure_gradient -
1441 shear_rate * dynamic_viscosity_gradient -
1442 dynamic_viscosity_eq * velocity_laplacian -
1443 density_eq * force + strong_residual_vec[q];
1444 /*- dynamic_viscosity_jump * (shear_rate * filtered_phase_gradient);*/
1445
1446 // Assembly of the right-hand side
1447 for (unsigned int i = 0; i < n_dofs; ++i)
1448 {
1449 const auto &phi_u_i = scratch_data.phi_u[q][i];
1450 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
1451 const auto &phi_p_i = scratch_data.phi_p[q][i];
1452 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
1453 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
1454
1455 // Navier-Stokes Residual
1456 local_rhs(i) +=
1457 (
1458 // Momentum
1459 -dynamic_viscosity_eq * scalar_product(shear_rate, grad_phi_u_i) -
1460 density_eq * velocity_gradient * velocity * phi_u_i +
1461 pressure * div_phi_u_i + density_eq * force * phi_u_i) *
1462 JxW;
1463
1464 // Continuity
1465 local_rhs(i) += -(velocity_divergence * phi_p_i) * JxW;
1466
1467 // PSPG GLS term
1468 local_rhs(i) += -tau * (strong_residual * grad_phi_p_i) * JxW;
1469
1470 // SUPG GLS term
1471 if (SUPG)
1472 {
1473 local_rhs(i) +=
1474 -tau * (strong_residual * (grad_phi_u_i * velocity)) * JxW;
1475 }
1476 }
1477 }
1478}
1479
1482
1483template <int dim>
1484void
1486 const NavierStokesScratchData<dim> &scratch_data,
1488{
1489 // The buoyancy force does not depend on the velocity or the pressure, so it
1490 // has no contribution to the Jacobian. However, it must still be added to the
1491 // strong residual since the SUPG term of the Jacobian depends on it.
1492 const unsigned int n_q_points = scratch_data.n_q_points;
1493
1494 auto &strong_residual = copy_data.strong_residual;
1495
1496 for (unsigned int q = 0; q < n_q_points; ++q)
1497 {
1498 strong_residual[q] +=
1499 scratch_data.force[q] * scratch_data.density_thermal_expansion[q] *
1500 (scratch_data.temperature_values[q] - reference_temperature);
1501 }
1502}
1503
1504template <int dim>
1505void
1507 const NavierStokesScratchData<dim> &scratch_data,
1509{
1510 // Loop and quadrature information
1511 const auto &JxW_vec = scratch_data.JxW;
1512 const unsigned int n_q_points = scratch_data.n_q_points;
1513 const unsigned int n_dofs = scratch_data.n_dofs;
1514
1515 auto &local_rhs = copy_data.local_rhs;
1516 auto &strong_residual = copy_data.strong_residual;
1517
1518 // Loop over the quadrature points
1519 for (unsigned int q = 0; q < n_q_points; ++q)
1520 {
1521 // Forcing term (gravity)
1522 const Tensor<1, dim> &force = scratch_data.force[q];
1523
1524 const double density_thermal_expansion_eq =
1525 scratch_data.density_thermal_expansion[q];
1526
1527 // Store JxW in local variable for faster access;
1528 const double JxW = JxW_vec[q];
1529
1530 // Current temperature values
1531 double current_temperature = scratch_data.temperature_values[q];
1532
1533 strong_residual[q] += force * density_thermal_expansion_eq *
1534 (current_temperature - reference_temperature);
1535
1536 // Assembly of the right-hand side
1537 for (unsigned int i = 0; i < n_dofs; ++i)
1538 {
1539 const auto phi_u_i = scratch_data.phi_u[q][i];
1540
1541 local_rhs(i) -= force * density_thermal_expansion_eq *
1542 (current_temperature - reference_temperature) *
1543 phi_u_i * JxW;
1544 }
1545 }
1546}
1547
1548template class ThermalBuoyancyAssemblyCLS<2>;
1549template class ThermalBuoyancyAssemblyCLS<3>;
unsigned int number_of_previous_solutions(const Parameters::SimulationControl::TimeSteppingMethod method)
Get the number of previous time steps for a specific BDF scheme.
Definition bdf.h:97
Assembles the transient time arising from BDF time integration for the Navier-Stokes equation with fr...
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Assembles the matrix
const std::shared_ptr< SimulationControl > simulation_control
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the rhs
Assembles the core of the Navier-Stokes equation with free surface using CLS modeling....
const std::shared_ptr< SimulationControl > simulation_control
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the rhs
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Assembles the matrix
Assembles the Marangoni effect for the Navier-Stokes equations according to the following equation:
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Adds the surface tension and Marangoni forces to the strong residual used by the stab...
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the rhs
Assembles the core of the Navier-Stokes equation using a Rheological model to predict non-Newtonian b...
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Assembles the matrix
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the rhs
Tensor< 1, dim > get_kinematic_viscosity_gradient(const Tensor< 2, dim > &velocity_gradient, const Tensor< 3, dim > &velocity_hessians, const double shear_rate_magnitude, const double grad_kinematic_viscosity_shear_rate) const
Calculates an approximation of the gradient of the viscosity.
const std::shared_ptr< SimulationControl > simulation_control
Assembles the Surface Tension Force (STF) for the Navier-Stokes equations according to the following ...
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Adds the surface tension force to the strong residual used by the stabilization terms...
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the rhs
Assembles the momentum source due to evaporation for the Navier-Stokes equations.
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Adds the recoil pressure force to the strong residual used by the stabilization terms...
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the rhs
std::shared_ptr< EvaporationModel > evaporation_model
Class that stores the information required by the assembly procedure for a Navier-Stokes equation....
std::vector< Tensor< 1, dim > > force
std::vector< double > density_thermal_expansion
std::vector< Tensor< 3, dim > > velocity_hessians
std::vector< std::vector< Tensor< 1, dim > > > previous_velocity_values
std::vector< Tensor< 1, dim > > temperature_gradients
std::vector< Tensor< 1, dim > > phase_gradient_values
std::vector< unsigned int > components
std::vector< Tensor< 2, dim > > velocity_gradients
std::vector< double > surface_tension_gradient
Table< 2, Tensor< 1, dim > > phi_u
std::vector< double > dynamic_viscosity_0
std::vector< Tensor< 1, dim > > velocity_values
Table< 2, Tensor< 2, dim > > grad_phi_u
Table< 2, Tensor< 1, dim > > laplacian_phi_u
std::vector< Tensor< 1, dim > > filtered_phase_gradient_values
std::vector< double > dynamic_viscosity_1
std::vector< double > temperature_values
std::vector< double > filtered_phase_values
std::vector< double > velocity_divergences
std::vector< double > dynamic_viscosity_for_stabilization
Values of the dynamic viscosity used in the SUPG and PSPG stabilizations.
Table< 2, Tensor< 1, dim > > grad_phi_p
std::vector< double > dynamic_viscosity
std::vector< double > grad_kinematic_viscosity_shear_rate
std::vector< Tensor< 1, dim > > pressure_gradients
std::vector< Tensor< 1, dim > > velocity_laplacians
const PhysicalPropertiesManager properties_manager
Assembler of the non-linear Carman-Kozeny permeability model for CLS simulations with phase change.
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
Assemble the right-hand side (rhs) of:
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
Assembles the matrix of:
const std::vector< double > carman_kozeny_permeability_area_inv
const std::vector< Parameters::PhaseChange > phase_change_parameters_vector
Assembles a phase change Darcy forcing term for a CLS two-fluid simulation. The term is added to the...
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Assembles the matrix of: .
const std::vector< Parameters::PhaseChange > phase_change_parameters_vector
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the weak form of:
Class responsible for storing the information calculated using the assembly of stabilized Tensor<1,...
Definition copy_data.h:166
FullMatrix< double > local_matrix
Definition copy_data.h:204
std::vector< Tensor< 1, dim > > strong_residual
Definition copy_data.h:207
std::vector< std::vector< Tensor< 1, dim > > > strong_jacobian
Definition copy_data.h:208
Assembles the thermal buoyancy source term for CLS simulations. This assembler includes density expli...
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the weak form of:
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Adds the buoyancy force to the strong residual used by the stabilization terms of the...
@ velocity
Velocity vector field from fluid dynamics.
@ pressure
Pressure scalar field from fluid dynamics.
@ temperature
Temperature scalar field from heat transfer.
double calculate_shear_rate_magnitude(const Tensor< 2, dim > shear_rate)
Calculates the magnitude of the shear rate tensor given as input.
Simulation control classes for managing time-stepping and iteration control in Lethe.
double calculate_navier_stokes_gls_tau_transient(const double u_mag, const double kinematic_viscosity, const double h, const double sdt)
Calculate the stabilization parameter for the transient Navier-Stokes equations.
double calculate_navier_stokes_gls_tau_steady(const double u_mag, const double kinematic_viscosity, const double h)
Calculate the stabilization parameter for the Navier-Stokes equations in steady-state.