specfem::point::impl::field¶
Parent class for all field datatypes at a quadrature point.
-
template<specfem::element::dimension_tag DimensionTag, specfem::element::medium_tag MediumTag, specfem::data_access::DataClassType DataClass, bool UseSIMD>
class field : public specfem::data_access::Accessor<specfem::datatype::AccessorType::point, DataClass, DimensionTag, UseSIMD>¶ Point field accessor for spectral element field data storage and manipulation.
This class provides a strongly-typed interface for accessing and manipulating field data at individual points within spectral elements. It serves as a data container that holds field values (displacement, velocity, acceleration, etc.) with compile-time knowledge of the spatial dimension, medium type, data class, and SIMD optimization settings.
The field class is designed to work seamlessly with the SPECFEM++ assembly system, providing type-safe access to field components while maintaining optimal performance through Kokkos integration and optional SIMD vectorization.
// Example: Creating displacement field accessors for 2D elastic medium using DisplacementField = specfem::point::impl::field< specfem::element::dimension_tag::dim2, specfem::element::medium_tag::elastic, specfem::data_access::DataClassType::displacement, false>; // No SIMD // Initialize with zero displacement DisplacementField u_field(0.0); // Set displacement components u_field(0) = 1.5; // x-component u_field(1) = 2.3; // z-component (2D) // Access displacement values auto ux = u_field(0); auto uz = u_field(1);
// Example: Creating velocity field with SIMD optimization using VelocityField = specfem::point::impl::field< specfem::element::dimension_tag::dim3, specfem::element::medium_tag::acoustic, specfem::data_access::DataClassType::velocity, true>; // Enable SIMD // Initialize velocity field with specific components VelocityField v_field(1.0, 2.0, 3.0); // vx, vy, vz // Use in assembly operations specfem::assembly::load_on_device(point_index, field_container, v_field);
Note
This class inherits from specfem::data_access::Accessor to provide consistent interface and type traits for the SPECFEM++ data access system.
- Template Parameters:
DimensionTag – The spatial dimension (dim2 or dim3) of the field
MediumTag – The medium type (acoustic, elastic, poroelastic, etc.)
DataClass – The type of field data (displacement, velocity, acceleration, mass_matrix)
UseSIMD – Whether to enable SIMD vectorization for performance optimization
Public Types
-
using simd = typename base_type::template simd<type_real>¶
SIMD type for vectorized operations.
-
using value_type = typename base_type::template vector_type<type_real, components>¶
Vector type for storing field component values.
-
template<typename T, int N = -1>
using scalar_type = typename impl::scalar_type_helper<T, N, UseSIMD>::type¶ Scalar field storage for single point.
With the default N=-1 returns a single SIMD scalar (
simd<T>::datatype). With an explicit N returns a fixed-size array of N SIMD scalars (VectorPointViewType<T, N, UseSIMD>), useful for per-SLS-mechanism arrays.- Template Parameters:
T – Base data type
N – Array size; -1 (default) means a single scalar
-
template<typename T, int dimension>
using vector_type = typename specfem::datatype::VectorPointViewType<T, dimension, UseSIMD>¶ Vector field storage for single point.
- Template Parameters:
T – Base data type
dimension – Vector dimension (2D/3D)
-
template<typename T, int components, int dimension>
using tensor_type = typename specfem::datatype::TensorPointViewType<T, components, dimension, UseSIMD>¶ Tensor field storage for single point.
- Template Parameters:
T – Base data type
components – Number of tensor components
dimension – Spatial dimension
Public Functions
-
field() = default¶
Default constructor - creates field with uninitialized values.
-
inline const value_type &get_data() const¶
Access internal field data storage.
- Returns:
const reference to the internal value_type storing field components
-
template<typename U, std::enable_if_t<std::is_convertible_v<U, typename value_type::value_type>, int> = 0>
inline constexpr field(const U initializer)¶ Construct field with uniform initialization across all components.
Initializes all field components to the same scalar value. This is useful for creating zero-initialized fields or fields with uniform values.
// Create zero-initialized displacement field DisplacementField u_field(0.0); // Create field with uniform value VelocityField v_field(1.5); // All components = 1.5
- Template Parameters:
U – Type convertible to the field’s component type
- Parameters:
initializer – The value to assign to all field components
- Pre:
U must be convertible to typename value_type::value_type
-
template<typename U, typename ...Args, typename = std::enable_if_t<std::is_same_v<U, value_type>, int>>
inline constexpr field(const U &initializer)¶ Construct field from value_type object.
Directly initializes the field from a compatible value_type object. This allows construction from pre-computed vector objects.
- Template Parameters:
U – Type that must match value_type exactly
- Parameters:
initializer – The value_type object to copy from
- Pre:
U must be exactly the same type as value_type
-
template<typename ...Args, typename = std::enable_if_t<sizeof...(Args) == components>>
inline constexpr field(Args&&... args)¶ Construct field with component-wise initialization.
Allows direct initialization of field components by providing individual values for each component. The number of arguments must exactly match the number of field components.
// 2D displacement field: ux, uz DisplacementField u_field(1.5, 2.3); // 3D velocity field: vx, vy, vz VelocityField v_field(0.1, 0.2, 0.3);
- Template Parameters:
Args – Types of the component values (must match component count)
- Parameters:
args – Individual values for each field component
- Pre:
sizeof…(Args) must equal the number of field components
-
inline const value_type::value_type &operator()(const std::size_t icomp) const¶
Access field component by index (const version).
Provides read-only access to individual field components using zero-based indexing. For 2D problems: 0=x, 1=z. For 3D problems: 0=x, 1=y, 2=z.
DisplacementField u_field(1.5, 2.3); auto ux = u_field(0); // x-component = 1.5 auto uz = u_field(1); // z-component = 2.3
- Parameters:
icomp – Component index (0 to components-1)
- Returns:
const reference to the component value
- Pre:
icomp must be less than the number of components
-
inline value_type::value_type &operator()(const std::size_t icomp)¶
Access field component by index (mutable version).
Provides read-write access to individual field components using zero-based indexing. Allows modification of field component values.
DisplacementField u_field; u_field(0) = 1.5; // Set x-component u_field(1) = 2.3; // Set z-component
- Parameters:
icomp – Component index (0 to components-1)
- Returns:
mutable reference to the component value
- Pre:
icomp must be less than the number of components
-
inline bool operator==(const field &other) const¶
Equality comparison operator.
Compares two field objects for exact equality by comparing their internal data storage.
- Parameters:
other – The field object to compare against
- Returns:
true if all components are exactly equal, false otherwise
-
inline bool operator!=(const field &other) const¶
Inequality comparison operator.
Compares two field objects for inequality.
- Parameters:
other – The field object to compare against
- Returns:
true if any component differs, false if all components are equal
-
inline constexpr auto &operator*=(const typename value_type::value_type &other)¶
Multiplication assignment operator with constant value.
Multiply by a constant value and assign the result to this field.
- Parameters:
other – The factor to be multiplied with
- Returns:
reference to this field after multiplication
-
inline std::string print() const¶
Output a string representation of the field components.
Outputs the values of all field components to the specified output stream. Each component is printed in order, enclosed in square brackets. If SIMD the SIMD values are printed in curly brackets.
Public Static Attributes
-
static constexpr int components = specfem::element::attributes<DimensionTag, MediumTag>::components¶
Number of field components based on dimension and medium type.
-
static constexpr auto accessor_type = specfem::datatype::AccessorType::point¶
Accessor pattern identifier.
-
static constexpr auto dimension_tag = DimensionTag¶
Spatial dimension.