Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
navier_stokes_base.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2019-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_navier_stokes_base_h
5#define lethe_navier_stokes_base_h
6
9#include <core/multiphysics.h>
10#include <core/output_struct.h>
11#include <core/parameters.h>
12#include <core/physics_solver.h>
13#include <core/pvd_handler.h>
17
26
27// Dealii Includes
28#include <deal.II/base/conditional_ostream.h>
29#include <deal.II/base/convergence_table.h>
30#include <deal.II/base/exceptions.h>
31#include <deal.II/base/function.h>
32#include <deal.II/base/quadrature_lib.h>
33#include <deal.II/base/table_handler.h>
34#include <deal.II/base/timer.h>
35
36#include <deal.II/dofs/dof_handler.h>
37
38#include <deal.II/fe/component_mask.h>
39#include <deal.II/fe/fe_system.h>
40#include <deal.II/fe/mapping_fe.h>
41#include <deal.II/fe/mapping_q_cache.h>
42
43#include <deal.II/grid/grid_out.h>
44#include <deal.II/grid/grid_tools.h>
45
46#include <deal.II/lac/affine_constraints.h>
47
48using namespace dealii;
49
50
51
53 FluidDynamicsBoundaryConditionMissing,
54 types::boundary_id,
55 << "The boundary id: " << arg1
56 << " is defined in the triangulation, but not as a boundary condition for the fluid dynamics physics. Lethe does not assign a default boundary condition to boundary ids. Every boundary id defined within the triangulation must have a corresponding boundary condition defined in the input file.");
57
58/**
59 * @brief Struct containing fluid id, temperature and phase indicator range
60 * information, and flag containers for DOFs used in temperature-dependent
61 * stasis constraints.
62 */
64{
65 /**
66 * @brief Default constructor of the struct.
67 *
68 * @param[in] fluid_id Identifier of the fluid that is constrained.
69 *
70 * @param[in] min_solid_temperature Lower threshold value of the constraining
71 * field (temperature).
72 *
73 * @param[in] max_solid_temperature Upper threshold values of the constraining
74 * field (temperature).
75 *
76 * @param[in] filtered_phase_indicator_tolerance Tolerance applied on filtered
77 * phase indicator.
78 */
89 /// Identifier of the fluid that is constrained.
90 const unsigned int fluid_id;
91 /// Lower threshold values of the constraining field (temperature)
93 /// Upper threshold values of the constraining field (temperature)
95 /// Tolerance applied on filtered phase indicator
97 /// Container of global DOF indices located in solid cells
98 std::unordered_set<types::global_dof_index> dofs_are_in_solid;
99 /// Container of global DOF indices connected to at least one fluid cell
100 std::unordered_set<types::global_dof_index> dofs_are_connected_to_fluid;
101};
102
103/**
104 * A base class for all the Navier-Stokes equation
105 * This class regroups common facilities that are shared by all
106 * the Navier-Stokes implementations to reduce code multiplicity
107 *
108 * @tparam dim An integer that denotes the dimension of the space in which
109 * the flow is solved
110 *
111 * @tparam VectorType The Vector type used for the solvers
112 *
113 * @tparam DofsType the type of dof storage indices
114 *
115 * @ingroup solvers
116 * @author Bruno Blais, 2019
117 */
118
119template <int dim, typename VectorType, typename DofsType>
120class NavierStokesBase : public PhysicsSolver<VectorType>
121{
122protected:
123 /**
124 * @brief Construct the Navier-Stokes base and the multiphysics interface.
125 * @param[in] nsparam Relevant parameters for the solver.
126 * @param[in] fluid_dynamics_formulation The formulation of the fluid dynamics
127 * equations. Whether the solver solves the volume-averaged Navier-Stokes
128 * (VANS) equations or the standard Navier-Stokes equations.
129 */
131 const FluidDynamicsFormulation fluid_dynamics_formulation =
133
134 virtual ~NavierStokesBase() = default;
135
136 /**
137 * @brief Getter methods to get the private attributes for the physic currently solved
138 *
139 * @param current_physics_id Indicates the number associated with the physic currently solved.
140 * If the solver is only solving for a fluid dynamics problem, then the value
141 * will always be PhysicsID::fluid_dynamics.
142 *
143 */
144 virtual VectorType &
146 {
147 return evaluation_point;
148 };
149 virtual VectorType &
151 {
153 };
154 virtual VectorType &
156 {
157 return newton_update;
158 };
159 virtual VectorType &
161 {
162 return *present_solution;
163 };
164 virtual VectorType &
165 get_system_rhs() override
166 {
167 return system_rhs;
168 };
169 virtual AffineConstraints<double> &
171 {
172 return nonzero_constraints;
173 };
174
175 /**
176 * @brief Output the L2 and Linfty norms of the correction vector.
177 */
178 virtual void
180
181 /**
182 * @brief Return the metric for residual rescaling. By default, should return 1.
183 * If the rescale_residual_by_volume is set to true, the method
184 * returns the global volume of the triangulation.
185 *
186 * @return Rescale metric.
187 */
188 double
190 {
191 return simulation_parameters.linear_solver.at(PhysicsID::fluid_dynamics)
192 .rescale_residual_by_volume ?
193 std::sqrt(
194 GridTools::volume(*this->triangulation, *this->mapping)) :
195 1.;
196 }
197
198 /**
199 * Generic interface routine to allow the CFD solver
200 * to cooperate with the multiphysics modules
201 **/
202
203 /**
204 * @brief Finish the simulation by calling all the post-processing elements that are required
205 */
206 void
208 {
210 multiphysics->finish_simulation();
211 }
212
213 /**
214 * @brief Post-process simulation after an iteration
215 *
216 * @param first_iteration Indicator if the simulation is at its first simulation or not.
217 */
218 virtual void
219 postprocess(bool first_iteration)
220 {
221 if (simulation_control->get_iteration_number() %
222 this->simulation_parameters.post_processing.calculation_frequency ==
223 0 ||
224 first_iteration || simulation_control->is_at_end())
225 {
226 postprocess_fd(first_iteration);
227 multiphysics->postprocess(first_iteration);
228 }
229
230 if (this->simulation_control->is_output_iteration())
232 };
233
234 /**
235 * @brief Initialize the degree of freedom and the memory associated with them for fluid dynamics and enabled auxiliary physics.
236 */
237 virtual void
244
245 /**
246 * @brief Set the initial condition
247 *
248 * @param initial_condition_type Type of method use to impose initial condition.
249 *
250 * @param restart Indicator if the simulation is being restarted or not.
251 *
252 **/
253
254 virtual void
256 const Parameters::FluidDynamicsInitialConditionType initial_condition_type,
257 const bool restart = false)
258 {
259 unsigned int ref_iter = 0;
260 do
261 {
262 if (ref_iter > 0)
263 this->refine_mesh();
264
265 set_initial_condition_fd(initial_condition_type, restart);
266 if (!restart)
267 {
268 multiphysics->set_initial_conditions();
269 }
270 ref_iter++;
271 }
272 while (
273 ref_iter <
274 (this->simulation_parameters.mesh_adaptation.initial_refinement + 1) &&
275 restart == false);
276
277 if (!restart)
278 {
279 this->postprocess_fd(true);
280 multiphysics->postprocess(true);
281 if (this->simulation_control->is_output_iteration())
283 }
284 }
285
286 /**
287 * Key physics component for fluid dynamics
288 **/
289
290 /**
291 * @brief Finishes the time step of the fluid dynamics. Post-processing and time stepping
292 */
293 virtual void
295
296 /**
297 * @brief finish_time_step
298 * Finishes the time step of the fluid dynamics
299 * Post-processing and time stepping
300 */
301 virtual void
303
304 /**
305 * @brief Finishes the simulation for fluid dynamics by calling the post-processing elements that are required
306 */
307 void
309
310 /**
311 * @brief Post-process fluid dynamics after an iteration
312 */
313 virtual void
314 postprocess_fd(bool first_iteration);
315
316 /**
317 * @brief Initialize the dofs for fluid dynamics
318 */
319 virtual void
321
322 /**
323 * @brief Update mortar configuration.
324 *
325 * When the rotor domain is rotated, the mortar cells need to be reinitialized
326 * according to the new rotor-stator interface configuration.
327 */
328 virtual void
331
332 /**
333 * @brief Update the time average velocity field solution
334 */
335 virtual void
337
338 /**
339 * @brief Required only for the matrix-free solver to update solutions within iterate function.
340 */
341 virtual void
344
345 /**
346 * @brief Required only for the matrix-free solver to update multiphysics solutions within iterate function.
347 */
348 virtual void
351
352 virtual void
355 bool restart = false) = 0;
356
357 /**
358 * End of key physics components for fluid dynamics
359 **/
360
361 /**
362 * @brief Post-processing function
363 * Outputs the forces acting on each boundary condition
364 */
365 void
367
368 /**
369 * @brief Post-processing function
370 * Outputs the torque acting on each boundary condition
371 */
372 void
374
375 /**
376 * @brief If set to enable, dynamic_flow_control allows to control the flow by executing space-average velocity and beta coefficient force calculation at each time step.
377 */
378 virtual void
380
381 /**
382 * @brief Update the sum_over_previous_stages variable to use it in the solver.
383 *
384 * @param stage An unsigned integer which gives the index of the current stage
385 * @param method SDIRK method for now (BDF methods are single stage)
386 */
387 virtual void
389 unsigned int stage,
391
392 /**
393 * @brief Calculate \f$ k_i \f$ from \f$ u*_i : k_i = \frac{u*_i - u_n}{time_step*a_ii} - \sum{j=1}^{i-1} a_ij * k_j \f$
394 * Update \f$ \sum_{i=1}^{N_{stages}} b_i * k_i \f$
395 *
396 * @param stage An unsigned integer which gives the index of the current stage
397 * @param method SDIRK method for now (BDF methods are single stage)
398 * @param time_step The current time step to build the solution at the next time step
399 */
400 virtual void
402 unsigned int stage,
404 double time_step);
405
406 /**
407 * @brief \f$ u_{n+1} = u_n + time_step * \sum_{i=1}^{N_{stages}} b_i * k_i \f$
408 *
409 * @param time_step The current time step to build the solution at the next time step
410 */
411 virtual void
412 update_multi_stage_solution(double time_step);
413
414 /**
415 * @brief Specify the fluid dynamics solution instead of solving for it.
416 *
417 * When the fluid dynamics is disabled (fluid dynamics = false in the
418 * multiphysics subsection), the velocity and the pressure fields are not
419 * solved for, but rather imposed. They are either taken from the average
420 * velocity profile or re-established from the initial condition, which may
421 * be time-dependent.
422 */
423 virtual void
425
426 /**
427 * @brief Do a regular CFD iteration
428 */
429 virtual void
430 iterate();
431
432 /**
433 * @brief Enable the use of dynamic zero constraints by initializing required
434 * FEValues objects.
435 *
436 * @note At the moment, the only solution-dependent dynamic constraint depends
437 * on the temperature field obtained from the Heat Transfer (HT) auxiliary
438 * physic.
439 */
440 virtual void
442
443 /**
444 * @brief Allow the initial refinement of all cells of the principal mesh that are partially
445 * contained in one of the cells of the box refinement mesh given in the
446 * parameter.
447 *
448 * @param restart Indicator if the simulation is being restarted or not.
449 */
450 void
451 box_refine_mesh(const bool restart);
452
453 /**
454 * @brief Allow the refinement of the mesh according to one of the 2 methods proposed
455 */
456 virtual void
457 refine_mesh();
458
459 /**
460 * @brief Allow the refinement of the mesh based on an error estimator.
461 */
462 void
464
465 /**
466 * @brief Allow the uniform refinement of all the mesh.
467 */
468 void
470
471 /**
472 * @brief Transfer solution after mesh refinement
473 */
474 void
475 transfer_solution(SolutionTransfer<dim, VectorType> &solution_transfer,
476 std::vector<SolutionTransfer<dim, VectorType>>
477 &previous_solutions_transfer);
478
479 /**
480 * @brief Restart a previous simulation from a checkpoint file.
481 */
482 virtual void
484
485 /**
486 * @brief Indicate whether the time-averaged velocity object holds vectors that
487 * must be preserved. The averaging is used either when it is explicitly
488 * requested through the post-processing parameters or when the initial
489 * condition is an average velocity profile, which is read back from a
490 * checkpoint. This condition must be identical everywhere the average
491 * velocity vectors are serialized, deserialized or transferred to a new
492 * mesh partition, otherwise the accumulated sums are silently lost.
493 *
494 * @return Whether the average velocity vectors must be preserved.
495 */
496 bool
498 {
499 return this->simulation_parameters.post_processing
500 .calculate_average_velocities ||
501 this->simulation_parameters.initial_condition->type ==
502 Parameters::FluidDynamicsInitialConditionType::
503 average_velocity_profile;
504 }
505
506 /**
507 * @brief Restore the state of the time-averaged velocity object after its
508 * vectors have been deserialized.
509 *
510 * The deserialization fills the vectors with locally_relevant (owned +
511 * ghost), since only those are serialized, whereas the averaging routines
512 * accumulate into the locally owned vectors. The locally owned vectors must
513 * therefore be reset from their locally_relevant version after a checkpoint,
514 * otherwise the averaging silently
515 * restarts from zero. The checkpointed average is also discarded here if the
516 * initial time for averaging has not been reached yet, which lets a
517 * simulation be restarted with a later averaging start time.
518 *
519 * This function must be called at the end of every read_checkpoint()
520 * implementation that deserializes the average velocity vectors.
521 */
522 void
524
525 /**
526 * @brief Read the solution from a checkpoint file and set it as the current solution.
527 */
528 virtual void
529 set_solution_from_checkpoint(const std::string &checkpoint_file_prefix);
530
531 /**
532 * @brief Set the nodal values of velocity and pressure
533 */
534 void
536
537 /**
538 * @brief Define the non-zero constraints used to solve the problem.
539 */
540 void
542
543 /**
544 * @brief Define the zero constraints used to solve the problem.
545 */
546 void
548
549 /**
550 * @brief Initialize mortar coupling manager, operator, and evaluator
551 */
552 void
554
555 /**
556 * @brief Returns the mapping shared pointer. A MappingQCache is
557 * necessary for prescribed rotation in rotor-stator configurations
558 */
559 inline std::shared_ptr<Mapping<dim>>
561 {
562 if (!this->simulation_parameters.mortar_parameters.enable)
563 return this->mapping;
564 else
565 return this->mapping_cache;
566 }
567
568 /**
569 * @brief Rotate rotor mapping in mortar method
570 *
571 * @param[in] is_first Whether this is the first mapping rotation. This
572 * boolean is used only for printing output purposes; since the mapping needs
573 * to be rotated before setting up dofs, but also after the constraints are
574 * first defined, this function is called twice before the iterate() loop. The
575 * parameter is_first just prevents the mortar verbosity from being printed
576 * twice
577 */
578 void
579 rotate_rotor_mapping(const bool is_first);
580
581 /**
582 * @brief Connect weight signals for load balancing of mortar cells.
583 * Cells touching mortar boundaries can be assigned assigned higher weight for
584 * better load distribution across processors.
585 */
586 void
588
589 /**
590 * @brief Update non-zero constraints if the boundary is time dependent.
591 * Note: not implemented for the block fluid dynamics application.
592 */
593 void
595
596 /**
597 * @brief Set the time of the forcing function and of the time-dependent
598 * boundary conditions to the current time of the simulation control, and
599 * re-impose the non-zero constraints on the present solution.
600 *
601 * This is called at the beginning of every time step and, for multi-stage
602 * (SDIRK) methods, at every stage so that the forcing and the boundary
603 * conditions are evaluated at the stage time \f$t_n + c_i \Delta t\f$.
604 */
605 virtual void
607
608 /**
609 * @brief Check if a specifique boundary condition exist
610 * @param bc, the boundary type that we want to check if it exists
611 */
612 bool
614
615 /**
616 * @brief Turn regions of the mesh where the @p material_id>0 into a solid
617 * block by injecting velocity and pressure DOFs into the zero constraints.
618 *
619 * It is achieved by imposing \f$\mathbf{u}=0\f$ within the cells which have a
620 * @p material_id>0. In addition, solid cells which are not connected to the
621 * fluid by any means also get a pressure Dirichlet boundary condition which
622 * fixes the pressure to 0. It ensures that the linear system is well-posed.
623 * Right now, this routine only supports the usage of 1 solid domain, but
624 * eventually it could be extended to more than one. By default, the fluid
625 * domain is assumed to have a @p material_id=0 and the rest of the domains
626 * have a @p material_id>0.
627 *
628 * @param[in] dof_handler DoFHandler for which the solid region is
629 * established. In the majority of cases this is the DoFHandler that is a
630 * member of this class, but if a multigrid preconditioner, constraints must
631 * be built at every level. In this case, this DoFHandler can be the
632 * DoFHandler at any of the multigrid level.
633 *
634 * @param[in] non_zero_constraints If this parameter is true, it indicates
635 * that non-zero constraints are being constrained for the solid domain. If
636 * this is set to false, homogeneous constraints are constrained in the solid
637 * domain.
638 *
639 * @param[in] constraints Set of constraints on which the solid domain
640 * constraint is applied. These constraints can be either zero or non-zero
641 * constraints, which is decided by the non_zero_constraints flag.
642 */
643 void
644 make_solid_domain(const DoFHandler<dim> &dof_handler,
645 const bool non_zero_constraints,
646 AffineConstraints<double> &constraints);
647
648 /**
649 * @brief Checks and identifies if the cell is located in the constraining
650 * domain defined by a plane with its outward-pointing normal vector. The
651 * check is done through a scalar product between a vector formed by a vertex
652 * of the cell to @plane_point and @plane_normal_vector. If one of the
653 * vertices of the cell results in a negative scalar product result, the cell
654 * is excluded from the constrained domain.
655 *
656 * @param[in] cell Pointer to an active cell of the fluid dynamics DoFHandler.
657 *
658 * @param[in] plane_point Coordinates of a point on the restriction plane for
659 * the stasis constraint application domain.
660 *
661 * @param[in] plane_normal_vector Outward-pointing normal vector to define the
662 * restriction plane for the stasis constraint application domain.
663 *
664 * @return Boolean indicating if the cell is in the domain of interest
665 * (@p true) or not (@p false).
666 */
667 inline bool
669 const typename DoFHandler<dim>::active_cell_iterator &cell,
670 const Point<dim> &plane_point,
671 const Tensor<1, dim> &plane_normal_vector)
672 {
673 for (unsigned int v = 0; v < cell->n_vertices(); ++v)
674 {
675 Point<dim> cell_vertex = cell->vertex(v);
676 Tensor<1, dim> cell_vertex_to_plane_point_vector =
677 plane_point - cell_vertex;
678 double scalar_product_result =
679 scalar_product(cell_vertex_to_plane_point_vector,
680 plane_normal_vector);
681 if (scalar_product_result <= 0)
682 return false;
683 }
684 return true;
685 }
686
687 /**
688 * @brief Get cell's local temperature values at quadrature points.
689 *
690 * @param[in] cell Pointer to an active cell of the fluid dynamics DoFHandler.
691 *
692 * @param[in] dof_handler_ht DoFHandler of the Heat Transfer (HT) auxiliary
693 * physic.
694 *
695 * @param[in] temperature_solution Temperature solution vector from the HT
696 * auxiliary physic.
697 *
698 * @param[out] local_temperature_values Cell's local temperature values at
699 * quadrature points.
700 */
701 inline void
703 const typename DoFHandler<dim>::active_cell_iterator &cell,
704 const DoFHandler<dim> *dof_handler_ht,
705 const GlobalVectorType &temperature_solution,
706 std::vector<double> &local_temperature_values)
707 {
708 const typename DoFHandler<dim>::active_cell_iterator temperature_cell(
709 &(*(this->triangulation)), cell->level(), cell->index(), dof_handler_ht);
710
711 this->fe_values_temperature->reinit(temperature_cell);
712 this->fe_values_temperature->get_function_values(temperature_solution,
713 local_temperature_values);
714 }
715
716 /**
717 * @brief Get cell's local filtered phase indicator values at quadrature
718 * points.
719 *
720 * @param[in] cell Pointer to an active cell of the fluid dynamics DoFHandler.
721 *
722 * @param[in] dof_handler_cls DoFHandler of the Conservative Level Set (CLS)
723 * auxiliary physic.
724 *
725 * @param[in] filtered_phase_indicator_solution Filtered phase indicator
726 * solution vector from the CLS auxiliary physic.
727 *
728 * @param[out] local_filtered_phase_indicator_values Cell's local filtered
729 * phase indicator values at quadrature points.
730 */
731 inline void
733 const typename DoFHandler<dim>::active_cell_iterator &cell,
734 const DoFHandler<dim> *dof_handler_cls,
735 const GlobalVectorType &filtered_phase_indicator_solution,
736 std::vector<double> &local_filtered_phase_indicator_values)
737 {
738 const typename DoFHandler<dim>::active_cell_iterator cls_cell(
739 &(*(this->triangulation)), cell->level(), cell->index(), dof_handler_cls);
740
741 this->fe_values_cls->reinit(cls_cell);
742 this->fe_values_cls->get_function_values(
743 filtered_phase_indicator_solution, local_filtered_phase_indicator_values);
744 }
745
746 /**
747 * @brief Identify if temperature DOFs of the cell are within the
748 * constraining range. If they are, velocity DOFs of the cell are constrained.
749 *
750 * @param[in] local_dof_indices Vector of a cell's local DOF indices.
751 *
752 * @param[in] local_temperature_values Cell's local temperature values at
753 * quadrature points.
754 *
755 * @param[in,out] stasis_constraint_struct Struct containing flagged DOF
756 * containers, temperature range information and fluid id.
757 */
758 void
760 const std::vector<types::global_dof_index> &local_dof_indices,
761 const std::vector<double> &local_temperature_values,
762 StasisConstraintWithTemperature &stasis_constraint_struct);
763
764 /**
765 * @brief Constrain a fluid's subdomains according to the temperature field to null
766 * velocity and pressure fields to model solid subdomains.
767 *
768 * @note Its equivalent for Conservative Level Set (CLS) simulations is
769 * NavierStokesBase<dim, VectorType, DofsType>::constrain_solid_domain_cls.
770 *
771 * @param[in] dof_handler_ht DoFHandler of the Heat Transfer (HT) auxiliary
772 * physic.
773 */
774 void
775 constrain_stasis_with_temperature(const DoFHandler<dim> *dof_handler_ht);
776
777 /**
778 * @brief Constrain fluids' subdomains according to the temperature field to
779 * null velocity and pressure fields to model solid subdomains in Volume of
780 * Fluid (CLS) simulations.
781 *
782 * @param[in] dof_handler_cls DoFHandler of the CLS auxiliary physic.
783 *
784 * @param[in] dof_handler_ht DoFHandler of the Heat Transfer (HT) auxiliary
785 * physic.
786 */
787 void
788 constrain_stasis_with_temperature_cls(const DoFHandler<dim> *dof_handler_cls,
789 const DoFHandler<dim> *dof_handler_ht);
790
791 /**
792 * @brief Returns a vector of references to TableHandler objects that needs to be serialized/
793 * deserialized for a given solver.
794 *
795 * @return Structure containing a vector of references to TableHandler objects that needs to be
796 * serialized/deserialized for a given solver, and their corresponding file
797 * names.
798 */
799 virtual std::vector<OutputStructTableHandler>
801
802 /**
803 * @brief Write the checkpoint
804 */
805 virtual void
807
808 /**
809 * @brief Gather and return vector of output structs that are particular to some applications.
810 *
811 * @return Vector of OutputStructs that will be used to write the output results as VTU files.
812 */
813 virtual std::vector<OutputStruct<dim, VectorType>>
815
816 /**
817 * @brief Gather solution information to generate output results
818 *
819 * @param[in] solution Vector of the present solution
820 * @param[in,out] solution_output_structs Vector of OutputStructs that will be
821 * used to write the output results as VTU files
822 */
823 void
825 const VectorType &solution,
826 std::vector<OutputStruct<dim, VectorType>> &solution_output_structs);
827
828 /**
829 * @brief Generate post-processing parallel VTU files from vector of
830 * solution_output_struct
831 *
832 * @param[in] solution Vector of present solution
833 */
834 void
835 write_output_results(const VectorType &solution);
836
837 /**
838 * @brief Writes the forces per boundary condition to a text file output
839 */
840 void
842
843 /**
844 * @brief Writes the torques per boundary condition to a text file output
845 */
846 void
848
849 /**
850 * @brief This function is used to rescale pressure DOFs in the newton correction
851 */
852 void
854
855 /**
856 * @brief This function initializes correctly a temporary vector depending on the
857 * vector type
858 */
859 inline VectorType
861
862 // Member variables
863protected:
864 /**
865 * @brief Verify consistency of the input parameters for boundary
866 * conditions to ensure that for every boundary condition within the
867 * triangulation, a boundary condition has been specified in the input file.
868 */
869 void
871 {
872 // Sanity check all the boundary conditions of the triangulation to ensure
873 // that they have a type.
874 std::vector<types::boundary_id> boundary_ids_in_triangulation =
875 this->triangulation->get_boundary_ids();
876 for (auto const &boundary_id_in_tria : boundary_ids_in_triangulation)
877 {
878 AssertThrow(simulation_parameters.boundary_conditions.type.find(
879 boundary_id_in_tria) !=
880 simulation_parameters.boundary_conditions.type.end(),
881 FluidDynamicsBoundaryConditionMissing(boundary_id_in_tria));
882 }
883 }
884
885
888
890 const unsigned int n_mpi_processes;
891 const unsigned int this_mpi_process;
892
893 std::shared_ptr<parallel::DistributedTriangulationBase<dim>> triangulation;
894 std::shared_ptr<DoFHandler<dim>> dof_handler;
895 std::shared_ptr<FESystem<dim>> fe;
896
897 TimerOutput computing_timer;
898
902
903 // Functions used for source term and error analysis
904 Function<dim> *exact_solution;
905 std::shared_ptr<Function<dim>> forcing_function;
906
907 // Dynamic flow control
909
910 // Constraints for Dirichlet boundary conditions
911 AffineConstraints<double> zero_constraints;
912 AffineConstraints<double> nonzero_constraints;
913
914 // Define whether manifolds are used for the normal vectors computation in
915 // slip BCs
917
918 // Present solution and non-linear solution components
922 std::shared_ptr<VectorType> present_solution;
924
925 // Previous solutions vectors
926 std::shared_ptr<std::vector<VectorType>> previous_solutions;
927
928 /**
929 * @brief Structure that stores all SDIRK-related vectors used during the time integration process.
930 */
932 {
933 /// Vector to hold the locally non-relevant part of the solution (for
934 /// calculation purposes)
936
937 /// Stores the previous k_j stage vectors (one per stage j < i)
938 std::vector<VectorType> previous_k_j_solutions;
939
940 /// Stores the sum of b_i * k_i across all stages
943
944 /// Stores the sum of a_ij * k_j for j < i
947 };
948
949 /**
950 * @brief Instance of SDIRK-related vectors.
951 */
953
954 // Finite element degree used
955 const unsigned int velocity_fem_degree;
956 const unsigned int pressure_fem_degree;
958
959 // Mappings and Quadratures
960 std::shared_ptr<Mapping<dim>> mapping;
961 std::shared_ptr<Quadrature<dim>> cell_quadrature;
962 std::shared_ptr<Quadrature<dim - 1>> face_quadrature;
963
964 // Mortar coupling manager and operator
965 std::shared_ptr<MortarManagerBase<dim>> mortar_manager;
966 std::shared_ptr<CouplingOperator<dim, double>> mortar_coupling_operator;
967 std::shared_ptr<NavierStokesCouplingEvaluationSIPG<dim, double>>
969
970 // Mapping cache used in rotor mesh rotation in mortar method
971 std::shared_ptr<MappingQCache<dim>> mapping_cache;
972
973 // Assemblers for the matrix and rhs
974 std::vector<std::shared_ptr<NavierStokesAssemblerBase<dim>>> assemblers;
975
976 // Multiphysics interface
977 std::shared_ptr<MultiphysicsInterface<dim>> multiphysics;
978
979 // Simulation control for time stepping and I/Os
980 std::shared_ptr<SimulationControl> simulation_control;
981
982 // Post-processing variables
983 TableHandler enstrophy_table;
989 TableHandler flow_rate_table;
990 std::shared_ptr<AverageVelocities<dim, VectorType, DofsType>>
993
994 // Refinement control
996
997 // Convergence Analysis
998 ConvergenceTable error_table;
999
1000 // Force analysis
1001 std::vector<std::map<types::boundary_id, Tensor<1, dim>>>
1003 std::map<types::boundary_id, TableHandler> forces_tables;
1004 std::map<types::boundary_id, TableHandler> torques_tables;
1005
1006 /// FEValues object used for temperature-dependent solid domain constraints
1007 std::shared_ptr<FEValues<dim>> fe_values_temperature;
1008 /// FEValues object used for temperature-dependent solid domain constraints in
1009 /// CLS simulations
1010 std::shared_ptr<FEValues<dim>> fe_values_cls;
1011 /// Vector containing solid domain constraint structs for
1012 /// temperature-dependent solid domain constraints in CLS simulations
1013 std::vector<StasisConstraintWithTemperature> stasis_constraint_structs;
1014 /// Dynamic homogeneous constraints used for temperature-dependent solid
1015 /// domain constraints
1016 AffineConstraints<double> dynamic_zero_constraints;
1017};
1018
1019#endif
Dynamic flow controller that drives the average velocity of the flow towards a target value.
std::vector< StasisConstraintWithTemperature > stasis_constraint_structs
virtual void output_newton_update_norms() override
Output the L2 and Linfty norms of the correction vector.
void constrain_stasis_with_temperature(const DoFHandler< dim > *dof_handler_ht)
Constrain a fluid's subdomains according to the temperature field to null velocity and pressure field...
void box_refine_mesh(const bool restart)
Allow the initial refinement of all cells of the principal mesh that are partially contained in one o...
ConvergenceTable error_table
std::map< types::boundary_id, TableHandler > torques_tables
std::map< types::boundary_id, TableHandler > forces_tables
virtual void update_solutions_for_fluid_dynamics()
Required only for the matrix-free solver to update multiphysics solutions within iterate function.
PVDHandler pvdhandler_boundary
virtual void set_specified_fluid_dynamics_solution()
Specify the fluid dynamics solution instead of solving for it.
std::shared_ptr< MortarManagerBase< dim > > mortar_manager
std::shared_ptr< FESystem< dim > > fe
void connect_mortar_weight_signals()
Connect weight signals for load balancing of mortar cells. Cells touching mortar boundaries can be as...
Function< dim > * exact_solution
void verify_consistency_of_boundary_conditions()
Verify consistency of the input parameters for boundary conditions to ensure that for every boundary ...
void get_cell_temperature_values(const typename DoFHandler< dim >::active_cell_iterator &cell, const DoFHandler< dim > *dof_handler_ht, const GlobalVectorType &temperature_solution, std::vector< double > &local_temperature_values)
Get cell's local temperature values at quadrature points.
std::shared_ptr< Quadrature< dim > > cell_quadrature
double get_residual_rescale_metric() const override
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
AffineConstraints< double > nonzero_constraints
void write_output_results(const VectorType &solution)
Generate post-processing parallel VTU files from vector of solution_output_struct.
virtual void set_initial_condition(const Parameters::FluidDynamicsInitialConditionType initial_condition_type, const bool restart=false)
Set the initial condition.
const unsigned int pressure_fem_degree
void refine_mesh_adaptive()
Allow the refinement of the mesh based on an error estimator.
virtual void update_multi_stage_solution(double time_step)
std::vector< std::map< types::boundary_id, Tensor< 1, dim > > > forces_on_boundaries
virtual std::vector< OutputStructTableHandler > gather_tables()
Returns a vector of references to TableHandler objects that needs to be serialized/ deserialized for ...
void define_zero_constraints()
Define the zero constraints used to solve the problem.
SDIRKVectors sdirk_vectors
Instance of SDIRK-related vectors.
const unsigned int n_mpi_processes
virtual void setup_dofs_fd()=0
Initialize the dofs for fluid dynamics.
unsigned int number_quadrature_points
virtual VectorType & get_local_evaluation_point() override
virtual void update_solutions_for_multiphysics()
Required only for the matrix-free solver to update solutions within iterate function.
void constrain_stasis_with_temperature_cls(const DoFHandler< dim > *dof_handler_cls, const DoFHandler< dim > *dof_handler_ht)
Constrain fluids' subdomains according to the temperature field to null velocity and pressure fields ...
void rescale_pressure_dofs_in_newton_update()
This function is used to rescale pressure DOFs in the newton correction.
std::shared_ptr< VectorType > present_solution
void write_output_torques()
Writes the torques per boundary condition to a text file output.
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
void write_output_forces()
Writes the forces per boundary condition to a text file output.
void transfer_solution(SolutionTransfer< dim, VectorType > &solution_transfer, std::vector< SolutionTransfer< dim, VectorType > > &previous_solutions_transfer)
Transfer solution after mesh refinement.
virtual AffineConstraints< double > & get_nonzero_constraints() override
void make_solid_domain(const DoFHandler< dim > &dof_handler, const bool non_zero_constraints, AffineConstraints< double > &constraints)
Turn regions of the mesh where the material_id>0 into a solid block by injecting velocity and pressur...
virtual void refine_mesh()
Allow the refinement of the mesh according to one of the 2 methods proposed.
virtual void read_checkpoint()
Restart a previous simulation from a checkpoint file.
void define_non_zero_constraints()
Define the non-zero constraints used to solve the problem.
virtual VectorType & get_evaluation_point() override
Getter methods to get the private attributes for the physic currently solved.
virtual void enable_dynamic_zero_constraints_fd()
Enable the use of dynamic zero constraints by initializing required FEValues objects.
void postprocessing_torques(const VectorType &evaluation_point)
Post-processing function Outputs the torque acting on each boundary condition.
std::shared_ptr< Mapping< dim > > get_mapping()
Returns the mapping shared pointer. A MappingQCache is necessary for prescribed rotation in rotor-sta...
virtual void finish_time_step()
Finishes the time step of the fluid dynamics. Post-processing and time stepping.
TableHandler apparent_viscosity_table
void rotate_rotor_mapping(const bool is_first)
Rotate rotor mapping in mortar method.
std::shared_ptr< FEValues< dim > > fe_values_temperature
FEValues object used for temperature-dependent solid domain constraints.
void gather_output_results(const VectorType &solution, std::vector< OutputStruct< dim, VectorType > > &solution_output_structs)
Gather solution information to generate output results.
AffineConstraints< double > dynamic_zero_constraints
virtual void dynamic_flow_control()
If set to enable, dynamic_flow_control allows to control the flow by executing space-average velocity...
std::shared_ptr< NavierStokesCouplingEvaluationSIPG< dim, double > > mortar_coupling_evaluator
virtual VectorType & get_present_solution() override
virtual void update_multiphysics_time_average_solution()=0
Update the time average velocity field solution.
const unsigned int this_mpi_process
SimulationParameters< dim > simulation_parameters
TableHandler kinetic_energy_table
virtual VectorType & get_system_rhs() override
bool check_existance_of_bc(BoundaryConditions::FluidDynamicsBoundaryType bc)
Check if a specifique boundary condition exist.
bool average_velocities_are_enabled() const
Indicate whether the time-averaged velocity object holds vectors that must be preserved....
virtual void set_initial_condition_fd(Parameters::FluidDynamicsInitialConditionType initial_condition_type, bool restart=false)=0
virtual void multi_stage_postresolution(unsigned int stage, Parameters::SimulationControl::TimeSteppingMethod method, double time_step)
Calculate from Update .
virtual void iterate()
Do a regular CFD iteration.
void finish_simulation_fd()
Finishes the simulation for fluid dynamics by calling the post-processing elements that are required.
void restore_average_velocities_after_checkpoint()
Restore the state of the time-averaged velocity object after its vectors have been deserialized.
virtual VectorType & get_newton_update() override
std::shared_ptr< CouplingOperator< dim, double > > mortar_coupling_operator
TableHandler flow_rate_table
virtual void postprocess_fd(bool first_iteration)
Post-process fluid dynamics after an iteration.
TimerOutput computing_timer
std::shared_ptr< std::vector< VectorType > > previous_solutions
TableHandler pressure_power_table
std::shared_ptr< MappingQCache< dim > > mapping_cache
std::shared_ptr< Function< dim > > forcing_function
VectorType init_temporary_vector()
This function initializes correctly a temporary vector depending on the vector type.
std::shared_ptr< SimulationControl > simulation_control
void update_boundary_conditions()
Update non-zero constraints if the boundary is time dependent. Note: not implemented for the block fl...
VectorType local_evaluation_point
virtual std::vector< OutputStruct< dim, VectorType > > gather_output_hook()
Gather and return vector of output structs that are particular to some applications.
void finish_simulation()
Finish the simulation by calling all the post-processing elements that are required.
virtual void multi_stage_preresolution(unsigned int stage, Parameters::SimulationControl::TimeSteppingMethod method)
Update the sum_over_previous_stages variable to use it in the solver.
FlowControl< dim > flow_control
void refine_mesh_uniform()
Allow the uniform refinement of all the mesh.
TableHandler pressure_drop_table
std::vector< std::shared_ptr< NavierStokesAssemblerBase< dim > > > assemblers
std::shared_ptr< MultiphysicsInterface< dim > > multiphysics
virtual void set_solution_from_checkpoint(const std::string &checkpoint_file_prefix)
Read the solution from a checkpoint file and set it as the current solution.
std::shared_ptr< FEValues< dim > > fe_values_cls
NavierStokesBase(SimulationParameters< dim > &nsparam, const FluidDynamicsFormulation fluid_dynamics_formulation=FluidDynamicsFormulation::standard)
Construct the Navier-Stokes base and the multiphysics interface.
bool cell_in_constraining_domain(const typename DoFHandler< dim >::active_cell_iterator &cell, const Point< dim > &plane_point, const Tensor< 1, dim > &plane_normal_vector)
Checks and identifies if the cell is located in the constraining domain defined by a plane with its o...
AffineConstraints< double > zero_constraints
MeshController mesh_controller
virtual void percolate_time_vectors_fd()
finish_time_step Finishes the time step of the fluid dynamics Post-processing and time stepping
virtual void update_forcing_and_boundary_conditions()
Set the time of the forcing function and of the time-dependent boundary conditions to the current tim...
std::shared_ptr< AverageVelocities< dim, VectorType, DofsType > > average_velocities
virtual void setup_dofs()
Initialize the degree of freedom and the memory associated with them for fluid dynamics and enabled a...
TableHandler enstrophy_table
std::shared_ptr< Mapping< dim > > mapping
void identify_cell_and_constrain_velocity(const std::vector< types::global_dof_index > &local_dof_indices, const std::vector< double > &local_temperature_values, StasisConstraintWithTemperature &stasis_constraint_struct)
Identify if temperature DOFs of the cell are within the constraining range. If they are,...
TableHandler viscous_dissipation_table
virtual void update_mortar_configuration()
Update mortar configuration.
void postprocessing_forces(const VectorType &evaluation_point)
Post-processing function Outputs the forces acting on each boundary condition.
void set_nodal_values()
Set the nodal values of velocity and pressure.
void get_cell_filtered_phase_indicator_values(const typename DoFHandler< dim >::active_cell_iterator &cell, const DoFHandler< dim > *dof_handler_cls, const GlobalVectorType &filtered_phase_indicator_solution, std::vector< double > &local_filtered_phase_indicator_values)
Get cell's local filtered phase indicator values at quadrature points.
virtual void write_checkpoint()
Write the checkpoint.
std::shared_ptr< DoFHandler< dim > > dof_handler
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
virtual ~NavierStokesBase()=default
void reinit_mortar_operators()
Initialize mortar coupling manager, operator, and evaluator.
virtual void postprocess(bool first_iteration)
Post-process simulation after an iteration.
const unsigned int velocity_fem_degree
The PVDHandler class manages the storage of the information required to write pvd file....
Definition pvd_handler.h:17
PhysicsSolver(const Parameters::NonLinearSolver non_linear_solver_parameters)
Constructor for the non-linear physics.
Identifiers for multiphysics modules and their solution fields.
FluidDynamicsFormulation
Formulation of the fluid dynamics equations solved by a Navier-Stokes solver.
@ standard
Standard Navier-Stokes equations.
@ fluid_dynamics
Fluid Dynamics (Velocity,Pressure).
DeclException1(FluidDynamicsBoundaryConditionMissing, types::boundary_id,<< "The boundary id: "<< arg1<< " is defined in the triangulation, but not as a boundary condition for the fluid dynamics physics. Lethe does not assign a default boundary condition to boundary ids. Every boundary id defined within the triangulation must have a corresponding boundary condition defined in the input file.")
std::variant< OutputStructPostprocessor< dim, VectorType >, OutputStructSolution< dim, VectorType >, OutputStructCellVector > OutputStruct
Variant handler of the three output structs (OutputStructPostprocessor, OutputStructSolution and Outp...
Simulation control classes for managing time-stepping and iteration control in Lethe.
Structure that stores all SDIRK-related vectors used during the time integration process.
std::vector< VectorType > previous_k_j_solutions
Stores the previous k_j stage vectors (one per stage j < i).
VectorType sum_over_previous_stages
Stores the sum of a_ij * k_j for j < i.
VectorType sum_bi_ki
Stores the sum of b_i * k_i across all stages.
Struct containing fluid id, temperature and phase indicator range information, and flag containers fo...
StasisConstraintWithTemperature(const unsigned int fluid_id, const double min_solid_temperature, const double max_solid_temperature, const double filtered_phase_indicator_tolerance)
Default constructor of the struct.
std::unordered_set< types::global_dof_index > dofs_are_connected_to_fluid
Container of global DOF indices connected to at least one fluid cell.
std::unordered_set< types::global_dof_index > dofs_are_in_solid
Container of global DOF indices located in solid cells.
const double filtered_phase_indicator_tolerance
Tolerance applied on filtered phase indicator.
const unsigned int fluid_id
Identifier of the fluid that is constrained.
const double min_solid_temperature
Lower threshold values of the constraining field (temperature).
const double max_solid_temperature
Upper threshold values of the constraining field (temperature).
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17