Skip to content

Commit

Permalink
Merge pull request #1648 from timfelle/fix/ibm_device
Browse files Browse the repository at this point in the history
Fix bugs and update mesh preparation script
  • Loading branch information
timfelle authored Dec 19, 2024
2 parents 3002ff6 + cb78a6f commit f3f6eb1
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 124 deletions.
2 changes: 1 addition & 1 deletion examples/immersed_bunny/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
!.gitignore
!*.case
!readme.md
!run.sh
!prepare.sh
!bunny.stl
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,34 @@
# Define the help function

function help() {
echo -e "run.sh case"
echo -e " Generate a mesh and run all the desired case."
echo -e "prepare.sh case"
echo -e " Generate a mesh to prepare for the desired case."
echo -e " The input arguments are the number of cells in the x, y, and z"
echo -e " directions, respectively."
echo -e ""
echo -e " If no input arguments are provided, the default mesh size is"
echo -e " 32x8x8."
echo -e ""
echo -e " Example usage:"
echo -e " run.sh -x32 -y8 -z8 case_name.case"
echo -e " prepare.sh -x32 -y8 -z8"
echo -e ""
echo -e " Options:"
echo -e " -h, --help Show this help message and exit."
echo -e " -x# Number of cells in the x direction."
echo -e " -y# Number of cells in the y direction."
echo -e " -z# Number of cells in the z direction."
echo -e " -a, --all Run all cases."
echo -e " -q, --quiet Suppress output."
echo -e ""
echo -e " See Readme for additional details."
exit 0
}
if [ $# -eq 0 ]; then ALL=1; fi

# Handle options
Nx=32 && Ny=8 && Nz=8
for arg in "$@"; do
if [ "${arg:0:2}" == "--" ]; then
case ${arg:2} in
help) help ;;
all) ALL=1 ;;
quiet) QUIET=1 ;;
*) echo -e "Invalid option: $arg" >&2 && help ;;
esac
Expand All @@ -44,7 +41,6 @@ for arg in "$@"; do
x) Nx=${arg:2} ;;
y) Ny=${arg:2} ;;
z) Nz=${arg:2} ;;
a) ALL=1 ;;
q) QUIET=1 ;;
*) echo -e "Invalid option: ${arg:1}" >&2 && help ;;
esac
Expand All @@ -53,38 +49,25 @@ for arg in "$@"; do
fi
done

if [ "$ALL" ]; then
cases=$(find $(dirname $0) -name "*.case")
fi

# ============================================================================ #
# Ensure Neko can be found and set default mesh size

if [ "$NEKO_DIR" ]; then
PATH=$NEKO_DIR/bin:$PATH
fi

if [[ -z $(which neko) ]]; then
if [[ -z $(which genmeshbox) ]]; then
echo -e "Neko not found." >&2
echo -e "Please ensure Neko is installed and in your PATH." >&2
echo -e "Alternatively, set the NEKO_DIR environment variable." >&2
exit 1
fi

# ============================================================================ #
# Generate mesh and run case
# Generate mesh and prepare case

echo "Generating mesh with dimensions: $Nx $Ny $Nz"
genmeshbox 0 4 0 1 0 1 $Nx $Ny $Nz .false. .false. .false.

for case in $cases; do
echo "Running case: $case"
if [ "$QUIET" ]; then
neko $case >/dev/null
else
neko $case >${case%.case}.log
fi
done

# End of file
# ============================================================================ #
57 changes: 0 additions & 57 deletions examples/immersed_bunny/run.sh

This file was deleted.

2 changes: 1 addition & 1 deletion examples/immersed_zones/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
!.gitignore
!*.case
!readme.md
!run.sh
!prepare.sh
73 changes: 73 additions & 0 deletions examples/immersed_zones/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/bash

# ============================================================================ #
# Define the help function

function help() {
echo -e "prepare.sh case"
echo -e " Generate a mesh to prepare for the desired case."
echo -e " The input arguments are the number of cells in the x, y, and z"
echo -e " directions, respectively."
echo -e ""
echo -e " If no input arguments are provided, the default mesh size is"
echo -e " 32x8x8."
echo -e ""
echo -e " Example usage:"
echo -e " prepare.sh -x32 -y8 -z8"
echo -e ""
echo -e " Options:"
echo -e " -h, --help Show this help message and exit."
echo -e " -x# Number of cells in the x direction."
echo -e " -y# Number of cells in the y direction."
echo -e " -z# Number of cells in the z direction."
echo -e " -q, --quiet Suppress output."
echo -e ""
echo -e " See Readme for additional details."
exit 0
}

# Handle options
Nx=32 && Ny=8 && Nz=8
for arg in "$@"; do
if [ "${arg:0:2}" == "--" ]; then
case ${arg:2} in
help) help ;;
quiet) QUIET=1 ;;
*) echo -e "Invalid option: $arg" >&2 && help ;;
esac
elif [ "${arg:0:1}" == "-" ]; then
case ${arg:1:1} in
h) help ;;
x) Nx=${arg:2} ;;
y) Ny=${arg:2} ;;
z) Nz=${arg:2} ;;
q) QUIET=1 ;;
*) echo -e "Invalid option: ${arg:1}" >&2 && help ;;
esac
else
cases="$cases $arg"
fi
done

# ============================================================================ #
# Ensure Neko can be found and set default mesh size

if [ "$NEKO_DIR" ]; then
PATH=$NEKO_DIR/bin:$PATH
fi

if [[ -z $(which genmeshbox) ]]; then
echo -e "Neko not found." >&2
echo -e "Please ensure Neko is installed and in your PATH." >&2
echo -e "Alternatively, set the NEKO_DIR environment variable." >&2
exit 1
fi

# ============================================================================ #
# Generate mesh and prepare case

echo "Generating mesh with dimensions: $Nx $Ny $Nz"
genmeshbox 0 4 0 1 0 1 $Nx $Ny $Nz .false. .false. .false.

# End of file
# ============================================================================ #
2 changes: 1 addition & 1 deletion src/.depends
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ source_terms/boussinesq_source_term.lo : source_terms/boussinesq_source_term.f90
source_terms/bcknd/cpu/boussinesq_source_term_cpu.lo : source_terms/bcknd/cpu/boussinesq_source_term_cpu.f90 math/math.lo field/field.lo field/field_list.lo config/num_types.lo
source_terms/bcknd/device/boussinesq_source_term_device.lo : source_terms/bcknd/device/boussinesq_source_term_device.f90 math/bcknd/device/device_math.lo field/field.lo field/field_list.lo config/num_types.lo
source_terms/source_term_fctry.lo : source_terms/source_term_fctry.f90 common/utils.lo common/json_utils.lo source_terms/coriolis_source_term.lo source_terms/brinkman_source_term.lo source_terms/boussinesq_source_term.lo source_terms/const_source_term.lo source_terms/source_term.lo
source_terms/brinkman_source_term.lo : source_terms/brinkman_source_term.f90 mesh/point_zone_registry.lo mesh/point_zone.lo mesh/search_tree/aabb.lo common/profiler.lo math/signed_distance.lo source_terms/brinkman/filters.lo device/device.lo mesh/tri_mesh.lo io/file.lo math/bcknd/device/device_math.lo math/math.lo math/field_math.lo common/utils.lo config/neko_config.lo sem/coef.lo source_terms/source_term.lo field/field_registry.lo common/json_utils.lo field/field_list.lo field/field.lo config/num_types.lo
source_terms/brinkman_source_term.lo : source_terms/brinkman_source_term.f90 common/utils.lo source_terms/source_term.lo math/signed_distance.lo common/profiler.lo mesh/point_zone_registry.lo mesh/point_zone.lo config/num_types.lo config/neko_config.lo mesh/tri_mesh.lo math/math.lo common/log.lo common/json_utils.lo io/file.lo source_terms/brinkman/filters.lo field/field_registry.lo math/field_math.lo field/field_list.lo field/field.lo math/bcknd/device/device_math.lo device/device.lo sem/coef.lo mesh/search_tree/aabb.lo
source_terms/brinkman/filters.lo : source_terms/brinkman/filters.f90 source_terms/bcknd/device/filters_device.lo source_terms/bcknd/cpu/filters_cpu.lo common/utils.lo config/num_types.lo config/neko_config.lo field/field.lo
source_terms/bcknd/cpu/filters_cpu.lo : source_terms/bcknd/cpu/filters_cpu.f90 config/num_types.lo
source_terms/bcknd/device/filters_device.lo : source_terms/bcknd/device/filters_device.F90 source_terms/bcknd/device/opencl/opencl_filters.lo source_terms/bcknd/device/hip/hip_filters.lo source_terms/bcknd/device/cuda/cuda_filters.lo common/utils.lo math/bcknd/device/device_math.lo config/num_types.lo
Expand Down
83 changes: 41 additions & 42 deletions src/source_terms/brinkman_source_term.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,29 @@
!
!> Implements the `brinkman_source_term_t` type.
module brinkman_source_term
use num_types, only: rp, dp
use aabb, only : aabb_t, get_aabb
use coefs, only: coef_t
use device, only: device_memcpy, HOST_TO_DEVICE
use device_math, only: device_pwmax, device_cfill_mask
use field, only: field_t
use field_list, only: field_list_t
use json_module, only: json_file
use json_utils, only: json_get, json_get_or_default, json_extract_item
use field_math, only: field_subcol3
use field_registry, only: neko_field_registry
use source_term, only: source_term_t
use coefs, only: coef_t
use filters, only: smooth_step_field, step_function_field, permeability_field
use file, only: file_t
use json_module, only: json_file, json_core, json_value
use json_utils, only: json_get, json_get_or_default, json_extract_item
use logger, only: neko_log, LOG_SIZE
use math, only: pwmax, cfill_mask
use tri_mesh, only: tri_mesh_t
use neko_config, only: NEKO_BCKND_DEVICE
use num_types, only: rp, dp
use point_zone, only: point_zone_t
use point_zone_registry, only: neko_point_zone_registry
use profiler, only: profiler_start_region, profiler_end_region
use signed_distance, only: signed_distance_field
use source_term, only: source_term_t
use utils, only: neko_error
use field_math, only: field_subcol3

use math, only: pwmax
use device_math, only: device_pwmax
implicit none
private

Expand Down Expand Up @@ -84,16 +93,6 @@ module brinkman_source_term
!! @param fields A list of fields for adding the source values.
!! @param coef The SEM coeffs.
subroutine brinkman_source_term_init_from_json(this, json, fields, coef)
use file, only: file_t
use tri_mesh, only: tri_mesh_t
use device, only: device_memcpy, HOST_TO_DEVICE
use filters, only: smooth_step_field, step_function_field, &
permeability_field
use signed_distance, only: signed_distance_field
use profiler, only: profiler_start_region, profiler_end_region
use json_module, only: json_core, json_value
implicit none

class(brinkman_source_term_t), intent(inout) :: this
type(json_file), intent(inout) :: json
type(field_list_t), intent(in), target :: fields
Expand Down Expand Up @@ -190,6 +189,7 @@ subroutine brinkman_source_term_free(this)
call this%indicator%free()
call this%brinkman%free()
call this%free_base()

end subroutine brinkman_source_term_free

!> Computes the source term and adds the result to `fields`.
Expand Down Expand Up @@ -223,16 +223,6 @@ end subroutine brinkman_source_term_compute

!> Initializes the source term from a boundary mesh.
subroutine init_boundary_mesh(this, json)
use file, only: file_t
use tri_mesh, only: tri_mesh_t
use device, only: device_memcpy, HOST_TO_DEVICE
use filters, only: smooth_step_field, step_function_field, &
permeability_field
use signed_distance, only: signed_distance_field
use profiler, only: profiler_start_region, profiler_end_region
use aabb, only : aabb_t, get_aabb
implicit none

class(brinkman_source_term_t), intent(inout) :: this
type(json_file), intent(inout) :: json

Expand All @@ -256,6 +246,7 @@ subroutine init_boundary_mesh(this, json)
type(field_t) :: temp_field
type(aabb_t) :: mesh_box, target_box
integer :: idx_p
character(len=LOG_SIZE) :: log_msg

! ------------------------------------------------------------------------ !
! Read the options for the boundary mesh
Expand Down Expand Up @@ -311,6 +302,14 @@ subroutine init_boundary_mesh(this, json)
scaling * boundary_mesh%points(idx_p)%x + translation
end do

! Report the transformation applied
write(log_msg, '(A)') "The following transformation was applied:"
call neko_log%message(log_msg)
write(log_msg, '(A, 3F12.6)') "Scaling: ", scaling
call neko_log%message(log_msg)
write(log_msg, '(A, 3F12.6)') "Translation: ", translation
call neko_log%message(log_msg)

case default
call neko_error('Unknown mesh transform')
end select
Expand Down Expand Up @@ -369,15 +368,6 @@ end subroutine init_boundary_mesh

!> Initializes the source term from a point zone.
subroutine init_point_zone(this, json)
use filters, only: smooth_step_field, step_function_field, &
permeability_field
use signed_distance, only: signed_distance_field
use profiler, only: profiler_start_region, profiler_end_region
use point_zone, only: point_zone_t
use device, only: device_memcpy, HOST_TO_DEVICE
use point_zone_registry, only: neko_point_zone_registry
implicit none

class(brinkman_source_term_t), intent(inout) :: this
type(json_file), intent(inout) :: json

Expand All @@ -400,9 +390,13 @@ subroutine init_point_zone(this, json)

my_point_zone => neko_point_zone_registry%get_point_zone(zone_name)

do i = 1, my_point_zone%size
temp_field%x(my_point_zone%mask(i), 1, 1, 1) = 1.0_rp
end do
if (NEKO_BCKND_DEVICE .eq. 1) then
call device_cfill_mask(temp_field%x_d, 1.0_rp, temp_field%size(), &
my_point_zone%mask_d, my_point_zone%size)
else
call cfill_mask(temp_field%x, 1.0_rp, temp_field%size(), &
my_point_zone%mask, my_point_zone%size)
end if

! Run filter on the temporary indicator field to smooth it out.

Expand All @@ -414,7 +408,12 @@ subroutine init_point_zone(this, json)
end select

! Update the global indicator field by max operator
this%indicator%x = max(this%indicator%x, temp_field%x)
if (NEKO_BCKND_DEVICE .eq. 1) then
call device_pwmax(this%indicator%x_d, temp_field%x_d, &
this%indicator%size())
else
this%indicator%x = max(this%indicator%x, temp_field%x)
end if

end subroutine init_point_zone

Expand Down

0 comments on commit f3f6eb1

Please sign in to comment.