2D Utilities

Point Structure

struct point

Represents a point in 2D space with coordinates and global/local indices.

Public Members

type_real x = 0

x coordinate

type_real z = 0

z coordinate

int iloc = 0

local index

int iglob = 0

global index

Bounding Box Structure

struct bounding_box

Represents a bounding box in 2D space.

This structure defines the minimum and maximum extents of a 2D region. required by the index mapping procedure.

Public Members

type_real xmin = std::numeric_limits<type_real>::max()

Minimum x coordinate.

type_real xmax = std::numeric_limits<type_real>::min()

Maximum x coordinate.

type_real zmin = std::numeric_limits<type_real>::max()

Minimum z coordinate.

type_real zmax = std::numeric_limits<type_real>::min()

Maximum z coordinate.

Utility Functions

type_real specfem::assembly::mesh_impl::dim2::compute_spatial_tolerance(const std::vector<point> &points, int nspec, int ngllxz)

Computes the spatial tolerance for a set of 2D points.

This function calculates the spatial tolerance based on the distribution of points in the mesh. It is used to determine the acceptable level of precision for spatial operations.

Parameters:
  • points – The 2D points to analyze

  • nspec – The number of spectral elements

  • ngllxz – The number of Gauss-Lobatto-Legendre points in the x and z directions

Returns:

type_real The computed spatial tolerance

std::vector<point> specfem::assembly::mesh_impl::dim2::flatten_coordinates(const Kokkos::View<double****, Kokkos::LayoutRight, Kokkos::HostSpace> global_coordinates)

Flattens a 4D array of global coordinates into a 2D vector of points.

This function takes a 4D array of global coordinates and converts it into a 2D vector of point structures, which contain the relevant coordinate information for each point in the mesh.

Parameters:

global_coordinates – The 4D array of global coordinates

Returns:

std::vector<point> The flattened vector of points

void specfem::assembly::mesh_impl::dim2::sort_points_spatially(std::vector<point> &points)

Sorts a vector of 2D points spatially.

This function sorts the points in the vector based on their spatial coordinates (x and z). The sorting is performed in-place.

Parameters:

points – The vector of 2D points to sort

int specfem::assembly::mesh_impl::dim2::assign_global_numbering(std::vector<point> &points, type_real tolerance)

Assigns global numbering to a vector of 2D points.

This function assigns a global index to each point in the vector based on its spatial location. The global numbering is used to establish a consistent ordering of points across different processes.

Parameters:
  • points – The vector of 2D points to assign global numbering

  • tolerance – The spatial tolerance for determining point proximity

Returns:

int The number of unique global indices assigned

std::vector<point> specfem::assembly::mesh_impl::dim2::reorder_to_original_layout(const std::vector<point> &sorted_points)

Reorders a vector of 2D points to match the original layout.

This function takes a vector of sorted 2D points and reorders them to match the original layout before sorting. This is useful for maintaining consistency between different representations of the mesh.

Parameters:

sorted_points – The vector of sorted 2D points

Returns:

std::vector<point> The reordered vector of points

bounding_box specfem::assembly::mesh_impl::dim2::compute_bounding_box(const std::vector<point> &points)

Computes the bounding box for a set of 2D points.

This function calculates the minimum and maximum extents of the points in the x and z dimensions, effectively creating a bounding box that encloses all the points.

Parameters:

points – The vector of 2D points to analyze

Returns:

bounding_box The computed bounding box

std::tuple<Kokkos::View<int***, Kokkos::LayoutLeft, Kokkos::HostSpace>, Kokkos::View<type_real****, Kokkos::LayoutRight, Kokkos::HostSpace>, int> specfem::assembly::mesh_impl::dim2::create_coordinate_arrays(const std::vector<point> &reordered_points, int nspec, int ngll, int nglob)

Create a coordinate arrays object.

Given the reordered 2D points and the mesh specifications, this function creates the necessary unique coordinate arrays for the simulation, as well as the associated mapping from local coordinates local to global coordinates, number of total points.

Parameters:
  • reordered_points – The vector of reordered 2D points

  • nspec – The number of spectral elements

  • ngll – The number of Gauss-Lobatto-Legendre points

  • nglob – The number of global points

Returns:

std::tuple<Kokkos::View<int ***, Kokkos::LayoutLeft, Kokkos::HostSpace>, Kokkos::View<type_real ****, Kokkos::LayoutRight, Kokkos::HostSpace>, int>