Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
interface_tools.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2024-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
6
7#include <deal.II/dofs/dof_tools.h>
8
9#include <deal.II/grid/grid_tools.h>
10
11#include <deal.II/hp/fe_collection.h>
12#include <deal.II/hp/q_collection.h>
13
14#include <deal.II/non_matching/fe_values.h>
15#include <deal.II/non_matching/mesh_classifier.h>
16#include <deal.II/non_matching/quadrature_generator.h>
17
18template <int dim>
19double
21 FEPointEvaluation<1, dim> &fe_point_evaluation,
22 const typename DoFHandler<dim>::active_cell_iterator &cell,
23 Vector<double> cell_dof_level_set_values,
24 const double corr,
25 const unsigned int n_quad_points)
26{
27 const unsigned int n_dofs = cell_dof_level_set_values.size();
28
29 // Initialize required variables to compute local volume
30 const BoundingBox<dim> unit_box = create_unit_bounding_box<dim>();
31 CellWiseFunction<dim> signed_distance_function =
32 CellWiseFunction<dim>(cell->get_fe().degree);
33
34 hp::QCollection<1> q_collection;
35 q_collection.push_back(QGauss<1>(n_quad_points));
36
37 NonMatching::QuadratureGenerator<dim> quadrature_generator =
38 NonMatching::QuadratureGenerator<dim>(q_collection);
39
40 for (unsigned int j = 0; j < n_dofs; j++)
41 {
42 cell_dof_level_set_values[j] += corr;
43 }
44
45 signed_distance_function.set_active_cell(cell_dof_level_set_values);
46 quadrature_generator.generate(signed_distance_function, unit_box);
47
48 const Quadrature<dim> inside_quadrature =
49 quadrature_generator.get_inside_quadrature();
50
51 if (inside_quadrature.size() == 0)
52 return 0.0;
53
54 fe_point_evaluation.reinit(cell, inside_quadrature.get_points());
55
56 double inside_cell_volume = 0.0;
57 for (unsigned int q = 0; q < inside_quadrature.size(); q++)
58 {
59 /* Compute the volume int 1*JxW*dOmega. FEPointEvaluation.JxW() does not
60 return the right thing.*/
61 inside_cell_volume += fe_point_evaluation.jacobian(q).determinant() *
62 inside_quadrature.weight(q);
63 }
64
65 return inside_cell_volume;
66}
67
68template <int dim, typename VectorType>
69std::pair<double, double>
71 const DoFHandler<dim> &dof_handler,
72 const FiniteElement<dim> &fe,
73 const VectorType &level_set_vector_relevant_copy)
74{
75 // Get MPI communicator
76 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
77
78 NonMatching::MeshClassifier<dim> mesh_classifier(
79 dof_handler, level_set_vector_relevant_copy);
80 mesh_classifier.reclassify();
81
82 const hp::FECollection<dim> fe_collection(fe);
83
84 const QGauss<1> quadrature_1D(fe.degree + 1);
85
86 NonMatching::RegionUpdateFlags region_update_flags;
87 region_update_flags.inside = update_JxW_values;
88 region_update_flags.surface = update_JxW_values;
89
90 NonMatching::FEValues<dim> non_matching_fe_values(
91 fe_collection,
92 quadrature_1D,
93 region_update_flags,
94 mesh_classifier,
95 dof_handler,
96 level_set_vector_relevant_copy);
97
98 double volume = 0.0;
99 double surface = 0.0;
100 for (const auto &cell : dof_handler.active_cell_iterators())
101 {
102 if (cell->is_locally_owned())
103 {
104 non_matching_fe_values.reinit(cell);
105
106 const std::optional<FEValues<dim>> &inside_fe_values =
107 non_matching_fe_values.get_inside_fe_values();
108
109 if (inside_fe_values)
110 for (const unsigned int q :
111 inside_fe_values->quadrature_point_indices())
112 {
113 volume += inside_fe_values->JxW(q);
114 }
115
116 const std::optional<NonMatching::FEImmersedSurfaceValues<dim>>
117 &surface_fe_values = non_matching_fe_values.get_surface_fe_values();
118
119 if (surface_fe_values)
120 for (const unsigned int q :
121 surface_fe_values->quadrature_point_indices())
122 {
123 surface += surface_fe_values->JxW(q);
124 }
125 }
126 }
127 volume = Utilities::MPI::sum(volume, mpi_communicator);
128 surface = Utilities::MPI::sum(surface, mpi_communicator);
129
130 return {volume, surface};
131}
132
133template std::pair<double, double>
135 const DoFHandler<2> &dof_handler,
136 const FiniteElement<2> &fe,
137 const GlobalVectorType &level_set_vector_relevant_copy);
138
139template std::pair<double, double>
141 const DoFHandler<3> &dof_handler,
142 const FiniteElement<3> &fe,
143 const GlobalVectorType &level_set_vector_relevant_copy);
144
145template <int dim, typename VectorType>
146std::pair<double, double>
147InterfaceTools::integrate_volume_and_surface(const DoFHandler<dim> &dof_handler,
148 const FiniteElement<dim> &fe,
149 const VectorType &level_set_vector,
150 const double iso_level)
151{
152 // Get MPI communicator
153 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
154
155 VectorType level_set_vector_owned_copy(dof_handler.locally_owned_dofs(),
156 mpi_communicator);
157
158 level_set_vector_owned_copy = level_set_vector;
159
160 level_set_vector_owned_copy.add(-iso_level);
161
162 VectorType level_set_vector_relevant_copy(
163 dof_handler.locally_owned_dofs(),
164 DoFTools::extract_locally_relevant_dofs(dof_handler),
165 mpi_communicator);
166
167 level_set_vector_relevant_copy = level_set_vector_owned_copy;
168
169 return integrate_volume_and_surface(dof_handler,
170 fe,
171 level_set_vector_relevant_copy);
172}
173
174template std::pair<double, double>
176 const DoFHandler<2> &dof_handler,
177 const FiniteElement<2> &fe,
178 const GlobalVectorType &level_set_vector,
179 const double iso_level);
180template std::pair<double, double>
182 const DoFHandler<3> &dof_handler,
183 const FiniteElement<3> &fe,
184 const GlobalVectorType &level_set_vector,
185 const double iso_level);
186
187template <int dim, typename VectorType>
188std::pair<Point<dim>, Tensor<1, dim>>
190 const DoFHandler<dim> &dof_handler,
191 const FiniteElement<dim> &fe,
192 const VectorType &level_set_vector_relevant_copy,
193 const Mapping<dim> &mapping_velocity,
194 const DoFHandler<dim> &dof_handler_velocity,
195 const FiniteElement<dim> &fe_velocity,
196 const VectorType &velocity_vector)
197{
198 // Get MPI communicator
199 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
200
201 NonMatching::MeshClassifier<dim> mesh_classifier(
202 dof_handler, level_set_vector_relevant_copy);
203 mesh_classifier.reclassify();
204
205 const hp::FECollection<dim> fe_collection(fe);
206
207 const QGauss<1> quadrature_1D(fe.degree + 1);
208
209 NonMatching::RegionUpdateFlags region_update_flags;
210 region_update_flags.inside =
211 update_JxW_values | update_quadrature_points | update_values;
212
213 NonMatching::FEValues<dim> non_matching_fe_values(
214 fe_collection,
215 quadrature_1D,
216 region_update_flags,
217 mesh_classifier,
218 dof_handler,
219 level_set_vector_relevant_copy);
220
221 double volume = 0.0;
222
223 Point<dim> barycenter;
224 Tensor<1, dim> barycenter_velocity;
225
226 Vector<double> cell_dof_values(fe_velocity.dofs_per_cell);
227
228 FEPointEvaluation<dim + 1, dim> fe_point_evaluation(mapping_velocity,
229 fe_velocity,
230 update_values);
231
232 for (const auto &cell : dof_handler.active_cell_iterators())
233 {
234 if (cell->is_locally_owned())
235 {
236 non_matching_fe_values.reinit(cell);
237
238 const std::optional<FEValues<dim>> &inside_fe_values =
239 non_matching_fe_values.get_inside_fe_values();
240
241 if (inside_fe_values)
242 {
243 std::vector<Point<dim>> quadrature_points =
244 inside_fe_values->get_quadrature_points();
245
246 std::vector<Point<dim>> quadrature_points_ref(
247 inside_fe_values->n_quadrature_points);
248
249 mapping_velocity.transform_points_real_to_unit_cell(
250 cell, quadrature_points, quadrature_points_ref);
251
252 typename DoFHandler<dim>::active_cell_iterator cell_fd(
253 &(dof_handler_velocity.get_triangulation()),
254 cell->level(),
255 cell->index(),
256 &dof_handler_velocity);
257
258 fe_point_evaluation.reinit(cell, quadrature_points_ref);
259
260 cell_fd->get_dof_values(velocity_vector,
261 cell_dof_values.begin(),
262 cell_dof_values.end());
263
264 fe_point_evaluation.evaluate(cell_dof_values,
265 EvaluationFlags::values);
266
267 for (const unsigned int q :
268 inside_fe_values->quadrature_point_indices())
269 {
270 volume += inside_fe_values->JxW(q);
271
272 auto velocity_value = fe_point_evaluation.get_value(q);
273
274 for (int i = 0; i < dim; i++)
275 {
276 barycenter[i] +=
277 quadrature_points[q][i] * inside_fe_values->JxW(q);
278
279 barycenter_velocity[i] +=
280 velocity_value[i] * inside_fe_values->JxW(q);
281 }
282 }
283 }
284 }
285 }
286
287 volume = Utilities::MPI::sum(volume, mpi_communicator);
288 for (int i = 0; i < dim; i++)
289 {
290 barycenter[i] =
291 Utilities::MPI::sum(barycenter[i], mpi_communicator) / (volume + 1e-16);
292 barycenter_velocity[i] =
293 Utilities::MPI::sum(barycenter_velocity[i], mpi_communicator) /
294 (volume + 1e-16);
295 }
296
297 return {barycenter, barycenter_velocity};
298}
299
300template std::pair<Point<2>, Tensor<1, 2>>
302 const DoFHandler<2> &dof_handler,
303 const FiniteElement<2> &fe,
304 const GlobalVectorType &level_set_vector_relevant_copy,
305 const Mapping<2> &mapping_velocity,
306 const DoFHandler<2> &dof_handler_velocity,
307 const FiniteElement<2> &fe_velocity,
309
310template std::pair<Point<3>, Tensor<1, 3>>
312 const DoFHandler<3> &dof_handler,
313 const FiniteElement<3> &fe,
314 const GlobalVectorType &level_set_vector_relevant_copy,
315 const Mapping<3> &mapping_velocity,
316 const DoFHandler<3> &dof_handler_velocity,
317 const FiniteElement<3> &fe_velocity,
319
320
321template <int dim, typename VectorType>
322std::pair<Point<dim>, Tensor<1, dim>>
324 const DoFHandler<dim> &dof_handler,
325 const FiniteElement<dim> &fe,
326 const VectorType &level_set_vector,
327 const Mapping<dim> &mapping_velocity,
328 const DoFHandler<dim> &dof_handler_velocity,
329 const FiniteElement<dim> &fe_velocity,
330 const VectorType &velocity_vector,
331 const double iso_level)
332{
333 // Get MPI communicator
334 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
335
336 VectorType level_set_vector_owned_copy(dof_handler.locally_owned_dofs(),
337 mpi_communicator);
338
339 level_set_vector_owned_copy = level_set_vector;
340
341 level_set_vector_owned_copy *= -1.0;
342 level_set_vector_owned_copy.add(iso_level);
343
344 VectorType level_set_vector_relevant_copy(
345 dof_handler.locally_owned_dofs(),
346 DoFTools::extract_locally_relevant_dofs(dof_handler),
347 mpi_communicator);
348
349 level_set_vector_relevant_copy = level_set_vector_owned_copy;
350
351 return integrate_barycenter(dof_handler,
352 fe,
353 level_set_vector_relevant_copy,
354 mapping_velocity,
355 dof_handler_velocity,
356 fe_velocity,
357 velocity_vector);
358}
359
360template std::pair<Point<2>, Tensor<1, 2>>
361InterfaceTools::integrate_barycenter(const DoFHandler<2> &dof_handler,
362 const FiniteElement<2> &fe,
363 const GlobalVectorType &level_set_vector,
364 const Mapping<2> &mapping_velocity,
365 const DoFHandler<2> &dof_handler_velocity,
366 const FiniteElement<2> &fe_velocity,
368 const double iso_level);
369
370template std::pair<Point<3>, Tensor<1, 3>>
371InterfaceTools::integrate_barycenter(const DoFHandler<3> &dof_handler,
372 const FiniteElement<3> &fe,
373 const GlobalVectorType &level_set_vector,
374 const Mapping<3> &mapping_velocity,
375 const DoFHandler<3> &dof_handler_velocity,
376 const FiniteElement<3> &fe_velocity,
378 const double iso_level);
379
380template <int dim, typename VectorType>
381void
383 const Mapping<dim> &mapping,
384 const DoFHandler<dim> &dof_handler,
385 const FiniteElement<dim> &fe,
386 const VectorType &level_set_vector,
387 const double iso_level,
388 std::map<types::global_cell_index, std::vector<Point<dim>>>
389 &interface_reconstruction_vertices,
390 std::map<types::global_cell_index, std::vector<CellData<dim - 1>>>
391 &interface_reconstruction_cells,
392 std::set<types::global_dof_index> &intersected_dofs)
393{
394 GridTools::MarchingCubeAlgorithm<dim, VectorType> marching_cube(mapping,
395 fe,
396 1,
397 1e-10);
398 const unsigned int dofs_per_cell = fe.n_dofs_per_cell();
399
400 for (const auto &cell : dof_handler.active_cell_iterators())
401 {
402 if ((cell->is_locally_owned()) || (cell->is_ghost()))
403 {
404 std::vector<Point<dim>> surface_vertices;
405 std::vector<CellData<dim - 1>> surface_cells;
406
407 marching_cube.process_cell(
408 cell, level_set_vector, iso_level, surface_vertices, surface_cells);
409
410 // If the cell is intersected, reconstruct the interface in it
411 if (surface_vertices.size() != 0)
412 {
413 const unsigned int cell_index = cell->global_active_cell_index();
414
415 // Store the interface reconstruction vertices and cells
416 interface_reconstruction_vertices[cell_index] = surface_vertices;
417 interface_reconstruction_cells[cell_index] = surface_cells;
418
419 if (cell->is_locally_owned())
420 { // Store the DoFs of the intersected volume cell
421 std::vector<types::global_dof_index> dof_indices(
422 dofs_per_cell);
423 cell->get_dof_indices(dof_indices);
424
425 for (unsigned int i = 0; i < dofs_per_cell; ++i)
426 {
427 intersected_dofs.insert(dof_indices[i]);
428 }
429 }
430 }
431 }
432 }
433}
434
435template void
437 const Mapping<2> &mapping,
438 const DoFHandler<2> &dof_handler,
439 const FiniteElement<2> &fe,
440 const GlobalVectorType &level_set_vector,
441 const double iso_level,
442 std::map<types::global_cell_index, std::vector<Point<2>>>
443 &interface_reconstruction_vertices,
444 std::map<types::global_cell_index, std::vector<CellData<1>>>
445 &interface_reconstruction_cells,
446 std::set<types::global_dof_index> &intersected_dofs);
447
448template void
450 const Mapping<3> &mapping,
451 const DoFHandler<3> &dof_handler,
452 const FiniteElement<3> &fe,
453 const GlobalVectorType &level_set_vector,
454 const double iso_level,
455 std::map<types::global_cell_index, std::vector<Point<3>>>
456 &interface_reconstruction_vertices,
457 std::map<types::global_cell_index, std::vector<CellData<2>>>
458 &interface_reconstruction_cells,
459 std::set<types::global_dof_index> &intersected_dofs);
460
461template void
463 const Mapping<2> &mapping,
464 const DoFHandler<2> &dof_handler,
465 const FiniteElement<2> &fe,
466 const Vector<double> &level_set_vector,
467 const double iso_level,
468 std::map<types::global_cell_index, std::vector<Point<2>>>
469 &interface_reconstruction_vertices,
470 std::map<types::global_cell_index, std::vector<CellData<1>>>
471 &interface_reconstruction_cells,
472 std::set<types::global_dof_index> &intersected_dofs);
473
474template void
476 const Mapping<3> &mapping,
477 const DoFHandler<3> &dof_handler,
478 const FiniteElement<3> &fe,
479 const Vector<double> &level_set_vector,
480 const double iso_level,
481 std::map<types::global_cell_index, std::vector<Point<3>>>
482 &interface_reconstruction_vertices,
483 std::map<types::global_cell_index, std::vector<CellData<2>>>
484 &interface_reconstruction_cells,
485 std::set<types::global_dof_index> &intersected_dofs);
486
487
488template <int dim, typename VectorType>
489void
491{
492 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
493
494 dof_handler.distribute_dofs(*this->fe);
495
496 locally_owned_dofs = dof_handler.locally_owned_dofs();
497 locally_relevant_dofs = DoFTools::extract_locally_relevant_dofs(dof_handler);
498 locally_active_dofs = DoFTools::extract_locally_active_dofs(dof_handler);
499
500 level_set.reinit(locally_owned_dofs, locally_relevant_dofs, mpi_communicator);
501
504 mpi_communicator);
507 mpi_communicator);
510 mpi_communicator);
511
512 distance.reinit(locally_owned_dofs, locally_active_dofs, mpi_communicator);
515 mpi_communicator);
516
519 mpi_communicator);
520
521 constraints.clear();
523 DoFTools::make_hanging_node_constraints(dof_handler, constraints);
524 constraints.close();
525}
526
527template <int dim, typename VectorType>
528void
531 const DoFHandler<dim> &background_dof_handler,
532 const VectorType &background_level_set_vector)
533{
534 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
535
536 VectorType tmp_local_level_set(this->locally_owned_dofs, mpi_communicator);
537
538 FETools::interpolate(background_dof_handler,
539 background_level_set_vector,
542 tmp_local_level_set);
543
544 tmp_local_level_set *= scaling;
545
546 level_set = tmp_local_level_set;
547}
548
549template <int dim, typename VectorType>
550void
552{
554 {
555 announce_string(this->pcout, "Signed Distance Solver");
556 }
557 // Gain the writing right.
559
560 // Clear maps and sets
563 intersected_dofs.clear();
564
566
567 // Identify intersected cells and compute the interface reconstruction.
570 *fe,
571 level_set,
572 iso_level,
576
577 /* Compute the distance for the DoFs of the intersected cells (the ones in
578 the intersected_dofs set). They correspond to the first neighbor DoFs.*/
580
581 /* Compute signed distance from distance (only first neighbors have an
582 updated value)*/
584
585 // Conserve local and global volume
588
589 /* Compute the distance for the DoFs of the rest of the mesh. They
590 correspond to the second neighbors DoFs. */
592
593 // Compute signed distance from distance (all DoFs have updated value)
595
596 // Update ghost values to regain reading ability.
598}
599
600template <int dim, typename VectorType>
601void
603{
604 /* Initialization of the active DoFs to the max distance we want to
605 find the signed distance. It requires a loop on the active DoFs to initialize
606 also the distance value of the ghost DoFs. Otherwise, they are set to 0.0 by
607 default. */
608 for (auto p : this->locally_active_dofs)
609 {
612
613 const double sgn_level_set_value = sgn(level_set(p) - iso_level);
614 signed_distance(p) = max_distance * sgn_level_set_value;
615 signed_distance_with_ghost(p) = max_distance * sgn_level_set_value;
616 }
617}
618
619template <int dim, typename VectorType>
622{
623 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
624
625 VectorType tmp_local_level_set(this->locally_owned_dofs, mpi_communicator);
626
627 // Loop on the DoFs to be compatible with the difference in vector type
628 // between level_set and signed_distance
629 for (auto p : this->locally_owned_dofs)
630 {
631 tmp_local_level_set(p) = signed_distance(p);
632 }
633
634 level_set = tmp_local_level_set;
635
636 return level_set;
637}
638
639template <int dim, typename VectorType>
640void
642 const
643{
644 /* To have the right to write in a LinearAlgebra::distributed::Vector, we
645 have to zero out the ghost values.*/
646 signed_distance.zero_out_ghost_values();
647 signed_distance_with_ghost.zero_out_ghost_values();
648 distance.zero_out_ghost_values();
649 distance_with_ghost.zero_out_ghost_values();
650 volume_correction.zero_out_ghost_values();
651}
652
653template <int dim, typename VectorType>
654void
656 const
657{
658 /* To have the right to read a LinearAlgebra::distributed::Vector, we have
659 to update the ghost values.*/
660 signed_distance.update_ghost_values();
661 signed_distance_with_ghost.update_ghost_values();
662 distance.update_ghost_values();
663 distance_with_ghost.update_ghost_values();
664 volume_correction.update_ghost_values();
665}
666
667template <int dim, typename VectorType>
668void
670{
671 // Exchange and "select" min value between the processes
672 distance.compress(VectorOperation::min);
673
674 // Update local ghost (distance becomes read only)
675 distance.update_ghost_values();
676
677 /* Copy distance to distance_with_ghost to keep the knowledge of local ghost
678 values and to have a read only version of the vector*/
680
681 /* Zero out ghost DoFs to regain write functionalities in distance (it
682 becomes write only, that is why we need distance_with_ghost - to read the
683 ghost values in it).*/
684 distance.zero_out_ghost_values();
685
686 /* Copy the ghost values back in distance (zero_out_ghost_values() puts
687 zeros in ghost DoFs)*/
688 for (auto p : this->locally_active_dofs)
689 {
690 /* We need to have the ghost values in distance for future
691 compress(VectorOperation::min) operation*/
693 }
694}
695
696template <int dim, typename VectorType>
697void
700{
701 /* The signed distance for the first neighbors (the DoFs belonging to the
702 * cells intersected by the reconstructed interface. This is a brute force
703 * distance computation, meaning the distance is computed geometrically, as
704 * presented by Ausas et al. (2011). */
705
706 // DoF coordinates
707 std::map<types::global_dof_index, Point<dim>> dof_support_points =
708 DoFTools::map_dofs_to_support_points(*mapping, dof_handler);
709
710 // Loop over the intersected cells (volume cells)
711 for (auto &intersected_cell : interface_reconstruction_cells)
712 {
713 const unsigned int cell_index = intersected_cell.first;
714
715 // Create interface reconstruction triangulation (surface triangulation)
716 // in the intersected volume cell
717 std::vector<Point<dim>> surface_vertices =
719 std::vector<CellData<dim - 1>> surface_cells = intersected_cell.second;
720
721 Triangulation<dim - 1, dim> surface_triangulation;
722 surface_triangulation.create_triangulation(surface_vertices,
723 surface_cells,
724 {});
725
726 /* Loop over all DoFs of the volume mesh belonging to an intersected
727 * volume cell. This is more expensive, but it is required to have the
728 * right signed distance approximation for the first neighbors.*/
729 for (const types::global_dof_index &intersected_dof : intersected_dofs)
730 {
731 const Point<dim> y = dof_support_points.at(intersected_dof);
732
733 /* Loop over the surface cells of the interface reconstruction in
734 * the volume cell. In 2D, there is only 1 surface cell (line),
735 * while in 3D, it can vary from 1 to 4 or 5 (triangles), depending
736 * on the marching cube algorithm.*/
737 for (const auto &surface_cell :
738 surface_triangulation.active_cell_iterators())
739 {
740 // Store the current surface cell vertex coordinates
741 unsigned int surface_cell_n_vertices = surface_cell->n_vertices();
742 std::vector<Point<dim>> surface_cell_vertices(
743 surface_cell_n_vertices);
744 for (unsigned int p = 0; p < surface_cell_n_vertices; p++)
745 {
746 surface_cell_vertices[p] = surface_cell->vertex(p);
747 }
748
749 // Compute the geometrical distance between the surface cell
750 // (line in 2D, triangle in 3D) and the DoF
752 surface_cell_vertices, y);
753
754 // Select the minimum distance
755 distance(intersected_dof) =
756 std::min(std::abs(distance(intersected_dof)), std::abs(D));
757 }
758 }
759 }
761}
762
763template <int dim, typename VectorType>
764void
767{
768 /* The signed distance for the second neighbors (the cells not intersected
769 * by the interface) is resolved according the minimization problem
770 * presented by Ausas et al. (2011). The method looks for the point in the
771 * opposite faces of each second neighbor DoFs that minimizes the distance to
772 * the interface. It works in a similar manner as a marching algorithm from
773 * the knowledge of the signed distance for the interface first neighbors. */
774
775 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
776
777 // Initialization of connectivity data. We are interested in the opposite DoFs
778 // of each face of the cell. This reduces the number of calls to
779 // FEPointEvaluation.reinit() compared to a routine based on the opposite
780 // faces of each DoF of the cell.
781 const unsigned int dofs_per_cell = fe->n_dofs_per_cell();
782 unsigned int faces_per_cell = 4;
783 if constexpr (dim == 3)
784 faces_per_cell = 6;
785
786 unsigned int n_opposite_dofs_per_faces = 2;
787 if constexpr (dim == 3)
788 n_opposite_dofs_per_faces = 4;
789
790 unsigned int n_dofs_per_faces = 2;
791 if constexpr (dim == 3)
792 n_dofs_per_faces = 4;
793
794 std::vector<types::global_dof_index> dof_indices(dofs_per_cell);
795 std::vector<double> cell_dof_values(dofs_per_cell);
796
797 std::vector<unsigned int> face_opposite_dofs(n_opposite_dofs_per_faces);
798 std::vector<unsigned int> face_local_dofs(n_dofs_per_faces);
799 std::vector<double> face_local_dof_values(n_dofs_per_faces);
800
801 // Initialization of points and tensors
802 Point<dim> x_I_real;
803 Tensor<1, dim> x_n_to_x_I_real;
804 Tensor<1, dim> correction;
805 Point<dim> x_n_p1_ref;
806 Point<dim - 1> ref_face_center_point = Point<dim - 1>();
807 ref_face_center_point(0) = 0.5;
808 if constexpr (dim == 3)
809 ref_face_center_point(1) = 0.5;
810
811 // Evalutation points
812 std::vector<Point<dim>> x_n_ref_vector(n_opposite_dofs_per_faces);
813 std::vector<Point<dim>> x_n_real_vector(n_opposite_dofs_per_faces);
814 Tensor<1, dim> distance_gradients;
815
816 // Transformation jacobian
817 DerivativeForm<1, dim, dim> cell_transformation_jacobian;
818 LAPACKFullMatrix<double> face_transformation_jacobian(dim, dim - 1);
819
820 // Jacobian matrix, residual vector and correction
821 LAPACKFullMatrix<double> jacobian_matrix(dim - 1, dim - 1);
822 jacobian_matrix.set_property(LAPACKSupport::general);
823 Vector<double> residual_n_vec(dim - 1);
824 std::vector<double> correction_norm(n_opposite_dofs_per_faces, 1.0);
825
826 // Check to constrain the solution inside the face
827 std::vector<int> outside_check(n_opposite_dofs_per_faces);
828
829 // DoF coordinates
830 std::map<types::global_dof_index, Point<dim>> dof_support_points =
831 DoFTools::map_dofs_to_support_points(*mapping, dof_handler);
832
833 // FEPointEvaluation for the values, gradients and transformation jacobians
834 FEPointEvaluation<1, dim> fe_point_evaluation(
835 *mapping, *fe, update_gradients | update_jacobians);
836
837 FEPointEvaluation<1, dim> fe_point_evaluation_values_only(*mapping,
838 *fe,
839 update_values);
840
841 /* The method is iterative, hence, we solve as long as the distance
842 approximation changes for at least one dof. We use the flag "change" to
843 track this change. */
844 bool change = true;
845
846 // Extract the vertices to cell information to have the neighbours
847 // Vertices to cell mapping
848 std::map<unsigned int,
849 std::set<typename DoFHandler<dim>::active_cell_iterator>>
850 vertices_to_cell;
851 LetheGridTools::vertices_cell_mapping(this->dof_handler, vertices_to_cell);
852
853 // Create a set with the cells for which we wish to loop (corona)
854 std::set<typename DoFHandler<dim>::active_cell_iterator> corona_cell;
855 for (const auto &cell : dof_handler.active_cell_iterators())
856 {
857 if (cell->is_locally_owned())
858 {
859 const unsigned int cell_index = cell->global_active_cell_index();
860
861 // If the cell is intersected, the distance is already computed and
862 // its neighbors are in the corona
863 if (interface_reconstruction_vertices.contains(cell_index))
864 {
865 auto active_neighbors =
867 cell);
868 corona_cell.insert(active_neighbors.begin(),
869 active_neighbors.end());
870 }
871 }
872 }
873
874 /* The count corresponds to how many times we iterate. In fact, it
875 corresponds to the number of cell layers (starting from the interface)
876 that the approximation of the distance is known. */
877 int count = 0;
878 while (change)
879 {
881 pcout << "Solving signed distance of layer " << count << std::endl;
882 change = false;
883
884 for (const auto &cell : dof_handler.active_cell_iterators())
885 {
886 if (cell->is_locally_owned())
887 {
888 cell->get_dof_values(distance_with_ghost,
889 cell_dof_values.begin(),
890 cell_dof_values.end());
891
892 // Loop over the cell's DoFs to check if an absolute distance is
893 // below the max distance.
894 for (unsigned int i = 0; i < dofs_per_cell; ++i)
895 {
896 if (std::abs(cell_dof_values[i]) < (max_distance))
897 {
898 // If this is the case, insert the cell in the corona and
899 // break the loop.
900 corona_cell.insert(cell);
901 break;
902 }
903 }
904 }
905 }
906 for (const auto &cell : corona_cell)
907 {
908 if (cell->is_locally_owned())
909 {
910 const unsigned int cell_index = cell->global_active_cell_index();
911
912 // If the cell is intersected, the distance is already computed.
913 if (interface_reconstruction_vertices.contains(cell_index))
914 {
915 continue;
916 }
917
918 cell->get_dof_indices(dof_indices);
919 cell->get_dof_values(distance_with_ghost,
920 cell_dof_values.begin(),
921 cell_dof_values.end());
922
923 // Loop over the cell's faces
924 for (unsigned int j = 0; j < faces_per_cell; ++j)
925 {
926 get_face_opposite_dofs(j, face_opposite_dofs);
927 get_face_local_dofs(j, face_local_dofs);
928
929 for (unsigned int i = 0; i < n_opposite_dofs_per_faces; ++i)
930 {
931 // Initial evaluation points for the Newton method
932 x_n_ref_vector[i] = transform_ref_face_point_to_ref_cell(
933 ref_face_center_point, j);
934
935 // Reinitialize the correction norm and outside_check
936 correction_norm[i] = 1.0;
937 outside_check[i] = 0;
938 }
939
940 for (unsigned int i = 0; i < n_dofs_per_faces; ++i)
941 {
942 face_local_dof_values[i] =
943 cell_dof_values[face_local_dofs[i]];
944 }
945
946 constexpr double tol = 1e-9;
947 unsigned int newton_it = 0;
948 constexpr int newton_max_it = 100;
949
950
951 // Solve the minimization problem with Newton method
952 // using an analytical Jacobian matrix
953 while (*std::ranges::max_element(correction_norm) > tol &&
954 newton_it < newton_max_it)
955 {
956 /* Prepare FEPointEvaluation to compute value and
957 gradient at the stencil points*/
958 fe_point_evaluation.reinit(cell, x_n_ref_vector);
959 fe_point_evaluation.evaluate(cell_dof_values,
960 EvaluationFlags::gradients);
961
962 // Loop over the face's opposite DoFs
963 for (unsigned int i = 0; i < n_opposite_dofs_per_faces;
964 ++i)
965 {
966 if (correction_norm[i] < tol)
967 {
968 continue;
969 }
970
971 const unsigned int local_face_opposite_dof =
972 face_opposite_dofs[i];
973 if (intersected_dofs.contains(
974 dof_indices[local_face_opposite_dof]))
975 {
976 correction_norm[i] = 0;
977 continue;
978 }
979 // Get the real coordinates of the current DoF I
980 x_I_real = dof_support_points.at(
981 dof_indices[local_face_opposite_dof]);
982
983 x_n_real_vector[i] =
984 fe_point_evaluation.quadrature_point(i);
985 distance_gradients =
986 fe_point_evaluation.get_gradient(i);
987 cell_transformation_jacobian =
988 fe_point_evaluation.jacobian(i);
990 cell_transformation_jacobian,
991 j,
992 face_transformation_jacobian);
993
994 x_n_to_x_I_real = x_I_real - x_n_real_vector[i];
995
996 /* Compute the jacobian matrix. The Ax=b system is
997 formulated as the dim-1 system. We solve for the
998 correction in the reference face. */
1000 x_n_to_x_I_real,
1001 face_transformation_jacobian,
1002 face_local_dof_values,
1003 jacobian_matrix);
1004
1005
1006 // Compute the right hand side.
1007 Tensor<1, dim - 1> residual_n;
1008 compute_residual(x_n_to_x_I_real,
1009 distance_gradients,
1010 face_transformation_jacobian,
1011 residual_n);
1012
1013 // Convert the right hand side to the right format
1014 // for the linear solver
1015 residual_n.unroll(residual_n_vec.begin(),
1016 residual_n_vec.end());
1017 residual_n_vec *= -1.0;
1018
1019 /* Factorize and solve the matrix. The correction is
1020 put back in residual_n_vec. */
1021 jacobian_matrix.compute_lu_factorization();
1022 jacobian_matrix.solve(residual_n_vec);
1023 jacobian_matrix.reinit(dim - 1, dim - 1);
1024
1025 // Compute the norm of the correction
1026 correction_norm[i] = residual_n_vec.l2_norm();
1027
1028 /* Transform the dim-1 correction (in the reference
1029 face) to dim (in the reference cell) */
1030 correction =
1032 residual_n_vec, j);
1033
1034 /* Compute the solution (the point x_n_p1_ref on the
1035 face minimizing the distance)*/
1036 x_n_p1_ref = x_n_ref_vector[i] + correction;
1037
1038 /* Relax the correction if it brings us outside
1039 the cell */
1040 double relaxation = 1.0;
1041
1042 /* Check if the Newton method results in a solution
1043 outside the face. For example in 3D, we could have:
1044 _____________
1045 | | solution
1046 | | *
1047 | |
1048 | |
1049 | |
1050 |_____________|
1051
1052 Each time it does, we relax the scheme to bring
1053 back the estimation of the solution in the face:
1054 _____________
1055 | | relaxed solution
1056 | * |
1057 | |
1058 | |
1059 | |
1060 |_____________|
1061
1062 If the solution is outside the face more than three
1063 times, we constrain the solution on the right
1064 boundary of the face:
1065 _____________
1066 | | real
1067 | constraint * * solution
1068 | solution |
1069 | |
1070 | |
1071 |_____________|
1072
1073 */
1074
1075 /* Flag indicating if the correction brings us
1076 outside the cell.*/
1077 bool check = false;
1078
1079 // Tolerance on the position for the outside check
1080 for (int k = 0; k < dim; ++k)
1081 {
1082 if (x_n_p1_ref[k] > 1.0 + tol ||
1083 x_n_p1_ref[k] < 0.0 - tol)
1084 {
1085 check = true;
1086
1087 /* Set the correction to put the solution on
1088 the face boundary. Select the minimum
1089 relaxation of the all directions to ensure
1090 the solution stays inside the face.*/
1091 if (correction[k] > tol)
1092 {
1093 relaxation =
1094 std::min((1.0 - x_n_ref_vector[i][k]) /
1095 (correction[k] + tol),
1096 relaxation);
1097 }
1098 else if (correction[k] < -tol)
1099 {
1100 relaxation =
1101 std::min((0.0 - x_n_ref_vector[i][k]) /
1102 (correction[k] + tol),
1103 relaxation);
1104 }
1105 }
1106 }
1107 // Increment the outside_check if the correction
1108 // brought us outside the face
1109 if (check)
1110 outside_check[i] += 1;
1111
1112 if (outside_check[i] > 3)
1113 {
1114 correction_norm[i] = 0.0;
1115 correction = 0.0;
1116 }
1117 // Re-compute the solution with the relaxation
1118 x_n_p1_ref =
1119 x_n_ref_vector[i] + relaxation * correction;
1120
1121 // Update the solution.
1122 x_n_ref_vector[i] = x_n_p1_ref;
1123 }
1124
1125 newton_it += 1;
1126 } // End of the Newton solver.
1127
1128 fe_point_evaluation_values_only.reinit(cell, x_n_ref_vector);
1129 fe_point_evaluation_values_only.evaluate(
1130 cell_dof_values, EvaluationFlags::values);
1131 for (unsigned int i = 0; i < n_opposite_dofs_per_faces; ++i)
1132 {
1133 const unsigned int local_face_opposite_dof =
1134 face_opposite_dofs[i];
1135
1136 x_I_real = dof_support_points.at(
1137 dof_indices[local_face_opposite_dof]);
1138
1139 x_n_real_vector[i] =
1140 fe_point_evaluation_values_only.quadrature_point(i);
1141 x_n_to_x_I_real = x_I_real - x_n_real_vector[i];
1142
1143 double distance_value_at_x_n =
1144 fe_point_evaluation_values_only.get_value(i);
1145
1146 double approx_distance =
1147 compute_distance(x_n_to_x_I_real,
1148 distance_value_at_x_n);
1149
1150 /* If the new distance is smaller than the previous,
1151 update the value and flag the change.
1152 The tolerance needs to be higher than the one for the
1153 Newton method because we don't want the change flag to
1154 depend on the Newton method convergence.*/
1155 constexpr double distance_tol = 1e-8;
1156 if (distance(dof_indices[local_face_opposite_dof]) >
1157 (approx_distance + distance_tol))
1158 {
1159 change = true;
1160 distance(dof_indices[local_face_opposite_dof]) =
1161 approx_distance;
1162 }
1163 }
1164 }
1165 }
1166 } // End of the loop on the cells
1167
1169
1170 // Track the change flag across the processes
1171 change = Utilities::MPI::logical_or(change, mpi_communicator);
1172
1173 count += 1;
1174 } // End of the iterative while loop
1175
1176 // Update the hagging node values
1177 constraints.distribute(distance);
1178}
1179
1180template <int dim, typename VectorType>
1181void
1184{
1185 for (auto p : this->locally_active_dofs)
1186 {
1188 }
1189
1190 // Update local ghost (signed_distance becomes read only)
1191 signed_distance.update_ghost_values();
1192
1193 /* Copy distance to signed_distance_with_ghost to keep the knowledge of
1194 local ghost values and to have a read-only version of the vector. Ghost
1195 values of the signed distance are needed for volume computations.*/
1197
1198 /* Zero out ghost DoFs to regain write functionalities in signed_distance
1199 (it becomes write-only, that is why we need signed_distance_with_ghost -
1200 to read the ghost values in it).*/
1201 signed_distance.zero_out_ghost_values();
1202
1203 /* Copy the ghost values back in signed_distance (zero_out_ghost_values()
1204 puts zeros in ghost DoFs)*/
1205 for (auto p : this->locally_active_dofs)
1206 {
1208 }
1209}
1210
1211template <int dim, typename VectorType>
1212void
1215{
1216 FEPointEvaluation<1, dim> fe_point_evaluation(
1217 *mapping, *fe, update_jacobians | update_JxW_values);
1218
1219 const unsigned int dofs_per_cell = fe->n_dofs_per_cell();
1220
1221 /* For the L2 projection of the cell-wise correction (the projection for a
1222 given DOF corresponds to the average of the neighbor cell values)*/
1223 double n_cells_per_dofs_inv = 1.0 / 4.0;
1224 if constexpr (dim == 3)
1225 {
1226 n_cells_per_dofs_inv = 1.0 / 8.0;
1227 }
1228
1229 // Re-initialize volume_correction vector.
1230 volume_correction = 0.0;
1231
1232 for (const auto &cell : dof_handler.active_cell_iterators())
1233 {
1234 if (cell->is_locally_owned())
1235 {
1236 const unsigned int cell_index = cell->global_active_cell_index();
1237
1238 // The cell is not intersected, no need to correct the volume
1239 if (!interface_reconstruction_vertices.contains(cell_index))
1240 {
1241 continue;
1242 }
1243
1244 /* We want to find a cell-wise correction to apply to the cell's dof
1245 values of the signed_distance so that the geometric cell-wise volume
1246 encompassed by the level 0 of the signed_distance V_K and by the
1247 iso-contour 0.5 of the phase indicator V_K,CLS match. This is
1248 required because the computed distance doesn't belong to the Q1
1249 approximation space.
1250
1251 We solve the non-linear problem: DeltaV_K(phi* + eta_K) = V_K,CLS -
1252 V_K(phi* + eta_K) = 0, where phi* is the current
1253 signed distance, eta_K is the correction on the signed_distance that
1254 we are looking for. We use the secant method to do so. See Ausas et
1255 al. (2011) for more details.*/
1256
1257 // Get the level set values
1258 Vector<double> cell_level_set_dof_values(dofs_per_cell);
1259
1260 cell->get_dof_values(level_set,
1261 cell_level_set_dof_values.begin(),
1262 cell_level_set_dof_values.end());
1263
1264 // Compute the targeted volume to correct for
1265 double targeted_cell_volume =
1266 InterfaceTools::compute_cell_wise_volume(fe_point_evaluation,
1267 cell,
1268 cell_level_set_dof_values,
1269 -iso_level,
1270 fe->degree + 1);
1271
1272 // Get the signed distance values to be corrected
1273 Vector<double> cell_dof_values(dofs_per_cell);
1274 cell->get_dof_values(signed_distance_with_ghost,
1275 cell_dof_values.begin(),
1276 cell_dof_values.end());
1277
1278 /* Get an approximation of the cell size to initialize secant method.
1279 The approximation corresponds to the diameter of the equivalent disk
1280 (2D) or sphere (3D) in terms of area/volume. We use it to compute the
1281 first derivative value in the secant method. */
1282 const double cell_volume = cell->measure();
1283 const double cell_size =
1284 compute_cell_diameter<dim>(cell_volume, this->fe->degree);
1285
1286 /* Secant method. The subscript nm1 (or n minus 1) stands for the
1287 previous secant iteration (it = n-1), the subscript n stands for
1288 the current iteration and the subscript np1 stands for the next
1289 iteration (it = n+1).*/
1290 double inside_cell_volume_nm1 = 0.0;
1291 double inside_cell_volume_n = 0.0;
1292
1293 double delta_volume_nm1 = 0.0;
1294 double delta_volume_n = 0.0;
1295
1296 double delta_volume_prime = 0.0;
1297
1298 double eta_nm1 = 0.0;
1299 double eta_n = 1e-6 * cell_size;
1300 double eta_np1 = 0.0;
1301
1302 // Compute the volume for the first initial value (eta_nm1)
1303 inside_cell_volume_nm1 =
1304 InterfaceTools::compute_cell_wise_volume(fe_point_evaluation,
1305 cell,
1306 cell_dof_values,
1307 eta_nm1,
1308 fe->degree + 1);
1309 delta_volume_nm1 = targeted_cell_volume - inside_cell_volume_nm1;
1310
1311 /* Store the initial volume in the cell to limit the secant method
1312 in some case.*/
1313 const double initial_inside_cell_volume = inside_cell_volume_nm1;
1314
1315 /* Check if there is enough volume to correct. If not, we don't
1316 correct.*/
1317 constexpr double tol = 1e-12;
1318 if (inside_cell_volume_nm1 < tol * cell_volume ||
1319 inside_cell_volume_nm1 > (cell_volume - tol * cell_volume))
1320 {
1321 eta_n = 0.0;
1322 continue;
1323 }
1324
1325 unsigned int secant_it = 0;
1326 unsigned int secant_max_it = 20;
1327 double secant_update = 1.0;
1328
1329 // Secant method
1330 while (abs(secant_update) > tol &&
1331 abs(delta_volume_nm1) > tol * initial_inside_cell_volume &&
1332 secant_it < secant_max_it)
1333 {
1334 // If the cell is almost full or empty, we stop correcting the
1335 // volume.
1336 if (inside_cell_volume_nm1 < tol * cell_size ||
1337 inside_cell_volume_nm1 > (cell_size - tol * cell_size))
1338 {
1339 eta_n = 0.0;
1340 break;
1341 }
1342 secant_it += 1;
1343
1344 inside_cell_volume_n =
1345 InterfaceTools::compute_cell_wise_volume(fe_point_evaluation,
1346 cell,
1347 cell_dof_values,
1348 eta_n,
1349 fe->degree + 1);
1350
1351 delta_volume_n = targeted_cell_volume - inside_cell_volume_n;
1352
1353 delta_volume_prime =
1354 (delta_volume_n - delta_volume_nm1) / (eta_n - eta_nm1 + tol);
1355
1356 secant_update = -delta_volume_n / (delta_volume_prime + tol);
1357 eta_np1 = eta_n + secant_update;
1358
1359 eta_nm1 = eta_n;
1360 eta_n = eta_np1;
1361 inside_cell_volume_nm1 = inside_cell_volume_n;
1362 delta_volume_nm1 = delta_volume_n;
1363 } // End secant method loop.
1364
1365 // If the secant method does not converge, do not correct.
1366 if (secant_it >= secant_max_it)
1367 {
1368 eta_n = 0.0;
1369 }
1370
1371 std::vector<types::global_dof_index> dof_indices(dofs_per_cell);
1372 cell->get_dof_indices(dof_indices);
1373
1374 // L2 projection of the cell-wise (discontinuous) correction to have
1375 // a continuous correction at the DoFs.
1376 for (unsigned int i = 0; i < dofs_per_cell; ++i)
1377 {
1378 volume_correction(dof_indices[i]) += eta_n * n_cells_per_dofs_inv;
1379 }
1380 }
1381 } // End loop on cells.
1382
1383 volume_correction.compress(VectorOperation::add);
1384 volume_correction.update_ghost_values();
1385}
1386
1387template <int dim, typename VectorType>
1388void
1390{
1391 /* We want to find a global correction function to apply to the dof value of
1392 the signed_distance so that the geometric global volume encompassed by the
1393 level 0 of the signed_distance V and by the iso-contour 0.5 of the phase
1394 fraction V_CLS match. This is required because the computed distance
1395 doesn't belong to the Q1 approximation space. We solve the non-linear
1396 problem: DeltaV(phi* + xi) = V_CLS - V(phi* + xi) = 0, where phi* is the
1397 current signed distance, xi = C*eta is the correction function on
1398 the signed_distance that we are looking for, with eta being the cell-wise
1399 correction computed with compute_cell_wise_volume_correction() and C being
1400 a constant. We use the secant method to do so. See Ausas et al. (2011) for
1401 more details.*/
1402
1403 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
1404
1405 /* Compute targeted global volume. It corresponds to the one enclosed by
1406 the level 0 of the level_set vector (same volume as the one enclosed
1407 by iso-contour 0.5 of the phase indicator).*/
1408 double global_volume, surface;
1409
1410 std::tie(global_volume, surface) =
1412
1413 /* Initialization of values for the secant method. The subscript nm1 (or n
1414 minus 1) stands for the previous secant iteration (it = n-1), the
1415 subscript n stands for the current iteration and the subscript np1 stands
1416 for the next iteration (it = n+1).*/
1417 double global_volume_nm1 = 0.0;
1418 double global_volume_n = 0.0;
1419
1420 double global_delta_volume_nm1 = 0.0;
1421 double global_delta_volume_n = 0.0;
1422
1423 double global_delta_volume_prime = 0.0;
1424
1425 /* Global constant C that we are solving for to obtain
1426 DeltaV(phi* + C*eta) = V_CLS - V(phi* + C*eta) = 0
1427 where eta is the cell-wise correction computed with
1428 compute_cell_wise_volume_correction()*/
1429 double C_nm1 = 0.0;
1430 double C_n = 0.0;
1431 double C_np1 = 0.0;
1432
1433 /* Compute the volume and the difference with the targeted volume for 1st
1434 initial guess of the correction function (xi_nm1 = C_nm1*eta)*/
1435 C_nm1 = 1.0;
1436 LinearAlgebra::distributed::Vector<double> signed_distance_0(
1438 signed_distance_0.add(C_nm1, volume_correction);
1439
1440 // Update_ghost_values is required for cell-wise volume computations
1441 signed_distance_0.update_ghost_values();
1442
1443 std::tie(global_volume_nm1, surface) =
1444 integrate_volume_and_surface(dof_handler, *fe, signed_distance_0, 0.0);
1445
1446 global_delta_volume_nm1 = global_volume - global_volume_nm1;
1447
1448 // Initialize the 2nd initial guest
1449 C_n = 1e-6 * global_volume;
1450
1451 // Store the initial volume for the stop criterion
1452 const double global_volume_0 = global_volume_nm1;
1453
1454 // Initialize secant method it and update
1455 constexpr double tol = 1e-12;
1456 unsigned int secant_it = 0;
1457 constexpr unsigned int secant_max_it = 20;
1458 double secant_update = 1.0;
1459
1460 // Secant method
1461 while (abs(secant_update) > tol &&
1462 abs(global_delta_volume_nm1) > tol * global_volume_0 &&
1463 secant_it < secant_max_it)
1464 {
1465 secant_it += 1;
1466
1467 LinearAlgebra::distributed::Vector<double> signed_distance_n(
1469 signed_distance_n.add(C_n, volume_correction);
1470 signed_distance_n.update_ghost_values();
1471
1472 std::tie(global_volume_n, surface) =
1473 integrate_volume_and_surface(dof_handler, *fe, signed_distance_n, 0.0);
1474
1475 global_delta_volume_n = global_volume - global_volume_n;
1476
1477 global_delta_volume_prime =
1478 (global_delta_volume_n - global_delta_volume_nm1) / (C_n - C_nm1 + tol);
1479
1480 secant_update =
1481 -global_delta_volume_n / (global_delta_volume_prime + tol);
1482
1483 C_np1 = C_n + secant_update;
1484 C_nm1 = C_n;
1485 C_n = C_np1;
1486
1487 global_volume_nm1 = global_volume_n;
1488 global_delta_volume_nm1 = global_delta_volume_n;
1489 }
1490
1491 // If the secant method does not converge, do not correct.
1492 if (secant_it >= secant_max_it)
1493 C_n = 0.0;
1494
1496 {
1497 unsigned int this_mpi_process(
1498 Utilities::MPI::this_mpi_process(mpi_communicator));
1499 if (this_mpi_process == 0)
1500 {
1501 std::vector<std::string> column_names = {
1502 "Initial volume",
1503 "Volume after redistanciation",
1504 "Remaining error on the volume"};
1505
1506 TableHandler volume_conservation_table;
1507 volume_conservation_table.declare_column(column_names[0]);
1508 volume_conservation_table.add_value(column_names[0], global_volume);
1509 volume_conservation_table.set_scientific(column_names[0], true);
1510
1511 volume_conservation_table.declare_column(column_names[1]);
1512 volume_conservation_table.add_value(column_names[1], global_volume_n);
1513 volume_conservation_table.set_scientific(column_names[1], true);
1514
1515 volume_conservation_table.declare_column(column_names[2]);
1516 volume_conservation_table.add_value(column_names[2],
1517 global_delta_volume_n);
1518 volume_conservation_table.set_scientific(column_names[2], true);
1519
1520 volume_conservation_table.write_text(std::cout);
1521 }
1522 }
1523
1524 // Update signed_distance with the correction
1526 signed_distance_with_ghost.update_ghost_values();
1527
1528 for (auto p : this->locally_active_dofs)
1529 {
1531 distance(p) = abs(signed_distance(p));
1532 }
1533
1535}
1536
1537template <int dim, typename VectorType>
1538void
1540 output_interface_reconstruction(const std::string &output_name,
1541 const std::string &output_path,
1542 const double time,
1543 const unsigned int it)
1544{
1545 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
1546 InterfaceReconstructionDataOut<dim> reconstruction_data_out;
1547
1548 reconstruction_data_out.build_patches(interface_reconstruction_vertices);
1549
1551 reconstruction_data_out,
1552 output_path,
1553 output_name,
1554 time,
1555 it,
1556 1,
1557 mpi_communicator);
1558}
1559
1560template <int dim, typename VectorType>
1561void
1563 const std::string &output_name,
1564 const std::string &output_path,
1565 const double time,
1566 const unsigned int it)
1567{
1568 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
1569
1570 DataOut<dim> data_out;
1571 data_out.attach_dof_handler(this->dof_handler);
1572 data_out.add_data_vector(this->signed_distance, "signed_distance");
1573 data_out.build_patches(*this->mapping,
1574 1, // subdivision
1575 DataOut<dim>::curved_inner_cells);
1577 data_out,
1578 output_path,
1579 output_name,
1580 time,
1581 it,
1582 1,
1583 mpi_communicator);
1584}
1585
1586template <int dim, typename VectorType>
1587std::vector<OutputStruct<dim, GlobalVectorType>>
1589{
1590#ifndef LETHE_USE_LDV
1591 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
1592
1593 GlobalVectorType tmp_local_signed_distance(this->locally_owned_dofs,
1594 mpi_communicator);
1595
1596 convert_vector_dealii_to_trilinos(tmp_local_signed_distance,
1597 this->signed_distance);
1598
1599 this->signed_distance_output = tmp_local_signed_distance;
1600#else
1602#endif
1603 std::vector<OutputStruct<dim, GlobalVectorType>> solution_output_structs;
1604 std::vector<std::string> solution_names(1, "signed_distance");
1605 std::vector<DataComponentInterpretation::DataComponentInterpretation>
1606 solution_data_component_interpretation(
1607 1, DataComponentInterpretation::component_is_scalar);
1608 solution_output_structs.emplace_back(
1610 this->dof_handler,
1612 solution_names,
1613 solution_data_component_interpretation);
1614
1615 return solution_output_structs;
1616}
1617
1620
1621#ifndef LETHE_USE_LDV
1622template class InterfaceTools::
1623 SignedDistanceSolver<2, LinearAlgebra::distributed::Vector<double>>;
1624template class InterfaceTools::
1625 SignedDistanceSolver<3, LinearAlgebra::distributed::Vector<double>>;
1626#endif
1627
1630
1631template <int dim, typename VectorType>
1634 const DoFHandler<dim> &dof_handler,
1635 const VectorType &solution_vector,
1636 const double isovalue)
1637{
1638 // Get MPI communicator
1639 const MPI_Comm mpi_communicator = dof_handler.get_mpi_communicator();
1640
1641 bool isocontour_exists = false;
1642
1643 // Initialize IsocontourBoundingValues object and reference variables for
1644 // readability
1645 InterfaceTools::IsocontourBoundingValues<dim> isocontour_bounding_values;
1646 double &x_min =
1647 isocontour_bounding_values.bounding_values[BoundingCoordinates::x_min];
1648 double &x_max =
1649 isocontour_bounding_values.bounding_values[BoundingCoordinates::x_max];
1650 double &y_min =
1651 isocontour_bounding_values.bounding_values[BoundingCoordinates::y_min];
1652 double &y_max =
1653 isocontour_bounding_values.bounding_values[BoundingCoordinates::y_max];
1654
1655 // Copy values of owned DoFs
1656 VectorType solution_vector_owned_copy(dof_handler.locally_owned_dofs(),
1657 mpi_communicator);
1658 solution_vector_owned_copy = solution_vector;
1659
1660 // Offset field to impose 0 at the isovalue
1661 solution_vector_owned_copy.add(-isovalue);
1662
1663 // Make relevant copy
1664 VectorType solution_vector_relevant_copy(
1665 dof_handler.locally_owned_dofs(),
1666 DoFTools::extract_locally_relevant_dofs(dof_handler),
1667 mpi_communicator);
1668 solution_vector_relevant_copy = solution_vector_owned_copy;
1669
1670 // Initialize MeshClassifier
1671 NonMatching::MeshClassifier<dim> mesh_classifier(
1672 dof_handler, solution_vector_relevant_copy);
1673 mesh_classifier.reclassify();
1674
1675 // Initialize FEValues
1676 const hp::FECollection<dim> fe_collection(dof_handler.get_fe());
1677 const QGauss<1> quadrature_1D(dof_handler.get_fe().degree + 1);
1678 NonMatching::RegionUpdateFlags region_update_flags;
1679 region_update_flags.surface = update_quadrature_points;
1680 NonMatching::FEValues<dim> non_matching_fe_values(
1681 fe_collection,
1682 quadrature_1D,
1683 region_update_flags,
1684 mesh_classifier,
1685 dof_handler,
1686 solution_vector_relevant_copy);
1687
1688 for (const auto &cell : dof_handler.active_cell_iterators())
1689 {
1690 if (cell->is_locally_owned())
1691 {
1692 // Reinitialize and get surface FE values
1693 non_matching_fe_values.reinit(cell);
1694 const std::optional<NonMatching::FEImmersedSurfaceValues<dim>>
1695 &surface_fe_values = non_matching_fe_values.get_surface_fe_values();
1696
1697 // If the surface does exist, approximate the bounding values with
1698 // quadrature points
1699 if (surface_fe_values)
1700 {
1701 const auto &q_points = surface_fe_values->get_quadrature_points();
1702 if (q_points.size() > 0)
1703 isocontour_exists = true;
1704 for (const auto &p : q_points)
1705 {
1706 x_min = std::min(x_min, p[0]);
1707 x_max = std::max(x_max, p[0]);
1708 y_min = std::min(y_min, p[1]);
1709 y_max = std::max(y_max, p[1]);
1710 if constexpr (dim == 3)
1711 {
1712 isocontour_bounding_values
1714 std::min(isocontour_bounding_values
1715 .bounding_values[BoundingCoordinates::z_min],
1716 p[2]);
1717 isocontour_bounding_values
1719 std::max(isocontour_bounding_values
1720 .bounding_values[BoundingCoordinates::z_max],
1721 p[2]);
1722 }
1723 }
1724 }
1725 }
1726 }
1727
1728 // Reduce across ranks
1729 x_min = Utilities::MPI::min(x_min, mpi_communicator);
1730 x_max = Utilities::MPI::max(x_max, mpi_communicator);
1731 y_min = Utilities::MPI::min(y_min, mpi_communicator);
1732 y_max = Utilities::MPI::max(y_max, mpi_communicator);
1733 if constexpr (dim == 3)
1734 {
1735 isocontour_bounding_values.bounding_values[BoundingCoordinates::z_min] =
1736 Utilities::MPI::min(isocontour_bounding_values
1737 .bounding_values[BoundingCoordinates::z_min],
1738 mpi_communicator);
1739 isocontour_bounding_values.bounding_values[BoundingCoordinates::z_max] =
1740 Utilities::MPI::max(isocontour_bounding_values
1741 .bounding_values[BoundingCoordinates::z_max],
1742 mpi_communicator);
1743 }
1744 isocontour_bounding_values.isocontour_exists =
1745 Utilities::MPI::logical_or(isocontour_exists, mpi_communicator);
1746
1747 return isocontour_bounding_values;
1748}
1749
1752 const DoFHandler<2> &dof_handler,
1753 const GlobalVectorType &solution_vector,
1754 const double isovalue);
1755
1758 const DoFHandler<3> &dof_handler,
1759 const GlobalVectorType &solution_vector,
1760 const double isovalue);
1761
1762template <int dim, typename VectorType>
1763void
1765 const Variable &variable,
1766 const std::multimap<Variable,
1767 std::pair<unsigned int,
1769 dim>::IsocontourBoundingBoxes::Isocontour>>
1770 &ids_and_isocontours_per_variable,
1771 const DoFHandler<dim> &dof_handler,
1772 const VectorType &solution_vector,
1773 const double current_time,
1774 const Parameters::Verbosity &verbosity,
1775 const ConditionalOStream &pcout,
1776 std::vector<TableHandler> &isocontour_bounding_values_tables)
1777{
1778 // Get iterator range that corresponds to the variable of interest
1779 auto [begin, end] = ids_and_isocontours_per_variable.equal_range(variable);
1780
1781 // Initialize iterator for the table
1782 unsigned int i = 0;
1783
1784 for (auto it = begin; it != end; ++it, ++i)
1785 {
1786 // Get ID and isocontour
1787 const unsigned int id = it->second.first;
1788 const typename Parameters::PostProcessing<
1789 dim>::IsocontourBoundingBoxes::Isocontour &isocontour =
1790 it->second.second;
1791
1792 // Get isocontour bounding values
1793 InterfaceTools::IsocontourBoundingValues<dim> isocontour_bounding_values =
1795 solution_vector,
1796 isocontour.isovalue);
1797
1798 if (isocontour_bounding_values.isocontour_exists)
1799 {
1800 const auto &bounding_coordinates_names =
1801 isocontour_bounding_values.bounding_coordinates_names;
1802 // Console output
1803 if (verbosity == Parameters::Verbosity::verbose)
1804 {
1805 pcout << "Isocontour " << id << ": " << isocontour.output_name
1806 << std::endl;
1807
1808 for (unsigned int j = 0; j < bounding_coordinates_names.size();
1809 ++j)
1810 {
1811 pcout << bounding_coordinates_names[j] << ": "
1812 << isocontour_bounding_values.bounding_values[j]
1813 << std::endl;
1814 }
1815 }
1816
1817 // Fill table
1818 const unsigned int table_precision = 6;
1819 TableHandler &current_table = isocontour_bounding_values_tables[i];
1820
1821 current_table.add_value("time", current_time);
1822 current_table.set_scientific("time", true);
1823 for (unsigned int j = 0; j < bounding_coordinates_names.size(); ++j)
1824 {
1825 current_table.add_value(
1826 bounding_coordinates_names[j],
1827 isocontour_bounding_values.bounding_values[j]);
1828 current_table.set_precision(bounding_coordinates_names[j],
1829 table_precision);
1830 current_table.set_scientific(bounding_coordinates_names[j], true);
1831 }
1832 }
1833 }
1834}
1835
1836template void
1838 const Variable &variable,
1839 const std::multimap<Variable,
1840 std::pair<unsigned int,
1842 2>::IsocontourBoundingBoxes::Isocontour>>
1843 &ids_and_isocontours_per_variable,
1844 const DoFHandler<2> &dof_handler,
1845 const GlobalVectorType &solution_vector,
1846 const double current_time,
1847 const Parameters::Verbosity &verbosity,
1848 const ConditionalOStream &pcout,
1849 std::vector<TableHandler> &isocontour_bounding_values_tables);
1850
1851template void
1853 const Variable &variable,
1854 const std::multimap<Variable,
1855 std::pair<unsigned int,
1857 3>::IsocontourBoundingBoxes::Isocontour>>
1858 &ids_and_isocontours_per_variable,
1859 const DoFHandler<3> &dof_handler,
1860 const GlobalVectorType &solution_vector,
1861 const double current_time,
1862 const Parameters::Verbosity &verbosity,
1863 const ConditionalOStream &pcout,
1864 std::vector<TableHandler> &isocontour_bounding_values_tables);
1865
1866template <int dim>
1867void
1869 const MPI_Comm &mpi_communicator,
1870 const std::string &output_folder,
1871 const Variable &variable,
1872 const std::multimap<Variable,
1873 std::pair<unsigned int,
1875 dim>::IsocontourBoundingBoxes::Isocontour>>
1876 &ids_and_isocontours_per_variable,
1877 const std::vector<TableHandler> &isocontour_bounding_values_tables)
1878{
1879 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
1880 {
1881 // Get iterator range that corresponds to the variable of interest
1882 auto [begin, end] =
1883 ids_and_isocontours_per_variable.equal_range(variable);
1884
1885 // Initialize iterator for the table(s)
1886 unsigned int i = 0;
1887
1888 for (auto it = begin; it != end; ++it, ++i)
1889 {
1890 // Get isocontour output name
1891 const std::string &isocontour_output_name =
1892 it->second.second.output_name;
1893 std::string filename =
1894 output_folder + isocontour_output_name + ".dat";
1895 std::ofstream output(filename.c_str());
1896
1897 isocontour_bounding_values_tables[i].write_text(output);
1898 }
1899 }
1900}
1901
1902template void
1904 const MPI_Comm &mpi_communicator,
1905 const std::string &output_folder,
1906 const Variable &variable,
1907 const std::multimap<Variable,
1908 std::pair<unsigned int,
1910 2>::IsocontourBoundingBoxes::Isocontour>>
1911 &ids_and_isocontours_per_variable,
1912 const std::vector<TableHandler> &isocontour_bounding_values_tables);
1913
1914template void
1916 const MPI_Comm &mpi_communicator,
1917 const std::string &output_folder,
1918 const Variable &variable,
1919 const std::multimap<Variable,
1920 std::pair<unsigned int,
1922 3>::IsocontourBoundingBoxes::Isocontour>>
1923 &ids_and_isocontours_per_variable,
1924 const std::vector<TableHandler> &isocontour_bounding_values_tables);
Scalar function defined by the DOF values of a single cell. Based on the CellWiseFunction and RefSpac...
void set_active_cell(const VectorType &in_local_dof_values)
Set the cell that the function should be evaluated on.
Interface to build the patches of the interface reconstruction vertices for visualization....
void build_patches(const std::map< types::global_cell_index, std::vector< Point< dim > > > &interface_reconstruction_vertices)
Build the patches of the interface reconstruction vertices for visualization.
Solver to compute the signed distance from a given level of a level-set field. It is based on the met...
void get_face_opposite_dofs(unsigned int local_face_id, std::vector< unsigned int > &local_opposite_dofs)
Return the local id of the opposite DoFs to the given face (works for quad only).
void set_level_set_from_background_mesh(const DoFHandler< dim > &background_dof_handler, const VectorType &background_level_set_vector)
Set the level-set field from the background mesh solver.
void get_face_transformation_jacobian(const DerivativeForm< 1, dim, dim > &cell_transformation_jac, const unsigned int local_face_id, LAPACKFullMatrix< double > &face_transformation_jac)
Return the face transformation jacobian (dim-1 x dim-1). This is required because the distance minimi...
void compute_cell_wise_volume_correction()
Compute the cell-wise volume correction to match the volume englobed by the given level of the level_...
Tensor< 1, dim > transform_ref_face_correction_to_ref_cell(const Vector< double > &correction_ref_face, const unsigned int local_face_id)
Transform the Newton correction in a reference face to a tensor (dim) in the reference cell....
IndexSet locally_owned_dofs
Set of locally owned DoFs.
void update_ghost_values() const
Update the ghost DoFs entries of the solution vectors to gain read access to the ghost elements.
std::map< types::global_cell_index, std::vector< Point< dim > > > interface_reconstruction_vertices
LinearAlgebra::distributed::Vector< double > distance_with_ghost
PVDHandler pvd_handler_signed_distance
PVDHandler for signed distance.
void compute_analytical_jacobian(const Tensor< 1, dim > &x_n_to_x_I_real_p1, const LAPACKFullMatrix< double > &transformation_jacobian, const std::vector< double > &face_local_dof_values, LAPACKFullMatrix< double > &jacobian_matrix)
Compute the analytical jacobian at the point x_n of the distance minimization problem for the DoF x_I...
const Parameters::Verbosity verbosity
Verbosity level.
LinearAlgebra::distributed::Vector< double > signed_distance_with_ghost
const double max_distance
Maximum redistanciation distance.
LinearAlgebra::distributed::Vector< double > distance
Solution vector of the distance (write only).
VectorType level_set
Level-set field coming from the main solver.
double compute_distance(const Tensor< 1, dim > &x_n_to_x_I_real, const double distance)
Compute the distance according to: d(x_I) = d(x_n) + ||x_I - x_n||.
AffineConstraints< double > constraints
Hanging node constraints.
DoFHandler< dim > dof_handler
DoFHandler describing the problem.
void initialize_distance()
Initialize the distance solution vectors to the given max_distance.
void compute_second_neighbors_distance()
Compute the geometric distance (marching method) between the interface reconstruction and the rest of...
GlobalVectorType signed_distance_output
Solution vector of the signed distance as used for output only.
IndexSet locally_relevant_dofs
Set of locally relevant DoFs.
ConditionalOStream pcout
Parallel output stream.
PVDHandler pvd_handler_reconstruction
PVDHandler for interface reconstruction.
void setup_dofs()
Initialize the degrees of freedom and associated memory.
void conserve_global_volume()
Correct the global volume to match the volume englobed by the given level of the level_set field.
std::shared_ptr< FiniteElement< dim > > fe
Finite element discretizing the problem.
IndexSet locally_active_dofs
Set of locally active DoFs.
Point< dim > transform_ref_face_point_to_ref_cell(const Point< dim - 1 > &x_ref_face, const unsigned int local_face_id)
Transform a point dim-1 in a reference face to a point dim in the reference cell. This is required be...
VectorType & get_signed_distance()
Get the computed signed distance field.
void compute_signed_distance_from_distance()
Compute the signed_distance from the distance vector and the sign of the signed_distance vector entri...
LinearAlgebra::distributed::Vector< double > signed_distance
Solution vector of the signed distance (write only).
void output_interface_reconstruction(const std::string &output_name, const std::string &output_path, const double time, const unsigned int it)
Output the interface reconstruction used for signed distance computations.
std::set< types::global_dof_index > intersected_dofs
Set of DoFs belonging to intersected cells.
void solve()
Solve for the signed distance from the given level of the level-set vector.
std::map< types::global_cell_index, std::vector< CellData< dim - 1 > > > interface_reconstruction_cells
LinearAlgebra::distributed::Vector< double > volume_correction
const double scaling
Scaling factor to apply to the input level-set field.
void compute_first_neighbors_distance()
Compute the geometric distance (brute force) between the interface reconstruction and the DoFs of the...
void output_signed_distance(const std::string &output_name, const std::string &output_path, const double time, const unsigned int it)
Output the signed distance field for visualization.
void zero_out_ghost_values() const
Zero the ghost DoFs entries of the solution vectors to gain write access to the ghost elements.
void compute_residual(const Tensor< 1, dim > &x_n_to_x_I_real, const Tensor< 1, dim > &distance_gradient, const LAPACKFullMatrix< double > &transformation_jac, Tensor< 1, dim - 1 > &residual_ref)
Compute the residual at the point x_n of the distance minimization problem for the DoF x_I in the ref...
std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook()
Gather and return vector of output structs that are particular to some applications.
void get_face_local_dofs(unsigned int local_face_id, std::vector< unsigned int > &local_dofs)
Return the local id of the face DoFs (works for quad only).
std::shared_ptr< MappingQ< dim > > mapping
Mapping between the real and reference space.
void exchange_distance()
Exchange the distance and set it to the minimum value across the processors by using the compress(Vec...
Postprocessing - Defines the parameters for the post-processing. In Lethe, post-processing implies th...
void announce_string(const ConditionalOStream &pcout, const std::string &expression, const char delimiter='-')
Prints a string and then adds a line above and below made with dashes containing as many dashes as th...
Definition utilities.h:500
constexpr int sgn(const T val) noexcept
Retrieve the sign of a value.
Definition utilities.h:344
double compute_cell_diameter(const double cell_measure, const unsigned int fe_degree)
Computes equivalent cell diameter by comparing the area to a disk (2D) or the volume to a sphere (3D)...
Definition utilities.h:989
Variable
Solution fields of the different physics that are used as an indicator for multiple purposes (e....
@ velocity
Velocity vector field from fluid dynamics.
double compute_cell_wise_volume(FEPointEvaluation< 1, dim > &fe_point_evaluation, const typename DoFHandler< dim >::active_cell_iterator &cell, Vector< double > cell_dof_level_set_values, const double corr, const unsigned int n_quad_points)
Compute the volume enclosed by the 0 level of a level-set field inside a cell. The inside volume is c...
void postprocess_isocontour_bounding_values(const Variable &variable, const std::multimap< Variable, std::pair< unsigned int, typename Parameters::PostProcessing< dim >::IsocontourBoundingBoxes::Isocontour > > &ids_and_isocontours_per_variable, const DoFHandler< dim > &dof_handler, const VectorType &solution_vector, const double current_time, const Parameters::Verbosity &verbosity, const ConditionalOStream &pcout, std::vector< TableHandler > &isocontour_bounding_values_tables)
Identifies the bounding values of requested isocontours using InterfaceTools::compute_isocontour_boun...
void reconstruct_interface(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const FiniteElement< dim > &fe, const VectorType &level_set_vector, const double iso_level, std::map< types::global_cell_index, std::vector< Point< dim > > > &interface_reconstruction_vertices, std::map< types::global_cell_index, std::vector< CellData< dim - 1 > > > &interface_reconstruction_cells, std::set< types::global_dof_index > &intersected_dofs)
Reconstruct the interface defined by a given level of a level set field in the domain.
IsocontourBoundingValues< dim > compute_isocontour_bounding_values(const DoFHandler< dim > &dof_handler, const VectorType &solution_vector, const double isovalue)
Identifies and returns bounding coordinates of a given isocontour by scanning through quadrature poin...
void write_isocontour_bounding_values_tables(const MPI_Comm &mpi_communicator, const std::string &output_folder, const Variable &variable, const std::multimap< Variable, std::pair< unsigned int, typename Parameters::PostProcessing< dim >::IsocontourBoundingBoxes::Isocontour > > &ids_and_isocontours_per_variable, const std::vector< TableHandler > &isocontour_bounding_values_tables)
Writes the bounding values tables of the specified isocontours in their respective output files.
@ z_max
Maximum z value of the isocontour.
@ z_min
Minimum z value of the isocontour.
@ x_max
Maximum x value of the isocontour.
@ y_max
Maximum y value of the isocontour.
@ y_min
Minimum y value of the isocontour.
@ x_min
Minimum x value of the isocontour.
std::pair< Point< dim >, Tensor< 1, dim > > integrate_barycenter(const DoFHandler< dim > &dof_handler, const FiniteElement< dim > &fe, const VectorType &level_set_vector_relevant_copy, const Mapping< dim > &mapping_velocity, const DoFHandler< dim > &dof_handler_velocity, const FiniteElement< dim > &fe_velocity, const VectorType &velocity_vector)
Integrate the barycenter position and velocity of the volume enclosed by the zero-level of a level se...
std::pair< double, double > integrate_volume_and_surface(const DoFHandler< dim > &dof_handler, const FiniteElement< dim > &fe, const VectorType &level_set_vector_relevant_copy)
Integrate the surface area of a given level of a level set field and the volume enclosed by it....
double find_point_triangle_distance(const std::vector< Point< dim > > &triangle_vertices, const Point< dim > &point)
Calculates the distance between points and a triangle (defined using three vertices)....
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...
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...
Bounding values of an isocontour along each coordinate direction ( and in 2D; , ,...
const std::array< std::string, 2 *dim > bounding_coordinates_names
Array of bounding coordinates names.
dealii::Vector< double > bounding_values
Vector containing the bounding values of an isocontour.
Struct containing information about the solution output. It is used to pass all the information requi...
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17
void convert_vector_dealii_to_trilinos(dealii::TrilinosWrappers::MPI::Vector &out, const dealii::LinearAlgebra::distributed::Vector< number > &in)
Helper function that allows to convert deal.II vectors to Trilinos vectors.
Definition vector.h:39