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

Property reader / writer #348

Merged
merged 39 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9a4d2b0
Break run() into 3 steps.
icui Dec 6, 2024
e5604bb
Add dependency for pip install
icui Dec 7, 2024
63bb3a1
Update clang-format to 15.0.6
icui Dec 7, 2024
84302ac
Define runtime config in Python
icui Dec 8, 2024
a406e68
Move Python code to specfempp-py
icui Dec 9, 2024
30060cc
Add YAML::Node as setup overload
icui Dec 9, 2024
36a0aec
Merge pull request #253 from PrincetonUniversity/issue-231-3-1
icui Dec 18, 2024
2c96cec
Property writer
icui Dec 20, 2024
9c8cd56
Merge branch 'issue-340' into issue-307
icui Dec 24, 2024
180ac6b
Merge branch 'issue-340' into issue-343
icui Dec 24, 2024
68e831b
Update formatting.
icui Dec 24, 2024
e9ad65d
Add parameter to skip material property assignment.
icui Dec 24, 2024
c30dacc
Property reader
icui Dec 26, 2024
6574ec5
revert example change
icui Dec 26, 2024
c3b6622
Fix GLL model argument in setup.
icui Dec 30, 2024
43e7790
Merge branch 'issue-231' into issue-343
icui Dec 30, 2024
e1ed1d2
Update Python import
icui Dec 30, 2024
45c6ba6
Merge branch 'issue-231' into issue-343
icui Dec 30, 2024
8c02b04
Refactor reader
icui Jan 2, 2025
ff522a2
Update cmake
icui Jan 2, 2025
d4b2865
Fix setup constructor
icui Jan 2, 2025
2a216cd
move property reader to assembly constructor.
icui Jan 3, 2025
8623532
refactor writer
icui Jan 3, 2025
4d61e5a
Test store_on_host and load_on_device for properties.
icui Jan 7, 2025
6c4903b
Test reader, writer and compute_to_mesh.
icui Jan 8, 2025
3530f8f
Update formatting.
icui Jan 8, 2025
df16e57
Merge branch 'issue-228-anisotropy' into issue-354
icui Jan 9, 2025
5e025fa
Update static_cast
icui Jan 9, 2025
9a74cc7
Merge branch 'issue-228-anisotropy' into issue-354
icui Jan 9, 2025
65fbb24
Merge branch 'issue-228-anisotropy' into issue-343
icui Jan 9, 2025
35b11f6
Use macro for material tests
icui Jan 9, 2025
1af33fa
Update kernel test
icui Jan 9, 2025
027f40f
Refactor reader
icui Jan 9, 2025
f1c6b25
Refactor writer
icui Jan 9, 2025
668d9b7
Merge fix.
icui Jan 10, 2025
e5400f6
Update comments.
icui Jan 10, 2025
190fe0f
Merge branch 'issue-354' into issue-343
icui Jan 10, 2025
42cdfcc
Merge branch 'issue-343' into issue-370
icui Jan 10, 2025
02e4b58
Merge pull request #371 from PrincetonUniversity/issue-370
icui Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ option(BUILD_TESTS "Tests included" OFF)
option(BUILD_EXAMPLES "Examples included" ON)
option(ENABLE_SIMD "Enable SIMD" OFF)
option(ENABLE_PROFILING "Enable profiling" OFF)
option(SPECFEMPP_ENABLE_PYTHON "Enable Python binding" OFF)
option(SPECFEMPP_BINDING_PYTHON "Enable Python binding" OFF)
# set(CMAKE_BUILD_TYPE Release)
set(CHUNK_SIZE 32)
set(NUM_CHUNKS 1)
Expand All @@ -25,7 +25,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# For external modules that need to be built suppress build output
set(FETCHCONTENT_QUIET TRUE)

if (SPECFEMPP_ENABLE_PYTHON)
if (SPECFEMPP_BINDING_PYTHON)
message("-- Adding -fPIC flag for Python binding.")
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
set(CMAKE_CXX_FLAGS "-fp-model=precise -fPIC")
Expand All @@ -36,15 +36,15 @@ if (SPECFEMPP_ENABLE_PYTHON)
else()
set(CMAKE_CXX_FLAGS "-fPIC")
endif()
else (SPECFEMPP_ENABLE_PYTHON)
else (SPECFEMPP_BINDING_PYTHON)
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
set(CMAKE_CXX_FLAGS "-fp-model=precise")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
message("-- Detected Intel classic compiler which will be deprecated soon.")
message("-- It is recommended you use IntelLLVM compiler.")
set(CMAKE_CXX_FLAGS "-diag-disable=10441 -fp-model=precise")
endif()
endif (SPECFEMPP_ENABLE_PYTHON)
endif (SPECFEMPP_BINDING_PYTHON)

# Check if MacOS
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand Down Expand Up @@ -341,7 +341,7 @@ target_link_libraries(

add_library(
read_seismogram
src/reader/seismogram.cpp
src/IO/seismogram/reader.cpp
)

target_link_libraries(
Expand All @@ -351,7 +351,8 @@ target_link_libraries(

add_library(
reader
src/reader/wavefield.cpp
src/IO/wavefield/reader.cpp
src/IO/property/reader.cpp
)

target_link_libraries(
Expand Down Expand Up @@ -535,9 +536,10 @@ target_link_libraries(

add_library(
writer
src/writer/seismogram.cpp
src/writer/wavefield.cpp
src/writer/kernel.cpp
src/IO/seismogram/writer.cpp
src/IO/wavefield/writer.cpp
src/IO/kernel/writer.cpp
src/IO/property/writer.cpp
)

target_link_libraries(
Expand Down Expand Up @@ -589,6 +591,7 @@ add_library(
src/parameter_parser/writer/wavefield.cpp
src/parameter_parser/writer/plot_wavefield.cpp
src/parameter_parser/writer/kernel.cpp
src/parameter_parser/writer/property.cpp
)

target_link_libraries(
Expand Down Expand Up @@ -674,7 +677,7 @@ if (SPECFEMPP_USE_SKBUILD AND EXISTS ${SKBUILD_SCRIPTS_DIR})
install(FILES ${CMAKE_BINARY_DIR}/xmeshfem2D DESTINATION ${SKBUILD_SCRIPTS_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)
endif ()

if (SPECFEMPP_ENABLE_PYTHON)
if (SPECFEMPP_BINDING_PYTHON)
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
find_package(pybind11 CONFIG REQUIRED)
python_add_library(_core MODULE src/specfem2d.cpp WITH_SOABI)
Expand All @@ -689,6 +692,7 @@ if (SPECFEMPP_ENABLE_PYTHON)
parameter_reader
receiver_class
writer
plotter
reader
domain
medium
Expand All @@ -698,7 +702,7 @@ if (SPECFEMPP_ENABLE_PYTHON)
${BOOST_LIBS}
pybind11::headers
)
target_compile_definitions(_core PRIVATE SPECFEMPP_ENABLE_PYTHON)
target_compile_definitions(_core PRIVATE SPECFEMPP_BINDING_PYTHON)
target_compile_definitions(_core PRIVATE VERSION_INFO=${PROJECT_VERSION})
install(TARGETS _core DESTINATION specfempp_core)
endif (SPECFEMPP_ENABLE_PYTHON)
endif (SPECFEMPP_BINDING_PYTHON)
6 changes: 3 additions & 3 deletions docs/api/IO/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ formats for the reading of the mesh is binary, and for sources and receivers it
is yaml.

In addition to these basic read functions, there are also the two
reader and writer classes, :cpp:class:`specfem::reader::wavefield` and
:cpp:class:`specfem::writer::wavefield`, which support both HDF5 and ASCII I/O.
And, to write seismograms, we can use :cpp:class:`specfem::writer::seismogram`.
reader and writer classes, :cpp:class:`specfem::IO::wavefield_reader` and
:cpp:class:`specfem::IO::wavefield_writer`, which support both HDF5 and ASCII I/O.
And, to write seismograms, we can use :cpp:class:`specfem::IO::seismogram_writer`.
Seismogram I/O is only supported in ASCII format thus far.

The slightly-lower level functionality to read and write data to and from disk
Expand Down
2 changes: 1 addition & 1 deletion docs/api/IO/reader/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Reader

The ``reader`` class provides interfaces to read simulation data as output files.

.. doxygenclass:: specfem::writer::writer
.. doxygenclass:: specfem::IO::writer

Types of readers
----------------
Expand Down
2 changes: 1 addition & 1 deletion docs/api/IO/reader/wavefield.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
Wavefield Reader
================

.. doxygenclass:: specfem::reader::wavefield
.. doxygenclass:: specfem::IO::wavefield_reader
:members:
2 changes: 1 addition & 1 deletion docs/api/IO/writer/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Writer

The ``writer`` class provides interfaces to write simulation data as output files.

.. doxygenclass:: specfem::writer::writer
.. doxygenclass:: specfem::IO::writer
:members:

Types of writers
Expand Down
2 changes: 1 addition & 1 deletion docs/api/IO/writer/seismogram_writer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Seismogram Writer

The ``seismogram`` provides methods to write seismograms to a file.

.. doxygenclass:: specfem::writer::seismogram
.. doxygenclass:: specfem::IO::seismogram_writer
:members:
2 changes: 1 addition & 1 deletion docs/api/IO/writer/wavefield.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
Wavefield Writer
================

.. doxygenclass:: specfem::writer::wavefield
.. doxygenclass:: specfem::IO::wavefield_writer
:members:
6 changes: 3 additions & 3 deletions fortran/meshfem3d/setup/precision.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ either version 3 of the License,
!
! You should have received a copy of the GNU General Public License along
! with this program;
if
not, write to the Free Software Foundation, Inc., !51 Franklin Street,
Fifth Floor, Boston,
if not
, write to the Free Software Foundation, Inc., !51 Franklin Street, Fifth Floor,
Boston,
MA 02110 - 1301 USA.! != == == == == == == == == == == == == == == == == ==
== == == == == == == == == == == == == == == == ==

Expand Down
22 changes: 8 additions & 14 deletions include/writer/kernel.hpp → include/IO/kernel/writer.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
#ifndef _SPECFEM_WRITER_KERNEL_HPP
#define _SPECFEM_WRITER_KERNEL_HPP
#pragma once

#include "compute/interface.hpp"
#include "enumerations/interface.hpp"
#include "writer/writer.hpp"
#include "IO/writer.hpp"

namespace specfem {
namespace writer {
namespace IO {
/**
* @brief Writer to output misfit kernel data to disk
*
* @tparam OutputLibrary Library to use for output (HDF5, ASCII, etc.)
*/
template <typename OutputLibrary> class kernel : public writer {
template <typename OutputLibrary> class kernel_writer : public writer {
public:
/**
* @name Constructors
Expand All @@ -26,21 +25,16 @@ template <typename OutputLibrary> class kernel : public writer {
* @param output_folder Path to output location (will be an .h5 file if using
* HDF5, and a folder if using ASCII)
*/
kernel(const specfem::compute::assembly &assembly,
const std::string output_folder);
kernel_writer(const std::string output_folder);

/**
* @brief write the kernel data to disk
*
*/
void write() override;
void write(specfem::compute::assembly &assembly) override;

private:
std::string output_folder; ///< Path to output folder
specfem::compute::mesh mesh; ///< Mesh object
specfem::compute::kernels kernels; ///< Kernels object
std::string output_folder; ///< Path to output folder
};
} // namespace writer
} // namespace IO
} // namespace specfem

#endif /* _SPECFEM_WRITER_KERNEL_HPP */
19 changes: 8 additions & 11 deletions include/writer/kernel.tpp → include/IO/kernel/writer.tpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
#ifndef _SPECFEM_WRITER_KERNEL_TPP
#define _SPECFEM_WRITER_KERNEL_TPP
#pragma once

#include "compute/assembly/assembly.hpp"
#include "enumerations/dimension.hpp"
#include "enumerations/medium.hpp"
#include "kokkos_abstractions.h"
#include "point/kernels.hpp"
#include "writer/kernel.hpp"
#include "IO/kernel/writer.hpp"
#include <Kokkos_Core.hpp>

template <typename OutputLibrary>
specfem::writer::kernel<OutputLibrary>::kernel(
const specfem::compute::assembly &assembly, const std::string output_folder)
: output_folder(output_folder), mesh(assembly.mesh),
kernels(assembly.kernels) {}
specfem::IO::kernel_writer<OutputLibrary>::kernel_writer(const std::string output_folder)
: output_folder(output_folder) {}

template <typename OutputLibrary>
void specfem::writer::kernel<OutputLibrary>::write() {
void specfem::IO::kernel_writer<OutputLibrary>::write(specfem::compute::assembly &assembly) {
const auto &mesh = assembly.mesh;
auto &kernels = assembly.kernels;

using DomainView =
Kokkos::View<type_real ***, Kokkos::LayoutLeft, Kokkos::HostSpace>;
Expand Down Expand Up @@ -167,7 +166,7 @@ void specfem::writer::kernel<OutputLibrary>::write() {
const specfem::point::index<specfem::dimension::type::dim2> index(
ispec, iz, ix);
specfem::point::kernels<specfem::dimension::type::dim2,
specfem::element::medium_tag::elastic,
specfem::element::medium_tag::acoustic,
specfem::element::property_tag::isotropic,
false>
point_kernels;
Expand Down Expand Up @@ -195,5 +194,3 @@ void specfem::writer::kernel<OutputLibrary>::write() {
std::cout << "Kernels written to " << output_folder << "/Kernels"
<< std::endl;
}

#endif /* _SPECFEM_WRITER_KERNEL_TPP */
42 changes: 42 additions & 0 deletions include/IO/property/reader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include "compute/interface.hpp"
#include "enumerations/interface.hpp"
#include "IO/reader.hpp"

namespace specfem {
namespace IO {
/**
* @brief Read model property
*
* @tparam InputLibrary Library to use for output (HDF5, ASCII, etc.)
*/
template <typename InputLibrary> class property_reader : public reader {
public:
/**
* @name Constructors
*
*/
///@{
/**
* @brief Construct a reader object
*
* @param output_folder Path to input location (will be an .h5 file if using
* HDF5, and a folder if using ASCII)
*/
property_reader(const std::string input_folder);

/**
* @brief read the property from disk
*
* @param assembly SPECFEM++ assembly
*
*/
void read(specfem::compute::assembly &assembly) override;

private:
std::string input_folder; ///< Path to output folder
specfem::compute::properties properties; ///< Properties object
};
} // namespace IO
} // namespace specfem
57 changes: 57 additions & 0 deletions include/IO/property/reader.tpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

#include "compute/assembly/assembly.hpp"
#include "enumerations/dimension.hpp"
#include "enumerations/medium.hpp"
#include "kokkos_abstractions.h"
#include "point/properties.hpp"
#include "IO/property/reader.hpp"
#include <Kokkos_Core.hpp>

template <typename InputLibrary>
specfem::IO::property_reader<InputLibrary>::property_reader(const std::string input_folder): input_folder(input_folder) {}

template <typename InputLibrary>
void specfem::IO::property_reader<InputLibrary>::read(specfem::compute::assembly &assembly) {
auto &properties = assembly.properties;

using DomainView =
Kokkos::View<type_real ***, Kokkos::LayoutLeft, Kokkos::HostSpace>;

typename InputLibrary::File file(input_folder + "/Properties");

{
typename InputLibrary::Group elastic = file.openGroup("/ElasticIsotropic");

elastic.openDataset("rho", properties.elastic_isotropic.h_rho).read();
elastic.openDataset("mu", properties.elastic_isotropic.h_mu).read();
elastic.openDataset("lambdaplus2mu", properties.elastic_isotropic.h_lambdaplus2mu).read();
}

{
typename InputLibrary::Group elastic = file.openGroup("/ElasticAnisotropic");

elastic.openDataset("rho", properties.elastic_anisotropic.h_rho).read();
elastic.openDataset("c11", properties.elastic_anisotropic.h_c11).read();
elastic.openDataset("c13", properties.elastic_anisotropic.h_c13).read();
elastic.openDataset("c15", properties.elastic_anisotropic.h_c15).read();
elastic.openDataset("c33", properties.elastic_anisotropic.h_c33).read();
elastic.openDataset("c35", properties.elastic_anisotropic.h_c35).read();
elastic.openDataset("c55", properties.elastic_anisotropic.h_c55).read();
elastic.openDataset("c12", properties.elastic_anisotropic.h_c12).read();
elastic.openDataset("c23", properties.elastic_anisotropic.h_c23).read();
elastic.openDataset("c25", properties.elastic_anisotropic.h_c25).read();
}

{
typename InputLibrary::Group acoustic = file.openGroup("/Acoustic");

acoustic.openDataset("rho_inverse", properties.acoustic_isotropic.h_rho_inverse).read();
acoustic.openDataset("kappa", properties.acoustic_isotropic.h_kappa).read();
}

std::cout << "Properties read from " << input_folder << "/Properties"
<< std::endl;

properties.copy_to_device();
}
Loading
Loading