Skip to content

Commit

Permalink
Merge pull request #371 from PrincetonUniversity/issue-370
Browse files Browse the repository at this point in the history
Refactor reader / writer to IO namespace
  • Loading branch information
icui authored Jan 13, 2025
2 parents 190fe0f + 42cdfcc commit 02e4b58
Show file tree
Hide file tree
Showing 51 changed files with 194 additions and 296 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
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,8 +351,8 @@ target_link_libraries(

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

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

add_library(
writer
src/writer/seismogram.cpp
src/writer/wavefield.cpp
src/writer/kernel.cpp
src/writer/property.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
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
15 changes: 6 additions & 9 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,7 +25,7 @@ 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 std::string output_folder);
kernel_writer(const std::string output_folder);

/**
* @brief write the kernel data to disk
Expand All @@ -37,7 +36,5 @@ template <typename OutputLibrary> class kernel : public writer {
private:
std::string output_folder; ///< Path to output folder
};
} // namespace writer
} // namespace IO
} // namespace specfem

#endif /* _SPECFEM_WRITER_KERNEL_HPP */
11 changes: 4 additions & 7 deletions include/writer/kernel.tpp → include/IO/kernel/writer.tpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#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 std::string output_folder)
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(specfem::compute::assembly &assembly) {
void specfem::IO::kernel_writer<OutputLibrary>::write(specfem::compute::assembly &assembly) {
const auto &mesh = assembly.mesh;
auto &kernels = assembly.kernels;

Expand Down Expand Up @@ -195,5 +194,3 @@ void specfem::writer::kernel<OutputLibrary>::write(specfem::compute::assembly &a
std::cout << "Kernels written to " << output_folder << "/Kernels"
<< std::endl;
}

#endif /* _SPECFEM_WRITER_KERNEL_TPP */
10 changes: 5 additions & 5 deletions include/reader/property.hpp → include/IO/property/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

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

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

/**
* @brief read the property from disk
Expand All @@ -38,5 +38,5 @@ template <typename InputLibrary> class property : public reader {
std::string input_folder; ///< Path to output folder
specfem::compute::properties properties; ///< Properties object
};
} // namespace reader
} // namespace IO
} // namespace specfem
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#include "enumerations/medium.hpp"
#include "kokkos_abstractions.h"
#include "point/properties.hpp"
#include "reader/property.hpp"
#include "IO/property/reader.hpp"
#include <Kokkos_Core.hpp>

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

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

using DomainView =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

#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 model property data to disk
*
* @tparam OutputLibrary Library to use for output (HDF5, ASCII, etc.)
*/
template <typename OutputLibrary> class property : public writer {
template <typename OutputLibrary> class property_writer : public writer {
public:
/**
* @name Constructors
Expand All @@ -24,7 +24,7 @@ template <typename OutputLibrary> class property : public writer {
* @param output_folder Path to output location (will be an .h5 file if using
* HDF5, and a folder if using ASCII)
*/
property(const std::string output_folder);
property_writer(const std::string output_folder);

/**
* @brief write the property data to disk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
#include "enumerations/medium.hpp"
#include "kokkos_abstractions.h"
#include "point/properties.hpp"
#include "writer/property.hpp"
#include "IO/property/writer.hpp"
#include <Kokkos_Core.hpp>

template <typename OutputLibrary>
specfem::writer::property<OutputLibrary>::property(const std::string output_folder)
specfem::IO::property_writer<OutputLibrary>::property_writer(const std::string output_folder)
: output_folder(output_folder) {}

template <typename OutputLibrary>
void specfem::writer::property<OutputLibrary>::write(specfem::compute::assembly &assembly) {
void specfem::IO::property_writer<OutputLibrary>::write(specfem::compute::assembly &assembly) {
const auto &mesh = assembly.mesh;
auto &properties = assembly.properties;

Expand Down
4 changes: 2 additions & 2 deletions include/reader/reader.hpp → include/IO/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class assembly;
} // namespace specfem

namespace specfem {
namespace reader {
namespace IO {
/**
* @brief Base reader class
*
Expand All @@ -22,5 +22,5 @@ class reader {
*/
virtual void read(specfem::compute::assembly &assembly) = 0;
};
} // namespace reader
} // namespace IO
} // namespace specfem
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define SPECFEM_READER_SEISMOGRAM_HPP

#include "enumerations/specfem_enums.hpp"
#include "reader/reader.hpp"
#include "IO/reader.hpp"

namespace specfem {
namespace forcing_function {
Expand All @@ -11,17 +11,17 @@ class external;
} // namespace specfem

namespace specfem {
namespace reader {
namespace IO {

class seismogram {
class seismogram_reader {
public:
seismogram(){};
seismogram(const char *filename,
seismogram_reader(){};
seismogram_reader(const char *filename,
const specfem::enums::seismogram::format type,
specfem::kokkos::HostView2d<type_real> source_time_function)
: filename(filename), type(type),
source_time_function(source_time_function) {}
seismogram(const std::string &filename,
seismogram_reader(const std::string &filename,
const specfem::enums::seismogram::format type,
specfem::kokkos::HostView2d<type_real> source_time_function)
: filename(filename), type(type),
Expand All @@ -34,7 +34,7 @@ class seismogram {
specfem::enums::seismogram::format type;
specfem::kokkos::HostView2d<type_real> source_time_function;
};
} // namespace reader
} // namespace IO
} // namespace specfem

#endif /* SPECFEM_READER_SEISMOGRAM_HPP */
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#ifndef _SEISMOGRAM_WRITER_HPP
#define _SEISMOGRAM_WRITER_HPP
#pragma once

#include "compute/interface.hpp"
#include "constants.hpp"
#include "receiver/interface.hpp"
#include "specfem_setup.hpp"
#include "writer.hpp"
#include "IO/writer.hpp"
#include <vector>

namespace specfem {
namespace writer {
namespace IO {
/**
* @brief Seismogram writer class to write seismogram to a file
*
*/
class seismogram : public writer {
class seismogram_writer : public writer {

public:
/**
Expand All @@ -27,7 +26,7 @@ class seismogram : public writer {
* @param nstep_between_samples number of timesteps between seismogram
* sampling (seismogram sampling frequency)
*/
seismogram(const specfem::enums::seismogram::format type,
seismogram_writer(const specfem::enums::seismogram::format type,
const std::string output_folder, const type_real dt,
const type_real t0, const int nstep_between_samples)
: type(type), output_folder(output_folder), dt(dt), t0(t0),
Expand All @@ -51,7 +50,5 @@ class seismogram : public writer {
///< sampling (seismogram sampling frequency)
};

} // namespace writer
} // namespace IO
} // namespace specfem

#endif
Loading

0 comments on commit 02e4b58

Please sign in to comment.