![]() |
SemiDiscreteOT 1.0
Semi-Discrete Optimal Transport Library
|
Main class for the semi-discrete optimal transport solver. More...
#include <SemiDiscreteOT.h>
Public Member Functions | |
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::SolverParameters & | get_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 | |
ConditionalOStream | pcout |
A conditional output stream for parallel printing. | |
Protected Member Functions | |
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 | |
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::MeshParameters & | source_params |
A reference to the source mesh parameters. | |
SotParameterManager::MeshParameters & | target_params |
A reference to the target mesh parameters. | |
SotParameterManager::SolverParameters & | solver_params |
A reference to the solver parameters. | |
SotParameterManager::MultilevelParameters & | multilevel_params |
A reference to the multilevel parameters. | |
SotParameterManager::PowerDiagramParameters & | power_diagram_params |
A reference to the power diagram parameters. | |
SotParameterManager::TransportMapParameters & | transport_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< EpsilonScalingHandler > | epsilon_scaling_handler |
The epsilon scaling handler. | |
Private Member Functions | |
void | mesh_generation () |
Generates the source and target meshes. | |
void | load_meshes () |
Loads the source and target meshes from files. | |
Vector< double > | run_sot (const Vector< double > &initial_potential=Vector< double >()) |
Run single-level SOT computation. | |
void | compute_power_diagram () |
Computes the power diagram of the target points. | |
void | compute_transport_map () |
Computes the transport map from the source to the target measure. | |
void | compute_conditional_density () |
Computes the conditional density of the source measure. | |
Vector< double > | run_multilevel (const Vector< double > &initial_potential=Vector< double >()) |
Run multilevel SOT computation (dispatcher method). | |
Vector< double > | run_combined_multilevel (const Vector< double > &initial_potential=Vector< double >()) |
Run combined source and target multilevel SOT computation. | |
Vector< double > | run_source_multilevel (const Vector< double > &initial_potential=Vector< double >()) |
Run source-only multilevel SOT computation. | |
Vector< double > | run_target_multilevel (const Vector< double > &initial_potential=Vector< double >()) |
Run target-only multilevel SOT computation. | |
void | setup_source_finite_elements (bool is_multilevel=false) |
Sets up the finite elements for the source mesh. | |
void | setup_target_finite_elements () |
Sets up the finite elements for the target mesh. | |
void | setup_finite_elements () |
Sets up the finite elements for both the source and target meshes. | |
void | setup_target_points () |
Sets up the target points. | |
void | setup_multilevel_finite_elements () |
Sets up the finite elements for a multilevel computation. | |
template<int d = dim, int s = spacedim> | |
std::enable_if< d==3 &&s==3 >::type | run_exact_sot () |
Runs the exact semi-discrete optimal transport solver. | |
void | load_hierarchy_data (const std::string &hierarchy_dir, int specific_level=-1) |
Loads the hierarchy data from a directory. | |
void | assign_potentials_by_hierarchy (Vector< double > &potentials, int coarse_level, int fine_level, const Vector< double > &prev_potentials) |
Assigns potentials by hierarchy. | |
std::vector< std::pair< std::string, std::string > > | get_target_hierarchy_files () const |
Gets the target hierarchy files. | |
std::vector< std::string > | get_mesh_hierarchy_files () const |
Gets the mesh hierarchy files. | |
void | load_target_points_at_level (const std::string &points_file, const std::string &density_file) |
Loads the target points at a specific level. | |
void | save_interpolated_fields () |
Private Attributes | |
std::vector< std::vector< std::vector< size_t > > > | child_indices_ |
The child indices for the multilevel hierarchy. | |
bool | has_hierarchy_data_ {false} |
A flag to indicate if the hierarchy data is loaded. | |
std::vector< Point< spacedim > > | target_points_coarse |
The coarse level target points. | |
Vector< double > | target_density_coarse |
The coarse level target densities. | |
double | current_distance_threshold {0.0} |
The current distance threshold for computations. | |
Vector< double > | coarsest_potential |
The coarsest level potential for the multilevel solve. | |
Main class for the semi-discrete optimal transport solver.
This class orchestrates the entire process of solving a semi-discrete optimal transport problem. It manages the source and target measures, the solver, and the various numerical strategies that can be employed.
dim | The dimension of the source mesh. |
spacedim | The dimension of the space the mesh is embedded in. |
Definition at line 77 of file SemiDiscreteOT.h.
SemiDiscreteOT< dim, spacedim >::SemiDiscreteOT | ( | const MPI_Comm & | mpi_communicator | ) |
Constructor for the SemiDiscreteOT class.
mpi_communicator | The MPI communicator. |
Definition at line 8 of file SemiDiscreteOT.cc.
void SemiDiscreteOT< dim, spacedim >::run | ( | ) |
Runs the solver with the current configuration.
Definition at line 2592 of file SemiDiscreteOT.cc.
void SemiDiscreteOT< dim, spacedim >::configure | ( | std::function< void(SotParameterManager &)> | config_func | ) |
Configure the solver parameters programmatically.
config_func | A lambda function that takes a reference to the SotParameterManager and modifies its parameters. |
Definition at line 32 of file SemiDiscreteOT.cc.
void SemiDiscreteOT< dim, spacedim >::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)
tria | A standard Triangulation |
dh | A DoFHandler on the provided triangulation |
density | A standard Vector containing the density values |
name | An optional name for the source mesh (used for saving and hierarchy generation) |
This method internally handles the conversion to distributed objects when needed for parallel computation.
Definition at line 51 of file SemiDiscreteOT.cc.
void SemiDiscreteOT< dim, spacedim >::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.
points | A vector of target points. |
weights | A vector of weights/densities for each target point. |
Definition at line 131 of file SemiDiscreteOT.cc.
void SemiDiscreteOT< dim, spacedim >::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.
Definition at line 175 of file SemiDiscreteOT.cc.
void SemiDiscreteOT< dim, spacedim >::prepare_source_multilevel | ( | ) |
Pre-computes the multilevel hierarchy for the source.
source_level | The level of the source hierarchy to prepare. |
Definition at line 1845 of file SemiDiscreteOT.cc.
void SemiDiscreteOT< dim, spacedim >::prepare_target_multilevel | ( | ) |
Pre-computes the multilevel hierarchy for the target.
target_level | The level of the target hierarchy to prepare. |
Definition at line 1897 of file SemiDiscreteOT.cc.
|
inline |
Get a pointer to the solver object.
Definition at line 144 of file SemiDiscreteOT.h.
|
inline |
Get a reference to the solver parameters.
Definition at line 150 of file SemiDiscreteOT.h.
|
inline |
Get the coarsest potential from the multilevel solve.
Definition at line 156 of file SemiDiscreteOT.h.
Vector< double > SemiDiscreteOT< dim, spacedim >::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.
initial_potential | Optional initial potential values to start the optimization from. |
Definition at line 196 of file SemiDiscreteOT.cc.
void SemiDiscreteOT< dim, spacedim >::save_discrete_measures | ( | ) |
Saves the discrete source and target measures to files.
Definition at line 2404 of file SemiDiscreteOT.cc.
|
inline |
Sets the distance function to be used by the solver.
dist | The distance function. |
Definition at line 177 of file SemiDiscreteOT.h.
|
protected |
Saves the results of the computation.
potentials | The computed optimal transport potentials. |
filename | The name of the file to save the results to. |
add_epsilon_prefix | Whether to add an epsilon prefix to the filename. |
Definition at line 1982 of file SemiDiscreteOT.cc.
|
protected |
Normalizes the density vector.
density | The density vector to normalize. |
Definition at line 337 of file SemiDiscreteOT.cc.
|
private |
Generates the source and target meshes.
Definition at line 216 of file SemiDiscreteOT.cc.
|
private |
Loads the source and target meshes from files.
Definition at line 234 of file SemiDiscreteOT.cc.
|
private |
Run single-level SOT computation.
initial_potential | Optional initial potential values to start the optimization from. |
Definition at line 748 of file SemiDiscreteOT.cc.
|
private |
Computes the power diagram of the target points.
Definition at line 2124 of file SemiDiscreteOT.cc.
|
private |
Computes the transport map from the source to the target measure.
Definition at line 2010 of file SemiDiscreteOT.cc.
|
private |
Computes the conditional density of the source measure.
Definition at line 2239 of file SemiDiscreteOT.cc.
|
private |
Run multilevel SOT computation (dispatcher method).
initial_potential | Optional initial potential values to start the optimization from. |
Definition at line 1759 of file SemiDiscreteOT.cc.
|
private |
Run combined source and target multilevel SOT computation.
initial_potential | Optional initial potential values to start the optimization from. |
Definition at line 1472 of file SemiDiscreteOT.cc.
|
private |
Run source-only multilevel SOT computation.
initial_potential | Optional initial potential values to start the optimization from. |
Definition at line 1242 of file SemiDiscreteOT.cc.
|
private |
Run target-only multilevel SOT computation.
initial_potential | Optional initial potential values to start the optimization from. |
Definition at line 883 of file SemiDiscreteOT.cc.
|
private |
Sets up the finite elements for the source mesh.
is_multilevel | Whether the setup is for a multilevel computation. |
Definition at line 369 of file SemiDiscreteOT.cc.
|
private |
Sets up the finite elements for the target mesh.
Definition at line 501 of file SemiDiscreteOT.cc.
|
private |
Sets up the finite elements for both the source and target meshes.
Definition at line 651 of file SemiDiscreteOT.cc.
|
private |
Sets up the target points.
Definition at line 659 of file SemiDiscreteOT.cc.
|
private |
Sets up the finite elements for a multilevel computation.
|
private |
Runs the exact semi-discrete optimal transport solver.
Definition at line 1795 of file SemiDiscreteOT.cc.
|
private |
Loads the hierarchy data from a directory.
hierarchy_dir | The directory containing the hierarchy data. |
specific_level | The specific level to load. |
Definition at line 332 of file SemiDiscreteOT.cc.
|
private |
Assigns potentials by hierarchy.
potentials | The potentials to assign. |
coarse_level | The coarse level. |
fine_level | The fine level. |
prev_potentials | The previous potentials. |
Definition at line 666 of file SemiDiscreteOT.cc.
|
private |
Gets the target hierarchy files.
Definition at line 256 of file SemiDiscreteOT.cc.
|
private |
Gets the mesh hierarchy files.
|
private |
Loads the target points at a specific level.
points_file | The path to the points file. |
density_file | The path to the density file. |
Definition at line 262 of file SemiDiscreteOT.cc.
|
private |
Save interpolated fields for source and target meshes. This is useful for debugging and visualization purposes. Uses the field names from the parameter files.
Definition at line 2475 of file SemiDiscreteOT.cc.
ConditionalOStream SemiDiscreteOT< dim, spacedim >::pcout |
A conditional output stream for parallel printing.
Definition at line 183 of file SemiDiscreteOT.h.
|
protected |
The MPI communicator.
Definition at line 186 of file SemiDiscreteOT.h.
|
protected |
The number of MPI processes.
Definition at line 187 of file SemiDiscreteOT.h.
|
protected |
The rank of the current MPI process.
Definition at line 188 of file SemiDiscreteOT.h.
|
protected |
The semi-discrete optimal transport solver.
Definition at line 191 of file SemiDiscreteOT.h.
|
protected |
The parameter manager.
Definition at line 194 of file SemiDiscreteOT.h.
|
protected |
A reference to the source mesh parameters.
Definition at line 195 of file SemiDiscreteOT.h.
|
protected |
A reference to the target mesh parameters.
Definition at line 196 of file SemiDiscreteOT.h.
|
protected |
A reference to the solver parameters.
Definition at line 197 of file SemiDiscreteOT.h.
|
protected |
A reference to the multilevel parameters.
Definition at line 198 of file SemiDiscreteOT.h.
|
protected |
A reference to the power diagram parameters.
Definition at line 199 of file SemiDiscreteOT.h.
|
protected |
A reference to the transport map parameters.
Definition at line 200 of file SemiDiscreteOT.h.
|
protected |
A reference to the selected task.
Definition at line 201 of file SemiDiscreteOT.h.
|
protected |
A reference to the I/O coding.
Definition at line 202 of file SemiDiscreteOT.h.
|
protected |
The initial fine DoF handler.
Definition at line 204 of file SemiDiscreteOT.h.
|
protected |
The initial fine density.
Definition at line 205 of file SemiDiscreteOT.h.
|
protected |
A flag to indicate if the setup is done programmatically.
Definition at line 206 of file SemiDiscreteOT.h.
|
protected |
The name of the source mesh.
Definition at line 209 of file SemiDiscreteOT.h.
|
protected |
The source mesh.
Definition at line 212 of file SemiDiscreteOT.h.
|
protected |
The target mesh.
Definition at line 213 of file SemiDiscreteOT.h.
|
protected |
The DoF handler for the source mesh.
Definition at line 214 of file SemiDiscreteOT.h.
|
protected |
The DoF handler for the target mesh.
Definition at line 215 of file SemiDiscreteOT.h.
|
protected |
The VTK handler for the source mesh.
Definition at line 217 of file SemiDiscreteOT.h.
|
protected |
The DoF handler for the source VTK mesh.
Definition at line 218 of file SemiDiscreteOT.h.
|
protected |
The source field from the VTK file.
Definition at line 219 of file SemiDiscreteOT.h.
|
protected |
The triangulation from the source VTK file.
Definition at line 220 of file SemiDiscreteOT.h.
|
protected |
The finite element system.
Definition at line 222 of file SemiDiscreteOT.h.
|
protected |
The mapping.
Definition at line 223 of file SemiDiscreteOT.h.
|
protected |
The target finite element system.
Definition at line 224 of file SemiDiscreteOT.h.
|
protected |
The target mapping.
Definition at line 225 of file SemiDiscreteOT.h.
|
protected |
The source density.
Definition at line 226 of file SemiDiscreteOT.h.
|
protected |
The target density.
Definition at line 227 of file SemiDiscreteOT.h.
|
protected |
The target points.
Definition at line 228 of file SemiDiscreteOT.h.
|
protected |
The source points.
Definition at line 229 of file SemiDiscreteOT.h.
|
protected |
The mesh manager.
Definition at line 232 of file SemiDiscreteOT.h.
|
protected |
The epsilon scaling handler.
Definition at line 235 of file SemiDiscreteOT.h.
|
private |
The child indices for the multilevel hierarchy.
Definition at line 343 of file SemiDiscreteOT.h.
|
private |
A flag to indicate if the hierarchy data is loaded.
Definition at line 344 of file SemiDiscreteOT.h.
|
private |
The coarse level target points.
Definition at line 353 of file SemiDiscreteOT.h.
|
private |
The coarse level target densities.
Definition at line 354 of file SemiDiscreteOT.h.
|
mutableprivate |
The current distance threshold for computations.
Definition at line 355 of file SemiDiscreteOT.h.
|
private |
The coarsest level potential for the multilevel solve.
Definition at line 356 of file SemiDiscreteOT.h.