Skip to content

Issue 1593 part 3 - Reads attenuation database#1628

Open
Rohit-Kakodkar wants to merge 8 commits intodevelfrom
issue-1593-part-3
Open

Issue 1593 part 3 - Reads attenuation database#1628
Rohit-Kakodkar wants to merge 8 commits intodevelfrom
issue-1593-part-3

Conversation

@Rohit-Kakodkar
Copy link
Collaborator

Description

  • Refactors materials reader
  • Reads attenuation props
  • Adds a test for acoustic elastic w attenuation
  • Adds a test for poroelastic w attenuation

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.

  • I ran the code through pre-commit to check style
  • THE DOCUMENTATION BUILDS WITHOUT WARNINGS/ERRORS
  • I have added labels to the PR (see right hand side of the PR page)
  • My code passes all the integration tests
  • I have added sufficient unittests to test my changes
  • I have added/updated documentation for the changes I am proposing
  • I have updated CMakeLists to ensure my code builds
  • My code builds across all platforms

Rohit-Kakodkar and others added 3 commits February 3, 2026 07:44
- [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
@Rohit-Kakodkar Rohit-Kakodkar added the enhancement New feature or request label Feb 3, 2026
Copilot AI review requested due to automatic review settings February 3, 2026 21:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 materials container via add_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.

Comment on lines 228 to +240
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;
}
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
ELASTIC_PSV_T, ELECTROMAGNETIC_TE),
PROPERTY_TAG(ISOTROPIC, ANISOTROPIC, ISOTROPIC_COSSERAT),
ATTENUATION_TAG(NONE)),
ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)),
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
ATTENUATION_TAG(NONE, CONSTANT_ISOTROPIC)),
ATTENUATION_TAG(NONE)),

Copilot uses AI. Check for mistakes.
Comment on lines 39 to 45
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]() {
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@lsawade lsawade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't catch the add_material member in 3D when you originally implemented it. Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants