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

A class for performing Lloyd's algorithm for semi-discrete optimal transport. More...

#include <Lloyd.h>

Inheritance diagram for Lloyd< dim, spacedim >:
Inheritance graph
[legend]
Collaboration diagram for Lloyd< dim, spacedim >:
Collaboration graph
[legend]

Public Member Functions

 Lloyd (const MPI_Comm &mpi_communicator)
 Constructor for the Lloyd class.
 
void run ()
 Runs the Lloyd's algorithm.
 
void run_lloyd (const double absolute_threshold=1e-8, const unsigned int max_iterations=100)
 Runs the Lloyd's algorithm with the given parameters.
 
void run_sot_iteration (const unsigned int n_iter)
 Runs a single iteration of the semi-discrete optimal transport solver.
 
void run_centroid_iteration (const unsigned int n_iter)
 Runs a single iteration of the centroid computation.
 
void compute_step_norm (const std::vector< Point< spacedim > > &barycenters_next, const std::vector< Point< spacedim > > &barycenters_prev, double &l2_norm)
 Computes the L2 norm of the step.
 
- Public Member Functions inherited from SemiDiscreteOT< dim, spacedim >
 SemiDiscreteOT (const MPI_Comm &mpi_communicator)
 Constructor for the SemiDiscreteOT class.
 
void run ()
 Runs the solver with the current configuration.
 
void configure (std::function< void(SotParameterManager &)> config_func)
 Configure the solver parameters programmatically.
 
void setup_source_measure (Triangulation< dim, spacedim > &tria, const DoFHandler< dim, spacedim > &dh, const Vector< double > &density, const std::string &name="source")
 Setup source measure from standard deal.II objects (simplified API for tutorials)
 
void setup_target_measure (const std::vector< Point< spacedim > > &points, const Vector< double > &weights)
 Set up the target measure from a discrete set of points and weights.
 
void prepare_multilevel_hierarchies ()
 Pre-computes the multilevel hierarchies for source and/or target. This must be called after setting up the base measures and before calling solve() if multilevel computation is desired.
 
void prepare_source_multilevel ()
 Pre-computes the multilevel hierarchy for the source.
 
void prepare_target_multilevel ()
 Pre-computes the multilevel hierarchy for the target.
 
SotSolver< dim, spacedim > * get_solver ()
 Get a pointer to the solver object.
 
const SotParameterManager::SolverParametersget_solver_params () const
 Get a reference to the solver parameters.
 
const Vector< double > & get_coarsest_potential () const
 Get the coarsest potential from the multilevel solve.
 
Vector< double > solve (const Vector< double > &initial_potential=Vector< double >())
 Run the optimal transport computation based on the current configuration. This method handles single-level, multilevel, and epsilon scaling automatically.
 
void save_discrete_measures ()
 Saves the discrete source and target measures to files.
 
void set_distance_function (const std::function< double(const Point< spacedim > &, const Point< spacedim > &)> &dist)
 Sets the distance function to be used by the solver.
 

Public Attributes

LloydParameterManager param_manager_lloyd
 The parameter manager for the Lloyd's algorithm.
 
std::vector< Point< spacedim > > barycenters
 The barycenters of the power cells.
 
std::vector< Point< spacedim > > barycenters_prev
 The barycenters of the power cells in the previous iteration.
 
Vector< double > potential
 The optimal transport potential.
 
- Public Attributes inherited from SemiDiscreteOT< dim, spacedim >
ConditionalOStream pcout
 A conditional output stream for parallel printing.
 

Additional Inherited Members

- Protected Member Functions inherited from SemiDiscreteOT< dim, spacedim >
void save_results (const Vector< double > &potentials, const std::string &filename, bool add_epsilon_prefix=true)
 Saves the results of the computation.
 
void normalize_density (LinearAlgebra::distributed::Vector< double > &density)
 Normalizes the density vector.
 
- Protected Attributes inherited from SemiDiscreteOT< dim, spacedim >
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.
 
std::unique_ptr< SotSolver< dim, spacedim > > sot_solver
 The semi-discrete optimal transport solver.
 
SotParameterManager param_manager
 The parameter manager.
 
SotParameterManager::MeshParameterssource_params
 A reference to the source mesh parameters.
 
SotParameterManager::MeshParameterstarget_params
 A reference to the target mesh parameters.
 
SotParameterManager::SolverParameterssolver_params
 A reference to the solver parameters.
 
SotParameterManager::MultilevelParametersmultilevel_params
 A reference to the multilevel parameters.
 
SotParameterManager::PowerDiagramParameterspower_diagram_params
 A reference to the power diagram parameters.
 
SotParameterManager::TransportMapParameterstransport_map_params
 A reference to the transport map parameters.
 
std::string & selected_task
 A reference to the selected task.
 
std::string & io_coding
 A reference to the I/O coding.
 
std::unique_ptr< DoFHandler< dim, spacedim > > initial_fine_dof_handler
 The initial fine DoF handler.
 
std::unique_ptr< Vector< double > > initial_fine_density
 The initial fine density.
 
bool is_setup_programmatically_ = false
 A flag to indicate if the setup is done programmatically.
 
std::string source_mesh_name = "source"
 The name of the source mesh.
 
parallel::fullydistributed::Triangulation< dim, spacedim > source_mesh
 The source mesh.
 
Triangulation< dim, spacedim > target_mesh
 The target mesh.
 
DoFHandler< dim, spacedim > dof_handler_source
 The DoF handler for the source mesh.
 
DoFHandler< dim, spacedim > dof_handler_target
 The DoF handler for the target mesh.
 
std::unique_ptr< VTKHandler< dim, spacedim > > source_vtk_handler
 The VTK handler for the source mesh.
 
DoFHandler< dim, spacedim > vtk_dof_handler_source
 The DoF handler for the source VTK mesh.
 
Vector< double > vtk_field_source
 The source field from the VTK file.
 
Triangulation< dim, spacedim > vtk_tria_source
 The triangulation from the source VTK file.
 
std::unique_ptr< FiniteElement< dim, spacedim > > fe_system
 The finite element system.
 
std::unique_ptr< Mapping< dim, spacedim > > mapping
 The mapping.
 
std::unique_ptr< FiniteElement< dim, spacedim > > fe_system_target
 The target finite element system.
 
std::unique_ptr< Mapping< dim, spacedim > > mapping_target
 The target mapping.
 
LinearAlgebra::distributed::Vector< double > source_density
 The source density.
 
Vector< double > target_density
 The target density.
 
std::vector< Point< spacedim > > target_points
 The target points.
 
std::vector< Point< spacedim > > source_points
 The source points.
 
std::unique_ptr< MeshManager< dim, spacedim > > mesh_manager
 The mesh manager.
 
std::unique_ptr< EpsilonScalingHandlerepsilon_scaling_handler
 The epsilon scaling handler.
 

Detailed Description

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

A class for performing Lloyd's algorithm for semi-discrete optimal transport.

This class implements Lloyd's algorithm, which is an iterative method for finding the optimal locations of the target points in a semi-discrete optimal transport problem. It alternates between solving the dual problem for the optimal transport potential and moving the target points to the centroids of their power cells.

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

Definition at line 23 of file Lloyd.h.

Constructor & Destructor Documentation

◆ Lloyd()

template<int dim, int spacedim>
Lloyd< dim, spacedim >::Lloyd ( const MPI_Comm &  mpi_communicator)

Constructor for the Lloyd class.

Parameters
mpi_communicatorThe MPI communicator.

Definition at line 8 of file Lloyd.cc.

Member Function Documentation

◆ run()

template<int dim, int spacedim>
void Lloyd< dim, spacedim >::run ( )

Runs the Lloyd's algorithm.

Definition at line 285 of file Lloyd.cc.

◆ run_lloyd()

template<int dim, int spacedim>
void Lloyd< dim, spacedim >::run_lloyd ( const double  absolute_threshold = 1e-8,
const unsigned int  max_iterations = 100 
)

Runs the Lloyd's algorithm with the given parameters.

Parameters
absolute_thresholdThe absolute threshold for the step norm.
max_iterationsThe maximum number of iterations.

Definition at line 14 of file Lloyd.cc.

◆ run_sot_iteration()

template<int dim, int spacedim>
void Lloyd< dim, spacedim >::run_sot_iteration ( const unsigned int  n_iter)

Runs a single iteration of the semi-discrete optimal transport solver.

Parameters
n_iterThe current iteration number.

Definition at line 180 of file Lloyd.cc.

Here is the call graph for this function:

◆ run_centroid_iteration()

template<int dim, int spacedim>
void Lloyd< dim, spacedim >::run_centroid_iteration ( const unsigned int  n_iter)

Runs a single iteration of the centroid computation.

Parameters
n_iterThe current iteration number.

Definition at line 83 of file Lloyd.cc.

◆ compute_step_norm()

template<int dim, int spacedim>
void Lloyd< dim, spacedim >::compute_step_norm ( const std::vector< Point< spacedim > > &  barycenters_next,
const std::vector< Point< spacedim > > &  barycenters_prev,
double &  l2_norm 
)

Computes the L2 norm of the step.

Parameters
barycenters_nextThe barycenters of the next iteration.
barycenters_prevThe barycenters of the previous iteration.
l2_normThe L2 norm of the step.

Definition at line 64 of file Lloyd.cc.

Member Data Documentation

◆ param_manager_lloyd

template<int dim, int spacedim = dim>
LloydParameterManager Lloyd< dim, spacedim >::param_manager_lloyd

The parameter manager for the Lloyd's algorithm.

Definition at line 64 of file Lloyd.h.

◆ barycenters

template<int dim, int spacedim = dim>
std::vector<Point<spacedim> > Lloyd< dim, spacedim >::barycenters

The barycenters of the power cells.

Definition at line 65 of file Lloyd.h.

◆ barycenters_prev

template<int dim, int spacedim = dim>
std::vector<Point<spacedim> > Lloyd< dim, spacedim >::barycenters_prev

The barycenters of the power cells in the previous iteration.

Definition at line 66 of file Lloyd.h.

◆ potential

template<int dim, int spacedim = dim>
Vector<double> Lloyd< dim, spacedim >::potential

The optimal transport potential.

Definition at line 67 of file Lloyd.h.


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