Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
interface_tools.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_interface_tools_h
5#define lethe_interface_tools_h
6
10#include <core/utilities.h>
11#include <core/vector.h>
12
13#include <deal.II/base/conditional_ostream.h>
14#include <deal.II/base/data_out_base.h>
15#include <deal.II/base/function.h>
16
17#include <deal.II/dofs/dof_handler.h>
18
19#include <deal.II/fe/fe.h>
20#include <deal.II/fe/fe_q.h>
21#include <deal.II/fe/mapping_fe.h>
22
23#include <deal.II/lac/lapack_full_matrix.h>
24
25#include <deal.II/matrix_free/fe_point_evaluation.h>
26
27#include <deal.II/non_matching/fe_immersed_values.h>
28
29#include <iostream>
30#include <utility>
31
32using namespace dealii;
33
35{
36 /**
37 * @brief Scalar function defined by the DOF values of a single cell. Based on
38 * the CellWiseFunction and RefSpaceFEFieldFunction of dealii.
39 *
40 * @tparam dim An integer that denotes the dimension of the space in which
41 * the problem is solved.
42 *
43 * @tparam VectorType The vector type of the solution vector.
44 *
45 * @tparam FEType The finite element type used to discretize the problem.
46 */
47 template <int dim,
48 typename VectorType = Vector<double>,
49 typename FEType = FE_Q<dim>>
50 class CellWiseFunction : public Function<dim>
51 {
52 public:
53 /**
54 * @brief Constructor.
55 *
56 * @param[in] p_fe_degree Finite element degree discretizing the field we
57 * want to convert to a CellWiseFunction.
58 *
59 */
60 CellWiseFunction(const unsigned int p_fe_degree)
61 : fe(p_fe_degree)
62 , n_cell_wise_dofs(fe.dofs_per_cell)
63 {}
64
65 /**
66 * @brief Set the cell that the function should be evaluated on.
67 *
68 * @param[in] in_local_dof_values Cell's DOF values
69 *
70 */
71 void
72 set_active_cell(const VectorType &in_local_dof_values)
73 {
74 cell_dof_values = in_local_dof_values;
75 }
76
77 /**
78 * @brief Return the value of the function at the given point in the reference cell.
79 *
80 * @param[in] point Coordinates of the point in the reference cell
81 *
82 * @param[in] component Index of the component of the function for which the
83 * value is computed
84 *
85 * @return Value of the function (or the component of interest) at the given point
86 *
87 */
88 double
89 value(const Point<dim> &point,
90 const unsigned int component = 0) const override;
91
92 /**
93 * @brief Return the function gradient of the specified component at the
94 * given point in the reference cell.
95 *
96 * @param[in] point Coordinates of the point in the reference cell
97 *
98 * @param[in] component Index of the component of the function for which the
99 * gradient is computed
100 *
101 * @return Value of the gradient of the specified component at the given point
102 *
103 */
104 Tensor<1, dim>
105 gradient(const Point<dim> &point,
106 const unsigned int component = 0) const override;
107
108 /**
109 * @brief Return the function Hessian of the specified component at the given point in the reference cell.
110 *
111 * @param[in] point Coordinates of the point in the reference cell
112 *
113 * @param[in] component Index of the component of the function for which the
114 * Hessian is computed
115 *
116 * @return Value of the Hessian of the specified component at the given point
117 *
118 */
119 SymmetricTensor<2, dim>
120 hessian(const Point<dim> &point,
121 const unsigned int component = 0) const override;
122
123 private:
124 /// Finite element discretizing the field of interest
125 FEType fe;
126
127 /// Number of DoFs per element
128 unsigned int n_cell_wise_dofs;
129
130 /// Value of the level-set field at the DoFs of the cell
132 };
133
134
135 template <int dim, typename VectorType, typename FEType>
136 inline double
138 const Point<dim> &point,
139 const unsigned int component) const
140 {
141 double value = 0;
142 for (unsigned int i = 0; i < n_cell_wise_dofs; ++i)
143 value +=
144 cell_dof_values[i] * fe.shape_value_component(i, point, component);
145
146 return value;
147 }
148
149 template <int dim, typename VectorType, typename FEType>
150 inline Tensor<1, dim>
152 const Point<dim> &point,
153 const unsigned int component) const
154 {
155 Tensor<1, dim> gradient;
156 for (unsigned int i = 0; i < n_cell_wise_dofs; ++i)
157 gradient +=
158 cell_dof_values[i] * fe.shape_grad_component(i, point, component);
159
160 return gradient;
161 }
162
163 template <int dim, typename VectorType, typename FEType>
164 inline SymmetricTensor<2, dim>
166 const Point<dim> &point,
167 const unsigned int component) const
168 {
169 Tensor<2, dim> hessian;
170 for (unsigned int i = 0; i < n_cell_wise_dofs; ++i)
171 hessian +=
172 cell_dof_values[i] * fe.shape_grad_grad_component(i, point, component);
173
174 return symmetrize(hessian);
175 }
176
177 /**
178 * @brief
179 * Compute the volume enclosed by the 0 level of a level-set field
180 * inside a cell. The inside volume is computed, defined by negative values of
181 * the level-set field.
182 *
183 * @tparam dim An integer that denotes the dimension of the space in which
184 * the problem is solved.
185 *
186 * @param[in] fe_point_evaluation FePointEvaluation
187 *
188 * @param[in] cell Cell for which the volume is computed
189 *
190 * @param[in] cell_dof_level_set_values Cell DoF values of the level-set field
191 *
192 * @param[in] corr Correction to apply to the DOF values (constant for all
193 * DoFs). It can be used if we want the volume enclosed by the iso-level equal
194 * to the value of the correction.
195 *
196 * @param[in] n_quad_points Number of quadrature points for the volume
197 * integration faces
198 *
199 * @return cell-wise volume
200 */
201 template <int dim>
202 double
204 FEPointEvaluation<1, dim> &fe_point_evaluation,
205 const typename DoFHandler<dim>::active_cell_iterator &cell,
206 Vector<double> cell_dof_level_set_values,
207 const double corr,
208 const unsigned int n_quad_points);
209
210 /**
211 * @brief Integrate the surface area of a given level of a level set field and the
212 * volume enclosed by it. The inside volume is computed, defined by negative
213 * values of the level-set field.
214 *
215 * @tparam dim An integer that denotes the dimension of the space in which
216 * the problem is solved.
217 * @tparam VectorType The vector type of the solution vector.
218 *
219 * @param[in] dof_handler DofHandler associated to the triangulation on which
220 * the volume is computed
221 * @param[in] fe Finite element
222 * @param[in] level_set_vector_relevant_copy Level-set vector
223 *
224 * @return Volume enclosed by specified level and its surface area.
225 * The volume is the first value and the surface the second.
226 */
227 template <int dim, typename VectorType>
228 std::pair<double, double>
230 const DoFHandler<dim> &dof_handler,
231 const FiniteElement<dim> &fe,
232 const VectorType &level_set_vector_relevant_copy);
233
234 /**
235 * @brief Overload of the function above. Here, the zero-contour of the level
236 * set field is defined with respect to the @p iso_level value precised by
237 * shifting the values of the level set field.
238 *
239 * @tparam dim An integer that denotes the dimension of the space in which
240 * the problem is solved.
241 * @tparam VectorType The vector type of the solution vector.
242 *
243 * @param[in] dof_handler DofHandler associated to the triangulation on which
244 * the volume is computed
245 * @param[in] fe Finite element
246 * @param[in] level_set_vector Level-set vector
247 * @param[in] iso_level Given level of the level-set field enclosing the
248 * volume of interest
249 *
250 * @return Volume and surface enclosed by specified @p iso_level.
251 * The volume is the first value and the surface the second.
252 */
253 template <int dim, typename VectorType>
254 std::pair<double, double>
255 integrate_volume_and_surface(const DoFHandler<dim> &dof_handler,
256 const FiniteElement<dim> &fe,
257 const VectorType &level_set_vector,
258 const double iso_level);
259
260 /**
261 * @brief Integrate the barycenter position and velocity of the volume
262 * enclosed by the zero-level of a level set field. The region of interest
263 * correspond to the sub-domain where the level-set value is smaller or
264 * equal to 0.
265 *
266 * @tparam dim An integer that denotes the dimension of the space in which
267 * the problem is solved.
268 * @tparam VectorType The vector type of the solution vector.
269 *
270 * @param[in] dof_handler DofHandler associated to the triangulation on which
271 * the level-set is described
272 * @param[in] fe Finite element describing the level-set
273 * @param[in] level_set_vector_relevant_copy Level-set vector
274 * @param[in] mapping_velocity Mapping associated to the velocity field
275 * @param[in] dof_handler_velocity DofHandler associated to the triangulation
276 * on which the velocity is described
277 * @param[in] fe Finite element describing the velocity
278 * @param[in] velocity_vector Velocity solution vector
279
280 * @return The position and the velocity of the barycenter of the region enclosed
281 * by the zero-level of the level-set field. The position is the first entry
282 and
283 * the velocity the second.
284 */
285 template <int dim, typename VectorType>
286 std::pair<Point<dim>, Tensor<1, dim>>
287 integrate_barycenter(const DoFHandler<dim> &dof_handler,
288 const FiniteElement<dim> &fe,
289 const VectorType &level_set_vector_relevant_copy,
290 const Mapping<dim> &mapping_velocity,
291 const DoFHandler<dim> &dof_handler_velocity,
292 const FiniteElement<dim> &fe_velocity,
293 const VectorType &velocity_vector);
294
295 /**
296 * @brief Integrate the barycenter position and velocity of the region
297 * enclosed by a given level of a level-set field. The region of interest
298 * correspond to the sub-domain where the level-set value is greater or
299 * equal to the specified level.
300 *
301 * @tparam dim An integer that denotes the dimension of the space in which
302 * the problem is solved.
303 * @tparam VectorType The vector type of the solution vector.
304 *
305 * @param[in] dof_handler DofHandler associated to the triangulation on which
306 * the level-set is described
307 * @param[in] fe Finite element describing the level-set
308 * @param[in] level_set_vector Level-set vector
309 * @param[in] mapping_velocity Mapping associated to the velocity field
310 * @param[in] dof_handler_velocity DofHandler associated to the triangulation
311 * on which the velocity is described
312 * @param[in] fe Finite element describing the velocity
313 * @param[in] velocity_vector Velocity solution vector
314 * @param[in] iso_level Given level of the level-set field enclosing the
315 * region of interest
316
317 * @return The position and the velocity of the barycenter of the region enclosed
318 * by the specified level of the level-set field. The position is the first
319 entry
320 * and the velocity the second.
321 */
322 template <int dim, typename VectorType>
323 std::pair<Point<dim>, Tensor<1, dim>>
324 integrate_barycenter(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 /**
334 * @brief
335 * Reconstruct the interface defined by a given level of a level set field
336 * in the domain.
337 *
338 * @tparam dim An integer that denotes the dimension of the space in which
339 * the problem is solved.
340 *
341 * @tparam VectorType The vector type of the solution vector.
342 *
343 * @param[in] mapping Mapping of the domain
344 *
345 * @param[in] dof_handler DofHandler associated to the triangulation for which
346 * the interface is reconstructed
347 *
348 * @param[in] fe Finite element
349 *
350 * @param[in] level_set_vector Level-set vector
351 *
352 * @param[in] iso_level Given level of the level-set field defining the
353 * interface of interest
354 *
355 * @param[in,out] interface_reconstruction_vertices Cell-wise map of the
356 * reconstructed surface vertices. The map contains vectors storing the
357 * vertices of the reconstructed surface for each intersected volume cell
358 * (dim).
359 *
360 * @param[in,out] interface_reconstruction_cells Cell-wise map of the
361 * reconstructed surface cells. The map contains vectors storing the cell
362 * (dim-1) of the reconstructed surface for each intersected volume cell
363 * (dim).
364 *
365 * @param[in,out] intersected_dofs Set of DoFs that belong to intersected
366 * volume cell (dim).
367 *
368 */
369 template <int dim, typename VectorType>
370 void
372 const Mapping<dim> &mapping,
373 const DoFHandler<dim> &dof_handler,
374 const FiniteElement<dim> &fe,
375 const VectorType &level_set_vector,
376 const double iso_level,
377 std::map<types::global_cell_index, std::vector<Point<dim>>>
378 &interface_reconstruction_vertices,
379 std::map<types::global_cell_index, std::vector<CellData<dim - 1>>>
380 &interface_reconstruction_cells,
381 std::set<types::global_dof_index> &intersected_dofs);
382
383
384 /**
385 * @brief Interface to build the patches of the interface reconstruction
386 * vertices for visualization. It reproduce the same structure as particle
387 * visualization.
388 *
389 * @tparam dim An integer that denotes the number of spatial dimensions.
390 *
391 */
392 template <int dim>
393 class InterfaceReconstructionDataOut : public dealii::DataOutInterface<0, dim>
394 {
395 public:
396 /**
397 * @brief Default constructor.
398 */
400
401 /**
402 * @brief Build the patches of the interface reconstruction vertices for
403 * visualization.
404 *
405 * @param[in,out] interface_reconstruction_vertices Cell-wise map of the
406 * reconstructed surface vertices. The map contains vectors storing the
407 * vertices of the reconstructed surface for each intersected volume cell
408 * (dim).
409 */
410 void
412 const std::map<types::global_cell_index, std::vector<Point<dim>>>
413 &interface_reconstruction_vertices);
414
415 private:
416 /**
417 * @brief Implementation of the corresponding function of the base class.
418 */
419 const std::vector<DataOutBase::Patch<0, dim>> &
420 get_patches() const override
421 {
422 return patches;
423 }
424
425 /**
426 * @brief Implementation of the corresponding function of the base class.
427 */
428 std::vector<std::string>
429 get_dataset_names() const override
430 {
431 return dataset_names;
432 }
433
434 /// Output information that is filled by build_patches() and
435 /// written by the write function of the base class.
436 std::vector<DataOutBase::Patch<0, dim>> patches;
437
438 /// A list of field names for all data components stored in patches.
439 std::vector<std::string> dataset_names;
440 };
441
442 template <int dim>
443 void
445 const std::map<types::global_cell_index, std::vector<Point<dim>>>
446 &interface_reconstruction_vertices)
447 {
448 for (auto const &cell : interface_reconstruction_vertices)
449 {
450 const std::vector<Point<dim>> &vertices = cell.second;
451 for (const Point<dim> &vertex : vertices)
452 {
453 DataOutBase::Patch<0, dim> temp;
454 temp.vertices[0] = vertex;
455 patches.push_back(temp);
456 }
457 }
458 }
459
460 /**
461 * @brief Solver to compute the signed distance from a given level of a level-set field. It is based on the method proposed in the following article: Ausas, R.F., Dari, E.A. and Buscaglia, G.C. (2011), A geometric mass-preserving redistancing scheme for the level set function. Int. J. Numer. Meth. Fluids, 65: 989-1010. https://doi.org/10.1002/fld.2227.
462 *
463 * @tparam dim An integer that denotes the dimension of the space in which
464 * the problem is solved.
465 *
466 * @tparam VectorType The vector type of the level-set vector.
467 */
468 template <int dim, typename VectorType>
470 {
471 public:
472 /**
473 * @brief Base constructor.
474 *
475 * @param[in] background_triangulation Shared pointer to the triangulation
476 * of the domain
477 *
478 * @param[in] background_fe Shared pointer to the finite element
479 * discretizing the domain
480 *
481 * @param[in] p_max_distance Maximum reinitialization distance value
482 *
483 * @param[in] p_iso_level Iso-level (before scaling) from which the signed
484 * distance is computed
485 *
486 * @param[in] p_scaling Scaling factor to apply to the input level-set
487 * field. It is used to switch the inside and outside subdomains, if needed.
488 *
489 * @param[in] p_verbosity Verbosity level
490 *
491 */
493 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
494 &background_triangulation,
495 std::shared_ptr<FiniteElement<dim>> background_fe,
496 const double p_max_distance,
497 const double p_iso_level,
498 const double p_scaling,
499 const Parameters::Verbosity p_verbosity)
500 : dof_handler(*background_triangulation)
501 , fe(std::move(background_fe))
502 , max_distance(p_max_distance)
503 , iso_level(p_iso_level * p_scaling)
504 , scaling(p_scaling)
505 , verbosity(p_verbosity)
506 , pcout(std::cout,
507 (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0))
508 {
509 // MappingQ is required to reduce significantly the computational time of
510 // the FEPointEvaluation.reinit(). Using MappingQ and FE_Q allow to take
511 // the "fast path" in FEPointEvaluation calls.
512 mapping = std::make_shared<MappingQ<dim>>(fe->degree);
515
516 // Matrices for analytical Jacobian computations
517 hessian_matrix = LAPACKFullMatrix<double>(dim, dim);
518 H_x_transformation_jacobian = LAPACKFullMatrix<double>(dim, dim - 1);
519 }
520
521 /**
522 * @brief Initialize the degrees of freedom and associated memory.
523 *
524 * This function sets up the DoF handler, initializes the solution vectors,
525 * and configures the constraints for the signed distance solver.
526 */
527 void
528 setup_dofs();
529
530 /**
531 * @brief Set the level-set field from the background mesh solver.
532 *
533 * This function transfers the level-set field from the main solver to the
534 * signed distance solver. For example, when using geometric redistanciation
535 * of the CLS phase indicator, the level-set field comes from the CLS
536 * solver.
537 *
538 * @param[in] background_dof_handler DoFHandler corresponding to the
539 * level-set field solver.
540 * @param[in] background_level_set_vector Level-set solution vector from
541 * the background solver.
542 */
543 void
545 const DoFHandler<dim> &background_dof_handler,
546 const VectorType &background_level_set_vector);
547
548 /**
549 * @brief Solve for the signed distance from the given level of the level-set vector.
550 *
551 * This function computes the signed distance field using the method
552 * described in Ausas et al. (2011). The algorithm preserves the interface
553 * location while computing accurate distances throughout the domain.
554 */
555 void
556 solve();
557
558 /**
559 * @brief Get the computed signed distance field.
560 *
561 * @return Reference to the vector storing the computed signed distance values.
562 */
563 VectorType &
565
566 /**
567 * @brief Output the interface reconstruction used for signed distance computations.
568 *
569 * This function writes the reconstructed interface vertices and cells to
570 * VTU files for visualization purposes.
571 *
572 * @param[in] output_name Name of the output file.
573 * @param[in] output_path Path to the output directory.
574 * @param[in] time Current simulation time.
575 * @param[in] it Iteration number for file naming.
576 */
577 void
578 output_interface_reconstruction(const std::string &output_name,
579 const std::string &output_path,
580 const double time,
581 const unsigned int it);
582
583 /**
584 * @brief Output the signed distance field for visualization.
585 *
586 * This function writes the computed signed distance field to VTU files
587 * for post-processing and visualization.
588 *
589 * @param[in] output_name Name of the output file.
590 * @param[in] output_path Path to the output directory.
591 * @param[in] time Current simulation time.
592 * @param[in] it Iteration number for file naming.
593 */
594 void
595 output_signed_distance(const std::string &output_name,
596 const std::string &output_path,
597 const double time,
598 const unsigned int it);
599
600 /**
601 * @brief Gather and return vector of output structs that are particular to some applications.
602 *
603 * @return Vector of OutputStructs that will be used to write the output results as VTU files.
604 */
605 std::vector<OutputStruct<dim, GlobalVectorType>>
607
608 /// DoFHandler describing the problem
609 DoFHandler<dim> dof_handler;
610
611 private:
612 /**
613 * @brief Zero the ghost DoFs entries of the solution vectors to gain write
614 * access to the ghost elements
615 */
616 void
617 zero_out_ghost_values() const;
618
619 /**
620 * @brief Update the ghost DoFs entries of the solution vectors to gain read
621 * access to the ghost elements
622 */
623 void
624 update_ghost_values() const;
625
626 /**
627 * @brief Exchange the distance and set it to the minimum value across the
628 * processors by using the compress(VectorOperation::min) function
629 */
630 void
632
633 /**
634 * @brief Initialize the distance solution vectors to the given max_distance
635 */
636 void
638
639 /**
640 * @brief Compute the geometric distance (brute force) between the interface
641 * reconstruction and the DoFs of the intersected cells (first neighbors)
642 */
643 void
645
646 /**
647 * @brief Compute the geometric distance (marching method) between the
648 * interface reconstruction and the rest of the DoFs (second neighbors)
649 */
650 void
652
653 /**
654 * @brief Compute the signed_distance from the distance vector and the sign of the
655 * signed_distance vector entries
656 */
657 void
659
660 /**
661 * @brief Compute the cell-wise volume correction to match the volume englobed
662 * by the given level of the level_set field in each element
663 */
664 void
666
667 /**
668 * @brief Correct the global volume to match the volume englobed by the given level
669 * of the level_set field
670 */
671 void
673
674 /**
675 * @brief Return the local id of the opposite faces to the given local Dof
676 * (works for quad only).
677 *
678 * @param[in] local_dof_id Local id of the DoF in the cell
679 *
680 * @param[out] local_opposite_faces The vector containing the id of the
681 * opposite faces
682 */
683 inline void
684 get_dof_opposite_faces(unsigned int local_dof_id,
685 std::vector<unsigned int> &local_opposite_faces)
686 {
687 unsigned int local_dof_id_2d = local_dof_id % 4;
688
689 local_opposite_faces[0] = (local_dof_id_2d + 1) % 2;
690 local_opposite_faces[1] = 3 - local_dof_id_2d / 2;
691
692 if constexpr (dim == 3)
693 local_opposite_faces[2] = 5 - local_dof_id / 4;
694 };
695
696 /**
697 * @brief Set the map of local id of the opposite DoFs to the given face
698 * (works for quad only).
699 */
700 inline void
702 {
703 if constexpr (dim == 2)
704 {
705 face_opposite_dofs_map[0] = {1, 3};
706 face_opposite_dofs_map[1] = {0, 2};
707 face_opposite_dofs_map[2] = {2, 3};
708 face_opposite_dofs_map[3] = {0, 1};
709 }
710
711 if constexpr (dim == 3)
712 {
713 face_opposite_dofs_map[0] = {1, 3, 5, 7};
714 face_opposite_dofs_map[1] = {0, 2, 4, 6};
715 face_opposite_dofs_map[2] = {2, 3, 6, 7};
716 face_opposite_dofs_map[3] = {0, 1, 4, 5};
717 face_opposite_dofs_map[4] = {4, 5, 6, 7};
718 face_opposite_dofs_map[5] = {0, 1, 2, 3};
719 }
720 }
721
722 /**
723 * @brief Set the map of local id of the face DoFs (works for quad only).
724 */
725 inline void
727 {
728 if constexpr (dim == 2)
729 {
730 face_dofs_map[0] = {0, 2};
731 face_dofs_map[1] = {1, 3};
732 face_dofs_map[2] = {0, 1};
733 face_dofs_map[3] = {2, 3};
734 }
735
736 if constexpr (dim == 3)
737 {
738 face_dofs_map[0] = {0, 2, 4, 6};
739 face_dofs_map[1] = {1, 3, 5, 7};
740 face_dofs_map[2] = {0, 1, 4, 5};
741 face_dofs_map[3] = {2, 3, 6, 7};
742 face_dofs_map[4] = {0, 1, 2, 3};
743 face_dofs_map[5] = {4, 5, 6, 7};
744 }
745 }
746
747 /**
748 * @brief Return the local id of the opposite DoFs to the given face
749 * (works for quad only).
750 *
751 * @param[in] local_face_id Local id of the face in the cell
752 *
753 * @param[out] local_opposite_dofs The vector containing the id of the
754 * opposite DoFs
755 */
756 inline void
757 get_face_opposite_dofs(unsigned int local_face_id,
758 std::vector<unsigned int> &local_opposite_dofs)
759 {
760 local_opposite_dofs = face_opposite_dofs_map.at(local_face_id);
761 };
762
763 /**
764 * @brief Return the local id of the face DoFs (works for quad only).
765 *
766 * @param[in] local_face_id Local id of the face in the cell
767 *
768 * @param[out] local_dofs The vector containing the id of the
769 * local DoFs
770 */
771 inline void
772 get_face_local_dofs(unsigned int local_face_id,
773 std::vector<unsigned int> &local_dofs)
774 {
775 local_dofs = face_dofs_map.at(local_face_id);
776 };
777
778 /**
779 * @brief Return the face transformation jacobian (dim-1 x dim-1). This is
780 * required because the distance minimization problem is resolved in the
781 * reference face space (dim-1).
782 *
783 * @param[in] cell_transformation_jac transformation jacobian of the cell
784 * (dim x dim)
785 *
786 * @param[in] local_face_id local id of the face
787 *
788 * @param[out] face_transformation_jac face transformation jacobian (dim-1 x
789 * dim-1) faces
790 */
791 inline void
793 const DerivativeForm<1, dim, dim> &cell_transformation_jac,
794 const unsigned int local_face_id,
795 LAPACKFullMatrix<double> &face_transformation_jac)
796 {
797 for (int i = 0; i < dim; ++i)
798 {
799 int k = 0;
800 for (unsigned int j = 0; std::cmp_less(j, dim); ++j)
801 {
802 if (local_face_id / 2 == j)
803 continue;
804
805 if (k < dim - 1)
806 face_transformation_jac(i, k) = cell_transformation_jac[i][j];
807 k += 1;
808 }
809 }
810 };
811
812 /**
813 * @brief
814 * Transform a point dim-1 in a reference face to a point dim in the
815 * reference cell. This is required because the distance minimization
816 * problem is resolved in the reference face space (dim-1).
817 *
818 * @param[in] x_ref_face point dim-1 in the reference face
819 *
820 * @param[in] local_face_id local id of the face
821 *
822 * @return Point dim in the reference cell
823 */
824 inline Point<dim>
825 transform_ref_face_point_to_ref_cell(const Point<dim - 1> &x_ref_face,
826 const unsigned int local_face_id)
827 {
828 Point<dim> x_ref_cell;
829
830 unsigned int j = 0;
831 for (unsigned int i = 0; std::cmp_less(i, dim); ++i)
832 {
833 if (local_face_id / 2 == i)
834 {
835 x_ref_cell[i] = double(local_face_id % 2);
836 continue;
837 }
838 x_ref_cell[i] = x_ref_face[j];
839 j += 1;
840 }
841
842 return x_ref_cell;
843 };
844
845 /**
846 * @brief Compute the residual at the point x_n of the distance minimization
847 * problem for the DoF x_I in the reference face space (dim - 1). In the
848 * real space the residual correspond to: R = grad(d) - (x_I - x_n)/||x_I -
849 * x_n||
850 *
851 *
852 * @param[in] x_n_to_x_I_real vector from x_n to x_I in the real space
853 *
854 * @param[in] distance_gradient gradient of the distance at the point x_n
855 *
856 * @param[in] transformation_jac transformation jacobian of the face
857 *
858 * @param[out] residual_ref residual in the reference face space
859 */
860 inline void
861 compute_residual(const Tensor<1, dim> &x_n_to_x_I_real,
862 const Tensor<1, dim> &distance_gradient,
863 const LAPACKFullMatrix<double> &transformation_jac,
864 Tensor<1, dim - 1> &residual_ref)
865 {
866 Tensor<1, dim> residual_real =
867 distance_gradient - (1.0 / x_n_to_x_I_real.norm()) * x_n_to_x_I_real;
868
869 for (int i = 0; i < dim - 1; ++i)
870 for (int j = 0; j < dim; ++j)
871 residual_ref[i] += transformation_jac(j, i) * residual_real[j];
872 };
873
874 /**
875 * @brief Compute the stencil for the numerical jacobian of the distance
876 * minimization problem in the face where the problem is solved
877 *
878 * @param[in] x_ref point in the reference cell space where the jacobian is
879 * evaluated
880 *
881 * @param[in] local_face_id local id of the face in which the numerical
882 * jacobian is required
883 *
884 * @param[in] perturbation value of the perturbation use for the
885 * numerical jacobian computation
886 *
887 * @return vector containing the 2*dim - 1 stencil point. The entries of the
888 * vector are the following:
889 * 4
890 *
891 * 1 0 2
892 *
893 * 3
894 * The entry 0 is the current evaluation point x_ref
895 */
896 inline void
898 const unsigned int local_face_id,
899 const double perturbation,
900 std::vector<Point<dim>> &stencil)
901 {
902 for (int i = 0; i < 2 * dim - 1; ++i)
903 {
904 stencil[i] = x_ref;
905 }
906
907 unsigned int skip_index = local_face_id / 2;
908 std::vector<unsigned int> j_index(dim - 1);
909
910 // Set the coordinates (x,y,z) to be skipped (the coordinates not
911 // perturbed)
912 unsigned int j = 0;
913 for (unsigned int i = 0; std::cmp_less(i, dim); ++i)
914 {
915 if (i == skip_index)
916 continue;
917 j_index[j] = i;
918 j += 1;
919 }
920
921 for (int i = 1; i < dim; ++i)
922 {
923 j = j_index[i - 1];
924 stencil[2 * i - 1][j] -= perturbation;
925 stencil[2 * i][j] += perturbation;
926 }
927 };
928
929 /**
930 * @brief
931 * Transform the Newton correction in a reference face to a tensor (dim) in
932 * the reference cell. This is required because the distance minimization
933 * problem is resolved in the reference face space (dim-1).
934 *
935 * @param[in] correction_ref_face Newton correction in the reference face
936 *
937 * @param[in] local_face_id local id of the face
938 *
939 * @return tensor dim in the reference cell
940 */
941 inline Tensor<1, dim>
943 const Vector<double> &correction_ref_face,
944 const unsigned int local_face_id)
945 {
946 Tensor<1, dim> correction_ref_cell;
947
948 unsigned int j = 0;
949 for (unsigned int i = 0; std::cmp_less(i, dim); ++i)
950 {
951 if (local_face_id / 2 == i)
952 {
953 correction_ref_cell[i] = 0.0;
954 continue;
955 }
956 correction_ref_cell[i] = correction_ref_face[j];
957 j += 1;
958 }
959
960 return correction_ref_cell;
961 };
962
963 /**
964 * @brief
965 * Compute the analytical jacobian at the point x_n of the distance
966 * minimization problem for the DoF x_I in the reference face space (dim -
967 * 1): J_R = J^T*H*J, where J is the face transformation jacobian, and
968 * H is the Hessian matrix in the real space (H = H(d) + H(||x_I - x_n||)).
969 *
970 * @param[in] transformation_jacobian face transformation jacobian
971 *
972 * @param[in] face_local_dof_values values of the DoFs of the face
973 *
974 * @param[out] jacobian_matrix jacobian matrix of the minimization problem
975 */
976 inline void
978 const Tensor<1, dim> &x_n_to_x_I_real_p1,
979 const LAPACKFullMatrix<double> &transformation_jacobian,
980 const std::vector<double> &face_local_dof_values,
981 LAPACKFullMatrix<double> &jacobian_matrix)
982 {
983 const double x_n_to_x_I_real_p1_norm = x_n_to_x_I_real_p1.norm();
984
985 const double x_n_to_x_I_real_p1_norm_inv = 1.0 / x_n_to_x_I_real_p1_norm;
986
987 const double x_n_to_x_I_real_p1_norm_cubic_inv =
988 x_n_to_x_I_real_p1_norm_inv * x_n_to_x_I_real_p1_norm_inv *
989 x_n_to_x_I_real_p1_norm_inv;
990
991 for (int i = 0; i < dim; ++i)
992 {
993 double h_ii = -(x_n_to_x_I_real_p1[i] * x_n_to_x_I_real_p1[i]) *
994 x_n_to_x_I_real_p1_norm_cubic_inv +
995 x_n_to_x_I_real_p1_norm_inv;
996
997 hessian_matrix(i, i) = h_ii;
998
999 for (int j = i + 1; j < dim; ++j)
1000 {
1001 double h_ij = -(x_n_to_x_I_real_p1[i] * x_n_to_x_I_real_p1[j]) *
1002 x_n_to_x_I_real_p1_norm_cubic_inv;
1003
1004 hessian_matrix(i, j) = h_ij;
1005 hessian_matrix(j, i) = h_ij;
1006 }
1007 }
1008
1009 for (int i = 0; i < dim; ++i)
1010 {
1011 for (int j = 0; j < dim - 1; ++j)
1012 {
1013 double matrix_ij = 0;
1014 for (int k = 0; k < dim; ++k)
1015 {
1016 matrix_ij +=
1017 hessian_matrix(i, k) * transformation_jacobian(k, j);
1018 }
1019 H_x_transformation_jacobian(i, j) = matrix_ij;
1020 }
1021 }
1022
1023 for (int i = 0; i < dim - 1; ++i)
1024 {
1025 for (int j = i; j < dim - 1; ++j)
1026 {
1027 double matrix_ij = 0;
1028 for (int k = 0; k < dim; ++k)
1029 {
1030 matrix_ij += transformation_jacobian(k, i) *
1032 }
1033 jacobian_matrix(i, j) = matrix_ij;
1034 jacobian_matrix(j, i) = matrix_ij;
1035 }
1036 }
1037
1038 // In Q1, off-diagonal terms are coming from the term H(d) of the
1039 // real space Hessian. FEPointEvaluation doesn't include the
1040 // implementation of the Hessian, hence it is computed by hand.
1041 double off_diag_H = 0;
1042 if constexpr (dim == 3)
1043 {
1044 off_diag_H = face_local_dof_values[0] - face_local_dof_values[1] -
1045 face_local_dof_values[2] + face_local_dof_values[3];
1046 jacobian_matrix(0, 1) += off_diag_H;
1047 jacobian_matrix(1, 0) += off_diag_H;
1048 }
1049 };
1050
1051 /**
1052 * @brief
1053 * Compute the distance according to: d(x_I) = d(x_n) + ||x_I - x_n||
1054 *
1055 * @param[in] x_n_to_x_I_real vector from x_n to x_I in the real space
1056 *
1057 * @param[in] distance value of the distance at the point x_n
1058 *
1059 * @return distance between x_I and the interface
1060 */
1061 inline double
1062 compute_distance(const Tensor<1, dim> &x_n_to_x_I_real,
1063 const double distance)
1064 {
1065 return distance + x_n_to_x_I_real.norm();
1066 };
1067
1068 /// Finite element discretizing the problem
1069 std::shared_ptr<FiniteElement<dim>> fe;
1070
1071 /// Mapping between the real and reference space
1072 std::shared_ptr<MappingQ<dim>> mapping;
1073
1074 /// Maximum redistanciation distance
1075 const double max_distance;
1076
1077 /// Iso-level describing the interface from which the signed distance is
1078 /// computed (after scaling!!)
1079 const double iso_level;
1080
1081 /// Scaling factor to apply to the input level-set field
1082 const double scaling;
1083
1084 /// Verbosity level
1086
1087 /// Parallel output stream
1088 ConditionalOStream pcout;
1089
1090 /// Set of locally owned DoFs
1092
1093 /// Set of locally relevant DoFs
1095
1096 /// Set of locally active DoFs
1098
1099 /// Level-set field coming from the main solver
1101
1102 /// Solution vector of the signed distance (write only)
1103 LinearAlgebra::distributed::Vector<double> signed_distance;
1104
1105 /// Solution vector of the signed distance as used for output only
1107
1108 /// Solution vector of the signed distance with ghost values (read-only
1109 /// version of signed_distance)
1110 LinearAlgebra::distributed::Vector<double> signed_distance_with_ghost;
1111
1112 /// Solution vector of the distance (write only)
1113 LinearAlgebra::distributed::Vector<double> distance;
1114
1115 /// Solution vector of the distance with ghost values (read-only version of
1116 /// distance)
1117 LinearAlgebra::distributed::Vector<double> distance_with_ghost;
1118
1119 /// Value of the correction to apply to the signed_distance to match the
1120 /// cell-wise volume encompassed by the level 0 of level_set
1121 LinearAlgebra::distributed::Vector<double> volume_correction;
1122
1123 /// Hanging node constraints
1124 AffineConstraints<double> constraints;
1125
1126 /// Surface vertices of the interface reconstruction stored in a cell-wise
1127 /// map (volume cell)
1128 std::map<types::global_cell_index, std::vector<Point<dim>>>
1130
1131 /// Surface cells of the interface reconstruction stored in a cell-wise map
1132 /// (volume cell)
1133 std::map<types::global_cell_index, std::vector<CellData<dim - 1>>>
1135
1136 /// Set of DoFs belonging to intersected cells
1137 std::set<types::global_dof_index> intersected_dofs;
1138
1139 /// PVDHandler for interface reconstruction
1141
1142 /// PVDHandler for signed distance
1144
1145 std::map<unsigned int, std::vector<unsigned int>> face_opposite_dofs_map;
1146
1147 std::map<unsigned int, std::vector<unsigned int>> face_dofs_map;
1148
1149 LAPACKFullMatrix<double> hessian_matrix;
1150 LAPACKFullMatrix<double> H_x_transformation_jacobian;
1151 };
1152
1153
1154 /**
1155 * @brief Named indices used to access the bounding coordinates of an
1156 * isocontour.
1157 *
1158 * This enum defines named indices for the minimum and maximum coordinates
1159 * stored in IsocontourBoundingValues::bounding_values. The values are ordered
1160 * by spatial direction: \f$x\f$, \f$y\f$, then \f$z\f$.
1161 */
1162 enum BoundingCoordinates : unsigned int
1163 {
1164 x_min = 0, ///< Minimum x value of the isocontour
1165 x_max = 1, ///< Maximum x value of the isocontour
1166 y_min = 2, ///< Minimum y value of the isocontour
1167 y_max = 3, ///< Maximum y value of the isocontour
1168 z_min = 4, ///< Minimum z value of the isocontour
1169 z_max = 5 ///< Maximum z value of the isocontour
1170 };
1171
1172 /**
1173 * @brief Bounding values of an isocontour along each coordinate direction
1174 * (\f$x\f$ and \f$y\f$ in 2D; \f$x\f$, \f$y\f$, and \f$z\f$ in 3D). A boolean
1175 * flag also indicates whether the isocontour is present in the simulated
1176 * domain or not.
1177 */
1178 template <int dim>
1180 {
1181 /// Vector containing the bounding values of an isocontour.
1183
1184 /// Array of bounding coordinates names
1185 const std::array<std::string, 2 *dim> bounding_coordinates_names =
1187
1188 /**
1189 * Boolean that indicates that at least one cell of the domain contains the
1190 * interface. This is used to indicate when to write values on the console
1191 * and in the data table. If @p false, the bounding values are invalid and
1192 * not added to the tables nor displayed on console.
1193 */
1194 bool isocontour_exists = false;
1195
1196 /**
1197 * @brief Initializes the vector used to store the bounding values of
1198 * isocontours.
1199 *
1200 * @return Vector of bounding values initialized with extreme values for
1201 * lower and upper bounds in each coordinate direction.
1202 */
1203 dealii::Vector<double>
1205 {
1206 dealii::Vector<double> bounding_values_vec(2 * dim);
1207 for (int i = 0; i < dim; ++i)
1208 {
1209 bounding_values_vec[2 * i] = std::numeric_limits<double>::max();
1210 bounding_values_vec[2 * i + 1] = -std::numeric_limits<double>::max();
1211 }
1212 return bounding_values_vec;
1213 }
1214
1215 /**
1216 * @brief Initializes the array of coordinate boundary name strings for the
1217 * isocontour bounding box.
1218 *
1219 * @return Array with name strings for bounding coordinates.
1220 * - In 2D: "x_min", "x_max", "y_min", "y_max"
1221 * - In 3D: "x_min", "x_max", "y_min", "y_max", "z_min", "z_max"
1222 */
1223 std::array<std::string, 2 * dim>
1225 {
1226 if constexpr (dim == 2)
1227 return {{"x_min", "x_max", "y_min", "y_max"}};
1228 else // dim == 3
1229 return {{"x_min", "x_max", "y_min", "y_max", "z_min", "z_max"}};
1230 }
1231 };
1232
1233 /**
1234 * @brief Identifies and returns bounding coordinates of a given isocontour by
1235 * scanning through quadrature points on the isocontour.
1236 *
1237 * @tparam dim An integer that denotes the dimension of the space in which
1238 * the problem is solved.
1239 * @tparam VectorType The vector type of the solution vector.
1240 *
1241 * @param[in] dof_handler DofHandler associated to the triangulation where
1242 * the isocontour lies.
1243 * @param[in] solution_vector Solution vector field.
1244 * @param[in] isovalue Isovalue corresponding to the isocontour of interest.
1245 *
1246 * @return Struct with the bounding isocontour's bounding values.
1247 */
1248 template <int dim, typename VectorType>
1249 IsocontourBoundingValues<dim>
1250 compute_isocontour_bounding_values(const DoFHandler<dim> &dof_handler,
1251 const VectorType &solution_vector,
1252 const double isovalue);
1253
1254 /**
1255 * @brief Identifies the bounding values of requested isocontours using
1256 * InterfaceTools::compute_isocontour_bounding_values.
1257 *
1258 * @tparam dim An integer that denotes the dimension of the space in which
1259 * the problem is solved.
1260 * @tparam VectorType The vector type of the solution vector.
1261 *
1262 * @param[in] variable Variable of the isocontour.
1263 * @param[in] ids_and_isocontours_per_variable Map of isocontours with their
1264 * IDs sorted with their variable as a key.
1265 * @param[in] dof_handler DofHandler associated to the triangulation where
1266 * the isocontour lies.
1267 * @param[in] solution_vector Solution vector field.
1268 * @param[in] current_time Current simulation time.
1269 * @param[in] verbosity Verbosity level for console output.
1270 * @param[in] pcout Parallel conditional output stream used to print
1271 * information on console.
1272 * @param[in,out] isocontour_bounding_values_tables Tables to be filled with
1273 * isocontour bounding values of the current time.
1274 */
1275 template <int dim, typename VectorType>
1276 void
1278 const Variable &variable,
1279 const std::multimap<Variable,
1280 std::pair<unsigned int,
1282 dim>::IsocontourBoundingBoxes::Isocontour>>
1283 &ids_and_isocontours_per_variable,
1284 const DoFHandler<dim> &dof_handler,
1285 const VectorType &solution_vector,
1286 const double current_time,
1287 const Parameters::Verbosity &verbosity,
1288 const ConditionalOStream &pcout,
1289 std::vector<TableHandler> &isocontour_bounding_values_tables);
1290
1291 /**
1292 * @brief Writes the bounding values tables of the specified isocontours in
1293 * their respective output files.
1294 *
1295 * @param[in] mpi_communicator MPI communicator.
1296 * @param[in] output_folder Output folder where the output files are saved.
1297 * @param[in] variable Variable of the isocontour.
1298 * @param[in] ids_and_isocontours_per_variable Map of isocontours with their
1299 * IDs sorted with their variable as a key.
1300 * @param[in] isocontour_bounding_values_tables Tables with isocontour
1301 * bounding values.
1302 */
1303 template <int dim>
1304 void
1306 const MPI_Comm &mpi_communicator,
1307 const std::string &output_folder,
1308 const Variable &variable,
1309 const std::multimap<Variable,
1310 std::pair<unsigned int,
1312 dim>::IsocontourBoundingBoxes::Isocontour>>
1313 &ids_and_isocontours_per_variable,
1314 const std::vector<TableHandler> &isocontour_bounding_values_tables);
1315
1316} // namespace InterfaceTools
1317
1318#endif
VectorType cell_dof_values
Value of the level-set field at the DoFs of the cell.
FEType fe
Finite element discretizing the field of interest.
void set_active_cell(const VectorType &in_local_dof_values)
Set the cell that the function should be evaluated on.
CellWiseFunction(const unsigned int p_fe_degree)
Constructor.
double value(const Point< dim > &point, const unsigned int component=0) const override
Return the value of the function at the given point in the reference cell.
SymmetricTensor< 2, dim > hessian(const Point< dim > &point, const unsigned int component=0) const override
Return the function Hessian of the specified component at the given point in the reference cell.
Tensor< 1, dim > gradient(const Point< dim > &point, const unsigned int component=0) const override
Return the function gradient of the specified component at the given point in the reference cell.
unsigned int n_cell_wise_dofs
Number of DoFs per element.
std::vector< DataOutBase::Patch< 0, dim > > patches
InterfaceReconstructionDataOut()=default
Default constructor.
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.
std::vector< std::string > get_dataset_names() const override
Implementation of the corresponding function of the base class.
const std::vector< DataOutBase::Patch< 0, dim > > & get_patches() const override
Implementation of the corresponding function of the base class.
std::vector< std::string > dataset_names
A list of field names for all data components stored in patches.
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).
std::map< unsigned int, std::vector< unsigned int > > face_opposite_dofs_map
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
void compute_numerical_jacobian_stencil(const Point< dim > x_ref, const unsigned int local_face_id, const double perturbation, std::vector< Point< dim > > &stencil)
Compute the stencil for the numerical jacobian of the distance minimization problem in the face where...
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.
std::map< unsigned int, std::vector< unsigned int > > face_dofs_map
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.
SignedDistanceSolver(const std::shared_ptr< parallel::DistributedTriangulationBase< dim > > &background_triangulation, std::shared_ptr< FiniteElement< dim > > background_fe, const double p_max_distance, const double p_iso_level, const double p_scaling, const Parameters::Verbosity p_verbosity)
Base constructor.
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.
void set_face_dofs_map()
Set the map of local id of the face DoFs (works for quad only).
LAPACKFullMatrix< double > H_x_transformation_jacobian
void get_dof_opposite_faces(unsigned int local_dof_id, std::vector< unsigned int > &local_opposite_faces)
Return the local id of the opposite faces to the given local Dof (works for quad only).
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...
LAPACKFullMatrix< double > hessian_matrix
void set_face_opposite_dofs_map()
Set the map of local id of the opposite DoFs to the given face (works for quad only).
The PVDHandler class manages the storage of the information required to write pvd file....
Definition pvd_handler.h:17
Postprocessing - Defines the parameters for the post-processing. In Lethe, post-processing implies th...
Variable
Solution fields of the different physics that are used as an indicator for multiple purposes (e....
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.
BoundingCoordinates
Named indices used to access the bounding coordinates of an isocontour.
@ 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....
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.
dealii::Vector< double > initialize_bounding_values()
Initializes the vector used to store the bounding values of isocontours.
std::array< std::string, 2 *dim > initialize_bounding_coordinates_names_array()
Initializes the array of coordinate boundary name strings for the isocontour bounding box.
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType
Definition vector.h:17