Skip to content

Commit 686449c

Browse files
authored
Merge pull request #38 from MiCurry/cmake-add-spherical
This commit adds the ability for the CMake build system to build the spherical version of ModEM. The user can add the -CBUILD_SPHERICAL=ON flag to build the spherical version. Similar to the Configure script, it produces a warning to the user alerting them that they cannot use it as simply as normal MT setups. In order to bypass the warning the error message indicates they should use the -DFORCE_SPHERICAL=ON.
2 parents 695757c + 172bea8 commit 686449c

6 files changed

Lines changed: 90 additions & 19 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ option(BUILD_MPI "Build MPI version of MPI" ON)
1010
option(BUILD_HDF5 "Build with HDF5" OFF)
1111
option(FG "Build the Fine-Grained ModEM Version - (Only compatiable with SP2)" OFF)
1212
option(USE_C_TIMERS "Use the C timers in ModEM_timers" OFF)
13+
option(BUILD_SPHERICAL "Specify whether to build Spherical Coordinate version of ModEM" OFF)
1314

1415
set(FORWARD_FORMULATION "SP2" CACHE STRING "Set the forward formulation: < MF | SP | SP2 >")
1516
set(MODEM_BUILD_DIMS "3D" CACHE STRING "Specify whether to build either the 2D or 3D versino of ModEM < 2D | 3D >")
@@ -72,6 +73,14 @@ if (FG AND NOT FORWARD_FORMULATION STREQUAL SP2)
7273
message(FATAL_ERROR "You cannot build 'FG' with '${FORWARD_FORMULATION}' - Only SP2: -DFG=on -DFORWARD_FORMULATION=SP2")
7374
endif()
7475

76+
if (BUILD_SPHERICAL AND NOT FORCE_SPHERICAL)
77+
message(SEND_ERROR
78+
"The Spherical Version is experimental and will not work with traditional MT source setup."
79+
"For more information please see 'Spherical Coordinates' section in the README.md.\n"
80+
"To bypass this error run cmake with: '-DBUILD_SPHERICAL -DFORCE_SPHERICAL' flags"
81+
)
82+
endif()
83+
7584
if (BUILD_MPI)
7685
add_compile_definitions(MPI)
7786
endif()

docs/source/building_with_cmake.rst

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Building ModEM with CMake
3939

4040
or if you are in ``ModEM/build``:
4141

42-
``cmake -S .. -B . -LH``
42+
``cmake .. -LH``
4343

4444
Navigate into ModEM and create a new directory, ``build``. CMake is nice in that
4545
it allows us to build out of source. Change directory into this ``build`` directory:
@@ -54,17 +54,13 @@ Now, we can run CMake:
5454

5555
.. code-block:: bash
5656
57-
$ cmake -S .. -B . -DCMAKE_Fortran_COMPILER=mpifort
58-
59-
In the above command, the ``-S ..`` says that CMake should look in the directory
60-
above for the source and the ``-B .`` specifies that CMake should build in the
61-
current working directory.
57+
$ cmake .. -DCMAKE_Fortran_COMPILER=mpifort
6258
6359
The above command prints some output:
6460

6561
.. code-block:: bash
6662
67-
$ cmake -S .. -B . -DCMAKE_Fortran_COMPILER=mpifort
63+
$ cmake .. -DCMAKE_Fortran_COMPILER=mpifort
6864
-- The Fortran compiler identification is LLVMFlang 20.1.8
6965
-- Detecting Fortran compiler ABI info
7066
-- Detecting Fortran compiler ABI info - done
@@ -100,7 +96,7 @@ difficulties finding them, you can specify them by using the
10096

10197
.. code-block:: bash
10298
103-
$ cmake -S .. -B -DLAPACK_LIBRARIES=/path/to/lapacklib/liblapack.a -DBLAS_LIBRARIES=/path/to/lablaslib/libblas.a
99+
$ cmake .. -DLAPACK_LIBRARIES=/path/to/lapacklib/liblapack.a -DBLAS_LIBRARIES=/path/to/lablaslib/libblas.a
104100
105101
106102
After running CMake command above, and you see that the build files have been
@@ -182,7 +178,7 @@ Again, once can use the following to display all the available options:
182178
183179
$ mkdir build
184180
$ cd build
185-
$ cmake -B .. -S . -LH
181+
$ cmake .. -LH
186182
187183
* 2D/3D Builds:
188184
* ``-DMODEM_BUILD_DIMS=<2D | 3D>``
@@ -243,6 +239,39 @@ also explicitly specify your feature set:
243239
$ cmake .. -DCMAKE_Fortran_FLAGS="-msse4.2"
244240
245241
242+
243+
Building ModEM Spherical Version
244+
==================================
245+
246+
.. warning::
247+
248+
The Spherical version of ModEM is experimental and will not work with
249+
traditional MT source setup. MT forward modeling in spherical coordinates
250+
relies on an external 1D forward model and the secondary field formulation
251+
option in ModEM to be physically correct.
252+
253+
Using spherical coordinates with the tradtional MT source setup has not
254+
been shown to be physically accurate.
255+
256+
257+
To build the experimental spherical version of ModEM you can specify the
258+
``BUILD_SPHERICAL`` argument in CMake:
259+
260+
.. code-block:: bash
261+
262+
$ cmake .. -DBUILD_SPHERICAL=on
263+
264+
265+
After running the above, you will presented with the same warning printed
266+
above, in order to fully build the experimental version, you must also pass the
267+
`FORCE_SPHERICAL` argument as well:
268+
269+
.. code-block:: bash
270+
271+
$ cmake .. -DBUILD_SPHERICAL=on -DFORCE_SPHERICAL=on
272+
$ make
273+
274+
246275
Building GPU capable ModEM with CMake
247276
======================================
248277

@@ -271,7 +300,7 @@ To build ModEM with GPU CUDA we can run the following command:
271300
.. code-block:: bash
272301
273302
$ mkdir build; cd build
274-
$ cmake -S .. -B . -DCMAKE_Fortran_COMPILER=mpifort -DBUILD_GPU=CUDA
303+
$ cmake .. -DCMAKE_Fortran_COMPILER=mpifort -DBUILD_GPU=CUDA
275304
276305
Again, you may need to specify LAPACK or BLAS libraries, see
277306
:ref:`findlapack_n_blas`. After building, you should see confirmation that the
@@ -328,14 +357,14 @@ You can specify your desired compute capability by specifying the
328357

329358
.. code-block:: bash
330359
331-
$ cmake -S .. -B . -DCMAKE_Fortran_COMPILER=mpifort -DBUILD_GPU=CUDA -DCMAKE_CUDA_ARCHITECTURES="35;50;72"
360+
$ cmake .. -DCMAKE_Fortran_COMPILER=mpifort -DBUILD_GPU=CUDA -DCMAKE_CUDA_ARCHITECTURES="35;50;72"
332361
333362
This will generate code for Cuda architectures 35, 50 and 72. You can also tell
334363
CMake to use whatever capability your GPU can handle with the ``native`` keyword:
335364

336365
.. code-block:: bash
337366
338-
$ cmake -S .. -B . -DCMAKE_Fortran_COMPILER=mpifort -DBUILD_GPU=CUDA -DCMAKE_CUDA_ARCHITECTURES="native"
367+
$ cmake .. -DCMAKE_Fortran_COMPILER=mpifort -DBUILD_GPU=CUDA -DCMAKE_CUDA_ARCHITECTURES="native"
339368
340369
You can also specify ``all`` or ``all-major``, which will generate code for all
341370
or all major version. For more information on available options see:
@@ -404,3 +433,5 @@ Compiling ModEM GPU Code with HIP
404433
----------------------------------
405434

406435
Compiling the HIP code with CMAKE is currently a WIP.
436+
437+

f90/3D_MT/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,26 @@ add_subdirectory(modelParam)
2121

2222
target_sources(${MODEM_EXE}
2323
PRIVATE DataFunc.f90
24+
PRIVATE DataIO.f90
2425
PRIVATE EMfieldInterp.f90
2526
PRIVATE ForwardSolver.f90
26-
PRIVATE GridCalc.f90
27-
#PRIVATE GridCalcS.f90
2827
PRIVATE GridDef.f90
2928
PRIVATE Main.f90
30-
#PRIVATE mtInvSetup.f90
3129
PRIVATE SolnSpace.f90
3230
PRIVATE SolverSens.f90
3331
PRIVATE Sub_MPI.f90
3432
)
3533

34+
if (!BUILD_SPHERICAL)
35+
target_sources(${MODEM_EXE}
36+
PRIVATE GridCalc.f90
37+
)
38+
else()
39+
target_sources(${MODEM_EXE}
40+
PRIVATE GridCalcS.f90
41+
)
42+
endif()
43+
3644
if(BUILD_MPI)
3745
target_sources(${MODEM_EXE}
3846
PRIVATE Sub_MPI.f90

f90/3D_MT/FWD/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
add_subdirectory(Mod2d)
44

5+
if (!BUILD_SPHERICAL)
6+
target_sources(${MODEM_EXE}
7+
PRIVATE boundary_ws.f90
8+
)
9+
else()
10+
target_sources(${MODEM_EXE}
11+
PRIVATE boundary_wsS.f90
12+
)
13+
endif()
14+
515
target_sources(${MODEM_EXE}
6-
PRIVATE boundary_ws.f90
7-
#PRIVATE boundary_wsS.f90
816
PRIVATE nestedEM.f90
917
)
1018

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# f90/3D_MT/SP_Topology CMakeLists.txt
22

33
target_sources(${MODEM_EXE}
4-
PRIVATE MetricElements_CSG.f90
54
PRIVATE spOpTools.f90
65
PRIVATE spOpTopology_SG.f90
76
PRIVATE vecTranslate.f90
8-
)
7+
)
8+
9+
if (!BUILD_SPHERICAL)
10+
target_sources(${MODEM_EXE}
11+
PRIVATE MetricElements_CSG.f90
12+
)
13+
else()
14+
target_sources(${MODEM_EXE}
15+
PRIVATE MetricElements_SSG.f90
16+
)
17+
endif()

f90/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ elseif (MODEM_BUILD_DIMS STREQUAL 3D)
88
set(MODEM_EXE Mod3DMT_${FORWARD_FORMULATION})
99
set(MODEM_MAIN_FILE Mod3DMT.f90)
1010
set(DIM_DIR 3D_MT)
11+
12+
message(STATUS "Spherical ${BUILD_SPHERICAL}")
13+
14+
if (BUILD_SPHERICAL)
15+
string(APPEND MODEM_EXE "_SPH")
16+
endif()
1117
endif()
1218

1319
add_executable(${MODEM_EXE} ${MODEM_MAIN_FILE})

0 commit comments

Comments
 (0)