C++ API Reference

This section provides the API reference for the µGrid C++ library. The library is organized into several modules for field management, grid operations, MPI communication, and I/O.

Field Collections

Field collections manage groups of fields on structured grids. All fields in a collection share the same spatial discretization.

class FieldCollection

Base class for both muGrid::GlobalFieldCollection and muGrid::LocalFieldCollection. Manages the a group of fields with the same domain of validity (i.e., global fields, or local fields defined on the same pixels).

Subclassed by muGrid::GlobalFieldCollection, muGrid::LocalFieldCollection

Public Types

enum class ValidityDomain

domain of validity of the managed fields

Values:

enumerator Global
enumerator Local
using Field_ptr = std::unique_ptr<Field, FieldDestructor<Field>>

unique_ptr for holding fields

using SubPtMap_t = std::map<std::string, Index_t>

map to hold nb_sub_pts by tag

using StateField_ptr = std::unique_ptr<StateField, FieldDestructor<StateField>>

unique_ptr for holding state fields

Public Functions

FieldCollection() = delete

Default constructor.

FieldCollection(const FieldCollection &other) = delete

Copy constructor.

FieldCollection(FieldCollection &&other) = default

Move constructor.

virtual ~FieldCollection() = default

Destructor.

FieldCollection &operator=(const FieldCollection &other) = delete

Copy assignment operator.

FieldCollection &operator=(FieldCollection &&other) = default

Move assignment operator.

template<typename T>
inline Field &register_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

template<typename T>
inline Field &register_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

template<typename T>
Field_ptr detached_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

create a detached field (i.e., the field collection does not take responsibility for it, and it is up to the user to make sure that the field is used only during the life-time of the collection.

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &register_real_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new real-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &register_real_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &register_complex_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new complex-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &register_complex_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &register_int_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new integer-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &register_int_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &register_uint_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new unsigned integer-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &register_uint_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

template<typename T>
inline TypedStateField<T> &register_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

TypedStateField<Real> &register_real_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new real-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Complex> &register_complex_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new complex-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Int> &register_int_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new integer-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Uint> &register_uint_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new unsigned integer-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

template<typename T>
inline Field &field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &real_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new real-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &real_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &complex_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new complex-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &complex_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &int_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new integer-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &int_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &uint_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new unsigned integer-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &uint_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

template<typename T>
inline TypedStateField<T> &state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

TypedStateField<Real> &real_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new real-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Complex> &complex_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new complex-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Int> &int_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new integer-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Uint> &uint_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new unsigned integer-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

bool field_exists(const std::string &unique_name) const

check whether a field of name ‘unique_name’ has already been registered

bool state_field_exists(const std::string &unique_prefix) const

check whether a field of name ‘unique_name’ has already been registered

Index_t get_nb_pixels() const

returns the number of pixels present in the collection

virtual Index_t get_nb_pixels_without_ghosts() const

returns the number of pixels present in the collection without ghosts

Index_t get_nb_buffer_pixels() const

returns the number of (virtual) pixels required to store the underlying data that may involve padding regions

bool has_nb_sub_pts(const std::string &tag) const

Check whether the number of subdivision points peir pixel/voxel has been set for a given tags

void set_nb_sub_pts(const std::string &tag, const Index_t &nb_sub_pts_per_pixel)

set the number of sub points per pixel/voxel for a given tag. Can only be done once per tag

Index_t get_nb_sub_pts(const std::string &tag)

return the number of subpoints per pixel/voxel for a given tag

Index_t get_nb_sub_pts(const std::string &tag) const

return the number of subpoints per pixel/voxel for a given tag

Dim_t get_spatial_dim() const

return the spatial dimension of the underlying discretisation grid

ValidityDomain get_domain() const

return the domain of validity (i.e., wher the fields are defined globally (muGrid::FieldCollection::ValidityDomain::Global) or locally (muGrid::FieldCollection::ValidityDomain::Local)

virtual Shape_t get_pixels_shape() const = 0

return shape of the pixels

virtual Shape_t get_pixels_shape_without_ghosts() const = 0

return shape of the pixels without any ghost buffer

virtual Shape_t get_pixels_offset_without_ghosts() const = 0

return the offset of the pixels in the storage without ghosts

virtual Shape_t get_pixels_strides(Index_t element_size = 1) const = 0

return strides of the pixels

StorageOrder get_storage_order() const

return the storage order of the pixels vs. subpoints

Device get_device() const

return the device for all fields in this collection

bool is_on_device() const

check if fields in this collection are on a GPU device

bool has_same_memory_layout(const FieldCollection &other) const

check whether two field collections have the same memory layout

bool is_initialised() const

whether the collection has been properly initialised (i.e., it knows the number of quadrature points and all its pixels/voxels

PixelIndexIterable get_pixel_indices() const

return an iterable proxy to the collection which allows to efficiently iterate over the indices fo the collection’s pixels

IndexIterable get_sub_pt_indices(const std::string &tag) const

return an iterable proxy to the collection which allows to iterate over the indices fo the collection’s quadrature points

inline const std::vector<Index_t> &get_pixel_ids()
Field &get_field(const std::string &unique_name)

returns a (base-type) reference to the field identified by unique_name. Throws a muGrid::FieldCollectionError if the field does not exist.

const Field &get_field(const std::string &unique_name) const

returns a (base-type) reference to the field identified by unique_name. Throws a muGrid::FieldCollectionError if the field does not exist.

Field_ptr pop_field(const std::string &unique_name)

returns the unique ptr holding the field named unique_name. Warning: note that this effectively removes the field from the collection. You can use this to delete fields to free memory

StateField &get_state_field(const std::string &unique_prefix)

returns a (base-type) reference to the state field identified by unique_prefix. Throws a muGrid::FieldCollectionError if the state field does not exist.

std::vector<std::string> list_fields() const

returns a vector of all field names

std::vector<std::string> list_state_field_unique_prefixes() const

returns a vector of all unique_prefixes of state fields in the field collection

void preregister_map(std::shared_ptr<std::function<void()>> &call_back)

preregister a map for latent initialisation

Index_t check_nb_sub_pts(const Index_t &nb_sub_pts, const IterUnit &iteration_type, const std::string &tag) const

run-time checker for nb_sub_pts: checks whether the number of sub-points (e.g., quadrature points) is compatible with the sub-division scheme). Attention: this does allow Unknown as valid values for IterUnit::SubPt, if the tag is defined, since these values can be specified for the entire FieldCollection at a later point, before initialisation. Hence, this function cannot be used for checking nb_sub_pts for iterators, which need a known value. Use check_initialised_nb_sub_pts() instead for that.

size_t check_initialised_nb_sub_pts(const Index_t &nb_sub_pts, const IterUnit &iteration_type, const std::string &tag) const

run-time checker for nb_sub_pts: checks whether the number of sub-points (e.g., quadrature points) is compatible with the sub-division scheme), and set to a positive integer value (i.e., not Unknown).

std::string generate_unique_name() const

use this to obtain an unused unique name for a new field to register, if you do not care about what name you obtain.

template<typename T>
Field &register_field_helper(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag, const Unit &unit, bool allow_existing = false)

Internal worker function called by register_<T>_field. Creates a field in the collection’s memory space (host or device). Returns Field& to allow runtime polymorphism.

template<typename T>
Field &register_field_helper(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag, const Unit &unit, bool allow_existing = false)

Internal worker function called by register_<T>_field. Creates a field in the collection’s memory space (host or device). Returns Field& to allow runtime polymorphism.

template<typename T>
TypedStateField<T> &register_state_field_helper(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag, const Unit &unit, bool allow_existing = false)

internal worker function called by register_<T>_state_field

class IndexIterable

Iterate class for iterating over quadrature point indices of a field collection (i.e. the iterate you get when iterating over the result of muGrid::FieldCollection::get_quad_pt_indices).

Public Functions

IndexIterable() = delete

Default constructor.

IndexIterable(const IndexIterable &other) = delete

Copy constructor.

IndexIterable(IndexIterable &&other) = default

Move constructor.

virtual ~IndexIterable() = default

Destructor.

IndexIterable &operator=(const IndexIterable &other) = delete

Copy assignment operator.

IndexIterable &operator=(IndexIterable &&other) = delete

Move assignment operator.

iterator begin() const

stl

iterator end() const

stl

size_t size() const

stl

class iterator

iterator class for iterating over quadrature point indices or pixel indices of a muGrid::FieldCollection::IndexIterable. Dereferences to an index.

Public Types

using PixelIndexIterator_t = typename std::vector<Index_t>::const_iterator

convenience alias

Public Functions

iterator() = delete

Default constructor.

iterator(const PixelIndexIterator_t &pixel_index_iterator, const size_t &stride)

constructor

iterator(const iterator &other) = default

Copy constructor.

iterator(iterator &&other) = default

Move constructor.

~iterator() = default

Destructor.

inline iterator &operator++()

pre-increment

inline bool operator!=(const iterator &other) const

comparison

inline bool operator==(const iterator &other) const

comparison (required by akantu::iterators)

inline size_t operator*()

dereference

class PixelIndexIterable

Lightweight proxy class providing iteration over the pixel indices of a muGrid::FieldCollection

Public Types

using iterator = typename std::vector<Index_t>::const_iterator

stl

Public Functions

PixelIndexIterable() = delete

Default constructor.

PixelIndexIterable(const PixelIndexIterable &other) = delete

Copy constructor.

PixelIndexIterable(PixelIndexIterable &&other) = default

Move constructor.

virtual ~PixelIndexIterable() = default

Destructor.

PixelIndexIterable &operator=(const PixelIndexIterable &other) = delete

Copy assignment operator.

PixelIndexIterable &operator=(PixelIndexIterable &&other) = delete

Move assignment operator.

iterator begin() const

stl

iterator end() const

stl

size_t size() const

stl

class GlobalFieldCollection : public muGrid::FieldCollection

muGrid::GlobalFieldCollection derives from muGrid::FieldCollection and stores global fields that live throughout the whole computational domain, i.e. are defined for every pixel/voxel.

Public Types

using Parent = FieldCollection

alias of base class

using Pixels = CcoordOps::Pixels

pixel iterator

using SubPtMap_t = std::map<std::string, Index_t>

map to hold nb_sub_pts by tag

Public Functions

GlobalFieldCollection() = delete

Default constructor.

GlobalFieldCollection(Dim_t spatial_dimension, const SubPtMap_t &nb_sub_pts = {}, StorageOrder storage_order = StorageOrder::ArrayOfStructures, Device device = Device::cpu())

Constructor

Parameters:
  • spatial_dimension – number of spatial dimensions, must be 1, 2, 3, or Unknown

  • nb_sub_pts – number of quadrature points per pixel/voxel

  • storage_order – storage order for field components

  • device – where to allocate field memory

GlobalFieldCollection(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts = {}, const DynGridIndex &subdomain_locations_with_ghosts = {}, const SubPtMap_t &nb_sub_pts = {}, StorageOrder storage_order = StorageOrder::ArrayOfStructures, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {}, Device device = Device::cpu())

Constructor with initialization

Parameters:
  • nb_subdomain_grid_pts_with_ghosts – number of grid points on the current MPI process (subdomain)

  • subdomain_locations_with_ghosts – location of the current subdomain within the global grid

  • nb_sub_pts – number of quadrature points per pixel/voxel

  • device – where to allocate field memory

GlobalFieldCollection(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts, const DynGridIndex &subdomain_locations_with_ghosts, const DynGridIndex &pixels_strides, const SubPtMap_t &nb_sub_pts = {}, StorageOrder storage_order = StorageOrder::ArrayOfStructures, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {}, Device device = Device::cpu())

Constructor with initialisation

Parameters:
  • nb_subdomain_grid_pts_with_ghosts – number of grid points on the current MPI process (subdomain)

  • subdomain_locations_with_ghosts – location of the current subdomain within the global grid

  • pixels_strides – strides specifying memory layout of the pixels

  • storage_order – Storage order of the pixels vs subdivision portion of the field. In a column-major storage order, the pixel subdivision (i.e. the components of the field) are stored next to each other in memory, while in a row-major storage order, for each component the pixels are stored next to each other in memory. (This is also sometimes called the array of structures vs. structure of arrays storage order.) Important: The pixels or subpoints have their own storage order that is not affected by this setting.

  • device – where to allocate field memory

GlobalFieldCollection(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts, const DynGridIndex &subdomain_locations_with_ghosts, StorageOrder pixels_storage_order, const SubPtMap_t &nb_sub_pts = {}, StorageOrder storage_order = StorageOrder::ArrayOfStructures, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {}, Device device = Device::cpu())

Constructor with initialisation

Parameters:
  • nb_subdomain_grid_pts_with_ghosts – number of grid points on the current MPI process (subdomain)

  • subdomain_locations_with_ghosts – location of the current subdomain within the global grid

  • pixels_storage_order – Storage order of the pixels

  • storage_order – Storage order of the pixels vs subdivision portion of the field. In a column-major storage order, the pixel subdivision (i.e. the components of the field) are stored next to each other in memory, while in a row-major storage order for each component the pixels are stored next to each other in memory. (This is also sometimes called the array of structures vs. structure of arrays storage order.) Important: The pixels or subpoints have their own storage order that is not affected by this setting.

  • device – where to allocate field memory

GlobalFieldCollection(const GlobalFieldCollection &other) = delete

Copy constructor.

GlobalFieldCollection(GlobalFieldCollection &&other) = default

Move constructor.

~GlobalFieldCollection() override = default

Destructor.

GlobalFieldCollection &operator=(const GlobalFieldCollection &other) = delete

Copy assignment operator.

GlobalFieldCollection &operator=(GlobalFieldCollection &&other) = delete

Move assignment operator.

const Pixels &get_pixels_with_ghosts() const

Return the pixels class that allows to iterator over pixels.

const Pixels &get_pixels_without_ghosts() const

Return the pixels class that allows to iterator over pixels.

inline Index_t get_index(const DynGridIndex &ccoord) const

evaluate and return the linear index corresponding to dynamic ccoord

template<size_t Dim>
inline Index_t get_index(const GridIndex<Dim> &ccoord) const

evaluate and return the linear index corresponding to ccoord

inline DynGridIndex get_coord(const Index_t &index) const

return coordinates of the i-th pixel

void initialise(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts, const DynGridIndex &subdomain_locations_with_ghosts, const DynGridIndex &pixels_strides, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {})

freeze the problem size and allocate memory for all fields of the collection. Fields added later on will have their memory allocated upon construction.

template<size_t Dim>
inline void initialise(const GridIndex<Dim> &nb_domain_grid_pts, const GridIndex<Dim> &nb_subdomain_grid_pts, const GridIndex<Dim> &subdomain_locations, const GridIndex<Dim> &pixels_strides, const GridIndex<Dim> &nb_ghosts_left = {}, const GridIndex<Dim> &nb_ghosts_right = {})

freeze the problem size and allocate memory for all fields of the collection. Fields added later on will have their memory allocated upon construction.

void initialise(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts = {}, const DynGridIndex &subdomain_locations_with_ghosts = {}, StorageOrder pixels_storage_order = StorageOrder::Automatic, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {})

freeze the problem size and allocate memory for all fields of the collection. Fields added later on will have their memory allocated upon construction.

template<size_t Dim>
inline void initialise(const GridIndex<Dim> &nb_domain_grid_pts, const GridIndex<Dim> &nb_subdomain_grid_pts = {}, const GridIndex<Dim> &subdomain_locations = {}, StorageOrder pixels_storage_order = StorageOrder::Automatic, const GridIndex<Dim> &nb_ghosts_left = {}, const GridIndex<Dim> &nb_ghosts_right = {})

freeze the problem size and allocate memory for all fields of the collection. Fields added later on will have their memory allocated upon construction.

GlobalFieldCollection get_empty_clone() const

obtain a new field collection with the same domain and pixels

virtual Shape_t get_pixels_shape() const override

return shape of the pixels

virtual Shape_t get_pixels_shape_without_ghosts() const override

return shape of the pixels without ghosts

virtual Index_t get_nb_pixels_without_ghosts() const override

return the number of pixels without ghosts

virtual Shape_t get_pixels_offset_without_ghosts() const override

return the offset of the pixels in the storage without ghosts

virtual Shape_t get_pixels_strides(Index_t element_size = 1) const override

return strides of the pixels

inline const DynGridIndex &get_nb_domain_grid_pts() const

returns the global (domain) number of grid points in each direction

inline const DynGridIndex &get_nb_subdomain_grid_pts_with_ghosts() const

returns the process-local (subdomain) number of grid points in each direction including the ghost cells

inline DynGridIndex get_nb_subdomain_grid_pts_without_ghosts() const

returns the process-local (subdomain) number of grid points in each directionl, but without the ghost cells

inline const DynGridIndex &get_subdomain_locations_with_ghosts() const

returns the process-local (subdomain) locations of subdomain grid including the ghost cells

inline DynGridIndex get_subdomain_locations_without_ghosts() const

returns the process-local (subdomain) locations of subdomain grid, but without the ghost cells

inline const DynGridIndex &get_nb_ghosts_left() const

Returns the number of ghost cells on the left side of the subdomain.

Returns:

const reference to a DynGridIndex object containing the number of left ghost cells.

inline const DynGridIndex &get_nb_ghosts_right() const

Returns the number of ghost cells on the right side of the subdomain.

Returns:

const reference to a DynGridIndex object containing the number of right ghost cells.

inline Index_t get_pixels_index_diff() const

Returns the index difference between iterators of pixels with and without ghosts.

Returns:

an Index_t instance.

class LocalFieldCollection : public muGrid::FieldCollection

muGrid::LocalFieldCollection derives from muGrid::FieldCollection and stores local fields, i.e. fields that are only defined for a subset of all pixels/voxels in the computational domain. The coordinates of these active pixels are explicitly stored by this field collection. muGrid::LocalFieldCollection::add_pixel allows to add individual pixels/voxels to the field collection.

Public Types

using Parent = FieldCollection

alias for base class

Public Functions

LocalFieldCollection() = delete

Default constructor.

LocalFieldCollection(Dim_t spatial_dimension, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())

Constructor

Parameters:
  • spatial_dimension – spatial dimension of the field (can be muGrid::Unknown, e.g., in the case of the local fields for storing internal material variables)

  • nb_sub_pts – number of sub-points per pixel

  • device – where to allocate field memory

LocalFieldCollection(Dim_t spatial_dimension, const std::string &name, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())

Constructor with explicit given name for the field collection. This name can be arbitrary and only has to be unique for all LocalFieldCollections which are saved to the same NetCDF file through the parallel IO object ‘FileIONetCDF’. If you register two LocalFieldCollections with the same name in a FileIONetCDF object you will get a muGrid::FieldCollectionError.

Parameters:
  • spatial_dimension – spatial dimension of the field

  • name – unique name for the field collection

  • nb_sub_pts – number of sub-points per pixel

  • device – where to allocate field memory

LocalFieldCollection(const LocalFieldCollection &other) = delete

Copy constructor.

LocalFieldCollection(LocalFieldCollection &&other) = default

Move constructor.

~LocalFieldCollection() override = default

Destructor.

LocalFieldCollection &operator=(const LocalFieldCollection &other) = delete

Copy assignment operator.

LocalFieldCollection &operator=(LocalFieldCollection &&other) = delete

Move assignment operator.

void add_pixel(const size_t &global_index)

Insert a new pixel/voxel into the collection.

Parameters:

global_index – refers to the linear index this pixel has in the global field collection defining the problem space

void initialise()

Freeze the set of pixels this collection is responsible for and allocate memory for all fields of the collection. Fields added lateron will have their memory allocated upon construction

LocalFieldCollection get_empty_clone(const std::string &new_name) const

obtain a new field collection with the same domain and pixels and a given new name

LocalFieldCollection get_empty_clone() const

obtain a new field collection with the same domain and pixels and the same name

virtual Shape_t get_pixels_shape() const override

return shape of the pixels

virtual Shape_t get_pixels_shape_without_ghosts() const override

return shape of the pixels

virtual Index_t get_nb_pixels_without_ghosts() const override

return the number of pixels without ghosts

virtual Shape_t get_pixels_offset_without_ghosts() const override

return the offset of the pixels in the storage without ghosts

virtual Shape_t get_pixels_strides(Index_t element_size = 1) const override

return strides of the pixels

inline std::map<Index_t, Index_t> &get_global_to_local_index_map()
const std::string &get_name() const

return the unique name of the local field collection

Fields

Fields represent scalar, vector, or tensor quantities that vary over the grid. Each field belongs to a field collection.

class Field

Abstract base class for all fields. A field provides storage discretising a mathematical (scalar, vectorial, tensorial) (real-valued, integer-valued, complex-valued) field on a fixed number of quadrature points per pixel/voxel of a regular grid. Fields defined on the same domains are grouped within muGrid::FieldCollections.

To understand the interface, it is important to clarify the following nomenclature:

  • Pixels are the grid dimensions for global fields or a single linear dimension for local fields

  • SubPts specify the number of (tensor) quantities held per pixel. These could for example be quadrature points.

  • Components are the components of the physical tensor quantity represented by the field.

Subclassed by muGrid::TypedFieldBase< Scalar, MemorySpace >, muGrid::TypedFieldBase< T, MemorySpace >

Public Functions

Field() = delete

Default constructor.

Field(const Field &other) = delete

Copy constructor.

Field(Field &&other) = default

Move constructor.

virtual ~Field() = default

Destructor.

Field &operator=(const Field &other) = delete

Copy assignment operator.

Field &operator=(Field &&other) = delete

Move assignment operator.

const std::string &get_name() const

return the field’s unique name

FieldCollection &get_collection() const

return a const reference to the field’s collection

const Index_t &get_nb_components() const

return the number of components stored per sub-point point

const Index_t &get_nb_sub_pts() const

return the number of sub points per pixel

Index_t get_nb_dof_per_pixel() const

return the number of components stored per pixel

Index_t get_nb_pixels() const

return the number of pixels

Index_t get_nb_pixels_without_ghosts() const

return the number of pixels without ghosts

Index_t get_nb_buffer_pixels() const

return the number of pixels that are required for the buffer. This can be larger than get_nb_pixels if the buffer contains padding regions.

Index_t get_nb_entries() const

returns the number of entries held by this field. This corresponds to nb_pixels × nb_sub_pts, (I.e., a scalar field and a vector field sharing the the same collection and subdivision tag have the same number of entries, even though the vector field has more scalar values.)

Index_t get_nb_buffer_entries() const

returns the number of entries held by the buffer of this field. This corresponds to nb_buffer_pixels × nb_sub_pts, (I.e., a scalar field and a vector field sharing the the same collection have the same number of entries, even though the vector field has more scalar values.)

Shape_t get_components_shape() const

evaluate and return the shape of the data contained in a single sub-point (e.g. quadrature point) (for passing the field to generic multidimensional array objects such as numpy.ndarray)

void reshape(const Shape_t &components_shape)

Reshape the components part of the field. The total number of degrees of freedom per pixel must remain the same.

void reshape(const Shape_t &components_shape, const std::string &sub_div_tag)

Reshape component and sub-point parts of the field. The total number of degrees of freedom per pixel must remain the same.

Shape_t get_sub_pt_shape(const IterUnit &iter_type) const

evaluate and return the shape of the data contained in a single pixel (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_pixels_shape() const

evaluate and return the overall shape of the pixels portion of the field (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_pixels_shape_without_ghosts() const

evaluate and return the overall shape of the pixels portion of the field without any potential ghost buffers (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_pixels_offset_without_ghosts() const

evaluate and return the offset of the pixels in the storage without any potential ghost buffers

Shape_t get_shape(const IterUnit &iter_type) const

evaluate and return the overall shape of the field (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_shape_without_ghosts(const IterUnit &iter_type) const

evaluate and return the overall shape of the field without any potential ghost buffers (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_offsets_without_ghosts(const IterUnit &iter_type) const

evaluate and return the overall offset of the field without any potential ghost buffers (for passing the field to generic multidimensional array objects such as numpy.ndarray)

virtual Shape_t get_strides(const IterUnit &iter_type, Index_t element_size = 1) const

evaluate and return the overall strides field (for passing the field to generic multidimensional array objects such as numpy.ndarray). The multiplier can be used e.g., if strides are needed in bytes, rather than in pointer offsets.

virtual StorageOrder get_storage_order() const

Return the storage order

Index_t get_stride(const IterUnit &iter_type) const

evaluate and return the number of components in an iterate when iterating over this field

bool has_same_memory_layout(const Field &other) const

check whether two fields have the same memory layout

Index_t get_default_nb_rows(const IterUnit &iter_type) const

evaluate and return the number of rows of a default iterate over this field. Warning, this function does no sanity checks at all. It is assumed that the user called get_stride before, that all checks have been performed there, and that rechecking would be a waste of time)

Index_t get_default_nb_cols(const IterUnit &iter_type) const

evaluate and return the number of cols of a default iterate over this field. Warning, this function does no sanity checks at all. It is assumed that the user called get_stride before, that all checks have been performed there, and that rechecking would be a waste of time)

virtual TypeDescriptor get_type_descriptor() const = 0

return the unified type descriptor for this field’s element type. This can be converted to MPI_Datatype or nc_type as needed.

virtual std::size_t get_element_size_in_bytes() const = 0

return the size of the elementary field entry in bytes

void assert_type_descriptor(TypeDescriptor type_desc) const

assert that the stored type corresponds to the given type descriptor

virtual void *get_void_data_ptr(bool assert_host_memory = true) const = 0

return a pointer to the raw data

Parameters:

assert_host_memory – If true (default), throws an error if the field is on device memory. Set to false only when passing the pointer to CUDA-aware libraries (e.g., CUDA-aware MPI).

Index_t get_current_nb_entries() const

number of entries in the field (= nb_pixel × nb_sub_pts)

virtual size_t get_buffer_size() const = 0

size of the internal buffer (in scalars)

virtual void set_zero() = 0

initialise field to zero (do more complicated initialisations through fully typed maps)

bool is_global() const

checks whether this field is registered in a global FieldCollection

Dim_t get_spatial_dim() const

return the spatial dimension of the underlying discretisation grid

bool has_nb_sub_pts() const

check wether the number of pixel sub-divisions has been set

const std::string &get_sub_division_tag() const

returns a const ref to the field’s pixel sub-division type

Unit get_physical_unit() const

returns the physical unit of the values stored in the field

virtual bool is_on_device() const = 0

Check if field resides on device (GPU) memory. Returns true for CUDA and ROCm/HIP device memory spaces.

virtual int get_dlpack_device_type() const = 0

Get DLPack device type for this field’s memory space. Returns kDLCPU=1, kDLCUDA=2, kDLROCm=10, etc.

virtual int get_device_id() const = 0

Get device ID for multi-GPU systems. Returns 0 for single-GPU or CPU systems.

virtual std::string get_device_string() const = 0

Get device string for Python interoperability. Returns “cpu”, “cuda:N”, or “rocm:N” where N is the device ID.

template<typename T, typename MemorySpace>
class TypedFieldBase : public muGrid::Field

forward declaration

Subclassed by muGrid::TypedField< Scalar >, muGrid::TypedField< T, MemorySpace >

Public Types

using Memory_Space = MemorySpace

Memory space type.

using View_t = Array<T, MemorySpace>

Array type for storage.

using Scalar = T

stored scalar type

using EigenRep_t = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>

Eigen type used to represent the field’s data.

using EigenVecRep_t = Eigen::Matrix<T, Eigen::Dynamic, 1>

Eigen type used to represent the field’s data.

using Eigen_map = Eigen::Map<EigenRep_t>

eigen map (handle for EigenRep_t)

using Eigen_cmap = Eigen::Map<const EigenRep_t>

eigen const map (handle for EigenRep_t)

using EigenVec_map = Eigen::Map<EigenVecRep_t>

eigen vector map (handle for EigenVecRep_t)

using EigenVec_cmap = Eigen::Map<const EigenVecRep_t>

eigen vector const map (handle for EigenVecRep_t)

using Parent = Field

base class

Public Functions

TypedFieldBase() = delete

Default constructor.

TypedFieldBase(const TypedFieldBase &other) = delete

Copy constructor.

TypedFieldBase(TypedFieldBase &&other) = default

Move constructor.

virtual ~TypedFieldBase() = default

Destructor.

TypedFieldBase &operator=(TypedFieldBase &&other) = delete

Move assignment operator.

TypedFieldBase &operator=(const TypedFieldBase &other)

Copy assignment operator.

TypedFieldBase &operator=(const Negative &other)

Copy assignment operator.

TypedFieldBase &operator=(const EigenRep_t &other)

Copy assignment operators.

Negative operator-() const

Unary negative.

TypedFieldBase &operator+=(const TypedFieldBase &other)

addition assignment

TypedFieldBase &operator-=(const TypedFieldBase &other)

subtraction assignment

inline virtual TypeDescriptor get_type_descriptor() const final

return the unified type descriptor for this field’s element type

inline virtual std::size_t get_element_size_in_bytes() const final

return the size of the elementary field entry in bytes

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_map> eigen_mat()

return a vector map onto the underlying data (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_cmap> eigen_mat() const

return a const vector map onto the underlying data (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, EigenVec_map> eigen_vec()

return a vector map onto the underlying data (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, EigenVec_cmap> eigen_vec() const

return a const vector map onto the underlying data (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_map> eigen_sub_pt()

return a matrix map onto the underlying data with one column per quadrature point (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_cmap> eigen_sub_pt() const

return a const matrix map onto the underlying data with one column per quadrature point (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_map> eigen_pixel()

return a matrix map onto the underlying data with one column per pixel (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_cmap> eigen_pixel() const

return a const matrix map onto the underlying data with one column per pixel (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, FieldMap<T, Mapping::Mut>> get_pixel_map(const Index_t &nb_rows = Unknown)

convenience function returns a map of this field, iterable per pixel. (host-space only)

Parameters:

nb_rows – optional specification of the number of rows for the iterate. If left to default value, a matrix of shape nb_components × nb_quad_pts is used

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, FieldMap<T, Mapping::Const>> get_pixel_map(const Index_t &nb_rows = Unknown) const

convenience function returns a const map of this field, iterable per pixel. (host-space only)

Parameters:

nb_rows – optional specification of the number of rows for the iterate. If left to default value, a matrix of shape nb_components × nb_quad_pts is used

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, FieldMap<T, Mapping::Mut>> get_sub_pt_map(const Index_t &nb_rows = Unknown)

convenience function returns a map of this field, iterable per quadrature point. (host-space only)

Parameters:

nb_rows – optional specification of the number of rows for the iterate. If left to default value, a column vector is used

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, FieldMap<T, Mapping::Const>> get_sub_pt_map(const Index_t &nb_rows = Unknown) const

convenience function returns a const map of this field, iterable per quadrature point. (host-space only)

Parameters:

nb_rows – optional specification of the number of rows for the iterate. If left to default value, a column vector is used

template<typename M = MemorySpace>
inline std::enable_if_t<is_host_space_v<M>, T*> data()

Get the raw data pointer. Only available for host-space fields. Don’t use unless interfacing with external libs.

template<typename M = MemorySpace>
inline std::enable_if_t<is_host_space_v<M>, const T*> data() const

Get the raw data pointer (const). Only available for host-space fields. Don’t use unless interfacing with external libs.

virtual void *get_void_data_ptr(bool assert_host_memory = true) const final

return a pointer to the raw data. Don’t use unless interfacing with external libs.

Parameters:

assert_host_memory – If true (default), throws an error if the field is on device memory. Set to false only when passing the pointer to CUDA-aware libraries (e.g., CUDA-aware MPI).

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_map> eigen_map(const Index_t &nb_rows, const Index_t &nb_cols)

non-const eigen_map with arbitrary sizes (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_cmap> eigen_map(const Index_t &nb_rows, const Index_t &nb_cols) const

const eigen_map with arbitrary sizes (host-space only)

inline View_t &view()

Get the underlying Array for use in kernels.

inline const View_t &view() const

Get the underlying Array (const) for use in kernels.

template<typename OtherSpace>
void deep_copy_from(const TypedFieldBase<T, OtherSpace> &src)

Deep copy from another field (potentially in a different memory space). This performs a host-device or device-host transfer as needed.

inline virtual bool is_on_device() const final

Check if field resides on device (GPU) memory. Implementation uses compile-time type trait.

inline virtual int get_dlpack_device_type() const final

Get DLPack device type for this field’s memory space.

inline virtual int get_device_id() const final

Get device ID for multi-GPU systems. Returns the device ID from the field collection’s Device.

inline virtual std::string get_device_string() const final

Get device string for Python interoperability. Returns “cpu”, “cuda:N”, or “rocm:N” where N is the device ID.

template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_map> eigen_map(const Index_t &nb_rows, const Index_t &nb_cols)
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_cmap> eigen_map(const Index_t &nb_rows, const Index_t &nb_cols) const
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::EigenVec_map> eigen_vec()
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::EigenVec_cmap> eigen_vec() const
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_map> eigen_sub_pt()
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_cmap> eigen_sub_pt() const
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_map> eigen_pixel()
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_cmap> eigen_pixel() const
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_map> eigen_mat()
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_cmap> eigen_mat() const

Friends

friend class FieldMap
struct Negative

Simple structure used to allow for lazy evaluation of the unary ‘-’ sign. When assiging the the negative of a field to another, as in field_a = -field_b, this structure allows to implement this operation without needing a temporary object holding the negative value of field_b.

Public Members

const TypedFieldBase &field

field on which the unary ‘-’ was applied

class StateField

Base class for state fields, useful for storing polymorphic references

Subclassed by muGrid::TypedStateField< Scalar >, muGrid::TypedStateField< T >

Public Functions

StateField() = delete

Default constructor.

StateField(const StateField &other) = delete

Copy constructor.

StateField(StateField &&other) = delete

Move constructor.

virtual ~StateField() = default

Destructor.

StateField &operator=(const StateField &other) = delete

Copy assignment operator.

StateField &operator=(StateField &&other) = delete

Move assignment operator.

const Index_t &get_nb_memory() const

return number of old states that are stored

const Index_t &get_nb_components() const

return the number of components stored per sub-point point

const std::string &get_sub_division_tag() const

returns a const ref to the field’s pixel sub-division type

const Unit &get_physical_unit() const

returns the physical unit of the values stored in the field

virtual TypeDescriptor get_type_descriptor() const = 0

return the unified type descriptor for this state field’s element type

virtual std::size_t get_element_size_in_bytes() const = 0

return the size of the elementary field entry in bytes

void assert_type_descriptor(TypeDescriptor type_desc) const

assert that the stored type corresponds to the given type descriptor

void cycle()

cycle the fields (current becomes old, old becomes older, oldest becomes current)

Field &current()

return a reference to the field holding the current values

const Field &current() const

return a const reference to the field holding the current values

const Field &old(const size_t &nb_steps_ago = 1) const

return a reference to the field holding the values which were current nb_steps_ago ago

inline const std::vector<size_t> &get_indices() const

get the current ordering of the fields (inlineable because called in hot loop)

FieldCollection &get_collection()

get the field collection which holds all fields of the state field

const std::string &get_unique_prefix() const

get the unique prefix used for the naming of the associated fields and can be used like a name for the StateField

const RefVector<Field> &get_fields() const

return a const RefVector<Field> of fields belonging to the StateField

RefVector<Field> &set_fields()

return a mutable RefVector<Field> of fields belonging to the StateField

Domain Decomposition

Classes for parallel domain decomposition and ghost communication.

class Decomposition

Subclassed by muGrid::CartesianDecomposition

Public Functions

Decomposition() = default
virtual ~Decomposition() = default
virtual void communicate_ghosts(const Field &field) const = 0

fill the ghost buffers with the values from the neighboring processes.

virtual void communicate_ghosts(const std::string &field_name) const = 0

fill the ghost buffers with the values from the neighboring processes.

virtual void reduce_ghosts(const Field &field) const = 0

accumulate ghost buffer contributions back to the interior domain. This is the adjoint operation of communicate_ghosts and is needed for transpose operations (e.g., divergence) with periodic BCs. After the operation, ghost buffers are zeroed.

virtual void reduce_ghosts(const std::string &field_name) const = 0

accumulate ghost buffer contributions back to the interior domain.

class CartesianDecomposition : public muGrid::Decomposition

Subclassed by muGrid::FFTEngineBase

Public Types

using Parent_t = Decomposition
using SubPtMap_t = FieldCollection::SubPtMap_t

Public Functions

CartesianDecomposition(const Communicator &comm, Dim_t spatial_dimension, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())
CartesianDecomposition(const Communicator &comm, const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdivisions, const DynGridIndex &nb_ghosts_left, const DynGridIndex &nb_ghosts_right, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())
CartesianDecomposition() = delete
~CartesianDecomposition() override = default
void initialise(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdivisions, const DynGridIndex &nb_subdomain_grid_pts_without_ghosts, const DynGridIndex &subdomain_locations_without_ghosts, const DynGridIndex &nb_ghosts_left, const DynGridIndex &nb_ghosts_right, const DynGridIndex &subdomain_strides = DynGridIndex{})

initialise with known subdomains

void initialise(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdivisions, const DynGridIndex &nb_ghosts_left, const DynGridIndex &nb_ghosts_right)

initialise and determine subdomains from subdivisions

virtual void communicate_ghosts(const Field &field) const override

fill the ghost buffers with the values from the neighboring processes.

virtual void communicate_ghosts(const std::string &field_name) const override

fill the ghost buffers with the values from the neighboring processes.

virtual void reduce_ghosts(const Field &field) const override

accumulate ghost buffer contributions back to the interior domain. This is the adjoint operation of communicate_ghosts and is needed for transpose operations (e.g., divergence) with periodic BCs. After the operation, ghost buffers are zeroed.

virtual void reduce_ghosts(const std::string &field_name) const override

accumulate ghost buffer contributions back to the interior domain.

GlobalFieldCollection &get_collection()

get the field collection

const GlobalFieldCollection &get_collection() const

get the field collection

virtual Dim_t get_spatial_dim() const

get the spatial dimension

const DynGridIndex &get_nb_subdivisions() const

get the number of subdivisions

virtual const DynGridIndex &get_nb_domain_grid_pts() const

get the number of grid points of the whole domain

const DynGridIndex &get_nb_subdomain_grid_pts_with_ghosts() const

get the number of grid points per subdomain

DynGridIndex get_nb_subdomain_grid_pts_without_ghosts() const

get the number of grid points per subdomain

const DynGridIndex &get_subdomain_locations_with_ghosts() const

get the subdomain locations

DynGridIndex get_subdomain_locations_without_ghosts() const

get the subdomain locations

inline const DynGridIndex &get_nb_ghosts_left() const

get the number of ghost cells on the left side

inline const DynGridIndex &get_nb_ghosts_right() const

get the number of ghost cells on the right side

inline bool is_on_device() const

check if fields in this decomposition are on device (GPU) memory

inline Device get_device() const

get the device of the field collection

class Communicator

stub communicator object that doesn’t communicate anything

Subclassed by muGrid::CartesianCommunicator

Public Functions

inline Communicator()
inline ~Communicator()
inline int rank() const

get rank of present process

inline int size() const

get total number of processes

inline void barrier()

Barrier syncronization, nothing to be done in serial.

template<typename T>
inline T sum(const T &arg) const

sum reduction on scalar types

template<typename T>
inline DynMatrix_t<T> sum(const Eigen::Ref<DynMatrix_t<T>> &arg) const

sum on EigenMatrix types

template<typename T>
inline T max(const T &arg) const

max reduction on scalar types

template<typename T>
inline T cumulative_sum(const T &arg) const

ordered partial cumulative sum on scalar types. Find more details in the doc of the into the parallel implementation.

template<typename T>
inline T gather(const T &arg) const

gather on scalar types

template<typename T>
inline DynMatrix_t<T> gather(const Eigen::Ref<DynMatrix_t<T>> &arg) const

gather on EigenMatrix types

template<typename T>
inline T bcast(T &arg, const Int&)

broadcast of scalar types

inline bool all(const bool &arg) const

return logical and

inline bool any(const bool &arg) const

return logical or

Public Static Functions

static inline bool has_mpi()

find whether the underlying communicator is mpi

Operators

Discrete operators for stencil-based computations like gradients and the Laplacian.

Warning

doxygenclass: Cannot find class “muGrid::ConvolutionOperatorBase” in doxygen xml output for project “libmugrid” from directory: ../xml

Warning

doxygenclass: Cannot find class “muGrid::ConvolutionOperator” in doxygen xml output for project “libmugrid” from directory: ../xml

Warning

doxygenclass: Cannot find class “muGrid::LaplaceOperator” in doxygen xml output for project “libmugrid” from directory: ../xml

Warning

doxygenclass: Cannot find class “muGrid::FEMGradientOperator” in doxygen xml output for project “libmugrid” from directory: ../xml

FFT Engine

Distributed FFT operations using pencil decomposition.

class FFTEngineBase : public muGrid::CartesianDecomposition

Non-templated base class for FFTEngine.

This class contains all the domain decomposition logic, MPI setup, transpose configurations, and field collection management. It is inherited by the templated FFTEngine<MemorySpace> which adds the memory-space-specific FFT execution logic.

Subclassed by muGrid::FFTEngine< MemorySpace >

Public Types

using Parent_t = CartesianDecomposition
using SubPtMap_t = FieldCollection::SubPtMap_t

Public Functions

FFTEngineBase(const DynGridIndex &nb_domain_grid_pts, const Communicator &comm = Communicator(), const DynGridIndex &nb_ghosts_left = DynGridIndex{}, const DynGridIndex &nb_ghosts_right = DynGridIndex{}, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())

Construct an FFT engine base with pencil decomposition.

Parameters:
  • nb_domain_grid_pts – Global grid dimensions [Nx, Ny] or [Nx, Ny, Nz]

  • comm – MPI communicator (default: serial)

  • nb_ghosts_left – Ghost cells on low-index side of each dimension

  • nb_ghosts_right – Ghost cells on high-index side of each dimension

  • nb_sub_pts – Number of sub-points per pixel (optional)

  • device – Where to allocate field memory

FFTEngineBase() = delete
FFTEngineBase(const FFTEngineBase&) = delete
FFTEngineBase(FFTEngineBase&&) = delete
~FFTEngineBase() override = default
FFTEngineBase &operator=(const FFTEngineBase&) = delete
FFTEngineBase &operator=(FFTEngineBase&&) = delete
virtual void fft(const Field &input, Field &output) = 0

Forward FFT: real space -> Fourier space.

virtual void ifft(const Field &input, Field &output) = 0

Inverse FFT: Fourier space -> real space.

Field &register_real_space_field(const std::string &name, Index_t nb_components = 1)

Register a new real-space field. Throws if field already exists.

Field &register_real_space_field(const std::string &name, const Shape_t &components)
Field &register_fourier_space_field(const std::string &name, Index_t nb_components = 1)

Register a new Fourier-space field. Throws if field already exists.

Field &register_fourier_space_field(const std::string &name, const Shape_t &components)
Field &real_space_field(const std::string &name, Index_t nb_components = 1)

Get or create a real-space field. Returns existing field if present.

Field &real_space_field(const std::string &name, const Shape_t &components)
Field &fourier_space_field(const std::string &name, Index_t nb_components = 1)

Get or create a Fourier-space field. Returns existing field if present.

Field &fourier_space_field(const std::string &name, const Shape_t &components)
GlobalFieldCollection &get_real_space_collection()
const GlobalFieldCollection &get_real_space_collection() const
GlobalFieldCollection &get_fourier_space_collection()
const GlobalFieldCollection &get_fourier_space_collection() const
inline Real normalisation() const
inline const DynGridIndex &get_nb_fourier_grid_pts() const
inline const DynGridIndex &get_nb_fourier_subdomain_grid_pts() const
inline const DynGridIndex &get_fourier_subdomain_locations() const
inline std::array<int, 2> get_process_grid() const
inline std::array<int, 2> get_process_coords() const
virtual const char *get_backend_name() const = 0

Get the name of the FFT backend being used.

template<typename MemorySpace>
class FFTEngine : public muGrid::FFTEngineBase

Distributed FFT engine using pencil (2D) decomposition.

This class provides distributed FFT operations on structured grids with MPI parallelization. It uses pencil decomposition which allows efficient scaling to large numbers of ranks.

Key features:

  • Supports 2D and 3D grids

  • Handles arbitrary ghost buffer configurations in real space

  • No ghosts in Fourier space (hard assumption)

  • Compile-time memory space selection (Host, CUDA, HIP)

  • Unnormalized transforms (like FFTW)

The engine owns field collections for both real and Fourier space, and work buffers for intermediate results during the distributed FFT.

Template Parameters:

MemorySpace – The memory space for work buffers (HostSpace, CUDASpace, ROCmSpace)

Public Types

using Parent_t = FFTEngineBase
using WorkBuffer = Array<Complex, MemorySpace>

Public Functions

inline FFTEngine(const DynGridIndex &nb_domain_grid_pts, const Communicator &comm = Communicator(), const DynGridIndex &nb_ghosts_left = DynGridIndex{}, const DynGridIndex &nb_ghosts_right = DynGridIndex{}, const SubPtMap_t &nb_sub_pts = {}, Device device = memory_space_to_device<MemorySpace>())

Construct an FFT engine with pencil decomposition.

Parameters:
  • nb_domain_grid_pts – Global grid dimensions [Nx, Ny] or [Nx, Ny, Nz]

  • comm – MPI communicator (default: serial)

  • nb_ghosts_left – Ghost cells on low-index side of each dimension

  • nb_ghosts_right – Ghost cells on high-index side of each dimension

  • nb_sub_pts – Number of sub-points per pixel (optional)

  • deviceDevice for field memory allocation (optional, default uses memory space’s default device)

FFTEngine() = delete
FFTEngine(const FFTEngine&) = delete
FFTEngine(FFTEngine&&) = delete
~FFTEngine() override = default
FFTEngine &operator=(const FFTEngine&) = delete
FFTEngine &operator=(FFTEngine&&) = delete
inline virtual void fft(const Field &input, Field &output) override

Forward FFT: real space -> Fourier space.

inline virtual void ifft(const Field &input, Field &output) override

Inverse FFT: Fourier space -> real space.

inline virtual const char *get_backend_name() const override

Get the name of the FFT backend being used.

File I/O

Classes for reading and writing fields to disk in NetCDF format.

class FileIOBase

A virtual base class for FileIO classes.

This class provides a common interface for file input/output operations. It defines an enumeration for open modes (Read, Write, Append) and provides a set of constructors and assignment operators (both copy and move are deleted). It also provides a virtual destructor and a random access operator.

Note

This class cannot be instantiated directly (default constructor is deleted).

Subclassed by muGrid::FileIONetCDF

Public Types

enum class OpenMode

Enumeration for file open modes.

This enumeration defines the possible modes for opening a file:

  • Read: File is opened for reading only. This mode is used when the data in the file is only needed for input and will not be modified.

  • Write: File is opened for writing only. This mode is used when new data is to be written to a file. If the file already exists, this mode will fail to prevent accidental data loss.

  • Overwrite: File is opened for writing only. This mode is used when new data is to be written to a file. If the file already exists, it will be overwritten. Use this mode with caution to prevent accidental data loss.

  • Append: File is opened for writing only. This mode is used when new data is to be added to the end of a file. If the file already exists, the new data will be added at the end, preserving the existing data.

Values:

enumerator Read
enumerator Write
enumerator Overwrite
enumerator Append

Public Functions

FileIOBase() = delete

Default constructor is deleted to prevent direct instantiation of this class without parameters.

FileIOBase(const std::string &file_name, const OpenMode &open_mode, Communicator comm = Communicator())

Constructor with file name, open mode, and communicator.

This constructor initializes a FileIOBase object with the given file name, open mode, and communicator.

Parameters:
  • file_name – The name of the file to be opened.

  • open_mode – The mode to open the file in (Read, Write, or Append).

  • comm – The communicator to be used for parallel I/O operations (default is a default-constructed Communicator object).

FileIOBase(const FileIOBase &other) = delete

Copy constructor is deleted to prevent copying of FileIOBase objects.

FileIOBase(FileIOBase &&other) = delete

Move constructor is deleted to prevent moving of FileIOBase objects.

virtual ~FileIOBase() = default

Virtual destructor.

FileIOBase &operator=(const FileIOBase &other) = delete

Copy assignment operator is deleted to prevent copying of FileIOBase objects.

FileIOBase &operator=(FileIOBase &&other) = delete

Move assignment operator is deleted to prevent moving of FileIOBase objects.

FileFrame operator[](const Index_t &frame_index)

Random access operator.

This operator provides access to a specific frame in the file. The frame must exist for this operation to succeed.

Parameters:

frame_index – The index of the frame to access.

Returns:

FileFrame The requested frame.

virtual void register_field_collection(muGrid::FieldCollection &fc, std::vector<std::string> field_names = {REGISTER_ALL_FIELDS}, std::vector<std::string> state_field_unique_prefixes = {REGISTER_ALL_STATE_FIELDS}) = 0

Register a field collection to be dumped to the file.

This function should be called before the file is opened. If no field names are given, all fields of the given field collection are registered by default.

Parameters:
  • fc – The field collection to be registered.

  • field_names – The names of the fields to be registered. Default is all fields.

  • state_field_unique_prefixes – The unique prefixes of the state fields to be registered. Default is all state fields.

virtual void close() = 0

Close the file.

virtual void read(const Index_t &frame, const std::vector<std::string> &field_names) = 0

Read the fields identified by field_names from a specific frame in the file.

Parameters:
  • frame – The frame to read from.

  • field_names – The names of the fields to read.

virtual void read(const Index_t &frame) = 0

Read all registered fields from a specific frame in the file.

Parameters:

frame – The frame to read from.

virtual void write(const Index_t &frame, const std::vector<std::string> &field_names) = 0

Write the contents of all fields identified by field_names within the field collection to a specific frame in the file.

Parameters:
  • frame – The frame to write to.

  • field_names – The names of the fields to write.

virtual void write(const Index_t &frame) = 0

Write the contents of all fields within the field collection to a specific frame in the file.

Parameters:

frame – The frame to write to.

FileFrame append_frame()

Yield an empty file frame at the end of the file.

Returns:

FileFrame The empty file frame.

Communicator &get_communicator()

Get the communicator object.

Returns:

Communicator& The communicator object.

iterator begin()

Get an iterator pointing to the first frame in the file.

Returns:

iterator An iterator pointing to the first frame.

iterator end()

Get an iterator pointing one past the last frame in the file.

Returns:

iterator An iterator pointing one past the last frame.

size_t size() const

Get the number of frames in the file.

Returns:

size_t The number of frames.

class iterator

A class for iterating over the frames in the file.

This class provides a common interface for file frame iteration operations. It provides a set of constructors and assignment operators (both copy and move are deleted). It also provides a destructor and methods for dereferencing and incrementing.

Note

This class cannot be instantiated directly (default constructor is deleted).

Public Types

using value_type = FileFrame

STL type aliases for iterator conformance.

using const_value_type = const value_type

STL conformance.

using pointer = value_type*

STL conformance.

using difference_type = std::ptrdiff_t

STL conformance.

using iterator_category = std::forward_iterator_tag

STL conformance.

Public Functions

iterator() = delete

Default constructor is deleted to prevent direct instantiation of this class without parameters.

inline explicit iterator(FileIOBase &parent, Index_t frame_index = 0)

Constructor with the FileIOBase object and the required frame index.

This constructor initializes an iterator object with the given FileIOBase object and frame index.

Parameters:
  • parent – The FileIOBase object.

  • frame_index – The frame index.

iterator(const iterator &other) = default

Copy constructor.

iterator(iterator &&other) = default

Move constructor.

~iterator() = default

Destructor.

iterator &operator=(const iterator &other) = delete

Copy assignment operator is deleted to prevent copying of iterator objects.

iterator &operator=(iterator &&other) = delete

Move assignment operator is deleted to prevent moving of iterator objects.

inline const_value_type operator*() const

Dereferencing operator.

This operator provides access to a specific frame in the file. The frame must exist for this operation to succeed.

Returns:

const_value_type The requested frame.

inline iterator &operator++()

Pre-increment operator.

This operator increments the frame index by one.

Returns:

iterator& A reference to the incremented iterator.

inline bool operator==(const iterator &other) const

Equality comparison operator.

This operator checks if the frame index of the current iterator is equal to that of the other iterator.

Parameters:

other – The other iterator to compare with.

Returns:

bool True if the frame indices are equal, false otherwise.

inline bool operator!=(const iterator &other) const

Inequality comparison operator.

This operator checks if the frame index of the current iterator is not equal to that of the other iterator.

Parameters:

other – The other iterator to compare with.

Returns:

bool True if the frame indices are not equal, false otherwise.

class FileIONetCDF : public muGrid::FileIOBase

A class for handling NetCDF files in the µGrid codebase.

This class inherits from the FileIOBase class and provides specific functionality for handling NetCDF files. NetCDF (Network Common Data Format) is a self-describing, machine-independent data format that support the creation, access, and sharing of array-oriented scientific data.

Public Types

enum class NetCDFMode

Values:

enumerator UndefinedMode
enumerator DefineMode
enumerator DataMode

Public Functions

FileIONetCDF() = delete

Default constructor.

FileIONetCDF(const std::string &file_name, const FileIOBase::OpenMode &open_mode, Communicator comm = Communicator())

Constructs a new FileIONetCDF object.

This constructor creates a new FileIONetCDF object with the specified file name, open mode, and communicator. The FileIONetCDF class is used for handling NetCDF files in the µGrid codebase.

Parameters:
  • file_name – The name of the file to be handled. This should be a valid file path.

  • open_mode – The mode in which the file should be opened. This should be a valid mode from the FileIOBase::OpenMode enumeration.

  • comm – The communicator to be used for parallel I/O operations. If not provided, a default Communicator object is used.

FileIONetCDF(const FileIONetCDF &other) = delete

Copy constructor (deleted)

This copy constructor is deleted to prevent copying of FileIONetCDF objects.

Parameters:

other – The other FileIONetCDF object to be copied.

FileIONetCDF(FileIONetCDF &&other) = delete

Move constructor (deleted)

This move constructor is deleted to prevent moving of FileIONetCDF objects.

Parameters:

other – The other FileIONetCDF object to be moved.

virtual ~FileIONetCDF()

Destructor.

This is the destructor for the FileIONetCDF class. It is responsible for freeing any resources that the object may have acquired during its lifetime.

FileIONetCDF &operator=(const FileIONetCDF &other) = delete

Copy assignment operator (deleted)

This copy assignment operator is deleted to prevent copying of FileIONetCDF objects.

Parameters:

other – The other FileIONetCDF object to be copied.

Returns:

A reference to the current object.

FileIONetCDF &operator=(FileIONetCDF &&other) = delete

Move assignment operator (deleted)

This move assignment operator is deleted to prevent moving of FileIONetCDF objects.

Parameters:

other – The other FileIONetCDF object to be moved.

Returns:

A reference to the current object.

virtual void register_field_collection(muGrid::FieldCollection &fc, std::vector<std::string> field_names = {REGISTER_ALL_FIELDS}, std::vector<std::string> state_field_unique_prefixes = {REGISTER_ALL_STATE_FIELDS}) final

Registers the field collections that should be written to the file.

This function should be called before the file is opened. It allows the user to specify which fields from the field collection should be saved in the NetCDF file.

Parameters:
  • fc – The field collection to be registered.

  • field_names – A vector of names of fields from the field collection that should be saved in the NetCDF file. This parameter should be used if not all fields from the field collection will be written to the file (default case).

  • state_field_unique_prefixes – A vector of unique prefixes for state fields.

virtual void close() final

Closes the file.

This function is used to close the NetCDF file after all operations are done.

virtual void read(const Index_t &frame, const std::vector<std::string> &field_names) final

Reads the specified fields from the file.

This function reads the fields identified by field_names from the specified frame in the file.

Parameters:
  • frame – The frame from which to read the fields.

  • field_names – A vector of names of fields to be read from the file.

virtual void read(const Index_t &frame) final

Reads all fields from the specified frame in the file.

This function reads all fields from the specified frame in the file.

Parameters:

frame – The frame from which to read the fields.

virtual void write(const Index_t &frame, const std::vector<std::string> &field_names) final

Writes the specified fields to the file.

This function writes the contents of all fields within the field collection with the name in field_names to the specified frame in the file.

Parameters:
  • frame – The frame to which to write the fields.

  • field_names – A vector of names of fields to be written to the file.

virtual void write(const Index_t &frame) final

Writes all fields to the file.

This function writes the contents of all fields within the field collection to the specified frame in the file.

Parameters:

frame – The frame to which to write the fields.

Index_t handle_frame(Index_t frame) const

Checks if the frame is valid and computes the corresponding positive frame value for a negative frame value.

This function checks if the frame is valid and computes the corresponding positive frame value for a negative frame value. For example, if the total number of frames is 5:

  • If the input frame is -3, the output frame is 2.

  • If the input frame is 3, the output frame is 3.

  • If the input frame is 7 or -6, an error is thrown.

Parameters:

frame – The frame to be checked and converted. This can be a positive or negative integer.

Throws:

FileIOError – If the input frame is not valid (i.e., it is greater than the total number of frames or less than the negative of the total number of frames).

Returns:

The corresponding positive frame value for the input frame.

template<class T>
inline void write_global_attribute(const std::string &att_name, T value)

Registers a global attribute to the NetCDF file.

This function can only be used in open_mode = FileIOBase::OpenMode::Write or FileIOBase::OpenMode::Overwrite and before write() was called the first time. Otherwise, there is the danger of having time expensive NetCDF header expansions, which is the reason why this is prevented.

Template Parameters:

T – The type of the value to be written as a global attribute.

Parameters:
  • att_name – The name of the attribute.

  • value – The value of the attribute.

Throws:

FileIOError – If the global attributes are already defined or if the open mode is not Write.

const NetCDFGlobalAtt &read_global_attribute(const std::string &att_name) const

Retrieves a global attribute from the NetCDF file by its name.

This function is used to fetch a global attribute from the NetCDF file. The attribute is identified by its name.

Parameters:

att_name – The name of the attribute.

Returns:

A constant reference to the NetCDFGlobalAtt object representing the global attribute.

const std::vector<std::string> read_global_attribute_names() const

Retrieves the names of all current global attributes in the NetCDF file.

This function is used to fetch the names of all global attributes present in the NetCDF file.

Returns:

A constant vector of strings containing the names of all current global attributes.

template<class T>
inline void update_global_attribute(const std::string &old_att_name, const std::string &new_att_name, T new_att_value)

Updates the value or name of an existing global attribute in the NetCDF file.

This function can only be used in open_mode = FileIOBase::OpenMode::Write, FileIOBase::OpenMode::Overwrite or FileIOBase::OpenMode::Append. The changes are only allowed if they do not lead to an increase in the size of the global attribute and the data_type of the attribute is not changed.

Template Parameters:

T – The type of the new value for the global attribute.

Parameters:
  • old_att_name – The current name of the attribute.

  • new_att_name – The new name for the attribute.

  • new_att_value – The new value for the attribute.

Throws:

FileIOError – If the function is called in a mode other than Write or Append, or if the attribute was not previously written to the NetCDF file.

Public Static Functions

static Index_t handle_frame(Index_t frame, Index_t tot_nb_frames)

Checks if the frame is valid and computes the corresponding positive frame value for a negative frame value (static version).

This is a static version of the handle_frame function. It performs the same operation but takes an additional parameter for the total number of frames.

Parameters:
  • frame – The frame to be checked and converted. This can be a positive or negative integer.

  • tot_nb_frames – The total number of frames.

Throws:

FileIOError – If the input frame is not valid (i.e., it is greater than the total number of frames or less than the negative of the total number of frames).

Returns:

The corresponding positive frame value for the input frame.

Public Static Attributes

static constexpr int MAX_NB_ATTRIBUTES{10}
static constexpr int MAX_LEN_ATTRIBUTE_NAME{NC_MAX_NAME}
static constexpr int MAX_NB_GLOBAL_ATTRIBUTES{30}
static constexpr int MAX_LEN_GLOBAL_ATTRIBUTE_NAME{NC_MAX_NAME}

Core Types

Fundamental types and enumerations used throughout the library.

Warning

doxygentypedef: Cannot find typedef “muGrid::Real” in doxygen xml output for project “libmugrid” from directory: ../xml

Warning

doxygentypedef: Cannot find typedef “muGrid::Complex” in doxygen xml output for project “libmugrid” from directory: ../xml

Warning

doxygentypedef: Cannot find typedef “muGrid::Int” in doxygen xml output for project “libmugrid” from directory: ../xml

Warning

doxygentypedef: Cannot find typedef “muGrid::Uint” in doxygen xml output for project “libmugrid” from directory: ../xml

Warning

doxygentypedef: Cannot find typedef “muGrid::Index_t” in doxygen xml output for project “libmugrid” from directory: ../xml

enum class muGrid::IterUnit

An enumeration class for iteration units.

This enumeration class is used in two contexts within the µGrid codebase. Firstly, it is used in Fields to specify the relative storage of data with respect to pixels, quadrature points, or nodal points. Secondly, it is used in FieldMaps to specify the unit of iteration, whether it be over pixels, quadrature points, or nodal points.

Values:

enumerator Pixel

dofs relative to a pixel/voxel, no subdivision

enumerator SubPt

dofs relative to sub-points (e.g. quadrature points)

enum class muGrid::StorageOrder

An enumeration class for storage orders of field components.

This enumeration class defines three types of storage orders: ArrayOfStructures, StructureOfArrays and Automatic. These storage orders can be used to determine the order in which field components are stored in memory.

Values:

enumerator ArrayOfStructures

components are consecutive in memory

enumerator StructureOfArrays
enumerator Automatic

inherit storage order from FieldCollection

Grid Utilities

Utilities for working with grid coordinates and indices.

Warning

doxygenfunction: Cannot find function “muGrid::get_domain_ccoord” in doxygen xml output for project “libmugrid” from directory: ../xml

Warning

doxygenfunction: Cannot find function “muGrid::get_domain_index” in doxygen xml output for project “libmugrid” from directory: ../xml

FFT Utilities

Low-level utilities for computing FFT frequencies. In Python, use the fftfreq and ifftfreq properties on FFTEngine instead.

std::vector<Real> muGrid::fft_freq(Index_t n, Real d)

Compute the frequency values for a full c2c FFT.

Returns frequencies in cycles per unit spacing: f = k / (n * d) where k is the frequency index from fft_freqind.

This is equivalent to numpy.fft.fftfreq(n, d).

Parameters:
  • n – Number of points in the transform

  • d – Sample spacing (default 1.0)

Returns:

Vector of frequency values

inline Int muGrid::fft_freqind(Index_t i, Index_t n)

Compute the frequency bin index for a single position in a full c2c FFT.

Maps position i (0 <= i < n) to frequency index:

  • For i < (n+1)/2: returns i

  • For i >= (n+1)/2: returns i - n

Parameters:
  • i – Position in the FFT output (0 <= i < n)

  • n – Number of points in the transform

Returns:

Frequency index for position i

std::vector<Int> muGrid::fft_freqind(Index_t n)

Compute the frequency bin indices for a full c2c FFT.

For n samples, returns indices [0, 1, …, n/2-1, -n/2, …, -1] for even n, or [0, 1, …, (n-1)/2, -(n-1)/2, …, -1] for odd n.

This is equivalent to numpy.fft.fftfreq(n) * n.

Parameters:

n – Number of points in the transform

Returns:

Vector of integer frequency indices

std::vector<Real> muGrid::rfft_freq(Index_t n, Real d)

Compute the frequency values for a r2c (half-complex) FFT.

Returns frequencies in cycles per unit spacing: f = k / (n * d) where k is the frequency index from rfft_freqind.

This is equivalent to numpy.fft.rfftfreq(n, d).

Parameters:
  • n – Number of real input points

  • d – Sample spacing (default 1.0)

Returns:

Vector of frequency values (length n/2+1)

std::vector<Int> muGrid::rfft_freqind(Index_t n)

Compute the frequency bin indices for a r2c (half-complex) FFT.

For n real input samples, the r2c transform produces n/2+1 complex outputs. Returns indices [0, 1, …, n/2].

This is equivalent to numpy.fft.rfftfreq(n) * n.

Parameters:

n – Number of real input points

Returns:

Vector of integer frequency indices (length n/2+1)

Real muGrid::fft_normalization(const DynGridIndex &nb_grid_pts)

Compute the normalization factor for FFT roundtrip.

For an unnormalized FFT, ifft(fft(x)) = N * x where N is the total number of grid points. This returns 1/N for normalizing the result.

Parameters:

nb_grid_pts – Grid dimensions

Returns:

Normalization factor (1.0 / total_grid_points)

DynGridIndex muGrid::get_hermitian_grid_pts(const DynGridIndex &nb_grid_pts, Index_t r2c_axis)

Compute the Fourier grid dimensions for a half-complex r2c transform.

For a real-space grid of size [Nx, Ny, Nz], the half-complex Fourier grid has size [Nx/2+1, Ny, Nz] (for the first axis being the r2c axis).

Parameters:
  • nb_grid_pts – Real-space grid dimensions

  • r2c_axis – Axis along which r2c transform is performed (default 0)

Returns:

Fourier-space grid dimensions

Full Index

For a complete listing of all classes, functions, and types:

template<typename T>
struct add_vec

Public Types

using type = vtype_t<T>
template<typename T>
struct add_vec<cmplx<T>>

Public Types

using type = cmplx<vtype_t<T>>
template<typename T>
struct aligned_allocator

Public Types

using value_type = T

Public Functions

template<class U>
inline aligned_allocator(const aligned_allocator<U>&)
aligned_allocator() = default
inline T *allocate(size_t n)
inline void deallocate(T *p, size_t)
template<typename T, typename MemorySpace>
struct AllocatorSelector
#include <array.hh>

Type trait to select the correct allocator for a memory space

Public Types

using type = HostAllocator<T>
template<typename T>
class arr

Public Functions

inline arr()
inline arr(size_t n)
inline arr(arr &&other)
inline ~arr()
inline void resize(size_t n)
inline T &operator[](size_t idx)
inline const T &operator[](size_t idx) const
inline T *data()
inline const T *data() const
inline size_t size() const

Private Members

T *p
size_t sz

Private Static Functions

static inline T *ralloc(size_t num)
static inline void dealloc(T *ptr)
class arr_info

Subclassed by pocketfft::detail::cndarr< T >

Public Functions

inline arr_info(const shape_t &shape_, const stride_t &stride_)
inline size_t ndim() const
inline size_t size() const
inline const shape_t &shape() const
inline size_t shape(size_t i) const
inline const stride_t &stride() const
inline const ptrdiff_t &stride(size_t i) const

Protected Attributes

shape_t shp
stride_t str
template<typename T, typename MemorySpace = HostSpace>
class Array
#include <array.hh>

GPU-portable 1D array class.

This class provides a simple interface for managing arrays in different memory spaces (host, CUDA, HIP).

Template Parameters:
  • T – Element type

  • MemorySpace – Memory space tag (HostSpace, CUDASpace, ROCmSpace, etc.)

Public Types

using value_type = T
using memory_space = MemorySpace
using allocator_type = detail::Allocator<T, MemorySpace>

Public Functions

inline Array()

Default constructor - creates empty array

inline explicit Array(const std::string&)

Constructor with label (for debugging) - creates empty array

inline explicit Array(std::size_t n)

Constructor that allocates n elements

inline Array(const std::string&, std::size_t n)

Constructor with label and size

inline ~Array()

Destructor - frees memory

Array(const Array&) = delete
Array &operator=(const Array&) = delete
inline Array(Array &&other) noexcept
inline Array &operator=(Array &&other) noexcept
inline T *data()

Get raw pointer to data

inline const T *data() const
inline std::size_t size() const

Get number of elements

inline bool empty() const

Check if array is empty

inline void resize(std::size_t new_size)

Resize the array, reallocating if necessary. Note: Does NOT preserve existing data (unlike std::vector).

inline void fill_zero()

Set all bytes to zero

template<typename M = MemorySpace>
inline std::enable_if_t<is_host_space_v<M>, T&> operator[](std::size_t i)

Element access (host-space only)

template<typename M = MemorySpace>
inline std::enable_if_t<is_host_space_v<M>, const T&> operator[](std::size_t i) const

Private Members

T *data_
std::size_t size_
template<Dim_t Rank>
struct AxisTransformer
template<>
struct AxisTransformer<firstOrder>

Public Static Functions

template<class T1, class T2>
static inline decltype(auto) push_forward(const Eigen::MatrixBase<T1> &t1, const Eigen::MatrixBase<T2> &F)
template<class T1, class T2>
static inline decltype(auto) pull_back(const Eigen::MatrixBase<T1> &t1, const Eigen::MatrixBase<T2> &F)
template<>
struct AxisTransformer<fourthOrder>

Public Static Functions

template<class T4, class T2>
static inline decltype(auto) push_forward(const Eigen::MatrixBase<T4> &t4, const Eigen::MatrixBase<T2> &F)
template<class T4, class T2>
static inline decltype(auto) pull_back(const Eigen::MatrixBase<T4> &t4, const Eigen::MatrixBase<T2> &F)
template<>
struct AxisTransformer<secondOrder>

Public Static Functions

template<class T2, class T2_F>
static inline decltype(auto) push_forward(const Eigen::MatrixBase<T2> &t2, const Eigen::MatrixBase<T2_F> &F)
template<class T2, class T2_F>
static inline decltype(auto) pull_back(const Eigen::MatrixBase<T2> &t2, const Eigen::MatrixBase<T2_F> &F)
struct CachedPlan
#include <rocfft_backend.hh>

Cached plan with associated execution info.

Public Members

rocfft_plan plan
rocfft_execution_info info
void *work_buffer
size_t work_buffer_size
class CartesianCommunicator : public muGrid::Communicator

Manages communication for Cartesian domain decomposition on structured grids.

This class provides MPI-based communication abstractions for distributed memory parallelization on Cartesian grids. It creates a Cartesian MPI topology, automatically computing neighbor ranks and allowing efficient halo/boundary exchange along each spatial dimension.

The class distinguishes between left and right neighbors: in a given direction, the left neighbor is at coordinate[direction] - 1 and the right neighbor is at coordinate[direction] + 1. With periodic boundaries, these wrap around at the domain edges.

For efficient structured grid stencil operations, the class provides:

  • Template methods for scalar value exchange (sendrecv_left/sendrecv_right)

  • Bulk data transfer methods that handle complex memory layouts via MPI derived types

Public Types

using Parent_t = Communicator

Public Functions

explicit CartesianCommunicator(const Parent_t &parent, const DynGridIndex &nb_subdivisions)

Constructor for a Cartesian communicator with automatic topology creation.

Initializes a CartesianCommunicator with the parent communicator and the number of subdivisions in each spatial direction. This constructor creates a Cartesian MPI topology with periodic boundaries in all directions. The Cartesian communicator automatically computes this rank’s coordinates and the ranks of its left and right neighbors in each dimension.

Parameters:
  • parent – The parent communicator from which the MPI communicator is derived.

  • nb_subdivisions – The number of subdivisions (ranks) in each spatial direction. The product of all elements must equal the size of the parent communicator.

Throws:

RuntimeError – if the product of nb_subdivisions does not match the communicator size.

explicit CartesianCommunicator(const Parent_t &parent, const DynGridIndex &nb_subdivisions, const DynGridIndex &coordinates, const std::vector<int> &left_ranks, const std::vector<int> &right_ranks)

Construct a Cartesian communicator with explicit topology.

This constructor initializes a CartesianCommunicator object with pre-computed coordinates and neighbor ranks. This is useful for reconstructing a CartesianCommunicator from previously computed decomposition information or for testing purposes.

Parameters:
  • parent – The parent communicator from which the MPI communicator is derived.

  • nb_subdivisions – The number of subdivisions (ranks) in each spatial direction.

  • coordinates – The Cartesian coordinates (0-indexed) of this rank within the decomposition. Must be consistent with the parent communicator’s rank.

  • left_ranks – A vector of neighbor ranks to the left (lower coordinate) in each spatial dimension. Use MPI_PROC_NULL for boundaries (in periodic mode, wraps to the opposite side).

  • right_ranks – A vector of neighbor ranks to the right (higher coordinate) in each spatial dimension. Use MPI_PROC_NULL for boundaries (in periodic mode, wraps to the opposite side).

CartesianCommunicator() = delete
inline virtual ~CartesianCommunicator()
CartesianCommunicator &operator=(const CartesianCommunicator &other)

Assignment operator.

Assigns the MPI communicator from another CartesianCommunicator. Note that other members (nb_subdivisions, coordinates, ranks) are not copied.

Parameters:

other – The CartesianCommunicator to copy the communicator from.

Returns:

Reference to this CartesianCommunicator.

const DynGridIndex &get_nb_subdivisions() const

Get the number of subdivisions in each spatial dimension.

Returns:

Const reference to the vector of subdivision counts.

const DynGridIndex &get_coordinates() const

Get the Cartesian coordinates of this rank.

Returns the 0-indexed coordinates of this rank in the Cartesian topology grid.

Returns:

Const reference to the vector of coordinates.

void sendrecv_right(int direction, int block_stride, int nb_send_blocks, int send_block_len, Index_t send_offset, int nb_recv_blocks, int recv_block_len, Index_t recv_offset, char *data, int stride_in_direction, int elem_size_in_bytes, TypeDescriptor type_desc, bool is_device_memory = false) const

Send data to the right neighbor; receive from the left.

Performs a synchronous send-receive operation using MPI derived types to handle non-contiguous memory layouts. Data is sent to the right neighbor (higher coordinate) and received from the left neighbor (lower coordinate) in the specified spatial dimension. The MPI derived type efficiently describes strided block data.

Parameters:
  • direction – The spatial dimension in which to communicate (0 <= direction < spatial_dim).

  • block_stride – Stride to the next block in the next dimension (in elements).

  • nb_send_blocks – Number of blocks to send.

  • send_block_len – Length of each contiguous block to send (in elements).

  • send_offset – Offset of the first block in the send buffer (in blocks, computed as offset * stride_in_direction).

  • nb_recv_blocks – Number of blocks to receive.

  • recv_block_len – Length of each contiguous block to receive (in elements).

  • recv_offset – Offset of the first block in the receive buffer (in blocks, computed as offset * stride_in_direction).

  • data – Base address of the data buffer.

  • stride_in_direction – Stride in the communication direction (in elements).

  • elem_size_in_bytes – Size of each element in bytes.

  • type_desc – TypeDescriptor identifying the element type. Used for MPI type conversion; ignored in serial mode.

  • is_device_memory – If true, data resides on GPU device memory. Used in serial mode to select appropriate memory copy method (CUDA/HIP for GPU).

void sendrecv_left(int direction, int block_stride, int nb_send_blocks, int send_block_len, Index_t send_offset, int nb_recv_blocks, int recv_block_len, Index_t recv_offset, char *data, int stride_in_direction, int elem_size_in_bytes, TypeDescriptor type_desc, bool is_device_memory = false) const

Send data to the left neighbor; receive from the right.

Performs a synchronous send-receive operation using MPI derived types to handle non-contiguous memory layouts. Data is sent to the left neighbor (lower coordinate) and received from the right neighbor (higher coordinate) in the specified spatial dimension. The MPI derived type efficiently describes strided block data.

Parameters:
  • direction – The spatial dimension in which to communicate (0 <= direction < spatial_dim).

  • block_stride – Stride to the next block in the next dimension (in elements).

  • nb_send_blocks – Number of blocks to send.

  • send_block_len – Length of each contiguous block to send (in elements).

  • send_offset – Offset of the first block in the send buffer (in blocks, computed as offset * stride_in_direction).

  • nb_recv_blocks – Number of blocks to receive.

  • recv_block_len – Length of each contiguous block to receive (in elements).

  • recv_offset – Offset of the first block in the receive buffer (in blocks, computed as offset * stride_in_direction).

  • data – Base address of the data buffer.

  • stride_in_direction – Stride in the communication direction (in elements).

  • elem_size_in_bytes – Size of each element in bytes.

  • type_desc – TypeDescriptor identifying the element type. Used for MPI type conversion; ignored in serial mode.

  • is_device_memory – If true, data resides on GPU device memory. Used in serial mode to select appropriate memory copy method (CUDA/HIP for GPU).

template<typename T>
inline T sendrecv_right(int direction, T data) const

Template method for sending a scalar to the right neighbor and receiving from the left.

Efficiently exchanges a single scalar value with neighbors. The data is sent to the right neighbor (higher coordinate) and the return value is received from the left neighbor (lower coordinate) in the specified spatial dimension. This is suitable for point-wise values rather than large data transfers.

Template Parameters:

T – Scalar type (must have an mpi_type<T>() specialization).

Parameters:
  • direction – The spatial dimension in which to communicate (0 <= direction < spatial_dim).

  • data – The scalar value to send to the right neighbor.

Returns:

The scalar value received from the left neighbor.

template<typename T>
inline T sendrecv_left(int direction, T data) const

Template method for sending a scalar to the left neighbor and receiving from the right.

Efficiently exchanges a single scalar value with neighbors. The data is sent to the left neighbor (lower coordinate) and the return value is received from the right neighbor (higher coordinate) in the specified spatial dimension. This is suitable for point-wise values rather than large data transfers.

Template Parameters:

T – Scalar type (must have an mpi_type<T>() specialization).

Parameters:
  • direction – The spatial dimension in which to communicate (0 <= direction < spatial_dim).

  • data – The scalar value to send to the left neighbor.

Returns:

The scalar value received from the right neighbor.

void sendrecv_right_accumulate(int direction, int block_stride, int nb_send_blocks, int send_block_len, Index_t send_offset, int nb_recv_blocks, int recv_block_len, Index_t recv_offset, char *data, int stride_in_direction, int elem_size_in_bytes, TypeDescriptor type_desc, bool is_device_memory = false) const

Send to right neighbor, receive from left and accumulate (add).

Like sendrecv_right, but received values are added to the destination rather than overwriting it. This is the adjoint operation for ghost reduction in transpose operations with periodic BCs.

Parameters:
  • direction – The spatial dimension in which to communicate.

  • block_stride – Stride to the next block.

  • nb_send_blocks – Number of blocks to send.

  • send_block_len – Length of each block to send.

  • send_offset – Offset of send buffer in blocks.

  • nb_recv_blocks – Number of blocks to receive.

  • recv_block_len – Length of each block to receive.

  • recv_offset – Offset of receive buffer in blocks.

  • data – Base address of the data buffer.

  • stride_in_direction – Stride in communication direction.

  • elem_size_in_bytes – Size of each element in bytes.

  • type_desc – TypeDescriptor identifying the element type.

  • is_device_memory – If true, data is on GPU device memory.

void sendrecv_left_accumulate(int direction, int block_stride, int nb_send_blocks, int send_block_len, Index_t send_offset, int nb_recv_blocks, int recv_block_len, Index_t recv_offset, char *data, int stride_in_direction, int elem_size_in_bytes, TypeDescriptor type_desc, bool is_device_memory = false) const

Send to left neighbor, receive from right and accumulate (add).

Like sendrecv_left, but received values are added to the destination rather than overwriting it. This is the adjoint operation for ghost reduction in transpose operations with periodic BCs.

Parameters:
  • direction – The spatial dimension in which to communicate.

  • block_stride – Stride to the next block.

  • nb_send_blocks – Number of blocks to send.

  • send_block_len – Length of each block to send.

  • send_offset – Offset of send buffer in blocks.

  • nb_recv_blocks – Number of blocks to receive.

  • recv_block_len – Length of each block to receive.

  • recv_offset – Offset of receive buffer in blocks.

  • data – Base address of the data buffer.

  • stride_in_direction – Stride in communication direction.

  • elem_size_in_bytes – Size of each element in bytes.

  • type_desc – TypeDescriptor identifying the element type.

  • is_device_memory – If true, data is on GPU device memory.

Protected Attributes

Parent_t parent

The parent communicator from which this Cartesian communicator was derived.

DynGridIndex nb_subdivisions

The number of subdivisions (ranks) in each spatial dimension.

DynGridIndex coordinates

The Cartesian coordinates of this rank (0-indexed in each dimension).

class CartesianDecomposition : public muGrid::Decomposition

Subclassed by muGrid::FFTEngineBase

Public Types

using Parent_t = Decomposition
using SubPtMap_t = FieldCollection::SubPtMap_t

Public Functions

CartesianDecomposition(const Communicator &comm, Dim_t spatial_dimension, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())
CartesianDecomposition(const Communicator &comm, const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdivisions, const DynGridIndex &nb_ghosts_left, const DynGridIndex &nb_ghosts_right, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())
CartesianDecomposition() = delete
~CartesianDecomposition() override = default
void initialise(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdivisions, const DynGridIndex &nb_subdomain_grid_pts_without_ghosts, const DynGridIndex &subdomain_locations_without_ghosts, const DynGridIndex &nb_ghosts_left, const DynGridIndex &nb_ghosts_right, const DynGridIndex &subdomain_strides = DynGridIndex{})

initialise with known subdomains

void initialise(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdivisions, const DynGridIndex &nb_ghosts_left, const DynGridIndex &nb_ghosts_right)

initialise and determine subdomains from subdivisions

virtual void communicate_ghosts(const Field &field) const override

fill the ghost buffers with the values from the neighboring processes.

virtual void communicate_ghosts(const std::string &field_name) const override

fill the ghost buffers with the values from the neighboring processes.

virtual void reduce_ghosts(const Field &field) const override

accumulate ghost buffer contributions back to the interior domain. This is the adjoint operation of communicate_ghosts and is needed for transpose operations (e.g., divergence) with periodic BCs. After the operation, ghost buffers are zeroed.

virtual void reduce_ghosts(const std::string &field_name) const override

accumulate ghost buffer contributions back to the interior domain.

GlobalFieldCollection &get_collection()

get the field collection

const GlobalFieldCollection &get_collection() const

get the field collection

virtual Dim_t get_spatial_dim() const

get the spatial dimension

const DynGridIndex &get_nb_subdivisions() const

get the number of subdivisions

virtual const DynGridIndex &get_nb_domain_grid_pts() const

get the number of grid points of the whole domain

const DynGridIndex &get_nb_subdomain_grid_pts_with_ghosts() const

get the number of grid points per subdomain

DynGridIndex get_nb_subdomain_grid_pts_without_ghosts() const

get the number of grid points per subdomain

const DynGridIndex &get_subdomain_locations_with_ghosts() const

get the subdomain locations

DynGridIndex get_subdomain_locations_without_ghosts() const

get the subdomain locations

inline const DynGridIndex &get_nb_ghosts_left() const

get the number of ghost cells on the left side

inline const DynGridIndex &get_nb_ghosts_right() const

get the number of ghost cells on the right side

inline bool is_on_device() const

check if fields in this decomposition are on device (GPU) memory

inline Device get_device() const

get the device of the field collection

Protected Functions

void check_dimension(const DynGridIndex &n, const std::string &name) const

Protected Attributes

Communicator comm
std::unique_ptr<CartesianCommunicator> cart_comm
GlobalFieldCollection collection
std::vector<std::vector<Index_t>> recv_right_sequence
std::vector<std::vector<Index_t>> recv_left_sequence
std::vector<Index_t> nb_sendrecv_steps
template<typename T0>
class cfftp

Public Functions

template<typename T>
inline void exec(T c[], T0 fct, bool fwd) const
inline POCKETFFT_NOINLINE cfftp(size_t length_)

Private Functions

inline void add_factor(size_t factor)
template<bool fwd, typename T> inline void pass2 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const cmplx< T0 > *POCKETFFT_RESTRICT wa) const
template<bool fwd, typename T> inline void pass3 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const cmplx< T0 > *POCKETFFT_RESTRICT wa) const
template<bool fwd, typename T> inline void pass4 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const cmplx< T0 > *POCKETFFT_RESTRICT wa) const
template<bool fwd, typename T> inline void pass5 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const cmplx< T0 > *POCKETFFT_RESTRICT wa) const
template<bool fwd, typename T> inline void pass7 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const cmplx< T0 > *POCKETFFT_RESTRICT wa) const
template<bool fwd, typename T>
inline void ROTX45(T &a) const
template<bool fwd, typename T>
inline void ROTX135(T &a) const
template<bool fwd, typename T> inline void pass8 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const cmplx< T0 > *POCKETFFT_RESTRICT wa) const
template<bool fwd, typename T> inline void pass11 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const cmplx< T0 > *POCKETFFT_RESTRICT wa) const
template<bool fwd, typename T> inline void passg (size_t ido, size_t ip, size_t l1, T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const cmplx< T0 > *POCKETFFT_RESTRICT wa, const cmplx< T0 > *POCKETFFT_RESTRICT csarr) const
template<bool fwd, typename T>
inline void pass_all(T c[], T0 fct) const
inline POCKETFFT_NOINLINE void factorize ()
inline size_t twsize() const
inline void comp_twiddle()

Private Members

size_t length
arr<cmplx<T0>> mem
std::vector<fctdata> fact
template<typename T>
struct cmplx

Public Functions

inline cmplx()
inline cmplx(T r_, T i_)
inline void Set(T r_, T i_)
inline void Set(T r_)
inline cmplx &operator+=(const cmplx &other)
template<typename T2>
inline cmplx &operator*=(T2 other)
template<typename T2>
inline cmplx &operator*=(const cmplx<T2> &other)
template<typename T2>
inline cmplx &operator+=(const cmplx<T2> &other)
template<typename T2>
inline cmplx &operator-=(const cmplx<T2> &other)
template<typename T2>
inline auto operator*(const T2 &other) const -> cmplx<decltype(r * other)>
template<typename T2>
inline auto operator+(const cmplx<T2> &other) const -> cmplx<decltype(r + other.r)>
template<typename T2>
inline auto operator-(const cmplx<T2> &other) const -> cmplx<decltype(r + other.r)>
template<typename T2>
inline auto operator*(const cmplx<T2> &other) const -> cmplx<decltype(r + other.r)>
template<bool fwd, typename T2>
inline auto special_mul(const cmplx<T2> &other) const -> cmplx<decltype(r + other.r)>

Public Members

T r
T i
template<typename T>
class cndarr : public pocketfft::detail::arr_info

Subclassed by pocketfft::detail::ndarr< T >

Public Functions

inline cndarr(const void *data_, const shape_t &shape_, const stride_t &stride_)
inline const T &operator[](ptrdiff_t ofs) const

Protected Attributes

const char *d
class Communicator
#include <communicator.hh>

stub communicator object that doesn’t communicate anything

Subclassed by muGrid::CartesianCommunicator

Public Functions

inline Communicator()
inline ~Communicator()
inline int rank() const

get rank of present process

inline int size() const

get total number of processes

inline void barrier()

Barrier syncronization, nothing to be done in serial.

template<typename T>
inline T sum(const T &arg) const

sum reduction on scalar types

template<typename T>
inline DynMatrix_t<T> sum(const Eigen::Ref<DynMatrix_t<T>> &arg) const

sum on EigenMatrix types

template<typename T>
inline T max(const T &arg) const

max reduction on scalar types

template<typename T>
inline T cumulative_sum(const T &arg) const

ordered partial cumulative sum on scalar types. Find more details in the doc of the into the parallel implementation.

template<typename T>
inline T gather(const T &arg) const

gather on scalar types

template<typename T>
inline DynMatrix_t<T> gather(const Eigen::Ref<DynMatrix_t<T>> &arg) const

gather on EigenMatrix types

template<typename T>
inline T bcast(T &arg, const Int&)

broadcast of scalar types

inline bool all(const bool &arg) const

return logical and

inline bool any(const bool &arg) const

return logical or

Public Static Functions

static inline bool has_mpi()

find whether the underlying communicator is mpi

template<typename T>
class concurrent_queue

Public Functions

inline void push(T val)
inline bool try_pop(T &val)
inline bool empty() const

Private Types

using lock_t = std::lock_guard<std::mutex>

Private Members

std::queue<T> q_
std::mutex mut_
std::atomic<size_t> size_
class Coordinates
#include <pixels.hh>

Range class for coordinate iteration. Coordinates are computed on-demand during dereference.

Public Functions

Coordinates() = delete

Default constructor.

inline explicit Coordinates(const Pixels &pixels)

Constructor.

Coordinates(const Coordinates &other) = default

Copy constructor.

Coordinates(Coordinates &&other) = default

Move constructor.

~Coordinates() = default

Destructor.

Coordinates &operator=(const Coordinates &other) = delete

Copy assignment operator.

Coordinates &operator=(Coordinates &&other) = delete

Move assignment operator.

inline iterator begin() const

stl conformance

inline iterator end() const

stl conformance

inline size_t size() const

stl conformance

Protected Attributes

const Pixels &pixels
class cuFFTBackend : public muGrid::FFT1DBackend
#include <cufft_backend.hh>

cuFFT implementation of FFT1DBackend for NVIDIA GPUs.

This backend uses NVIDIA’s cuFFT library for GPU-accelerated FFT operations. It operates on device memory and supports batched 1D transforms with arbitrary strides.

cuFFT plans are cached by (n, batch, stride, dist) signature to avoid repeated plan creation overhead.

Public Functions

cuFFTBackend()
~cuFFTBackend() override
virtual void r2c(Index_t n, Index_t batch, const Real *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D real-to-complex FFT.

Parameters:
  • n – Transform size (number of real input points)

  • batch – Number of independent 1D transforms

  • input – Pointer to real input data

  • in_stride – Stride between consecutive input elements (in Reals)

  • in_dist – Distance between batches in input (in Reals)

  • output – Pointer to complex output data (n/2+1 complex per batch)

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual void c2r(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Real *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-real FFT.

Parameters:
  • n – Transform size (number of real output points)

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data (n/2+1 complex per batch)

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to real output data

  • out_stride – Stride between consecutive output elements (in Reals)

  • out_dist – Distance between batches in output (in Reals)

virtual void c2c_forward(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-complex forward FFT.

Parameters:
  • n – Transform size

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to complex output data

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual void c2c_backward(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-complex backward FFT.

Parameters:
  • n – Transform size

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to complex output data

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

inline virtual bool supports_device_memory() const override

Returns true if this backend supports device (GPU) memory

inline virtual const char *name() const override

Returns the name of this backend

Protected Types

enum TransformType

Transform type identifiers for plan caching.

Values:

enumerator R2C
enumerator C2R
enumerator C2C
using PlanKey = std::tuple<int, Index_t, Index_t, Index_t, Index_t, Index_t, Index_t>

Key type for plan cache: (transform_type, n, batch, in_stride, in_dist, out_stride, out_dist)

Protected Functions

cufftHandle get_plan(TransformType type, Index_t n, Index_t batch, Index_t in_stride, Index_t in_dist, Index_t out_stride, Index_t out_dist)

Get or create a cuFFT plan for the given parameters.

Parameters:
  • type – Transform type (R2C, C2R, or C2C)

  • n – Transform size

  • batch – Number of batched transforms

  • in_stride – Input stride

  • in_dist – Input distance between batches

  • out_stride – Output stride

  • out_dist – Output distance between batches

Returns:

cufftHandle for the requested transform

Protected Attributes

std::unordered_map<PlanKey, cufftHandle, PlanKeyHash> plan_cache

Plan cache.

Protected Static Functions

static void check_cufft_result(cufftResult result, const char *operation)

Check cuFFT result and throw on error.

class Decomposition

Subclassed by muGrid::CartesianDecomposition

Public Functions

Decomposition() = default
virtual ~Decomposition() = default
virtual void communicate_ghosts(const Field &field) const = 0

fill the ghost buffers with the values from the neighboring processes.

virtual void communicate_ghosts(const std::string &field_name) const = 0

fill the ghost buffers with the values from the neighboring processes.

virtual void reduce_ghosts(const Field &field) const = 0

accumulate ghost buffer contributions back to the interior domain. This is the adjoint operation of communicate_ghosts and is needed for transpose operations (e.g., divergence) with periodic BCs. After the operation, ghost buffers are zeroed.

virtual void reduce_ghosts(const std::string &field_name) const = 0

accumulate ghost buffer contributions back to the interior domain.

class Device
#include <device.hh>

Runtime device abstraction that encapsulates device information.

This class provides a unified way to represent and query device information, independent of the Field or FieldCollection that may reside on that device.

Device is a value type that can be:

  • Compared for equality

  • Passed as function arguments

  • Stored and returned from functions

  • Constructed from memory spaces at compile time

The Device class complements (does not replace) the compile-time MemorySpace system:

  • MemorySpace: Compile-time template parameter determining code generation

  • Device: Runtime value for queries, comparison, and multi-GPU support

Public Functions

inline constexpr Device()

Default constructor creates a CPU device (device_id = 0).

inline constexpr Device(DeviceType type, int id = 0)

Construct device with explicit type and ID.

Parameters:
  • type – The device type (CPU, CUDA, ROCm, etc.)

  • idDevice ID for multi-GPU systems (default 0)

inline constexpr bool is_device() const

Check if this is a device (GPU) memory location.

inline constexpr bool is_host() const

Check if this is a host (CPU) memory location.

inline constexpr DeviceType get_type() const

Get the device type.

inline constexpr int get_dlpack_device_type() const

Get DLPack device type (for Python/DLPack interoperability)

inline constexpr int get_device_id() const

Get device ID for multi-GPU systems.

std::string get_device_string() const

Get device string for Python interoperability (“cpu”, “cuda:0”, “rocm:0”)

const char *get_type_name() const

Get device type name (“CPU”, “CUDA”, “ROCm”, etc.)

inline constexpr bool operator==(const Device &other) const

Equality comparison.

inline constexpr bool operator!=(const Device &other) const

Inequality comparison.

Public Static Functions

static inline constexpr Device cpu()

Static factory for CPU device.

static inline constexpr Device cuda(int id = 0)

Static factory for CUDA device.

static inline constexpr Device rocm(int id = 0)

Static factory for ROCm device.

static inline constexpr Device gpu(int id = 0)

Static factory for default GPU device.

Returns the default GPU device based on compile-time configuration:

  • If CUDA is enabled, returns Device::cuda(0)

  • If HIP/ROCm is enabled (and CUDA is not), returns Device::rocm(0)

  • If no GPU backend is available, returns Device::cpu() as fallback

This provides a portable way to request “any available GPU” without knowing which backend is compiled in.

Protected Attributes

DeviceType device_type

Type of device (CPU, CUDA, ROCm, etc.)

int device_id

Device ID for multi-GPU systems.

template<class Derived>
struct DimCounter
template<class Derived>
struct DimCounter<Eigen::MatrixBase<Derived>>
#include <T4_map_proxy.hh>

Convenience structure to determine the spatial dimension of a tensor represented by a fixed-size Eigen::Matrix. used to derive spatial dimension from input arguments of template functions thus avoiding the need for redundant explicit specification.

Public Static Attributes

static constexpr Dim_t value = {ct_sqrt(Rows)}

storage for the dimension

Private Types

using Type = Eigen::MatrixBase<Derived>

Private Static Attributes

static constexpr Dim_t Rows = {Type::RowsAtCompileTime}
struct DimensionStartValue
#include <file_io_netcdf.hh>

Helper method to get start value for a dimension base name Subclasses may override to add support for additional dimension types Returns {found, value} where found indicates if the dimension was handled

Public Members

bool found = {false}
IOSize_t value = {0}
template<typename MemorySpace>
struct dlpack_device_type
#include <memory_space.hh>

Type trait mapping memory spaces to DLPack device types.

Public Static Attributes

static constexpr int value = DLPackDeviceType::CPU
template<Dim_t Dim, Dim_t Rank1, Dim_t Rank2>
struct Dotter
template<Dim_t Dim>
struct Dotter<Dim, fourthOrder, fourthOrder>
#include <tensor_algebra.hh>

Double contraction between two fourth-rank tensors A and B returns a fourth-rank tensor Cᵢⱼₖₗ = Aᵢⱼₐₑ·Bₐₑₖₗ

Public Static Functions

template<class T1, class T2>
static inline constexpr decltype(auto) ddot(const Eigen::MatrixBase<T1> &t1, const Eigen::MatrixBase<T2> &t2)

raison d’être

template<Dim_t Dim>
struct Dotter<Dim, fourthOrder, secondOrder>
#include <tensor_algebra.hh>

Tensor-product between a fourth-rank tensor A and a second-rank tensor B. Returns a fourth-rank Cᵢⱼₖₗ = Aᵢⱼₖₐ·Bₐₗ

Public Static Functions

template<class T4, class T2>
static inline constexpr decltype(auto) dot(const Eigen::MatrixBase<T4> &t4, const Eigen::MatrixBase<T2> &t2)

raison d’être

template<Dim_t Dim>
struct Dotter<Dim, secondOrder, fourthOrder>
#include <tensor_algebra.hh>

Tensor-product between a second-rank tensor A and a fourth-rank tensor B. Returns a fourth-rank Cᵢⱼₖₗ = Aᵢₐ·Bₐⱼₖₗ

Public Static Functions

template<class T1, class T2>
static inline constexpr decltype(auto) dot(const Eigen::MatrixBase<T1> &t1, const Eigen::MatrixBase<T2> &t2)

raison d’être

template<Dim_t Dim>
struct Dotter<Dim, secondOrder, secondOrder>
#include <tensor_algebra.hh>

Double contraction between two second-rank tensors A and B returns a scalar c = AᵢⱼBᵢⱼ

Public Static Functions

template<class T1, class T2>
static inline constexpr decltype(auto) ddot(const Eigen::MatrixBase<T1> &t1, const Eigen::MatrixBase<T2> &t2)

raison d’être

template<size_t MaxDim, typename T = Index_t>
class DynCoord
#include <coordinates.hh>

Dynamic coordinate container with runtime-determined dimension.

This class can accept any spatial dimension between 1 and MaxDim at runtime. DynCoord references can be cast to GridIndex or GridPoint references. Used when templating with the spatial dimension is undesirable or impossible (e.g., Python bindings).

Template Parameters:
  • MaxDim – Maximum supported dimension (for stack allocation)

  • T – Element type (Index_t for integers, Real for floating point)

Public Types

typedef typename std::array<T, MaxDim>::iterator iterator

A type alias for an iterator over the elements of a std::array.

typedef typename std::array<T, MaxDim>::const_iterator const_iterator

A type alias for a constant iterator over the elements of a std::array.

Public Functions

inline DynCoord()

default constructor

inline DynCoord(std::initializer_list<T> init_list)

Constructs a DynCoord object from an initializer list.

Parameters:

init_list – Initializer list used to set the values.

Throws:

RuntimeError – If the length exceeds MaxDim.

inline explicit DynCoord(Dim_t dim, const T value = T{})

Constructs a DynCoord object with a specified dimension.

Note: Use round braces ‘()’. Curly braces ‘{}’ invoke the initializer list constructor.

Parameters:
  • dim – The spatial dimension (1 to MaxDim).

  • value – The value to fill with (optional, default 0).

template<size_t Dim>
inline explicit DynCoord(const std::array<T, Dim> &coord)

Constructor from a statically sized coord.

inline explicit DynCoord(const std::vector<T> &coord)

Constructs a DynCoord object from a std::vector.

Parameters:

coord – Vector used to set the values.

Throws:

RuntimeError – If the size exceeds MaxDim.

DynCoord(const DynCoord &other) = default

Copy constructor.

DynCoord(DynCoord &&other) = default

Move constructor.

~DynCoord() = default

nonvirtual Destructor

template<size_t Dim>
inline DynCoord &operator=(const std::array<T, Dim> &coord)

Assign arrays.

DynCoord &operator=(const DynCoord &other) = default

Copy assignment operator.

DynCoord &operator=(DynCoord &&other) = default

Move assignment operator.

template<size_t Dim2>
inline bool operator==(const std::array<T, Dim2> &other) const

comparison operator

inline bool operator==(const DynCoord &other) const

comparison operator

inline bool operator!=(const DynCoord &other) const

comparison operator

inline DynCoord &operator+=(const DynCoord &other)

element-wise addition

template<typename T2>
inline DynCoord<MaxDim, decltype(T{} + T2{})> operator+(const DynCoord<MaxDim, T2> &other) const

element-wise addition

inline DynCoord &operator-=(const DynCoord &other)

element-wise subtraction

template<typename T2>
inline DynCoord<MaxDim, decltype(T{} - T2{})> operator-(const DynCoord<MaxDim, T2> &other) const

element-wise subtraction

template<typename T2>
inline DynCoord<MaxDim, decltype(T{} - T2{})> operator-(T2 other) const

element-wise subtraction

template<typename T2>
inline DynCoord<MaxDim, decltype(T{} * T2{})> operator*(const DynCoord<MaxDim, T2> &other) const

element-wise multiplication

template<typename T2>
inline DynCoord<MaxDim, decltype(T{} / T2{})> operator/(const DynCoord<MaxDim, T2> &other) const

element-wise division

inline DynCoord &operator%=(const DynCoord &other)

modulo assignment operator (mostly for periodic boundaries stuff)

inline DynCoord operator%(const DynCoord &other) const

modulo operator (mostly for periodic boundaries stuff)

inline T &operator[](const size_t &index)

access operator

inline const T &operator[](const size_t &index) const

access operator

inline void push_back(const T &value)

push element to the end

template<size_t Dim>
inline operator std::array<T, Dim>() const

conversion operator

template<Dim_t Dim>
inline std::array<T, Dim> &get()

cast to a reference to a statically sized array

template<Dim_t Dim>
inline const std::array<T, Dim> &get() const

cast to a const reference to a statically sized array

inline Dim_t get_dim() const

return the spatial dimension of this coordinate

inline Dim_t size() const

return the spatial dimension of this coordinate, STL compatibility

inline explicit operator std::vector<T>() const

convert into a vector

inline iterator begin()

iterator to the first entry for iterating over only the valid entries

inline iterator end()

iterator past the dim-th entry for iterating over only the valid entries

inline const_iterator begin() const

const iterator to the first entry for iterating over only the valid entries

inline const_iterator end() const

const iterator past the dim-th entry for iterating over only the valid entries

inline T *data()

return the underlying data pointer

inline const T *data() const

return the underlying data pointer

inline T &back()

return a reference to the last valid entry

inline const T &back() const

return a const reference to the last valid entry

Protected Attributes

Dim_t dim

spatial dimension of the coordinate

std::array<T, MaxDim> long_array

storage for coordinate components

Private Functions

template<size_t Dim>
inline constexpr std::array<T, MaxDim> fill_front(const std::array<T, Dim> &coord)

Private Static Functions

template<size_t Dim, size_t... Indices>
static inline constexpr std::array<T, MaxDim> fill_front_helper(const std::array<T, Dim> &coord, std::index_sequence<Indices...>)
template<typename T, class EigenPlain>
struct EigenMap

Internal struct for handling the matrix-shaped iterates of muGrid::FieldMap

Public Types

using PlainType = EigenPlain

Eigen type of the iterate.

template<Mapping MutIter>
using value_type = std::conditional_t<MutIter == Mapping::Const, Eigen::Map<const PlainType>, Eigen::Map<PlainType>>

stl (const-correct)

template<Mapping MutIter>
using ref_type = value_type<MutIter>

stl (const-correct)

template<Mapping MutIter>
using Return_t = value_type<MutIter>

for direct access through operator[]

template<Mapping MutIter>
using storage_type = value_type<MutIter>

stored type (cannot always be same as ref_type)

Public Static Functions

static inline constexpr bool IsValidStaticMapType()

check at compile time whether the type is meant to be a map with statically sized iterates.

static inline constexpr bool IsScalarMapType()

check at compiler time whether this map is scalar

template<Mapping MutIter>
static inline constexpr value_type<MutIter> &provide_ref(storage_type<MutIter> &storage)

return the return_type version of the iterate from storage_type

template<Mapping MutIter>
static inline constexpr const value_type<MutIter> &provide_const_ref(const storage_type<MutIter> &storage)

return the const return_type version of the iterate from storage_type

template<Mapping MutIter>
static inline constexpr value_type<MutIter> *provide_ptr(storage_type<MutIter> &storage)

return a pointer to the iterate from storage_type

template<Mapping MutIter>
static inline constexpr Return_t<MutIter> from_data_ptr(std::conditional_t<MutIter == Mapping::Const, const T*, T*> data)

return a return_type version of the iterate from its pointer

template<Mapping MutIter>
static inline constexpr storage_type<MutIter> to_storage(value_type<MutIter> &&value)

return a storage_type version of the iterate from its value

static inline constexpr Index_t stride()

return the nb of components of the iterate (known at compile time)

static inline std::string shape()

return the iterate’s shape as text, mostly for error messages

static inline constexpr Index_t NbRow()
class Enumerator
#include <pixels.hh>

Range class for enumerated iteration. Returns tuples of (index, coordinate).

Public Functions

Enumerator() = delete

Default constructor.

inline explicit Enumerator(const Pixels &pixels)

Constructor.

Enumerator(const Enumerator &other) = default

Copy constructor.

Enumerator(Enumerator &&other) = default

Move constructor.

~Enumerator() = default

Destructor.

Enumerator &operator=(const Enumerator &other) = delete

Copy assignment operator.

Enumerator &operator=(Enumerator &&other) = delete

Move assignment operator.

inline iterator begin() const

stl conformance

inline iterator end() const

stl conformance

inline size_t size() const

stl conformance

inline size_t buffer_size() const

Protected Attributes

const Pixels &pixels
template<class T>
class ExceptionWithTraceback : public T
#include <exception.hh>

A template class that extends the exception class provided as a template parameter.

This class is used to add traceback information to exceptions. It captures the stack trace at the point of exception creation. The traceback information is then included in the exception message.

Template Parameters:

T – The exception class to extend. This should be a type derived from std::exception.

Subclassed by muGrid::FieldCollectionError, muGrid::FieldError, muGrid::FieldMapError, muGrid::FileIOError, muGrid::UnitError

Public Functions

inline explicit ExceptionWithTraceback(const std::string &message)

Construct a new ExceptionWithTraceback object.

This constructor initializes the base exception with the provided message, captures the current stack trace, and prepares the full exception message including the traceback information.

Parameters:

message – The message for the base exception.

inline virtual ~ExceptionWithTraceback() noexcept

Destroy the ExceptionWithTraceback object.

This is a no-throw destructor, as required for exceptions.

inline virtual const char *what() const noexcept

Get the exception message.

This function returns the full exception message, including the traceback information.

Returns:

const char* The exception message.

Protected Attributes

Traceback traceback

The captured stack trace.

std::string buffer

The full exception message, including the traceback information.

struct ExecC2C

Public Functions

template<typename T0, typename T, size_t vlen>
inline void operator()(const multi_iter<vlen> &it, const cndarr<cmplx<T0>> &in, ndarr<cmplx<T0>> &out, T *buf, const pocketfft_c<T0> &plan, T0 fct) const

Public Members

bool forward
struct ExecDcst

Public Functions

template<typename T0, typename T, typename Tplan, size_t vlen>
inline void operator()(const multi_iter<vlen> &it, const cndarr<T0> &in, ndarr<T0> &out, T *buf, const Tplan &plan, T0 fct) const

Public Members

bool ortho
int type
bool cosine
struct ExecHartley

Public Functions

template<typename T0, typename T, size_t vlen>
inline void operator()(const multi_iter<vlen> &it, const cndarr<T0> &in, ndarr<T0> &out, T *buf, const pocketfft_r<T0> &plan, T0 fct) const
struct ExecR2R

Public Functions

template<typename T0, typename T, size_t vlen>
inline void operator()(const multi_iter<vlen> &it, const cndarr<T0> &in, ndarr<T0> &out, T *buf, const pocketfft_r<T0> &plan, T0 fct) const

Public Members

bool r2h
bool forward
struct fctdata

Public Members

size_t fct
cmplx<T0> *tw
cmplx<T0> *tws
struct fctdata

Public Members

size_t fct
T0 *tw
T0 *tws
class FEMGradientOperator2D : public muGrid::LinearOperator
#include <fem_gradient_2d.hh>

Hard-coded 2D linear FEM gradient operator with optimized implementation.

This class provides optimized implementations of the gradient operator for linear finite elements on 2D structured grids:

2D (Linear Triangles):

  • 4 nodal points per pixel (corners at [0,0], [1,0], [0,1], [1,1])

  • 2 triangles per pixel (lower-left and upper-right)

  • 2 quadrature points (one per triangle, at centroid)

  • 2 gradient components (d/dx, d/dy)

The apply() method computes the gradient (nodal → quadrature points). The transpose() method computes the divergence (quadrature → nodal points).

Shape function gradients are compile-time constants for linear elements, enabling SIMD vectorization and optimal performance.

Public Types

using Parent = LinearOperator

Public Functions

explicit FEMGradientOperator2D(std::vector<Real> grid_spacing = {})

Construct a 2D FEM gradient operator.

The grid spacing is used to scale the shape function gradients.

Parameters:

grid_spacing – Grid spacing in each direction (default: [1.0, 1.0])

FEMGradientOperator2D() = delete

Default constructor is deleted.

FEMGradientOperator2D(const FEMGradientOperator2D &other) = delete

Copy constructor is deleted.

FEMGradientOperator2D(FEMGradientOperator2D &&other) = default

Move constructor.

~FEMGradientOperator2D() override = default

Destructor.

FEMGradientOperator2D &operator=(const FEMGradientOperator2D &other) = delete

Copy assignment operator is deleted.

FEMGradientOperator2D &operator=(FEMGradientOperator2D &&other) = default

Move assignment operator.

virtual void apply(const TypedFieldBase<Real> &nodal_field, TypedFieldBase<Real> &gradient_field) const override

Apply the gradient operator (nodal → quadrature).

Input field: nodal values with shape [nb_nodal_pts, …] Output field: gradient at quadrature points with shape [dim, nb_quad_pts, …]

Parameters:
  • nodal_field – Input field at nodal points

  • gradient_field – Output gradient field at quadrature points

virtual void apply_increment(const TypedFieldBase<Real> &nodal_field, const Real &alpha, TypedFieldBase<Real> &gradient_field) const override

Apply the gradient operator with increment.

Computes: gradient_field += alpha * grad(nodal_field)

Parameters:
  • nodal_field – Input field at nodal points

  • alpha – Scaling factor for the increment

  • gradient_field – Output gradient field to increment

virtual void transpose(const TypedFieldBase<Real> &gradient_field, TypedFieldBase<Real> &nodal_field, const std::vector<Real> &weights = {}) const override

Apply the transpose (divergence) operator (quadrature → nodal).

Computes: nodal_field = -div(gradient_field) (negative divergence for consistency with weak form)

Parameters:
  • gradient_field – Input gradient field at quadrature points

  • nodal_field – Output field at nodal points

  • weights – Quadrature weights (optional, default: equal weights)

virtual void transpose_increment(const TypedFieldBase<Real> &gradient_field, const Real &alpha, TypedFieldBase<Real> &nodal_field, const std::vector<Real> &weights = {}) const override

Apply the transpose (divergence) with increment.

Computes: nodal_field += alpha * (-div(gradient_field))

Parameters:
  • gradient_field – Input gradient field at quadrature points

  • alpha – Scaling factor for the increment

  • nodal_field – Output field at nodal points to increment

  • weights – Quadrature weights (optional)

inline virtual Index_t get_nb_output_components() const override

Get the number of output components (2 for 2D gradient).

Returns:

2 (d/dx, d/dy)

inline virtual Index_t get_nb_quad_pts() const override

Get the number of quadrature points per pixel.

Returns:

2 (one per triangle)

inline virtual Index_t get_nb_input_components() const override

Get the number of input components per pixel.

For continuous FEM, nodes are shared between pixels via ghost communication. Each pixel uses values from 4 grid points, but the field itself has only 1 value per grid point.

Returns:

1 (one scalar value per grid point)

inline virtual Dim_t get_spatial_dim() const override

Get the spatial dimension.

Returns:

2

inline const std::vector<Real> &get_grid_spacing() const

Get the grid spacing.

Returns:

Grid spacing vector

std::vector<Real> get_quadrature_weights() const

Get the quadrature weights.

For 2D: Each triangle has weight = 0.5 * hx * hy (half the pixel area)

Returns:

Vector of quadrature weights (one per quadrature point)

inline Shape_t get_offset() const

Get the stencil offset.

Returns:

Stencil offset in pixels ([0,0])

inline Shape_t get_stencil_shape() const

Get the stencil shape.

Returns:

Shape of the stencil ([2,2])

std::vector<Real> get_coefficients() const

Get the stencil coefficients.

Returns the shape function gradients scaled by grid spacing. Shape: (nb_output_components, nb_quad_pts, nb_input_components, 2, 2)

Returns:

Vector of shape function gradients as flat array

Public Static Attributes

static constexpr Index_t NB_NODES = 4

Number of nodes per pixel (compile-time constant for 2D)

static constexpr Index_t NB_QUAD = 2

Number of quadrature points per pixel (compile-time constant for 2D)

static constexpr Dim_t DIM = 2

Spatial dimension.

Private Functions

const GlobalFieldCollection &validate_fields(const Field &nodal_field, const Field &gradient_field, Index_t &nb_components) const

Validate that fields are compatible with this operator.

Parameters:
  • nodal_field – Input field at nodal points

  • gradient_field – Output field at gradient/quadrature points

  • nb_components – Output: number of components in nodal field

Throws:

RuntimeError – if validation fails

void apply_impl(const TypedFieldBase<Real> &nodal_field, TypedFieldBase<Real> &gradient_field, Real alpha, bool increment) const

Internal implementation of apply with optional increment.

void transpose_impl(const TypedFieldBase<Real> &gradient_field, TypedFieldBase<Real> &nodal_field, Real alpha, bool increment, const std::vector<Real> &weights) const

Internal implementation of transpose with optional increment.

Private Members

std::vector<Real> grid_spacing
class FEMGradientOperator3D : public muGrid::LinearOperator
#include <fem_gradient_3d.hh>

Hard-coded 3D linear FEM gradient operator with optimized implementation.

This class provides optimized implementations of the gradient operator for linear finite elements on 3D structured grids:

3D (Linear Tetrahedra):

  • 8 nodal points per voxel (corners of unit cube)

  • 5 tetrahedra per voxel (Kuhn triangulation)

  • 5 quadrature points (one per tetrahedron, at centroid)

  • 3 gradient components (d/dx, d/dy, d/dz)

The apply() method computes the gradient (nodal → quadrature points). The transpose() method computes the divergence (quadrature → nodal points).

Shape function gradients are compile-time constants for linear elements, enabling SIMD vectorization and optimal performance.

Public Types

using Parent = LinearOperator

Public Functions

explicit FEMGradientOperator3D(std::vector<Real> grid_spacing = {})

Construct a 3D FEM gradient operator.

The grid spacing is used to scale the shape function gradients.

Parameters:

grid_spacing – Grid spacing in each direction (default: [1.0, 1.0, 1.0])

FEMGradientOperator3D() = delete

Default constructor is deleted.

FEMGradientOperator3D(const FEMGradientOperator3D &other) = delete

Copy constructor is deleted.

FEMGradientOperator3D(FEMGradientOperator3D &&other) = default

Move constructor.

~FEMGradientOperator3D() override = default

Destructor.

FEMGradientOperator3D &operator=(const FEMGradientOperator3D &other) = delete

Copy assignment operator is deleted.

FEMGradientOperator3D &operator=(FEMGradientOperator3D &&other) = default

Move assignment operator.

virtual void apply(const TypedFieldBase<Real> &nodal_field, TypedFieldBase<Real> &gradient_field) const override

Apply the gradient operator (nodal → quadrature).

virtual void apply_increment(const TypedFieldBase<Real> &nodal_field, const Real &alpha, TypedFieldBase<Real> &gradient_field) const override

Apply the gradient operator with increment.

virtual void transpose(const TypedFieldBase<Real> &gradient_field, TypedFieldBase<Real> &nodal_field, const std::vector<Real> &weights = {}) const override

Apply the transpose (divergence) operator (quadrature → nodal).

virtual void transpose_increment(const TypedFieldBase<Real> &gradient_field, const Real &alpha, TypedFieldBase<Real> &nodal_field, const std::vector<Real> &weights = {}) const override

Apply the transpose (divergence) with increment.

inline virtual Index_t get_nb_output_components() const override

Get the number of output components (3 for 3D gradient).

Returns:

3 (d/dx, d/dy, d/dz)

inline virtual Index_t get_nb_quad_pts() const override

Get the number of quadrature points per voxel.

Returns:

5 (one per tetrahedron)

inline virtual Index_t get_nb_input_components() const override

Get the number of input components per voxel.

Returns:

1 (one scalar value per grid point)

inline virtual Dim_t get_spatial_dim() const override

Get the spatial dimension.

Returns:

3

inline const std::vector<Real> &get_grid_spacing() const

Get the grid spacing.

Returns:

Grid spacing vector

std::vector<Real> get_quadrature_weights() const

Get the quadrature weights.

For 3D: 5-tet decomposition with:

  • Central tetrahedron (tet 0): volume = 1/3 of voxel

  • Corner tetrahedra (tet 1-4): volume = 1/6 of voxel each

Returns:

Vector of quadrature weights (one per quadrature point)

inline Shape_t get_offset() const

Get the stencil offset.

Returns:

Stencil offset in pixels ([0,0,0])

inline Shape_t get_stencil_shape() const

Get the stencil shape.

Returns:

Shape of the stencil ([2,2,2])

std::vector<Real> get_coefficients() const

Get the stencil coefficients.

Returns:

Vector of shape function gradients as flat array

Public Static Attributes

static constexpr Index_t NB_NODES = 8

Number of nodes per voxel (compile-time constant for 3D)

static constexpr Index_t NB_QUAD = 5

Number of quadrature points per voxel (compile-time constant for 3D)

static constexpr Dim_t DIM = 3

Spatial dimension.

Private Functions

const GlobalFieldCollection &validate_fields(const Field &nodal_field, const Field &gradient_field, Index_t &nb_components) const
void apply_impl(const TypedFieldBase<Real> &nodal_field, TypedFieldBase<Real> &gradient_field, Real alpha, bool increment) const
void transpose_impl(const TypedFieldBase<Real> &gradient_field, TypedFieldBase<Real> &nodal_field, Real alpha, bool increment, const std::vector<Real> &weights) const

Private Members

std::vector<Real> grid_spacing
class FFT1DBackend
#include <fft_1d_backend.hh>

Abstract interface for 1D FFT operations.

Implementations are selected at compile time based on GPU backend configuration (MUGRID_ENABLE_CUDA or MUGRID_ENABLE_HIP). The backend operates on raw pointers - the caller is responsible for ensuring the pointers are valid for the backend’s memory space.

Subclassed by muGrid::PocketFFTBackend, muGrid::cuFFTBackend, muGrid::rocFFTBackend

Public Functions

virtual ~FFT1DBackend() = default
virtual void r2c(Index_t n, Index_t batch, const Real *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) = 0

Batched 1D real-to-complex FFT.

Parameters:
  • n – Transform size (number of real input points)

  • batch – Number of independent 1D transforms

  • input – Pointer to real input data

  • in_stride – Stride between consecutive input elements (in Reals)

  • in_dist – Distance between batches in input (in Reals)

  • output – Pointer to complex output data (n/2+1 complex per batch)

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual void c2r(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Real *output, Index_t out_stride, Index_t out_dist) = 0

Batched 1D complex-to-real FFT.

Parameters:
  • n – Transform size (number of real output points)

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data (n/2+1 complex per batch)

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to real output data

  • out_stride – Stride between consecutive output elements (in Reals)

  • out_dist – Distance between batches in output (in Reals)

virtual void c2c_forward(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) = 0

Batched 1D complex-to-complex forward FFT.

Parameters:
  • n – Transform size

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to complex output data

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual void c2c_backward(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) = 0

Batched 1D complex-to-complex backward FFT.

Parameters:
  • n – Transform size

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to complex output data

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual bool supports_device_memory() const = 0

Returns true if this backend supports device (GPU) memory

virtual const char *name() const = 0

Returns the name of this backend

template<typename MemorySpace>
struct FFTBackendSelector

Traits class that maps MemorySpace to the appropriate FFT backend type.

This enables compile-time selection of the FFT backend based on the memory space template parameter.

template<>
struct FFTBackendSelector<HostSpace>

Public Types

using type = PocketFFTBackend

Public Static Functions

static inline std::unique_ptr<FFT1DBackend> create()
static inline constexpr const char *name()
template<typename T0>
class fftblue

Public Functions

inline POCKETFFT_NOINLINE fftblue(size_t length)
template<typename T>
inline void exec(cmplx<T> c[], T0 fct, bool fwd) const
template<typename T>
inline void exec_r(T c[], T0 fct, bool fwd)

Private Functions

template<bool fwd, typename T>
inline void fft(cmplx<T> c[], T0 fct) const

Private Members

size_t n
size_t n2
cfftp<T0> plan
arr<cmplx<T0>> mem
cmplx<T0> *bk
cmplx<T0> *bkf
template<typename MemorySpace>
class FFTEngine : public muGrid::FFTEngineBase
#include <fft_engine.hh>

Distributed FFT engine using pencil (2D) decomposition.

This class provides distributed FFT operations on structured grids with MPI parallelization. It uses pencil decomposition which allows efficient scaling to large numbers of ranks.

Key features:

  • Supports 2D and 3D grids

  • Handles arbitrary ghost buffer configurations in real space

  • No ghosts in Fourier space (hard assumption)

  • Compile-time memory space selection (Host, CUDA, HIP)

  • Unnormalized transforms (like FFTW)

The engine owns field collections for both real and Fourier space, and work buffers for intermediate results during the distributed FFT.

Template Parameters:

MemorySpace – The memory space for work buffers (HostSpace, CUDASpace, ROCmSpace)

Public Types

using Parent_t = FFTEngineBase
using WorkBuffer = Array<Complex, MemorySpace>

Public Functions

inline FFTEngine(const DynGridIndex &nb_domain_grid_pts, const Communicator &comm = Communicator(), const DynGridIndex &nb_ghosts_left = DynGridIndex{}, const DynGridIndex &nb_ghosts_right = DynGridIndex{}, const SubPtMap_t &nb_sub_pts = {}, Device device = memory_space_to_device<MemorySpace>())

Construct an FFT engine with pencil decomposition.

Parameters:
  • nb_domain_grid_pts – Global grid dimensions [Nx, Ny] or [Nx, Ny, Nz]

  • comm – MPI communicator (default: serial)

  • nb_ghosts_left – Ghost cells on low-index side of each dimension

  • nb_ghosts_right – Ghost cells on high-index side of each dimension

  • nb_sub_pts – Number of sub-points per pixel (optional)

  • deviceDevice for field memory allocation (optional, default uses memory space’s default device)

FFTEngine() = delete
FFTEngine(const FFTEngine&) = delete
FFTEngine(FFTEngine&&) = delete
~FFTEngine() override = default
FFTEngine &operator=(const FFTEngine&) = delete
FFTEngine &operator=(FFTEngine&&) = delete
inline virtual void fft(const Field &input, Field &output) override

Forward FFT: real space -> Fourier space.

inline virtual void ifft(const Field &input, Field &output) override

Inverse FFT: Fourier space -> real space.

inline virtual const char *get_backend_name() const override

Get the name of the FFT backend being used.

Protected Functions

inline void fft_2d(const Field &input, Field &output)
inline void fft_3d(const Field &input, Field &output)
inline void ifft_2d(const Field &input, Field &output)
inline void ifft_3d(const Field &input, Field &output)

Protected Attributes

std::unique_ptr<FFT1DBackend> backend

FFT backend for this memory space.

class FFTEngineBase : public muGrid::CartesianDecomposition
#include <fft_engine_base.hh>

Non-templated base class for FFTEngine.

This class contains all the domain decomposition logic, MPI setup, transpose configurations, and field collection management. It is inherited by the templated FFTEngine<MemorySpace> which adds the memory-space-specific FFT execution logic.

Subclassed by muGrid::FFTEngine< MemorySpace >

Public Types

using Parent_t = CartesianDecomposition
using SubPtMap_t = FieldCollection::SubPtMap_t

Public Functions

FFTEngineBase(const DynGridIndex &nb_domain_grid_pts, const Communicator &comm = Communicator(), const DynGridIndex &nb_ghosts_left = DynGridIndex{}, const DynGridIndex &nb_ghosts_right = DynGridIndex{}, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())

Construct an FFT engine base with pencil decomposition.

Parameters:
  • nb_domain_grid_pts – Global grid dimensions [Nx, Ny] or [Nx, Ny, Nz]

  • comm – MPI communicator (default: serial)

  • nb_ghosts_left – Ghost cells on low-index side of each dimension

  • nb_ghosts_right – Ghost cells on high-index side of each dimension

  • nb_sub_pts – Number of sub-points per pixel (optional)

  • device – Where to allocate field memory

FFTEngineBase() = delete
FFTEngineBase(const FFTEngineBase&) = delete
FFTEngineBase(FFTEngineBase&&) = delete
~FFTEngineBase() override = default
FFTEngineBase &operator=(const FFTEngineBase&) = delete
FFTEngineBase &operator=(FFTEngineBase&&) = delete
virtual void fft(const Field &input, Field &output) = 0

Forward FFT: real space -> Fourier space.

virtual void ifft(const Field &input, Field &output) = 0

Inverse FFT: Fourier space -> real space.

Field &register_real_space_field(const std::string &name, Index_t nb_components = 1)

Register a new real-space field. Throws if field already exists.

Field &register_real_space_field(const std::string &name, const Shape_t &components)
Field &register_fourier_space_field(const std::string &name, Index_t nb_components = 1)

Register a new Fourier-space field. Throws if field already exists.

Field &register_fourier_space_field(const std::string &name, const Shape_t &components)
Field &real_space_field(const std::string &name, Index_t nb_components = 1)

Get or create a real-space field. Returns existing field if present.

Field &real_space_field(const std::string &name, const Shape_t &components)
Field &fourier_space_field(const std::string &name, Index_t nb_components = 1)

Get or create a Fourier-space field. Returns existing field if present.

Field &fourier_space_field(const std::string &name, const Shape_t &components)
GlobalFieldCollection &get_real_space_collection()
const GlobalFieldCollection &get_real_space_collection() const
GlobalFieldCollection &get_fourier_space_collection()
const GlobalFieldCollection &get_fourier_space_collection() const
inline Real normalisation() const
inline const DynGridIndex &get_nb_fourier_grid_pts() const
inline const DynGridIndex &get_nb_fourier_subdomain_grid_pts() const
inline const DynGridIndex &get_fourier_subdomain_locations() const
inline std::array<int, 2> get_process_grid() const
inline std::array<int, 2> get_process_coords() const
virtual const char *get_backend_name() const = 0

Get the name of the FFT backend being used.

Protected Functions

void initialise_fft_base()

Initialize the FFT infrastructure after construction. Sets up work buffer collections and transpose configurations.

Transpose *get_transpose_xz(Index_t nb_components)

Get or create a transpose for the given nb_components.

Transpose *get_transpose_yz_forward(Index_t nb_components)
Transpose *get_transpose_yz_backward(Index_t nb_components)

Protected Attributes

int proc_grid_p1 = {1}

First dimension of process grid.

int proc_grid_p2 = {1}

Second dimension of process grid.

int proc_coord_p1 = {0}

This rank’s p1 coordinate.

int proc_coord_p2 = {0}

This rank’s p2 coordinate.

TransposeConfig transpose_xz_config
TransposeConfig transpose_yz_fwd_config
TransposeConfig transpose_yz_bwd_config
std::map<Index_t, std::unique_ptr<Transpose>> transpose_xz_cache
std::map<Index_t, std::unique_ptr<Transpose>> transpose_yz_fwd_cache
std::map<Index_t, std::unique_ptr<Transpose>> transpose_yz_bwd_cache
bool need_transpose_xz = {false}
bool need_transpose_yz = {false}
std::unique_ptr<GlobalFieldCollection> fourier_collection

Fourier-space field collection (final X-pencil layout)

std::unique_ptr<GlobalFieldCollection> work_zpencil

Work buffer collection for Z-pencils.

std::unique_ptr<GlobalFieldCollection> work_ypencil

Work buffer collection for Y-pencils (3D only)

DynGridIndex nb_fourier_grid_pts
DynGridIndex nb_fourier_subdomain_grid_pts
DynGridIndex fourier_subdomain_locations
Real norm_factor
Dim_t spatial_dim
class Field
#include <field.hh>

Abstract base class for all fields. A field provides storage discretising a mathematical (scalar, vectorial, tensorial) (real-valued, integer-valued, complex-valued) field on a fixed number of quadrature points per pixel/voxel of a regular grid. Fields defined on the same domains are grouped within muGrid::FieldCollections.

To understand the interface, it is important to clarify the following nomenclature:

  • Pixels are the grid dimensions for global fields or a single linear dimension for local fields

  • SubPts specify the number of (tensor) quantities held per pixel. These could for example be quadrature points.

  • Components are the components of the physical tensor quantity represented by the field.

Subclassed by muGrid::TypedFieldBase< Scalar, MemorySpace >, muGrid::TypedFieldBase< T, MemorySpace >

Public Functions

Field() = delete

Default constructor.

Field(const Field &other) = delete

Copy constructor.

Field(Field &&other) = default

Move constructor.

virtual ~Field() = default

Destructor.

Field &operator=(const Field &other) = delete

Copy assignment operator.

Field &operator=(Field &&other) = delete

Move assignment operator.

const std::string &get_name() const

return the field’s unique name

FieldCollection &get_collection() const

return a const reference to the field’s collection

const Index_t &get_nb_components() const

return the number of components stored per sub-point point

const Index_t &get_nb_sub_pts() const

return the number of sub points per pixel

Index_t get_nb_dof_per_pixel() const

return the number of components stored per pixel

Index_t get_nb_pixels() const

return the number of pixels

Index_t get_nb_pixels_without_ghosts() const

return the number of pixels without ghosts

Index_t get_nb_buffer_pixels() const

return the number of pixels that are required for the buffer. This can be larger than get_nb_pixels if the buffer contains padding regions.

Index_t get_nb_entries() const

returns the number of entries held by this field. This corresponds to nb_pixels × nb_sub_pts, (I.e., a scalar field and a vector field sharing the the same collection and subdivision tag have the same number of entries, even though the vector field has more scalar values.)

Index_t get_nb_buffer_entries() const

returns the number of entries held by the buffer of this field. This corresponds to nb_buffer_pixels × nb_sub_pts, (I.e., a scalar field and a vector field sharing the the same collection have the same number of entries, even though the vector field has more scalar values.)

Shape_t get_components_shape() const

evaluate and return the shape of the data contained in a single sub-point (e.g. quadrature point) (for passing the field to generic multidimensional array objects such as numpy.ndarray)

void reshape(const Shape_t &components_shape)

Reshape the components part of the field. The total number of degrees of freedom per pixel must remain the same.

void reshape(const Shape_t &components_shape, const std::string &sub_div_tag)

Reshape component and sub-point parts of the field. The total number of degrees of freedom per pixel must remain the same.

Shape_t get_sub_pt_shape(const IterUnit &iter_type) const

evaluate and return the shape of the data contained in a single pixel (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_pixels_shape() const

evaluate and return the overall shape of the pixels portion of the field (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_pixels_shape_without_ghosts() const

evaluate and return the overall shape of the pixels portion of the field without any potential ghost buffers (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_pixels_offset_without_ghosts() const

evaluate and return the offset of the pixels in the storage without any potential ghost buffers

Shape_t get_shape(const IterUnit &iter_type) const

evaluate and return the overall shape of the field (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_shape_without_ghosts(const IterUnit &iter_type) const

evaluate and return the overall shape of the field without any potential ghost buffers (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_offsets_without_ghosts(const IterUnit &iter_type) const

evaluate and return the overall offset of the field without any potential ghost buffers (for passing the field to generic multidimensional array objects such as numpy.ndarray)

virtual Shape_t get_strides(const IterUnit &iter_type, Index_t element_size = 1) const

evaluate and return the overall strides field (for passing the field to generic multidimensional array objects such as numpy.ndarray). The multiplier can be used e.g., if strides are needed in bytes, rather than in pointer offsets.

virtual StorageOrder get_storage_order() const

Return the storage order

Index_t get_stride(const IterUnit &iter_type) const

evaluate and return the number of components in an iterate when iterating over this field

bool has_same_memory_layout(const Field &other) const

check whether two fields have the same memory layout

Index_t get_default_nb_rows(const IterUnit &iter_type) const

evaluate and return the number of rows of a default iterate over this field. Warning, this function does no sanity checks at all. It is assumed that the user called get_stride before, that all checks have been performed there, and that rechecking would be a waste of time)

Index_t get_default_nb_cols(const IterUnit &iter_type) const

evaluate and return the number of cols of a default iterate over this field. Warning, this function does no sanity checks at all. It is assumed that the user called get_stride before, that all checks have been performed there, and that rechecking would be a waste of time)

virtual TypeDescriptor get_type_descriptor() const = 0

return the unified type descriptor for this field’s element type. This can be converted to MPI_Datatype or nc_type as needed.

virtual std::size_t get_element_size_in_bytes() const = 0

return the size of the elementary field entry in bytes

void assert_type_descriptor(TypeDescriptor type_desc) const

assert that the stored type corresponds to the given type descriptor

virtual void *get_void_data_ptr(bool assert_host_memory = true) const = 0

return a pointer to the raw data

Parameters:

assert_host_memory – If true (default), throws an error if the field is on device memory. Set to false only when passing the pointer to CUDA-aware libraries (e.g., CUDA-aware MPI).

Index_t get_current_nb_entries() const

number of entries in the field (= nb_pixel × nb_sub_pts)

virtual size_t get_buffer_size() const = 0

size of the internal buffer (in scalars)

virtual void set_zero() = 0

initialise field to zero (do more complicated initialisations through fully typed maps)

bool is_global() const

checks whether this field is registered in a global FieldCollection

Dim_t get_spatial_dim() const

return the spatial dimension of the underlying discretisation grid

bool has_nb_sub_pts() const

check wether the number of pixel sub-divisions has been set

const std::string &get_sub_division_tag() const

returns a const ref to the field’s pixel sub-division type

Unit get_physical_unit() const

returns the physical unit of the values stored in the field

virtual bool is_on_device() const = 0

Check if field resides on device (GPU) memory. Returns true for CUDA and ROCm/HIP device memory spaces.

virtual int get_dlpack_device_type() const = 0

Get DLPack device type for this field’s memory space. Returns kDLCPU=1, kDLCUDA=2, kDLROCm=10, etc.

virtual int get_device_id() const = 0

Get device ID for multi-GPU systems. Returns 0 for single-GPU or CPU systems.

virtual std::string get_device_string() const = 0

Get device string for Python interoperability. Returns “cpu”, “cuda:N”, or “rocm:N” where N is the device ID.

Protected Functions

Field(const std::string &unique_name, FieldCollection &collection, const Index_t &nb_components, const std::string &sub_div_tag, const Unit &unit)

Fields are supposed to only exist in the form of std::unique_ptrs held by a FieldCollection. The Field constructor is protected to ensure this. This constructor initializes a field that does not know the shape and storage order of its components.

Parameters:
  • unique_name – unique field name (unique within a collection)

  • nb_components – number of components to store per sub-point

  • collection – reference to the holding field collection.

Field(const std::string &unique_name, FieldCollection &collection, const Shape_t &components_shape, const std::string &sub_div_tag, const Unit &unit)

Fields are supposed to only exist in the form of std::unique_ptrs held by a FieldCollection. The Field constructor is protected to ensure this.

Parameters:
  • unique_name – unique field name (unique within a collection)

  • collection – reference to the holding field collection.

  • components_shape – number of components to store per quadrature point

  • storage_oder – in-memory storage order of the components

void set_nb_sub_pts(const Index_t &nb_quad_pts_per_pixel)

sets the number of sub points per pixel

Shape_t get_components_strides(Index_t element_size = 1) const

evaluate and return the strides of the sub-point portion of the field (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_sub_pt_strides(const IterUnit &iter_type, Index_t element_size = 1) const

evaluate and return the strides of the pixels portion of the field (for passing the field to generic multidimensional array objects such as numpy.ndarray)

Shape_t get_pixels_strides(Index_t element_size = 1) const

evaluate and return the overall strides of the pixels portion of the field (for passing the field to generic multidimensional array objects such as numpy.ndarray)

virtual void resize() = 0

resizes the field to the given size

Protected Attributes

friend FieldCollection

gives field collections the ability to resize() fields

Index_t current_nb_entries = {}

maintains a tally of the current size, as it cannot be reliably determined from values alone.

const std::string name

the field’s unique name

FieldCollection &collection

reference to the collection this field belongs to

Index_t nb_components

number of components stored per sub-point (e.g., 3 for a three-dimensional vector, or 9 for a three-dimensional second-rank tensor)

Shape_t components_shape

shape of the data stored per sub-point (e.g., 3, 3 for a three-dimensional second-rank tensor)

Index_t nb_sub_pts

number of pixel subdivisions. Will depend on sub_division. This value depends on the field collection and might or might not exist at construction time (it would be muGrid::Unknown if not yes set

std::string sub_division_tag

Pixel subdivision kind (determines how many datapoints to store per pixel)

Unit unit

Physical unit of the values stored in this field.

class FieldCollection

Base class for both muGrid::GlobalFieldCollection and muGrid::LocalFieldCollection. Manages the a group of fields with the same domain of validity (i.e., global fields, or local fields defined on the same pixels).

Subclassed by muGrid::GlobalFieldCollection, muGrid::LocalFieldCollection

Public Types

enum class ValidityDomain

domain of validity of the managed fields

Values:

enumerator Global
enumerator Local
using Field_ptr = std::unique_ptr<Field, FieldDestructor<Field>>

unique_ptr for holding fields

using SubPtMap_t = std::map<std::string, Index_t>

map to hold nb_sub_pts by tag

using StateField_ptr = std::unique_ptr<StateField, FieldDestructor<StateField>>

unique_ptr for holding state fields

Public Functions

FieldCollection() = delete

Default constructor.

FieldCollection(const FieldCollection &other) = delete

Copy constructor.

FieldCollection(FieldCollection &&other) = default

Move constructor.

virtual ~FieldCollection() = default

Destructor.

FieldCollection &operator=(const FieldCollection &other) = delete

Copy assignment operator.

FieldCollection &operator=(FieldCollection &&other) = default

Move assignment operator.

template<typename T>
inline Field &register_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

template<typename T>
inline Field &register_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

template<typename T>
Field_ptr detached_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

create a detached field (i.e., the field collection does not take responsibility for it, and it is up to the user to make sure that the field is used only during the life-time of the collection.

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &register_real_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new real-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &register_real_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &register_complex_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new complex-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &register_complex_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &register_int_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new integer-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &register_int_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &register_uint_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new unsigned integer-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &register_uint_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

template<typename T>
inline TypedStateField<T> &register_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

TypedStateField<Real> &register_real_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new real-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Complex> &register_complex_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new complex-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Int> &register_int_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new integer-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Uint> &register_uint_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new unsigned integer-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

template<typename T>
inline Field &field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &real_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new real-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &real_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &complex_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new complex-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &complex_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &int_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new integer-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &int_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

Field &uint_field(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new unsigned integer-valued field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • nb_components – number of components to be stored per sub-point (e.g., 4 for a two-dimensional second-rank tensor, or 1 for a scalar field)

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

Field &uint_field(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new field in the responsibility of this collection (Note, because fields have protected constructors, users can’t create them

Parameters:
  • unique_name – unique identifier for this field

  • components_shape – number of components to store per quadrature point

  • sub_division_tag – unique identifier of the subdivision scheme

  • unit – phyiscal unit of this field

  • storage_oder – in-memory storage order of the components

template<typename T>
inline TypedStateField<T> &state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

TypedStateField<Real> &real_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new real-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Complex> &complex_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new complex-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Int> &int_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new integer-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

TypedStateField<Uint> &uint_state_field(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag = PixelTag, const Unit &unit = Unit::unitless())

place a new unsigned integer-valued state field in the responsibility of this collection (Note, because state fields have protected constructors, users can’t create them

Parameters:
  • unique_prefix – unique idendifier for this state field

  • nb_memory – number of previous values of this field to store

  • nb_components – number of scalar components to store per quadrature point

bool field_exists(const std::string &unique_name) const

check whether a field of name ‘unique_name’ has already been registered

bool state_field_exists(const std::string &unique_prefix) const

check whether a field of name ‘unique_name’ has already been registered

Index_t get_nb_pixels() const

returns the number of pixels present in the collection

virtual Index_t get_nb_pixels_without_ghosts() const

returns the number of pixels present in the collection without ghosts

Index_t get_nb_buffer_pixels() const

returns the number of (virtual) pixels required to store the underlying data that may involve padding regions

bool has_nb_sub_pts(const std::string &tag) const

Check whether the number of subdivision points peir pixel/voxel has been set for a given tags

void set_nb_sub_pts(const std::string &tag, const Index_t &nb_sub_pts_per_pixel)

set the number of sub points per pixel/voxel for a given tag. Can only be done once per tag

Index_t get_nb_sub_pts(const std::string &tag)

return the number of subpoints per pixel/voxel for a given tag

Index_t get_nb_sub_pts(const std::string &tag) const

return the number of subpoints per pixel/voxel for a given tag

Dim_t get_spatial_dim() const

return the spatial dimension of the underlying discretisation grid

ValidityDomain get_domain() const

return the domain of validity (i.e., wher the fields are defined globally (muGrid::FieldCollection::ValidityDomain::Global) or locally (muGrid::FieldCollection::ValidityDomain::Local)

virtual Shape_t get_pixels_shape() const = 0

return shape of the pixels

virtual Shape_t get_pixels_shape_without_ghosts() const = 0

return shape of the pixels without any ghost buffer

virtual Shape_t get_pixels_offset_without_ghosts() const = 0

return the offset of the pixels in the storage without ghosts

virtual Shape_t get_pixels_strides(Index_t element_size = 1) const = 0

return strides of the pixels

StorageOrder get_storage_order() const

return the storage order of the pixels vs. subpoints

Device get_device() const

return the device for all fields in this collection

bool is_on_device() const

check if fields in this collection are on a GPU device

bool has_same_memory_layout(const FieldCollection &other) const

check whether two field collections have the same memory layout

bool is_initialised() const

whether the collection has been properly initialised (i.e., it knows the number of quadrature points and all its pixels/voxels

PixelIndexIterable get_pixel_indices() const

return an iterable proxy to the collection which allows to efficiently iterate over the indices fo the collection’s pixels

IndexIterable get_sub_pt_indices(const std::string &tag) const

return an iterable proxy to the collection which allows to iterate over the indices fo the collection’s quadrature points

inline const std::vector<Index_t> &get_pixel_ids()
Field &get_field(const std::string &unique_name)

returns a (base-type) reference to the field identified by unique_name. Throws a muGrid::FieldCollectionError if the field does not exist.

const Field &get_field(const std::string &unique_name) const

returns a (base-type) reference to the field identified by unique_name. Throws a muGrid::FieldCollectionError if the field does not exist.

Field_ptr pop_field(const std::string &unique_name)

returns the unique ptr holding the field named unique_name. Warning: note that this effectively removes the field from the collection. You can use this to delete fields to free memory

StateField &get_state_field(const std::string &unique_prefix)

returns a (base-type) reference to the state field identified by unique_prefix. Throws a muGrid::FieldCollectionError if the state field does not exist.

std::vector<std::string> list_fields() const

returns a vector of all field names

std::vector<std::string> list_state_field_unique_prefixes() const

returns a vector of all unique_prefixes of state fields in the field collection

void preregister_map(std::shared_ptr<std::function<void()>> &call_back)

preregister a map for latent initialisation

Index_t check_nb_sub_pts(const Index_t &nb_sub_pts, const IterUnit &iteration_type, const std::string &tag) const

run-time checker for nb_sub_pts: checks whether the number of sub-points (e.g., quadrature points) is compatible with the sub-division scheme). Attention: this does allow Unknown as valid values for IterUnit::SubPt, if the tag is defined, since these values can be specified for the entire FieldCollection at a later point, before initialisation. Hence, this function cannot be used for checking nb_sub_pts for iterators, which need a known value. Use check_initialised_nb_sub_pts() instead for that.

size_t check_initialised_nb_sub_pts(const Index_t &nb_sub_pts, const IterUnit &iteration_type, const std::string &tag) const

run-time checker for nb_sub_pts: checks whether the number of sub-points (e.g., quadrature points) is compatible with the sub-division scheme), and set to a positive integer value (i.e., not Unknown).

std::string generate_unique_name() const

use this to obtain an unused unique name for a new field to register, if you do not care about what name you obtain.

template<typename T>
Field &register_field_helper(const std::string &unique_name, const Index_t &nb_components, const std::string &sub_division_tag, const Unit &unit, bool allow_existing = false)

Internal worker function called by register_<T>_field. Creates a field in the collection’s memory space (host or device). Returns Field& to allow runtime polymorphism.

template<typename T>
Field &register_field_helper(const std::string &unique_name, const Shape_t &components_shape, const std::string &sub_division_tag, const Unit &unit, bool allow_existing = false)

Internal worker function called by register_<T>_field. Creates a field in the collection’s memory space (host or device). Returns Field& to allow runtime polymorphism.

template<typename T>
TypedStateField<T> &register_state_field_helper(const std::string &unique_prefix, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division_tag, const Unit &unit, bool allow_existing = false)

internal worker function called by register_<T>_state_field

Protected Functions

FieldCollection(ValidityDomain domain, Dim_t spatial_dimension, const SubPtMap_t &nb_sub_pts, StorageOrder storage_order = StorageOrder::ArrayOfStructures, Device device = Device::cpu())

Constructor (not called by user, who constructs either a LocalFieldCollection or a GlobalFieldCollection

Parameters:
  • domain – Domain of validity, can be global or local

  • spatial_dimension – spatial dimension of the field (can be muGrid::Unknown, e.g., in the case of the local fields for storing internal material variables)

  • nb_sub_pts – Specification of pixel subdivision. This is a map that of a string (the name of the subdivision scheme) to the number of subdivisions

  • storage_order – Storage order of the pixels vs subdivision portion of the field. In a column-major storage order, the pixel subdivision (i.e. the components of the field) are stored next to each other in memory, file in a row-major storage order for each component the pixels are stored next to each other in memory. (This is also sometimes called the array of structures vs. structure of arrays storage order.) Important: The pixels or subpoints have their own storage order that is not affected by this setting.

void allocate_fields()

loop through all fields and allocate their memory. Is exclusively called by the daughter classes’ initialise member function.

void initialise_maps()

initialise all preregistered maps

Protected Attributes

std::map<std::string, Field_ptr> fields = {}

storage container for fields

std::map<std::string, StateField_ptr> state_fields = {}

storage container for state fields

std::vector<std::weak_ptr<std::function<void()>>> init_callbacks = {}

Maps registered before initialisation which will need their data_ptr set

ValidityDomain domain

domain of validity

Dim_t spatial_dim

spatial dimension

SubPtMap_t nb_sub_pts

number of subpoints per pixel/voxel, stored by tag

Index_t nb_pixels = {Unknown}

total number of pixels

Index_t nb_buffer_pixels = {Unknown}

total number of pixels for the buffer (including padding regions)

StorageOrder storage_order

storage oder

Device device

device for all fields in this collection

bool initialised = {false}

keeps track of whether the collection has already been initialised

std::vector<Index_t> pixel_indices = {}

Storage for indices of the stored pixels in the global field collection. Note that these are not truly global indices, but rather absolute indices within the domain of the local processor. I.e., they are universally valid to address any pixel on the local processor, and not for any pixel located on another processor.

class FieldCollectionError : public muGrid::ExceptionWithTraceback<T>

base class for field collection-related exceptions

Public Functions

inline explicit FieldCollectionError(const std::string &what)

constructor

inline explicit FieldCollectionError(const char *what)

constructor

template<class DefaultDestroyable>
struct FieldDestructor

forward declacation of the field’s destructor-functor

Public Functions

void operator()(DefaultDestroyable *field)

deletes the held field

class FieldError : public muGrid::ExceptionWithTraceback<T>
#include <field.hh>

base class for field-related exceptions

Public Functions

inline explicit FieldError(const std::string &what)

constructor

inline explicit FieldError(const char *what)

constructor

template<typename T, Mapping Mutability>
class FieldMap
#include <field_map.hh>

forward declaration

Dynamically sized field map. Field maps allow iterating over the pixels or quadrature points of a field and to select the shape (in a matrix sense) of the iterate. For example, it allows to iterate in 2×2 matrices over the quadrature points of a strain field for a two-dimensional problem.

Subclassed by muGrid::StaticFieldMap< T, Mutability, MapType, IterationType >

Public Types

using Scalar = T

stored scalar type

using Field_t = std::conditional_t<Mutability == Mapping::Const, const TypedFieldBase<T, HostSpace>, TypedFieldBase<T, HostSpace>>

const-correct field depending on mapping mutability (HostSpace only)

using PlainType = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>

dynamically mapped eigen type

template<Mapping MutVal>
using Return_t = std::conditional_t<MutVal == Mapping::Const, Eigen::Map<const PlainType>, Eigen::Map<PlainType>>

return type for iterators over this- map

using EigenRef = Eigen::Ref<const PlainType>

Input type for matrix-like values (used for setting uniform values)

using PixelEnumeration_t = akantu::containers::ZipContainer<FieldCollection::PixelIndexIterable, FieldMap&>

zip-container for iterating over pixel index and stored value simultaneously

using Enumeration_t = akantu::containers::ZipContainer<FieldCollection::IndexIterable, FieldMap&>

zip-container for iterating over pixel or quadrature point index and stored value simultaneously

using iterator = Iterator<(Mutability == Mapping::Mut) ? Mapping::Mut : Mapping::Const>

stl

using const_iterator = Iterator<Mapping::Const>

stl

Public Functions

FieldMap() = delete

Default constructor.

explicit FieldMap(Field_t &field, const IterUnit &iter_type = IterUnit::SubPt)

Constructor from a field. The iter_type can be the natural sub-division of the field, or `muGridIterUnit::Pixel. The default case is a map iterating over sub-division points with a matrix of shape (nb_components × 1) per field entry

FieldMap(Field_t &field, Index_t nb_rows, const IterUnit &iter_type = IterUnit::SubPt)

Constructor from a field with explicitly chosen shape of iterate. (the number of columns is inferred). The iter_type can be the natural sub-division of the field, or `muGridIterUnit::Pixel

FieldMap(const FieldMap &other) = delete

Copy constructor.

FieldMap(FieldMap &&other)

Move constructor.

virtual ~FieldMap() = default

Destructor.

FieldMap &operator=(const FieldMap &other) = delete

Copy assignment operator (delete because of reference member)

FieldMap &operator=(FieldMap &&other) = delete

Move assignment operator (delete because of reference member)

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, FieldMap> &operator=(const EigenRef &val)

Assign a matrix-like value to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, FieldMap> &operator+=(const EigenRef &val)

Addition-assign a matrix-like value to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, FieldMap> &operator-=(const EigenRef &val)

Subtraction-assign a matrix-like value to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, FieldMap> &operator=(const Scalar &val)

Assign a scalar value to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, FieldMap> &operator+=(const Scalar &val)

Addition-assign a scalar value to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, FieldMap> &operator-=(const Scalar &val)

Subtraction-assign a scalar value to every entry.

iterator begin()

stl

iterator end()

stl

const_iterator cbegin()

stl

const_iterator cend()

stl

const_iterator begin() const

stl

const_iterator end() const

stl

size_t size() const

returns the number of iterates produced by this map (corresponds to the number of field entries if Iteration::Subpt, or the number of pixels/voxels if Iteration::Pixel); In parallel, if the processor does not hold a part of the field (empty processor) this empty processor returns size=0.

inline Return_t<Mutability> operator[](size_t index)

random access operator

inline Return_t<Mapping::Const> operator[](size_t index) const

random const access operator

void set_data_ptr()

query the size from the field’s collection and set data_ptr

PixelEnumeration_t enumerate_pixel_indices_fast()

return an iterable proxy over pixel indices and stored values simultaneously. Throws a muGrid::FieldMapError if the iteration type is over quadrature points

Enumeration_t enumerate_indices()

return an iterable proxy over pixel/quadrature indices and stored values simultaneously

PlainType sum() const

evaluate and return the sum of the map. In parallel, if the processor does not hold a part of the field (empty processor) this empty processor returns a zero matrix of the proper size and type.

PlainType mean() const

evaluate and return the mean value of the map. In parallel, if the processor does not hold a part of the field (empty processor) this empty processor returns a zero matrix of the proper size and type.

const Field_t &get_field() const

return const reference to the mapped field

Index_t get_stride() const

Public Static Functions

static inline constexpr Mapping FieldMutability()

determine whether a field is mutably mapped at compile time

static inline constexpr bool IsStatic()

determine whether a field map is statically sized at compile time

Protected Attributes

const Field_t &field

mapped field. Needed for query at initialisations

const IterUnit iteration

type of map iteration

const Index_t stride

precomputed stride

const Index_t nb_rows

number of rows of the iterate

const Index_t nb_cols

number of columns fo the iterate

T *data_ptr = {nullptr}

Pointer to mapped data; is also unknown at construction and set in the map’s begin function

bool is_initialised = {false}

keeps track of whether the map has been initialised.

std::shared_ptr<std::function<void()>> callback = {nullptr}

shared_ptr used for latent initialisation

class FieldMapError : public muGrid::ExceptionWithTraceback<T>
#include <field_map.hh>

base class for field map-related exceptions

Public Functions

inline explicit FieldMapError(const std::string &what)

constructor

inline explicit FieldMapError(const char *what)

constructor

class FileFrame
#include <file_io_base.hh>

A virtual base class for Frame classes.

This class provides a common interface for file frame operations. It provides a set of constructors and assignment operators (both copy and move are deleted). It also provides a virtual destructor and methods for reading and writing frames.

Note

This class cannot be instantiated directly (default constructor is deleted).

Public Functions

FileFrame() = delete

Default constructor is deleted to prevent direct instantiation of this class without parameters.

explicit FileFrame(FileIOBase &parent, Index_t frame)

Constructor with the FileIOBase object and the required frame number.

This constructor initializes a FileFrame object with the given FileIOBase object and frame number.

Parameters:
  • parent – The FileIOBase object.

  • frame – The frame number.

FileFrame(const FileFrame &other) = default

Copy constructor is deleted to prevent copying of FileFrame objects.

FileFrame(FileFrame &&other) = default

Move constructor is deleted to prevent moving of FileFrame objects.

virtual ~FileFrame() = default

Virtual destructor.

FileFrame &operator=(const FileFrame &other) = delete

Copy assignment operator is deleted to prevent copying of FileFrame objects.

FileFrame &operator=(FileFrame &&other) = delete

Move assignment operator is deleted to prevent moving of FileFrame objects.

void read(const std::vector<std::string> &field_names) const

Read the fields identified by field_names from the current frame.

Parameters:

field_names – The names of the fields to read.

void read() const

Read all fields of the registered field collection(s) from the current frame.

void write(const std::vector<std::string> &field_names) const

Write the contents of all fields within the field collection with the names ‘field_names’ to the file.

Parameters:

field_names – The names of the fields to write.

void write() const

Write the contents of all fields within the field collection to the file.

Protected Attributes

FileIOBase &parent

The FileIOBase object.

Index_t frame

The frame number.

class FileIOBase
#include <file_io_base.hh>

A virtual base class for FileIO classes.

This class provides a common interface for file input/output operations. It defines an enumeration for open modes (Read, Write, Append) and provides a set of constructors and assignment operators (both copy and move are deleted). It also provides a virtual destructor and a random access operator.

Note

This class cannot be instantiated directly (default constructor is deleted).

Subclassed by muGrid::FileIONetCDF

Public Types

enum class OpenMode

Enumeration for file open modes.

This enumeration defines the possible modes for opening a file:

  • Read: File is opened for reading only. This mode is used when the data in the file is only needed for input and will not be modified.

  • Write: File is opened for writing only. This mode is used when new data is to be written to a file. If the file already exists, this mode will fail to prevent accidental data loss.

  • Overwrite: File is opened for writing only. This mode is used when new data is to be written to a file. If the file already exists, it will be overwritten. Use this mode with caution to prevent accidental data loss.

  • Append: File is opened for writing only. This mode is used when new data is to be added to the end of a file. If the file already exists, the new data will be added at the end, preserving the existing data.

Values:

enumerator Read
enumerator Write
enumerator Overwrite
enumerator Append

Public Functions

FileIOBase() = delete

Default constructor is deleted to prevent direct instantiation of this class without parameters.

FileIOBase(const std::string &file_name, const OpenMode &open_mode, Communicator comm = Communicator())

Constructor with file name, open mode, and communicator.

This constructor initializes a FileIOBase object with the given file name, open mode, and communicator.

Parameters:
  • file_name – The name of the file to be opened.

  • open_mode – The mode to open the file in (Read, Write, or Append).

  • comm – The communicator to be used for parallel I/O operations (default is a default-constructed Communicator object).

FileIOBase(const FileIOBase &other) = delete

Copy constructor is deleted to prevent copying of FileIOBase objects.

FileIOBase(FileIOBase &&other) = delete

Move constructor is deleted to prevent moving of FileIOBase objects.

virtual ~FileIOBase() = default

Virtual destructor.

FileIOBase &operator=(const FileIOBase &other) = delete

Copy assignment operator is deleted to prevent copying of FileIOBase objects.

FileIOBase &operator=(FileIOBase &&other) = delete

Move assignment operator is deleted to prevent moving of FileIOBase objects.

FileFrame operator[](const Index_t &frame_index)

Random access operator.

This operator provides access to a specific frame in the file. The frame must exist for this operation to succeed.

Parameters:

frame_index – The index of the frame to access.

Returns:

FileFrame The requested frame.

virtual void register_field_collection(muGrid::FieldCollection &fc, std::vector<std::string> field_names = {REGISTER_ALL_FIELDS}, std::vector<std::string> state_field_unique_prefixes = {REGISTER_ALL_STATE_FIELDS}) = 0

Register a field collection to be dumped to the file.

This function should be called before the file is opened. If no field names are given, all fields of the given field collection are registered by default.

Parameters:
  • fc – The field collection to be registered.

  • field_names – The names of the fields to be registered. Default is all fields.

  • state_field_unique_prefixes – The unique prefixes of the state fields to be registered. Default is all state fields.

virtual void close() = 0

Close the file.

virtual void read(const Index_t &frame, const std::vector<std::string> &field_names) = 0

Read the fields identified by field_names from a specific frame in the file.

Parameters:
  • frame – The frame to read from.

  • field_names – The names of the fields to read.

virtual void read(const Index_t &frame) = 0

Read all registered fields from a specific frame in the file.

Parameters:

frame – The frame to read from.

virtual void write(const Index_t &frame, const std::vector<std::string> &field_names) = 0

Write the contents of all fields identified by field_names within the field collection to a specific frame in the file.

Parameters:
  • frame – The frame to write to.

  • field_names – The names of the fields to write.

virtual void write(const Index_t &frame) = 0

Write the contents of all fields within the field collection to a specific frame in the file.

Parameters:

frame – The frame to write to.

FileFrame append_frame()

Yield an empty file frame at the end of the file.

Returns:

FileFrame The empty file frame.

Communicator &get_communicator()

Get the communicator object.

Returns:

Communicator& The communicator object.

iterator begin()

Get an iterator pointing to the first frame in the file.

Returns:

iterator An iterator pointing to the first frame.

iterator end()

Get an iterator pointing one past the last frame in the file.

Returns:

iterator An iterator pointing one past the last frame.

size_t size() const

Get the number of frames in the file.

Returns:

size_t The number of frames.

Protected Functions

virtual void open() = 0

Open the file for read/write operations.

This function should be called by the constructor at instantiation. It is a pure virtual function and must be implemented by derived classes.

virtual void register_field_collection_global(muGrid::GlobalFieldCollection &fc_global, const std::vector<std::string> &field_names, const std::vector<std::string> &state_field_unique_prefixes) = 0

Register a global field collection to be dumped to the file.

This function should be called before the file is opened. If no field names are given, all fields of the given field collection are registered by default.

Parameters:
  • fc_global – The global field collection to be registered.

  • field_names – The names of the fields to be registered. Default is all fields.

  • state_field_unique_prefixes – The unique prefixes of the state fields to be registered. Default is all state fields.

virtual void register_field_collection_local(muGrid::LocalFieldCollection &fc_local, const std::vector<std::string> &field_names, const std::vector<std::string> &state_field_unique_prefixes) = 0

Register a local field collection to be dumped to the file.

This function should be called before the file is opened. If no field names are given, all fields of the given field collection are registered by default.

Parameters:
  • fc_local – The local field collection to be registered.

  • field_names – The names of the fields to be registered. Default is all fields.

  • state_field_unique_prefixes – The unique prefixes of the state fields to be registered. Default is all state fields.

Protected Attributes

const std::string file_name

The name of the file to be opened.

const OpenMode open_mode

The mode to open the file in (Read, Write, or Append).

Communicator comm

The communicator to be used for parallel I/O operations.

Index_t nb_frames = {0}

The number of frames in the file.

class FileIOError : public muGrid::ExceptionWithTraceback<T>
#include <file_io_base.hh>

base class for FileIO related exceptions

Public Functions

inline explicit FileIOError(const std::string &what)

constructor

inline explicit FileIOError(const char *what)

constructor

class FileIONetCDF : public muGrid::FileIOBase
#include <file_io_netcdf.hh>

A class for handling NetCDF files in the µGrid codebase.

This class inherits from the FileIOBase class and provides specific functionality for handling NetCDF files. NetCDF (Network Common Data Format) is a self-describing, machine-independent data format that support the creation, access, and sharing of array-oriented scientific data.

Public Types

enum class NetCDFMode

Values:

enumerator UndefinedMode
enumerator DefineMode
enumerator DataMode

Public Functions

FileIONetCDF() = delete

Default constructor.

FileIONetCDF(const std::string &file_name, const FileIOBase::OpenMode &open_mode, Communicator comm = Communicator())

Constructs a new FileIONetCDF object.

This constructor creates a new FileIONetCDF object with the specified file name, open mode, and communicator. The FileIONetCDF class is used for handling NetCDF files in the µGrid codebase.

Parameters:
  • file_name – The name of the file to be handled. This should be a valid file path.

  • open_mode – The mode in which the file should be opened. This should be a valid mode from the FileIOBase::OpenMode enumeration.

  • comm – The communicator to be used for parallel I/O operations. If not provided, a default Communicator object is used.

FileIONetCDF(const FileIONetCDF &other) = delete

Copy constructor (deleted)

This copy constructor is deleted to prevent copying of FileIONetCDF objects.

Parameters:

other – The other FileIONetCDF object to be copied.

FileIONetCDF(FileIONetCDF &&other) = delete

Move constructor (deleted)

This move constructor is deleted to prevent moving of FileIONetCDF objects.

Parameters:

other – The other FileIONetCDF object to be moved.

virtual ~FileIONetCDF()

Destructor.

This is the destructor for the FileIONetCDF class. It is responsible for freeing any resources that the object may have acquired during its lifetime.

FileIONetCDF &operator=(const FileIONetCDF &other) = delete

Copy assignment operator (deleted)

This copy assignment operator is deleted to prevent copying of FileIONetCDF objects.

Parameters:

other – The other FileIONetCDF object to be copied.

Returns:

A reference to the current object.

FileIONetCDF &operator=(FileIONetCDF &&other) = delete

Move assignment operator (deleted)

This move assignment operator is deleted to prevent moving of FileIONetCDF objects.

Parameters:

other – The other FileIONetCDF object to be moved.

Returns:

A reference to the current object.

virtual void register_field_collection(muGrid::FieldCollection &fc, std::vector<std::string> field_names = {REGISTER_ALL_FIELDS}, std::vector<std::string> state_field_unique_prefixes = {REGISTER_ALL_STATE_FIELDS}) final

Registers the field collections that should be written to the file.

This function should be called before the file is opened. It allows the user to specify which fields from the field collection should be saved in the NetCDF file.

Parameters:
  • fc – The field collection to be registered.

  • field_names – A vector of names of fields from the field collection that should be saved in the NetCDF file. This parameter should be used if not all fields from the field collection will be written to the file (default case).

  • state_field_unique_prefixes – A vector of unique prefixes for state fields.

virtual void close() final

Closes the file.

This function is used to close the NetCDF file after all operations are done.

virtual void read(const Index_t &frame, const std::vector<std::string> &field_names) final

Reads the specified fields from the file.

This function reads the fields identified by field_names from the specified frame in the file.

Parameters:
  • frame – The frame from which to read the fields.

  • field_names – A vector of names of fields to be read from the file.

virtual void read(const Index_t &frame) final

Reads all fields from the specified frame in the file.

This function reads all fields from the specified frame in the file.

Parameters:

frame – The frame from which to read the fields.

virtual void write(const Index_t &frame, const std::vector<std::string> &field_names) final

Writes the specified fields to the file.

This function writes the contents of all fields within the field collection with the name in field_names to the specified frame in the file.

Parameters:
  • frame – The frame to which to write the fields.

  • field_names – A vector of names of fields to be written to the file.

virtual void write(const Index_t &frame) final

Writes all fields to the file.

This function writes the contents of all fields within the field collection to the specified frame in the file.

Parameters:

frame – The frame to which to write the fields.

Index_t handle_frame(Index_t frame) const

Checks if the frame is valid and computes the corresponding positive frame value for a negative frame value.

This function checks if the frame is valid and computes the corresponding positive frame value for a negative frame value. For example, if the total number of frames is 5:

  • If the input frame is -3, the output frame is 2.

  • If the input frame is 3, the output frame is 3.

  • If the input frame is 7 or -6, an error is thrown.

Parameters:

frame – The frame to be checked and converted. This can be a positive or negative integer.

Throws:

FileIOError – If the input frame is not valid (i.e., it is greater than the total number of frames or less than the negative of the total number of frames).

Returns:

The corresponding positive frame value for the input frame.

template<class T>
inline void write_global_attribute(const std::string &att_name, T value)

Registers a global attribute to the NetCDF file.

This function can only be used in open_mode = FileIOBase::OpenMode::Write or FileIOBase::OpenMode::Overwrite and before write() was called the first time. Otherwise, there is the danger of having time expensive NetCDF header expansions, which is the reason why this is prevented.

Template Parameters:

T – The type of the value to be written as a global attribute.

Parameters:
  • att_name – The name of the attribute.

  • value – The value of the attribute.

Throws:

FileIOError – If the global attributes are already defined or if the open mode is not Write.

const NetCDFGlobalAtt &read_global_attribute(const std::string &att_name) const

Retrieves a global attribute from the NetCDF file by its name.

This function is used to fetch a global attribute from the NetCDF file. The attribute is identified by its name.

Parameters:

att_name – The name of the attribute.

Returns:

A constant reference to the NetCDFGlobalAtt object representing the global attribute.

const std::vector<std::string> read_global_attribute_names() const

Retrieves the names of all current global attributes in the NetCDF file.

This function is used to fetch the names of all global attributes present in the NetCDF file.

Returns:

A constant vector of strings containing the names of all current global attributes.

template<class T>
inline void update_global_attribute(const std::string &old_att_name, const std::string &new_att_name, T new_att_value)

Updates the value or name of an existing global attribute in the NetCDF file.

This function can only be used in open_mode = FileIOBase::OpenMode::Write, FileIOBase::OpenMode::Overwrite or FileIOBase::OpenMode::Append. The changes are only allowed if they do not lead to an increase in the size of the global attribute and the data_type of the attribute is not changed.

Template Parameters:

T – The type of the new value for the global attribute.

Parameters:
  • old_att_name – The current name of the attribute.

  • new_att_name – The new name for the attribute.

  • new_att_value – The new value for the attribute.

Throws:

FileIOError – If the function is called in a mode other than Write or Append, or if the attribute was not previously written to the NetCDF file.

Public Static Functions

static Index_t handle_frame(Index_t frame, Index_t tot_nb_frames)

Checks if the frame is valid and computes the corresponding positive frame value for a negative frame value (static version).

This is a static version of the handle_frame function. It performs the same operation but takes an additional parameter for the total number of frames.

Parameters:
  • frame – The frame to be checked and converted. This can be a positive or negative integer.

  • tot_nb_frames – The total number of frames.

Throws:

FileIOError – If the input frame is not valid (i.e., it is greater than the total number of frames or less than the negative of the total number of frames).

Returns:

The corresponding positive frame value for the input frame.

Public Static Attributes

static constexpr int MAX_NB_ATTRIBUTES{10}
static constexpr int MAX_LEN_ATTRIBUTE_NAME{NC_MAX_NAME}
static constexpr int MAX_NB_GLOBAL_ATTRIBUTES{30}
static constexpr int MAX_LEN_GLOBAL_ATTRIBUTE_NAME{NC_MAX_NAME}

Protected Functions

virtual void open() final

open file for read/write This function is called by the constructor at instantiation.

virtual void register_field_collection_global(muGrid::GlobalFieldCollection &fc_global, const std::vector<std::string> &field_names, const std::vector<std::string> &state_field_unique_prefixes) final

register global field collection

virtual void register_field_collection_local(muGrid::LocalFieldCollection &fc_local, const std::vector<std::string> &field_names, const std::vector<std::string> &state_field_unique_prefixes) final

register local field collection

void initialise_gfc_local_pixels(const muGrid::GlobalFieldCollection &fc_global)

when registering the first global field collection, I initialise the global field collection local_pixels.

std::string register_lfc_to_gfc_local_pixels(muGrid::LocalFieldCollection &fc_local)

add the global pixels field associated with a local field collection to the global field collection which stores the position of the local pixels and the offsets to read the data of a local variable in a proper way.

void check_variable_not_registered(const NetCDFVariables &variables, const std::string &var_name, const std::string &var_type)

Helper method to check if a variable with given name is already registered Throws FileIOError if duplicate is found

void collect_state_field_names(muGrid::StateField &state_field)

Helper method to collect field names from state field and add to tracking.

void setup_variable_metadata(NetCDFVarBase &var, const std::string &local_field_name = "")

Helper method to setup variable attributes and local field info Used for both global and local field registration

void write_no_frame(const std::vector<std::string> &field_names)

write contents of all fields within the field collection with the name in field_names that have no frame dimension.

void define_netcdf_dimensions(NetCDFDimensions &dimensions)

define the dimensions in the NetCDF file (to write a file)

actual call of NetCDF functions to read in the data of a single NetCDFVarBase

void define_netcdf_variables(NetCDFVariables &variables)

define the variables in the NetCDF file (to write a file)

void define_netcdf_attributes(NetCDFVariables &variables)

define the variables attributes in the NetCDF file (to write a file)

void register_netcdf_dimension_ids(std::uint64_t ndims, Index_t unlimdimid)

inquiry and register the dimension ids of the NetCDF file (to read or append a file) @ ndims : number of dimensions that have to be registered, i.e. computed by ncmu_inq(). @ unlimdimid : the NetCDF dimension ID of the unlimited dimension, i.e. computed by ncmu_inq().

void register_netcdf_variable_ids(std::uint64_t nvars)

inquiry and register the variable ids of the NetCDF file (to read or append a file) @ ndims : number of variables that have to be registered, i.e. computed by ncmu_inq().

void register_netcdf_attribute_names()

inquiry and register the attribute names of variables from the NetCDF file. Here the names are registered because attributes have no unique IDs, their numbers can change. (to read or append a file)

void register_netcdf_attribute_values()

register the values of all attributes with registered names

void define_global_attributes()

write NetCDFGlobalAtts from global_attributes (which are not already written) this function is only called if the file was open in FileIOBase::OpenMode::Write or FileIOBase::OpenMode::Overwrite. Then it is only called twice, once in FileIONetCDF::open() and once in FileIONetCDF::write() or FileIONetCDF::close() if write() was not called before close.

void define_global_attributes_save_call()

call define global attributes and check all requiremnts and bring the NetCDF file in the correct status if necessary. If no save call is possible the function exits without doing anything

void register_netcdf_global_attribute_names()

inquiry and register the global attribute names of variables from the NetCDF file. Here the names are registered because global attributes have no unique IDs, their numbers can change. (to read or append a file)

void register_netcdf_global_attribute_values()

register the values of all global attributes with registered names

void update_global_attribute_last_modified()

update the last modified flag by the current date and time

void update_global_attribute_last_modified_save_call()

save call of update_global_attribute_last_modified which checks all necessary conditions and otherwise do not call the function.

void netcdf_file_changes()

stes the flag netcdf_file_changed to true if it is not already true

Protected Attributes

int netcdf_id = {-1}
NetCDFMode netcdf_mode{NetCDFMode::UndefinedMode}
bool netcdf_file_changed = {false}
bool global_attributes_defined{false}
NetCDFGlobalAttributes global_attributes
NetCDFDimensions dimensions
NetCDFVariables variables
const std::string pixel = {"pixel"}
const muGrid::FieldCollection::SubPtMap_t nb_sub_pts
muGrid::GlobalFieldCollection GFC_local_pixels
bool initialised_GFC_local_pixels = {false}
std::vector<std::string> written_local_pixel_fields = {}
std::vector<std::string> read_local_pixel_fields = {}
std::vector<std::string> state_field_field_names = {}
class GenericLinearOperator : public muGrid::LinearOperator
#include <generic.hh>

Implements gradient operations using a stencil-based approach.

This class extends GradientOperator to provide specific implementations for gradient and divergence operations based on the shape function gradients for each quadrature point. It is designed to work with fields defined on nodal points and quadrature points, facilitating the evaluation of gradients and the discretised divergence.

The implementation supports portable execution across CPU and GPU (CUDA/HIP) architectures through backend-specific kernel implementations. The sparse operator representation uses a Structure-of-Arrays (SoA) layout for optimal memory access patterns on both CPU and GPU.

Note

This class cannot be instantiated directly and does not support copy construction or copy assignment.

Public Types

using Parent = LinearOperator

Public Functions

GenericLinearOperator() = delete

Default constructor is deleted to prevent instantiation.

GenericLinearOperator(const Shape_t &offset, std::span<const Real> coefficients, const Shape_t &stencil_shape, const Index_t &nb_pixel_input_components, const Index_t &nb_quad_pts, const Index_t &nb_output_components)

Constructs a GenericLinearOperator object. It initializes the gradient operator with the provided stencil coefficients, and necessary information to indicate its shape.

Parameters:
  • offset – Stencil offset in number of pixels

  • coefficients – The stencil coefficients raveled as an array.

  • stencil_shape – Shape of the stencil.

  • nb_pixel_input_components – Number of input components per pixel.

  • nb_quad_pts – Number of quadrature points per pixel.

  • nb_output_components – Number of output components.

GenericLinearOperator(const GenericLinearOperator &other) = delete

Copy constructor.

GenericLinearOperator(GenericLinearOperator &&other) = default

Move constructor.

~GenericLinearOperator() override = default

Destructor.

GenericLinearOperator &operator=(const GenericLinearOperator &other) = delete

Copy assignment operator.

GenericLinearOperator &operator=(GenericLinearOperator &&other) = default

Move assignment operator.

virtual void apply(const TypedFieldBase<Real> &nodal_field, TypedFieldBase<Real> &quadrature_point_field) const final

Evaluates the gradient of nodal_field into quadrature_point_field

Parameters:
  • nodal_field – input field of which to take gradient. Defined on nodal points

  • quadrature_point_field – output field to write gradient into. Defined on quadrature points

virtual void apply_increment(const TypedFieldBase<Real> &nodal_field, const Real &alpha, TypedFieldBase<Real> &quadrature_point_field) const override

Evaluates the gradient of nodal_field and adds it to quadrature_point_field

Parameters:
  • nodal_field – input field of which to take gradient. Defined on nodal points

  • alpha – scaling factor for the increment

  • quadrature_point_field – output field to increment by the gradient field. Defined on quadrature points

virtual void transpose(const TypedFieldBase<Real> &quadrature_point_field, TypedFieldBase<Real> &nodal_field, const std::vector<Real> &weights = {}) const final

Evaluates the discretised divergence of quadrature_point_field into nodal_field, weights corresponds to Gaussian quadrature weights. If weights are omitted, this returns some scaled version of discretised divergence.

Parameters:
  • quadrature_point_field – input field of which to take the divergence. Defined on quadrature points.

  • nodal_field – output field into which divergence is written

  • weights – Gaussian quadrature weights

virtual void transpose_increment(const TypedFieldBase<Real> &quadrature_point_field, const Real &alpha, TypedFieldBase<Real> &nodal_field, const std::vector<Real> &weights = {}) const final

Evaluates the discretised divergence of quadrature_point_field and adds the result to nodal_field, weights corresponds to Gaussian quadrature weights. If weights are omitted, this returns some scaled version of discretised divergence.

Parameters:
  • quadrature_point_field – input field of which to take the divergence. Defined on quadrature points.

  • alpha – scaling factor for the increment

  • nodal_field – output field to be incremented by the divergence

  • weights – Gaussian quadrature weights

const std::vector<Real> &get_coefficients() const

Return the stencil coefficients.

const Shape_t &get_offset() const

Return the stencil offset in number of pixels.

const Shape_t &get_stencil_shape() const

Return the shape of the stencil.

virtual Index_t get_nb_quad_pts() const final

returns the number of quadrature points are associated with any pixel/voxel (i.e., the sum of the number of quadrature points associated with each element belonging to any pixel/voxel.

virtual Index_t get_nb_output_components() const final

returns the number of output components

virtual Index_t get_nb_input_components() const final

returns the number of input components associated with any pixel/voxel. (Every node belonging to at least one of the elements belonging to any pixel/voxel, without recounting nodes that appear multiple times)

virtual Dim_t get_spatial_dim() const final

return the spatial dimension of this gradient operator

void clear_cache() const

Clear the cached sparse operator (useful if memory is a concern)

Complex fourier(const Eigen::VectorXd &phase) const

Compute the Fourier representation of this stencil operator

Converts a translationally invariant linear combination of grid values into a multiplication with a complex number in Fourier space.

Parameters:

phase – The wavevector times cell dimension (lacking factor of 2π)

Returns:

Complex Fourier representation of the operator

Private Functions

const GlobalFieldCollection &validate_fields(const TypedFieldBase<Real> &nodal_field, const TypedFieldBase<Real> &quad_field, bool is_transpose = false) const

Validate that fields are compatible with this operator.

Parameters:
  • nodal_field – The nodal field

  • quad_field – The quadrature point field

  • is_transpose – If true, swap ghost requirements (transpose reads at negative offsets, so left/right ghost needs are flipped)

Throws:

RuntimeError – if validation fails

Returns:

Reference to the GlobalFieldCollection

const GlobalFieldCollection &validate_fields_generic(const Field &nodal_field, const Field &quad_field, bool is_transpose = false) const

Validate that fields are compatible with this operator (generic version)

This version accepts base Field references and works for both host and device-space fields. It performs the same validation as the typed version but without requiring a specific memory space.

Parameters:
  • nodal_field – The nodal field (base class reference)

  • quad_field – The quadrature point field (base class reference)

  • is_transpose – If true, swap ghost requirements

Throws:

RuntimeError – if validation fails

Returns:

Reference to the GlobalFieldCollection

const SparseOperatorSoA<HostSpace> &get_apply_operator(const DynGridIndex &nb_grid_pts, const Index_t nb_nodal_components) const

Get or create sparse operator for apply operation.

Parameters:
  • nb_grid_pts – number of process-local (subdomain) grid points with ghosts

  • nb_nodal_components – number of components in nodal field

Returns:

Reference to the sparse operator (cached, row-major order)

const SparseOperatorSoA<HostSpace> &get_transpose_operator(const DynGridIndex &nb_grid_pts, const Index_t nb_nodal_components) const

Get or create sparse operator for transpose operation.

Parameters:
  • nb_grid_pts – number of process-local (subdomain) grid points with ghosts

  • nb_nodal_components – number of components in nodal field

Returns:

Reference to the sparse operator (cached, column-major order)

template<StorageOrder storage_order>
SparseOperatorSoA<HostSpace> create_apply_operator(const DynGridIndex &nb_grid_pts, const Index_t nb_nodal_components) const

Create sparse operator with row-major ordering.

Row-major order groups entries by quad index, providing write locality for apply_increment (scatter to quad_data).

The storage_order template parameter determines how indices are computed:

  • ArrayOfStructures: indices = (pixel_offset * pts + pt) * comps + comp

  • StructureOfArrays: indices = comp * total_elements + pixel_offset * pts + pt

Template Parameters:

storage_order – Storage order for index computation

Parameters:
  • nb_grid_pts – number of process-local (subdomain) grid points with ghosts

  • nb_nodal_components – number of components in nodal field

Returns:

The sparse operator in SoA format (row-major order)

template<StorageOrder storage_order>
SparseOperatorSoA<HostSpace> create_transpose_operator(const DynGridIndex &nb_grid_pts, const Index_t nb_nodal_components) const

Create sparse operator with column-major ordering.

Column-major order groups entries by nodal index, providing write locality for transpose_increment (scatter to nodal_data).

The storage_order template parameter determines how indices are computed:

  • ArrayOfStructures: indices = (pixel_offset * pts + pt) * comps + comp

  • StructureOfArrays: indices = comp * total_elements + pixel_offset * pts + pt

Template Parameters:

storage_order – Storage order for index computation

Parameters:
  • nb_grid_pts – number of process-local (subdomain) grid points with ghosts

  • nb_nodal_components – number of components in nodal field

Returns:

The sparse operator in SoA format (column-major order)

template<StorageOrder storage_order>
GridTraversalParams compute_traversal_params(const GlobalFieldCollection &collection, Index_t nb_nodal_components, Index_t nb_quad_components) const

Compute grid traversal parameters.

For ArrayOfStructures: stride_x = elems_per_pixel For StructureOfArrays: stride_x = 1 (pixels consecutive per component)

Template Parameters:

storage_order – Storage order for stride computation

Parameters:
  • collection – The field collection

  • nb_nodal_components – Number of nodal components

  • nb_quad_components – Number of quadrature components

Returns:

GridTraversalParams structure with all computed values

template<typename DeviceSpace>
void apply_on_device(const Real *nodal_data, Real *quad_data, const Real alpha, const GridTraversalParams &params) const

Apply convolution on device memory fields. Data must already be in device memory space.

Template Parameters:

DeviceSpace – Target device memory space (CUDASpace, ROCmSpace)

Parameters:
  • nodal_data – Pointer to nodal field data in device memory

  • quad_data – Pointer to quadrature field data in device memory

  • alpha – Scaling factor

  • params – Grid traversal parameters

template<typename DeviceSpace>
void transpose_on_device(const Real *quad_data, Real *nodal_data, const Real alpha, const GridTraversalParams &params) const

Transpose convolution on device memory fields. Data must already be in device memory space.

Template Parameters:

DeviceSpace – Target device memory space (CUDASpace, ROCmSpace)

Parameters:
  • quad_data – Pointer to quadrature field data in device memory

  • nodal_data – Pointer to nodal field data in device memory

  • alpha – Scaling factor

  • params – Grid traversal parameters

template<typename DeviceSpace>
const SparseOperatorSoA<DeviceSpace> &get_device_apply_operator(const DynGridIndex &nb_grid_pts, Index_t nb_nodal_components) const

Get or create device-space sparse operator for apply operation. Lazily copies from host cache to device.

Template Parameters:

DeviceSpace – Target device memory space

Parameters:
  • nb_grid_pts – Grid points with ghosts

  • nb_nodal_components – Number of nodal components

Returns:

Reference to device sparse operator

template<typename DeviceSpace>
const SparseOperatorSoA<DeviceSpace> &get_device_transpose_operator(const DynGridIndex &nb_grid_pts, Index_t nb_nodal_components) const

Get or create device-space sparse operator for transpose operation. Lazily copies from host cache to device.

Template Parameters:

DeviceSpace – Target device memory space

Parameters:
  • nb_grid_pts – Grid points with ghosts

  • nb_nodal_components – Number of nodal components

Returns:

Reference to device sparse operator

Private Members

Shape_t offset_ = {}

stencil offset in number of pixels

std::vector<Real> coefficients_ = {}

Stencil coefficients linking the nodal degrees of freedom to their quadrature-point values.

Shape_t stencil_shape_

Shape of the stencil (number of pixels in each dimension).

Index_t nb_pixel_input_components_

number of input components per pixel. When the grid gets complicated, it shall be divided into sub-grids, where each of them is a regular grid.

Index_t nb_quad_pts_

number of quadrature points per pixel (e.g.. 4 for linear quadrilateral)

Index_t nb_output_components_

number of output components (e.g., spatial dimension for gradients)

Dim_t spatial_dim_

the spatial dimension & number of stencil points

Index_t nb_stencil_pts_
mutable std::optional<SparseOperatorSoA<HostSpace>> cached_apply_op_ = {}

Cached sparse operators for reuse (two orderings for optimal access) Row-major: groups by quad index (optimal for apply - write locality)

mutable std::optional<SparseOperatorSoA<HostSpace>> cached_transpose_op_ = {}

Column-major: groups by nodal index (optimal for transpose - write locality)

mutable std::optional<SparseOperatorCacheKey> cached_key_ = {}
mutable std::optional<SparseOperatorSoA<DefaultDeviceSpace>> cached_device_apply_op_ = {}

Device-space cached operators (lazily copied from host)

mutable std::optional<SparseOperatorSoA<DefaultDeviceSpace>> cached_device_transpose_op_ = {}

Private Static Attributes

static constexpr Real zero_tolerance = 1e-14

Tolerance for considering operator values as zero.

class GlobalFieldCollection : public muGrid::FieldCollection

muGrid::GlobalFieldCollection derives from muGrid::FieldCollection and stores global fields that live throughout the whole computational domain, i.e. are defined for every pixel/voxel.

Public Types

using Parent = FieldCollection

alias of base class

using Pixels = CcoordOps::Pixels

pixel iterator

using SubPtMap_t = std::map<std::string, Index_t>

map to hold nb_sub_pts by tag

Public Functions

GlobalFieldCollection() = delete

Default constructor.

GlobalFieldCollection(Dim_t spatial_dimension, const SubPtMap_t &nb_sub_pts = {}, StorageOrder storage_order = StorageOrder::ArrayOfStructures, Device device = Device::cpu())

Constructor

Parameters:
  • spatial_dimension – number of spatial dimensions, must be 1, 2, 3, or Unknown

  • nb_sub_pts – number of quadrature points per pixel/voxel

  • storage_order – storage order for field components

  • device – where to allocate field memory

GlobalFieldCollection(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts = {}, const DynGridIndex &subdomain_locations_with_ghosts = {}, const SubPtMap_t &nb_sub_pts = {}, StorageOrder storage_order = StorageOrder::ArrayOfStructures, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {}, Device device = Device::cpu())

Constructor with initialization

Parameters:
  • nb_subdomain_grid_pts_with_ghosts – number of grid points on the current MPI process (subdomain)

  • subdomain_locations_with_ghosts – location of the current subdomain within the global grid

  • nb_sub_pts – number of quadrature points per pixel/voxel

  • device – where to allocate field memory

GlobalFieldCollection(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts, const DynGridIndex &subdomain_locations_with_ghosts, const DynGridIndex &pixels_strides, const SubPtMap_t &nb_sub_pts = {}, StorageOrder storage_order = StorageOrder::ArrayOfStructures, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {}, Device device = Device::cpu())

Constructor with initialisation

Parameters:
  • nb_subdomain_grid_pts_with_ghosts – number of grid points on the current MPI process (subdomain)

  • subdomain_locations_with_ghosts – location of the current subdomain within the global grid

  • pixels_strides – strides specifying memory layout of the pixels

  • storage_order – Storage order of the pixels vs subdivision portion of the field. In a column-major storage order, the pixel subdivision (i.e. the components of the field) are stored next to each other in memory, while in a row-major storage order, for each component the pixels are stored next to each other in memory. (This is also sometimes called the array of structures vs. structure of arrays storage order.) Important: The pixels or subpoints have their own storage order that is not affected by this setting.

  • device – where to allocate field memory

GlobalFieldCollection(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts, const DynGridIndex &subdomain_locations_with_ghosts, StorageOrder pixels_storage_order, const SubPtMap_t &nb_sub_pts = {}, StorageOrder storage_order = StorageOrder::ArrayOfStructures, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {}, Device device = Device::cpu())

Constructor with initialisation

Parameters:
  • nb_subdomain_grid_pts_with_ghosts – number of grid points on the current MPI process (subdomain)

  • subdomain_locations_with_ghosts – location of the current subdomain within the global grid

  • pixels_storage_order – Storage order of the pixels

  • storage_order – Storage order of the pixels vs subdivision portion of the field. In a column-major storage order, the pixel subdivision (i.e. the components of the field) are stored next to each other in memory, while in a row-major storage order for each component the pixels are stored next to each other in memory. (This is also sometimes called the array of structures vs. structure of arrays storage order.) Important: The pixels or subpoints have their own storage order that is not affected by this setting.

  • device – where to allocate field memory

GlobalFieldCollection(const GlobalFieldCollection &other) = delete

Copy constructor.

GlobalFieldCollection(GlobalFieldCollection &&other) = default

Move constructor.

~GlobalFieldCollection() override = default

Destructor.

GlobalFieldCollection &operator=(const GlobalFieldCollection &other) = delete

Copy assignment operator.

GlobalFieldCollection &operator=(GlobalFieldCollection &&other) = delete

Move assignment operator.

const Pixels &get_pixels_with_ghosts() const

Return the pixels class that allows to iterator over pixels.

const Pixels &get_pixels_without_ghosts() const

Return the pixels class that allows to iterator over pixels.

inline Index_t get_index(const DynGridIndex &ccoord) const

evaluate and return the linear index corresponding to dynamic ccoord

template<size_t Dim>
inline Index_t get_index(const GridIndex<Dim> &ccoord) const

evaluate and return the linear index corresponding to ccoord

inline DynGridIndex get_coord(const Index_t &index) const

return coordinates of the i-th pixel

void initialise(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts, const DynGridIndex &subdomain_locations_with_ghosts, const DynGridIndex &pixels_strides, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {})

freeze the problem size and allocate memory for all fields of the collection. Fields added later on will have their memory allocated upon construction.

template<size_t Dim>
inline void initialise(const GridIndex<Dim> &nb_domain_grid_pts, const GridIndex<Dim> &nb_subdomain_grid_pts, const GridIndex<Dim> &subdomain_locations, const GridIndex<Dim> &pixels_strides, const GridIndex<Dim> &nb_ghosts_left = {}, const GridIndex<Dim> &nb_ghosts_right = {})

freeze the problem size and allocate memory for all fields of the collection. Fields added later on will have their memory allocated upon construction.

void initialise(const DynGridIndex &nb_domain_grid_pts, const DynGridIndex &nb_subdomain_grid_pts_with_ghosts = {}, const DynGridIndex &subdomain_locations_with_ghosts = {}, StorageOrder pixels_storage_order = StorageOrder::Automatic, const DynGridIndex &nb_ghosts_left = {}, const DynGridIndex &nb_ghosts_right = {})

freeze the problem size and allocate memory for all fields of the collection. Fields added later on will have their memory allocated upon construction.

template<size_t Dim>
inline void initialise(const GridIndex<Dim> &nb_domain_grid_pts, const GridIndex<Dim> &nb_subdomain_grid_pts = {}, const GridIndex<Dim> &subdomain_locations = {}, StorageOrder pixels_storage_order = StorageOrder::Automatic, const GridIndex<Dim> &nb_ghosts_left = {}, const GridIndex<Dim> &nb_ghosts_right = {})

freeze the problem size and allocate memory for all fields of the collection. Fields added later on will have their memory allocated upon construction.

GlobalFieldCollection get_empty_clone() const

obtain a new field collection with the same domain and pixels

virtual Shape_t get_pixels_shape() const override

return shape of the pixels

virtual Shape_t get_pixels_shape_without_ghosts() const override

return shape of the pixels without ghosts

virtual Index_t get_nb_pixels_without_ghosts() const override

return the number of pixels without ghosts

virtual Shape_t get_pixels_offset_without_ghosts() const override

return the offset of the pixels in the storage without ghosts

virtual Shape_t get_pixels_strides(Index_t element_size = 1) const override

return strides of the pixels

inline const DynGridIndex &get_nb_domain_grid_pts() const

returns the global (domain) number of grid points in each direction

inline const DynGridIndex &get_nb_subdomain_grid_pts_with_ghosts() const

returns the process-local (subdomain) number of grid points in each direction including the ghost cells

inline DynGridIndex get_nb_subdomain_grid_pts_without_ghosts() const

returns the process-local (subdomain) number of grid points in each directionl, but without the ghost cells

inline const DynGridIndex &get_subdomain_locations_with_ghosts() const

returns the process-local (subdomain) locations of subdomain grid including the ghost cells

inline DynGridIndex get_subdomain_locations_without_ghosts() const

returns the process-local (subdomain) locations of subdomain grid, but without the ghost cells

inline const DynGridIndex &get_nb_ghosts_left() const

Returns the number of ghost cells on the left side of the subdomain.

Returns:

const reference to a DynGridIndex object containing the number of left ghost cells.

inline const DynGridIndex &get_nb_ghosts_right() const

Returns the number of ghost cells on the right side of the subdomain.

Returns:

const reference to a DynGridIndex object containing the number of right ghost cells.

inline Index_t get_pixels_index_diff() const

Returns the index difference between iterators of pixels with and without ghosts.

Returns:

an Index_t instance.

Protected Attributes

Pixels pixels_with_ghosts = {}

helper to iterate over the grid

Pixels pixels_without_ghosts = {}

helper to iterate over the grid

DynGridIndex nb_domain_grid_pts = {}
DynGridIndex nb_ghosts_left = {}
DynGridIndex nb_ghosts_right = {}
struct GridTraversalParams

Parameters for grid traversal in convolution kernels

Public Members

Index_t nx
Index_t ny
Index_t nz
Index_t total_pixels
Index_t row_width
Index_t start_pixel_index
Index_t nodal_elems_per_pixel
Index_t quad_elems_per_pixel
Index_t nodal_stride_x
Index_t nodal_stride_y
Index_t nodal_stride_z
Index_t quad_stride_x
Index_t quad_stride_y
Index_t quad_stride_z
Index_t total_nodal_elements
Index_t total_quad_elements
template<typename T>
struct HostAllocator
#include <array.hh>

Memory allocator for host space - uses standard allocation

Public Static Functions

static inline T *allocate(std::size_t n)
static inline void deallocate(T *ptr)
static inline void memset(T *ptr, int value, std::size_t n)
struct HostSpace
#include <memory_space.hh>

Tag type for host (CPU) memory space.

Uses ArrayOfStructures storage order for optimal CPU cache locality when iterating over components within a pixel.

Public Static Attributes

static constexpr const char *name = "Host"
static constexpr StorageOrder storage_order = StorageOrder::ArrayOfStructures
class IndexIterable

Iterate class for iterating over quadrature point indices of a field collection (i.e. the iterate you get when iterating over the result of muGrid::FieldCollection::get_quad_pt_indices).

Public Functions

IndexIterable() = delete

Default constructor.

IndexIterable(const IndexIterable &other) = delete

Copy constructor.

IndexIterable(IndexIterable &&other) = default

Move constructor.

virtual ~IndexIterable() = default

Destructor.

IndexIterable &operator=(const IndexIterable &other) = delete

Copy assignment operator.

IndexIterable &operator=(IndexIterable &&other) = delete

Move assignment operator.

iterator begin() const

stl

iterator end() const

stl

size_t size() const

stl

Protected Functions

IndexIterable(const FieldCollection &collection, const std::string &tag, const Index_t &stride = Unknown)

Constructor is protected, because no one ever need to construct this except the fieldcollection. Constructor for sub_point iteration

explicit IndexIterable(const FieldCollection &collection, const Index_t &stride = Unknown)

Constructor is protected, because no one ever need to construct this except the fieldcollection. Constructor for pixel iteration

Protected Attributes

friend FieldCollection

allow the field collection to create muGrid::FieldCollection::IndexIterables

const FieldCollection &collection

reference back to the proxied collection

const IterUnit iteration_type

whether to iterate over pixels or quadrature points

size_t stride

stride for the slow moving index

class Indices
#include <pixels.hh>

Range class for index-only iteration. Most efficient iteration mode - just returns linear indices.

Public Functions

Indices() = delete

Default constructor.

inline explicit Indices(const Pixels &pixels)

Constructor.

Indices(const Indices &other) = default

Copy constructor.

Indices(Indices &&other) = default

Move constructor.

~Indices() = default

Destructor.

Indices &operator=(const Indices &other) = delete

Copy assignment operator.

Indices &operator=(Indices &&other) = delete

Move assignment operator.

inline iterator begin() const

stl conformance

inline iterator end() const

stl conformance

inline size_t size() const

stl conformance

Protected Attributes

const Pixels &pixels
template<typename MemorySpace>
struct is_device_space : public std::false_type
#include <memory_space.hh>

Type trait to check if a memory space is device (GPU) memory.

template<class Derived>
struct is_fixed
#include <eigen_checks.hh>

Helper class to check whether an Eigen::Array or Eigen::Matrix is statically sized

Public Types

using T = std::remove_cv_t<std::remove_reference_t<Derived>>

raw type for testing

Public Static Attributes

static constexpr bool value = {T::SizeAtCompileTime != Eigen::Dynamic}

evaluated test

template<typename MemorySpace>
struct is_host_space : public std::is_same<MemorySpace, HostSpace>
#include <memory_space.hh>

Type trait to check if a memory space is host-accessible.

template<class TestClass>
struct is_matrix
#include <eigen_checks.hh>

Structure to determine whether an expression can be evaluated into a Eigen::Matrix, Eigen::Array, etc. and which helps determine compile-time size

Public Types

using T = std::remove_cv_t<std::remove_reference_t<TestClass>>

Public Static Attributes

static constexpr bool value{std::is_base_of<Eigen::MatrixBase<T>, T>::value}
template<class Derived>
struct is_matrix<Eigen::Map<Derived>>

Public Static Attributes

static constexpr bool value = {is_matrix<Derived>::value}
template<class Derived>
struct is_matrix<Eigen::MatrixBase<Eigen::Map<Derived>>>

Public Static Attributes

static constexpr bool value = {is_matrix<Derived>::value}
template<class Derived>
struct is_matrix<Eigen::Ref<Derived>>

Public Static Attributes

static constexpr bool value = {is_matrix<Derived>::value}
template<class Derived>
struct is_square
#include <eigen_checks.hh>

Helper class to check whether an Eigen::Array or Eigen::Matrix is a static-size and square.

Public Types

using T = std::remove_cv_t<std::remove_reference_t<Derived>>

raw type for testing

Public Static Attributes

static constexpr bool value{(T::RowsAtCompileTime == T::ColsAtCompileTime) && is_fixed<T>::value}

true if the object is square and statically sized

template<class T, Dim_t order>
struct is_tensor
#include <tensor_algebra.hh>

Check whether a given expression represents a Tensor specified order.

Public Static Attributes

static constexpr bool value = (std::is_convertible<T, Eigen::Tensor<Real, order>>::value || std::is_convertible<T, Eigen::Tensor<Int, order>>::value || std::is_convertible<T, Eigen::Tensor<Complex, order>>::value)

evaluated test

class IsotropicStiffnessOperator2D

Fused stiffness operator for 2D isotropic linear elastic materials.

Computes K @ u = B^T C B @ u for 2D linear triangular elements. Uses the decomposition K = 2μ G + λ V where G and V are precomputed geometry matrices shared by all pixels.

Memory layout:

  • Displacement field: [3, nx, ny] (3 DOFs per node: ux, uy for 2D + ghost)

  • Material field: [2, nx-1, ny-1] (λ, μ per pixel)

  • Force field: [3, nx, ny] (same as displacement)

Public Functions

explicit IsotropicStiffnessOperator2D(const std::vector<Real> &grid_spacing)

Construct the operator with given grid spacing.

Parameters:

grid_spacing – Grid spacing [hx, hy]

IsotropicStiffnessOperator2D() = delete

Default constructor is deleted.

~IsotropicStiffnessOperator2D() = default

Destructor.

void apply(const TypedFieldBase<Real> &displacement, const TypedFieldBase<Real> &lambda, const TypedFieldBase<Real> &mu, TypedFieldBase<Real> &force) const

Apply the stiffness operator: force = K @ displacement.

Parameters:
  • displacement – Input displacement field [2, nx, ny]

  • lambda – Lamé first parameter field [nx-1, ny-1]

  • mu – Lamé second parameter (shear modulus) field [nx-1, ny-1]

  • force – Output force field [2, nx, ny]

void apply_increment(const TypedFieldBase<Real> &displacement, const TypedFieldBase<Real> &lambda, const TypedFieldBase<Real> &mu, Real alpha, TypedFieldBase<Real> &force) const

Apply with increment: force += alpha * K @ displacement.

inline const std::array<Real, NB_ELEMENT_DOFS * NB_ELEMENT_DOFS> &get_G() const

Get the precomputed G matrix (geometry-only).

Returns:

G matrix as flat array [NB_ELEMENT_DOFS × NB_ELEMENT_DOFS]

inline const std::array<Real, NB_ELEMENT_DOFS * NB_ELEMENT_DOFS> &get_V() const

Get the precomputed V matrix (volumetric coupling).

Returns:

V matrix as flat array [NB_ELEMENT_DOFS × NB_ELEMENT_DOFS]

Public Static Attributes

static constexpr Index_t NB_NODES = 4

Number of nodes per pixel (4 corners)

static constexpr Index_t NB_DOFS_PER_NODE = 2

Number of DOFs per node (2 for 2D)

static constexpr Index_t NB_ELEMENT_DOFS = NB_NODES * NB_DOFS_PER_NODE

Total DOFs per element.

static constexpr Index_t NB_QUAD = 2

Number of quadrature points (2 triangles)

Private Functions

void precompute_matrices()

Compute the geometry matrices G and V.

void apply_impl(const TypedFieldBase<Real> &displacement, const TypedFieldBase<Real> &lambda, const TypedFieldBase<Real> &mu, Real alpha, TypedFieldBase<Real> &force, bool increment) const

Internal implementation.

Private Members

std::vector<Real> grid_spacing
std::array<Real, NB_ELEMENT_DOFS * NB_ELEMENT_DOFS> G_matrix

Precomputed G = Σ_q w_q B_q^T B_q (shear stiffness)

std::array<Real, NB_ELEMENT_DOFS * NB_ELEMENT_DOFS> V_matrix

Precomputed V = Σ_q w_q (B_q^T m)(m^T B_q) (volumetric stiffness)

class IsotropicStiffnessOperator3D

Fused stiffness operator for 3D isotropic linear elastic materials.

Computes K @ u = B^T C B @ u for 3D linear tetrahedral elements. Uses the 5-tetrahedra decomposition with correct quadrature weights.

Memory layout:

  • Displacement field: [3, nx, ny, nz] (3 DOFs per node)

  • Material field: [2, nx-1, ny-1, nz-1] (λ, μ per voxel)

  • Force field: [3, nx, ny, nz]

Public Functions

explicit IsotropicStiffnessOperator3D(const std::vector<Real> &grid_spacing)

Construct the operator with given grid spacing.

Parameters:

grid_spacing – Grid spacing [hx, hy, hz]

IsotropicStiffnessOperator3D() = delete

Default constructor is deleted.

~IsotropicStiffnessOperator3D() = default

Destructor.

void apply(const TypedFieldBase<Real> &displacement, const TypedFieldBase<Real> &lambda, const TypedFieldBase<Real> &mu, TypedFieldBase<Real> &force) const

Apply the stiffness operator: force = K @ displacement.

Parameters:
  • displacement – Input displacement field [3, nx, ny, nz]

  • lambda – Lamé first parameter field [nx-1, ny-1, nz-1]

  • mu – Lamé second parameter (shear modulus) field [nx-1, ny-1, nz-1]

  • force – Output force field [3, nx, ny, nz]

void apply_increment(const TypedFieldBase<Real> &displacement, const TypedFieldBase<Real> &lambda, const TypedFieldBase<Real> &mu, Real alpha, TypedFieldBase<Real> &force) const

Apply with increment: force += alpha * K @ displacement.

inline const std::array<Real, NB_ELEMENT_DOFS * NB_ELEMENT_DOFS> &get_G() const

Get the precomputed G matrix (geometry-only).

Returns:

G matrix as flat array [NB_ELEMENT_DOFS × NB_ELEMENT_DOFS]

inline const std::array<Real, NB_ELEMENT_DOFS * NB_ELEMENT_DOFS> &get_V() const

Get the precomputed V matrix (volumetric coupling).

Returns:

V matrix as flat array [NB_ELEMENT_DOFS × NB_ELEMENT_DOFS]

Public Static Attributes

static constexpr Index_t NB_NODES = 8

Number of nodes per voxel (8 corners)

static constexpr Index_t NB_DOFS_PER_NODE = 3

Number of DOFs per node (3 for 3D)

static constexpr Index_t NB_ELEMENT_DOFS = NB_NODES * NB_DOFS_PER_NODE

Total DOFs per element.

static constexpr Index_t NB_QUAD = 5

Number of quadrature points (5 tetrahedra)

Private Functions

void precompute_matrices()

Compute the geometry matrices G and V.

void apply_impl(const TypedFieldBase<Real> &displacement, const TypedFieldBase<Real> &lambda, const TypedFieldBase<Real> &mu, Real alpha, TypedFieldBase<Real> &force, bool increment) const

Internal implementation.

Private Members

std::vector<Real> grid_spacing
std::array<Real, NB_ELEMENT_DOFS * NB_ELEMENT_DOFS> G_matrix

Precomputed G = Σ_q w_q B_q^T B_q (shear stiffness)

std::array<Real, NB_ELEMENT_DOFS * NB_ELEMENT_DOFS> V_matrix

Precomputed V = Σ_q w_q (B_q^T m)(m^T B_q) (volumetric stiffness)

class iterator : public muGrid::CcoordOps::Pixels::iterator
#include <pixels.hh>

Iterator that dereferences to grid coordinate.

Public Types

using Parent = Pixels::iterator
using value_type = DynGridIndex
using pointer = value_type*

Public Functions

inline value_type operator*() const

dereferencing returns the coordinate

class iterator : public muGrid::CcoordOps::Pixels::iterator
#include <pixels.hh>

Iterator that dereferences to (index, coordinate) tuple.

Public Types

using Parent = Pixels::iterator
using value_type = std::tuple<Index_t, DynGridIndex>
using pointer = value_type*

Public Functions

inline value_type operator*() const

dereferencing returns tuple of index and coordinate

class iterator : public muGrid::CcoordOps::Pixels::iterator
#include <pixels.hh>

Iterator that dereferences to linear index only.

Public Types

using Parent = Pixels::iterator
using value_type = Size_t
using pointer = value_type*

Public Functions

inline value_type operator*() const

dereferencing returns the linear index

class iterator
#include <pixels.hh>

Base iterator class storing only a linear index. Coordinates are computed on-demand when needed.

Subclassed by muGrid::CcoordOps::Pixels::Coordinates::iterator, muGrid::CcoordOps::Pixels::Enumerator::iterator, muGrid::CcoordOps::Pixels::Indices::iterator

Public Types

using difference_type = std::ptrdiff_t
using iterator_category = std::forward_iterator_tag

Public Functions

inline iterator(const Pixels &pixels, Size_t index)

constructor

iterator() = delete

Default constructor.

iterator(const iterator &other) = default

Copy constructor.

iterator(iterator &&other) = default

Move constructor.

~iterator() = default

Destructor.

iterator &operator=(const iterator &other) = delete

Copy assignment operator.

iterator &operator=(iterator &&other) = delete

Move assignment operator.

inline iterator &operator++()

pre-increment

inline bool operator!=(const iterator &other) const

inequality

inline bool operator==(const iterator &other) const

equality

inline Size_t get_index() const

get the current linear index

inline DynGridIndex get_coord() const

get the current coordinate (computed on demand)

Protected Attributes

const Pixels &pixels

ref to pixels in cell

Size_t index

current linear index

class iterator

iterator class for iterating over quadrature point indices or pixel indices of a muGrid::FieldCollection::IndexIterable. Dereferences to an index.

Public Types

using PixelIndexIterator_t = typename std::vector<Index_t>::const_iterator

convenience alias

Public Functions

iterator() = delete

Default constructor.

iterator(const PixelIndexIterator_t &pixel_index_iterator, const size_t &stride)

constructor

iterator(const iterator &other) = default

Copy constructor.

iterator(iterator &&other) = default

Move constructor.

~iterator() = default

Destructor.

inline iterator &operator++()

pre-increment

inline bool operator!=(const iterator &other) const

comparison

inline bool operator==(const iterator &other) const

comparison (required by akantu::iterators)

inline size_t operator*()

dereference

Protected Attributes

size_t stride

stride for the slow moving index

Index_t offset = {}

fast-moving index

PixelIndexIterator_t pixel_index_iterator

iterator of slow moving index

template<Mapping MutIter>
class Iterator

forward-declaration for mugrid::FieldMap’s iterator

Public Types

using FieldMap_t = std::conditional_t<MutIter == Mapping::Const, const FieldMap, FieldMap>

convenience alias

using value_type = typename FieldMap<T, Mutability>::template Return_t<MutIter>

stl

using cvalue_type = typename FieldMap<T, Mutability>::template Return_t<Mapping::Const>

stl

Public Functions

Iterator() = delete

Default constructor.

inline Iterator(FieldMap_t &map, bool end)

Constructor to beginning, or to end.

Iterator(const Iterator &other) = delete

Copy constructor.

Iterator(Iterator &&other) = default

Move constructor.

virtual ~Iterator() = default

Destructor.

Iterator &operator=(const Iterator &other) = default

Copy assignment operator.

Iterator &operator=(Iterator &&other) = default

Move assignment operator.

inline Iterator &operator++()

pre-increment

inline value_type operator*()

dereference

inline cvalue_type operator*() const

dereference (force const operator[] to get const Eigen::Map)

inline bool operator==(const Iterator &other) const

equality

inline bool operator!=(const Iterator &other) const

inequality

Protected Attributes

FieldMap_t &map

FieldMap being iterated over.

size_t index

current iteration index

class iterator
#include <file_io_base.hh>

A class for iterating over the frames in the file.

This class provides a common interface for file frame iteration operations. It provides a set of constructors and assignment operators (both copy and move are deleted). It also provides a destructor and methods for dereferencing and incrementing.

Note

This class cannot be instantiated directly (default constructor is deleted).

Public Types

using value_type = FileFrame

STL type aliases for iterator conformance.

using const_value_type = const value_type

STL conformance.

using pointer = value_type*

STL conformance.

using difference_type = std::ptrdiff_t

STL conformance.

using iterator_category = std::forward_iterator_tag

STL conformance.

Public Functions

iterator() = delete

Default constructor is deleted to prevent direct instantiation of this class without parameters.

inline explicit iterator(FileIOBase &parent, Index_t frame_index = 0)

Constructor with the FileIOBase object and the required frame index.

This constructor initializes an iterator object with the given FileIOBase object and frame index.

Parameters:
  • parent – The FileIOBase object.

  • frame_index – The frame index.

iterator(const iterator &other) = default

Copy constructor.

iterator(iterator &&other) = default

Move constructor.

~iterator() = default

Destructor.

iterator &operator=(const iterator &other) = delete

Copy assignment operator is deleted to prevent copying of iterator objects.

iterator &operator=(iterator &&other) = delete

Move assignment operator is deleted to prevent moving of iterator objects.

inline const_value_type operator*() const

Dereferencing operator.

This operator provides access to a specific frame in the file. The frame must exist for this operation to succeed.

Returns:

const_value_type The requested frame.

inline iterator &operator++()

Pre-increment operator.

This operator increments the frame index by one.

Returns:

iterator& A reference to the incremented iterator.

inline bool operator==(const iterator &other) const

Equality comparison operator.

This operator checks if the frame index of the current iterator is equal to that of the other iterator.

Parameters:

other – The other iterator to compare with.

Returns:

bool True if the frame indices are equal, false otherwise.

inline bool operator!=(const iterator &other) const

Inequality comparison operator.

This operator checks if the frame index of the current iterator is not equal to that of the other iterator.

Parameters:

other – The other iterator to compare with.

Returns:

bool True if the frame indices are not equal, false otherwise.

Protected Attributes

FileIOBase &parent

The FileIOBase object.

Index_t frame_index = {}

The frame index.

class iterator : public std::vector::iterator
#include <ref_vector.hh>

iterator over muGrid::RefVector

Public Functions

inline iterator(Parent &iterator)

copy constructor

inline iterator(Parent &&iterator)

move constructor

inline T &operator*()

dereference

Private Types

using Parent = typename std::vector<T*>::iterator
template<Mapping MutIter>
class Iterator
#include <state_field_map.hh>

iterator type

Iterator class for muGrid::StateFieldMap

Public Types

using StateFieldMap_t = std::conditional_t<MutIter == Mapping::Const, const StateFieldMap, StateFieldMap>

convenience alias

using StateWrapper_t = typename StateFieldMap::template StateWrapper<MutIter>

const-correct proxy for iterates

Public Functions

Iterator() = delete

Deleted default constructor.

Iterator(StateFieldMap_t &state_field_map, size_t index)

constructor (should never have to be called by the user)

Iterator(const Iterator &other) = delete

Copy constructor.

Iterator(Iterator &&other) = default

Move constructor.

virtual ~Iterator() = default

destructor

Iterator &operator=(const Iterator &other) = delete

Copy assignment operator.

Iterator &operator=(Iterator &&other) = default

Move assignment operator.

inline bool operator!=(const Iterator &other)

comparison

inline Iterator &operator++()

pre-increment

inline StateWrapper_t operator*()

dereference

Protected Attributes

StateFieldMap_t &state_field_map

reference back to the iterated map

size_t index

current iteration progress

template<Mapping MutIter>
class Iterator

Iterator class for muGrid::StaticFieldMap

Public Types

using value_type = typename MapType::template value_type<MutIter>

type returned by iterator

using storage_type = typename MapType::template storage_type<MutIter>

type stored

Public Functions

Iterator() = delete

Default constructor.

inline Iterator(const StaticFieldMap &map, bool end)

Constructor to beginning, or to end.

Iterator(const Iterator &other) = default

Copy constructor.

Iterator(Iterator &&other) = default

Move constructor.

virtual ~Iterator() = default

Destructor.

Iterator &operator=(const Iterator &other) = default

Copy assignment operator.

Iterator &operator=(Iterator &&other) = default

Move assignment operator.

inline Iterator &operator++()

pre-increment

inline value_type &operator*()

dereference

inline value_type *operator->()

pointer to member

inline bool operator==(const Iterator &other) const

equality

inline bool operator!=(const Iterator &other) const

inequality

Protected Attributes

const StaticFieldMap &map

FieldMap being iterated over.

size_t index

current iteration index

storage_type iterate

map which is being returned per iterate

template<Mapping MutIter>
class Iterator

froward declaration of iterator class

Public Types

using StaticStateFieldMap_t = std::conditional_t<MutIter == Mapping::Const, const StaticStateFieldMap, StaticStateFieldMap>

const correct iterated map

using StateWrapper_t = typename StaticStateFieldMap::template StaticStateWrapper<MutIter>

convenience alias to dererencing return type

Public Functions

Iterator() = delete

Default constructor.

Iterator(const Iterator &other) = delete

Copy constructor.

inline Iterator(StaticStateFieldMap_t &state_field_map, size_t index)

constructor with field map and index, not for user to call

Iterator(Iterator &&other) = default

Move constructor.

virtual ~Iterator() = default

Destructor.

Iterator &operator=(const Iterator &other) = delete

Copy assignment operator.

Iterator &operator=(Iterator &&other) = default

Move assignment operator.

inline bool operator!=(const Iterator &other) const

comparison

inline bool operator==(const Iterator &other) const

comparison (needed by akantu::iterator

inline Iterator &operator++()

pre-increment

inline StateWrapper_t operator*()

dereference

Protected Attributes

StaticStateFieldMap_t &state_field_map

reference bap to iterated map

size_t index

current progress in iteration

template<typename MemorySpace>
struct KernelDispatcher

Dispatch convolution kernel to appropriate backend based on memory space.

Template Parameters:

MemorySpace – The memory space where the data resides

Public Static Functions

static inline void apply_convolution(const Real *nodal_data, Real *quad_data, const Real alpha, const GridTraversalParams &params, const SparseOperatorSoA<MemorySpace> &sparse_op)

Forward convolution: quad_data += alpha * Op * nodal_data.

static inline void transpose_convolution(const Real *quad_data, Real *nodal_data, const Real alpha, const GridTraversalParams &params, const SparseOperatorSoA<MemorySpace> &sparse_op)

Transpose convolution: nodal_data += alpha * Op^T * quad_data.

class LaplaceOperator2D : public muGrid::LinearOperator
#include <laplace_2d.hh>

Hard-coded 2D Laplace operator with optimized 5-point stencil.

This class provides an optimized implementation of the discrete Laplace operator using a 5-point stencil for 2D grids: [0,1,0; 1,-4,1; 0,1,0]

The output is multiplied by a scale factor, which can be used to incorporate grid spacing and sign conventions (e.g., for making the operator positive-definite for use with CG solvers).

This operator inherits from GradientOperator and can be used interchangeably with other gradient operators. The hard-coded implementation provides significantly better performance (~3-10x) due to compile-time known memory access patterns that enable SIMD vectorization.

Since the Laplacian is self-adjoint (symmetric), the transpose operation is identical to the forward apply operation.

Public Types

using Parent = LinearOperator

Public Functions

explicit LaplaceOperator2D(Real scale = 1.0)

Construct a 2D Laplace operator.

Parameters:

scale – Scale factor applied to the output (default: 1.0)

LaplaceOperator2D() = delete

Default constructor is deleted.

LaplaceOperator2D(const LaplaceOperator2D &other) = delete

Copy constructor is deleted.

LaplaceOperator2D(LaplaceOperator2D &&other) = default

Move constructor.

~LaplaceOperator2D() override = default

Destructor.

LaplaceOperator2D &operator=(const LaplaceOperator2D &other) = delete

Copy assignment operator is deleted.

LaplaceOperator2D &operator=(LaplaceOperator2D &&other) = default

Move assignment operator.

virtual void apply(const TypedFieldBase<Real> &input_field, TypedFieldBase<Real> &output_field) const override

Apply the Laplace operator on host memory fields.

Computes output = scale * Laplace(input) using the 5-point stencil.

Parameters:
  • input_field – Input field (with ghost layers populated)

  • output_field – Output field

virtual void apply_increment(const TypedFieldBase<Real> &input_field, const Real &alpha, TypedFieldBase<Real> &output_field) const override

Apply the Laplace operator with increment.

Computes output += alpha * scale * Laplace(input)

Parameters:
  • input_field – Input field (with ghost layers populated)

  • alpha – Scaling factor for the increment

  • output_field – Output field to increment

virtual void transpose(const TypedFieldBase<Real> &input_field, TypedFieldBase<Real> &output_field, const std::vector<Real> &weights = {}) const override

Apply the transpose (same as apply for symmetric Laplacian).

Since the Laplacian is self-adjoint, transpose equals apply.

Parameters:
  • input_field – Input field (quadrature point field in base class terms)

  • output_field – Output field (nodal field in base class terms)

  • weights – Ignored for Laplacian (no quadrature weighting)

virtual void transpose_increment(const TypedFieldBase<Real> &input_field, const Real &alpha, TypedFieldBase<Real> &output_field, const std::vector<Real> &weights = {}) const override

Apply the transpose with increment (same as apply_increment).

Parameters:
  • input_field – Input field

  • alpha – Scaling factor for the increment

  • output_field – Output field to increment

  • weights – Ignored for Laplacian

inline virtual Index_t get_nb_output_components() const override

Get the number of output components (always 1 for Laplacian).

Returns:

1

inline virtual Index_t get_nb_quad_pts() const override

Get the number of quadrature points (always 1 for Laplacian).

Returns:

1

inline virtual Index_t get_nb_input_components() const override

Get the number of input components (always 1 for Laplacian).

Returns:

1

inline virtual Dim_t get_spatial_dim() const override

Get the spatial dimension.

Returns:

2

inline Index_t get_nb_stencil_pts() const

Get the number of stencil points.

Returns:

5

inline Real get_scale() const

Get the scale factor.

Returns:

Scale factor applied to output

inline Shape_t get_offset() const

Get the stencil offset.

Returns:

Stencil offset in pixels (centered: [-1,-1])

inline Shape_t get_stencil_shape() const

Get the stencil shape.

Returns:

Shape of the stencil ([3,3])

inline std::vector<Real> get_coefficients() const

Get the stencil coefficients in reshaped form.

Returns [0, 1, 0, 1, -4, 1, 0, 1, 0] * scale

Returns:

Vector of stencil coefficients

Public Static Attributes

static constexpr Index_t NB_STENCIL_PTS = 5

Number of stencil points (compile-time constant for 2D)

Private Functions

const GlobalFieldCollection &validate_fields(const Field &input_field, const Field &output_field) const

Validate that fields are compatible with this operator.

Parameters:
  • input_field – The input field

  • output_field – The output field

Throws:

RuntimeError – if validation fails

Returns:

Reference to the GlobalFieldCollection

void apply_impl(const TypedFieldBase<Real> &input_field, TypedFieldBase<Real> &output_field, Real alpha, bool increment) const

Internal implementation of apply with optional increment.

Parameters:
  • input_field – Input field

  • output_field – Output field

  • alpha – Scaling factor (0 means overwrite, non-zero means increment)

  • increment – If true, add to output; if false, overwrite output

Private Members

Real scale
class LaplaceOperator3D : public muGrid::LinearOperator
#include <laplace_3d.hh>

Hard-coded 3D Laplace operator with optimized 7-point stencil.

This class provides an optimized implementation of the discrete Laplace operator using a 7-point stencil for 3D grids: center=-6, neighbors=+1

The output is multiplied by a scale factor, which can be used to incorporate grid spacing and sign conventions (e.g., for making the operator positive-definite for use with CG solvers).

This operator inherits from GradientOperator and can be used interchangeably with other gradient operators. The hard-coded implementation provides significantly better performance (~3-10x) due to compile-time known memory access patterns that enable SIMD vectorization.

Since the Laplacian is self-adjoint (symmetric), the transpose operation is identical to the forward apply operation.

Public Types

using Parent = LinearOperator

Public Functions

explicit LaplaceOperator3D(Real scale = 1.0)

Construct a 3D Laplace operator.

Parameters:

scale – Scale factor applied to the output (default: 1.0)

LaplaceOperator3D() = delete

Default constructor is deleted.

LaplaceOperator3D(const LaplaceOperator3D &other) = delete

Copy constructor is deleted.

LaplaceOperator3D(LaplaceOperator3D &&other) = default

Move constructor.

~LaplaceOperator3D() override = default

Destructor.

LaplaceOperator3D &operator=(const LaplaceOperator3D &other) = delete

Copy assignment operator is deleted.

LaplaceOperator3D &operator=(LaplaceOperator3D &&other) = default

Move assignment operator.

virtual void apply(const TypedFieldBase<Real> &input_field, TypedFieldBase<Real> &output_field) const override

Apply the Laplace operator on host memory fields.

Computes output = scale * Laplace(input) using the 7-point stencil.

Parameters:
  • input_field – Input field (with ghost layers populated)

  • output_field – Output field

virtual void apply_increment(const TypedFieldBase<Real> &input_field, const Real &alpha, TypedFieldBase<Real> &output_field) const override

Apply the Laplace operator with increment.

Computes output += alpha * scale * Laplace(input)

Parameters:
  • input_field – Input field (with ghost layers populated)

  • alpha – Scaling factor for the increment

  • output_field – Output field to increment

virtual void transpose(const TypedFieldBase<Real> &input_field, TypedFieldBase<Real> &output_field, const std::vector<Real> &weights = {}) const override

Apply the transpose (same as apply for symmetric Laplacian).

Since the Laplacian is self-adjoint, transpose equals apply.

Parameters:
  • input_field – Input field (quadrature point field in base class terms)

  • output_field – Output field (nodal field in base class terms)

  • weights – Ignored for Laplacian (no quadrature weighting)

virtual void transpose_increment(const TypedFieldBase<Real> &input_field, const Real &alpha, TypedFieldBase<Real> &output_field, const std::vector<Real> &weights = {}) const override

Apply the transpose with increment (same as apply_increment).

Parameters:
  • input_field – Input field

  • alpha – Scaling factor for the increment

  • output_field – Output field to increment

  • weights – Ignored for Laplacian

inline virtual Index_t get_nb_output_components() const override

Get the number of output components (always 1 for Laplacian).

Returns:

1

inline virtual Index_t get_nb_quad_pts() const override

Get the number of quadrature points (always 1 for Laplacian).

Returns:

1

inline virtual Index_t get_nb_input_components() const override

Get the number of input components (always 1 for Laplacian).

Returns:

1

inline virtual Dim_t get_spatial_dim() const override

Get the spatial dimension.

Returns:

3

inline Index_t get_nb_stencil_pts() const

Get the number of stencil points.

Returns:

7

inline Real get_scale() const

Get the scale factor.

Returns:

Scale factor applied to output

inline Shape_t get_offset() const

Get the stencil offset.

Returns:

Stencil offset in pixels (centered: [-1,-1,-1])

inline Shape_t get_stencil_shape() const

Get the stencil shape.

Returns:

Shape of the stencil ([3,3,3])

inline std::vector<Real> get_coefficients() const

Get the stencil coefficients in reshaped form.

Returns 7-point stencil with center=-6*scale, neighbors=1*scale

Returns:

Vector of stencil coefficients

Public Static Attributes

static constexpr Index_t NB_STENCIL_PTS = 7

Number of stencil points (compile-time constant for 3D)

Private Functions

const GlobalFieldCollection &validate_fields(const Field &input_field, const Field &output_field) const

Validate that fields are compatible with this operator.

Parameters:
  • input_field – The input field

  • output_field – The output field

Throws:

RuntimeError – if validation fails

Returns:

Reference to the GlobalFieldCollection

void apply_impl(const TypedFieldBase<Real> &input_field, TypedFieldBase<Real> &output_field, Real alpha, bool increment) const

Internal implementation of apply with optional increment.

Parameters:
  • input_field – Input field

  • output_field – Output field

  • alpha – Scaling factor (0 means overwrite, non-zero means increment)

  • increment – If true, add to output; if false, overwrite output

Private Members

Real scale
class latch

Public Functions

inline latch(size_t n)
inline void count_down()
inline void wait()
inline bool is_ready()

Private Types

using lock_t = std::unique_lock<std::mutex>

Private Members

std::atomic<size_t> num_left_
std::mutex mut_
std::condition_variable completed_
class LinearOperator
#include <linear.hh>

Base class for gradient and divergence operations.

This class defines the interface for performing gradient and divergence operations in the context of finite element analysis. It provides the foundational structure for implementing these operations on various types of fields and supports both nodal and quadrature point evaluations.

The class is designed to be inherited by specific implementations that define the actual computational logic for gradient and divergence operations. It includes constructors, a destructor, and assignment operators to manage object lifecycle and ensure proper resource management.

Subclassed by muGrid::FEMGradientOperator2D, muGrid::FEMGradientOperator3D, muGrid::GenericLinearOperator, muGrid::LaplaceOperator2D, muGrid::LaplaceOperator3D

Public Functions

LinearOperator() = default

Default constructor.

Initializes a new instance of the GradientOperator class. This constructor is defaulted, indicating that it performs no special actions other than initializing the object.

LinearOperator(const LinearOperator &other) = delete

Copy constructor (deleted).

Disables the copy construction of GradientOperator instances. This ensures that a GradientOperator object cannot be copied, enforcing unique ownership of its resources.

LinearOperator(LinearOperator &&other) = default

Move constructor.

Enables the move semantics for GradientOperator instances. This allows the efficient transfer of resources from one object to another without copying.

virtual ~LinearOperator() = default

Virtual destructor.

Ensures that derived classes can be properly cleaned up through pointers to the base class. This destructor is defaulted.

LinearOperator &operator=(const LinearOperator &other) = delete

Copy assignment operator (deleted).

Disables the copy assignment of GradientOperator instances. This prevents the accidental or intentional copying of an instance, enforcing unique ownership of its resources.

LinearOperator &operator=(LinearOperator &&other) = default

Move assignment operator.

Enables the move assignment of GradientOperator instances, allowing resources to be transferred between objects without copying.

virtual void apply(const TypedFieldBase<Real> &nodal_field, TypedFieldBase<Real> &quadrature_point_field) const = 0

Applies the gradient operation.

This method evaluates the gradient of a field defined at nodal points and writes the result into a field defined at quadrature points.

Parameters:
  • nodal_field – The input field from which the gradient is computed. Defined on nodal points.

  • quadrature_point_field – The output field where the gradient is written. Defined on quadrature points.

virtual void apply_increment(const TypedFieldBase<Real> &nodal_field, const Real &alpha, TypedFieldBase<Real> &quadrature_point_field) const = 0

Applies the gradient operation with increment.

Evaluates the gradient of a field defined at nodal points and adds the result to a field defined at quadrature points.

Parameters:
  • nodal_field – The input field from which the gradient is computed. Defined on nodal points.

  • alpha – A scaling factor applied to the gradient before adding it to the quadrature_point_field.

  • quadrature_point_field – The field to which the scaled gradient is added. Defined on quadrature points.

virtual void transpose(const TypedFieldBase<Real> &quadrature_point_field, TypedFieldBase<Real> &nodal_field, const std::vector<Real> &weights = {}) const = 0

Applies the discretised divergence operation.

Evaluates the discretised divergence of a field defined at quadrature points and writes the result into a field defined at nodal points.

Parameters:
  • quadrature_point_field – The input field from which the divergence is computed. Defined on quadrature points.

  • nodal_field – The output field where the divergence is written. Defined on nodal points.

  • weights – Optional Gaussian quadrature weights. If omitted, a scaled version of the discretised divergence is returned.

virtual void transpose_increment(const TypedFieldBase<Real> &quadrature_point_field, const Real &alpha, TypedFieldBase<Real> &nodal_field, const std::vector<Real> &weights = {}) const = 0

Applies the discretised divergence operation with increment.

Evaluates the discretised divergence of a field defined at quadrature points and adds the result to a field defined at nodal points.

Parameters:
  • quadrature_point_field – The input field from which the divergence is computed. Defined on quadrature points.

  • alpha – A scaling factor applied to the divergence before adding it to the nodal_field.

  • nodal_field – The field to which the scaled divergence is added. Defined on nodal points.

  • weights – Optional Gaussian quadrature weights. If omitted, a scaled version of the discretised divergence is returned.

virtual Index_t get_nb_output_components() const = 0

Returns the number of output components per pixel/voxel.

For gradient operators, this is the number of gradient components (typically equal to spatial dimension).

Returns:

The number of output components.

virtual Index_t get_nb_quad_pts() const = 0

Returns the number of quadrature points per pixel/voxel.

Calculates the total number of quadrature points associated with each pixel/voxel, summing the quadrature points of all elements belonging to the pixel/voxel.

Returns:

The total number of quadrature points per pixel/voxel.

virtual Index_t get_nb_input_components() const = 0

Returns the number of input components per pixel/voxel.

For gradient operators, this is typically 1 (one scalar value per grid point, with neighbors accessed via ghost communication).

Returns:

The number of input components per pixel/voxel.

virtual Dim_t get_spatial_dim() const = 0

Returns the spatial dimension of the gradient operator.

Returns:

The spatial dimensionality of the operations performed by this gradient operator.

class LocalFieldCollection : public muGrid::FieldCollection

muGrid::LocalFieldCollection derives from muGrid::FieldCollection and stores local fields, i.e. fields that are only defined for a subset of all pixels/voxels in the computational domain. The coordinates of these active pixels are explicitly stored by this field collection. muGrid::LocalFieldCollection::add_pixel allows to add individual pixels/voxels to the field collection.

Public Types

using Parent = FieldCollection

alias for base class

Public Functions

LocalFieldCollection() = delete

Default constructor.

LocalFieldCollection(Dim_t spatial_dimension, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())

Constructor

Parameters:
  • spatial_dimension – spatial dimension of the field (can be muGrid::Unknown, e.g., in the case of the local fields for storing internal material variables)

  • nb_sub_pts – number of sub-points per pixel

  • device – where to allocate field memory

LocalFieldCollection(Dim_t spatial_dimension, const std::string &name, const SubPtMap_t &nb_sub_pts = {}, Device device = Device::cpu())

Constructor with explicit given name for the field collection. This name can be arbitrary and only has to be unique for all LocalFieldCollections which are saved to the same NetCDF file through the parallel IO object ‘FileIONetCDF’. If you register two LocalFieldCollections with the same name in a FileIONetCDF object you will get a muGrid::FieldCollectionError.

Parameters:
  • spatial_dimension – spatial dimension of the field

  • name – unique name for the field collection

  • nb_sub_pts – number of sub-points per pixel

  • device – where to allocate field memory

LocalFieldCollection(const LocalFieldCollection &other) = delete

Copy constructor.

LocalFieldCollection(LocalFieldCollection &&other) = default

Move constructor.

~LocalFieldCollection() override = default

Destructor.

LocalFieldCollection &operator=(const LocalFieldCollection &other) = delete

Copy assignment operator.

LocalFieldCollection &operator=(LocalFieldCollection &&other) = delete

Move assignment operator.

void add_pixel(const size_t &global_index)

Insert a new pixel/voxel into the collection.

Parameters:

global_index – refers to the linear index this pixel has in the global field collection defining the problem space

void initialise()

Freeze the set of pixels this collection is responsible for and allocate memory for all fields of the collection. Fields added lateron will have their memory allocated upon construction

LocalFieldCollection get_empty_clone(const std::string &new_name) const

obtain a new field collection with the same domain and pixels and a given new name

LocalFieldCollection get_empty_clone() const

obtain a new field collection with the same domain and pixels and the same name

virtual Shape_t get_pixels_shape() const override

return shape of the pixels

virtual Shape_t get_pixels_shape_without_ghosts() const override

return shape of the pixels

virtual Index_t get_nb_pixels_without_ghosts() const override

return the number of pixels without ghosts

virtual Shape_t get_pixels_offset_without_ghosts() const override

return the offset of the pixels in the storage without ghosts

virtual Shape_t get_pixels_strides(Index_t element_size = 1) const override

return strides of the pixels

inline std::map<Index_t, Index_t> &get_global_to_local_index_map()
const std::string &get_name() const

return the unique name of the local field collection

Protected Attributes

std::map<Index_t, Index_t> global_to_local_index_map = {}
std::string name = {}
template<class FieldMapType>
class MappedField
#include <mapped_field.hh>

MappedFields are a combination of a field and an associated map, and as such it does not introduce any new functionality that Fields and FieldMaps do not already possess. They provide a convenience structure for the default use case of internal variables, which are typically used only by a single material and always the same way.

Public Types

using Scalar = typename FieldMapType::Scalar

stored scalar type

using Return_t = typename FieldMapType::template Return_t<FieldMapType::FieldMutability()>

return type for iterators over this- map

using iterator = typename FieldMapType::iterator

iterator over this map

using const_iterator = typename FieldMapType::const_iterator

constant iterator over this map

Public Functions

MappedField() = delete

Default constructor.

template<bool StaticConstructor = IsStatic(), std::enable_if_t<StaticConstructor, int> = 0>
inline MappedField(const std::string &unique_name, FieldCollection &collection, const std::string &sub_division_tag, const Unit &unit = Unit::unitless())

Constructor with name and collection for statically sized mapped fields

template<bool StaticConstructor = IsStatic(), std::enable_if_t<not StaticConstructor, int> = 0>
inline MappedField(const std::string &unique_name, const Index_t &nb_rows, const Index_t &nb_cols, const IterUnit &iter_type, FieldCollection &collection, const std::string &sub_division_tag, const Unit &unit = Unit::unitless())

Constructor for dynamically sized mapped field

Parameters:
  • unique_name – unique identifier for this field

  • nb_rows – number of rows for the iterates

  • nb_cols – number of columns for the iterates

  • iter_type – whether to iterate over pixels or quadrature points

  • collection – collection where the field is to be registered

  • unit – physical units of mapped field

  • nb_sub_pts – number of subpoints per pixel. Specify only if iter_type is muGrid::IterUnit::FreePt

template<bool StaticConstructor = IsStatic(), std::enable_if_t<StaticConstructor, int> = 0>
inline explicit MappedField(TypedField<Scalar> &field)

Constructor of statically sized mapped fields from a pre-existing field checking the consistency of the size of the map and the field is handled in the constructor of the FieldMap

template<bool StaticConstructor = IsStatic(), std::enable_if_t<not StaticConstructor, int> = 0>
inline MappedField(TypedField<Scalar> &field, const Index_t &nb_rows, const IterUnit &iter_type)

Constructor of statically sized mapped fields from a pre-existing field checking the consistency of the size of the map and the field is handled in the constructor of the FieldMap

MappedField(const MappedField &other) = delete

Copy constructor.

MappedField(MappedField &&other) = default

Move constructor.

virtual ~MappedField() = default

Destructor.

MappedField &operator=(const MappedField &other) = delete

Copy assignment operator.

MappedField &operator=(MappedField &&other) = default

Move assignment operator.

inline MappedField &operator-=(const MappedField &other)

subtraction assignment

inline MappedField &operator+=(const MappedField &other)

addition assignment

inline MappedField &operator=(const TypedFieldBase<Scalar> &other)

Copy assignment operator.

inline MappedField &operator=(const typename TypedFieldBase<Scalar>::Negative &other)

Copy assignment operator.

inline Return_t operator[](size_t index)

random access operator

inline iterator begin()

stl

inline iterator end()

stl

inline const_iterator begin() const

stl

inline const_iterator end() const

stl

inline TypedField<Scalar> &get_field()

return a reference to the mapped field

inline const TypedField<Scalar> &get_field() const

return a reference to the mapped field

inline FieldMapType &get_map()

return a reference to the map

inline const FieldMapType &get_map() const

return a reference to the map

Public Static Functions

static inline constexpr bool IsStatic()

detemine at compile time whether the field map is statically sized

Protected Attributes

TypedField<Scalar> &field

reference to mapped field

FieldMapType map

associated field map

template<class StateFieldMapType>
class MappedStateField

MappedStateFields are a combination of a state field and an associated map, and as such it does not introduce any new functionality that StateFields and StateFieldMaps do not already possess. They provide a convenience structure for the default use case of internal variables, which are typically used only by a single material and always the same way.

Public Types

using Scalar = typename StateFieldMapType::Scalar

stored scalar type

using Return_t = typename StateFieldMapType::template StaticStateWrapper<StateFieldMapType::FieldMutability()>

return type for iterators over this- map

using iterator = typename StateFieldMapType::iterator

iterator over this map

using const_iterator = typename StateFieldMapType::const_iterator

constant iterator over this map

Public Functions

MappedStateField() = delete

Deleted default constructor.

inline MappedStateField(const std::string &unique_name, FieldCollection &collection, const std::string &sub_division_tag)

Constructor with name and collection.

MappedStateField(const MappedStateField &other) = delete

Copy constructor.

MappedStateField(MappedStateField &&other) = default

Move constructor.

virtual ~MappedStateField() = default

Destructor.

MappedStateField &operator=(const MappedStateField &other) = delete

Copy assignment operator.

MappedStateField &operator=(MappedStateField &&other) = default

Move assignment operator.

inline Return_t operator[](size_t index)

random access operator

inline iterator begin()

stl

inline iterator end()

stl

inline const_iterator begin() const

stl

inline const_iterator end() const

stl

inline TypedStateField<Scalar> &get_state_field()

return a reference to the mapped state field

inline StateFieldMapType &get_map()

return a reference to the map

Protected Attributes

size_t nb_components

number of components stored per quadrature point

TypedStateField<Scalar> &state_field

ref to mapped state field

StateFieldMapType map

associated field map

template<size_t N>
class multi_iter

Public Functions

inline multi_iter(const arr_info &iarr_, const arr_info &oarr_, size_t idim_)
inline void advance(size_t n)
inline ptrdiff_t iofs(size_t i) const
inline ptrdiff_t iofs(size_t j, size_t i) const
inline ptrdiff_t oofs(size_t i) const
inline ptrdiff_t oofs(size_t j, size_t i) const
inline size_t length_in() const
inline size_t length_out() const
inline ptrdiff_t stride_in() const
inline ptrdiff_t stride_out() const
inline size_t remaining() const

Private Functions

inline void advance_i()

Private Members

shape_t pos
const arr_info &iarr
const arr_info &oarr
ptrdiff_t p_ii
ptrdiff_t p_i[N]
ptrdiff_t str_i
ptrdiff_t p_oi
ptrdiff_t p_o[N]
ptrdiff_t str_o
size_t idim
size_t rem
template<typename T>
class ndarr : public pocketfft::detail::cndarr<T>

Public Functions

inline ndarr(void *data_, const shape_t &shape_, const stride_t &stride_)
inline T &operator[](ptrdiff_t ofs)
struct Negative
#include <field_typed.hh>

Simple structure used to allow for lazy evaluation of the unary ‘-’ sign. When assiging the the negative of a field to another, as in field_a = -field_b, this structure allows to implement this operation without needing a temporary object holding the negative value of field_b.

Public Members

const TypedFieldBase &field

field on which the unary ‘-’ was applied

class NetCDFAtt
#include <file_io_netcdf.hh>

Class to store the attributes belonging to a NetCDFVar variable (att_name, data_type, nelems, value, name_initialised, value_initialised)

Subclassed by muGrid::NetCDFGlobalAtt

Public Functions

NetCDFAtt() = delete

Default constructor.

NetCDFAtt(const std::string &att_name, const std::vector<char> &value)

Constructor with the attribute name and its value (char, muGrid::Int, muGrid::Uint, muGrid::real) the values are represented by std::vector<T> of the corresponding type ‘T’. The type char has an additional convenience constructor which can take also std::string as input.

NetCDFAtt(const std::string &att_name, const std::string &value)
NetCDFAtt(const std::string &att_name, const std::vector<muGrid::Int> &value)
NetCDFAtt(const std::string &att_name, const std::vector<muGrid::Uint> &value)
NetCDFAtt(const std::string &att_name, const std::vector<muGrid::Index_t> &value)
NetCDFAtt(const std::string &att_name, const std::vector<muGrid::Real> &value)
NetCDFAtt(const std::string &att_name, const nc_type &att_data_type, const IOSize_t &att_nelems)

Constructor with the attribute name, data_type and nelems

NetCDFAtt(const NetCDFAtt &other) = default

Copy constructor.

NetCDFAtt(NetCDFAtt &&other) = default

Move constructor.

virtual ~NetCDFAtt() = default

Destructor.

NetCDFAtt &operator=(const NetCDFAtt &other) = delete

Copy assignment operator.

NetCDFAtt &operator=(NetCDFAtt &&other) = delete

Move assignment operator.

const std::string &get_name() const

return attribute name

const nc_type &get_data_type() const

return nc_type data type of attribute value

const IOSize_t &get_nelems() const

return ‘nelems’ number of values stored in the attribute value

IOSize_t get_data_size() const

return the size of the attributes raw data in bytes

IOSize_t get_name_size() const

return the size of the attributes name in bytes

const void *get_value() const

return a const pointer on the attribute value

template<typename T>
const std::vector<T> &get_typed_value() const

return the attribute values in its ‘real type’. It is only allowed to call the function with a type that matches the attribute’s data_type. If you call it with a mismatched type, a FileIOError will be thrown. Supported types: char, muGrid::Int, muGrid::Uint, muGrid::Index_t, muGrid::Real

const std::vector<char> &get_typed_value_c() const
const std::vector<muGrid::Int> &get_typed_value_i() const
const std::vector<muGrid::Uint> &get_typed_value_ui() const
const std::vector<muGrid::Index_t> &get_typed_value_l() const
const std::vector<muGrid::Real> &get_typed_value_d() const
std::string get_value_as_string() const

return the attribute value as std::string

std::string convert_void_value_to_string(void *value) const

converts an input void * value into an std::string under the assumption that its data type is equal to the attributes data type and also its number of elements corresponds to the attributes number of elements. Internal the function get_value_as_string() is used.

void register_value(void *value)

register the attribute value from a void * on the value it is assumed that the value type is the already registered data_type.

void *reserve_value_space()

reserve enoug space for the value returned from the NetCDF file and return a pointer on it

bool equal_value(void *value) const

compares the input void * value with the stored attributes value and returns true if they have the same value(s) and otherwise false. The function compares the actual stored value(s) and not the pointers.

bool is_name_initialised() const

return initialisation status of name, data_type and nelems

bool is_value_initialised() const

return initialisation status of the value

Private Types

using AttributeValue = std::variant<std::vector<char>, std::vector<muGrid::Int>, std::vector<muGrid::Uint>, std::vector<muGrid::Index_t>, std::vector<muGrid::Real>>

Private Functions

void update_attribute(const std::string &new_att_name, const nc_type &new_att_data_type, const IOSize_t &new_att_nelems, void *new_att_value)

update the name and value of the NetCDFAtt while keeping the data_type. The user of this function is responsible to take care of possible resulting time consuming extensions of the NetCDF header.

void *get_value_non_const_ptr()

return a non const pointer on the attribute value

Private Members

std::string att_name
nc_type data_type = {NC_NAT}
IOSize_t nelems = {0}
AttributeValue value = {std::vector<char>()}
bool name_initialised{false}
bool value_initialised = {false}

Friends

friend class NetCDFGlobalAtt
class NetCDFDim
#include <file_io_netcdf.hh>

Class to store the properties of a single NetCDF dimension (name, id, size, initialised)

Public Functions

NetCDFDim() = delete

Default constructor.

NetCDFDim(const std::string &dim_base_name, const IOSize_t &dim_size)

Constructor with the dimension name and size

NetCDFDim(const NetCDFDim &other) = default

Copy constructor.

NetCDFDim(NetCDFDim &&other) = delete

Move constructor.

virtual ~NetCDFDim() = default

Destructor.

NetCDFDim &operator=(const NetCDFDim &other) = delete

Copy assignment operator.

NetCDFDim &operator=(NetCDFDim &&other) = delete

Move assignment operator.

const int &get_id() const

get_dimension id

int &set_id()

set_dimension id

const IOSize_t &get_size() const

get_dimension size

const std::string &get_name() const

get_dimension name

std::string get_base_name() const

get the base name of the dimension

int compute_tensor_dim_index() const
bool equal(const std::string &dim_name, const IOSize_t &dim_size) const

compare the dimension is equal to the given dim_name and size

void register_id(const int dim_id)

register dimension id, only possible if the id was not already registered (initialised == false).

void register_unlimited_dim_size()

register unlimited dimension size to NC_UNLIMITED this is only possible for the dimension with name “frame”.

Public Static Functions

static std::string compute_base_name(const std::string &full_name)

compute the base name of a given name.

static std::string compute_dim_name(const std::string &dim_base_name, const std::string &suffix)

Protected Attributes

int id = {DEFAULT_NETCDFDIM_ID}

location to store the returned dimension ID.

IOSize_t size = {}

Length of dimension; that is, number of values for this dimension as an index to variables that use it. 0 is reserved for the unlimited dimension, NC_UNLIMITED.

std::string name

Dimension name. Must be a legal netCDF identifier.

bool initialised{false}

bool to check the initialisation status of a dimension only true if size was correct initialised.

class NetCDFDimensions
#include <file_io_netcdf.hh>

Class to store the NetCDF dimensions (dim_vector, global_domain_grid)

Public Functions

NetCDFDimensions() = default
NetCDFDimensions(const NetCDFDimensions &other) = delete

Copy constructor.

NetCDFDimensions(NetCDFDimensions &&other) = delete

Move constructor.

virtual ~NetCDFDimensions() = default

Destructor.

NetCDFDimensions &operator=(const NetCDFDimensions &other) = delete

Copy assignment operator.

NetCDFDimensions &operator=(NetCDFDimensions &&other) = delete

Move assignment operator.

std::shared_ptr<NetCDFDim> add_dim(const std::string &dim_name, const IOSize_t &dim_size)

Add a Dimension given its base name and size returns a std::shared_ptr<NetCDFDim> to the added NetCDFDim object

void add_field_dims_global(const muGrid::Field &field, std::vector<std::shared_ptr<NetCDFDim>> &field_dims, std::string state_field_name = std::string{})

Add all dimensions of a global Field (f, (h,) s, n, x, y, z) f: frame h: history index for state fields x: number of points in x direction y: number of points in y direction z: number of points in z direction s: number of sub points per point (pixel) n: number of DOFs per sub point

void add_field_dims_local(const muGrid::Field &field, std::vector<std::shared_ptr<NetCDFDim>> &field_dims, const Communicator &comm, std::string state_field_name = std::string{})

Add all dimensions of a local Field (f, (h,) s, n, i) f: frame h: history index for state fields s: number of sub points per point (pixel) n: number of DOFs per sub point i: total number of points (pixels) in the local field

std::shared_ptr<NetCDFDim> find_dim(const std::string &dim_name, const IOSize_t &dim_size)

find dimension by unique dim_name and size returns a std::shared_ptr<NetCDFDim> to the found dimension, if the dimension is not found it returns the end of the dim_vector of the NetCDFDimensions object and throws a muGrid::FielIOError.

std::shared_ptr<NetCDFDim> find_dim(const std::string &dim_name)

find dimension only by the unique dim_name returns a std::shared_ptr<NetCDFDim> to the found dimension, if the dimension is not found it returns the end of the dim_vector of the NetCDFDimensions object and throws a muGrid::FielIOError.

const std::vector<std::shared_ptr<NetCDFDim>> &get_dim_vector() const

return a std::vector<std::shared_ptr<NetCDFDim>> & of all NetCDFDims belonging to the NetCDFDimensions

Protected Attributes

std::vector<std::shared_ptr<NetCDFDim>> dim_vector = {}
std::vector<Index_t> global_domain_grid = {0, 0, 0}
class NetCDFGlobalAtt : public muGrid::NetCDFAtt
#include <file_io_netcdf.hh>

Class to represent GLOBAL NetCDF attributes which do not belong to a NetCDFVar

Public Functions

NetCDFGlobalAtt() = delete

Default constructor.

NetCDFGlobalAtt(const std::string &att_name, const std::vector<char> &value)

Constructor from parent with the attribute name and its value (char, muGrid::Int, muGrid::Uint, muGrid::real) the values are represented by std::vector<T> of the corresponding type ‘T’. The type char has an additional convenience constructor which can take also std::string as input.

NetCDFGlobalAtt(const std::string &att_name, const std::string &value)
NetCDFGlobalAtt(const std::string &att_name, const std::vector<muGrid::Int> &value)
NetCDFGlobalAtt(const std::string &att_name, const std::vector<muGrid::Uint> &value)
NetCDFGlobalAtt(const std::string &att_name, const std::vector<muGrid::Index_t> &value)
NetCDFGlobalAtt(const std::string &att_name, const std::vector<muGrid::Real> &value)
NetCDFGlobalAtt(const std::string &att_name, const nc_type &att_data_type, const IOSize_t &att_nelems)

Constructor from parent with the attribute name, data_type and nelems

NetCDFGlobalAtt(const NetCDFGlobalAtt &other) = default

Copy constructor.

NetCDFGlobalAtt(NetCDFGlobalAtt &&other) = delete

Move constructor.

virtual ~NetCDFGlobalAtt() = default

Destructor.

NetCDFGlobalAtt &operator=(const NetCDFGlobalAtt &other) = delete

Copy assignment operator.

NetCDFGlobalAtt &operator=(NetCDFGlobalAtt &&other) = delete

Move assignment operator.

inline bool is_already_written_to_file()

check if the global attribute was already written to the file; true &#8212; the attribute was already written to the file false &#8212; the attribute was up to now not written to the file

inline void was_written()

call this function after the NetCDFGlobalAtt was written to the NetCDF file to set is_written to true.

template<class T>
inline void update_global_attribute(const std::string &new_att_name, T new_att_value)

changes the global attributes value to new_value if the type of the new_value matches the old value and the size of the new_value does not exceed the size of the old value. Here with old value the current calue of the global attribute is meant.

Protected Attributes

bool is_written
class NetCDFGlobalAttributes
#include <file_io_netcdf.hh>

Class to store the GLOBAL NetCDF attributes

Public Functions

NetCDFGlobalAttributes() = default
NetCDFGlobalAttributes(const NetCDFGlobalAttributes &other) = delete

Copy constructor.

NetCDFGlobalAttributes(NetCDFGlobalAttributes &&other) = delete

Move constructor.

virtual ~NetCDFGlobalAttributes() = default

Destructor.

NetCDFGlobalAttributes &operator=(const NetCDFGlobalAttributes &other) = delete

Copy assignment operator.

NetCDFGlobalAttributes &operator=(NetCDFGlobalAttributes &&other) = delete

Move assignment operator.

template<class T>
inline NetCDFGlobalAtt &add_attribute(const std::string &global_att_name, const T &value)

add a global attribute in all available value type versions

const NetCDFGlobalAtt &get_attribute(const std::string &global_att_name) const

get a global attribute from the global_att_vector by its name

const std::vector<std::shared_ptr<NetCDFGlobalAtt>> get_global_attribute_vector() const

get a const std::vector<std::shared_ptr<NetCDFGlobalAtt>> of all NetCDFGlobalAtts belonging to the NetCDFGlobalAttributes object, i.e. a const view on the global_att_vector.

std::vector<std::shared_ptr<NetCDFGlobalAtt>> set_global_attribute_vector()

get a std::vector<std::shared_ptr<NetCDFGlobalAtt>> of all NetCDFGlobalAtts belonging to the NetCDFGlobalAttributes object, i.e. a non const view on the global_att_vector.

std::shared_ptr<NetCDFGlobalAtt> set_global_attribute(const std::string &global_att_name)

get a std::shared_ptr<NetCDFGlobalAtt> of the NetCDFGlobalAtt with name ‘global_att_name’ from the global_att_vector.

std::vector<std::string> get_global_attribute_names() const

get a std::vector<std::string> of all global attribute names

void register_attribute(const std::string &g_att_name, const nc_type &g_att_data_type, const IOSize_t &g_att_nelems)

register a global attribute by its name (g_att_name), data type (g_att_data_type) and number of elements (g_att_nelems), afterwards you can read in a value of type ‘void *’ from a NetCDF file by e.g. ncmu_get_att()

std::string todays_date() const

std::string todays date

std::string time_now() const

std::string time now

void add_date_and_time(std::string name_prefix = "creation")

add the actual date and time to the global_att_vector as creation_date and creation_time

void add_muGrid_version_info()

add muGrid version information

Protected Functions

void check_global_attribute_name(const std::string global_att_name)

check if the global_att_name is valid/already in use no Error &#8212; if global_att_name is valid and was not used before Error &#8212; if global_att_name is in use and can not be used twice

Protected Attributes

std::vector<std::shared_ptr<NetCDFGlobalAtt>> global_att_vector = {}
class NetCDFVarBase
#include <file_io_netcdf.hh>

Base class to store the properties of a single NetCDF variable (name, data_type, ndims, id, netcdf_dims, field, netcdf_atts, initialised, validity_domain, local_field_name, hidden)

Subclassed by muGrid::NetCDFVarField, muGrid::NetCDFVarStateField

Public Functions

NetCDFVarBase() = delete

Default constructor.

NetCDFVarBase(const std::string &var_name, const nc_type &var_data_type, const IOSize_t &var_ndims, const std::vector<std::shared_ptr<NetCDFDim>> &netcdf_var_dims, const muGrid::FieldCollection::ValidityDomain &validity_domain, bool hidden = false)

Constructor with the variable name, data type, variable dimensions and a vector of shared pointers to its associated NetCDFDims.

NetCDFVarBase(const NetCDFVarBase &other) = default

Copy constructor.

NetCDFVarBase(NetCDFVarBase &&other) = delete

Move constructor.

virtual ~NetCDFVarBase() = default

Destructor.

NetCDFVarBase &operator=(const NetCDFVarBase &other) = delete

Copy assignment operator.

NetCDFVarBase &operator=(NetCDFVarBase &&other) = delete

Move assignment operator.

const std::string &get_name() const

get the name of the NetCDF variable

const nc_type &get_data_type() const

get the data type of the NetCDF variable

const IOSize_t &get_ndims() const

get the number of dimensions of the NetCDF variable

const int &get_id() const

get the unique id of the NetCDF variable

int &set_id()

get a non const reference to the unique id of the NetCDF variable to set its value

std::vector<int> get_netcdf_dim_ids() const

get a vector of all dimension ids of the NetCDF variable

std::vector<std::string> get_netcdf_dim_names() const

get a vector of all dimension names of the NetCDF variable

virtual const muGrid::Field &get_field() const = 0

get a reference to the field represented by the NetCDF variable

const std::vector<NetCDFAtt> &get_netcdf_attributes() const

get a const std::vector<NetCDFAtt> & of all attributes belonging to the NetCDFVarBase

std::vector<NetCDFAtt> &set_netcdf_attributes()

get a non const std::vector<NetCDFAtt> & of all attributes belonging to the NetCDFVarBase to set the actual values of the attributes

std::vector<std::string> get_netcdf_attribute_names() const

get a std::vector<std::string> with the names of all attributes

const muGrid::FieldCollection::ValidityDomain &get_validity_domain() const

get the FieldCollection::ValidityDomain & of the NetCDFVarBase

IOSize_t get_nb_local_pixels() const

get the number of pixels of the local field collection living on the current processor

void *get_buf() const

get a pointer to the raw data for the NetCDF variable

IOSize_t get_bufcount_mpi_global() const

An integer indicates the number of MPI derived data type elements in the global variable buffer to be written to a file.

IOSize_t get_bufcount_mpi_local() const

An integer indicates the number of MPI derived data type elements in the local variable buffer to be written to a file. (this is the buf count for a single pixel)

Datatype_t get_buftype() const

A data type that describes the memory layout of the variable buffer.

virtual std::vector<IOSize_t> get_start_global(const Index_t &frame) const = 0

A vector of IOSize_t values specifying the index in the variable where the first of the data values will be written. This function gives the start for contiguous global fields written with ncmu_put_varm_all

virtual std::vector<IOSize_t> get_start_local(const Index_t &frame, muGrid::Field &local_pixels) const = 0

A vector of IOSize_t values specifying the index in the variable where the first of the data values will be written. This function gives the start for distributed local fields written with ncmu_put_varn_all

std::vector<IOSize_t> get_count_global() const

A vector of IOSize_t values specifying the edge lengths along each dimension of the block of data values to be written. This function gives the count for contiguous global fields written with ncmu_put_varm_all

std::vector<IOSize_t> get_count_local(muGrid::Field &local_pixels) const

A vector of IOSize_t values specifying the edge lengths along each dimension of the block of data values to be written. This function gives the count for distributed local fields written with ncmu_put_varn_all

virtual std::vector<IODiff_t> get_nc_stride() const = 0
virtual std::vector<IODiff_t> get_nc_imap_global() const = 0
virtual std::vector<IODiff_t> get_nc_imap_local() const = 0
virtual DimensionStartValue get_dimension_start_value(const std::string &base_name, const Index_t &frame) const

Get the start value for a specific dimension type This method is called by compute_start_vector to get individual dimension values

std::vector<IOSize_t> compute_start_vector_global(const Index_t &frame) const

Common implementation to compute start vector for both global and state fields Subclasses call this to avoid code duplication

void register_id(const int var_id)

register variable id, only possible if the id was not already registered (id=-1).

void register_local_field_name(const std::string &local_field_name)

register local_field_name, only possible if the variable belongs to a local field collection

const std::string &get_local_field_name() const

get the local_field_name, only possible if the variable belongs to a local field collection

bool get_hidden_status() const

return the status of the variable whether it is a hidden=true netCDFVar which is only used for book keeping of local fields or a normal NetCDFVarBase hidden=false

template<typename T>
inline void add_attribute(const std::string &att_name, const T &value)

add an attribute to the variable by its name and value the following types are supported:

void register_attribute(const std::string &att_name, const nc_type &att_data_type, const IOSize_t &att_nelems)

register an attribute by its name (att_name), data type (att_data_type) and number of elements (att_nelems), afterwards you can read in a value of type ‘void *’ from a NetCDF file by e.g. ncmu_get_att()

void add_attribute_unit()

add the unit of the field as attribute to the variable

void add_attribute_local_pixels_field()

add the name of the associated local pixels field as attribute to the variable

void *increment_buf_ptr(void *buf_ptr, const IOSize_t &increment_nb_elements) const

increments the input buf pointer “buf_ptr” by n elements “increment_nb_elements” and returns the incremented void pointer to the new buffer position. This function is made to increment the pointer of the variables field. Therefore the variables data_type is assumed to be the data type of the input void * buf_ptr. If your input does not have the same type the increment will give you wrong results

void consistency_check_global_var() const

cross check the properties (start, count, stride and imap, which are crucial for reading and writing) of the initialised NetCDFVarBase for consistency.

void consistency_check_local_var(muGrid::Field &local_pixels) const
virtual void write(const int netcdf_id, const Index_t &tot_nb_frames, GlobalFieldCollection &GFC_local_pixels, const Index_t &frame_index)

actual call of NetCDF functions to write a single NetCDFVar into the NetCDF file

virtual void read(const int netcdf_id, const Index_t &tot_nb_frames, GlobalFieldCollection &GFC_local_pixels, const Index_t &frame_index)

actual call of NetCDF functions to read in the data of a single NetCDFVar from a NetCDF file

Public Static Functions

template<typename T>
static inline constexpr nc_type type_to_nc_type()

Compile-time type to nc_type mapping for supported types This uses the pre-computed netcdf_type<T>() values

Protected Attributes

std::string name
nc_type data_type = {NC_NAT}
IOSize_t ndims = {}
int id = {DEFAULT_NETCDFVAR_ID}
std::vector<std::shared_ptr<NetCDFDim>> netcdf_dims{nullptr}
std::vector<NetCDFAtt> netcdf_atts = {}
bool initialised{false}

bool to check the initialisation status of a variable only true if ndims was correct initialised.

const muGrid::FieldCollection::ValidityDomain validity_domain = {}
std::string local_field_name = {}
bool hidden = {false}
class NetCDFVarField : public muGrid::NetCDFVarBase
#include <file_io_netcdf.hh>

Class to store the properties of a single NetCDF variable representing a Field

Public Functions

NetCDFVarField() = delete

Default constructor.

NetCDFVarField(const std::string &var_name, const nc_type &var_data_type, const IOSize_t &var_ndims, const std::vector<std::shared_ptr<NetCDFDim>> &netcdf_var_dims, muGrid::Field &var_field, bool hidden = false)

Constructor with the variable name, data type, variable dimensions and a vector of shared pointers to its associated NetCDFDims.

NetCDFVarField(const NetCDFVarField &other) = default

Copy constructor.

NetCDFVarField(NetCDFVarField &&other) = delete

Move constructor.

~NetCDFVarField() override = default

Destructor.

NetCDFVarField &operator=(const NetCDFVarField &other) = delete

Copy assignment operator.

NetCDFVarField &operator=(NetCDFVarField &&other) = delete

Move assignment operator.

virtual const muGrid::Field &get_field() const override

get a reference to the field represented by the NetCDF variable

virtual std::vector<IOSize_t> get_start_global(const Index_t &frame) const override

A vector of IOSize_t values specifying the index in the variable where the first of the data values will be written. This function gives the start for contiguous global fields written with ncmu_put_varm_all

virtual std::vector<IOSize_t> get_start_local(const Index_t &frame, muGrid::Field &local_pixels) const override

A vector of IOSize_t values specifying the index in the variable where the first of the data values will be written. This function gives the start for distributed local fields written with ncmu_put_varn_all

virtual std::vector<IODiff_t> get_nc_stride() const override
virtual std::vector<IODiff_t> get_nc_imap_global() const override
virtual std::vector<IODiff_t> get_nc_imap_local() const override
virtual void write(const int netcdf_id, const Index_t &tot_nb_frames, GlobalFieldCollection &GFC_local_pixels, const Index_t &frame_index) override

actual call of NetCDF functions to write a single NetCDFVar into the NetCDF file

virtual void read(const int netcdf_id, const Index_t &tot_nb_frames, GlobalFieldCollection &GFC_local_pixels, const Index_t &frame_index) override

actual call of NetCDF functions to read in the data of a single NetCDFVar from a NetCDF file

Protected Attributes

muGrid::Field &field
class NetCDFVariables
#include <file_io_netcdf.hh>

Class to store the NetCDF variables

Public Functions

NetCDFVariables() = default
NetCDFVariables(const NetCDFVariables &other) = delete

Copy constructor.

NetCDFVariables(NetCDFVariables &&other) = delete

Move constructor.

virtual ~NetCDFVariables() = default

Destructor.

NetCDFVariables &operator=(const NetCDFVariables &other) = delete

Copy assignment operator.

NetCDFVariables &operator=(NetCDFVariables &&other) = delete

Move assignment operator.

NetCDFVariables &operator+=(std::shared_ptr<NetCDFVarBase> &rhs)

Add operator for a single NetCDFVarBase.

NetCDFVarBase &add_field_var(muGrid::Field &var_field, const std::vector<std::shared_ptr<NetCDFDim>> &var_dims, bool hidden = false)

Add a local or global field as variable and attach the dimensions to it.

NetCDFVarBase &add_state_field_var(muGrid::StateField &var_state_field, const std::vector<std::shared_ptr<NetCDFDim>> &var_dims)

Add a local or global state field as variable and attach the dimensions to it.

const std::vector<std::shared_ptr<NetCDFVarBase>> &get_var_vector() const

return a const reference on the var_vector which stores all variables

std::vector<std::shared_ptr<NetCDFVarBase>> &set_var_vector()

return a non const reference on the var_vector which stores all variables to modify the NetCDFVarBase objects

std::vector<std::string> get_names() const

vector of all variable names (i.e. all field names stored in variables) with exception of the book keeping variables for the local fields which can be given by get_hidden_names()

std::vector<std::string> get_hidden_names() const

vector of all book keeping variables for the registered local fields

const NetCDFVarBase &get_variable(const std::string &var_name) const

get a NetCDFVarBase variable from the var_vector by its unique name

NetCDFVarBase &get_variable(const std::string &var_name)

get a NetCDFVarBase variable from the var_vector by its unique name

Protected Attributes

std::vector<std::shared_ptr<NetCDFVarBase>> var_vector = {}
class NetCDFVarStateField : public muGrid::NetCDFVarBase
#include <file_io_netcdf.hh>

Class to store the properties of a single NetCDF variable representing a StateField. The class behaves like it represents a single Field of the StateField. The state_filed_index decides which Field is represented. The Fields are always ordered such that state_field_index=0 represents the current Field of the StateField and state_field_index=nb_memory represents the oldest Field of the StateField.

Public Functions

NetCDFVarStateField() = delete

Default constructor.

NetCDFVarStateField(const std::string &var_name, const nc_type &var_data_type, const IOSize_t &var_ndims, const std::vector<std::shared_ptr<NetCDFDim>> &netcdf_var_dims, muGrid::StateField &var_state_field)

Constructor with the variable name, data type, variable dimensions and a vector of shared pointers to its associated NetCDFDims.

NetCDFVarStateField(const NetCDFVarStateField &other) = default

Copy constructor.

NetCDFVarStateField(NetCDFVarStateField &&other) = delete

Move constructor.

~NetCDFVarStateField() override = default

Destructor.

NetCDFVarStateField &operator=(const NetCDFVarStateField &other) = delete

Copy assignment operator.

NetCDFVarStateField &operator=(NetCDFVarStateField &&other) = delete

Move assignment operator.

virtual const muGrid::Field &get_field() const override

get a reference to the field represented by the NetCDF variable

size_t get_nb_fields() const

return the number of fields belonging to the state field (nb_memory + 1)

virtual DimensionStartValue get_dimension_start_value(const std::string &base_name, const Index_t &frame) const override

Override to handle history_index dimension.

virtual std::vector<IOSize_t> get_start_global(const Index_t &frame) const override

A vector of IOSize_t values specifying the index in the variable where the first of the data values will be written. This function gives the start for contiguous global fields written with ncmu_put_varm_all

virtual std::vector<IOSize_t> get_start_local(const Index_t &frame, muGrid::Field &local_pixels) const override

A vector of IOSize_t values specifying the index in the variable where the first of the data values will be written. This function gives the start for distributed local fields written with ncmu_put_varn_all

virtual std::vector<IODiff_t> get_nc_stride() const override
virtual std::vector<IODiff_t> get_nc_imap_global() const override
virtual std::vector<IODiff_t> get_nc_imap_local() const override
virtual void write(const int netcdf_id, const Index_t &tot_nb_frames, GlobalFieldCollection &GFC_local_pixels, const Index_t &frame_index) override

actual call of NetCDF functions to write a single NetCDFVar into the NetCDF file

virtual void read(const int netcdf_id, const Index_t &tot_nb_frames, GlobalFieldCollection &GFC_local_pixels, const Index_t &frame_index) override

actual call of NetCDF functions to read in the data of a single NetCDFVar from a NetCDF file

Protected Attributes

muGrid::StateField &state_field
size_t state_field_index{DEFAULT_STATE_FIELD_INDEX}

Private Static Attributes

static constexpr size_t DEFAULT_STATE_FIELD_INDEX{0}
template<class MappedField>
class OptionalMappedField
Param MappedField:

needs to be any of the template variants of muGrid::MappedField, typically one of its aliases, e.g., muGrid::MappedT2Field

Public Functions

OptionalMappedField() = delete

Default constructor.

inline OptionalMappedField(FieldCollection &collection, const std::string &unique_name, const std::string &sub_division_tag)

constructor

OptionalMappedField(const OptionalMappedField &other) = delete

Copy constructor.

OptionalMappedField(OptionalMappedField &&other) = delete

Move constructor.

virtual ~OptionalMappedField() = default

Destructor.

OptionalMappedField &operator=(const OptionalMappedField &other) = delete

Copy assignment operator.

OptionalMappedField &operator=(OptionalMappedField &&other) = delete

Move assignment operator.

inline bool has_value() const

returns whether the field has been created

inline MappedField &get()

returns a reference to the held mapped field. If the field has not yet been created, this call will cause it to be.

Protected Attributes

FieldCollection &collection
std::string unique_name
std::string sub_division_tag
std::optional<std::unique_ptr<MappedField>> mapped_field = {}
class PixelIndexIterable

Lightweight proxy class providing iteration over the pixel indices of a muGrid::FieldCollection

Public Types

using iterator = typename std::vector<Index_t>::const_iterator

stl

Public Functions

PixelIndexIterable() = delete

Default constructor.

PixelIndexIterable(const PixelIndexIterable &other) = delete

Copy constructor.

PixelIndexIterable(PixelIndexIterable &&other) = default

Move constructor.

virtual ~PixelIndexIterable() = default

Destructor.

PixelIndexIterable &operator=(const PixelIndexIterable &other) = delete

Copy assignment operator.

PixelIndexIterable &operator=(PixelIndexIterable &&other) = delete

Move assignment operator.

iterator begin() const

stl

iterator end() const

stl

size_t size() const

stl

Protected Functions

explicit PixelIndexIterable(const FieldCollection &collection)

Constructor is protected, because no one ever need to construct this except the field collection

Protected Attributes

friend FieldCollection

allow field collections to call the protected constructor of this iterable

const FieldCollection &collection

reference back to the proxied collection

class Pixels
#include <pixels.hh>

Iteration over square (or cubic) discretisation grids. Duplicates capabilities of muGrid::CcoordOps::Pixels without needing to be templated with the spatial dimension. Iteration is slower, though.

Iteration is provided through three explicit methods:

Public Functions

Pixels()
explicit Pixels(const DynGridIndex &nb_subdomain_grid_pts, const DynGridIndex &subdomain_locations = DynGridIndex{})

Constructor with default strides (column-major pixel storage order)

Pixels(const DynGridIndex &nb_subdomain_grid_pts, const DynGridIndex &subdomain_locations, const DynGridIndex &strides)

Constructor with custom strides (any, including partially transposed pixel storage order)

template<size_t Dim>
explicit Pixels(const GridIndex<Dim> &nb_subdomain_grid_pts, const GridIndex<Dim> &subdomain_locations = GridIndex<Dim>{})

Constructor with default strides from statically sized coords.

template<size_t Dim>
Pixels(const GridIndex<Dim> &nb_subdomain_grid_pts, const GridIndex<Dim> &subdomain_locations, const GridIndex<Dim> &strides)

Constructor with custom strides from statically sized coords.

Pixels(const Pixels &other) = default

Copy constructor.

Pixels(Pixels &&other) = default

Move constructor.

virtual ~Pixels() = default

Destructor.

Pixels &operator=(const Pixels &other) = default

Copy assignment operator.

Pixels &operator=(Pixels &&other) = default

Move assignment operator.

inline Index_t get_index(const DynGridIndex &ccoord) const

evaluate and return the linear index corresponding to dynamic ccoord

template<size_t Dim>
inline Index_t get_index(const GridIndex<Dim> &ccoord) const

evaluate and return the linear index corresponding to ccoord

inline DynGridIndex get_coord(const Index_t &index) const

return coordinates of the i-th pixel

inline DynGridIndex get_coord0(const Index_t &index) const

return coordinates of the i-th pixel, with zero as location

inline DynGridIndex get_neighbour(const DynGridIndex &ccoord, const DynGridIndex &offset) const
inline size_t size() const

stl conformance

inline size_t buffer_size() const

buffer size, including padding

inline Dim_t get_dim() const

return spatial dimension

inline const DynGridIndex &get_nb_subdomain_grid_pts() const

return the resolution of the discretisation grid in each spatial dim

inline const DynGridIndex &get_subdomain_locations() const

return the ccoordinates of the bottom, left, (front) pixel/voxel of this processors partition of the discretisation grid. For sequential calculations, this is alvays the origin

inline const DynGridIndex &get_strides() const

return the strides used for iterating over the pixels

inline Indices indices() const

Iterate over linear indices only. Most efficient iteration mode.

Example: for (auto index : pixels.indices()) { data[index] = …; }

inline Coordinates coordinates() const

Iterate over grid coordinates.

Example: for (auto && coord : pixels.coordinates()) { // coord is DynGridIndex }

inline Enumerator enumerate() const

Iterate over tuples of (index, coordinate). Useful in parallel problems where simple enumeration would be incorrect.

Example: for (auto && [index, coord] : pixels.enumerate()) { data[index] = f(coord); }

Protected Attributes

Dim_t dim

spatial dimension

DynGridIndex nb_subdomain_grid_pts

nb_grid_pts of this domain

DynGridIndex subdomain_locations

locations of this domain

DynGridIndex strides

strides of memory layout

DynGridIndex axes_order

order of axes

bool contiguous

is this a contiguous buffer?

struct PlanKeyHash
#include <cufft_backend.hh>

Hash function for PlanKey.

Public Functions

inline std::size_t operator()(const PlanKey &key) const
struct PlanKeyHash
#include <rocfft_backend.hh>

Hash function for PlanKey.

Public Functions

inline std::size_t operator()(const PlanKey &key) const
template<typename T0>
class pocketfft_c

Public Functions

inline POCKETFFT_NOINLINE pocketfft_c(size_t length)
template<typename T> inline POCKETFFT_NOINLINE void exec (cmplx< T > c[], T0 fct, bool fwd) const
inline size_t length() const

Private Members

std::unique_ptr<cfftp<T0>> packplan
std::unique_ptr<fftblue<T0>> blueplan
size_t len
template<typename T0>
class pocketfft_r

Public Functions

inline POCKETFFT_NOINLINE pocketfft_r(size_t length)
template<typename T> inline POCKETFFT_NOINLINE void exec (T c[], T0 fct, bool fwd) const
inline size_t length() const

Private Members

std::unique_ptr<rfftp<T0>> packplan
std::unique_ptr<fftblue<T0>> blueplan
size_t len
class PocketFFTBackend : public muGrid::FFT1DBackend

PocketFFT implementation of FFT1DBackend.

Uses the embedded pocketfft library (BSD-3 licensed) for CPU-based FFT. This backend is always available and serves as the fallback for host memory.

Public Functions

PocketFFTBackend() = default
~PocketFFTBackend() override = default
virtual void r2c(Index_t n, Index_t batch, const Real *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D real-to-complex FFT.

Parameters:
  • n – Transform size (number of real input points)

  • batch – Number of independent 1D transforms

  • input – Pointer to real input data

  • in_stride – Stride between consecutive input elements (in Reals)

  • in_dist – Distance between batches in input (in Reals)

  • output – Pointer to complex output data (n/2+1 complex per batch)

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual void c2r(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Real *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-real FFT.

Parameters:
  • n – Transform size (number of real output points)

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data (n/2+1 complex per batch)

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to real output data

  • out_stride – Stride between consecutive output elements (in Reals)

  • out_dist – Distance between batches in output (in Reals)

virtual void c2c_forward(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-complex forward FFT.

Parameters:
  • n – Transform size

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to complex output data

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual void c2c_backward(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-complex backward FFT.

Parameters:
  • n – Transform size

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to complex output data

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

inline virtual bool supports_device_memory() const override

Returns true if this backend supports device (GPU) memory

inline virtual const char *name() const override

Returns the name of this backend

template<typename T, size_t N>
class RefArray
#include <ref_array.hh>

work-around to allow making a statically sized array of references (which are forbidden by the C++ language

Public Functions

RefArray() = delete

Deleted default constructor.

template<typename ...Vals>
inline explicit RefArray(Vals&... vals)

bulk initialisation constructor

RefArray(const RefArray &other) = default

Copy constructor.

RefArray(RefArray &&other) = default

Move constructor.

virtual ~RefArray() = default

Destructor.

RefArray &operator=(const RefArray &other) = default

Copy assignment operator.

RefArray &operator=(RefArray &&other) = delete

Move assignment operator.

inline T &operator[](size_t index)

random access operator

inline constexpr T &operator[](size_t index) const

random constant access operator

Protected Attributes

std::array<T*, N> values = {}

storage

template<typename T>
class RefVector : protected std::vector<T*>
#include <ref_vector.hh>

work-around to allow using vectors of references (which are forbidden by the C++ stl

Public Functions

RefVector() = default

Default constructor.

RefVector(const RefVector &other) = default

Copy constructor.

RefVector(RefVector &&other) = default

Move constructor.

virtual ~RefVector() = default

Destructor.

RefVector &operator=(const RefVector &other) = default

Copy assignment operator.

RefVector &operator=(RefVector &&other) = default

Move assignment operator.

inline void push_back(T &value)

stl

inline T &at(size_t index)

stl

inline const T &at(size_t index) const

stl

inline T &operator[](size_t index)

random access operator

inline const T &operator[](size_t index) const

random const access operator

inline iterator begin()

stl

inline iterator end()

stl

Private Types

using Parent = std::vector<T*>
class rev_iter

Public Functions

inline rev_iter(const arr_info &arr_, const shape_t &axes)
inline void advance()
inline ptrdiff_t ofs() const
inline ptrdiff_t rev_ofs() const
inline size_t remaining() const

Private Members

shape_t pos
const arr_info &arr
std::vector<char> rev_axis
std::vector<char> rev_jump
size_t last_axis
size_t last_size
shape_t shp
ptrdiff_t p
ptrdiff_t rp
size_t rem
template<typename T0>
class rfftp

Public Functions

template<typename T>
inline void exec(T c[], T0 fct, bool r2hc) const
inline POCKETFFT_NOINLINE rfftp(size_t length_)

Private Functions

inline void add_factor(size_t factor)
template<typename T1, typename T2, typename T3>
inline void MULPM(T1 &a, T1 &b, T2 c, T2 d, T3 e, T3 f) const
template<typename T> inline void radf2 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa) const
template<typename T> inline void radf3 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa) const
template<typename T> inline void radf4 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa) const
template<typename T> inline void radf5 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa) const
template<typename T> inline void radfg (size_t ido, size_t ip, size_t l1, T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa, const T0 *POCKETFFT_RESTRICT csarr) const
template<typename T> inline void radb2 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa) const
template<typename T> inline void radb3 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa) const
template<typename T> inline void radb4 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa) const
template<typename T> inline void radb5 (size_t ido, size_t l1, const T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa) const
template<typename T> inline void radbg (size_t ido, size_t ip, size_t l1, T *POCKETFFT_RESTRICT cc, T *POCKETFFT_RESTRICT ch, const T0 *POCKETFFT_RESTRICT wa, const T0 *POCKETFFT_RESTRICT csarr) const
template<typename T>
inline void copy_and_norm(T *c, T *p1, T0 fct) const
inline void factorize()
inline size_t twsize() const
inline void comp_twiddle()

Private Members

size_t length
arr<T0> mem
std::vector<fctdata> fact
class rocFFTBackend : public muGrid::FFT1DBackend
#include <rocfft_backend.hh>

Native rocFFT implementation of FFT1DBackend for AMD GPUs.

This backend uses AMD’s rocFFT library directly (not via hipFFT) for GPU-accelerated FFT operations. Using the native rocFFT API provides better support for strided data layouts, which is essential for 3D MPI-parallel FFTs.

rocFFT plans are cached by (transform_type, n, batch, in_stride, in_dist, out_stride, out_dist) signature to avoid repeated plan creation overhead.

Key advantage over hipFFT: rocFFT’s native API supports arbitrary strides for all transform types including R2C and C2R, which cuFFT does not support.

Public Functions

rocFFTBackend()
~rocFFTBackend() override
virtual void r2c(Index_t n, Index_t batch, const Real *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D real-to-complex FFT.

Parameters:
  • n – Transform size (number of real input points)

  • batch – Number of independent 1D transforms

  • input – Pointer to real input data

  • in_stride – Stride between consecutive input elements (in Reals)

  • in_dist – Distance between batches in input (in Reals)

  • output – Pointer to complex output data (n/2+1 complex per batch)

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual void c2r(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Real *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-real FFT.

Parameters:
  • n – Transform size (number of real output points)

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data (n/2+1 complex per batch)

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to real output data

  • out_stride – Stride between consecutive output elements (in Reals)

  • out_dist – Distance between batches in output (in Reals)

virtual void c2c_forward(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-complex forward FFT.

Parameters:
  • n – Transform size

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to complex output data

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

virtual void c2c_backward(Index_t n, Index_t batch, const Complex *input, Index_t in_stride, Index_t in_dist, Complex *output, Index_t out_stride, Index_t out_dist) override

Batched 1D complex-to-complex backward FFT.

Parameters:
  • n – Transform size

  • batch – Number of independent 1D transforms

  • input – Pointer to complex input data

  • in_stride – Stride between consecutive input elements (in Complex)

  • in_dist – Distance between batches in input (in Complex)

  • output – Pointer to complex output data

  • out_stride – Stride between consecutive output elements (in Complex)

  • out_dist – Distance between batches in output (in Complex)

inline virtual bool supports_device_memory() const override

Returns true if this backend supports device (GPU) memory

inline virtual const char *name() const override

Returns the name of this backend

Protected Types

enum TransformType

Transform type identifiers for plan caching.

Values:

enumerator R2C
enumerator C2R
enumerator C2C
enum Direction

Direction identifiers for C2C transforms.

Values:

enumerator FORWARD
enumerator BACKWARD
using PlanKey = std::tuple<int, int, Index_t, Index_t, Index_t, Index_t, Index_t, Index_t>

Key type for plan cache: (transform_type, direction, n, batch, in_stride, in_dist, out_stride, out_dist)

Protected Functions

CachedPlan &get_plan(TransformType type, Direction direction, Index_t n, Index_t batch, Index_t in_stride, Index_t in_dist, Index_t out_stride, Index_t out_dist)

Get or create a rocFFT plan for the given parameters.

Parameters:
  • type – Transform type (R2C, C2R, or C2C)

  • direction – Transform direction (FORWARD or BACKWARD, only for C2C)

  • n – Transform size

  • batch – Number of batched transforms

  • in_stride – Input stride between elements

  • in_dist – Input distance between batches

  • out_stride – Output stride between elements

  • out_dist – Output distance between batches

Returns:

CachedPlan for the requested transform

Protected Attributes

std::unordered_map<PlanKey, CachedPlan, PlanKeyHash> plan_cache

Plan cache.

Protected Static Functions

static void check_rocfft_result(rocfft_status result, const char *operation)

Check rocFFT result and throw on error.

Protected Static Attributes

static bool rocfft_initialized = false

Flag to track if rocfft_setup has been called.

template<typename T>
class RuntimeWorkBuffer
#include <fft_work_buffer.hh>

Work buffer that allocates on host or device based on runtime flag.

This class provides a simple RAII wrapper for temporary buffers used in FFT operations. The memory location (host or device) is determined at construction time based on a runtime flag.

Template Parameters:

T – Element type (typically Complex)

Public Functions

inline RuntimeWorkBuffer(std::size_t size, bool on_device)

Construct a work buffer.

Parameters:
  • size – Number of elements to allocate

  • on_device – If true, allocate on GPU device; otherwise on host

inline ~RuntimeWorkBuffer()
RuntimeWorkBuffer(const RuntimeWorkBuffer&) = delete
RuntimeWorkBuffer &operator=(const RuntimeWorkBuffer&) = delete
inline RuntimeWorkBuffer(RuntimeWorkBuffer &&other) noexcept
inline RuntimeWorkBuffer &operator=(RuntimeWorkBuffer &&other) noexcept
inline T *data()

Get raw pointer to data.

inline const T *data() const
inline std::size_t size() const

Get number of elements.

inline bool is_on_device() const

Check if buffer is on device.

inline void copy_from(const T *src, std::size_t count, bool src_on_device)

Copy data from another buffer.

Parameters:
  • src – Source pointer

  • count – Number of elements to copy

  • src_on_device – True if source is on device

inline void copy_to(T *dst, std::size_t count, bool dst_on_device) const

Copy data to another buffer.

Parameters:
  • dst – Destination pointer

  • count – Number of elements to copy

  • dst_on_device – True if destination is on device

Private Members

std::size_t size_
bool on_device_
T *data_
template<typename T>
struct ScalarMap

Internal struct for handling the scalar iterates of muGrid::FieldMap

Public Types

using PlainType = T

Scalar maps don’t have an eigen type representing the iterate, just the raw stored type itsef

template<Mapping MutIter>
using value_type = std::conditional_t<MutIter == Mapping::Const, const T, T>

return type for iterates

template<Mapping MutIter>
using ref_type = value_type<MutIter>&

reference type for iterates

template<Mapping MutIter>
using Return_t = value_type<MutIter>&

for direct access through operator[]

template<Mapping MutIter>
using storage_type = std::conditional_t<MutIter == Mapping::Const, const T*, T*>

need to encapsulate

Public Static Functions

static inline constexpr bool IsValidStaticMapType()

check at compile time whether this map is suitable for statically sized iterates

static inline constexpr bool IsScalarMapType()

check at compiler time whether this map is scalar

template<Mapping MutIter>
static inline constexpr value_type<MutIter> &provide_ref(storage_type<MutIter> storage)

return the return_type version of the iterate from storage_type

template<Mapping MutIter>
static inline constexpr const value_type<MutIter> &provide_const_ref(const storage_type<MutIter> storage)

return the const return_type version of the iterate from storage_type

template<Mapping MutIter>
static inline constexpr storage_type<MutIter> provide_ptr(storage_type<MutIter> storage)

return a pointer to the iterate from storage_type

template<Mapping MutIter>
static inline constexpr Return_t<MutIter> from_data_ptr(std::conditional_t<MutIter == Mapping::Const, const T*, T*> data)

return a return_type version of the iterate from its pointer

template<Mapping MutIter>
static inline constexpr storage_type<MutIter> to_storage(ref_type<MutIter> ref)

return a storage_type version of the iterate from its value

static inline constexpr Index_t stride()

return the nb of components of the iterate (known at compile time)

static inline std::string shape()

return the iterate’s shape as text, mostly for error messages

static inline constexpr Index_t NbRow()
class simple_iter

Public Functions

inline simple_iter(const arr_info &arr_)
inline void advance()
inline ptrdiff_t ofs() const
inline size_t remaining() const

Private Members

shape_t pos
const arr_info &arr
ptrdiff_t p
size_t rem
template<typename T>
class sincos_2pibyn

Public Functions

inline POCKETFFT_NOINLINE sincos_2pibyn(size_t n)
inline cmplx<T> operator[](size_t idx) const

Private Types

using Thigh = typename std::conditional<(sizeof(T) > sizeof(double)), T, double>::type

Private Members

size_t N
size_t mask
size_t shift
arr<cmplx<Thigh>> v1
arr<cmplx<Thigh>> v2

Private Static Functions

static inline cmplx<Thigh> calc(size_t x, size_t n, Thigh ang)
struct SparseOperatorCacheKey
#include <generic.hh>

Cache key for sparse operator memoization.

Public Functions

inline bool operator==(const SparseOperatorCacheKey &other) const

Public Members

DynGridIndex nb_grid_pts
Index_t nb_nodal_components
template<typename MemorySpace>
struct SparseOperatorSoA

Sparse operator in Structure-of-Arrays format

Public Functions

SparseOperatorSoA() = default

Default constructor - creates empty operator.

inline explicit SparseOperatorSoA(Index_t n)

Constructor that allocates arrays of given size.

inline bool empty() const

Check if operator is empty.

Public Members

Index_t size = {0}
Array<Index_t, MemorySpace> quad_indices
Array<Index_t, MemorySpace> nodal_indices
Array<Real, MemorySpace> values
class StateField
#include <state_field.hh>

Base class for state fields, useful for storing polymorphic references

Subclassed by muGrid::TypedStateField< Scalar >, muGrid::TypedStateField< T >

Public Functions

StateField() = delete

Default constructor.

StateField(const StateField &other) = delete

Copy constructor.

StateField(StateField &&other) = delete

Move constructor.

virtual ~StateField() = default

Destructor.

StateField &operator=(const StateField &other) = delete

Copy assignment operator.

StateField &operator=(StateField &&other) = delete

Move assignment operator.

const Index_t &get_nb_memory() const

return number of old states that are stored

const Index_t &get_nb_components() const

return the number of components stored per sub-point point

const std::string &get_sub_division_tag() const

returns a const ref to the field’s pixel sub-division type

const Unit &get_physical_unit() const

returns the physical unit of the values stored in the field

virtual TypeDescriptor get_type_descriptor() const = 0

return the unified type descriptor for this state field’s element type

virtual std::size_t get_element_size_in_bytes() const = 0

return the size of the elementary field entry in bytes

void assert_type_descriptor(TypeDescriptor type_desc) const

assert that the stored type corresponds to the given type descriptor

void cycle()

cycle the fields (current becomes old, old becomes older, oldest becomes current)

Field &current()

return a reference to the field holding the current values

const Field &current() const

return a const reference to the field holding the current values

const Field &old(const size_t &nb_steps_ago = 1) const

return a reference to the field holding the values which were current nb_steps_ago ago

inline const std::vector<size_t> &get_indices() const

get the current ordering of the fields (inlineable because called in hot loop)

FieldCollection &get_collection()

get the field collection which holds all fields of the state field

const std::string &get_unique_prefix() const

get the unique prefix used for the naming of the associated fields and can be used like a name for the StateField

const RefVector<Field> &get_fields() const

return a const RefVector<Field> of fields belonging to the StateField

RefVector<Field> &set_fields()

return a mutable RefVector<Field> of fields belonging to the StateField

Protected Functions

StateField(const std::string &unique_prefix, FieldCollection &collection, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division, const Unit &unit)

Protected constructor

Protected Attributes

std::string prefix

the unique prefix is used as the first part of the unique name of the subfields belonging to this state field

FieldCollection &collection

reference to the collection this statefield belongs to

const Index_t nb_memory

number of old states to store, defaults to 1

const Index_t nb_components

number of dof_per_sub_pt stored per sub-point (e.g., 3 for a three-dimensional vector, or 9 for a three-dimensional second-rank tensor)

std::string sub_division_tag

Pixel subdivision kind (determines how many datapoints to store per pixel)

Unit unit

Physical unit of the values stored in this field.

Index_t nb_sub_pts

number of pixel subdivisions. Will depend on sub_division

std::vector<size_t> indices = {}

the current (historically accurate) ordering of the fields

RefVector<Field> fields = {}

storage of references to the diverse fields

template<typename T, Mapping Mutability>
class StateFieldMap
#include <state_field_map.hh>

forward-declaration for friending

Dynamically sized map for iterating over muGrid::StateFields

Subclassed by muGrid::StaticStateFieldMap< T, Mutability, MapType, NbMemory, IterationType >

Public Types

using FieldMap_t = FieldMap<T, Mutability>

type for the current-values map (may be mutable, if the underlying field was)

using CFieldMap_t = FieldMap<T, Mapping::Const>

type for the old-values map, non-mutable

using iterator = Iterator<(Mutability == Mapping::Mut) ? Mapping::Mut : Mapping::Const>

stl

using const_iterator = Iterator<Mapping::Const>

stl

Public Functions

StateFieldMap() = delete

Default constructor.

StateFieldMap(TypedStateField<T> &state_field, IterUnit iter_type = IterUnit::SubPt)

constructor from a state field. The default case is a map iterating over quadrature points with a matrix of shape (nb_components × 1) per field entry

StateFieldMap(TypedStateField<T> &state_field, Index_t nb_rows, IterUnit iter_type = IterUnit::SubPt)

Constructor from a state field with explicitly chosen shape of iterate. (the number of columns is inferred).

StateFieldMap(const StateFieldMap &other) = delete
StateFieldMap(StateFieldMap &&other) = delete

Move constructor.

virtual ~StateFieldMap() = default

Destructor.

StateFieldMap &operator=(const StateFieldMap &other) = delete

Copy assignment operator.

StateFieldMap &operator=(StateFieldMap &&other) = delete

Move assignment operator.

iterator begin()

stl

iterator end()

stl

const TypedStateField<T> &get_state_field() const

return a const reference to the mapped state field

const Index_t &get_nb_rows() const

return the number of rows the iterates have

size_t size() const

returns the number of iterates produced by this map (corresponds to the number of field entries if Iteration::Quadpt, or the number of pixels/voxels if Iteration::Pixel);

inline StateWrapper<Mutability> operator[](size_t index)

random access operator

inline StateWrapper<Mapping::Const> operator[](size_t index) const

random constaccess operator

FieldMap_t &get_current()

returns a reference to the map over the current data

const FieldMap_t &get_current() const

returns a const reference to the map over the current data

const CFieldMap_t &get_old(size_t nb_steps_ago) const

returns a const reference to the map over the data which was current nb_steps_ago ago

Protected Functions

RefVector<Field> &get_fields()

protected access to the constituent fields

std::vector<FieldMap_t> make_maps(RefVector<Field> &fields)

helper function creating the list of maps to store for current values

std::vector<CFieldMap_t> make_cmaps(RefVector<Field> &fields)

helper function creating the list of maps to store for old values

Protected Attributes

TypedStateField<T> &state_field

mapped state field. Needed for query at initialisations

const IterUnit iteration

type of map iteration

const Index_t nb_rows

number of rows of the iterate

std::vector<FieldMap_t> maps

maps over nb_memory + 1 possibly mutable maps. current points to one of these

std::vector<CFieldMap_t> cmaps

maps over nb_memory + 1 const maps. old(nb_steps_ago) points to one of these

template<Mapping MutWrapper>
class StateWrapper
#include <state_field_map.hh>

The iterate needs to give access to current or previous values. This is handled by the muGrid::StateFieldMap::StateWrapper, a light-weight wrapper around the iterate’s data.

Public Types

using StateFieldMap_t = std::conditional_t<MutWrapper == Mapping::Const, const StateFieldMap, StateFieldMap>

convenience alias

using CurrentVal_t = typename FieldMap_t::template Return_t<MutWrapper>

return value when getting current value from iterate

using OldVal_t = typename FieldMap_t::template Return_t<Mapping::Const>

return value when getting old value from iterate

Public Functions

inline StateWrapper(StateFieldMap_t &state_field_map, size_t index)

constructor (should never have to be called by user)

~StateWrapper() = default
inline CurrentVal_t &current()

return the current value at this iterate

inline const OldVal_t &old(size_t nb_steps_ago) const

return the value at this iterate which was current nb_steps_ago ago

Protected Attributes

CurrentVal_t current_val

current value at this iterate

std::vector<OldVal_t> old_vals = {}

all old values at this iterate

template<typename T, Mapping Mutability, class MapType, IterUnit IterationType = IterUnit::SubPt>
class StaticFieldMap : public muGrid::FieldMap<T, Mutability>

Statically sized field map. Static field maps reproduce the capabilities of the (dynamically sized) muGrid::FieldMap, but iterate much more efficiently.

Public Types

using Scalar = T

stored scalar type

using Parent = FieldMap<T, Mutability>

base class

using Field_t = typename Parent::Field_t

convenience alias

template<Mapping MutType>
using Return_t = typename MapType::template Return_t<MutType>

return type when dereferencing iterators over this map

using reference = Return_t<Mutability>

stl

using PlainType = typename MapType::PlainType

Eigen type representing iterates of this map.

using Enumeration_t = akantu::containers::ZipContainer<std::conditional_t<(IterationType == IterUnit::SubPt), FieldCollection::IndexIterable, FieldCollection::PixelIndexIterable>, StaticFieldMap&>

iterable proxy type to iterate over the quad point/pixel indices and stored values simultaneously

using iterator = Iterator<(Mutability == Mapping::Mut) ? Mapping::Mut : Mapping::Const>

stl

using const_iterator = Iterator<Mapping::Const>

stl

Public Functions

StaticFieldMap() = delete

Default constructor.

inline explicit StaticFieldMap(Field &field)

Constructor from a non-typed field ref (has more runtime cost than the next constructor

inline explicit StaticFieldMap(Field_t &field)

Constructor from typed field ref.

StaticFieldMap(const StaticFieldMap &other) = delete

Copy constructor.

StaticFieldMap(StaticFieldMap &&other) = default

Move constructor.

virtual ~StaticFieldMap() = default

Destructor.

StaticFieldMap &operator=(const StaticFieldMap &other) = delete

Copy assignment operator.

StaticFieldMap &operator=(StaticFieldMap &&other) = delete

Move assignment operator.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, StaticFieldMap> &operator=(const typename Parent::EigenRef &val)

Assign a matrix-like value with dynamic size to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, StaticFieldMap> &operator+=(const typename Parent::EigenRef &val)

Addition-assign a matrix-like value with dynamic size to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField, StaticFieldMap> &operator-=(const typename Parent::EigenRef &val)

Subtraction-assign a matrix-like value with dynamic size to every entry

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField && !MapType::IsScalarMapType(), StaticFieldMap<T, Mutability, MapType, IterationType>> &operator=(const reference &val)

Assign a matrix-like value with static size to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField && !MapType::IsScalarMapType(), StaticFieldMap<T, Mutability, MapType, IterationType>> &operator+=(const reference &val)

Addition-assign a matrix-like value with static size to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField && !MapType::IsScalarMapType(), StaticFieldMap<T, Mutability, MapType, IterationType>> &operator-=(const reference &val)

Subtraction-assign a matrix-like value with static size to every entry

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField && MapType::IsScalarMapType(), StaticFieldMap<T, Mutability, MapType, IterationType>> &operator=(const Scalar &val)

Assign a scalar value to every entry.

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField && MapType::IsScalarMapType(), StaticFieldMap<T, Mutability, MapType, IterationType>> &operator+=(const Scalar &val)

add a scalar value to every entry

template<bool IsMutableField = Mutability == Mapping::Mut>
inline std::enable_if_t<IsMutableField && MapType::IsScalarMapType(), StaticFieldMap<T, Mutability, MapType, IterationType>> &operator-=(const Scalar &val)

Subtract a scalar value from every entry.

inline Return_t<Mutability> operator[](size_t index)

random access operator

inline Return_t<Mapping::Const> operator[](size_t index) const

random const access operator

inline PlainType mean() const

evaluate the average of the field

inline iterator begin()

stl

inline iterator end()

stl

inline const_iterator begin() const

stl

inline const_iterator end() const

stl

template<bool IsPixelIterable = (IterationType == IterUnit::Pixel)>
inline std::enable_if_t<IsPixelIterable, Enumeration_t> enumerate_indices()

iterate over pixel/quad point indices and stored values simultaneously

template<IterUnit Iter = IterUnit::SubPt, class Dummy = std::enable_if_t<IterationType == Iter, bool>>
inline Enumeration_t enumerate_indices()

iterate over pixel/quad point indices and stored values simultaneously

Public Static Functions

static inline constexpr IterUnit GetIterationType()

determine at compile time whether pixels or quadrature points are iterater over

static inline constexpr size_t Stride()

determine the number of components in the iterate at compile time

static inline constexpr bool IsStatic()

determine whether this map has statically sized iterates at compile time

template<typename T, Mapping Mutability, class MapType, size_t NbMemory, IterUnit IterationType = IterUnit::SubPt>
class StaticStateFieldMap : public muGrid::StateFieldMap<T, Mutability>

statically sized version of muGrid::TypedStateField. Duplicates its capabilities, with much more efficient statically sized iterates.

Public Types

using Scalar = T

stored scalar type

using Parent = StateFieldMap<T, Mutability>

base class

using StaticFieldMap_t = StaticFieldMap<T, Mutability, MapType, IterationType>

convenience alias for current map

using CStaticFieldMap_t = StaticFieldMap<T, Mapping::Const, MapType, IterationType>

convenience alias for old map

using MapArray_t = std::array<StaticFieldMap_t, NbMemory + 1>

storage type for current maps

using CMapArray_t = std::array<CStaticFieldMap_t, NbMemory + 1>

storage type for old maps

using iterator = Iterator<(Mutability == Mapping::Mut) ? Mapping::Mut : Mapping::Const>

stl

using const_iterator = Iterator<Mapping::Const>

stl

Public Functions

StaticStateFieldMap() = delete

Deleted default constructor.

inline explicit StaticStateFieldMap(TypedStateField<T> &state_field)

constructor from a state field. The default case is a map iterating over quadrature points with a matrix of shape (nb_components × 1) per field entry

StaticStateFieldMap(const StaticStateFieldMap &other) = delete

Deleted copy constructor.

StaticStateFieldMap(StaticStateFieldMap &&other) = default

Move constructor.

virtual ~StaticStateFieldMap() = default

Destructor.

StaticStateFieldMap &operator=(const StaticStateFieldMap &other) = delete

Copy assignment operator.

StaticStateFieldMap &operator=(StaticStateFieldMap &&other) = default

Move assignment operator.

inline iterator begin()

stl

inline iterator end()

stl

inline const CStaticFieldMap_t &get_old_static(size_t nb_steps_ago) const

return a const ref to an old value map

inline StaticFieldMap_t &get_current_static()

return a ref to an the current map

inline StaticFieldMap_t &get_current()
inline StaticFieldMap_t &get_current_static() const

return a const ref to an the current map

inline StaticFieldMap_t &get_current() const
inline StaticStateWrapper<Mutability> operator[](size_t index)

random access operator

inline StaticStateWrapper<Mapping::Const> operator[](size_t index) const

random const access operator

Public Static Functions

static inline constexpr size_t GetNbMemory()

determine at compile time the number of old values stored

static inline constexpr Mapping FieldMutability()

determine the map’s mutability at compile time

static inline constexpr IterUnit GetIterationType()

determine the map’s iteration type (pixels vs quad pts) at compile time

Protected Types

template<Mapping MutIter>
using HelperRet_t = std::conditional_t<MutIter == Mapping::Const, CMapArray_t, MapArray_t>

internal convenience alias

Protected Functions

template<Mapping MutIter, size_t... I>
inline auto map_helper(std::index_sequence<I...>) -> HelperRet_t<MutIter>

helper for building the maps

inline MapArray_t make_maps()

build the current value maps

inline CMapArray_t make_cmaps()

build the old value maps

Protected Attributes

MapArray_t static_maps

container for current maps

CMapArray_t static_cmaps

container for old maps

template<Mapping MutWrapper>
class StaticStateWrapper

The iterate needs to give access to current or previous values. This is handled by the muGrid::StaticStateFieldMap::StateWrapper, a light-weight wrapper around the iterate’s data.

Template Parameters:

MutWrapper – mutability of the mapped field. It should never be necessary to set this manually, rather the iterators dereference operator*() should return the correct type.

Public Types

using StaticStateFieldMap_t = std::conditional_t<MutWrapper == Mapping::Const, const StaticStateFieldMap, StaticStateFieldMap>

const-correct map

using CurrentVal_t = typename MapType::template ref_type<MutWrapper>

return type handle for current value

using CurrentStorage_t = typename MapType::template storage_type<MutWrapper>

storage type for current value handle

using OldVal_t = typename MapType::template ref_type<Mapping::Const>

return type handle for old value

using OldStorage_t = typename MapType::template storage_type<Mapping::Const>

storage type for old value handle

Public Functions

inline StaticStateWrapper(StaticStateFieldMap_t &state_field_map, size_t index)

constructor with map and index, not for user to call

~StaticStateWrapper() = default
inline CurrentVal_t &current()

return the current value of the iterate

inline const OldVal_t &old(size_t nb_steps_ago) const

return the value of the iterate which was current nb_steps_ago steps ago. Possibly has excess runtime cost compared to the next function, and has no bounds checking, unlike the next function

template<size_t NbStepsAgo = 1>
inline const OldVal_t &old() const

return the value of the iterate which was current NbStepsAgo steps ago

Protected Functions

inline std::array<OldStorage_t, NbMemory> make_old_vals_static(StaticStateFieldMap_t &state_field_map, size_t index)

helper function to build the list of old values

template<size_t... NbStepsAgo>
inline std::array<OldStorage_t, NbMemory> old_vals_helper_static(StaticStateFieldMap_t &state_field_map, size_t index, std::index_sequence<NbStepsAgo...>)

helper function to build the list of old values

Protected Attributes

CurrentStorage_t current_val

handle to current value

std::array<OldStorage_t, NbMemory> old_vals = {}

storage for handles to old values

template<typename T0>
class T_dcst23

Public Functions

inline POCKETFFT_NOINLINE T_dcst23(size_t length)
template<typename T> inline POCKETFFT_NOINLINE void exec (T c[], T0 fct, bool ortho, int type, bool cosine) const
inline size_t length() const

Private Members

pocketfft_r<T0> fftplan
std::vector<T0> twiddle
template<typename T0>
class T_dcst4

Public Functions

inline POCKETFFT_NOINLINE T_dcst4(size_t length)
template<typename T> inline POCKETFFT_NOINLINE void exec (T c[], T0 fct, bool, int, bool cosine) const
inline size_t length() const

Private Members

size_t N
std::unique_ptr<pocketfft_c<T0>> fft
std::unique_ptr<pocketfft_r<T0>> rfft
arr<cmplx<T0>> C2
template<typename T0>
class T_dct1

Public Functions

inline POCKETFFT_NOINLINE T_dct1(size_t length)
template<typename T> inline POCKETFFT_NOINLINE void exec (T c[], T0 fct, bool ortho, int, bool) const
inline size_t length() const

Private Members

pocketfft_r<T0> fftplan
template<typename T0>
class T_dst1

Public Functions

inline POCKETFFT_NOINLINE T_dst1(size_t length)
template<typename T> inline POCKETFFT_NOINLINE void exec (T c[], T0 fct, bool, int, bool) const
inline size_t length() const

Private Members

pocketfft_r<T0> fftplan
template<class Derived>
struct tensor_4_dim
#include <eigen_checks.hh>

computes the dimension from a fourth order tensor represented by a square matrix

Public Types

using T = std::remove_reference_t<Derived>

raw type for testing

Public Static Attributes

static constexpr Index_t value = {ct_sqrt(T::RowsAtCompileTime)}

evaluated dimension

template<class Derived>
struct tensor_dim
#include <eigen_checks.hh>

computes the dimension from a second order tensor represented square matrix or array

Public Types

using T = std::remove_cv_t<std::remove_reference_t<Derived>>

raw type for testing

Public Static Attributes

static constexpr Index_t value = {T::RowsAtCompileTime}

evaluated dimension

template<class Derived, Dim_t Dim>
struct tensor_rank
#include <eigen_checks.hh>

computes the rank of a tensor given the spatial dimension

Public Types

using T = std::remove_reference_t<Derived>

Public Static Attributes

static constexpr Dim_t value = {internal::get_rank<Dim, T::RowsAtCompileTime, T::ColsAtCompileTime>()}
template<Dim_t Dim, Dim_t SmallRank>
struct TensorMultiplicationProvider
template<Dim_t Dim>
struct TensorMultiplicationProvider<Dim, firstOrder>

Public Static Functions

template<typename T2, typename T1>
static inline constexpr auto multiply(const Eigen::MatrixBase<T2> &A, const Eigen::MatrixBase<T1> &B) -> decltype(A * B)
template<Dim_t Dim>
struct TensorMultiplicationProvider<Dim, secondOrder>

Public Static Functions

template<typename T4, typename T2>
static inline constexpr auto multiply(const Eigen::MatrixBase<T4> &A, const Eigen::MatrixBase<T2> &B) -> Eigen::Matrix<typename T2::Scalar, T2::RowsAtCompileTime, T2::RowsAtCompileTime>
template<>
struct TensorMultiplicationProvider<oneD, firstOrder>

Public Static Functions

template<typename T2, typename T1>
static inline constexpr auto multiply(const Eigen::MatrixBase<T2> &A, const Eigen::MatrixBase<T1> &B) -> decltype(A * B)
template<>
struct TensorMultiplicationProvider<oneD, secondOrder>

Public Static Functions

template<typename T2, typename T1>
static inline constexpr auto multiply(const Eigen::MatrixBase<T2> &A, const Eigen::MatrixBase<T1> &B) -> decltype(A * B)
class thread_pool

Public Functions

inline explicit thread_pool(size_t nthreads)
inline thread_pool()
inline ~thread_pool()
inline void submit(std::function<void()> work)
inline void shutdown()
inline void restart()

Private Types

using lock_t = std::lock_guard<std::mutex>

Private Functions

inline void create_threads()
inline void shutdown_locked()

Private Members

concurrent_queue<std::function<void()>> overflow_work_
std::mutex mut_
std::vector<worker, aligned_allocator<worker>> workers_
std::atomic<bool> shutdown_
std::atomic<size_t> unscheduled_tasks_

Private Static Attributes

static constexpr size_t cache_line_size = 64
class Traceback
#include <exception.hh>

A class that captures and manages a stack traceback.

This class is used to capture the stack traceback at the point of exception creation. It provides methods to get the stack traceback and to print it.

Public Functions

explicit Traceback(int discard_entries)

Construct a new Traceback object.

This constructor captures the current stack traceback, discarding the topmost entries as specified.

Parameters:

discard_entries – The number of topmost entries to discard from the captured stack traceback.

virtual ~Traceback()

Destroy the Traceback object.

This is a virtual destructor, allowing this class to be used as a base class.

inline const std::vector<TracebackEntry> &get_stack() const

Get the stack traceback.

This function returns a reference to the vector of traceback entries.

Returns:

const std::vector<TracebackEntry>& The stack traceback.

Protected Attributes

std::vector<TracebackEntry> stack

The captured stack traceback.

This vector contains the entries of the captured stack traceback.

Friends

inline friend std::ostream &operator<<(std::ostream &os, const Traceback &self)

Output the stack traceback.

This function outputs the stack traceback to the provided output stream. The traceback is output in reverse order (most recent entry last), and stops at the first entry that could not be resolved to a function name.

Parameters:
  • os – The output stream to output the traceback to.

  • self – The Traceback object to output the traceback of.

Returns:

std::ostream& The output stream.

class TracebackEntry
#include <exception.hh>

A class that represents an entry from the stack traceback.

This class is used to manage individual entries in a stack traceback. It provides methods to get the symbol, name, and file associated with the entry, and to check if the entry has been successfully resolved to a function/method name.

Public Functions

TracebackEntry(void *address, const std::string &symbol)

Construct a new TracebackEntry object with a given address and symbol.

Parameters:
  • address – The address of the stack frame.

  • symbol – The symbol associated with the stack frame.

TracebackEntry(void *address, const char *symbol)

Construct a new TracebackEntry object with a given address and symbol.

Parameters:
  • address – The address of the stack frame.

  • symbol – The symbol associated with the stack frame.

TracebackEntry(const TracebackEntry &other)

Copy constructor for the TracebackEntry class.

Parameters:

other – The TracebackEntry object to copy from.

~TracebackEntry()

Destroy the TracebackEntry object.

TracebackEntry &operator=(const TracebackEntry &other)

Assignment operator for the TracebackEntry class.

Parameters:

other – The TracebackEntry object to assign from.

Returns:

TracebackEntry& A reference to the assigned object.

inline const std::string &get_symbol() const

Get the symbol associated with the stack frame.

Returns:

const std::string& The symbol associated with the stack frame.

inline const std::string &get_name() const

Get the name associated with the stack frame.

Returns:

const std::string& The name associated with the stack frame.

inline const std::string &get_file() const

Get the file associated with the stack frame.

Returns:

const std::string& The file associated with the stack frame.

inline bool is_resolved() const

Check if the stack frame has been successfully resolved to a function/method name.

Returns:

bool True if the stack frame has been successfully resolved, false otherwise.

Protected Functions

void discover_name_and_file()

Discover the name and file associated with the stack frame.

This function attempts to resolve the stack frame to a function/method name and file. It demangles the function name if necessary.

Protected Attributes

void *address

The address of the stack frame.

std::string symbol

The symbol associated with the stack frame.

std::string name

The name associated with the stack frame.

std::string file

The file associated with the stack frame.

bool resolved

True if the stack frame has been successfully resolved to a function/method name, false otherwise.

Friends

inline friend std::ostream &operator<<(std::ostream &os, const TracebackEntry &self)

Output the TracebackEntry object.

This function outputs the TracebackEntry object to the provided output stream. If the stack frame has been successfully resolved, it outputs the file and name associated with the stack frame. Otherwise, it outputs a message indicating that the stack frame could not be resolved to a function/method name.

The output is formatted like Python stack tracebacks, because its primary purpose is to be displayed in conjunction with a Python exception.

Parameters:
Returns:

std::ostream& The output stream.

class Transpose
#include <transpose.hh>

Handles MPI transpose operations using derived datatypes.

This class uses MPI derived datatypes instead of explicit pack/unpack buffers. The MPI library handles the non-contiguous memory access patterns, which can be more efficient and works with GPU-aware MPI.

For pencil decomposition, data needs to be redistributed between ranks to switch which dimension is “local” (not distributed). The transpose operation is characterized by:

  • Input: Data distributed along axis_in, full along axis_out

  • Output: Data distributed along axis_out, full along axis_in

Public Functions

Transpose(const Communicator &comm, const DynGridIndex &local_in, const DynGridIndex &local_out, Index_t global_in, Index_t global_out, Index_t axis_in, Index_t axis_out, Index_t nb_components = 1, StorageOrder layout = StorageOrder::ArrayOfStructures)

Configure a transpose operation between two pencil orientations.

Parameters:
  • comm – MPI communicator (typically a row or column subcommunicator of the process grid)

  • local_in – Local input shape (before transpose)

  • local_out – Local output shape (after transpose)

  • global_in – Global size of the dimension that is distributed in input but becomes local in output

  • global_out – Global size of the dimension that is local in input but becomes distributed in output

  • axis_in – Axis that is distributed in input (becomes local)

  • axis_out – Axis that is local in input (becomes distributed)

  • nb_components – Number of field components (default: 1)

  • layout – Memory layout for multi-component fields

Transpose() = delete
Transpose(const Transpose &other) = delete
Transpose(Transpose &&other) noexcept
~Transpose()
Transpose &operator=(const Transpose &other) = delete
Transpose &operator=(Transpose &&other) noexcept
void forward(const Complex *input, Complex *output) const

Perform forward transpose (gather axis_in, scatter axis_out).

Parameters:
  • input – Pointer to input complex data

  • output – Pointer to output complex data

void backward(const Complex *input, Complex *output) const

Perform backward transpose (reverse of forward).

Parameters:
  • input – Pointer to input complex data

  • output – Pointer to output complex data

inline const DynGridIndex &get_local_in() const

Get the local input shape.

inline const DynGridIndex &get_local_out() const

Get the local output shape.

inline Index_t get_axis_in() const

Get the input axis that is distributed (will become local after forward).

inline Index_t get_axis_out() const

Get the output axis that is local in input (will become distributed after forward).

inline Index_t get_nb_components() const

Get the number of components.

Protected Attributes

Communicator comm

MPI communicator for this transpose.

DynGridIndex local_in

Local shape before transpose.

DynGridIndex local_out

Local shape after transpose.

Index_t global_in

Global size of dimension distributed in input.

Index_t global_out

Global size of dimension local in input (becomes distributed)

Index_t axis_in

Axis that is distributed in input (will become local)

Index_t axis_out

Axis that is local in input (will become distributed)

Index_t nb_components

Number of field components.

StorageOrder layout

Memory layout for multi-component fields.

std::vector<Index_t> in_counts

Distribution of global_in across ranks.

std::vector<Index_t> in_displs
std::vector<Index_t> out_counts

Distribution of global_out across ranks.

std::vector<Index_t> out_displs
bool types_initialized = {false}

Flag indicating if datatypes have been initialized.

bool is_allgather = {false}

Flag indicating if this is an allgather (no scatter) operation.

bool is_scatter_only = {false}

Flag indicating if this is a scatter-only (no gather) operation.

Protected Static Functions

static void compute_distribution(Index_t global_size, int comm_size, std::vector<Index_t> &counts, std::vector<Index_t> &displs)

Compute how a dimension is distributed across ranks.

Parameters:
  • global_size – Global size of the dimension

  • comm_size – Number of ranks

  • counts – Output: number of elements per rank

  • displs – Output: starting offset for each rank

struct TransposeConfig
#include <fft_engine_base.hh>

Configuration for creating transposes with different nb_components.

Public Members

DynGridIndex local_in
DynGridIndex local_out
Index_t global_in
Index_t global_out
Index_t axis_in
Index_t axis_out
bool use_row_comm

true = row_comm, false = col_comm

template<typename T, typename FirstVal, typename ...RestVals>
struct TypeChecker
#include <ref_array.hh>

Struct user for checking that every member of a parameter pack has type T

Public Static Attributes

static constexpr bool value  {std::is_same<T, std::remove_reference_t<FirstVal>>::value andTypeChecker<T, RestVals...>::value}

whether the check passed

template<typename T, typename OnlyVal>
struct TypeChecker<T, OnlyVal>
#include <ref_array.hh>

Specialisation for recursion tail

Public Static Attributes

static constexpr bool value{std::is_same<T, std::remove_reference_t<OnlyVal>>::value}

whether the check passed

template<typename T, typename MemorySpace>
class TypedField : public muGrid::TypedFieldBase<T, MemorySpace>
#include <field_typed.hh>

forward declaration of the muSpectre::TypedField

forward declaration of the muGrid::TypedField

Forward declaration of TypedField (default arg already in field_collection.hh)

A muGrid::TypedField holds a certain number of components (scalars of type T per quadrature point of a muGrid::FieldCollection’s domain.

Template Parameters:

Public Types

using Parent = TypedFieldBase<T, MemorySpace>

base class

using EigenRep_t = typename Parent::EigenRep_t

Eigen type to represent the field’s data.

using Negative = typename Parent::Negative

convenience alias

Public Functions

TypedField() = delete

Default constructor.

TypedField(const TypedField &other) = delete

Copy constructor.

TypedField(TypedField &&other) = delete

Move constructor.

virtual ~TypedField() = default

Destructor.

TypedField &operator=(TypedField &&other) = delete

Move assignment operator.

TypedField &operator=(const TypedField &other)

Copy assignment operator.

TypedField &operator=(const Parent &other)

Copy assignment operator.

TypedField &operator=(const Negative &other)

Copy assignment operator.

TypedField &operator=(const EigenRep_t &other)

Copy assignment operator.

virtual void set_zero() final

initialise field to zero (do more complicated initialisations through fully typed maps)

virtual size_t get_buffer_size() const final

size of the internal buffer (in scalars)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, void> push_back(const T &value)

add a new scalar value at the end of the field (incurs runtime cost, do not use this in any hot loop). If your field has more than one quadrature point per pixel the same scalar value is pushed back on all quadrature points of the pixel. (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, void> push_back_single(const T &value)

add a new scalar value at the end of the field (incurs runtime cost, do not use this in any hot loop). Even if you have several quadrature points per pixel you push back only a single value on a single quadrature point. Thus you can push back different values on quadrature points belongign to the same pixel. (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, void> push_back(const Eigen::Ref<const Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic>> &value)

add a new non-scalar value at the end of the field (incurs runtime cost, do not use this in any hot loop) If your field has more than one quadrature point per pixel the same non-scalar value is pushed back on all quadrature points of the pixel. (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, void> push_back_single(const Eigen::Ref<const Eigen::Array<T, Eigen::Dynamic, Eigen::Dynamic>> &value)

add a new non-scalar value at the end of the field (incurs runtime cost, do not use this in any hot loop) Even if you have several quadrature points per pixel you push back only a single non-scalar value on a single quadrature point. Thus you can push back different values on quadrature points belongign to the same pixel. (host-space only)

TypedField &clone(const std::string &new_name, const bool &allow_overwrite = false) const

perform a full copy of a field

Parameters:
  • new_name – the name under which the new field will be stored

  • allow_overwrite – by default, this function throws an error if the destination field already exists to avoid accidental clobbering of fields. If set to true, the copy will be made into the existing field.

Public Members

friend FieldCollection

give access to collections

Public Static Functions

static TypedField &safe_cast(Field &other)

cast a reference to a base type to this type, with full checks

static const TypedField &safe_cast(const Field &other)

cast a const reference to a base type to this type, with full checks

static TypedField &safe_cast(Field &other, const Index_t &nb_components, const std::string &sub_division)

cast a reference to a base type to this type safely, plus check whether it has the right number of components

static const TypedField &safe_cast(const Field &other, const Index_t &nb_components, const std::string &sub_division)

cast a const reference to a base type to this type safely, plus check whether it has the right number of components

Protected Functions

inline TypedField(const std::string &unique_name, FieldCollection &collection, const Index_t &nb_components, const std::string &sub_division, const Unit &unit)

Fields are supposed to only exist in the form of std::unique_ptrs held by a FieldCollection. The Field constructor is protected to ensure this.

Parameters:
  • unique_name – unique field name (unique within a collection)

  • nb_components – number of components to store per quadrature point

  • collection – reference to the holding field collection.

inline TypedField(const std::string &unique_name, FieldCollection &collection, const Shape_t &components_shape, const std::string &sub_division, const Unit &unit)

Fields are supposed to only exist in the form of std::unique_ptrs held by a FieldCollection. The Field constructor is protected to ensure this.

Parameters:
  • unique_name – unique field name (unique within a collection)

  • collection – reference to the holding field collection.

  • components_shape – number of components to store per quadrature point

  • storage_oder – in-memory storage order of the components

virtual void resize() final

resizes the field to the given size

template<typename T, typename MemorySpace>
class TypedFieldBase : public muGrid::Field

forward declaration

Subclassed by muGrid::TypedField< Scalar >, muGrid::TypedField< T, MemorySpace >

Public Types

using Memory_Space = MemorySpace

Memory space type.

using View_t = Array<T, MemorySpace>

Array type for storage.

using Scalar = T

stored scalar type

using EigenRep_t = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>

Eigen type used to represent the field’s data.

using EigenVecRep_t = Eigen::Matrix<T, Eigen::Dynamic, 1>

Eigen type used to represent the field’s data.

using Eigen_map = Eigen::Map<EigenRep_t>

eigen map (handle for EigenRep_t)

using Eigen_cmap = Eigen::Map<const EigenRep_t>

eigen const map (handle for EigenRep_t)

using EigenVec_map = Eigen::Map<EigenVecRep_t>

eigen vector map (handle for EigenVecRep_t)

using EigenVec_cmap = Eigen::Map<const EigenVecRep_t>

eigen vector const map (handle for EigenVecRep_t)

using Parent = Field

base class

Public Functions

TypedFieldBase() = delete

Default constructor.

TypedFieldBase(const TypedFieldBase &other) = delete

Copy constructor.

TypedFieldBase(TypedFieldBase &&other) = default

Move constructor.

virtual ~TypedFieldBase() = default

Destructor.

TypedFieldBase &operator=(TypedFieldBase &&other) = delete

Move assignment operator.

TypedFieldBase &operator=(const TypedFieldBase &other)

Copy assignment operator.

TypedFieldBase &operator=(const Negative &other)

Copy assignment operator.

TypedFieldBase &operator=(const EigenRep_t &other)

Copy assignment operators.

Negative operator-() const

Unary negative.

TypedFieldBase &operator+=(const TypedFieldBase &other)

addition assignment

TypedFieldBase &operator-=(const TypedFieldBase &other)

subtraction assignment

inline virtual TypeDescriptor get_type_descriptor() const final

return the unified type descriptor for this field’s element type

inline virtual std::size_t get_element_size_in_bytes() const final

return the size of the elementary field entry in bytes

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_map> eigen_mat()

return a vector map onto the underlying data (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_cmap> eigen_mat() const

return a const vector map onto the underlying data (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, EigenVec_map> eigen_vec()

return a vector map onto the underlying data (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, EigenVec_cmap> eigen_vec() const

return a const vector map onto the underlying data (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_map> eigen_sub_pt()

return a matrix map onto the underlying data with one column per quadrature point (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_cmap> eigen_sub_pt() const

return a const matrix map onto the underlying data with one column per quadrature point (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_map> eigen_pixel()

return a matrix map onto the underlying data with one column per pixel (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_cmap> eigen_pixel() const

return a const matrix map onto the underlying data with one column per pixel (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, FieldMap<T, Mapping::Mut>> get_pixel_map(const Index_t &nb_rows = Unknown)

convenience function returns a map of this field, iterable per pixel. (host-space only)

Parameters:

nb_rows – optional specification of the number of rows for the iterate. If left to default value, a matrix of shape nb_components × nb_quad_pts is used

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, FieldMap<T, Mapping::Const>> get_pixel_map(const Index_t &nb_rows = Unknown) const

convenience function returns a const map of this field, iterable per pixel. (host-space only)

Parameters:

nb_rows – optional specification of the number of rows for the iterate. If left to default value, a matrix of shape nb_components × nb_quad_pts is used

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, FieldMap<T, Mapping::Mut>> get_sub_pt_map(const Index_t &nb_rows = Unknown)

convenience function returns a map of this field, iterable per quadrature point. (host-space only)

Parameters:

nb_rows – optional specification of the number of rows for the iterate. If left to default value, a column vector is used

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, FieldMap<T, Mapping::Const>> get_sub_pt_map(const Index_t &nb_rows = Unknown) const

convenience function returns a const map of this field, iterable per quadrature point. (host-space only)

Parameters:

nb_rows – optional specification of the number of rows for the iterate. If left to default value, a column vector is used

template<typename M = MemorySpace>
inline std::enable_if_t<is_host_space_v<M>, T*> data()

Get the raw data pointer. Only available for host-space fields. Don’t use unless interfacing with external libs.

template<typename M = MemorySpace>
inline std::enable_if_t<is_host_space_v<M>, const T*> data() const

Get the raw data pointer (const). Only available for host-space fields. Don’t use unless interfacing with external libs.

virtual void *get_void_data_ptr(bool assert_host_memory = true) const final

return a pointer to the raw data. Don’t use unless interfacing with external libs.

Parameters:

assert_host_memory – If true (default), throws an error if the field is on device memory. Set to false only when passing the pointer to CUDA-aware libraries (e.g., CUDA-aware MPI).

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_map> eigen_map(const Index_t &nb_rows, const Index_t &nb_cols)

non-const eigen_map with arbitrary sizes (host-space only)

template<typename M = MemorySpace>
std::enable_if_t<is_host_space_v<M>, Eigen_cmap> eigen_map(const Index_t &nb_rows, const Index_t &nb_cols) const

const eigen_map with arbitrary sizes (host-space only)

inline View_t &view()

Get the underlying Array for use in kernels.

inline const View_t &view() const

Get the underlying Array (const) for use in kernels.

template<typename OtherSpace>
void deep_copy_from(const TypedFieldBase<T, OtherSpace> &src)

Deep copy from another field (potentially in a different memory space). This performs a host-device or device-host transfer as needed.

inline virtual bool is_on_device() const final

Check if field resides on device (GPU) memory. Implementation uses compile-time type trait.

inline virtual int get_dlpack_device_type() const final

Get DLPack device type for this field’s memory space.

inline virtual int get_device_id() const final

Get device ID for multi-GPU systems. Returns the device ID from the field collection’s Device.

inline virtual std::string get_device_string() const final

Get device string for Python interoperability. Returns “cpu”, “cuda:N”, or “rocm:N” where N is the device ID.

template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_map> eigen_map(const Index_t &nb_rows, const Index_t &nb_cols)
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_cmap> eigen_map(const Index_t &nb_rows, const Index_t &nb_cols) const
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::EigenVec_map> eigen_vec()
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::EigenVec_cmap> eigen_vec() const
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_map> eigen_sub_pt()
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_cmap> eigen_sub_pt() const
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_map> eigen_pixel()
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_cmap> eigen_pixel() const
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_map> eigen_mat()
template<typename M>
std::enable_if_t<is_host_space_v<M>, typename TypedFieldBase<T, MemorySpace>::Eigen_cmap> eigen_mat() const

Protected Functions

inline TypedFieldBase(const std::string &unique_name, FieldCollection &collection, Index_t nb_components, const std::string &sub_division, const Unit &unit)

Fields are supposed to only exist in the form of std::unique_ptrs held by a FieldCollection. TheFieldconstructor is protected to ensure this. Fields are instantiated through theregister_field` methods FieldCollection.

Parameters:
  • unique_name – unique field name (unique within a collection)

  • collection – reference to the holding field collection.

  • nb_components – number of components to store per quadrature point

inline TypedFieldBase(const std::string &unique_name, FieldCollection &collection, const Shape_t &components_shape, const std::string &sub_division, const Unit &unit)

Fields are supposed to only exist in the form of std::unique_ptrs held by a FieldCollection. TheFieldconstructor is protected to ensure this. Fields are instantiated through theregister_field` methods FieldCollection.

Parameters:
  • unique_name – unique field name (unique within a collection)

  • collection – reference to the holding field collection.

  • components_shape – number of components to store per quadrature point

Protected Attributes

View_t values = {}

Array storage for the raw field data.

Friends

friend class FieldMap
template<typename T>
class TypedStateField : public muGrid::StateField
#include <state_field.hh>

forward declaration of the state field

forward declaration

The TypedStateField class is a byte compatible daughter class of the StateField class, and it can return fully typed Field references.

Public Types

using Parent = StateField

base class

Public Functions

TypedStateField() = delete

Deleted default constructor.

TypedStateField(const TypedStateField &other) = delete

Copy constructor.

TypedStateField(TypedStateField &&other) = delete

Move constructor.

virtual ~TypedStateField() = default

Destructor.

TypedStateField &operator=(const TypedStateField &other) = delete

Copy assignment operator.

TypedStateField &operator=(TypedStateField &&other) = delete

Move assignment operator.

virtual TypeDescriptor get_type_descriptor() const final

return the unified type descriptor for this state field’s element type

virtual std::size_t get_element_size_in_bytes() const final

return the size of the elementary field entry in bytes

TypedField<T> &current()

return a reference to the current field

const TypedField<T> &current() const

return a const reference to the current field

const TypedField<T> &old(size_t nb_steps_ago = 1) const

return a const reference to the field which was current nb_steps_ago steps ago

Protected Functions

TypedStateField(const std::string &unique_prefix, FieldCollection &collection, const Index_t &nb_memory, const Index_t &nb_components, const std::string &sub_division, const Unit &unit)

protected constructor, to avoid the creation of unregistered fields. Users should create fields through the muGrid::FieldCollection::register_real_field() (or int, uint, complex) factory functions.

RefVector<Field> &get_fields()

return a reference to the storage of the constituent fields

Protected Attributes

friend FieldCollection

give access to the protected state field constructor

Friends

friend class StateFieldMap< T, Mapping::Const >
friend class StateFieldMap< T, Mapping::Mut >
class Unit
#include <units.hh>

A wrapper class around 5 DynBaseUnit objects representing length, mass, time, temperature, and change. This should be sufficient to handle all of µSpectre’s needs, but could easily be extended by mol and luminous intensity to represent the full SI.

Public Functions

Unit(const UnitExponent &length, const UnitExponent &mass, const UnitExponent &time, const UnitExponent &temperature, const UnitExponent &current, const UnitExponent &luminous_intensity, const UnitExponent &amount, const Int &tag = 0)

constructor from subunits ond optional integer tag can be used to handle cases of additional incompatibilities, e.g., for species. Imagine a coupled diffusion calculation, where one constitutive law handles a concentration of mol·Na/l, and another one a concentration of mol·Ka/l. Both have the same SI unit, but are not compatible. Use different tags for units that need to be mutually incompatible for whatever reason

const UnitExponent &get_length() const

returns a const reference to length

const UnitExponent &get_mass() const

returns a const reference to mass

const UnitExponent &get_time() const

returns a const reference to time

const UnitExponent &get_temperature() const

returns a const reference to temperature

const UnitExponent &get_current() const

returns a const reference to current

const UnitExponent &get_luminous_intensity() const

returns a const reference to luminous intensity

const UnitExponent &get_amount() const

returns a const reference to amount of matter

Unit(const Unit &other) = default

Copy constructor.

Unit(Unit &&other) = default

Move constructor.

virtual ~Unit() = default

Destructor.

Unit &operator=(const Unit &other) = default

Copy assignment operator.

Unit &operator=(Unit &&other) = default

Move assignment operator.

bool operator==(const Unit &other) const

comparison operator

bool operator!=(const Unit &other) const

comparison operator

bool operator<(const Unit &other) const

comparison (required for use as key in std::map)

Unit operator+(const Unit &other) const

addition

Unit operator-(const Unit &other) const

subtraction

Unit operator*(const Unit &other) const

multiplication

Unit operator/(const Unit &other) const

division

Public Static Functions

static Unit unitless(const Int &tag = 0)

factory function for base unit pure number

static Unit length(const Int &tag = 0)

factory function for base unit length

static Unit mass(const Int &tag = 0)

factory function for base unit mass

static Unit time(const Int &tag = 0)

factory function for base unit time

static Unit temperature(const Int &tag = 0)

factory function for base unit temperature

static Unit current(const Int &tag = 0)

factory function for base unit current

static Unit luminous_intensity(const Int &tag = 0)

factory function for base unit luminous intensity

static Unit amount(const Int &tag = 0)

factory function for base unit amount of matter

static Unit force(const Int &tag = 0)

factory function for mechanical stress

static Unit stress(const Int &tag = 0)

factory function for mechanical stress

static Unit strain(const Int &tag = 0)

factory function for mechanical strain

Protected Functions

UnitExponent &get_length()

returns a reference to length

UnitExponent &get_mass()

returns a reference to mass

UnitExponent &get_time()

returns a reference to time

UnitExponent &get_temperature()

returns a reference to temperature

UnitExponent &get_current()

returns a reference to current

UnitExponent &get_luminous_intensity()

returns a reference to luminous intensity

UnitExponent &get_amount()

returns a reference to amount of matter

void check_tags(const Unit &other) const

Throws a UnitError if *this and other have mismatched tags.

explicit Unit(const Int &tag)

tagged almost-default constructor

Protected Attributes

std::array<UnitExponent, NbUnits> units = {}
Int tag

Protected Static Attributes

static constexpr int NbUnits = {7}

Friends

friend std::ostream &operator<<(std::ostream&, const Unit &unit)
class UnitError : public muGrid::ExceptionWithTraceback<T>

Public Types

using Parent = RuntimeError

Public Functions

UnitError() = delete

Default constructor.

explicit UnitError(const std::string &what)

Constructor with message.

UnitError(const UnitError &other) = default

Copy constructor.

UnitError(UnitError &&other) = default

Move constructor.

virtual ~UnitError() = default

Destructor.

UnitError &operator=(const UnitError &other) = default

Copy assignment operator.

UnitError &operator=(UnitError &&other) = default

Move assignment operator.

class UnitExponent
#include <units.hh>

Run-time representation of a rational exponent for base units. This can be used to compose any unit. e.g., speed would be length per time, i.e. length¹ · time⁻¹. Note that the rational exponent allows to express more exotic units such as for instance the 1/√length in fracture toughness (length^(⁻¹/₂)). The rational exponent is always reduced to the simplest form with a positive denominator. A zero denominator results in a UnitError being thrown.

Public Functions

UnitExponent() = default

default constructor (needed for default initialisation of std::array)

explicit UnitExponent(const Int &numerator, const Int &denominator = 1)

constructor

UnitExponent(const UnitExponent &other) = default

Copy constructor.

UnitExponent(UnitExponent &&other) = default

Move constructor.

virtual ~UnitExponent() = default

Destructor.

UnitExponent &operator=(const UnitExponent &other) = default

Copy assignment operator.

UnitExponent &operator=(UnitExponent &&other) = default

Move assignment operator.

bool operator==(const UnitExponent &other) const

comparison operator

bool operator!=(const UnitExponent &other) const

comparison operator

bool operator<(const UnitExponent &other) const

comparison operator (required for use as key in std::map)

UnitExponent operator+(const UnitExponent &other) const

addition

UnitExponent operator-(const UnitExponent &other) const

subtraction

UnitExponent operator*(const UnitExponent &other) const

multiplication (exponent addition)

UnitExponent operator/(const UnitExponent &other) const

division (exponent subtraction)

const Int &get_numerator() const
const Int &get_denominator() const

Protected Functions

void reduce()

Protected Attributes

Int numerator = {}
Int denominator = {}

Friends

friend std::ostream &operator<<(std::ostream&, const UnitExponent &unit)
struct util

Public Static Functions

static inline POCKETFFT_NOINLINE size_t largest_prime_factor (size_t n)
static inline POCKETFFT_NOINLINE double cost_guess (size_t n)
static inline POCKETFFT_NOINLINE size_t good_size_cmplx (size_t n)
static inline POCKETFFT_NOINLINE size_t good_size_cmplx (size_t n, size_t required_factor)
static inline POCKETFFT_NOINLINE size_t good_size_real (size_t n)
static inline POCKETFFT_NOINLINE size_t good_size_real (size_t n, size_t required_factor)
static inline POCKETFFT_NOINLINE size_t prev_good_size_cmplx (size_t n)
static inline POCKETFFT_NOINLINE size_t prev_good_size_real (size_t n)
static inline size_t prod(const shape_t &shape)
static inline POCKETFFT_NOINLINE void sanity_check (const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, bool inplace)
static inline POCKETFFT_NOINLINE void sanity_check (const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, bool inplace, const shape_t &axes)
static inline POCKETFFT_NOINLINE void sanity_check (const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, bool inplace, size_t axis)
static inline size_t thread_count(size_t nthreads, const shape_t &shape, size_t axis, size_t vlen)
template<typename T>
struct VLEN

Public Static Attributes

static constexpr size_t val = 1
template<typename T>
struct VTYPE
struct worker

Public Functions

inline void worker_main(std::atomic<bool> &shutdown_flag, std::atomic<size_t> &unscheduled_tasks, concurrent_queue<std::function<void()>> &overflow_work)

Public Members

std::thread thread
std::condition_variable work_ready
std::mutex mut
std::atomic_flag busy_flag = ATOMIC_FLAG_INIT
std::function<void()> work
template<class ...Containers>
class ZipContainer

Container adapter for zip iteration.

Public Functions

inline explicit ZipContainer(Containers&&... containers)
inline decltype(auto) begin() const
inline decltype(auto) end() const
inline decltype(auto) begin()
inline decltype(auto) end()

Private Types

using containers_t = std::tuple<Containers...>

Private Members

containers_t containers
template<class ...Iterators>
class ZipIterator
#include <iterators.hh>

Iterator for zip - holds tuple of iterators.

Public Functions

inline explicit ZipIterator(tuple_t iterators)
inline decltype(auto) operator*()
inline ZipIterator &operator++()
inline bool operator==(const ZipIterator &other) const
inline bool operator!=(const ZipIterator &other) const

Private Types

using tuple_t = std::tuple<Iterators...>

Private Members

tuple_t iterators
namespace akantu

Functions

template<class ...Iterators>
decltype(auto) zip_iterator(std::tuple<Iterators...> &&iterators_tuple)

Create zip iterator from tuple of iterators.

template<class ...Containers>
decltype(auto) zip(Containers&&... conts)

Emulates Python’s zip() - iterate over multiple containers in parallel

template<class Container>
inline auto enumerate(Container &&container, size_t start = 0)

Emulates Python’s enumerate() - iterate with index Uses C++20 std::views::iota for the index range

namespace containers
namespace iterators
namespace tuple

Functions

template<class Tuple, size_t... Is>
bool are_not_equal_impl(Tuple &&a, Tuple &&b, std::index_sequence<Is...>)

Check if ALL corresponding elements in two tuples are not equal For zip iterators: returns false when ANY iterator reaches its end (stops iteration at shortest container) Uses C++17 fold expression

template<class Tuple>
bool are_not_equal(Tuple &&a, Tuple &&b)
template<class F, class Tuple, size_t... Is>
void foreach_impl(F &&func, Tuple &&tuple, std::index_sequence<Is...>)

Apply function to each element of tuple (C++17 fold expression)

template<class F, class Tuple>
void foreach_(F &&func, Tuple &&tuple)
template<class F, class Tuple, size_t... Is>
decltype(auto) transform_impl(F &&func, Tuple &&tuple, std::index_sequence<Is...>)

Transform each element of tuple with function.

template<class F, class Tuple>
decltype(auto) transform(F &&func, Tuple &&tuple)
namespace details

Functions

template<typename ...Ts>
decltype(auto) make_tuple_no_decay(Ts&&... args)

Create tuple without decay (preserves references)

namespace muGrid

Typedefs

using DynGridIndex = DynCoord<fourD>

Dynamic integer grid indices with runtime dimension.

Used for grid dimensions, pixel coordinates, strides, and ghost counts when the spatial dimension is determined at runtime (e.g., Python API). Maximum dimension is 4 for SIMD alignment.

using GridShape = DynGridIndex

Alias for DynGridIndex used for grid/pixel shapes.

Provides semantic clarity when the coordinate represents a shape (e.g., nb_grid_pts) rather than a position.

typedef ExceptionWithTraceback<std::runtime_error> RuntimeError

A type alias for ExceptionWithTraceback specialized with std::runtime_error.

This type is used to throw exceptions that include a stack trace, for runtime errors.

using Shape_t = std::vector<Index_t>

Type used for shapes and strides.

template<typename MemorySpace>
using FFTBackend_t = typename FFTBackendSelector<MemorySpace>::type

Helper alias for the backend type for a given memory space.

template<class EigenPlain, Mapping Mutability, IterUnit IterationType>
using EigenFieldMap = StaticFieldMap<typename EigenPlain::Scalar, Mutability, internal::EigenMap<typename EigenPlain::Scalar, EigenPlain>, IterationType>

Alias of muGrid::StaticFieldMap you wish to iterate over pixel by pixel or quadrature point by quadrature point with a chosen, statically sized plain Eigen type

Template Parameters:
  • EigenPlain – a statically sized Eigen::Array or Eigen::Matrix

  • Mutability – whether or not the map allows to modify the content of the field

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t NbRow, Dim_t NbCol, IterUnit IterationType>
using MatrixFieldMap = StaticFieldMap<T, Mutability, internal::MatrixMap<T, NbRow, NbCol>, IterationType>

Alias of muGrid::StaticFieldMap you wish to iterate over pixel by pixel or quadrature point by quadrature point with statically sized Eigen::Matrix iterates

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbRow – number of rows of the iterate

  • NbCol – number of columns of the iterate

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t NbRow, Dim_t NbCol, IterUnit IterationType>
using ArrayFieldMap = StaticFieldMap<T, Mutability, internal::ArrayMap<T, NbRow, NbCol>, IterationType>

Alias of muGrid::StaticFieldMap you wish to iterate over pixel by pixel or quadrature point by quadrature point with* statically sized Eigen::Array iterates

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbRow – number of rows of the iterate

  • NbCol – number of columns of the iterate

  • IterationType – describes the pixel-subdivisionuadrature points

template<typename T, Mapping Mutability, IterUnit IterationType>
using ScalarFieldMap = StaticFieldMap<T, Mutability, internal::ScalarMap<T>, IterationType>

Alias of muGrid::StaticFieldMap over a scalar field you wish to iterate over

Template Parameters:
template<typename T, Mapping Mutability, Dim_t Rank, Dim_t Dim, IterUnit IterationType>
using TensorFieldMap = StaticFieldMap<T, Mutability, internal::TensorMap<T, Rank, Dim>, IterationType>

Alias of muGrid::StaticNFieldMap over a tensor field you wish to iterate over

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Rank – tensorial rank

  • Dim – spatial dimension of the tensor

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType>
using T1FieldMap = StaticFieldMap<T, Mutability, internal::MatrixMap<T, Dim, 1>, IterationType>

Alias of muGrid::StaticFieldMap over a second-rank tensor field you wish to iterate over

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensor

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType>
using T2FieldMap = StaticFieldMap<T, Mutability, internal::MatrixMap<T, Dim, Dim>, IterationType>

Alias of muGrid::StaticFieldMap over a second-rank tensor field you wish to iterate over

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensor

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType>
using T4FieldMap = StaticFieldMap<T, Mutability, internal::MatrixMap<T, Dim * Dim, Dim * Dim>, IterationType>

Alias of muGrid::StaticFieldMap over a fourth-rank tensor field you wish to iterate over

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensor

  • IterationType – describes the pixel-subdivision

using RealField = TypedField<Real, HostSpace>

Alias for real-valued host fields.

using ComplexField = TypedField<Complex, HostSpace>

Alias for complex-valued host fields.

using IntField = TypedField<Int, HostSpace>

Alias for integer-valued host fields.

using UintField = TypedField<Uint, HostSpace>

Alias for unsigned integer-valued host fields.

using IndexField = TypedField<Index_t, HostSpace>

Alias for index-valued host fields.

using RealFieldDevice = TypedField<Real, DefaultDeviceSpace>

Alias for real-valued device fields (CUDA/HIP)

using ComplexFieldDevice = TypedField<Complex, DefaultDeviceSpace>

Alias for complex-valued device fields.

using IntFieldDevice = TypedField<Int, DefaultDeviceSpace>

Alias for integer-valued device fields.

using UintFieldDevice = TypedField<Uint, DefaultDeviceSpace>

Alias for unsigned integer-valued device fields.

using IndexFieldDevice = TypedField<Index_t, DefaultDeviceSpace>

Alias for index-valued device fields.

template<typename MemorySpace = HostSpace>
using RealFieldT = TypedField<Real, MemorySpace>

Alias for real-valued fields with configurable memory space.

template<typename MemorySpace = HostSpace>
using ComplexFieldT = TypedField<Complex, MemorySpace>

Alias for complex-valued fields with configurable memory space.

template<typename MemorySpace = HostSpace>
using IntFieldT = TypedField<Int, MemorySpace>

Alias for integer-valued fields with configurable memory space.

template<typename MemorySpace = HostSpace>
using UintFieldT = TypedField<Uint, MemorySpace>

Alias for unsigned integer-valued fields with configurable memory space.

template<class EigenPlain, Mapping Mutability, IterUnit IterationType>
using MappedEigenField = MappedField<EigenFieldMap<EigenPlain, Mutability, IterationType>>

Alias of muGrid::MappedField for a map with corresponding muSpectre::Field you wish to iterate over pixel by pixel or quadrature point by quadrature point with a chosen, statically sized plain Eigen type

Template Parameters:
  • EigenPlain – a statically sized Eigen::Array or Eigen::Matrix

  • Mutability – whether or not the map allows to modify the content of the field

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t NbRow, Dim_t NbCol, IterUnit IterationType>
using MappedMatrixField = MappedField<MatrixFieldMap<T, Mutability, NbRow, NbCol, IterationType>>

Alias of muGrid::MappedField for a map with corresponding muSpectre::Field you wish to iterate over pixel by pixel or quadrature point by quadrature point with statically sized Eigen::Matrix iterates

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbRow – number of rows of the iterate

  • NbCol – number of columns of the iterate

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t NbRow, Dim_t NbCol, IterUnit IterationType>
using MappedArrayField = MappedField<ArrayFieldMap<T, Mutability, NbRow, NbCol, IterationType>>

Alias of muGrid::MappedField for a map with corresponding muSpectre::Field you wish to iterate over pixel by pixel or quadrature point by quadrature point with statically sized Eigen::Array iterates

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbRow – number of rows of the iterate

  • NbCol – number of columns of the iterate

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, IterUnit IterationType>
using MappedScalarField = MappedField<ScalarFieldMap<T, Mutability, IterationType>>

Alias of muGrid::MappedField for a map of scalars with corresponding muSpectre::Field you wish to iterate over.

Template Parameters:
template<typename T, Mapping Mutability, Dim_t Rank, Dim_t Dim, IterUnit IterationType>
using MappedTensorField = MappedField<TensorFieldMap<T, Mutability, Rank, Dim, IterationType>>

Alias of muGrid::MappedField for a map of second-rank with corresponding muSpectre::Field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Rank – tensorial rank

  • Dim – spatial dimension of the tensors

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType>
using MappedT1Field = MappedField<T1FieldMap<T, Mutability, Dim, IterationType>>

Alias of muGrid::MappedField for a map of second-rank with corresponding muSpectre::Field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensors

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType>
using MappedT2Field = MappedField<T2FieldMap<T, Mutability, Dim, IterationType>>

Alias of muGrid::MappedField for a map of first-rank with corresponding muSpectre::Field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensors

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType>
using MappedT4Field = MappedField<T4FieldMap<T, Mutability, Dim, IterationType>>

Alias of muGrid::MappedField for a map of fourth-rank with corresponding muSpectre::Field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensors

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t NbRow, Dim_t NbCol, IterUnit IterationType, size_t NbMemory = 1>
using MappedMatrixStateField = MappedStateField<MatrixStateFieldMap<T, Mutability, NbRow, NbCol, NbMemory, IterationType>>

Alias of muGrid::MappedStateField for a map with corresponding muSpectre::StateField you wish to iterate over pixel by pixel or quadrature point by quadrature point with statically sized Eigen::Matrix iterates

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbRow – number of rows of the iterate

  • NbCol – number of columns of the iterate

  • IterationType – describes the pixel-subdivision

  • NbMemory – number of previous values to store

template<typename T, Mapping Mutability, Dim_t NbRow, Dim_t NbCol, IterUnit IterationType, size_t NbMemory = 1>
using MappedArrayStateField = MappedStateField<ArrayStateFieldMap<T, Mutability, NbRow, NbCol, NbMemory, IterationType>>

Alias of muGrid::MappedStateField for a map with corresponding muSpectre::StateField you wish to iterate over pixel by pixel or quadrature point by quadrature point with statically sized Eigen::Array iterates

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbRow – number of rows of the iterate

  • NbCol – number of columns of the iterate

  • IterationType – describes the pixel-subdivision

  • NbMemory – number of previous values to store

template<typename T, Mapping Mutability, IterUnit IterationType, size_t NbMemory = 1>
using MappedScalarStateField = MappedStateField<ScalarStateFieldMap<T, Mutability, NbMemory, IterationType>>

Alias of muGrid::MappedStateField for a map of scalars with corresponding muSpectre::StateField you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • IterationType – describes the pixel-subdivision

  • NbMemory – number of previous values to store

template<typename T, Mapping Mutability, Dim_t Rank, Dim_t Dim, IterUnit IterationType, size_t NbMemory = 1>
using MappedTensorStateNField = MappedStateField<TensorStateFieldMap<T, Mutability, Rank, Dim, NbMemory, IterationType>>

Alias of muGrid::MappedStateField for a map of first-rank with corresponding muSpectre::StateNField you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Rank – tensorial rank

  • Dim – spatial dimension of the tensors

  • IterationType – describes the pixel-subdivision

  • NbMemory – number of previous values to store

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType, size_t NbMemory = 1>
using MappedT1StateNField = MappedStateField<T1StateFieldMap<T, Mutability, Dim, NbMemory, IterationType>>

Alias of muGrid::MappedStateField for a map of first-rank with corresponding muSpectre::StateNField you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensors

  • IterationType – describes the pixel-subdivision

  • NbMemory – number of previous values to store

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType, size_t NbMemory = 1>
using MappedT2StateField = MappedStateField<T2StateFieldMap<T, Mutability, Dim, NbMemory, IterationType>>

Alias of muGrid::MappedStateField for a map of second-rank with corresponding muSpectre::StateField you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensors

  • IterationType – describes the pixel-subdivision

  • NbMemory – number of previous values to store

template<typename T, Mapping Mutability, Dim_t Dim, IterUnit IterationType, size_t NbMemory = 1>
using MappedT4StateField = MappedStateField<T4StateFieldMap<T, Mutability, Dim, NbMemory, IterationType>>

Alias of muGrid::MappedStateField for a map of fourth-rank with corresponding muSpectre::StateField you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensors

  • IterationType – describes the pixel-subdivision

  • NbMemory – number of previous values to store

using RealStateField = TypedStateField<Real>

Alias for real-valued state fields.

using ComplexStateField = TypedStateField<Complex>

Alias for complex-valued state fields.

using IntStateField = TypedStateField<Int>

Alias for integer-valued state fields.

using Uintfield = TypedStateField<Uint>

Alias for unsigned integer-valued state fields.

template<typename T, Mapping Mutability, Dim_t NbRow, Dim_t NbCol, size_t NbMemory, IterUnit IterationType = IterUnit::SubPt>
using MatrixStateFieldMap = StaticStateFieldMap<T, Mutability, internal::MatrixMap<T, NbRow, NbCol>, NbMemory, IterationType>

Alias of muGrid::StaticStateFieldMap you wish to iterate over pixel by pixel or quadrature point by quadrature point with statically sized Eigen::Matrix iterates

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbRow – number of rows of the iterate

  • NbCol – number of columns of the iterate

  • NbMemory – number of previous values to store

  • IterationType – whether to iterate over pixels or quadrature points

template<typename T, Mapping Mutability, Dim_t NbRow, Dim_t NbCol, size_t NbMemory, IterUnit IterationType>
using ArrayStateFieldMap = StaticStateFieldMap<T, Mutability, internal::ArrayMap<T, NbRow, NbCol>, NbMemory, IterationType>

Alias of muGrid::StaticStateFieldMap you wish to iterate over pixel by pixel or quadrature point by quadrature point with* statically sized Eigen::Array iterates

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbRow – number of rows of the iterate

  • NbCol – number of columns of the iterate

  • NbMemory – number of previous values to store

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, size_t NbMemory, IterUnit IterationType>
using ScalarStateFieldMap = StaticStateFieldMap<T, Mutability, internal::ScalarMap<T>, NbMemory, IterationType>

Alias of muGrid::StaticStateFieldMap over a scalar field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • NbMemory – number of previous values to store

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Rank, Dim_t Dim, size_t NbMemory, IterUnit IterationType>
using TensorStateFieldMap = StaticStateFieldMap<T, Mutability, internal::TensorMap<T, Rank, Dim>, NbMemory, IterationType>

Alias of muGrid::StaticStateNFieldMap over a first-rank tensor field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Rank – tensorial rank

  • Dim – spatial dimension of the tensor

  • NbMemory – number of previous values to store

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, size_t NbMemory, IterUnit IterationType>
using T1StateFieldMap = StaticStateFieldMap<T, Mutability, internal::MatrixMap<T, Dim, 1>, NbMemory, IterationType>

Alias of muGrid::StaticStateNFieldMap over a first-rank tensor field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensor

  • NbMemory – number of previous values to store

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, size_t NbMemory, IterUnit IterationType>
using T2StateFieldMap = StaticStateFieldMap<T, Mutability, internal::MatrixMap<T, Dim, Dim>, NbMemory, IterationType>

Alias of muGrid::StaticStateNFieldMap over a second-rank tensor field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensor

  • NbMemory – number of previous values to store

  • IterationType – describes the pixel-subdivision

template<typename T, Mapping Mutability, Dim_t Dim, size_t NbMemory, IterUnit IterationType>
using T4StateFieldMap = StaticStateFieldMap<T, Mutability, internal::MatrixMap<T, Dim * Dim, Dim * Dim>, NbMemory, IterationType>

Alias of muGrid::StaticStateFieldMap over a fourth-rank tensor field you wish to iterate over.

Template Parameters:
  • T – scalar type stored in the field, must be one of muGrid::Real, muGrid::Int, muGrid::Uint, muGrid::Complex

  • Mutability – whether or not the map allows to modify the content of the field

  • Dim – spatial dimension of the tensor

  • NbMemory – number of previous values to store

  • IterationType – describes the pixel-subdivision

using DefaultDeviceSpace = HostSpace
template<typename T>
using DynMatrix_t = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
template<typename T, Dim_t Dim>
using T4Mat = Eigen::Matrix<T, Dim * Dim, Dim * Dim>

simple adapter function to create a matrix that can be mapped as a tensor

template<typename T, Dim_t Dim, bool ConstMap = false>
using T4MatMap = std::conditional_t<ConstMap, Eigen::Map<const T4Mat<T, Dim>>, Eigen::Map<T4Mat<T, Dim>>>

Map onto muGrid::T4Mat

Enums

enum class IterUnit

An enumeration class for iteration units.

This enumeration class is used in two contexts within the µGrid codebase. Firstly, it is used in Fields to specify the relative storage of data with respect to pixels, quadrature points, or nodal points. Secondly, it is used in FieldMaps to specify the unit of iteration, whether it be over pixels, quadrature points, or nodal points.

Values:

enumerator Pixel

dofs relative to a pixel/voxel, no subdivision

enumerator SubPt

dofs relative to sub-points (e.g. quadrature points)

enum class StorageOrder

An enumeration class for storage orders of field components.

This enumeration class defines three types of storage orders: ArrayOfStructures, StructureOfArrays and Automatic. These storage orders can be used to determine the order in which field components are stored in memory.

Values:

enumerator ArrayOfStructures

components are consecutive in memory

enumerator StructureOfArrays
enumerator Automatic

inherit storage order from FieldCollection

enum class Mapping

An enumeration class for mapping types.

This enumeration class defines two types of mappings: Const and Mut. These mappings can be used to determine the type of access (constant or mutable) to the mapped field through their iterators or access operators.

Values:

enumerator Const
enumerator Mut
enum class TypeDescriptor : std::uint8_t

Unified type identifier that works across C++, MPI, and NetCDF.

This enum provides a single, unified way to describe the muGrid scalar types that can be converted to MPI_Datatype (when WITH_MPI is defined) or nc_type (when NetCDF is available). It eliminates the need for void* type passing in communication routines.

The supported types correspond to the muGrid scalar types:

  • Int: signed integer (int)

  • Uint: unsigned integer (unsigned int)

  • Real: double precision floating point (double)

  • Complex: complex double (std::complex<double>)

  • Index: signed index type (std::ptrdiff_t)

Values:

enumerator Unknown
enumerator Int
enumerator Uint
enumerator Real
enumerator Complex
enumerator Index
enum class DeviceType : std::int8_t

Device type enumeration following DLPack conventions. Values match DLPack’s DLDeviceType for interoperability.

Values:

enumerator CPU

kDLCPU - CPU device

enumerator CUDA

kDLCUDA - CUDA GPU

enumerator CUDAHost

kDLCUDAHost - CUDA pinned memory

enumerator ROCm

kDLROCm - ROCm/HIP GPU

enumerator ROCmHost

kDLROCMHost - ROCm pinned memory

Functions

std::ostream &operator<<(std::ostream &os, const muGrid::FieldCollection::ValidityDomain &value)

Allows inserting muGrid::FieldCollection::ValidityDomain into std::ostreams

template<typename T, size_t Dim>
Eigen::Map<Eigen::Matrix<T, Dim, 1>> eigen(std::array<T, Dim> &coord)

return a Eigen representation of the data stored in a std::array (e.g., for doing vector operations on a coordinate)

template<typename T, size_t Dim>
Eigen::Map<const Eigen::Matrix<T, Dim, 1>> eigen(const std::array<T, Dim> &coord)

return a constant Eigen representation of the data stored in a std::array (e.g., for doing vector operations on a coordinate)

template<typename T, size_t MaxDim>
Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1>> eigen(DynCoord<MaxDim, T> &coord)

return a Eigen representation of the data stored in a DynCoord (e.g., for doing vector operations on a coordinate)

template<typename T, size_t MaxDim>
Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> eigen(const DynCoord<MaxDim, T> &coord)

return a const Eigen representation of the data stored in a DynCoord (e.g., for doing vector operations on a coordinate)

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &values)

Allows inserting std::vector into std::ostreams

template<typename T, size_t dim>
std::ostream &operator<<(std::ostream &os, const std::array<T, dim> &values)

Allows inserting muGrid::GridIndex and muGrid::GridPoint into std::ostreams

template<size_t MaxDim, typename T>
std::ostream &operator<<(std::ostream &os, const DynCoord<MaxDim, T> &values)

Allows inserting muGrid::DynCoord into std::ostreams

template<size_t dim>
GridPoint<dim> operator/(const GridPoint<dim> &a, const GridPoint<dim> &b)

element-wise division

template<size_t dim>
GridPoint<dim> operator/(const GridPoint<dim> &a, const GridIndex<dim> &b)

element-wise division

std::ostream &operator<<(std::ostream &os, const IterUnit &sub_division)

inserts muGrid::IterUnit into std::ostreams

std::ostream &operator<<(std::ostream &os, const StorageOrder &storage_order)

inserts muGrid::StorageOrder into std::ostreams

TypeDescriptor typeid_to_descriptor(const std::type_info &type_id)

Get the TypeDescriptor from std::type_info (runtime).

This function provides runtime type mapping when the type is not known at compile time (e.g., through polymorphic Field pointers).

Parameters:

type_id – The type_info from typeid()

Throws:

RuntimeError – if the type is not recognized

Returns:

The corresponding TypeDescriptor

const char *type_descriptor_name(TypeDescriptor td)

Get human-readable name for a TypeDescriptor.

Parameters:

td – The type descriptor

Returns:

A C string with the type name

constexpr std::size_t type_descriptor_size(TypeDescriptor td)

Get the size in bytes for a TypeDescriptor.

Parameters:

td – The type descriptor

Returns:

Size in bytes, or 0 for Unknown

constexpr bool is_signed(TypeDescriptor td)

Check if a TypeDescriptor represents a signed type.

Parameters:

td – The type descriptor

Returns:

true if signed, false otherwise

constexpr bool is_integer(TypeDescriptor td)

Check if a TypeDescriptor represents an integer type.

Parameters:

td – The type descriptor

Returns:

true if integer, false otherwise

constexpr bool is_floating_point(TypeDescriptor td)

Check if a TypeDescriptor represents a floating point type.

Parameters:

td – The type descriptor

Returns:

true if floating point, false otherwise

constexpr bool is_complex(TypeDescriptor td)

Check if a TypeDescriptor represents a complex type.

Parameters:

td – The type descriptor

Returns:

true if complex, false otherwise

template<typename T>
constexpr TypeDescriptor type_to_descriptor()

Get the TypeDescriptor for a C++ type (compile-time).

Only muGrid scalar types are supported: Int (int), Uint (unsigned int), Real (double), Complex (std::complex<double>), Index_t (std::ptrdiff_t).

Template Parameters:

T – The C++ type

Returns:

The corresponding TypeDescriptor

constexpr Int compute_gcd_worker(const Uint &a, const Uint &b)

computes the greatest common divisor of two integer values using the Binary GCD algorithm. Can hopefully soon be replaced by C++17’s std::gcd.

Int compute_gcd(const Int &a_signed, const Int &b_signed)

computes the greatest common divisor of two integer values using the Binary GCD algorithm. Can hopefully soon be replaced by C++17’s std::gcd.

std::string superscript(const int &val)
std::ostream &operator<<(std::ostream &os, const UnitExponent &unit)
std::ostream &operator<<(std::ostream &os, const Unit &unit)
std::unique_ptr<FFT1DBackend> get_host_fft_backend()

Get the appropriate FFT backend for host memory. Returns PocketFFT (always available).

std::unique_ptr<FFT1DBackend> get_device_fft_backend()

Get the appropriate FFT backend for device memory. Returns cuFFT, rocFFT, or nullptr if no GPU backend available.

template<typename MemorySpace>
std::unique_ptr<FFT1DBackend> create_fft_backend()

Create the appropriate FFT backend for a memory space.

template<typename MemorySpace>
constexpr const char *fft_backend_name()

Get the backend name for a memory space.

template<typename MemorySpace>
constexpr Device memory_space_to_device()

Convert MemorySpace to Device.

Compile-time conversion from memory space tag to Device.

Template Parameters:

MemorySpace – The memory space tag type

Returns:

Device corresponding to the memory space

std::vector<Int> fft_freqind(Index_t n)

Compute the frequency bin indices for a full c2c FFT.

For n samples, returns indices [0, 1, …, n/2-1, -n/2, …, -1] for even n, or [0, 1, …, (n-1)/2, -(n-1)/2, …, -1] for odd n.

This is equivalent to numpy.fft.fftfreq(n) * n.

Parameters:

n – Number of points in the transform

Returns:

Vector of integer frequency indices

std::vector<Real> fft_freq(Index_t n, Real d)

Compute the frequency values for a full c2c FFT.

Returns frequencies in cycles per unit spacing: f = k / (n * d) where k is the frequency index from fft_freqind.

This is equivalent to numpy.fft.fftfreq(n, d).

Parameters:
  • n – Number of points in the transform

  • d – Sample spacing (default 1.0)

Returns:

Vector of frequency values

std::vector<Int> rfft_freqind(Index_t n)

Compute the frequency bin indices for a r2c (half-complex) FFT.

For n real input samples, the r2c transform produces n/2+1 complex outputs. Returns indices [0, 1, …, n/2].

This is equivalent to numpy.fft.rfftfreq(n) * n.

Parameters:

n – Number of real input points

Returns:

Vector of integer frequency indices (length n/2+1)

std::vector<Real> rfft_freq(Index_t n, Real d)

Compute the frequency values for a r2c (half-complex) FFT.

Returns frequencies in cycles per unit spacing: f = k / (n * d) where k is the frequency index from rfft_freqind.

This is equivalent to numpy.fft.rfftfreq(n, d).

Parameters:
  • n – Number of real input points

  • d – Sample spacing (default 1.0)

Returns:

Vector of frequency values (length n/2+1)

DynGridIndex get_hermitian_grid_pts(const DynGridIndex &nb_grid_pts, Index_t r2c_axis)

Compute the Fourier grid dimensions for a half-complex r2c transform.

For a real-space grid of size [Nx, Ny, Nz], the half-complex Fourier grid has size [Nx/2+1, Ny, Nz] (for the first axis being the r2c axis).

Parameters:
  • nb_grid_pts – Real-space grid dimensions

  • r2c_axis – Axis along which r2c transform is performed (default 0)

Returns:

Fourier-space grid dimensions

Real fft_normalization(const DynGridIndex &nb_grid_pts)

Compute the normalization factor for FFT roundtrip.

For an unnormalized FFT, ifft(fft(x)) = N * x where N is the total number of grid points. This returns 1/N for normalizing the result.

Parameters:

nb_grid_pts – Grid dimensions

Returns:

Normalization factor (1.0 / total_grid_points)

void distribute_dimension(Index_t global_size, int comm_size, int rank, Index_t &local_size, Index_t &offset)

Evenly distribute a global dimension across ranks.

Returns the local size and offset for a given rank.

Parameters:
  • global_size – Total size of the dimension

  • comm_size – Number of MPI ranks

  • rank – This rank’s index (0-based)

  • local_size – Output: number of elements on this rank

  • offset – Output: starting index of this rank’s portion

void select_process_grid(int num_ranks, const DynGridIndex &nb_grid_pts, int &p1, int &p2)

Select an optimal 2D process grid for P ranks.

For P total ranks, finds P1 x P2 = P that minimizes communication. Prefers P1 <= P2 and tries to make the grid as square as possible while respecting the grid dimensions.

Parameters:
  • num_ranks – Total number of MPI ranks

  • nb_grid_pts – Grid dimensions (used to prefer certain factorizations)

  • p1 – Output: first dimension of process grid

  • p2 – Output: second dimension of process grid

inline Int fft_freqind(Index_t i, Index_t n)

Compute the frequency bin index for a single position in a full c2c FFT.

Maps position i (0 <= i < n) to frequency index:

  • For i < (n+1)/2: returns i

  • For i >= (n+1)/2: returns i - n

Parameters:
  • i – Position in the FFT output (0 <= i < n)

  • n – Number of points in the transform

Returns:

Frequency index for position i

template<typename T>
void runtime_memcpy(T *dst, const T *src, std::size_t count, bool dst_on_device, bool src_on_device)

Copy memory between buffers with runtime memory location detection.

This function handles all combinations of host/device memory copies:

  • Host to Host: uses std::memcpy

  • Device to Device: uses cudaMemcpy/hipMemcpy with DeviceToDevice

  • Host to Device: uses cudaMemcpy/hipMemcpy with HostToDevice

  • Device to Host: uses cudaMemcpy/hipMemcpy with DeviceToHost

Template Parameters:

T – Element type

Parameters:
  • dst – Destination pointer

  • src – Source pointer

  • count – Number of elements to copy

  • dst_on_device – True if destination is on GPU device

  • src_on_device – True if source is on GPU device

template<typename T, typename DstSpace, typename SrcSpace>
void deep_copy(TypedFieldBase<T, DstSpace> &dst, const TypedFieldBase<T, SrcSpace> &src)

Free function for deep copying between fields in different memory spaces.

This function handles layout conversion between AoS (Array of Structures, used by host/CPU) and SoA (Structure of Arrays, used by device/GPU).

For same-space copies (host-host or device-device), a fast byte copy is used. For cross-space copies (host-device or device-host), layout conversion is performed so that the logical field values are preserved.

template<int size>
constexpr nc_type netcdf_signed_type()
template<>
constexpr nc_type netcdf_signed_type<1>()
template<>
constexpr nc_type netcdf_signed_type<2>()
template<>
constexpr nc_type netcdf_signed_type<4>()
template<>
constexpr nc_type netcdf_signed_type<8>()
template<int size>
constexpr nc_type netcdf_unsigned_type()
template<>
constexpr nc_type netcdf_unsigned_type<1>()
template<>
constexpr nc_type netcdf_unsigned_type<2>()
template<>
constexpr nc_type netcdf_unsigned_type<4>()
template<>
constexpr nc_type netcdf_unsigned_type<8>()
template<typename T>
constexpr nc_type netcdf_type()
template<>
constexpr nc_type netcdf_type<char>()
template<>
constexpr nc_type netcdf_type<float>()
template<>
constexpr nc_type netcdf_type<double>()
template<typename T, typename MemorySpace>
void resize(Array<T, MemorySpace> &arr, std::size_t new_size)

Resize a Array (free function for compatibility)

template<typename T, typename DstSpace, typename SrcSpace>
void deep_copy(Array<T, DstSpace> &dst, const Array<T, SrcSpace> &src)

Deep copy between arrays, potentially in different memory spaces.

template<typename T, typename MemorySpace>
void deep_copy(Array<T, MemorySpace> &dst, const T &value)

Fill array with a scalar value.

template<typename T, typename DstSpace, typename SrcSpace>
void deep_copy(T *dst, const T *src, std::size_t count)

Deep copy between raw pointers in different memory spaces.

This overload allows copying between raw pointers when the memory spaces are known at compile time. Useful for FFT work buffers.

Template Parameters:
  • T – Element type

  • DstSpace – Destination memory space

  • SrcSpace – Source memory space

Parameters:
  • dst – Destination pointer

  • src – Source pointer

  • count – Number of elements to copy

template<typename T, typename MemorySpace>
void deep_copy(T *dst, const T *src, std::size_t count)

Deep copy within the same memory space (raw pointers).

Convenience overload when source and destination are in the same space.

template<>
constexpr Device memory_space_to_device<HostSpace>()
template<typename MemorySpace>
constexpr const char *device_name()

Get device name string for a memory space.

template GridTraversalParams GenericLinearOperator::compute_traversal_params< StorageOrder::ArrayOfStructures > (const GlobalFieldCollection &, Index_t, Index_t) const
template GridTraversalParams GenericLinearOperator::compute_traversal_params< StorageOrder::StructureOfArrays > (const GlobalFieldCollection &, Index_t, Index_t) const
template SparseOperatorSoA< HostSpace > GenericLinearOperator::create_apply_operator< StorageOrder::ArrayOfStructures > (const DynGridIndex &, Index_t) const
template SparseOperatorSoA< HostSpace > GenericLinearOperator::create_apply_operator< StorageOrder::StructureOfArrays > (const DynGridIndex &, Index_t) const
template SparseOperatorSoA< HostSpace > GenericLinearOperator::create_transpose_operator< StorageOrder::ArrayOfStructures > (const DynGridIndex &, Index_t) const
template SparseOperatorSoA< HostSpace > GenericLinearOperator::create_transpose_operator< StorageOrder::StructureOfArrays > (const DynGridIndex &, Index_t) const
inline Shape_t pad_shape_to_3d(const Shape_t &shape, Index_t fill_value = 1)

Pad a shape vector to 3D by appending fill_value.

Parameters:
  • shape – Input shape (can be 1D, 2D, or 3D)

  • fill_value – Value to use for padding (default: 1)

Returns:

3D shape vector

template<size_t MaxDim, typename T>
inline Shape_t pad_shape_to_3d(const DynCoord<MaxDim, T> &coord, Index_t fill_value = 1)

Pad a DynCoord to 3D Shape_t by appending fill_value.

Parameters:
  • coord – Input coordinate (can be 1D, 2D, or 3D)

  • fill_value – Value to use for padding (default: 1)

Returns:

3D shape vector

template<typename DstSpace, typename SrcSpace>
SparseOperatorSoA<DstSpace> deep_copy_sparse_operator(const SparseOperatorSoA<SrcSpace> &src)

Deep copy sparse operator between memory spaces.

inline void device_synchronize()

Synchronize device (no-op for CPU)

template<typename R, typename I>
constexpr R ipow(R base, I exponent)

compile-time potentiation required for field-size computations

static constexpr Dim_t ct_sqrt(Dim_t res, Dim_t l, Dim_t r)

compile-time square root (helper)

static constexpr Dim_t ct_sqrt(Dim_t res)

compile-time square root

template<typename T>
Index_t get_nb_from_shape(const T &shape)

helper to get the number of elements from a shape

template<typename T>
T normalize_coord(Int coord, Int length)
template<>
inline Int normalize_coord<Int>(Int coord, Int length)
template<typename T, bool with_ghosts, class C>
auto py_coords(const C &field_like)
template<typename T>
py::tuple to_tuple(const T &container)

Convert any iterable container with get_dim() to a Python tuple.

Used to convert DynGridIndex, DynCoord, etc. to Python tuples for a more natural Python API (allows unpacking, hashing, etc.).

template<typename T>
T normalize_fftfreq(Int freq_index, Int nb_domain_grid_pts)

Helper to compute normalized FFT frequency from integer index. For Real: returns freq / nb_domain_grid_pts (fractional frequency) For Int: returns the raw frequency index

template<>
inline Int normalize_fftfreq<Int>(Int freq_index, Int)
template<typename T, class Engine>
auto py_fftfreq(const Engine &eng)

Generate FFT frequency array for a distributed FFT engine.

Returns an array of shape [dim, local_fx, local_fy, …] containing the FFT frequencies for each pixel in the local Fourier subdomain.

For T=Real: frequencies are normalized (in range [-0.5, 0.5)) For T=Int: frequencies are integer indices (in range [-N/2, N/2-1])

Template Parameters:
  • T – Output type (Real or Int)

  • Engine – FFT engine type

Parameters:

eng – The FFT engine

Returns:

numpy array of FFT frequencies

template<typename T4>
inline auto get(const Eigen::MatrixBase<T4> &t4, Dim_t i, Dim_t j, Dim_t k, Dim_t l) -> decltype(auto)

provides index-based access to fourth-order Tensors represented by square matrices

template<typename T4>
inline auto get(Eigen::MatrixBase<T4> &t4, Dim_t i, Dim_t j, Dim_t k, Dim_t l) -> decltype(t4.coeffRef(i, j))

provides constant index-based access to fourth-order Tensors represented by square matrices

Variables

const std::string PixelTag = {"pixel"}

this tag is always defined to one in every field collection

constexpr Dim_t oneD = {1}

Dimension constants.

constant for a one-dimensional problem

constexpr Dim_t twoD = {2}

constant for a two-dimensional problem

constexpr Dim_t threeD = {3}

constant for a three-dimensional problem

constexpr Dim_t fourD = {4}

constant for a four-dimensional problem

constexpr Index_t zerothOrder = {0}

Tensor order constants.

constant for scalars

constexpr Index_t firstOrder = {1}

constant for vectors

constexpr Index_t secondOrder = {2}

constant second-order tensors

constexpr Index_t fourthOrder = {4}

constant fourth-order tensors

constexpr Index_t OneQuadPt = {1}

Quadrature/node constants.

constant for 1 quadrature point/pixel

constexpr Index_t TwoQuadPts = {2}

constant for 2 quadrature point/pixel

constexpr Index_t FourQuadPts{4}

constant for 4 quadrature point/pixel

constexpr Index_t OneNode = {1}

constant for 1 node per pixel

static constexpr Dim_t Unknown = {-1}

constant used to explicitly denote unknown positive integers

static constexpr char REGISTER_ALL_FIELDS[] = "REGISTER_ALL_FIELDS"
static constexpr char REGISTER_ALL_STATE_FIELDS[] = "REGISTER_ALL_STATE_FIELDS"
constexpr nc_type MU_NC_CHAR = netcdf_type<char>()
constexpr nc_type MU_NC_INT = netcdf_type<muGrid::Int>()
constexpr nc_type MU_NC_UINT = netcdf_type<muGrid::Uint>()
constexpr nc_type MU_NC_INDEX_T = netcdf_type<muGrid::Index_t>()
constexpr nc_type MU_NC_REAL = netcdf_type<muGrid::Real>()
static constexpr std::int64_t GFC_LOCAL_PIXELS_DEFAULT_VALUE{-1}
static constexpr int DEFAULT_NETCDFDIM_ID{-1}
static constexpr int DEFAULT_NETCDFVAR_ID{-1}
template<typename MemorySpace>
constexpr bool is_host_space_v = is_host_space<MemorySpace>::value
template<typename MemorySpace>
constexpr bool is_device_space_v = is_device_space<MemorySpace>::value
template<typename MemorySpace>
constexpr int dlpack_device_type_v = dlpack_device_type<MemorySpace>::value
static const Real B_2D[2][2][4] = {{{-1.0, 1.0, 0.0, 0.0}, {-1.0, 0.0, 1.0, 0.0}}, {{0.0, 0.0, -1.0, 1.0}, {0.0, -1.0, 0.0, 1.0}}}
static const Real W_2D[2] = {0.5, 0.5}
static const Real B_3D[5][3][8] = {{{0.0, 0.5, -0.5, 0.0, -0.5, 0.0, 0.0, 0.5}, {0.0, -0.5, 0.5, 0.0, -0.5, 0.0, 0.0, 0.5}, {0.0, -0.5, -0.5, 0.0, 0.5, 0.0, 0.0, 0.5}}, {{-1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, {-1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}}, {{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 1.0}, {0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0, 0.0}, {0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0}}, {{0.0, 0.0, 0.0, 0.0, -1.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 1.0}, {0.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}}, {{0.0, 0.0, -1.0, 1.0, 0.0, 0.0, 0.0, 0.0}, {0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0}}}
static const Real W_3D[5] = {1.0 / 3.0, 1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0}
constexpr Real pi = {3.1415926535897932384626433}

convenience definitions

namespace muGrid
namespace CcoordOps

Functions

Dim_t get_index(const DynGridIndex &nb_grid_pts, const DynGridIndex &locations, const DynGridIndex &ccoord)

get the linear index of a pixel in a column-major grid

Real compute_pixel_volume(const DynGridIndex &nb_grid_pts, const DynCoord<fourD, Real> &lengths)
template<typename T>
T modulo(const T &a, const T &b)

modulo operator that can handle negative values

template<size_t Dim>
constexpr GridIndex<Dim> get_coord(const GridIndex<Dim> &nb_grid_pts, const GridIndex<Dim> &locations, Index_t index)

get the i-th pixel in a grid of size nb_grid_pts

template<size_t Dim, size_t... I>
constexpr GridIndex<Dim> get_coord(const GridIndex<Dim> &nb_grid_pts, const GridIndex<Dim> &locations, Index_t index, std::index_sequence<I...>)

get the i-th pixel in a grid of size nb_grid_pts

template<size_t... I>
constexpr GridIndex<1> get_coord(const GridIndex<1> &nb_grid_pts, const GridIndex<1> &locations, Index_t index, std::index_sequence<I...>)

get the i-th pixel in a grid of size nb_grid_pts - specialization for one dimension

template<size_t dim>
GridIndex<dim> get_coord_from_axes_order(const GridIndex<dim> &nb_grid_pts, const GridIndex<dim> &locations, const GridIndex<dim> &strides, const GridIndex<dim> &axes_order, Index_t index)

get the i-th pixel in a grid of size nb_grid_pts, with axes order

template<size_t dim>
GridIndex<dim> get_coord_from_strides(const GridIndex<dim> &nb_grid_pts, const GridIndex<dim> &locations, const GridIndex<dim> &strides, Index_t index)

get the i-th pixel in a grid of size nb_grid_pts, with strides

template<class T>
T get_coord0_from_axes_order(const T &nb_grid_pts, const T &strides, const T &axes_order, Index_t index)

get the i-th pixel in a grid of size nb_grid_pts, with axes order and location

template<class T>
T get_coord_from_axes_order(const T &nb_grid_pts, const T &locations, const T &strides, const T &axes_order, Index_t index)

get the i-th pixel in a grid of size nb_grid_pts, with axes order

template<class T>
T get_coord_from_strides(const T &nb_grid_pts, const T &locations, const T &strides, Index_t index)

get the i-th pixel in a grid of size nb_grid_pts, with strides

template<size_t Dim>
constexpr Dim_t get_index(const GridIndex<Dim> &nb_grid_pts, const GridIndex<Dim> &locations, const GridIndex<Dim> &ccoord)

get the linear index of a pixel in a column-major grid

template<size_t MaxDim, typename T>
T compute_volume(const DynCoord<MaxDim, T> &lengths)

these functions can be used whenever it is necessary to calculate the volume of a cell or each pixels of the cell

template<typename T>
T compute_volume(const std::vector<T> &lengths)

these functions can be used whenever it is necessary to calculate the volume of a cell or each pixels of the cell

template<size_t Dim>
constexpr Index_t get_index_from_strides(const GridIndex<Dim> &strides, const GridIndex<Dim> &locations, const GridIndex<Dim> &ccoord)

get the linear index of a pixel given a set of strides

template<class T>
Index_t get_index_from_strides(const T &strides, const T &locations, const T &ccoord)

get the linear index of a pixel given a set of strides

size_t get_buffer_size(const DynGridIndex &nb_grid_pts, const DynGridIndex &strides)

get the buffer size required to store a grid given its strides

size_t get_buffer_size(const Shape_t &nb_grid_pts, const Shape_t &strides)

get the buffer size required to store a grid given its strides

template<size_t Dim, typename T>
constexpr std::array<T, Dim> get_cube(T nb_grid_pts)

returns a grid of equal number of grid points in each direction

template<size_t MaxDim = fourD>
DynCoord<MaxDim> get_cube(const Dim_t &dim, const Index_t &nb_grid_pts)

returns a grid of equal number of grid points in each direction

template<size_t Dim>
constexpr GridIndex<Dim> get_col_major_strides(const GridIndex<Dim> &nb_grid_pts)

get all strides from a column-major grid

template<size_t MaxDim>
constexpr DynCoord<MaxDim> get_col_major_strides(const DynCoord<MaxDim> &nb_grid_pts)

get all strides from a column-major grid

template<size_t Dim>
constexpr GridIndex<Dim> get_row_major_strides(const GridIndex<Dim> &nb_grid_pts)

get all strides from a row-major grid

template<size_t MaxDim>
constexpr DynCoord<MaxDim> get_row_major_strides(const DynCoord<MaxDim> &nb_grid_pts)

get all strides from a row-major grid

template<class T>
T compute_axes_order(const T &shape, const T &strides)

compute the order of the axes given strides, fastest first

template<size_t dim>
GridIndex<dim> compute_axes_order(const GridIndex<dim> &shape, const GridIndex<dim> &strides)

compute the order of the axes given strides, fastest first

template<class T>
bool is_buffer_contiguous(const T &nb_grid_pts, const T &strides)

check whether strides represent a contiguous buffer

template<size_t Dim>
constexpr size_t get_size(const GridIndex<Dim> &nb_grid_pts)

get the number of pixels in a grid

template<size_t MaxDim>
size_t get_size(const DynCoord<MaxDim> &nb_grid_pts)

get the number of pixels in a grid

template<size_t dim>
constexpr size_t get_buffer_size(const GridIndex<dim> &nb_grid_pts, const GridIndex<dim> &strides)

get the buffer size required to store a grid given its strides

namespace internal

Functions

template<typename T>
constexpr T ret(T val, size_t)

simple helper returning the first argument and ignoring the second

template<Dim_t Dim, typename T, size_t... I>
constexpr std::array<T, Dim> cube_fun(T val, std::index_sequence<I...>)

helper to build cubes

template<Dim_t Dim>
constexpr Index_t col_major_stride(const GridIndex<Dim> &nb_grid_pts, const size_t index)

compute the stride in a direction of a column-major grid

template<Dim_t Dim>
constexpr Index_t row_major_stride(const GridIndex<Dim> &nb_grid_pts, const size_t index)

compute the stride in a direction of a row-major grid

template<Dim_t Dim, size_t... I>
constexpr GridIndex<Dim> compute_col_major_strides(const GridIndex<Dim> &nb_grid_pts, std::index_sequence<I...>)

get all strides from a column-major grid (helper function)

template<Dim_t Dim, size_t... I>
constexpr GridIndex<Dim> compute_row_major_strides(const GridIndex<Dim> &nb_grid_pts, std::index_sequence<I...>)

get all strides from a row-major grid (helper function)

namespace cpu

Functions

inline void apply_convolution_kernel (const Real *MUGRID_RESTRICT nodal_data, Real *MUGRID_RESTRICT quad_data, const Real alpha, const GridTraversalParams &params, const Index_t *MUGRID_RESTRICT quad_indices, const Index_t *MUGRID_RESTRICT nodal_indices, const Real *MUGRID_RESTRICT op_values, const Index_t nnz)

Forward convolution kernel for CPU.

Applies: quad_data += alpha * Op * nodal_data

Loop structure is optimized for SIMD vectorization:

  • Stencil entries are in the outermost loop (constant per x-sweep)

  • X-dimension is innermost for contiguous memory access

  • Compiler can vectorize the x-loop when strides are 1

inline void transpose_convolution_kernel (const Real *MUGRID_RESTRICT quad_data, Real *MUGRID_RESTRICT nodal_data, const Real alpha, const GridTraversalParams &params, const Index_t *MUGRID_RESTRICT quad_indices, const Index_t *MUGRID_RESTRICT nodal_indices, const Real *MUGRID_RESTRICT op_values, const Index_t nnz)

Transpose convolution kernel for CPU.

Applies: nodal_data += alpha * Op^T * quad_data

Note: This kernel accumulates to nodal_data, which may have overlapping writes if stencils overlap. For CPU, no atomics are needed since we process sequentially.

Loop structure is optimized for SIMD vectorization (same as apply).

namespace detail

Typedefs

template<typename T, typename MemorySpace>
using Allocator = typename AllocatorSelector<T, MemorySpace>::type
namespace DLPackDeviceType

DLPack device type constants (from dlpack/dlpack.h)

Variables

constexpr int CPU = 1
constexpr int CUDA = 2
constexpr int CUDAHost = 3
constexpr int ROCm = 10
constexpr int ROCmHost = 11
namespace EigenCheck
namespace internal

Functions

template<Dim_t Dim, Dim_t NbRow, Dim_t NbCol>
inline constexpr Dim_t get_rank()

determine the rank of a Dim-dimensional tensor represented by an Eigen::Matrix of shape NbRow × NbCol

Template Parameters:
  • Dim – spatial dimension

  • NbRow – number of rows

  • NbCol – number of columns

namespace fem_gradient_kernels

Functions

void fem_gradient_2d_host (const Real *MUGRID_RESTRICT nodal_input, Real *MUGRID_RESTRICT gradient_output, Index_t nx, Index_t ny, Index_t nodal_stride_x, Index_t nodal_stride_y, Index_t nodal_stride_n, Index_t grad_stride_x, Index_t grad_stride_y, Index_t grad_stride_q, Index_t grad_stride_d, Real hx, Real hy, Real alpha, bool increment)

Apply 2D FEM gradient operator on host.

void fem_divergence_2d_host (const Real *MUGRID_RESTRICT gradient_input, Real *MUGRID_RESTRICT nodal_output, Index_t nx, Index_t ny, Index_t grad_stride_x, Index_t grad_stride_y, Index_t grad_stride_q, Index_t grad_stride_d, Index_t nodal_stride_x, Index_t nodal_stride_y, Index_t nodal_stride_n, Real hx, Real hy, const Real *quad_weights, Real alpha, bool increment)

Apply 2D FEM transpose (divergence) operator on host.

void fem_gradient_3d_host (const Real *MUGRID_RESTRICT nodal_input, Real *MUGRID_RESTRICT gradient_output, Index_t nx, Index_t ny, Index_t nz, Index_t nodal_stride_x, Index_t nodal_stride_y, Index_t nodal_stride_z, Index_t nodal_stride_n, Index_t grad_stride_x, Index_t grad_stride_y, Index_t grad_stride_z, Index_t grad_stride_q, Index_t grad_stride_d, Real hx, Real hy, Real hz, Real alpha, bool increment)
void fem_divergence_3d_host (const Real *MUGRID_RESTRICT gradient_input, Real *MUGRID_RESTRICT nodal_output, Index_t nx, Index_t ny, Index_t nz, Index_t grad_stride_x, Index_t grad_stride_y, Index_t grad_stride_z, Index_t grad_stride_q, Index_t grad_stride_d, Index_t nodal_stride_x, Index_t nodal_stride_y, Index_t nodal_stride_z, Index_t nodal_stride_n, Real hx, Real hy, Real hz, const Real *quad_weights, Real alpha, bool increment)
inline __device__ double atomicAddDouble (double *address, double val)
__global__ void fem_gradient_2d_kernel (const Real *MUGRID_RESTRICT nodal_input, Real *MUGRID_RESTRICT gradient_output, Index_t nx, Index_t ny, Index_t nodal_stride_x, Index_t nodal_stride_y, Index_t nodal_stride_n, Index_t grad_stride_x, Index_t grad_stride_y, Index_t grad_stride_q, Index_t grad_stride_d, Real inv_hx, Real inv_hy, bool increment)

GPU kernel for 2D FEM gradient operator.

Computes gradient at 2 quadrature points per pixel from 4 nodal values. Each thread processes one pixel.

__global__ void fem_divergence_2d_kernel (const Real *MUGRID_RESTRICT gradient_input, Real *MUGRID_RESTRICT nodal_output, Index_t nx, Index_t ny, Index_t grad_stride_x, Index_t grad_stride_y, Index_t grad_stride_q, Index_t grad_stride_d, Index_t nodal_stride_x, Index_t nodal_stride_y, Index_t nodal_stride_n, Real w0_inv_hx, Real w0_inv_hy, Real w1_inv_hx, Real w1_inv_hy, bool increment)

GPU kernel for 2D FEM divergence (transpose) operator.

Uses gather pattern: each thread handles one NODE and gathers contributions from adjacent pixels. This eliminates the need for atomic operations.

For node at (ix, iy), gather from:

  • Pixel (ix, iy): this node is corner 0 (lower-left)

  • Pixel (ix-1, iy): this node is corner 1 (lower-right)

  • Pixel (ix, iy-1): this node is corner 2 (upper-left)

  • Pixel (ix-1, iy-1): this node is corner 3 (upper-right)

__global__ void fem_gradient_3d_kernel (const Real *MUGRID_RESTRICT nodal_input, Real *MUGRID_RESTRICT gradient_output, Index_t nx, Index_t ny, Index_t nz, Index_t nodal_stride_x, Index_t nodal_stride_y, Index_t nodal_stride_z, Index_t nodal_stride_n, Index_t grad_stride_x, Index_t grad_stride_y, Index_t grad_stride_z, Index_t grad_stride_q, Index_t grad_stride_d, Real inv_hx, Real inv_hy, Real inv_hz, bool increment)

GPU kernel for 3D FEM gradient operator with shared memory optimization.

Computes gradient at 5 quadrature points per voxel from 8 nodal values. Uses shared memory to reduce redundant global memory loads - adjacent voxels share nodes, so we cooperatively load a tile of nodes.

Hand-unrolled gradient computation exploits B matrix sparsity:

  • Each gradient component has only 2 non-zero terms per quadrature point

  • Avoids loop overhead and constant memory access latency

__global__ void fem_divergence_3d_kernel (const Real *MUGRID_RESTRICT gradient_input, Real *MUGRID_RESTRICT nodal_output, Index_t nx, Index_t ny, Index_t nz, Index_t grad_stride_x, Index_t grad_stride_y, Index_t grad_stride_z, Index_t grad_stride_q, Index_t grad_stride_d, Index_t nodal_stride_x, Index_t nodal_stride_y, Index_t nodal_stride_z, Index_t nodal_stride_n, Real inv_hx, Real inv_hy, Real inv_hz, const Real *MUGRID_RESTRICT quad_weights, bool increment)

GPU kernel for 3D FEM divergence (transpose) operator - GATHER version.

Uses gather pattern - NO ATOMICS, NO SHARED MEMORY:

  • Each thread handles one NODE

  • Gathers contributions from up to 8 neighboring voxels

  • Single write per node

This kernel relies on L2 cache for data reuse between adjacent threads. Adjacent threads in x access adjacent voxels, which have adjacent memory addresses (x stride = 1).

dim3 block(BLOCK_SIZE_2D, BLOCK_SIZE_2D)
dim3 grid ((interior_nx+block.x - 1)/block.x,(interior_ny+block.y - 1)/block.y)
GPU_LAUNCH_KERNEL(fem_gradient_2d_kernel, grid, block, nodal_input, gradient_output, nx, ny, nodal_stride_x, nodal_stride_y, nodal_stride_n, grad_stride_x, grad_stride_y, grad_stride_q, grad_stride_d, inv_hx, inv_hy, increment)
GPU_DEVICE_SYNCHRONIZE()
dim3 grid ((nx+block.x - 1)/block.x,(ny+block.y - 1)/block.y)
GPU_LAUNCH_KERNEL(fem_divergence_2d_kernel, grid, block, gradient_input, nodal_output, nx, ny, grad_stride_x, grad_stride_y, grad_stride_q, grad_stride_d, nodal_stride_x, nodal_stride_y, nodal_stride_n, w0_inv_hx, w0_inv_hy, w1_inv_hx, w1_inv_hy, increment)
dim3 block(BLOCK_SIZE_3D, BLOCK_SIZE_3D, BLOCK_SIZE_3D)
dim3 grid ((interior_nx+block.x - 1)/block.x,(interior_ny+block.y - 1)/block.y,(interior_nz+block.z - 1)/block.z)
GPU_LAUNCH_KERNEL(fem_gradient_3d_kernel, grid, block, nodal_input, gradient_output, nx, ny, nz, nodal_stride_x, nodal_stride_y, nodal_stride_z, nodal_stride_n, grad_stride_x, grad_stride_y, grad_stride_z, grad_stride_q, grad_stride_d, inv_hx, inv_hy, inv_hz, increment)
dim3 grid ((nx+block.x - 1)/block.x,(ny+block.y - 1)/block.y,(nz+block.z - 1)/block.z)
GPU_LAUNCH_KERNEL(fem_divergence_3d_kernel, grid, block, gradient_input, nodal_output, nx, ny, nz, grad_stride_x, grad_stride_y, grad_stride_z, grad_stride_q, grad_stride_d, nodal_stride_x, nodal_stride_y, nodal_stride_z, nodal_stride_n, inv_hx, inv_hy, inv_hz, quad_weights, increment)

Variables

constexpr Index_t NB_NODES_2D = 4
constexpr Index_t NB_QUAD_2D = 2
constexpr Index_t DIM_2D = 2
constexpr Real B_2D_REF[DIM_2D][NB_QUAD_2D][NB_NODES_2D] = {{{-1.0, 1.0, 0.0, 0.0}, {0.0, 0.0, -1.0, 1.0}}, {{-1.0, 0.0, 1.0, 0.0}, {0.0, -1.0, 0.0, 1.0}}}
constexpr Index_t NODE_OFFSET_2D[NB_NODES_2D][DIM_2D] = {{0, 0}, {1, 0}, {0, 1}, {1, 1}}
constexpr Real QUAD_WEIGHT_2D[NB_QUAD_2D] = {0.5, 0.5}
const Real B_3D_REF[DIM_3D][NB_QUAD_3D][NB_NODES_3D]
constexpr Index_t NB_NODES_3D = 8
constexpr Index_t NB_QUAD_3D = 5
constexpr Index_t DIM_3D = 3
constexpr Index_t NODE_OFFSET_3D[NB_NODES_3D][DIM_3D] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}, {0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1}}
constexpr Index_t TET_NODES[NB_QUAD_3D][4] = {{1, 2, 4, 7}, {0, 1, 2, 4}, {1, 2, 3, 7}, {1, 4, 5, 7}, {2, 4, 6, 7}}
constexpr Real QUAD_WEIGHT_3D[NB_QUAD_3D] = {1.0 / 3.0, 1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0}
constexpr int BLOCK_SIZE_2D = 16
constexpr int BLOCK_SIZE_3D = 8
__constant__ Real d_B_3D_REF [DIM_3D][NB_QUAD_3D][NB_NODES_3D] = {{{ 0.0,  0.5, -0.5,  0.0, -0.5,  0.0,  0.0,  0.5},{-1.0,  1.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0},{ 0.0,  0.0, -1.0,  1.0,  0.0,  0.0,  0.0,  0.0},{ 0.0,  0.0,  0.0,  0.0, -1.0,  1.0,  0.0,  0.0},{ 0.0,  0.0,  0.0,  0.0,  0.0,  0.0, -1.0,  1.0}},{{ 0.0, -0.5,  0.5,  0.0, -0.5,  0.0,  0.0,  0.5},{-1.0,  0.0,  1.0,  0.0,  0.0,  0.0,  0.0,  0.0},{ 0.0, -1.0,  0.0,  1.0,  0.0,  0.0,  0.0,  0.0},{ 0.0,  0.0,  0.0,  0.0,  0.0, -1.0,  0.0,  1.0},{ 0.0,  0.0,  0.0,  0.0, -1.0,  0.0,  1.0,  0.0}},{{ 0.0, -0.5, -0.5,  0.0,  0.5,  0.0,  0.0,  0.5},{-1.0,  0.0,  0.0,  0.0,  1.0,  0.0,  0.0,  0.0},{ 0.0,  0.0,  0.0, -1.0,  0.0,  0.0,  0.0,  1.0},{ 0.0, -1.0,  0.0,  0.0,  0.0,  1.0,  0.0,  0.0},{ 0.0,  0.0, -1.0,  0.0,  0.0,  0.0,  1.0,  0.0}}}
__constant__ Index_t d_NODE_OFFSET_3D [NB_NODES_3D][DIM_3D] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0},{0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1}}
const Real *nodal_input
const Real Real * gradient_output
const Real Real Index_t nx
const Real Real Index_t Index_t ny
const Real Real Index_t Index_t Index_t nodal_stride_x
const Real Real Index_t Index_t Index_t Index_t nodal_stride_y
const Real Real Index_t Index_t Index_t Index_t Index_t nodal_stride_n
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t grad_stride_x
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t grad_stride_y
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t grad_stride_q
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t grad_stride_d
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Real hx
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Real Real hy
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Real Real Real alpha
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Real Real Real bool increment   = {           Real inv_hx = alpha / hx
Real inv_hy = alpha / hy
Index_t interior_nx = nx - 1
Index_t interior_ny = ny - 1
const Real *gradient_input
const Real Real * nodal_output
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Real Real const Real * quad_weights
Real w0_inv_hy = alpha * quad_weights[0] / hy
Real w1_inv_hx = alpha * quad_weights[1] / hx
Real w1_inv_hy = alpha * quad_weights[1] / hy
const Real Real Index_t Index_t Index_t nz
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t nodal_stride_z
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t grad_stride_z
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Index_t Real Real Real hz
Real inv_hz = alpha / hz
Index_t interior_nz = nz - 1
namespace internal

Typedefs

template<typename T, Dim_t NbRow, Dim_t NbCol>
using MatrixMap = EigenMap<T, Eigen::Matrix<T, NbRow, NbCol>>

internal convenience alias for creating maps iterating over statically sized Eigen::Matrixs

template<typename T, Dim_t Rank, Dim_t Dim>
using TensorMap = EigenMap<T, Eigen::Matrix<T, TensorRows(Rank, Dim), TensorCols(Rank, Dim)>>

internal convenience alias for creating maps iterating over statically sized tensors

template<typename T, Dim_t NbRow, Dim_t NbCol>
using ArrayMap = EigenMap<T, Eigen::Array<T, NbRow, NbCol>>

internal convenience alias for creating maps iterating over statically sized Eigen::Arrays

Functions

constexpr Dim_t TensorRows(Dim_t rank, Dim_t dim)

returns number of rows a dim-dimensional tensor of rank rank has in matrix representation

constexpr Dim_t TensorCols(Dim_t rank, Dim_t dim)

returns number of columns a dim-dimensional tensor of rank rank has in matrix representation

namespace isotropic_stiffness_kernels

Functions

void isotropic_stiffness_2d_host (const Real *MUGRID_RESTRICT displacement, const Real *MUGRID_RESTRICT lambda, const Real *MUGRID_RESTRICT mu, Real *MUGRID_RESTRICT force, Index_t nnx, Index_t nny, Index_t nelx, Index_t nely, Index_t disp_stride_x, Index_t disp_stride_y, Index_t disp_stride_d, Index_t mat_stride_x, Index_t mat_stride_y, Index_t force_stride_x, Index_t force_stride_y, Index_t force_stride_d, const Real *G, const Real *V, Real alpha, bool increment)

2D host kernel for isotropic stiffness operator.

Uses gather pattern: iterates over interior nodes, gathers from neighboring elements via ghost cells. Ghost communication handles periodicity and MPI boundaries.

Parameters:
  • nnx, nny – Number of interior nodes

  • nelx, nely – Number of elements

void isotropic_stiffness_3d_host (const Real *MUGRID_RESTRICT displacement, const Real *MUGRID_RESTRICT lambda, const Real *MUGRID_RESTRICT mu, Real *MUGRID_RESTRICT force, Index_t nnx, Index_t nny, Index_t nnz, Index_t nelx, Index_t nely, Index_t nelz, Index_t disp_stride_x, Index_t disp_stride_y, Index_t disp_stride_z, Index_t disp_stride_d, Index_t mat_stride_x, Index_t mat_stride_y, Index_t mat_stride_z, Index_t force_stride_x, Index_t force_stride_y, Index_t force_stride_z, Index_t force_stride_d, const Real *G, const Real *V, Real alpha, bool increment)

3D host kernel for isotropic stiffness operator.

Uses gather pattern: iterates over interior nodes, gathers from neighboring elements via ghost cells. Ghost communication handles periodicity and MPI boundaries.

Parameters:
  • nnx, nny, nnz – Number of interior nodes

  • nelx, nely, nelz – Number of elements

Variables

static const Index_t NODE_OFFSET_2D[4][2] = {{0, 0}, {1, 0}, {0, 1}, {1, 1}}
static const Index_t NODE_OFFSET_3D[8][3] = {{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {1, 1, 0}, {0, 0, 1}, {1, 0, 1}, {0, 1, 1}, {1, 1, 1}}
namespace laplace_kernels

Functions

void laplace_2d_host (const Real *MUGRID_RESTRICT input, Real *MUGRID_RESTRICT output, Index_t nx, Index_t ny, Index_t stride_x, Index_t stride_y, Real scale, bool increment=false)

Apply 5-point 2D Laplace stencil on host.

Stencil: scale * [0, 1, 0] [1,-4, 1] [0, 1, 0]

Parameters:
  • input – Input array

  • output – Output array

  • nx – Grid size in x (including ghosts)

  • ny – Grid size in y (including ghosts)

  • stride_x – Stride in x direction

  • stride_y – Stride in y direction

  • scale – Scale factor

  • increment – If true, add to output; if false, overwrite

void laplace_3d_host (const Real *MUGRID_RESTRICT input, Real *MUGRID_RESTRICT output, Index_t nx, Index_t ny, Index_t nz, Index_t stride_x, Index_t stride_y, Index_t stride_z, Real scale, bool increment=false)

Apply 7-point 3D Laplace stencil on host.

Stencil: scale * (center = -6, each of 6 neighbors = +1)

Parameters:
  • input – Input array

  • output – Output array

  • nx – Grid size in x (including ghosts)

  • ny – Grid size in y (including ghosts)

  • nz – Grid size in z (including ghosts)

  • stride_x – Stride in x direction

  • stride_y – Stride in y direction

  • stride_z – Stride in z direction

  • scale – Scale factor

  • increment – If true, add to output; if false, overwrite

__global__ void laplace_2d_kernel (const Real *MUGRID_RESTRICT input, Real *MUGRID_RESTRICT output, Index_t nx, Index_t ny, Index_t stride_x, Index_t stride_y, Real scale, bool increment)

GPU kernel for 2D Laplace operator with 5-point stencil. Works with both CUDA and HIP - the global keyword is the same.

__global__ void laplace_3d_kernel (const Real *MUGRID_RESTRICT input, Real *MUGRID_RESTRICT output, Index_t nx, Index_t ny, Index_t nz, Index_t stride_x, Index_t stride_y, Index_t stride_z, Real scale, bool increment)

GPU kernel for 3D Laplace operator with 7-point stencil. Works with both CUDA and HIP.

dim3 block(BLOCK_SIZE_2D, BLOCK_SIZE_2D)
dim3 grid ((interior_nx+block.x - 1)/block.x,(interior_ny+block.y - 1)/block.y)
GPU_LAUNCH_KERNEL(laplace_2d_kernel, grid, block, input, output, nx, ny, stride_x, stride_y, scale, increment)
GPU_DEVICE_SYNCHRONIZE()
dim3 block(BLOCK_SIZE_3D, BLOCK_SIZE_3D, BLOCK_SIZE_3D)
dim3 grid ((interior_nx+block.x - 1)/block.x,(interior_ny+block.y - 1)/block.y,(interior_nz+block.z - 1)/block.z)
GPU_LAUNCH_KERNEL(laplace_3d_kernel, grid, block, input, output, nx, ny, nz, stride_x, stride_y, stride_z, scale, increment)

Variables

constexpr int BLOCK_SIZE_2D = 16
constexpr int BLOCK_SIZE_3D = 8
const Real *input
const Real Real * output
const Real Real Index_t nx
const Real Real Index_t Index_t ny
const Real Real Index_t Index_t Index_t stride_x
const Real Real Index_t Index_t Index_t Index_t stride_y
const Real Real Index_t Index_t Index_t Index_t Real scale
const Real Real Index_t Index_t Index_t Index_t Real bool increment   = {           Index_t interior_nx = nx - 2
Index_t interior_ny = ny - 2
const Real Real Index_t Index_t Index_t nz
const Real Real Index_t Index_t Index_t Index_t Index_t Index_t stride_z
Index_t interior_nz = nz - 2
namespace linalg

Functions

template<typename T, typename MemorySpace>
T vecdot(const TypedField<T, MemorySpace> &a, const TypedField<T, MemorySpace> &b)

Vector dot product on interior pixels only (excludes ghost regions). Computes sum_i(a[i] * b[i]) for all interior pixels and all components.

This function iterates only over the interior region of the field, excluding ghost cells. This is essential for MPI-parallel computations where ghost values are duplicated across processes.

Following Array API vecdot semantics: https://data-apis.org/array-api/latest/API_specification/generated/array_api.vecdot.html

Template Parameters:
  • T – Scalar type (Real, Complex, etc.)

  • MemorySpace – Memory space (HostSpace, CUDASpace, ROCmSpace)

Parameters:
  • a – First field

  • b – Second field (must have same shape as a)

Throws:

FieldError – if fields have incompatible shapes or collections

Returns:

Scalar dot product (local, not MPI-reduced)

template<typename T, typename MemorySpace>
void axpy(T alpha, const TypedField<T, MemorySpace> &x, TypedField<T, MemorySpace> &y)

AXPY operation: y = alpha * x + y

Operates on the FULL buffer (including ghost regions) for efficiency, as the underlying memory is contiguous. Ghost values will typically be overwritten by subsequent ghost communication anyway.

Template Parameters:
  • T – Scalar type (Real, Complex, etc.)

  • MemorySpace – Memory space (HostSpace, CUDASpace, ROCmSpace)

Parameters:
  • alpha – Scalar multiplier

  • x – Input field

  • y – Input/output field (modified in place)

Throws:

FieldError – if fields have incompatible shapes

template<typename T, typename MemorySpace>
void scal(T alpha, TypedField<T, MemorySpace> &x)

Scale operation: x = alpha * x

Operates on the FULL buffer for efficiency.

Template Parameters:
  • T – Scalar type (Real, Complex, etc.)

  • MemorySpace – Memory space (HostSpace, CUDASpace, ROCmSpace)

Parameters:
  • alpha – Scalar multiplier

  • x – Input/output field (modified in place)

template<typename T, typename MemorySpace>
void axpby(T alpha, const TypedField<T, MemorySpace> &x, T beta, TypedField<T, MemorySpace> &y)

AXPBY operation: y = alpha * x + beta * y

Combined scale-and-add that is more efficient than separate scal + axpy because it reads and writes each element only once.

Operates on the FULL buffer (including ghost regions) for efficiency.

Template Parameters:
  • T – Scalar type (Real, Complex, etc.)

  • MemorySpace – Memory space (HostSpace, CUDASpace, ROCmSpace)

Parameters:
  • alpha – Scalar multiplier for x

  • x – Input field

  • beta – Scalar multiplier for y

  • y – Input/output field (modified in place)

Throws:

FieldError – if fields have incompatible shapes

template<typename T, typename MemorySpace>
void copy(const TypedField<T, MemorySpace> &src, TypedField<T, MemorySpace> &dst)

Copy operation: dst = src

Operates on the FULL buffer.

Template Parameters:
  • T – Scalar type (Real, Complex, etc.)

  • MemorySpace – Memory space (HostSpace, CUDASpace, ROCmSpace)

Parameters:
  • src – Source field

  • dst – Destination field (modified in place)

Throws:

FieldError – if fields have incompatible shapes

template<typename T, typename MemorySpace>
T norm_sq(const TypedField<T, MemorySpace> &x)

Squared L2 norm on interior pixels: sum_i(x[i]^2)

Convenience function, equivalent to vecdot(x, x). Only iterates over interior region (excludes ghosts).

Template Parameters:
  • T – Scalar type (Real, Complex, etc.)

  • MemorySpace – Memory space (HostSpace, CUDASpace, ROCmSpace)

Parameters:

x – Input field

Returns:

Squared norm (local, not MPI-reduced)

template<typename T, typename MemorySpace>
T axpy_norm_sq(T alpha, const TypedField<T, MemorySpace> &x, TypedField<T, MemorySpace> &y)

Fused AXPY + norm_sq: y = alpha * x + y, returns ||y||² (interior only)

This fused operation computes both the AXPY update and the squared norm of the result in a single pass through memory. This is more efficient than separate axpy() + norm_sq() calls because:

  • axpy + norm_sq: 2 reads of x, 2 reads of y, 1 write of y

  • axpy_norm_sq: 1 read of x, 1 read of y, 1 write of y

The AXPY operates on the FULL buffer, while the norm is computed only over interior pixels (excludes ghost regions for MPI correctness).

Template Parameters:
  • T – Scalar type (Real, Complex, etc.)

  • MemorySpace – Memory space (HostSpace, CUDASpace, ROCmSpace)

Parameters:
  • alpha – Scalar multiplier

  • x – Input field

  • y – Input/output field (modified in place)

Throws:

FieldError – if fields have incompatible shapes

Returns:

Squared norm of y after update (local, not MPI-reduced)

template<>
Real vecdot<Real, DeviceSpace>(const TypedField<Real, DeviceSpace> &a, const TypedField<Real, DeviceSpace> &b)
template<>
Real norm_sq<Real, DeviceSpace>(const TypedField<Real, DeviceSpace> &x)
template<>
void axpy<Real, DeviceSpace>(Real alpha, const TypedField<Real, DeviceSpace> &x, TypedField<Real, DeviceSpace> &y)
template<>
void scal<Real, DeviceSpace>(Real alpha, TypedField<Real, DeviceSpace> &x)
template<>
void axpby<Real, DeviceSpace>(Real alpha, const TypedField<Real, DeviceSpace> &x, Real beta, TypedField<Real, DeviceSpace> &y)
template<>
void copy<Real, DeviceSpace>(const TypedField<Real, DeviceSpace> &src, TypedField<Real, DeviceSpace> &dst)
template<>
Real axpy_norm_sq<Real, DeviceSpace>(Real alpha, const TypedField<Real, DeviceSpace> &x, TypedField<Real, DeviceSpace> &y)
template<>
Complex vecdot<Complex, DeviceSpace>(const TypedField<Complex, DeviceSpace> &a, const TypedField<Complex, DeviceSpace> &b)
template<>
Complex norm_sq<Complex, DeviceSpace>(const TypedField<Complex, DeviceSpace> &x)
template<>
void axpy<Complex, DeviceSpace>(Complex alpha, const TypedField<Complex, DeviceSpace> &x, TypedField<Complex, DeviceSpace> &y)
template<>
void scal<Complex, DeviceSpace>(Complex alpha, TypedField<Complex, DeviceSpace> &x)
template<>
void axpby<Complex, DeviceSpace>(Complex alpha, const TypedField<Complex, DeviceSpace> &x, Complex beta, TypedField<Complex, DeviceSpace> &y)
template<>
void copy<Complex, DeviceSpace>(const TypedField<Complex, DeviceSpace> &src, TypedField<Complex, DeviceSpace> &dst)
template<>
Complex axpy_norm_sq<Complex, DeviceSpace>(Complex alpha, const TypedField<Complex, DeviceSpace> &x, TypedField<Complex, DeviceSpace> &y)
template<>
Real vecdot<Real, HostSpace>(const TypedField<Real, HostSpace> &a, const TypedField<Real, HostSpace> &b)
template<>
Complex vecdot<Complex, HostSpace>(const TypedField<Complex, HostSpace> &a, const TypedField<Complex, HostSpace> &b)
template<>
void axpy<Real, HostSpace>(Real alpha, const TypedField<Real, HostSpace> &x, TypedField<Real, HostSpace> &y)
template<>
void axpy<Complex, HostSpace>(Complex alpha, const TypedField<Complex, HostSpace> &x, TypedField<Complex, HostSpace> &y)
template<>
void scal<Real, HostSpace>(Real alpha, TypedField<Real, HostSpace> &x)
template<>
void scal<Complex, HostSpace>(Complex alpha, TypedField<Complex, HostSpace> &x)
template<>
void axpby<Real, HostSpace>(Real alpha, const TypedField<Real, HostSpace> &x, Real beta, TypedField<Real, HostSpace> &y)
template<>
void axpby<Complex, HostSpace>(Complex alpha, const TypedField<Complex, HostSpace> &x, Complex beta, TypedField<Complex, HostSpace> &y)
template<>
void copy<Real, HostSpace>(const TypedField<Real, HostSpace> &src, TypedField<Real, HostSpace> &dst)
template<>
void copy<Complex, HostSpace>(const TypedField<Complex, HostSpace> &src, TypedField<Complex, HostSpace> &dst)
template<>
Real norm_sq<Real, HostSpace>(const TypedField<Real, HostSpace> &x)
template<>
Complex norm_sq<Complex, HostSpace>(const TypedField<Complex, HostSpace> &x)
template<>
Real axpy_norm_sq<Real, HostSpace>(Real alpha, const TypedField<Real, HostSpace> &x, TypedField<Real, HostSpace> &y)
template<>
Complex axpy_norm_sq<Complex, HostSpace>(Complex alpha, const TypedField<Complex, HostSpace> &x, TypedField<Complex, HostSpace> &y)
namespace gpu_kernels

Functions

__global__ void axpy_kernel (Real alpha, const Real *x, Real *y, Index_t n)

AXPY kernel: y = alpha * x + y

__global__ void scal_kernel (Real alpha, Real *x, Index_t n)

Scale kernel: x = alpha * x

__global__ void copy_kernel (const Real *src, Real *dst, Index_t n)

Copy kernel: dst = src

__global__ void axpby_kernel (Real alpha, const Real *x, Real beta, Real *y, Index_t n)

AXPBY kernel: y = alpha * x + beta * y

__global__ void axpy_norm_sq_kernel (Real alpha, const Real *x, Real *y, Real *partial_sums, Index_t n)

Fused AXPY + norm_sq kernel: y = alpha * x + y, returns partial ||y||² Each block computes AXPY for its elements AND accumulates partial norm.

__global__ void dot_reduce_kernel (const Real *a, const Real *b, Real *partial_sums, Index_t n)

Dot product reduction kernel (first pass). Computes partial sums per block.

__global__ void norm_sq_reduce_kernel (const Real *x, Real *partial_sums, Index_t n)

Squared norm reduction kernel (first pass). Computes partial sums per block.

__global__ void final_reduce_kernel (Real *data, Index_t n)

Final reduction kernel - sums partial results.

__global__ void ghost_dot_2d_kernel (const Real *a, const Real *b, Real *partial_sums, Index_t nx_total, Index_t ny_total, Index_t gx_left, Index_t gx_right, Index_t gy_left, Index_t gy_right, Index_t field_stride_c, Index_t field_stride_x, Index_t field_stride_y, Index_t nb_components)

Compute dot product over ghost region only (2D). Ghost region = left/right columns + top/bottom rows (excluding corners). Uses field data strides directly for correct SoA layout handling.

__global__ void ghost_norm_sq_2d_kernel (const Real *x, Real *partial_sums, Index_t nx_total, Index_t ny_total, Index_t gx_left, Index_t gx_right, Index_t gy_left, Index_t gy_right, Index_t field_stride_c, Index_t field_stride_x, Index_t field_stride_y, Index_t nb_components)

Compute squared norm over ghost region only (2D). Uses field data strides directly for correct SoA layout handling.

__global__ void ghost_dot_3d_kernel (const Real *a, const Real *b, Real *partial_sums, Index_t nx_total, Index_t ny_total, Index_t nz_total, Index_t gx_left, Index_t gx_right, Index_t gy_left, Index_t gy_right, Index_t gz_left, Index_t gz_right, Index_t field_stride_c, Index_t field_stride_x, Index_t field_stride_y, Index_t field_stride_z, Index_t nb_components)

Compute dot product over ghost region only (3D). Ghost region = all pixels outside the interior box. Uses a simple approach: iterate all pixels, skip interior ones. Uses field strides for correct SoA layout handling.

__global__ void ghost_norm_sq_3d_kernel (const Real *x, Real *partial_sums, Index_t nx_total, Index_t ny_total, Index_t nz_total, Index_t gx_left, Index_t gx_right, Index_t gy_left, Index_t gy_right, Index_t gz_left, Index_t gz_right, Index_t field_stride_c, Index_t field_stride_x, Index_t field_stride_y, Index_t field_stride_z, Index_t nb_components)

Compute squared norm over ghost region only (3D). Uses a simple approach: iterate all pixels, skip interior ones. Uses field strides for correct SoA layout handling.

Variables

constexpr int BLOCK_SIZE = 256
constexpr int REDUCE_BLOCK_SIZE = 256
namespace internal

Functions

template<typename T>
T ghost_vecdot(const T *a_data, const T *b_data, const GlobalFieldCollection &coll, Index_t nb_components_per_pixel)

Helper to compute dot product of ghost region only. We compute full buffer dot with Eigen, then subtract ghosts.

template<typename T>
T ghost_norm_sq(const T *data, const GlobalFieldCollection &coll, Index_t nb_components_per_pixel)

Helper to compute squared norm of ghost region only. We compute full buffer norm with Eigen, then subtract ghosts.

namespace Matrices

Typedefs

template<Dim_t dim>
using Tens2_t = Eigen::Matrix<Real, dim, dim>

second-order tensor representation

template<Dim_t dim>
using Tens4_t = T4Mat<Real, dim>

fourth-order tensor representation

Functions

template<Dim_t dim>
inline constexpr Tens2_t<dim> I2()

compile-time second-order identity

template<typename T1, typename T2>
inline constexpr decltype(auto) outer(const Eigen::MatrixBase<T1> &A, const Eigen::MatrixBase<T2> &B)

compile-time outer tensor product as defined by Curnier R_ijkl = A_ij.B_klxx 0123 01 23

template<typename Derived1, typename Derived2>
inline constexpr decltype(auto) outer_under(const Eigen::MatrixBase<Derived1> &A, const Eigen::MatrixBase<Derived2> &B)

compile-time underlined outer tensor product as defined by Curnier R_ijkl = A_ik.B_jlxx 0123 02 13 0213 01 23 <- this defines the shuffle order

template<typename T1, typename T2>
inline constexpr decltype(auto) outer_over(const Eigen::MatrixBase<T1> &A, const Eigen::MatrixBase<T2> &B)

compile-time overlined outer tensor product as defined by Curnier R_ijkl = A_il.B_jkxx 0123 03 12 0231 01 23 <- this defines the shuffle order

template<typename TLarge, typename TSmall>
inline constexpr decltype(auto) tensmult(const Eigen::MatrixBase<TLarge> &A, const Eigen::MatrixBase<TSmall> &B)

Standard tensor multiplication

template<Dim_t dim>
inline constexpr Tens4_t<dim> Itrac()

compile-time fourth-order tracer

template<Dim_t dim>
inline constexpr Tens4_t<dim> Iiden()

compile-time fourth-order identity

template<Dim_t dim>
inline constexpr Tens4_t<dim> Itrns()

compile-time fourth-order transposer

template<Dim_t dim>
inline constexpr Tens4_t<dim> Isymm()

compile-time fourth-order symmetriser

template<Dim_t dim>
inline constexpr Tens4_t<dim> Iasymm()

compile-time fourth-order asymmetriser

template<Dim_t Dim, class T1, class T2>
decltype(auto) dot(const Eigen::MatrixBase<T1> &t1, const Eigen::MatrixBase<T2> &t2)

simple contraction between two tensors. The result depends on the rank of the tesnors, see documentation for muGrid::internal::Dotter

template<Dim_t Dim, class T1, class T2>
decltype(auto) ddot(const Eigen::MatrixBase<T1> &t1, const Eigen::MatrixBase<T2> &t2)

double contraction between two tensors. The result depends on the rank of the tesnors, see documentation for muGrid::internal::Dotter

namespace AxisTransform

Functions

template<class T_in, class T2>
static inline decltype(auto) push_forward(const Eigen::MatrixBase<T_in> &t, const Eigen::MatrixBase<T2> &F)
template<class T_in, class T2>
static inline decltype(auto) pull_back(const Eigen::MatrixBase<T_in> &t, const Eigen::MatrixBase<T2> &F)
namespace internal
namespace Tensors

Typedefs

template<Dim_t dim>
using Tens2_t = Eigen::TensorFixedSize<Real, Eigen::Sizes<dim, dim>>

second-order tensor representation

template<Dim_t dim>
using Tens4_t = Eigen::TensorFixedSize<Real, Eigen::Sizes<dim, dim, dim, dim>>

fourth-order tensor representation

Functions

template<Dim_t dim>
inline constexpr Tens2_t<dim> I2()

compile-time second-order identity

template<Dim_t dim, typename T1, typename T2>
inline constexpr decltype(auto) outer(T1 &&A, T2 &&B)

compile-time outer tensor product as defined by Curnier R_ijkl = A_ij.B_klxx 0123 01 23

template<Dim_t dim, typename T1, typename T2>
inline constexpr decltype(auto) outer_under(T1 &&A, T2 &&B)

compile-time underlined outer tensor product as defined by Curnier R_ijkl = A_ik.B_jlxx 0123 02 13 0213 01 23 <- this defines the shuffle order

template<Dim_t dim, typename T1, typename T2>
inline constexpr decltype(auto) outer_over(T1 &&A, T2 &&B)

compile-time overlined outer tensor product as defined by Curnier R_ijkl = A_il.B_jkxx 0123 03 12 0231 01 23 <- this defines the shuffle order

template<Dim_t dim>
inline constexpr Tens4_t<dim> I4S()

compile-time fourth-order symmetrising identity

namespace version

Functions

std::string info()

Returns a formatted text that can be printed to stdout or to output files.

This function generates a string that contains the git commit hash and repository url used to compile µGrid. It also indicates whether the current state was dirty or not.

Returns:

A formatted string containing the git commit hash, repository url and the state of the repository.

const char *hash()

Returns the git commit hash.

This function retrieves the git commit hash used to compile µGrid.

Returns:

A constant character pointer representing the git commit hash.

const char *description()

Returns the repository description.

This function retrieves the repository description used to compile µGrid.

Returns:

A constant character pointer representing the repository description.

bool is_dirty()

Checks if the current state was dirty.

This function checks if the current state of the repository used to compile µGrid was dirty or not.

Returns:

A boolean value indicating if the state was dirty (true) or not (false).

namespace pocketfft
namespace detail

Typedefs

using shape_t = std::vector<size_t>
using stride_t = std::vector<ptrdiff_t>
template<typename T>
using vtype_t = typename VTYPE<T>::type
template<typename T>
using add_vec_t = typename add_vec<T>::type

Functions

template<typename T>
T cos(T) = delete
template<typename T>
T sin(T) = delete
template<typename T>
T sqrt(T) = delete
inline void *aligned_alloc(size_t align, size_t size)
inline void aligned_dealloc(void *ptr)
template<typename T>
inline void PM(T &a, T &b, T c, T d)
template<typename T>
inline void PMINPLACE(T &a, T &b)
template<typename T>
inline void MPINPLACE(T &a, T &b)
template<typename T>
cmplx<T> conj(const cmplx<T> &a)
template<bool fwd, typename T, typename T2>
void special_mul(const cmplx<T> &v1, const cmplx<T2> &v2, cmplx<T> &res)
template<typename T>
void ROT90(cmplx<T> &a)
template<bool fwd, typename T>
void ROTX90(cmplx<T> &a)
template<typename T>
std::shared_ptr<T> get_plan(size_t length)
template<typename T>
arr<char> alloc_tmp(const shape_t &shape, size_t axsize, size_t elemsize)
template<typename T>
arr<char> alloc_tmp(const shape_t &shape, const shape_t &axes, size_t elemsize)
template<typename T, size_t vlen> void copy_input (const multi_iter< vlen > &it, const cndarr< cmplx< T > > &src, cmplx< vtype_t< T > > *POCKETFFT_RESTRICT dst)
template<typename T, size_t vlen> void copy_input (const multi_iter< vlen > &it, const cndarr< T > &src, vtype_t< T > *POCKETFFT_RESTRICT dst)
template<typename T, size_t vlen> void copy_input (const multi_iter< vlen > &it, const cndarr< T > &src, T *POCKETFFT_RESTRICT dst)
template<typename T, size_t vlen> void copy_output (const multi_iter< vlen > &it, const cmplx< vtype_t< T > > *POCKETFFT_RESTRICT src, ndarr< cmplx< T > > &dst)
template<typename T, size_t vlen> void copy_output (const multi_iter< vlen > &it, const vtype_t< T > *POCKETFFT_RESTRICT src, ndarr< T > &dst)
template<typename T, size_t vlen> void copy_output (const multi_iter< vlen > &it, const T *POCKETFFT_RESTRICT src, ndarr< T > &dst)
template<typename Tplan, typename T, typename T0, typename Exec> POCKETFFT_NOINLINE void general_nd (const cndarr< T > &in, ndarr< T > &out, const shape_t &axes, T0 fct, size_t nthreads, const Exec &exec, const bool allow_inplace=true)
template<typename T, size_t vlen> void copy_hartley (const multi_iter< vlen > &it, const vtype_t< T > *POCKETFFT_RESTRICT src, ndarr< T > &dst)
template<typename T, size_t vlen> void copy_hartley (const multi_iter< vlen > &it, const T *POCKETFFT_RESTRICT src, ndarr< T > &dst)
template<typename T> POCKETFFT_NOINLINE void general_r2c (const cndarr< T > &in, ndarr< cmplx< T > > &out, size_t axis, bool forward, T fct, size_t nthreads)
template<typename T> POCKETFFT_NOINLINE void general_c2r (const cndarr< cmplx< T > > &in, ndarr< T > &out, size_t axis, bool forward, T fct, size_t nthreads)
template<typename T>
void c2c(const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, const shape_t &axes, bool forward, const std::complex<T> *data_in, std::complex<T> *data_out, T fct, size_t nthreads = 1)
template<typename T>
void dct(const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, const shape_t &axes, int type, const T *data_in, T *data_out, T fct, bool ortho, size_t nthreads = 1)
template<typename T>
void dst(const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, const shape_t &axes, int type, const T *data_in, T *data_out, T fct, bool ortho, size_t nthreads = 1)
template<typename T>
void r2c(const shape_t &shape_in, const stride_t &stride_in, const stride_t &stride_out, size_t axis, bool forward, const T *data_in, std::complex<T> *data_out, T fct, size_t nthreads = 1)
template<typename T>
void r2c(const shape_t &shape_in, const stride_t &stride_in, const stride_t &stride_out, const shape_t &axes, bool forward, const T *data_in, std::complex<T> *data_out, T fct, size_t nthreads = 1)
template<typename T>
void c2r(const shape_t &shape_out, const stride_t &stride_in, const stride_t &stride_out, size_t axis, bool forward, const std::complex<T> *data_in, T *data_out, T fct, size_t nthreads = 1)
template<typename T>
void c2r(const shape_t &shape_out, const stride_t &stride_in, const stride_t &stride_out, const shape_t &axes, bool forward, const std::complex<T> *data_in, T *data_out, T fct, size_t nthreads = 1)
template<typename T>
void r2r_fftpack(const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, const shape_t &axes, bool real2hermitian, bool forward, const T *data_in, T *data_out, T fct, size_t nthreads = 1)
template<typename T>
void r2r_separable_hartley(const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, const shape_t &axes, const T *data_in, T *data_out, T fct, size_t nthreads = 1)
template<typename T>
void r2r_genuine_hartley(const shape_t &shape, const stride_t &stride_in, const stride_t &stride_out, const shape_t &axes, const T *data_in, T *data_out, T fct, size_t nthreads = 1)

Variables

constexpr bool FORWARD = true
constexpr bool BACKWARD = false
namespace threading

Functions

inline size_t &thread_id()
inline size_t &num_threads()
inline thread_pool &get_pool()
template<typename Func>
void thread_map(size_t nthreads, Func f)

Map a function f over nthreads

Variables

static const size_t max_threads = std::max(1u, std::thread::hardware_concurrency())
namespace std
file field_collection.cc
#include “field/field.hh
#include “field/state_field.hh
#include “field/field_typed.hh

Implementations for field collections.

Author

Till Junge till.junge@altermail.ch

Date

11 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_collection.hh
#include “core/exception.hh
#include “core/types.hh
#include “core/enums.hh
#include “core/units.hh
#include “memory/memory_space.hh
#include “memory/device.hh
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <sstream>
#include <vector>

Base class for field collections.

Author

Till Junge till.junge@altermail.ch

Date

10 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_collection_global.cc
#include “util/math.hh

Implementation of GlobalFieldCollection.

Author

Till Junge till.junge@altermail.ch

Date

11 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_collection_global.hh
#include “grid/pixels.hh

Global field collections.

Author

Till Junge till.junge@altermail.ch

Date

11 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_collection_local.cc

implementation of local field collection

Author

Till Junge till.junge@epfl.ch

Date

12 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_collection_local.hh

Local field collection.

Author

Till Junge till.junge@epfl.ch

Date

12 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file coordinates.hh
#include “types.hh
#include “exception.hh
#include “grid/iterators.hh
#include “Eigen/Dense”
#include <array>
#include <algorithm>
#include <sstream>
#include <vector>

Coordinate type definitions for muGrid.

Author

Till Junge till.junge@epfl.ch

Date

24 Jan 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file enums.cc
#include “core/enums.hh
#include “exception.hh

Implementation of enum operators.

Author

Indre Joedicke indre.joedicke@imtek.uni-freiburg.de

Date

17 Feb 2020

LICENSE

Copyright © 2020 Indre Joedicke

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file enums.hh
#include <ostream>
#include <string>

Enumeration definitions for muGrid.

Author

Till Junge till.junge@epfl.ch

Date

24 Jan 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file exception.cc
#include <cxxabi.h>
#include <dlfcn.h>
#include <execinfo.h>
#include “core/exception.hh

exception class for libmuGrid that collect a stack trace

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

04 Feb 2020

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

  • Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

Variables

const int MAX_DEPTH = 256
file exception.hh
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

exception class for libmuGrid that collect a stack trace

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

04 Feb 2020

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

  • Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file type_descriptor.cc
#include “type_descriptor.hh
#include “exception.hh
#include <complex>
#include <cstddef>
#include <sstream>

Runtime implementations for TypeDescriptor utilities.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file type_descriptor.hh
#include <complex>
#include <cstddef>
#include <cstdint>
#include <typeinfo>
#include <type_traits>

Unified type descriptor for cross-library type mapping.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2024

This header provides a TypeDescriptor enum that serves as a unified type identifier for muGrid. It can be converted to MPI_Datatype (when MPI is available) or nc_type (when NetCDF is available), enabling type-safe communication without void* casts.

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file types.hh
#include <complex>
#include <cstddef>
#include <cstdint>
#include <vector>

Scalar type definitions for muGrid.

Author

Till Junge till.junge@epfl.ch

Date

24 Jan 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

Defines

MUGRID_RESTRICT
file units.cc
#include “core/units.hh
#include “grid/iterators.hh
#include <algorithm>
#include <sstream>
#include <cmath>

dynamic units class based on mass, length, time (could be interpreted as kg, m, s according to the SI). Useful to avoid bugs due to multiphisics mixing of domains.

Author

Till Junge till.junge@altermail.ch

Date

23 Apr 2020

Copyright © 2020 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file units.hh
#include “core/types.hh
#include “core/exception.hh
#include <array>
#include <iostream>

dynamic units class based on mass, length, time (could be interpreted as kg, m, s according to the SI). Useful to avoid bugs due to multiphisics mixing of domains.

Author

Till Junge till.junge@altermail.ch

Date

23 Apr 2020

Copyright © 2020 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file version.hh
#include <string>

Version information for muGrid.

Author

Till Junge till.junge@epfl.ch

Date

24 Jan 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file cufft_backend.cc
#include “cufft_backend.hh
#include “core/exception.hh
#include <sstream>

cuFFT implementation of FFT1DBackend for NVIDIA GPUs

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

19 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file cufft_backend.hh
#include “fft_1d_backend.hh
#include <cufft.h>
#include <unordered_map>
#include <tuple>

cuFFT implementation of FFT1DBackend for NVIDIA GPUs

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

19 Dec 2024

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_1d_backend.hh
#include “core/types.hh
#include <memory>

Abstract interface for 1D FFT backends.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

18 Dec 2024

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_backend_factory.cc
#include “fft_1d_backend.hh
#include “pocketfft_backend.hh

Factory functions for FFT backends.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

20 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_backend_traits.hh
#include “memory/memory_space.hh
#include “memory/device.hh
#include “fft_1d_backend.hh
#include “pocketfft_backend.hh
#include <memory>

Compile-time FFT backend selection based on memory space.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

21 Dec 2024

Copyright (c) 2024 Lars Pastewka

muGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

muGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with muGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_engine.cc
#include “fft_engine.hh

Explicit template instantiations for FFTEngine.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

18 Dec 2025

Copyright (c) 2024 Lars Pastewka

muGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

muGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with muGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_engine.hh
#include “fft_engine_base.hh
#include “fft_backend_traits.hh
#include “memory/array.hh
#include “field/field_typed.hh
#include “core/exception.hh

Distributed FFT engine with pencil decomposition.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

18 Dec 2024

Copyright (c) 2024 Lars Pastewka

muGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

muGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with muGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_engine_base.cc
#include “fft_engine_base.hh
#include “core/exception.hh

Non-templated base class for distributed FFT engine.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

21 Dec 2025

Copyright (c) 2024 Lars Pastewka

muGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

muGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with muGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_engine_base.hh
#include “mpi/communicator.hh
#include “fft_1d_backend.hh
#include “transpose.hh
#include “fft_utils.hh
#include <memory>
#include <array>
#include <string>
#include <map>

Non-templated base class for distributed FFT engine.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

21 Dec 2024

Copyright (c) 2024 Lars Pastewka

muGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

muGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with muGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_utils.cc
#include “fft_utils.hh
#include <cmath>
#include <numeric>

Utility functions for FFT operations.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

18 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_utils.hh
#include “core/types.hh
#include “core/coordinates.hh
#include <vector>

Utility functions for FFT operations.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

18 Dec 2024

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fft_work_buffer.hh
#include “core/types.hh
#include <cstddef>
#include <cstring>
#include <stdexcept>
#include <vector>

Runtime work buffer and memory operations for FFT engine.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

21 Dec 2024

This file provides utilities for managing work buffers that can be allocated on either host or device memory, with the location determined at runtime. This is essential for FFT operations that need temporary storage matching the input/output field memory locations.

Copyright (c) 2024 Lars Pastewka

muGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

muGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with muGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file pocketfft_hdronly.h
#include <cmath>
#include <cstdlib>
#include <stdexcept>
#include <memory>
#include <vector>
#include <complex>
#include <algorithm>
#include <mutex>
#include <condition_variable>
#include <thread>
#include <queue>
#include <atomic>
#include <functional>
#include <new>

Defines

POCKETFFT_CACHE_SIZE
POCKETFFT_NOINLINE
POCKETFFT_RESTRICT
POCKETFFT_NO_VECTORS
POCKETFFT_PREP3(idx)
POCKETFFT_PARTSTEP3a(u1, u2, twr, twi)
POCKETFFT_PARTSTEP3b(u1, u2, twr, twi)
POCKETFFT_PREP5(idx)
POCKETFFT_PARTSTEP5a(u1, u2, twar, twbr, twai, twbi)
POCKETFFT_PARTSTEP5b(u1, u2, twar, twbr, twai, twbi)
POCKETFFT_PREP7(idx)
POCKETFFT_PARTSTEP7a0(u1, u2, x1, x2, x3, y1, y2, y3, out1, out2)
POCKETFFT_PARTSTEP7a(u1, u2, x1, x2, x3, y1, y2, y3)
POCKETFFT_PARTSTEP7(u1, u2, x1, x2, x3, y1, y2, y3)
POCKETFFT_PREP11(idx)
POCKETFFT_PARTSTEP11a0(u1, u2, x1, x2, x3, x4, x5, y1, y2, y3, y4, y5, out1, out2)
POCKETFFT_PARTSTEP11a(u1, u2, x1, x2, x3, x4, x5, y1, y2, y3, y4, y5)
POCKETFFT_PARTSTEP11(u1, u2, x1, x2, x3, x4, x5, y1, y2, y3, y4, y5)
POCKETFFT_REARRANGE(rx, ix, ry, iy)
file pocketfft_backend.cc
#include “pocketfft_backend.hh

PocketFFT implementation of FFT1DBackend.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

18 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

Defines

POCKETFFT_NO_MULTITHREADING
file pocketfft_backend.hh
#include “fft_1d_backend.hh

PocketFFT implementation of FFT1DBackend.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

18 Dec 2024

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file rocfft_backend.cc
#include “rocfft_backend.hh
#include “core/exception.hh
#include <hip/hip_runtime.h>
#include <sstream>

Native rocFFT implementation of FFT1DBackend for AMD GPUs.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

05 Jan 2026

Copyright © 2024-2026 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file rocfft_backend.hh
#include “fft_1d_backend.hh
#include <rocfft/rocfft.h>
#include <unordered_map>
#include <tuple>

Native rocFFT implementation of FFT1DBackend for AMD GPUs.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

05 Jan 2026

Copyright © 2024-2026 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file transpose.cc
#include “transpose.hh
#include “core/exception.hh
#include <algorithm>
#include <numeric>

MPI transpose using derived datatypes (no explicit pack/unpack)

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

21 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file transpose.hh
#include “core/types.hh
#include “core/enums.hh
#include “core/coordinates.hh
#include “mpi/communicator.hh
#include <vector>

MPI transpose using derived datatypes (no explicit pack/unpack)

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

21 Dec 2024

This implementation uses MPI derived datatypes (MPI_Type_create_subarray, MPI_Type_vector, MPI_Type_create_hvector) with MPI_Alltoallw to perform transpose operations without explicit pack/unpack buffers. This approach:

  • Eliminates memory overhead from temporary buffers

  • Allows MPI to optimize non-contiguous memory access

  • Works seamlessly with GPU-aware MPI implementations

  • Supports multi-component fields (AoS and SoA layouts)

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field.cc
#include “field/field.hh
#include “util/math.hh

implementation of Field

Author

Till Junge till.junge@altermail.ch

Date

11 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field.hh
#include “core/exception.hh
#include “core/types.hh
#include “core/enums.hh
#include “core/units.hh
#include “core/type_descriptor.hh
#include <string>

Base class for fields.

Author

Till Junge till.junge@altermail.ch

Date

10 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_map.cc
#include “field/field_map.hh
#include “field/field_typed.hh
#include “grid/iterators.hh
#include <sstream>
#include <iostream>

Implementation for basic FieldMap.

Author

Till Junge till.junge@epfl.ch

Date

15 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_map.hh
#include “core/types.hh
#include “core/enums.hh
#include “grid/iterators.hh
#include “Eigen/Dense”
#include <cassert>
#include <type_traits>
#include <memory>
#include <functional>

Implementation of the base class of all field maps.

Author

Till Junge till.junge@epfl.ch

Date

15 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_map_static.hh
#include “field/field.hh
#include “field/field_typed.hh
#include “field/field_map.hh
#include “util/T4_map_proxy.hh
#include <sstream>

header-only implementation of field maps with statically known iterate sizes

Author

Till Junge till.junge@epfl.ch

Date

20 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_typed.cc
#include <sstream>
#include “grid/index_ops.hh
#include “field/field_typed.hh
#include “field/field_map.hh
#include “util/tensor_algebra.hh

Implementation for typed fields.

Author

Till Junge till.junge@epfl.ch

Date

13 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file field_typed.hh
#include “field/field.hh
#include “core/enums.hh
#include “memory/array.hh
#include “Eigen/Dense”
#include <type_traits>
#include <memory>

Field classes for which the scalar type has been defined.

Author

Till Junge till.junge@altermail.ch

Date

10 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file mapped_field.hh
#include “field/field_typed.hh
#include <string>

convenience class to deal with data structures common to most internal variable fields in materials

Author

Till Junge till.junge@epfl.ch

Date

04 Sep 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file mapped_state_field.hh
#include “field/state_field.hh

Convenience class extending the mapped field concept to state fields.

Author

Till Junge till.junge@epfl.ch

Date

09 Sep 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file optional_mapped_field.hh
#include <optional>
#include <memory>

Simple structure for optional mapped fields with low runtime overhead. This is practical if some fields need be be stored depending on some solver arguments. The original use-case is a stress field for storing native stresses, which usually do not need to be stored, but are useful for visualisation and analysis of stress states.

Author

Till Junge till.junge@epfl.ch

Date

27 Jan 2020

Copyright © 2020 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file state_field.cc
#include “field/state_field.hh
#include “field/field.hh
#include “field/field_typed.hh
#include <sstream>

implementation for state fields

Author

Till Junge till.junge@altermail.ch

Date

20 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file state_field.hh
#include “core/types.hh
#include “core/type_descriptor.hh
#include “util/ref_vector.hh
#include “field/state_field_map.hh
#include <string>
#include <vector>
#include <utility>

A state field is an abstraction of a field that can hold current, as well as a chosen number of previous values. This is useful for instance for internal state variables in plastic laws, where a current, new, or trial state is computed based on its previous state, and at convergence, this new state gets cycled into the old, the old into the old-1 etc. The state field abstraction helps doing this safely (i.e. only const references to the old states are available, while the current state can be assigned to/modified), and efficiently (i.e., no need to copy values from new to old, we just cycle the labels). This file implements the state field as well as state maps using the Field, FieldCollection and FieldMap abstractions of µGrid.

Author

Till Junge till.junge@altermail.ch

Date

20 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file state_field_map.cc
#include “field/state_field_map.hh
#include “field/state_field.hh
#include “field/field_map.hh
#include “field/field_typed.hh
#include “field/field.hh

implementation of state field maps

Author

Till Junge till.junge@epfl.ch

Date

22 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file state_field_map.hh
#include “core/enums.hh
#include “field/field_map.hh
#include “util/ref_vector.hh
#include <vector>
#include <memory>

implementation of state field maps

Author

Till Junge till.junge@epfl.ch

Date

22 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file state_field_map_static.hh
#include “field/state_field_map.hh
#include “field/field_typed.hh
#include <array>
#include <sstream>
#include <utility>

header-only implementation of state field maps with statically known iterate sizes

Author

Till Junge till.junge@epfl.ch

Date

27 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file index_ops.cc
#include <iostream>
#include “core/exception.hh
#include “grid/index_ops.hh
file index_ops.hh
#include “core/types.hh
#include “core/coordinates.hh
#include “core/exception.hh
#include “grid/iterators.hh
#include “strides.hh
#include “Eigen/Dense”
#include <cassert>
#include <sstream>
#include <vector>

Index and coordinate conversion operations for grid addressing.

Author

Till Junge till.junge@epfl.ch

Date

29 Sep 2017

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

  • Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file iterators.hh
#include <ranges>
#include <tuple>
#include <utility>

iterator interfaces - modernized with C++20 features

Author

Nicolas Richart (original akantu version)

Author

Lars Pastewka (C++20 modernization)

Date

creation Wed Jul 19 2017

Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)

Akantu is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Akantu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with Akantu. If not, see http://www.gnu.org/licenses/.

Above block was left intact as in akantu. µGrid exercises the right to redistribute and modify the code below

file pixels.cc
#include <iostream>
#include “core/exception.hh
#include “grid/pixels.hh

pre-compilable pixel operations

Author

Till Junge till.junge@epfl.ch

Date

01 Oct 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file pixels.hh
#include “core/types.hh
#include “core/coordinates.hh
#include “core/exception.hh
#include “strides.hh
#include “index_ops.hh
#include <tuple>

Pixels iterator class for iteration over discretisation grids.

Author

Till Junge till.junge@epfl.ch

Date

29 Sep 2017

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

  • Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file strides.cc
#include <iostream>
#include “core/exception.hh
#include “grid/pixels.hh
file strides.hh
#include “core/types.hh
#include “core/coordinates.hh
#include “core/exception.hh
#include <utility>
#include <numeric>
#include <algorithm>

Stride calculation utilities for grid operations.

Author

Till Junge till.junge@epfl.ch

Date

29 Sep 2017

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

  • Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file file_io_base.cc
#include “io/file_io_base.hh

Interface for parallel I/O of grid data.

Author

Richard Leute richard.leute@imtek.uni-freiburg.de

Date

20 Mai 2020

Copyright © 2020 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file file_io_base.hh
#include “mpi/communicator.hh
#include <vector>
#include <string>

Interface for parallel I/O of grid data.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de Richard Leute richard.leute@imtek.uni-freiburg.de

Date

17 May 2020

Copyright © 2020 Richard Leute, Lars Pastewka, Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

Typedefs

using Size_t = size_t
file file_io_netcdf.cc
#include “core/exception.hh
#include “core/version.hh
#include “grid/iterators.hh
#include “core/units.hh
#include “util/math.hh
#include “field/state_field.hh
#include “io/file_io_netcdf.hh

Using the FileIOBase class to implement a serial and parallel I/O interface for NetCDF files.

Author

Richard Leute richard.leute@imtek.uni-freiburg.de

Date

25 Mai 2020

Copyright © 2020 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file file_io_netcdf.hh
#include <string>
#include <memory>
#include <typeinfo>
#include <type_traits>
#include <iomanip>
#include <variant>
#include “core/types.hh
#include “io/file_io_base.hh
#include “mpi/communicator.hh
#include <netcdf.h>

Using the FileIOBase class to implement a serial and parallel I/O interface for NetCDF files.

Author

Richard Leute richard.leute@imtek.uni-freiburg.de

Date

25 Mai 2020

Copyright © 2020 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

Typedefs

using Datatype_t = nc_type
using IOSize_t = size_t
using IODiff_t = ptrdiff_t

Variables

const auto ncmu_create = nc_create
const auto ncmu_open = nc_open
const auto ncmu_enddef = nc_enddef
const auto ncmu_redef = nc_redef
const auto ncmu_close = nc_close
const auto ncmu_strerror = nc_strerror
const auto ncmu_def_dim = nc_def_dim
const auto ncmu_def_var = nc_def_var
const auto ncmu_inq = nc_inq
const auto ncmu_inq_varid = nc_inq_varid
const auto ncmu_inq_dimlen = nc_inq_dimlen
const auto ncmu_inq_dimid = nc_inq_dimid
const auto ncmu_inq_unlimdim = nc_inq_unlimdim
const auto ncmu_inq_attname = nc_inq_attname
const auto ncmu_inq_att = nc_inq_att
const auto ncmu_get_vara_all = nc_get_vara
const auto ncmu_get_varm_all = nc_get_varm
const auto ncmu_get_varm = nc_get_varm
const auto ncmu_get_varn_all = nc_get_vara
const auto ncmu_get_att = nc_get_att
const auto ncmu_put_vara_all = nc_put_vara
const auto ncmu_put_varm_all = nc_put_varm
const auto ncmu_put_varm = nc_put_varm
const auto ncmu_put_varn_all = nc_put_vara
const auto ncmu_put_att_text = nc_put_att_text
const auto ncmu_put_att = nc_put_att
const auto ncmu_rename_att = nc_rename_att
file type_descriptor_netcdf.cc

NetCDF type conversion implementations for TypeDescriptor.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file type_descriptor_netcdf.hh
#include “core/type_descriptor.hh

NetCDF type conversions for TypeDescriptor.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2024

This header provides conversion functions between TypeDescriptor and nc_type. It is only available when NetCDF support is enabled (WITH_NETCDF_IO).

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file linalg.hh
#include “field/field_typed.hh

Linear algebra operations for muGrid fields.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2024

This module provides efficient linear algebra operations that operate directly on muGrid fields, avoiding the overhead of creating non-contiguous views. Operations follow the Array API specification where applicable: https://data-apis.org/array-api/latest/

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file linalg_gpu.cc
#include “linalg/linalg.hh
#include “core/exception.hh

Unified CUDA/HIP implementations of linear algebra operations.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2025

This file provides GPU implementations that work with both CUDA and HIP backends. The kernel code is identical; only the launch mechanism and runtime API differ, which are abstracted via macros.

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file linalg_host.cc
#include “linalg/linalg.hh
#include “core/exception.hh

CPU implementations of linear algebra operations for fields.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file array.hh
#include <cstddef>
#include <cstring>
#include <string>
#include <stdexcept>
#include “memory_space.hh

One-dimensional array class for portable memory management on CPUs and GPUs.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

19 Dec 2024

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file device.cc
#include “device.hh

Device abstraction layer implementation.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file device.hh
#include <cstdint>
#include <string>

Device abstraction layer for runtime device representation.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2024

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file memory_space.hh
#include <type_traits>
#include “core/enums.hh

Memory space definitions for GPU-portable memory management.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

19 Dec 2024

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file cartesian_communicator.cc
#include “core/coordinates.hh
#include “core/exception.hh
#include “core/types.hh
#include “mpi/communicator.hh
#include <cstring>
#include <numeric>
#include <vector>
file cartesian_communicator.hh
#include “core/coordinates.hh
#include “core/type_descriptor.hh
#include “mpi/communicator.hh

Cartesian domain decomposition communicator for structured grids.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file cartesian_decomposition.cc
#include <cassert>
#include <cstring>
#include <iterator>
#include “core/coordinates.hh
#include “core/enums.hh
#include “core/type_descriptor.hh
#include “field/field.hh
file cartesian_decomposition.hh
#include “core/coordinates.hh
#include “mpi/communicator.hh
#include “mpi/decomposition.hh
file communicator.cc
#include “mpi/communicator.hh

implementation for mpi abstraction layer

Author

Till Junge till.junge@epfl.ch

Date

02 Oct 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file communicator.hh
#include <cassert>
#include <type_traits>
#include “Eigen/Dense”
#include “core/types.hh
#include “core/exception.hh

abstraction layer for the distributed memory communicator object

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

07 Mar 2018

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file decomposition.hh
#include “core/types.hh
file type_descriptor_mpi.cc
#include “type_descriptor_mpi.hh

MPI type conversion implementations for TypeDescriptor.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2025

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file type_descriptor_mpi.hh
#include “core/type_descriptor.hh

MPI type conversions for TypeDescriptor.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

29 Dec 2024

This header provides conversion functions between TypeDescriptor and MPI_Datatype. It is only available when MPI support is enabled (WITH_MPI).

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file convolution_kernels_cpu.hh
#include “core/types.hh
#include “memory/array.hh

CPU implementations of convolution kernels.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

19 Dec 2024

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file convolution_kernels_gpu.hh

Unified CUDA/HIP implementations of convolution kernels.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

25 Dec 2024

This file provides GPU implementations that work with both CUDA and HIP backends. The kernel code is identical; only the launch mechanism and runtime API differ, which are abstracted via macros.

Copyright © 2024 Lars Pastewka

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file fem_gradient_2d.cc
#include “fem_gradient_2d.hh
#include “core/exception.hh
file fem_gradient_2d.hh
#include “core/types.hh
#include “field/field_typed.hh
#include “memory/memory_space.hh
#include “operators/linear.hh
#include <array>
#include <vector>
file fem_gradient_3d.cc
#include “fem_gradient_3d.hh
#include “core/exception.hh
file fem_gradient_3d.hh
#include “core/types.hh
#include “field/field_typed.hh
#include “memory/memory_space.hh
#include “operators/linear.hh
#include <array>
#include <vector>
file fem_gradient_gpu.cc
#include “fem_gradient_2d.hh
#include “fem_gradient_3d.hh
file generic.cc
#include “operators/generic.hh
#include “core/types.hh
#include “grid/index_ops.hh
#include “grid/pixels.hh
#include “util/math.hh
#include “grid/iterators.hh
#include “core/exception.hh
#include <sstream>
#include <cmath>
file generic.hh
#include “core/coordinates.hh
#include “operators/linear.hh
#include “Eigen/Dense”
#include <vector>
#include <optional>
#include <span>
file generic_gpu.cc
#include <cassert>
#include “operators/generic.hh
file kernel_dispatcher.hh
#include “memory/memory_space.hh
#include “memory/array.hh
file laplace_2d.cc
#include “laplace_2d.hh
#include “core/exception.hh
file laplace_2d.hh
#include “core/types.hh
#include “field/field_typed.hh
#include “memory/memory_space.hh
#include “operators/linear.hh
file laplace_3d.cc
#include “laplace_3d.hh
#include “core/exception.hh
file laplace_3d.hh
#include “core/types.hh
#include “field/field_typed.hh
#include “memory/memory_space.hh
#include “operators/linear.hh
file laplace_gpu.cc
#include “core/types.hh
#include <vector>
file linear.hh
#include “core/types.hh
#include “field/field_typed.hh
file isotropic_stiffness_2d.cc
#include “core/exception.hh
file isotropic_stiffness_2d.hh
#include “core/types.hh
#include “field/field_typed.hh
#include “memory/memory_space.hh
#include <array>
#include <vector>
file isotropic_stiffness_3d.cc
#include “core/exception.hh
file isotropic_stiffness_3d.hh
#include “core/types.hh
#include “field/field_typed.hh
#include “memory/memory_space.hh
#include <array>
#include <vector>
file isotropic_stiffness_gpu.cc
#include “core/exception.hh
file eigen_checks.hh
#include “../core/types.hh
#include “math.hh
#include “Eigen/Dense”
#include <type_traits>

Type traits for Eigen matrices.

Author

Till Junge till.junge@epfl.ch

Date

20 Sep 2017

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

  • Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file math.hh
#include “../core/types.hh
#include <numeric>
#include <type_traits>

Mathematical utilities for muGrid.

Author

Till Junge till.junge@epfl.ch

Date

24 Jan 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file python_helpers.hh
#include <pybind11/eigen.h>
#include <pybind11/numpy.h>
#include “grid/index_ops.hh
#include “core/coordinates.hh
#include “fft/fft_utils.hh

Helper classes for Python bindings.

Author

Lars Pastewka lars.pastewka@imtek.uni-freiburg.de

Date

10 Apr 2025

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file ref_array.hh
#include <array>
#include <initializer_list>
#include “grid/iterators.hh

convenience class to simulate an array of references

Author

Till Junge till.junge@epfl.ch

Date

04 Dec 2018

Copyright © 2018 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file ref_vector.hh
#include <vector>

convenience class providing a vector of references

Author

Till Junge till.junge@epfl.ch

Date

21 Aug 2019

Copyright © 2019 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file T4_map_proxy.hh
#include “util/math.hh
#include “Eigen/Dense”
#include “Eigen/src/Core/util/Constants.h”
#include <type_traits>

Map type to allow fourth-order tensor-like maps on 2D matrices.

Author

Till Junge till.junge@altermail.ch

Date

19 Nov 2017

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

  • Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

file tensor_algebra.hh
#include “core/types.hh
#include “util/T4_map_proxy.hh
#include “util/eigen_checks.hh
#include “Eigen/Dense”
#include “unsupported/Eigen/CXX11/Tensor”
#include <type_traits>

collection of compile-time quantities and algrebraic functions for tensor operations

Author

Till Junge till.junge@epfl.ch

Date

05 Nov 2017

Copyright © 2017 Till Junge

µGrid is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3, or (at your option) any later version.

µGrid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with µGrid; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,

  • Boston, MA 02111-1307, USA.

Additional permission under GNU GPL version 3 section 7

If you modify this Program, or any covered work, by linking or combining it with proprietary FFT implementations or numerical libraries, containing parts covered by the terms of those libraries’ licenses, the licensors of this Program grant you additional permission to convey the resulting work.

group Coordinate types

Type Selection Guide:

  • GridIndex<Dim>: Compile-time dimension grid indices (for templates)

  • GridPoint<Dim>: Compile-time dimension physical coordinates

  • DynGridIndex: Runtime dimension grid indices (Python API, config)

  • GridShape: Alias for DynGridIndex, semantic clarity for shapes

Typedefs

template<size_t Dim>
using GridIndex = std::array<Index_t, Dim>

Integer grid indices with compile-time known dimension.

Used for pixel/voxel coordinates, grid sizes, and strides in performance-critical templated code where the spatial dimension is known at compile time.

Template Parameters:

Dim – The spatial dimension (1, 2, or 3)

template<size_t Dim>
using GridPoint = std::array<Real, Dim>

Real-valued spatial coordinates with compile-time known dimension.

Used for physical space coordinates and domain lengths in performance-critical templated code.

Template Parameters:

Dim – The spatial dimension (1, 2, or 3)

group Scalar types

Typedefs

typedef int Dim_t

A type alias for signed integers used for static dimensions.

This type alias is used to represent signed integers for static dimensions in the µGrid codebase. It is used for consistency throughout the code. It is also capable of representing -1, which can be used to denote unknown or undefined dimensions.

typedef std::ptrdiff_t Index_t

A type alias for std::ptrdiff_t used for size-related values.

This type alias is used to represent size-related values in the µGrid codebase. It ensures compatibility with Eigen’s indexing system and supports large arrays that exceed the range of Dim_t. For example, arrays with dimensions 65536 × 65536 would overflow Dim_t, so Index_t is used instead.

typedef std::size_t Size_t

A type alias for std::size_t used for size-related values.

This type alias is used to represent unsigned size-related values in the µGrid codebase. It is typically used for indexing and size calculations where negative values are not expected.

using Uint = unsigned int

type to use in math for unsigned integers

using Int = int

type to use in math for signed integers

using Real = double

type to use in math for real numbers

typedef std::complex<double> Complex

type to use in math for complex numbers

dir /home/runner/work/muGrid/muGrid/src/libmugrid/collection
dir /home/runner/work/muGrid/muGrid/src/libmugrid/core
dir /home/runner/work/muGrid/muGrid/src/libmugrid/fft
dir /home/runner/work/muGrid/muGrid/src/libmugrid/field
dir /home/runner/work/muGrid/muGrid/src/libmugrid/grid
dir /home/runner/work/muGrid/muGrid/src/libmugrid/io
dir /home/runner/work/muGrid/muGrid/src/libmugrid
dir /home/runner/work/muGrid/muGrid/src/libmugrid/linalg
dir /home/runner/work/muGrid/muGrid/src/libmugrid/memory
dir /home/runner/work/muGrid/muGrid/src/libmugrid/mpi
dir /home/runner/work/muGrid/muGrid/src/libmugrid/operators
dir /home/runner/work/muGrid/muGrid/src/libmugrid/fft/pocketfft
dir /home/runner/work/muGrid/muGrid/src/libmugrid/operators/solids
dir /home/runner/work/muGrid/muGrid/src
dir /home/runner/work/muGrid/muGrid/src/libmugrid/util