SemiDiscreteOT 1.0
Semi-Discrete Optimal Transport Library
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SoftmaxRefinement< dim, spacedim > Class Template Reference

A class for refining the optimal transport potential using a softmax operation. More...

#include <SoftmaxRefinement.h>

Classes

struct  CopyData
 A struct to hold copy data for parallel assembly. More...
 
struct  ScratchData
 A struct to hold scratch data for parallel assembly. More...
 

Public Member Functions

void set_distance_function (const std::function< double(const Point< spacedim > &, const Point< spacedim > &)> &dist)
 Sets the distance function to be used.
 
 SoftmaxRefinement (MPI_Comm mpi_comm, const DoFHandler< dim, spacedim > &dof_handler, const Mapping< dim, spacedim > &mapping, const FiniteElement< dim, spacedim > &fe, const LinearAlgebra::distributed::Vector< double > &source_density, unsigned int quadrature_order, double distance_threshold, bool use_log_sum_exp_trick=true)
 Constructor for the SoftmaxRefinement class.
 
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.
 

Private Types

using IndexedPoint = std::pair< Point< spacedim >, std::size_t >
 
using RTreeParams = boost::geometry::index::rstar< 8 >
 
using RTree = boost::geometry::index::rtree< IndexedPoint, RTreeParams >
 

Private Member Functions

void setup_rtree ()
 Sets up the R-tree.
 
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 local_assemble (const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell, ScratchData &scratch_data, CopyData &copy_data)
 Assembles the local contributions to the refined potential.
 
bool is_simplex_element () const
 Checks if the finite element is a simplex element.
 

Private Attributes

MPI_Comm mpi_communicator
 The MPI communicator.
 
const unsigned int n_mpi_processes
 The number of MPI processes.
 
const unsigned int this_mpi_process
 The rank of the current MPI process.
 
ConditionalOStream pcout
 A conditional output stream for parallel printing.
 
std::function< double(const Point< spacedim > &, const Point< spacedim > &)> distance_function
 The distance function.
 
const DoFHandler< dim, spacedim > & dof_handler
 The DoF handler for the source mesh.
 
const Mapping< dim, spacedim > & mapping
 The mapping for the source mesh.
 
const FiniteElement< dim, spacedim > & fe
 The finite element for the source mesh.
 
const LinearAlgebra::distributed::Vector< double > & source_density
 The density of the source measure.
 
const unsigned int quadrature_order
 The order of the quadrature rule to use for integration.
 
RTree target_points_rtree
 An R-tree for fast spatial queries on the target points.
 
double current_lambda {0.0}
 The current regularization parameter.
 
const double current_distance_threshold
 The current distance threshold.
 
const bool use_log_sum_exp_trick
 Whether to use the log-sum-exp trick.
 
const std::vector< Point< spacedim > > * current_target_points_fine {nullptr}
 The current fine target points.
 
const Vector< double > * current_target_density_fine {nullptr}
 The current fine target density.
 
const std::vector< Point< spacedim > > * current_target_points_coarse {nullptr}
 The current coarse target points.
 
const Vector< double > * current_target_density_coarse {nullptr}
 The current coarse target density.
 
const Vector< double > * current_potential_coarse {nullptr}
 The current coarse potential.
 
const std::vector< std::vector< std::vector< size_t > > > * current_child_indices {nullptr}
 The current child indices.
 
int current_level {0}
 The current level.
 

Detailed Description

template<int dim, int spacedim = dim>
class SoftmaxRefinement< dim, spacedim >

A class for refining the optimal transport potential using a softmax operation.

This class implements a method for refining the optimal transport potential from a coarser level to a finer level in a multilevel scheme. It uses a softmax-like operation to distribute the potential from the coarse points to their children in the finer level.

Template Parameters
dimThe dimension of the source mesh.
spacedimThe dimension of the space the mesh is embedded in.

Definition at line 43 of file SoftmaxRefinement.h.

Member Typedef Documentation

◆ IndexedPoint

template<int dim, int spacedim = dim>
using SoftmaxRefinement< dim, spacedim >::IndexedPoint = std::pair<Point<spacedim>, std::size_t>
private

Definition at line 147 of file SoftmaxRefinement.h.

◆ RTreeParams

template<int dim, int spacedim = dim>
using SoftmaxRefinement< dim, spacedim >::RTreeParams = boost::geometry::index::rstar<8>
private

Definition at line 148 of file SoftmaxRefinement.h.

◆ RTree

template<int dim, int spacedim = dim>
using SoftmaxRefinement< dim, spacedim >::RTree = boost::geometry::index::rtree<IndexedPoint, RTreeParams>
private

Definition at line 149 of file SoftmaxRefinement.h.

Constructor & Destructor Documentation

◆ SoftmaxRefinement()

template<int dim, int spacedim>
SoftmaxRefinement< dim, spacedim >::SoftmaxRefinement ( MPI_Comm  mpi_comm,
const DoFHandler< dim, spacedim > &  dof_handler,
const Mapping< dim, spacedim > &  mapping,
const FiniteElement< dim, spacedim > &  fe,
const LinearAlgebra::distributed::Vector< double > &  source_density,
unsigned int  quadrature_order,
double  distance_threshold,
bool  use_log_sum_exp_trick = true 
)

Constructor for the SoftmaxRefinement class.

Parameters
mpi_commThe MPI communicator.
dof_handlerThe DoF handler for the source mesh.
mappingThe mapping for the source mesh.
feThe finite element for the source mesh.
source_densityThe density of the source measure.
quadrature_orderThe order of the quadrature rule to use for integration.
distance_thresholdThe distance threshold for the R-tree search.
use_log_sum_exp_trickWhether to use the log-sum-exp trick for numerical stability.

Definition at line 5 of file SoftmaxRefinement.cc.

Member Function Documentation

◆ set_distance_function()

template<int dim, int spacedim = dim>
void SoftmaxRefinement< dim, spacedim >::set_distance_function ( const std::function< double(const Point< spacedim > &, const Point< spacedim > &)> &  dist)
inline

Sets the distance function to be used.

Parameters
distThe distance function.

Definition at line 49 of file SoftmaxRefinement.h.

◆ compute_refinement()

template<int dim, int spacedim>
Vector< double > SoftmaxRefinement< dim, spacedim >::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.

Parameters
target_points_fineThe points of the fine target measure.
target_density_fineThe weights of the fine target measure.
target_points_coarseThe points of the coarse target measure.
target_density_coarseThe weights of the coarse target measure.
potential_coarseThe potential at the coarse level.
regularization_paramThe regularization parameter.
current_levelThe current level in the multilevel hierarchy.
child_indicesThe indices of the children of each coarse point.
Returns
The refined potential.

Definition at line 201 of file SoftmaxRefinement.cc.

Here is the caller graph for this function:

◆ setup_rtree()

template<int dim, int spacedim>
void SoftmaxRefinement< dim, spacedim >::setup_rtree ( )
private

Sets up the R-tree.

Definition at line 30 of file SoftmaxRefinement.cc.

◆ find_nearest_target_points()

template<int dim, int spacedim>
std::vector< std::size_t > SoftmaxRefinement< dim, spacedim >::find_nearest_target_points ( const Point< spacedim > &  query_point) const
private

Finds the nearest target points to a query point.

Parameters
query_pointThe query point.
Returns
A vector of indices of the nearest target points.

Definition at line 44 of file SoftmaxRefinement.cc.

◆ local_assemble()

template<int dim, int spacedim>
void SoftmaxRefinement< dim, spacedim >::local_assemble ( const typename DoFHandler< dim, spacedim >::active_cell_iterator &  cell,
ScratchData scratch_data,
CopyData copy_data 
)
private

Assembles the local contributions to the refined potential.

Parameters
cellThe current cell.
scratch_dataThe scratch data.
copy_dataThe copy data.

Definition at line 62 of file SoftmaxRefinement.cc.

◆ is_simplex_element()

template<int dim, int spacedim = dim>
bool SoftmaxRefinement< dim, spacedim >::is_simplex_element ( ) const
inlineprivate

Checks if the finite element is a simplex element.

Definition at line 189 of file SoftmaxRefinement.h.

Member Data Documentation

◆ mpi_communicator

template<int dim, int spacedim = dim>
MPI_Comm SoftmaxRefinement< dim, spacedim >::mpi_communicator
private

The MPI communicator.

Definition at line 131 of file SoftmaxRefinement.h.

◆ n_mpi_processes

template<int dim, int spacedim = dim>
const unsigned int SoftmaxRefinement< dim, spacedim >::n_mpi_processes
private

The number of MPI processes.

Definition at line 132 of file SoftmaxRefinement.h.

◆ this_mpi_process

template<int dim, int spacedim = dim>
const unsigned int SoftmaxRefinement< dim, spacedim >::this_mpi_process
private

The rank of the current MPI process.

Definition at line 133 of file SoftmaxRefinement.h.

◆ pcout

template<int dim, int spacedim = dim>
ConditionalOStream SoftmaxRefinement< dim, spacedim >::pcout
private

A conditional output stream for parallel printing.

Definition at line 134 of file SoftmaxRefinement.h.

◆ distance_function

template<int dim, int spacedim = dim>
std::function<double(const Point<spacedim>&, const Point<spacedim>&)> SoftmaxRefinement< dim, spacedim >::distance_function
private

The distance function.

Definition at line 137 of file SoftmaxRefinement.h.

◆ dof_handler

template<int dim, int spacedim = dim>
const DoFHandler<dim, spacedim>& SoftmaxRefinement< dim, spacedim >::dof_handler
private

The DoF handler for the source mesh.

Definition at line 140 of file SoftmaxRefinement.h.

◆ mapping

template<int dim, int spacedim = dim>
const Mapping<dim, spacedim>& SoftmaxRefinement< dim, spacedim >::mapping
private

The mapping for the source mesh.

Definition at line 141 of file SoftmaxRefinement.h.

◆ fe

template<int dim, int spacedim = dim>
const FiniteElement<dim, spacedim>& SoftmaxRefinement< dim, spacedim >::fe
private

The finite element for the source mesh.

Definition at line 142 of file SoftmaxRefinement.h.

◆ source_density

template<int dim, int spacedim = dim>
const LinearAlgebra::distributed::Vector<double>& SoftmaxRefinement< dim, spacedim >::source_density
private

The density of the source measure.

Definition at line 143 of file SoftmaxRefinement.h.

◆ quadrature_order

template<int dim, int spacedim = dim>
const unsigned int SoftmaxRefinement< dim, spacedim >::quadrature_order
private

The order of the quadrature rule to use for integration.

Definition at line 144 of file SoftmaxRefinement.h.

◆ target_points_rtree

template<int dim, int spacedim = dim>
RTree SoftmaxRefinement< dim, spacedim >::target_points_rtree
private

An R-tree for fast spatial queries on the target points.

Definition at line 150 of file SoftmaxRefinement.h.

◆ current_lambda

template<int dim, int spacedim = dim>
double SoftmaxRefinement< dim, spacedim >::current_lambda {0.0}
private

The current regularization parameter.

Definition at line 153 of file SoftmaxRefinement.h.

◆ current_distance_threshold

template<int dim, int spacedim = dim>
const double SoftmaxRefinement< dim, spacedim >::current_distance_threshold
private

The current distance threshold.

Definition at line 154 of file SoftmaxRefinement.h.

◆ use_log_sum_exp_trick

template<int dim, int spacedim = dim>
const bool SoftmaxRefinement< dim, spacedim >::use_log_sum_exp_trick
private

Whether to use the log-sum-exp trick.

Definition at line 155 of file SoftmaxRefinement.h.

◆ current_target_points_fine

template<int dim, int spacedim = dim>
const std::vector<Point<spacedim> >* SoftmaxRefinement< dim, spacedim >::current_target_points_fine {nullptr}
private

The current fine target points.

Definition at line 156 of file SoftmaxRefinement.h.

◆ current_target_density_fine

template<int dim, int spacedim = dim>
const Vector<double>* SoftmaxRefinement< dim, spacedim >::current_target_density_fine {nullptr}
private

The current fine target density.

Definition at line 157 of file SoftmaxRefinement.h.

◆ current_target_points_coarse

template<int dim, int spacedim = dim>
const std::vector<Point<spacedim> >* SoftmaxRefinement< dim, spacedim >::current_target_points_coarse {nullptr}
private

The current coarse target points.

Definition at line 158 of file SoftmaxRefinement.h.

◆ current_target_density_coarse

template<int dim, int spacedim = dim>
const Vector<double>* SoftmaxRefinement< dim, spacedim >::current_target_density_coarse {nullptr}
private

The current coarse target density.

Definition at line 159 of file SoftmaxRefinement.h.

◆ current_potential_coarse

template<int dim, int spacedim = dim>
const Vector<double>* SoftmaxRefinement< dim, spacedim >::current_potential_coarse {nullptr}
private

The current coarse potential.

Definition at line 160 of file SoftmaxRefinement.h.

◆ current_child_indices

template<int dim, int spacedim = dim>
const std::vector<std::vector<std::vector<size_t> > >* SoftmaxRefinement< dim, spacedim >::current_child_indices {nullptr}
private

The current child indices.

Definition at line 161 of file SoftmaxRefinement.h.

◆ current_level

template<int dim, int spacedim = dim>
int SoftmaxRefinement< dim, spacedim >::current_level {0}
private

The current level.

Definition at line 162 of file SoftmaxRefinement.h.


The documentation for this class was generated from the following files: