Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
fluid_dynamics_sharp.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-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>
5#include <core/grids.h>
10#include <core/utilities.h>
11
15
19#include <dem/visualization.h>
21
22#include <deal.II/base/work_stream.h>
23
24#include <deal.II/fe/fe_q.h>
25
26#include <deal.II/grid/grid_tools.h>
27
28#include <deal.II/lac/full_matrix.h>
29
30#include <boost/signals2/connection.hpp>
31
32#include <numbers>
33
34// Constructor for class FluidDynamicsSharp
35template <int dim>
38 : FluidDynamicsMatrixBased<dim>(p_nsparam.cfd_parameters)
39 , cfd_dem_parameters(p_nsparam)
40 , all_spheres(true)
42{}
43
44template <int dim>
46
47
48template <int dim>
49void
51{
52 // Find all the cells around each vertex
53 TimerOutput::Scope t(this->computing_timer, "Map vertices to cell");
54
56}
57
58template <int dim>
59void
61{
62 all_spheres = false;
63
64 // TODO The optimized cut-cell mapping seems to lead to instability
65 /*
66 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
67 {
68 if (particles[p_i].shape->get_shape_name().second !=
69 Shape<dim>::ShapeType::sphere)
70 {
71 all_spheres = false;
72 std::cout
73 << "A non-spherical particle was found: using regular
74 cut_cells_mapping."
75 << std::endl;
76 break;
77 }
78 }
79 */
80}
81
82template <int dim>
83void
85{
86 // Potential amelioration of this function. This function could try to use the
87 // information of the previous cut cell mapping as an initial guess of the new
88 // cell mapping by looking at the parent level of the cells to look for new
89 // cells cut.
90
91
92
93 // check all the cells if they are cut or not. Put the information in a map
94 // with the key being the cell.
95 TimerOutput::Scope t(this->computing_timer, "Map cut cells");
96
97
98 // A vector of the unordered map. Each map stores if a point is inside or
99 // outside a given particle.
100 std::vector<std::unordered_map<types::global_dof_index, bool>>
101 inside_outside_support_point_vector(particles.size());
102 std::map<types::global_dof_index, Point<dim>> support_points =
103 DoFTools::map_dofs_to_support_points(*this->mapping, *this->dof_handler);
104
105 // When the finite element order > 1, overconstrained cells are impossible
106 // since there is always at least a DOF inside the element that is not
107 // overconstrained. We therefore only have to check when the velocity order
108 // When the finite element degree > 1, overconstrained cells are impossible
109 // since there is always at least a DOF inside the element that is not
110 // overconstrained. We therefore only have to check when the velocity degree
111 // == 1.
112 const bool mapping_overconstrained_cells =
113 this->simulation_parameters.fem_parameters.velocity_degree == 1;
114
115 cut_cells_map.clear();
116 cells_inside_map.clear();
119 if (mapping_overconstrained_cells)
120 {
122 this->mpi_communicator);
125 this->mpi_communicator);
126 }
127
128 const auto &cell_iterator = this->dof_handler->active_cell_iterators();
129 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
130 const unsigned int dofs_per_face = this->fe->dofs_per_face;
131
132 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
133 std::vector<types::global_dof_index> local_face_dof_indices(dofs_per_face);
134
135 auto &v_x_fe = this->fe->get_sub_fe(0, 1);
136 const unsigned int dofs_per_cell_local_v_x = v_x_fe.dofs_per_cell;
137
138
139 // // Loop on all the cells and check if they are cut.
140 for (const auto &cell : cell_iterator)
141 {
142 if (cell->is_locally_owned() || cell->is_ghost())
143 {
144 bool cell_is_cut = false;
145 bool cell_is_inside = false;
146 unsigned int particle_id_which_cuts_this_cell = 0;
147 unsigned int particle_id_in_which_this_cell_is_embedded = 0;
148 std::vector<unsigned int> particles_cutting_this_cell;
149 // is the particle index that cuts the cell if it's cut. If the cell
150 // is not cut the default value is stored (0). If the cell is not cut
151 // this value will never be used.
152 // particles_cutting_this_cell count the number of particles
153 // that cut a cell if multiple particles cut this cell. This is used
154 // to treat cells that are cut by multiple particles differently.
155 cell->get_dof_indices(local_dof_indices);
156
157 for (unsigned int p = 0; p < particles.size(); ++p)
158 {
159 // Particles defined from a stl or an iges don't have a signed
160 // distance function. To identify cells that are cut a special
161 // algorithm is required. For this type of particle, no cell are
162 // identified as being inside the particle. This means that the
163 // fluid is always solved inside the particle.
164 if (particles[p].shape->additional_info_on_shape == "iges")
165 {
166 if (cell_cut_by_p_absolute_distance(cell, support_points, p))
167 {
168 // We only register the particle with the lowest id as
169 // the particle by which this cell is cut if the cell is
170 // cut by multiple particles.
171 if (particles_cutting_this_cell.size() == 0)
172 {
173 cell_is_cut = true;
174 particle_id_which_cuts_this_cell = p;
175 }
176 particles_cutting_this_cell.push_back(p);
177 }
178 }
179 else
180 {
181 unsigned int nb_dof_inside = 0;
182 for (unsigned int j = 0; j < local_dof_indices.size(); ++j)
183 {
184 // Count the number of DOFs that are inside
185 // of the particles. If all the DOfs are on one side
186 // the cell is not cut by the boundary.
187 if (0 == this->fe->system_to_component_index(j).first)
188 {
189 // Check if we already have checked this point in a
190 // previously evaluated cell. If we didn't find it in
191 // the previous evaluation, we assess whether the DOF
192 // is inside or outside the shape.
193 if (particles[p].get_levelset(
194 support_points[local_dof_indices[j]], cell) <=
195 0)
196 {
197 ++nb_dof_inside;
198 inside_outside_support_point_vector
199 [p][local_dof_indices[j]] = true;
200 }
201 }
202 }
203
204 // If some DOFs are inside the boundary, the cell is inside
205 // the particle or cut by the particle.
206 if (nb_dof_inside != 0)
207 {
208 // If all the DOFs are inside the boundary this cell is
209 // inside the particle. Otherwise, the particle is cut.
210 if (nb_dof_inside == dofs_per_cell_local_v_x)
211 {
212 // We register only the particle with the lowest id
213 // as the particle in which this cell is embedded if
214 // the cell is in multiple particles.
215 if (particles_cutting_this_cell.size() == 0)
216 {
217 cell_is_cut = false;
218 particle_id_which_cuts_this_cell = 0;
219 cell_is_inside = true;
220 particle_id_in_which_this_cell_is_embedded = p;
221 }
222 break;
223 }
224 else
225 {
226 // We only register the particle with the lowest id as
227 // the particle by this cell is cut if the cell is cut
228 // in multiple particles.
229 if (particles_cutting_this_cell.size() == 0)
230 {
231 cell_is_cut = true;
232 particle_id_which_cuts_this_cell = p;
233 cell_is_inside = false;
234 particle_id_in_which_this_cell_is_embedded = 0;
235 }
236 particles_cutting_this_cell.push_back(p);
237 if (particles_cutting_this_cell.size() > 1)
238 {
239 for (const auto &dof_index : local_dof_indices)
240 {
242 true;
243 }
244 }
245 }
246 }
247 else
248 {
249 if (particles_cutting_this_cell.size() == 0)
250 {
251 cell_is_cut = false;
252 particle_id_which_cuts_this_cell = 0;
253 cell_is_inside = false;
254 particle_id_in_which_this_cell_is_embedded = 0;
255 }
256 }
257 }
258 }
259
260 if (mapping_overconstrained_cells)
261 {
262 // If a cell is cut, we register its DOFs as "cut" also. This
263 // will allow us to detect fluid cells that have all their DOFs
264 // cut, and consider them as cut cells.
265 if (cell_is_cut)
266 {
267 for (const auto &id : local_dof_indices)
268 {
270 }
271 }
272
273 // We loop on every face of the cell, and if the face is at a
274 // boundary we count it as constrained.
275 size_t nb_faces = cell->n_faces();
276 for (unsigned int f = 0; f < nb_faces; ++f)
277 {
278 const auto face = cell->face(f);
279 if (face->at_boundary())
280 {
281 face->get_dof_indices(local_face_dof_indices);
282 for (const auto &id : local_face_dof_indices)
283 {
285 }
286 }
287 }
288 }
289
290 cut_cells_map[cell] = {cell_is_cut,
291 particle_id_which_cuts_this_cell,
292 particles_cutting_this_cell};
293 cells_inside_map[cell] = {cell_is_inside,
294 particle_id_in_which_this_cell_is_embedded};
295 }
296 }
297
298 if (mapping_overconstrained_cells)
299 {
300 local_dof_overconstrained.compress(VectorOperation::insert);
302
303
304 for (const auto &cell : cell_iterator)
305 {
306 if (cell->is_locally_owned() || cell->is_ghost())
307 {
308 bool cell_is_cut;
309 bool cell_is_inside;
310 cell->get_dof_indices(local_dof_indices);
311 std::tie(cell_is_cut, std::ignore, std::ignore) =
312 cut_cells_map[cell];
313 std::tie(cell_is_inside, std::ignore) = cells_inside_map[cell];
314 if (!cell_is_cut && !cell_is_inside)
315 {
316 unsigned int number_of_vertices_in_cell =
317 local_dof_indices.size();
318 unsigned int number_of_vertices_cut = 0;
319 unsigned int particle_current_id =
320 std::numeric_limits<int>::max();
321
322 double particle_current_distance(
323 std::numeric_limits<double>::max());
324 double particle_candidate_distance(
325 std::numeric_limits<double>::max());
326
327 unsigned int global_dof_id;
328 // We count the number of vertices that are constrained.
329 for (unsigned int j = 0; j < number_of_vertices_in_cell; ++j)
330 {
331 global_dof_id = local_dof_indices[j];
332 if (dof_overconstrained(global_dof_id) > 0)
333 {
334 number_of_vertices_cut += 1;
335 }
336 }
337 // We check which particle is the closest to the cell, so
338 // that we know which one to use for applying the immersed
339 // boundary constraints.
340 if (number_of_vertices_in_cell == number_of_vertices_cut)
341 {
342 for (unsigned int p = 0; p < particles.size(); p++)
343 {
344 particle_candidate_distance =
345 particles[p].get_levelset(cell->barycenter(), cell);
346 if (abs(particle_candidate_distance) <
347 abs(particle_current_distance))
348 {
349 particle_current_id = p;
350 particle_current_distance =
351 particle_candidate_distance;
352 }
353 }
354
355 for (const auto &local_dof_index : local_dof_indices)
356 {
357 dof_with_more_then_one_particle[local_dof_index] =
358 true;
359 }
360
362 true, particle_current_id, particle_current_distance};
363 }
364 }
365 }
366 }
367 }
368}
369
370template <int dim>
371void
373{
374 // We add a post-refinement check to update precalculations only if needed.
375 // Two booleans are used: the first one is used to update the precalculations,
376 // and the other one is used to remove superfluous nodes. We make this
377 // separation between the steps to avoid removing useful information until all
378 // triangulation refinement steps are done.
379 bool update_precalculations_flag = false;
380 bool remove_superfluous_data_flag = false;
381 // The slot captures a local variable, so the connection is scoped to
382 // disconnect it when leaving this function.
383 const boost::signals2::scoped_connection post_refinement_connection =
384 this->triangulation->signals.post_refinement.connect(
385 [&update_precalculations_flag]() { update_precalculations_flag = true; });
386
387 // This function applies the various refinement steps depending on the
388 // parameters and the state.
389 if (initial_refinement)
390 {
391 // Apply the initial box refinement
392 this->box_refine_mesh(false);
394 }
395 if (this->simulation_parameters.particlesParameters
396 ->time_extrapolation_of_refinement_zone ||
397 initial_refinement)
398 {
399 // Stores variable for refinement around the particle.
400 double temp_refine =
401 this->simulation_parameters.mesh_adaptation.variables.begin()
402 ->second.refinement_fraction;
403 double temp_coarse =
404 this->simulation_parameters.mesh_adaptation.variables.begin()
405 ->second.coarsening_fraction;
406 this->simulation_parameters.mesh_adaptation.variables.begin()
407 ->second.refinement_fraction = 0;
408 this->simulation_parameters.mesh_adaptation.variables.begin()
409 ->second.coarsening_fraction = 0;
410
411 for (unsigned int i = 0;
412 i <
413 this->simulation_parameters.particlesParameters->initial_refinement;
414 ++i)
415 {
416 update_precalculations_flag = false;
417 this->pcout << "Initial refinement around IB particles - Step : "
418 << i + 1 << " of "
419 << this->simulation_parameters.particlesParameters
420 ->initial_refinement
421 << std::endl;
422 mesh_adapt_ib(initial_refinement);
424 if (update_precalculations_flag)
425 {
426 remove_superfluous_data_flag = true;
428 }
429 }
430 this->simulation_parameters.mesh_adaptation.variables.begin()
431 ->second.refinement_fraction = temp_refine;
432 this->simulation_parameters.mesh_adaptation.variables.begin()
433 ->second.coarsening_fraction = temp_coarse;
434 }
435 if (initial_refinement == false)
436 {
437 update_precalculations_flag = false;
438 mesh_adapt_ib(initial_refinement);
440 if (update_precalculations_flag)
441 {
442 remove_superfluous_data_flag = true;
444 }
445 }
446 if (remove_superfluous_data_flag || initial_refinement)
447 {
448 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
449 {
450 TimerOutput::Scope t(this->computing_timer, "Remove RBF nodes");
451 particles[p_i].remove_superfluous_data(
452 *this->dof_handler, particles[p_i].mesh_based_precalculations);
453 }
454 }
455}
456
457template <int dim>
458bool
460 const typename DoFHandler<dim>::active_cell_iterator &cell,
461 std::map<types::global_dof_index, Point<dim>> &support_points,
462 unsigned int p)
463{
464 // This function aims at defining if a cell is cut when the level set used to
465 // define the particle is not signed. This function works by analyzing the
466 // location of the projection of the support point and the cell centroid on
467 // the particle's surface. If the projected point at the surface of the
468 // particle is inside the cell then the cell is cut.
469
470 // First step: define useful variables.
471 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
472 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
473 cell->get_dof_indices(local_dof_indices);
474 bool cell_is_cut = false;
475 Point<dim> centroid_of_cell = cell->barycenter();
476 Point<dim> projected_point;
477 particles[p].closest_surface_point(centroid_of_cell, projected_point, cell);
478
479 // Check the centroid of the cell first.
480 if (cell->point_inside(projected_point))
481 {
482 cell_is_cut = true;
483 return cell_is_cut;
484 }
485 else
486 {
487 // If the projection of the centroid is not inside the cell we also check
488 // for each dof support point of the cell.
489 for (unsigned int j = 0; j < local_dof_indices.size(); ++j)
490 {
491 // Only check for the support point of the velocity in x.
492 if (0 == this->fe->system_to_component_index(j).first)
493 {
494 particles[p].closest_surface_point(
495 support_points[local_dof_indices[j]], projected_point, cell);
496
497 if (cell->point_inside(projected_point))
498 {
499 cell_is_cut = true;
500 break;
501 }
502 if ((projected_point - support_points[local_dof_indices[j]])
503 .norm() < cell->diameter() * 0.1)
504 {
505 cell_is_cut = true;
506 break;
507 }
508 }
509 }
510 }
511 return cell_is_cut;
512}
513
514template <int dim>
515void
517{
518 TimerOutput::Scope t(this->computing_timer, "Optmize cut cells mapping");
519 MappingQ1<dim> mapping;
520 unsigned int max_children = GeometryInfo<dim>::max_children_per_cell;
521
522 std::set<typename DoFHandler<dim>::cell_iterator> all_candidate_cells;
523 std::set<typename DoFHandler<dim>::cell_iterator>
524 previous_all_candidate_cells;
525
526 cut_cells_map.clear();
527 cells_inside_map.clear();
528 for (const auto &cell : this->dof_handler->active_cell_iterators())
529 {
530 if (cell->is_locally_owned() || cell->is_ghost())
531 {
532 cut_cells_map[cell] = {false, 0, std::vector<unsigned int>()};
533 cells_inside_map[cell] = {false, 0};
534 }
535 }
536
537 // Loop over particles in reverse.
538 // This is done in reverse to guarantee that the lowest particle ID is
539 // associated to the cut cell or the inside particle cell. For instance, if
540 // you have two particles cutting the same cell, it guarantees that the lowest
541 // ID particle is associated with the cell in the map.
542 for (int p = particles.size() - 1; p >= 0; --p)
543 {
544 bool empty = true;
545 unsigned int lvl_iter = 0;
546
547 // Fix max level search
548 unsigned int max_lvl_search =
549 this->dof_handler->get_triangulation().n_levels() - 2;
550 if (max_lvl_search < 4)
551 max_lvl_search = this->dof_handler->get_triangulation().n_levels();
552
553 // Search for candidates until at least one is found or until the
554 // max_lvl_search is reached
555 while (empty || lvl_iter < max_lvl_search)
556 {
557 const auto &cell_iterator =
558 this->dof_handler->cell_iterators_on_level(lvl_iter);
559
560 // Loop over the cells on level lvl_iter of the mesh
561 for (const auto &cell : cell_iterator)
562 {
563 auto is_candidate = generate_cut_cell_candidates(cell, p);
564
565 // check whether the cell is candidate for inside of cut
566 if (is_candidate.first)
567 {
568 all_candidate_cells.insert(cell);
569 }
570 if (is_candidate.second)
571 {
572 all_candidate_cells.insert(cell);
573 }
574 }
575 if (all_candidate_cells.size() > 0)
576 empty = false;
577
578 lvl_iter += 1;
579 }
580
581 // Store list with all candidate cells
582 previous_all_candidate_cells = all_candidate_cells;
583
584 // If there are candidate cells
585 if (all_candidate_cells.size() != 0)
586 {
587 bool all_cells_are_active = false;
588
589 // Loop until candidate cells are active
590 while (!all_cells_are_active)
591 {
592 all_cells_are_active = true;
593 all_candidate_cells.clear();
594
595 // loop over the last set of candidates to check if it is still a
596 // candidate
597 for (auto cell : previous_all_candidate_cells)
598 {
599 auto is_candidate = generate_cut_cell_candidates(cell, p);
600
601 // Check if cell is inside particles
602 if (is_candidate.first)
603 {
604 // If it is an active cell, add it to cells_inside_map
605 if (cell->is_active())
606 {
607 cells_inside_map[cell] = {true, p};
608 }
609 else
610 {
611 // If we are here, the cell has children.
612 all_cells_are_active = false;
613 for (unsigned int j = 0; j < max_children; ++j)
614 {
615 // Store the children of the cell for
616 // further checks.
617 all_candidate_cells.insert(cell->child(j));
618 }
619 }
620 }
621
622 if (is_candidate.second)
623 {
624 // If it is an active cell, add it to cells_cut_map
625 if (cell->is_active())
626 {
627 cut_cells_map[cell] = {true,
628 p,
629 std::vector<unsigned int>()};
630 }
631 else
632 {
633 // If we are here, the cell has children.
634 all_cells_are_active = false;
635 for (unsigned int j = 0; j < max_children; ++j)
636 {
637 // Store the children of the cell for
638 // further checks.
639 all_candidate_cells.insert(cell->child(j));
640 }
641 }
642 }
643 }
644 previous_all_candidate_cells.clear();
645 previous_all_candidate_cells = all_candidate_cells;
646 }
647 }
648 }
649}
650
651
652template <int dim>
653std::pair<bool, bool>
655 const typename DoFHandler<dim>::cell_iterator &cell,
656 const unsigned int p_id)
657{
658 bool cell_is_inside = false;
659 bool cell_is_cut = false;
660
661 double search_radius = particles[p_id].radius * (1.0 - 1e-07);
662 auto position = particles[p_id].position;
663
664 bool point_inside_cell = cell->point_inside(position);
665
666 // Check how many vertices are inside the particle
667 unsigned int nb_vertices_inside = 0;
668 for (unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_cell; ++i)
669 {
670 if ((cell->vertex(i) - position).norm() < search_radius)
671 ++nb_vertices_inside;
672 }
673
674 // If vertices are found inside the particle
675 if (nb_vertices_inside > 0)
676 {
677 // If the number of vertices inside the cell is equal to the number of
678 // vertices per cell, the cell is inside the particle
679 if (nb_vertices_inside == GeometryInfo<dim>::vertices_per_cell)
680 {
681 cell_is_inside = true;
682 cell_is_cut = false;
683 }
684 // Otherwise, the cell is cut
685 else
686 {
687 cell_is_inside = false;
688 cell_is_cut = true;
689 }
690 return {cell_is_inside, cell_is_cut};
691 }
692
693 // If the particle intersect the cell and is not known whether all
694 // vertices are inside the particles, set all true by default
696 {
697 cell_is_inside = true;
698 cell_is_cut = true;
699 return {cell_is_inside, cell_is_cut};
700 }
701
702 // The last check consists of projecting the particle's position on the cells'
703 // face and checking whether the projected points are within the particle. If
704 // one of the projected points is inside the particle, either the cell is
705 // inside or is cut by the particles. If this is true, the next
706 // level will be tested again by this function.
707
708 // Initialize superpoint of manifold
709 std::vector<Point<dim>> manifold_points(
710 GeometryInfo<dim - 1>::vertices_per_cell);
711
712 // Loop through faces
713 for (const auto face : cell->face_indices())
714 {
715 auto face_iter = cell->face(face);
716 auto &local_face_manifold = face_iter->get_manifold();
717
718 // Loop through face vertices
719 for (unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face; ++i)
720 {
721 // Assign vertex to manifold superpoint
722 manifold_points[i] = face_iter->vertex(i);
723 }
724
725 // Create array of points on face
726 auto surrounding_face_points =
727 make_array_view(manifold_points.begin(), manifold_points.end());
728
729 // Loop through face vertices
730 for (unsigned int i = 0; i < GeometryInfo<dim>::vertices_per_face; ++i)
731 {
732 // Project points to face
733 Point<dim> projected_point =
734 local_face_manifold.project_to_manifold(surrounding_face_points,
735 position);
736
737 bool projected_point_over_face = true;
738 Tensor<1, dim> projected_point_tensor(projected_point);
739
740 // Check whether the projected point is within the cell
741 try
742 {
743 projected_point_over_face = cell->point_inside(projected_point);
744
745 if ((position - projected_point).norm() < search_radius &&
746 projected_point_over_face)
747 {
748 cell_is_inside = true;
749 cell_is_cut = true;
750 return {cell_is_inside, cell_is_cut};
751 }
752 }
753 // If the method crashes, change default for false
754 catch (...)
755 {
756 projected_point_over_face = false;
757 }
758
759 for (int d = 0; d != dim; d++)
760 {
761 if (projected_point_tensor[d] < 0 ||
762 projected_point_tensor[d] > 1)
763 {
764 projected_point_over_face = false;
765 }
766 }
767 }
768 }
769 return {cell_is_inside, cell_is_cut};
770}
771
772template <int dim>
773void
775{
777 // initialized the particles
778 if (this->simulation_parameters.particlesParameters
779 ->load_particles_from_file == false)
780 {
781 particles.resize(
782 this->simulation_parameters.particlesParameters->nb_particles);
783 for (unsigned int i = 0;
784 i < this->simulation_parameters.particlesParameters->nb_particles;
785 ++i)
786 {
787 particles[i] =
788 this->simulation_parameters.particlesParameters->particles[i];
789 if (particles[i].integrate_motion == true)
790 {
792 }
793 }
794 }
795 else
796 {
797 // The number of particles is defined by the file, not by the "number of
798 // particles" parameter.
800 for (unsigned int i = 0; i < particles.size(); ++i)
801 {
802 if (particles[i].integrate_motion == true)
803 {
805 }
806 }
807 }
808
809 table_p.resize(particles.size());
810 ib_dem.initialize(
811 this->simulation_parameters.particlesParameters,
813 cfd_dem_parameters.dem_parameters.floating_walls),
814 std::make_shared<Parameters::Lagrangian::BCDEM>(
815 cfd_dem_parameters.dem_parameters.boundary_conditions),
816 this->mpi_communicator,
817 particles);
818
820
821 std::vector<std::shared_ptr<Shape<dim>>> all_shapes(particles.size());
822 for (const IBParticle<dim> &particle : particles)
823 {
824 all_shapes[particle.particle_id] = particle.shape;
825 }
827 std::make_shared<CompositeShape<dim>>(all_shapes, Point<dim>(), Point<3>());
828 this->multiphysics->set_immersed_solid_shape(combined_shapes);
829}
830
831
832template <int dim>
833void
834FluidDynamicsSharp<dim>::mesh_adapt_ib(const bool initial_refinement)
835{
836 // If this is not the initial refinement cycle nor a usual refinement step,
837 // we refine the cells around immersed solids only if they have moved since
838 // the last time step.
839 if (!initial_refinement && !this->simulation_control->is_refinement_step(
840 this->simulation_parameters.mesh_adaptation))
841 {
842 bool stationary_particles = true;
843 for (unsigned int p = 0; p < particles.size(); ++p)
844 {
845 if ((particles[p].position - particles[p].previous_positions[0])
846 .norm() > 1e-16 ||
847 (particles[p].orientation - particles[p].previous_orientation[0])
848 .norm() > 1e-16)
849 {
850 stationary_particles = false;
851 break;
852 }
853 }
854 if (stationary_particles)
855 return;
856 }
857
858 TimerOutput::Scope t(this->computing_timer,
859 "Refine around immersed boundary");
860 Point<dim> center_immersed;
861 std::map<types::global_dof_index, Point<dim>> support_points =
862 DoFTools::map_dofs_to_support_points(*this->mapping, *this->dof_handler);
863
864 double dt = this->simulation_control->get_time_steps_vector()[0];
865
866 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
867 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
868
869 bool extrapolate_particle_position =
870 this->simulation_parameters.particlesParameters
871 ->time_extrapolation_of_refinement_zone;
872
873 double smallest_cut_cell = std::numeric_limits<double>::max();
874 bool minimal_crown_refinement_enabled =
875 abs(this->simulation_parameters.particlesParameters
876 ->refinement_outside_distance_factor -
877 1) < 1e-16 &&
878 abs(this->simulation_parameters.particlesParameters
879 ->refinement_inside_distance_factor -
880 1) < 1e-16;
881 if (minimal_crown_refinement_enabled)
882 {
883 const auto &cell_iterator_smallest_cell =
884 this->dof_handler->active_cell_iterators();
885 for (const auto &cell : cell_iterator_smallest_cell)
886 {
887 if (cell->is_locally_owned())
888 smallest_cut_cell = std::min(smallest_cut_cell, cell->diameter());
889 }
890 smallest_cut_cell =
891 Utilities::MPI::min(smallest_cut_cell, this->mpi_communicator);
892 }
893
894 const auto &cell_iterator = this->dof_handler->active_cell_iterators();
895 for (const auto &cell : cell_iterator)
896 {
897 if (cell->is_locally_owned())
898 {
899 bool cell_can_be_coarsened =
900 this->simulation_parameters.particlesParameters->enable_coarsening;
901
902 cell->get_dof_indices(local_dof_indices);
903 for (unsigned int p = 0; p < particles.size(); ++p)
904 {
905 unsigned int count_small = 0;
906 center_immersed = particles[p].position;
907 Tensor<1, dim> r;
908 r[0] = particles[p].radius;
909
910 Point<dim> particle_position;
911 Tensor<1, 3> particle_orientation;
912 if (extrapolate_particle_position)
913 {
914 particle_position = particles[p].position;
915 particle_orientation = particles[p].orientation;
916 particles[p].orientation =
917 particles[p].orientation + particles[p].omega * dt;
918 particles[p].position[0] =
919 particles[p].position[0] + particles[p].velocity[0] * dt;
920 particles[p].position[1] =
921 particles[p].position[1] + particles[p].velocity[1] * dt;
922
923 if constexpr (dim == 3)
924 {
925 particles[p].position[2] = particles[p].position[2] +
926 particles[p].velocity[2] * dt;
927 }
928 particles[p].set_position(particles[p].position);
929 particles[p].set_orientation(particles[p].orientation);
930 }
931 // Check if a point on the random point on the IB is contained in
932 // that cell. If the particle is much smaller than the cell, all
933 // its vertices may be outside of the particle. In that case the
934 // cell won't be refined. To prevent that, we check if a random
935 // point on the boundary is contained in the cell.
936 bool cell_as_ib_inside =
937 cell->point_inside(particles[p].position + r);
938 bool cell_is_near_particle_for_coarsening = false;
939
940 for (unsigned int j = 0; j < local_dof_indices.size(); ++j)
941 {
942 // Only check the dof of velocity in x.
943 if (this->fe->system_to_component_index(j).first == 0)
944 {
945 // Count the number of DOFs that fall in the refinement
946 // zone around the particle. To fall in the zone, the
947 // radius of the DOFs to the center of the particle must
948 // be bigger than the inside radius of the refinement zone
949 // and smaller than the outside radius of the refinement
950 // zone.
951 bool is_inside_crown;
952 if (minimal_crown_refinement_enabled)
953 {
954 // The factor should be equal to the length of the
955 // current smallest cell. Since cell->diameter()
956 // returns the longest diagonal, we divide the
957 // diameter by the diagonal of a unit hypercube to
958 // obtain the correct length.
959 double factor = 1 / sqrt(dim);
960 is_inside_crown = particles[p].is_inside_crown(
961 support_points[local_dof_indices[j]],
962 factor * smallest_cut_cell,
963 -factor * smallest_cut_cell,
964 true, // indicates that we use the absolute
965 // distance definition
966 cell);
967 }
968 else
969 {
970 is_inside_crown = particles[p].is_inside_crown(
971 support_points[local_dof_indices[j]],
972 this->simulation_parameters.particlesParameters
973 ->refinement_outside_distance_factor,
974 this->simulation_parameters.particlesParameters
975 ->refinement_inside_distance_factor,
976 false, // indicates that we use the
977 // radius relative distance definition
978 cell);
979 }
980
981 if (cell_can_be_coarsened)
982 {
983 const double coarsening_distance =
984 particles[p].shape->value_with_cell_guess(
985 support_points[local_dof_indices[j]], cell);
986 const double coarsening_threshold =
987 particles[p].shape->effective_radius *
988 (this->simulation_parameters.particlesParameters
989 ->coarsening_distance_factor -
990 1);
991
992 if (coarsening_distance <= coarsening_threshold)
993 cell_is_near_particle_for_coarsening = true;
994 }
995
996 if (is_inside_crown)
997 {
998 ++count_small;
999 }
1000 }
1001 }
1002
1003 if (extrapolate_particle_position)
1004 {
1005 particles[p].position = particle_position;
1006 particles[p].orientation = particle_orientation;
1007 particles[p].set_position(particles[p].position);
1008 particles[p].set_orientation(particles[p].orientation);
1009 }
1010
1011 if (cell_as_ib_inside || cell_is_near_particle_for_coarsening)
1012 cell_can_be_coarsened = false;
1013
1014 if (count_small > 0 || cell_as_ib_inside)
1015 {
1016 cell->set_refine_flag();
1017 break;
1018 }
1019 }
1020
1021 if (cell_can_be_coarsened && !cell->refine_flag_set())
1022 cell->set_coarsen_flag();
1023 }
1024 }
1025}
1026
1027
1028
1029template <int dim>
1030void
1032{
1033 // This function defines the force and torque applied on an Immersed Boundary
1034 // based on the sharp edge method on a hyper_sphere of dim=2 or dim=3
1035
1036 TimerOutput::Scope t(this->computing_timer,
1037 "Evaluate force on immersed boundary");
1038
1039 const FEValuesExtractors::Scalar pressure(dim);
1040 const FEValuesExtractors::Vector velocities(0);
1041
1042 std::vector<double> time_steps_vector =
1043 this->simulation_control->get_time_steps_vector();
1044 // Define a map to all DOFs and their support points
1045 std::map<types::global_dof_index, Point<dim>> support_points =
1046 DoFTools::map_dofs_to_support_points(*this->mapping, *this->dof_handler);
1047
1048 // Initalize fe value objects in order to do calculation with it later
1049 QGauss<dim> q_formula(this->number_quadrature_points);
1050 MappingQ<dim - 1, dim> local_face_map(
1051 (2 > this->simulation_parameters.fem_parameters.velocity_degree) ?
1052 2 :
1053 this->simulation_parameters.fem_parameters.velocity_degree);
1054
1055 FESystem<dim - 1, dim> local_face_fe(
1056 FE_Q<dim - 1, dim>(
1057 this->simulation_parameters.fem_parameters.velocity_degree),
1058 dim,
1059 FE_Q<dim - 1, dim>(
1060 this->simulation_parameters.fem_parameters.pressure_degree),
1061 1);
1062 FEValues<dim - 1, dim> fe_face_projection_values(local_face_map,
1063 local_face_fe,
1064 *this->face_quadrature,
1065 update_values |
1066 update_quadrature_points |
1067 update_gradients |
1068 update_JxW_values |
1069 update_normal_vectors);
1070
1071
1072
1073 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
1074 const unsigned int dofs_per_face = this->fe->dofs_per_face;
1075
1076 AssertThrow(this->simulation_parameters.physical_properties_manager
1077 .density_is_constant(),
1078 RequiresConstantDensity("FluidDynamicsSharp<dim>::force_on_ib"));
1079
1080 unsigned int degree =
1081 this->simulation_parameters.particlesParameters->stencil_degree;
1082 auto density_model =
1083 this->simulation_parameters.physical_properties_manager.get_density(0);
1084 std::map<field, double> field_values;
1085 field_values[field::temperature] = 0;
1086 double fluid_density = density_model->value(field_values);
1087 double length_ratio =
1088 this->simulation_parameters.particlesParameters->length_ratio;
1089 IBStencil<dim> stencil;
1090 std::vector<double> ib_coef = stencil.coefficients(degree, length_ratio);
1091
1092 // Rheological model for viscosity properties
1093 double kinematic_viscosity;
1094 const auto rheological_model =
1095 this->simulation_parameters.physical_properties_manager.get_rheology();
1096
1097 const unsigned int vertices_per_face = GeometryInfo<dim>::vertices_per_face;
1098 const unsigned int n_q_points_face = this->face_quadrature->size();
1099
1100 std::vector<double> pressure_values(ib_coef.size());
1101 Tensor<1, dim> normal_vector;
1102 std::vector<Tensor<2, dim>> velocity_gradients(ib_coef.size());
1103 std::vector<std::vector<Tensor<1, dim>>> velocity_gradients_component(dim +
1104 1);
1105 for (int i = 0; i < dim + 1; ++i)
1106 velocity_gradients_component[i].resize(ib_coef.size());
1107 Tensor<2, dim> fluid_viscous_stress;
1108 Tensor<2, dim> fluid_pressure;
1109 Tensor<2, dim> fluid_viscous_stress_at_ib;
1110 Tensor<2, dim> fluid_pressure_stress_at_ib;
1111 Tensor<2, dim> shear_rate;
1112 DoFHandler<dim - 1, dim> local_face_dof_handler;
1113 Triangulation<dim - 1, dim> local_face_projection_triangulation;
1114
1115 std::vector<Point<dim>> vertices_of_face_projection(vertices_per_face);
1116 std::vector<CellData<dim - 1>> local_face_cell_data(1);
1117
1118 typename Mapping<dim>::InternalDataBase mapping_data;
1119 // Define multiple local_dof_indices one for the cell iterator one for the
1120 // cell with the second point for the sharp edge stencil and one for
1121 // manipulation on the neighbour’s cell.
1122
1123 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
1124 std::vector<types::global_dof_index> local_dof_indices_2(dofs_per_cell);
1125
1126 std::vector<types::global_dof_index> local_face_dof_indices(dofs_per_face);
1127
1128 std::vector<Point<dim>> unite_cell_interpolation_points(ib_coef.size());
1129 std::vector<Point<dim>> cell_interpolation_points(ib_coef.size());
1130 std::vector<double> local_interp_sol(ib_coef.size());
1131
1132 std::unordered_map<unsigned int, std::pair<Tensor<2, dim>, Tensor<2, dim>>>
1133 force_eval;
1134
1135 // Define cell iterator
1136 const auto &cell_iterator = this->dof_handler->active_cell_iterators();
1137
1138 // Clear particle force and torque
1139 for (unsigned int i = 0; i < particles.size(); ++i)
1140 {
1141 particles[i].fluid_forces = 0;
1142 particles[i].fluid_viscous_forces = 0;
1143 particles[i].fluid_pressure_forces = 0;
1144 particles[i].fluid_torque = 0;
1145 }
1146
1147 // Loop over all the cell
1148 for (const auto &cell : cell_iterator)
1149 {
1150 if (cell->is_locally_owned())
1151 {
1152 // Particle id that cut the cell.
1153 unsigned int p_main; // The index of the particle used in the
1154 // imposition of this cell
1155 std::vector<unsigned int> p_count;
1156 bool cell_is_cut;
1157 std::tie(cell_is_cut, p_main, p_count) = cut_cells_map[cell];
1158 // If the cell is cut
1159 if (cell_is_cut)
1160 {
1161 // loop over all particles that cut this precise cell
1162 for (auto p : p_count)
1163 {
1164 // Loop over all cut cell faces'.
1165 for (const auto face : cell->face_indices())
1166 {
1167 auto local_face = cell->face(face);
1168 cell->face(face)->get_dof_indices(local_face_dof_indices);
1169
1170 // Check if the face is cut
1171 unsigned int nb_dof_inside = 0;
1172 for (const auto &dof_index : local_face_dof_indices)
1173 {
1174 // Count the number of DOFs that are inside
1175 // of the particles. If all the DOfs are on one side
1176 // the cell is not cut by the boundary.
1177 if (particles[p].get_levelset(
1178 support_points[dof_index], cell) <= 0)
1179 ++nb_dof_inside;
1180 }
1181
1182 // If the face is not cut and the face is outside the
1183 // IB, the face of the cell is on the boundary of the
1184 // computational domain.
1185 if (nb_dof_inside == 0)
1186 {
1187 // Create a vector to approximate the normal of the
1188 // cell to orient the projection of the face.
1189 Tensor<1, dim> approximate_surface_cell_normal;
1190 // Project the face on the surface of the IB. This
1191 // creates a surface cell where we can evaluate the
1192 // solution. Define the triangulation of the surface
1193 // cell.
1194 for (unsigned int i = 0; i < vertices_per_face; ++i)
1195 {
1196 Point<dim> vertex_projection;
1197 particles[p].closest_surface_point(
1198 local_face->vertex(i), vertex_projection, cell);
1199 approximate_surface_cell_normal +=
1200 (local_face->vertex(i) - vertex_projection) /
1201 ((local_face->vertex(i) - vertex_projection)
1202 .norm() +
1203 DBL_MIN);
1204
1205 // Define the vertices of the surface cell.
1206 // Create the list of vertices
1207 for (int j = 0; j < dim; ++j)
1208 {
1209 vertices_of_face_projection[i][j] =
1210 vertex_projection[j];
1211 }
1212 // Create the connectivity of the vertices of the
1213 // cell
1214 local_face_cell_data[0].vertices[i] = i;
1215 }
1216 approximate_surface_cell_normal =
1217 approximate_surface_cell_normal / vertices_per_face;
1218
1219 local_face_cell_data[0].material_id = 0;
1220
1221 local_face_projection_triangulation =
1222 Triangulation<dim - 1, dim>();
1223 // Create a dof_handler that contains the
1224 // triangulation of the projection of the face on the
1225 // IB. This creates the surface cell on the IB
1226 local_face_projection_triangulation
1227 .create_triangulation(vertices_of_face_projection,
1228 local_face_cell_data,
1229 SubCellData());
1230 local_face_projection_triangulation
1231 .set_all_manifold_ids(0);
1232 local_face_projection_triangulation.set_manifold(
1233 0, *particles[p].shape->get_shape_manifold());
1234
1235 local_face_dof_handler.reinit(
1236 local_face_projection_triangulation);
1237 local_face_dof_handler.distribute_dofs(local_face_fe);
1238
1239 // Define the solution on IB surface cell by using
1240 // the IB stencil to extrapolate the fluid stress
1241 // tensor.
1242 std::vector<Tensor<2, dim>>
1243 local_face_viscous_stress_tensor(dofs_per_face);
1244 std::vector<Tensor<2, dim>>
1245 local_face_pressure_tensor(dofs_per_face);
1246 for (unsigned int i = 0;
1247 i < local_face_dof_indices.size();
1248 ++i)
1249 {
1250 const unsigned int component_i =
1251 this->fe->face_system_to_component_index(i)
1252 .first;
1253 // Check if that dof already have been used to
1254 // extrapolate the fluid stress tensor on the IB
1255 // surface.
1256 if (force_eval.find(local_face_dof_indices[i]) ==
1257 force_eval.end() or
1259 [local_face_dof_indices[i]] == true)
1260 {
1261 if (component_i == 0)
1262 {
1263 // Only need one extrapolation by dof
1264 // location;
1265
1266 // Count the number of evaluation
1267
1268 auto [point, interpolation_points] =
1269 stencil
1271 degree,
1272 length_ratio,
1273 particles[p],
1274 support_points
1275 [local_face_dof_indices[i]],
1276 cell);
1277
1278 auto cell_2 =
1279 ib_done[local_face_dof_indices[i]]
1280 .second;
1281 // Check if we already have the cell used
1282 // to define the IB constraint of that
1283 // dof. We always have that information
1284 // except if the dof is not owned.
1285 if (ib_done[local_face_dof_indices[i]]
1286 .first == false or
1288 [local_face_dof_indices[i]] ==
1289 true)
1290 {
1291 // Get the cell use for the
1292 // extrapolation
1293 auto point_to_find_cell =
1295 particles[p],
1296 support_points
1297 [local_face_dof_indices[i]],
1298 cell);
1299
1300 try
1301 {
1302 cell_2 = LetheGridTools::
1303 find_cell_around_point_with_neighbors<
1304 dim>(*this->dof_handler,
1306 cell,
1307 point_to_find_cell);
1308 }
1309 catch (...)
1310 {
1311 cell_2 = cell;
1312 }
1313 }
1314
1315 cell_2->get_dof_indices(
1316 local_dof_indices_2);
1317
1318 unite_cell_interpolation_points[0] =
1319 this->mapping
1320 ->transform_real_to_unit_cell(cell_2,
1321 point);
1322 for (unsigned int j = 1;
1323 j < ib_coef.size();
1324 ++j)
1325 {
1326 unite_cell_interpolation_points[j] =
1327 this->mapping
1328 ->transform_real_to_unit_cell(
1329 cell_2,
1330 interpolation_points[j - 1]);
1331 }
1332
1333 fluid_viscous_stress_at_ib = 0;
1334 fluid_pressure_stress_at_ib = 0;
1335
1336 // Create a quadrature that is based on
1337 // the IB stencil
1338 Quadrature<dim> q_local(
1339 unite_cell_interpolation_points,
1340 ib_coef);
1341 FEValues<dim> fe_values_cell2(
1342 *this->fe,
1343 q_local,
1344 update_quadrature_points |
1345 update_gradients | update_values);
1346
1347 // Evaluate the relevant information at
1348 // the quadrature points to do the
1349 // extrapolation.
1350 fe_values_cell2.reinit(cell_2);
1351 fe_values_cell2[velocities]
1352 .get_function_gradients(
1353 this->evaluation_point,
1354 velocity_gradients);
1355 fe_values_cell2[pressure]
1356 .get_function_values(
1357 this->evaluation_point,
1358 pressure_values);
1359
1360 // Extrapolate the fluid stress tensor on
1361 // the surface of the IB.
1362
1363 for (unsigned int k = 0;
1364 k < ib_coef.size();
1365 ++k)
1366 {
1367 fluid_pressure = 0;
1368 for (int d = 0; d < dim; ++d)
1369 {
1370 fluid_pressure[d][d] =
1371 pressure_values[k];
1372 }
1373 shear_rate =
1374 velocity_gradients[k] +
1375 transpose(velocity_gradients[k]);
1376
1377
1378 const double shear_rate_magnitude =
1380 shear_rate);
1381
1382 std::map<field, double> field_values;
1383 field_values[field::shear_rate] =
1384 shear_rate_magnitude;
1385
1386 kinematic_viscosity =
1387 rheological_model->value(
1388 field_values);
1389
1390 fluid_viscous_stress =
1391 -kinematic_viscosity * shear_rate;
1392
1393 fluid_viscous_stress_at_ib -=
1394 fluid_viscous_stress * ib_coef[k];
1395
1396 fluid_pressure_stress_at_ib -=
1397 fluid_pressure * ib_coef[k];
1398 }
1399 // Store the stress tensor that results
1400 // from the extrapolation in the local
1401 // evaluation vector of the IB surface
1402 // cell and in a map that is used if the
1403 // same extrapolation is needed in another
1404 // face.
1405 local_face_viscous_stress_tensor[i] =
1406 fluid_viscous_stress_at_ib;
1407 local_face_pressure_tensor[i] =
1408 fluid_pressure_stress_at_ib;
1409
1410
1411 force_eval[local_face_dof_indices[i]] =
1412 std::make_pair(
1413 fluid_viscous_stress_at_ib,
1414 fluid_pressure_stress_at_ib);
1415 }
1416 }
1417 else
1418 {
1419 // Use the results from a previously evaluated
1420 // extrapolation. This step comes with an
1421 // error due to the curvature of the surface
1422 // in Q2 and higher degree elements.
1423 local_face_viscous_stress_tensor[i] =
1424 force_eval[local_face_dof_indices[i]].first;
1425 local_face_pressure_tensor[i] =
1426 force_eval[local_face_dof_indices[i]]
1427 .second;
1428 }
1429 }
1430 // Use the extrapolation of fluid stress tensor at the
1431 // dof location of the IB surface cell to integrate
1432 // the stress tensor on the surface of the IB
1433 auto local_face_viscous_stress_tensor_old =
1434 local_face_viscous_stress_tensor;
1435 auto local_face_pressure_tensor_old =
1436 local_face_pressure_tensor;
1437
1438 local_face_viscous_stress_tensor.clear();
1439 local_face_pressure_tensor.clear();
1440
1441 local_face_viscous_stress_tensor.resize(
1442 local_face_dof_indices.size());
1443 local_face_pressure_tensor.resize(
1444 local_face_dof_indices.size());
1445
1446 for (const auto &projection_cell_face :
1447 local_face_dof_handler.active_cell_iterators())
1448 {
1449 fe_face_projection_values.reinit(
1450 projection_cell_face);
1451 std::vector<Point<dim>> q_points =
1452 fe_face_projection_values
1453 .get_quadrature_points();
1454 try
1455 {
1456 if (this->simulation_parameters.fem_parameters
1457 .velocity_degree > 1)
1458 {
1459 FullMatrix<double> interpolation_matrix(
1460 local_face_dof_indices.size(),
1461 local_face_dof_indices.size());
1462 FullMatrix<double>
1463 inv_interpolation_matrix(
1464 local_face_dof_indices.size(),
1465 local_face_dof_indices.size());
1466
1467 // Define the interpolation matrix of the
1468 // surface cell
1469 for (unsigned int i = 0;
1470 i < local_face_dof_indices.size();
1471 ++i)
1472 {
1473 Point<dim> point_projection;
1474 particles[p].closest_surface_point(
1475 support_points
1476 [local_face_dof_indices[i]],
1477 point_projection,
1478 cell);
1479
1480 auto projected_point_unit =
1481 local_face_map
1482 .transform_real_to_unit_cell(
1483 projection_cell_face,
1484 point_projection);
1485
1486 for (unsigned int j = 0;
1487 j <
1488 local_face_dof_indices.size();
1489 ++j)
1490 {
1491 interpolation_matrix[i][j] = 0;
1492 if (
1493 this->fe
1494 ->face_system_to_component_index(
1495 j)
1496 .first ==
1497 this->fe
1498 ->face_system_to_component_index(
1499 i)
1500 .first)
1501 interpolation_matrix[i][j] +=
1502 local_face_fe.shape_value(
1503 j, projected_point_unit);
1504 }
1505 }
1506 inv_interpolation_matrix.invert(
1507 interpolation_matrix);
1508 // Define the value of the fluid stress
1509 // tensor on the surface cell at the DOF
1510 // support points location.
1511 for (unsigned int i = 0;
1512 i < local_face_dof_indices.size();
1513 ++i)
1514 {
1515 for (unsigned int j = 0;
1516 j <
1517 local_face_dof_indices.size();
1518 ++j)
1519 {
1520 local_face_viscous_stress_tensor
1521 [i] +=
1522 inv_interpolation_matrix[i][j] *
1523 local_face_viscous_stress_tensor_old
1524 [j];
1525 local_face_pressure_tensor[i] +=
1526 inv_interpolation_matrix[i][j] *
1527 local_face_pressure_tensor_old
1528 [j];
1529 }
1530 }
1531 }
1532 else
1533 {
1534 local_face_viscous_stress_tensor =
1535 local_face_viscous_stress_tensor_old;
1536 local_face_pressure_tensor =
1537 local_face_pressure_tensor_old;
1538 }
1539 }
1540 catch (...)
1541 {
1542 local_face_viscous_stress_tensor =
1543 local_face_viscous_stress_tensor_old;
1544 local_face_pressure_tensor =
1545 local_face_pressure_tensor_old;
1546 }
1547 for (unsigned int q = 0; q < n_q_points_face; q++)
1548 {
1549 // Evaluate the total surface
1550 // Redefined the normal at the quadrature
1551 // point since we don't control the
1552 // orientation of the cell.
1553 normal_vector =
1554 fe_face_projection_values.normal_vector(q);
1555 if (scalar_product(
1556 normal_vector,
1557 approximate_surface_cell_normal) < 0)
1558 normal_vector = -normal_vector;
1559
1560 fluid_viscous_stress = 0;
1561 fluid_pressure = 0;
1562
1563 // Integrate
1564 for (unsigned int i = 0;
1565 i < local_face_dof_indices.size();
1566 ++i)
1567 {
1568 const unsigned int component_i =
1569 local_face_fe
1570 .system_to_component_index(i)
1571 .first;
1572 if (component_i == 0)
1573 {
1574 fluid_viscous_stress +=
1575 fe_face_projection_values
1576 .shape_value(i, q) *
1577 local_face_viscous_stress_tensor[i];
1578
1579 fluid_pressure +=
1580 fe_face_projection_values
1581 .shape_value(i, q) *
1582 local_face_pressure_tensor[i];
1583 }
1584 }
1585
1586 auto viscous_force =
1587 fluid_viscous_stress * normal_vector *
1588 fe_face_projection_values.JxW(q);
1589
1590 auto pressure_force =
1591 fluid_pressure * normal_vector *
1592 fe_face_projection_values.JxW(q);
1593
1594 auto force = viscous_force + pressure_force;
1595
1596 if (force != force)
1597 {
1598 // The force is nan; this happens when the
1599 // face projection is a line. This
1600 // generally happens when the surface on
1601 // which the force is evaluated is
1602 // perfectly flat and aligned with the
1603 // mesh. Since the area associated with
1604 // this face projection is zero, we set
1605 // the local force contribution to zero.
1606 force = 0;
1607 viscous_force = 0;
1608 pressure_force = 0;
1609 }
1610
1611 // Add the local contribution of this surface
1612 // cell.
1613
1614 particles[p].fluid_viscous_forces +=
1615 tensor_nd_to_3d(viscous_force);
1616
1617 particles[p].fluid_pressure_forces +=
1618 tensor_nd_to_3d(pressure_force);
1619
1620 auto distance =
1621 q_points[q] - particles[p].position;
1622 if constexpr (dim == 2)
1623 {
1624 particles[p].fluid_torque[0] += 0.;
1625 particles[p].fluid_torque[1] += 0.;
1626 particles[p].fluid_torque[2] +=
1627 distance[0] * force[1] -
1628 distance[1] * force[0];
1629 }
1630 else if constexpr (dim == 3)
1631 {
1632 particles[p].fluid_torque[0] +=
1633 distance[1] * force[2] -
1634 distance[2] * force[1];
1635 particles[p].fluid_torque[1] +=
1636 distance[2] * force[0] -
1637 distance[0] * force[2];
1638 particles[p].fluid_torque[2] +=
1639 distance[0] * force[1] -
1640 distance[1] * force[0];
1641 }
1642 }
1643 }
1644 }
1645 }
1646 }
1647 }
1648 }
1649 }
1650
1651 // Sums the force evaluation on each of the processor.
1652 for (unsigned int i = 0; i < particles.size(); ++i)
1653 {
1654 particles[i].fluid_viscous_forces =
1655 Utilities::MPI::sum(particles[i].fluid_viscous_forces,
1656 this->mpi_communicator) *
1657 fluid_density;
1658 particles[i].fluid_pressure_forces =
1659 Utilities::MPI::sum(particles[i].fluid_pressure_forces,
1660 this->mpi_communicator) *
1661 fluid_density;
1662 particles[i].fluid_forces =
1663 particles[i].fluid_viscous_forces + particles[i].fluid_pressure_forces;
1664 particles[i].fluid_torque =
1665 Utilities::MPI::sum(particles[i].fluid_torque, this->mpi_communicator) *
1666 fluid_density;
1667 }
1668}
1669
1670template <int dim>
1671void
1673{
1674 TimerOutput::Scope t(this->computing_timer,
1675 "Output forces on immersed boundary");
1676 for (unsigned int p = 0; p < particles.size(); ++p)
1677 {
1678 {
1679 if (this->this_mpi_process == 0)
1680 {
1681 std::string filename =
1682 this->simulation_parameters.simulation_control.output_folder +
1683 this->simulation_parameters.particlesParameters
1684 ->ib_force_output_file +
1685 "." + Utilities::int_to_string(p, 2) + ".dat";
1686 std::ofstream output(filename.c_str());
1687
1688 table_p[p].write_text(output);
1689 }
1690 MPI_Barrier(this->mpi_communicator);
1691 }
1692 }
1693}
1694
1695template <int dim>
1696std::vector<OutputStruct<dim, GlobalVectorType>>
1698{
1699 std::vector<OutputStruct<dim, GlobalVectorType>> solution_output_structs;
1700 // If the particles have moved, the combined shapes will have been cleared by
1701 // the particle integration routines.
1703 std::make_shared<LevelsetPostprocessor<dim>>(combined_shapes);
1704 solution_output_structs.emplace_back(
1706 *this->dof_handler,
1707 *this->present_solution,
1709
1710 Vector<float> cell_cuts(this->triangulation->n_active_cells());
1711 Vector<float> cell_overconstrained(this->triangulation->n_active_cells());
1712 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
1713 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
1714 // If the enable extra verbose output is activated we add an output field to
1715 // the results where we identify which particle cuts each cell of the domain.
1716 if (this->simulation_parameters.particlesParameters
1717 ->enable_extra_sharp_interface_vtu_output_field)
1718 {
1719 // Define cell iterator
1720 const auto &cell_iterator = this->dof_handler->active_cell_iterators();
1721 unsigned int i = 0;
1722
1723 for (const auto &cell : cell_iterator)
1724 {
1725 if (cell->is_locally_owned())
1726 {
1727 // Here we identify all cut cells, and if a cell is cut we output
1728 // the ID of the cell that cuts it. If the cell is not cut, a
1729 // default value of -1 is output.
1730 bool cell_is_cut;
1731 int particle_id;
1732 std::tie(cell_is_cut, particle_id, std::ignore) =
1733 cut_cells_map[cell];
1734 if (cell_is_cut)
1735 cell_cuts(i) = particle_id;
1736 else
1737 cell_cuts(i) = -1;
1738
1739 // Here we identify all overconstrained cells. If a cell is
1740 // overconstrained, we output the ID of the closest particle (the
1741 // one used for extrapolation of the velocity immersed boundary
1742 // condition). If the cell is not overconstrained, a default value
1743 // of -1 is output.
1744 bool cell_is_overconstrained;
1745 std::tie(cell_is_overconstrained, particle_id, std::ignore) =
1747 if (cell_is_overconstrained)
1748 cell_overconstrained(i) = particle_id;
1749 else
1750 cell_overconstrained(i) = -1;
1751 }
1752 i += 1;
1753 }
1754 solution_output_structs.emplace_back(
1755 std::in_place_type<OutputStructCellVector>, cell_cuts, "cell_cut");
1756 solution_output_structs.emplace_back(
1757 std::in_place_type<OutputStructCellVector>,
1758 cell_overconstrained,
1759 "overconstrained");
1760
1762 std::make_shared<LevelsetGradientPostprocessor<dim>>(combined_shapes);
1763 solution_output_structs.emplace_back(
1765 *this->dof_handler,
1766 *this->present_solution,
1768 }
1769 return solution_output_structs;
1770}
1771
1772template <int dim>
1773void
1775{
1776 bool enable =
1777 this->simulation_parameters.analytical_solution->calculate_error();
1778 this->simulation_parameters.analytical_solution->set_enable(false);
1780 this->simulation_parameters.analytical_solution->set_enable(enable);
1781 // Calculate the error with respect to the analytical solution
1782 if (!firstIter &&
1783 this->simulation_parameters.analytical_solution->calculate_error())
1784 {
1785 // Update the time of the exact solution to the actual time
1786 this->exact_solution->set_time(
1787 this->simulation_control->get_current_time());
1788 const std::pair<double, double> error =
1790
1791 if (this->simulation_parameters.simulation_control.method ==
1793 {
1794 this->error_table.add_value(
1795 "cells", this->triangulation->n_global_active_cells());
1796 this->error_table.add_value("error_velocity", error.first);
1797 this->error_table.add_value("error_pressure", error.second);
1798
1799 auto summary = this->computing_timer.get_summary_data(
1800 this->computing_timer.total_wall_time);
1801 double total_time = 0;
1802 for (auto it = summary.begin(); it != summary.end(); ++it)
1803 {
1804 total_time += summary[it->first];
1805 }
1806 this->error_table.add_value("total_time", total_time);
1807 }
1808 else
1809 {
1810 this->error_table.add_value(
1811 "time", this->simulation_control->get_current_time());
1812 this->error_table.add_value("error_velocity", error.first);
1813 this->error_table.add_value("error_pressure", error.second);
1814
1815 if (this->simulation_parameters.timer.write_time_in_error_table)
1816 {
1817 auto summary = this->computing_timer.get_summary_data(
1818 this->computing_timer.total_wall_time);
1819 double total_time = 0;
1820 for (auto it = summary.begin(); it != summary.end(); ++it)
1821 {
1822 total_time += summary[it->first];
1823 }
1824 this->error_table.add_value("total_time", total_time);
1825 }
1826 }
1827 if (this->simulation_parameters.analytical_solution->verbosity ==
1829 {
1830 this->pcout << "L2 error velocity : " << error.first
1831 << " L2 error pressure: " << error.second << std::endl;
1832 }
1833 }
1834}
1835
1836
1837template <int dim>
1838std::pair<double, double>
1840{
1841 TimerOutput::Scope t(this->computing_timer, "error");
1842 QGauss<dim> quadrature_formula(this->number_quadrature_points + 1);
1843 FEValues<dim> fe_values(*this->mapping,
1844 *this->fe,
1845 quadrature_formula,
1846 update_values | update_gradients |
1847 update_quadrature_points | update_JxW_values);
1848 FEFaceValues<dim> fe_face_values(*this->mapping,
1849 *this->fe,
1850 *this->face_quadrature,
1851 update_values | update_gradients |
1852 update_quadrature_points |
1853 update_JxW_values);
1854
1855 const FEValuesExtractors::Vector velocities(0);
1856 const FEValuesExtractors::Scalar pressure(dim);
1857
1858 const unsigned int dofs_per_cell =
1859 this->fe->dofs_per_cell; // This gives you DOFs per cell
1860 std::vector<types::global_dof_index> local_dof_indices(
1861 dofs_per_cell); // Local connectivity
1862
1863 const unsigned int n_q_points = quadrature_formula.size();
1864 const unsigned int n_q_points_face = this->face_quadrature->size();
1865
1866 std::vector<Vector<double>> q_exactSol(n_q_points, Vector<double>(dim + 1));
1867
1868 std::vector<Tensor<1, dim>> local_velocity_values(n_q_points);
1869 std::vector<Tensor<1, dim>> local_face_velocity_values(n_q_points_face);
1870 std::vector<double> local_pressure_values(n_q_points);
1871 std::vector<double> div_phi_u(dofs_per_cell);
1872 std::vector<Tensor<2, dim>> present_velocity_gradients(n_q_points);
1873
1874 Function<dim> *l_exact_solution = this->exact_solution;
1875
1876 std::map<types::global_dof_index, Point<dim>> support_points =
1877 DoFTools::map_dofs_to_support_points(*this->mapping, *this->dof_handler);
1878
1879 double l2errorU = 0.;
1880 double l2errorU_boundary = 0.;
1881 double l2errorP = 0.;
1882 double total_velocity_divergence = 0.;
1883 double pressure_integral = 0;
1884 double exact_pressure_integral = 0;
1885 double volume = 0;
1886
1887 // loop over elements
1888 typename DoFHandler<dim>::active_cell_iterator cell = this->dof_handler
1889 ->begin_active(),
1890 endc =
1891 this->dof_handler->end();
1892
1893 // loop over elements to calculate average pressure
1894 for (; cell != endc; ++cell)
1895 {
1896 if (cell->is_locally_owned())
1897 {
1898 bool cell_is_cut;
1899 // std::ignore is used because we don't care about what particle cut
1900 // the cell or the number of particles that cut the cell.
1901 std::tie(cell_is_cut, std::ignore, std::ignore) = cut_cells_map[cell];
1902 bool cell_is_inside;
1903 std::tie(cell_is_inside, std::ignore) = cells_inside_map[cell];
1904 bool cell_is_overconstrained;
1905 std::tie(cell_is_overconstrained, std::ignore, std::ignore) =
1907
1908 if ((!cell_is_cut && !cell_is_inside) && !cell_is_overconstrained)
1909 {
1910 auto &evaluation_point = this->evaluation_point;
1911 fe_values.reinit(cell);
1912
1913 fe_values[pressure].get_function_values(evaluation_point,
1914 local_pressure_values);
1915 // Get the exact solution at all gauss points
1916 l_exact_solution->vector_value_list(
1917 fe_values.get_quadrature_points(), q_exactSol);
1918
1919
1920 // Retrieve the effective "connectivity matrix" for this element
1921 cell->get_dof_indices(local_dof_indices);
1922
1923 for (unsigned int q = 0; q < n_q_points; q++)
1924 {
1925 pressure_integral +=
1926 local_pressure_values[q] * fe_values.JxW(q);
1927 exact_pressure_integral +=
1928 q_exactSol[q][dim] * fe_values.JxW(q);
1929 volume += fe_values.JxW(q);
1930 }
1931 }
1932 }
1933 }
1934
1935 pressure_integral =
1936 Utilities::MPI::sum(pressure_integral, this->mpi_communicator);
1937 exact_pressure_integral =
1938 Utilities::MPI::sum(exact_pressure_integral, this->mpi_communicator);
1939 volume = Utilities::MPI::sum(volume, this->mpi_communicator);
1940
1941
1942 double average_pressure = pressure_integral / volume;
1943 double average_exact_pressure = exact_pressure_integral / volume;
1944 cell = this->dof_handler->begin_active(), endc = this->dof_handler->end();
1945
1946 for (; cell != endc; ++cell)
1947 {
1948 if (cell->is_locally_owned())
1949 {
1950 cell->get_dof_indices(local_dof_indices);
1951
1952 bool cell_is_cut;
1953 // std::ignore is used because we don't care about what particle cut
1954 // the cell or the number of particles that cut the cell.
1955 std::tie(cell_is_cut, std::ignore, std::ignore) = cut_cells_map[cell];
1956
1957 bool cell_is_overconstrained;
1958 std::tie(cell_is_overconstrained, std::ignore, std::ignore) =
1960
1961 bool cell_is_inside;
1962 std::tie(cell_is_inside, std::ignore) = cells_inside_map[cell];
1963 if (cell->at_boundary() &&
1964 this->check_existance_of_bc(
1966 {
1967 for (const auto face : cell->face_indices())
1968 {
1969 if (cell->face(face)->at_boundary())
1970 {
1971 unsigned int boundary_id =
1972 cell->face(face)->boundary_id();
1973 if (this->simulation_parameters.boundary_conditions.type
1974 .at(boundary_id) ==
1976 function_weak)
1977 {
1979 &this->simulation_parameters.boundary_conditions
1980 .navier_stokes_functions.at(boundary_id)
1981 ->u,
1982 &this->simulation_parameters.boundary_conditions
1983 .navier_stokes_functions.at(boundary_id)
1984 ->v,
1985 &this->simulation_parameters.boundary_conditions
1986 .navier_stokes_functions.at(boundary_id)
1987 ->w);
1988
1989 fe_face_values.reinit(cell, face);
1990 fe_face_values[velocities].get_function_values(
1991 *this->present_solution,
1992 local_face_velocity_values);
1993 for (unsigned int q = 0; q < n_q_points_face; q++)
1994 {
1995 double u_x = local_face_velocity_values[q][0];
1996 double u_y = local_face_velocity_values[q][1];
1997
1998 double u_x_a = function_v.value(
1999 fe_face_values.quadrature_point(q), 0);
2000 double u_y_a = function_v.value(
2001 fe_face_values.quadrature_point(q), 1);
2002
2003 l2errorU_boundary +=
2004 ((u_x - u_x_a) * (u_x - u_x_a) +
2005 (u_y - u_y_a) * (u_y - u_y_a)) *
2006 fe_face_values.JxW(q);
2007 if constexpr (dim == 3)
2008 {
2009 double u_z = local_face_velocity_values[q][2];
2010 double u_z_a = function_v.value(
2011 fe_face_values.quadrature_point(q), 2);
2012 l2errorU_boundary += (u_z - u_z_a) *
2013 (u_z - u_z_a) *
2014 fe_face_values.JxW(q);
2015 }
2016 }
2017 }
2018 }
2019 }
2020 }
2021
2022 if (!cell_is_cut && !cell_is_overconstrained)
2023 {
2024 auto &evaluation_point = this->evaluation_point;
2025 auto &present_solution = *this->present_solution;
2026 fe_values.reinit(cell);
2027 fe_values[velocities].get_function_values(present_solution,
2028 local_velocity_values);
2029 fe_values[pressure].get_function_values(present_solution,
2030 local_pressure_values);
2031 fe_values[velocities].get_function_gradients(
2032 evaluation_point, present_velocity_gradients);
2033
2034
2035 // Retrieve the effective "connectivity matrix" for this element
2036 cell->get_dof_indices(local_dof_indices);
2037
2038 // Get the exact solution at all gauss points
2039 l_exact_solution->vector_value_list(
2040 fe_values.get_quadrature_points(), q_exactSol);
2041 for (unsigned int q = 0; q < n_q_points; q++)
2042 {
2043 double present_velocity_divergence =
2044 trace(present_velocity_gradients[q]);
2045 double mass_source =
2046 this->simulation_parameters.source_term
2047 .navier_stokes_source->value(
2048 fe_values.get_quadrature_points()[q], dim);
2049
2050
2051 // Find the values of x and u_h (the finite element solution)
2052 // at the quadrature points
2053 double ux_sim = local_velocity_values[q][0];
2054 double ux_exact = q_exactSol[q][0];
2055
2056 double uy_sim = local_velocity_values[q][1];
2057 double uy_exact = q_exactSol[q][1];
2058 l2errorU += (ux_sim - ux_exact) * (ux_sim - ux_exact) *
2059 fe_values.JxW(q);
2060 l2errorU += (uy_sim - uy_exact) * (uy_sim - uy_exact) *
2061 fe_values.JxW(q);
2062
2063 if constexpr (dim == 3)
2064 {
2065 double uz_sim = local_velocity_values[q][2];
2066 double uz_exact = q_exactSol[q][2];
2067 l2errorU += (uz_sim - uz_exact) * (uz_sim - uz_exact) *
2068 fe_values.JxW(q);
2069 }
2070 if (!cell_is_inside)
2071 {
2072 total_velocity_divergence +=
2073 (present_velocity_divergence - mass_source) *
2074 fe_values.JxW(q);
2075 double p_sim =
2076 local_pressure_values[q] - average_pressure;
2077 double p_exact =
2078 q_exactSol[q][dim] - average_exact_pressure;
2079 l2errorP += (p_sim - p_exact) * (p_sim - p_exact) *
2080 fe_values.JxW(q);
2081 }
2082 }
2083 }
2084 }
2085 }
2086 l2errorU = Utilities::MPI::sum(l2errorU, this->mpi_communicator);
2087 l2errorU_boundary =
2088 Utilities::MPI::sum(l2errorU_boundary, this->mpi_communicator);
2089 l2errorP = Utilities::MPI::sum(l2errorP, this->mpi_communicator);
2090 total_velocity_divergence =
2091 Utilities::MPI::sum(total_velocity_divergence, this->mpi_communicator);
2092
2093 this->pcout << "div u : " << total_velocity_divergence << std::endl;
2094 if (this->check_existance_of_bc(
2096 {
2097 this->pcout << "error at the weak BC : " << std::sqrt(l2errorU_boundary)
2098 << std::endl;
2099 }
2100
2101 return std::make_pair(std::sqrt(l2errorU), std::sqrt(l2errorP));
2102}
2103
2104
2105template <int dim>
2106void
2108 IBParticle<dim> &particle,
2109 const double time,
2110 const double dt) const
2111{
2112 if (this->simulation_parameters.particlesParameters
2113 ->load_particles_from_file == false)
2114 {
2115 particle.f_position->set_time(time);
2116 particle.f_velocity->set_time(time);
2117 particle.f_omega->set_time(time);
2118 particle.f_orientation->set_time(time);
2119
2120 particle.position[0] = particle.f_position->value(particle.position, 0);
2121 particle.position[1] = particle.f_position->value(particle.position, 1);
2122 particle.velocity[0] = particle.f_velocity->value(particle.position, 0);
2123 particle.velocity[1] = particle.f_velocity->value(particle.position, 1);
2124 particle.omega[0] = particle.f_omega->value(particle.position, 0);
2125 particle.omega[1] = particle.f_omega->value(particle.position, 1);
2126 particle.omega[2] = particle.f_omega->value(particle.position, 2);
2127 particle.orientation[0] =
2128 particle.f_orientation->value(particle.position, 0);
2129 particle.orientation[1] =
2130 particle.f_orientation->value(particle.position, 1);
2131 particle.orientation[2] =
2132 particle.f_orientation->value(particle.position, 2);
2133 if constexpr (dim == 3)
2134 {
2135 particle.position[2] =
2136 particle.f_position->value(particle.position, 2);
2137 particle.velocity[2] =
2138 particle.f_velocity->value(particle.position, 2);
2139 }
2140 }
2141 else
2142 {
2143 // The velocity and angular velocity of a particle loaded from a file are
2144 // constant. The new state is computed from the state at the start of the
2145 // time step, so that it does not change when this function is called at
2146 // each Newton iteration.
2147 for (int d = 0; d < dim; ++d)
2148 particle.position[d] =
2149 particle.previous_positions[0][d] + particle.velocity[d] * dt;
2150 particle.orientation =
2151 particle.previous_orientation[0] + particle.omega * dt;
2152 }
2153}
2154
2155
2156template <int dim>
2157void
2159{
2161
2162 TimerOutput::Scope t(this->computing_timer, "Integrate particles");
2163 // Integrate the velocity of the particle. If integrate motion is set to
2164 // true in the parameter this function will also integrate the force to update
2165 // the velocity. Otherwise, the velocity is kept constant
2166
2167 // To integrate the forces and update the velocity, this function uses the
2168 // implicit Euler algorithm. To find the force at t+dt the function use the
2169 // fix point algorithm in parallel to the newton iteration used for the fluid
2170 // resolution.
2171 using dealii::numbers::PI;
2172 double dt = this->simulation_control->get_time_steps_vector()[0];
2173 double time = this->simulation_control->get_current_time();
2174 double alpha = this->simulation_parameters.particlesParameters->alpha;
2175 this->simulation_parameters.particlesParameters->f_gravity->set_time(time);
2176 double dr = GridTools::minimal_cell_diameter(*this->triangulation) /
2177 std::numbers::sqrt2;
2178
2179 const auto rheological_model =
2180 this->simulation_parameters.physical_properties_manager.get_rheology();
2181
2182 ib_dem.update_particles(particles, time - dt);
2183
2184 std::map<field, double> field_values;
2185 field_values[field::shear_rate] = 1;
2186 field_values[field::temperature] = 1;
2187
2188 // Check if the parameters' combination is compatible. This is temporary and
2189 // will be moved to a new class that tests the parameter combination in the
2190 // parameter initialization.
2191
2192 AssertThrow(!(this->simulation_parameters.physical_properties_manager
2193 .is_non_newtonian() and
2194 this->simulation_parameters.particlesParameters
2195 ->enable_lubrication_force and
2197 RequiresConstantViscosity(
2198 "FluidDynamicsSharp<dim>::integrate_particles"));
2199
2200 double h_min =
2201 dr * this->simulation_parameters.particlesParameters->lubrication_range_min;
2202 double h_max =
2203 dr * this->simulation_parameters.particlesParameters->lubrication_range_max;
2204 // Deactivated the lubrication force if the fluid is Non-newtonian.
2205 if (this->simulation_parameters.particlesParameters
2206 ->enable_lubrication_force == false)
2207 h_max = 0;
2208
2210 if (some_particles_are_coupled && time > 0)
2211 {
2212 AssertThrow(this->simulation_parameters.physical_properties_manager
2213 .density_is_constant(),
2214 RequiresConstantDensity(
2215 "FluidDynamicsSharp<dim>::integrate_particles"));
2216 auto density_model =
2217 this->simulation_parameters.physical_properties_manager.get_density(0);
2218 double fluid_density = density_model->value(field_values);
2219 double kinematic_viscosity =
2220 rheological_model->value(field_values) * fluid_density;
2221
2222 Vector<double> particles_residual_vect;
2223 particles_residual_vect.reinit(particles.size());
2224 Tensor<1, 3> g;
2225 this->simulation_parameters.particlesParameters->f_gravity->set_time(
2226 time);
2227 unsigned int current_newton_iteration =
2229
2230 // Do the DEM only if it’s the first newton iteration or both the
2231 // explicit calculation of the impulsion and position are false.
2232 if (current_newton_iteration == 0 ||
2233 (this->simulation_parameters.particlesParameters
2234 ->explicit_contact_impulsion_calculation == false and
2235 this->simulation_parameters.particlesParameters
2236 ->explicit_position_integration_calculation == false))
2237 {
2238 ib_dem.integrate_particles_motion(
2239 dt, h_max, h_min, fluid_density, kinematic_viscosity);
2240 }
2241
2242 unsigned int worst_residual_particle_id = UINT_MAX;
2243
2244 bool clear_combined_shape_cache = false;
2245
2246 for (unsigned int p = 0; p < particles.size(); ++p)
2247 {
2248 if (particles[p].integrate_motion)
2249 {
2250 // If the motion of a single particle is to be integrated, the
2251 // combined cache should be cleared after the integration.
2252 // Otherwise, the visualization of the level set will be wrong.
2253 clear_combined_shape_cache = true;
2254
2255 // calculate the volume of fluid displaced by the particle.
2256 double volume = particles[p].volume;
2257
2258 g[0] = this->simulation_parameters.particlesParameters->f_gravity
2259 ->value(particles[p].position, 0);
2260 g[1] = this->simulation_parameters.particlesParameters->f_gravity
2261 ->value(particles[p].position, 1);
2262 if constexpr (dim == 3)
2263 g[2] = this->simulation_parameters.particlesParameters
2264 ->f_gravity->value(particles[p].position, 2);
2265
2266 Tensor<1, 3> gravity_buoyancy_force =
2267 g * (particles[p].mass / volume - fluid_density) * volume;
2268
2269 // Transfers the impulsion evaluated in the sub-time-stepping
2270 // scheme to the particle at the CFD timescale.
2271 particles[p].impulsion = ib_dem.dem_particles[p].impulsion;
2272 particles[p].omega_impulsion =
2273 ib_dem.dem_particles[p].omega_impulsion;
2274 particles[p].contact_impulsion =
2275 ib_dem.dem_particles[p].contact_impulsion;
2276 particles[p].omega_contact_impulsion =
2277 ib_dem.dem_particles[p].omega_contact_impulsion;
2278 // Time stepping information
2279 const auto method =
2280 this->simulation_control->get_assembly_method();
2281 std::vector<double> time_steps_vector =
2282 this->simulation_control->get_time_steps_vector();
2283
2284 // Vector for the BDF coefficients
2285 const Vector<double> &bdf_coefs =
2286 this->simulation_control->get_bdf_coefficients();
2287
2288 // Define the residual of the particle dynamics.
2289 Tensor<1, 3> residual_velocity =
2290 -(bdf_coefs[0] * particles[p].velocity);
2291
2292 for (unsigned int i = 1;
2293 i < number_of_previous_solutions(method) + 1;
2294 ++i)
2295 {
2296 residual_velocity +=
2297 -(bdf_coefs[i] * particles[p].previous_velocity[i - 1]);
2298 }
2299 residual_velocity +=
2300 (particles[p].contact_impulsion / dt +
2301 particles[p].fluid_forces + gravity_buoyancy_force) /
2302 particles[p].mass;
2303
2304 double inverse_of_relaxation_coefficient_velocity =
2305 -bdf_coefs[0] -
2306 0.5 * volume * fluid_density / particles[p].mass / dt + DBL_MIN;
2307
2308 // Evaluate the relaxation parameter using a generalization of the
2309 // secant method.
2310 if (particles[p].previous_velocity_residual.norm() != 0)
2311 {
2312 auto vector_of_velocity_variation =
2313 (particles[p].velocity - particles[p].velocity_iter);
2314 auto vector_of_residual_variation =
2315 residual_velocity - particles[p].previous_velocity_residual;
2316 double dot_product_of_the_variation_vectors =
2317 scalar_product(vector_of_velocity_variation,
2318 vector_of_residual_variation);
2319 inverse_of_relaxation_coefficient_velocity =
2320 1 / (dot_product_of_the_variation_vectors /
2321 (vector_of_residual_variation.norm_square()) +
2322 DBL_MIN);
2323 }
2324 // Relaxation parameter for the particle dynamics.
2325 double local_alpha = 1.;
2326 // We keep in memory the state of the particle before the update
2327 // in case something went wrong and the particle is now outside of
2328 // the domain. If this is the case, the particle won't be updated.
2329 IBParticle<dim> save_particle_state = particles[p];
2330 bool save_particle_state_is_used = false;
2331 // Define the correction vector.
2332 Tensor<1, 3> velocity_correction_vector;
2333 // Define the correction vector. And check if it is not NAN. NAN
2334 // happen when the residual tends to zero in cases where the fluid
2335 // density is 0.
2336 if (inverse_of_relaxation_coefficient_velocity ==
2337 inverse_of_relaxation_coefficient_velocity)
2338 {
2339 velocity_correction_vector =
2340 residual_velocity * 1. /
2341 inverse_of_relaxation_coefficient_velocity;
2342 }
2343 else
2344 velocity_correction_vector = residual_velocity;
2345
2346 // Update the particle state and keep in memory the last iteration
2347 // information.
2348 particles[p].velocity_iter = particles[p].velocity;
2349 particles[p].velocity =
2350 particles[p].velocity_iter -
2351 velocity_correction_vector * alpha * local_alpha;
2352 particles[p].impulsion_iter = particles[p].impulsion;
2353 particles[p].previous_velocity_residual = residual_velocity;
2354
2355 // If the particles have impacted a wall or another particle, we
2356 // want to use the sub-time step position. Otherwise, we solve the
2357 // new position directly with the new velocity found.
2358 if (particles[p].contact_impulsion.norm() < 1e-12 and
2359 (this->simulation_parameters.particlesParameters
2360 ->explicit_position_integration_calculation == false))
2361 {
2362 particles[p].position.clear();
2363 for (int d = 0; d < dim; ++d)
2364 {
2365 for (unsigned int i = 1;
2366 i < number_of_previous_solutions(method) + 1;
2367 ++i)
2368 {
2369 double position_update =
2370 -bdf_coefs[i] *
2371 particles[p].previous_positions[i - 1][d] /
2372 bdf_coefs[0];
2373
2374 particles[p].set_position(particles[p].position[d] +
2375 position_update,
2376 d);
2377 }
2378
2379 double position_update =
2380 particles[p].velocity[d] / bdf_coefs[0];
2381 particles[p].set_position(particles[p].position[d] +
2382 position_update,
2383 d);
2384 }
2385 }
2386 else
2387 {
2388 particles[p].position = ib_dem.dem_particles[p].position;
2389 particles[p].set_position(particles[p].position);
2390 }
2391 // Check if the particle is in the domain. Throw an error if it's
2392 // the case.
2393 try
2394 {
2395 const auto &cell =
2397 *this->dof_handler, particles[p].position);
2398 (void)cell;
2399 }
2400 catch (...)
2401 {
2402 this->pcout
2403 << "particle " << p
2404 << " is now outside the domain we do not update this particle. Position: "
2405 << particles[p].position[0] << ", "
2406 << particles[p].position[1];
2407 if constexpr (dim == 3)
2408 this->pcout << ", " << particles[p].position[2];
2409 this->pcout << std::endl;
2410 save_particle_state_is_used = true;
2411 }
2412
2413 // For the rotation velocity : same logic as the velocity.
2414 auto inv_inertia = invert(particles[p].inertia);
2415
2416 // Calculate the torque in the particle frame of reference.
2417 Tensor<1, 3> total_torque =
2418 particles[p].rotation_matrix *
2419 (particles[p].omega_contact_impulsion / dt +
2420 particles[p].fluid_torque);
2421
2422 // Calculate angular acceleration in particle frame
2423 Tensor<1, 3> angular_velocity_in_particle_frame =
2424 particles[p].rotation_matrix * particles[p].omega;
2425 Tensor<1, 3> angular_acceleration_in_particle_frame;
2426 angular_acceleration_in_particle_frame[0] =
2427 (total_torque[0] -
2428 (particles[p].inertia[2][2] - particles[p].inertia[1][1]) *
2429 angular_velocity_in_particle_frame[2] *
2430 angular_velocity_in_particle_frame[1]) /
2431 particles[p].inertia[0][0];
2432 angular_acceleration_in_particle_frame[1] =
2433 (total_torque[1] -
2434 (particles[p].inertia[0][0] - particles[p].inertia[2][2]) *
2435 angular_velocity_in_particle_frame[2] *
2436 angular_velocity_in_particle_frame[0]) /
2437 particles[p].inertia[1][1];
2438 angular_acceleration_in_particle_frame[2] =
2439 (total_torque[2] -
2440 (particles[p].inertia[1][1] - particles[p].inertia[0][0]) *
2441 angular_velocity_in_particle_frame[0] *
2442 angular_velocity_in_particle_frame[1]) /
2443 particles[p].inertia[2][2];
2444
2445 // Evaluate the residual
2446 Tensor<1, 3> residual_omega =
2447 -(bdf_coefs[0] * particles[p].omega);
2448 for (unsigned int i = 1;
2449 i < number_of_previous_solutions(method) + 1;
2450 ++i)
2451 {
2452 residual_omega +=
2453 -(bdf_coefs[i] * particles[p].previous_omega[i - 1]);
2454 }
2455 // Rotate angular acceleration in world frame
2456 residual_omega += // omega_accel
2457 invert(particles[p].rotation_matrix) *
2458 angular_acceleration_in_particle_frame;
2459
2460
2461 double inverse_of_relaxation_coefficient_omega =
2462 -bdf_coefs[0] - 0.5 * 2. / 5 * volume * fluid_density *
2463 particles[p].radius * particles[p].radius *
2464 inv_inertia.norm() / dt;
2465 // Evaluate the relaxation parameter using a generalization of the
2466 // secant method.
2467 if (particles[p].previous_omega_residual.norm() != 0)
2468 {
2469 auto vector_of_omega_variation =
2470 (particles[p].omega - particles[p].omega_iter);
2471 auto vector_of_residual_variation =
2472 residual_omega - particles[p].previous_omega_residual;
2473
2474 double dot_product_of_the_variation_vectors =
2475 scalar_product(vector_of_omega_variation,
2476 vector_of_residual_variation);
2477 inverse_of_relaxation_coefficient_omega =
2478 1 / (dot_product_of_the_variation_vectors /
2479 (vector_of_residual_variation.norm_square()) +
2480 DBL_MIN);
2481 }
2482 // Define the correction vector. And check if it is not NAN. NAN
2483 // happen when the residual tends to zero in cases where the fluid
2484 // density is 0.
2485 Tensor<1, 3> omega_correction_vector;
2486 if (inverse_of_relaxation_coefficient_omega ==
2487 inverse_of_relaxation_coefficient_omega)
2488 {
2489 omega_correction_vector =
2490 residual_omega * 1 /
2491 inverse_of_relaxation_coefficient_omega;
2492 }
2493 else
2494 {
2495 omega_correction_vector = residual_omega;
2496 }
2497
2498 double local_alpha_omega = 1;
2499
2500 particles[p].omega_iter = particles[p].omega;
2501 particles[p].omega =
2502 particles[p].omega_iter -
2503 omega_correction_vector * alpha * local_alpha_omega;
2504 particles[p].omega_impulsion_iter = particles[p].omega_impulsion;
2505 particles[p].previous_omega_residual = residual_omega;
2506
2507 // If the particles have impacted a wall or another particle, we
2508 // want to use the sub-time step position. Otherwise, we solve the
2509 // new position directly with the new velocity found.
2510 if (particles[p].omega_contact_impulsion.norm() < 1e-12 and
2511 (this->simulation_parameters.particlesParameters
2512 ->explicit_position_integration_calculation == false))
2513 {
2514 if (particles[p].omega.norm() > 0)
2515 {
2516 // Impose a new orientation of the particle based on the
2517 // integration and previous orientation.
2518 particles[p].rotation_matrix = 0;
2519 particles[p].rotation_matrix[0][0] = 1.0;
2520 particles[p].rotation_matrix[1][1] = 1.0;
2521 particles[p].rotation_matrix[2][2] = 1.0;
2522 if constexpr (dim == 2)
2523 {
2524 Tensor<1, 3> axis;
2525 axis[2] = 1.0;
2526 particles[p].rotation_matrix = Physics::
2527 Transformations::Rotations::rotation_matrix_3d(
2528 axis, particles[p].previous_orientation[0][2]);
2529 }
2530 if constexpr (dim == 3)
2531 {
2532 for (unsigned int i = 0; i < 3; ++i)
2533 {
2534 Tensor<1, 3> axis;
2535 axis[2 - i] = 1.0;
2536 particles[p].rotation_matrix =
2537 Physics::Transformations::Rotations::
2538 rotation_matrix_3d(
2539 axis,
2540 particles[p]
2541 .previous_orientation[0][2 - i]) *
2542 particles[p].rotation_matrix;
2543 }
2544 }
2545 particles[p].rotation_matrix =
2546 Physics::Transformations::Rotations::rotation_matrix_3d(
2547 particles[p].omega / particles[p].omega.norm(),
2548 particles[p].omega.norm() * dt) *
2549 particles[p].rotation_matrix;
2550 particles[p].orientation =
2551 particles[p].shape->rotation_matrix_to_xyz_angles(
2552 particles[p].rotation_matrix);
2553 }
2554 }
2555 else
2556 {
2557 // We have contact so we impose the DEM orientation as the new
2558 // orientation.
2559 particles[p].orientation =
2560 ib_dem.dem_particles[p].orientation;
2561 particles[p].set_orientation(particles[p].orientation);
2562 }
2563 // If something went wrong during the update, the particle's state
2564 // would be reversed to its original state here.
2565 if (save_particle_state_is_used)
2566 particles[p] = save_particle_state;
2567
2568 // Evaluate global residual of the particle dynamics.
2569 double this_particle_residual =
2570 sqrt(std::pow(residual_velocity.norm(), 2) +
2571 std::pow(residual_omega.norm() * particles[p].radius, 2)) *
2572 dt;
2573
2574 // Keep in memory the residual.
2575 particles_residual_vect[p] = this_particle_residual;
2576 // L_inf of all the particles' residual.
2577 if (this_particle_residual > particle_residual)
2578 {
2579 particle_residual = this_particle_residual;
2580 worst_residual_particle_id = p;
2581 }
2582 particles[p].set_position(particles[p].position);
2583 particles[p].set_orientation(particles[p].orientation);
2584 }
2585 else
2586 {
2588 if (particles[p].position != particles[p].previous_positions[0] ||
2589 particles[p].orientation !=
2590 particles[p].previous_orientation[0])
2591 {
2592 particles[p].clear_shape_cache();
2593 // One particle has moved significantly: the combined shape
2594 // cache should be cleared for visualization purposes.
2595 clear_combined_shape_cache = true;
2596 }
2597
2598 particles[p].set_position(particles[p].position);
2599 particles[p].set_orientation(particles[p].orientation);
2600 }
2601 }
2602
2603 if (clear_combined_shape_cache)
2604 combined_shapes->clear_cache();
2605
2606 if (this->simulation_parameters.physics_solving_strategy
2608 .verbosity != Parameters::Verbosity::quiet)
2609 {
2610 this->pcout << "L_inf particle residual : " << particle_residual
2611 << " particle id : " << worst_residual_particle_id
2612 << std::endl;
2613 this->pcout << "L2 particle residual L2 "
2614 << particles_residual_vect.l2_norm() << std::endl;
2615 }
2616 }
2617 else
2618 {
2619 // Direct application of the function for the velocity and position if the
2620 // particle dynamics is not integrated.
2621 for (unsigned int p = 0; p < particles.size(); ++p)
2622 {
2624 if (particles[p].position != particles[p].previous_positions[0] ||
2625 particles[p].orientation != particles[p].previous_orientation[0])
2626 particles[p].clear_shape_cache();
2627
2628 particles[p].set_position(particles[p].position);
2629 particles[p].set_orientation(particles[p].orientation);
2630 }
2632 }
2633}
2634
2635
2636
2637template <int dim>
2638void
2640 std::vector<IBParticle<dim>> particles)
2641{
2642 properties_to_write = particles[0].get_properties_name();
2643 // A list of field names for all data components stored in patches.
2644 vector_datasets.clear();
2645 dataset_names.clear();
2646 // Defining property field position
2647 int field_position = 0;
2648 // Iterating over properties
2649 for (const auto &properties_iterator : properties_to_write)
2650 {
2651 // Get the property field name
2652 const std::string field_name = properties_iterator.first;
2653
2654 // Number of components of the corresponding property
2655 const unsigned components_number = properties_iterator.second;
2656
2657 // Check to see if the property is a vector
2658 if (components_number == 3)
2659 {
2660 vector_datasets.emplace_back(
2661 field_position,
2662 field_position + components_number - 1,
2663 field_name,
2664 DataComponentInterpretation::component_is_part_of_vector);
2665 }
2666 dataset_names.push_back(field_name);
2667 ++field_position;
2668 }
2669
2670 // Building the patch data
2671 patches.resize(particles.size());
2672
2673 // Looping over particle to get the properties from the particle_handler
2674 for (unsigned int p = 0; p < particles.size(); ++p)
2675 {
2676 // Particle location
2677 patches[p].vertices[0] = particles[p].position;
2678 patches[p].patch_index = p;
2679 patches[p].data.reinit(particles[p].get_number_properties(), 1);
2680
2681 // ID and other properties
2682
2683 // Calculating force for visualization
2684 auto particle_properties = particles[p].get_properties();
2685
2686 for (unsigned int property_index = 0;
2687 property_index < particles[p].get_number_properties();
2688 ++property_index)
2689 patches[p].data(property_index, 0) =
2690 particle_properties[property_index];
2691 }
2692}
2693
2694template <int dim>
2695const std::vector<DataOutBase::Patch<0, dim>> &
2700
2701template <int dim>
2702std::vector<std::string>
2707
2708template <int dim>
2709std::vector<
2710 std::tuple<unsigned int,
2711 unsigned int,
2712 std::string,
2713 DataComponentInterpretation::DataComponentInterpretation>>
2718
2719template <int dim>
2721
2722template <int dim>
2723void
2725{
2726 // Store information about the particle used for the integration and print the
2727 // results if requested.
2728
2729 table_all_p.clear();
2730 for (unsigned int p = 0; p < particles.size(); ++p)
2731 {
2732 for (unsigned int i = particles[p].previous_velocity.size() - 1; i > 0;
2733 --i)
2734 {
2735 particles[p].previous_positions[i] =
2736 particles[p].previous_positions[i - 1];
2737 particles[p].previous_velocity[i] =
2738 particles[p].previous_velocity[i - 1];
2739 particles[p].previous_orientation[i] =
2740 particles[p].previous_orientation[i - 1];
2741 particles[p].previous_omega[i] = particles[p].previous_omega[i - 1];
2742 }
2743
2744 particles[p].previous_positions[0] = particles[p].position;
2745 particles[p].previous_velocity[0] = particles[p].velocity;
2746 particles[p].previous_omega[0] = particles[p].omega;
2747 particles[p].previous_orientation[0] = particles[p].orientation;
2748
2749 particles[p].previous_fluid_forces = particles[p].fluid_forces;
2750 particles[p].previous_fluid_viscous_forces =
2751 particles[p].fluid_viscous_forces;
2752 particles[p].previous_fluid_pressure_forces =
2753 particles[p].fluid_pressure_forces;
2754 particles[p].previous_fluid_torque = particles[p].fluid_torque;
2755
2756 particles[p].velocity_iter = particles[p].velocity;
2757 particles[p].impulsion_iter = particles[p].impulsion;
2758 particles[p].omega_iter = particles[p].omega;
2759 particles[p].omega_impulsion_iter = particles[p].omega_impulsion;
2760 particles[p].previous_velocity_residual = 0;
2761 particles[p].previous_omega_residual = 0;
2762
2764 this->simulation_parameters.particlesParameters->print_dem)
2765 {
2766 this->pcout << "particle " << p << " position "
2767 << particles[p].position << std::endl;
2768 if constexpr (dim == 2)
2769 {
2770 this->pcout << "particle " << p << " velocity "
2772 << std::endl;
2773 }
2774 else
2775 {
2776 this->pcout << "particle " << p << " velocity "
2777 << particles[p].velocity << std::endl;
2778 }
2779 }
2780 table_p[p].add_value("particle_ID", p);
2781 table_all_p.add_value("particle_ID", p);
2782 if (this->simulation_parameters.simulation_control.method !=
2784 table_p[p].add_value("time",
2785 this->simulation_control->get_current_time());
2786 table_all_p.add_value("time",
2787 this->simulation_control->get_current_time());
2788 if constexpr (dim == 3)
2789 {
2790 table_p[p].add_value("T_x", particles[p].fluid_torque[0]);
2791 table_p[p].set_precision(
2792 "T_x",
2793 this->simulation_parameters.simulation_control.log_precision);
2794 table_all_p.add_value("T_x", particles[p].fluid_torque[0]);
2795 table_all_p.set_precision(
2796 "T_x",
2797 this->simulation_parameters.simulation_control.log_precision);
2799 {
2800 table_p[p].add_value("omega_x", particles[p].omega[0]);
2801 table_p[p].set_precision(
2802 "omega_x",
2803 this->simulation_parameters.simulation_control.log_precision);
2804 table_p[p].add_value("theta_x", particles[p].orientation[0]);
2805 table_p[p].set_precision(
2806 "theta_x",
2807 this->simulation_parameters.simulation_control.log_precision);
2808 table_all_p.add_value("omega_x", particles[p].omega[0]);
2809 table_all_p.set_precision(
2810 "omega_x",
2811 this->simulation_parameters.simulation_control.log_precision);
2812 table_all_p.add_value("theta_x", particles[p].orientation[0]);
2813 table_all_p.set_precision(
2814 "theta_x",
2815 this->simulation_parameters.simulation_control.log_precision);
2816 }
2817
2818 table_p[p].add_value("T_y", particles[p].fluid_torque[1]);
2819 table_p[p].set_precision(
2820 "T_y",
2821 this->simulation_parameters.simulation_control.log_precision);
2822 table_all_p.add_value("T_y", particles[p].fluid_torque[1]);
2823 table_all_p.set_precision(
2824 "T_y",
2825 this->simulation_parameters.simulation_control.log_precision);
2827 {
2828 table_p[p].add_value("omega_y", particles[p].omega[1]);
2829 table_p[p].set_precision(
2830 "omega_y",
2831 this->simulation_parameters.simulation_control.log_precision);
2832 table_p[p].add_value("theta_y", particles[p].orientation[1]);
2833 table_p[p].set_precision(
2834 "theta_y",
2835 this->simulation_parameters.simulation_control.log_precision);
2836 table_all_p.add_value("omega_y", particles[p].omega[1]);
2837 table_all_p.set_precision(
2838 "omega_y",
2839 this->simulation_parameters.simulation_control.log_precision);
2840 table_all_p.add_value("theta_y", particles[p].orientation[1]);
2841 table_all_p.set_precision(
2842 "theta_y",
2843 this->simulation_parameters.simulation_control.log_precision);
2844 }
2845 }
2846
2847 table_p[p].add_value("T_z", particles[p].fluid_torque[2]);
2848 table_p[p].set_precision(
2849 "T_z", this->simulation_parameters.simulation_control.log_precision);
2850 table_all_p.add_value("T_z", particles[p].fluid_torque[2]);
2851 table_all_p.set_precision(
2852 "T_z", this->simulation_parameters.simulation_control.log_precision);
2854 {
2855 table_p[p].add_value("omega_z", particles[p].omega[2]);
2856 table_p[p].set_precision(
2857 "omega_z",
2858 this->simulation_parameters.simulation_control.log_precision);
2859 table_p[p].add_value("theta_z", particles[p].orientation[2]);
2860 table_p[p].set_precision(
2861 "theta_z",
2862 this->simulation_parameters.simulation_control.log_precision);
2863 table_all_p.add_value("omega_z", particles[p].omega[2]);
2864 table_all_p.set_precision(
2865 "omega_z",
2866 this->simulation_parameters.simulation_control.log_precision);
2867 table_all_p.add_value("theta_z", particles[p].orientation[2]);
2868 table_all_p.set_precision(
2869 "theta_z",
2870 this->simulation_parameters.simulation_control.log_precision);
2871 }
2872
2873 table_p[p].add_value("f_x", particles[p].fluid_forces[0]);
2874 table_all_p.add_value("f_x", particles[p].fluid_forces[0]);
2875 table_p[p].set_precision(
2876 "f_x", this->simulation_parameters.simulation_control.log_precision);
2877 table_all_p.set_precision(
2878 "f_x", this->simulation_parameters.simulation_control.log_precision);
2880 {
2881 table_p[p].add_value("v_x", particles[p].velocity[0]);
2882 table_p[p].add_value("p_x", particles[p].position[0]);
2883 table_all_p.add_value("v_x", particles[p].velocity[0]);
2884 table_all_p.add_value("p_x", particles[p].position[0]);
2885 table_p[p].set_precision(
2886 "v_x",
2887 this->simulation_parameters.simulation_control.log_precision);
2888
2889 table_p[p].set_precision(
2890 "p_x",
2891 this->simulation_parameters.simulation_control.log_precision);
2892 table_all_p.set_precision(
2893 "v_x",
2894 this->simulation_parameters.simulation_control.log_precision);
2895 table_all_p.set_precision(
2896 "p_x",
2897 this->simulation_parameters.simulation_control.log_precision);
2898 }
2899
2900 table_p[p].add_value("f_y", particles[p].fluid_forces[1]);
2901 table_p[p].set_precision(
2902 "f_y", this->simulation_parameters.simulation_control.log_precision);
2903 table_all_p.add_value("f_y", particles[p].fluid_forces[1]);
2904 table_all_p.set_precision(
2905 "f_y", this->simulation_parameters.simulation_control.log_precision);
2907 {
2908 table_p[p].add_value("v_y", particles[p].velocity[1]);
2909 table_p[p].add_value("p_y", particles[p].position[1]);
2910 table_all_p.add_value("v_y", particles[p].velocity[1]);
2911 table_all_p.add_value("p_y", particles[p].position[1]);
2912 table_p[p].set_precision(
2913 "v_y",
2914 this->simulation_parameters.simulation_control.log_precision);
2915 table_p[p].set_precision(
2916 "p_y",
2917 this->simulation_parameters.simulation_control.log_precision);
2918 table_all_p.set_precision(
2919 "v_y",
2920 this->simulation_parameters.simulation_control.log_precision);
2921 table_all_p.set_precision(
2922 "p_y",
2923 this->simulation_parameters.simulation_control.log_precision);
2924 }
2925
2926 if constexpr (dim == 3)
2927 {
2928 table_p[p].add_value("f_z", particles[p].fluid_forces[2]);
2929 table_p[p].set_precision(
2930 "f_z",
2931 this->simulation_parameters.simulation_control.log_precision);
2932 table_all_p.add_value("f_z", particles[p].fluid_forces[2]);
2933 table_all_p.set_precision(
2934 "f_z",
2935 this->simulation_parameters.simulation_control.log_precision);
2937 {
2938 table_p[p].add_value("v_z", particles[p].velocity[2]);
2939 table_p[p].add_value("p_z", particles[p].position[2]);
2940 table_all_p.add_value("v_z", particles[p].velocity[2]);
2941 table_all_p.add_value("p_z", particles[p].position[2]);
2942 table_p[p].set_precision(
2943 "v_z",
2944 this->simulation_parameters.simulation_control.log_precision);
2945 table_p[p].set_precision(
2946 "p_z",
2947 this->simulation_parameters.simulation_control.log_precision);
2948 table_all_p.set_precision(
2949 "v_z",
2950 this->simulation_parameters.simulation_control.log_precision);
2951 table_all_p.set_precision(
2952 "p_z",
2953 this->simulation_parameters.simulation_control.log_precision);
2954 }
2955 }
2956
2957 table_p[p].add_value("f_xv", particles[p].fluid_viscous_forces[0]);
2958 table_all_p.add_value("f_xv", particles[p].fluid_viscous_forces[0]);
2959 table_p[p].add_value("f_yv", particles[p].fluid_viscous_forces[1]);
2960 table_all_p.add_value("f_yv", particles[p].fluid_viscous_forces[1]);
2961
2962 table_p[p].set_precision(
2963 "f_xv", this->simulation_parameters.simulation_control.log_precision);
2964 table_p[p].set_precision(
2965 "f_yv", this->simulation_parameters.simulation_control.log_precision);
2966 table_all_p.set_precision(
2967 "f_xv", this->simulation_parameters.simulation_control.log_precision);
2968 table_all_p.set_precision(
2969 "f_yv", this->simulation_parameters.simulation_control.log_precision);
2970 if constexpr (dim == 3)
2971 {
2972 table_p[p].add_value("f_zv", particles[p].fluid_viscous_forces[2]);
2973 table_all_p.add_value("f_zv", particles[p].fluid_viscous_forces[2]);
2974 table_p[p].set_precision(
2975 "f_zv",
2976 this->simulation_parameters.simulation_control.log_precision);
2977 table_all_p.set_precision(
2978 "f_zv",
2979 this->simulation_parameters.simulation_control.log_precision);
2980 }
2981
2982 table_p[p].add_value("f_xp", particles[p].fluid_pressure_forces[0]);
2983 table_all_p.add_value("f_xp", particles[p].fluid_pressure_forces[0]);
2984 table_p[p].add_value("f_yp", particles[p].fluid_pressure_forces[1]);
2985 table_all_p.add_value("f_yp", particles[p].fluid_pressure_forces[1]);
2986 table_p[p].set_precision(
2987 "f_xp", this->simulation_parameters.simulation_control.log_precision);
2988 table_p[p].set_precision(
2989 "f_yp", this->simulation_parameters.simulation_control.log_precision);
2990 table_all_p.set_precision(
2991 "f_xp", this->simulation_parameters.simulation_control.log_precision);
2992 table_all_p.set_precision(
2993 "f_yp", this->simulation_parameters.simulation_control.log_precision);
2994 if constexpr (dim == 3)
2995 {
2996 table_p[p].add_value("f_zp", particles[p].fluid_pressure_forces[2]);
2997 table_all_p.add_value("f_zp", particles[p].fluid_pressure_forces[2]);
2998 table_p[p].set_precision(
2999 "f_zp",
3000 this->simulation_parameters.simulation_control.log_precision);
3001 table_all_p.set_precision(
3002 "f_zp",
3003 this->simulation_parameters.simulation_control.log_precision);
3004 }
3005 }
3006 if (this->this_mpi_process == 0)
3007 {
3008 if (this->simulation_parameters.forces_parameters.verbosity ==
3010 {
3011 std::cout << "+------------------------------------------+"
3012 << std::endl;
3013 std::cout << "| Force summary particles "
3014 << " |" << std::endl;
3015 std::cout << "+------------------------------------------+"
3016 << std::endl;
3017 table_all_p.write_text(std::cout);
3018 }
3019 }
3020}
3021
3022template <int dim>
3023void
3025 const IBParticle<dim> &particle,
3026 std::vector<double> &properties) const
3027{
3028 using PropertiesIndex = DEM::CFDDEMProperties::PropertiesIndex;
3029
3030 properties.assign(PropertiesIndex::n_properties, 0.);
3031
3032 properties[PropertiesIndex::type] = 0.;
3033 properties[PropertiesIndex::dp] = 2.0 * particle.radius;
3034 properties[PropertiesIndex::mass] = particle.mass;
3035
3036 properties[PropertiesIndex::v_x] = particle.velocity[0];
3037 properties[PropertiesIndex::v_y] = particle.velocity[1];
3038 properties[PropertiesIndex::omega_x] = particle.omega[0];
3039 properties[PropertiesIndex::omega_y] = particle.omega[1];
3040 properties[PropertiesIndex::omega_z] = particle.omega[2];
3041
3042 properties[PropertiesIndex::fem_force_two_way_coupling_x] =
3043 particle.fluid_forces[0];
3044 properties[PropertiesIndex::fem_force_two_way_coupling_y] =
3045 particle.fluid_forces[1];
3046 properties[PropertiesIndex::fem_torque_x] = particle.fluid_torque[0];
3047 properties[PropertiesIndex::fem_torque_y] = particle.fluid_torque[1];
3048 properties[PropertiesIndex::fem_torque_z] = particle.fluid_torque[2];
3049
3050 if constexpr (dim == 2)
3051 {
3052 properties[PropertiesIndex::v_z] = 0.;
3053 properties[PropertiesIndex::fem_force_two_way_coupling_z] = 0.;
3054 }
3055 else
3056 {
3057 properties[PropertiesIndex::v_z] = particle.velocity[2];
3058 properties[PropertiesIndex::fem_force_two_way_coupling_z] =
3059 particle.fluid_forces[2];
3060 }
3061}
3062
3063template <int dim>
3064void
3066 Particles::ParticleHandler<dim, dim> &particle_handler,
3068 &particle_container,
3069 std::unordered_set<unsigned int> &local_particle_ids) const
3070{
3071 particle_handler.clear();
3072 particle_container.clear();
3073 local_particle_ids.clear();
3074
3075 Point<dim> ref_point;
3076 std::vector<double> properties;
3077
3078 // Rebuild a DEM particle handler from the Sharp-IB particles so that DEM
3079 // output and post-processing can reuse the same code path.
3080 for (const auto &particle : particles)
3081 {
3082 typename DoFHandler<dim>::active_cell_iterator cell;
3083 try
3084 {
3085 cell =
3087 particle.position);
3088 }
3089 catch (...)
3090 {
3091 continue;
3092 }
3093
3094 if (!cell->is_locally_owned())
3095 continue;
3096
3097 fill_particle_properties(particle, properties);
3098 particle_handler.insert_particle(
3099 particle.position, ref_point, particle.particle_id, cell, properties);
3100 local_particle_ids.insert(particle.particle_id);
3101 }
3102
3103 particle_handler.sort_particles_into_subdomains_and_cells();
3104 particle_handler.exchange_ghost_particles(true);
3105
3106 update_particle_container(particle_container, &particle_handler);
3107}
3108
3109template <int dim>
3110void
3113 &particle_container,
3114 const std::unordered_set<unsigned int> &local_particle_ids,
3116 &local_adjacent_particles,
3118 &ghost_adjacent_particles) const
3119{
3120 local_adjacent_particles.clear();
3121 ghost_adjacent_particles.clear();
3122
3123 // Convert the Sharp-IB contact map into the DEM containers expected by the
3124 // existing DEM post-processing utilities.
3125 const auto &pp_contact_map = ib_dem.get_particle_particle_contact_map();
3126 for (const auto &[particle_id, contacts] : pp_contact_map)
3127 {
3128 // After ghost exchange, a contact near a subdomain boundary can be
3129 // visible on more than one rank. To avoid duplicate DEM
3130 // post-processing entries, each rank only contributes contacts whose
3131 // first particle is locally owned here.
3132 if (local_particle_ids.find(particle_id) == local_particle_ids.end())
3133 continue;
3134
3135 const auto particle_one_it = particle_container.find(particle_id);
3136 if (particle_one_it == particle_container.end())
3137 continue;
3138
3139 for (const auto &[particle_two_id, contact_info] : contacts)
3140 {
3141 const auto particle_two_it = particle_container.find(particle_two_id);
3142 if (particle_two_it == particle_container.end())
3143 continue;
3144
3145 particle_particle_contact_info<dim> dem_contact_info;
3146 dem_contact_info.particle_two = particle_two_it->second;
3147 dem_contact_info.tangential_displacement =
3148 contact_info.tangential_displacement;
3149 dem_contact_info.rolling_resistance_spring_torque =
3150 contact_info.rolling_resistance_spring_torque;
3151
3152 // Keep the same convention as for DEM, contacts between two owned
3153 // particles stay in the local container, while contacts involving a
3154 // ghost neighbor go in the ghost container. The iterator to particle
3155 // one is shared by all its contacts and stored once in the adjacency
3156 // value.
3157 if (local_particle_ids.find(particle_two_id) !=
3158 local_particle_ids.end())
3159 {
3160 auto &adjacency = local_adjacent_particles[particle_id];
3161 adjacency.particle_one = particle_one_it->second;
3162 adjacency.second_particles[particle_two_id] = dem_contact_info;
3163 }
3164 else
3165 {
3166 auto &adjacency = ghost_adjacent_particles[particle_id];
3167 adjacency.particle_one = particle_one_it->second;
3168 adjacency.second_particles[particle_two_id] = dem_contact_info;
3169 }
3170 }
3171 }
3172}
3173
3174template <int dim>
3175void
3177{
3178 const auto &dem_parameters = cfd_dem_parameters.dem_parameters;
3179
3180 // Mirror DEM output cadence for Sharp-IB particles and any DEM-style
3181 // post-processing derived from them.
3182 const bool output_iteration = this->simulation_control->is_output_iteration();
3183 const bool write_particle_output = output_iteration;
3184 const bool write_force_chains =
3185 output_iteration && dem_parameters.post_processing.force_chains;
3186
3187 if (!(write_particle_output || write_force_chains))
3188 return;
3189
3190 Particles::ParticleHandler<dim, dim> particle_handler(
3191 *this->triangulation,
3192 *this->mapping,
3195 particle_container;
3196 std::unordered_set<unsigned int> local_particle_ids;
3197
3198 build_ib_particle_handler(particle_handler,
3199 particle_container,
3200 local_particle_ids);
3201
3203 local_adjacent_particles;
3205 ghost_adjacent_particles;
3206
3207 if (write_force_chains)
3208 build_contact_containers(particle_container,
3209 local_particle_ids,
3210 local_adjacent_particles,
3211 ghost_adjacent_particles);
3212
3213 if (write_particle_output)
3214 {
3215 const std::string folder =
3216 this->simulation_parameters.simulation_control.output_folder;
3217 const std::string particles_solution_name =
3218 this->simulation_parameters.particlesParameters->ib_particles_pvd_file;
3219 const unsigned int iter =
3220 this->simulation_control->get_iteration_number();
3221 const double time = this->simulation_control->get_current_time();
3222 const unsigned int group_files =
3223 this->simulation_parameters.simulation_control.group_files;
3224
3226 particle_data_out;
3227 particle_data_out.build_patches(
3228 particle_handler,
3230 get_properties_name());
3231
3233 particle_data_out,
3234 folder,
3235 particles_solution_name,
3236 time,
3237 iter,
3238 group_files,
3239 this->mpi_communicator);
3240
3241 if (write_force_chains)
3242 {
3243 auto particles_force_chains_object =
3245 dim,
3247 particles_force_chains_object->write_force_chains(
3248 dem_parameters,
3250 this->mpi_communicator,
3251 dem_parameters.simulation_control.output_folder,
3252 iter,
3253 time,
3254 local_adjacent_particles,
3255 ghost_adjacent_particles);
3256 }
3257 }
3258}
3259
3260template <int dim>
3261void
3263{
3264 // This function defines an Immersed Boundary based on the sharp edge method
3265 // on a solid of dim=2 or dim=3
3266
3267 TimerOutput::Scope t(this->computing_timer, "Assemble sharp");
3268 using dealii::numbers::PI;
3269 std::vector<typename DoFHandler<dim>::active_cell_iterator> active_neighbors;
3270 std::vector<typename DoFHandler<dim>::active_cell_iterator>
3271 active_neighbors_set;
3272 std::vector<typename DoFHandler<dim>::active_cell_iterator>
3273 active_neighbors_2;
3274 const FEValuesExtractors::Scalar pressure(dim);
3275
3276 std::vector<double> time_steps_vector =
3277 this->simulation_control->get_time_steps_vector();
3278 // Define a map to all DOFs and their support points
3279 std::map<types::global_dof_index, Point<dim>> support_points =
3280 DoFTools::map_dofs_to_support_points(*this->mapping, *this->dof_handler);
3281
3282 // Initalize fe value objects in order to do calculation with it later
3283 QGauss<dim> q_formula(this->number_quadrature_points);
3284 FEValues<dim> fe_values(*this->fe,
3285 q_formula,
3286 update_quadrature_points | update_JxW_values);
3287 const unsigned int dofs_per_cell = this->fe->dofs_per_cell;
3288
3289 const unsigned int degree =
3290 this->simulation_parameters.particlesParameters->stencil_degree;
3291 double length_ratio =
3292 this->simulation_parameters.particlesParameters->length_ratio;
3293
3294 IBStencil<dim> stencil;
3295 std::vector<double> ib_coef = stencil.coefficients(degree, length_ratio);
3296
3297 unsigned int n_q_points = q_formula.size();
3298
3299 // Define multiple local_dof_indices one for the cell iterator one for the
3300 // cell with the second point for the sharp edge stencil and one for
3301 // manipulation on the neighbour’s cell.
3302 std::vector<types::global_dof_index> local_dof_indices(dofs_per_cell);
3303 std::vector<types::global_dof_index> local_dof_indices_2(dofs_per_cell);
3304 std::vector<types::global_dof_index> local_dof_indices_3(dofs_per_cell);
3305 std::vector<types::global_dof_index> local_dof_indices_4(dofs_per_cell);
3306 std::set<unsigned int> clear_line;
3307
3308 // Define minimal cell length
3309 double dr = GridTools::minimal_cell_diameter(*this->triangulation) /
3310 std::numbers::sqrt2;
3311
3312 // Define cell iterator
3313 const auto &cell_iterator = this->dof_handler->active_cell_iterators();
3314 double dt = time_steps_vector[0];
3316 this->simulation_parameters.simulation_control.method)
3317 dt = 1;
3318
3319 if (this->simulation_parameters.particlesParameters
3320 ->assemble_navier_stokes_inside == true)
3321 {
3322 // impose pressure reference in each of the particle
3323 for (unsigned int p = 0; p < particles.size(); ++p)
3324 {
3325 Point<dim> pressure_reference_location =
3326 particles[p].pressure_location + particles[p].position;
3327
3328
3330 *this->dof_handler, pressure_reference_location);
3331
3332 if (cell->is_locally_owned())
3333 {
3334 cell->get_dof_indices(local_dof_indices);
3335 double sum_line = 0;
3336 double volume = 0;
3337 fe_values.reinit(cell);
3338 std::vector<int> set_pressure_cell;
3339 set_pressure_cell.resize(particles.size());
3340
3341 // Define the order of magnitude for the stencil.
3342 for (unsigned int qf = 0; qf < n_q_points; ++qf)
3343 volume += fe_values.JxW(qf);
3344
3345 sum_line = volume / dt;
3346 // Clear the line in the matrix
3347 unsigned int inside_index = local_dof_indices[dim];
3348 // Check on which DOF of the cell to impose the pressure. If the
3349 // dof is on a hanging node, it is already constrained and the
3350 // pressure cannot be imposed there. So we just go to the next
3351 // pressure DOF of the cell.
3352
3353 for (unsigned int i = 0; i < local_dof_indices.size(); ++i)
3354 {
3355 const int component_i =
3356 this->fe->system_to_component_index(i).first;
3357 if (this->zero_constraints.is_constrained(
3358 local_dof_indices[i]) == false &&
3359 this->locally_owned_dofs.is_element(
3360 local_dof_indices[i]) &&
3361 component_i == dim)
3362 {
3363 inside_index = local_dof_indices[i];
3364 break;
3365 }
3366 }
3367 this->system_matrix.clear_row(inside_index);
3368 // this->system_matrix.clear_row(inside_index)
3369 // is not reliable on edge case
3370
3371 // Set the new equation for the first pressure DOFs of the
3372 // cell. this is the new reference pressure inside a
3373 // particle. As for the other pressure DOFs, the rhs is divided
3374 // by the pressure_scaling_factor since the pressure DOFs are
3375 // rescaled in the newton correction.
3376 this->system_matrix.add(inside_index, inside_index, sum_line);
3377 this->system_rhs(inside_index) =
3378 -this->evaluation_point(inside_index) * sum_line /
3379 this->simulation_parameters.stabilization
3380 .pressure_scaling_factor;
3381 }
3382 }
3383 }
3384
3385 ib_done.clear();
3386 // Loop on all the cell to define if the sharp edge cut them
3387 for (const auto &cell_cut : cell_iterator)
3388 {
3389 if (cell_cut->is_locally_owned() || cell_cut->is_ghost())
3390 {
3391 // Check if the cell_cut is cut or not by the IB and what the particle
3392 // the cut the cell_cut. If the particle is cut
3393 bool cell_is_cut;
3394 // The id of the particle that cut the cell_cut. Returns 0 if the
3395 // cell_cut is not cut.We also check the number of particles that cut
3396 // the cell_cut. If multiple particles cut the cell_cut, the dummy
3397 // DOFs of pressure will be treated differently to avoid
3398 // self-reference.
3399 unsigned int ib_particle_id;
3400 std::vector<unsigned int> count_particles;
3401 std::tie(cell_is_cut, ib_particle_id, count_particles) =
3403 bool cell_is_overconstrained;
3404 std::tie(cell_is_overconstrained, std::ignore, std::ignore) =
3406 if (cell_is_overconstrained)
3407 std::tie(cell_is_overconstrained, ib_particle_id, std::ignore) =
3409
3410 if (cell_is_cut || cell_is_overconstrained)
3411 {
3412 double sum_line = 0;
3413 fe_values.reinit(cell_cut);
3414
3415 double volume = 0;
3416 // Define the order of magnitude for the stencil.
3417 for (unsigned int qf = 0; qf < n_q_points; ++qf)
3418 volume += fe_values.JxW(qf);
3419
3420 sum_line = volume / dt;
3421 cell_cut->get_dof_indices(local_dof_indices);
3422 // If we are here, the cell_cut is cut by the IB.
3423 // Loops on the dof that represents the velocity component
3424 // and pressure separately
3425 for (unsigned int i = 0; i < local_dof_indices.size(); ++i)
3426 {
3427 unsigned int global_index_overwrite = local_dof_indices[i];
3428 if (ib_done[global_index_overwrite].first == false)
3429 {
3430 const int component_i =
3431 this->fe->system_to_component_index(i).first;
3432 bool dof_is_inside =
3433 particles[ib_particle_id].get_levelset(
3434 support_points[local_dof_indices[i]], cell_cut) <= 0;
3435
3436 // If multiple particles cut the cell_cut, we treat the
3437 // dof of pressure as a dummy dof. We don't use them to
3438 // set the boundary condition for the Poisson problem
3439 // inside the particle.
3440 bool use_ib_for_pressure =
3441 (dof_is_inside) && (component_i == dim) &&
3442 (this->simulation_parameters.particlesParameters
3443 ->assemble_navier_stokes_inside == false) &&
3444 count_particles.size() < 2;
3445
3446 // Reapply the zero and nonzero constraints.
3447 if ((this->zero_constraints.is_constrained(
3448 local_dof_indices[i]) ||
3449 this->nonzero_constraints.is_constrained(
3450 local_dof_indices[i])) &&
3451 this->locally_owned_dofs.is_element(
3452 global_index_overwrite))
3453 {
3454 if (this->zero_constraints.is_constrained(
3455 local_dof_indices[i]))
3456 {
3457 // Clear the line if there is something on it
3458 this->system_matrix.clear_row(
3459 global_index_overwrite);
3460 // Get the constraint equations
3461 auto local_entries =
3462 *this->zero_constraints.get_constraint_entries(
3463 local_dof_indices[i]);
3464 double interpolation = 0;
3465 // Write the equation
3466 for (unsigned int j = 0; j < local_entries.size();
3467 ++j)
3468 {
3469 unsigned int col = local_entries[j].first;
3470 double entries = local_entries[j].second;
3471
3472 interpolation +=
3473 this->evaluation_point(col) * entries;
3474
3475 try
3476 {
3477 this->system_matrix.add(
3478 local_dof_indices[i],
3479 col,
3480 entries * sum_line);
3481 }
3482 catch (...)
3483 {
3484 // If we are here, an error happens
3485 // when trying to fill the line in
3486 // the matrix.
3487 // For example, this can occur if a
3488 // particle is close to a wall and we
3489 // are trying to impose the equation
3490 // on a DOF that as a boundary
3491 // condition applied to it. As such,
3492 // we discard these errors.
3493 }
3494 }
3495 this->system_matrix.add(local_dof_indices[i],
3496 local_dof_indices[i],
3497 sum_line);
3498
3499 // Write the RHS
3500 this->system_rhs(local_dof_indices[i]) =
3501 -this->evaluation_point(local_dof_indices[i]) *
3502 sum_line +
3503 interpolation * sum_line +
3504 this->zero_constraints.get_inhomogeneity(
3505 local_dof_indices[i]) *
3506 sum_line;
3507 }
3508 if (this->nonzero_constraints.is_constrained(
3509 local_dof_indices[i]))
3510 {
3511 // Clear the line if there is something on it
3512 this->system_matrix.clear_row(
3513 global_index_overwrite);
3514 // Get the constraint equations
3515
3516 auto local_entries_non_zero =
3517 *this->nonzero_constraints
3518 .get_constraint_entries(
3519 local_dof_indices[i]);
3520
3521 double interpolation = 0;
3522 // Write the equation
3523 for (unsigned int j = 0;
3524 j < local_entries_non_zero.size();
3525 ++j)
3526 {
3527 unsigned int col_non_zero =
3528 local_entries_non_zero[j].first;
3529 double entries_non_zero =
3530 local_entries_non_zero[j].second;
3531
3532 interpolation +=
3533 this->evaluation_point(col_non_zero) *
3534 entries_non_zero;
3535 try
3536 {
3537 this->system_matrix.add(
3538 local_dof_indices[i],
3539 col_non_zero,
3540 entries_non_zero * sum_line);
3541 }
3542 catch (...)
3543 {
3544 // If we are here, an error happens
3545 // when trying to fill the line in
3546 // the matrix.
3547 // For example, this can occur if a
3548 // particle is close to a wall and we
3549 // are trying to impose the equation
3550 // on a DOF that as a boundary
3551 // condition applied to it. As such,
3552 // we discard these errors.
3553 }
3554 }
3555 this->system_matrix.add(local_dof_indices[i],
3556 local_dof_indices[i],
3557 sum_line);
3558
3559 // Write the RHS
3560 this->system_rhs(local_dof_indices[i]) =
3561 -this->evaluation_point(local_dof_indices[i]) *
3562 sum_line +
3563 interpolation * sum_line +
3564 this->nonzero_constraints.get_inhomogeneity(
3565 local_dof_indices[i]) *
3566 sum_line;
3567 }
3568 }
3569
3570 // Check if the DOfs is owned and if it's not a hanging
3571 // node.
3572 if (((component_i < dim) || use_ib_for_pressure) &&
3573 this->locally_owned_dofs.is_element(
3574 global_index_overwrite) &&
3575 (this->zero_constraints.is_constrained(
3576 local_dof_indices[i]) ||
3577 this->nonzero_constraints.is_constrained(
3578 local_dof_indices[i])) == false)
3579 {
3580 // We are working on the DOFs of cells cut by a
3581 // particle. We clear the current equation associated
3582 // with the current DOF and replace it with the sharp
3583 // IB constraints.
3584
3585 // Clear the current line of this dof
3586 this->system_matrix.clear_row(global_index_overwrite);
3587
3588 // Define the points for the IB stencil based on the
3589 // degree, particle position, and DOF position. The
3590 // definition of the output variable "point" changes
3591 // depending on the degree. In the case of stencil
3592 // degrees 1 to 4, the variable point returns the
3593 // position of the DOF directly. In the case of higher
3594 // degree stencil (5 or more), it returns the position
3595 // of the point that is on the IB. This is because
3596 // stencil degrees higher than four are not
3597 // implemented. The function extrapolates the element
3598 // at the particle's surface in these cases. To do so,
3599 // we use the point at the surface of the particle.
3600 // The variable "interpolation points" return the
3601 // points used to define the cell_cut used for the
3602 // stencil definition and the locations of the points
3603 // used in the stencil calculation.
3604
3605 auto [point, interpolation_points] =
3607 degree,
3608 length_ratio,
3609 particles[ib_particle_id],
3610 support_points[local_dof_indices[i]],
3611 cell_cut);
3612 // Find the cell_cut used for the stencil definition.
3613 auto point_to_find_cell =
3615 particles[ib_particle_id],
3616 support_points[local_dof_indices[i]],
3617 cell_cut);
3618 typename DoFHandler<dim>::active_cell_iterator
3619 stencil_cell;
3620 bool particle_close_to_wall = false;
3621 (void)particle_close_to_wall;
3622 try
3623 {
3624 stencil_cell = LetheGridTools::
3626 *this->dof_handler,
3628 cell_cut,
3629 point_to_find_cell);
3630 }
3631 catch (...)
3632 {
3633 // If we are here, the DOF is on a boundary.
3634 particle_close_to_wall = true;
3635 stencil_cell = cell_cut;
3636 // If a boundary condition is already applied to
3637 // this DOF we skip it otherwise we impose a value
3638 // base on the velocity of the particle.
3639 if (this->zero_constraints.is_constrained(
3640 global_index_overwrite) ||
3641 this->nonzero_constraints.is_constrained(
3642 global_index_overwrite))
3643 {
3644 continue;
3645 }
3646 }
3647
3648 stencil_cell->get_dof_indices(local_dof_indices_2);
3649 ib_done[global_index_overwrite] =
3650 std::make_pair(true, stencil_cell);
3651
3652 bool skip_stencil = false;
3653
3654 // Check if the DOF intersect the IB
3655 bool dof_on_ib = false;
3656
3657 // Check if this dof is a dummy dof or directly on IB
3658 // and Check if the point used to define the cell_cut
3659 // used for the definition of the stencil
3660 // ("stencil_cell") is on a face between the cell_cut
3661 // that is cut ("cell_cut") and the "stencil_cell".
3662 bool point_in_cell;
3663 // The extrapolation can be disabled for debugging
3664 // purposes, although in most cases it shouldn't since
3665 // it is a core part of this solver
3666 if (this->simulation_parameters.particlesParameters
3667 ->enable_extrapolation)
3668 point_in_cell = cell_cut->point_inside(
3669 interpolation_points
3671 degree) -
3672 1]);
3673 else
3674 point_in_cell = cell_cut->point_inside(
3675 support_points[local_dof_indices[i]]);
3676
3677 bool dof_is_dummy = false;
3678 bool cell2_is_cut;
3679 unsigned int ib_particle_id_2;
3680 std::tie(cell2_is_cut,
3681 ib_particle_id_2,
3682 std::ignore) = cut_cells_map[stencil_cell];
3683 bool cell2_is_overconstrained;
3684 std::tie(cell2_is_overconstrained,
3685 std::ignore,
3686 std::ignore) =
3687 overconstrained_fluid_cell_map[stencil_cell];
3688 if (cell2_is_cut || point_in_cell)
3689 {
3690 dof_is_dummy = true;
3691 }
3692
3693 if (dof_is_dummy || use_ib_for_pressure ||
3694 cell2_is_overconstrained ||
3695 particle_close_to_wall)
3696 {
3697 // Give the DOF an approximated value. This help
3698 // with pressure shock when the DOF passes from
3699 // part of the boundary to the fluid.
3700
3701 this->system_matrix.add(global_index_overwrite,
3702 global_index_overwrite,
3703 sum_line);
3704 skip_stencil = true;
3705
3706 // Tolerance to define an intersection of
3707 // the DOF and IB
3708 if (abs(particles[ib_particle_id].get_levelset(
3709 support_points[local_dof_indices[i]],
3710 cell_cut)) <= 1e-12 * dr)
3711 {
3712 dof_on_ib = true;
3713 }
3714 }
3715 // Define the variable used for the
3716 // extrapolation of the actual solution at the
3717 // boundaries in order to define the correction
3718
3719 // Define the unit cell_cut points for the points
3720 // used in the stencil.
3721 std::vector<Point<dim>>
3722 unite_cell_interpolation_points(ib_coef.size());
3723 unite_cell_interpolation_points[0] =
3724 this->mapping->transform_real_to_unit_cell(
3725 stencil_cell, point);
3726 for (unsigned int j = 1; j < ib_coef.size(); ++j)
3727 {
3728 // The extrapolation can be disabled for debugging
3729 // purposes, although in most cases it shouldn't
3730 // since it is a core part of this solver
3731 if (this->simulation_parameters
3732 .particlesParameters->enable_extrapolation)
3733 unite_cell_interpolation_points[j] =
3734 this->mapping->transform_real_to_unit_cell(
3735 stencil_cell, interpolation_points[j - 1]);
3736 else
3737 unite_cell_interpolation_points[j] =
3738 this->mapping->transform_real_to_unit_cell(
3739 stencil_cell,
3740 support_points[local_dof_indices[i]]);
3741 }
3742
3743 std::vector<double> local_interp_sol(ib_coef.size());
3744
3745 // Define the new matrix entry for this dof
3746 if (skip_stencil == false)
3747 {
3748 for (unsigned int j = 0;
3749 j < local_dof_indices_2.size();
3750 ++j)
3751 {
3752 const int component_j =
3753 this->fe->system_to_component_index(j)
3754 .first;
3755 if (component_j == component_i)
3756 {
3757 // Define the solution at each point used
3758 // for the stencil and applied the
3759 // stencil for the specific DOF. For
3760 // stencils of degree 4 or higher, the
3761 // stencil is defined through direct
3762 // extrapolation of the cell_cut. This
3763 // can only be done when using a
3764 // structured mesh as this required a
3765 // mapping of a point outside of a
3766 // cell_cut.
3767
3768 // Define the local matrix entries of this
3769 // DOF based on its contribution of each
3770 // of the points used in the stencil
3771 // definition and the coefficient
3772 // associated with this point. This loop
3773 // defined the current solution at the
3774 // boundary using the same stencil. This
3775 // is needed to define the residual.
3776 double local_matrix_entry = 0;
3777 for (unsigned int k = 0;
3778 k < ib_coef.size();
3779 ++k)
3780 {
3781 local_matrix_entry +=
3782 this->fe->shape_value(
3783 j,
3784 unite_cell_interpolation_points
3785 [k]) *
3786 ib_coef[k];
3787 local_interp_sol[k] +=
3788 this->fe->shape_value(
3789 j,
3790 unite_cell_interpolation_points
3791 [k]) *
3792 this->evaluation_point(
3793 local_dof_indices_2[j]);
3794 }
3795 // update the matrix.
3796 try
3797 {
3798 this->system_matrix.add(
3799 global_index_overwrite,
3800 local_dof_indices_2[j],
3801 local_matrix_entry * sum_line);
3802 }
3803 catch (...)
3804 {
3805 // If we are here, an error happens
3806 // when trying to fill the line in
3807 // the matrix.
3808 // For example, this can occur if a
3809 // particle is close to a wall and we
3810 // are trying to impose the equation
3811 // on a DOF that as a boundary
3812 // condition applied to it. As such,
3813 // we discard these errors.
3814 }
3815 }
3816 }
3817 }
3818
3819 // Define the RHS of the equation.
3820 double rhs_add = 0;
3821 // Different boundary conditions depending
3822 // on the component index of the DOF and
3823 // the dimension.
3824 double v_ib = stencil.ib_velocity(
3825 particles[ib_particle_id],
3826 support_points[local_dof_indices[i]],
3827 component_i,
3828 cell_cut);
3829
3830 // If the pressure is imposed trough IB inside the
3831 // particle we use an approximation of the pressure
3832 // outside of the IB in this cell_cut.
3833 if (component_i == dim)
3834 {
3835 for (unsigned int k = 0;
3836 k < local_dof_indices.size();
3837 ++k)
3838 {
3839 // Check if the dof is inside or outside of
3840 // the particle.
3841 bool dof_is_inside_p =
3842 particles[ib_particle_id].get_levelset(
3843 support_points[local_dof_indices[k]],
3844 cell_cut) <= 0;
3845 const int component_k =
3846 this->fe->system_to_component_index(k)
3847 .first;
3848 if (component_k == dim &&
3849 dof_is_inside_p == false)
3850 {
3851 v_ib = this->evaluation_point(
3852 local_dof_indices[k]);
3853 try
3854 {
3855 this->system_matrix.add(
3856 global_index_overwrite,
3857 local_dof_indices[k],
3858 -1 * sum_line);
3859 }
3860 catch (...)
3861 {
3862 // If we are here, an error happens
3863 // when trying to fill the line in
3864 // the matrix.
3865 // For example, this can occur if a
3866 // particle is close to a wall and we
3867 // are trying to impose the equation
3868 // on a DOF that as a boundary
3869 // condition applied to it. As such,
3870 // we discard these errors.
3871 }
3872 break;
3873 }
3874 }
3875 }
3876
3877 for (unsigned int k = 0; k < ib_coef.size(); ++k)
3878 {
3879 rhs_add +=
3880 -local_interp_sol[k] * ib_coef[k] * sum_line;
3881 }
3882 // The rhs contribution where the component would
3883 // correspond to a pressure dof are divided by the
3884 // pressure_scaling_factor. This is because when the
3885 // pressure DOFs are rescaled in the newton
3886 // correction, there is no distinction between
3887 // dummy and non-dummy pressure dofs. Since this
3888 // case is only applicable to this solver, the
3889 // choice was made to modify the rhs itself.
3890 const double pressure_scaling_factor =
3891 this->simulation_parameters.stabilization
3892 .pressure_scaling_factor;
3893 this->system_rhs(global_index_overwrite) =
3894 component_i == dim ? (v_ib * sum_line + rhs_add) /
3895 pressure_scaling_factor :
3896 v_ib * sum_line + rhs_add;
3897
3898 if (dof_on_ib)
3899 // Dof is on the immersed boundary
3900 this->system_rhs(global_index_overwrite) =
3901 component_i == dim ?
3902 (v_ib * sum_line - this->evaluation_point(
3903 global_index_overwrite) *
3904 sum_line) /
3905 pressure_scaling_factor :
3906 (v_ib * sum_line - this->evaluation_point(
3907 global_index_overwrite) *
3908 sum_line);
3909
3910 if (skip_stencil && dof_on_ib == false)
3911 // Impose the value of the dummy dof. This help
3912 // with pressure variation when the IB is
3913 // moving.
3914 this->system_rhs(global_index_overwrite) =
3915 component_i == dim ?
3916 (sum_line * v_ib - this->evaluation_point(
3917 global_index_overwrite) *
3918 sum_line) /
3919 pressure_scaling_factor :
3920 sum_line * v_ib - this->evaluation_point(
3921 global_index_overwrite) *
3922 sum_line;
3923 }
3924
3925 if (component_i == dim &&
3926 this->locally_owned_dofs.is_element(
3927 global_index_overwrite))
3928 {
3929 // Applied equation on dof that have no equation
3930 // defined for them. those DOF become Dummy dof. This
3931 // is useful for high degree cells or when a dof is
3932 // only element of cells that are cut.
3933 unsigned int global_index_overwrite =
3934 local_dof_indices[i];
3935 bool dummy_dof = true;
3936
3937 // To check if the pressure dof is a dummy. first
3938 // check if the matrix entry is close to 0.
3939 if (abs(this->system_matrix.el(
3940 global_index_overwrite,
3941 global_index_overwrite)) <= 1e-16 * dr)
3942 {
3943 // If the matrix entry on the diagonal of this DOF
3944 // is close to zero, check if all the cells close
3945 // are cut. If it's the case, the DOF is a dummy
3946 // DOF.
3947 active_neighbors_set =
3950 for (unsigned int m = 0;
3951 m < active_neighbors_set.size();
3952 m++)
3953 {
3954 const auto &neighbor_cell =
3955 active_neighbors_set[m];
3956 neighbor_cell->get_dof_indices(
3957 local_dof_indices_3);
3958 for (const auto o : local_dof_indices_3)
3959 {
3960 if (global_index_overwrite == o)
3961 {
3962 // neighbor_cell contain the same dof
3963 // check if this cell_cut is cut if
3964 // it's not cut this dof must not
3965 // be overwritten
3966 bool cell_is_cut;
3967 std::tie(cell_is_cut,
3968 std::ignore,
3969 std::ignore) =
3970 cut_cells_map[neighbor_cell];
3971 bool cell_is_overconstrained;
3972 std::tie(cell_is_overconstrained,
3973 std::ignore,
3974 std::ignore) =
3976 [neighbor_cell];
3977 if (cell_is_cut == false &&
3978 cell_is_overconstrained == false)
3979 {
3980 dummy_dof = false;
3981 break;
3982 }
3983 }
3984 }
3985 if (dummy_dof == false)
3986 break;
3987 }
3988
3989 if (dummy_dof)
3990 {
3991 // The DOF is dummy
3992 this->system_matrix.add(
3993 global_index_overwrite,
3994 global_index_overwrite,
3995 sum_line);
3996 auto &system_rhs = this->system_rhs;
3997 system_rhs(global_index_overwrite) = 0;
3998 }
3999 }
4000 }
4001 }
4002 }
4003 }
4004 }
4005 }
4006
4007 this->system_rhs.compress(VectorOperation::insert);
4008 this->system_matrix.compress(VectorOperation::add);
4009}
4010
4011
4012template <int dim>
4013void
4015{
4016 // The sharp-interface immersed boundary solver only supports BDF methods.
4017 AssertThrow(
4018 !time_stepping_is_sdirk(this->simulation_control->get_assembly_method()),
4019 ExcMessage("SDIRK time-stepping methods are not supported by the "
4020 "sharp-interface immersed boundary solver. Use a BDF method "
4021 "instead."));
4022
4023 this->assemblers.clear();
4024 assemblers_inside_ib.clear();
4025
4026 if (this->check_existance_of_bc(
4028 {
4029 this->assemblers.push_back(
4030 std::make_shared<WeakDirichletBoundaryCondition<dim>>(
4031 this->simulation_control,
4032 this->simulation_parameters.boundary_conditions));
4033 }
4034 if (this->check_existance_of_bc(
4036 {
4037 this->assemblers.push_back(
4038 std::make_shared<PressureBoundaryCondition<dim>>(
4039 this->simulation_control,
4040 this->simulation_parameters.boundary_conditions));
4041 }
4042 if (this->check_existance_of_bc(
4044 {
4045 this->assemblers.push_back(std::make_shared<OutletBoundaryCondition<dim>>(
4046 this->simulation_control,
4047 this->simulation_parameters.boundary_conditions));
4048 }
4049 if (this->check_existance_of_bc(
4051 {
4052 this->assemblers.push_back(
4054 this->simulation_control,
4055 this->simulation_parameters.boundary_conditions));
4056 }
4057 if (this->simulation_parameters.multiphysics.CLS)
4058 {
4059 // Time-stepping schemes
4061 this->simulation_control->get_assembly_method()) &&
4062 this->simulation_parameters.physical_properties_manager
4063 .density_is_constant())
4064 {
4065 this->assemblers.push_back(
4066 std::make_shared<GLSNavierStokesCLSAssemblerBDF<dim>>(
4067 this->simulation_control));
4068 }
4069 else if (time_stepping_is_bdf(
4070 this->simulation_control->get_assembly_method()))
4071 {
4072 this->assemblers.push_back(
4073 std::make_shared<
4075 this->simulation_control));
4076 }
4077
4078 // Core assemblers
4079 if (this->simulation_parameters.physical_properties_manager
4080 .is_non_newtonian())
4081 {
4082 // Core assembler with Non newtonian viscosity
4083 this->assemblers.push_back(
4086 }
4087 else if (!this->simulation_parameters.physical_properties_manager
4088 .density_is_constant())
4089 {
4090 this->assemblers.push_back(
4091 std::make_shared<
4094 }
4095 else
4096 {
4097 // Core assembler
4098 this->assemblers.push_back(
4099 std::make_shared<GLSNavierStokesCLSAssemblerCore<dim>>(
4101 }
4102 }
4103 else
4104 {
4105 // Time-stepping schemes
4106 if (time_stepping_is_bdf(this->simulation_control->get_assembly_method()))
4107 {
4108 this->assemblers.push_back(
4109 std::make_shared<GLSNavierStokesAssemblerBDF<dim>>(
4110 this->simulation_control));
4111 }
4112
4113 // Velocity sources term
4114 if (this->simulation_parameters.velocity_sources.rotating_frame_type ==
4116 {
4117 this->assemblers.push_back(
4118 std::make_shared<GLSNavierStokesAssemblerSRF<dim>>(
4119 this->simulation_parameters.velocity_sources));
4120 }
4121
4122 // Core assemblers
4123 if (this->simulation_parameters.physical_properties_manager
4124 .is_non_newtonian())
4125 {
4126 // Core assembler with Non newtonian viscosity
4127 this->assemblers.push_back(
4129 this->simulation_control));
4130 }
4131 else
4132 {
4133 // Core assembler
4134 this->assemblers.push_back(
4136 this->simulation_control));
4137 }
4138 }
4139
4140 assemblers_inside_ib.push_back(
4141 std::make_shared<LaplaceAssembly<dim>>(this->simulation_control));
4142}
4143
4144template <int dim>
4145void
4147 const typename DoFHandler<dim>::active_cell_iterator &cell,
4148 NavierStokesScratchData<dim> &scratch_data,
4150{
4151 copy_data.cell_is_local = cell->is_locally_owned();
4152
4153 if (!cell->is_locally_owned())
4154 return;
4155
4156 // We check if the cell is cut by the IB and if it is overconstrained. If the
4157 // cell is cut or overconstrained, we adjust the copy data so that the
4158 // assemblers don't execute work on this cell.
4159 bool cell_is_cut = false;
4160 std::tie(cell_is_cut, std::ignore, std::ignore) = cut_cells_map[cell];
4161 bool cell_is_overconstrained;
4162 std::tie(cell_is_overconstrained, std::ignore, std::ignore) =
4164
4165 copy_data.cell_is_cut = cell_is_cut || cell_is_overconstrained;
4166
4167 if (copy_data.cell_is_cut)
4168 return;
4169
4170 scratch_data.reinit(
4171 cell,
4172 this->evaluation_point,
4173 *this->previous_solutions,
4174 this->sdirk_vectors.sum_over_previous_stages,
4175 this->forcing_function,
4176 this->flow_control.get_beta(),
4177 this->simulation_parameters.stabilization.pressure_scaling_factor);
4178
4179 if (this->simulation_parameters.multiphysics.CLS)
4180 {
4181 const DoFHandler<dim> &dof_handler_cls =
4182 this->multiphysics->get_dof_handler(PhysicsID::CLS);
4183 typename DoFHandler<dim>::active_cell_iterator phase_cell(
4184 &(*(this->triangulation)),
4185 cell->level(),
4186 cell->index(),
4187 &dof_handler_cls);
4188
4189 scratch_data.reinit_cls(
4190 phase_cell,
4191 this->multiphysics->get_solution(PhysicsID::CLS),
4192 this->multiphysics->get_filtered_solution(PhysicsID::CLS),
4193 this->multiphysics->get_previous_solutions(PhysicsID::CLS));
4194 }
4195
4196 scratch_data.calculate_physical_properties();
4197 copy_data.reset();
4198
4199 // check if we assemble the NS equation inside the particle or the Laplacian
4200 // of the variables
4201 bool cell_is_inside;
4202 std::tie(cell_is_inside, std::ignore) = cells_inside_map[cell];
4203 if (cell_is_inside && this->simulation_parameters.particlesParameters
4204 ->assemble_navier_stokes_inside == false)
4205 {
4206 for (auto &assembler : this->assemblers_inside_ib)
4207 {
4208 assembler->assemble_matrix(scratch_data, copy_data);
4209 }
4210 }
4211 else
4212 {
4213 for (auto &assembler : this->assemblers)
4214 {
4215 assembler->assemble_matrix(scratch_data, copy_data);
4216 }
4217 }
4218 cell->get_dof_indices(copy_data.local_dof_indices);
4219}
4220
4221template <int dim>
4222void
4224 const StabilizedMethodsTensorCopyData<dim> &copy_data)
4225{
4226 if (!copy_data.cell_is_local || copy_data.cell_is_cut)
4227 return;
4228
4229 const AffineConstraints<double> &constraints_used = this->zero_constraints;
4230 constraints_used.distribute_local_to_global(copy_data.local_matrix,
4231 copy_data.local_dof_indices,
4232 this->system_matrix);
4233}
4234
4235template <int dim>
4236void
4238 const typename DoFHandler<dim>::active_cell_iterator &cell,
4239 NavierStokesScratchData<dim> &scratch_data,
4241{
4242 copy_data.cell_is_local = cell->is_locally_owned();
4243
4244 if (!cell->is_locally_owned())
4245 return;
4246
4247 // We check if the cell is cut by the IB and if it is overconstrained. If the
4248 // cell is cut or overconstrained, we adjust the copy data so that the
4249 // assemblers don't execute work on this cell.
4250 bool cell_is_cut = false;
4251 std::tie(cell_is_cut, std::ignore, std::ignore) = cut_cells_map[cell];
4252
4253 bool cell_is_overconstrained;
4254 std::tie(cell_is_overconstrained, std::ignore, std::ignore) =
4256
4257 copy_data.cell_is_cut = cell_is_cut || cell_is_overconstrained;
4258
4259 if (copy_data.cell_is_cut)
4260 return;
4261
4262 scratch_data.reinit(
4263 cell,
4264 this->evaluation_point,
4265 *this->previous_solutions,
4266 this->sdirk_vectors.sum_over_previous_stages,
4267 this->forcing_function,
4268 this->flow_control.get_beta(),
4269 this->simulation_parameters.stabilization.pressure_scaling_factor);
4270
4271 if (this->simulation_parameters.multiphysics.CLS)
4272 {
4273 const DoFHandler<dim> &dof_handler_cls =
4274 this->multiphysics->get_dof_handler(PhysicsID::CLS);
4275 typename DoFHandler<dim>::active_cell_iterator phase_cell(
4276 &(*(this->triangulation)),
4277 cell->level(),
4278 cell->index(),
4279 &dof_handler_cls);
4280
4281 scratch_data.reinit_cls(
4282 phase_cell,
4283 this->multiphysics->get_solution(PhysicsID::CLS),
4284 this->multiphysics->get_filtered_solution(PhysicsID::CLS),
4285 this->multiphysics->get_previous_solutions(PhysicsID::CLS));
4286 }
4287
4288 scratch_data.calculate_physical_properties();
4289 copy_data.reset();
4290
4291 // check if we assemble the NS equation inside the particle or the Laplacian
4292 // of the variables
4293 bool cell_is_inside;
4294 std::tie(cell_is_inside, std::ignore) = cells_inside_map[cell];
4295 if (cell_is_inside && this->simulation_parameters.particlesParameters
4296 ->assemble_navier_stokes_inside == false)
4297 {
4298 for (auto &assembler : this->assemblers_inside_ib)
4299 {
4300 assembler->assemble_rhs(scratch_data, copy_data);
4301 }
4302 }
4303 else
4304 {
4305 for (auto &assembler : this->assemblers)
4306 {
4307 assembler->assemble_rhs(scratch_data, copy_data);
4308 }
4309 }
4310
4311 cell->get_dof_indices(copy_data.local_dof_indices);
4312}
4313
4314template <int dim>
4315void
4317 const StabilizedMethodsTensorCopyData<dim> &copy_data)
4318{
4319 if (!copy_data.cell_is_local || copy_data.cell_is_cut)
4320 return;
4321
4322
4323 const AffineConstraints<double> &constraints_used = this->zero_constraints;
4324 constraints_used.distribute_local_to_global(copy_data.local_rhs,
4325 copy_data.local_dof_indices,
4326 this->system_rhs);
4327}
4328
4329template <int dim>
4330void
4332{
4334
4335 // Write a table with all the relevant properties of the particle in a table.
4336 if (Utilities::MPI::this_mpi_process(this->mpi_communicator) == 0)
4337 {
4338 std::string prefix =
4339 this->simulation_parameters.simulation_control.output_folder +
4340 this->simulation_parameters.restart_parameters.filename;
4341
4342 TableHandler particles_information_table;
4343 std::string filename = prefix + ".ib_particles";
4344 std::ofstream output(filename.c_str());
4345 this->simulation_control->save(prefix);
4346 ib_particles_pvdhandler.save(prefix + ".ib_particles");
4347
4348 this->pvdhandler.save(prefix);
4349 for (unsigned int i_particle = 0; i_particle < particles.size();
4350 ++i_particle)
4351 {
4352 for (unsigned int j = 0;
4353 j < particles[i_particle].previous_positions.size();
4354 ++j)
4355 {
4356 particles_information_table.add_value("ID", i_particle);
4357 particles_information_table.add_value(
4358 "p_x", particles[i_particle].previous_positions[j][0]);
4359 particles_information_table.set_precision("p_x", 16);
4360 particles_information_table.add_value(
4361 "p_y", particles[i_particle].previous_positions[j][1]);
4362 particles_information_table.set_precision("p_y", 16);
4363 if constexpr (dim == 3)
4364 {
4365 particles_information_table.add_value(
4366 "p_z", particles[i_particle].previous_positions[j][2]);
4367 particles_information_table.set_precision("p_z", 16);
4368 }
4369
4370 particles_information_table.add_value(
4371 "v_x", particles[i_particle].previous_velocity[j][0]);
4372 particles_information_table.set_precision("v_x", 16);
4373 particles_information_table.add_value(
4374 "v_y", particles[i_particle].previous_velocity[j][1]);
4375 particles_information_table.set_precision("v_y", 16);
4376 if constexpr (dim == 3)
4377 {
4378 particles_information_table.add_value(
4379 "v_z", particles[i_particle].previous_velocity[j][2]);
4380 particles_information_table.set_precision("v_z", 16);
4381 }
4382
4383 particles_information_table.add_value(
4384 "f_x", particles[i_particle].previous_fluid_forces[0]);
4385 particles_information_table.set_precision("f_x", 16);
4386 particles_information_table.add_value(
4387 "f_y", particles[i_particle].previous_fluid_forces[1]);
4388 particles_information_table.set_precision("f_y", 16);
4389
4390 if constexpr (dim == 3)
4391 {
4392 particles_information_table.add_value(
4393 "f_z", particles[i_particle].previous_fluid_forces[2]);
4394 particles_information_table.set_precision("f_z", 16);
4395 }
4396
4397 particles_information_table.add_value(
4398 "f_xv", particles[i_particle].previous_fluid_viscous_forces[0]);
4399 particles_information_table.set_precision("f_xv", 16);
4400 particles_information_table.add_value(
4401 "f_yv", particles[i_particle].previous_fluid_viscous_forces[1]);
4402 particles_information_table.set_precision("f_yv", 16);
4403
4404 if constexpr (dim == 3)
4405 {
4406 particles_information_table.add_value(
4407 "f_zv",
4408 particles[i_particle].previous_fluid_viscous_forces[2]);
4409 particles_information_table.set_precision("f_zv", 16);
4410 }
4411
4412 particles_information_table.add_value(
4413 "f_xp",
4414 particles[i_particle].previous_fluid_pressure_forces[0]);
4415 particles_information_table.set_precision("f_xp", 16);
4416 particles_information_table.add_value(
4417 "f_yp",
4418 particles[i_particle].previous_fluid_pressure_forces[1]);
4419 particles_information_table.set_precision("f_yp", 16);
4420
4421 if constexpr (dim == 3)
4422 {
4423 particles_information_table.add_value(
4424 "f_zp",
4425 particles[i_particle].previous_fluid_pressure_forces[2]);
4426 particles_information_table.set_precision("f_zp", 16);
4427 }
4428
4429 if constexpr (dim == 3)
4430 {
4431 particles_information_table.add_value(
4432 "omega_x", particles[i_particle].previous_omega[j][0]);
4433 particles_information_table.set_precision("omega_x", 16);
4434 particles_information_table.add_value(
4435 "omega_y", particles[i_particle].previous_omega[j][1]);
4436 particles_information_table.set_precision("omega_y", 16);
4437 particles_information_table.add_value(
4438 "theta_x",
4439 particles[i_particle].previous_orientation[j][0]);
4440 particles_information_table.set_precision("theta_x", 16);
4441 particles_information_table.add_value(
4442 "theta_y",
4443 particles[i_particle].previous_orientation[j][1]);
4444 particles_information_table.set_precision("theta_y", 16);
4445 }
4446 particles_information_table.add_value(
4447 "omega_z", particles[i_particle].previous_omega[j][2]);
4448 particles_information_table.set_precision("omega_z", 16);
4449 particles_information_table.add_value(
4450 "theta_z", particles[i_particle].previous_orientation[j][2]);
4451 particles_information_table.set_precision("theta_z", 16);
4452 if constexpr (dim == 3)
4453 {
4454 particles_information_table.add_value(
4455 "T_x", particles[i_particle].previous_fluid_torque[0]);
4456 particles_information_table.set_precision("T_x", 16);
4457 particles_information_table.add_value(
4458 "T_y", particles[i_particle].previous_fluid_torque[1]);
4459 particles_information_table.set_precision("T_y", 16);
4460 }
4461 particles_information_table.add_value(
4462 "T_z", particles[i_particle].previous_fluid_torque[2]);
4463 particles_information_table.set_precision("T_z", 16);
4464 }
4465 }
4466 // Write the table in the checkpoint file.
4467 particles_information_table.write_text(output);
4468 }
4469}
4470
4471template <int dim>
4472void
4474{
4476
4477 TimerOutput::Scope t(this->computing_timer,
4478 "Reset Sharp-Edge particle information");
4479
4480 std::string prefix =
4481 this->simulation_parameters.simulation_control.output_folder +
4482 this->simulation_parameters.restart_parameters.filename;
4483
4484 std::string filename = prefix + ".ib_particles";
4485
4486 ib_particles_pvdhandler.read(prefix + ".ib_particles");
4487 // refill the table from checkpoint
4488 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
4489 {
4490 std::string filename_table =
4491 this->simulation_parameters.simulation_control.output_folder +
4492 this->simulation_parameters.particlesParameters->ib_force_output_file +
4493 "." + Utilities::int_to_string(p_i, 2) + ".dat";
4494 fill_table_from_file(table_p[p_i], filename_table);
4495 }
4496
4497 // Read the data of each particle and put the relevant information in a
4498 // vector.
4499 std::map<std::string, std::vector<double>> restart_data;
4500 fill_vectors_from_file(restart_data, filename);
4501
4502 // Implement the data in the particles.
4503 if constexpr (dim == 2)
4504 {
4505 unsigned int row = 0;
4506 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
4507 {
4508 unsigned int j = 0;
4509 while (row < restart_data["ID"].size() &&
4510 restart_data["ID"][row] == p_i)
4511 {
4512 if (j == 0)
4513 {
4514 particles[p_i].position[0] = restart_data["p_x"][row];
4515 particles[p_i].position[1] = restart_data["p_y"][row];
4516 particles[p_i].velocity[0] = restart_data["v_x"][row];
4517 particles[p_i].velocity[1] = restart_data["v_y"][row];
4518 particles[p_i].fluid_forces[0] = restart_data["f_x"][row];
4519 particles[p_i].fluid_forces[1] = restart_data["f_y"][row];
4520 particles[p_i].fluid_viscous_forces[0] =
4521 restart_data["f_xv"][row];
4522 particles[p_i].fluid_viscous_forces[1] =
4523 restart_data["f_yv"][row];
4524 particles[p_i].fluid_pressure_forces[0] =
4525 restart_data["f_xp"][row];
4526 particles[p_i].fluid_pressure_forces[1] =
4527 restart_data["f_yp"][row];
4528 particles[p_i].omega[2] = restart_data["omega_z"][row];
4529 particles[p_i].orientation[2] = restart_data["theta_z"][row];
4530 particles[p_i].fluid_torque[2] = restart_data["T_z"][row];
4531
4532 // fill previous time step
4533 particles[p_i].previous_positions[j][0] =
4534 restart_data["p_x"][row];
4535 particles[p_i].previous_positions[j][1] =
4536 restart_data["p_y"][row];
4537 particles[p_i].previous_velocity[j][0] =
4538 restart_data["v_x"][row];
4539 particles[p_i].previous_velocity[j][1] =
4540 restart_data["v_y"][row];
4541 particles[p_i].previous_omega[j][2] =
4542 restart_data["omega_z"][row];
4543 particles[p_i].previous_orientation[j][2] =
4544 restart_data["theta_z"][row];
4545
4546 particles[p_i].set_position(particles[p_i].position);
4547 particles[p_i].set_orientation(particles[p_i].orientation);
4548 }
4549 else
4550 {
4551 // fill previous time step
4552 particles[p_i].previous_positions[j][0] =
4553 restart_data["p_x"][row];
4554 particles[p_i].previous_positions[j][1] =
4555 restart_data["p_y"][row];
4556 particles[p_i].previous_velocity[j][0] =
4557 restart_data["v_x"][row];
4558 particles[p_i].previous_velocity[j][1] =
4559 restart_data["v_y"][row];
4560 particles[p_i].previous_omega[j][2] =
4561 restart_data["omega_z"][row];
4562 particles[p_i].previous_orientation[j][2] =
4563 restart_data["theta_z"][row];
4564 }
4565 row += 1;
4566 j += 1;
4567 }
4568 }
4569 }
4570 if constexpr (dim == 3)
4571 {
4572 unsigned int row = 0;
4573 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
4574 {
4575 unsigned int j = 0;
4576 while (row < restart_data["ID"].size() &&
4577 restart_data["ID"][row] == p_i)
4578 {
4579 if (j == 0)
4580 {
4581 particles[p_i].position[0] = restart_data["p_x"][row];
4582 particles[p_i].position[1] = restart_data["p_y"][row];
4583 particles[p_i].position[2] = restart_data["p_z"][row];
4584 particles[p_i].velocity[0] = restart_data["v_x"][row];
4585 particles[p_i].velocity[1] = restart_data["v_y"][row];
4586 particles[p_i].velocity[2] = restart_data["v_z"][row];
4587 particles[p_i].fluid_forces[0] = restart_data["f_x"][row];
4588 particles[p_i].fluid_forces[1] = restart_data["f_y"][row];
4589 particles[p_i].fluid_forces[2] = restart_data["f_z"][row];
4590 particles[p_i].fluid_viscous_forces[0] =
4591 restart_data["f_xv"][row];
4592 particles[p_i].fluid_viscous_forces[1] =
4593 restart_data["f_yv"][row];
4594 particles[p_i].fluid_viscous_forces[2] =
4595 restart_data["f_zv"][row];
4596 particles[p_i].fluid_pressure_forces[0] =
4597 restart_data["f_xp"][row];
4598 particles[p_i].fluid_pressure_forces[1] =
4599 restart_data["f_yp"][row];
4600 particles[p_i].fluid_pressure_forces[2] =
4601 restart_data["f_zp"][row];
4602 particles[p_i].orientation[0] = restart_data["theta_x"][row];
4603 particles[p_i].orientation[1] = restart_data["theta_y"][row];
4604 particles[p_i].orientation[2] = restart_data["theta_z"][row];
4605 particles[p_i].omega[0] = restart_data["omega_x"][row];
4606 particles[p_i].omega[1] = restart_data["omega_y"][row];
4607 particles[p_i].omega[2] = restart_data["omega_z"][row];
4608 particles[p_i].fluid_torque[0] = restart_data["T_x"][row];
4609 particles[p_i].fluid_torque[1] = restart_data["T_y"][row];
4610 particles[p_i].fluid_torque[2] = restart_data["T_z"][row];
4611
4612 // fill previous time step
4613 particles[p_i].previous_positions[j][0] =
4614 restart_data["p_x"][row];
4615 particles[p_i].previous_positions[j][1] =
4616 restart_data["p_y"][row];
4617 particles[p_i].previous_positions[j][2] =
4618 restart_data["p_z"][row];
4619 particles[p_i].previous_velocity[j][0] =
4620 restart_data["v_x"][row];
4621 particles[p_i].previous_velocity[j][1] =
4622 restart_data["v_y"][row];
4623 particles[p_i].previous_velocity[j][2] =
4624 restart_data["v_z"][row];
4625 particles[p_i].previous_omega[j][0] =
4626 restart_data["omega_x"][row];
4627 particles[p_i].previous_omega[j][1] =
4628 restart_data["omega_y"][row];
4629 particles[p_i].previous_omega[j][2] =
4630 restart_data["omega_z"][row];
4631 particles[p_i].previous_orientation[j][0] =
4632 restart_data["theta_x"][row];
4633 particles[p_i].previous_orientation[j][1] =
4634 restart_data["theta_y"][row];
4635 particles[p_i].previous_orientation[j][2] =
4636 restart_data["theta_z"][row];
4637
4638 particles[p_i].set_position(particles[p_i].position);
4639 particles[p_i].set_orientation(particles[p_i].orientation);
4640 }
4641 else
4642 {
4643 // fill previous time step
4644 particles[p_i].previous_positions[j][0] =
4645 restart_data["p_x"][row];
4646 particles[p_i].previous_positions[j][1] =
4647 restart_data["p_y"][row];
4648 particles[p_i].previous_positions[j][2] =
4649 restart_data["p_z"][row];
4650 particles[p_i].previous_velocity[j][0] =
4651 restart_data["v_x"][row];
4652 particles[p_i].previous_velocity[j][1] =
4653 restart_data["v_y"][row];
4654 particles[p_i].previous_velocity[j][2] =
4655 restart_data["v_z"][row];
4656 particles[p_i].previous_omega[j][0] =
4657 restart_data["omega_x"][row];
4658 particles[p_i].previous_omega[j][1] =
4659 restart_data["omega_y"][row];
4660 particles[p_i].previous_omega[j][2] =
4661 restart_data["omega_z"][row];
4662 particles[p_i].previous_orientation[j][0] =
4663 restart_data["theta_x"][row];
4664 particles[p_i].previous_orientation[j][1] =
4665 restart_data["theta_y"][row];
4666 particles[p_i].previous_orientation[j][2] =
4667 restart_data["theta_z"][row];
4668 }
4669 row += 1;
4670 j += 1;
4671 }
4672 }
4673 }
4674 // Check if particles are spheres
4676
4677 // Create the list of contact candidates
4678 ib_dem.initialize(
4679 this->simulation_parameters.particlesParameters,
4681 cfd_dem_parameters.dem_parameters.floating_walls),
4682 std::make_shared<Parameters::Lagrangian::BCDEM>(
4683 cfd_dem_parameters.dem_parameters.boundary_conditions),
4684 this->mpi_communicator,
4685 particles);
4686 ib_dem.update_contact_candidates();
4687 // Finish the time step of the particles.
4688 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
4689 {
4690 particles[p_i].velocity_iter = particles[p_i].velocity;
4691 particles[p_i].impulsion_iter = particles[p_i].impulsion;
4692 particles[p_i].omega_iter = particles[p_i].omega;
4693 particles[p_i].omega_impulsion_iter = particles[p_i].omega_impulsion;
4694 }
4695 // Finish the time step of the particle.
4696
4698 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
4699 {
4700 TimerOutput::Scope t(this->computing_timer, "Remove RBF nodes");
4701 particles[p_i].remove_superfluous_data(
4702 *this->dof_handler, particles[p_i].mesh_based_precalculations);
4703 }
4704}
4705
4706template <int dim>
4707void
4709{
4710 using dealii::numbers::PI;
4711 TimerOutput::Scope t(this->computing_timer,
4712 "Reset Sharp-Edge particle information");
4713 this->pcout << "Loading particles from a file" << std::endl;
4714 std::string filename =
4715 this->simulation_parameters.particlesParameters->particles_file;
4716
4717 // Read the data of each particle and put the relevant information in a
4718 // vector.
4719 std::map<std::string, std::vector<std::string>> particles_data;
4720 fill_string_vectors_from_file(particles_data, filename, ";");
4721 particles.resize(particles_data["type"].size());
4722
4723 this->pcout << "Particles found: " << particles.size() << std::endl;
4724
4725 // The inertia is given either as a single value, when it is uniform around
4726 // each axis, or as the 9 components of the inertia matrix separated by ":".
4727 const auto parse_inertia = [](const std::string &inertia_str) {
4728 const std::vector<double> inertia_list = Utilities::string_to_double(
4729 Utilities::split_string_list(inertia_str, ":"));
4730 Tensor<2, 3> inertia;
4731 if (inertia_list.size() == 9)
4732 {
4733 for (unsigned int i = 0; i < 3; ++i)
4734 for (unsigned int j = 0; j < 3; ++j)
4735 inertia[i][j] = inertia_list[3 * i + j];
4736 }
4737 else if (inertia_list.size() == 1)
4738 {
4739 for (unsigned int i = 0; i < 3; ++i)
4740 inertia[i][i] = inertia_list[0];
4741 }
4742 else
4743 {
4744 throw(std::runtime_error(
4745 " Invalid inertia matrix. The inertia is given as a 3 by 3 matrix or a single value if the inertia is uniform around each axis."));
4746 }
4747 return inertia;
4748 };
4749
4750 // Implement the data in the particles.
4751 if constexpr (dim == 2)
4752 {
4753 // Loop over each line of the file and filling the particles properties.
4754 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
4755 {
4756 particles[p_i].initialize_all();
4757
4758 particles[p_i].particle_id = p_i;
4759
4760 particles[p_i].position[0] =
4761 Utilities::string_to_double(particles_data["p_x"][p_i]);
4762 particles[p_i].position[1] =
4763 Utilities::string_to_double(particles_data["p_y"][p_i]);
4764 particles[p_i].velocity[0] =
4765 Utilities::string_to_double(particles_data["v_x"][p_i]);
4766 particles[p_i].velocity[1] =
4767 Utilities::string_to_double(particles_data["v_y"][p_i]);
4768 particles[p_i].orientation[2] =
4769 Utilities::string_to_double(particles_data["orientation_z"][p_i]);
4770 // Initialize shape of particles according to the type parameter in
4771 // the file
4772
4773 std::string shape_type = particles_data["type"][p_i];
4774 std::string shape_arguments_str =
4775 particles_data["shape_argument"][p_i];
4776 // Here shape is supposed to be separated by : but the initializer
4777 // take ; as separator so we replace : by ;.
4778 std::string toReplace = ":";
4779 std::string replacement = ";";
4780
4781 // Check if the substring is found
4782 size_t pos = shape_arguments_str.find(toReplace);
4783 while (pos != std::string::npos)
4784 {
4785 // Replace the substring
4786 shape_arguments_str.replace(pos, toReplace.length(), replacement);
4787
4788 // Find next occurrence of the substring
4789 pos =
4790 shape_arguments_str.find(toReplace, pos + replacement.length());
4791 }
4792 particles[p_i].initialize_shape(shape_type, shape_arguments_str);
4793
4794
4795 particles[p_i].radius = particles[p_i].shape->effective_radius;
4796
4797 double volume =
4798 Utilities::string_to_double(particles_data["volume"][p_i]);
4799 if (volume == 0)
4800 {
4801 // value is automatically defined.
4802 volume = particles[p_i].shape->displaced_volume();
4803 if (volume == 0)
4804 {
4805 if constexpr (dim == 2)
4806 {
4807 volume =
4808 PI * particles[p_i].radius * particles[p_i].radius;
4809 }
4810 else if constexpr (dim == 3)
4811 {
4812 volume = 4.0 / 3.0 * PI * particles[p_i].radius *
4813 particles[p_i].radius * particles[p_i].radius;
4814 }
4815 }
4816 }
4817 particles[p_i].volume = volume;
4818 particles[p_i].mass =
4819 particles[p_i].volume *
4820 Utilities::string_to_double(particles_data["density"][p_i]);
4821
4822 particles[p_i].omega[2] =
4823 Utilities::string_to_double(particles_data["omega_z"][p_i]);
4824
4825 particles[p_i].inertia =
4826 parse_inertia(particles_data["inertia"][p_i]);
4827
4828 particles[p_i].pressure_location[0] =
4829 Utilities::string_to_double(particles_data["pressure_x"][p_i]);
4830 particles[p_i].pressure_location[1] =
4831 Utilities::string_to_double(particles_data["pressure_y"][p_i]);
4832
4833 particles[p_i].youngs_modulus =
4834 Utilities::string_to_double(particles_data["youngs_modulus"][p_i]);
4835 particles[p_i].restitution_coefficient = Utilities::string_to_double(
4836 particles_data["restitution_coefficient"][p_i]);
4837 particles[p_i].friction_coefficient = Utilities::string_to_double(
4838 particles_data["friction_coefficient"][p_i]);
4839 particles[p_i].poisson_ratio =
4840 Utilities::string_to_double(particles_data["poisson_ratio"][p_i]);
4841 particles[p_i].rolling_friction_coefficient =
4842 Utilities::string_to_double(
4843 particles_data["rolling_friction_coefficient"][p_i]);
4844 particles[p_i].initialize_previous_solution();
4845 if (particles_data["integrate_motion"][p_i] == "false")
4846 {
4847 particles[p_i].integrate_motion = false;
4848 }
4849 else
4850 {
4851 particles[p_i].integrate_motion = true;
4852 }
4853 particles[p_i].set_position(particles[p_i].position);
4854 particles[p_i].set_orientation(particles[p_i].orientation);
4855 }
4856 }
4857 if constexpr (dim == 3)
4858 {
4859 // Loop over each line of the file and filling the particles properties.
4860 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
4861 {
4862 particles[p_i].initialize_all();
4863
4864 particles[p_i].particle_id = p_i;
4865 particles[p_i].position[0] =
4866 Utilities::string_to_double(particles_data["p_x"][p_i]);
4867 particles[p_i].position[1] =
4868 Utilities::string_to_double(particles_data["p_y"][p_i]);
4869 particles[p_i].position[2] =
4870 Utilities::string_to_double(particles_data["p_z"][p_i]);
4871 particles[p_i].velocity[0] =
4872 Utilities::string_to_double(particles_data["v_x"][p_i]);
4873 particles[p_i].velocity[1] =
4874 Utilities::string_to_double(particles_data["v_y"][p_i]);
4875 particles[p_i].velocity[2] =
4876 Utilities::string_to_double(particles_data["v_z"][p_i]);
4877 particles[p_i].orientation[0] =
4878 Utilities::string_to_double(particles_data["orientation_x"][p_i]);
4879 particles[p_i].orientation[1] =
4880 Utilities::string_to_double(particles_data["orientation_y"][p_i]);
4881 particles[p_i].orientation[2] =
4882 Utilities::string_to_double(particles_data["orientation_z"][p_i]);
4883
4884 std::string shape_type = particles_data["type"][p_i];
4885 std::string shape_arguments_str =
4886 particles_data["shape_argument"][p_i];
4887 // Here shape is supposed to be separated by : but the initializer
4888 // takes ; as separator so we replace : by ;.
4889 std::string toReplace = ":";
4890 std::string replacement = ";";
4891
4892 // Check if the substring is found
4893 size_t pos = shape_arguments_str.find(toReplace);
4894 while (pos != std::string::npos)
4895 {
4896 // Replace the substring
4897 shape_arguments_str.replace(pos, toReplace.length(), replacement);
4898
4899 // Find next occurrence of the substring
4900 pos =
4901 shape_arguments_str.find(toReplace, pos + replacement.length());
4902 }
4903 particles[p_i].initialize_shape(shape_type, shape_arguments_str);
4904
4905 particles[p_i].radius = particles[p_i].shape->effective_radius;
4906 double volume =
4907 Utilities::string_to_double(particles_data["volume"][p_i]);
4908 if (volume == 0)
4909 {
4910 // value is automatically defined.
4911 volume = particles[p_i].shape->displaced_volume();
4912 if (volume == 0)
4913 {
4914 if constexpr (dim == 2)
4915 {
4916 volume =
4917 PI * particles[p_i].radius * particles[p_i].radius;
4918 }
4919 else if constexpr (dim == 3)
4920 {
4921 volume = 4.0 / 3.0 * PI * particles[p_i].radius *
4922 particles[p_i].radius * particles[p_i].radius;
4923 }
4924 }
4925 }
4926 particles[p_i].volume = volume;
4927 particles[p_i].mass =
4928 particles[p_i].volume *
4929 Utilities::string_to_double(particles_data["density"][p_i]);
4930
4931 particles[p_i].omega[0] =
4932 Utilities::string_to_double(particles_data["omega_x"][p_i]);
4933 particles[p_i].omega[1] =
4934 Utilities::string_to_double(particles_data["omega_y"][p_i]);
4935 particles[p_i].omega[2] =
4936 Utilities::string_to_double(particles_data["omega_z"][p_i]);
4937
4938 particles[p_i].inertia =
4939 parse_inertia(particles_data["inertia"][p_i]);
4940
4941 particles[p_i].pressure_location[0] =
4942 Utilities::string_to_double(particles_data["pressure_x"][p_i]);
4943 particles[p_i].pressure_location[1] =
4944 Utilities::string_to_double(particles_data["pressure_y"][p_i]);
4945 particles[p_i].pressure_location[2] =
4946 Utilities::string_to_double(particles_data["pressure_z"][p_i]);
4947
4948 particles[p_i].youngs_modulus =
4949 Utilities::string_to_double(particles_data["youngs_modulus"][p_i]);
4950 particles[p_i].restitution_coefficient = Utilities::string_to_double(
4951 particles_data["restitution_coefficient"][p_i]);
4952 particles[p_i].friction_coefficient = Utilities::string_to_double(
4953 particles_data["friction_coefficient"][p_i]);
4954 particles[p_i].poisson_ratio =
4955 Utilities::string_to_double(particles_data["poisson_ratio"][p_i]);
4956 particles[p_i].rolling_friction_coefficient =
4957 Utilities::string_to_double(
4958 particles_data["rolling_friction_coefficient"][p_i]);
4959 particles[p_i].initialize_previous_solution();
4960 if (particles_data["integrate_motion"][p_i] == "false")
4961 {
4962 particles[p_i].integrate_motion = false;
4963 }
4964 else
4965 {
4966 particles[p_i].integrate_motion = true;
4967 }
4968 particles[p_i].set_position(particles[p_i].position);
4969 particles[p_i].set_orientation(particles[p_i].orientation);
4970 }
4971 }
4972}
4973
4974template <int dim>
4975void
4977{
4978 TimerOutput::Scope t(this->computing_timer,
4979 "Update precalculated shape distance");
4980 for (unsigned int p_i = 0; p_i < particles.size(); ++p_i)
4981 {
4982 particles[p_i].update_precalculations(
4983 *this->dof_handler, particles[p_i].mesh_based_precalculations);
4984 }
4985}
4986
4987template <int dim>
4988void
4990{
4991 AssertThrow(
4992 !cfd_dem_parameters.dem_parameters.post_processing
4993 .lagrangian_post_processing_enabled,
4994 ExcMessage(
4995 "DEM lagrangian post-processing is not supported for lethe-fluid-sharp. "
4996 "Disable it in the DEM post-processing subsection."));
4997
4998 AssertThrow(!cfd_dem_parameters.dem_parameters.post_processing
4999 .particle_wall_collision_statistics,
5000 ExcMessage(
5001 "DEM particle-wall collision statistics are not supported for "
5002 "lethe-fluid-sharp. Disable them in the DEM post-processing "
5003 "subsection."));
5004
5006 *this->triangulation,
5007 this->simulation_parameters.mesh,
5008 this->simulation_parameters.manifolds_parameters,
5009 this->simulation_parameters.restart_parameters.restart,
5010 this->simulation_parameters.boundary_conditions.periodic_boundaries);
5011
5013 this->setup_dofs();
5014
5015 if (this->simulation_parameters.restart_parameters.restart == false)
5016 {
5017 refinement_control(true);
5019
5020 if (all_spheres)
5022 else
5024 }
5025
5027 this->simulation_parameters.initial_condition->type,
5028 this->simulation_parameters.restart_parameters.restart);
5030 if (this->simulation_parameters.restart_parameters.restart == false &&
5031 this->simulation_control->is_output_iteration())
5032 {
5033 // Match the fluid solver by writing the initial Sharp-IB particle output
5034 // on step 0 whenever the current iteration is an output iteration.
5036 }
5037
5038 while (this->simulation_control->integrate())
5039 {
5040 this->simulation_control->print_progression(this->pcout);
5041 this->forcing_function->set_time(
5042 this->simulation_control->get_current_time());
5043
5044 // We allow the physics to update their boundary conditions
5045 // according to their own parameters
5047 this->multiphysics->update_boundary_conditions();
5048
5049 this->dynamic_flow_control();
5050
5051 if (some_particles_are_coupled == false)
5053
5054
5055 if (this->simulation_control->is_at_start())
5056 {
5059
5060 ib_dem.update_particles_boundary_contact(this->particles,
5061 *this->dof_handler,
5062 *this->face_quadrature,
5063 *this->mapping);
5064 ib_dem.update_contact_candidates();
5065 this->iterate();
5066 }
5067 else
5068 {
5069 ib_done.clear();
5070 refinement_control(false);
5072
5073 ib_dem.update_particles_boundary_contact(this->particles,
5074 *this->dof_handler,
5075 *this->face_quadrature,
5076 *this->mapping);
5077 if (this->simulation_control->get_iteration_number() == 0 ||
5078 this->simulation_control->get_iteration_number() %
5079 this->simulation_parameters.particlesParameters
5080 ->contact_search_frequency ==
5081 0)
5082 ib_dem.update_contact_candidates();
5083
5084 // add initialization
5085 this->iterate();
5086 }
5087
5088 this->postprocess(false);
5090
5091 if (this->simulation_parameters.particlesParameters->calculate_force_ib)
5092 force_on_ib();
5095 this->finish_time_step();
5096 }
5097
5098 this->finish_simulation();
5099}
5100
5101// Pre-compile the 2D and 3D versopm solver to ensure that the library is
5102// valid before we actually compile the final solver
5103template class FluidDynamicsSharp<2>;
5104template class FluidDynamicsSharp<3>;
unsigned int number_of_previous_solutions(const Parameters::SimulationControl::TimeSteppingMethod method)
Get the number of previous time steps for a specific BDF scheme.
Definition bdf.h:97
Controls the name of output variables for the vtu.
TrilinosWrappers::SparseMatrix system_matrix
virtual void update_multiphysics_time_average_solution() override
Updates the average velocity field solution in the multiphyscics interface.
FluidDynamicsMatrixBased(SimulationParameters< dim > &nsparam, const FluidDynamicsFormulation fluid_dynamics_formulation=FluidDynamicsFormulation::standard)
Construct the matrix-based Navier-Stokes solver.
GlobalVectorType dof_overconstrained
void generate_cut_cells_map()
This function creates a map (cut_cells_map) that indicates if a cell is cut, and the particle id of t...
virtual void read_checkpoint() override
Restart a previous simulation from a checkpoint file.
std::pair< bool, bool > generate_cut_cell_candidates(const typename DoFHandler< dim >::cell_iterator &cell, const unsigned int p_id)
This function abstracts the generation of cell candidates that possibly are cut.
void copy_local_matrix_to_global_matrix(const StabilizedMethodsTensorCopyData< dim > &copy_data) override
Copy local cell information to global matrix This function is modified compared to the GLS function t...
FluidDynamicsSharp(CFDDEMSimulationParameters< dim > &nsparam)
virtual void write_checkpoint() override
Write a gls_sharp simulation checkpointing to allow for gls_sharp simulation restart This function st...
void apply_prescribed_particle_motion(IBParticle< dim > &particle, const double time, const double dt) const
Apply the prescribed motion of a particle whose dynamics is not integrated, at the end of the current...
std::map< unsigned int, bool > dof_with_more_then_one_particle
std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > vertices_to_cell
void build_ib_particle_handler(Particles::ParticleHandler< dim, dim > &particle_handler, typename DEM::dem_data_structures< dim >::particle_index_iterator_map &particle_container, std::unordered_set< unsigned int > &local_particle_ids) const
Build a temporary DEM particle handler from the current Sharp-IB particles.
void optimized_generate_cut_cells_map()
This function is only applied if all particles are spheres. It creates two maps (cut_cells_map and ce...
CFDDEMSimulationParameters< dim > cfd_dem_parameters
void force_on_ib()
Evaluate the forces applied on each of the IB particle.
std::shared_ptr< Shape< dim > > combined_shapes
void mesh_adapt_ib(const bool initial_refinement)
Adapt the mesh around each immersed-boundary particle. The refinement zone is defined by a ring in 2D...
bool cell_cut_by_p_absolute_distance(const typename DoFHandler< dim >::active_cell_iterator &cell, std::map< types::global_dof_index, Point< dim > > &support_points, unsigned int p)
Return a bool to define if a cell is cut by an IB. This function is built to handle special cases whe...
virtual std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook() override
Adds levelset to output files.
std::map< typename DoFHandler< dim >::active_cell_iterator, std::tuple< bool, unsigned int, double > > overconstrained_fluid_cell_map
PVDHandler ib_particles_pvdhandler_force_chains
void integrate_particles()
Integrate the particle velocity and position based on the forces and torques and applies the next val...
void assemble_local_system_matrix(const typename DoFHandler< dim >::active_cell_iterator &cell, NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
Assemble the local matrix for a given cell.
std::map< typename DoFHandler< dim >::active_cell_iterator, std::tuple< bool, unsigned int > > cells_inside_map
void fill_particle_properties(const IBParticle< dim > &particle, std::vector< double > &properties) const
Fill DEM particle properties from a Sharp-IB particle state.
void copy_local_rhs_to_global_rhs(const StabilizedMethodsTensorCopyData< dim > &copy_data) override
Copy local cell rhs information to global rhs This function is modified compared to the GLS function ...
std::shared_ptr< LevelsetGradientPostprocessor< dim > > levelset_gradient_postprocessor
std::map< typename DoFHandler< dim >::active_cell_iterator, std::tuple< bool, unsigned int, std::vector< unsigned int > > > cut_cells_map
std::vector< TableHandler > table_p
std::shared_ptr< LevelsetPostprocessor< dim > > levelset_postprocessor
void refinement_control(const bool initial_refinement)
Regroup and organize the refinement process around the IB particle.
void finish_time_step_particles()
Store the solution of the particles dynamics parameters for integration. Defines the table to store t...
void update_precalculations_for_ib()
This function updates the precalculations for every immersed particle.
void write_force_ib()
Write in a specifique file for each of the paticles its forces, velocity, position at each time step.
void sharp_edge()
Modify the system matrix to impose IB condition using the sharp_edge approach. The detail of this app...
void vertices_cell_mapping()
Map the vertex index to the cell that includes that vertex. This map is used to find all the cell clo...
GlobalVectorType local_dof_overconstrained
void build_contact_containers(const typename DEM::dem_data_structures< dim >::particle_index_iterator_map &particle_container, const std::unordered_set< unsigned int > &local_particle_ids, typename DEM::dem_data_structures< dim >::adjacent_particle_pairs &local_adjacent_particles, typename DEM::dem_data_structures< dim >::adjacent_particle_pairs &ghost_adjacent_particles) const
Build the DEM-style particle-particle contact containers of the Sharp-IB particles,...
std::map< unsigned int, std::pair< bool, typename DoFHandler< dim >::active_cell_iterator > > ib_done
void setup_assemblers() override
sets up the vector of assembler functions This function is modified compared to the GLS function to t...
std::tuple< bool, unsigned int, std::vector< types::global_dof_index > > cell_cut(const typename DoFHandler< dim >::active_cell_iterator &cell, std::vector< types::global_dof_index > &local_dof_indices, std::map< types::global_dof_index, Point< dim > > &support_points)
Return a bool to define if a cell is cut by an IB particle and the local DOFs of the cell for later u...
void check_whether_all_particles_are_sphere()
This function checks if all particles are spheres. If one of them is not, the code will use the regul...
std::pair< double, double > calculate_L2_error_particles()
Evaluate the L2 error on the computational domain if an analytical solution is given....
IBParticlesDEM< dim > ib_dem
void solve() override
solve Solves the Navier-Stokes problem
std::vector< IBParticle< dim > > particles
virtual void postprocess_fd(bool firstIter) override
Same function as its standard GLS counterpart but it used the error evaluation that takes into accoun...
void define_particles()
Defines the particle structure and value based on the parameter file. This structure gives access to ...
std::vector< std::shared_ptr< NavierStokesAssemblerBase< dim > > > assemblers_inside_ib
void assemble_local_system_rhs(const typename DoFHandler< dim >::active_cell_iterator &cell, NavierStokesScratchData< dim > &scratch_data, StabilizedMethodsTensorCopyData< dim > &copy_data) override
Assemble the local rhs for a given cell.
void handle_dem_particle_output_and_postprocessing()
Mirror DEM-style particle output and post-processing for Sharp-IB particles.
bool point_inside_cell(const typename DoFHandler< dim >::active_cell_iterator &cell, Point< dim > point)
Return a bool that describes if a cell contains a specific point.
This class implements a boundary conditions for the fluid dynamics solver where the velocity componen...
double value(const Point< dim > &point, const unsigned int component) const override
Calculates the value of a Function-type fluid dynamics equations.
Class that assembles the core of the Navier-Stokes equation with free surface using CLS modeling....
Class that assembles the transient time arising from BDF time integration for the Navier Stokes equat...
Class that assembles the core of the Navier-Stokes equation using a Rheological model to predict non-...
Class that assembles the coriolis and the centrifugal if a simulation is carried out in a rotating fr...
Assembles the transient time arising from BDF time integration for the Navier-Stokes equation with fr...
Assembles the core of the Navier-Stokes equation with free surface using CLS modeling....
Assembles the core of the Navier-Stokes equation using a Rheological model to predict non-Newtonian b...
Define the behavior of a specific particle for the sharp interface IB solver.
Definition ib_particle.h:26
std::vector< Tensor< 1, 3 > > previous_orientation
Previous time step's orientation.
Tensor< 1, 3 > orientation
Orientation, with 0 angular position by default on every axis.
double radius
Effective radius, which is the actual radius for spheres.
Tensor< 1, 3 > omega
Angular velocity.
std::shared_ptr< Functions::ParsedFunction< dim > > f_omega
Function that determines the angular velocity.
Tensor< 1, 3 > fluid_forces
Total fluid force applied on the particle.
std::vector< Point< dim > > previous_positions
Positions at the last n time steps. n depends on the time integration scheme.
double mass
Particle's mass.
Tensor< 1, 3 > velocity
Translational velocity.
std::shared_ptr< Functions::ParsedFunction< dim > > f_velocity
Function that determines the velocity.
Tensor< 1, 3 > fluid_torque
Fluid torque applied on the particle.
std::shared_ptr< Functions::ParsedFunction< dim > > f_position
Function that determines the position.
std::shared_ptr< Functions::ParsedFunction< dim > > f_orientation
Function that determines the orientation.
Point< dim > position
Position, which corresponds to the centroid for most implemented shapes.
Define where the sharp immersed-boundaries are imposed on Eulerian grid.
Definition ib_stencil.h:21
virtual std::tuple< Point< dim >, std::vector< Point< dim > > > support_points_for_interpolation(const unsigned int degree, const double length_ratio, IBParticle< dim > &p, const Point< dim > &dof_point, const typename DoFHandler< dim >::active_cell_iterator &cell_guess)
Find the DOF at which we try to apply the IB by interpolation and the location of the support points ...
Definition ib_stencil.cc:99
virtual double ib_velocity(IBParticle< dim > &p, const Point< dim > &dof_point, const unsigned int component, const typename DoFHandler< dim >::active_cell_iterator &cell_guess)
Return the velocity of the IB used in the RHS of the equation.
virtual std::vector< double > coefficients(const unsigned int degree, const double length_ratio)
Return the coefficients (weights) of the stencil.
Definition ib_stencil.cc:43
virtual Point< dim > point_for_cell_detection(IBParticle< dim > &p, const Point< dim > &dof_point, const typename DoFHandler< dim >::active_cell_iterator &cell_guess)
Define the point used to define the cell used for the stencil calculation.
virtual unsigned int number_of_interpolation_support_points(const unsigned int degree)
Return the number of points used by the interpolation stencil (excluding the dof itself) for a stenci...
Definition ib_stencil.cc:11
Class that assembles a Poisson problem for all velocity components and pressure variables....
virtual void set_initial_condition(const Parameters::FluidDynamicsInitialConditionType initial_condition_type, const bool restart=false)
std::shared_ptr< GlobalVectorType > present_solution
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
virtual void refine_mesh()
Allow the refinement of the mesh according to one of the 2 methods proposed.
bool check_existance_of_bc(BoundaryConditions::FluidDynamicsBoundaryType bc)
virtual void postprocess_fd(bool first_iteration)
Post-process fluid dynamics after an iteration.
std::shared_ptr< std::vector< GlobalVectorType > > previous_solutions
std::shared_ptr< Function< dim > > forcing_function
std::shared_ptr< SimulationControl > simulation_control
std::vector< std::shared_ptr< NavierStokesAssemblerBase< dim > > > assemblers
std::shared_ptr< MultiphysicsInterface< dim > > multiphysics
std::shared_ptr< DoFHandler< dim > > dof_handler
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
Class that stores the information required by the assembly procedure for a Navier-Stokes equation....
void calculate_physical_properties()
Calculates the physical properties. This function calculates the physical properties that may be requ...
void reinit(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType &current_solution, const std::vector< VectorType > &previous_solutions, const VectorType &sum_over_previous_stages, const std::shared_ptr< Function< dim > > &forcing_function, const Tensor< 1, dim > &beta_force, const double pressure_scaling_factor)
Reinitializes the content of the scratch.
void reinit_cls(const typename DoFHandler< dim >::active_cell_iterator &cell, const VectorType &current_solution, const VectorType &current_filtered_solution, const std::vector< VectorType > &previous_solutions)
Reinitialize the content of the scratch for the cls.
Class that assembles the weak formulation of an outlet boundary condition according to the following ...
Class that assembles the core of the Navier-Stokes equation. According to the following weak form: ...
Parameters for floating walls in DEM simulations.
Class that assembles the special case of partial slip condition using the weak formulation of a Diric...
unsigned int get_current_newton_iteration() const
Class that assembles a Neumann boundary condition. According to the following weak form: (p-mu*grad_u...
Class responsible for storing the information calculated using the assembly of stabilized Tensor<1,...
Definition copy_data.h:166
FullMatrix< double > local_matrix
Definition copy_data.h:204
void reset()
Resets the cell_matrix, cell_rhs, strong_residual and strong_jacobian to zero.
Definition copy_data.h:190
std::vector< types::global_dof_index > local_dof_indices
Definition copy_data.h:206
Building patches of particle properties for visualization. This function is taken from Aspect and dea...
void build_patches(Particles::ParticleHandler< dim > &particle_handler, const std::vector< std::pair< std::string, int > > &properties)
Build the patches of properties of particles for visualization.
Class that assembles the weak formulation of a Dirichlet boundary condition using the Nitsche method....
void fill_string_vectors_from_file(std::map< std::string, std::vector< std::string > > &map, const std::string &file_name, const std::string &delimiter=" ")
Function that read a file that was build from a dealii table and create a map with the key being the ...
Definition utilities.cc:352
void fill_vectors_from_file(std::map< std::string, std::vector< double > > &map, const std::string &file_name, const std::string &delimiter=" ")
function that read a file that was build from a dealii table and fill 2 vectors. The first vector con...
Definition utilities.cc:299
void fill_table_from_file(TableHandler &table, const std::string &file_name, const std::string &delimiter=" ")
Reads a file generated by a deal.II TableHandler and fills a TableHandler with its data.
Definition utilities.cc:253
void read_mesh_and_manifolds(parallel::DistributedTriangulationBase< dim, spacedim > &triangulation, const Parameters::Mesh< dim, spacedim > &mesh_parameters, const Parameters::Manifolds &manifolds_parameters, bool restart, const Parameters::PeriodicBoundaries &periodic_boundaries)
Completely sets up a mesh and its manifolds.
Definition grids.cc:447
@ pressure
Pressure scalar field from fluid dynamics.
@ fluid_dynamics
Fluid Dynamics (Velocity,Pressure).
@ CLS
PropertiesIndex
Particle property indices for CFD-DEM simulations.
@ n_properties
Number of properties.
void vertices_cell_mapping(const DoFHandler< dim > &dof_handler, std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > &vertices_cell_map)
Map the vertex index to the cells that includes that vertex.
std::vector< typename DoFHandler< dim >::active_cell_iterator > find_cells_around_cell(std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > &vertices_cell_map, const typename DoFHandler< dim >::active_cell_iterator &cell)
Return a vector of cells around a cell. The vector of cells includes all the cells that share a verte...
DoFHandler< dim >::active_cell_iterator find_cell_around_point_with_neighbors(const DoFHandler< dim > &dof_handler, std::map< unsigned int, std::set< typename DoFHandler< dim >::active_cell_iterator > > &vertices_cell_map, const typename DoFHandler< dim >::active_cell_iterator &cell, const Point< dim > &point)
Return the cell around a point based on an initial guess of a nearby cell.
DoFHandler< dim >::active_cell_iterator find_cell_around_point_with_tree(const DoFHandler< dim > &dof_handler, const Point< dim > &point)
Return the cell around a point by starting from the least refined level and iterating over children.
double calculate_shear_rate_magnitude(const Tensor< 2, dim > shear_rate)
Calculates the magnitude of the shear rate tensor given as input.
std::shared_ptr< ParticlesForceChainsBase< dim, PropertiesIndex > > set_force_chains_contact_force_model(const DEMSolverParameters< dim > &dem_parameters)
Return the particle-particle contact force model based on the spring-dashpot model and the rolling re...
void write_vtu_and_pvd(PVDHandler &pvd_handler, const DataOutInterface< dim, spacedim > &data_out, const std::string &folder, const std::string &file_prefix, const double time, const unsigned int iter, const unsigned int group_files, const MPI_Comm &mpi_communicator, const unsigned int digits=5)
Output the data out to "group_files" vtu files, with a pvtu file and a pvd to store the timing This f...
ankerl::unordered_dense::map< types::particle_index, Particles::ParticleIterator< dim > > particle_index_iterator_map
ankerl::unordered_dense::map< types::particle_index, adjacent_particle_pairs_value > adjacent_particle_pairs
virtual const std::vector< DataOutBase::Patch< 0, dim > > & get_patches() const override
virtual std::vector< std::string > get_dataset_names() const override
std::vector< DataOutBase::Patch< 0, dim > > patches
void build_patches(std::vector< IBParticle< dim > > particles)
std::vector< std::pair< std::string, int > > properties_to_write
std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > vector_datasets
virtual std::vector< std::tuple< unsigned int, unsigned int, std::string, DataComponentInterpretation::DataComponentInterpretation > > get_nonscalar_data_ranges() const override
Struct containing information about the solution output. It is used to pass the information required ...
Handle the information related to the calculation of the particle-particle contact force....
Particles::ParticleIterator< dim > particle_two
Tensor< 1, 3 > tangential_displacement
Tensor< 1, 3 > rolling_resistance_spring_torque
Tensor< 1, 3 > tensor_nd_to_3d(const Tensor< 1, dim > &tensor)
Tensor< 1, 2 > tensor_nd_to_2d(const Tensor< 1, dim > &tensor)
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.
void update_particle_container(typename DEM::dem_data_structures< dim >::particle_index_iterator_map &particle_container, const Particles::ParticleHandler< dim > *particle_handler)
Update the iterators to local particles in a map of particles (particle_container).