include/meltpooldg/level_set/nearest_point.hpp Source File

Developer Documentation: include/meltpooldg/level_set/nearest_point.hpp Source File
Developer Documentation
nearest_point.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <deal.II/base/array_view.h>
4#include <deal.II/base/conditional_ostream.h>
5#include <deal.II/base/exceptions.h>
6#include <deal.II/base/mpi.h>
7#include <deal.II/base/mpi.templates.h>
8#include <deal.II/base/mpi_noncontiguous_partitioner.h>
9#include <deal.II/base/mpi_remote_point_evaluation.h>
10#include <deal.II/base/point.h>
11#include <deal.II/base/timer.h>
12#include <deal.II/base/types.h>
13
14#include <deal.II/dofs/dof_handler.h>
15
16#include <deal.II/fe/mapping.h>
17
18#include <deal.II/lac/la_parallel_block_vector.h>
19#include <deal.II/lac/la_parallel_vector.h>
20
21#include <deal.II/matrix_free/fe_point_evaluation.h>
22
23#include <deal.II/numerics/rtree.h>
24#include <deal.II/numerics/vector_tools_evaluate.h>
25
28
29#include <boost/geometry/index/rtree.hpp>
30
31#include <algorithm>
32#include <array>
33#include <cmath>
34#include <fstream>
35#include <functional>
36#include <optional>
37#include <string>
38#include <vector>
39
40
42{
65 template <int dim, typename number>
67 {
68 using VectorType = dealii::LinearAlgebra::distributed::Vector<number>;
69 using BlockVectorType = dealii::LinearAlgebra::distributed::BlockVector<number>;
70
71 public:
85 NearestPoint(const dealii::Mapping<dim> &mapping,
86 const dealii::DoFHandler<dim> &dof_handler_signed_distance,
89 dealii::Utilities::MPI::RemotePointEvaluation<dim, dim> &remote_point_evaluation,
90 const NearestPointData<number> &nearest_point_data,
91 std::optional<std::reference_wrapper<dealii::TimerOutput>> timer_output = {});
92
107 void
108 reinit(const dealii::DoFHandler<dim> *dof_handler_src_in,
109 const dealii::DoFHandler<dim> *dof_handler_dst_in = nullptr);
110
127 template <int n_components = 1>
128 void
130 const VectorType &solution_in,
131 const bool zero_out = true,
132 const std::function<number(const number)> &operation = {}) const;
133
134
146 const std::vector<dealii::Point<dim>> &
147 get_projected_points() const;
148
159 const std::vector<std::vector<dealii::types::global_dof_index>> &
161
170 void
171 write_to_file(const std::string filename_without_ending) const;
172
174 mutable std::vector<dealii::Point<dim>> points_not_found;
175
176 private:
178 const dealii::Mapping<dim> &mapping;
179
181 const dealii::DoFHandler<dim> &dof_handler_ls;
182
185
189
192 const NearestPointData<number> &nearest_point_data;
193
196 dealii::Utilities::MPI::RemotePointEvaluation<dim, dim> &remote_point_evaluation;
197
198 // Tolerance to be reached for the distance of the projected points to the distance = 0
199 // isosurface
200 const number tol_distance;
201
208
211
213 const MPI_Comm mpi_comm;
214
215 dealii::ConditionalOStream pcout;
217 std::optional<std::reference_wrapper<dealii::TimerOutput>> timer_output;
218
220 const dealii::DoFHandler<dim> *dof_handler_src = nullptr;
221
224 const dealii::DoFHandler<dim> *dof_handler_dst = nullptr;
225
226 // --- Output data: projection results ---
227
229 std::vector<dealii::Point<dim>> projected_points_at_interface;
230
232 std::vector<std::vector<dealii::types::global_dof_index>> dof_indices;
233
235 std::vector<dealii::Point<dim>> stencil;
236
237 // --- Internal state ---
238
241
243 bool is_reinit_called = false;
244
248
249 // --- Internal data for fast path (ArborX-based projection) ---
250
252 dealii::Utilities::MPI::NoncontiguousPartitioner partitioner;
253
255 std::vector<dealii::types::global_dof_index> locally_owned_surface_indices;
256
259 std::vector<dealii::types::global_dof_index> ghost_surface_indices;
260
263 std::vector<std::pair<std::pair<unsigned int, unsigned int>, std::vector<dealii::Point<dim>>>>
265
280 template <int n_components = 1>
281 void
283 VectorType &solution_out,
284 const VectorType &solution_in,
285 const bool zero_out = true,
286 const std::function<number(const number)> &operation = {}) const;
287
295 void
297
308 void
309 register_dof_handlers(const dealii::DoFHandler<dim> *dof_handler_src_in,
310 const dealii::DoFHandler<dim> *dof_handler_dst_in);
311
319 void
321
329 void
331
344 bool
345 local_compute_normal_correction(std::vector<dealii::Point<dim>> &y);
346
375 bool
376 local_compute_normal_and_tangential_correction_coquerelle(std::vector<dealii::Point<dim>> &y);
377
402 bool
403 local_compute_normal_and_tangential_correction(std::vector<dealii::Point<dim>> &y);
404
409 void
411
416 void
418 };
419} // namespace MeltPoolDG::LevelSet::Tools
Compute nearest points to the isocontour of a level set function.
Definition nearest_point.hpp:67
dealii::LinearAlgebra::distributed::Vector< number > VectorType
Definition nearest_point.hpp:68
void reinit(const dealii::DoFHandler< dim > *dof_handler_src_in, const dealii::DoFHandler< dim > *dof_handler_dst_in=nullptr)
Initialize projection by computing nearest points for each DoF in the given DoFHandler.
Definition nearest_point.cpp:89
std::optional< std::reference_wrapper< dealii::TimerOutput > > timer_output
Optional scoped timer for profiling different stages of projection.
Definition nearest_point.hpp:217
void clear_cached_data()
Clear all internally cached data.
Definition nearest_point.cpp:118
bool input_vector_is_cut
Definition nearest_point.hpp:247
void extend_interface_values_nearest_point_fast(VectorType &solution_out, const VectorType &solution_in, const bool zero_out=true, const std::function< number(const number)> &operation={}) const
Populate a DoF vector with values from the interface using ArborX acceleration.
Definition nearest_point.cpp:419
const number tol_distance
Definition nearest_point.hpp:200
void register_dof_handlers(const dealii::DoFHandler< dim > *dof_handler_src_in, const dealii::DoFHandler< dim > *dof_handler_dst_in)
Register DoFHandler objects for source and destination spaces.
Definition nearest_point.cpp:134
std::vector< dealii::Point< dim > > points_not_found
List of points where the projection failed or did not converge (for debug purposes).
Definition nearest_point.hpp:174
bool local_compute_normal_and_tangential_correction(std::vector< dealii::Point< dim > > &y)
Definition nearest_point.cpp:866
void extend_interface_values(VectorType &solution_out, const VectorType &solution_in, const bool zero_out=true, const std::function< number(const number)> &operation={}) const
Populate a DoF vector with values from the interface.
Definition nearest_point.cpp:346
const VectorType & signed_distance
Level set / signed distance function used to define the interface.
Definition nearest_point.hpp:184
const number tolerance_normal_vector
Tolerance for accuracy of the normal vector, if used in projection.
Definition nearest_point.hpp:210
const dealii::DoFHandler< dim > * dof_handler_dst
Definition nearest_point.hpp:224
void write_to_file(const std::string filename_without_ending) const
Write the computed nearest points to a file.
Definition nearest_point.cpp:513
dealii::Utilities::MPI::NoncontiguousPartitioner partitioner
Noncontiguous partitioner used to communicate surface point values across MPI ranks.
Definition nearest_point.hpp:252
const std::vector< dealii::Point< dim > > & get_projected_points() const
Get the computed nearest points corresponding to the nodal locations.
Definition nearest_point.cpp:327
void collect_narrow_band_support_points()
Collect support points from the source DoFHandler near the level set interface.
Definition nearest_point.cpp:164
const MPI_Comm mpi_comm
Communicator associated with this projection process.
Definition nearest_point.hpp:213
const NearestPointData< number > & nearest_point_data
Definition nearest_point.hpp:192
std::vector< dealii::types::global_dof_index > ghost_surface_indices
Definition nearest_point.hpp:259
const BlockVectorType & normal_vector
Definition nearest_point.hpp:188
void local_compute_nearest_point_fast()
Definition nearest_point.cpp:1158
int total_points_rpe
Temporary variable used to count total projected points in RPE or partitioning.
Definition nearest_point.hpp:240
bool is_reinit_called
Tracks whether the reinit() function has been called, to prevent misuse.
Definition nearest_point.hpp:243
std::vector< dealii::types::global_dof_index > locally_owned_surface_indices
Global indices of surface/interface points owned by this MPI rank.
Definition nearest_point.hpp:255
void run_projection_algorithm()
Run the projection algorithm to determine nearest points on the interface.
Definition nearest_point.cpp:267
bool local_compute_normal_and_tangential_correction_coquerelle(std::vector< dealii::Point< dim > > &y)
Definition nearest_point.cpp:700
dealii::LinearAlgebra::distributed::BlockVector< number > BlockVectorType
Definition nearest_point.hpp:69
const std::vector< std::vector< dealii::types::global_dof_index > > & get_projected_points_dof_indices() const
Get the global DoF indices associated with each nearest point.
Definition nearest_point.cpp:336
std::vector< std::pair< std::pair< unsigned int, unsigned int >, std::vector< dealii::Point< dim > > > > surface_cells_and_unit_points
Definition nearest_point.hpp:264
const dealii::DoFHandler< dim > * dof_handler_src
Source DoFHandler: values are projected from this FE space.
Definition nearest_point.hpp:220
std::vector< dealii::Point< dim > > stencil
Coordinates (physical space) of the stencil points used as nearest point queries.
Definition nearest_point.hpp:235
std::vector< dealii::Point< dim > > projected_points_at_interface
Projected physical coordinates on the interface, corresponding to each DoF in the stencil.
Definition nearest_point.hpp:229
void local_compute_nearest_point()
Definition nearest_point.cpp:1103
dealii::ConditionalOStream pcout
Definition nearest_point.hpp:215
const number narrow_band_threshold
Definition nearest_point.hpp:207
const dealii::DoFHandler< dim > & dof_handler_ls
DoFHandler associated with the level set function (signed distance field)
Definition nearest_point.hpp:181
bool local_compute_normal_correction(std::vector< dealii::Point< dim > > &y)
Definition nearest_point.cpp:567
std::vector< std::vector< dealii::types::global_dof_index > > dof_indices
Global DoF indices (per stencil point) — maps each stencil entry to its target DoFs.
Definition nearest_point.hpp:232
dealii::Utilities::MPI::RemotePointEvaluation< dim, dim > & remote_point_evaluation
Definition nearest_point.hpp:196
const dealii::Mapping< dim > & mapping
Mapping.
Definition nearest_point.hpp:178
Definition level_set_tools.hpp:25