Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
fluid_dynamics_matrix_free_operators.cc
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#include <core/bdf.h>
6
8
9#include <deal.II/grid/grid_generator.h>
10
11#include <deal.II/lac/sparsity_tools.h>
12
13#include <deal.II/multigrid/mg_tools.h>
14
15/**
16 * @brief Creates and fills a table that works as bool dof mask object
17 * needed for the sparsity pattern and computation of the system matrix
18 * of the coarse level in case FE_Q_iso_Q1 elements are used.
19 *
20 * @tparam dim An integer that denotes the number of spatial dimensions.
21 * @tparam spacedim Space dimension.
22 * @param[in] fe Type of finite element used.
23 * @param[in] quadrature Quadrature being used.
24 * @return Table<2, bool> Boolean mask with pairs of dof indices.
25 */
26template <int dim, int spacedim>
27const Table<2, bool>
28create_bool_dof_mask(const FiniteElement<dim, spacedim> &fe,
29 const Quadrature<dim> &quadrature)
30{
31 const auto compute_scalar_bool_dof_mask = [&quadrature](const auto &fe) {
32 Table<2, bool> bool_dof_mask(fe.dofs_per_cell, fe.dofs_per_cell);
33 MappingQ1<dim, spacedim> mapping;
34 FEValues<dim> fe_values(mapping, fe, quadrature, update_values);
35
36 Triangulation<dim, spacedim> tria;
37 GridGenerator::hyper_cube(tria);
38
39 fe_values.reinit(tria.begin());
40 for (unsigned int i = 0; i < fe.dofs_per_cell; ++i)
41 for (unsigned int j = 0; j < fe.dofs_per_cell; ++j)
42 {
43 double sum = 0;
44 for (unsigned int q = 0; q < quadrature.size(); ++q)
45 sum += fe_values.shape_value(i, q) * fe_values.shape_value(j, q);
46 if (sum != 0)
47 bool_dof_mask(i, j) = true;
48 }
49
50 return bool_dof_mask;
51 };
52
53 Table<2, bool> bool_dof_mask(fe.dofs_per_cell, fe.dofs_per_cell);
54
55 if (fe.n_components() == 1)
56 {
57 bool_dof_mask = compute_scalar_bool_dof_mask(fe);
58 }
59 else
60 {
61 const auto scalar_bool_dof_mask =
62 compute_scalar_bool_dof_mask(fe.base_element(0));
63
64 for (unsigned int i = 0; i < fe.n_dofs_per_cell(); ++i)
65 for (unsigned int j = 0; j < fe.n_dofs_per_cell(); ++j)
66 if (scalar_bool_dof_mask[fe.system_to_component_index(i).second]
67 [fe.system_to_component_index(j).second])
68 bool_dof_mask[i][j] = true;
69 }
70
71
72 return bool_dof_mask;
73}
74
75
76
77template <int dim, typename number>
79 : pcout(std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
80 , timer(this->pcout, TimerOutput::never, TimerOutput::wall_times)
81{}
82
83template <int dim, typename number>
85 const Mapping<dim> &mapping,
86 const DoFHandler<dim> &dof_handler,
87 const AffineConstraints<number> &constraints,
88 const Quadrature<dim> &quadrature,
89 const std::shared_ptr<Function<dim>> &forcing_function,
90 const std::shared_ptr<PhysicalPropertiesManager> &physical_properties_manager,
92 const unsigned int mg_level,
93 const std::shared_ptr<SimulationControl> &simulation_control,
96 const bool &enable_hessians_jacobian,
97 const bool &enable_hessians_residual,
98 const bool &enable_mortar)
99 : pcout(std::cout, Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
100 , timer(this->pcout, TimerOutput::never, TimerOutput::wall_times)
101{
102 this->reinit(mapping,
103 dof_handler,
105 quadrature,
107 physical_properties_manager,
109 mg_level,
115}
116
117template <int dim, typename number>
118void
120 const Mapping<dim> &mapping,
121 const DoFHandler<dim> &dof_handler,
122 const AffineConstraints<number> &constraints,
123 const Quadrature<dim> &quadrature,
124 const std::shared_ptr<Function<dim>> &forcing_function,
125 const std::shared_ptr<PhysicalPropertiesManager> &physical_properties_manager,
127 const unsigned int mg_level,
128 const std::shared_ptr<SimulationControl> &simulation_control,
131 const bool &enable_hessians_jacobian,
132 const bool &enable_hessians_residual,
133 const bool &enable_mortar)
134{
135 this->enable_face_terms = false;
136
137 this->boundary_conditions = boundary_conditions;
138
139 this->enable_mortar = enable_mortar;
140
141 this->system_matrix.clear();
142 this->constraints.copy_from(constraints);
143
144 typename MatrixFree<dim, number>::AdditionalData additional_data;
145 additional_data.mapping_update_flags =
146 (update_values | update_gradients | update_JxW_values |
147 update_quadrature_points | update_hessians);
148 additional_data.mg_level = mg_level;
149
150 // Loop over all boundary conditions to establish if one of them has face
151 // terms, if yes, enable them and add appropriate flags in the matrix-free
152 // additional data
153 for (auto const &[id, type] : boundary_conditions.type)
154 {
155 if (type ==
158 {
159 this->enable_face_terms = true;
160 additional_data.mapping_update_flags_boundary_faces =
161 update_values | update_gradients | update_quadrature_points |
162 update_JxW_values | update_normal_vectors;
163 }
165 {
166 this->enable_face_terms = true;
167 additional_data.mapping_update_flags_boundary_faces =
168 update_values | update_quadrature_points | update_JxW_values |
169 update_normal_vectors;
170 }
171 else if (type ==
173 {
174 this->enable_face_terms = true;
175 additional_data.mapping_update_flags_boundary_faces =
176 update_values | update_quadrature_points | update_JxW_values |
177 update_normal_vectors;
178 }
179 }
180
181 matrix_free.reinit(
182 mapping, dof_handler, this->constraints, quadrature, additional_data);
183
184 this->fe_degree = dof_handler.get_fe().degree;
185
187
188 this->properties_manager = physical_properties_manager;
189
190 if (stabilization ==
194 {
195 this->stabilization = stabilization;
196 }
197 else
198 throw std::runtime_error(
199 "Only SUPG/PSPG and GLS stabilization is supported at the moment.");
200
201 this->simulation_control = simulation_control;
202
203 this->enable_hessians_jacobian = enable_hessians_jacobian;
204
205 this->enable_hessians_residual = enable_hessians_residual;
206
207 this->compute_element_size();
208
209 this->has_solids = (this->properties_manager &&
210 this->properties_manager->get_number_of_solids() > 0);
211 if (this->has_solids)
213 else
214 this->solid_cell_mask.clear();
215
216 this->compute_forcing_term();
217
218 bool_dof_mask = create_bool_dof_mask(dof_handler.get_fe(), quadrature);
219
220 constrained_indices.clear();
221 for (auto i : this->matrix_free.get_constrained_dofs())
222 constrained_indices.push_back(i);
224
225 if (this->matrix_free.get_mg_level() != numbers::invalid_unsigned_int)
226 {
227 std::vector<types::global_dof_index> interface_indices;
228 IndexSet refinement_edge_indices;
229 refinement_edge_indices = get_refinement_edges(this->matrix_free);
230
231 interface_indices = refinement_edge_indices.get_index_vector();
232
234 edge_constrained_indices.reserve(interface_indices.size());
235 edge_constrained_values.resize(interface_indices.size());
236 const IndexSet &locally_owned =
237 this->matrix_free.get_dof_handler().locally_owned_mg_dofs(
238 this->matrix_free.get_mg_level());
239
240 for (const auto i : interface_indices)
241 if (locally_owned.is_element(i))
242 edge_constrained_indices.push_back(locally_owned.index_within_set(i));
243
245 Utilities::MPI::max(edge_constrained_indices.size(),
246 dof_handler.get_mpi_communicator()) > 0;
247
249 {
250 edge_constrained_cell.resize(matrix_free.n_cell_batches(), false);
251
252 VectorType temp;
253 matrix_free.initialize_dof_vector(temp);
254
255 for (const auto i : edge_constrained_indices)
256 temp.local_element(i) = 1.0;
257
258 temp.update_ghost_values();
259
260 FECellIntegrator integrator(matrix_free);
261
262 for (unsigned int cell = 0; cell < matrix_free.n_cell_batches();
263 ++cell)
264 {
265 integrator.reinit(cell);
266 integrator.read_dof_values(temp);
267
268 for (unsigned int i = 0; i < integrator.dofs_per_cell; ++i)
269 if ((integrator.begin_dof_values()[i] ==
270 VectorizedArray<number>()) == false)
271 {
272 edge_constrained_cell[cell] = true;
273 break;
274 }
275 }
276 }
277 }
278}
279
280template <int dim, typename number>
283{
284 TimeSteppingData data;
285
286 if (time_stepping_is_bdf(this->simulation_control->get_assembly_method()))
287 {
288 const auto time_steps_vector =
289 this->simulation_control->get_time_steps_vector();
290 data.dt = time_steps_vector[0];
291 data.bdf_coefficients = &this->simulation_control->get_bdf_coefficients();
292 data.is_bdf = true;
293 data.is_sdirk = false;
294 data.is_transient = true;
295 return data;
296 }
297
298 else if (time_stepping_is_sdirk(
299 this->simulation_control->get_assembly_method()))
300 {
301 const SDIRKTable table =
302 sdirk_table(this->simulation_control->get_assembly_method());
303 const SDIRKStageData stage_data(table, 1);
304 data.a_ii = stage_data.a_ij[0];
305
306 const auto time_steps_vector =
307 this->simulation_control->get_time_steps_vector();
308 data.dt = time_steps_vector[0];
309 data.is_sdirk = true;
310 data.is_bdf = false;
311 data.is_transient = true;
312 return data;
313 }
314 else
315 {
316 // Otherwise, this is not a transient simulation
317 data.is_transient = false;
318 return data;
319 }
320}
321
322template <int dim, typename number>
323void
325{
326 const unsigned int n_cells =
327 matrix_free.n_cell_batches() + matrix_free.n_ghost_cell_batches();
328 solid_cell_mask.resize(n_cells);
329
330 for (unsigned int cell = 0; cell < n_cells; ++cell)
331 {
332 // Inactive lanes never contribute to dst, but we set them to 0.0 for
333 // safety in case future code reads the mask before submission.
334 VectorizedArray<number> mask(0.0);
335
336 for (unsigned int lane = 0;
337 lane < matrix_free.n_active_entries_per_cell_batch(cell);
338 ++lane)
339 {
340 mask[lane] =
341 (matrix_free.get_cell_iterator(cell, lane)->material_id() == 0) ?
342 1.0 :
343 0.0;
344 }
345
346 solid_cell_mask[cell] = mask;
347 }
348}
349
350template <int dim, typename number>
351void
353{
354 const unsigned int n_cells =
355 matrix_free.n_cell_batches() + matrix_free.n_ghost_cell_batches();
356 element_size.resize(n_cells);
357
358 for (unsigned int cell = 0; cell < n_cells; ++cell)
359 {
360 for (auto lane = 0u;
361 lane < matrix_free.n_active_entries_per_cell_batch(cell);
362 lane++)
363 {
364 const double h_k =
365 matrix_free.get_cell_iterator(cell, lane)->measure();
366
368 }
369 }
370}
371
372template <int dim, typename number>
373void
375{
376 if (this->forcing_function)
377 {
378 const unsigned int n_cells =
379 matrix_free.n_cell_batches() + matrix_free.n_ghost_cell_batches();
380
381 FECellIntegrator integrator(matrix_free);
382
383 forcing_terms.reinit(n_cells, integrator.n_q_points);
384
385 for (unsigned int cell = 0; cell < n_cells; ++cell)
386 {
387 integrator.reinit(cell);
388 for (const auto q : integrator.quadrature_point_indices())
389 {
390 const Point<dim, VectorizedArray<number>> point_batch =
391 integrator.quadrature_point(q);
392 forcing_terms(cell, q) =
394 point_batch);
395 }
396 }
397 }
398}
399
400template <int dim, typename number>
401void
403 const VectorType &temperature_solution,
404 const DoFHandler<dim> &temperature_dof_handler)
405{
406 const auto thermal_expansion_model =
407 this->properties_manager->get_thermal_expansion();
408
409 const double reference_temperature =
410 this->properties_manager->get_reference_temperature();
411
412 const unsigned int n_cells =
413 matrix_free.n_cell_batches() + matrix_free.n_ghost_cell_batches();
414
415 FEValues<dim> fe_values(*(this->matrix_free.get_mapping_info().mapping),
416 temperature_dof_handler.get_fe(),
417 this->matrix_free.get_quadrature(),
418 update_values);
419
420 thermal_buoyancy_term.reinit(n_cells, fe_values.n_quadrature_points);
421
422 std::vector<number> cell_temperature_solution(fe_values.n_quadrature_points);
423 std::vector<double> thermal_expansion(fe_values.n_quadrature_points);
424
425 for (unsigned int cell = 0; cell < n_cells; ++cell)
426 {
427 for (auto lane = 0u;
428 lane < matrix_free.n_active_entries_per_cell_batch(cell);
429 lane++)
430 {
431 fe_values.reinit(
432 matrix_free.get_cell_iterator(cell, lane)
433 ->as_dof_handler_iterator(temperature_dof_handler));
434
435 fe_values.get_function_values(temperature_solution,
436 cell_temperature_solution);
437
438 thermal_expansion_model->vector_value({}, thermal_expansion);
439
440 for (const auto q : fe_values.quadrature_point_indices())
441 {
442 // The following term is precomputed: (1 - β (T -Tref))
443 const auto scaling =
444 1 - thermal_expansion[q] *
445 (cell_temperature_solution[q] - reference_temperature);
446
447 // Store in table the total buoyancy term given as:
448 // (1 - β (T -Tref))g where the g has already been precomputed
449 // in compute_forcing_term() function.
450 for (int c = 0; c < dim; ++c)
451 thermal_buoyancy_term[cell][q][c][lane] =
452 forcing_terms[cell][q][c][lane] * scaling;
453 }
454 }
455 }
456}
457
458
459template <int dim, typename number>
460types::global_dof_index
462{
463 if (this->matrix_free.get_mg_level() != numbers::invalid_unsigned_int)
464 return this->matrix_free.get_dof_handler().n_dofs(
465 this->matrix_free.get_mg_level());
466 else
467 return this->matrix_free.get_dof_handler().n_dofs();
468}
469
470template <int dim, typename number>
471number
472NavierStokesOperatorBase<dim, number>::el(unsigned int, unsigned int) const
473{
474 Assert(false, ExcNotImplemented());
475 return 0;
476}
477
478template <int dim, typename number>
479void
484
485template <int dim, typename number>
486void
488 VectorType &vec) const
489{
490 matrix_free.initialize_dof_vector(vec);
491}
492
493template <int dim, typename number>
494const std::shared_ptr<const Utilities::MPI::Partitioner> &
496{
497 return matrix_free.get_vector_partitioner();
498}
499
500template <int dim, typename number>
501void
503 const VectorType &src) const
504{
505 this->timer.enter_subsection("operator::vmult");
506
507 // save values for edge constrained dofs and set them to 0 in src vector
508 for (unsigned int i = 0; i < edge_constrained_indices.size(); ++i)
509 {
511 src.local_element(edge_constrained_indices[i]);
512
513 const_cast<LinearAlgebra::distributed::Vector<number> &>(src)
514 .local_element(edge_constrained_indices[i]) = 0.;
515 }
516
517 // If mortar is enabled, we need to make the ghost values available so that
518 // they can be accessed by the mortar operator
519 if (this->enable_mortar)
520 src.update_ghost_values();
521
522 if (this->enable_face_terms)
523 this->matrix_free.loop(
527 this,
528 dst,
529 src,
530 true);
531 else
532 this->matrix_free.cell_loop(
534
535 // If enabled, add mortar entries
536 if (this->enable_mortar)
537 {
538 this->timer.enter_subsection("operator::vmult_mortar");
539 this->mortar_coupling_operator_mf->vmult_add(dst, src);
540 dst.compress(VectorOperation::add);
541 src.zero_out_ghost_values();
542 this->timer.leave_subsection("operator::vmult_mortar");
543 }
544
545 // copy constrained dofs from src to dst (corresponding to diagonal
546 // entries with value 1.0)
547 for (const auto &constrained_index : constrained_indices)
548 dst.local_element(constrained_index) = src.local_element(constrained_index);
549
550 // restoring edge constrained dofs in src and copy the values to dst
551 // (corresponding to diagonal entries with value 1.0)
552 for (unsigned int i = 0; i < edge_constrained_indices.size(); ++i)
553 {
554 const_cast<LinearAlgebra::distributed::Vector<number> &>(src)
555 .local_element(edge_constrained_indices[i]) =
557 dst.local_element(edge_constrained_indices[i]) =
559 }
560
561 this->timer.leave_subsection("operator::vmult");
562}
563
564template <int dim, typename number>
565void
567 const VectorType &src) const
568{
569 this->vmult(dst, src);
570}
571
572template <int dim, typename number>
573void
575 VectorType &dst,
576 VectorType const &src) const
577{
578 if (this->enable_face_terms)
579 this->matrix_free.loop(
583 this,
584 dst,
585 src,
586 true);
587 else
588 this->matrix_free.cell_loop(
590
591 // set constrained dofs as the sum of current dst value and src value
592 for (const auto i : constrained_indices)
593 dst.local_element(i) = src.local_element(i);
594}
595
596
597
598template <int dim, typename number>
599void
601 VectorType &dst,
602 VectorType const &src) const
603{
604 this->timer.enter_subsection("operator::vmult_interface_up");
605
606 if (has_edge_constrained_indices == false)
607 {
608 dst = number(0.);
609
610 this->timer.leave_subsection("operator::vmult_interface_up");
611 return;
612 }
613
614 dst = 0.0;
615
616 // make a copy of src vector and set everything to 0 except edge
617 // constrained dofs
618 VectorType src_cpy;
619 src_cpy.reinit(src, /*omit_zeroing_entries=*/false);
620
621 for (const auto i : edge_constrained_indices)
622 src_cpy.local_element(i) = src.local_element(i);
623
624 // do loop with copy of src
625 if (this->enable_face_terms)
626 this->matrix_free.loop(
630 this,
631 dst,
632 src_cpy,
633 true);
634 else
635 this->matrix_free.cell_loop(
637 this,
638 dst,
639 src_cpy,
640 false);
641
642 this->timer.leave_subsection("operator::vmult_interface_up");
643}
644
645
646
647template <int dim, typename number>
648const DynamicSparsityPattern &
653
654
655
656template <int dim, typename number>
657const TrilinosWrappers::SparseMatrix &
659{
660 this->timer.enter_subsection("operator::get_system_matrix");
661
662 if (system_matrix.m() == 0 && system_matrix.n() == 0)
663 {
664 const auto &dof_handler = this->matrix_free.get_dof_handler();
665
666 const unsigned int mg_level = this->matrix_free.get_mg_level();
667
668 IndexSet locally_relevant_dofs;
669 IndexSet locally_owned_dofs;
670
671 if (mg_level != numbers::invalid_unsigned_int)
672 {
673 locally_relevant_dofs =
674 DoFTools::extract_locally_relevant_level_dofs(dof_handler,
675 mg_level);
676 locally_owned_dofs = dof_handler.locally_owned_mg_dofs(mg_level);
677 }
678 else
679 {
680 locally_owned_dofs = dof_handler.locally_owned_dofs();
681 locally_relevant_dofs =
682 DoFTools::extract_locally_relevant_dofs(dof_handler);
683 }
684
685 this->dsp.reinit(locally_relevant_dofs.size(),
686 locally_relevant_dofs.size(),
687 locally_relevant_dofs);
688
689 if (mg_level != numbers::invalid_unsigned_int)
690 {
691 // the following code does the same as
692 // MGTools::make_sparsity_pattern() but also
693 // considers bool_dof_mask for FE_Q_iso_Q1
694 std::vector<types::global_dof_index> dofs_on_this_cell;
695
696 for (const auto &cell : dof_handler.cell_iterators_on_level(mg_level))
697 if (cell->is_locally_owned_on_level())
698 {
699 const unsigned int dofs_per_cell =
700 dof_handler.get_fe().n_dofs_per_cell();
701 dofs_on_this_cell.resize(dofs_per_cell);
702 cell->get_mg_dof_indices(dofs_on_this_cell);
703
704 constraints.add_entries_local_to_global(dofs_on_this_cell,
705 dsp,
706 false,
708 }
709 }
710 else
711 {
712 // the following code does the same as
713 // DoFTools::make_sparsity_pattern() but also
714 // considers bool_dof_mask for FE_Q_iso_Q1
715 std::vector<types::global_dof_index> dofs_on_this_cell;
716
717 for (const auto &cell : dof_handler.active_cell_iterators())
718 if (cell->is_locally_owned())
719 {
720 const unsigned int dofs_per_cell =
721 cell->get_fe().n_dofs_per_cell();
722 dofs_on_this_cell.resize(dofs_per_cell);
723 cell->get_dof_indices(dofs_on_this_cell);
724
725 constraints.add_entries_local_to_global(dofs_on_this_cell,
726 dsp,
727 false,
729 }
730 }
731
732 // If mortar is enabled, add sparsity pattern entries
733 if (this->enable_mortar)
734 this->mortar_coupling_operator_mf->add_sparsity_pattern_entries(dsp);
735
736 SparsityTools::distribute_sparsity_pattern(
737 dsp,
738 locally_owned_dofs,
739 dof_handler.get_triangulation().get_mpi_communicator(),
740 locally_relevant_dofs);
741
742 system_matrix.reinit(
743 locally_owned_dofs,
744 locally_owned_dofs,
745 dsp,
746 dof_handler.get_triangulation().get_mpi_communicator());
747 }
748
749 system_matrix = 0.0;
750
751 // the following code does the same as
752 // MatrixFreeTools::compute_matrix() but with
753 // minor corrections for FE_Q_iso_Q1
754
755 const auto &lexicographic_numbering =
756 matrix_free.get_shape_info().lexicographic_numbering;
757
758 unsigned int cell = numbers::invalid_unsigned_int;
759 unsigned int face = numbers::invalid_unsigned_int;
760 unsigned int column = numbers::invalid_unsigned_int;
761
762 std::function<void(FEFaceIntegrator &)> boundary_function;
763
765 {
766 boundary_function = [&](auto &integrator) {
767 if (face != integrator.get_current_cell_index())
768 {
769 face = integrator.get_current_cell_index();
770 column = 0;
771 }
772
774
775 // remove spurious entries for FE_Q_iso_Q1
776 for (unsigned int i = 0; i < lexicographic_numbering.size(); ++i)
777 {
778 if (!bool_dof_mask[lexicographic_numbering[i]]
779 [lexicographic_numbering[column]])
780 integrator.begin_dof_values()[i] = 0.0;
781 }
782
783
784 column++;
785 };
786 }
787
788 MatrixFreeTools::
789 compute_matrix<dim, -1, 0, dim + 1, number, VectorizedArray<number>>(
793 [&](auto &integrator) {
794 if (cell != integrator.get_current_cell_index())
795 {
796 cell = integrator.get_current_cell_index();
797 column = 0;
798 }
799
800 do_cell_integral_local(integrator);
801
802 // remove spurious entries for FE_Q_iso_Q1
803 for (unsigned int i = 0; i < lexicographic_numbering.size(); ++i)
804 if (!bool_dof_mask[lexicographic_numbering[i]]
805 [lexicographic_numbering[column]])
806 integrator.begin_dof_values()[i] = 0.0;
807
808 column++;
809 },
810 {},
811 boundary_function);
812
813 // If mortar is enabled, add system matrix entries
814 if (this->enable_mortar)
815 {
816 this->timer.enter_subsection("operator::get_system_matrix_mortar");
817 this->mortar_coupling_operator_mf->add_system_matrix_entries(
819 system_matrix.compress(VectorOperation::add);
820 this->timer.leave_subsection("operator::get_system_matrix_mortar");
821 }
822
823 // make sure that diagonal entries related to constrained dofs
824 // have a value of 1.0 (note this is consistent to vmult() and
825 // compute_inverse_diagonal())
826 for (const auto &local_row : constrained_indices)
827 {
828 const auto global_row =
829 get_vector_partitioner()->local_to_global(local_row);
830 system_matrix.set(global_row, global_row, 1.0);
831 }
832
833 for (const auto &local_row : edge_constrained_indices)
834 {
835 const auto global_row =
836 get_vector_partitioner()->local_to_global(local_row);
837 system_matrix.set(global_row, global_row, 1.0);
838 }
839
840 system_matrix.compress(VectorOperation::insert);
841
842 this->timer.leave_subsection("operator::get_system_matrix");
843
844 return this->system_matrix;
845}
846
847template <int dim, typename number>
848const MatrixFree<dim, number> &
853
854template <int dim, typename number>
855const AlignedVector<VectorizedArray<number>>
860
861template <int dim, typename number>
862void
864{
866 {
867 // Change the timer subsection name.
868 this->timer.enter_subsection(
869 "operator::evaluate_prescribed_neumann_traction");
870 const unsigned int n_inner_faces = matrix_free.n_inner_face_batches();
871 const unsigned int n_boundary_faces =
872 matrix_free.n_boundary_face_batches();
873
874 FEFaceIntegrator face_integrator(matrix_free, true, 0);
875
876 prescribed_neumann_traction.reinit(n_boundary_faces,
877 face_integrator.n_q_points);
878
879 for (unsigned int face = n_inner_faces;
880 face < n_inner_faces + n_boundary_faces;
881 ++face)
882 {
883 face_integrator.reinit(face);
884
885 for (const auto q : face_integrator.quadrature_point_indices())
886 {
887 if (this->boundary_conditions.type.at(
888 face_integrator.boundary_id()) ==
890 neumann_traction)
891 {
892 Point<dim, VectorizedArray<number>> point_batch =
893 face_integrator.quadrature_point(q);
894
895 /*
896 Neumann traction is of type Tensor<1, dim+1,
897 VectorizedArray<number>> where the first dim components
898 correspond to the traction vector and the last component
899 corresponds to the pressure value at the boundary. The dummy
900 pressure component is needed to properly assemble the traction
901 term as FEFaceIntegrator uses MatrixFree which in turn is
902 based on the DoFHandler which in turn is based on the FE
903 system that has dim velocity components and 1 pressure
904 component.
905 */
906
907 prescribed_neumann_traction(face - n_inner_faces, q) =
909 this->boundary_conditions.navier_stokes_functions
910 .at(face_integrator.boundary_id())
911 ->traction_fn,
912 point_batch);
913 }
914 }
915 }
916 this->timer.leave_subsection(
917 "operator::evaluate_prescribed_neumann_traction");
918 }
919}
920
921template <int dim, typename number>
922void
925{
926 this->timer.enter_subsection("operator::evaluate_non_linear_term");
927
928 const unsigned int n_cells = matrix_free.n_cell_batches();
929 const unsigned int n_inner_faces = matrix_free.n_inner_face_batches();
930 const unsigned int n_boundary_faces = matrix_free.n_boundary_face_batches();
931
932 const double kinematic_viscosity =
933 this->properties_manager->get_rheology()->get_kinematic_viscosity();
934
935 FECellIntegrator integrator(matrix_free);
936 FEFaceIntegrator face_integrator(matrix_free, true, 0);
937
938
939 // 1. Precompute values on cells:
940
941 // Set appropriate size for tables
942 nonlinear_previous_values.reinit(n_cells, integrator.n_q_points);
943 nonlinear_previous_gradient.reinit(n_cells, integrator.n_q_points);
944 nonlinear_previous_hessian_diagonal.reinit(n_cells, integrator.n_q_points);
945 nonlinear_previous_hessian.reinit(n_cells, integrator.n_q_points);
946 stabilization_parameter.reinit(n_cells, integrator.n_q_points);
947 stabilization_parameter_lsic.reinit(n_cells, integrator.n_q_points);
948 kinematic_viscosity_vector.reinit(n_cells, integrator.n_q_points);
949 grad_kinematic_viscosity_shear_rate.reinit(n_cells, integrator.n_q_points);
950 kinematic_viscosity_gradient.reinit(n_cells, integrator.n_q_points);
951 previous_shear_rate.reinit(n_cells, integrator.n_q_points);
952 previous_shear_rate_magnitude.reinit(n_cells, integrator.n_q_points);
953 nonlinear_previous_advective_values.reinit(n_cells, integrator.n_q_points);
954
955 // Define 1/dt if the simulation is transient
956 double sdt = 0.0;
957
958 const bool transient =
959 time_stepping_is_bdf(simulation_control->get_assembly_method()) ||
960 time_stepping_is_sdirk(simulation_control->get_assembly_method());
961
962 if (transient)
963 {
964 const auto time_steps_vector =
965 this->simulation_control->get_time_steps_vector();
966 const double dt = time_steps_vector[0];
967 sdt = 1. / dt;
968 }
969
970 for (unsigned int cell = 0; cell < n_cells; ++cell)
971 {
972 integrator.reinit(cell);
973 integrator.read_dof_values_plain(newton_step);
974
975 if (this->enable_hessians_jacobian)
976 integrator.evaluate(EvaluationFlags::values |
977 EvaluationFlags::gradients |
978 EvaluationFlags::hessians);
979 else
980 integrator.evaluate(EvaluationFlags::values |
981 EvaluationFlags::gradients);
982
983 // Get previously calculated element size needed for tau
984 const auto h = integrator.read_cell_data(this->get_element_size());
985
986 for (const auto q : integrator.quadrature_point_indices())
987 {
988 nonlinear_previous_values(cell, q) = integrator.get_value(q);
989 nonlinear_previous_gradient(cell, q) = integrator.get_gradient(q);
991 integrator.get_value(q);
992
993 // If mortar is enabled, subtract u_ALE from the advective velocity
994 if (this->enable_mortar)
996 this->velocity_ale(cell, q);
997
998 if (this->enable_hessians_jacobian)
999 {
1001 integrator.get_hessian_diagonal(q);
1002 nonlinear_previous_hessian(cell, q) = integrator.get_hessian(q);
1003 }
1004
1005 // Calculate tau
1006 VectorizedArray<number> u_mag_squared = 1e-12;
1007 for (int k = 0; k < dim; ++k)
1008 u_mag_squared += Utilities::fixed_power<2>(
1009 this->nonlinear_previous_advective_values(cell, q)[k]);
1010
1011 stabilization_parameter(cell, q) =
1012 1. / std::sqrt(Utilities::fixed_power<2>(sdt) +
1013 4. * u_mag_squared / h / h +
1014 9. * Utilities::fixed_power<2>(
1015 4. * kinematic_viscosity / (h * h)));
1016
1018 std::sqrt(u_mag_squared) * h * 0.5;
1019 }
1020
1021 // Compute kinematic viscosity-related entries for non-Newtonian fluids
1022 // according to the rheological model
1023 if (this->properties_manager->is_non_newtonian())
1024 {
1025 typename FECellIntegrator::gradient_type shear_rate;
1026 typename FECellIntegrator::value_type grad_shear_rate = {};
1027 VectorizedArray<number> shear_rate_magnitude;
1028
1029 for (const auto q : integrator.quadrature_point_indices())
1030 {
1031 typename FECellIntegrator::gradient_type gradient =
1032 integrator.get_gradient(q);
1033
1034 typename FECellIntegrator::hessian_type hessian =
1035 integrator.get_hessian(q);
1036
1037 // Calculate shear rate
1038 for (int i = 0; i < dim; ++i)
1039 {
1040 for (int j = 0; j < dim; ++j)
1041 {
1042 shear_rate[i][j] = gradient[i][j] + gradient[j][i];
1043 }
1044 }
1045
1046 // Store shear rate in the previous_shear_rate
1047 this->previous_shear_rate[cell][q] = shear_rate;
1048
1049 // Calculate shear rate magnitude
1050 shear_rate_magnitude = shear_rate * shear_rate;
1051
1052 shear_rate_magnitude = std::max(sqrt(0.5 * shear_rate_magnitude),
1053 VectorizedArray<number>(1e-12));
1054
1055 // Store shear rate magnitude in the previous_shear_rate
1056 this->previous_shear_rate_magnitude[cell][q] =
1057 shear_rate_magnitude;
1058
1059 // Compute gradient of shear rate
1060 // ∂d gamma_dot = 1/(2*gamma_dot)*(∂iuj + ∂jui) * ∂d(∂iuj +
1061 // ∂jui)
1062 for (int d = 0; d < dim; ++d)
1063 {
1064 grad_shear_rate[d] = 0.;
1065 for (int i = 0; i < dim; ++i)
1066 {
1067 for (int k = 0; k < dim; ++k)
1068 {
1069 grad_shear_rate[d] +=
1070 VectorizedArray<number>(0.5) *
1071 (gradient[i][k] + gradient[k][i]) *
1072 (hessian[i][d][k] + hessian[k][d][i]) /
1073 shear_rate_magnitude;
1074 }
1075 }
1076 }
1077
1078 // Store the shear rate magnitude in the appropriate data
1079 // structure needed for the set field vector function
1080
1081 VectorizedArray<number> viscosity;
1082 VectorizedArray<number> grad_viscosity_shear_rate;
1083
1084 for (unsigned int v = 0; v < VectorizedArray<number>::size(); ++v)
1085 {
1086 // Get information from physical properties class
1087 std::map<field, double> fields;
1088 fields[field::shear_rate] = shear_rate_magnitude[v];
1089
1090 viscosity[v] =
1091 this->properties_manager->get_rheology()->value(fields);
1092
1093 grad_viscosity_shear_rate[v] =
1094 this->properties_manager->get_rheology()->jacobian(
1095 fields, field::shear_rate);
1096 }
1097
1099 grad_viscosity_shear_rate;
1100
1102 grad_shear_rate * grad_viscosity_shear_rate;
1103
1104 kinematic_viscosity_vector(cell, q) = viscosity;
1105
1106 // Recalculate stabilization parameter using kinematic
1107 // viscosity vector
1108 VectorizedArray<number> u_mag_squared = 1e-12;
1109 for (int k = 0; k < dim; ++k)
1110 u_mag_squared +=
1111 Utilities::fixed_power<2>(integrator.get_value(q)[k]);
1112
1113 stabilization_parameter(cell, q) =
1114 1. /
1115 std::sqrt(
1116 Utilities::fixed_power<2>(sdt) + 4. * u_mag_squared / h / h +
1117 9. * Utilities::fixed_power<2>(4. * viscosity / (h * h)));
1118 }
1119 }
1120 }
1121
1122 // 2. Precompute values on faces if required
1123
1125 {
1126 effective_beta_face.reinit(n_boundary_faces);
1127 face_target_velocity.reinit(n_boundary_faces, face_integrator.n_q_points);
1128 face_target_pressure.reinit(n_boundary_faces, face_integrator.n_q_points);
1129
1130 face_nonlinear_previous_values.reinit(n_boundary_faces,
1131 face_integrator.n_q_points);
1132
1133 // Boundary faces are padded after the internal faces
1134 // Consequently, we need to offset the indices to avoid storing too
1135 // much information regarding the boundary faces (e.g. too large
1136 // vectors)
1137 for (unsigned int face = n_inner_faces;
1138 face < n_inner_faces + n_boundary_faces;
1139 ++face)
1140 {
1141 face_integrator.reinit(face);
1142
1143 // Check if the boundary condition is a weak Dirichlet boundary
1144 // condition or an outlet boundary condition, otherwise, no terms
1145 // need to be precomputed for faces
1147 this->boundary_conditions.type.at(
1148 face_integrator.boundary_id())) == false)
1149 continue;
1150
1151 // We need to read the values for the outlet boundary condition
1152 if (this->boundary_conditions.type.at(
1153 face_integrator.boundary_id()) ==
1155 {
1156 face_integrator.read_dof_values_plain(newton_step);
1157 face_integrator.evaluate(
1158 EvaluationFlags::EvaluationFlags::values);
1159 }
1160
1161 for (const auto q : face_integrator.quadrature_point_indices())
1162 {
1163 if (this->boundary_conditions.type.at(
1164 face_integrator.boundary_id()) ==
1166 {
1167 Point<dim, VectorizedArray<number>> point_batch =
1168 face_integrator.quadrature_point(q);
1169
1170 Tensor<1, dim, VectorizedArray<number>> target_velocity_value;
1171
1172 target_velocity_value[0] = evaluate_function<dim, number>(
1173 boundary_conditions.navier_stokes_functions
1174 .at(face_integrator.boundary_id())
1175 ->u,
1176 point_batch);
1177
1178 target_velocity_value[1] = evaluate_function<dim, number>(
1179 boundary_conditions.navier_stokes_functions
1180 .at(face_integrator.boundary_id())
1181 ->v,
1182 point_batch);
1183
1184 if constexpr (dim == 3)
1185 target_velocity_value[2] = evaluate_function<dim, number>(
1186 boundary_conditions.navier_stokes_functions
1187 .at(face_integrator.boundary_id())
1188 ->w,
1189 point_batch);
1190
1191 face_target_velocity(face - n_inner_faces, q) =
1192 target_velocity_value;
1193 }
1194 else if (this->boundary_conditions.type.at(
1195 face_integrator.boundary_id()) ==
1197 {
1198 face_nonlinear_previous_values[face - n_inner_faces][q] =
1199 face_integrator.get_value(q);
1200 }
1201
1202 else if (this->boundary_conditions.type.at(
1203 face_integrator.boundary_id()) ==
1205 {
1206 // Gather the quadrature points
1207 Point<dim, VectorizedArray<number>> point_batch =
1208 face_integrator.quadrature_point(q);
1209
1210 // Evaluate the face target pressure
1211 face_target_pressure(face - n_inner_faces, q) =
1213 boundary_conditions.navier_stokes_functions
1214 .at(face_integrator.boundary_id())
1215 ->p,
1216 point_batch);
1217 }
1218 }
1219
1220 // Calculate the element size and use it to calculate the penalty
1221 // parameter with the beta factor given in the parameter file
1222 VectorizedArray<number> cell_size = 1.0;
1223
1224 const auto [cell_it, _] = matrix_free.get_face_iterator(face, 0);
1225
1226 cell_size = compute_cell_diameter<dim>(cell_it->measure(), fe_degree);
1227
1228 const double beta =
1229 this->boundary_conditions.beta.at(face_integrator.boundary_id());
1230
1231 effective_beta_face(face - n_inner_faces) =
1232 beta / std::pow(cell_size, static_cast<number>(fe_degree + 1));
1233 }
1234 }
1235
1236 this->timer.leave_subsection("operator::evaluate_non_linear_term");
1237}
1238
1239template <int dim, typename number>
1240void
1243 const VectorType &time_derivative_previous_solutions)
1244{
1245 this->timer.enter_subsection(
1246 "operator::evaluate_time_derivative_previous_solutions");
1247
1248 const unsigned int n_cells = matrix_free.n_cell_batches();
1249 FECellIntegrator integrator(matrix_free);
1250
1251 time_derivatives_previous_solutions.reinit(n_cells, integrator.n_q_points);
1252
1253 for (unsigned int cell = 0; cell < n_cells; ++cell)
1254 {
1255 integrator.reinit(cell);
1256 integrator.read_dof_values_plain(time_derivative_previous_solutions);
1257 integrator.evaluate(EvaluationFlags::values);
1258 for (const auto q : integrator.quadrature_point_indices())
1259 time_derivatives_previous_solutions(cell, q) += integrator.get_value(q);
1260 }
1261
1262 this->timer.leave_subsection(
1263 "operator::evaluate_time_derivative_previous_solutions");
1264}
1265
1266template <int dim, typename number>
1267void
1269 const Mapping<dim> &mapping,
1270 const Point<dim> center_of_rotation,
1271 const unsigned int rotation_axis_direction,
1272 const std::shared_ptr<Functions::ParsedFunction<dim>> &rotor_angular_velocity)
1273{
1274 this->timer.enter_subsection("operator::evaluate_velocity_ale");
1275
1276 const unsigned int n_cells =
1277 matrix_free.n_cell_batches() + matrix_free.n_ghost_cell_batches();
1278
1279 FECellIntegrator integrator(matrix_free);
1280 matrix_free.update_mapping(mapping);
1281
1282 // 1. Precompute values on cells:
1283
1284 // Set appropriate size for tables
1285 velocity_ale.reinit(n_cells, integrator.n_q_points);
1286
1287 // Get updated rotor angular velocity
1288 rotor_angular_velocity->set_time(
1289 this->simulation_control->get_current_time());
1290 const double rotor_angular_velocity_value =
1291 rotor_angular_velocity->value(Point<dim>());
1292
1293 for (unsigned int cell = 0; cell < n_cells; ++cell)
1294 {
1295 integrator.reinit(cell);
1296 for (auto lane = 0u;
1297 lane < matrix_free.n_active_entries_per_cell_batch(cell);
1298 lane++)
1299 {
1300 // Apply prescribed rotor angular velocity only at rotor cells
1301 // (material_id = 1)
1302 double omega = 0.0;
1303 if (matrix_free.get_cell_iterator(cell, lane)->material_id() == 1)
1304 omega = rotor_angular_velocity_value;
1305
1306 // The mortar implementation is not defined for more than two
1307 // materials. Throw when running debug mode as a security measure to
1308 // prevent this case
1309 Assert(
1310 matrix_free.get_cell_iterator(cell, lane)->material_id() < 2,
1311 ExcMessage(
1312 "The material id in a cell was identified as equal or greater than 2, however the mortar implementation is not defined for more than two materials."));
1313
1314 // Compute linear velocity at quadrature points
1315 for (const auto q : integrator.quadrature_point_indices())
1316 {
1317 // Store point coordinates in tensor format
1318 Tensor<1, dim> p;
1319 for (int i = 0; i < dim; i++)
1320 p[i] = integrator.quadrature_point(q)[i][lane] -
1321 center_of_rotation[i];
1322
1323 // Compute terms of u_ale
1324 const auto product = LetheGridTools::angular_to_linear_velocity(
1325 omega, p, rotation_axis_direction);
1326
1327 for (int i = 0; i < dim; i++)
1328 this->velocity_ale[cell][q][i][lane] = product[i];
1329 }
1330 }
1331 }
1332
1333 this->timer.leave_subsection("operator::evaluate_velocity_ale");
1334}
1335
1336template <int dim, typename number>
1337void
1339 const Tensor<1, dim> &beta_force)
1340{
1341 for (unsigned int v = 0; v < VectorizedArray<number>::size(); ++v)
1342 {
1343 for (int d = 0; d < dim; ++d)
1344 this->beta_force[d][v] = beta_force[d];
1345 }
1346}
1347
1348template <int dim, typename number>
1349void
1351 const VectorType &src)
1352{
1353 this->timer.enter_subsection("operator::evaluate_residual");
1354
1356 this->matrix_free.loop(
1360 this,
1361 dst,
1362 src,
1363 true);
1364 else
1365 this->matrix_free.cell_loop(
1367
1368 this->timer.leave_subsection("operator::evaluate_residual");
1369}
1370
1371template <int dim, typename number>
1372void
1374 VectorType &diagonal) const
1375{
1376 this->timer.enter_subsection("operator::compute_inverse_diagonal");
1377
1378 std::function<void(FEFaceIntegrator &)> boundary_function;
1379
1380 if ((enable_face_terms))
1381 boundary_function = [&](auto &integrator) {
1383 };
1384
1385 matrix_free.initialize_dof_vector(diagonal);
1386 MatrixFreeTools::
1387 compute_diagonal<dim, -1, 0, dim + 1, number, VectorizedArray<number>>(
1389 diagonal,
1390 [&](auto &integrator) { this->do_cell_integral_local(integrator); },
1391 {},
1392 boundary_function);
1393
1394 // If mortar is enabled, add diagonal entries
1395 if (this->enable_mortar)
1396 {
1397 this->timer.enter_subsection("operator::compute_inverse_diagonal_mortar");
1398 this->mortar_coupling_operator_mf->add_diagonal_entries(diagonal);
1399 this->timer.leave_subsection("operator::compute_inverse_diagonal_mortar");
1400 }
1401
1402 for (const auto &i : edge_constrained_indices)
1403 diagonal.local_element(i) = 0.0;
1404
1405 for (auto &i : diagonal)
1406 i = (std::abs(i) > 1.0e-10) ? (1.0 / i) : 1.0;
1407
1408 this->timer.leave_subsection("operator::compute_inverse_diagonal");
1409}
1410
1411template <int dim, typename number>
1412void
1414 const MatrixFree<dim, number> &matrix_free,
1415 VectorType &dst,
1416 const VectorType &src,
1417 const std::pair<unsigned int, unsigned int> &range) const
1418{
1419 FECellIntegrator integrator(matrix_free, range);
1420
1421 for (unsigned int cell = range.first; cell < range.second; ++cell)
1422 {
1423 integrator.reinit(cell);
1424
1425 integrator.read_dof_values(src);
1426
1427 do_cell_integral_local(integrator);
1428
1429 integrator.distribute_local_to_global(dst);
1430 }
1431}
1432
1433template <int dim, typename number>
1434void
1436 const MatrixFree<dim, number> &matrix_free,
1437 VectorType &dst,
1438 const VectorType &src,
1439 const std::pair<unsigned int, unsigned int> &range) const
1440{
1441 (void)matrix_free;
1442 (void)dst;
1443 (void)src;
1444 (void)range;
1445
1446 // nothing to do
1447}
1448
1449template <int dim, typename number>
1450template <bool assemble_residual>
1451void
1453 const MatrixFree<dim, number> &matrix_free,
1454 VectorType &dst,
1455 const VectorType &src,
1456 const std::pair<unsigned int, unsigned int> &range) const
1457{
1458 FEFaceIntegrator phi(matrix_free, true, 0);
1459
1460 for (auto cell = range.first; cell < range.second; ++cell)
1461 {
1462 phi.reinit(cell);
1463
1464 if (assemble_residual)
1465 phi.read_dof_values_plain(src);
1466 else
1467 phi.read_dof_values(src);
1468
1470
1471 phi.distribute_local_to_global(dst);
1472 }
1473}
1474
1475
1476// Assembles face terms of boundary conditions for both the Jacobian matrix
1477// and the residual. There are two types implemented:
1478// 1. Weak Dirichlet boundary conditions using Nitsche's symmetric
1479// penalty method. It adds the following term:
1480// (v,β·(u-u_target)) - ν(v,∇δu·n) - ν(∇v·n,(u-u_target))
1481// 2. Outlet boundary conditions using the directional do-nothing method.
1482// It adds the following term: -(v,β(u·n)_·u) where (u·n)_=min(0,u·n)
1483// 3. Neumann traction boundary conditions adding the term
1484// \f$(\mathrm{traction\_fn},\, \mathbf{v})\f$ on the RHS.
1485template <int dim, typename number>
1486template <bool assemble_residual>
1487void
1489 FEFaceIntegrator &integrator) const
1490{
1491 if (!enable_face_terms)
1492 return;
1493
1494 // If the boundary condition is not in our list of boundary
1495 // conditions or the boundary condition that is set in the list is
1496 // not a boundary condition that requires face asssembly (for example
1497 // pressure, weak dirichlet, outlet or neumann traction), there is nothing
1498 // to do, so we set the values to zero and return
1500 this->boundary_conditions.type.at(integrator.boundary_id())) == false)
1501 {
1502 const VectorizedArray<number> zero = 0.0;
1503
1504 for (unsigned int i = 0; i < integrator.dofs_per_cell; ++i)
1505 integrator.begin_dof_values()[i] = zero;
1506 return;
1507 }
1508
1509 const auto face = integrator.get_current_cell_index();
1510 const unsigned int face_index = face - matrix_free.n_inner_face_batches();
1511
1512 const double kinematic_viscosity =
1513 this->properties_manager->get_rheology()->get_kinematic_viscosity();
1514
1515 const auto penalty_parameter = this->effective_beta_face[face_index];
1516
1517 if (this->boundary_conditions.type.at(integrator.boundary_id()) ==
1519 {
1520 integrator.evaluate(EvaluationFlags::EvaluationFlags::values |
1521 EvaluationFlags::EvaluationFlags::gradients);
1522
1523 for (const auto q : integrator.quadrature_point_indices())
1524 {
1525 typename FEFaceIntegrator::value_type value_result = {};
1526 typename FEFaceIntegrator::gradient_type gradient_result = {};
1527
1528 const auto normal_vector = integrator.normal_vector(q);
1529
1530 auto value = integrator.get_value(q);
1531 const auto gradient = integrator.get_gradient(q);
1532
1533
1534 // If we are assembling the residual, subtract the target velocity
1535 // from the velocity value.
1536 if constexpr (assemble_residual)
1537 for (int d = 0; d < dim; ++d)
1538 value[d] -= this->face_target_velocity[face_index][q][d];
1539
1540 for (int d = 0; d < dim; ++d)
1541 {
1542 // Assemble (v,beta (u-u_target)) for the main penalization
1543 value_result[d] += penalty_parameter * value[d];
1544
1545 // Assemble ν(v,∇δu·n)
1546 for (int i = 0; i < dim; ++i)
1547 value_result[d] -=
1548 kinematic_viscosity * gradient[d][i] * normal_vector[i];
1549 // Assemble ν(∇v·n,(u-u_target))
1550 for (int i = 0; i < dim; ++i)
1551 gradient_result[d][i] -=
1552 kinematic_viscosity * value[d] * normal_vector[i];
1553 }
1554 integrator.submit_value(value_result, q);
1555 integrator.submit_gradient(gradient_result, q);
1556 }
1557
1558 integrator.integrate(EvaluationFlags::EvaluationFlags::values |
1559 EvaluationFlags::EvaluationFlags::gradients);
1560 }
1561 // This part assembles the prescribed Neumann traction boundary condition (σ
1562 // . n , v) = (traction_fn, v) only on the RHS (residual) since it does not
1563 // depend on the solution
1564 else if (this->boundary_conditions.type.at(integrator.boundary_id()) ==
1566 {
1567 integrator.evaluate(EvaluationFlags::values);
1568 {
1569 for (const auto q : integrator.quadrature_point_indices())
1570 {
1571 typename FEFaceIntegrator::value_type value_result = {};
1572 for (int d = 0; d < dim; ++d)
1573 {
1574 // Because we have enabled submission of the value for the
1575 // faces, a value must be provided even when the operator is
1576 // assembled. When the RHS is being assembled, we provide the
1577 // value of the traction, and when the operator is assembled, we
1578 // provide a zero value.
1579 if constexpr (assemble_residual)
1580 // The matrix free solver assembles the residual and not - the
1581 // residual, so a minus sign here is necessary.
1582 value_result[d] =
1583 -this->prescribed_neumann_traction(face_index, q)[d];
1584 else
1585 value_result[d] = 0;
1586 }
1587 integrator.submit_value(value_result, q);
1588 }
1589
1590 integrator.integrate(EvaluationFlags::EvaluationFlags::values);
1591 }
1592 }
1593
1594 else if (this->boundary_conditions.type.at(integrator.boundary_id()) ==
1596 {
1597 integrator.evaluate(EvaluationFlags::values);
1598
1599 for (const auto q : integrator.quadrature_point_indices())
1600 {
1601 typename FEFaceIntegrator::value_type value_result = {};
1602
1603 const auto normal_vector = integrator.normal_vector(q);
1604
1605 auto value = integrator.get_value(q);
1606
1607 Tensor<1, dim, VectorizedArray<number>> velocity;
1608 if constexpr (assemble_residual)
1609 {
1610 for (int d = 0; d < dim; ++d)
1611 velocity[d] = value[d];
1612 }
1613 else
1614 {
1615 // Only use the previous velocity values for the Jacobian
1616 for (int d = 0; d < dim; ++d)
1618 }
1619
1620 // (u·n)_=min(0,u·n)
1621 VectorizedArray<number> normal_outflux = velocity * normal_vector;
1622
1623 normal_outflux =
1624 std::min(VectorizedArray<number>(0.0), normal_outflux);
1625
1626 // -(v,β(u·n)_·u)
1627 for (int d = 0; d < dim; ++d)
1628 value_result[d] -= penalty_parameter * normal_outflux * value[d];
1629
1630 integrator.submit_value(value_result, q);
1631 }
1632
1633 integrator.integrate(EvaluationFlags::EvaluationFlags::values);
1634 }
1635
1636 else if (this->boundary_conditions.type.at(integrator.boundary_id()) ==
1638 {
1639 integrator.evaluate(EvaluationFlags::EvaluationFlags::values |
1640 EvaluationFlags::EvaluationFlags::gradients);
1641
1642 for (const auto q : integrator.quadrature_point_indices())
1643 {
1644 typename FEFaceIntegrator::value_type value_result = {};
1645
1646 const auto normal_vector = integrator.normal_vector(q);
1647 auto gradient = integrator.get_gradient(q);
1648
1649 for (int d = 0; d < dim; ++d)
1650 {
1651 // We are assembling the residual, so we need to impose the
1652 // target pressure
1653 if constexpr (assemble_residual)
1654 {
1655 // Assemble ν(v,-∇δu·n - p n )
1656 for (int i = 0; i < dim; ++i)
1657 value_result[d] +=
1658 kinematic_viscosity * gradient[d][i] * normal_vector[i];
1659
1660 value_result[d] += this->face_target_pressure[face_index][q] *
1661 normal_vector[d];
1662 }
1663 // We are just assembling the matrix, the face target pressure
1664 // is not part of the assembly process.
1665 else
1666 {
1667 // Assemble ν(v,-∇δu·n )
1668 for (int i = 0; i < dim; ++i)
1669 value_result[d] -=
1670 kinematic_viscosity * gradient[d][i] * normal_vector[i];
1671 }
1672 }
1673 integrator.submit_value(value_result, q);
1674 }
1675
1676 integrator.integrate(EvaluationFlags::EvaluationFlags::values);
1677 }
1678}
1679
1680
1681template <int dim, typename number>
1682IndexSet
1684 const MatrixFree<dim, number> &matrix_free)
1685{
1686 const unsigned int level = matrix_free.get_mg_level();
1687
1688 std::vector<IndexSet> refinement_edge_indices;
1689 refinement_edge_indices.clear();
1690 const unsigned int nlevels =
1691 matrix_free.get_dof_handler().get_triangulation().n_global_levels();
1692 refinement_edge_indices.resize(nlevels);
1693 for (unsigned int l = 0; l < nlevels; l++)
1694 refinement_edge_indices[l] =
1695 IndexSet(matrix_free.get_dof_handler().n_dofs(l));
1696
1697 MGTools::extract_inner_interface_dofs(matrix_free.get_dof_handler(),
1698 refinement_edge_indices);
1699 return refinement_edge_indices[level];
1700}
1701
1706
1707template <int dim, typename number>
1709 default;
1710
1711/**
1712 * The expressions calculated in this cell integral are:
1713 * (q,∇δu) + (v,∂t δu) + (v,(u_adv·∇)δu) + (v,(δu·∇)u) - (∇·v,δp) + ν(∇v,∇δu)
1714 * (Weak form Jacobian), plus three additional terms in the case of SUPG-PSPG
1715 * stabilization:
1716 * \+ (∂t δu +(u_adv·∇)δu + (δu·∇)u + ∇δp - ν∆δu)τ·∇q (PSPG Jacobian)
1717 * \+ (∂t δu +(u_adv·∇)δu + (δu·∇)u + ∇δp - ν∆δu)τu_adv·∇v (SUPG Jacobian Part
1718 * 1)
1719 * \+ (∂t u +(u_adv·∇)u + ∇p - ν∆u - f )τδu·∇v (SUPG Jacobian Part 2),
1720 * plus two additional terms in the case of full gls stabilization:
1721 * \+ (∂t δu +(u_adv·∇)δu + (δu·∇)u + ∇δp - ν∆δu)τ(−ν∆v) (GLS Jacobian)
1722 * \+ (∇·δu)τ'(∇·v) (LSIC Jacobian).
1723 * The advective velocity u_adv is the same as the velocity u unless an ALE
1724 * simulation is performed. In this case, u_adv = u - u_ALE, and u_ALE is
1725 * previously subtracted from u_adv at the function
1726 * evaluate_non_linear_term_and_calculate_tau().
1727 */
1728template <int dim, typename number>
1729void
1731 FECellIntegrator &integrator) const
1732{
1733 if (this->enable_hessians_jacobian)
1734 integrator.evaluate(EvaluationFlags::values | EvaluationFlags::gradients |
1735 EvaluationFlags::hessians);
1736 else
1737 integrator.evaluate(EvaluationFlags::values | EvaluationFlags::gradients);
1738
1739 const unsigned int cell = integrator.get_current_cell_index();
1740
1741 // Solid-cell mask (1.0 for fluid lanes, 0.0 for solid lanes). Suppresses
1742 // contributions from solid cells, mirroring the matrix-based behavior
1743 // where solid cells are skipped during assembly.
1744 VectorizedArray<number> cell_mask(1.0);
1745 if (this->has_solids)
1746 {
1747 AssertIndexRange(cell, this->solid_cell_mask.size());
1748 cell_mask = this->solid_cell_mask[cell];
1749 }
1750
1751 // Time stepping data information structure.
1752 // We create a small helper structure that contains everything related to
1753 // the time-stepping process and carries out all the flag checking.
1754 const TimeSteppingData time_stepping_data =
1756
1757 const double a_ii = time_stepping_data.a_ii;
1758 const double dt = time_stepping_data.dt;
1759 const bool is_bdf = time_stepping_data.is_bdf;
1760 const bool is_sdirk = time_stepping_data.is_sdirk;
1761 const bool transient = time_stepping_data.is_transient;
1762 const Vector<double> *bdf_coefficients = time_stepping_data.bdf_coefficients;
1763
1764 const double kinematic_viscosity =
1765 this->properties_manager->get_rheology()->get_kinematic_viscosity();
1766
1767 for (const auto q : integrator.quadrature_point_indices())
1768 {
1769 Tensor<1, dim, VectorizedArray<number>> source_value;
1770
1771 // Evaluate source term function if enabled
1772 if (!this->thermal_buoyancy_term.empty())
1773 source_value = this->thermal_buoyancy_term(cell, q);
1774 else if (this->forcing_function)
1775 source_value = this->forcing_terms(cell, q);
1776
1777 // Add to source term the dynamic flow control force (zero if not
1778 // enabled)
1779 source_value += this->beta_force;
1780
1781 // Gather the original value/gradient
1782 typename FECellIntegrator::value_type value = integrator.get_value(q);
1783 typename FECellIntegrator::gradient_type gradient =
1784 integrator.get_gradient(q);
1785 typename FECellIntegrator::gradient_type hessian_diagonal;
1786
1787 if (this->enable_hessians_jacobian)
1788 hessian_diagonal = integrator.get_hessian_diagonal(q);
1789
1790 // Result value/gradient we will use
1791 typename FECellIntegrator::value_type value_result;
1792 typename FECellIntegrator::gradient_type gradient_result;
1793 typename FECellIntegrator::hessian_type hessian_result;
1794
1795 // Gather previous values of the velocity and the pressure
1796 auto previous_values = this->nonlinear_previous_values(cell, q);
1797 auto previous_gradient = this->nonlinear_previous_gradient(cell, q);
1798 auto previous_hessian_diagonal =
1800 auto previous_advective_values =
1802
1803 Tensor<1, dim + 1, VectorizedArray<number>> previous_time_derivatives;
1804 if (transient)
1805 previous_time_derivatives =
1807
1808 // Get stabilization parameter
1809 const auto tau = this->stabilization_parameter[cell][q];
1810 const auto tau_lsic = this->stabilization_parameter_lsic[cell][q];
1811
1812 // Weak form Jacobian
1813 for (int i = 0; i < dim; ++i)
1814 {
1815 // ν(∇v,∇δu)
1816 gradient_result[i] = kinematic_viscosity * gradient[i];
1817 // -(∇·v,δp)
1818 gradient_result[i][i] += -value[dim];
1819 // +(q,∇δu)
1820 value_result[dim] += gradient[i][i];
1821
1822 for (int k = 0; k < dim; ++k)
1823 {
1824 // +(v,(u_adv·∇)δu + (δu·∇)u)
1825 value_result[i] += gradient[i][k] * previous_advective_values[k] +
1826 previous_gradient[i][k] * value[k];
1827 }
1828 // +(v,∂t δu)
1829 if (is_bdf)
1830 value_result[i] += (*bdf_coefficients)[0] * value[i];
1831 if (is_sdirk)
1832 {
1833 value_result[i] += (1.0 / (dt * a_ii)) * value[i];
1834 }
1835 }
1836
1837 // PSPG Jacobian
1838 for (int i = 0; i < dim; ++i)
1839 {
1840 for (int k = 0; k < dim; ++k)
1841 {
1842 // (-ν∆δu + (u_adv·∇)δu + (δu·∇)u)·τ∇q
1843 gradient_result[dim][i] +=
1844 tau * (-kinematic_viscosity * hessian_diagonal[i][k] +
1845 gradient[i][k] * previous_advective_values[k] +
1846 previous_gradient[i][k] * value[k]);
1847 }
1848 // +(∂t δu)·τ∇q
1849 if (is_bdf)
1850 gradient_result[dim][i] += tau * (*bdf_coefficients)[0] * value[i];
1851
1852 if (is_sdirk)
1853 gradient_result[dim][i] += tau * (1.0 / (dt * a_ii)) * value[i];
1854 }
1855 // (∇δp)τ·∇q
1856 gradient_result[dim] += tau * gradient[dim];
1857
1858 // SUPG Jacobian
1859 for (int i = 0; i < dim; ++i)
1860 {
1861 for (int k = 0; k < dim; ++k)
1862 {
1863 // Part 1
1864 for (int l = 0; l < dim; ++l)
1865 {
1866 // +((u_adv·∇)δu + (δu·∇)u - ν∆δu)τ(u_adv·∇)v
1867 gradient_result[i][k] +=
1868 tau * previous_advective_values[k] *
1869 (gradient[i][l] * previous_advective_values[l] +
1870 previous_gradient[i][l] * value[l] -
1871 kinematic_viscosity * hessian_diagonal[i][l]);
1872 }
1873 // +(∇δp)τ(u_adv·∇)v
1874 gradient_result[i][k] +=
1875 tau * previous_advective_values[k] * (gradient[dim][i]);
1876
1877 // +(∂t δu)τ(u_adv·∇)v
1878 if (is_bdf)
1879 gradient_result[i][k] += tau * previous_advective_values[k] *
1880 ((*bdf_coefficients)[0] * value[i]);
1881
1882 if (is_sdirk)
1883 {
1884 gradient_result[i][k] += tau * previous_advective_values[k] *
1885 ((1.0 / (dt * a_ii)) * value[i]);
1886 }
1887
1888 // Part 2
1889 for (int l = 0; l < dim; ++l)
1890 {
1891 // +((u·∇)u - ν∆u)τ(δu·∇)v
1892 gradient_result[i][k] +=
1893 tau * value[k] *
1894 (previous_gradient[i][l] * previous_advective_values[l] -
1895 kinematic_viscosity * previous_hessian_diagonal[i][l]);
1896 }
1897 // +(∇p - f)τ(δu·∇)v
1898 gradient_result[i][k] +=
1899 tau * value[k] * (previous_gradient[dim][i] - source_value[i]);
1900
1901 // +(∂t u)τ(δu·∇)v
1902 if (is_bdf)
1903 gradient_result[i][k] +=
1904 tau * value[k] *
1905 ((*bdf_coefficients)[0] * previous_values[i] +
1906 previous_time_derivatives[i]);
1907 if (is_sdirk)
1908 {
1909 gradient_result[i][k] +=
1910 tau * value[k] *
1911 ((1.0 / (dt * a_ii)) * previous_values[i] +
1912 previous_time_derivatives[i]);
1913 }
1914 }
1915 }
1916
1917 if (this->stabilization ==
1919 {
1920 // GLS Jacobian
1921 for (int i = 0; i < dim; ++i)
1922 {
1923 for (int k = 0; k < dim; ++k)
1924 {
1925 if (this->enable_hessians_jacobian)
1926 {
1927 for (int l = 0; l < dim; ++l)
1928 {
1929 // +((u_adv·∇)δu + (δu·∇)u - ν∆δu)τ(−ν∆v)
1930 hessian_result[i][k][k] +=
1931 tau * -kinematic_viscosity *
1932 (gradient[i][l] * previous_advective_values[l] +
1933 previous_gradient[i][l] * value[l] -
1934 kinematic_viscosity * hessian_diagonal[i][l]);
1935 }
1936
1937 // +(∇δp)τ(−ν∆v)
1938 hessian_result[i][k][k] +=
1939 tau * -kinematic_viscosity * (gradient[dim][i]);
1940
1941 // +(∂t δu)τ(−ν∆v)
1942 if (is_bdf)
1943 hessian_result[i][k][k] +=
1944 tau * -kinematic_viscosity *
1945 ((*bdf_coefficients)[0] * value[i]);
1946 if (is_sdirk)
1947 {
1948 hessian_result[i][k][k] +=
1949 tau * -kinematic_viscosity *
1950 ((1.0 / (dt * a_ii)) * value[i]);
1951 }
1952 }
1953
1954 // LSIC term
1955 // (∇·δu)τ'(∇·v)
1956 gradient_result[i][i] += tau_lsic * gradient[k][k];
1957 }
1958 }
1959 }
1960
1961 if (this->has_solids)
1962 {
1963 gradient_result = gradient_result * cell_mask;
1964 value_result = value_result * cell_mask;
1965 if (this->enable_hessians_jacobian)
1966 hessian_result = hessian_result * cell_mask;
1967 }
1968
1969 integrator.submit_gradient(gradient_result, q);
1970 integrator.submit_value(value_result, q);
1971
1972 if (this->enable_hessians_jacobian)
1973 integrator.submit_hessian(hessian_result, q);
1974 }
1975
1976 if (this->enable_hessians_jacobian)
1977 integrator.integrate(EvaluationFlags::values | EvaluationFlags::gradients |
1978 EvaluationFlags::hessians);
1979 else
1980 integrator.integrate(EvaluationFlags::values | EvaluationFlags::gradients);
1981}
1982
1983/**
1984 * The expressions calculated in this cell integral are:
1985 * (q, ∇·u) + (v,∂t u) + (v,(u_adv·∇)u) - (∇·v,p) + ν(∇v,∇u) - (v,f) (Weak
1986 * form), plus two additional terms in the case of SUPG-PSPG stabilization:
1987 * \+ (∂t u +(u_adv·∇)u + ∇p - ν∆u - f)τ∇·q (PSPG term)
1988 * \+ (∂t u +(u_adv·∇)u + ∇p - ν∆u - f)τu_adv·∇v (SUPG term),
1989 * plus two additional terms in the case of full gls stabilization:
1990 * \+ (∂t u +(u_adv·∇)u + ∇p - ν∆u - f)τ(−ν∆v) (GLS term)
1991 * \+ (∇·u)τ'(∇·v) (LSIC term).
1992 * The advective velocity u_adv is the same as the velocity u unless an ALE
1993 * simulation is performed. In this case, u_adv = u - u_ALE, and u_ALE is
1994 * previously subtracted from u_adv at the function
1995 * evaluate_non_linear_term_and_calculate_tau().
1996 */
1997template <int dim, typename number>
1998void
2000 const MatrixFree<dim, number> &matrix_free,
2001 VectorType &dst,
2002 const VectorType &src,
2003 const std::pair<unsigned int, unsigned int> &range) const
2004{
2005 FECellIntegrator integrator(matrix_free);
2006
2007 const double kinematic_viscosity =
2008 this->properties_manager->get_rheology()->get_kinematic_viscosity();
2009
2010 for (unsigned int cell = range.first; cell < range.second; ++cell)
2011 {
2012 integrator.reinit(cell);
2013 integrator.read_dof_values_plain(src);
2014
2015 if (this->enable_hessians_residual)
2016 integrator.evaluate(EvaluationFlags::values |
2017 EvaluationFlags::gradients |
2018 EvaluationFlags::hessians);
2019 else
2020 integrator.evaluate(EvaluationFlags::values |
2021 EvaluationFlags::gradients);
2022
2023 // Solid-cell mask (1.0 for fluid lanes, 0.0 for solid lanes).
2024 VectorizedArray<number> cell_mask(1.0);
2025 if (this->has_solids)
2026 {
2027 AssertIndexRange(cell, this->solid_cell_mask.size());
2028 cell_mask = this->solid_cell_mask[cell];
2029 }
2030
2031 // Time stepping data information structure.
2032 // We create a small helper structure that contains everything related to
2033 // the time-stepping process and carries out all the flag checking.
2034 const TimeSteppingData time_stepping_data =
2036
2037 const double a_ii = time_stepping_data.a_ii;
2038 const double dt = time_stepping_data.dt;
2039 const bool is_bdf = time_stepping_data.is_bdf;
2040 const bool is_sdirk = time_stepping_data.is_sdirk;
2041 const bool transient = time_stepping_data.is_transient;
2042 const Vector<double> *bdf_coefficients =
2043 time_stepping_data.bdf_coefficients;
2044
2045 for (const auto q : integrator.quadrature_point_indices())
2046 {
2047 Tensor<1, dim, VectorizedArray<number>> source_value;
2048
2049 // Evaluate source term function if enabled
2050 if (!this->thermal_buoyancy_term.empty())
2051 source_value = this->thermal_buoyancy_term(cell, q);
2052 else if (this->forcing_function)
2053 source_value = this->forcing_terms(cell, q);
2054
2055 // Add to source term the dynamic flow control force (zero if not
2056 // enabled)
2057 source_value += this->beta_force;
2058
2059 // Gather the original value/gradient
2060 typename FECellIntegrator::value_type value = integrator.get_value(q);
2061 typename FECellIntegrator::gradient_type gradient =
2062 integrator.get_gradient(q);
2063 typename FECellIntegrator::gradient_type hessian_diagonal;
2064 const auto advective_value =
2066
2067 if (this->enable_hessians_residual)
2068 hessian_diagonal = integrator.get_hessian_diagonal(q);
2069
2070 // Time derivatives of previous solutions
2071 Tensor<1, dim + 1, VectorizedArray<number>> previous_time_derivatives;
2072 if (transient)
2073 previous_time_derivatives =
2075
2076 // Get stabilization parameter
2077 const auto tau = this->stabilization_parameter[cell][q];
2078 const auto tau_lsic = this->stabilization_parameter_lsic[cell][q];
2079
2080 // Result value/gradient we will use
2081 typename FECellIntegrator::value_type value_result;
2082 typename FECellIntegrator::gradient_type gradient_result;
2083 typename FECellIntegrator::hessian_type hessian_result;
2084
2085 // Weak form
2086 for (int i = 0; i < dim; ++i)
2087 {
2088 // ν(∇v,∇u)
2089 gradient_result[i] = kinematic_viscosity * gradient[i];
2090 // -(∇·v,p)
2091 gradient_result[i][i] += -value[dim];
2092 // +(v,-f)
2093 value_result[i] = -source_value[i];
2094
2095 // +(v,∂t u)
2096 if (is_bdf)
2097 value_result[i] += (*bdf_coefficients)[0] * value[i] +
2098 previous_time_derivatives[i];
2099 if (is_sdirk)
2100 {
2101 value_result[i] += (1.0 / (dt * a_ii)) * value[i] +
2102 previous_time_derivatives[i];
2103 }
2104
2105 // +(q,∇·u)
2106 value_result[dim] += gradient[i][i];
2107 for (int k = 0; k < dim; ++k)
2108 {
2109 // +(v,(u·∇)u)
2110 value_result[i] += gradient[i][k] * advective_value[k];
2111 }
2112 }
2113
2114 // PSPG term
2115 for (int i = 0; i < dim; ++i)
2116 {
2117 for (int k = 0; k < dim; ++k)
2118 {
2119 // (-ν∆u + (u_adv·∇)u)·τ∇q
2120 gradient_result[dim][i] +=
2121 tau * (-kinematic_viscosity * hessian_diagonal[i][k] +
2122 gradient[i][k] * advective_value[k]);
2123 }
2124 // +(-f)·τ∇q
2125 gradient_result[dim][i] += tau * (-source_value[i]);
2126
2127 // +(∂t u)·τ∇q
2128 if (is_bdf)
2129 gradient_result[dim][i] +=
2130 tau * ((*bdf_coefficients)[0] * value[i] +
2131 previous_time_derivatives[i]);
2132 if (is_sdirk)
2133 gradient_result[dim][i] +=
2134 tau * ((1.0 / (dt * a_ii)) * value[i] +
2135 previous_time_derivatives[i]);
2136 }
2137 // +(∇p)τ∇·q
2138 gradient_result[dim] += tau * gradient[dim];
2139
2140 // SUPG term
2141 for (int i = 0; i < dim; ++i)
2142 {
2143 for (int k = 0; k < dim; ++k)
2144 {
2145 for (int l = 0; l < dim; ++l)
2146 {
2147 // (-ν∆u)τ(u_adv·∇)v
2148 gradient_result[i][k] += -tau * kinematic_viscosity *
2149 advective_value[k] *
2150 hessian_diagonal[i][l];
2151
2152 // + ((u_adv·∇)u)τ(u_adv·∇)v
2153 gradient_result[i][k] += tau * advective_value[k] *
2154 gradient[i][l] *
2155 advective_value[l];
2156 }
2157 // + (∇p - f)τ(u_adv·∇)v
2158 gradient_result[i][k] += tau * advective_value[k] *
2159 (gradient[dim][i] - source_value[i]);
2160
2161 // + (∂t u)τ(u_adv·∇)v
2162 if (is_bdf)
2163 gradient_result[i][k] +=
2164 tau * advective_value[k] *
2165 ((*bdf_coefficients)[0] * value[i] +
2166 previous_time_derivatives[i]);
2167
2168 if (is_sdirk)
2169 gradient_result[i][k] += tau * advective_value[k] *
2170 ((1.0 / (dt * a_ii)) * value[i] +
2171 previous_time_derivatives[i]);
2172 }
2173 }
2174
2175 if (this->stabilization ==
2177 {
2178 // GLS term
2179 for (int i = 0; i < dim; ++i)
2180 {
2181 for (int k = 0; k < dim; ++k)
2182 {
2183 if (this->enable_hessians_residual)
2184 {
2185 for (int l = 0; l < dim; ++l)
2186 {
2187 // (-ν∆u + (u_adv·∇)u)τ(−ν∆v)
2188 hessian_result[i][k][k] +=
2189 tau * -kinematic_viscosity *
2190 (-kinematic_viscosity * hessian_diagonal[i][l] +
2191 gradient[i][l] * advective_value[l]);
2192 }
2193 // + (∇p - f)τ(−ν∆v)
2194 hessian_result[i][k][k] +=
2195 tau * -kinematic_viscosity *
2196 (gradient[dim][i] - source_value[i]);
2197
2198 // + (∂t u)τ(−ν∆v)
2199 if (is_bdf)
2200 hessian_result[i][k][k] +=
2201 tau * -kinematic_viscosity *
2202 ((*bdf_coefficients)[0] * value[i] +
2203 previous_time_derivatives[i]);
2204
2205 if (is_sdirk)
2206 hessian_result[i][k][k] +=
2207 tau * -kinematic_viscosity *
2208 ((1.0 / (dt * a_ii)) * value[i] +
2209 previous_time_derivatives[i]);
2210 }
2211
2212 // LSIC term
2213 // (∇·u)τ'(∇·v)
2214 gradient_result[i][i] += tau_lsic * gradient[k][k];
2215 }
2216 }
2217 }
2218
2219 if (this->has_solids)
2220 {
2221 gradient_result = gradient_result * cell_mask;
2222 value_result = value_result * cell_mask;
2223 if (this->enable_hessians_residual)
2224 hessian_result = hessian_result * cell_mask;
2225 }
2226
2227 integrator.submit_gradient(gradient_result, q);
2228 integrator.submit_value(value_result, q);
2229 if (this->enable_hessians_residual)
2230 integrator.submit_hessian(hessian_result, q);
2231 }
2232
2233 if (this->enable_hessians_residual)
2234 integrator.integrate_scatter(EvaluationFlags::values |
2235 EvaluationFlags::gradients |
2236 EvaluationFlags::hessians,
2237 dst);
2238 else
2239 integrator.integrate_scatter(EvaluationFlags::values |
2240 EvaluationFlags::gradients,
2241 dst);
2242 }
2243}
2244
2249
2250
2251template <int dim, typename number>
2254
2255/**
2256 * The expressions calculated in this cell integral are:
2257 * (q,∇δu) + (v,∂t δu) + (v,(u_adv·∇)δu) + (v,(δu·∇)u) - (∇·v,δp) + ν(∇v,(∇δu +
2258 * ∇δuT)) + (∇v, 0.5/γ_dot (∂ν/∂γ_dot)(∇u + ∇uT)(∇δu + ∇δuT)(∇u + ∇uT)) (Weak
2259 * form Jacobian), plus three additional terms in the case of SUPG-PSPG
2260 * stabilization:
2261 * \+ (∂t δu +(u_adv·∇)δu + (δu·∇)u + ∇δp - ν∆δu - (∇ν)(∇δu + ∇δuT))τ·∇q (PSPG
2262 * Jacobian)
2263 * \+ (∂t δu +(u_adv·∇)δu + (δu·∇)u + ∇δp - ν∆δu - (∇ν)(∇δu + ∇δuT))τu_adv·∇v
2264 * (SUPG Jacobian Part 1)
2265 * \+ (∂t u +(u_adv·∇)u + ∇p - ν∆u - (∇ν)((∇u + ∇uT) - f )τδu_adv·∇v (SUPG
2266 * Jacobian Part 2).
2267 * The advective velocity u_adv is the same as the velocity u unless an ALE
2268 * simulation is performed. In this case, u_adv = u - u_ALE, and u_ALE is
2269 * previously subtracted from u_adv at the function
2270 * evaluate_non_linear_term_and_calculate_tau().
2271 */
2272template <int dim, typename number>
2273void
2275 FECellIntegrator &integrator) const
2276{
2277 if (this->enable_hessians_jacobian)
2278 integrator.evaluate(EvaluationFlags::values | EvaluationFlags::gradients |
2279 EvaluationFlags::hessians);
2280 else
2281 integrator.evaluate(EvaluationFlags::values | EvaluationFlags::gradients);
2282
2283 const unsigned int cell = integrator.get_current_cell_index();
2284
2285 // Solid-cell mask (1.0 for fluid lanes, 0.0 for solid lanes).
2286 VectorizedArray<number> cell_mask(1.0);
2287 if (this->has_solids)
2288 {
2289 AssertIndexRange(cell, this->solid_cell_mask.size());
2290 cell_mask = this->solid_cell_mask[cell];
2291 }
2292
2293 // Time stepping data information structure.
2294 // We create a small helper structure that contains everything related to
2295 // the time-stepping process and carries out all the flag checking.
2296 const TimeSteppingData time_stepping_data =
2298
2299 const double a_ii = time_stepping_data.a_ii;
2300 const double dt = time_stepping_data.dt;
2301 const bool is_bdf = time_stepping_data.is_bdf;
2302 const bool is_sdirk = time_stepping_data.is_sdirk;
2303 const bool transient = time_stepping_data.is_transient;
2304 const Vector<double> *bdf_coefficients = time_stepping_data.bdf_coefficients;
2305
2306 for (const auto q : integrator.quadrature_point_indices())
2307 {
2308 Tensor<1, dim, VectorizedArray<number>> source_value;
2309
2310 // Evaluate source term function if enabled
2311 if (this->forcing_function)
2312 source_value = this->forcing_terms(cell, q);
2313
2314 // Add to source term the dynamic flow control force (zero if not
2315 // enabled)
2316 source_value += this->beta_force;
2317
2318 // Gather the original value/gradient
2319 typename FECellIntegrator::value_type value = integrator.get_value(q);
2320 typename FECellIntegrator::gradient_type gradient =
2321 integrator.get_gradient(q);
2322 typename FECellIntegrator::gradient_type hessian_diagonal;
2323
2324 if (this->enable_hessians_jacobian)
2325 hessian_diagonal = integrator.get_hessian_diagonal(q);
2326
2327 // Result value/gradient we will use
2328 typename FECellIntegrator::value_type value_result;
2329 typename FECellIntegrator::gradient_type gradient_result;
2330 typename FECellIntegrator::hessian_type hessian_result;
2331
2332 // Gather previous values of the velocity and the pressure
2333 auto previous_values = this->nonlinear_previous_values(cell, q);
2334 auto previous_gradient = this->nonlinear_previous_gradient(cell, q);
2335 auto previous_hessian_diagonal =
2337 auto previous_advective_values =
2339
2340 Tensor<1, dim + 1, VectorizedArray<number>> previous_time_derivatives;
2341 if (transient)
2342 previous_time_derivatives =
2344
2345 // Gather previous values of the shear_rate and shear_rate_magnitude
2346 auto previous_shear_rate = this->previous_shear_rate(cell, q);
2348 this->previous_shear_rate_magnitude(cell, q);
2349
2351 std::max(previous_shear_rate_magnitude, VectorizedArray<number>(1e-3));
2352
2353 // Get kinematic viscosity from rheology model
2354 const auto kinematic_viscosity =
2355 this->kinematic_viscosity_vector[cell][q];
2356 const auto kinematic_viscosity_gradient =
2357 this->kinematic_viscosity_gradient[cell][q];
2360
2361 // Get stabilization parameter
2362 const auto tau = this->stabilization_parameter[cell][q];
2363
2364 // Calculate shear rate per component
2365 typename FECellIntegrator::gradient_type shear_rate;
2366 for (int i = 0; i < dim; ++i)
2367 {
2368 for (int j = 0; j < dim; ++j)
2369 {
2370 shear_rate[i][j] = gradient[i][j] + gradient[j][i];
2371 }
2372 }
2373
2374 // Precompute double contraction between shear rate and previous shear
2375 // rate
2376 VectorizedArray<number> shear_rate_previous_product =
2377 VectorizedArray<number>(0.);
2378
2379 for (int i = 0; i < dim; ++i)
2380 {
2381 for (int k = 0; k < dim; ++k)
2382 {
2383 shear_rate_previous_product +=
2384 shear_rate[i][k] * previous_shear_rate[k][i];
2385 }
2386 }
2387
2388 // Weak form Jacobian
2389 value_result[dim] = VectorizedArray<number>(0.);
2390 for (int i = 0; i < dim; ++i)
2391 {
2392 // -(∇·v,δp)
2393 gradient_result[i][i] = -value[dim];
2394 // +(q,∇δu)
2395 value_result[dim] += gradient[i][i];
2396 // ν(∇v,(∇δu + ∇δuT))
2397 gradient_result[i] += kinematic_viscosity * shear_rate[i];
2398 for (int k = 0; k < dim; ++k)
2399 {
2400 // (∇v, 0.5/γ_dot (∂ν/∂γ_dot)(∇u + ∇uT)(∇δu + ∇δuT)(∇u + ∇uT))
2401 gradient_result[i][k] += 0.5 / previous_shear_rate_magnitude *
2403 shear_rate_previous_product *
2404 previous_shear_rate[i][k];
2405 // +(v,(u_adv·∇)δu + (δu·∇)u)
2406 value_result[i] += gradient[i][k] * previous_advective_values[k] +
2407 previous_gradient[i][k] * value[k];
2408 }
2409 // +(v,∂t δu)
2410 if (is_bdf)
2411 value_result[i] += (*bdf_coefficients)[0] * value[i];
2412 if (is_sdirk)
2413 {
2414 value_result[i] += (1.0 / (dt * a_ii)) * value[i];
2415 }
2416 }
2417
2418 // PSPG Jacobian
2419 for (int i = 0; i < dim; ++i)
2420 {
2421 for (int k = 0; k < dim; ++k)
2422 {
2423 // (-ν∆δu - (∇ν)(∇δu + ∇δuT) + (u_adv·∇)δu + (δu·∇)u)·τ∇q
2424 gradient_result[dim][i] +=
2425 tau * (-kinematic_viscosity * hessian_diagonal[i][k] -
2427 gradient[i][k] * previous_advective_values[k] +
2428 previous_gradient[i][k] * value[k]);
2429 }
2430 // +(∂t δu)·τ∇q
2431 if (is_bdf)
2432 gradient_result[dim][i] += tau * (*bdf_coefficients)[0] * value[i];
2433 if (is_sdirk)
2434 gradient_result[dim][i] += tau * (1.0 / (dt * a_ii)) * value[i];
2435 }
2436 // (∇δp)τ·∇q
2437 gradient_result[dim] += tau * gradient[dim];
2438
2439 // SUPG Jacobian
2440 for (int i = 0; i < dim; ++i)
2441 {
2442 for (int k = 0; k < dim; ++k)
2443 {
2444 // Part 1
2445 for (int l = 0; l < dim; ++l)
2446 {
2447 // +((u_adv·∇)δu + (δu·∇)u - ν∆δu - (∇ν)(∇δu +
2448 // ∇δuT))τ(u_adv·∇)v
2449 gradient_result[i][k] +=
2450 tau * previous_advective_values[k] *
2451 (gradient[i][l] * previous_advective_values[l] +
2452 previous_gradient[i][l] * value[l] -
2453 kinematic_viscosity * hessian_diagonal[i][l] -
2455 }
2456 // +(∇δp)τ(u_adv·∇)v
2457 gradient_result[i][k] +=
2458 tau * previous_advective_values[k] * (gradient[dim][i]);
2459
2460 // +(∂t δu)τ(u_adv·∇)v
2461 if (is_bdf)
2462 gradient_result[i][k] += tau * previous_advective_values[k] *
2463 ((*bdf_coefficients)[0] * value[i]);
2464
2465 if (is_sdirk)
2466 gradient_result[i][k] += tau * previous_advective_values[k] *
2467 ((1.0 / (dt * a_ii)) * value[i]);
2468
2469
2470 // Part 2
2471 for (int l = 0; l < dim; ++l)
2472 {
2473 // +((u_adv·∇)u - ν∆u - (∇ν)((∇u + ∇uT))τ(δu·∇)v
2474 gradient_result[i][k] +=
2475 tau * value[k] *
2476 (previous_gradient[i][l] * previous_advective_values[l] -
2477 kinematic_viscosity * previous_hessian_diagonal[i][l] -
2479 previous_shear_rate[i][l]);
2480 }
2481 // +(∇p - f)τ(δu·∇)v
2482 gradient_result[i][k] +=
2483 tau * value[k] * (previous_gradient[dim][i] - source_value[i]);
2484
2485 // +(∂t u)τ(δu·∇)v
2486 if (is_bdf)
2487 gradient_result[i][k] +=
2488 tau * value[k] *
2489 ((*bdf_coefficients)[0] * previous_values[i] +
2490 previous_time_derivatives[i]);
2491 if (is_sdirk)
2492 gradient_result[i][k] +=
2493 tau * value[k] *
2494 ((1.0 / (dt * a_ii)) * previous_values[i] +
2495 previous_time_derivatives[i]);
2496 }
2497 }
2498
2499 if (this->has_solids)
2500 {
2501 gradient_result = gradient_result * cell_mask;
2502 value_result = value_result * cell_mask;
2503 if (this->enable_hessians_jacobian)
2504 hessian_result = hessian_result * cell_mask;
2505 }
2506
2507 integrator.submit_gradient(gradient_result, q);
2508 integrator.submit_value(value_result, q);
2509
2510 if (this->enable_hessians_jacobian)
2511 integrator.submit_hessian(hessian_result, q);
2512 }
2513
2514 if (this->enable_hessians_jacobian)
2515 integrator.integrate(EvaluationFlags::values | EvaluationFlags::gradients |
2516 EvaluationFlags::hessians);
2517 else
2518 integrator.integrate(EvaluationFlags::values | EvaluationFlags::gradients);
2519}
2520
2521/**
2522 * The expressions calculated in this cell integral are:
2523 * (q, ∇·u) + (v,∂t u) + (v,(u_adv·∇)u) - (∇·v,p) + ν(∇v,(∇u + ∇uT)) - (v,f)
2524 * (Weak form), plus two additional terms in the case of SUPG-PSPG
2525 * stabilization:
2526 * \+ (∂t u +(u_adv·∇)u + ∇p -ν∆u - (∇ν)((∇u + ∇uT) - f)τ∇·q (PSPG term)
2527 * \+ (∂t u +(u_adv·∇)u + ∇p -ν∆u - (∇ν)((∇u + ∇uT) - f)τu_adv·∇v (SUPG term).
2528 * The advective velocity u_adv is the same as the velocity u unless an ALE
2529 * simulation is performed. In this case, u_adv = u - u_ALE, and u_ALE is
2530 * previously subtracted from u_adv at the function
2531 * evaluate_non_linear_term_and_calculate_tau().
2532 */
2533template <int dim, typename number>
2534void
2537 const MatrixFree<dim, number> &matrix_free,
2538 VectorType &dst,
2539 const VectorType &src,
2540 const std::pair<unsigned int, unsigned int> &range) const
2541{
2542 FECellIntegrator integrator(matrix_free);
2543
2544 for (unsigned int cell = range.first; cell < range.second; ++cell)
2545 {
2546 integrator.reinit(cell);
2547 integrator.read_dof_values_plain(src);
2548
2549 if (this->enable_hessians_residual)
2550 integrator.evaluate(EvaluationFlags::values |
2551 EvaluationFlags::gradients |
2552 EvaluationFlags::hessians);
2553 else
2554 integrator.evaluate(EvaluationFlags::values |
2555 EvaluationFlags::gradients);
2556
2557 // Solid-cell mask (1.0 for fluid lanes, 0.0 for solid lanes).
2558 VectorizedArray<number> cell_mask(1.0);
2559 if (this->has_solids)
2560 {
2561 AssertIndexRange(cell, this->solid_cell_mask.size());
2562 cell_mask = this->solid_cell_mask[cell];
2563 }
2564
2565 // Time stepping data information structure.
2566 // We create a small helper structure that contains everything related to
2567 // the time-stepping process and carries out all the flag checking.
2568 const TimeSteppingData time_stepping_data =
2570
2571 const double a_ii = time_stepping_data.a_ii;
2572 const double dt = time_stepping_data.dt;
2573 const bool is_bdf = time_stepping_data.is_bdf;
2574 const bool is_sdirk = time_stepping_data.is_sdirk;
2575 const bool transient = time_stepping_data.is_transient;
2576 const Vector<double> *bdf_coefficients =
2577 time_stepping_data.bdf_coefficients;
2578
2579 for (const auto q : integrator.quadrature_point_indices())
2580 {
2581 Tensor<1, dim, VectorizedArray<number>> source_value;
2582
2583 // Evaluate source term function if enabled
2584 if (this->forcing_function)
2585 source_value = this->forcing_terms(cell, q);
2586
2587 // Add to source term the dynamic flow control force (zero if not
2588 // enabled)
2589 source_value += this->beta_force;
2590
2591 // Gather the original value/gradient
2592 typename FECellIntegrator::value_type value = integrator.get_value(q);
2593 typename FECellIntegrator::gradient_type gradient =
2594 integrator.get_gradient(q);
2595 typename FECellIntegrator::gradient_type hessian_diagonal;
2596 const auto advective_value =
2598
2599 if (this->enable_hessians_residual)
2600 hessian_diagonal = integrator.get_hessian_diagonal(q);
2601
2602 // Time derivatives of previous solutions
2603 Tensor<1, dim + 1, VectorizedArray<number>> previous_time_derivatives;
2604 if (transient)
2605 previous_time_derivatives =
2607
2608 // Get stabilization parameter
2609 const auto tau = this->stabilization_parameter[cell][q];
2610
2611 // Get kinematic viscosity from rheology model
2612 const auto kinematic_viscosity =
2613 this->kinematic_viscosity_vector[cell][q];
2614
2615 // Get kinematic viscosity gradient
2616 const auto kinematic_viscosity_gradient =
2617 this->kinematic_viscosity_gradient[cell][q];
2618
2619 // Result value/gradient we will use
2620 typename FECellIntegrator::value_type value_result;
2621 typename FECellIntegrator::gradient_type gradient_result;
2622 typename FECellIntegrator::hessian_type hessian_result;
2623
2624 // Additional values/gradients needed
2625 typename FECellIntegrator::gradient_type shear_rate;
2626
2627 // Calculate shear rate per component
2628 for (int i = 0; i < dim; ++i)
2629 {
2630 for (int j = 0; j < dim; ++j)
2631 {
2632 shear_rate[i][j] = gradient[i][j] + gradient[j][i];
2633 }
2634 }
2635
2636 // Weak form
2637 for (int i = 0; i < dim; ++i)
2638 {
2639 // ν(∇v,(∇u + ∇uT))
2640 gradient_result[i] = kinematic_viscosity * shear_rate[i];
2641 // -(∇·v,p)
2642 gradient_result[i][i] += -value[dim];
2643 // +(v,-f)
2644 value_result[i] = -source_value[i];
2645
2646 // +(v,∂t u)
2647 if (is_bdf)
2648 value_result[i] += (*bdf_coefficients)[0] * value[i] +
2649 previous_time_derivatives[i];
2650 if (is_sdirk)
2651 value_result[i] +=
2652 (1.0 / (dt * a_ii)) * value[i] + previous_time_derivatives[i];
2653
2654
2655 // +(q,∇·u)
2656 value_result[dim] += gradient[i][i];
2657
2658 for (int k = 0; k < dim; ++k)
2659 {
2660 // +(v,(u_adv·∇)u)
2661 value_result[i] += gradient[i][k] * advective_value[k];
2662 }
2663 }
2664
2665 // PSPG term
2666 for (int i = 0; i < dim; ++i)
2667 {
2668 for (int k = 0; k < dim; ++k)
2669 {
2670 // (-ν∆u - (∇ν)((∇u + ∇uT)) + (u_adv·∇)u)·τ∇q
2671 gradient_result[dim][i] +=
2672 tau * (-kinematic_viscosity * hessian_diagonal[i][k] -
2674 gradient[i][k] * advective_value[k]);
2675 }
2676 // +(-f)·τ∇q
2677 gradient_result[dim][i] += tau * (-source_value[i]);
2678
2679 // +(∂t u)·τ∇q
2680 if (is_bdf)
2681 gradient_result[dim][i] +=
2682 tau * ((*bdf_coefficients)[0] * value[i] +
2683 previous_time_derivatives[i]);
2684 if (is_sdirk)
2685 gradient_result[dim][i] +=
2686 tau * ((1.0 / (dt * a_ii)) * value[i] +
2687 previous_time_derivatives[i]);
2688 }
2689 // +(∇p)τ∇·q
2690 gradient_result[dim] += tau * gradient[dim];
2691
2692 // SUPG term
2693 for (int i = 0; i < dim; ++i)
2694 {
2695 for (int k = 0; k < dim; ++k)
2696 {
2697 for (int l = 0; l < dim; ++l)
2698 {
2699 // (-ν∆u - (∇ν)((∇u + ∇uT)))τ(u_adv·∇)v
2700 gradient_result[i][k] +=
2701 tau * advective_value[k] *
2702 (-kinematic_viscosity * hessian_diagonal[i][l] -
2704
2705 // + ((u_adv·∇)u)τ(u_adv·∇)v
2706 gradient_result[i][k] += tau * advective_value[k] *
2707 gradient[i][l] *
2708 advective_value[l];
2709 }
2710 // + (∇p - f)τ(u_adv·∇)v
2711 gradient_result[i][k] += tau * advective_value[k] *
2712 (gradient[dim][i] - source_value[i]);
2713
2714 // + (∂t u)τ(u_adv·∇)v
2715 if (is_bdf || is_sdirk)
2716 gradient_result[i][k] +=
2717 tau * advective_value[k] *
2718 ((*bdf_coefficients)[0] * value[i] +
2719 previous_time_derivatives[i]);
2720 }
2721 }
2722
2723 if (this->has_solids)
2724 {
2725 gradient_result = gradient_result * cell_mask;
2726 value_result = value_result * cell_mask;
2727 if (this->enable_hessians_residual)
2728 hessian_result = hessian_result * cell_mask;
2729 }
2730
2731 integrator.submit_gradient(gradient_result, q);
2732 integrator.submit_value(value_result, q);
2733 if (this->enable_hessians_residual)
2734 integrator.submit_hessian(hessian_result, q);
2735 }
2736
2737 if (this->enable_hessians_residual)
2738 integrator.integrate_scatter(EvaluationFlags::values |
2739 EvaluationFlags::gradients |
2740 EvaluationFlags::hessians,
2741 dst);
2742 else
2743 integrator.integrate_scatter(EvaluationFlags::values |
2744 EvaluationFlags::gradients,
2745 dst);
2746 }
2747}
2748
Vector< double > bdf_coefficients(const unsigned int p, const std::vector< double > &time_steps)
Definition bdf.cc:10
This class manages the boundary conditions forhe fluid dynamics solver It introduces the boundary fun...
Implements the matrix-free operator to solve steady/transient non-Newtonian Navier-Stokes equations u...
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 ...
LinearAlgebra::distributed::Vector< number > VectorType
A class that serves as base for all the matrix-free Navier-Stokes operators.
Table< 2, VectorizedArray< number > > face_target_pressure
Table with correct alignment for vectorization to store the values of the target pressure of a pressu...
Table< 2, Tensor< 1, dim+1, VectorizedArray< number > > > nonlinear_previous_advective_values
Table with correct alignment for vectorization to store the values of the velocity within the advecti...
Table< 2, Tensor< 1, dim, VectorizedArray< number > > > face_target_velocity
Table with correct alignment for vectorization to store the values of the target velocity of a weakly...
Table< 2, Tensor< 1, dim+1, Tensor< 1, dim, VectorizedArray< number > > > > nonlinear_previous_gradient
Table with correct alignment for vectorization to store the gradients of the previous newton step.
TrilinosWrappers::SparseMatrix system_matrix
Sparse trilinos matrix used when the matrix of certain level is computed and stored.
std::vector< unsigned int > constrained_indices
Vector with the constrained indices used for the local smoothing approach.
number el(unsigned int, unsigned int) const
Access a particular element in the matrix. Only required for compilation and it is not used.
Table< 2, bool > bool_dof_mask
DoF mask object needed for the sparsity pattern and computation of the system matrix of the coarse le...
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().
void do_boundary_face_integral_local(FEFaceIntegrator &integrator) const
Carry out the integration of boundary face integrals.
Table< 2, Tensor< 1, dim, VectorizedArray< number > > > forcing_terms
Table with precomputed forcing term values.
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...
bool has_edge_constrained_indices
Variable to identify whether there are edge constrained indices for the local smoothing approach.
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< number > > > velocity_ale
Table with correct alignment for vectorization to store the values of the ALE velocity used in mortar...
Table< 2, Tensor< 1, dim+1, VectorizedArray< number > > > nonlinear_previous_values
Table with correct alignment for vectorization to store the values of the previous newton step.
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
Object pointing to the physical properties manager of the matrix free class.
std::vector< unsigned int > edge_constrained_indices
Vector with the constrained edge indices for the local smoothing approach.
std::vector< std::pair< number, number > > constrained_values
Vector with the constrained values used for the local smoothing approach.
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< number > > > thermal_buoyancy_term
Table with precomputed thermal buoyancy term values.
bool enable_hessians_jacobian
Flag to turn hessian terms from jacobian on or off.
AffineConstraints< number > constraints
Object that stores constraints for the matrix free implementation.
bool enable_hessians_residual
Flag to turn hessian terms from residual on or off.
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...
unsigned int fe_degree
Finite element degree for the operator.
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_vector_partitioner() const
Get the vector partitioner object required for local smoothing multigrid preconditioner.
ConditionalOStream pcout
Conditional OStream for parallel output.
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
Boundary conditions object to impose the correct boundary conditions. This object is only used to imp...
void compute_element_size()
Compute the element size h of the cells required to calculate stabilization parameters.
Table< 2, VectorizedArray< number > > stabilization_parameter_lsic
Table with correct alignment for vectorization to store the values of the stabilization parameter tau...
Table< 1, VectorizedArray< number > > effective_beta_face
Table with correct alignment for vectorization to store the values of the face penalization term effe...
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< number > > > face_nonlinear_previous_values
Table with correct alignment for vectorization to store the values of the velocity at faces.
std::shared_ptr< Function< dim > > forcing_function
Force function or source function for the Navier-Stokes equations.
FEFaceEvaluation< dim, -1, 0, dim+1, number > FEFaceIntegrator
void evaluate_residual(VectorType &dst, const VectorType &src)
Evaluate right hand side using the matrix-free operator.
Table< 2, Tensor< 1, dim+1, VectorizedArray< number > > > prescribed_neumann_traction
Table with correct alignment for vectorization to store the values of the 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< number > > > > previous_shear_rate
Table with correct alignment for vectorization to store the values of the shear_rate.
AlignedVector< VectorizedArray< number > > element_size
Aligned vector to store the element size of all the elements.
std::vector< number > edge_constrained_values
Vector with edge constrained values used for the local smoothing approach.
Table< 2, Tensor< 1, dim+1, Tensor< 2, dim, VectorizedArray< number > > > > nonlinear_previous_hessian
Table with correct alignment for vectorization to store the hessian of the previous newton step.
AlignedVector< VectorizedArray< number > > solid_cell_mask
Per-cell-batch mask used to suppress contributions from solid cells (material_id > 0) inside the cell...
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< number > > > time_derivatives_previous_solutions
Table with correct alignment for vectorization to store the time derivatives of previous solutions.
FEEvaluation< dim, -1, 0, dim+1, number > 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 ...
std::vector< bool > edge_constrained_cell
Vector used to mark edge constrained cells in order to verify constrained indices for the local smoot...
bool enable_mortar
Flag to turn the computation of mortar coupling terms on or off.
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< number > > > kinematic_viscosity_gradient
Table with correct alignment for vectorization to store the values of the kinematic viscosity gradien...
TimerOutput timer
Timer for internal operator calls.
StabilizationType stabilization
Stabilization type needed to add or remove terms from operator.
std::shared_ptr< SimulationControl > simulation_control
Object storing the information regarding the time stepping method.
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.
bool has_solids
Flag indicating whether the simulation contains any solid region (material_id > 0)....
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< number > > > > nonlinear_previous_hessian_diagonal
Table with correct alignment for vectorization to store the hessian diagonal of the previous newton s...
bool enable_face_terms
Flag to turn the calculation of face terms on or off. This is used for weakly imposed Dirichlet bound...
Tensor< 1, dim, VectorizedArray< number > > beta_force
Additional source term in the case of dynamic flow control.
Table< 2, VectorizedArray< number > > grad_kinematic_viscosity_shear_rate
Table with correct alignment for vectorization to store the values of the gradient of the kinematic v...
Table< 2, VectorizedArray< number > > kinematic_viscosity_vector
Table with correct alignment for vectorization to store the values of the kinematic viscosity.
Table< 2, VectorizedArray< number > > stabilization_parameter
Table with correct alignment for vectorization to store the values of the stabilization parameter tau...
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...
DynamicSparsityPattern dsp
Sparsity pattern used when the matrix of certain level is computed and stored.
LinearAlgebra::distributed::Vector< number > 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< number > > previous_shear_rate_magnitude
Table with correct alignment for vectorization to store the values of the shear_rate_magnitude.
MatrixFree< dim, number > matrix_free
Object storing all the relevant data needed for the matrix free implementation.
Implements the matrix-free operator to solve steady/transient Navier-Stokes equations using stabiliza...
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,...
LinearAlgebra::distributed::Vector< number > VectorType
FEEvaluation< dim, -1, 0, dim+1, number > FECellIntegrator
std::vector< double > a_ij
double compute_cell_diameter(const double cell_measure, const unsigned int fe_degree)
Computes equivalent cell diameter by comparing the area to a disk (2D) or the volume to a sphere (3D)...
Definition utilities.h:989
const Table< 2, bool > create_bool_dof_mask(const FiniteElement< dim, spacedim > &fe, const Quadrature< dim > &quadrature)
Creates and fills a table that works as bool dof mask object needed for the sparsity pattern and comp...
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.
@ velocity
Velocity vector field from fluid dynamics.
Tensor< 1, dim > angular_to_linear_velocity(const double omega, const Tensor< 1, dim > &point, const unsigned int rotation_axis_direction=2)
Transform angular velocity into linear velocity considering that the angular velocity omega is consta...
SDIRKTable sdirk_table(const Parameters::SimulationControl::TimeSteppingMethod method)
Construct the Butcher tableau (A, b, c) for a given SDIRK method.
Structure representing a Butcher tableau for a SDIRK method.
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
bool time_stepping_is_bdf(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is within the bdf family.
bool time_stepping_is_sdirk(const Parameters::SimulationControl::TimeSteppingMethod method)
Determines if the time integration method is within the sdirk family.