Skip to content

Commit fdc4381

Browse files
Merge pull request #1622 from PrincetonUniversity/issue-1593-part-2
Issue-1593 - 2 - Updates macros and containers
2 parents 01bfa8f + 87838ee commit fdc4381

File tree

47 files changed

+548
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+548
-322
lines changed

core/specfem/assembly/assembly/dim2/assembly.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,21 @@ specfem::assembly::assembly<specfem::dimension::type::dim2>::print() const {
109109
bool is_psv = false;
110110

111111
FOR_EACH_IN_PRODUCT(
112-
(DIMENSION_TAG(DIM2),
113-
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC, POROELASTIC,
114-
ELASTIC_PSV_T),
115-
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT)),
112+
(DIMENSION_TAG(DIM2), MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC,
113+
POROELASTIC, ELASTIC_PSV_T)),
116114
{
117115
// Getting the number of elements per medium
118-
int n_elements = this->element_types.get_number_of_elements(
119-
_medium_tag_, _property_tag_);
116+
int n_elements =
117+
this->element_types.get_number_of_elements(_medium_tag_);
120118

121119
// Printing the number of elements if more than 0
122120
if (n_elements > 0) {
123121
// Adding the number of elements to the total
124122
total_elements += n_elements;
125123

126124
message << " Total number of elements of type "
127-
<< specfem::element::to_string(_medium_tag_, _property_tag_)
128-
<< " : " << n_elements << "\n";
125+
<< specfem::element::to_string(_medium_tag_) << " : "
126+
<< n_elements << "\n";
129127
if (_medium_tag_ == specfem::element::medium_tag::elastic_sh) {
130128
is_sh = true;
131129
} else if (_medium_tag_ ==

core/specfem/assembly/assembly/dim2/compute_wavefield/compute_wavefield.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ specfem::assembly::assembly<specfem::dimension::type::dim2>::
9191
(DIMENSION_TAG(DIM2),
9292
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC, POROELASTIC,
9393
ELASTIC_PSV_T),
94-
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT)),
94+
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT),
95+
ATTENUATION_TAG(NONE)),
9596
{
9697
if constexpr (_dimension_tag_ == specfem::dimension::type::dim2) {
9798
get_wavefield_on_entire_grid<_medium_tag_, _property_tag_>(

core/specfem/assembly/assembly/dim3/assembly.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,20 @@ specfem::assembly::assembly<specfem::dimension::type::dim3>::print() const {
8787

8888
int total_elements = 0;
8989

90-
FOR_EACH_IN_PRODUCT(
91-
(DIMENSION_TAG(DIM3), MEDIUM_TAG(ELASTIC, ACOUSTIC),
92-
PROPERTY_TAG(ISOTROPIC)),
93-
{
94-
// Getting the number of elements per medium
95-
int n_elements = this->element_types.get_number_of_elements(
96-
_medium_tag_, _property_tag_);
97-
98-
// Printing the number of elements if more than 0
99-
if (n_elements > 0) {
100-
// Adding the number of elements to the total
101-
total_elements += n_elements;
102-
103-
message << " Total number of elements of type "
104-
<< specfem::element::to_string(_medium_tag_, _property_tag_)
105-
<< " : " << n_elements << "\n";
106-
};
107-
})
90+
FOR_EACH_IN_PRODUCT((DIMENSION_TAG(DIM3), MEDIUM_TAG(ELASTIC, ACOUSTIC)), {
91+
// Getting the number of elements per medium
92+
int n_elements = this->element_types.get_number_of_elements(_medium_tag_);
93+
94+
// Printing the number of elements if more than 0
95+
if (n_elements > 0) {
96+
// Adding the number of elements to the total
97+
total_elements += n_elements;
98+
99+
message << " Total number of elements of type "
100+
<< specfem::element::to_string(_medium_tag_) << " : "
101+
<< n_elements << "\n";
102+
};
103+
})
108104

109105
if (total_elements == mesh.nspec) {
110106
message << " All elements accounted for.\n";

core/specfem/assembly/assembly/dim3/compute_wavefield/compute_wavefield.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ specfem::assembly::assembly<specfem::dimension::type::dim3>::
9090

9191
FOR_EACH_IN_PRODUCT(
9292
(DIMENSION_TAG(DIM3), MEDIUM_TAG(ELASTIC, ACOUSTIC),
93-
PROPERTY_TAG(ISOTROPIC)),
93+
PROPERTY_TAG(ISOTROPIC), ATTENUATION_TAG(NONE)),
9494
{
9595
if constexpr (_dimension_tag_ == specfem::dimension::type::dim3) {
9696
get_wavefield_on_entire_grid<_medium_tag_, _property_tag_>(

core/specfem/assembly/assembly/impl/helper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ class helper {
8888
// Get the element grid (ngllx, nglly, ngllz)
8989
const auto &element_grid = assembly.mesh.element_grid;
9090

91-
const auto elements =
92-
assembly.element_types.get_elements_on_device(medium_tag, property_tag);
91+
const auto elements = assembly.element_types.get_elements_on_device(
92+
medium_tag, property_tag, specfem::element::attenuation_tag::none);
9393

9494
const int nelements = elements.extent(0);
9595

core/specfem/assembly/element_types/dim2/element_types.cpp

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ specfem::assembly::element_types<specfem::dimension::type::dim2>::element_types(
77
: nspec(nspec),
88
medium_tags("specfem::assembly::element_types::medium_tags", nspec),
99
property_tags("specfem::assembly::element_types::property_tags", nspec),
10+
attenuation_tags("specfem::assembly::element_types::attenuation_tags",
11+
nspec),
1012
boundary_tags("specfem::assembly::element_types::boundary_tags", nspec) {
1113

1214
for (int ispec = 0; ispec < nspec; ispec++) {
1315
const int ispec_mesh = mesh.compute_to_mesh(ispec);
1416
medium_tags(ispec) = tags.tags_container(ispec_mesh).medium_tag;
1517
property_tags(ispec) = tags.tags_container(ispec_mesh).property_tag;
18+
attenuation_tags(ispec) = tags.tags_container(ispec_mesh).attenuation_tag;
1619
boundary_tags(ispec) = tags.tags_container(ispec_mesh).boundary_tag;
1720
}
1821

@@ -43,31 +46,34 @@ specfem::assembly::element_types<specfem::dimension::type::dim2>::element_types(
4346
(DIMENSION_TAG(DIM2),
4447
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC, POROELASTIC,
4548
ELASTIC_PSV_T),
46-
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT)),
47-
CAPTURE(elements, h_elements) {
49+
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT),
50+
ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)),
51+
CAPTURE(material_elements, h_material_elements) {
4852
int count = 0;
4953
int index = 0;
5054

5155
for (int ispec = 0; ispec < nspec; ispec++) {
5256
if (medium_tags(ispec) == _medium_tag_ &&
53-
property_tags(ispec) == _property_tag_) {
57+
property_tags(ispec) == _property_tag_ &&
58+
attenuation_tags(ispec) == _attenuation_tag_) {
5459
count++;
5560
}
5661
}
5762

58-
_elements_ =
63+
_material_elements_ =
5964
IndexViewType("specfem::assembly::element_types::elements", count);
60-
_h_elements_ = Kokkos::create_mirror_view(_elements_);
65+
_h_material_elements_ = Kokkos::create_mirror_view(_material_elements_);
6166

6267
for (int ispec = 0; ispec < nspec; ispec++) {
6368
if (medium_tags(ispec) == _medium_tag_ &&
64-
property_tags(ispec) == _property_tag_) {
65-
_h_elements_(index) = ispec;
69+
property_tags(ispec) == _property_tag_ &&
70+
attenuation_tags(ispec) == _attenuation_tag_) {
71+
_h_material_elements_(index) = ispec;
6672
index++;
6773
}
6874
}
6975

70-
Kokkos::deep_copy(_elements_, _h_elements_);
76+
Kokkos::deep_copy(_material_elements_, _h_material_elements_);
7177
})
7278

7379
FOR_EACH_IN_PRODUCT(
@@ -139,37 +145,43 @@ Kokkos::View<int *, Kokkos::DefaultExecutionSpace> specfem::assembly::
139145
Kokkos::View<int *, Kokkos::DefaultHostExecutionSpace> specfem::assembly::
140146
element_types<specfem::dimension::type::dim2>::get_elements_on_host(
141147
const specfem::element::medium_tag medium_tag,
142-
const specfem::element::property_tag property_tag) const {
148+
const specfem::element::property_tag property_tag,
149+
const specfem::element::attenuation_tag attenuation_tag) const {
143150

144-
FOR_EACH_IN_PRODUCT(
145-
(DIMENSION_TAG(DIM2),
146-
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC, POROELASTIC,
147-
ELASTIC_PSV_T),
148-
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT)),
149-
CAPTURE(h_elements) {
150-
if (_medium_tag_ == medium_tag && _property_tag_ == property_tag) {
151-
return _h_elements_;
152-
}
153-
})
151+
FOR_EACH_IN_PRODUCT((DIMENSION_TAG(DIM2),
152+
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC,
153+
POROELASTIC, ELASTIC_PSV_T),
154+
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT),
155+
ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)),
156+
CAPTURE(h_material_elements) {
157+
if (_medium_tag_ == medium_tag &&
158+
_property_tag_ == property_tag &&
159+
_attenuation_tag_ == attenuation_tag) {
160+
return _h_material_elements_;
161+
}
162+
})
154163

155164
throw std::runtime_error("Medium tag or property tag not found");
156165
}
157166

158167
Kokkos::View<int *, Kokkos::DefaultExecutionSpace> specfem::assembly::
159168
element_types<specfem::dimension::type::dim2>::get_elements_on_device(
160169
const specfem::element::medium_tag medium_tag,
161-
const specfem::element::property_tag property_tag) const {
170+
const specfem::element::property_tag property_tag,
171+
const specfem::element::attenuation_tag attenuation_tag) const {
162172

163-
FOR_EACH_IN_PRODUCT(
164-
(DIMENSION_TAG(DIM2),
165-
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC, POROELASTIC,
166-
ELASTIC_PSV_T),
167-
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT)),
168-
CAPTURE(elements) {
169-
if (_medium_tag_ == medium_tag && _property_tag_ == property_tag) {
170-
return _elements_;
171-
}
172-
})
173+
FOR_EACH_IN_PRODUCT((DIMENSION_TAG(DIM2),
174+
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC,
175+
POROELASTIC, ELASTIC_PSV_T),
176+
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT),
177+
ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)),
178+
CAPTURE(material_elements) {
179+
if (_medium_tag_ == medium_tag &&
180+
_property_tag_ == property_tag &&
181+
_attenuation_tag_ == attenuation_tag) {
182+
return _material_elements_;
183+
}
184+
})
173185

174186
throw std::runtime_error("Medium tag or property tag not found");
175187
}

core/specfem/assembly/element_types/dim2/element_types.hpp

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ template <> struct element_types<specfem::dimension::type::dim2> {
7676
using BoundaryViewType = Kokkos::View<specfem::element::boundary_tag *,
7777
Kokkos::DefaultHostExecutionSpace>;
7878

79+
/**
80+
* @brief Kokkos view type for storing attenuation tags in host memory.
81+
*
82+
* Stores the attenuation type (none, constant_isotropic, etc.) for each
83+
* spectral element. Host storage enables efficient attenuation property setup
84+
* and validation.
85+
*/
86+
using AttenuationTagViewType =
87+
Kokkos::View<specfem::element::attenuation_tag *,
88+
Kokkos::DefaultHostExecutionSpace>;
89+
7990
/**
8091
* @brief Kokkos view type for storing element indices in device memory.
8192
*
@@ -93,9 +104,10 @@ template <> struct element_types<specfem::dimension::type::dim2> {
93104
constexpr static auto dimension_tag =
94105
specfem::dimension::type::dim2; ///< Dimension tag
95106

96-
MediumTagViewType medium_tags; ///< View to store medium tags
97-
PropertyTagViewType property_tags; ///< View to store property tags
98-
BoundaryViewType boundary_tags; ///< View to store boundary tags
107+
MediumTagViewType medium_tags; ///< View to store medium tags
108+
PropertyTagViewType property_tags; ///< View to store property tags
109+
BoundaryViewType boundary_tags; ///< View to store boundary tags
110+
AttenuationTagViewType attenuation_tags; ///< View to store attenuation tags
99111

100112
/**
101113
* @brief Default constructor.
@@ -164,9 +176,10 @@ template <> struct element_types<specfem::dimension::type::dim2> {
164176
* @param property Property type (isotropic, anisotropic, isotropic_cosserat)
165177
* @return Kokkos view containing element indices for host access
166178
*/
167-
Kokkos::View<int *, Kokkos::DefaultHostExecutionSpace>
168-
get_elements_on_host(const specfem::element::medium_tag tag,
169-
const specfem::element::property_tag property) const;
179+
Kokkos::View<int *, Kokkos::DefaultHostExecutionSpace> get_elements_on_host(
180+
const specfem::element::medium_tag tag,
181+
const specfem::element::property_tag property,
182+
const specfem::element::attenuation_tag attenuation) const;
170183

171184
/**
172185
* @brief Get count of elements with specified medium and property types.
@@ -177,8 +190,9 @@ template <> struct element_types<specfem::dimension::type::dim2> {
177190
*/
178191
int get_number_of_elements(
179192
const specfem::element::medium_tag tag,
180-
const specfem::element::property_tag property) const {
181-
return get_elements_on_host(tag, property).extent(0);
193+
const specfem::element::property_tag property,
194+
const specfem::element::attenuation_tag attenuation) const {
195+
return get_elements_on_host(tag, property, attenuation).extent(0);
182196
}
183197

184198
/**
@@ -189,9 +203,10 @@ template <> struct element_types<specfem::dimension::type::dim2> {
189203
* @param property Property type (isotropic, anisotropic, isotropic_cosserat)
190204
* @return Kokkos view containing element indices for device access
191205
*/
192-
Kokkos::View<int *, Kokkos::DefaultExecutionSpace>
193-
get_elements_on_device(const specfem::element::medium_tag tag,
194-
const specfem::element::property_tag property) const;
206+
Kokkos::View<int *, Kokkos::DefaultExecutionSpace> get_elements_on_device(
207+
const specfem::element::medium_tag tag,
208+
const specfem::element::property_tag property,
209+
const specfem::element::attenuation_tag attenuation) const;
195210

196211
/**
197212
* @brief Get elements with specified medium, property, and boundary types in
@@ -270,6 +285,10 @@ template <> struct element_types<specfem::dimension::type::dim2> {
270285
return boundary_tags(ispec);
271286
}
272287

288+
specfem::element::attenuation_tag get_attenuation_tag(const int ispec) const {
289+
return attenuation_tags(ispec);
290+
}
291+
273292
private:
274293
FOR_EACH_IN_PRODUCT((DIMENSION_TAG(DIM2),
275294
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC,
@@ -280,10 +299,15 @@ template <> struct element_types<specfem::dimension::type::dim2> {
280299
FOR_EACH_IN_PRODUCT((DIMENSION_TAG(DIM2),
281300
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC,
282301
POROELASTIC, ELASTIC_PSV_T),
283-
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC,
284-
ISOTROPIC_COSSERAT)),
285-
DECLARE((IndexViewType, elements),
286-
(IndexViewType::HostMirror, h_elements)))
302+
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT),
303+
ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)),
304+
DECLARE((IndexViewType, material_elements),
305+
(IndexViewType::HostMirror,
306+
h_material_elements))) /// This is a temporary
307+
/// fix since none
308+
/// attenuation tag
309+
/// conflicts with none
310+
/// boundary tag
287311

288312
FOR_EACH_IN_PRODUCT((DIMENSION_TAG(DIM2),
289313
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC,

0 commit comments

Comments
 (0)