1#ifndef SOFTMAX_REFINEMENT_H
2#define SOFTMAX_REFINEMENT_H
4#include <boost/geometry.hpp>
5#include <boost/geometry/index/rtree.hpp>
10#include <deal.II/base/conditional_ostream.h>
11#include <deal.II/lac/vector.h>
12#include <deal.II/lac/la_parallel_vector.h>
13#include <deal.II/base/point.h>
14#include <deal.II/fe/fe_values.h>
15#include <deal.II/fe/fe_simplex_p.h>
16#include <deal.II/fe/fe_q.h>
17#include <deal.II/dofs/dof_handler.h>
18#include <deal.II/base/work_stream.h>
19#include <deal.II/base/exceptions.h>
20#include <deal.II/dofs/dof_tools.h>
21#include <deal.II/grid/filtered_iterator.h>
22#include <deal.II/numerics/rtree.h>
23#include <deal.II/base/mpi.h>
24#include <deal.II/base/utilities.h>
25#include <deal.II/base/multithread_info.h>
29using namespace dealii;
42template <
int dim,
int spacedim = dim>
50 const std::function<
double(
const Point<spacedim>&,
const Point<spacedim>&)>& dist)
60 const Mapping<dim, spacedim> &
mapping,
61 const Quadrature<dim> &quadrature)
63 update_values | update_quadrature_points | update_JxW_values),
70 update_values | update_quadrature_points | update_JxW_values),
100 const Mapping<dim, spacedim>&
mapping,
101 const FiniteElement<dim, spacedim>&
fe,
104 double distance_threshold,
120 const std::vector<Point<spacedim>>& target_points_fine,
121 const Vector<double>& target_density_fine,
122 const std::vector<Point<spacedim>>& target_points_coarse,
123 const Vector<double>& target_density_coarse,
124 const Vector<double>& potential_coarse,
125 double regularization_param,
127 const std::vector<std::vector<std::vector<size_t>>>& child_indices);
142 const FiniteElement<dim, spacedim>&
fe;
149 using RTree = boost::geometry::index::rtree<IndexedPoint, RTreeParams>;
182 void local_assemble(
const typename DoFHandler<dim, spacedim>::active_cell_iterator &cell,
183 ScratchData &scratch_data,
184 CopyData ©_data);
192 const auto* simplex_fe =
dynamic_cast<const FE_SimplexP<dim, spacedim>*
>(&
fe);
193 return (simplex_fe !=
nullptr);
A class for refining the optimal transport potential using a softmax operation.
boost::geometry::index::rstar< 8 > RTreeParams
const unsigned int quadrature_order
The order of the quadrature rule to use for integration.
std::vector< std::size_t > find_nearest_target_points(const Point< spacedim > &query_point) const
Finds the nearest target points to a query point.
void setup_rtree()
Sets up the R-tree.
void set_distance_function(const std::function< double(const Point< spacedim > &, const Point< spacedim > &)> &dist)
Sets the distance function to be used.
const Vector< double > * current_target_density_coarse
The current coarse target density.
Vector< double > compute_refinement(const std::vector< Point< spacedim > > &target_points_fine, const Vector< double > &target_density_fine, const std::vector< Point< spacedim > > &target_points_coarse, const Vector< double > &target_density_coarse, const Vector< double > &potential_coarse, double regularization_param, int current_level, const std::vector< std::vector< std::vector< size_t > > > &child_indices)
Computes the refined potential.
const unsigned int n_mpi_processes
The number of MPI processes.
MPI_Comm mpi_communicator
The MPI communicator.
const DoFHandler< dim, spacedim > & dof_handler
The DoF handler for the source mesh.
const std::vector< std::vector< std::vector< size_t > > > * current_child_indices
The current child indices.
const Mapping< dim, spacedim > & mapping
The mapping for the source mesh.
ConditionalOStream pcout
A conditional output stream for parallel printing.
const FiniteElement< dim, spacedim > & fe
The finite element for the source mesh.
const std::vector< Point< spacedim > > * current_target_points_fine
The current fine target points.
void local_assemble(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, ScratchData &scratch_data, CopyData ©_data)
Assembles the local contributions to the refined potential.
RTree target_points_rtree
An R-tree for fast spatial queries on the target points.
std::function< double(const Point< spacedim > &, const Point< spacedim > &)> distance_function
The distance function.
const LinearAlgebra::distributed::Vector< double > & source_density
The density of the source measure.
boost::geometry::index::rtree< IndexedPoint, RTreeParams > RTree
const unsigned int this_mpi_process
The rank of the current MPI process.
const std::vector< Point< spacedim > > * current_target_points_coarse
The current coarse target points.
std::pair< Point< spacedim >, std::size_t > IndexedPoint
const double current_distance_threshold
The current distance threshold.
const Vector< double > * current_target_density_fine
The current fine target density.
const bool use_log_sum_exp_trick
Whether to use the log-sum-exp trick.
double current_lambda
The current regularization parameter.
const Vector< double > * current_potential_coarse
The current coarse potential.
bool is_simplex_element() const
Checks if the finite element is a simplex element.
int current_level
The current level.
A struct to hold copy data for parallel assembly.
CopyData(const unsigned int n_target_points)
Vector< double > potential_values
The potential values at the target points.
A struct to hold scratch data for parallel assembly.
ScratchData(const ScratchData &scratch_data)
FEValues< dim, spacedim > fe_values
FEValues object for the current cell.
ScratchData(const FiniteElement< dim, spacedim > &fe, const Mapping< dim, spacedim > &mapping, const Quadrature< dim > &quadrature)
std::vector< double > density_values
The density values at the quadrature points of the current cell.