Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
fluid_dynamics_matrix_free_operators.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2023-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_fluid_dynamics_matrix_free_operators_h
5#define lethe_fluid_dynamics_matrix_free_operators_h
6
7#include <core/bdf.h>
12
14
15#include <deal.II/base/timer.h>
16
17#include <deal.II/lac/dynamic_sparsity_pattern.h>
18#include <deal.II/lac/trilinos_sparse_matrix.h>
19
20#include <deal.II/matrix_free/fe_evaluation.h>
21#include <deal.II/matrix_free/matrix_free.h>
22#include <deal.II/matrix_free/operators.h>
23#include <deal.II/matrix_free/tools.h>
24
25using namespace dealii;
26
27/**
28 * @brief Data structure to store time-stepping data in the matrix-free operator. This is a very small structure that is used to simplify the operator process instead of relying on function calls to the SimulationControl object. It should not be used outside of the operator.
29 *
30 */
32{
33 // Diagonal coefficient for sdirk methods
34 double a_ii = 0.0;
35 // Time step
36 double dt = 0.0;
37 // Coefficients used in the bdf methods
38 const Vector<double> *bdf_coefficients = nullptr;
39
40 // Boolean indicating that the method is an SDIRK method
41 bool is_sdirk = false;
42
43 /// Boolean indicating that the method is a BDF method
44 bool is_bdf = false;
45
46 /// Boolean indicating if the method is transient
47 bool is_transient = false;
48};
49
50
51/**
52 * @brief Evaluate the value of a function at a batch of points to obtain a vectorized array of numbers
53 *
54 * @tparam dim An integer that denotes the number of spatial dimensions.
55 * @tparam Number Abstract type for number across the class (i.e., double).
56 * @param function Function to evaluate.
57 * @param p_vectorized Batch of points to evaluate function at.
58 * @param component Component of the function to evaluate.
59 * @return VectorizedArray<Number> Batch of evaluated values.
60 */
61template <int dim, typename Number>
62VectorizedArray<Number>
63evaluate_function(const Function<dim> &function,
64 const Point<dim, VectorizedArray<Number>> &p_vectorized,
65 const unsigned int component = 0)
66{
67 VectorizedArray<Number> result;
68 for (unsigned int v = 0; v < VectorizedArray<Number>::size(); ++v)
69 {
70 Point<dim> p;
71 for (int d = 0; d < dim; ++d)
72 p[d] = p_vectorized[d][v];
73 result[v] = function.value(p, component);
74 }
75 return result;
76}
77
78/**
79 * @brief Evaluate the gradient of a function at a batch of points to obtain a tensor of vectorized arrays
80 *
81 * @tparam dim An integer that denotes the number of spatial dimensions.
82 * @tparam Number Abstract type for number across the class (i.e., double).
83 * @param function Function to evaluate.
84 * @param p_vectorized Batch of points to evaluate function at.
85 * @return Tensor<1, components, VectorizedArray<Number>> Batch of evaluated gradients.
86 */
87template <int dim, typename Number>
88Tensor<1, dim, VectorizedArray<Number>>
90 const Function<dim> &function,
91 const Point<dim, VectorizedArray<Number>> &p_vectorized)
92{
93 Tensor<1, dim, VectorizedArray<Number>> result;
94 for (unsigned int v = 0; v < VectorizedArray<Number>::size(); ++v)
95 {
96 Point<dim> p;
97 for (int d = 0; d < dim; ++d)
98 p[d] = p_vectorized[d][v];
99
100 Tensor<1, dim> gradient = function.gradient(p);
101 for (int d = 0; d < dim; ++d)
102 result[d][v] = gradient[d];
103 }
104 return result;
105}
106
107/**
108 * @brief Evaluate the value of a function at a batch of points to obtain a tensor of vectorized arrays
109 *
110 * @tparam dim An integer that denotes the number of spatial dimensions.
111 * @tparam Number Abstract type for number across the class (i.e., double).
112 * @tparam components Number of solution components.
113 * @param function Function to evaluate.
114 * @param p_vectorized Batch of points to evaluate function at.
115 * @return Tensor<1, components, VectorizedArray<Number>> Batch of evaluated values.
116 */
117template <int dim, typename Number, int components>
118Tensor<1, components, VectorizedArray<Number>>
119evaluate_function(const Function<dim> &function,
120 const Point<dim, VectorizedArray<Number>> &p_vectorized)
121{
122 Tensor<1, components, VectorizedArray<Number>> result;
123 for (unsigned int v = 0; v < VectorizedArray<Number>::size(); ++v)
124 {
125 Point<dim> p;
126 for (int d = 0; d < dim; ++d)
127 p[d] = p_vectorized[d][v];
128 for (int d = 0; d < components; ++d)
129 result[d][v] = function.value(p, d);
130 }
131 return result;
132}
133
134/**
135 * @brief Check if a boundary condition type requires face assembly in the
136 * matrix-free operator.
137 *
138 * @param boundary_type Type of the boundary condition.
139 * @return true if the boundary condition requires face assembly.
140 */
141inline bool
156
157/**
158 * @brief A class that serves as base for all the matrix-free
159 * Navier-Stokes operators.
160 *
161 * @tparam dim An integer that denotes the number of spatial dimensions.
162 * @tparam number Abstract type for number across the class (i.e., double).
163 */
164template <int dim, typename number>
165class NavierStokesOperatorBase : public EnableObserverPointer
166{
167public:
168 using FECellIntegrator = FEEvaluation<dim, -1, 0, dim + 1, number>;
169 using FEFaceIntegrator = FEFaceEvaluation<dim, -1, 0, dim + 1, number>;
170 using VectorType = LinearAlgebra::distributed::Vector<number>;
171 using value_type = number;
172 using size_type = VectorizedArray<number>;
175
176 /**
177 * @brief Default constructor.
178 */
180
181 /**
182 * @brief Constructor that points to the reinit function.
183 *
184 * @param[in] mapping Describes the transformations from unit to real cell.
185 * @param[in] dof_handler Describes the layout of DoFs and the type of FE.
186 * @param[in] constraints Object with constraints according to DoFs.
187 * @param[in] quadrature Required for local operations on cells.
188 * @param[in] forcing_function Function specified in parameter file as source
189 * term.
190 * @param[in] properties_manager The physical properties manager (see
191 physical_properties_manager.h)
192 * @param[in] stabilization Stabilization type specified in parameter file.
193 * @param[in] mg_level Level of the operator in case of MG methods.
194 * @param[in] simulation_control Required to get the time stepping method.
195 * @param[in] physical_properties_manager Required to have the updated values
196 * of physical properties in case of ramp or viscous initial conditions.
197 * @param[in] boundary_conditions Contains information regarding all boundary
198 * conditions. Required to weakly impose boundary conditions.
199 * @param[in] enable_hessians_jacobian Flag to turn hessian terms from
200 * jacobian on or off.
201 * @param[in] enable_hessians_residual Flag to turn hessian terms from
202 * residual on or off.
203 * @param[in] enable_mortar Flag to turn mortar parameters on or off.
204
205 */
207 const Mapping<dim> &mapping,
208 const DoFHandler<dim> &dof_handler,
209 const AffineConstraints<number> &constraints,
210 const Quadrature<dim> &quadrature,
211 const std::shared_ptr<Function<dim>> &forcing_function,
212 const std::shared_ptr<PhysicalPropertiesManager>
213 &physical_properties_manager,
215 const unsigned int mg_level,
216 const std::shared_ptr<SimulationControl> &simulation_control,
219 const bool &enable_hessians_jacobian,
220 const bool &enable_hessians_residual,
221 const bool &enable_mortar);
222
223 /**
224 * @brief Initialize the main matrix free object that contains all data and is
225 * needed to perform loops over cells, and initialize relevant member
226 * variables such as parameters and element size. Calculate edge constraints
227 * in case the local smoothing multigrid is used.
228 *
229 * @param[in] mapping Describes the transformations from unit to real cell.
230 * @param[in] dof_handler Describes the layout of DoFs and the type of FE.
231 * @param[in] constraints Object with constraints according to DoFs.
232 * @param[in] quadrature Required for local operations on cells.
233 * @param[in] forcing_function Function specified in parameter file as source
234 * term.
235 * @param[in] properties_manager The physical properties manager (see
236 * physical_properties_manager.h)
237 * @param[in] stabilization Stabilization type specified in parameter file.
238 * @param[in] mg_level Level of the operator in case of MG methods.
239 * @param[in] simulation_control Required to get the time stepping method.
240 * @param[in] boundary_conditions Contains information regarding all
241 * boundary conditions. Required to weakly impose boundary conditions.
242 * @param[in] enable_hessians_jacobian Flag to turn hessian terms from
243 * jacobian on or off.
244 * @param[in] enable_hessians_residual Flag to turn hessian terms from
245 * residual on or off.
246 * @param[in] enable_mortar Flag to turn mortar parameters on or off.
247 */
248 void
249 reinit(const Mapping<dim> &mapping,
250 const DoFHandler<dim> &dof_handler,
251 const AffineConstraints<number> &constraints,
252 const Quadrature<dim> &quadrature,
253 const std::shared_ptr<Function<dim>> &forcing_function,
254 const std::shared_ptr<PhysicalPropertiesManager>
255 &physical_properties_manager,
257 const unsigned int mg_level,
258 const std::shared_ptr<SimulationControl> &simulation_control,
261 const bool &enable_hessians_jacobian,
262 const bool &enable_hessians_residual,
263 const bool &enable_mortar);
264
265 /**
266 * @brief Compute the element size h of the cells required to calculate
267 * stabilization parameters.
268 */
269 void
271
272 /**
273 * @brief Compute a per-cell-batch mask that suppresses contributions from
274 * solid cells (material_id > 0). Each lane of @p solid_cell_mask is set to
275 * 1.0 for fluid cells and 0.0 for solid cells, mirroring the matrix-based
276 * behavior where solid cells are skipped during assembly.
277 */
278 void
280
281 /**
282 * @brief Precompute forcing term at the quadrature points. This is called
283 * when the operator is initialized and must be called again whenever the
284 * time of the forcing function changes, since the forcing function is
285 * otherwise only evaluated at the time at which the operator was
286 * initialized.
287 */
288 virtual void
290
291
292 /**
293 * @brief Precompute thermal buoyancy term for heat-transfer coupling.
294 *
295 * @param[in] temperature_solution Present solution of the temperature
296 * as given by the multiphysics interface.
297 * @param[in] temperature_dof_handler DoF Handler used for the heat transfer.
298 */
299 void
300 compute_thermal_buoyancy_term(const VectorType &temperature_solution,
301 const DoFHandler<dim> &temperature_dof_handler);
302
303 /**
304 * @brief Get the total number of DoFs.
305 *
306 * @return Total number of degrees of freedom.
307 */
308 types::global_dof_index
309 m() const;
310
311 /**
312 * @brief Access a particular element in the matrix. Only required
313 * for compilation and it is not used.
314 *
315 * @param int
316 * @param int
317 * @return number
318 */
319 number
320 el(unsigned int, unsigned int) const;
321
322 /**
323 * @brief Clear the matrix-free object.
324 */
325 void
327
328 /**
329 * @brief Initialize a given vector by delegating it to the MatrixFree
330 * function in charge of this task.
331 *
332 * @param[in,out] vec Vector to be initialized.
333 */
334 void
336
337 /**
338 * @brief Get the vector partitioner object required for local smoothing
339 * multigrid preconditioner.
340 *
341 * @return Pointer to vector partitioner.
342 */
343 const std::shared_ptr<const Utilities::MPI::Partitioner> &
345
346 /**
347 * @brief Perform an operator evaluation dst = A*src by looping with the help of the
348 * MatrixFree object over all cells and evaluating the effect of cell
349 * integrals.
350 *
351 * @param[in,out] dst Destination vector holding the result.
352 * @param[in] src Input source vector.
353 */
354 void
355 vmult(VectorType &dst, const VectorType &src) const;
356
357 /**
358 * @brief Perform the transposed operator evaluation.
359 *
360 * @param[in,out] dst Destination vector holding the result.
361 * @param[in] src Input source vector.
362 */
363 void
364 Tvmult(VectorType &dst, const VectorType &src) const;
365
366 /**
367 * @brief Vmult operator for an interface. Required only if local smoothing
368 * multigrid is used and for meshes with hanging nodes.
369 *
370 * @param[in,out] dst Destination vector holding the result.
371 * @param[in] src Input source vector.
372 */
373 void
375
376 /**
377 * @brief Vmult operator for an interface. Required only if local smoothing
378 * multigrid is used and for meshes with hanging nodes.
379 *
380 * @param[in,out] dst Destination vector holding the result.
381 * @param[in] src Input source vector.
382 */
383 void
384 vmult_interface_up(VectorType &dst, VectorType const &src) const;
385
386 /**
387 * @brief Return sparsity pattern used to set up the sparse matrix by
388 * get_system_matrix().
389 *
390 * @return Sparsity pattern.
391 */
392 const DynamicSparsityPattern &
394
395 /**
396 * @brief Calculate matrix if needed, e.g., by coarse-grid solver when a multigrid
397 * algorithm is used.
398 *
399 * @return Trilinos sparse matrix.
400 */
401 const TrilinosWrappers::SparseMatrix &
403
404 /**
405 * @brief Get the system matrix free object.
406 *
407 * @return Matrix free object.
408 */
409 const MatrixFree<dim, number> &
411
412 /**
413 * @brief Get the element size object.
414 *
415 * @return Aligned vector with the size of all elements.
416 */
417 const AlignedVector<VectorizedArray<number>>
419
420 /**
421 * @brief Compute the diagonal of the operator using an optimized MatrixFree
422 * function. Needed for preconditioners.
423 *
424 * @param[in,out] diagonal The vector where the computed diagonal is stored.
425 */
426 void
428
429 /**
430 * @brief Store the values of the prescribed Neumann traction boundary condition to use it
431 * \f$
432 * (\boldsymbol{\sigma} \cdot \mathbf{n},\, \mathbf{v}) =
433 * (\mathrm{traction\_fn},\, \mathbf{v})\f$.
434 * in the residual assembly and Jacobian assembly of the matrix-free operator.
435 */
436 void
438
439 /**
440 * @brief Store relevant values of the vector of the last newton step to use it
441 * in the Jacobian and pre-calculate the stabilization parameter tau.
442 *
443 * @param[in] newton_step Vector of the last newton step.
444 */
445 virtual void
447
448 /**
449 * @brief Store the values of the vector containing the time derivatives of
450 * previous solutions to use them in the Jacobian and residual cell integrals.
451 *
452 * @param[in] time_derivative_previous_solutions Vector with the time
453 * derivative of previous solutions.
454 */
455 void
457 const VectorType &time_derivative_previous_solutions);
458
459 /**
460 * @brief Store the values of the vector containing the ALE velocity to use
461 * them in the Jacobian and residual cell integrals. This function is called
462 * when the mortar feature is enabled.
463 *
464 * @param[in] mapping Describes the transformations from unit to real cell.
465 * @param[in] center_of_rotation Center of rotation of the rotor domain.
466 * @param[in] rotation_axis_direction Direction of the rotation axis.
467 * @param[in] rotor_angular_velocity Angular velocity of the rotor domain.
468 */
469 void
470 evaluate_velocity_ale(const Mapping<dim> &mapping,
471 const Point<dim> center_of_rotation,
472 const unsigned int rotation_axis_direction,
473 const std::shared_ptr<Functions::ParsedFunction<dim>>
474 &rotor_angular_velocity);
475
476 /**
477 * @brief Store the values of the source term calculated if dynamic control
478 * is enabled in the appropriate structure.
479 *
480 * @param[in] beta_force Source term calculated by the dynamic flow control.
481 */
482 void
483 update_beta_force(const Tensor<1, dim> &beta_force);
484
485 /**
486 * @brief Evaluate right hand side using the matrix-free operator.
487 *
488 * @param[in,out] dst Destination vector holding the result.
489 * @param[in] src Input vector for which the residual is evaluated.
490 */
491 void
493
494 /**
495 * @brief Mortar coupling manager, operator, and evaluator used in the matrix-free
496 * solver. The matrix-based solver uses the shared pointers created in the NS
497 * base. Because we have a different system_operator here, we need to create
498 * new pointers.
499 */
500 std::shared_ptr<MortarManagerBase<dim>> mortar_manager_mf;
501 std::shared_ptr<CouplingOperator<dim, double>> mortar_coupling_operator_mf;
502 std::shared_ptr<NavierStokesCouplingEvaluationSIPG<dim, double>>
504
505protected:
506 /**
507 * @brief Interface to function that performs a cell integral in a cell batch
508 * without gathering and scattering the values. Should be overriden by derived
509 * classes.
510 *
511 * @param[in] integrator FEEvaluation object that allows to evaluate functions
512 * at quadrature points and perform cell integrations.
513 */
514 virtual void
516
517 /**
518 * @brief Loop over all cell batches within certain range and perform a cell
519 * integral with access to global vectors, i.e., gathering and scattering
520 * values.
521 *
522 * @param[in] matrix_free Object that contains all data.
523 * @param[in,out] dst Global vector where the final result is added.
524 * @param[in] src Input vector with all values in all cells.
525 * @param[in] range Range of the cell batch.
526 */
527 void
529 const MatrixFree<dim, number> &matrix_free,
530 VectorType &dst,
531 const VectorType &src,
532 const std::pair<unsigned int, unsigned int> &range) const;
533
534 /**
535 * @brief Carry out the integration of boundary face integrals.
536 *
537 * @tparam assemble_residual Flag to assemble the residual or the Jacobian.
538 *
539 * @param[in] integrator FEFaceEvaluation object that allows to evaluate
540 * functions at quadrature points and perform face integrations.
541 */
542 template <bool assemble_residual>
543 void
545
546 /**
547 * @brief Loop over all boundary face batches within certain range and perform a face
548 * integral with access to global vectors, i.e., gathering and scattering
549 * values. This is used to weakly impose Dirichlet boundary conditions or
550 * outlet boundary conditions.
551 *
552 * @tparam assemble_residual Flag to assemble the residual or the Jacobian.
553 *
554 * @param[in] matrix_free Object that contains all data.
555 * @param[in,out] dst Global vector where the final result is added.
556 * @param[in] src Input vector with all values in all cells.
557 * @param[in] range Range of the face batch.
558 */
559 template <bool assemble_residual>
560 void
562 const MatrixFree<dim, number> &matrix_free,
563 VectorType &dst,
564 const VectorType &src,
565 const std::pair<unsigned int, unsigned int> &range) const;
566
567 /**
568 * @brief Loop over all internal face batches within certain range and perform a face
569 * integral with access to global vectors, i.e., gathering and scattering
570 * values. This is only required for compilation and not needed for our CG
571 * implementation.
572 *
573 * @param[in] matrix_free Object that contains all data.
574 * @param[in,out] dst Global vector where the final result is added.
575 * @param[in] src Input vector with all values in all cells.
576 * @param[in] range Range of the face batch.
577 */
578 void
580 const MatrixFree<dim, number> &matrix_free,
581 VectorType &dst,
582 const VectorType &src,
583 const std::pair<unsigned int, unsigned int> &range) const;
584
585 /**
586 * @brief Interface to function in charge of computing the residual using a cell
587 * integral in a cell batch with gathering and scattering values. Should be
588 * overriden by derived classes.
589 *
590 * @param[in] matrix_free Object that contains all data.
591 * @param[in,out] dst Global vector where the final result is added.
592 * @param[in] src Input vector with all values in all cells.
593 * @param[in] range Range of the cell batch.
594 */
595 virtual void
597 const MatrixFree<dim, number> &matrix_free,
598 VectorType &dst,
599 const VectorType &src,
600 const std::pair<unsigned int, unsigned int> &range) const = 0;
601
602 /**
603 * @brief Initialize time stepping data such as the time step size and BDF
604 * coefficients.
605 *
606 * @return TimeSteppingData structure containing all of the information for time-stepping
607
608 */
611
612
613private:
614 /**
615 * @brief Get the refinement edges. Only needed if the local smoothing
616 * multigrid approach is used.
617 *
618 * @param[in] matrix_free Object that contains all data.
619 *
620 * @return Set containing the indices of the refinement edges.
621 */
622 static IndexSet
623 get_refinement_edges(const MatrixFree<dim, number> &matrix_free);
624
625protected:
626 /**
627 * @brief Object storing all the relevant data needed for the matrix free
628 * implementation.
629 *
630 */
631 MatrixFree<dim, number> matrix_free;
632
633 /**
634 * @brief Object that stores constraints for the matrix free implementation.
635 *
636 */
637 AffineConstraints<number> constraints;
638
639 /**
640 * @brief Sparsity pattern used when the matrix of certain level is computed
641 * and stored.
642 */
643 mutable DynamicSparsityPattern dsp;
644
645 /**
646 * @brief Sparse trilinos matrix used when the matrix of certain level is computed
647 * and stored.
648 *
649 */
650 mutable TrilinosWrappers::SparseMatrix system_matrix;
651
652 /**
653 * @brief Aligned vector to store the element size of all the elements.
654 *
655 */
656 AlignedVector<VectorizedArray<number>> element_size;
657
658 /**
659 * @brief Per-cell-batch mask used to suppress contributions from solid
660 * cells (material_id > 0) inside the cell integrals. Each lane is 1.0 for
661 * fluid cells and 0.0 for solid cells. Mirrors the matrix-based behavior
662 * where solid cells are skipped during assembly. Only filled when
663 * @p has_solids is true.
664 *
665 */
666 AlignedVector<VectorizedArray<number>> solid_cell_mask;
667
668 /**
669 * @brief Flag indicating whether the simulation contains any solid region
670 * (material_id > 0). When false, the solid-cell masking is skipped
671 * entirely so the no-solid case has zero overhead in the inner loop.
672 *
673 */
674 bool has_solids = false;
675
676 /**
677 * @brief Finite element degree for the operator.
678 *
679 */
680 unsigned int fe_degree;
681
682 /**
683 * @brief Force function or source function for the Navier-Stokes equations.
684 *
685 */
686 std::shared_ptr<Function<dim>> forcing_function;
687
688 /**
689 * @brief Additional source term in the case of dynamic flow control.
690 *
691 */
692 Tensor<1, dim, VectorizedArray<number>> beta_force;
693
694 /**
695 * @brief Stabilization type needed to add or remove terms from operator.
696 *
697 */
699
700 /**
701 * @brief Object storing the information regarding the time stepping method.
702 *
703 */
704 std::shared_ptr<SimulationControl> simulation_control;
705
706 /**
707 * @brief Object pointing to the physical properties manager of the matrix free class.
708 *
709 */
710 std::shared_ptr<PhysicalPropertiesManager> properties_manager;
711
712 /**
713 * @brief Boundary conditions object to impose the correct boundary conditions. This object
714 * is only used to impose boundary conditions that appear in the weak form as
715 * face terms (Weak Dirichlet boundary conditions and, eventually, outlets).
716 * However, the entire boundary_conditions object is stored instead of trying
717 * to isolate which parameters are used since many of them are used in the
718 * initialization of the boundary conditions.
719 *
720 */
722
723 /**
724 * @brief Flag to turn hessian terms from jacobian on or off.
725 *
726 */
728
729 /**
730 * @brief Flag to turn hessian terms from residual on or off.
731 *
732 */
734
735 /**
736 * @brief Table with precomputed forcing term values.
737 *
738 */
739 Table<2, Tensor<1, dim, VectorizedArray<number>>> forcing_terms;
740
741
742 /**
743 * @brief Table with precomputed thermal buoyancy term values.
744 *
745 */
746 Table<2, Tensor<1, dim, VectorizedArray<number>>> thermal_buoyancy_term;
747
748 /**
749 * @brief Flag to turn the calculation of face terms on or off.
750 * This is used for weakly imposed Dirichlet boundary conditions or outlets.
751 *
752 */
754
755 /**
756 * @brief Table with correct alignment for vectorization to store the values
757 * of the previous newton step.
758 *
759 */
760 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
762
763 /**
764 * @brief Table with correct alignment for vectorization to store the gradients
765 * of the previous newton step.
766 *
767 */
768 Table<2, Tensor<1, dim + 1, Tensor<1, dim, VectorizedArray<number>>>>
770
771 /**
772 * @brief Table with correct alignment for vectorization to store the hessian
773 * diagonal of the previous newton step.
774 *
775 */
776 Table<2, Tensor<1, dim + 1, Tensor<1, dim, VectorizedArray<number>>>>
778
779 /**
780 * @brief Table with correct alignment for vectorization to store the hessian
781 * of the previous newton step.
782 *
783 */
784 Table<2, Tensor<1, dim + 1, Tensor<2, dim, VectorizedArray<number>>>>
786
787 /**
788 * @brief Table with correct alignment for vectorization to store the time derivatives
789 * of previous solutions.
790 *
791 */
792 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
794
795 /**
796 * @brief Table with correct alignment for vectorization to store the values
797 * of the velocity at faces.
798 *
799 */
800 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
802
803 /**
804 * @brief Table with correct alignment for vectorization to store the values
805 * of the target velocity of a weakly imposed Dirichlet boundary condition.
806 *
807 */
808 Table<2, Tensor<1, dim, VectorizedArray<number>>> face_target_velocity;
809
810 /**
811 * @brief Table with correct alignment for vectorization to store the values
812 * of the target pressure of a pressure boundary condition.
813 *
814 */
815 Table<2, VectorizedArray<number>> face_target_pressure;
816
817 /**
818 * @brief Table with correct alignment for vectorization to store the values
819 * of the prescribed Neumann traction boundary condition values.
820 *
821 * \f$
822 * (\boldsymbol{\sigma} \cdot \mathbf{n},\, \mathbf{v}) =
823 * (\mathrm{traction\_fn},\, \mathbf{v})\f$.
824 * assembled \f$(\mathbf{v},\mathrm{traction\_fn})\f$ on boundary faces where
825 * Neumann traction is prescribed. Our test function v involves both velocity
826 * and pressure components. Hence, the prescribed_neumann_traction has
827 * \f$\dim\f$ components corresponding to velocity and 1 component
828 * corresponding to pressure (which is dummy), totalling \f$\dim+1\f$
829 * components.
830 */
831 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
833
834 /**
835 * @brief Table with correct alignment for vectorization to store the values
836 * of the stabilization parameter tau.
837 *
838 */
839 Table<2, VectorizedArray<number>> stabilization_parameter;
840
841 /**
842 * @brief Table with correct alignment for vectorization to store the values
843 * of the stabilization parameter tau lsic.
844 *
845 */
846 Table<2, VectorizedArray<number>> stabilization_parameter_lsic;
847
848
849 /**
850 * @brief Table with correct alignment for vectorization to store the values
851 * of the kinematic viscosity.
852 *
853 */
854 Table<2, VectorizedArray<number>> kinematic_viscosity_vector;
855
856 /**
857 * @brief Table with correct alignment for vectorization to store the values
858 * of the gradient of the kinematic viscosity w.r.t shear rate.
859 *
860 */
861 Table<2, VectorizedArray<number>> grad_kinematic_viscosity_shear_rate;
862
863 /**
864 * @brief Table with correct alignment for vectorization to store the values
865 * of the kinematic viscosity gradient.
866 *
867 */
868 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
870
871 /**
872 * @brief Table with correct alignment for vectorization to store the values
873 * of the shear_rate.
874 *
875 */
876 Table<2, Tensor<1, dim + 1, Tensor<1, dim, VectorizedArray<number>>>>
878
879 /**
880 * @brief Table with correct alignment for vectorization to store the values
881 * of the shear_rate_magnitude.
882 *
883 */
884 Table<2, VectorizedArray<number>> previous_shear_rate_magnitude;
885
886 /**
887 * @brief Table with correct alignment for vectorization to store the values
888 * of the face penalization term effective_beta_face
889 *
890 */
891 Table<1, VectorizedArray<number>> effective_beta_face;
892
893 /**
894 * @brief Flag to turn the computation of mortar coupling terms on or off.
895 */
897
898 /**
899 * @brief Table with correct alignment for vectorization to store the values
900 * of the velocity within the advective term. If ALE is enabled, this term is
901 * given by u - u_ALE. Otherwise, it returns the regular velocity tensor.
902 *
903 */
904 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
906
907 /**
908 * @brief Table with correct alignment for vectorization to store the values
909 * of the ALE velocity used in mortar coupling terms.
910 *
911 */
912 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>> velocity_ale;
913
914 /**
915 * @brief Vector with the constrained indices used for the local smoothing approach.
916 *
917 */
918 std::vector<unsigned int> constrained_indices;
919
920 /**
921 * @brief Vector with the constrained values used for the local smoothing approach.
922 *
923 */
924 mutable std::vector<std::pair<number, number>> constrained_values;
925
926 /**
927 * @brief Vector with the constrained edge indices for the local smoothing approach.
928 *
929 */
930 std::vector<unsigned int> edge_constrained_indices;
931
932 /**
933 * @brief Variable to identify whether there are edge constrained indices for the
934 * local smoothing approach.
935 *
936 */
938
939 /**
940 * @brief Vector with edge constrained values used for the local smoothing approach.
941 *
942 */
943 mutable std::vector<number> edge_constrained_values;
944
945
946 /**
947 * @brief Vector used to mark edge constrained cells in order to verify constrained indices
948 * for the local smoothing approach.
949 *
950 */
951 std::vector<bool> edge_constrained_cell;
952
953 /**
954 * @brief DoF mask object needed for the sparsity pattern and computation of the system
955 * matrix of the coarse level in case FE_Q_iso_Q1 elements are used.
956 *
957 */
958 Table<2, bool> bool_dof_mask;
959
960 /**
961 * @brief Conditional OStream for parallel output.
962 *
963 */
964 ConditionalOStream pcout;
965
966
967public:
968 /**
969 * @brief Timer for internal operator calls.
970 *
971 */
972 mutable TimerOutput timer;
973};
974
975/**
976 * @brief Implements the matrix-free operator to solve steady/transient Navier-Stokes equations
977 * using stabilization.
978 *
979 * @tparam dim An integer that denotes the number of spatial dimensions.
980 * @tparam number Abstract type for number across the class (i.e., double).
981 */
982template <int dim, typename number>
984 : public NavierStokesOperatorBase<dim, number>
985{
986public:
987 using FECellIntegrator = FEEvaluation<dim, -1, 0, dim + 1, number>;
988 using FEFaceIntegrator = FEFaceEvaluation<dim, -1, 0, dim + 1, number>;
989 using VectorType = LinearAlgebra::distributed::Vector<number>;
990
992
993protected:
994 /**
995 * @brief Perform cell integral on a cell batch without gathering and scattering
996 * the values, and according to the Jacobian of the discretized
997 * steady/transient Navier-Stokes equations with stabilization.
998 *
999 * @param[in] integrator FEEvaluation object that allows to evaluate functions
1000 * at quadrature points and perform cell integrations.
1001 */
1002 void
1003 do_cell_integral_local(FECellIntegrator &integrator) const override;
1004
1005 /**
1006 * @brief Perform cell integral on a cell batch with gathering and scattering
1007 * the values, and according to the residual of the discretized
1008 * steady/transient Navier-Stokes equations with stabilization.
1009 *
1010 * @param[in] matrix_free Object that contains all data.
1011 * @param[in,out] dst Global vector where the final result is added.
1012 * @param[in] src Input vector with all values in all cells.
1013 * @param[in] range Range of the cell batch.
1014 */
1015 void
1017 const MatrixFree<dim, number> &matrix_free,
1018 VectorType &dst,
1019 const VectorType &src,
1020 const std::pair<unsigned int, unsigned int> &range) const override;
1021};
1022
1023/**
1024 * @brief Implements the matrix-free operator to solve steady/transient non-Newtonian Navier-Stokes equations using stabilization.
1025 *
1026 * @tparam dim An integer that denotes the number of spatial dimensions.
1027 * @tparam number Abstract type for number across the class (i.e., double).
1028 */
1029template <int dim, typename number>
1031 : public NavierStokesOperatorBase<dim, number>
1032{
1033public:
1034 using FECellIntegrator = FEEvaluation<dim, -1, 0, dim + 1, number>;
1035 using FEFaceIntegrator = FEFaceEvaluation<dim, -1, 0, dim + 1, number>;
1036 using VectorType = LinearAlgebra::distributed::Vector<number>;
1037
1039
1040protected:
1041 /**
1042 * @brief Perform cell integral on a cell batch without gathering and scattering
1043 * the values, and according to the Jacobian of the discretized
1044 * steady/transient Navier-Stokes equations with stabilization.
1045 *
1046 * @param[in] integrator FEEvaluation object that allows to evaluate functions
1047 * at quadrature points and perform cell integrations.
1048 */
1049 void
1050 do_cell_integral_local(FECellIntegrator &integrator) const override;
1051
1052 /**
1053 * @brief Perform cell integral on a cell batch with gathering and scattering
1054 * the values, and according to the residual of the discretized
1055 * steady/transient Navier-Stokes equations with stabilization.
1056 *
1057 * @param[in] matrix_free Object that contains all data.
1058 * @param[in,out] dst Global vector where the final result is added.
1059 * @param[in] src Input vector with all values in all cells.
1060 * @param[in] range Range of the cell batch.
1061 */
1062 void
1064 const MatrixFree<dim, number> &matrix_free,
1065 VectorType &dst,
1066 const VectorType &src,
1067 const std::pair<unsigned int, unsigned int> &range) const override;
1068};
1069
1070#endif
This class manages the boundary conditions forhe fluid dynamics solver It introduces the boundary fun...
FEEvaluation< dim, -1, 0, dim+1, number > FECellIntegrator
void do_cell_integral_local(FECellIntegrator &integrator) const override
Perform cell integral on a cell batch without gathering and scattering the values,...
void local_evaluate_residual(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const override
Perform cell integral on a cell batch with gathering and scattering the values, and according to the ...
FEFaceEvaluation< dim, -1, 0, dim+1, number > FEFaceIntegrator
LinearAlgebra::distributed::Vector< number > VectorType
Table< 2, VectorizedArray< MGNumber > > face_target_pressure
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > nonlinear_previous_advective_values
Table< 2, Tensor< 1, dim, VectorizedArray< MGNumber > > > face_target_velocity
Table< 2, Tensor< 1, dim+1, Tensor< 1, dim, VectorizedArray< MGNumber > > > > nonlinear_previous_gradient
number el(unsigned int, unsigned int) const
Access a particular element in the matrix. Only required for compilation and it is not used.
void evaluate_velocity_ale(const Mapping< dim > &mapping, const Point< dim > center_of_rotation, const unsigned int rotation_axis_direction, const std::shared_ptr< Functions::ParsedFunction< dim > > &rotor_angular_velocity)
Store the values of the vector containing the ALE velocity to use them in the Jacobian and residual c...
virtual void local_evaluate_residual(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const =0
Interface to function in charge of computing the residual using a cell integral in a cell batch with ...
const DynamicSparsityPattern & get_sparsity_pattern() const
Return sparsity pattern used to set up the sparse matrix by get_system_matrix().
std::shared_ptr< NavierStokesCouplingEvaluationSIPG< dim, double > > mortar_coupling_evaluator_mf
void do_boundary_face_integral_local(FEFaceIntegrator &integrator) const
Carry out the integration of boundary face integrals.
Table< 2, Tensor< 1, dim, VectorizedArray< MGNumber > > > forcing_terms
void reinit(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< number > &constraints, const Quadrature< dim > &quadrature, const std::shared_ptr< Function< dim > > &forcing_function, const std::shared_ptr< PhysicalPropertiesManager > &physical_properties_manager, const StabilizationType stabilization, const unsigned int mg_level, const std::shared_ptr< SimulationControl > &simulation_control, const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > &boundary_conditions, const bool &enable_hessians_jacobian, const bool &enable_hessians_residual, const bool &enable_mortar)
Initialize the main matrix free object that contains all data and is needed to perform loops over cel...
virtual void evaluate_non_linear_term_and_calculate_tau(const VectorType &newton_step)
Store relevant values of the vector of the last newton step to use it in the Jacobian and pre-calcula...
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > velocity_ale
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > nonlinear_previous_values
std::shared_ptr< CouplingOperator< dim, double > > mortar_coupling_operator_mf
void update_beta_force(const Tensor< 1, dim > &beta_force)
Store the values of the source term calculated if dynamic control is enabled in the appropriate struc...
std::shared_ptr< PhysicalPropertiesManager > properties_manager
std::vector< std::pair< MGNumber, MGNumber > > constrained_values
void compute_thermal_buoyancy_term(const VectorType &temperature_solution, const DoFHandler< dim > &temperature_dof_handler)
Precompute thermal buoyancy term for heat-transfer coupling.
void evaluate_prescribed_neumann_traction()
Store the values of the prescribed Neumann traction boundary condition to use it ....
Table< 2, Tensor< 1, dim, VectorizedArray< MGNumber > > > thermal_buoyancy_term
void clear()
Clear the matrix-free object.
void vmult_interface_down(VectorType &dst, VectorType const &src) const
Vmult operator for an interface. Required only if local smoothing multigrid is used and for meshes wi...
void vmult(VectorType &dst, const VectorType &src) const
Perform an operator evaluation dst = A*src by looping with the help of the MatrixFree object over all...
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_vector_partitioner() const
Get the vector partitioner object required for local smoothing multigrid preconditioner.
void do_boundary_face_integral_range(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const
Loop over all boundary face batches within certain range and perform a face integral with access to g...
BoundaryConditions::FluidDynamicsBoundaryConditions< dim > boundary_conditions
void compute_element_size()
Compute the element size h of the cells required to calculate stabilization parameters.
Table< 2, VectorizedArray< MGNumber > > stabilization_parameter_lsic
Table< 1, VectorizedArray< MGNumber > > effective_beta_face
types::global_dof_index m() const
Get the total number of DoFs.
void compute_solid_cell_mask()
Compute a per-cell-batch mask that suppresses contributions from solid cells (material_id > 0)....
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > face_nonlinear_previous_values
FEFaceEvaluation< dim, -1, 0, dim+1, MGNumber > FEFaceIntegrator
NavierStokesOperatorBase(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< number > &constraints, const Quadrature< dim > &quadrature, const std::shared_ptr< Function< dim > > &forcing_function, const std::shared_ptr< PhysicalPropertiesManager > &physical_properties_manager, const StabilizationType stabilization, const unsigned int mg_level, const std::shared_ptr< SimulationControl > &simulation_control, const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > &boundary_conditions, const bool &enable_hessians_jacobian, const bool &enable_hessians_residual, const bool &enable_mortar)
Constructor that points to the reinit function.
void evaluate_residual(VectorType &dst, const VectorType &src)
Evaluate right hand side using the matrix-free operator.
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > prescribed_neumann_traction
TimeSteppingData initialize_time_stepping_data() const
Initialize time stepping data such as the time step size and BDF coefficients.
Table< 2, Tensor< 1, dim+1, Tensor< 1, dim, VectorizedArray< MGNumber > > > > previous_shear_rate
AlignedVector< VectorizedArray< MGNumber > > element_size
std::shared_ptr< MortarManagerBase< dim > > mortar_manager_mf
Table< 2, Tensor< 1, dim+1, Tensor< 2, dim, VectorizedArray< MGNumber > > > > nonlinear_previous_hessian
AlignedVector< VectorizedArray< MGNumber > > solid_cell_mask
void evaluate_time_derivative_previous_solutions(const VectorType &time_derivative_previous_solutions)
Store the values of the vector containing the time derivatives of previous solutions to use them in t...
void do_internal_face_integral_range(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const
Loop over all internal face batches within certain range and perform a face integral with access to g...
void do_cell_integral_range(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const
Loop over all cell batches within certain range and perform a cell integral with access to global vec...
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > time_derivatives_previous_solutions
FEEvaluation< dim, -1, 0, dim+1, MGNumber > FECellIntegrator
Parameters::Stabilization::NavierStokesStabilization StabilizationType
void compute_inverse_diagonal(VectorType &diagonal) const
Compute the diagonal of the operator using an optimized MatrixFree function. Needed for preconditione...
virtual void do_cell_integral_local(FECellIntegrator &integrator) const =0
Interface to function that performs a cell integral in a cell batch without gathering and scattering ...
static IndexSet get_refinement_edges(const MatrixFree< dim, number > &matrix_free)
Get the refinement edges. Only needed if the local smoothing multigrid approach is used.
virtual void compute_forcing_term()
Precompute forcing term at the quadrature points. This is called when the operator is initialized and...
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > kinematic_viscosity_gradient
const AlignedVector< VectorizedArray< number > > get_element_size() const
Get the element size object.
void initialize_dof_vector(VectorType &vec) const
Initialize a given vector by delegating it to the MatrixFree function in charge of this task.
const MatrixFree< dim, number > & get_system_matrix_free() const
Get the system matrix free object.
Table< 2, Tensor< 1, dim+1, Tensor< 1, dim, VectorizedArray< MGNumber > > > > nonlinear_previous_hessian_diagonal
Tensor< 1, dim, VectorizedArray< MGNumber > > beta_force
Table< 2, VectorizedArray< MGNumber > > grad_kinematic_viscosity_shear_rate
Table< 2, VectorizedArray< MGNumber > > kinematic_viscosity_vector
Table< 2, VectorizedArray< MGNumber > > stabilization_parameter
void Tvmult(VectorType &dst, const VectorType &src) const
Perform the transposed operator evaluation.
void vmult_interface_up(VectorType &dst, VectorType const &src) const
Vmult operator for an interface. Required only if local smoothing multigrid is used and for meshes wi...
LinearAlgebra::distributed::Vector< MGNumber > VectorType
const TrilinosWrappers::SparseMatrix & get_system_matrix() const
Calculate matrix if needed, e.g., by coarse-grid solver when a multigrid algorithm is used.
Table< 2, VectorizedArray< MGNumber > > previous_shear_rate_magnitude
void local_evaluate_residual(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const override
Perform cell integral on a cell batch with gathering and scattering the values, and according to the ...
void do_cell_integral_local(FECellIntegrator &integrator) const override
Perform cell integral on a cell batch without gathering and scattering the values,...
FEFaceEvaluation< dim, -1, 0, dim+1, number > FEFaceIntegrator
LinearAlgebra::distributed::Vector< number > VectorType
FEEvaluation< dim, -1, 0, dim+1, number > FECellIntegrator
Tensor< 1, dim, VectorizedArray< Number > > evaluate_function_gradient(const Function< dim > &function, const Point< dim, VectorizedArray< Number > > &p_vectorized)
Evaluate the gradient of a function at a batch of points to obtain a tensor of vectorized arrays.
bool boundary_condition_requires_face_assembly(BoundaryConditions::FluidDynamicsBoundaryType boundary_type)
Check if a boundary condition type requires face assembly in the matrix-free operator.
VectorizedArray< Number > evaluate_function(const Function< dim > &function, const Point< dim, VectorizedArray< Number > > &p_vectorized, const unsigned int component=0)
Evaluate the value of a function at a batch of points to obtain a vectorized array of numbers.
Simulation control classes for managing time-stepping and iteration control in Lethe.
Data structure to store time-stepping data in the matrix-free operator. This is a very small structur...
bool is_transient
Boolean indicating if the method is transient.
bool is_bdf
Boolean indicating that the method is a BDF method.
const Vector< double > * bdf_coefficients