Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pressure Seismogram #138

Open
wants to merge 10 commits into
base: devel
Choose a base branch
from

Conversation

int-ptr-ptr
Copy link

@int-ptr-ptr int-ptr-ptr commented Nov 15, 2024

Description

This PR attempts to add a pressure seismogram option.

Issue Number

#137

Checklist

Developers' List

Before certain checks in the maintainers' list, the PR should be feature complete (ex. CMakeLists does not need an update at first, but a new feature in the PR creates a new .tpp file). These should be verified maintainer-side:

  • The writer should have the right naming scheme. Commit 7e9d40b used f"{network}{station}BX.semp" as a placeholder. (link to comment)
  • The implementation in kernel should be satisfactory. The implementation from the initial commit (7e9d40b) on this PR is detailed here.
  • The pressure computation should have the right parameters to access the bulk modulus. (link to comment)

Maintainers' List

Please make sure to check developer documentation on specfem docs.
  • I ran the code through pre-commit to check style
  • 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

@buildbot-princeton
Copy link
Collaborator

Can one of the admins verify this patch?

2 similar comments
@buildbot-princeton
Copy link
Collaborator

Can one of the admins verify this patch?

@buildbot-princeton
Copy link
Collaborator

Can one of the admins verify this patch?

Comment on lines 46 to 49
case specfem::enums::seismogram::type::pressure:
filename = { this->output_folder + "/" + network_name + station_name +
"BX" + ".semp" }; // TODO get the right name
break;
Copy link
Author

@int-ptr-ptr int-ptr-ptr Nov 15, 2024

Choose a reason for hiding this comment

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

Relevant to this checklist.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment on lines 245 to 256
//bulk modulus
const type_real kappa = [&]() -> type_real {
if constexpr (MediumTag == specfem::element::medium_tag::acoustic){
return point_properties.kappa;
}else if constexpr (MediumTag == specfem::element::medium_tag::elastic){
//we may also need an isotropic if statement?
return point_properties.lambdaplus2mu;
}else{
static_assert(false, "include/domain/impl/receivers/kernel.tpp: unknown medium to retrieve kappa!");
return 0;
}
}();
Copy link
Author

Choose a reason for hiding this comment

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

These may or may not be the right properties for the bulk modulus. Please verify.

Copy link
Author

Choose a reason for hiding this comment

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

@Rohit-Kakodkar
Copy link
Collaborator

I think your formulation is different then what has been previously used in SPECFEM2D.

For elastic domains - https://github.com/SPECFEM/specfem2d/blob/98741db1a0c8082ca57364f5b17ea95df6cbf1c2/src/specfem2D/compute_pressure.f90#L398

For acoustic domains - https://github.com/SPECFEM/specfem2d/blob/98741db1a0c8082ca57364f5b17ea95df6cbf1c2/src/specfem2D/compute_pressure.f90#L569

I think we should use the same formulations.

@@ -84,6 +84,10 @@ void specfem::domain::impl::kernels::receiver_kernel<
NGLL, DimensionType, MediumTag, specfem::kokkos::DevScratchSpace,
Kokkos::MemoryTraits<Kokkos::Unmanaged>, true, true, true, false, using_simd>;

using Aux2ComponentFieldType = specfem::element::field<
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think what you might want to use is using Aux2ComponentFieldType = typename ElementFieldType::ViewType. This should directly give you access to the underlying Kokkos::View used to store the data

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove Aux2ComponentFieldType if its not getting used?

#pragma unroll
#endif
for (int l = 0; l < specfem::dimension::dimension<DimensionType>::dim; l++) {
aux_field.displacement(iz,ix,l) = sv_receiver_field(l);
Copy link
Collaborator

Choose a reason for hiding this comment

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

With direct access to Kokkos::View as stated in the comment above. This could be aux_field(iz, ix, l)

@@ -186,10 +194,110 @@ void specfem::domain::impl::kernels::receiver_kernel<
point_properties,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be ideal if we can pass seismogram type to this function. I realize for pressure we need the seismo type within get_field. With your current formulation this seems not possible, since we need the divergence. Can you look at the SPECFEM2D formulation https://github.com/SPECFEM/specfem2d/blob/master/src/specfem2D/compute_pressure.f90 .

With that formulation we should be able to compute pressure using only gradients

Comment on lines 46 to 49
case specfem::enums::seismogram::type::pressure:
filename = { this->output_folder + "/" + network_name + station_name +
"BX" + ".semp" }; // TODO get the right name
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@int-ptr-ptr
Copy link
Author

I've added seismogram-typing to get_field parameters, and moved active_field-setting to get_field.

As for unit testing, I was thinking about just having a set of (SPECFEM++ parameter-file, SPECFEM2D seismogram-output-files) pairs to compare against. The current seismogram tests don't have a ground truth for pressure.

@Rohit-Kakodkar
Copy link
Collaborator

Rohit-Kakodkar commented Nov 22, 2024

I've added seismogram-typing to get_field parameters, and moved active_field-setting to get_field.

As for unit testing, I was thinking about just having a set of (SPECFEM++ parameter-file, SPECFEM2D seismogram-output-files) pairs to compare against. The current seismogram tests don't have a ground truth for pressure.

Yes I think thats the best way of doing it right now. Where we compare seismograms from the 2 versions of the software. We already do that within displacement tests https://github.com/PrincetonUniversity/SPECFEMPP/blob/78365e29dca1ad784f336bdefdbd5b370585fb69/tests/unit-tests/displacement_tests/Newmark/newmark_tests.cpp#L283C1-L328C1. In that case I compare displacement seismograms, but you could easily do the same by adding pressure seismograms in traces folder.

}

// -kappa * (dsxdx + dszdz)
receiver_field(0) = -properties.lambdaplus2mu * (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like your computation for pressure field is different from the original formulation. In the original formulation pressure = trace of stress tensor (https://github.com/SPECFEM/specfem2d/blob/98741db1a0c8082ca57364f5b17ea95df6cbf1c2/src/specfem2D/compute_pressure.f90#L398)


// -kappa * (dsxdx + dszdz)
receiver_field(0) = -properties.lambdaplus2mu * (
(dsx_dxi * partial_derivatives.xix +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also seems like I havent given access to kappa within the point properties type. lambdaplus2mu != kappa (

: density(density), cs(cs), cp(cp), Qkappa(Qkappa), Qmu(Qmu),
).

// tells us that fhe first index is the derivative index
#define du(i,j) (i==0? (j==0? dsx_dx:dsz_dx):(j==0? dsx_dz:dsz_dz))

// WET code... should this be refactored with
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree. At later point, we should just call the function from impl/elements. I think I need to do some refactoring before that. For now this implementation looks good.


//https://specfem2d-kokkos.readthedocs.io/en/devel/api/datatypes/field_derivatives/point.html#_CPPv4N7specfem5point17field_derivatives2duE
// tells us that fhe first index is the derivative index
#define du(i,j) (i==0? (j==0? dsx_dx:dsz_dx):(j==0? dsx_dz:dsz_dz))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This LGTM, we should eventually define this as field_Derivatives. I think some refactor is needed before then. For now this is fine.

#undef du
// https://github.com/SPECFEM/specfem2d/blob/98741db1a0c8082ca57364f5b17ea95df6cbf1c2/src/specfem2D/compute_pressure.f90#L398
// pressure = - trace(sigma) / 3
receiver_field(0) = - (sigma_xx + sigma_zz)/3.0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You missed sigma_yy which in 2D is lambdaplus2mu * (du(0,0) + du(1,1))

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for catching that! I was planning on looking for a lost factor of 0.75 after the meeting. This might be it.

@int-ptr-ptr
Copy link
Author

The database.bin files from the most recent version of the Fortran code error out when being read in to SPECFEM++, so I am still using the old database.bin files.

It seems like serial test 3 has the wrong displacement, but serial tests 1 and 2 are good for all 4 seismogram types. It does not seem like the provenance parfile generates the same simulation.

Serial tests 5-7 have acceleration relative errors ~ 5e-2, and there are some stations that give all zeros for pressure Fortran-side, so rel-errors are failing out as NaN.

@Rohit-Kakodkar
Copy link
Collaborator

The database.bin files from the most recent version of the Fortran code error out when being read in to SPECFEM++, so I am still using the old database.bin files.

It seems like serial test 3 has the wrong displacement, but serial tests 1 and 2 are good for all 4 seismogram types. It does not seem like the provenance parfile generates the same simulation.

Serial tests 5-7 have acceleration relative errors ~ 5e-2, and there are some stations that give all zeros for pressure Fortran-side, so rel-errors are failing out as NaN.

It might not be the best to test all seismograms in all simulations then. Especially if the seismogram values are very small. I think that might be the issue with acceleration. I am not sure what issue you are seeing with serial test 3, unless the reference Fortran seismograms have changed. The implementation in this PR hasnt modified how displacement seismograms should be computed.

If you selectively wanted to add pressure seimogram tests, I would recommend adding it to serial test 1 and 2 since it'll test both elastic and acoustic implementation individually.

@Rohit-Kakodkar
Copy link
Collaborator

Also I am used git commit ID 5bacf50dcd9c295cd236c8fb602006f9ac97b107 for the fortran code. i.e. thats where my devel is. I think seismoelectric domains have been added since then, which will cause errors when reading the database files

@int-ptr-ptr
Copy link
Author

To add/remove seismgrams to the tests, it suffices to modify the parameter .yaml file. Tests 1 and 2 currently check all 4 types, but test 3 onward only look at velocity. I've also reverted the traces on test 3, since mine were different. I think we're ready for integration/build tests.

Is the specfem parameter documentation the only part of the docs that has seismograms? I added a table here. Is that sufficient, or is there somewhere else that needs changing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants