Skip to content

Commit 00289e1

Browse files
authored
Rationalize CMake and switch to C++17 to accommodate MFEM (#320)
* Add override, and 1 delete per line * Add override * Correct delete * Make destructor virtual * Fix visit ambiguity * Fix visit ambiguity * Removing using namespace std from library * Fix example usage of std * Change examples bak * Remove debug statements * Rationalize Cmakefiles * Revert some changes * Add white space * Allow both cmake and configure for MFEM builds * Add missing using statements
1 parent 80aa762 commit 00289e1

27 files changed

+203
-151
lines changed

CMakeLists.txt

Lines changed: 29 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -110,133 +110,45 @@ set(CAROM_HAVE_LAPACK ${LAPACK_FOUND})
110110
set(CAROM_HAVE_HDF5 ${HDF5_FOUND})
111111

112112
if (USE_MFEM)
113-
find_library(MFEM mfem "${CMAKE_SOURCE_DIR}/dependencies/mfem" "${MFEM_DIR}/lib")
114-
find_library(HYPRE HYPRE "${CMAKE_SOURCE_DIR}/dependencies/hypre/src/hypre/lib" "${HYPRE_DIR}/lib")
115-
find_library(PARMETIS parmetis "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/build/lib/libparmetis" "${PARMETIS_DIR}/lib")
116-
find_library(METIS metis "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/build/lib/libmetis" "${METIS_DIR}/lib")
117-
find_path(MFEM_INCLUDES mfem.hpp "${CMAKE_SOURCE_DIR}/dependencies/mfem" "${MFEM_DIR}/include")
118-
find_path(HYPRE_INCLUDES HYPRE.h "${CMAKE_SOURCE_DIR}/dependencies/hypre/src/hypre/include" "${HYPRE_DIR}/include")
119-
find_path(PARMETIS_INCLUDES metis.h "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/metis/include" "${PARMETIS_DIR}/metis/include")
113+
# Try to find MFEM installed using cmake
114+
find_package(mfem NAMES MFEM HINTS "${MFEM_DIR}"
115+
"${MFEM_DIR}/lib/cmake/mfem" "${CMAKE_SOURCE_DIR}/dependencies/mfem/lib/cmake/mfem" NO_DEFAULT_PATH QUIET)
116+
if (mfem_FOUND)
117+
message(STATUS "Found mfem config in: ${mfem_DIR} (version ${MFEM_VERSION})")
118+
else()
119+
# Try to find MFEM installed using configure
120+
find_library(MFEM mfem HINTS "${MFEM_DIR}/lib" "${CMAKE_SOURCE_DIR}/dependencies/mfem")
121+
find_library(HYPRE HYPRE HINTS "${HYPRE_DIR}/lib" "${CMAKE_SOURCE_DIR}/dependencies/hypre/src/hypre/lib")
122+
find_library(PARMETIS parmetis HINTS "${PARMETIS_DIR}/lib" "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/build/lib/libparmetis")
123+
find_library(METIS metis HINTS "${METIS_DIR}/lib" "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/build/lib/libmetis")
124+
find_path(MFEM_INCLUDES mfem.hpp HINTS "${MFEM_DIR}/include" "${CMAKE_SOURCE_DIR}/dependencies/mfem")
125+
find_path(HYPRE_INCLUDES HYPRE.h HINTS "${HYPRE_DIR}/include" "${CMAKE_SOURCE_DIR}/dependencies/hypre/src/hypre/include")
126+
find_path(PARMETIS_INCLUDES metis.h "${PARMETIS_DIR}/metis/include" "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/metis/include")
127+
128+
if (${MFEM} STREQUAL "MFEM-NOTFOUND")
129+
error( "MFEM not found" )
130+
else()
131+
message(STATUS "MFEM library:" ${MFEM})
132+
message(STATUS "MFEM includes:" ${MFEM_INCLUDES})
133+
endif()
134+
endif()
120135
endif()
121136

122-
add_subdirectory(lib)
137+
set(CAROM_LIBS ${MPI_C_LINK_FLAGS} ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES} MPI::MPI_C ${MPI_FORTRAN_LINK_FLAGS} ${MPI_FORTRAN_LIBRARIES} MPI::MPI_Fortran)
138+
set(CAROM_INCS ${CMAKE_CURRENT_SOURCE_DIR} ${MPI_C_INCLUDE_DIRS})
123139

124-
# Use the C++11 standard as an entire feature instead of
125-
# enumerating individual compiler features for simplicity
126-
target_compile_features(ROM PRIVATE cxx_std_11)
140+
add_subdirectory(lib)
127141

128142
if (ENABLE_EXAMPLES)
143+
add_subdirectory(examples/misc)
129144
if (USE_MFEM)
130-
set(examples
131-
poisson_global_rom
132-
poisson_local_rom_greedy
133-
dg_advection_global_rom
134-
dg_advection_local_rom_matrix_interp
135-
mixed_nonlinear_diffusion
136-
nonlinear_elasticity_global_rom
137-
linear_elasticity_global_rom
138-
maxwell_global_rom
139-
de_parametric_maxwell_greedy
140-
maxwell_local_rom_greedy
141-
grad_div_global_rom
142-
elliptic_eigenproblem_global_rom
143-
dg_advection
144-
nonlinear_elasticity
145-
heat_conduction
146-
heat_conduction_dmdc
147-
parametric_heat_conduction
148-
de_parametric_heat_conduction_greedy
149-
de_dg_advection_greedy
150-
wave_equation
151-
dg_euler
152-
local_dw_csv
153-
parametric_tw_csv
154-
parametric_dw_csv
155-
parametric_dmdc_heat_conduction)
156-
set(example_directories
157-
prom
158-
prom
159-
prom
160-
prom
161-
prom
162-
prom
163-
prom
164-
prom
165-
prom
166-
prom
167-
prom
168-
prom
169-
dmd
170-
dmd
171-
dmd
172-
dmd
173-
dmd
174-
dmd
175-
dmd
176-
dmd
177-
dmd
178-
dmd
179-
dmd
180-
dmd
181-
dmd)
182-
183-
list(LENGTH examples len1)
184-
math(EXPR len2 "${len1} - 1")
185-
186-
foreach(val RANGE ${len2})
187-
list(GET examples ${val} name)
188-
list(GET example_directories ${val} example_dir)
189-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples/${example_dir})
190-
add_executable(${name} examples/${example_dir}/${name}.cpp)
191-
192-
target_link_libraries(${name}
193-
PRIVATE ROM ${MPI_C_LINK_FLAGS} ${MPI_C_LIBRARIES} MPI::MPI_C ${MPI_FORTRAN_LINK_FLAGS} ${MPI_FORTRAN_LIBRARIES} MPI::MPI_Fortran)
194-
target_include_directories(${name}
195-
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
196-
${MPI_C_INCLUDE_DIRS})
197-
target_compile_features(${name} PRIVATE cxx_std_11)
198-
endforeach() # IN LISTS examples
145+
add_subdirectory(examples/prom)
146+
add_subdirectory(examples/dmd)
199147
file(COPY examples/data DESTINATION ${CMAKE_BINARY_DIR}/examples)
200148
file(COPY examples/merlin DESTINATION ${CMAKE_BINARY_DIR}/examples)
201149
file(COPY examples/dmd/heat_conduction_csv.sh DESTINATION ${CMAKE_BINARY_DIR}/examples/dmd)
202150
file(COPY examples/dmd/heat_conduction_hdf.sh DESTINATION ${CMAKE_BINARY_DIR}/examples/dmd)
203-
endif()
204-
205-
set(misc_example_names
206-
combine_samples)
207-
208-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples/misc)
209-
210-
foreach(name IN LISTS misc_example_names)
211-
add_executable(${name} examples/misc/${name}.cpp)
212-
213-
target_link_libraries(${name}
214-
PRIVATE ROM ${MPI_C_LINK_FLAGS} ${MPI_C_LIBRARIES} MPI::MPI_C ${MPI_FORTRAN_LINK_FLAGS} ${MPI_FORTRAN_LIBRARIES} MPI::MPI_Fortran)
215-
target_include_directories(${name}
216-
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
217-
${MPI_C_INCLUDE_DIRS})
218-
target_compile_features(${name} PRIVATE cxx_std_11)
219-
endforeach(name) # IN LISTS misc_exmaple_names
220-
221-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
222-
223-
if (USE_MFEM)
224-
set(regression_test_names
225-
basisComparator
226-
checkError
227-
computeSpeedup
228-
solutionComparator
229-
fileComparator)
230-
231-
foreach(name IN LISTS regression_test_names)
232-
add_executable(${name} regression_tests/${name}.cpp)
233-
target_link_libraries(${name}
234-
PRIVATE ROM ${MPI_C_LINK_FLAGS} ${MPI_C_LIBRARIES} MPI::MPI_C ${MPI_FORTRAN_LINK_FLAGS} ${MPI_FORTRAN_LIBRARIES} MPI::MPI_Fortran)
235-
target_include_directories(${name}
236-
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
237-
${MPI_C_INCLUDE_DIRS})
238-
target_compile_features(${name} PRIVATE cxx_std_11)
239-
endforeach(name) # IN LISTS regression_test_names
151+
add_subdirectory(regression_tests)
240152
endif()
241153
endif(ENABLE_EXAMPLES)
242154

examples/dmd/CMakeLists.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
###############################################################################
2+
#
3+
# Copyright (c) 2013-2024, Lawrence Livermore National Security, LLC
4+
# and other libROM project developers. See the top-level COPYRIGHT
5+
# file for details.
6+
#
7+
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
8+
#
9+
###############################################################################
10+
11+
set(examples
12+
dg_advection
13+
nonlinear_elasticity
14+
heat_conduction
15+
heat_conduction_dmdc
16+
parametric_heat_conduction
17+
de_parametric_heat_conduction_greedy
18+
de_dg_advection_greedy
19+
wave_equation
20+
dg_euler
21+
local_dw_csv
22+
parametric_tw_csv
23+
parametric_dw_csv
24+
parametric_dmdc_heat_conduction)
25+
26+
foreach(name IN LISTS examples)
27+
add_executable(${name} ${name}.cpp)
28+
target_link_libraries(${name} PRIVATE ROM ${CAROM_LIBS})
29+
target_include_directories(${name} PRIVATE ${CAROM_INCS})
30+
target_compile_features(${name} PRIVATE cxx_std_17)
31+
endforeach()

examples/dmd/de_dg_advection_greedy.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,18 @@
7272
#include "utils/CSVDatabase.h"
7373

7474

75-
using namespace std;
75+
using std::vector;
76+
using std::cout;
77+
using std::endl;
78+
using std::flush;
79+
using std::max;
80+
using std::min;
81+
using std::to_string;
82+
using std::ifstream;
83+
using std::ofstream;
84+
using std::ostringstream;
85+
using std::setfill;
86+
using std::setw;
7687
using namespace mfem;
7788

7889
// Choice for the problem setup. The fluid velocity, initial condition and

examples/dmd/de_parametric_heat_conduction_greedy.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,18 @@
7070
#define mkdir(dir, mode) _mkdir(dir)
7171
#endif
7272

73-
using namespace std;
73+
using std::vector;
74+
using std::cout;
75+
using std::endl;
76+
using std::flush;
77+
using std::max;
78+
using std::min;
79+
using std::to_string;
80+
using std::ifstream;
81+
using std::ofstream;
82+
using std::ostringstream;
83+
using std::setfill;
84+
using std::setw;
7485
using namespace mfem;
7586

7687
/** After spatial discretization, the conduction model can be written as:

examples/dmd/heat_conduction_dmdc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ int main(int argc, char *argv[])
210210
// handle triangular, quadrilateral, tetrahedral and hexahedral meshes
211211
// with the same code.
212212
Mesh *mesh;
213-
if (mesh_file == "")
213+
if (strcmp(mesh_file, "") == 0 )
214214
{
215215
mesh = new Mesh(Mesh::MakeCartesian2D(2, 2, Element::QUADRILATERAL));
216216
}

examples/dmd/parametric_dmdc_heat_conduction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ int main(int argc, char *argv[])
323323
// handle triangular, quadrilateral, tetrahedral and hexahedral meshes
324324
// with the same code.
325325
Mesh *mesh;
326-
if (mesh_file == "")
326+
if (strcmp(mesh_file, "") == 0 )
327327
{
328328
mesh = new Mesh(Mesh::MakeCartesian2D(2, 2, Element::QUADRILATERAL));
329329
}

examples/misc/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(examples
2+
combine_samples)
3+
4+
foreach(name IN LISTS examples)
5+
add_executable(${name} ${name}.cpp)
6+
target_link_libraries(${name} PRIVATE ROM ${CAROM_LIBS})
7+
target_include_directories(${name} PRIVATE ${CAROM_INCS})
8+
target_compile_features(${name} PRIVATE cxx_std_17)
9+
endforeach()

examples/prom/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
###############################################################################
2+
#
3+
# Copyright (c) 2013-2024, Lawrence Livermore National Security, LLC
4+
# and other libROM project developers. See the top-level COPYRIGHT
5+
# file for details.
6+
#
7+
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
8+
#
9+
###############################################################################
10+
set(examples
11+
poisson_global_rom
12+
poisson_local_rom_greedy
13+
dg_advection_global_rom
14+
dg_advection_local_rom_matrix_interp
15+
mixed_nonlinear_diffusion
16+
nonlinear_elasticity_global_rom
17+
linear_elasticity_global_rom
18+
maxwell_global_rom
19+
de_parametric_maxwell_greedy
20+
maxwell_local_rom_greedy
21+
elliptic_eigenproblem_global_rom)
22+
23+
foreach(name IN LISTS examples)
24+
add_executable(${name} ${name}.cpp)
25+
target_link_libraries(${name} PRIVATE ROM ${CAROM_LIBS})
26+
target_include_directories(${name} PRIVATE ${CAROM_INCS})
27+
target_compile_features(${name} PRIVATE cxx_std_17)
28+
endforeach()

examples/prom/de_parametric_maxwell_greedy.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,20 @@
7272
#define mkdir(dir, mode) _mkdir(dir)
7373
#endif
7474

75-
using namespace std;
75+
using std::vector;
76+
using std::set;
77+
using std::map;
78+
using std::make_pair;
79+
using std::string;
80+
using std::cout;
81+
using std::endl;
82+
using std::flush;
83+
using std::max;
84+
using std::min;
85+
using std::to_string;
86+
using std::ifstream;
87+
using std::ofstream;
88+
using std::ostringstream;
7689
using namespace mfem;
7790

7891
// Exact solution, E, and r.h.s., f. See below for implementation.

examples/prom/elliptic_eigenproblem_global_rom.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ int main(int argc, char *argv[])
234234
// handle triangular, quadrilateral, tetrahedral and hexahedral meshes
235235
// with the same code.
236236
Mesh *mesh;
237-
if (mesh_file == "")
237+
if (strcmp(mesh_file, "") == 0 )
238238
{
239239
mesh = new Mesh(Mesh::MakeCartesian2D(2, 2, Element::QUADRILATERAL));
240240
}

0 commit comments

Comments
 (0)