Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
navier_stokes_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 // Scheme and physical properties
18 const std::vector<double> &viscosity_vector =
19 scratch_data.kinematic_viscosity;
20
21 const std::vector<double> &viscosity_for_stabilization_vector =
23
24 // Loop and quadrature information
25 const auto &JxW_vec = scratch_data.JxW;
26 const unsigned int n_q_points = scratch_data.n_q_points;
27 const unsigned int n_dofs = scratch_data.n_dofs;
28 const double h = scratch_data.cell_size;
29
30 // Copy data elements
31 auto &strong_residual_vec = copy_data.strong_residual;
32 auto &strong_jacobian_vec = copy_data.strong_jacobian;
33 auto &local_matrix = copy_data.local_matrix;
34
35 // Time steps and inverse time steps which is used for stabilization constant
36 std::vector<double> time_steps_vector =
37 this->simulation_control->get_time_steps_vector();
38 const double dt = time_steps_vector[0];
39 const double sdt = 1. / dt;
40
41 // Pressure scaling factor
42 const double pressure_scaling_factor = scratch_data.pressure_scaling_factor;
43
44 // Loop over the quadrature points
45 for (unsigned int q = 0; q < n_q_points; ++q)
46 {
47 // Gather into local variables the relevant fields
48 const double kinematic_viscosity = viscosity_vector[q];
49 const Tensor<1, dim> &velocity = scratch_data.velocity_values[q];
50 const Tensor<2, dim> &velocity_gradient =
51 scratch_data.velocity_gradients[q];
52 const Tensor<1, dim> &velocity_laplacian =
53 scratch_data.velocity_laplacians[q];
54 const Tensor<1, dim> &advective_velocity =
55 scratch_data.advective_velocity[q];
56
57 const Tensor<1, dim> &pressure_gradient =
58 scratch_data.pressure_gradients[q];
59
60 // Forcing term
61 const Tensor<1, dim> &force = scratch_data.force[q];
62 double mass_source = scratch_data.mass_source[q];
63
64 // Calculation of the magnitude of the velocity for the
65 // stabilization parameter
66 const double u_mag = std::max(advective_velocity.norm(), 1e-12);
67
68 // Store JxW in local variable for faster access;
69 const double JxW = JxW_vec[q];
70
71 // Calculation of the GLS stabilization parameter. The
72 // stabilization parameter used is different if the simulation
73 // is steady or unsteady. In the unsteady case it includes the
74 // value of the time step
75 const double tau =
76 this->simulation_control->get_assembly_method() ==
79 u_mag, viscosity_for_stabilization_vector[q], h) :
81 u_mag, viscosity_for_stabilization_vector[q], h, sdt);
82
83 // Calculate the strong residual for GLS stabilization
84 auto strong_residual = velocity_gradient * advective_velocity +
85 pressure_gradient -
86 kinematic_viscosity * velocity_laplacian - force +
87 mass_source * velocity + strong_residual_vec[q];
88
89 std::vector<Tensor<1, dim>> grad_phi_u_j_x_velocity(n_dofs);
90 std::vector<Tensor<1, dim>> velocity_gradient_x_phi_u_j(n_dofs);
91
92
93 // We loop over the column first to prevent recalculation
94 // of the strong jacobian in the inner loop
95 for (unsigned int j = 0; j < n_dofs; ++j)
96 {
97 const auto &phi_u_j = scratch_data.phi_u[q][j];
98 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
99 const auto &laplacian_phi_u_j = scratch_data.laplacian_phi_u[q][j];
100
101 const auto &grad_phi_p_j =
102 pressure_scaling_factor * scratch_data.grad_phi_p[q][j];
103
104 strong_jacobian_vec[q][j] +=
105 (velocity_gradient * phi_u_j + grad_phi_u_j * advective_velocity +
106 grad_phi_p_j - kinematic_viscosity * laplacian_phi_u_j +
107 mass_source * phi_u_j);
108
109 // Store these temporary products in auxiliary variables for speed
110 grad_phi_u_j_x_velocity[j] = grad_phi_u_j * advective_velocity;
111 velocity_gradient_x_phi_u_j[j] = velocity_gradient * phi_u_j;
112 }
113
114
115
116 for (unsigned int i = 0; i < n_dofs; ++i)
117 {
118 const int component_i = scratch_data.components[i];
119
120 const auto &phi_u_i = scratch_data.phi_u[q][i];
121 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
122 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
123 const auto &phi_p_i = scratch_data.phi_p[q][i];
124 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
125
126
127 // Store these temporary products in auxiliary variables for speed
128 const auto grad_phi_u_i_x_velocity =
129 grad_phi_u_i * advective_velocity;
130 const auto strong_residual_x_grad_phi_u_i =
131 strong_residual * grad_phi_u_i;
132
133 for (unsigned int j = 0; j < n_dofs; ++j)
134 {
135 const int component_j = scratch_data.components[j];
136
137 const auto &phi_u_j = scratch_data.phi_u[q][j];
138
139 const auto &phi_p_j =
140 pressure_scaling_factor * scratch_data.phi_p[q][j];
141
142 const auto &strong_jac = strong_jacobian_vec[q][j];
143
144 double local_matrix_ij =
145 component_j == dim ? -div_phi_u_i * phi_p_j : 0;
146 if (component_i == dim)
147 {
148 const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
149
150 local_matrix_ij += phi_p_i * div_phi_u_j;
151
152 // PSPG GLS term
153 local_matrix_ij += tau * (strong_jac * grad_phi_p_i);
154 }
155
156 if (component_i < dim && component_j < dim)
157 {
158 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
159
160 local_matrix_ij += velocity_gradient_x_phi_u_j[j] * phi_u_i +
161 grad_phi_u_j_x_velocity[j] * phi_u_i;
162
163 if (component_i == component_j)
164 {
165 local_matrix_ij +=
166 kinematic_viscosity * (grad_phi_u_j[component_j] *
167 grad_phi_u_i[component_i]) +
168 mass_source * phi_u_j * phi_u_i;
169 }
170 }
171 if (component_i < dim)
172 {
173 // The jacobian matrix for the SUPG formulation
174 // currently does not include the jacobian of the
175 // stabilization parameter tau. Our experience has shown that
176 // does not alter the number of newton iteration for
177 // convergence, but greatly simplifies assembly.
178
179 local_matrix_ij +=
180 tau * (strong_jac * grad_phi_u_i_x_velocity +
181 strong_residual_x_grad_phi_u_i * phi_u_j);
182 }
183
184 local_matrix_ij *= JxW;
185 local_matrix(i, j) += local_matrix_ij;
186 }
187 }
188 }
189}
190
191template <int dim>
192void
194 const NavierStokesScratchData<dim> &scratch_data,
196{
197 // Scheme and physical properties
198 const std::vector<double> &viscosity_vector =
199 scratch_data.kinematic_viscosity;
200
201 const std::vector<double> &viscosity_for_stabilization_vector =
203
204 // Loop and quadrature information
205 const auto &JxW_vec = scratch_data.JxW;
206 const unsigned int n_q_points = scratch_data.n_q_points;
207 const unsigned int n_dofs = scratch_data.n_dofs;
208 const double h = scratch_data.cell_size;
209
210 // Copy data elements
211 auto &strong_residual_vec = copy_data.strong_residual;
212 auto &local_rhs = copy_data.local_rhs;
213
214 // Time steps and inverse time steps which is used for stabilization constant
215 std::vector<double> time_steps_vector =
216 this->simulation_control->get_time_steps_vector();
217 const double dt = time_steps_vector[0];
218 const double sdt = 1. / dt;
219
220 // Loop over the quadrature points
221 for (unsigned int q = 0; q < n_q_points; ++q)
222 {
223 // Physical properties
224 const double kinematic_viscosity = viscosity_vector[q];
225
226 // Velocity
227 const Tensor<1, dim> &velocity = scratch_data.velocity_values[q];
228 const double velocity_divergence = scratch_data.velocity_divergences[q];
229 const Tensor<2, dim> &velocity_gradient =
230 scratch_data.velocity_gradients[q];
231 const Tensor<1, dim> &velocity_laplacian =
232 scratch_data.velocity_laplacians[q];
233 const Tensor<1, dim> &advective_velocity =
234 scratch_data.advective_velocity[q];
235
236 // Pressure
237 const double pressure = scratch_data.pressure_values[q];
238 const Tensor<1, dim> &pressure_gradient =
239 scratch_data.pressure_gradients[q];
240
241 // Forcing term
242 const Tensor<1, dim> &force = scratch_data.force[q];
243 double mass_source = scratch_data.mass_source[q];
244 // Calculation of the magnitude of the velocity for the stabilization
245 // parameter
246 const double u_mag = std::max(advective_velocity.norm(), 1e-12);
247
248 // Store JxW in local variable for faster access;
249 const double JxW = JxW_vec[q];
250
251 // Calculation of the GLS stabilization parameter. The
252 // stabilization parameter used is different if the simulation
253 // is steady or unsteady. In the unsteady case it includes the
254 // value of the time step
255 const double tau =
256 this->simulation_control->get_assembly_method() ==
259 u_mag, viscosity_for_stabilization_vector[q], h) :
261 u_mag, viscosity_for_stabilization_vector[q], h, sdt);
262
263
264
265 // Calculate the strong residual for GLS stabilization
266 auto strong_residual = velocity_gradient * advective_velocity +
267 pressure_gradient -
268 kinematic_viscosity * velocity_laplacian - force +
269 mass_source * velocity + strong_residual_vec[q];
270
271 // Assembly of the right-hand side
272 for (unsigned int i = 0; i < n_dofs; ++i)
273 {
274 const auto &phi_u_i = scratch_data.phi_u[q][i];
275 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
276 const auto &phi_p_i = scratch_data.phi_p[q][i];
277 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
278 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
279
280 double local_rhs_i = 0;
281
282 // Navier-Stokes Residual
283 local_rhs_i +=
284 (
285 // Momentum
286 -kinematic_viscosity *
287 scalar_product(velocity_gradient, grad_phi_u_i) -
288 velocity_gradient * advective_velocity * phi_u_i +
289 pressure * div_phi_u_i + force * phi_u_i -
290 mass_source * velocity * phi_u_i -
291 // Continuity
292 velocity_divergence * phi_p_i + mass_source * phi_p_i) *
293 JxW;
294
295 // PSPG GLS term
296 local_rhs_i += -tau * (strong_residual * grad_phi_p_i) * JxW;
297
298 // SUPG GLS term
299 local_rhs_i +=
300 -tau * (strong_residual * (grad_phi_u_i * advective_velocity)) *
301 JxW;
302
303 local_rhs(i) += local_rhs_i;
304 }
305 }
306}
307
308
309
312
313template <int dim>
314void
316 const NavierStokesScratchData<dim> &scratch_data,
318{
319 // Scheme and physical properties
320 const std::vector<double> &viscosity_vector =
321 scratch_data.kinematic_viscosity;
322
323 const std::vector<double> &viscosity_for_stabilization_vector =
325
326 // Loop and quadrature information
327 const auto &JxW_vec = scratch_data.JxW;
328 const unsigned int n_q_points = scratch_data.n_q_points;
329 const unsigned int n_dofs = scratch_data.n_dofs;
330 const double h = scratch_data.cell_size;
331
332 // Copy data elements
333 auto &strong_residual_vec = copy_data.strong_residual;
334 auto &strong_jacobian_vec = copy_data.strong_jacobian;
335 auto &local_matrix = copy_data.local_matrix;
336
337 // Time steps and inverse time steps which is used for stabilization constant
338 std::vector<double> time_steps_vector =
339 this->simulation_control->get_time_steps_vector();
340 const double dt = time_steps_vector[0];
341 const double sdt = 1. / dt;
342
343 // Pressure scaling factor
344 const double pressure_scaling_factor = scratch_data.pressure_scaling_factor;
345
346 // Loop over the quadrature points
347 for (unsigned int q = 0; q < n_q_points; ++q)
348 {
349 // Gather into local variables the relevant fields
350 const double kinematic_viscosity = viscosity_vector[q];
351 const Tensor<1, dim> &velocity = scratch_data.velocity_values[q];
352 const Tensor<2, dim> &velocity_gradient =
353 scratch_data.velocity_gradients[q];
354 const Tensor<1, dim> &velocity_laplacian =
355 scratch_data.velocity_laplacians[q];
356 const Tensor<1, dim> &advective_velocity =
357 scratch_data.advective_velocity[q];
358
359 const Tensor<1, dim> &pressure_gradient =
360 scratch_data.pressure_gradients[q];
361
362 // Forcing term
363 const Tensor<1, dim> &force = scratch_data.force[q];
364 double mass_source = scratch_data.mass_source[q];
365
366 // Calculation of the magnitude of the velocity for the
367 // stabilization parameter
368 const double u_mag = std::max(advective_velocity.norm(), 1e-12);
369
370 // Store JxW in local variable for faster access;
371 const double JxW = JxW_vec[q];
372
373 // Calculation of the GLS stabilization parameter. The
374 // stabilization parameter used is different if the simulation
375 // is steady or unsteady. In the unsteady case it includes the
376 // value of the time step
377 const double tau =
378 this->simulation_control->get_assembly_method() ==
381 u_mag, viscosity_for_stabilization_vector[q], h) :
383 u_mag, viscosity_for_stabilization_vector[q], h, sdt);
384
385 // LSIC stabilization term
386 const double tau_lsic = 0.5 * u_mag * h;
387
388
389 // Calculate the strong residual for GLS stabilization
390 auto strong_residual = velocity_gradient * advective_velocity +
391 pressure_gradient -
392 kinematic_viscosity * velocity_laplacian - force +
393 mass_source * velocity + strong_residual_vec[q];
394
395 std::vector<Tensor<1, dim>> grad_phi_u_j_x_velocity(n_dofs);
396 std::vector<Tensor<1, dim>> velocity_gradient_x_phi_u_j(n_dofs);
397
398
399 // We loop over the column first to prevent recalculation
400 // of the strong jacobian in the inner loop
401 for (unsigned int j = 0; j < n_dofs; ++j)
402 {
403 const auto &phi_u_j = scratch_data.phi_u[q][j];
404 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
405 const auto &laplacian_phi_u_j = scratch_data.laplacian_phi_u[q][j];
406
407 const auto &grad_phi_p_j =
408 pressure_scaling_factor * scratch_data.grad_phi_p[q][j];
409
410 strong_jacobian_vec[q][j] +=
411 (velocity_gradient * phi_u_j + grad_phi_u_j * advective_velocity +
412 grad_phi_p_j - kinematic_viscosity * laplacian_phi_u_j +
413 mass_source * phi_u_j);
414
415 // Store these temporary products in auxiliary variables for speed
416 grad_phi_u_j_x_velocity[j] = grad_phi_u_j * advective_velocity;
417 velocity_gradient_x_phi_u_j[j] = velocity_gradient * phi_u_j;
418 }
419
420 for (unsigned int i = 0; i < n_dofs; ++i)
421 {
422 const int component_i = scratch_data.components[i];
423
424 const auto &phi_u_i = scratch_data.phi_u[q][i];
425 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
426 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
427 const auto &phi_p_i = scratch_data.phi_p[q][i];
428 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
429 const auto &laplacian_phi_u_i = scratch_data.laplacian_phi_u[q][i];
430
431
432
433 // Store these temporary products in auxiliary variables for speed
434 const auto grad_phi_u_i_x_velocity =
435 grad_phi_u_i * advective_velocity;
436 const auto strong_residual_x_grad_phi_u_i =
437 strong_residual * grad_phi_u_i;
438
439 for (unsigned int j = 0; j < n_dofs; ++j)
440 {
441 const int component_j = scratch_data.components[j];
442
443 const auto &phi_u_j = scratch_data.phi_u[q][j];
444
445 const auto &phi_p_j =
446 pressure_scaling_factor * scratch_data.phi_p[q][j];
447
448 const auto &strong_jac = strong_jacobian_vec[q][j];
449
450 double local_matrix_ij =
451 component_j == dim ? -div_phi_u_i * phi_p_j : 0;
452 if (component_i == dim)
453 {
454 const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
455 local_matrix_ij += phi_p_i * div_phi_u_j; // continuity
456
457 // PSPG GLS term
458 local_matrix_ij += tau * (strong_jac * grad_phi_p_i);
459 }
460
461 if (component_i < dim && component_j < dim)
462 {
463 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
464
465 local_matrix_ij += velocity_gradient_x_phi_u_j[j] * phi_u_i +
466 grad_phi_u_j_x_velocity[j] * phi_u_i;
467
468 // LSIC GLS term
469 const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
470 local_matrix_ij += tau_lsic * (div_phi_u_i * div_phi_u_j);
471
472 if (component_i == component_j)
473 {
474 local_matrix_ij +=
475 kinematic_viscosity * (grad_phi_u_j[component_j] *
476 grad_phi_u_i[component_i]) +
477 mass_source * phi_u_j * phi_u_i;
478 }
479 }
480 if (component_i < dim)
481 {
482 // The jacobian matrix for the SUPG formulation
483 // currently does not include the jacobian of the
484 // stabilization parameter tau. Our experience has shown that
485 // does not alter the number of newton iteration for
486 // convergence, but greatly simplifies assembly.
487 local_matrix_ij +=
488 tau *
489 (strong_jac * (grad_phi_u_i_x_velocity -
490 kinematic_viscosity * laplacian_phi_u_i) +
491 strong_residual_x_grad_phi_u_i * phi_u_j);
492 }
493
494 local_matrix_ij *= JxW;
495 local_matrix(i, j) += local_matrix_ij;
496 }
497 }
498 }
499}
500
501template <int dim>
502void
504 const NavierStokesScratchData<dim> &scratch_data,
506{
507 // Scheme and physical properties
508 const std::vector<double> &viscosity_vector =
509 scratch_data.kinematic_viscosity;
510
511 const std::vector<double> &viscosity_for_stabilization_vector =
513
514 // Loop and quadrature information
515 const auto &JxW_vec = scratch_data.JxW;
516 const unsigned int n_q_points = scratch_data.n_q_points;
517 const unsigned int n_dofs = scratch_data.n_dofs;
518 const double h = scratch_data.cell_size;
519
520 // Copy data elements
521 auto &strong_residual_vec = copy_data.strong_residual;
522 auto &local_rhs = copy_data.local_rhs;
523
524 // Time steps and inverse time steps which is used for stabilization constant
525 std::vector<double> time_steps_vector =
526 this->simulation_control->get_time_steps_vector();
527 const double dt = time_steps_vector[0];
528 const double sdt = 1. / dt;
529
530 // Loop over the quadrature points
531 for (unsigned int q = 0; q < n_q_points; ++q)
532 {
533 // Physical properties
534 const double kinematic_viscosity = viscosity_vector[q];
535
536 // Velocity
537 const Tensor<1, dim> &velocity = scratch_data.velocity_values[q];
538 const double velocity_divergence = scratch_data.velocity_divergences[q];
539 const Tensor<2, dim> &velocity_gradient =
540 scratch_data.velocity_gradients[q];
541 const Tensor<1, dim> &velocity_laplacian =
542 scratch_data.velocity_laplacians[q];
543 const Tensor<1, dim> &advective_velocity =
544 scratch_data.advective_velocity[q];
545
546 // Pressure
547 const double pressure = scratch_data.pressure_values[q];
548 const Tensor<1, dim> &pressure_gradient =
549 scratch_data.pressure_gradients[q];
550
551 // Forcing term
552 const Tensor<1, dim> &force = scratch_data.force[q];
553 double mass_source = scratch_data.mass_source[q];
554 // Calculation of the magnitude of the
555 // velocity for the stabilization parameter
556 const double u_mag = std::max(advective_velocity.norm(), 1e-12);
557
558 // Store JxW in local variable for faster access;
559 const double JxW = JxW_vec[q];
560
561 // Calculation of the GLS stabilization parameter. The
562 // stabilization parameter used is different if the simulation
563 // is steady or unsteady. In the unsteady case it includes the
564 // value of the time step
565 const double tau =
566 this->simulation_control->get_assembly_method() ==
569 u_mag, viscosity_for_stabilization_vector[q], h) :
571 u_mag, viscosity_for_stabilization_vector[q], h, sdt);
572
573
574 // LSIC stabilization term
575 const double tau_lsic = u_mag * h / 2;
576
577
578 // Calculate the strong residual for GLS stabilization
579 auto strong_residual = velocity_gradient * advective_velocity +
580 pressure_gradient -
581 kinematic_viscosity * velocity_laplacian - force +
582 mass_source * velocity + strong_residual_vec[q];
583
584 // Assembly of the right-hand side
585 for (unsigned int i = 0; i < n_dofs; ++i)
586 {
587 const auto &phi_u_i = scratch_data.phi_u[q][i];
588 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
589 const auto &phi_p_i = scratch_data.phi_p[q][i];
590 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
591 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
592 const auto &laplacian_phi_u_i = scratch_data.laplacian_phi_u[q][i];
593
594
595 double local_rhs_i = 0;
596
597 // Navier-Stokes Residual
598 local_rhs_i +=
599 (
600 // Momentum
601 -kinematic_viscosity *
602 scalar_product(velocity_gradient, grad_phi_u_i) -
603 velocity_gradient * advective_velocity * phi_u_i +
604 pressure * div_phi_u_i + force * phi_u_i -
605 mass_source * velocity * phi_u_i -
606 // Continuity
607 velocity_divergence * phi_p_i + mass_source * phi_p_i) *
608 JxW;
609
610 // PSPG GLS term
611 local_rhs_i += -tau * (strong_residual * grad_phi_p_i) * JxW;
612
613 // LSIC GLS term
614 local_rhs_i += -tau_lsic * (div_phi_u_i * velocity_divergence) * JxW;
615
616 // SUPG GLS term
617 local_rhs_i +=
618 -tau *
619 (strong_residual * (grad_phi_u_i * advective_velocity -
620 kinematic_viscosity * laplacian_phi_u_i)) *
621 JxW;
622
623 local_rhs(i) += local_rhs_i;
624 }
625 }
626}
627
628
629
632
633template <int dim>
634void
636 const NavierStokesScratchData<dim> &scratch_data,
638{
639 // Scheme and physical properties
640 const std::vector<double> &viscosity_vector =
641 scratch_data.kinematic_viscosity;
642
643 const std::vector<double> &viscosity_for_stabilization_vector =
645
646 // Loop and quadrature information
647 const auto &JxW_vec = scratch_data.JxW;
648 const unsigned int n_q_points = scratch_data.n_q_points;
649 const unsigned int n_dofs = scratch_data.n_dofs;
650 const double h = scratch_data.cell_size;
651
652 // Copy data elements
653 auto &strong_residual_vec = copy_data.strong_residual;
654 auto &strong_jacobian_vec = copy_data.strong_jacobian;
655 auto &local_matrix = copy_data.local_matrix;
656
657 // Time steps and inverse time steps which is used for stabilization constant
658 std::vector<double> time_steps_vector =
659 this->simulation_control->get_time_steps_vector();
660 const double dt = time_steps_vector[0];
661 const double sdt = 1. / dt;
662
663 // Pressure scaling factor
664 const double pressure_scaling_factor = scratch_data.pressure_scaling_factor;
665
666 // Loop over the quadrature points
667 for (unsigned int q = 0; q < n_q_points; ++q)
668 {
669 // Gather into local variables the relevant fields
670 const double kinematic_viscosity = viscosity_vector[q];
671
672 const Tensor<1, dim> &velocity = scratch_data.velocity_values[q];
673 const Tensor<2, dim> &velocity_gradient =
674 scratch_data.velocity_gradients[q];
675 const Tensor<1, dim> &velocity_laplacian =
676 scratch_data.velocity_laplacians[q];
677 const Tensor<3, dim> &velocity_hessian =
678 scratch_data.velocity_hessians[q];
679 const Tensor<1, dim> &pressure_gradient =
680 scratch_data.pressure_gradients[q];
681 const Tensor<1, dim> &advective_velocity =
682 scratch_data.advective_velocity[q];
683
684 // Calculate shear rate (at each q)
685 const Tensor<2, dim> shear_rate =
686 velocity_gradient + transpose(velocity_gradient);
687
688 // Calculate the shear rate magnitude
689 double shear_rate_magnitude = calculate_shear_rate_magnitude(shear_rate);
690 // Set the shear rate magnitude to 1e-12 if it is too close to zero,
691 // since the viscosity gradient is undefined for shear_rate_magnitude = 0
692 shear_rate_magnitude =
693 shear_rate_magnitude > 1e-12 ? shear_rate_magnitude : 1e-12;
694
695 // Calculate viscosity gradient
696 const Tensor<1, dim> viscosity_gradient =
698 velocity_gradient,
699 velocity_hessian,
700 shear_rate_magnitude,
702
703 // Forcing term
704 const Tensor<1, dim> force = scratch_data.force[q];
705 double mass_source = scratch_data.mass_source[q];
706
707 // Calculation of the magnitude of the velocity for the
708 // stabilization parameter
709 const double u_mag = std::max(advective_velocity.norm(), 1e-12);
710
711 // Store JxW in local variable for faster access;
712 const double JxW = JxW_vec[q];
713
714 // Calculation of the GLS stabilization parameter. The
715 // stabilization parameter used is different if the simulation
716 // is steady or unsteady. In the unsteady case it includes the
717 // value of the time step
718 const double tau =
719 this->simulation_control->get_assembly_method() ==
722 u_mag, viscosity_for_stabilization_vector[q], h) :
724 u_mag, viscosity_for_stabilization_vector[q], h, sdt);
725
726 // Calculate the strong residual for GLS stabilization
727 auto strong_residual = velocity_gradient * advective_velocity +
728 pressure_gradient -
729 shear_rate * viscosity_gradient -
730 kinematic_viscosity * velocity_laplacian - force +
731 mass_source * velocity + strong_residual_vec[q];
732
733 std::vector<Tensor<1, dim>> grad_phi_u_j_x_velocity(n_dofs);
734 std::vector<Tensor<1, dim>> velocity_gradient_x_phi_u_j(n_dofs);
735
736
737 // We loop over the column first to prevent recalculation
738 // of the strong jacobian in the inner loop
739 for (unsigned int j = 0; j < n_dofs; ++j)
740 {
741 const auto &phi_u_j = scratch_data.phi_u[q][j];
742 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
743 const auto &laplacian_phi_u_j = scratch_data.laplacian_phi_u[q][j];
744
745 const auto &grad_phi_p_j =
746 pressure_scaling_factor * scratch_data.grad_phi_p[q][j];
747
748 const auto &grad_phi_u_j_non_newtonian =
749 grad_phi_u_j + transpose(grad_phi_u_j);
750
751 strong_jacobian_vec[q][j] +=
752 (velocity_gradient * phi_u_j + grad_phi_u_j * advective_velocity +
753 grad_phi_p_j - kinematic_viscosity * laplacian_phi_u_j -
754 grad_phi_u_j_non_newtonian * viscosity_gradient +
755 mass_source * phi_u_j);
756
757 // Store these temporary products in auxiliary variables for speed
758 grad_phi_u_j_x_velocity[j] = grad_phi_u_j * advective_velocity;
759 velocity_gradient_x_phi_u_j[j] = velocity_gradient * phi_u_j;
760 }
761
762 shear_rate_magnitude =
763 shear_rate_magnitude > 1e-3 ? shear_rate_magnitude : 1e-3;
764
765 for (unsigned int i = 0; i < n_dofs; ++i)
766 {
767 const auto &phi_u_i = scratch_data.phi_u[q][i];
768 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
769 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
770 const auto &phi_p_i = scratch_data.phi_p[q][i];
771 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
772
773 // Store these temporary products in auxiliary variables for speed
774 const auto grad_phi_u_i_x_velocity =
775 grad_phi_u_i * advective_velocity;
776 const auto strong_residual_x_grad_phi_u_i =
777 strong_residual * grad_phi_u_i;
778
779 for (unsigned int j = 0; j < n_dofs; ++j)
780 {
781 const auto &phi_u_j = scratch_data.phi_u[q][j];
782 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
783 const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
784
785 const auto &grad_phi_u_j_non_newtonian =
786 grad_phi_u_j + transpose(grad_phi_u_j);
787
788 const auto &phi_p_j =
789 pressure_scaling_factor * scratch_data.phi_p[q][j];
790
791 const auto &strong_jac = strong_jacobian_vec[q][j];
792
793 double local_matrix_ij =
794 kinematic_viscosity *
795 scalar_product(grad_phi_u_j_non_newtonian, grad_phi_u_i) +
796 0.5 * scratch_data.grad_kinematic_viscosity_shear_rate[q] /
797 shear_rate_magnitude *
798 scalar_product(grad_phi_u_j_non_newtonian, shear_rate) *
799 scalar_product(shear_rate, grad_phi_u_i) +
800 velocity_gradient_x_phi_u_j[j] * phi_u_i +
801 grad_phi_u_j_x_velocity[j] * phi_u_i - div_phi_u_i * phi_p_j +
802 mass_source * phi_u_j * phi_u_i +
803 // Continuity
804 phi_p_i * div_phi_u_j;
805
806 // PSPG GLS term
807 local_matrix_ij += tau * (strong_jac * grad_phi_p_i);
808
809 // The jacobian matrix for the SUPG formulation
810 // currently does not include the jacobian of the stabilization
811 // parameter tau. Our experience has shown that does not alter the
812 // number of newton iteration for convergence, but greatly
813 // simplifies assembly.
814 if (SUPG)
815 {
816 local_matrix_ij +=
817 tau * (strong_jac * grad_phi_u_i_x_velocity +
818 strong_residual_x_grad_phi_u_i * phi_u_j);
819 }
820 local_matrix_ij *= JxW;
821 local_matrix(i, j) += local_matrix_ij;
822 }
823 }
824 }
825}
826
827template <int dim>
828void
830 const NavierStokesScratchData<dim> &scratch_data,
832{
833 // Scheme and physical properties
834 const std::vector<double> &viscosity_vector =
835 scratch_data.kinematic_viscosity;
836
837 const std::vector<double> &viscosity_for_stabilization_vector =
839
840 // Loop and quadrature information
841 const auto &JxW_vec = scratch_data.JxW;
842 const unsigned int n_q_points = scratch_data.n_q_points;
843 const unsigned int n_dofs = scratch_data.n_dofs;
844 const double h = scratch_data.cell_size;
845
846 // Copy data elements
847 auto &strong_residual_vec = copy_data.strong_residual;
848 auto &local_rhs = copy_data.local_rhs;
849
850 // Time steps and inverse time steps which is used for stabilization constant
851 std::vector<double> time_steps_vector =
852 this->simulation_control->get_time_steps_vector();
853 const double dt = time_steps_vector[0];
854 const double sdt = 1. / dt;
855
856 // Loop over the quadrature points
857 for (unsigned int q = 0; q < n_q_points; ++q)
858 {
859 // Physical properties
860 const double kinematic_viscosity = viscosity_vector[q];
861
862 // Velocity
863 const Tensor<1, dim> &velocity = scratch_data.velocity_values[q];
864 const double velocity_divergence = scratch_data.velocity_divergences[q];
865 const Tensor<2, dim> &velocity_gradient =
866 scratch_data.velocity_gradients[q];
867 const Tensor<1, dim> &velocity_laplacian =
868 scratch_data.velocity_laplacians[q];
869 const Tensor<3, dim> &velocity_hessian =
870 scratch_data.velocity_hessians[q];
871 const Tensor<1, dim> &advective_velocity =
872 scratch_data.advective_velocity[q];
873
874 // Calculate shear rate (at each q)
875 const Tensor<2, dim> shear_rate =
876 velocity_gradient + transpose(velocity_gradient);
877
878 // Calculate the shear rate magnitude
879 double shear_rate_magnitude = calculate_shear_rate_magnitude(shear_rate);
880
881 shear_rate_magnitude =
882 shear_rate_magnitude > 1e-12 ? shear_rate_magnitude : 1e-12;
883
884 // Calculate kinematic viscosity gradient
885 const Tensor<1, dim> kinematic_viscosity_gradient =
887 velocity_gradient,
888 velocity_hessian,
889 shear_rate_magnitude,
891
892 // Pressure
893 const double pressure = scratch_data.pressure_values[q];
894 const Tensor<1, dim> pressure_gradient =
895 scratch_data.pressure_gradients[q];
896
897 // Forcing term
898 const Tensor<1, dim> force = scratch_data.force[q];
899 double mass_source = scratch_data.mass_source[q];
900 // Calculation of the magnitude of the
901 // velocity for the stabilization parameter
902 const double u_mag = std::max(advective_velocity.norm(), 1e-12);
903
904 // Store JxW in local variable for faster access;
905 const double JxW = JxW_vec[q];
906
907 // Calculation of the GLS stabilization parameter. The
908 // stabilization parameter used is different if the simulation
909 // is steady or unsteady. In the unsteady case it includes the
910 // value of the time step
911 const double tau =
912 this->simulation_control->get_assembly_method() ==
915 u_mag, viscosity_for_stabilization_vector[q], h) :
917 u_mag, viscosity_for_stabilization_vector[q], h, sdt);
918
919
920 // Calculate the strong residual for GLS stabilization
921 auto strong_residual = velocity_gradient * advective_velocity +
922 pressure_gradient -
923 shear_rate * kinematic_viscosity_gradient -
924 kinematic_viscosity * velocity_laplacian - force +
925 mass_source * velocity + strong_residual_vec[q];
926
927 // Assembly of the right-hand side
928 for (unsigned int i = 0; i < n_dofs; ++i)
929 {
930 const auto &phi_u_i = scratch_data.phi_u[q][i];
931 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
932 const auto &phi_p_i = scratch_data.phi_p[q][i];
933 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
934 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
935
936 double local_rhs_i = 0;
937
938 // Navier-Stokes Residual
939 local_rhs_i +=
940 (
941 // Momentum
942 -kinematic_viscosity * scalar_product(shear_rate, grad_phi_u_i) -
943 velocity_gradient * advective_velocity * phi_u_i +
944 pressure * div_phi_u_i + force * phi_u_i -
945 mass_source * velocity * phi_u_i -
946 // Continuity
947 velocity_divergence * phi_p_i + mass_source * phi_p_i) *
948 JxW;
949
950 // PSPG GLS term
951 local_rhs_i += -tau * (strong_residual * grad_phi_p_i) * JxW;
952
953 // SUPG GLS term
954 if (SUPG)
955 {
956 local_rhs_i +=
957 -tau * (strong_residual * (grad_phi_u_i * advective_velocity)) *
958 JxW;
959 }
960 local_rhs(i) += local_rhs_i;
961 }
962 }
963}
964
967
968
969template <int dim>
970void
972 const NavierStokesScratchData<dim> &scratch_data,
974{
975 // Loop and quadrature information
976 const auto &JxW = scratch_data.JxW;
977 const unsigned int n_q_points = scratch_data.n_q_points;
978 const unsigned int n_dofs = scratch_data.n_dofs;
979
980 // Copy data elements
981 auto &strong_residual = copy_data.strong_residual;
982 auto &strong_jacobian = copy_data.strong_jacobian;
983 auto &local_matrix = copy_data.local_matrix;
984
985 // SRF Source term
986 //----------------------------------
987 // Angular velocity of the rotating frame. This is always a 3D vector even
988 // in 2D.
989 Tensor<1, dim> omega_vector;
990
991 double omega_z = velocity_sources.omega_z;
992 omega_vector[0] = velocity_sources.omega_x;
993 omega_vector[1] = velocity_sources.omega_y;
994 if (dim == 3)
995 omega_vector[2] = velocity_sources.omega_z;
996
997 // Loop over the quadrature points
998 for (unsigned int q = 0; q < n_q_points; ++q)
999 {
1000 // Velocity
1001 const std::vector<Tensor<1, dim>> velocity = {
1002 scratch_data.velocity_values[q]};
1003
1004 if (dim == 2)
1005 {
1006 strong_residual[q] +=
1007 2 * omega_z * (-1.) * cross_product_2d(velocity[0]);
1008 auto centrifugal =
1009 omega_z * (-1.) *
1010 cross_product_2d(
1011 omega_z * (-1.) *
1012 cross_product_2d(scratch_data.quadrature_points[q]));
1013 strong_residual[q] += centrifugal;
1014 }
1015 else // dim == 3
1016 {
1017 strong_residual[q] += 2 * cross_product_3d(omega_vector, velocity[0]);
1018 strong_residual[q] += cross_product_3d(
1019 omega_vector,
1020 cross_product_3d(omega_vector, scratch_data.quadrature_points[q]));
1021 }
1022
1023 for (unsigned int j = 0; j < n_dofs; ++j)
1024 {
1025 const auto &phi_u_j = scratch_data.phi_u[q][j];
1026 if (dim == 2)
1027 strong_jacobian[q][j] +=
1028 2 * omega_z * (-1.) * cross_product_2d(phi_u_j);
1029 else if (dim == 3)
1030 strong_jacobian[q][j] +=
1031 2 * cross_product_3d(omega_vector, phi_u_j);
1032 }
1033
1034
1035 for (unsigned int i = 0; i < n_dofs; ++i)
1036 {
1037 const auto phi_u_i = scratch_data.phi_u[q][i];
1038 for (unsigned int j = 0; j < n_dofs; ++j)
1039 {
1040 const auto &phi_u_j = scratch_data.phi_u[q][j];
1041
1042 if (dim == 2)
1043 local_matrix(i, j) += 2 * omega_z * (-1.) *
1044 cross_product_2d(phi_u_j) * phi_u_i *
1045 JxW[q];
1046
1047 else if (dim == 3)
1048 local_matrix(i, j) += 2 *
1049 cross_product_3d(omega_vector, phi_u_j) *
1050 phi_u_i * JxW[q];
1051 }
1052 }
1053 }
1054}
1055
1056template <int dim>
1057void
1059 const NavierStokesScratchData<dim> &scratch_data,
1061{
1062 // Loop and quadrature information
1063 const auto &JxW = scratch_data.JxW;
1064 const auto &quadrature_points = scratch_data.quadrature_points;
1065 const unsigned int n_q_points = scratch_data.n_q_points;
1066 const unsigned int n_dofs = scratch_data.n_dofs;
1067
1068 // Copy data elements
1069 auto &strong_residual = copy_data.strong_residual;
1070 auto &local_rhs = copy_data.local_rhs;
1071
1072 // SRF Source term
1073 //----------------------------------
1074 // Angular velocity of the rotating frame. This is always a 3D vector even
1075 // in 2D.
1076 Tensor<1, dim> omega_vector;
1077
1078 double omega_z = velocity_sources.omega_z;
1079 omega_vector[0] = velocity_sources.omega_x;
1080 omega_vector[1] = velocity_sources.omega_y;
1081 if (dim == 3)
1082 omega_vector[2] = velocity_sources.omega_z;
1083
1084
1085 // Loop over the quadrature points
1086 for (unsigned int q = 0; q < n_q_points; ++q)
1087 {
1088 // Velocity
1089 const std::vector<Tensor<1, dim>> velocity = {
1090 scratch_data.velocity_values[q]};
1091
1092 if (dim == 2)
1093 {
1094 strong_residual[q] +=
1095 2 * omega_z * (-1.) * cross_product_2d(velocity[0]);
1096 auto centrifugal =
1097 omega_z * (-1.) *
1098 cross_product_2d(
1099 omega_z * (-1.) *
1100 cross_product_2d(scratch_data.quadrature_points[q]));
1101 strong_residual[q] += centrifugal;
1102 }
1103 else // dim == 3
1104 {
1105 strong_residual[q] += 2 * cross_product_3d(omega_vector, velocity[0]);
1106 strong_residual[q] += cross_product_3d(
1107 omega_vector,
1108 cross_product_3d(omega_vector, scratch_data.quadrature_points[q]));
1109 }
1110
1111 for (unsigned int i = 0; i < n_dofs; ++i)
1112 {
1113 const auto phi_u_i = scratch_data.phi_u[q][i];
1114
1115 if (dim == 2)
1116 {
1117 local_rhs(i) += -2 * omega_z * (-1.) *
1118 cross_product_2d(velocity[0]) * phi_u_i * JxW[q];
1119 auto centrifugal =
1120 omega_z * (-1.) *
1121 cross_product_2d(omega_z * (-1.) *
1122 cross_product_2d(quadrature_points[q]));
1123 local_rhs(i) += -centrifugal * phi_u_i * JxW[q];
1124 }
1125 else if (dim == 3)
1126 {
1127 local_rhs(i) += -2 * cross_product_3d(omega_vector, velocity[0]) *
1128 phi_u_i * JxW[q];
1129 local_rhs(i) +=
1130 -cross_product_3d(omega_vector,
1131 cross_product_3d(omega_vector,
1132 quadrature_points[q])) *
1133 phi_u_i * JxW[q];
1134 }
1135 }
1136 }
1137}
1138
1139
1140
1141template class GLSNavierStokesAssemblerSRF<2>;
1142template class GLSNavierStokesAssemblerSRF<3>;
1143
1144template <int dim>
1145void
1147 const NavierStokesScratchData<dim> &scratch_data,
1149{
1150 // Loop and quadrature information
1151 const auto &JxW = scratch_data.JxW;
1152 const unsigned int n_q_points = scratch_data.n_q_points;
1153 const unsigned int n_dofs = scratch_data.n_dofs;
1154
1155 // Copy data elements
1156 auto &strong_residual = copy_data.strong_residual;
1157 auto &strong_jacobian = copy_data.strong_jacobian;
1158 auto &local_matrix = copy_data.local_matrix;
1159
1160 // Time stepping information
1161 const auto method = this->simulation_control->get_assembly_method();
1162 // Vector for the BDF coefficients
1163 const Vector<double> &bdf_coefs =
1164 this->simulation_control->get_bdf_coefficients();
1165
1166 std::vector<Tensor<1, dim>> velocity(1 +
1168
1169 // Loop over the quadrature points
1170 for (unsigned int q = 0; q < n_q_points; ++q)
1171 {
1172 velocity[0] = scratch_data.velocity_values[q];
1173 for (unsigned int p = 0; p < number_of_previous_solutions(method); ++p)
1174 velocity[p + 1] = scratch_data.previous_velocity_values[p][q];
1175
1176 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
1177 ++p)
1178 {
1179 strong_residual[q] += bdf_coefs[p] * velocity[p];
1180 }
1181
1182 for (unsigned int j = 0; j < n_dofs; ++j)
1183 {
1184 strong_jacobian[q][j] += bdf_coefs[0] * scratch_data.phi_u[q][j];
1185 }
1186
1187
1188 for (unsigned int i = 0; i < n_dofs; ++i)
1189 {
1190 const Tensor<1, dim> &phi_u_i = scratch_data.phi_u[q][i];
1191 for (unsigned int j = 0; j < n_dofs; ++j)
1192 {
1193 const Tensor<1, dim> &phi_u_j = scratch_data.phi_u[q][j];
1194
1195 local_matrix(i, j) += phi_u_j * phi_u_i * bdf_coefs[0] * JxW[q];
1196 }
1197 }
1198 }
1199}
1200
1201template <int dim>
1202void
1204 const NavierStokesScratchData<dim> &scratch_data,
1206{
1207 // Loop and quadrature information
1208 const auto &JxW = scratch_data.JxW;
1209 const unsigned int n_q_points = scratch_data.n_q_points;
1210 const unsigned int n_dofs = scratch_data.n_dofs;
1211
1212 // Copy data elements
1213 auto &strong_residual = copy_data.strong_residual;
1214 auto &local_rhs = copy_data.local_rhs;
1215
1216 // Time stepping information
1217 const auto method = this->simulation_control->get_assembly_method();
1218 // Vector for the BDF coefficients
1219 const Vector<double> &bdf_coefs =
1220 this->simulation_control->get_bdf_coefficients();
1221
1222 std::vector<Tensor<1, dim>> velocity(1 +
1224
1225 // Loop over the quadrature points
1226 for (unsigned int q = 0; q < n_q_points; ++q)
1227 {
1228 velocity[0] = scratch_data.velocity_values[q];
1229 for (unsigned int p = 0; p < number_of_previous_solutions(method); ++p)
1230 velocity[p + 1] = scratch_data.previous_velocity_values[p][q];
1231
1232 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
1233 ++p)
1234 {
1235 strong_residual[q] += (bdf_coefs[p] * velocity[p]);
1236 }
1237
1238
1239 for (unsigned int i = 0; i < n_dofs; ++i)
1240 {
1241 const auto phi_u_i = scratch_data.phi_u[q][i];
1242 double local_rhs_i = 0;
1243 for (unsigned int p = 0; p < number_of_previous_solutions(method) + 1;
1244 ++p)
1245 {
1246 local_rhs_i -= bdf_coefs[p] * (velocity[p] * phi_u_i);
1247 }
1248 local_rhs(i) += local_rhs_i * JxW[q];
1249 }
1250 }
1251}
1252
1253template class GLSNavierStokesAssemblerBDF<2>;
1254template class GLSNavierStokesAssemblerBDF<3>;
1255
1256template <int dim>
1257void
1259 const NavierStokesScratchData<dim> &scratch_data,
1261{
1262 // Loop and quadrature information
1263 const auto &JxW = scratch_data.JxW;
1264 const unsigned int n_q_points = scratch_data.n_q_points;
1265 const unsigned int n_dofs = scratch_data.n_dofs;
1266
1267 // Copy data elements
1268 auto &strong_residual = copy_data.strong_residual;
1269 auto &strong_jacobian = copy_data.strong_jacobian;
1270 auto &local_matrix = copy_data.local_matrix;
1271
1272 std::vector<double> time_steps_vector =
1273 this->simulation_control->get_time_steps_vector();
1274 const double h = time_steps_vector[0];
1275
1276 // Time stepping information
1277 SDIRKStageData stage_data(scratch_data.sdirk_table, 1);
1278
1279 std::vector<Tensor<1, dim>> velocity(2);
1280
1281 // Loop over the quadrature points
1282 for (unsigned int q = 0; q < n_q_points; ++q)
1283 {
1284 velocity[0] = scratch_data.velocity_values[q];
1285 velocity[1] = scratch_data.previous_velocity_values[0][q];
1286
1287 strong_residual[q] +=
1288 (velocity[0] - velocity[1]) / (h * stage_data.a_ij[0]) -
1289 scratch_data.sdirk_stage_sum[q];
1290
1291 for (unsigned int j = 0; j < n_dofs; ++j)
1292 {
1293 strong_jacobian[q][j] +=
1294 scratch_data.phi_u[q][j] / (h * stage_data.a_ij[0]);
1295 }
1296
1297 for (unsigned int i = 0; i < n_dofs; ++i)
1298 {
1299 const Tensor<1, dim> &phi_u_i = scratch_data.phi_u[q][i];
1300 for (unsigned int j = 0; j < n_dofs; ++j)
1301 {
1302 const Tensor<1, dim> &phi_u_j = scratch_data.phi_u[q][j];
1303
1304 local_matrix(i, j) +=
1305 ((phi_u_j * phi_u_i) / (h * stage_data.a_ij[0])) * JxW[q];
1306 }
1307 }
1308 }
1309}
1310
1311template <int dim>
1312void
1314 const NavierStokesScratchData<dim> &scratch_data,
1316{
1317 // Loop and quadrature information
1318 const auto &JxW = scratch_data.JxW;
1319 const unsigned int n_q_points = scratch_data.n_q_points;
1320 const unsigned int n_dofs = scratch_data.n_dofs;
1321
1322 // Copy data elements
1323 auto &strong_residual = copy_data.strong_residual;
1324 auto &local_rhs = copy_data.local_rhs;
1325
1326 SDIRKStageData stage_data(scratch_data.sdirk_table, 1);
1327
1328 std::vector<double> time_steps_vector =
1329 this->simulation_control->get_time_steps_vector();
1330 const double h = time_steps_vector[0];
1331
1332 std::vector<Tensor<1, dim>> velocity(2);
1333
1334 // Loop over the quadrature points
1335 for (unsigned int q = 0; q < n_q_points; ++q)
1336 {
1337 velocity[0] = scratch_data.velocity_values[q];
1338 velocity[1] = scratch_data.previous_velocity_values[0][q];
1339
1340 strong_residual[q] +=
1341 (velocity[0] - velocity[1]) / (h * stage_data.a_ij[0]) -
1342 scratch_data.sdirk_stage_sum[q];
1343
1344 for (unsigned int i = 0; i < n_dofs; ++i)
1345 {
1346 const auto phi_u_i = scratch_data.phi_u[q][i];
1347 double local_rhs_i = 0;
1348 local_rhs_i -= (1 / (h * stage_data.a_ij[0])) * phi_u_i *
1349 (scratch_data.velocity_values[q] -
1350 scratch_data.previous_velocity_values[0][q]) -
1351 phi_u_i * scratch_data.sdirk_stage_sum[q];
1352 local_rhs(i) += local_rhs_i * JxW[q];
1353 }
1354 }
1355}
1356
1359
1360template <int dim>
1361void
1363 const NavierStokesScratchData<dim> &scratch_data,
1365{
1366 // Scheme and physical properties
1367 const std::vector<double> &kinematic_viscosity =
1368 scratch_data.kinematic_viscosity;
1369
1370 // Loop and quadrature information
1371 const auto &JxW_vec = scratch_data.JxW;
1372 const unsigned int n_q_points = scratch_data.n_q_points;
1373 const unsigned int n_dofs = scratch_data.n_dofs;
1374
1375 // Copy data elements
1376 auto &local_matrix = copy_data.local_matrix;
1377
1378 // Local variables to reuse multiplications
1379 std::vector<Tensor<1, dim>> grad_phi_u_j_x_velocity(n_dofs);
1380 std::vector<Tensor<1, dim>> velocity_gradient_x_phi_u_j(n_dofs);
1381
1382 // Pressure scaling factor
1383 const double pressure_scaling_factor = scratch_data.pressure_scaling_factor;
1384
1385 // Loop over the quadrature points
1386 for (unsigned int q = 0; q < n_q_points; ++q)
1387 {
1388 // Gather into local variables the relevant fields
1389 const Tensor<2, dim> &velocity_gradient =
1390 scratch_data.velocity_gradients[q];
1391 const Tensor<1, dim> &advective_velocity =
1392 scratch_data.advective_velocity[q];
1393
1394 // Store JxW in local variable for faster access;
1395 const double JxW = JxW_vec[q];
1396
1397 // We loop over the column first to prevent recalculation
1398 // of the strong jacobian in the inner loop
1399 for (unsigned int j = 0; j < n_dofs; ++j)
1400 {
1401 const auto &phi_u_j = scratch_data.phi_u[q][j];
1402 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
1403
1404 // Store these temporary products in auxiliary variables for speed
1405 grad_phi_u_j_x_velocity[j] = grad_phi_u_j * advective_velocity;
1406 velocity_gradient_x_phi_u_j[j] = velocity_gradient * phi_u_j;
1407 }
1408
1409 for (unsigned int i = 0; i < n_dofs; ++i)
1410 {
1411 const auto &phi_u_i = scratch_data.phi_u[q][i];
1412 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
1413 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
1414 const auto &phi_p_i = scratch_data.phi_p[q][i];
1415
1416 for (unsigned int j = 0; j < n_dofs; ++j)
1417 {
1418 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
1419 const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
1420
1421 const auto &phi_p_j =
1422 pressure_scaling_factor * scratch_data.phi_p[q][j];
1423
1424 const auto &grad_phi_u_j_non_newtonian =
1425 grad_phi_u_j + transpose(grad_phi_u_j);
1426
1427 double local_matrix_ij =
1428 kinematic_viscosity[q] *
1429 scalar_product(grad_phi_u_j_non_newtonian, grad_phi_u_i) +
1430 velocity_gradient_x_phi_u_j[j] * phi_u_i +
1431 grad_phi_u_j_x_velocity[j] * phi_u_i - div_phi_u_i * phi_p_j -
1432 // Continuity
1433 phi_p_i * div_phi_u_j + gamma * div_phi_u_j * div_phi_u_i +
1434 // Mass matrix for S block in schur complement
1435 phi_p_i * phi_p_j;
1436
1437 local_matrix_ij *= JxW;
1438 local_matrix(i, j) += local_matrix_ij;
1439 }
1440 }
1441 }
1442}
1443
1444template <int dim>
1445void
1447 const NavierStokesScratchData<dim> &scratch_data,
1449{
1450 // Scheme and physical properties
1451 const std::vector<double> &kinematic_viscosity_vector =
1452 scratch_data.kinematic_viscosity;
1453
1454 // Loop and quadrature information
1455 const auto &JxW_vec = scratch_data.JxW;
1456 const unsigned int n_q_points = scratch_data.n_q_points;
1457 const unsigned int n_dofs = scratch_data.n_dofs;
1458
1459 // Copy data elements
1460 auto &local_rhs = copy_data.local_rhs;
1461
1462 // Loop over the quadrature points
1463 for (unsigned int q = 0; q < n_q_points; ++q)
1464 {
1465 // Physical properties
1466 const double kinematic_viscosity = kinematic_viscosity_vector[q];
1467
1468 // Velocity
1469 const double velocity_divergence = scratch_data.velocity_divergences[q];
1470 const Tensor<2, dim> &velocity_gradient =
1471 scratch_data.velocity_gradients[q];
1472 const Tensor<1, dim> &advective_velocity =
1473 scratch_data.advective_velocity[q];
1474
1475 // Calculate shear rate (at each q)
1476 const Tensor<2, dim> shear_rate =
1477 velocity_gradient + transpose(velocity_gradient);
1478
1479 // Pressure
1480 const double pressure = scratch_data.pressure_values[q];
1481
1482 // Forcing term
1483 const Tensor<1, dim> &force = scratch_data.force[q];
1484
1485 // Store JxW in local variable for faster access
1486 const double JxW = JxW_vec[q];
1487
1488 // Assembly of the right-hand side
1489 for (unsigned int i = 0; i < n_dofs; ++i)
1490 {
1491 const auto phi_u_i = scratch_data.phi_u[q][i];
1492 const auto grad_phi_u_i = scratch_data.grad_phi_u[q][i];
1493 const auto phi_p_i = scratch_data.phi_p[q][i];
1494 const auto div_phi_u_i = scratch_data.div_phi_u[q][i];
1495
1496 double local_rhs_i = 0;
1497
1498 // Navier-Stokes Residual
1499 local_rhs_i +=
1500 (
1501 // Momentum
1502 -kinematic_viscosity * scalar_product(shear_rate, grad_phi_u_i) -
1503 velocity_gradient * advective_velocity * phi_u_i +
1504 pressure * div_phi_u_i + force * phi_u_i +
1505 // Continuity
1506 velocity_divergence * phi_p_i -
1507 gamma * velocity_divergence * div_phi_u_i) *
1508 JxW;
1509
1510 local_rhs(i) += local_rhs_i;
1511 }
1512 }
1513}
1514
1517
1518
1519template <int dim>
1520void
1522 const NavierStokesScratchData<dim> &scratch_data,
1524{
1525 // Scheme and physical properties
1526 const std::vector<double> &kinematic_viscosity_vector =
1527 scratch_data.kinematic_viscosity;
1528
1529 // Loop and quadrature information
1530 const auto &JxW_vec = scratch_data.JxW;
1531 const unsigned int n_q_points = scratch_data.n_q_points;
1532 const unsigned int n_dofs = scratch_data.n_dofs;
1533
1534 // Copy data elements
1535 auto &local_matrix = copy_data.local_matrix;
1536
1537 // Local variables to reuse multiplications
1538 std::vector<Tensor<1, dim>> grad_phi_u_j_x_velocity(n_dofs);
1539 std::vector<Tensor<1, dim>> velocity_gradient_x_phi_u_j(n_dofs);
1540
1541 // Pressure scaling factor
1542 const double pressure_scaling_factor = scratch_data.pressure_scaling_factor;
1543
1544 // Loop over the quadrature points
1545 for (unsigned int q = 0; q < n_q_points; ++q)
1546 {
1547 // Physical properties
1548 const double kinematic_viscosity = kinematic_viscosity_vector[q];
1549
1550 // Gather into local variables the relevant fields
1551 const Tensor<2, dim> &velocity_gradient =
1552 scratch_data.velocity_gradients[q];
1553 const Tensor<1, dim> &advective_velocity =
1554 scratch_data.advective_velocity[q];
1555
1556 // Store JxW in local variable for faster access;
1557 const double JxW = JxW_vec[q];
1558
1559 // We loop over the column first to prevent recalculation
1560 // of the strong jacobian in the inner loop
1561 for (unsigned int j = 0; j < n_dofs; ++j)
1562 {
1563 const auto &phi_u_j = scratch_data.phi_u[q][j];
1564 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
1565
1566 // Store these temporary products in auxiliary variables for speed
1567 grad_phi_u_j_x_velocity[j] = grad_phi_u_j * advective_velocity;
1568 velocity_gradient_x_phi_u_j[j] = velocity_gradient * phi_u_j;
1569 }
1570
1571 for (unsigned int i = 0; i < n_dofs; ++i)
1572 {
1573 const auto &phi_u_i = scratch_data.phi_u[q][i];
1574 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
1575 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
1576 const auto &phi_p_i = scratch_data.phi_p[q][i];
1577
1578 for (unsigned int j = 0; j < n_dofs; ++j)
1579 {
1580 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
1581 const auto &div_phi_u_j = scratch_data.div_phi_u[q][j];
1582
1583 const auto &phi_p_j =
1584 pressure_scaling_factor * scratch_data.phi_p[q][j];
1585
1586 double local_matrix_ij =
1587 kinematic_viscosity *
1588 scalar_product(grad_phi_u_j, grad_phi_u_i) +
1589 velocity_gradient_x_phi_u_j[j] * phi_u_i +
1590 grad_phi_u_j_x_velocity[j] * phi_u_i - div_phi_u_i * phi_p_j -
1591 // Continuity
1592 phi_p_i * div_phi_u_j + gamma * div_phi_u_j * div_phi_u_i +
1593 // Mass matrix for S block in schur complement
1594 phi_p_i * phi_p_j;
1595
1596 local_matrix_ij *= JxW;
1597 local_matrix(i, j) += local_matrix_ij;
1598 }
1599 }
1600 }
1601}
1602
1603template <int dim>
1604void
1606 const NavierStokesScratchData<dim> &scratch_data,
1608{
1609 // Scheme and physical properties
1610 const std::vector<double> &kinematic_viscosity_vector =
1611 scratch_data.kinematic_viscosity;
1612
1613 // Loop and quadrature information
1614 const auto &JxW_vec = scratch_data.JxW;
1615 const unsigned int n_q_points = scratch_data.n_q_points;
1616 const unsigned int n_dofs = scratch_data.n_dofs;
1617
1618 // Copy data elements
1619 auto &local_rhs = copy_data.local_rhs;
1620
1621 // Loop over the quadrature points
1622 for (unsigned int q = 0; q < n_q_points; ++q)
1623 {
1624 // Physical properties
1625 const double kinematic_viscosity = kinematic_viscosity_vector[q];
1626
1627 // Velocity
1628 const double velocity_divergence = scratch_data.velocity_divergences[q];
1629 const Tensor<2, dim> &velocity_gradient =
1630 scratch_data.velocity_gradients[q];
1631 const Tensor<1, dim> &advective_velocity =
1632 scratch_data.advective_velocity[q];
1633
1634 // Pressure
1635 const double pressure = scratch_data.pressure_values[q];
1636
1637 // Forcing term
1638 const Tensor<1, dim> &force = scratch_data.force[q];
1639
1640 // Store JxW in local variable for faster access;
1641 const double JxW = JxW_vec[q];
1642
1643 // Assembly of the right-hand side
1644 for (unsigned int i = 0; i < n_dofs; ++i)
1645 {
1646 const auto &phi_u_i = scratch_data.phi_u[q][i];
1647 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
1648 const auto &phi_p_i = scratch_data.phi_p[q][i];
1649 const auto &div_phi_u_i = scratch_data.div_phi_u[q][i];
1650
1651 double local_rhs_i = 0;
1652
1653 // Navier-Stokes Residual
1654 local_rhs_i += (
1655 // Momentum
1656 -kinematic_viscosity *
1657 scalar_product(velocity_gradient, grad_phi_u_i) -
1658 velocity_gradient * advective_velocity * phi_u_i +
1659 pressure * div_phi_u_i + force * phi_u_i +
1660 // Continuity
1661 velocity_divergence * phi_p_i -
1662 gamma * velocity_divergence * div_phi_u_i) *
1663 JxW;
1664
1665 local_rhs(i) += local_rhs_i;
1666 }
1667 }
1668}
1669
1670
1671
1674
1675template <int dim>
1676void
1678 const NavierStokesScratchData<dim> &scratch_data,
1680{
1681 // Loop and quadrature information
1682 const auto &JxW_vec = scratch_data.JxW;
1683 const unsigned int n_q_points = scratch_data.n_q_points;
1684 const unsigned int n_dofs = scratch_data.n_dofs;
1685 const double kinematic_viscosity = scratch_data.kinematic_viscosity_scale;
1686 const double h = scratch_data.cell_size;
1687 // Copy data elements
1688 auto &local_matrix = copy_data.local_matrix;
1689
1690 // Time steps and inverse time steps which is used for stabilization constant
1691 std::vector<double> time_steps_vector =
1692 this->simulation_control->get_time_steps_vector();
1693
1694 // Loop over the quadrature points
1695 for (unsigned int q = 0; q < n_q_points; ++q)
1696 {
1697 // Store JxW in local variable for faster access;
1698 const double JxW = JxW_vec[q];
1699
1700 for (unsigned int i = 0; i < n_dofs; ++i)
1701 {
1702 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
1703 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
1704
1705 for (unsigned int j = 0; j < n_dofs; ++j)
1706 {
1707 const auto &grad_phi_u_j = scratch_data.grad_phi_u[q][j];
1708 const auto &grad_phi_p_j = scratch_data.grad_phi_p[q][j];
1709
1710 // Units are not consistent for the following line, but it is
1711 // better that way for the problem scaling and it doesn't affect
1712 // the end result for our purposes
1713 // Laplacian on the velocity terms
1714 double local_matrix_ij =
1715 kinematic_viscosity *
1716 scalar_product(grad_phi_u_j, grad_phi_u_i);
1717
1718 // Laplacian on the pressure terms
1719 local_matrix_ij += 1 / kinematic_viscosity * h *
1720 scalar_product(grad_phi_p_j, grad_phi_p_i);
1721
1722 // The jacobian matrix for the SUPG formulation
1723 // currently does not include the jacobian of the stabilization
1724 // parameter tau. Our experience has shown that does not alter the
1725 // number of newton iteration for convergence, but greatly
1726 // simplifies assembly.
1727
1728 local_matrix_ij *= JxW;
1729 local_matrix(i, j) += local_matrix_ij;
1730 }
1731 }
1732 }
1733}
1734
1735template <int dim>
1736void
1738 const NavierStokesScratchData<dim> &scratch_data,
1740{
1741 // Loop and quadrature information
1742 const auto &JxW_vec = scratch_data.JxW;
1743 const unsigned int n_q_points = scratch_data.n_q_points;
1744 const unsigned int n_dofs = scratch_data.n_dofs;
1745 auto &local_rhs = copy_data.local_rhs;
1746 const double kinematic_viscosity = scratch_data.kinematic_viscosity_scale;
1747 const double h = scratch_data.cell_size;
1748
1749 // Time steps and inverse time steps which is used for stabilization constant
1750 std::vector<double> time_steps_vector =
1751 this->simulation_control->get_time_steps_vector();
1752
1753 // Loop over the quadrature points
1754 for (unsigned int q = 0; q < n_q_points; ++q)
1755 {
1756 // Velocity
1757 const Tensor<2, dim> &velocity_gradient =
1758 scratch_data.velocity_gradients[q];
1759
1760 // Pressure
1761 const Tensor<1, dim> &pressure_gradient =
1762 scratch_data.pressure_gradients[q];
1763
1764 // Store JxW in local variable for faster access;
1765 const double JxW = JxW_vec[q];
1766
1767
1768 // Assembly of the right-hand side
1769 for (unsigned int i = 0; i < n_dofs; ++i)
1770 {
1771 const auto &grad_phi_u_i = scratch_data.grad_phi_u[q][i];
1772 const auto &grad_phi_p_i = scratch_data.grad_phi_p[q][i];
1773
1774
1775 double local_rhs_i = 0;
1776
1777 // Laplacian on the velocity terms
1778 local_rhs_i += -kinematic_viscosity *
1779 scalar_product(velocity_gradient, grad_phi_u_i) * JxW;
1780
1781
1782 // Laplacian on the pressure terms
1783 local_rhs_i += -1 / kinematic_viscosity * h *
1784 scalar_product(pressure_gradient, grad_phi_p_i) * JxW;
1785
1786 if (scratch_data.components[i] == dim)
1787 local_rhs_i /= scratch_data.pressure_scaling_factor;
1788 local_rhs(i) += local_rhs_i;
1789 }
1790 }
1791}
1792
1793template class LaplaceAssembly<2>;
1794template class LaplaceAssembly<3>;
1795
1796
1797template <int dim>
1798void
1800 const NavierStokesScratchData<dim> &scratch_data,
1802{
1803 // The buoyancy force does not depend on the velocity or the pressure, so it
1804 // has no contribution to the Jacobian. However, it must still be added to the
1805 // strong residual since the SUPG term of the Jacobian depends on it.
1806 const unsigned int n_q_points = scratch_data.n_q_points;
1807
1808 auto &strong_residual = copy_data.strong_residual;
1809
1810 for (unsigned int q = 0; q < n_q_points; ++q)
1811 {
1812 strong_residual[q] +=
1813 scratch_data.force[q] * scratch_data.thermal_expansion[q] *
1814 (scratch_data.temperature_values[q] - reference_temperature);
1815 }
1816}
1817
1818
1819
1820template <int dim>
1821void
1823 const NavierStokesScratchData<dim> &scratch_data,
1825{
1826 // Loop and quadrature information
1827 const auto &JxW_vec = scratch_data.JxW;
1828 const unsigned int n_q_points = scratch_data.n_q_points;
1829 const unsigned int n_dofs = scratch_data.n_dofs;
1830
1831 auto &local_rhs = copy_data.local_rhs;
1832 auto &strong_residual = copy_data.strong_residual;
1833
1834
1835 // Loop over the quadrature points
1836 for (unsigned int q = 0; q < n_q_points; ++q)
1837 {
1838 // Forcing term (gravity)
1839 const Tensor<1, dim> &force = scratch_data.force[q];
1840
1841 const double thermal_expansion = scratch_data.thermal_expansion[q];
1842
1843 // Store JxW in local variable for faster access;
1844 const double JxW = JxW_vec[q];
1845
1846 // Current temperature values
1847 double current_temperature = scratch_data.temperature_values[q];
1848
1849 strong_residual[q] += force * thermal_expansion *
1850 (current_temperature - reference_temperature);
1851
1852 // Assembly of the right-hand side
1853 for (unsigned int i = 0; i < n_dofs; ++i)
1854 {
1855 const auto phi_u_i = scratch_data.phi_u[q][i];
1856
1857 local_rhs(i) -= force * thermal_expansion *
1858 (current_temperature - reference_temperature) *
1859 phi_u_i * JxW;
1860 }
1861 }
1862}
1863
1864template class ThermalBuoyancyAssembly<2>;
1865template class ThermalBuoyancyAssembly<3>;
1866
1867template <int dim>
1868void
1870 const NavierStokesScratchData<dim> &scratch_data,
1872{
1873 // Loop and quadrature information
1874 const auto &JxW_vec = scratch_data.JxW;
1875 const unsigned int n_q_points = scratch_data.n_q_points;
1876 const unsigned int n_dofs = scratch_data.n_dofs;
1877 const auto &velocities = scratch_data.velocity_values;
1878 const auto &temperatures = scratch_data.temperature_values;
1879
1880 auto &local_matrix = copy_data.local_matrix;
1881 auto &strong_residual = copy_data.strong_residual;
1882 auto &strong_jacobian = copy_data.strong_jacobian;
1883
1884
1885 // Loop over the quadrature points
1886 for (unsigned int q = 0; q < n_q_points; ++q)
1887 {
1888 // Store JxW in local variable for faster access;
1889 const double JxW = JxW_vec[q];
1890 // Current temperature values
1891 double current_temperature = temperatures[q];
1892 // Depending on the value of the temperature, calculate the Darcy
1893 // permeability. This min(max) approach is used to calculate the liquid
1894 // fraction without requiring if conditions.
1895 const double liquid_fraction =
1896 std::min(1.,
1897 std::max((current_temperature -
1898 phase_change_parameters.T_solidus) /
1899 (phase_change_parameters.T_liquidus -
1900 phase_change_parameters.T_solidus),
1901 0.));
1902 double darcy_penalty =
1903 phase_change_parameters.penalty_l * liquid_fraction +
1904 (1. - liquid_fraction) * phase_change_parameters.penalty_s;
1905
1906 strong_residual[q] += darcy_penalty * velocities[q];
1907
1908 for (unsigned int j = 0; j < n_dofs; ++j)
1909 {
1910 strong_jacobian[q][j] += darcy_penalty * scratch_data.phi_u[q][j];
1911 }
1912
1913 for (unsigned int i = 0; i < n_dofs; ++i)
1914 {
1915 const auto &phi_u_i = scratch_data.phi_u[q][i];
1916 for (unsigned int j = 0; j < n_dofs; ++j)
1917 {
1918 const auto &phi_u_j = scratch_data.phi_u[q][j];
1919 local_matrix(i, j) += darcy_penalty * phi_u_i * phi_u_j * JxW;
1920 }
1921 }
1922 }
1923}
1924
1925template <int dim>
1926void
1928 const NavierStokesScratchData<dim> &scratch_data,
1930{
1931 // Loop and quadrature information
1932 const auto &JxW_vec = scratch_data.JxW;
1933 const unsigned int n_q_points = scratch_data.n_q_points;
1934 const unsigned int n_dofs = scratch_data.n_dofs;
1935 const auto &velocities = scratch_data.velocity_values;
1936 const auto &temperatures = scratch_data.temperature_values;
1937
1938
1939 auto &local_rhs = copy_data.local_rhs;
1940 auto &strong_residual = copy_data.strong_residual;
1941
1942 // Loop over the quadrature points
1943 for (unsigned int q = 0; q < n_q_points; ++q)
1944 {
1945 // Store JxW in local variable for faster access;
1946 const double JxW = JxW_vec[q];
1947 // Current temperature values
1948 double current_temperature = temperatures[q];
1949 // Depending on the value of the temperature, calculate the Darcy
1950 // permeability. This min(max) approach is used to calculate the liquid
1951 // fraction without requiring if conditions.
1952 const double liquid_fraction =
1953 std::min(1.,
1954 std::max((current_temperature -
1955 phase_change_parameters.T_solidus) /
1956 (phase_change_parameters.T_liquidus -
1957 phase_change_parameters.T_solidus),
1958 0.));
1959 double darcy_penalty =
1960 phase_change_parameters.penalty_l * liquid_fraction +
1961 (1. - liquid_fraction) * phase_change_parameters.penalty_s;
1962
1963 strong_residual[q] += darcy_penalty * velocities[q];
1964
1965 // Assembly of the right-hand side
1966 for (unsigned int i = 0; i < n_dofs; ++i)
1967 {
1968 const auto phi_u_i = scratch_data.phi_u[q][i];
1969
1970 // Laplacian on the velocity terms
1971 local_rhs(i) -= darcy_penalty * velocities[q] * phi_u_i * JxW;
1972 }
1973 }
1974}
1975
1976template class PhaseChangeDarcyAssembly<2>;
1977template class PhaseChangeDarcyAssembly<3>;
1978
1979template <int dim>
1980void
1982 const NavierStokesScratchData<dim> &scratch_data,
1984{
1985 // Loop and quadrature information
1986 const auto &JxW_vec = scratch_data.JxW;
1987 const unsigned int n_q_points = scratch_data.n_q_points;
1988 const unsigned int n_dofs = scratch_data.n_dofs;
1989 const auto &velocities = scratch_data.velocity_values;
1990 const auto &temperatures = scratch_data.temperature_values;
1991 const auto &kinematic_viscosity_values = scratch_data.kinematic_viscosity;
1992
1993 auto &local_matrix = copy_data.local_matrix;
1994 auto &strong_residual = copy_data.strong_residual;
1995 auto &strong_jacobian = copy_data.strong_jacobian;
1996
1997 // Loop over the quadrature points
1998 for (unsigned int q = 0; q < n_q_points; ++q)
1999 {
2000 // Store JxW in local variable for faster access;
2001 const double JxW = JxW_vec[q];
2002
2003 // Current temperature and kinematics viscosity values
2004 double temperature = temperatures[q];
2005 double kinematic_viscosity = kinematic_viscosity_values[q];
2006
2007 // Compute the liquid fraction
2008 const double liquid_fraction =
2009 std::min(1.,
2010 std::max((temperature - solidus_temperature) /
2012 0.));
2013
2014 // Pre-compute the denominator inverse
2015 const double carman_kozeny_penalty_denominator_inv =
2016 1 /
2017 (Utilities::fixed_power<3>(liquid_fraction) + carman_kozeny_tolerance);
2018
2019 // Compute penalty term
2020 const double carman_kozeny_penalty =
2021 kinematic_viscosity * carman_kozeny_permeability_area_inv *
2022 Utilities::fixed_power<2>(1 - liquid_fraction) *
2023 carman_kozeny_penalty_denominator_inv;
2024
2025 strong_residual[q] += carman_kozeny_penalty * velocities[q];
2026
2027 for (unsigned int j = 0; j < n_dofs; ++j)
2028 {
2029 strong_jacobian[q][j] +=
2030 carman_kozeny_penalty * scratch_data.phi_u[q][j];
2031 }
2032
2033 for (unsigned int i = 0; i < n_dofs; ++i)
2034 {
2035 const auto &phi_u_i = scratch_data.phi_u[q][i];
2036 for (unsigned int j = 0; j < n_dofs; ++j)
2037 {
2038 const auto &phi_u_j = scratch_data.phi_u[q][j];
2039 local_matrix(i, j) +=
2040 carman_kozeny_penalty * phi_u_i * phi_u_j * JxW;
2041 }
2042 }
2043 }
2044}
2045
2046template <int dim>
2047void
2049 const NavierStokesScratchData<dim> &scratch_data,
2051{
2052 // Loop and quadrature information
2053 const auto &JxW_vec = scratch_data.JxW;
2054 const unsigned int n_q_points = scratch_data.n_q_points;
2055 const unsigned int n_dofs = scratch_data.n_dofs;
2056 const auto &velocities = scratch_data.velocity_values;
2057 const auto &temperatures = scratch_data.temperature_values;
2058 const auto &kinematic_viscosity_values = scratch_data.kinematic_viscosity;
2059
2060
2061 auto &local_rhs = copy_data.local_rhs;
2062 auto &strong_residual = copy_data.strong_residual;
2063
2064 // Loop over the quadrature points
2065 for (unsigned int q = 0; q < n_q_points; ++q)
2066 {
2067 // Store JxW in local variable for faster access;
2068 const double JxW = JxW_vec[q];
2069
2070 // Current temperature and kinematics viscosity values
2071 double temperature = temperatures[q];
2072 double kinematic_viscosity = kinematic_viscosity_values[q];
2073
2074 // Compute the liquid fraction
2075 const double liquid_fraction =
2076 std::min(1.,
2077 std::max((temperature - solidus_temperature) /
2079 0.));
2080
2081 // Pre-compute the denominator inverse
2082 const double carman_kozeny_penalty_denominator_inv =
2083 1 /
2084 (Utilities::fixed_power<3>(liquid_fraction) + carman_kozeny_tolerance);
2085
2086 // Compute penalty term
2087 const double carman_kozeny_penalty =
2088 kinematic_viscosity * carman_kozeny_permeability_area_inv *
2089 Utilities::fixed_power<2>(1 - liquid_fraction) *
2090 carman_kozeny_penalty_denominator_inv;
2091
2092 strong_residual[q] += carman_kozeny_penalty * velocities[q];
2093
2094 // Assembly of the right-hand side
2095 for (unsigned int i = 0; i < n_dofs; ++i)
2096 {
2097 const auto phi_u_i = scratch_data.phi_u[q][i];
2098
2099 // Laplacian on the velocity terms
2100 local_rhs(i) -= carman_kozeny_penalty * velocities[q] * phi_u_i * JxW;
2101 }
2102 }
2103}
2104
2107
2108
2109template <int dim>
2110void
2112 const NavierStokesScratchData<dim> &scratch_data,
2114{
2115 if (!scratch_data.is_boundary_cell)
2116 return;
2117
2118 // Scheme and physical properties
2119 // To generalize for dependent viscosity
2120 const double kinematic_viscosity = scratch_data.kinematic_viscosity_scale;
2121
2122 // Loop and quadrature information
2123 Tensor<2, dim> identity;
2124 for (int d = 0; d < dim; ++d)
2125 {
2126 identity[d][d] = 1;
2127 }
2128
2129 std::vector<std::vector<std::vector<Tensor<1, dim>>>> gn_j;
2130 gn_j = std::vector<std::vector<std::vector<Tensor<1, dim>>>>(
2131 scratch_data.n_faces,
2132 std::vector<std::vector<Tensor<1, dim>>>(scratch_data.n_faces_q_points,
2133 std::vector<Tensor<1, dim>>(
2134 scratch_data.n_dofs)));
2135
2136 auto &local_matrix = copy_data.local_matrix;
2137
2138 // Loop over the faces of the cell.
2139 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2140 {
2141 // Check if the face is on a boundary
2142 if (scratch_data.is_boundary_face[f])
2143 {
2144 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2145 // Check if the face is part of the boundary that as a
2146 // pressure BC.
2147 if (this->pressure_boundary_conditions.type.at(boundary_id) ==
2149 {
2150 // Assemble the matrix of the BC
2151 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2152 {
2153 const double JxW = scratch_data.face_JxW[f][q];
2154 for (const unsigned int j :
2155 scratch_data.fe_face_values.dof_indices())
2156 {
2157 gn_j[f][q][j] =
2158 (-kinematic_viscosity *
2159 (scratch_data.face_grad_phi_u[f][q][j])) *
2160 scratch_data.face_normal[f][q];
2161 }
2162 for (const unsigned int i :
2163 scratch_data.fe_face_values.dof_indices())
2164 {
2165 for (const unsigned int j :
2166 scratch_data.fe_face_values.dof_indices())
2167 {
2168 local_matrix[i][j] +=
2169 -scratch_data.face_phi_u[f][q][i] * gn_j[f][q][j] *
2170 JxW;
2171 }
2172 }
2173 }
2174 }
2175 }
2176 }
2177}
2178
2179template <int dim>
2180void
2182 const NavierStokesScratchData<dim> &scratch_data,
2184{
2185 if (!scratch_data.is_boundary_cell)
2186 return;
2187
2188 // Scheme and physical properties
2189 const double kinematic_viscosity = scratch_data.kinematic_viscosity_scale;
2190
2191 // Loop and quadrature information
2192 Tensor<2, dim> identity;
2193 for (int d = 0; d < dim; ++d)
2194 {
2195 identity[d][d] = 1;
2196 }
2197 std::vector<std::vector<double>> prescribed_pressure_values;
2198 prescribed_pressure_values = std::vector<std::vector<double>>(
2199 scratch_data.n_faces, std::vector<double>(scratch_data.n_faces_q_points));
2200
2201 std::vector<std::vector<Tensor<1, dim>>> gn_bc =
2202 std::vector<std::vector<Tensor<1, dim>>>(scratch_data.n_faces,
2203 std::vector<Tensor<1, dim>>(
2204 scratch_data.n_faces_q_points));
2205
2206
2207 auto &local_rhs = copy_data.local_rhs;
2208
2209 // Pressure boundary condition, loop on faces
2210 // implementation similar to deal.ii step-22
2211 // Loop over the BCs
2212 // Loop over the faces of the cell.
2213 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2214 {
2215 // Check if the face is on a boundary
2216 if (scratch_data.is_boundary_face[f])
2217 {
2218 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2219
2221 &pressure_boundary_conditions.navier_stokes_functions
2222 .at(boundary_id)
2223 ->p);
2224 // Check if the face is part of the boundary that as a
2225 // pressure BC.
2226 if (this->pressure_boundary_conditions.type.at(boundary_id) ==
2228 {
2229 // Assemble the rhs of the BC
2230 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2231 {
2232 const double JxW = scratch_data.face_JxW[f][q];
2233 prescribed_pressure_values[f][q] =
2234 function_p.value(scratch_data.face_quadrature_points[f][q],
2235 dim);
2236 gn_bc[f][q] =
2237 (-prescribed_pressure_values[f][q] * identity -
2238 kinematic_viscosity *
2239 (scratch_data.face_velocity_gradients[f][q])) *
2240 scratch_data.face_normal[f][q];
2241 for (const unsigned int i :
2242 scratch_data.fe_face_values.dof_indices())
2243 {
2244 local_rhs(i) -=
2245 -scratch_data.face_phi_u[f][q][i] * (gn_bc[f][q]) * JxW;
2246 }
2247 }
2248 }
2249 }
2250 }
2251}
2252
2253template class PressureBoundaryCondition<2>;
2254template class PressureBoundaryCondition<3>;
2255
2256template <int dim>
2257void
2259 [[maybe_unused]] const NavierStokesScratchData<dim> &scratch_data,
2260 [[maybe_unused]] StabilizedMethodsTensorCopyData<dim> &copy_data)
2261{}
2262
2263template <int dim>
2264void
2266 const NavierStokesScratchData<dim> &scratch_data,
2268{
2269 if (!scratch_data.is_boundary_cell)
2270 return;
2271
2272
2273 std::vector<std::vector<Tensor<1, dim>>> traction_vec_data =
2274 std::vector<std::vector<Tensor<1, dim>>>(scratch_data.n_faces,
2275 std::vector<Tensor<1, dim>>(
2276 scratch_data.n_faces_q_points));
2277
2278 auto &local_rhs = copy_data.local_rhs;
2279
2280 // Neumann traction boundary condition, loop on faces
2281 // ∫_Γ_N v · traction_fn dΓ_N
2282 //
2283 // where:
2284 // - Γ_N is the boundary domain where the Neumann traction condition is
2285 // applied
2286 // - v is the velocity test function in theory (However, in lethe for the
2287 // sake of using the test
2288 // function that has pressure components, we also have an extra pressure
2289 // component in the traction function but it is always zero and does not
2290 // affect the result),
2291 // - traction_fn is the prescribed traction on the boundary Γ_N.
2292
2293 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2294 {
2295 // Check if the face is on a boundary
2296 if (scratch_data.is_boundary_face[f])
2297 {
2298 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2299 // Check if the face is part of the boundary that as a
2300 // Neumann traction BC.
2301 if (this->neumann_traction_boundary_condition.type.at(boundary_id) ==
2303 {
2304 // Assemble the rhs of the BC
2305 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2306 {
2307 const double JxW = scratch_data.face_JxW[f][q];
2308
2309
2310 traction_vec_data[f][q][0] =
2311 neumann_traction_boundary_condition.navier_stokes_functions
2312 .at(boundary_id)
2313 ->traction_fn.value(
2314 scratch_data.face_quadrature_points[f][q], 0);
2315 traction_vec_data[f][q][1] =
2316 neumann_traction_boundary_condition.navier_stokes_functions
2317 .at(boundary_id)
2318 ->traction_fn.value(
2319 scratch_data.face_quadrature_points[f][q], 1);
2320 if constexpr (dim == 3)
2321 traction_vec_data[f][q][2] =
2323 .navier_stokes_functions.at(boundary_id)
2324 ->traction_fn.value(
2325 scratch_data.face_quadrature_points[f][q], 2);
2326
2327 for (const unsigned int i :
2328 scratch_data.fe_face_values.dof_indices())
2329 {
2330 local_rhs(i) -= -scratch_data.face_phi_u[f][q][i] *
2331 (traction_vec_data[f][q]) * JxW;
2332 }
2333 }
2334 }
2335 }
2336 }
2337}
2338
2341
2342template <int dim>
2343void
2345 const NavierStokesScratchData<dim> &scratch_data,
2347{
2348 if (!scratch_data.is_boundary_cell)
2349 return;
2350
2351 // Scheme and physical properties
2352 const double kinematic_viscosity = scratch_data.kinematic_viscosity_scale;
2353 // Loop and quadrature information
2354 Tensor<2, dim> identity;
2355 for (int d = 0; d < dim; ++d)
2356 {
2357 identity[d][d] = 1;
2358 }
2359 std::vector<std::vector<Tensor<1, dim>>> prescribed_velocity_values;
2360 prescribed_velocity_values =
2361 std::vector<std::vector<Tensor<1, dim>>>(scratch_data.n_faces,
2362 std::vector<Tensor<1, dim>>(
2363 scratch_data.n_faces_q_points));
2364 const FiniteElement<dim> &fe = scratch_data.fe_face_values.get_fe();
2365
2366 const double penalty_parameter =
2367 1. / std::pow(scratch_data.cell_size, fe.degree + 1);
2368 auto &local_matrix = copy_data.local_matrix;
2369
2370 // Loop over the faces of the cell.
2371 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2372 {
2373 // Check if the face is on a boundary
2374 if (scratch_data.is_boundary_face[f])
2375 {
2376 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2377 // Check if the face is part of the boundary that as a
2378 // pressure BC.
2379 if (this->boundary_conditions.type.at(boundary_id) ==
2381 {
2382 const double beta = boundary_conditions.beta.at(boundary_id);
2383
2384 // Assemble the matrix of the BC
2385 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2386 {
2387 const double JxW = scratch_data.face_JxW[f][q];
2388 for (const unsigned int i :
2389 scratch_data.fe_face_values.dof_indices())
2390 {
2391 const auto comp_i = fe.system_to_component_index(i).first;
2392 if (comp_i < dim)
2393 {
2394 for (const unsigned int j :
2395 scratch_data.fe_face_values.dof_indices())
2396 {
2397 const auto comp_j =
2398 fe.system_to_component_index(j).first;
2399 if (comp_i == comp_j)
2400 {
2401 double beta_terms =
2402 penalty_parameter * beta *
2403 (scratch_data.face_phi_u[f][q][j][comp_i]) *
2404 scratch_data.face_phi_u[f][q][i][comp_i] *
2405 JxW;
2406 double grad_phi_terms =
2407 ((kinematic_viscosity *
2408 scratch_data.face_phi_u[f][q][j]) *
2409 (scratch_data.face_grad_phi_u[f][q][i] *
2410 scratch_data.face_normal[f][q])) *
2411 JxW;
2412 double surface_stress_term =
2413 (kinematic_viscosity *
2414 scratch_data.face_grad_phi_u[f][q][j] *
2415 scratch_data.face_normal[f][q]) *
2416 scratch_data.face_phi_u[f][q][i] * JxW;
2417
2418 local_matrix(i, j) += +beta_terms -
2419 grad_phi_terms -
2420 surface_stress_term;
2421 }
2422 }
2423 }
2424 }
2425 }
2426 }
2427 }
2428 }
2429}
2430
2431template <int dim>
2432void
2434 const NavierStokesScratchData<dim> &scratch_data,
2436{
2437 if (!scratch_data.is_boundary_cell)
2438 return;
2439
2440 // Scheme and physical properties
2441 const double kinematic_viscosity = scratch_data.kinematic_viscosity_scale;
2442
2443 // Loop and quadrature information
2444 Tensor<2, dim> identity;
2445 for (int d = 0; d < dim; ++d)
2446 {
2447 identity[d][d] = 1;
2448 }
2449 std::vector<std::vector<Tensor<1, dim>>> prescribed_velocity_values =
2450 std::vector<std::vector<Tensor<1, dim>>>(scratch_data.n_faces,
2451 std::vector<Tensor<1, dim>>(
2452 scratch_data.n_faces_q_points));
2453
2454 const FiniteElement<dim> &fe = scratch_data.fe_face_values.get_fe();
2455
2456 const double penalty_parameter =
2457 1. / std::pow(scratch_data.cell_size, fe.degree + 1);
2458 auto &local_rhs = copy_data.local_rhs;
2459 // Loop over the faces of the cell.
2460 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2461 {
2462 // Check if the face is on a boundary
2463 if (scratch_data.is_boundary_face[f])
2464 {
2465 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2466 // Check if the face is part of the boundary that has a
2467 // weakly imposed Dirichlet BC.
2468 if (this->boundary_conditions.type.at(boundary_id) ==
2470 {
2471 const double beta = boundary_conditions.beta.at(boundary_id);
2472
2474 &boundary_conditions.navier_stokes_functions.at(boundary_id)->u,
2475 &boundary_conditions.navier_stokes_functions.at(boundary_id)->v,
2476 &boundary_conditions.navier_stokes_functions.at(boundary_id)
2477 ->w);
2478 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2479 {
2480 const double JxW = scratch_data.face_JxW[f][q];
2481 for (int d = 0; d < dim; ++d)
2482 {
2483 prescribed_velocity_values[f][q][d] = function_v.value(
2484 scratch_data.face_quadrature_points[f][q], d);
2485 }
2486 for (const unsigned int i :
2487 scratch_data.fe_face_values.dof_indices())
2488 {
2489 const auto comp_i = fe.system_to_component_index(i).first;
2490 if (comp_i < dim)
2491 {
2492 double beta_terms =
2493 penalty_parameter * beta *
2494 (scratch_data.face_velocity_values[f][q][comp_i] -
2495 prescribed_velocity_values[f][q][comp_i]) *
2496 scratch_data.face_phi_u[f][q][i][comp_i] * JxW;
2497 double grad_phi_terms =
2498 ((kinematic_viscosity *
2499 (scratch_data.face_velocity_values[f][q] -
2500 prescribed_velocity_values[f][q])) *
2501 (scratch_data.face_grad_phi_u[f][q][i] *
2502 scratch_data.face_normal[f][q])) *
2503 JxW;
2504 double surface_stress_term =
2505 (kinematic_viscosity *
2506 scratch_data.face_velocity_gradients[f][q] *
2507 scratch_data.face_normal[f][q] *
2508 scratch_data.face_phi_u[f][q][i]) *
2509 JxW;
2510
2511 local_rhs(i) +=
2512 -beta_terms + grad_phi_terms + surface_stress_term;
2513 }
2514 }
2515 }
2516 }
2517 }
2518 }
2519}
2520
2523
2524template <int dim>
2525void
2527 const NavierStokesScratchData<dim> &scratch_data,
2529{
2530 if (!scratch_data.is_boundary_cell)
2531 return;
2532
2533 // Scheme and physical properties
2534 const double kinematic_viscosity = scratch_data.kinematic_viscosity[0];
2535
2536 // Loop and quadrature information
2537 Tensor<2, dim> identity;
2538 for (int d = 0; d < dim; ++d)
2539 {
2540 identity[d][d] = 1;
2541 }
2542 std::vector<std::vector<Tensor<1, dim>>> prescribed_velocity_values;
2543 prescribed_velocity_values =
2544 std::vector<std::vector<Tensor<1, dim>>>(scratch_data.n_faces,
2545 std::vector<Tensor<1, dim>>(
2546 scratch_data.n_faces_q_points));
2547 const FiniteElement<dim> &fe = scratch_data.fe_face_values.get_fe();
2548
2549 const double penalty_parameter =
2550 1. / std::pow(scratch_data.cell_size, fe.degree + 1);
2551 auto &local_matrix = copy_data.local_matrix;
2552
2553 // Loop over the faces of the cell.
2554 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2555 {
2556 // Check if the face is on a boundary
2557 if (scratch_data.is_boundary_face[f])
2558 {
2559 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2560 // Check if the face is part of the boundary that as a
2561 // pressure BC.
2562 if (this->boundary_conditions.type.at(boundary_id) ==
2564 {
2565 const double beta = boundary_conditions.beta.at(boundary_id);
2566 const double boundary_layer_thickness =
2567 boundary_conditions.boundary_layer_thickness.at(boundary_id);
2568 const double beta_tangent =
2569 kinematic_viscosity / boundary_layer_thickness;
2570
2571 // Assemble the matrix of the BC
2572 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2573 {
2574 const double JxW = scratch_data.face_JxW[f][q];
2575 for (const unsigned int i :
2576 scratch_data.fe_face_values.dof_indices())
2577 {
2578 const auto comp_i = fe.system_to_component_index(i).first;
2579 if (comp_i < dim)
2580 {
2581 for (const unsigned int j :
2582 scratch_data.fe_face_values.dof_indices())
2583 {
2584 const auto comp_j =
2585 fe.system_to_component_index(j).first;
2586 if (comp_i == comp_j)
2587 {
2588 double beta_terms_normal =
2589 penalty_parameter * beta *
2590 scratch_data.face_normal[f][q][comp_i] *
2591 (scratch_data.face_normal[f][q][comp_i] *
2592 scratch_data.face_phi_u[f][q][j][comp_i]) *
2593 scratch_data.face_phi_u[f][q][i][comp_i] *
2594 JxW;
2595 double beta_terms_tangent =
2596 beta_tangent *
2597 (scratch_data.face_phi_u[f][q][j][comp_i] -
2598 scratch_data.face_normal[f][q][comp_i] *
2599 (scratch_data.face_normal[f][q][comp_i] *
2600 scratch_data
2601 .face_phi_u[f][q][j][comp_i])) *
2602 scratch_data.face_phi_u[f][q][i][comp_i] *
2603 JxW;
2604
2605 /* We don't use these terms has its
2606 * seems they don't affect the
2607 * solution for the normal component
2608 */
2609 /*
2610 double
2611 grad_phi_terms =
2612 scratch_data.face_normal[f][q][comp_i]*((kinematic_viscosity
2613 * scratch_data .face_phi_u[f][q][j]) *
2614 (scratch_data
2615 .face_grad_phi_u[f][q][i] *
2616 scratch_data.face_normal[f][q])) *
2617 JxW;
2618 double
2619 surface_stress_term =
2620 scratch_data.face_normal[f][q][comp_i]*
2621 (kinematic_viscosity * scratch_data
2622 .face_grad_phi_u[f][q][j] *
2623 scratch_data.face_normal[f][q]) *
2624 scratch_data.face_phi_u[f][q][i]
2625 * JxW;
2626 */
2627
2628 local_matrix(i, j) +=
2629 +beta_terms_normal +
2630 beta_terms_tangent; //-
2631 // grad_phi_terms
2632 //-
2633 // surface_stress_term;
2634 }
2635 }
2636 }
2637 }
2638 }
2639 }
2640 }
2641 }
2642}
2643
2644template <int dim>
2645void
2647 const NavierStokesScratchData<dim> &scratch_data,
2649{
2650 if (!scratch_data.is_boundary_cell)
2651 return;
2652
2653 // Scheme and physical properties
2654 const double kinematic_viscosity = scratch_data.kinematic_viscosity[0];
2655
2656 // Loop and quadrature information
2657 Tensor<2, dim> identity;
2658 for (int d = 0; d < dim; ++d)
2659 {
2660 identity[d][d] = 1;
2661 }
2662 std::vector<std::vector<Tensor<1, dim>>> prescribed_velocity_values =
2663 std::vector<std::vector<Tensor<1, dim>>>(scratch_data.n_faces,
2664 std::vector<Tensor<1, dim>>(
2665 scratch_data.n_faces_q_points));
2666
2667 const FiniteElement<dim> &fe = scratch_data.fe_face_values.get_fe();
2668
2669 const double penalty_parameter =
2670 1. / std::pow(scratch_data.cell_size, fe.degree + 1);
2671 auto &local_rhs = copy_data.local_rhs;
2672 // Loop over the faces of the cell.
2673 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2674 {
2675 // Check if the face is on a boundary
2676 if (scratch_data.is_boundary_face[f])
2677 {
2678 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2679
2680 // Check if the face is part of the boundary that has a
2681 // weakly imposed Dirichlet BC.
2682 if (this->boundary_conditions.type.at(boundary_id) ==
2684 {
2685 const double beta = boundary_conditions.beta.at(boundary_id);
2686 const double boundary_layer_thickness =
2687 boundary_conditions.boundary_layer_thickness.at(boundary_id);
2688 const double beta_tangent =
2689 kinematic_viscosity / boundary_layer_thickness;
2691 &boundary_conditions.navier_stokes_functions.at(boundary_id)->u,
2692 &boundary_conditions.navier_stokes_functions.at(boundary_id)->v,
2693 &boundary_conditions.navier_stokes_functions.at(boundary_id)
2694 ->w);
2695 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2696 {
2697 const double JxW = scratch_data.face_JxW[f][q];
2698 for (int d = 0; d < dim; ++d)
2699 {
2700 prescribed_velocity_values[f][q][d] = function_v.value(
2701 scratch_data.face_quadrature_points[f][q], d);
2702 }
2703 for (const unsigned int i :
2704 scratch_data.fe_face_values.dof_indices())
2705 {
2706 const auto comp_i = fe.system_to_component_index(i).first;
2707 if (comp_i < dim)
2708 {
2709 double beta_terms_normal =
2710 scratch_data.face_normal[f][q][comp_i] *
2711 penalty_parameter * beta *
2712 (scratch_data.face_normal[f][q][comp_i] *
2713 scratch_data.face_velocity_values[f][q][comp_i] -
2714 scratch_data.face_normal[f][q][comp_i] *
2715 prescribed_velocity_values[f][q][comp_i]) *
2716 scratch_data.face_phi_u[f][q][i][comp_i] * JxW;
2717 double beta_terms_tangent =
2718 beta_tangent *
2719 (scratch_data.face_velocity_values[f][q][comp_i] -
2720 scratch_data.face_normal[f][q][comp_i] *
2721 (scratch_data.face_normal[f][q][comp_i] *
2722 scratch_data
2723 .face_velocity_values[f][q][comp_i]) -
2724 (prescribed_velocity_values[f][q][comp_i] -
2725 scratch_data.face_normal[f][q][comp_i] *
2726 (scratch_data.face_normal[f][q][comp_i] *
2727 prescribed_velocity_values[f][q][comp_i]))) *
2728 scratch_data.face_phi_u[f][q][i][comp_i] * JxW;
2729 /* We don't use these terms has its seems they
2730 * don't affect the solution for the normal
2731 * component */
2732 /*
2733 double grad_phi_terms =
2734 scratch_data.face_normal[f][q][comp_i]*((kinematic_viscosity
2735 * (scratch_data.face_velocity_values[f][q] -
2736 prescribed_velocity_values[f][q])) *
2737 (scratch_data.face_grad_phi_u[f][q][i] *
2738 scratch_data.face_normal[f][q])) *
2739 JxW;
2740 double surface_stress_term =
2741 scratch_data.face_normal[f][q][comp_i]*(kinematic_viscosity
2742 * scratch_data .face_velocity_gradients[f][q]
2743 * scratch_data.face_normal[f][q] *
2744 scratch_data.face_phi_u[f][q][i]) *
2745 JxW;*/
2746
2747
2748
2749 local_rhs(i) +=
2750 -beta_terms_normal -
2751 beta_terms_tangent; //+ grad_phi_terms +
2752 // surface_stress_term;
2753 }
2754 }
2755 }
2756 }
2757 }
2758 }
2759}
2760
2763
2764template <int dim>
2765void
2767 const NavierStokesScratchData<dim> &scratch_data,
2769{
2770 if (!scratch_data.is_boundary_cell)
2771 return;
2772
2773 const FiniteElement<dim> &fe = scratch_data.fe_face_values.get_fe();
2774
2775 const double penalty_parameter =
2776 1. / std::pow(scratch_data.cell_size, fe.degree + 1);
2777 auto &local_matrix = copy_data.local_matrix;
2778
2779 // Loop over the faces of the cell.
2780 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2781 {
2782 // Check if the face is on a boundary
2783 if (scratch_data.is_boundary_face[f])
2784 {
2785 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2786 // Check if the face is part of the boundary that as a
2787 // pressure BC.
2788 if (this->boundary_conditions.type.at(boundary_id) ==
2790 {
2791 const double beta = boundary_conditions.beta.at(boundary_id);
2792
2793 // Assemble the matrix of the BC
2794 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2795 {
2796 const double JxW = scratch_data.face_JxW[f][q];
2797 for (const unsigned int i :
2798 scratch_data.fe_face_values.dof_indices())
2799 {
2800 double normal_outflux =
2801 std::min(0.,
2802 scratch_data.face_velocity_values[f][q] *
2803 scratch_data.face_normal[f][q]);
2804
2805 const auto comp_i = fe.system_to_component_index(i).first;
2806 if (comp_i < dim)
2807 {
2808 for (const unsigned int j :
2809 scratch_data.fe_face_values.dof_indices())
2810 {
2811 const auto comp_j =
2812 fe.system_to_component_index(j).first;
2813 if (comp_i == comp_j)
2814 {
2815 double beta_terms =
2816 penalty_parameter * beta * normal_outflux *
2817 (scratch_data.face_phi_u[f][q][j][comp_i] *
2818 scratch_data.face_phi_u[f][q][i][comp_i]) *
2819 JxW;
2820
2821 local_matrix(i, j) += -beta_terms;
2822 }
2823 }
2824 }
2825 }
2826 }
2827 }
2828 }
2829 }
2830}
2831
2832template <int dim>
2833void
2835 const NavierStokesScratchData<dim> &scratch_data,
2837{
2838 if (!scratch_data.is_boundary_cell)
2839 return;
2840
2841 const FiniteElement<dim> &fe = scratch_data.fe_face_values.get_fe();
2842
2843 const double penalty_parameter =
2844 1. / std::pow(scratch_data.cell_size, fe.degree + 1);
2845 auto &local_rhs = copy_data.local_rhs;
2846
2847 // Loop over the faces of the cell.
2848 for (unsigned int f = 0; f < scratch_data.n_faces; ++f)
2849 {
2850 // Check if the face is on a boundary
2851 if (scratch_data.is_boundary_face[f])
2852 {
2853 types::boundary_id boundary_id = scratch_data.boundary_face_id[f];
2854
2855 // Check if the face is part of the boundary that has a
2856 // weakly imposed Dirichlet BC.
2857 if (this->boundary_conditions.type.at(boundary_id) ==
2859 {
2860 const double beta = boundary_conditions.beta.at(boundary_id);
2861
2862 for (unsigned int q = 0; q < scratch_data.n_faces_q_points; ++q)
2863 {
2864 const double JxW = scratch_data.face_JxW[f][q];
2865 for (const unsigned int i :
2866 scratch_data.fe_face_values.dof_indices())
2867 {
2868 // Calculate beta term depending on the
2869 // value of u*n. If it is positive (outgoing
2870 // flow) then
2871 double normal_outflux =
2872 std::min(0.,
2873 (scratch_data.face_velocity_values[f][q] *
2874 scratch_data.face_normal[f][q]));
2875
2876 const auto comp_i = fe.system_to_component_index(i).first;
2877 if (comp_i < dim)
2878 {
2879 double beta_terms =
2880 penalty_parameter * beta * normal_outflux *
2881 (scratch_data.face_velocity_values[f][q][comp_i] *
2882 scratch_data.face_phi_u[f][q][i][comp_i]) *
2883 JxW;
2884
2885 local_rhs(i) += +beta_terms;
2886 }
2887 }
2888 }
2889 }
2890 }
2891 }
2892}
2893
2894template class OutletBoundaryCondition<2>;
2895template class OutletBoundaryCondition<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
Class that assembles the core of the Navier-Stokes equation. According to the following weak form: ...
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
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
This class implements a pressure boundary condition for the Navier-Stokes equations.
double value(const Point< dim > &point, unsigned int component) const override
Calculates the value of a Function-type fluid dynamics equations.
This class implements a boundary conditions for the fluid dynamics solver where the velocity componen...
double value(const Point< dim > &point, const unsigned int component) const override
Calculates the value of a Function-type fluid dynamics equations.
Class that assembles the transient time arising from BDF time integration for the Navier Stokes equat...
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
const std::shared_ptr< SimulationControl > simulation_control
Class that assembles the core of the Navier-Stokes equation. According to the following weak form: ...
const std::shared_ptr< SimulationControl > simulation_control
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
Class that assembles the core of the Navier-Stokes equation using a Rheological model to predict non-...
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the rhs
const std::shared_ptr< SimulationControl > simulation_control
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 kinematic viscosity.
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Assembles the matrix
Class that assembles the transient term arising from SDIRK time integration for the Navier Stokes equ...
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
Class that assembles the coriolis and the centrifugal if a simulation is carried out in a rotating fr...
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
Parameters::VelocitySource velocity_sources
Class that assembles a Poisson problem for all velocity components and pressure variables....
const std::shared_ptr< SimulationControl > simulation_control
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
Class that stores the information required by the assembly procedure for a Navier-Stokes equation....
Table< 2, Tensor< 1, dim > > face_normal
std::vector< Tensor< 1, dim > > sdirk_stage_sum
std::vector< Tensor< 1, dim > > force
SDIRKTable sdirk_table
SDIRK Butcher table with coefficients for the SDIRK time-stepping method.
Table< 3, Tensor< 2, dim > > face_grad_phi_u
std::vector< Tensor< 3, dim > > velocity_hessians
std::vector< std::vector< Tensor< 1, dim > > > previous_velocity_values
std::vector< unsigned int > components
std::vector< Tensor< 2, dim > > velocity_gradients
std::vector< Point< dim > > quadrature_points
Table< 2, Tensor< 1, dim > > phi_u
std::vector< Tensor< 1, dim > > advective_velocity
std::vector< double > kinematic_viscosity
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< std::vector< Tensor< 1, dim > > > face_velocity_values
Table< 3, Tensor< 1, dim > > face_phi_u
std::vector< double > temperature_values
std::vector< unsigned int > boundary_face_id
std::vector< double > kinematic_viscosity_for_stabilization
std::vector< double > velocity_divergences
std::vector< std::vector< Tensor< 2, dim > > > face_velocity_gradients
Table< 2, Tensor< 1, dim > > grad_phi_p
std::vector< double > grad_kinematic_viscosity_shear_rate
std::vector< std::vector< Point< dim > > > face_quadrature_points
std::vector< Tensor< 1, dim > > pressure_gradients
std::vector< double > thermal_expansion
std::vector< Tensor< 1, dim > > velocity_laplacians
Class that assembles a Neumann traction boundary condition. According to the following weak form: a...
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
const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > & neumann_traction_boundary_condition
Class that assembles the weak formulation of an outlet boundary condition according to the following ...
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
const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > & boundary_conditions
Class that assembles the core of the Navier-Stokes equation. According to the following weak form: ...
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
const std::shared_ptr< SimulationControl > simulation_control
Class that assembles the special case of partial slip condition using the weak formulation of a Diric...
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
const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > & boundary_conditions
Assembler of the non-linear Carman-Kozeny permeability model for simulations with phase change.
const double carman_kozeny_permeability_area_inv
One over the permeability area of the pseudo-porous bed (solid phase).
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
Assemble the right-hand side (rhs) of:
const double liquidus_temperature
Liquidus temperature.
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
Assembles the matrix of:
const double solidus_temperature
Solidus temperature.
const double carman_kozeny_tolerance
Tolerance in the Carman-Kozeny source term that avoids division by zero.
Class that assembles a phase change Darcy forcing term. This term adds to the right hand-side of the...
const Parameters::PhaseChange phase_change_parameters
virtual void assemble_matrix(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_matrix Assembles the matrix of:
virtual void assemble_rhs(const NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
assemble_rhs Assembles the weak form of:
Class that assembles a Neumann boundary condition. According to the following weak form: (p-mu*grad_u...
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
const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > & pressure_boundary_conditions
std::vector< double > a_ij
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
Class that assembles a thermal buoyancy forcing term using the Boussinesq approximation....
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...
Class that assembles the weak formulation of a Dirichlet boundary condition using the Nitsche method....
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
const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > & boundary_conditions
@ 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.