From f8b0fc8d0ae5698d180b6a7675f03a706d4cf71a Mon Sep 17 00:00:00 2001
From: Tim Felle Olsen <tife@dtu.dk>
Date: Mon, 14 Oct 2024 07:28:48 +0200
Subject: [PATCH 1/3] Brinkman forcing bug on gpu. Now terminates when
 unsupported mapping is called

---
 src/source_terms/brinkman/filters.f90 | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/source_terms/brinkman/filters.f90 b/src/source_terms/brinkman/filters.f90
index 879f89313ef..b14212d579e 100644
--- a/src/source_terms/brinkman/filters.f90
+++ b/src/source_terms/brinkman/filters.f90
@@ -35,6 +35,7 @@
 !! simulations.
 module filters
   use field, only: field_t
+  use neko_config, only: NEKO_BCKND_DEVICE
   use num_types, only: rp
   implicit none
 
@@ -64,7 +65,11 @@ subroutine smooth_step_field(F, edge0, edge1)
     type(field_t), intent(inout) :: F
     real(kind=rp), intent(in) :: edge0, edge1
 
-    F%x = smooth_step_cpu(F%x, edge0, edge1)
+    if (NEKO_BCKND_DEVICE .eq. 1) then
+       call neko_error('smooth_step_field: not implemented for device')
+    else
+       F%x = smooth_step_cpu(F%x, edge0, edge1)
+    end if
   end subroutine smooth_step_field
 
   !> @brief Apply a permeability function to a field.
@@ -82,7 +87,11 @@ subroutine permeability_field(F_out, x, k_0, k_1, q)
     real(kind=rp), intent(in) :: k_0, k_1
     real(kind=rp), intent(in) :: q
 
-    F_out%x = permeability_cpu(x%x, k_0, k_1, q)
+    if (NEKO_BCKND_DEVICE .eq. 1) then
+       call neko_error('permeability_field: not implemented for device')
+    else
+       F_out%x = permeability_cpu(x%x, k_0, k_1, q)
+    end if
   end subroutine permeability_field
 
   !> @brief Apply a step function to a field.
@@ -96,7 +105,11 @@ subroutine step_function_field(F, x0, value0, value1)
     type(field_t), intent(inout) :: F
     real(kind=rp), intent(in) :: x0, value0, value1
 
-    F%x = step_function_cpu(F%x, x0, value0, value1)
+    if (NEKO_BCKND_DEVICE .eq. 1) then
+       call neko_error('step_function_field: not implemented for device')
+    else
+       F%x = step_function_cpu(F%x, x0, value0, value1)
+    end if
   end subroutine step_function_field
 
 end module filters

From e8aea7172141e8a1c126e4b79d8d9f6713569ffe Mon Sep 17 00:00:00 2001
From: Tim Felle Olsen <tife@dtu.dk>
Date: Mon, 14 Oct 2024 07:48:38 +0200
Subject: [PATCH 2/3] make depend update

---
 src/.depends | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/.depends b/src/.depends
index 2ea758815a5..4bb5fe817d8 100644
--- a/src/.depends
+++ b/src/.depends
@@ -294,7 +294,7 @@ source_terms/bcknd/cpu/boussinesq_source_term_cpu.o : source_terms/bcknd/cpu/bou
 source_terms/bcknd/device/boussinesq_source_term_device.o : source_terms/bcknd/device/boussinesq_source_term_device.f90 math/bcknd/device/device_math.o field/field.o field/field_list.o config/num_types.o 
 source_terms/source_term_fctry.o : source_terms/source_term_fctry.f90 common/utils.o common/json_utils.o source_terms/coriolis_source_term.o source_terms/brinkman_source_term.o source_terms/boussinesq_source_term.o source_terms/const_source_term.o source_terms/source_term.o 
 source_terms/brinkman_source_term.o : source_terms/brinkman_source_term.f90 mesh/point_zone_registry.o mesh/point_zone.o mesh/search_tree/aabb.o common/profiler.o math/signed_distance.o source_terms/brinkman/filters.o device/device.o mesh/tri_mesh.o io/file.o math/field_math.o common/utils.o config/neko_config.o sem/coef.o source_terms/source_term.o field/field_registry.o common/json_utils.o field/field_list.o field/field.o config/num_types.o 
-source_terms/brinkman/filters.o : source_terms/brinkman/filters.f90 source_terms/bcknd/cpu/filters_cpu.o config/num_types.o field/field.o 
+source_terms/brinkman/filters.o : source_terms/brinkman/filters.f90 source_terms/bcknd/cpu/filters_cpu.o config/num_types.o config/neko_config.o field/field.o 
 source_terms/bcknd/cpu/filters_cpu.o : source_terms/bcknd/cpu/filters_cpu.f90 config/num_types.o 
 les/les_model.o : les/les_model.f90 math/bcknd/device/device_math.o math/math.o device/device.o config/neko_config.o gs/gs_ops.o sem/coef.o sem/dofmap.o field/field_registry.o field/field.o config/num_types.o 
 les/les_model_fctry.o : les/les_model_fctry.f90 common/utils.o les/sigma.o les/dynamic_smagorinsky.o les/smagorinsky.o les/vreman.o les/les_model.o 

From d362fa8e4a4014721395f8d9952d23005b8a5f48 Mon Sep 17 00:00:00 2001
From: Tim Felle Olsen <tife@dtu.dk>
Date: Mon, 14 Oct 2024 08:38:27 +0200
Subject: [PATCH 3/3] add missing use

---
 src/.depends                          | 2 +-
 src/source_terms/brinkman/filters.f90 | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/.depends b/src/.depends
index 4bb5fe817d8..3faa2fcb4ed 100644
--- a/src/.depends
+++ b/src/.depends
@@ -294,7 +294,7 @@ source_terms/bcknd/cpu/boussinesq_source_term_cpu.o : source_terms/bcknd/cpu/bou
 source_terms/bcknd/device/boussinesq_source_term_device.o : source_terms/bcknd/device/boussinesq_source_term_device.f90 math/bcknd/device/device_math.o field/field.o field/field_list.o config/num_types.o 
 source_terms/source_term_fctry.o : source_terms/source_term_fctry.f90 common/utils.o common/json_utils.o source_terms/coriolis_source_term.o source_terms/brinkman_source_term.o source_terms/boussinesq_source_term.o source_terms/const_source_term.o source_terms/source_term.o 
 source_terms/brinkman_source_term.o : source_terms/brinkman_source_term.f90 mesh/point_zone_registry.o mesh/point_zone.o mesh/search_tree/aabb.o common/profiler.o math/signed_distance.o source_terms/brinkman/filters.o device/device.o mesh/tri_mesh.o io/file.o math/field_math.o common/utils.o config/neko_config.o sem/coef.o source_terms/source_term.o field/field_registry.o common/json_utils.o field/field_list.o field/field.o config/num_types.o 
-source_terms/brinkman/filters.o : source_terms/brinkman/filters.f90 source_terms/bcknd/cpu/filters_cpu.o config/num_types.o config/neko_config.o field/field.o 
+source_terms/brinkman/filters.o : source_terms/brinkman/filters.f90 source_terms/bcknd/cpu/filters_cpu.o common/utils.o config/num_types.o config/neko_config.o field/field.o 
 source_terms/bcknd/cpu/filters_cpu.o : source_terms/bcknd/cpu/filters_cpu.f90 config/num_types.o 
 les/les_model.o : les/les_model.f90 math/bcknd/device/device_math.o math/math.o device/device.o config/neko_config.o gs/gs_ops.o sem/coef.o sem/dofmap.o field/field_registry.o field/field.o config/num_types.o 
 les/les_model_fctry.o : les/les_model_fctry.f90 common/utils.o les/sigma.o les/dynamic_smagorinsky.o les/smagorinsky.o les/vreman.o les/les_model.o 
diff --git a/src/source_terms/brinkman/filters.f90 b/src/source_terms/brinkman/filters.f90
index b14212d579e..d8f7b71ac4b 100644
--- a/src/source_terms/brinkman/filters.f90
+++ b/src/source_terms/brinkman/filters.f90
@@ -37,6 +37,7 @@ module filters
   use field, only: field_t
   use neko_config, only: NEKO_BCKND_DEVICE
   use num_types, only: rp
+  use utils, only: neko_error
   implicit none
 
   private