diff --git a/include/astaroth.h b/include/astaroth.h index 039ab82..21e45b9 100644 --- a/include/astaroth.h +++ b/include/astaroth.h @@ -590,6 +590,9 @@ AcResult acUpdateBuiltinParams(AcMeshInfo* config); /** Creates a mesh stored in host memory */ AcResult acMeshCreate(const AcMeshInfo mesh_info, AcMesh* mesh); +/** Randomizes a host mesh */ +AcResult acMeshRandomize(AcMesh* mesh); + /** Destroys a mesh stored in host memory */ AcResult acMeshDestroy(AcMesh* mesh); diff --git a/include/astaroth_utils.h b/include/astaroth_utils.h index f742f73..4289c1b 100644 --- a/include/astaroth_utils.h +++ b/include/astaroth_utils.h @@ -50,9 +50,6 @@ AcResult acVertexBufferSet(const VertexBufferHandle handle, const AcReal value, /** */ AcResult acMeshSet(const AcReal value, AcMesh* mesh); -/** */ -AcResult acMeshRandomize(AcMesh* mesh); - /** */ AcResult acMeshApplyPeriodicBounds(AcMesh* mesh); diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 15cd4fa..ca96366 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -2,7 +2,7 @@ find_package(CUDAToolkit) ## Astaroth Core add_library(astaroth_core STATIC device.cc node.cc astaroth.cc astaroth_fortran.cc) -target_link_libraries(astaroth_core astaroth_utils astaroth_kernels CUDA::cudart CUDA::cuda_driver) +target_link_libraries(astaroth_core astaroth_kernels CUDA::cudart CUDA::cuda_driver) ## Options if (MPI_ENABLED) diff --git a/src/core/astaroth.cc b/src/core/astaroth.cc index 1c8d0f7..c6d9a19 100644 --- a/src/core/astaroth.cc +++ b/src/core/astaroth.cc @@ -221,6 +221,23 @@ acMeshCreate(const AcMeshInfo info, AcMesh* mesh) return AC_SUCCESS; } +static AcReal +randf(void) +{ + return (AcReal)rand() / (AcReal)RAND_MAX; +} + +AcResult +acMeshRandomize(AcMesh* mesh) +{ + const int n = acVertexBufferSize(mesh->info); + for (int w = 0; w < NUM_VTXBUF_HANDLES; ++w) + for (int i = 0; i < n; ++i) + mesh->vertex_buffer[w][i] = randf(); + + return AC_SUCCESS; +} + AcResult acMeshDestroy(AcMesh* mesh) { diff --git a/src/core/device.cc b/src/core/device.cc index 4af17fc..24d6e38 100644 --- a/src/core/device.cc +++ b/src/core/device.cc @@ -1242,8 +1242,6 @@ acGridSynchronizeStream(const Stream stream) return AC_SUCCESS; } - -#include "astaroth_utils.h" // HACK TO RANDOMIZE AcResult acGridRandomize(void) { diff --git a/src/utils/memory.c b/src/utils/memory.c index 334d106..f52fa12 100644 --- a/src/utils/memory.c +++ b/src/utils/memory.c @@ -38,23 +38,6 @@ acMeshSet(const AcReal value, AcMesh* mesh) return AC_SUCCESS; } -static AcReal -randf(void) -{ - return (AcReal)rand() / (AcReal)RAND_MAX; -} - -AcResult -acMeshRandomize(AcMesh* mesh) -{ - const int n = acVertexBufferSize(mesh->info); - for (int w = 0; w < NUM_VTXBUF_HANDLES; ++w) - for (int i = 0; i < n; ++i) - mesh->vertex_buffer[w][i] = randf(); - - return AC_SUCCESS; -} - AcResult acMeshApplyPeriodicBounds(AcMesh* mesh) {