From e65b1477b08d371dd839e7e6802a23b3eb899abe Mon Sep 17 00:00:00 2001
From: Matteo Cicuttin <datafl4sh@toxicnet.eu>
Date: Thu, 6 May 2021 20:42:39 +0200
Subject: [PATCH] Fixed build without GPU.

---
 CMakeLists.txt              | 13 +++++++++----
 include/maxwell_interface.h |  7 +++++--
 include/param_loader.h      |  4 ++++
 src/entity_data.cpp         |  2 ++
 src/maxwell_cpu.cpp         | 14 ++++++++------
 src/maxwell_interface.cpp   |  3 ++-
 6 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3b1b3b..53d8023 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -250,16 +250,21 @@ set(LIBGMSHDG_SOURCES src/gmsh_io.cpp
                       src/connectivity.cpp
                       src/entity_data.cpp
                       src/kernels_cpu.cpp
-                      src/kernels_gpu_mi.cpp
-                      src/kernels_cuda.cu
                       src/maxwell_interface.cpp
                       src/maxwell_cpu.cpp
-                      src/maxwell_gpu.cpp
-                      src/maxwell_kernels_cuda.cu
                       src/maxwell_common.cpp
                       src/param_loader.cpp
                     )
 
+if (OPT_ENABLE_GPU_SOLVER)
+    set(LIBGMSHDG_SOURCES ${LIBGMSHDG_SOURCES}
+        src/maxwell_gpu.cpp
+        src/maxwell_kernels_cuda.cu
+        src/kernels_gpu_mi.cpp
+        src/kernels_cuda.cu
+    )
+endif()
+
 add_library(gmshdg SHARED ${LIBGMSHDG_SOURCES})
 target_link_libraries(gmshdg ${LINK_LIBS})
 
diff --git a/include/maxwell_interface.h b/include/maxwell_interface.h
index 27d62b4..29e163e 100644
--- a/include/maxwell_interface.h
+++ b/include/maxwell_interface.h
@@ -12,7 +12,10 @@
 
 #include "gmsh_io.h"
 #include "types.h"
+
+#ifdef ENABLE_GPU_SOLVER
 #include "gpu_support.hpp"
+#endif /* ENABLE_GPU_SOLVER */
 
 #ifndef HIDE_THIS_FROM_NVCC
 #include "param_loader.h"
@@ -255,14 +258,14 @@ struct solver_state_gpu
 #ifndef HIDE_THIS_FROM_NVCC
 void init_from_model(const model&, solver_state&);
 void init_matparams(const model&, solver_state&, const parameter_loader&);
-void apply_operator(solver_state&, const field&, field&);
+//void apply_operator(solver_state&, const field&, field&);
 void export_to_silo(const model&, const solver_state&, const std::string&);
 void timestep(solver_state&);
 
 #ifdef ENABLE_GPU_SOLVER
 void init_from_model(const model&, solver_state_gpu&);
 void init_matparams(const model&, solver_state_gpu&, const parameter_loader&);
-void apply_operator(solver_state_gpu&, const field_gpu&, field_gpu&);
+//void apply_operator(solver_state_gpu&, const field_gpu&, field_gpu&);
 void export_to_silo(const model&, const solver_state_gpu&, const std::string&);
 void timestep(solver_state_gpu&);
 #endif /* ENABLE_GPU_SOLVER */
diff --git a/include/param_loader.h b/include/param_loader.h
index ac216b3..20630ee 100644
--- a/include/param_loader.h
+++ b/include/param_loader.h
@@ -1,6 +1,10 @@
 #pragma once
 
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Weverything"
 #include "sol/sol.hpp"
+#pragma clang diagnostic pop
+
 #include "gmsh_io.h"
 
 class parameter_loader_base
diff --git a/src/entity_data.cpp b/src/entity_data.cpp
index b616b05..2e8a5b1 100644
--- a/src/entity_data.cpp
+++ b/src/entity_data.cpp
@@ -1,5 +1,6 @@
 #include "entity_data.h"
 
+#ifdef ENABLE_GPU_SOLVER
 entity_data_gpu::entity_data_gpu()
 {
 }
@@ -89,3 +90,4 @@ entity_data_gpu::~entity_data_gpu()
 {
 }
 
+#endif /* ENABLE_GPU_SOLVER */
\ No newline at end of file
diff --git a/src/maxwell_cpu.cpp b/src/maxwell_cpu.cpp
index c8ffddb..e3c3c96 100644
--- a/src/maxwell_cpu.cpp
+++ b/src/maxwell_cpu.cpp
@@ -181,7 +181,8 @@ eval_interface_sources(const model& mod, const parameter_loader& mpl,
     }
 }
 
-void init_from_model(const model& mod, solver_state& state)
+void
+init_from_model(const model& mod, solver_state& state)
 {
     state.emf_curr.resize( mod.num_dofs() );
     state.emf_next.resize( mod.num_dofs() );
@@ -211,7 +212,8 @@ void init_from_model(const model& mod, solver_state& state)
     state.curr_timestep = 0;
 }
 
-void compute_curls(solver_state& state, const field& curr, field& next)
+static void
+compute_curls(solver_state& state, const field& curr, field& next)
 {
     for (const auto& ed : state.eds)
     {
@@ -316,7 +318,7 @@ compute_fluxes_planar(solver_state& state)
     }
 }
 
-void
+static void
 compute_fluxes(solver_state& state, const field& in, field& out)
 {
     compute_field_jumps(state, in);
@@ -333,7 +335,7 @@ compute_fluxes(solver_state& state, const field& in, field& out)
     }
 }
 
-void
+static void
 compute_euler_update(solver_state& state, const field& y, const field& k, double dt, field& out)
 {
     for (size_t i = 0; i < out.num_dofs; i++)
@@ -354,7 +356,7 @@ compute_euler_update(solver_state& state, const field& y, const field& k, double
     }
 }
 
-void
+static void
 compute_rk4_weighted_sum(solver_state& state, const field& in, double dt, field& out)
 {
     for (size_t i = 0; i < out.num_dofs; i++)
@@ -375,7 +377,7 @@ compute_rk4_weighted_sum(solver_state& state, const field& in, double dt, field&
     }
 }
 
-void
+static void
 apply_operator(solver_state& state, const field& curr, field& next)
 {
     compute_curls(state, curr, next);
diff --git a/src/maxwell_interface.cpp b/src/maxwell_interface.cpp
index 764174f..8734f17 100644
--- a/src/maxwell_interface.cpp
+++ b/src/maxwell_interface.cpp
@@ -14,6 +14,7 @@ field::resize(size_t p_num_dofs)
     num_dofs = p_num_dofs;
 }
 
+#ifdef ENABLE_GPU_SOLVER
 void
 field_gpu::zero()
 {
@@ -24,7 +25,6 @@ field_gpu::zero()
     Hy.zero();
     Hz.zero();
 }
-
 void
 field_gpu::resize(size_t p_num_dofs)
 {
@@ -149,5 +149,6 @@ material_params_gpu::copyin(const material_params& mp)
     bc_coeffs.copyin(mp.bc_coeffs.data(), mp.bc_coeffs.size());
 }
 
+#endif /* ENABLE_GPU_SOLVER */
 
 } // namespace maxwell
-- 
GitLab