diff --git a/acc/mhd_solver/stencil_defines.h b/acc/mhd_solver/stencil_defines.h
index b86d287..0ab07c2 100644
--- a/acc/mhd_solver/stencil_defines.h
+++ b/acc/mhd_solver/stencil_defines.h
@@ -1,3 +1,23 @@
+/*
+ Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
+
+ This file is part of Astaroth.
+
+ Astaroth is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Astaroth is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Astaroth. If not, see .
+*/
+#pragma once
+
/*
* =============================================================================
* Logical switches
@@ -26,8 +46,11 @@
FUNC(AC_max_steps), \
FUNC(AC_save_steps), \
FUNC(AC_bin_steps), \
- FUNC(AC_bc_type)
-#define AC_FOR_REAL_PARAM_TYPES(FUNC)\
+ FUNC(AC_bc_type),
+
+#define AC_FOR_USER_INT3_PARAM_TYPES(FUNC)
+
+#define AC_FOR_USER_REAL_PARAM_TYPES(FUNC)\
/* cparams */\
FUNC(AC_dsx), \
FUNC(AC_dsy), \
@@ -97,7 +120,9 @@
FUNC(AC_cs2_sound), \
FUNC(AC_inv_dsx), \
FUNC(AC_inv_dsy), \
- FUNC(AC_inv_dsz)
+ FUNC(AC_inv_dsz),
+
+#define AC_FOR_USER_REAL3_PARAM_TYPES(FUNC)
// clang-format on
/*
@@ -106,49 +131,33 @@
* =============================================================================
*/
// clang-format off
-#if LDENSITY
-#define AC_FOR_DENSITY_VTXBUF_HANDLES(FUNC) \
- FUNC(VTXBUF_LNRHO),
-#else
-#define AC_FOR_DENSITY_VTXBUF_HANDLES(FUNC)
-#endif
-
-#if LHYDRO
-#define AC_FOR_HYDRO_VTXBUF_HANDLES(FUNC) \
- FUNC(VTXBUF_UUX), \
- FUNC(VTXBUF_UUY), \
- FUNC(VTXBUF_UUZ),
-#else
-#define AC_FOR_HYDRO_VTXBUF_HANDLES(FUNC)
-#endif
-
-#if LMAGNETIC
-#define AC_FOR_MAGNETIC_VTXBUF_HANDLES(FUNC) \
- FUNC(VTXBUF_AX), \
- FUNC(VTXBUF_AY), \
- FUNC(VTXBUF_AZ),
-#else
-#define AC_FOR_MAGNETIC_VTXBUF_HANDLES(FUNC)
-#endif
-
#if LENTROPY
-#define AC_FOR_ENTROPY_VTXBUF_HANDLES(FUNC) \
- FUNC(VTXBUF_ENTROPY),
+#define AC_FOR_VTXBUF_HANDLES(FUNC) \
+ FUNC(VTXBUF_LNRHO), \
+ FUNC(VTXBUF_UUX), \
+ FUNC(VTXBUF_UUY), \
+ FUNC(VTXBUF_UUZ), \
+ FUNC(VTXBUF_AX), \
+ FUNC(VTXBUF_AY), \
+ FUNC(VTXBUF_AZ), \
+ FUNC(VTXBUF_ENTROPY),
+#elif LMAGNETIC
+#define AC_FOR_VTXBUF_HANDLES(FUNC) \
+ FUNC(VTXBUF_LNRHO), \
+ FUNC(VTXBUF_UUX), \
+ FUNC(VTXBUF_UUY), \
+ FUNC(VTXBUF_UUZ), \
+ FUNC(VTXBUF_AX), \
+ FUNC(VTXBUF_AY), \
+ FUNC(VTXBUF_AZ),
+#elif LHYDRO
+#define AC_FOR_VTXBUF_HANDLES(FUNC) \
+ FUNC(VTXBUF_LNRHO), \
+ FUNC(VTXBUF_UUX), \
+ FUNC(VTXBUF_UUY), \
+ FUNC(VTXBUF_UUZ),
#else
-#define AC_FOR_ENTROPY_VTXBUF_HANDLES(FUNC)
+#define AC_FOR_VTXBUF_HANDLES(FUNC) \
+ FUNC(VTXBUF_LNRHO),
#endif
-
-//MR: Temperature must not have an additional variable slot, but should sit on the
-// same as entropy.
-#if LTEMPERATURE
- #define AC_FOR_TEMPERATURE_VTXBUF_HANDLES(FUNC)\
- FUNC(VTXBUF_TEMPERATURE),
-#else
- #define AC_FOR_TEMPERATURE_VTXBUF_HANDLES(FUNC)
-#endif
-
-#define AC_FOR_VTXBUF_HANDLES(FUNC) AC_FOR_HYDRO_VTXBUF_HANDLES(FUNC) \
- AC_FOR_DENSITY_VTXBUF_HANDLES(FUNC) \
- AC_FOR_ENTROPY_VTXBUF_HANDLES(FUNC) \
- AC_FOR_MAGNETIC_VTXBUF_HANDLES(FUNC) \
// clang-format on
diff --git a/include/astaroth.h b/include/astaroth.h
index 5c53238..3f6fdd6 100644
--- a/include/astaroth.h
+++ b/include/astaroth.h
@@ -16,183 +16,28 @@
You should have received a copy of the GNU General Public License
along with Astaroth. If not, see .
*/
-
-/**
- * @file
- * \brief Brief info.
- *
- * Provides an interface to Astaroth. Contains all the necessary configuration
- * structs and functions for running the code on multiple GPUs.
- *
- * All interface functions declared here (such as acInit()) operate all GPUs
- * available in the node under the hood, and the user does not need any
- * information about the decomposition, synchronization or such to use these
- * functions.
- *
- */
#pragma once
-/* Prevent name mangling */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include // FLT_EPSILON, etc
-#include // size_t
-#include // CUDA vector types (float4, etc)
-
-/*
- * =============================================================================
- * Flags for auto-optimization
- * =============================================================================
- */
-#define AUTO_OPTIMIZE (0) // DEPRECATED TODO remove
-#define BOUNDCONDS_OPTIMIZE (0)
-#define GENERATE_BENCHMARK_DATA (0)
-#define VERBOSE_PRINTING (1)
-
-// Device info
-#define REGISTERS_PER_THREAD (255)
-#define MAX_REGISTERS_PER_BLOCK (65536)
-#define MAX_THREADS_PER_BLOCK (1024)
-#define WARP_SIZE (32)
-/*
- * =============================================================================
- * Compile-time constants used during simulation (user definable)
- * =============================================================================
- */
-// USER_PROVIDED_DEFINES must be defined in user.h if the user wants to override the following
-// logical switches
-#include "user.h"
-
-// clang-format off
-#ifndef USER_PROVIDED_DEFINES
- #include "stencil_defines.h"
-#endif
-// clang-format on
-
-/*
- * =============================================================================
- * Built-in parameters
- * =============================================================================
- */
-// clang-format off
-#define AC_FOR_BUILTIN_INT_PARAM_TYPES(FUNC)\
- /* cparams */\
- FUNC(AC_nx), \
- FUNC(AC_ny), \
- FUNC(AC_nz), \
- FUNC(AC_mx), \
- FUNC(AC_my), \
- FUNC(AC_mz), \
- FUNC(AC_nx_min), \
- FUNC(AC_ny_min), \
- FUNC(AC_nz_min), \
- FUNC(AC_nx_max), \
- FUNC(AC_ny_max), \
- FUNC(AC_nz_max), \
- /* Additional */\
- FUNC(AC_mxy),\
- FUNC(AC_nxy),\
- FUNC(AC_nxyz),
-// clang-format on
-
-/*
- * =============================================================================
- * Single/double precision switch
- * =============================================================================
- */
-// clang-format off
-#if AC_DOUBLE_PRECISION == 1
- typedef double AcReal;
- typedef double3 AcReal3;
- #define AC_REAL_MAX (DBL_MAX)
- #define AC_REAL_MIN (DBL_MIN)
- #define AC_REAL_EPSILON (DBL_EPSILON)
-#else
- typedef float AcReal;
- typedef float3 AcReal3;
- #define AC_REAL_MAX (FLT_MAX)
- #define AC_REAL_MIN (FLT_MIN)
- #define AC_REAL_EPSILON (FLT_EPSILON)
-#endif
-// clang-format on
+#include "astaroth_defines.h"
typedef struct {
- AcReal3 row[3];
-} AcMatrix;
-
-/*
- * =============================================================================
- * Helper macros
- * =============================================================================
- */
-#define AC_GEN_ID(X) X
-#define AC_GEN_STR(X) #X
-
-/*
- * =============================================================================
- * Error codes
- * =============================================================================
- */
-typedef enum { AC_SUCCESS = 0, AC_FAILURE = 1 } AcResult;
-
-/*
- * =============================================================================
- * Reduction types
- * =============================================================================
- */
-typedef enum { RTYPE_MAX, RTYPE_MIN, RTYPE_RMS, RTYPE_RMS_EXP, NUM_REDUCTION_TYPES } ReductionType;
-
-/*
- * =============================================================================
- * Definitions for the enums and structs for AcMeshInfo (DO NOT TOUCH)
- * =============================================================================
- */
-
-typedef enum {
- AC_FOR_BUILTIN_INT_PARAM_TYPES(AC_GEN_ID) //
- AC_FOR_USER_INT_PARAM_TYPES(AC_GEN_ID), //
- NUM_INT_PARAM_TYPES
-} AcIntParam;
-
-typedef enum { AC_FOR_REAL_PARAM_TYPES(AC_GEN_ID), NUM_REAL_PARAM_TYPES } AcRealParam;
-// typedef enum { AC_FOR_VEC_PARAM_TYPES(AC_GEN_ID), NUM_VEC_PARAM_TYPES } AcVecParam;
-
-extern const char* intparam_names[]; // Defined in astaroth.cu
-extern const char* realparam_names[]; // Defined in astaroth.cu
-
-typedef struct {
- int int_params[NUM_INT_PARAM_TYPES];
- AcReal real_params[NUM_REAL_PARAM_TYPES];
- // AcReal* vec_params[NUM_VEC_PARAM_TYPES];
+ int int_params[NUM_INT_PARAMS];
+ int3 int3_params[NUM_INT3_PARAMS];
+ AcReal real_params[NUM_REAL_PARAMS];
+ AcReal3 vec_params[NUM_REAL3_PARAMS];
} AcMeshInfo;
-/*
- * =============================================================================
- * Definitions for the enums and structs for AcMesh (DO NOT TOUCH)
- * =============================================================================
- */
-typedef enum { AC_FOR_VTXBUF_HANDLES(AC_GEN_ID) NUM_VTXBUF_HANDLES } VertexBufferHandle;
-
-extern const char* vtxbuf_names[]; // Defined in astaroth.cu
-
-/*
-typedef struct {
- AcReal* data;
-} VertexBuffer;
-*/
-
-// NOTE: there's no particular benefit declaring AcMesh a class, since
-// a library user may already have allocated memory for the vertex_buffers.
-// But then we would allocate memory again when the user wants to start
-// filling the class with data. => Its better to consider AcMesh as a
-// payload-only struct
typedef struct {
AcReal* vertex_buffer[NUM_VTXBUF_HANDLES];
AcMeshInfo info;
} AcMesh;
+typedef enum {
+ STREAM_DEFAULT,
+ NUM_STREAM_TYPES, //
+ STREAM_ALL
+} StreamType;
+
#define AC_VTXBUF_SIZE(mesh_info) \
((size_t)(mesh_info.int_params[AC_mx] * mesh_info.int_params[AC_my] * \
mesh_info.int_params[AC_mz]))
@@ -209,17 +54,6 @@ typedef struct {
((i) + (j)*mesh_info.int_params[AC_mx] + \
(k)*mesh_info.int_params[AC_mx] * mesh_info.int_params[AC_my])
-/*
- * =============================================================================
- * Astaroth interface: Basic functions. Synchronous.
- * =============================================================================
- */
-typedef enum {
- STREAM_DEFAULT,
- NUM_STREAM_TYPES, //
- STREAM_ALL
-} StreamType;
-
/** Checks whether there are any CUDA devices available. Returns AC_SUCCESS if there is 1 or more,
* AC_FAILURE otherwise. */
AcResult acCheckDeviceAvailability(void);
@@ -303,8 +137,3 @@ AcResult acIntegrateStepWithOffsetAsync(const int& isubstep, const AcReal& dt, c
/** Performs the boundary condition step on the GPUs in the node. Asynchronous. */
AcResult acBoundcondStep(void);
AcResult acBoundcondStepAsync(const StreamType stream);
-
-/* End extern "C" */
-#ifdef __cplusplus
-}
-#endif
diff --git a/include/astaroth_defines.h b/include/astaroth_defines.h
new file mode 100644
index 0000000..89808c9
--- /dev/null
+++ b/include/astaroth_defines.h
@@ -0,0 +1,109 @@
+/*
+ Copyright (C) 2014-2019, Johannes Pekkilae, Miikka Vaeisalae.
+
+ This file is part of Astaroth.
+
+ Astaroth is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Astaroth is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Astaroth. If not, see .
+*/
+#pragma once
+#include // FLT_EPSILON, etc
+#include // size_t
+#include // CUDA vector types (float4, etc)
+
+#include "stencil_defines.h"
+
+// Library flags
+#define VERBOSE_PRINTING (1)
+
+// Built-in types and parameters
+#if AC_DOUBLE_PRECISION == 1
+typedef double AcReal;
+typedef double3 AcReal3;
+#define AC_REAL_MAX (DBL_MAX)
+#define AC_REAL_MIN (DBL_MIN)
+#define AC_REAL_EPSILON (DBL_EPSILON)
+#else
+typedef float AcReal;
+typedef float3 AcReal3;
+#define AC_REAL_MAX (FLT_MAX)
+#define AC_REAL_MIN (FLT_MIN)
+#define AC_REAL_EPSILON (FLT_EPSILON)
+#endif
+
+typedef struct {
+ AcReal3 row[3];
+} AcMatrix;
+
+// clang-format off
+#define AC_FOR_BUILTIN_INT_PARAM_TYPES(FUNC)\
+ FUNC(AC_nx), \
+ FUNC(AC_ny), \
+ FUNC(AC_nz), \
+ FUNC(AC_mx), \
+ FUNC(AC_my), \
+ FUNC(AC_mz), \
+ FUNC(AC_nx_min), \
+ FUNC(AC_ny_min), \
+ FUNC(AC_nz_min), \
+ FUNC(AC_nx_max), \
+ FUNC(AC_ny_max), \
+ FUNC(AC_nz_max), \
+ FUNC(AC_mxy),\
+ FUNC(AC_nxy),\
+ FUNC(AC_nxyz),\
+
+#define AC_FOR_BUILTIN_INT3_PARAM_TYPES(FUNC)
+
+#define AC_FOR_BUILTIN_REAL_PARAM_TYPES(FUNC)
+
+#define AC_FOR_BUILTIN_REAL3_PARAM_TYPES(FUNC)
+// clang-format on
+
+typedef enum { AC_SUCCESS = 0, AC_FAILURE = 1 } AcResult;
+
+typedef enum { RTYPE_MAX, RTYPE_MIN, RTYPE_RMS, RTYPE_RMS_EXP, NUM_REDUCTION_TYPES } ReductionType;
+
+#define AC_GEN_ID(X) X
+typedef enum {
+ AC_FOR_BUILTIN_INT_PARAM_TYPES(AC_GEN_ID) //
+ AC_FOR_USER_INT_PARAM_TYPES(AC_GEN_ID) //
+ NUM_INT_PARAMS
+} AcIntParam;
+
+typedef enum {
+ AC_FOR_BUILTIN_INT3_PARAM_TYPES(AC_GEN_ID) //
+ AC_FOR_USER_INT3_PARAM_TYPES(AC_GEN_ID) //
+ NUM_INT3_PARAMS
+} AcInt3Param;
+
+typedef enum {
+ AC_FOR_BUILTIN_REAL_PARAM_TYPES(AC_GEN_ID) //
+ AC_FOR_USER_REAL_PARAM_TYPES(AC_GEN_ID) //
+ NUM_REAL_PARAMS
+} AcRealParam;
+
+typedef enum {
+ AC_FOR_BUILTIN_REAL3_PARAM_TYPES(AC_GEN_ID) //
+ AC_FOR_USER_REAL3_PARAM_TYPES(AC_GEN_ID) //
+ NUM_REAL3_PARAMS
+} AcReal3Param;
+
+typedef enum { AC_FOR_VTXBUF_HANDLES(AC_GEN_ID) NUM_VTXBUF_HANDLES } VertexBufferHandle;
+#undef AC_GEN_ID
+
+extern const char* intparam_names[];
+extern const char* int3param_names[];
+extern const char* realparam_names[];
+extern const char* real3param_names[];
+extern const char* vtxbuf_names[];
diff --git a/src/core/astaroth.cu b/src/core/astaroth.cu
index 38b2863..427e82f 100644
--- a/src/core/astaroth.cu
+++ b/src/core/astaroth.cu
@@ -130,10 +130,17 @@
#include "math_utils.h" // sum for reductions
#include "standalone/config_loader.h" // update_config
-const char* intparam_names[] = {AC_FOR_BUILTIN_INT_PARAM_TYPES(AC_GEN_STR)
- AC_FOR_USER_INT_PARAM_TYPES(AC_GEN_STR)};
-const char* realparam_names[] = {AC_FOR_REAL_PARAM_TYPES(AC_GEN_STR)};
-const char* vtxbuf_names[] = {AC_FOR_VTXBUF_HANDLES(AC_GEN_STR)};
+#define AC_GEN_STR(X) #X
+const char* intparam_names[] = {AC_FOR_BUILTIN_INT_PARAM_TYPES(AC_GEN_STR) //
+ AC_FOR_USER_INT_PARAM_TYPES(AC_GEN_STR)};
+const char* int3param_names[] = {AC_FOR_BUILTIN_INT3_PARAM_TYPES(AC_GEN_STR) //
+ AC_FOR_USER_INT3_PARAM_TYPES(AC_GEN_STR)};
+const char* realparam_names[] = {AC_FOR_BUILTIN_REAL_PARAM_TYPES(AC_GEN_STR) //
+ AC_FOR_USER_REAL_PARAM_TYPES(AC_GEN_STR)};
+const char* real3param_names[] = {AC_FOR_BUILTIN_REAL3_PARAM_TYPES(AC_GEN_STR) //
+ AC_FOR_USER_REAL3_PARAM_TYPES(AC_GEN_STR)};
+const char* vtxbuf_names[] = {AC_FOR_VTXBUF_HANDLES(AC_GEN_STR)};
+#undef AC_GEN_STR
static const int MAX_NUM_DEVICES = 32;
static int num_devices = 0;