Skip to content

Commit e740972

Browse files
authored
Merge pull request #462 from PrincetonUniversity/issue-461
Issue 461 -- Implement Parameter Reader
2 parents 524a1c2 + fc4687e commit e740972

File tree

14 files changed

+658
-29
lines changed

14 files changed

+658
-29
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,15 @@ add_library(
197197
src/IO/sources.cpp
198198
src/IO/receivers.cpp
199199
src/IO/mesh.cpp
200+
# Fortran 2D part
200201
src/IO/mesh/impl/fortran/dim2/read_boundaries.cpp
201202
src/IO/mesh/impl/fortran/dim2/read_elements.cpp
202203
src/IO/mesh/impl/fortran/dim2/read_material_properties.cpp
203204
src/IO/mesh/impl/fortran/dim2/read_mesh_database.cpp
204205
src/IO/mesh/impl/fortran/dim2/read_interfaces.cpp
205206
src/IO/mesh/impl/fortran/dim2/read_parameters.cpp
207+
# Fortran 3D part
208+
src/IO/mesh/impl/fortran/dim3/read_parameters.cpp
206209
)
207210

208211
if (NOT HDF5_CXX_BUILD)

CMakePresets.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": 6,
3+
"configurePresets": [
4+
{
5+
"name": "debug",
6+
"displayName": "Debug (Serial)",
7+
"binaryDir": "build/debug",
8+
"cacheVariables": {
9+
"CMAKE_BUILD_TYPE": "Debug",
10+
"BUILD_TESTS": "ON",
11+
"ENABLE_SIMD": "OFF",
12+
"Kokkos_ARCH_NATIVE": "ON",
13+
"Kokkos_ENABLE_AGGRESSIVE_VECTORIZATION": "ON",
14+
"Kokkos_ENABLE_ATOMICS_BYPASS": "ON"
15+
}
16+
}
17+
],
18+
"buildPresets": [
19+
{
20+
"name": "debug",
21+
"configurePreset": "debug",
22+
"targets": ["all"],
23+
"jobs": 8
24+
}
25+
]
26+
}

examples/dim3/homogeneous_halfspace/specfem_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ parameters:
4545
## databases
4646
databases:
4747
mesh-database: "OUTPUT_FILES/DATABASES_MPI/proc000000_external_mesh.bin"
48+
mesh-parameters: "OUTPUT_FILES/DATABASES_MPI/mesh_parameters.bin"
4849

4950
## sources
5051
sources: "/Users/lsawade/SPECFEMPP/examples/homogeneous-medium-flat-topography/source.yaml"

fortran/meshfem3d/generate_databases/save_parameters.f90

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ subroutine save_parameters()
5858
WRITE(IOUT) APPROXIMATE_OCEAN_LOAD
5959
WRITE(IOUT) USE_MESH_COLORING_GPU
6060

61-
6261
! Write test parameter
6362
itest = 9998
6463
WRITE(IOUT) itest
@@ -72,32 +71,32 @@ subroutine save_parameters()
7271
WRITE(IOUT) NGLLSQUARE
7372

7473
! Write test parameter
75-
WRITE(IOUT) itest
7674
itest = 9997
75+
WRITE(IOUT) itest
7776

7877
WRITE(IOUT) NSPEC_AB ! nspec
7978
WRITE(IOUT) NSPEC_PORO ! nspec_poro == nspec, if POROELASTIC_SIMULATION
8079
WRITE(IOUT) NGLOB_AB ! nglob
8180
WRITE(IOUT) NGLOB_OCEAN
82-
WRITE(IOUT) NSPEC2D_BOTTOM
83-
WRITE(IOUT) NSPEC2D_TOP
84-
WRITE(IOUT) nspec_irregular
8581

8682
! Write test parameter
87-
WRITE(IOUT) itest
8883
itest = 9996
84+
WRITE(IOUT) itest
8985

90-
WRITE(IOUT) num_neighbors_all
91-
WRITE(IOUT) nfaces_surface
92-
WRITE(IOUT) nspec2D_xmin
86+
WRITE(IOUT) NSPEC2D_BOTTOM
87+
WRITE(IOUT) NSPEC2D_TOP
9388
WRITE(IOUT) nspec2D_xmin
89+
WRITE(IOUT) nspec2D_xmax
9490
WRITE(IOUT) nspec2D_ymin
95-
WRITE(IOUT) nspec2D_ymin
91+
WRITE(IOUT) nspec2D_ymax
92+
WRITE(IOUT) nspec_irregular
9693

9794
! Write test parameter
98-
WRITE(IOUT) itest
9995
itest = 9995
96+
WRITE(IOUT) itest
10097

98+
WRITE(IOUT) num_neighbors_all
99+
WRITE(IOUT) nfaces_surface
101100
WRITE(IOUT) num_abs_boundary_faces
102101
WRITE(IOUT) num_free_surface_faces
103102
WRITE(IOUT) num_coupling_ac_el_faces
@@ -108,8 +107,8 @@ subroutine save_parameters()
108107
WRITE(IOUT) max_nibool_interfaces_ext_mesh
109108

110109
! Write test parameter
111-
WRITE(IOUT) itest
112110
itest = 9994
111+
WRITE(IOUT) itest
113112

114113
WRITE(IOUT) nspec_inner_acoustic
115114
WRITE(IOUT) nspec_outer_acoustic
@@ -119,8 +118,8 @@ subroutine save_parameters()
119118
WRITE(IOUT) nspec_outer_poroelastic
120119

121120
! Write test parameter
122-
WRITE(IOUT) itest
123121
itest = 9993
122+
WRITE(IOUT) itest
124123

125124
WRITE(IOUT) num_phase_ispec_acoustic
126125
WRITE(IOUT) num_phase_ispec_elastic
@@ -131,8 +130,8 @@ subroutine save_parameters()
131130
WRITE(IOUT) num_colors_outer_elastic
132131

133132
! Write test parameter
134-
WRITE(IOUT) itest
135133
itest = 9992
134+
WRITE(IOUT) itest
136135
endif
137136

138137
end subroutine save_parameters

include/IO/interface.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ specfem::mesh::mesh<specfem::dimension::type::dim2>
2525
read_2d_mesh(const std::string filename, const specfem::MPI::MPI *mpi);
2626

2727
specfem::mesh::mesh<specfem::dimension::type::dim3>
28-
read_3d_mesh(const std::string filename, const specfem::MPI::MPI *mpi);
28+
read_3d_mesh(const std::string mesh_parameters_file,
29+
const std::string mesh_databases_file,
30+
const specfem::MPI::MPI *mpi);
2931
/**
3032
* @brief Read station file
3133
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#pragma once
2+
3+
#include "IO/fortranio/interface.hpp"
4+
#include "mesh/parameters/parameters.hpp"
5+
#include "specfem_mpi/interface.hpp"
6+
7+
namespace specfem {
8+
namespace IO {
9+
namespace mesh {
10+
namespace impl {
11+
namespace fortran {
12+
namespace dim3 {
13+
14+
/*
15+
* @brief Read paramters from 3D mesh database
16+
*
17+
* @param stream Input stream
18+
* @param mpi MPI object
19+
* @return specfem::mesh::parameters<specfem::dimension::type::dim2> Mesh
20+
* parameters
21+
*/
22+
specfem::mesh::parameters<specfem::dimension::type::dim3>
23+
read_mesh_parameters(std::ifstream &stream, const specfem::MPI::MPI *mpi);
24+
25+
} // namespace dim3
26+
} // namespace fortran
27+
} // namespace impl
28+
} // namespace mesh
29+
} // namespace IO
30+
} // namespace specfem

include/mesh/mesh.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "coupled_interfaces/coupled_interfaces.hpp"
66
#include "elements/axial_elements.hpp"
77
#include "elements/tangential_elements.hpp"
8+
#include "enumerations/dimension.hpp"
89
#include "enumerations/interface.hpp"
910
#include "materials/materials.hpp"
1011
#include "mesh/tags/tags.hpp"
@@ -104,6 +105,9 @@ template <> struct mesh<specfem::dimension::type::dim3> {
104105
constexpr static auto dimension =
105106
specfem::dimension::type::dim3; ///< Dimension
106107

108+
// Struct to store all the mesh parameter
109+
specfem::mesh::parameters<dimension> parameters;
110+
107111
// int npgeo; ///< Total number of spectral element control nodes
108112
// int nspec; ///< Total number of spectral elements
109113
// int nproc; ///< Total number of processors

include/mesh/parameters/parameters.hpp

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,186 @@ template <> struct parameters<specfem::dimension::type::dim2> {
7676
nelem_on_the_axis(nelem_on_the_axis),
7777
plot_lowerleft_corner_only(plot_lowerleft_corner_only){};
7878
};
79+
80+
/**
81+
* @brief Template specialization for 3D mesh parameters
82+
*/
83+
template <> struct parameters<specfem::dimension::type::dim3> {
84+
constexpr static auto dimension =
85+
specfem::dimension::type::dim3; ///< Dimension
86+
///< type
87+
88+
// Flags
89+
bool acoustic_simulation; ///< Flag for acoustic simulation
90+
bool elastic_simulation; ///< Flag for elastic simulation
91+
bool poroelastic_simulation; ///< Flag for poroelastic simulation
92+
bool anisotropy; ///< Flag for anisotropy
93+
bool stacey_abc; ///< Flag for Stacey absorbing boundary c.
94+
bool pml_abc; ///< Flag for PML absorbing boundary c.
95+
bool approximate_ocean_load; ///< Flag for approx. ocean load
96+
bool use_mesh_coloring; ///< Flag for mesh coloring
97+
98+
// Integer Parameters: Dimensions and GLL layouts
99+
int ndim; ///< Number of dimensions
100+
int ngllx; ///< Number of GLL points in x
101+
int nglly; ///< Number of GLL points in y
102+
int ngllz; ///< Number of GLL points in z
103+
int ngllsquare; ///< Number of GLL points in square
104+
105+
// Integer Parameters: Elements/Nodes
106+
int nspec; ///< Number of spectral elements (SEs)
107+
int nspec_poro; ///< Number of poroelastic SEs
108+
int nglob; ///< Number of global nodes
109+
int nglob_ocean; ///< Number of global ocean nodes
110+
int nspec2D_bottom; ///< Number of 2D SEs at the bottom
111+
int nspec2D_top; ///< Number of 2D SEs at the top
112+
int nspec2D_xmin; ///< Number of 2D SEs at the left
113+
int nspec2D_xmax; ///< Number of 2D SEs at the right
114+
int nspec2D_ymin; ///< Number of 2D SEs at the front
115+
int nspec2D_ymax; ///< Number of 2D SEs at the back
116+
int nspec_irregular; ///< Number of irregular SEs
117+
118+
// Integer Parameters: Mesh
119+
int num_neighbors; ///< Number of neighbors
120+
int nfaces_surface; ///< Number of faces on the surface
121+
int num_abs_boundary_faces; ///< Number of absorbing boundary faces
122+
int num_free_surface_faces; ///< Number of free surface faces
123+
int num_coupling_ac_el_faces; ///< Number of acoustic-elastic faces
124+
int num_coupling_ac_po_faces; ///< Number of acoustic-poroelastic faces
125+
int num_coupling_el_po_faces; ///< Number of elastic-poroelastic faces
126+
int num_coupling_po_el_faces; ///< Number of poroelastic-elastic faces
127+
int num_interfaces_ext_mesh; ///< Number of external mesh interfaces
128+
int max_nibool_interfaces_ext_mesh; ///< Maximum number of interfaces
129+
130+
// Integer Parameters: Nspec Inner/Outer
131+
int nspec_inner_acoustic; ///< Number of inner acoustic SEs
132+
int nspec_outer_acoustic; ///< Number of outer acoustic SEs
133+
int nspec_inner_elastic; ///< Number of inner elastic SEs
134+
int nspec_outer_elastic; ///< Number of outer elastic SEs
135+
int nspec_inner_poroelastic; ///< Number of inner poroelastic SEs
136+
int nspec_outer_poroelastic; ///< Number of outer poroelastic SEs
137+
138+
// Integer Parameters: coloring
139+
int num_phase_ispec_acoustic;
140+
int num_phase_ispec_elastic;
141+
int num_phase_ispec_poroelastic;
142+
int num_colors_inner_acoustic;
143+
int num_colors_outer_acoustic;
144+
int num_colors_inner_elastic;
145+
int num_colors_outer_elastic;
146+
147+
/**
148+
* @brief Default constructor
149+
*
150+
*/
151+
parameters(){};
152+
153+
/** Constructor
154+
* @param acoustic_simulation Flag for acoustic simulation
155+
* @param elastic_simulation Flag for elastic simulation
156+
* @param poroelastic_simulation Flag for poroelastic simulation
157+
* @param anisotropy Flag for anisotropy
158+
* @param stacey_abc Flag for Stacey absorbing boundary c.
159+
* @param pml_abc Flag for PML absorbing boundary c.
160+
* @param approximate_ocean_load Flag for approx. ocean load
161+
* @param use_mesh_coloring Flag for mesh coloring
162+
*
163+
*
164+
*
165+
* @param nspec Number of spectral elements (SEs)
166+
* @param nspec_poro Number of poroelastic SEs
167+
* @param nglob Number of global nodes
168+
* @param nglob_ocean Number of global ocean nodes
169+
* @param nspec2D_bottom Number of 2D SEs at the bottom
170+
* @param nspec2D_top Number of 2D SEs at the top
171+
* @param nspec2D_xmin Number of 2D SEs at the left
172+
* @param nspec2D_xmax Number of 2D SEs at the right
173+
* @param nspec2D_ymin Number of 2D SEs at the front
174+
* @param nspec2D_ymax Number of 2D SEs at the back
175+
* @param nspec_irregular Number of irregular SEs
176+
*
177+
* @param num_neighbors Number of neighbors
178+
* @param nfaces_surface Number of faces on the surface
179+
* @param num_abs_boundary_faces Number of absorbing boundary faces
180+
* @param num_free_surface_faces Number of free surface faces
181+
* @param num_coupling_ac_el_faces Number of acoustic-elastic faces
182+
* @param num_coupling_ac_po_faces Number of acoustic-poroelastic faces
183+
* @param num_coupling_el_po_faces Number of elastic-poroelastic faces
184+
* @param num_coupling_po_el_faces Number of poroelastic-elastic faces
185+
* @param num_interfaces_ext_mesh Number of external mesh interfaces
186+
* @param max_nibool_interfaces_ext_mesh Maximum number of interfaces
187+
*
188+
* @param nspec_inner_acoustic Number of inner acoustic SEs
189+
* @param nspec_outer_acoustic Number of outer acoustic SEs
190+
* @param nspec_inner_elastic Number of inner elastic SEs
191+
* @param nspec_outer_elastic Number of outer elastic SEs
192+
* @param nspec_inner_poroelastic Number of inner poroelastic SEs
193+
* @param nspec_outer_poroelastic Number of outer poroelastic SEs
194+
*
195+
* @param num_phase_ispec_acoustic
196+
* @param num_phase_ispec_elastic
197+
* @param num_phase_ispec_poroelastic
198+
* @param num_colors_inner_acoustic
199+
* @param num_colors_outer_acoustic
200+
* @param num_colors_inner_elastic
201+
* @param num_colors_outer_elastic
202+
*
203+
*/
204+
parameters(
205+
const bool acoustic_simulation, const bool elastic_simulation,
206+
const bool poroelastic_simulation, const bool anisotropy,
207+
const bool stacey_abc, const bool pml_abc,
208+
const bool approximate_ocean_load, const bool use_mesh_coloring,
209+
const int nspec, const int nspec_poro, const int nglob,
210+
const int nglob_ocean, const int nspec2D_bottom, const int nspec2D_top,
211+
const int nspec2D_xmin, const int nspec2D_xmax, const int nspec2D_ymin,
212+
const int nspec2D_ymax, const int nspec_irregular,
213+
const int num_neighbors, const int nfaces_surface,
214+
const int num_abs_boundary_faces, const int num_free_surface_faces,
215+
const int num_coupling_ac_el_faces, const int num_coupling_ac_po_faces,
216+
const int num_coupling_el_po_faces, const int num_coupling_po_el_faces,
217+
const int num_interfaces_ext_mesh,
218+
const int max_nibool_interfaces_ext_mesh, const int nspec_inner_acoustic,
219+
const int nspec_outer_acoustic, const int nspec_inner_elastic,
220+
const int nspec_outer_elastic, const int nspec_inner_poroelastic,
221+
const int nspec_outer_poroelastic, const int num_phase_ispec_acoustic,
222+
const int num_phase_ispec_elastic, const int num_phase_ispec_poroelastic,
223+
const int num_colors_inner_acoustic, const int num_colors_outer_acoustic,
224+
const int num_colors_inner_elastic, const int num_colors_outer_elastic)
225+
: acoustic_simulation(acoustic_simulation),
226+
elastic_simulation(elastic_simulation),
227+
poroelastic_simulation(poroelastic_simulation), anisotropy(anisotropy),
228+
stacey_abc(stacey_abc), pml_abc(pml_abc),
229+
approximate_ocean_load(approximate_ocean_load),
230+
use_mesh_coloring(use_mesh_coloring), nspec(nspec),
231+
nspec_poro(nspec_poro), nglob(nglob), nglob_ocean(nglob_ocean),
232+
nspec2D_bottom(nspec2D_bottom), nspec2D_top(nspec2D_top),
233+
nspec2D_xmin(nspec2D_xmin), nspec2D_xmax(nspec2D_xmax),
234+
nspec2D_ymin(nspec2D_ymin), nspec2D_ymax(nspec2D_ymax),
235+
nspec_irregular(nspec_irregular), num_neighbors(num_neighbors),
236+
nfaces_surface(nfaces_surface),
237+
num_abs_boundary_faces(num_abs_boundary_faces),
238+
num_free_surface_faces(num_free_surface_faces),
239+
num_coupling_ac_el_faces(num_coupling_ac_el_faces),
240+
num_coupling_ac_po_faces(num_coupling_ac_po_faces),
241+
num_coupling_el_po_faces(num_coupling_el_po_faces),
242+
num_coupling_po_el_faces(num_coupling_po_el_faces),
243+
num_interfaces_ext_mesh(num_interfaces_ext_mesh),
244+
max_nibool_interfaces_ext_mesh(max_nibool_interfaces_ext_mesh),
245+
nspec_inner_acoustic(nspec_inner_acoustic),
246+
nspec_outer_acoustic(nspec_outer_acoustic),
247+
nspec_inner_elastic(nspec_inner_elastic),
248+
nspec_outer_elastic(nspec_outer_elastic),
249+
nspec_inner_poroelastic(nspec_inner_poroelastic),
250+
nspec_outer_poroelastic(nspec_outer_poroelastic),
251+
num_phase_ispec_acoustic(num_phase_ispec_acoustic),
252+
num_phase_ispec_elastic(num_phase_ispec_elastic),
253+
num_phase_ispec_poroelastic(num_phase_ispec_poroelastic),
254+
num_colors_inner_acoustic(num_colors_inner_acoustic),
255+
num_colors_outer_acoustic(num_colors_outer_acoustic),
256+
num_colors_inner_elastic(num_colors_inner_elastic),
257+
num_colors_outer_elastic(num_colors_outer_elastic){};
258+
};
79259
} // namespace mesh
80260
} // namespace specfem
81261

0 commit comments

Comments
 (0)