Issue 1593 part 3 - Reads attenuation database#1628
Issue 1593 part 3 - Reads attenuation database#1628Rohit-Kakodkar wants to merge 8 commits intodevelfrom
Conversation
- [x] Refactors materials reader - [x] Reads attenuation props - [x] Adds a test for acoustic elastic w attenuation
- Updates ``TYPE_MATCH`` and ``SEQ_FOR_TAGS`` macros so that they are not dependent on naming schemes
There was a problem hiding this comment.
Pull request overview
Adds support for reading constant isotropic attenuation parameters from mesh material databases (2D and 3D), and introduces new 2D unit-test meshes/configurations to exercise attenuation reading.
Changes:
- Refactors 2D material reading to populate a unified
materialscontainer viaadd_material()and to recognize constant isotropic attenuation. - Extends material/container plumbing to track attenuation tags and adds a debug
materials::print()implementation (dim2). - Adds new 2D attenuation test datasets and new mesh test cases (acoustic/elastic and poroelastic).
Reviewed changes
Copilot reviewed 24 out of 27 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit-tests/mesh/dim2/test_config.yaml | Adds new dim2 mesh test cases including attenuation datasets; re-enables EM mesh test entry. |
| tests/unit-tests/mesh/dim2/materials/properties.cpp | Changes derived-properties test behavior when ground truth is missing. |
| tests/unit-tests/mesh/dim2/materials/materials.cpp | Adds ground-truth expectations for attenuation materials; expands attenuation-tag iteration. |
| core/specfem/mesh/dim2/materials/materials.hpp | Adds add_material(), adds constant attenuation tag handling, adds print() declaration, ctor change. |
| core/specfem/mesh/dim2/materials/materials.cpp | Implements materials<dim2>::print(). |
| core/specfem/mesh/dim3/materials/materials.hpp | Initializes n_materials fields; expands to support constant attenuation containers. |
| core/specfem/io/mesh/impl/fortran/dim2/read_material_properties.cpp | Refactors dim2 materials reading to use materials.add_material() and handle attenuation. |
| core/specfem/io/mesh/impl/fortran/dim2/mesh.cpp | Updates material counting iteration to include constant attenuation tags. |
| core/specfem/io/mesh/impl/fortran/dim3/read_materials.cpp | Adds support for reading constant isotropic attenuation for acoustic/elastic in 3D. |
| core/specfem/medium/dim2/*/material.hpp | Adds default ctors for attenuation value structs. |
| core/specfem/macros/material_iterators.hpp | Removes unsupported constant-attenuation combinations from MATERIAL_SYSTEMS_DIM2. |
| tests/unit-tests/data/dim2/* | Adds new attenuation mesh datasets and provenance inputs (poroelastic + fluid/solid). |
Comments suppressed due to low confidence (1)
core/specfem/io/mesh/impl/fortran/dim2/mesh.cpp:202
- This FOR_EACH_IN_PRODUCT includes CONSTANT_ISOTROPIC for electromagnetic_te and elastic_psv_t/isotropic_cosserat combinations, but those medium_container::material specializations don't exist. This will not compile once the macro expands. Iterate only over supported material systems (e.g., MATERIAL_SYSTEMS_DIM2) or otherwise exclude unsupported medium/property combinations from the attenuation cartesian product.
FOR_EACH_IN_PRODUCT(
(DIMENSION_TAG(DIM2),
MEDIUM_TAG(ELASTIC_PSV, ELASTIC_SH, ACOUSTIC, POROELASTIC, ELASTIC_PSV_T,
ELECTROMAGNETIC_TE),
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT),
ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)),
{
total_materials_read += mesh.materials
.get_container<_medium_tag_, _property_tag_,
_attenuation_tag_>()
.element_materials.size();
})
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const auto computed = mesh.materials; | ||
|
|
||
| // Check if Test.name is in properties_ground_truth | ||
| if (properties_ground_truth.find(Test.name) == | ||
| properties_ground_truth.end()) { | ||
| std::ostringstream message; | ||
| message << "No ground truth available for properties of test '" | ||
| << Test.name << "' [" << __FILE__ << ":" << __LINE__ << "]\n"; | ||
| specfem::Logger::info(message.str()); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
The test now logs and continues when no ground-truth entry exists for a test name. This makes it easy for new/renamed tests (including the newly added attenuation cases) to silently skip validation and still pass CI, reducing the value of the unit test. Prefer failing the test when ground truth is missing, or add ground-truth entries for the new attenuation meshes (even if the derived properties are identical to the non-attenuation cases).
| ELASTIC_PSV_T, ELECTROMAGNETIC_TE), | ||
| PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT), | ||
| ATTENUATION_TAG(NONE)), | ||
| ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)), |
There was a problem hiding this comment.
The ATTENUATION_TAG cartesian product was expanded to include CONSTANT_ISOTROPIC for all medium/property combinations, which will instantiate unsupported material types (e.g., electromagnetic_te + constant_isotropic, elastic_psv_t/isotropic_cosserat + constant_isotropic). Those medium_container::material specializations don't exist, so this macro expansion will not compile. Limit iteration to supported material systems (e.g., MATERIAL_SYSTEMS_DIM2) or explicitly exclude unsupported combinations.
| ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)), | |
| ATTENUATION_TAG(NONE)), |
| std::ifstream &stream, const int numat, | ||
| const specfem::enums::elastic_wave elastic_wave, | ||
| const specfem::enums::electromagnetic_wave electromagnetic_wave, | ||
| specfem::mesh::materials<specfem::dimension::type::dim2>::material< | ||
| acoustic, isotropic, no_attenuation> &acoustic_isotropic, | ||
| specfem::mesh::materials<specfem::dimension::type::dim2>::material< | ||
| elastic_psv, isotropic, no_attenuation> &elastic_psv_isotropic, | ||
| specfem::mesh::materials<specfem::dimension::type::dim2>::material< | ||
| elastic_sh, isotropic, no_attenuation> &elastic_sh_isotropic, | ||
| specfem::mesh::materials<specfem::dimension::type::dim2>::material< | ||
| elastic_psv, anisotropic, no_attenuation> &elastic_psv_anisotropic, | ||
| specfem::mesh::materials<specfem::dimension::type::dim2>::material< | ||
| elastic_sh, anisotropic, no_attenuation> &elastic_sh_anisotropic, | ||
| specfem::mesh::materials<specfem::dimension::type::dim2>::material< | ||
| poroelastic, isotropic, no_attenuation> &poroelastic_isotropic, | ||
| specfem::mesh::materials<specfem::dimension::type::dim2>::material< | ||
| electromagnetic_te, isotropic, no_attenuation> | ||
| &electromagnetic_te_isotropic, | ||
| specfem::mesh::materials<specfem::dimension::type::dim2>::material< | ||
| elastic_psv_t, isotropic_cosserat, no_attenuation> | ||
| &elastic_psv_t_isotropic_cosserat) { | ||
| specfem::mesh::materials<specfem::dimension::type::dim2> &materials) { | ||
|
|
||
| // Define the elastic medium tag based on input elastic wave type | ||
| const specfem::element::medium_tag elastic = [elastic_wave]() { |
There was a problem hiding this comment.
Within this refactor, electromagnetic_wave is validated via an immediately-invoked lambda (see the local electromagnetic = [electromagnetic_wave](){...}();) that throws for TM even if the database contains no electromagnetic materials, and the resulting variable is unused. That means non-EM runs can fail just because the config selects TM. Remove the unused variable and only validate/branch on electromagnetic_wave inside the indic == 4 (electromagnetic) parsing path.
lsawade
left a comment
There was a problem hiding this comment.
I didn't catch the add_material member in 3D when you originally implemented it. Nice!
Refactor implementation macros
Description
Issue Number
If there is an issue created for these changes, link it here
Checklist
Please make sure to check developer documentation on specfem docs.