SemiDiscreteOT 1.0
Semi-Discrete Optimal Transport Library
Loading...
Searching...
No Matches
Functions
Utils Namespace Reference

Collection of utility functions for file I/O, mesh handling and data management. More...

Functions

std::string to_scientific_string (double value, int precision=6)
 Convert a double to a string in scientific notation.
 
template<typename VectorContainer >
void write_vector (const VectorContainer &points, const std::string &filepath, const std::string &fileMode="txt")
 Write a vector container to a file in binary or text format.
 
template<typename VectorContainer >
bool read_vector (VectorContainer &points, const std::string &filepath, const std::string &fileMode="")
 Read a vector container from a file in binary or text format.
 
std::vector< std::string > select_folder (const std::string &base_dir="output", bool allow_all=true)
 List available epsilon folders and allow user selection.
 
std::vector< std::pair< std::string, std::string > > get_target_hierarchy_files (const std::string &dir)
 Get target point cloud hierarchy files.
 
template<int dim, int spacedim>
bool load_hierarchy_data (const std::string &hierarchy_dir, std::vector< std::vector< std::vector< size_t > > > &child_indices, int specific_level, const MPI_Comm &mpi_communicator, dealii::ConditionalOStream &pcout)
 Load hierarchy data from files.
 
template<int dim, int spacedim = dim>
bool write_mesh (const dealii::Triangulation< dim, spacedim > &mesh, const std::string &filepath, const std::vector< std::string > &formats, const std::vector< double > *cell_data=nullptr, const std::string &data_name="cell_data")
 Write mesh to file in specified formats with optional cell data.
 
template<int dim, int spacedim>
void interpolate_non_conforming_nearest (const dealii::DoFHandler< dim, spacedim > &source_dh, const dealii::Vector< double > &source_field, const dealii::DoFHandler< dim, spacedim > &target_dh, dealii::LinearAlgebra::distributed::Vector< double > &target_field)
 Interpolate a field from a source mesh to a target mesh using nearest neighbor approach.
 
template<int dim, int spacedim>
void interpolate_non_conforming (const dealii::DoFHandler< dim, spacedim > &source_dh, const dealii::Vector< double > &source_field, const dealii::DoFHandler< dim, spacedim > &target_dh, dealii::LinearAlgebra::distributed::Vector< double > &target_field)
 Interpolate a field from a source mesh to a target mesh.
 
template<int dim, int spacedim = dim>
std::unique_ptr< dealii::FiniteElement< dim, spacedim > > create_fe_for_mesh (const dealii::Triangulation< dim, spacedim > &triangulation, const unsigned int degree=1)
 Detect cell types in a triangulation and create appropriate finite element.
 
template<int dim, int spacedim>
std::pair< std::unique_ptr< dealii::FiniteElement< dim, spacedim > >, std::unique_ptr< dealii::Mapping< dim, spacedim > > > create_fe_and_mapping_for_mesh (const dealii::Triangulation< dim, spacedim > &triangulation, const unsigned int fe_degree=1, const unsigned int mapping_degree=1)
 Create appropriate finite element and mapping for a triangulation.
 
template<int dim, int spacedim = dim>
std::unique_ptr< dealii::Quadrature< dim > > create_quadrature_for_mesh (const dealii::Triangulation< dim, spacedim > &triangulation, const unsigned int order=2)
 Create appropriate quadrature for a triangulation based on cell types.
 
template<int spacedim>
bool write_points_with_density_vtk (const std::vector< dealii::Point< spacedim > > &points, const std::vector< double > &density, const std::string &filename, const std::string &description="Points with density values", const std::string &density_name="density")
 Write points with associated density to VTK file.
 
template<int spacedim>
bool write_points_with_displacement_vtk (const std::vector< dealii::Point< spacedim > > &source_points, const std::vector< dealii::Point< spacedim > > &mapped_points, const std::vector< double > &density, const std::string &filename, const std::string &description="Points with displacement vectors", const std::string &density_name="density")
 Write points with displacement vectors and density to VTK file.
 
template<int dim, int spacedim = dim>
bool read_vtk_field (const std::string &filename, dealii::DoFHandler< dim, spacedim > &vtk_dof_handler, dealii::Vector< double > &vtk_field, dealii::Triangulation< dim, spacedim > &vtk_tria, const MPI_Comm &mpi_communicator, dealii::ConditionalOStream &pcout, bool broadcast_field=false, const std::string &field_name="normalized_density")
 Read a scalar field from a VTK file.
 

Detailed Description

Collection of utility functions for file I/O, mesh handling and data management.

Function Documentation

◆ to_scientific_string()

std::string Utils::to_scientific_string ( double  value,
int  precision = 6 
)
inline

Convert a double to a string in scientific notation.

Parameters
valueThe double value to convert
precisionNumber of significant digits (default: 6)
Returns
String representation in scientific notation

Definition at line 42 of file utils.h.

Here is the caller graph for this function:

◆ write_vector()

template<typename VectorContainer >
void Utils::write_vector ( const VectorContainer &  points,
const std::string &  filepath,
const std::string &  fileMode = "txt" 
)

Write a vector container to a file in binary or text format.

Template Parameters
VectorContainerType of vector container
Parameters
pointsVector container to write
filepathPath to output file (without extension)
fileModeOutput format ("txt" or "bin")

Definition at line 56 of file utils.h.

Here is the caller graph for this function:

◆ read_vector()

template<typename VectorContainer >
bool Utils::read_vector ( VectorContainer &  points,
const std::string &  filepath,
const std::string &  fileMode = "" 
)

Read a vector container from a file in binary or text format.

Template Parameters
VectorContainerType of vector container
Parameters
pointsVector container to store read data
filepathPath to input file (with or without extension)
fileModeInput format ("txt" or "bin"), if empty will be inferred from filepath
Returns
true if read successful, false otherwise

Definition at line 108 of file utils.h.

Here is the caller graph for this function:

◆ select_folder()

std::vector< std::string > Utils::select_folder ( const std::string &  base_dir = "output",
bool  allow_all = true 
)
inline

List available epsilon folders and allow user selection.

Parameters
base_dirBase directory containing epsilon folders
allow_allWhether to allow selecting all folders
Returns
Vector of selected folder names

Definition at line 184 of file utils.h.

Here is the caller graph for this function:

◆ get_target_hierarchy_files()

std::vector< std::pair< std::string, std::string > > Utils::get_target_hierarchy_files ( const std::string &  dir)
inline

Get target point cloud hierarchy files.

Parameters
dirDirectory containing hierarchy files
Returns
Vector of pairs (points_file, density_file)

Definition at line 238 of file utils.h.

Here is the caller graph for this function:

◆ load_hierarchy_data()

template<int dim, int spacedim>
bool Utils::load_hierarchy_data ( const std::string &  hierarchy_dir,
std::vector< std::vector< std::vector< size_t > > > &  child_indices,
int  specific_level,
const MPI_Comm &  mpi_communicator,
dealii::ConditionalOStream &  pcout 
)

Load hierarchy data from files.

Parameters
hierarchy_dirDirectory containing hierarchy files
child_indicesVector to store parent-child relationships
specific_levelLevel to load (-1 for all levels)
mpi_communicatorMPI communicator
pcoutParallel console output
Returns
true if load successful, false otherwise

Definition at line 287 of file utils.h.

◆ write_mesh()

template<int dim, int spacedim = dim>
bool Utils::write_mesh ( const dealii::Triangulation< dim, spacedim > &  mesh,
const std::string &  filepath,
const std::vector< std::string > &  formats,
const std::vector< double > *  cell_data = nullptr,
const std::string &  data_name = "cell_data" 
)

Write mesh to file in specified formats with optional cell data.

Template Parameters
dimDimension of the mesh
spacedimAmbient space dimension
Parameters
meshTriangulation to write
filepathBase path for output files (without extension)
formatsVector of output formats ("vtk", "msh", "vtu")
cell_dataOptional vector of cell data to include
data_nameName for the cell data field
Returns
true if write successful, false otherwise

Definition at line 410 of file utils.h.

Here is the caller graph for this function:

◆ interpolate_non_conforming_nearest()

template<int dim, int spacedim>
void Utils::interpolate_non_conforming_nearest ( const dealii::DoFHandler< dim, spacedim > &  source_dh,
const dealii::Vector< double > &  source_field,
const dealii::DoFHandler< dim, spacedim > &  target_dh,
dealii::LinearAlgebra::distributed::Vector< double > &  target_field 
)

Interpolate a field from a source mesh to a target mesh using nearest neighbor approach.

Template Parameters
dimDimension of the mesh
spacedimSpatial dimension
Parameters
source_dhSource DoFHandler
source_fieldSource field values
target_dhTarget DoFHandler
target_fieldTarget field values (output)

Definition at line 504 of file utils.h.

Here is the caller graph for this function:

◆ interpolate_non_conforming()

template<int dim, int spacedim>
void Utils::interpolate_non_conforming ( const dealii::DoFHandler< dim, spacedim > &  source_dh,
const dealii::Vector< double > &  source_field,
const dealii::DoFHandler< dim, spacedim > &  target_dh,
dealii::LinearAlgebra::distributed::Vector< double > &  target_field 
)

Interpolate a field from a source mesh to a target mesh.

Template Parameters
dimDimension of the mesh
spacedimSpatial dimension
Parameters
source_dhSource DoFHandler
source_fieldSource field values
target_dhTarget DoFHandler
target_fieldTarget field values (output)

Definition at line 625 of file utils.h.

◆ create_fe_for_mesh()

template<int dim, int spacedim = dim>
std::unique_ptr< dealii::FiniteElement< dim, spacedim > > Utils::create_fe_for_mesh ( const dealii::Triangulation< dim, spacedim > &  triangulation,
const unsigned int  degree = 1 
)

Detect cell types in a triangulation and create appropriate finite element.

Template Parameters
dimDimension of the mesh
Parameters
triangulationInput triangulation to analyze
degreePolynomial degree for the finite element (defaults to 1)
Returns
Unique pointer to appropriate finite element
Exceptions
std::runtime_errorif cell type cannot be determined

Definition at line 743 of file utils.h.

Here is the caller graph for this function:

◆ create_fe_and_mapping_for_mesh()

template<int dim, int spacedim>
std::pair< std::unique_ptr< dealii::FiniteElement< dim, spacedim > >, std::unique_ptr< dealii::Mapping< dim, spacedim > > > Utils::create_fe_and_mapping_for_mesh ( const dealii::Triangulation< dim, spacedim > &  triangulation,
const unsigned int  fe_degree = 1,
const unsigned int  mapping_degree = 1 
)

Create appropriate finite element and mapping for a triangulation.

Template Parameters
dimDimension of the mesh
Parameters
triangulationInput triangulation to analyze
fe_degreePolynomial degree for the finite element (defaults to 1)
mapping_degreePolynomial degree for the mapping (defaults to 1)
Returns
Pair of unique pointers to appropriate finite element and mapping
Exceptions
std::runtime_errorif cell type cannot be determined

Definition at line 778 of file utils.h.

◆ create_quadrature_for_mesh()

template<int dim, int spacedim = dim>
std::unique_ptr< dealii::Quadrature< dim > > Utils::create_quadrature_for_mesh ( const dealii::Triangulation< dim, spacedim > &  triangulation,
const unsigned int  order = 2 
)

Create appropriate quadrature for a triangulation based on cell types.

Template Parameters
dimDimension of the mesh
Parameters
triangulationInput triangulation to analyze
orderQuadrature order (defaults to 2)
Returns
Unique pointer to appropriate quadrature
Exceptions
std::runtime_errorif cell type cannot be determined

Definition at line 818 of file utils.h.

◆ write_points_with_density_vtk()

template<int spacedim>
bool Utils::write_points_with_density_vtk ( const std::vector< dealii::Point< spacedim > > &  points,
const std::vector< double > &  density,
const std::string &  filename,
const std::string &  description = "Points with density values",
const std::string &  density_name = "density" 
)

Write points with associated density to VTK file.

Template Parameters
spacedimSpatial dimension
Parameters
pointsVector of points to write
densityVector of density values associated with points
filenameOutput VTK filename
descriptionDescription for the VTK file header
density_nameName for the density scalar field
Returns
true if write successful, false otherwise

Definition at line 852 of file utils.h.

◆ write_points_with_displacement_vtk()

template<int spacedim>
bool Utils::write_points_with_displacement_vtk ( const std::vector< dealii::Point< spacedim > > &  source_points,
const std::vector< dealii::Point< spacedim > > &  mapped_points,
const std::vector< double > &  density,
const std::string &  filename,
const std::string &  description = "Points with displacement vectors",
const std::string &  density_name = "density" 
)

Write points with displacement vectors and density to VTK file.

Template Parameters
spacedimSpatial dimension
Parameters
source_pointsVector of source points
mapped_pointsVector of mapped points (targets)
densityVector of density values associated with points
filenameOutput VTK filename
descriptionDescription for the VTK file header
density_nameName for the density scalar field
Returns
true if write successful, false otherwise

Definition at line 936 of file utils.h.

◆ read_vtk_field()

template<int dim, int spacedim = dim>
bool Utils::read_vtk_field ( const std::string &  filename,
dealii::DoFHandler< dim, spacedim > &  vtk_dof_handler,
dealii::Vector< double > &  vtk_field,
dealii::Triangulation< dim, spacedim > &  vtk_tria,
const MPI_Comm &  mpi_communicator,
dealii::ConditionalOStream &  pcout,
bool  broadcast_field = false,
const std::string &  field_name = "normalized_density" 
)

Read a scalar field from a VTK file.

Parameters
filenamePath to the VTK file
vtk_dof_handlerDoF handler for the VTK mesh
vtk_fieldVector for the VTK field data
vtk_triaTriangulation for the VTK mesh
mpi_communicatorMPI communicator
pcoutParallel output stream
broadcast_fieldWhether to broadcast the field to all processes (true for source, false for target)
field_nameName of the field to read from the VTK file
Returns
bool Success status

Definition at line 1039 of file utils.h.

Here is the call graph for this function: