|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include "domain_accessor.hpp" |
| 4 | +#include "enumerations/medium.hpp" |
| 5 | +#include "specfem/medium_container.hpp" |
| 6 | +#include <Kokkos_Core.hpp> |
| 7 | + |
| 8 | +namespace specfem::assembly { |
| 9 | +class mesh_to_compute_mapping; |
| 10 | +template <specfem::dimension::type Dimension> struct mesh; |
| 11 | +} // namespace specfem::assembly |
| 12 | + |
| 13 | +namespace specfem::mesh { |
| 14 | +template <specfem::dimension::type Dimension> struct materials; |
| 15 | +} |
| 16 | + |
| 17 | +namespace specfem::assembly::impl { |
| 18 | + |
| 19 | +/** |
| 20 | + * @brief Material properties storage for spectral elements at quadrature |
| 21 | + * points. |
| 22 | + * |
| 23 | + * Template container that stores material properties (density, elastic moduli, |
| 24 | + * etc.) for all quadrature points within spectral elements. Specializes for |
| 25 | + * different dimension/medium/property combinations and provides efficient |
| 26 | + * Kokkos-based storage. |
| 27 | + * |
| 28 | + * Inherits from `properties::data_container` for storage and `impl::Accessor` |
| 29 | + * for element-wise access. Material properties are organized as: |
| 30 | + * - **2D**: properties[nspec][ngllz][ngllx] |
| 31 | + * - **3D**: properties[nspec][ngllz][nglly][ngllx] |
| 32 | + * |
| 33 | + * Template parameters select appropriate specialization: |
| 34 | + * - **DimensionTag**: Spatial dimension (dim2/dim3) |
| 35 | + * - **MediumTag**: Physical medium (acoustic, elastic, poroelastic) |
| 36 | + * - **PropertyTag**: Material symmetry (isotropic, anisotropic) |
| 37 | + * |
| 38 | + * @tparam DimensionTag Spatial dimension |
| 39 | + * @tparam MediumTag Physical medium type |
| 40 | + * @tparam PropertyTag Material property type |
| 41 | + */ |
| 42 | +template <specfem::dimension::type DimensionTag, |
| 43 | + specfem::element::medium_tag MediumTag, |
| 44 | + specfem::element::property_tag PropertyTag> |
| 45 | +struct domain_properties; |
| 46 | + |
| 47 | +/** |
| 48 | + * @brief 2D material properties container specialization. |
| 49 | + * |
| 50 | + * Stores material properties at quadrature points for 2D spectral elements. |
| 51 | + * Data layout: properties[element][ngllz][ngllx] where ngllz and ngllx are |
| 52 | + * quadrature points in vertical and horizontal directions. |
| 53 | + * |
| 54 | + * @tparam MediumTag Physical medium (acoustic, elastic, poroelastic) |
| 55 | + * @tparam PropertyTag Material symmetry (isotropic, anisotropic, cosserat) |
| 56 | + */ |
| 57 | +template <specfem::element::medium_tag MediumTag, |
| 58 | + specfem::element::property_tag PropertyTag> |
| 59 | +struct domain_properties<specfem::dimension::type::dim2, MediumTag, PropertyTag> |
| 60 | + : public specfem::medium_container::properties::data_container< |
| 61 | + specfem::dimension::type::dim2, MediumTag, PropertyTag>, |
| 62 | + public DomainAccessor<specfem::dimension::type::dim2, |
| 63 | + domain_properties<specfem::dimension::type::dim2, |
| 64 | + MediumTag, PropertyTag> > { |
| 65 | + |
| 66 | + /// Base data container type for property storage |
| 67 | + using base_type = specfem::medium_container::properties::data_container< |
| 68 | + specfem::dimension::type::dim2, MediumTag, PropertyTag>; |
| 69 | + using base_type::base_type; |
| 70 | + |
| 71 | + constexpr static auto dimension_tag = |
| 72 | + base_type::dimension_tag; ///< 2D spatial dimension |
| 73 | + constexpr static auto medium_tag = |
| 74 | + base_type::medium_tag; ///< Physical medium type |
| 75 | + constexpr static auto property_tag = |
| 76 | + base_type::property_tag; ///< Material property type |
| 77 | + |
| 78 | + /// Default constructor for empty container |
| 79 | + domain_properties() = default; |
| 80 | + |
| 81 | + /** |
| 82 | + * @brief Construct 2D properties from mesh and material data. |
| 83 | + * |
| 84 | + * Extracts material properties from mesh materials and stores them |
| 85 | + * at all quadrature points for the specified spectral elements. |
| 86 | + * |
| 87 | + * @param elements Element indices to initialize |
| 88 | + * @param mesh 2D mesh geometry and connectivity |
| 89 | + * @param ngllz Number of vertical quadrature points |
| 90 | + * @param ngllx Number of horizontal quadrature points |
| 91 | + * @param materials Material database indexed by element |
| 92 | + * @param has_gll_model Skip material assignment for GLL models |
| 93 | + * @param property_index_mapping Element to property mapping |
| 94 | + */ |
| 95 | + domain_properties( |
| 96 | + const Kokkos::View<int *, Kokkos::DefaultHostExecutionSpace> elements, |
| 97 | + const specfem::assembly::mesh<dimension_tag> &mesh, const int ngllz, |
| 98 | + const int ngllx, const specfem::mesh::materials<dimension_tag> &materials, |
| 99 | + const bool has_gll_model, |
| 100 | + const specfem::kokkos::HostView1d<int> property_index_mapping); |
| 101 | + |
| 102 | + /// Device value access disabled for this container type |
| 103 | + template <typename PointValues, typename IndexType> |
| 104 | + KOKKOS_FORCEINLINE_FUNCTION void |
| 105 | + add_device_values(const IndexType &index, PointValues &values) const = delete; |
| 106 | + |
| 107 | + /// Host value access disabled for this container type |
| 108 | + template <typename PointValues, typename IndexType> |
| 109 | + KOKKOS_FORCEINLINE_FUNCTION void |
| 110 | + add_host_values(const IndexType &index, PointValues &values) const = delete; |
| 111 | +}; |
| 112 | + |
| 113 | +/** |
| 114 | + * @brief 3D material properties container specialization. |
| 115 | + * |
| 116 | + * Stores material properties at quadrature points for 3D spectral elements. |
| 117 | + * Data layout: properties[element][ngllz][nglly][ngllx] where ngllz, nglly, |
| 118 | + * and ngllx are quadrature points in z, y, and x directions respectively. |
| 119 | + * |
| 120 | + * @tparam MediumTag Physical medium (acoustic, elastic) |
| 121 | + * @tparam PropertyTag Material symmetry (isotropic, anisotropic) |
| 122 | + */ |
| 123 | +template <specfem::element::medium_tag MediumTag, |
| 124 | + specfem::element::property_tag PropertyTag> |
| 125 | +struct domain_properties<specfem::dimension::type::dim3, MediumTag, PropertyTag> |
| 126 | + : public specfem::medium_container::properties::data_container< |
| 127 | + specfem::dimension::type::dim3, MediumTag, PropertyTag>, |
| 128 | + public DomainAccessor<specfem::dimension::type::dim3, |
| 129 | + domain_properties<specfem::dimension::type::dim3, |
| 130 | + MediumTag, PropertyTag> > { |
| 131 | + |
| 132 | + /// Base data container type for property storage |
| 133 | + using base_type = specfem::medium_container::properties::data_container< |
| 134 | + specfem::dimension::type::dim3, MediumTag, PropertyTag>; |
| 135 | + using base_type::base_type; |
| 136 | + |
| 137 | + constexpr static auto dimension_tag = |
| 138 | + base_type::dimension_tag; ///< 3D spatial dimension |
| 139 | + constexpr static auto medium_tag = |
| 140 | + base_type::medium_tag; ///< Physical medium type |
| 141 | + constexpr static auto property_tag = |
| 142 | + base_type::property_tag; ///< Material property type |
| 143 | + |
| 144 | + /// Default constructor for empty container |
| 145 | + domain_properties() = default; |
| 146 | + |
| 147 | + /** |
| 148 | + * @brief Construct 3D properties from mesh and material data. |
| 149 | + * |
| 150 | + * Extracts material properties from mesh materials and stores them |
| 151 | + * at all quadrature points for the specified spectral elements. |
| 152 | + * |
| 153 | + * @param elements Element indices to initialize |
| 154 | + * @param nspec Total number of spectral elements |
| 155 | + * @param ngllz Number of z-direction quadrature points |
| 156 | + * @param nglly Number of y-direction quadrature points |
| 157 | + * @param ngllx Number of x-direction quadrature points |
| 158 | + * @param materials Material database indexed by element |
| 159 | + * @param property_index_mapping Element to property mapping |
| 160 | + */ |
| 161 | + domain_properties( |
| 162 | + const Kokkos::View<int *, Kokkos::DefaultHostExecutionSpace> elements, |
| 163 | + const int nspec, const int ngllz, const int nglly, const int ngllx, |
| 164 | + const specfem::mesh::materials<dimension_tag> &materials, |
| 165 | + const specfem::kokkos::HostView1d<int> property_index_mapping); |
| 166 | + |
| 167 | + /// Device value access disabled for this container type |
| 168 | + template <typename PointValues, typename IndexType> |
| 169 | + KOKKOS_FORCEINLINE_FUNCTION void |
| 170 | + add_device_values(const IndexType &index, PointValues &values) const = delete; |
| 171 | + |
| 172 | + /// Host value access disabled for this container type |
| 173 | + template <typename PointValues, typename IndexType> |
| 174 | + KOKKOS_FORCEINLINE_FUNCTION void |
| 175 | + add_host_values(const IndexType &index, PointValues &values) const = delete; |
| 176 | +}; |
| 177 | + |
| 178 | +} // namespace specfem::assembly::impl |
0 commit comments