diff --git a/include/array_macros/fluid/p.h b/include/array_macros/fluid/p.h index 4af25f42..d1843635 100644 --- a/include/array_macros/fluid/p.h +++ b/include/array_macros/fluid/p.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [0 : isize+1], [0 : jsize+1] #define P(I, J) (p[(I ) + (isize+2) * (J )]) #define P_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, } -#endif - -#if NDIMS == 3 -// [0 : isize+1], [0 : jsize+1], [0 : ksize+1] -#define P(I, J, K) (p[(I ) + (isize+2) * ((J ) + (jsize+2) * (K ))]) -#define P_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, {1, 1}, } -#endif #endif // INCLUDE_ARRAY_MACROS_FLUID_P_H diff --git a/include/array_macros/fluid/psi.h b/include/array_macros/fluid/psi.h index 5108e70c..25496234 100644 --- a/include/array_macros/fluid/psi.h +++ b/include/array_macros/fluid/psi.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [0 : isize+1], [0 : jsize+1] #define PSI(I, J) (psi[(I ) + (isize+2) * (J )]) #define PSI_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, } -#endif - -#if NDIMS == 3 -// [0 : isize+1], [0 : jsize+1], [0 : ksize+1] -#define PSI(I, J, K) (psi[(I ) + (isize+2) * ((J ) + (jsize+2) * (K ))]) -#define PSI_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, {1, 1}, } -#endif #endif // INCLUDE_ARRAY_MACROS_FLUID_PSI_H diff --git a/include/array_macros/fluid/srct.h b/include/array_macros/fluid/srct.h index e6f77894..c9926027 100644 --- a/include/array_macros/fluid/srct.h +++ b/include/array_macros/fluid/srct.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [1 : isize+0], [1 : jsize+0] #define SRCT(I, J) (srct[(I-1) + (isize+0) * (J-1)]) #define SRCT_NADDS (int [NDIMS][2]){ {0, 0}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [1 : isize+0], [1 : jsize+0], [1 : ksize+0] -#define SRCT(I, J, K) (srct[(I-1) + (isize+0) * ((J-1) + (jsize+0) * (K-1))]) -#define SRCT_NADDS (int [NDIMS][2]){ {0, 0}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_FLUID_SRCT_H diff --git a/include/array_macros/fluid/srcux.h b/include/array_macros/fluid/srcux.h index 907fd49d..46acc228 100644 --- a/include/array_macros/fluid/srcux.h +++ b/include/array_macros/fluid/srcux.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [2 : isize+0], [1 : jsize+0] #define SRCUX(I, J) (srcux[(I-2) + (isize-1) * (J-1)]) #define SRCUX_NADDS (int [NDIMS][2]){ {-1, 0}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [2 : isize+0], [1 : jsize+0], [1 : ksize+0] -#define SRCUX(I, J, K) (srcux[(I-2) + (isize-1) * ((J-1) + (jsize+0) * (K-1))]) -#define SRCUX_NADDS (int [NDIMS][2]){ {-1, 0}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_FLUID_SRCUX_H diff --git a/include/array_macros/fluid/srcuy.h b/include/array_macros/fluid/srcuy.h index f148359e..dbaee383 100644 --- a/include/array_macros/fluid/srcuy.h +++ b/include/array_macros/fluid/srcuy.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [1 : isize+0], [1 : jsize+0] #define SRCUY(I, J) (srcuy[(I-1) + (isize+0) * (J-1)]) #define SRCUY_NADDS (int [NDIMS][2]){ {0, 0}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [1 : isize+0], [1 : jsize+0], [1 : ksize+0] -#define SRCUY(I, J, K) (srcuy[(I-1) + (isize+0) * ((J-1) + (jsize+0) * (K-1))]) -#define SRCUY_NADDS (int [NDIMS][2]){ {0, 0}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_FLUID_SRCUY_H diff --git a/include/array_macros/fluid/srcuz.h b/include/array_macros/fluid/srcuz.h index d38afee5..084c59e8 100644 --- a/include/array_macros/fluid/srcuz.h +++ b/include/array_macros/fluid/srcuz.h @@ -3,10 +3,4 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 3 -// [1 : isize+0], [1 : jsize+0], [1 : ksize+0] -#define SRCUZ(I, J, K) (srcuz[(I-1) + (isize+0) * ((J-1) + (jsize+0) * (K-1))]) -#define SRCUZ_NADDS (int [NDIMS][2]){ {0, 0}, {0, 0}, {0, 0}, } -#endif - #endif // INCLUDE_ARRAY_MACROS_FLUID_SRCUZ_H diff --git a/include/array_macros/fluid/t.h b/include/array_macros/fluid/t.h index a31d946b..bce29046 100644 --- a/include/array_macros/fluid/t.h +++ b/include/array_macros/fluid/t.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [0 : isize+1], [0 : jsize+1] #define T(I, J) (t[(I ) + (isize+2) * (J )]) #define T_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, } -#endif - -#if NDIMS == 3 -// [0 : isize+1], [0 : jsize+1], [0 : ksize+1] -#define T(I, J, K) (t[(I ) + (isize+2) * ((J ) + (jsize+2) * (K ))]) -#define T_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, {1, 1}, } -#endif #endif // INCLUDE_ARRAY_MACROS_FLUID_T_H diff --git a/include/array_macros/fluid/ux.h b/include/array_macros/fluid/ux.h index c9ef585b..18563d86 100644 --- a/include/array_macros/fluid/ux.h +++ b/include/array_macros/fluid/ux.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [1 : isize+1], [0 : jsize+1] #define UX(I, J) (ux[(I-1) + (isize+1) * (J )]) #define UX_NADDS (int [NDIMS][2]){ {0, 1}, {1, 1}, } -#endif - -#if NDIMS == 3 -// [1 : isize+1], [0 : jsize+1], [0 : ksize+1] -#define UX(I, J, K) (ux[(I-1) + (isize+1) * ((J ) + (jsize+2) * (K ))]) -#define UX_NADDS (int [NDIMS][2]){ {0, 1}, {1, 1}, {1, 1}, } -#endif #endif // INCLUDE_ARRAY_MACROS_FLUID_UX_H diff --git a/include/array_macros/fluid/uy.h b/include/array_macros/fluid/uy.h index 0c576989..dc5b70d7 100644 --- a/include/array_macros/fluid/uy.h +++ b/include/array_macros/fluid/uy.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [0 : isize+1], [0 : jsize+1] #define UY(I, J) (uy[(I ) + (isize+2) * (J )]) #define UY_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, } -#endif - -#if NDIMS == 3 -// [0 : isize+1], [0 : jsize+1], [0 : ksize+1] -#define UY(I, J, K) (uy[(I ) + (isize+2) * ((J ) + (jsize+2) * (K ))]) -#define UY_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, {1, 1}, } -#endif #endif // INCLUDE_ARRAY_MACROS_FLUID_UY_H diff --git a/include/array_macros/fluid/uz.h b/include/array_macros/fluid/uz.h index a5e67fc5..5c870750 100644 --- a/include/array_macros/fluid/uz.h +++ b/include/array_macros/fluid/uz.h @@ -3,10 +3,4 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 3 -// [0 : isize+1], [0 : jsize+1], [0 : ksize+1] -#define UZ(I, J, K) (uz[(I ) + (isize+2) * ((J ) + (jsize+2) * (K ))]) -#define UZ_NADDS (int [NDIMS][2]){ {1, 1}, {1, 1}, {1, 1}, } -#endif - #endif // INCLUDE_ARRAY_MACROS_FLUID_UZ_H diff --git a/include/array_macros/statistics/adv.h b/include/array_macros/statistics/adv.h index a3ba0582..ac322be2 100644 --- a/include/array_macros/statistics/adv.h +++ b/include/array_macros/statistics/adv.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [1 : isize+1], [1 : jsize+0] #define ADV(I, J) (adv[(I-1) + (isize+1) * (J-1)]) #define ADV_NADDS (int [NDIMS][2]){ {0, 1}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [1 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define ADV(I, J, K) (adv[(I-1) + (isize+1) * ((J-1) + (jsize+0) * (K-1))]) -#define ADV_NADDS (int [NDIMS][2]){ {0, 1}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_STATISTICS_ADV_H diff --git a/include/array_macros/statistics/dif.h b/include/array_macros/statistics/dif.h index 6469d353..cf0ca320 100644 --- a/include/array_macros/statistics/dif.h +++ b/include/array_macros/statistics/dif.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [1 : isize+1], [1 : jsize+0] #define DIF(I, J) (dif[(I-1) + (isize+1) * (J-1)]) #define DIF_NADDS (int [NDIMS][2]){ {0, 1}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [1 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define DIF(I, J, K) (dif[(I-1) + (isize+1) * ((J-1) + (jsize+0) * (K-1))]) -#define DIF_NADDS (int [NDIMS][2]){ {0, 1}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_STATISTICS_DIF_H diff --git a/include/array_macros/statistics/t1.h b/include/array_macros/statistics/t1.h index 37566c89..56d9e7fb 100644 --- a/include/array_macros/statistics/t1.h +++ b/include/array_macros/statistics/t1.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [0 : isize+1], [1 : jsize+0] #define T1(I, J) (t1[(I ) + (isize+2) * (J-1)]) #define T1_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [0 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define T1(I, J, K) (t1[(I ) + (isize+2) * ((J-1) + (jsize+0) * (K-1))]) -#define T1_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_STATISTICS_T1_H diff --git a/include/array_macros/statistics/t2.h b/include/array_macros/statistics/t2.h index ca416658..9525dafb 100644 --- a/include/array_macros/statistics/t2.h +++ b/include/array_macros/statistics/t2.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [0 : isize+1], [1 : jsize+0] #define T2(I, J) (t2[(I ) + (isize+2) * (J-1)]) #define T2_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [0 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define T2(I, J, K) (t2[(I ) + (isize+2) * ((J-1) + (jsize+0) * (K-1))]) -#define T2_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_STATISTICS_T2_H diff --git a/include/array_macros/statistics/ux1.h b/include/array_macros/statistics/ux1.h index 04e58b7c..0232ad62 100644 --- a/include/array_macros/statistics/ux1.h +++ b/include/array_macros/statistics/ux1.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [1 : isize+1], [1 : jsize+0] #define UX1(I, J) (ux1[(I-1) + (isize+1) * (J-1)]) #define UX1_NADDS (int [NDIMS][2]){ {0, 1}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [1 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define UX1(I, J, K) (ux1[(I-1) + (isize+1) * ((J-1) + (jsize+0) * (K-1))]) -#define UX1_NADDS (int [NDIMS][2]){ {0, 1}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_STATISTICS_UX1_H diff --git a/include/array_macros/statistics/ux2.h b/include/array_macros/statistics/ux2.h index a3181c99..f7397e23 100644 --- a/include/array_macros/statistics/ux2.h +++ b/include/array_macros/statistics/ux2.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [1 : isize+1], [1 : jsize+0] #define UX2(I, J) (ux2[(I-1) + (isize+1) * (J-1)]) #define UX2_NADDS (int [NDIMS][2]){ {0, 1}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [1 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define UX2(I, J, K) (ux2[(I-1) + (isize+1) * ((J-1) + (jsize+0) * (K-1))]) -#define UX2_NADDS (int [NDIMS][2]){ {0, 1}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_STATISTICS_UX2_H diff --git a/include/array_macros/statistics/uy1.h b/include/array_macros/statistics/uy1.h index 4eed5fe8..c253a33e 100644 --- a/include/array_macros/statistics/uy1.h +++ b/include/array_macros/statistics/uy1.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [0 : isize+1], [1 : jsize+0] #define UY1(I, J) (uy1[(I ) + (isize+2) * (J-1)]) #define UY1_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [0 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define UY1(I, J, K) (uy1[(I ) + (isize+2) * ((J-1) + (jsize+0) * (K-1))]) -#define UY1_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_STATISTICS_UY1_H diff --git a/include/array_macros/statistics/uy2.h b/include/array_macros/statistics/uy2.h index 3f06daad..74d1dcf9 100644 --- a/include/array_macros/statistics/uy2.h +++ b/include/array_macros/statistics/uy2.h @@ -3,16 +3,8 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 2 // [0 : isize+1], [1 : jsize+0] #define UY2(I, J) (uy2[(I ) + (isize+2) * (J-1)]) #define UY2_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, } -#endif - -#if NDIMS == 3 -// [0 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define UY2(I, J, K) (uy2[(I ) + (isize+2) * ((J-1) + (jsize+0) * (K-1))]) -#define UY2_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, {0, 0}, } -#endif #endif // INCLUDE_ARRAY_MACROS_STATISTICS_UY2_H diff --git a/include/array_macros/statistics/uz1.h b/include/array_macros/statistics/uz1.h index 396c670a..bd03c79f 100644 --- a/include/array_macros/statistics/uz1.h +++ b/include/array_macros/statistics/uz1.h @@ -3,10 +3,4 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 3 -// [0 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define UZ1(I, J, K) (uz1[(I ) + (isize+2) * ((J-1) + (jsize+0) * (K-1))]) -#define UZ1_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, {0, 0}, } -#endif - #endif // INCLUDE_ARRAY_MACROS_STATISTICS_UZ1_H diff --git a/include/array_macros/statistics/uz2.h b/include/array_macros/statistics/uz2.h index 48543695..2b808bc5 100644 --- a/include/array_macros/statistics/uz2.h +++ b/include/array_macros/statistics/uz2.h @@ -3,10 +3,4 @@ // This file is generated by tools/define_arrays.py -#if NDIMS == 3 -// [0 : isize+1], [1 : jsize+0], [1 : ksize+0] -#define UZ2(I, J, K) (uz2[(I ) + (isize+2) * ((J-1) + (jsize+0) * (K-1))]) -#define UZ2_NADDS (int [NDIMS][2]){ {1, 1}, {0, 0}, {0, 0}, } -#endif - #endif // INCLUDE_ARRAY_MACROS_STATISTICS_UZ2_H diff --git a/include/domain.h b/include/domain.h index 0626fbb5..15fa7bd2 100644 --- a/include/domain.h +++ b/include/domain.h @@ -3,7 +3,7 @@ #include "sdecomp.h" -// definition of a structure domain_t | 25 +// definition of a structure domain_t /** * @struct domain_t * @brief struct storing parameters relevant to spatial domain @@ -25,9 +25,6 @@ typedef struct { double * restrict xf, * restrict xc; double * restrict hxxf, * restrict hxxc; double hy; -#if NDIMS == 3 - double hz; -#endif double * restrict jdxf, * restrict jdxc; } domain_t; diff --git a/include/fluid.h b/include/fluid.h index 555d737d..3956f25e 100644 --- a/include/fluid.h +++ b/include/fluid.h @@ -4,7 +4,7 @@ #include "array.h" #include "domain.h" -// definition of a structure fluid_t_ | 30 +// definition of a structure fluid_t_ /** * @struct fluid_t * @brief struct storing fluid-related variables @@ -20,17 +20,11 @@ typedef struct { array_t ux; array_t uy; -#if NDIMS == 3 - array_t uz; -#endif array_t p; array_t psi; array_t t; array_t srcux[3]; array_t srcuy[3]; -#if NDIMS == 3 - array_t srcuz[3]; -#endif array_t srct[3]; double Ra, Pr; } fluid_t; diff --git a/include/fluid_solver.h b/include/fluid_solver.h index adfac0e0..b7fe9c92 100644 --- a/include/fluid_solver.h +++ b/include/fluid_solver.h @@ -54,13 +54,6 @@ extern int fluid_update_boundaries_uy( array_t * uy ); -#if NDIMS == 3 -extern int fluid_update_boundaries_uz( - const domain_t * domain, - array_t * uz -); -#endif - extern int fluid_update_boundaries_p( const domain_t * domain, array_t * p diff --git a/include/halo.h b/include/halo.h index 177cec93..4bb81dc6 100644 --- a/include/halo.h +++ b/include/halo.h @@ -7,12 +7,4 @@ int halo_communicate_in_y( array_t * array ); -#if NDIMS == 3 -int halo_communicate_in_z( - const domain_t * domain, - MPI_Datatype * dtype, - array_t * array -); -#endif - #endif // HALO_H diff --git a/include/linear_system.h b/include/linear_system.h index fa217b85..6adb97f3 100644 --- a/include/linear_system.h +++ b/include/linear_system.h @@ -26,25 +26,12 @@ typedef struct { bool implicit[NDIMS]; double * restrict x1pncl; double * restrict y1pncl; -#if NDIMS == 3 - double * restrict z2pncl; -#endif size_t x1pncl_mysizes[NDIMS]; size_t y1pncl_mysizes[NDIMS]; -#if NDIMS == 3 - size_t z2pncl_mysizes[NDIMS]; -#endif tdm_info_t * tdm_x; tdm_info_t * tdm_y; -#if NDIMS == 3 - tdm_info_t * tdm_z; -#endif sdecomp_transpose_plan_t * transposer_x1_to_y1; sdecomp_transpose_plan_t * transposer_y1_to_x1; -#if NDIMS == 3 - sdecomp_transpose_plan_t * transposer_x1_to_z2; - sdecomp_transpose_plan_t * transposer_z2_to_x1; -#endif } linear_system_t; extern int linear_system_init( diff --git a/include/param.h b/include/param.h index 8f2d9da8..a3a073ba 100644 --- a/include/param.h +++ b/include/param.h @@ -17,15 +17,9 @@ extern const bool param_add_buoyancy; // flags to specify the diffusive treatment of the momentum equations extern const bool param_m_implicit_x; extern const bool param_m_implicit_y; -#if NDIMS == 3 -extern const bool param_m_implicit_z; -#endif // flags to specify the diffusive treatment of the temperature equation extern const bool param_t_implicit_x; extern const bool param_t_implicit_y; -#if NDIMS == 3 -extern const bool param_t_implicit_z; -#endif /* boundary-condition.c */ // NOTE: changing values may break the Nusselt balance @@ -34,12 +28,6 @@ extern const bool param_t_implicit_z; extern const double param_uy_xm; // positive-x-wall velocity in y direction extern const double param_uy_xp; -#if NDIMS == 3 -// negative-x-wall velocity in z direction -extern const double param_uz_xm; -// positive-x-wall velocity in z direction -extern const double param_uz_xp; -#endif // negative-x-wall temperature extern const double param_t_xm; // positive-x-wall temperature diff --git a/include/runge_kutta.h b/include/runge_kutta.h index 64353c79..69aaf1f6 100644 --- a/include/runge_kutta.h +++ b/include/runge_kutta.h @@ -3,7 +3,7 @@ #include -// Runge-Kutta configurations | 10 +// Runge-Kutta configurations // NOTE: three buffers: alpha, beta, gamma #define RKNBUFFERS 3 // indices diff --git a/src/array.c b/src/array.c index c7e02b3d..e204c098 100644 --- a/src/array.c +++ b/src/array.c @@ -71,17 +71,9 @@ static int get_index( const int nadds[NDIMS][2], const int indices[NDIMS] ){ -#if NDIMS == 2 const int index = + indices[0] + (indices[1] + nadds[1][0]) * (mysizes[0] + nadds[0][0] + nadds[0][1]); -#else - const int index = - + indices[0] - + (indices[1] + nadds[1][0]) * (mysizes[0] + nadds[0][0] + nadds[0][1]) - + (indices[2] + nadds[2][0]) * (mysizes[0] + nadds[0][0] + nadds[0][1]) - * (mysizes[1] + nadds[1][0] + nadds[1][1]); -#endif return index; } @@ -98,24 +90,14 @@ static int load( const int nadds[NDIMS][2] = { {array->nadds[0][0], array->nadds[0][1]}, {array->nadds[1][0], array->nadds[1][1]}, -#if NDIMS == 3 - {array->nadds[2][0], array->nadds[2][1]}, -#endif }; const size_t size = array->size; char * data = array->data; // prepare a buffer -#if NDIMS == 2 char * buf = memory_calloc( (mysizes[0] + nadds[0][0] + nadds[0][1]) * mysizes[1], size ); -#else - char * buf = memory_calloc( - (mysizes[0] + nadds[0][0] + nadds[0][1]) * mysizes[1] * mysizes[2], - size - ); -#endif // read MPI_Comm comm_cart = MPI_COMM_NULL; sdecomp.get_comm_cart(domain->info, &comm_cart); @@ -125,23 +107,14 @@ static int load( dsetname, NDIMS, (int [NDIMS]){ -#if NDIMS == 3 - glsizes[2], -#endif glsizes[1], glsizes[0] + nadds[0][0] + nadds[0][1], }, (int [NDIMS]){ -#if NDIMS == 3 - mysizes[2], -#endif mysizes[1], mysizes[0] + nadds[0][0] + nadds[0][1], }, (int [NDIMS]){ -#if NDIMS == 3 - offsets[2], -#endif offsets[1], offsets[0], }, @@ -154,7 +127,6 @@ static int load( return 1; } // copy -#if NDIMS == 2 const int imax = mysizes[0] + nadds[0][0] + nadds[0][1]; const int jmax = mysizes[1]; for(int cnt = 0, j = 0; j < jmax; j++){ @@ -167,23 +139,6 @@ static int load( memcpy(data + size * index, buf + size * cnt, size); } } -#else - const int imax = mysizes[0] + nadds[0][0] + nadds[0][1]; - const int jmax = mysizes[1]; - const int kmax = mysizes[2]; - for(int cnt = 0, k = 0; k < kmax; k++){ - for(int j = 0; j < jmax; j++){ - for(int i = 0; i < imax; i++, cnt++){ - const int index = get_index( - (int [NDIMS]){mysizes[0], mysizes[1], mysizes[2]}, - nadds, - (int [NDIMS]){i, j, k} - ); - memcpy(data + size * index, buf + size * cnt, size); - } - } - } -#endif memory_free(buf); return 0; } @@ -201,26 +156,15 @@ static int dump( const int nadds[NDIMS][2] = { {array->nadds[0][0], array->nadds[0][1]}, {array->nadds[1][0], array->nadds[1][1]}, -#if NDIMS == 3 - {array->nadds[2][0], array->nadds[2][1]}, -#endif }; const size_t size = array->size; const char * data = array->data; // prepare a buffer -#if NDIMS == 2 char * buf = memory_calloc( (mysizes[0] + nadds[0][0] + nadds[0][1]) * mysizes[1], size ); -#else - char * buf = memory_calloc( - (mysizes[0] + nadds[0][0] + nadds[0][1]) * mysizes[1] * mysizes[2], - size - ); -#endif // copy -#if NDIMS == 2 const int imax = mysizes[0] + nadds[0][0] + nadds[0][1]; const int jmax = mysizes[1]; for(int cnt = 0, j = 0; j < jmax; j++){ @@ -233,23 +177,6 @@ static int dump( memcpy(buf + size * cnt, data + size * index, size); } } -#else - const int imax = mysizes[0] + nadds[0][0] + nadds[0][1]; - const int jmax = mysizes[1]; - const int kmax = mysizes[2]; - for(int cnt = 0, k = 0; k < kmax; k++){ - for(int j = 0; j < jmax; j++){ - for(int i = 0; i < imax; i++, cnt++){ - const int index = get_index( - (int [NDIMS]){mysizes[0], mysizes[1], mysizes[2]}, - nadds, - (int [NDIMS]){i, j, k} - ); - memcpy(buf + size * cnt, data + size * index, size); - } - } - } -#endif // write MPI_Comm comm_cart = MPI_COMM_NULL; sdecomp.get_comm_cart(domain->info, &comm_cart); @@ -259,23 +186,14 @@ static int dump( dsetname, NDIMS, (int [NDIMS]){ -#if NDIMS == 3 - glsizes[2], -#endif glsizes[1], glsizes[0] + nadds[0][0] + nadds[0][1], }, (int [NDIMS]){ -#if NDIMS == 3 - mysizes[2], -#endif mysizes[1], mysizes[0] + nadds[0][0] + nadds[0][1], }, (int [NDIMS]){ -#if NDIMS == 3 - offsets[2], -#endif offsets[1], offsets[0], }, diff --git a/src/decide_dt.c b/src/decide_dt.c index 31443207..1a93971c 100644 --- a/src/decide_dt.c +++ b/src/decide_dt.c @@ -12,9 +12,6 @@ #include "fluid_solver.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "array_macros/domain/hxxf.h" // overriden later using environment variables @@ -42,70 +39,28 @@ static int decide_dt_adv( sdecomp.get_comm_cart(domain->info, &comm_cart); const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double hy = domain->hy; -#if NDIMS == 3 - const double hz = domain->hz; -#endif const double * restrict ux = fluid->ux.data; const double * restrict uy = fluid->uy.data; -#if NDIMS == 3 - const double * restrict uz = fluid->uz.data; -#endif // sufficiently small number to avoid zero division const double small = 1.e-8; *dt = dt_max; - // compute grid size over velocity in x | 19 -#if NDIMS == 2 + // compute grid size over velocity in x for (int j = 1; j <= jsize; j++) { for (int i = 2; i <= isize; i++) { const double vel = fabs(UX(i, j)) + small; *dt = fmin(*dt, HXXF(i) / vel); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 2; i <= isize; i++) { - const double vel = fabs(UX(i, j, k)) + small; - *dt = fmin(*dt, HXXF(i) / vel); - } - } - } -#endif - // compute grid size over velocity in y | 17 -#if NDIMS == 2 + // compute grid size over velocity in y for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize; i++) { const double vel = fabs(UY(i, j)) + small; *dt = fmin(*dt, hy / vel); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double vel = fabs(UY(i, j, k)) + small; - *dt = fmin(*dt, hy / vel); - } - } - } -#endif -#if NDIMS == 3 - // compute grid size over velocity in z | 10 - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double vel = fabs(UZ(i, j, k)) + small; - *dt = fmin(*dt, hz / vel); - } - } - } -#endif - // unify result, multiply safety factor | 2 + // unify result, multiply safety factor MPI_Allreduce(MPI_IN_PLACE, dt, 1, MPI_DOUBLE, MPI_MIN, comm_cart); *dt *= coef_dt_adv; return 0; @@ -126,9 +81,6 @@ static int decide_dt_dif ( const int isize = domain->mysizes[0]; const double * restrict hxxf = domain->hxxf; const double hy = domain->hy; -#if NDIMS == 3 - const double hz = domain->hz; -#endif double grid_sizes[NDIMS] = {0.}; // find minimum grid size in x direction grid_sizes[0] = DBL_MAX; @@ -136,10 +88,7 @@ static int decide_dt_dif ( grid_sizes[0] = fmin(grid_sizes[0], HXXF(i)); } grid_sizes[1] = hy; -#if NDIMS == 3 - grid_sizes[2] = hz; -#endif - // compute diffusive constraints | 3 + // compute diffusive constraints for (size_t dim = 0; dim < NDIMS; dim++) { dt[dim] = coef_dt_dif / diffusivity * 0.5 / NDIMS * pow(grid_sizes[dim], 2.); } @@ -170,14 +119,14 @@ int decide_dt( printf("coefs: (adv) % .3e, (dif) % .3e\n", coef_dt_adv, coef_dt_dif); } } - // compute advective and diffusive constraints | 6 + // compute advective and diffusive constraints double dt_adv[1] = {0.}; double dt_dif_m[NDIMS] = {0.}; double dt_dif_t[NDIMS] = {0.}; decide_dt_adv(domain, fluid, dt_adv); decide_dt_dif(domain, fluid_compute_momentum_diffusivity(fluid), dt_dif_m); decide_dt_dif(domain, fluid_compute_temperature_diffusivity(fluid), dt_dif_t); - // choose smallest value as dt | 26 + // choose smallest value as dt *dt = dt_max; // advection *dt = fmin(*dt, dt_adv[0]); @@ -188,11 +137,6 @@ int decide_dt( if (!param_m_implicit_y) { *dt = fmin(*dt, dt_dif_m[1]); } -#if NDIMS == 3 - if (!param_m_implicit_z) { - *dt = fmin(*dt, dt_dif_m[2]); - } -#endif // diffusion, temperature if (!param_t_implicit_x) { *dt = fmin(*dt, dt_dif_t[0]); @@ -200,11 +144,6 @@ int decide_dt( if (!param_t_implicit_y) { *dt = fmin(*dt, dt_dif_t[1]); } -#if NDIMS == 3 - if (!param_t_implicit_z) { - *dt = fmin(*dt, dt_dif_t[2]); - } -#endif return 0; } diff --git a/src/domain.c b/src/domain.c index ebdbaf97..a79ec95c 100644 --- a/src/domain.c +++ b/src/domain.c @@ -4,10 +4,6 @@ #include #include #include -#if NDIMS == 3 -#include -#include "timer.h" -#endif #include "sdecomp.h" #include "memory.h" #include "domain.h" @@ -79,180 +75,7 @@ int domain_save( return 0; } -#if NDIMS == 3 -static int get_ndigits( - int num -){ - // just for pretty print - // e.g. num = 3 -> return 1 - // e.g. num = 13 -> return 2 - // e.g. num = 1234 -> return 4 - if(num < 0){ - return 0; - } - int retval = 1; - while(num /= 10){ - retval++; - } - return retval; -} - -// optimise MPI domain decomposition, -// i.e. minimise all-to-all time -static int optimise_sdecomp_init( - const size_t * glsizes, - sdecomp_info_t ** info_optimum -){ - // periodicity in each dimension, - // which are fixed in this project - // (x: wall-bounded, otherwise periodic) - const bool periods[NDIMS] = {false, true, true}; - // global array size, real - const size_t r_gl_sizes[NDIMS] = {glsizes[0], glsizes[1], glsizes[2]}; - // global array size, complex (after-FFTed value in y) - const size_t c_gl_sizes[NDIMS] = {glsizes[0], glsizes[1] / 2 + 1, glsizes[2]}; - // number of processes in each dimension, - // which is to be optimised - size_t dims_optimum[NDIMS] = {0, 0, 0}; - double wtime_optimum = DBL_MAX; - const int root = 0; - int nprocs = 0; - int myrank = root; - MPI_Comm_size(MPI_COMM_WORLD, &nprocs); - MPI_Comm_rank(MPI_COMM_WORLD, &myrank); - const size_t nynz = (size_t)nprocs; - // factorise and decide dims - for(size_t ny = 1; ny <= nynz; ny++){ - if(0 != nynz % ny){ - // prime decomposition failed - continue; - } - const size_t nz = nynz / ny; - const size_t dims[NDIMS] = {1, ny, nz}; - // sanitise, for all dimensions, dims should not - // exceed the number of grid points - // NOTE: refer to the complex array, - // which is smaller in general - bool valid = true; - for(size_t dim1 = 0; dim1 < NDIMS; dim1++){ - const size_t glsize = c_gl_sizes[dim1]; - for(size_t dim0 = 0; dim0 < NDIMS; dim0++){ - const size_t np = dims[dim0]; - if(np > glsize){ - // number of processes is - // greater than number of grids - valid = false; - } - } - } - if(!valid){ - continue; - } - // execute transposes which are used to solve Poisson equation - // and check how long they take in total - // for the time being only transposes when solving Poisson equation are considered, - // i.e. implicity and implicitz also request transposes, which are neglected - sdecomp_info_t * info = NULL; - if(0 != sdecomp.construct( - MPI_COMM_WORLD, - NDIMS, - (size_t [NDIMS]){dims[0], dims[1], dims[2]}, - periods, - &info - )) return 1; - // initialise pencils and rotations - double * r_x1pcnl = NULL; - double * r_y1pcnl = NULL; - fftw_complex * c_y1pcnl = NULL; - fftw_complex * c_z1pcnl = NULL; - fftw_complex * c_x2pcnl = NULL; - sdecomp_transpose_plan_t * r_x1_to_y1 = NULL; - sdecomp_transpose_plan_t * r_y1_to_x1 = NULL; - sdecomp_transpose_plan_t * c_y1_to_z1 = NULL; - sdecomp_transpose_plan_t * c_z1_to_y1 = NULL; - sdecomp_transpose_plan_t * c_z1_to_x2 = NULL; - sdecomp_transpose_plan_t * c_x2_to_z1 = NULL; - if(0 != sdecomp.transpose.construct(info, SDECOMP_X1PENCIL, SDECOMP_Y1PENCIL, r_gl_sizes, sizeof( double), &r_x1_to_y1)) return 1; - if(0 != sdecomp.transpose.construct(info, SDECOMP_Y1PENCIL, SDECOMP_X1PENCIL, r_gl_sizes, sizeof( double), &r_y1_to_x1)) return 1; - if(0 != sdecomp.transpose.construct(info, SDECOMP_Y1PENCIL, SDECOMP_Z1PENCIL, c_gl_sizes, sizeof(fftw_complex), &c_y1_to_z1)) return 1; - if(0 != sdecomp.transpose.construct(info, SDECOMP_Z1PENCIL, SDECOMP_Y1PENCIL, c_gl_sizes, sizeof(fftw_complex), &c_z1_to_y1)) return 1; - if(0 != sdecomp.transpose.construct(info, SDECOMP_Z1PENCIL, SDECOMP_X2PENCIL, c_gl_sizes, sizeof(fftw_complex), &c_z1_to_x2)) return 1; - if(0 != sdecomp.transpose.construct(info, SDECOMP_X2PENCIL, SDECOMP_Z1PENCIL, c_gl_sizes, sizeof(fftw_complex), &c_x2_to_z1)) return 1; - size_t r_x1sizes[NDIMS] = {0}; - size_t r_y1sizes[NDIMS] = {0}; - size_t c_y1sizes[NDIMS] = {0}; - size_t c_z1sizes[NDIMS] = {0}; - size_t c_x2sizes[NDIMS] = {0}; - for(sdecomp_dir_t dim = 0; dim < NDIMS; dim++){ - if(0 != sdecomp.get_pencil_mysize(info, SDECOMP_X1PENCIL, dim, r_gl_sizes[dim], r_x1sizes + dim)) return 1; - if(0 != sdecomp.get_pencil_mysize(info, SDECOMP_Y1PENCIL, dim, r_gl_sizes[dim], r_y1sizes + dim)) return 1; - if(0 != sdecomp.get_pencil_mysize(info, SDECOMP_Y1PENCIL, dim, c_gl_sizes[dim], c_y1sizes + dim)) return 1; - if(0 != sdecomp.get_pencil_mysize(info, SDECOMP_Z1PENCIL, dim, c_gl_sizes[dim], c_z1sizes + dim)) return 1; - if(0 != sdecomp.get_pencil_mysize(info, SDECOMP_X2PENCIL, dim, c_gl_sizes[dim], c_x2sizes + dim)) return 1; - } - r_x1pcnl = memory_calloc(r_x1sizes[0] * r_x1sizes[1] * r_x1sizes[2], sizeof( double)); - r_y1pcnl = memory_calloc(r_y1sizes[0] * r_y1sizes[1] * r_y1sizes[2], sizeof( double)); - c_y1pcnl = memory_calloc(c_y1sizes[0] * c_y1sizes[1] * c_y1sizes[2], sizeof(fftw_complex)); - c_z1pcnl = memory_calloc(c_z1sizes[0] * c_z1sizes[1] * c_z1sizes[2], sizeof(fftw_complex)); - c_x2pcnl = memory_calloc(c_x2sizes[0] * c_x2sizes[1] * c_x2sizes[2], sizeof(fftw_complex)); - // execute transpose, repeat for "niter" times - const size_t niter = 4; - const double tic = timer(); - for(size_t iter = 0; iter < niter; iter++){ - sdecomp.transpose.execute(r_x1_to_y1, r_x1pcnl, r_y1pcnl); - sdecomp.transpose.execute(c_y1_to_z1, c_y1pcnl, c_z1pcnl); - sdecomp.transpose.execute(c_z1_to_x2, c_z1pcnl, c_x2pcnl); - sdecomp.transpose.execute(c_x2_to_z1, c_x2pcnl, c_z1pcnl); - sdecomp.transpose.execute(c_z1_to_y1, c_z1pcnl, c_y1pcnl); - sdecomp.transpose.execute(r_y1_to_x1, r_y1pcnl, r_x1pcnl); - } - const double toc = timer(); - // clean-up tentative transpose plans and buffers - sdecomp.transpose.destruct(r_x1_to_y1); - sdecomp.transpose.destruct(c_y1_to_z1); - sdecomp.transpose.destruct(c_z1_to_x2); - sdecomp.transpose.destruct(c_x2_to_z1); - sdecomp.transpose.destruct(c_z1_to_y1); - sdecomp.transpose.destruct(r_y1_to_x1); - memory_free(r_x1pcnl); - memory_free(r_y1pcnl); - memory_free(c_y1pcnl); - memory_free(c_z1pcnl); - memory_free(c_x2pcnl); - // clean-up current sdecomp config - sdecomp.destruct(info); - // check time - const double wtime = (toc - tic) / niter; - if(wtime < wtime_optimum){ - // this is the best option for now, - // update candidate - for(size_t dim = 0; dim < NDIMS; dim++){ - dims_optimum[dim] = dims[dim]; - } - wtime_optimum = wtime; - } - if(root == myrank){ - const int nd = get_ndigits(nprocs); - printf("dims: [%*zu, %*zu, %*zu]: % .7e [sec]\n", nd, dims[0], nd, dims[1], nd, dims[2], wtime); - } - } - // create sdecomp which will be used in the main run - if(0 != sdecomp.construct( - MPI_COMM_WORLD, - NDIMS, - (size_t [NDIMS]){dims_optimum[0], dims_optimum[1], dims_optimum[2]}, - periods, - info_optimum - )) return 1; - if(root == myrank){ - const int nd = get_ndigits(nprocs); - printf("Conclusive domain decomposition: [%*zu, %*zu, %*zu]\n", nd, dims_optimum[0], nd, dims_optimum[1], nd, dims_optimum[2]); - } - return 0; -} -#endif - -// x scale factors at x cell faces | 10 +// x scale factors at x cell faces static double * allocate_and_init_hxxf ( const int isize, const double * xc @@ -264,7 +87,7 @@ static double * allocate_and_init_hxxf ( return hxxf; } -// x scale factors at x cell centers | 10 +// x scale factors at x cell centers static double * allocate_and_init_hxxc ( const int isize, const double * xf @@ -276,46 +99,28 @@ static double * allocate_and_init_hxxc ( return hxxc; } -// jacobian determinants at x cell faces | 20 +// jacobian determinants at x cell faces static double * allocate_and_init_jdxf ( const int isize, const double * hxxf, -#if NDIMS == 2 const double hy -#else - const double hy, - const double hz -#endif ) { double * jdxf = memory_calloc(isize + 1, sizeof(double)); for (int i = 1; i <= isize + 1; i++) { -#if NDIMS == 2 JDXF(i ) = HXXF(i ) * hy; -#else - JDXF(i ) = HXXF(i ) * hy * hz; -#endif } return jdxf; } -// jacobian determinants at x cell centers | 20 +// jacobian determinants at x cell centers static double * allocate_and_init_jdxc ( const int isize, const double * hxxc, -#if NDIMS == 2 const double hy -#else - const double hy, - const double hz -#endif ) { double * jdxc = memory_calloc(isize, sizeof(double)); for (int i = 1; i <= isize; i++) { -#if NDIMS == 2 JDXC(i ) = HXXC(i ) * hy; -#else - JDXC(i ) = HXXC(i ) * hy * hz; -#endif } return jdxc; } @@ -359,34 +164,21 @@ int domain_init( double * restrict * hxxf = &domain->hxxf; double * restrict * hxxc = &domain->hxxc; double * restrict hy = &domain->hy; -#if NDIMS == 3 - double * restrict hz = &domain->hz; -#endif double * restrict * jdxf = &domain->jdxf; double * restrict * jdxc = &domain->jdxc; - // load spatial information | 3 + // load spatial information if(0 != domain_load(dirname_ic, domain)){ return 1; } // allocate and initialise scale factors *hxxf = allocate_and_init_hxxf(glsizes[0], *xc); *hxxc = allocate_and_init_hxxc(glsizes[0], *xf); - // y scale factor | 1 + // y scale factor *hy = lengths[1] / glsizes[1]; -#if NDIMS == 3 - // z scale factor | 1 - *hz = lengths[2] / glsizes[2]; -#endif // allocate and initialise Jacobian determinants -#if NDIMS == 2 *jdxf = allocate_and_init_jdxf(glsizes[0], *hxxf, *hy); *jdxc = allocate_and_init_jdxc(glsizes[0], *hxxc, *hy); -#else - *jdxf = allocate_and_init_jdxf(glsizes[0], *hxxf, *hy, *hz); - *jdxc = allocate_and_init_jdxc(glsizes[0], *hxxc, *hy, *hz); -#endif - // initialise sdecomp to distribute the domain | 14 -#if NDIMS == 2 + // initialise sdecomp to distribute the domain if(0 != sdecomp.construct( MPI_COMM_WORLD, NDIMS, @@ -394,13 +186,7 @@ int domain_init( (bool [NDIMS]){false, true}, info )) return 1; -#else - if(0 != optimise_sdecomp_init( - glsizes, - info - )) return 1; -#endif - // local array sizes and offsets | 4 + // local array sizes and offsets for(size_t dim = 0; dim < NDIMS; dim++){ sdecomp.get_pencil_mysize(*info, SDECOMP_X1PENCIL, dim, glsizes[dim], mysizes + dim); sdecomp.get_pencil_offset(*info, SDECOMP_X1PENCIL, dim, glsizes[dim], offsets + dim); diff --git a/src/fluid/boundary/p.c b/src/fluid/boundary/p.c index f9dbaf3c..b7f133e4 100644 --- a/src/fluid/boundary/p.c +++ b/src/fluid/boundary/p.c @@ -10,23 +10,11 @@ static int assign_boundary_conditions_in_x( ){ const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif - // set boundary values | 13 -#if NDIMS == 2 + // set boundary values for(int j = 1; j <= jsize; j++){ P( 0, j) = P( 1, j); // Neumann P(isize+1, j) = P(isize, j); // Neumann } -#else - for(int k = 1; k <= ksize; k++){ - for(int j = 1; j <= jsize; j++){ - P( 0, j, k) = P( 1, j, k); // Neumann - P(isize+1, j, k) = P(isize, j, k); // Neumann - } - } -#endif return 0; } @@ -42,18 +30,10 @@ int fluid_update_boundaries_p( ){ static MPI_Datatype dtypes[NDIMS - 1] = { MPI_DOUBLE, -#if NDIMS == 3 - MPI_DOUBLE, -#endif }; if(0 != halo_communicate_in_y(domain, dtypes + 0, p)){ return 1; } -#if NDIMS == 3 - if(0 != halo_communicate_in_z(domain, dtypes + 1, p)){ - return 1; - } -#endif assign_boundary_conditions_in_x(domain, p->data); return 0; } diff --git a/src/fluid/boundary/psi.c b/src/fluid/boundary/psi.c index 49d1b2be..51ef526a 100644 --- a/src/fluid/boundary/psi.c +++ b/src/fluid/boundary/psi.c @@ -10,23 +10,11 @@ static int assign_boundary_conditions_in_x( ){ const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif - // set boundary values | 13 -#if NDIMS == 2 + // set boundary values for(int j = 1; j <= jsize; j++){ PSI( 0, j) = PSI( 1, j); // Neumann PSI(isize+1, j) = PSI(isize, j); // Neumann } -#else - for(int k = 1; k <= ksize; k++){ - for(int j = 1; j <= jsize; j++){ - PSI( 0, j, k) = PSI( 1, j, k); // Neumann - PSI(isize+1, j, k) = PSI(isize, j, k); // Neumann - } - } -#endif return 0; } @@ -42,18 +30,10 @@ int fluid_update_boundaries_psi( ){ static MPI_Datatype dtypes[NDIMS - 1] = { MPI_DOUBLE, -#if NDIMS == 3 - MPI_DOUBLE, -#endif }; if(0 != halo_communicate_in_y(domain, dtypes + 0, psi)){ return 1; } -#if NDIMS == 3 - if(0 != halo_communicate_in_z(domain, dtypes + 1, psi)){ - return 1; - } -#endif assign_boundary_conditions_in_x(domain, psi->data); return 0; } diff --git a/src/fluid/boundary/t.c b/src/fluid/boundary/t.c index 2fe81e89..d1a2da90 100644 --- a/src/fluid/boundary/t.c +++ b/src/fluid/boundary/t.c @@ -11,23 +11,11 @@ static int assign_boundary_conditions_in_x( ){ const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif - // set boundary values | 13 -#if NDIMS == 2 + // set boundary values for(int j = 1; j <= jsize; j++){ T( 0, j) = param_t_xm; T(isize+1, j) = param_t_xp; } -#else - for(int k = 1; k <= ksize; k++){ - for(int j = 1; j <= jsize; j++){ - T( 0, j, k) = param_t_xm; - T(isize+1, j, k) = param_t_xp; - } - } -#endif return 0; } @@ -43,18 +31,10 @@ int fluid_update_boundaries_t( ){ static MPI_Datatype dtypes[NDIMS - 1] = { MPI_DOUBLE, -#if NDIMS == 3 - MPI_DOUBLE, -#endif }; if(0 != halo_communicate_in_y(domain, dtypes + 0, t)){ return 1; } -#if NDIMS == 3 - if(0 != halo_communicate_in_z(domain, dtypes + 1, t)){ - return 1; - } -#endif assign_boundary_conditions_in_x(domain, t->data); return 0; } diff --git a/src/fluid/boundary/ux.c b/src/fluid/boundary/ux.c index 85534898..8b3123d1 100644 --- a/src/fluid/boundary/ux.c +++ b/src/fluid/boundary/ux.c @@ -10,23 +10,11 @@ static int assign_boundary_conditions_in_x( ){ const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif - // set boundary values | 13 -#if NDIMS == 2 + // set boundary values for(int j = 1; j <= jsize; j++){ UX( 1, j) = 0.; // impermeable UX(isize+1, j) = 0.; // impermeable } -#else - for(int k = 1; k <= ksize; k++){ - for(int j = 1; j <= jsize; j++){ - UX( 1, j, k) = 0.; // impermeable - UX(isize+1, j, k) = 0.; // impermeable - } - } -#endif return 0; } @@ -42,18 +30,10 @@ int fluid_update_boundaries_ux( ){ static MPI_Datatype dtypes[NDIMS - 1] = { MPI_DOUBLE, -#if NDIMS == 3 - MPI_DOUBLE, -#endif }; if(0 != halo_communicate_in_y(domain, dtypes + 0, ux)){ return 1; } -#if NDIMS == 3 - if(0 != halo_communicate_in_z(domain, dtypes + 1, ux)){ - return 1; - } -#endif assign_boundary_conditions_in_x(domain, ux->data); return 0; } diff --git a/src/fluid/boundary/uy.c b/src/fluid/boundary/uy.c index 50b946fe..71443d5a 100644 --- a/src/fluid/boundary/uy.c +++ b/src/fluid/boundary/uy.c @@ -11,23 +11,11 @@ static int assign_boundary_conditions_in_x( ){ const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif - // set boundary values | 13 -#if NDIMS == 2 + // set boundary values for(int j = 1; j <= jsize; j++){ UY( 0, j) = param_uy_xm; // no-slip UY(isize+1, j) = param_uy_xp; // no-slip } -#else - for(int k = 1; k <= ksize; k++){ - for(int j = 1; j <= jsize; j++){ - UY( 0, j, k) = param_uy_xm; // no-slip - UY(isize+1, j, k) = param_uy_xp; // no-slip - } - } -#endif return 0; } @@ -43,18 +31,10 @@ int fluid_update_boundaries_uy( ){ static MPI_Datatype dtypes[NDIMS - 1] = { MPI_DOUBLE, -#if NDIMS == 3 - MPI_DOUBLE, -#endif }; if(0 != halo_communicate_in_y(domain, dtypes + 0, uy)){ return 1; } -#if NDIMS == 3 - if(0 != halo_communicate_in_z(domain, dtypes + 1, uy)){ - return 1; - } -#endif assign_boundary_conditions_in_x(domain, uy->data); return 0; } diff --git a/src/fluid/boundary/uz.c b/src/fluid/boundary/uz.c deleted file mode 100644 index 26244864..00000000 --- a/src/fluid/boundary/uz.c +++ /dev/null @@ -1,49 +0,0 @@ -#if NDIMS == 3 -#include "param.h" -#include "array.h" -#include "domain.h" -#include "halo.h" -#include "fluid_solver.h" -#include "array_macros/fluid/uz.h" - -static int assign_boundary_conditions_in_x( - const domain_t * domain, - double * uz -){ - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - // set boundary values | 6 - for(int k = 1; k <= ksize; k++){ - for(int j = 1; j <= jsize; j++){ - UZ( 0, j, k) = param_uz_xm; // no-slip - UZ(isize+1, j, k) = param_uz_xp; // no-slip - } - } - return 0; -} - -/** - * @brief update boundary values of z velocity - * @param[in] domain : information about domain decomposition and size - * @param[in,out] uz : z velocity - * @return : error code - */ -int fluid_update_boundaries_uz( - const domain_t * domain, - array_t * uz -){ - static MPI_Datatype dtypes[NDIMS - 1] = { - MPI_DOUBLE, - MPI_DOUBLE, - }; - if(0 != halo_communicate_in_y(domain, dtypes + 0, uz)){ - return 1; - } - if(0 != halo_communicate_in_z(domain, dtypes + 1, uz)){ - return 1; - } - assign_boundary_conditions_in_x(domain, uz->data); - return 0; -} -#endif diff --git a/src/fluid/compute_potential.c b/src/fluid/compute_potential.c index 97fce29e..9cdd758b 100644 --- a/src/fluid/compute_potential.c +++ b/src/fluid/compute_potential.c @@ -17,9 +17,6 @@ #include "array_macros/domain/jdxc.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "array_macros/fluid/psi.h" static const double g_pi = 3.14159265358979324; @@ -30,26 +27,13 @@ typedef struct { void * restrict buf0; void * restrict buf1; fftw_plan fftw_plan_y[2]; -#if NDIMS == 3 - fftw_plan fftw_plan_z[2]; -#endif size_t tdm_sizes[NDIMS]; tdm_info_t * tdm_info; double * restrict eval_ys; -#if NDIMS == 3 - double * restrict eval_zs; -#endif sdecomp_transpose_plan_t * r_transposer_x1_to_y1; sdecomp_transpose_plan_t * r_transposer_y1_to_x1; -#if NDIMS == 2 sdecomp_transpose_plan_t * c_transposer_x1_to_y1; sdecomp_transpose_plan_t * c_transposer_y1_to_x1; -#else - sdecomp_transpose_plan_t * c_transposer_y1_to_z1; - sdecomp_transpose_plan_t * c_transposer_z1_to_y1; - sdecomp_transpose_plan_t * c_transposer_z1_to_x2; - sdecomp_transpose_plan_t * c_transposer_x2_to_z1; -#endif } poisson_solver_t; /* initialise Poisson solver */ @@ -74,15 +58,8 @@ static size_t r_x1pncl_sizes[NDIMS] = {0}; static size_t r_y1pncl_sizes[NDIMS] = {0}; // local domain size (y1 pencil) in complex space static size_t c_y1pncl_sizes[NDIMS] = {0}; -#if NDIMS == 2 // local domain size (x1 pencil) in complex space static size_t c_x1pncl_sizes[NDIMS] = {0}; -#else -// local domain size (z1 pencil) in complex space -static size_t c_z1pncl_sizes[NDIMS] = {0}; -// local domain size (x2 pencil) in complex space -static size_t c_x2pncl_sizes[NDIMS] = {0}; -#endif static size_t prod ( const size_t sizes[NDIMS] @@ -130,27 +107,16 @@ static int compute_pencil_sizes ( const sdecomp_info_t * info = domain->info; r_gl_sizes[0] = domain->glsizes[0]; r_gl_sizes[1] = domain->glsizes[1]; -#if NDIMS == 3 - r_gl_sizes[2] = domain->glsizes[2]; -#endif // global domain size in complex space // NOTE: Hermite symmetry in y c_gl_sizes[0] = domain->glsizes[0]; c_gl_sizes[1] = domain->glsizes[1] / 2 + 1; -#if NDIMS == 3 - c_gl_sizes[2] = domain->glsizes[2]; -#endif // local domain sizes for (sdecomp_dir_t dim = 0; dim < NDIMS; dim++) { if (0 != sdecomp.get_pencil_mysize(info, SDECOMP_X1PENCIL, dim, r_gl_sizes[dim], r_x1pncl_sizes + dim)) return 1; if (0 != sdecomp.get_pencil_mysize(info, SDECOMP_Y1PENCIL, dim, r_gl_sizes[dim], r_y1pncl_sizes + dim)) return 1; if (0 != sdecomp.get_pencil_mysize(info, SDECOMP_Y1PENCIL, dim, c_gl_sizes[dim], c_y1pncl_sizes + dim)) return 1; -#if NDIMS == 2 if (0 != sdecomp.get_pencil_mysize(info, SDECOMP_X1PENCIL, dim, c_gl_sizes[dim], c_x1pncl_sizes + dim)) return 1; -#else - if (0 != sdecomp.get_pencil_mysize(info, SDECOMP_Z1PENCIL, dim, c_gl_sizes[dim], c_z1pncl_sizes + dim)) return 1; - if (0 != sdecomp.get_pencil_mysize(info, SDECOMP_X2PENCIL, dim, c_gl_sizes[dim], c_x2pncl_sizes + dim)) return 1; -#endif } return 0; } @@ -167,23 +133,12 @@ static int allocate_buffers ( const size_t c_dsize = sizeof(fftw_complex); size_t buf0_bytes = 0; size_t buf1_bytes = 0; -#if NDIMS == 2 // r_x1pncl -> rotate -> r_y1pncl -> FFT -> c_y1pncl -> rotate -> c_x1pncl // buffer0 buffer1 buffer0 buffer1 buf0_bytes = max(buf0_bytes, r_dsize * prod(r_x1pncl_sizes)); buf0_bytes = max(buf0_bytes, c_dsize * prod(c_y1pncl_sizes)); buf1_bytes = max(buf1_bytes, r_dsize * prod(r_y1pncl_sizes)); buf1_bytes = max(buf1_bytes, c_dsize * prod(c_x1pncl_sizes)); -#else - // r_x1pncl -> rotate -> r_y1pncl -> FFT -> c_y1pncl -> rotate -> c_z1pncl -> FFT -> c_z1pncl -> rotate -> c_x2pncl - // buffer0 buffer1 buffer0 buffer1 buffer0 buffer1 - buf0_bytes = max(buf0_bytes, r_dsize * prod(r_x1pncl_sizes)); - buf0_bytes = max(buf0_bytes, c_dsize * prod(c_y1pncl_sizes)); - buf0_bytes = max(buf0_bytes, c_dsize * prod(c_z1pncl_sizes)); - buf1_bytes = max(buf1_bytes, r_dsize * prod(r_y1pncl_sizes)); - buf1_bytes = max(buf1_bytes, c_dsize * prod(c_z1pncl_sizes)); - buf1_bytes = max(buf1_bytes, c_dsize * prod(c_x2pncl_sizes)); -#endif // allocate them using fftw_malloc to enforce them 16bit-aligned for SIMD *buf0 = fftw_malloc(buf0_bytes); if (NULL == *buf0) { @@ -214,14 +169,8 @@ static int init_tri_diagonal_solver ( // in the solver size_t * restrict tdm_sizes = poisson_solver->tdm_sizes; tdm_info_t ** tdm_info = &poisson_solver->tdm_info; -#if NDIMS == 2 tdm_sizes[0] = c_x1pncl_sizes[0]; tdm_sizes[1] = c_x1pncl_sizes[1]; -#else - tdm_sizes[0] = c_x2pncl_sizes[0]; - tdm_sizes[1] = c_x2pncl_sizes[1]; - tdm_sizes[2] = c_x2pncl_sizes[2]; -#endif if (0 != tdm.construct( /* size of system */ tdm_sizes[0], /* number of rhs */ 1, @@ -229,7 +178,7 @@ static int init_tri_diagonal_solver ( /* is complex */ true, /* output */ tdm_info )) return 1; - // initialise tri-diagonal matrix in x direction | 12 + // initialise tri-diagonal matrix in x direction double * tdm_l = NULL; double * tdm_u = NULL; tdm.get_l(*tdm_info, &tdm_l); @@ -260,7 +209,6 @@ static int init_pencil_rotations ( report_failure("SDECOMP y1 to x1 for real"); return 1; } -#if NDIMS == 2 if (0 != sdecomp.transpose.construct(info, SDECOMP_Y1PENCIL, SDECOMP_X1PENCIL, c_gl_sizes, c_dsize, &poisson_solver->c_transposer_y1_to_x1)) { report_failure("SDECOMP y1 to x1 for complex"); return 1; @@ -269,24 +217,6 @@ static int init_pencil_rotations ( report_failure("SDECOMP x1 to y1 for complex"); return 1; } -#else - if (0 != sdecomp.transpose.construct(info, SDECOMP_Y1PENCIL, SDECOMP_Z1PENCIL, c_gl_sizes, c_dsize, &poisson_solver->c_transposer_y1_to_z1)) { - report_failure("SDECOMP y1 to z1 for complex"); - return 1; - } - if (0 != sdecomp.transpose.construct(info, SDECOMP_Z1PENCIL, SDECOMP_Y1PENCIL, c_gl_sizes, c_dsize, &poisson_solver->c_transposer_z1_to_y1)) { - report_failure("SDECOMP z1 to y1 for complex"); - return 1; - } - if (0 != sdecomp.transpose.construct(info, SDECOMP_Z1PENCIL, SDECOMP_X2PENCIL, c_gl_sizes, c_dsize, &poisson_solver->c_transposer_z1_to_x2)) { - report_failure("SDECOMP z1 to x2 for complex"); - return 1; - } - if (0 != sdecomp.transpose.construct(info, SDECOMP_X2PENCIL, SDECOMP_Z1PENCIL, c_gl_sizes, c_dsize, &poisson_solver->c_transposer_x2_to_z1)) { - report_failure("SDECOMP x2 to z1 for complex"); - return 1; - } -#endif return 0; } @@ -302,11 +232,7 @@ static int init_ffts ( fftw_plan * bplan = &poisson_solver->fftw_plan_y[1]; const int r_signal_length = r_y1pncl_sizes[SDECOMP_YDIR]; const int c_signal_length = c_y1pncl_sizes[SDECOMP_YDIR]; -#if NDIMS == 2 const int repeat_for = r_y1pncl_sizes[SDECOMP_XDIR]; -#else - const int repeat_for = r_y1pncl_sizes[SDECOMP_ZDIR] * r_y1pncl_sizes[SDECOMP_XDIR]; -#endif *fplan = fftw_plan_many_dft_r2c( 1, &r_signal_length, repeat_for, poisson_solver->buf1, NULL, 1, r_signal_length, @@ -328,35 +254,6 @@ static int init_ffts ( return 1; } } -#if NDIMS == 3 - // z, complex to complex - { - const int signal_length = c_z1pncl_sizes[SDECOMP_ZDIR]; - const int repeat_for = c_z1pncl_sizes[SDECOMP_XDIR] * c_z1pncl_sizes[SDECOMP_YDIR]; - fftw_plan * fplan = &poisson_solver->fftw_plan_z[0]; - fftw_plan * bplan = &poisson_solver->fftw_plan_z[1]; - *fplan = fftw_plan_many_dft( - 1, &signal_length, repeat_for, - poisson_solver->buf1, NULL, 1, signal_length, - poisson_solver->buf0, NULL, 1, signal_length, - FFTW_FORWARD, flags - ); - *bplan = fftw_plan_many_dft( - 1, &signal_length, repeat_for, - poisson_solver->buf0, NULL, 1, signal_length, - poisson_solver->buf1, NULL, 1, signal_length, - FFTW_BACKWARD, flags - ); - if (NULL == *fplan) { - report_failure("FFTW z-forward"); - return 1; - } - if (NULL == *bplan) { - report_failure("FFTW z-backward"); - return 1; - } - } -#endif return 0; } @@ -365,14 +262,9 @@ static int init_eigenvalues ( poisson_solver_t * poisson_solver ) { const sdecomp_info_t * info = domain->info; -#if NDIMS == 2 // x1 pencil const sdecomp_pencil_t pencil = SDECOMP_X1PENCIL; -#else - // x2 pencil - const sdecomp_pencil_t pencil = SDECOMP_X2PENCIL; -#endif - // y eigenvalues | 16 + // y eigenvalues { double * restrict * evals = &poisson_solver->eval_ys; size_t mysize = 0; @@ -389,25 +281,6 @@ static int init_eigenvalues ( ); } } -#if NDIMS == 3 - // z eigenvalues | 16 - { - double * restrict * evals = &poisson_solver->eval_zs; - size_t mysize = 0; - size_t myoffs = 0; - sdecomp.get_pencil_mysize(info, pencil, SDECOMP_ZDIR, c_gl_sizes[SDECOMP_ZDIR], &mysize); - sdecomp.get_pencil_offset(info, pencil, SDECOMP_ZDIR, c_gl_sizes[SDECOMP_ZDIR], &myoffs); - *evals = memory_calloc(mysize, sizeof(double)); - for (size_t local_n = 0; local_n < mysize; local_n++) { - const size_t global_n = local_n + myoffs; - (*evals)[local_n] = - - 4. * pow( - sin( g_pi * global_n / r_gl_sizes[SDECOMP_ZDIR] ), - 2. - ); - } - } -#endif return 0; } @@ -433,25 +306,14 @@ static int init_poisson_solver ( return 0; } -#if NDIMS == 2 #define BEGIN \ for (int cnt = 0, j = 1; j <= jsize; j++) { \ for (int i = 1; i <= isize; i++, cnt++) { #define END \ } \ } -#else -#define BEGIN \ - for (int cnt = 0, k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 1; i <= isize; i++, cnt++) { -#define END \ - } \ - } \ - } -#endif -// compute right-hand side of Poisson equation | 61 +// compute right-hand side of Poisson equation static int assign_input ( const domain_t * domain, const size_t rkstep, @@ -461,27 +323,14 @@ static int assign_input ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double hy = domain->hy; -#if NDIMS == 3 - const double hz = domain->hz; -#endif const double * restrict jdxf = domain->jdxf; const double * restrict jdxc = domain->jdxc; const double * restrict ux = fluid->ux.data; const double * restrict uy = fluid->uy.data; -#if NDIMS == 3 - const double * restrict uz = fluid->uz.data; -#endif // normalise FFT beforehand -#if NDIMS == 2 const double norm = 1. * domain->glsizes[1]; -#else - const double norm = 1. * domain->glsizes[1] * domain->glsizes[2]; -#endif const double prefactor = 1. / (rkcoefs[rkstep][rk_g] * dt) / norm; BEGIN const double hx_xm = HXXF(i ); @@ -489,25 +338,13 @@ static int assign_input ( const double jd_xm = JDXF(i ); const double jd_x0 = JDXC(i ); const double jd_xp = JDXF(i+1); -#if NDIMS == 2 const double ux_xm = UX(i , j ); const double ux_xp = UX(i+1, j ); const double uy_ym = UY(i , j ); const double uy_yp = UY(i , j+1); -#else - const double ux_xm = UX(i , j , k ); - const double ux_xp = UX(i+1, j , k ); - const double uy_ym = UY(i , j , k ); - const double uy_yp = UY(i , j+1, k ); - const double uz_zm = UZ(i , j , k ); - const double uz_zp = UZ(i , j , k+1); -#endif const double div = 1. / jd_x0 * ( - jd_xm / hx_xm * ux_xm + jd_xp / hx_xp * ux_xp - jd_x0 / hy * uy_ym + jd_x0 / hy * uy_yp -#if NDIMS == 3 - - jd_x0 / hz * uz_zm + jd_x0 / hz * uz_zp -#endif ); rhs[cnt] = prefactor * div; END @@ -519,15 +356,9 @@ static int solve_linear_systems ( poisson_solver_t * poisson_solver ) { const double hy = domain->hy; -#if NDIMS == 3 - const double hz = domain->hz; -#endif const size_t * restrict tdm_sizes = poisson_solver->tdm_sizes; const size_t isize = tdm_sizes[0]; const size_t jsize = tdm_sizes[1]; -#if NDIMS == 3 - const size_t ksize = tdm_sizes[2]; -#endif // tri-diagonal matrix tdm_info_t * tdm_info = poisson_solver->tdm_info; double * restrict tdm_l = NULL; @@ -538,12 +369,8 @@ static int solve_linear_systems ( tdm.get_c(tdm_info, &tdm_c); // eigenvalues coming from Fourier projection const double * restrict eval_ys = poisson_solver->eval_ys; -#if NDIMS == 3 - const double * restrict eval_zs = poisson_solver->eval_zs; -#endif fftw_complex * restrict rhs = poisson_solver->buf1; - // solve tri-diagonal matrices | 37 -#if NDIMS == 2 + // solve tri-diagonal matrices for (size_t j = 0; j < jsize; j++) { const double eval_y = eval_ys[j]; // set center diagonal components @@ -559,27 +386,6 @@ static int solve_linear_systems ( // solve tdm.solve(tdm_info, rhs + j * isize); } -#else - for (size_t k = 0; k < ksize; k++) { - const double eval_z = eval_zs[k]; - for (size_t j = 0; j < jsize; j++) { - const double eval_y = eval_ys[j]; - // set center diagonal components - for (size_t i = 0; i < isize; i++) { - tdm_c[i] = - - tdm_l[i] - - tdm_u[i] - + eval_y / hy / hy - + eval_z / hz / hz; - } - // boundary treatment (Neumann boundary condition) - tdm_c[ 0] += tdm_l[ 0]; - tdm_c[isize - 1] += tdm_u[isize - 1]; - // solve - tdm.solve(tdm_info, rhs + (k * jsize + j) * isize); - } - } -#endif return 0; } @@ -590,16 +396,9 @@ static int extract_output ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif double * restrict psi = fluid->psi.data; BEGIN -#if NDIMS == 2 PSI(i, j) = rhs[cnt]; -#else - PSI(i, j, k) = rhs[cnt]; -#endif END if (0 != fluid_update_boundaries_psi(domain, &fluid->psi)) { return 1; @@ -607,7 +406,7 @@ static int extract_output ( return 0; } -// solve Poisson equation | 105 +// solve Poisson equation int fluid_compute_potential ( const domain_t * domain, const size_t rkstep, @@ -639,7 +438,6 @@ int fluid_compute_potential ( // f(x, y, z) -> f(x, k_y, z) // from buf1 to buf0 fftw_execute(poisson_solver.fftw_plan_y[0]); -#if NDIMS == 2 // transpose complex y1pencil to x1pencil // from buf0 to buf1 sdecomp.transpose.execute( @@ -647,29 +445,8 @@ int fluid_compute_potential ( poisson_solver.buf0, poisson_solver.buf1 ); -#else - // transpose complex y1pencil to z1pencil - // from buf0 to buf1 - sdecomp.transpose.execute( - poisson_solver.c_transposer_y1_to_z1, - poisson_solver.buf0, - poisson_solver.buf1 - ); - // project z to wave space - // f(x, k_y, z) -> f(x, k_y, k_z) - // from buf1 to buf0 - fftw_execute(poisson_solver.fftw_plan_z[0]); - // transpose complex z1pencil to x2pencil - // from buf0 to buf1 - sdecomp.transpose.execute( - poisson_solver.c_transposer_z1_to_x2, - poisson_solver.buf0, - poisson_solver.buf1 - ); -#endif // solve linear systems in x direction solve_linear_systems(domain, &poisson_solver); -#if NDIMS == 2 // transpose complex x1pencil to y1pencil // from buf1 to buf0 sdecomp.transpose.execute( @@ -677,26 +454,6 @@ int fluid_compute_potential ( poisson_solver.buf1, poisson_solver.buf0 ); -#else - // transpose complex x2pencil to z1pencil - // from buf1 to buf0 - sdecomp.transpose.execute( - poisson_solver.c_transposer_x2_to_z1, - poisson_solver.buf1, - poisson_solver.buf0 - ); - // project z to physical space - // f(x, k_y, k_z) -> f(x, k_y, z) - // from buf0 to buf1 - fftw_execute(poisson_solver.fftw_plan_z[1]); - // transpose complex z1pencil to y1pencil - // from buf1 to buf0 - sdecomp.transpose.execute( - poisson_solver.c_transposer_z1_to_y1, - poisson_solver.buf1, - poisson_solver.buf0 - ); -#endif // project y to physical space // f(x, k_y) -> f(x, y) // f(x, k_y, z) -> f(x, y, z) diff --git a/src/fluid/correct/internal.h b/src/fluid/correct/internal.h index ccb5f04f..c49a5940 100644 --- a/src/fluid/correct/internal.h +++ b/src/fluid/correct/internal.h @@ -13,12 +13,4 @@ extern int fluid_correct_velocity_uy( fluid_t * fluid ); -#if NDIMS == 3 -extern int fluid_correct_velocity_uz( - const domain_t * domain, - const double prefactor, - fluid_t * fluid -); -#endif - #endif // FLUID_CORRECT_VELOCITY_INTERNAL_H diff --git a/src/fluid/correct/main.c b/src/fluid/correct/main.c index 6d960144..c8b94b80 100644 --- a/src/fluid/correct/main.c +++ b/src/fluid/correct/main.c @@ -18,14 +18,11 @@ int fluid_correct_velocity( const double dt, fluid_t * fluid ){ - // compute prefactor gamma dt | 2 + // compute prefactor gamma dt const double gamma = rkcoefs[rkstep][rk_g]; const double prefactor = gamma * dt; if(0 != fluid_correct_velocity_ux(domain, prefactor, fluid)) return 1; if(0 != fluid_correct_velocity_uy(domain, prefactor, fluid)) return 1; -#if NDIMS == 3 - if(0 != fluid_correct_velocity_uz(domain, prefactor, fluid)) return 1; -#endif return 0; } diff --git a/src/fluid/correct/ux.c b/src/fluid/correct/ux.c index 5a29074c..2105a0d6 100644 --- a/src/fluid/correct/ux.c +++ b/src/fluid/correct/ux.c @@ -6,25 +6,14 @@ #include "array_macros/fluid/ux.h" #include "array_macros/fluid/psi.h" -#if NDIMS == 2 #define BEGIN \ for (int j = 1; j <= jsize; j++) { \ for (int i = 2; i <= isize; i++) { #define END \ } \ } -#else -#define BEGIN \ - for (int k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 2; i <= isize; i++) { -#define END \ - } \ - } \ - } -#endif -// correct x velocity | 35 +// correct x velocity int fluid_correct_velocity_ux ( const domain_t * domain, const double prefactor, @@ -32,23 +21,14 @@ int fluid_correct_velocity_ux ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict psi = fluid->psi.data; double * restrict ux = fluid->ux.data; BEGIN const double hx = HXXF(i ); -#if NDIMS == 2 const double psi_xm = PSI(i-1, j ); const double psi_xp = PSI(i , j ); double * vel = &UX(i, j); -#else - const double psi_xm = PSI(i-1, j , k ); - const double psi_xp = PSI(i , j , k ); - double * vel = &UX(i, j, k); -#endif *vel -= prefactor / hx * ( - psi_xm + psi_xp diff --git a/src/fluid/correct/uy.c b/src/fluid/correct/uy.c index 158ebbe2..38a33a98 100644 --- a/src/fluid/correct/uy.c +++ b/src/fluid/correct/uy.c @@ -5,25 +5,14 @@ #include "array_macros/fluid/uy.h" #include "array_macros/fluid/psi.h" -#if NDIMS == 2 #define BEGIN \ for (int j = 1; j <= jsize; j++) { \ for (int i = 1; i <= isize; i++) { #define END \ } \ } -#else -#define BEGIN \ - for (int k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 1; i <= isize; i++) { -#define END \ - } \ - } \ - } -#endif -// correct y velocity | 34 +// correct y velocity int fluid_correct_velocity_uy ( const domain_t * domain, const double prefactor, @@ -31,22 +20,13 @@ int fluid_correct_velocity_uy ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; const double * restrict psi = fluid->psi.data; double * restrict uy = fluid->uy.data; BEGIN -#if NDIMS == 2 const double psi_ym = PSI(i , j-1); const double psi_yp = PSI(i , j ); double * vel = &UY(i, j); -#else - const double psi_ym = PSI(i , j-1, k ); - const double psi_yp = PSI(i , j , k ); - double * vel = &UY(i, j, k); -#endif *vel -= prefactor / hy * ( - psi_ym + psi_yp diff --git a/src/fluid/correct/uz.c b/src/fluid/correct/uz.c deleted file mode 100644 index 98dd33bd..00000000 --- a/src/fluid/correct/uz.c +++ /dev/null @@ -1,39 +0,0 @@ -#if NDIMS == 3 -#include "domain.h" -#include "fluid.h" -#include "fluid_solver.h" -#include "internal.h" -#include "array_macros/fluid/uz.h" -#include "array_macros/fluid/psi.h" - -// correct z velocity | 29 -int fluid_correct_velocity_uz ( - const domain_t * domain, - const double prefactor, - fluid_t * fluid -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict psi = fluid->psi.data; - double * restrict uz = fluid->uz.data; - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double psi_zm = PSI(i , j , k-1); - const double psi_zp = PSI(i , j , k ); - UZ(i, j, k) -= prefactor / hz * ( - - psi_zm - + psi_zp - ); - } - } - } - // update boundary and halo cells - if (0 != fluid_update_boundaries_uz(domain, &fluid->uz)) { - return 1; - } - return 0; -} -#endif diff --git a/src/fluid/init.c b/src/fluid/init.c index 1fc44622..c68e7571 100644 --- a/src/fluid/init.c +++ b/src/fluid/init.c @@ -9,17 +9,11 @@ #include "fileio.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "array_macros/fluid/p.h" #include "array_macros/fluid/t.h" #include "array_macros/fluid/psi.h" #include "array_macros/fluid/srcux.h" #include "array_macros/fluid/srcuy.h" -#if NDIMS == 3 -#include "array_macros/fluid/srcuz.h" -#endif #include "array_macros/fluid/srct.h" static int allocate ( @@ -29,9 +23,6 @@ static int allocate ( // velocity if (0 != array.create(domain, UX_NADDS, sizeof(double), &fluid->ux )) return 1; if (0 != array.create(domain, UY_NADDS, sizeof(double), &fluid->uy )) return 1; -#if NDIMS == 3 - if (0 != array.create(domain, UZ_NADDS, sizeof(double), &fluid->uz )) return 1; -#endif // pressure and scalar potential if (0 != array.create(domain, P_NADDS, sizeof(double), &fluid->p )) return 1; if (0 != array.create(domain, PSI_NADDS, sizeof(double), &fluid->psi)) return 1; @@ -41,9 +32,6 @@ static int allocate ( for (size_t n = 0; n < RKNBUFFERS; n++) { if (0 != array.create(domain, SRCUX_NADDS, sizeof(double), fluid->srcux + n)) return 1; if (0 != array.create(domain, SRCUY_NADDS, sizeof(double), fluid->srcuy + n)) return 1; -#if NDIMS == 3 - if (0 != array.create(domain, SRCUZ_NADDS, sizeof(double), fluid->srcuz + n)) return 1; -#endif if (0 != array.create(domain, SRCT_NADDS, sizeof(double), fluid->srct + n)) return 1; } return 0; @@ -62,9 +50,6 @@ static int report ( printf("\tPr: % .7e\n", fluid->Pr); printf("\tdiffusive treatment in x: %s\n", param_m_implicit_x ? "implicit" : "explicit"); printf("\tdiffusive treatment in y: %s\n", param_m_implicit_y ? "implicit" : "explicit"); -#if NDIMS == 3 - printf("\tdiffusive treatment in z: %s\n", param_m_implicit_z ? "implicit" : "explicit"); -#endif fflush(stdout); } return 0; @@ -83,25 +68,19 @@ int fluid_init( const domain_t * domain, fluid_t * fluid ) { - // allocate arrays | 1 + // allocate arrays if (0 != allocate(domain, fluid)) return 1; - // load flow fields | 7 + // load flow fields if (0 != array.load(domain, dirname_ic, "ux", fileio.npy_double, &fluid->ux)) return 1; if (0 != array.load(domain, dirname_ic, "uy", fileio.npy_double, &fluid->uy)) return 1; -#if NDIMS == 3 - if (0 != array.load(domain, dirname_ic, "uz", fileio.npy_double, &fluid->uz)) return 1; -#endif if (0 != array.load(domain, dirname_ic, "p", fileio.npy_double, &fluid-> p)) return 1; if (0 != array.load(domain, dirname_ic, "t", fileio.npy_double, &fluid-> t)) return 1; - // impose boundary conditions and communicate halo cells | 7 + // impose boundary conditions and communicate halo cells if (0 != fluid_update_boundaries_ux(domain, &fluid->ux)) return 1; if (0 != fluid_update_boundaries_uy(domain, &fluid->uy)) return 1; -#if NDIMS == 3 - if (0 != fluid_update_boundaries_uz(domain, &fluid->uz)) return 1; -#endif if (0 != fluid_update_boundaries_p(domain, &fluid->p)) return 1; if (0 != fluid_update_boundaries_t(domain, &fluid->t)) return 1; - // load diffusivities | 2 + // load diffusivities if (0 != config.get_double("Pr", &fluid->Pr)) return 1; if (0 != config.get_double("Ra", &fluid->Ra)) return 1; report(domain->info, fluid); diff --git a/src/fluid/predict/internal.h b/src/fluid/predict/internal.h index 3aacc945..9e14e0a5 100644 --- a/src/fluid/predict/internal.h +++ b/src/fluid/predict/internal.h @@ -15,9 +15,6 @@ typedef struct { bool is_initialised; laplacian_t * lapx; laplacian_t lapy; -#if NDIMS == 3 - laplacian_t lapz; -#endif } laplacians_t; extern int compute_rhs_ux ( @@ -30,13 +27,6 @@ extern int compute_rhs_uy ( fluid_t * fluid ); -#if NDIMS == 3 -extern int compute_rhs_uz ( - const domain_t * domain, - fluid_t * fluid -); -#endif - extern int compute_rhs_t ( const domain_t * domain, fluid_t * fluid @@ -56,15 +46,6 @@ extern int update_uy ( fluid_t * fluid ); -#if NDIMS == 3 -extern int update_uz ( - const domain_t * domain, - const size_t rkstep, - const double dt, - fluid_t * fluid -); -#endif - extern int update_t ( const domain_t * domain, const size_t rkstep, diff --git a/src/fluid/predict/main.c b/src/fluid/predict/main.c index b10d9035..e3f85059 100644 --- a/src/fluid/predict/main.c +++ b/src/fluid/predict/main.c @@ -39,18 +39,13 @@ int fluid_predict_field( fluid_t * fluid ){ // reset buffers - // copy previous k-step source term and reset | 14 + // copy previous k-step source term and reset if(0 != reset_srcs(fluid->srcux + rk_a, fluid->srcux + rk_b, fluid->srcux + rk_g)){ return 1; } if(0 != reset_srcs(fluid->srcuy + rk_a, fluid->srcuy + rk_b, fluid->srcuy + rk_g)){ return 1; } -#if NDIMS == 3 - if(0 != reset_srcs(fluid->srcuz + rk_a, fluid->srcuz + rk_b, fluid->srcuz + rk_g)){ - return 1; - } -#endif if(0 != reset_srcs(fluid->srct + rk_a, fluid->srct + rk_b, fluid->srct + rk_g)){ return 1; } @@ -61,11 +56,6 @@ int fluid_predict_field( if(0 != compute_rhs_uy(domain, fluid)){ return 1; } -#if NDIMS == 3 - if(0 != compute_rhs_uz(domain, fluid)){ - return 1; - } -#endif if(0 != compute_rhs_t (domain, fluid)){ return 1; } @@ -76,11 +66,6 @@ int fluid_predict_field( if(0 != update_uy(domain, rkstep, dt, fluid)){ return 1; } -#if NDIMS == 3 - if(0 != update_uz(domain, rkstep, dt, fluid)){ - return 1; - } -#endif if(0 != update_t (domain, rkstep, dt, fluid)){ return 1; } diff --git a/src/fluid/predict/t.c b/src/fluid/predict/t.c index 98f0fbee..3eed8857 100644 --- a/src/fluid/predict/t.c +++ b/src/fluid/predict/t.c @@ -13,9 +13,6 @@ #include "array_macros/domain/jdxc.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "array_macros/fluid/t.h" static laplacians_t laplacians = { @@ -28,7 +25,7 @@ static laplacians_t laplacians = { static int init_laplacians ( const domain_t * domain ) { - // scalar laplacian in x | 15 + // scalar laplacian in x { const int isize = domain->glsizes[0]; const double * hxxf = domain->hxxf; @@ -44,7 +41,7 @@ static int init_laplacians ( laplacians.LAPX(i).u = u; } } - // scalar laplacian in y | 9 + // scalar laplacian in y { const double hy = domain->hy; const double l = 1. / hy / hy; @@ -54,41 +51,18 @@ static int init_laplacians ( laplacians.lapy.c = c; laplacians.lapy.u = u; } -#if NDIMS == 3 - // scalar laplacian in z | 9 - { - const double hz = domain->hz; - const double l = 1. / hz / hz; - const double u = 1. / hz / hz; - const double c = - l - u; - laplacians.lapz.l = l; - laplacians.lapz.c = c; - laplacians.lapz.u = u; - } -#endif laplacians.is_initialised = true; return 0; } -#if NDIMS == 2 #define BEGIN \ for (int cnt = 0, j = 1; j <= jsize; j++) { \ for (int i = 1; i <= isize; i++, cnt++) { #define END \ } \ } -#else -#define BEGIN \ - for (int cnt = 0, k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 1; i <= isize; i++, cnt++) { -#define END \ - } \ - } \ - } -#endif -// advected in x | 44 +// advected in x static int advection_x ( const domain_t * domain, const double * restrict t, @@ -97,9 +71,6 @@ static int advection_x ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; const double * restrict jdxc = domain->jdxc; @@ -109,32 +80,21 @@ static int advection_x ( const double jd_xm = JDXF(i ); const double jd_x0 = JDXC(i ); const double jd_xp = JDXF(i+1); -#if NDIMS == 2 const double ux_xm = jd_xm / hx_xm * UX(i , j ); const double ux_xp = jd_xp / hx_xp * UX(i+1, j ); -#else - const double ux_xm = jd_xm / hx_xm * UX(i , j , k ); - const double ux_xp = jd_xp / hx_xp * UX(i+1, j , k ); -#endif const double l = - 0.5 * ux_xm; const double u = + 0.5 * ux_xp; const double c = - l - u; src[cnt] -= 1. / jd_x0 * ( -#if NDIMS == 2 + l * T(i-1, j ) + c * T(i , j ) + u * T(i+1, j ) -#else - + l * T(i-1, j , k ) - + c * T(i , j , k ) - + u * T(i+1, j , k ) -#endif ); END return 0; } -// advected in y | 39 +// advected in y static int advection_y ( const domain_t * domain, const double * restrict t, @@ -143,69 +103,25 @@ static int advection_y ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; const double * restrict jdxc = domain->jdxc; BEGIN const double jd = JDXC(i ); -#if NDIMS == 2 const double uy_ym = jd / hy * UY(i , j ); const double uy_yp = jd / hy * UY(i , j+1); -#else - const double uy_ym = jd / hy * UY(i , j , k ); - const double uy_yp = jd / hy * UY(i , j+1, k ); -#endif const double l = - 0.5 * uy_ym; const double u = + 0.5 * uy_yp; const double c = - l - u; src[cnt] -= 1. / jd * ( -#if NDIMS == 2 + l * T(i , j-1) + c * T(i , j ) + u * T(i , j+1) -#else - + l * T(i , j-1, k ) - + c * T(i , j , k ) - + u * T(i , j+1, k ) -#endif - ); - END - return 0; -} - -#if NDIMS == 3 -// advected in z | 26 -static int advection_z ( - const domain_t * domain, - const double * restrict t, - const double * restrict uz, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict jdxc = domain->jdxc; - BEGIN - const double jd = JDXC(i ); - const double uz_zm = jd / hz * UZ(i , j , k ); - const double uz_zp = jd / hz * UZ(i , j , k+1); - const double l = - 0.5 * uz_zm; - const double u = + 0.5 * uz_zp; - const double c = - l - u; - src[cnt] -= 1. / jd * ( - + l * T(i , j , k-1) - + c * T(i , j , k ) - + u * T(i , j , k+1) ); END return 0; } -#endif -// diffused in x | 27 +// diffused in x static int diffusion_x ( const domain_t * domain, const double diffusivity, @@ -214,27 +130,18 @@ static int diffusion_x ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const laplacian_t * lapx = laplacians.lapx; BEGIN src[cnt] += diffusivity * ( -#if NDIMS == 2 + LAPX(i).l * T(i-1, j ) + LAPX(i).c * T(i , j ) + LAPX(i).u * T(i+1, j ) -#else - + LAPX(i).l * T(i-1, j , k ) - + LAPX(i).c * T(i , j , k ) - + LAPX(i).u * T(i+1, j , k ) -#endif ); END return 0; } -// diffused in y | 27 +// diffused in y static int diffusion_y ( const domain_t * domain, const double diffusivity, @@ -243,50 +150,18 @@ static int diffusion_y ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const laplacian_t * lapy = &laplacians.lapy; BEGIN src[cnt] += diffusivity * ( -#if NDIMS == 2 + (*lapy).l * T(i , j-1) + (*lapy).c * T(i , j ) + (*lapy).u * T(i , j+1) -#else - + (*lapy).l * T(i , j-1, k ) - + (*lapy).c * T(i , j , k ) - + (*lapy).u * T(i , j+1, k ) -#endif - ); - END - return 0; -} - -#if NDIMS == 3 -// diffused in z | 19 -static int diffusion_z ( - const domain_t * domain, - const double diffusivity, - const double * restrict t, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const laplacian_t * lapz = &laplacians.lapz; - BEGIN - src[cnt] += diffusivity * ( - + (*lapz).l * T(i , j , k-1) - + (*lapz).c * T(i , j , k ) - + (*lapz).u * T(i , j , k+1) ); END return 0; } -#endif -// compute right-hand-side terms, which are added to buffers | 34 +// compute right-hand-side terms, which are added to buffers int compute_rhs_t ( const domain_t * domain, fluid_t * fluid @@ -298,9 +173,6 @@ int compute_rhs_t ( } const double * restrict ux = fluid->ux.data; const double * restrict uy = fluid->uy.data; -#if NDIMS == 3 - const double * restrict uz = fluid->uz.data; -#endif const double * restrict t = fluid-> t.data; // buffer for explicit terms double * restrict srca = fluid->srct[rk_a].data; @@ -310,15 +182,9 @@ int compute_rhs_t ( // advective contributions, always explicit advection_x(domain, t, ux, srca); advection_y(domain, t, uy, srca); -#if NDIMS == 3 - advection_z(domain, t, uz, srca); -#endif // diffusive contributions, can be explicit or implicit diffusion_x(domain, diffusivity, t, param_t_implicit_x ? srcg : srca); diffusion_y(domain, diffusivity, t, param_t_implicit_y ? srcg : srca); -#if NDIMS == 3 - diffusion_z(domain, diffusivity, t, param_t_implicit_z ? srcg : srca); -#endif return 0; } @@ -338,22 +204,16 @@ int update_t ( const bool implicit[NDIMS] = { param_t_implicit_x, param_t_implicit_y, -#if NDIMS == 3 - param_t_implicit_z, -#endif }; const size_t glsizes[NDIMS] = { domain->glsizes[0], domain->glsizes[1], -#if NDIMS == 3 - domain->glsizes[2], -#endif }; if (0 != linear_system_init(domain->info, implicit, glsizes, &linear_system)) { return 1; } } - // compute increments | 28 + // compute increments { // Runge-Kutta coefficients, alpha, beta, gamma const double coef_a = rkcoefs[rkstep][rk_a]; @@ -365,15 +225,8 @@ int update_t ( const double * restrict srctg = fluid->srct[rk_g].data; const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif double * restrict dtemp = linear_system.x1pncl; -#if NDIMS == 2 const size_t nitems = isize * jsize; -#else - const size_t nitems = isize * jsize * ksize; -#endif // compute T(new) - T(old) for (size_t n = 0; n < nitems; n++) { dtemp[n] = @@ -386,7 +239,7 @@ int update_t ( { const double prefactor = 0.5 * rkcoefs[rkstep][rk_g] * dt * fluid_compute_temperature_diffusivity(fluid); - // solve linear systems in x | 20 + // solve linear systems in x if (param_t_implicit_x) { // prepare tri-diagonal coefficients tdm_info_t * tdm_info = linear_system.tdm_x; @@ -407,7 +260,7 @@ int update_t ( // solve all tdm.solve(tdm_info, linear_system.x1pncl); } - // solve linear systems in y | 32 + // solve linear systems in y if (param_t_implicit_y) { // make all y data accessible sdecomp.transpose.execute( @@ -440,57 +293,15 @@ int update_t ( linear_system.x1pncl ); } -#if NDIMS == 3 - // solve linear systems in z | 32 - if (param_t_implicit_z) { - // make all z data accessible - sdecomp.transpose.execute( - linear_system.transposer_x1_to_z2, - linear_system.x1pncl, - linear_system.z2pncl - ); - // prepare tri-diagonal coefficients - tdm_info_t * tdm_info = linear_system.tdm_z; - int size = 0; - double * restrict tdm_l = NULL; - double * restrict tdm_c = NULL; - double * restrict tdm_u = NULL; - tdm.get_size(tdm_info, &size); - tdm.get_l(tdm_info, &tdm_l); - tdm.get_c(tdm_info, &tdm_c); - tdm.get_u(tdm_info, &tdm_u); - const laplacian_t * lapz = &laplacians.lapz; - for (int k = 0; k < size; k++) { - tdm_l[k] = - prefactor * (*lapz).l; - tdm_c[k] = 1. - prefactor * (*lapz).c; - tdm_u[k] = - prefactor * (*lapz).u; - } - // solve all - tdm.solve(tdm_info, linear_system.z2pncl); - // recover original memory alignment - sdecomp.transpose.execute( - linear_system.transposer_z2_to_x1, - linear_system.z2pncl, - linear_system.x1pncl - ); - } -#endif } - // update temperature field | 19 + // update temperature field { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict dtemp = linear_system.x1pncl; double * restrict t = fluid->t.data; BEGIN -#if NDIMS == 2 T(i, j) += dtemp[cnt]; -#else - T(i, j, k) += dtemp[cnt]; -#endif END if (0 != fluid_update_boundaries_t(domain, &fluid->t)) { return 1; diff --git a/src/fluid/predict/ux.c b/src/fluid/predict/ux.c index c5509f34..d53394a7 100644 --- a/src/fluid/predict/ux.c +++ b/src/fluid/predict/ux.c @@ -13,9 +13,6 @@ #include "array_macros/domain/jdxc.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "array_macros/fluid/p.h" #include "array_macros/fluid/t.h" @@ -29,7 +26,7 @@ static laplacians_t laplacians = { static int init_laplacians ( const domain_t * domain ) { - // vector laplacian in x | 15 + // vector laplacian in x { const int isize = domain->glsizes[0]; const double * hxxc = domain->hxxc; @@ -45,7 +42,7 @@ static int init_laplacians ( laplacians.LAPX(i).u = u; } } - // vector laplacian in y | 9 + // vector laplacian in y { const double hy = domain->hy; const double l = 1. / hy / hy; @@ -55,41 +52,18 @@ static int init_laplacians ( laplacians.lapy.c = c; laplacians.lapy.u = u; } -#if NDIMS == 3 - // vector laplacian in z | 9 - { - const double hz = domain->hz; - const double l = 1. / hz / hz; - const double u = 1. / hz / hz; - const double c = - l - u; - laplacians.lapz.l = l; - laplacians.lapz.c = c; - laplacians.lapz.u = u; - } -#endif laplacians.is_initialised = true; return 0; } -#if NDIMS == 2 #define BEGIN \ for (int cnt = 0, j = 1; j <= jsize; j++) { \ for (int i = 2; i <= isize; i++, cnt++) { #define END \ } \ } -#else -#define BEGIN \ - for (int cnt = 0, k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 2; i <= isize; i++, cnt++) { -#define END \ - } \ - } \ - } -#endif -// advected in x | 47 +// advected in x static int advection_x ( const domain_t * domain, const double * restrict ux, @@ -97,9 +71,6 @@ static int advection_x ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; BEGIN @@ -109,36 +80,23 @@ static int advection_x ( const double jd_xm = JDXF(i-1); const double jd_x0 = JDXF(i ); const double jd_xp = JDXF(i+1); -#if NDIMS == 2 const double ux_xm = + 0.5 * jd_xm / hx_xm * UX(i-1, j ) + 0.5 * jd_x0 / hx_x0 * UX(i , j ); const double ux_xp = + 0.5 * jd_x0 / hx_x0 * UX(i , j ) + 0.5 * jd_xp / hx_xp * UX(i+1, j ); -#else - const double ux_xm = + 0.5 * jd_xm / hx_xm * UX(i-1, j , k ) - + 0.5 * jd_x0 / hx_x0 * UX(i , j , k ); - const double ux_xp = + 0.5 * jd_x0 / hx_x0 * UX(i , j , k ) - + 0.5 * jd_xp / hx_xp * UX(i+1, j , k ); -#endif const double l = - 0.5 * ux_xm; const double u = + 0.5 * ux_xp; const double c = - l - u; src[cnt] -= 1. / jd_x0 * ( -#if NDIMS == 2 + l * UX(i-1, j ) + c * UX(i , j ) + u * UX(i+1, j ) -#else - + l * UX(i-1, j , k ) - + c * UX(i , j , k ) - + u * UX(i+1, j , k ) -#endif ); END return 0; } -// advected in y | 46 +// advected in y static int advection_y ( const domain_t * domain, const double * restrict ux, @@ -147,9 +105,6 @@ static int advection_y ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; const double * restrict jdxf = domain->jdxf; const double * restrict jdxc = domain->jdxc; @@ -157,71 +112,23 @@ static int advection_y ( const double jd_xm = JDXC(i-1); const double jd_x0 = JDXF(i ); const double jd_xp = JDXC(i ); -#if NDIMS == 2 const double uy_ym = + 0.5 * jd_xm / hy * UY(i-1, j ) + 0.5 * jd_xp / hy * UY(i , j ); const double uy_yp = + 0.5 * jd_xm / hy * UY(i-1, j+1) + 0.5 * jd_xp / hy * UY(i , j+1); -#else - const double uy_ym = + 0.5 * jd_xm / hy * UY(i-1, j , k ) - + 0.5 * jd_xp / hy * UY(i , j , k ); - const double uy_yp = + 0.5 * jd_xm / hy * UY(i-1, j+1, k ) - + 0.5 * jd_xp / hy * UY(i , j+1, k ); -#endif const double l = - 0.5 * uy_ym; const double u = + 0.5 * uy_yp; const double c = - l - u; src[cnt] -= 1. / jd_x0 * ( -#if NDIMS == 2 + l * UX(i , j-1) + c * UX(i , j ) + u * UX(i , j+1) -#else - + l * UX(i , j-1, k ) - + c * UX(i , j , k ) - + u * UX(i , j+1, k ) -#endif - ); - END - return 0; -} - -#if NDIMS == 3 -// advected in z | 31 -static int advection_z ( - const domain_t * domain, - const double * restrict ux, - const double * restrict uz, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict jdxf = domain->jdxf; - const double * restrict jdxc = domain->jdxc; - BEGIN - const double jd_xm = JDXC(i-1); - const double jd_x0 = JDXF(i ); - const double jd_xp = JDXC(i ); - const double uz_zm = + 0.5 * jd_xm / hz * UZ(i-1, j , k ) - + 0.5 * jd_xp / hz * UZ(i , j , k ); - const double uz_zp = + 0.5 * jd_xm / hz * UZ(i-1, j , k+1) - + 0.5 * jd_xp / hz * UZ(i , j , k+1); - const double l = - 0.5 * uz_zm; - const double u = + 0.5 * uz_zp; - const double c = - l - u; - src[cnt] -= 1. / jd_x0 * ( - + l * UX(i , j , k-1) - + c * UX(i , j , k ) - + u * UX(i , j , k+1) ); END return 0; } -#endif -// pressure gradient effect | 24 +// pressure gradient effect static int pressure ( const domain_t * domain, const double * restrict p, @@ -229,25 +136,17 @@ static int pressure ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; BEGIN src[cnt] -= 1. / HXXF(i ) * ( -#if NDIMS == 2 - P(i-1, j ) + P(i , j ) -#else - - P(i-1, j , k ) - + P(i , j , k ) -#endif ); END return 0; } -// diffused in x | 27 +// diffused in x static int diffusion_x ( const domain_t * domain, const double diffusivity, @@ -256,27 +155,18 @@ static int diffusion_x ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const laplacian_t * lapx = laplacians.lapx; BEGIN src[cnt] += diffusivity * ( -#if NDIMS == 2 + LAPX(i).l * UX(i-1, j ) + LAPX(i).c * UX(i , j ) + LAPX(i).u * UX(i+1, j ) -#else - + LAPX(i).l * UX(i-1, j , k ) - + LAPX(i).c * UX(i , j , k ) - + LAPX(i).u * UX(i+1, j , k ) -#endif ); END return 0; } -// diffused in y | 27 +// diffused in y static int diffusion_y ( const domain_t * domain, const double diffusivity, @@ -285,50 +175,18 @@ static int diffusion_y ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const laplacian_t * lapy = &laplacians.lapy; BEGIN src[cnt] += diffusivity * ( -#if NDIMS == 2 + (*lapy).l * UX(i , j-1) + (*lapy).c * UX(i , j ) + (*lapy).u * UX(i , j+1) -#else - + (*lapy).l * UX(i , j-1, k ) - + (*lapy).c * UX(i , j , k ) - + (*lapy).u * UX(i , j+1, k ) -#endif ); END return 0; } -#if NDIMS == 3 -// diffused in z | 19 -static int diffusion_z ( - const domain_t * domain, - const double diffusivity, - const double * restrict ux, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const laplacian_t * lapz = &laplacians.lapz; - BEGIN - src[cnt] += diffusivity * ( - + (*lapz).l * UX(i , j , k-1) - + (*lapz).c * UX(i , j , k ) - + (*lapz).u * UX(i , j , k+1) - ); - END - return 0; -} -#endif - -// buoyancy effect | 29 +// buoyancy effect static int buoyancy ( const domain_t * domain, const double * restrict t, @@ -340,26 +198,15 @@ static int buoyancy ( } const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif -#if NDIMS == 2 BEGIN src[cnt] += + 0.5 * T(i-1, j ) + 0.5 * T(i , j ); END -#else - BEGIN - src[cnt] += - + 0.5 * T(i-1, j , k ) - + 0.5 * T(i , j , k ); - END -#endif return 0; } -// compute right-hand-side terms, which are added to buffers | 39 +// compute right-hand-side terms, which are added to buffers int compute_rhs_ux ( const domain_t * domain, fluid_t * fluid @@ -371,9 +218,6 @@ int compute_rhs_ux ( } const double * restrict ux = fluid->ux.data; const double * restrict uy = fluid->uy.data; -#if NDIMS == 3 - const double * restrict uz = fluid->uz.data; -#endif const double * restrict p = fluid-> p.data; const double * restrict t = fluid-> t.data; // buffer for explicit terms @@ -384,17 +228,11 @@ int compute_rhs_ux ( // advective contributions, always explicit advection_x(domain, ux, srca); advection_y(domain, ux, uy, srca); -#if NDIMS == 3 - advection_z(domain, ux, uz, srca); -#endif // pressure-gradient contribution, always implicit pressure(domain, p, srcg); // diffusive contributions, can be explicit or implicit diffusion_x(domain, diffusivity, ux, param_m_implicit_x ? srcg : srca); diffusion_y(domain, diffusivity, ux, param_m_implicit_y ? srcg : srca); -#if NDIMS == 3 - diffusion_z(domain, diffusivity, ux, param_m_implicit_z ? srcg : srca); -#endif // buoyancy contribution, always explicit buoyancy(domain, t, srca); return 0; @@ -416,22 +254,16 @@ int update_ux ( const bool implicit[NDIMS] = { param_m_implicit_x, param_m_implicit_y, -#if NDIMS == 3 - param_m_implicit_z, -#endif }; const size_t glsizes[NDIMS] = { domain->glsizes[0] - 1, domain->glsizes[1], -#if NDIMS == 3 - domain->glsizes[2], -#endif }; if (0 != linear_system_init(domain->info, implicit, glsizes, &linear_system)) { return 1; } } - // compute increments | 25 + // compute increments { const double coef_a = rkcoefs[rkstep][rk_a]; const double coef_b = rkcoefs[rkstep][rk_b]; @@ -441,15 +273,8 @@ int update_ux ( const double * restrict srcuxg = fluid->srcux[rk_g].data; const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif double * restrict dux = linear_system.x1pncl; -#if NDIMS == 2 const size_t nitems = (isize - 1) * jsize; -#else - const size_t nitems = (isize - 1) * jsize * ksize; -#endif for (size_t n = 0; n < nitems; n++) { dux[n] = + coef_a * dt * srcuxa[n] @@ -461,7 +286,7 @@ int update_ux ( { const double prefactor = 0.5 * rkcoefs[rkstep][rk_g] * dt * fluid_compute_momentum_diffusivity(fluid); - // solve linear systems in x | 18 + // solve linear systems in x if (param_m_implicit_x) { tdm_info_t * tdm_info = linear_system.tdm_x; int size = 0; @@ -480,7 +305,7 @@ int update_ux ( } tdm.solve(tdm_info, linear_system.x1pncl); } - // solve linear systems in y | 28 + // solve linear systems in y if (param_m_implicit_y) { sdecomp.transpose.execute( linear_system.transposer_x1_to_y1, @@ -509,53 +334,15 @@ int update_ux ( linear_system.x1pncl ); } -#if NDIMS == 3 - // solve linear systems in z | 28 - if (param_m_implicit_z) { - sdecomp.transpose.execute( - linear_system.transposer_x1_to_z2, - linear_system.x1pncl, - linear_system.z2pncl - ); - tdm_info_t * tdm_info = linear_system.tdm_z; - int size = 0; - double * restrict tdm_l = NULL; - double * restrict tdm_c = NULL; - double * restrict tdm_u = NULL; - tdm.get_size(tdm_info, &size); - tdm.get_l(tdm_info, &tdm_l); - tdm.get_c(tdm_info, &tdm_c); - tdm.get_u(tdm_info, &tdm_u); - const laplacian_t * lapz = &laplacians.lapz; - for (int k = 0; k < size; k++) { - tdm_l[k] = - prefactor * (*lapz).l; - tdm_c[k] = 1. - prefactor * (*lapz).c; - tdm_u[k] = - prefactor * (*lapz).u; - } - tdm.solve(tdm_info, linear_system.z2pncl); - sdecomp.transpose.execute( - linear_system.transposer_z2_to_x1, - linear_system.z2pncl, - linear_system.x1pncl - ); - } -#endif } - // update velocity field | 19 + // update velocity field { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict dux = linear_system.x1pncl; double * restrict ux = fluid->ux.data; BEGIN -#if NDIMS == 2 UX(i, j) += dux[cnt]; -#else - UX(i, j, k) += dux[cnt]; -#endif END if (0 != fluid_update_boundaries_ux(domain, &fluid->ux)) { return 1; diff --git a/src/fluid/predict/uy.c b/src/fluid/predict/uy.c index 25b160b3..cb5a1be2 100644 --- a/src/fluid/predict/uy.c +++ b/src/fluid/predict/uy.c @@ -13,9 +13,6 @@ #include "array_macros/domain/jdxc.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "array_macros/fluid/p.h" static laplacians_t laplacians = { @@ -28,7 +25,7 @@ static laplacians_t laplacians = { static int init_laplacians( const domain_t * domain ) { - // vector laplacian in x | 15 + // vector laplacian in x { const int isize = domain->glsizes[0]; const double * hxxf = domain->hxxf; @@ -44,7 +41,7 @@ static int init_laplacians( laplacians.LAPX(i).u = u; } } - // vector laplacian in y | 9 + // vector laplacian in y { const double hy = domain->hy; const double l = 1. / hy / hy; @@ -54,41 +51,18 @@ static int init_laplacians( laplacians.lapy.c = c; laplacians.lapy.u = u; } -#if NDIMS == 3 - // vector laplacian in z | 9 - { - const double hz = domain->hz; - const double l = 1. / hz / hz; - const double u = 1. / hz / hz; - const double c = - l - u; - laplacians.lapz.l = l; - laplacians.lapz.c = c; - laplacians.lapz.u = u; - } -#endif laplacians.is_initialised = true; return 0; } -#if NDIMS == 2 #define BEGIN \ for (int cnt = 0, j = 1; j <= jsize; j++) { \ for (int i = 1; i <= isize; i++, cnt++) { #define END \ } \ } -#else -#define BEGIN \ - for (int cnt = 0, k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 1; i <= isize; i++, cnt++) { -#define END \ - } \ - } \ - } -#endif -// advected in x | 48 +// advected in x static int advection_x ( const domain_t * domain, const double * restrict uy, @@ -97,9 +71,6 @@ static int advection_x ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; const double * restrict jdxc = domain->jdxc; @@ -109,36 +80,23 @@ static int advection_x ( const double jd_xm = JDXF(i ); const double jd_x0 = JDXC(i ); const double jd_xp = JDXF(i+1); -#if NDIMS == 2 const double ux_xm = + 0.5 * jd_xm / hx_xm * UX(i , j-1) + 0.5 * jd_xm / hx_xm * UX(i , j ); const double ux_xp = + 0.5 * jd_xp / hx_xp * UX(i+1, j-1) + 0.5 * jd_xp / hx_xp * UX(i+1, j ); -#else - const double ux_xm = + 0.5 * jd_xm / hx_xm * UX(i , j-1, k ) - + 0.5 * jd_xm / hx_xm * UX(i , j , k ); - const double ux_xp = + 0.5 * jd_xp / hx_xp * UX(i+1, j-1, k ) - + 0.5 * jd_xp / hx_xp * UX(i+1, j , k ); -#endif const double l = - 0.5 * ux_xm; const double u = + 0.5 * ux_xp; const double c = - l - u; src[cnt] -= 1. / jd_x0 * ( -#if NDIMS == 2 + l * UY(i-1, j ) + c * UY(i , j ) + u * UY(i+1, j ) -#else - + l * UY(i-1, j , k ) - + c * UY(i , j , k ) - + u * UY(i+1, j , k ) -#endif ); END return 0; } -// advected in y | 42 +// advected in y static int advection_y ( const domain_t * domain, const double * restrict uy, @@ -146,75 +104,27 @@ static int advection_y ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; const double * restrict jdxc = domain->jdxc; BEGIN const double jd = JDXC(i ); -#if NDIMS == 2 const double uy_ym = + 0.5 * jd / hy * UY(i , j-1) + 0.5 * jd / hy * UY(i , j ); const double uy_yp = + 0.5 * jd / hy * UY(i , j ) + 0.5 * jd / hy * UY(i , j+1); -#else - const double uy_ym = + 0.5 * jd / hy * UY(i , j-1, k ) - + 0.5 * jd / hy * UY(i , j , k ); - const double uy_yp = + 0.5 * jd / hy * UY(i , j , k ) - + 0.5 * jd / hy * UY(i , j+1, k ); -#endif const double l = - 0.5 * uy_ym; const double u = + 0.5 * uy_yp; const double c = - l - u; src[cnt] -= 1. / jd * ( -#if NDIMS == 2 + l * UY(i , j-1) + c * UY(i , j ) + u * UY(i , j+1) -#else - + l * UY(i , j-1, k ) - + c * UY(i , j , k ) - + u * UY(i , j+1, k ) -#endif ); END return 0; } -#if NDIMS == 3 -// advected in z | 28 -static int advection_z ( - const domain_t * domain, - const double * restrict uy, - const double * restrict uz, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict jdxc = domain->jdxc; - BEGIN - const double jd = JDXC(i ); - const double uz_zm = + 0.5 * jd / hz * UZ(i , j-1, k ) - + 0.5 * jd / hz * UZ(i , j , k ); - const double uz_zp = + 0.5 * jd / hz * UZ(i , j-1, k+1) - + 0.5 * jd / hz * UZ(i , j , k+1); - const double l = - 0.5 * uz_zm; - const double u = + 0.5 * uz_zp; - const double c = - l - u; - src[cnt] -= 1. / jd * ( - + l * UY(i , j , k-1) - + c * UY(i , j , k ) - + u * UY(i , j , k+1) - ); - END - return 0; -} -#endif - -// pressure gradient effect | 24 +// pressure gradient effect static int pressure ( const domain_t * domain, const double * restrict p, @@ -222,25 +132,17 @@ static int pressure ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; BEGIN src[cnt] -= 1. / hy * ( -#if NDIMS == 2 - P(i , j-1) + P(i , j ) -#else - - P(i , j-1, k ) - + P(i , j , k ) -#endif ); END return 0; } -// diffused in x | 27 +// diffused in x static int diffusion_x ( const domain_t * domain, const double diffusivity, @@ -249,27 +151,18 @@ static int diffusion_x ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const laplacian_t * lapx = laplacians.lapx; BEGIN src[cnt] += diffusivity * ( -#if NDIMS == 2 + LAPX(i).l * UY(i-1, j ) + LAPX(i).c * UY(i , j ) + LAPX(i).u * UY(i+1, j ) -#else - + LAPX(i).l * UY(i-1, j , k ) - + LAPX(i).c * UY(i , j , k ) - + LAPX(i).u * UY(i+1, j , k ) -#endif ); END return 0; } -// diffused in y | 27 +// diffused in y static int diffusion_y ( const domain_t * domain, const double diffusivity, @@ -278,50 +171,18 @@ static int diffusion_y ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const laplacian_t * lapy = &laplacians.lapy; BEGIN src[cnt] += diffusivity * ( -#if NDIMS == 2 + (*lapy).l * UY(i , j-1) + (*lapy).c * UY(i , j ) + (*lapy).u * UY(i , j+1) -#else - + (*lapy).l * UY(i , j-1, k ) - + (*lapy).c * UY(i , j , k ) - + (*lapy).u * UY(i , j+1, k ) -#endif ); END return 0; } -#if NDIMS == 3 -// diffused in z | 19 -static int diffusion_z ( - const domain_t * domain, - const double diffusivity, - const double * restrict uy, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const laplacian_t * lapz = &laplacians.lapz; - BEGIN - src[cnt] += diffusivity * ( - + (*lapz).l * UY(i , j , k-1) - + (*lapz).c * UY(i , j , k ) - + (*lapz).u * UY(i , j , k+1) - ); - END - return 0; -} -#endif - -// compute right-hand-side terms, which are added to buffers | 36 +// compute right-hand-side terms, which are added to buffers int compute_rhs_uy( const domain_t * domain, fluid_t * fluid @@ -333,9 +194,6 @@ int compute_rhs_uy( } const double * restrict ux = fluid->ux.data; const double * restrict uy = fluid->uy.data; -#if NDIMS == 3 - const double * restrict uz = fluid->uz.data; -#endif const double * restrict p = fluid-> p.data; // buffer for explicit terms double * restrict srca = fluid->srcuy[rk_a].data; @@ -345,17 +203,11 @@ int compute_rhs_uy( // advective contributions, always explicit advection_x(domain, uy, ux, srca); advection_y(domain, uy, srca); -#if NDIMS == 3 - advection_z(domain, uy, uz, srca); -#endif // pressure-gradient contribution, always implicit pressure(domain, p, srcg); // diffusive contributions, can be explicit or implicit diffusion_x(domain, diffusivity, uy, param_m_implicit_x ? srcg : srca); diffusion_y(domain, diffusivity, uy, param_m_implicit_y ? srcg : srca); -#if NDIMS == 3 - diffusion_z(domain, diffusivity, uy, param_m_implicit_z ? srcg : srca); -#endif return 0; } @@ -375,22 +227,16 @@ int update_uy( const bool implicit[NDIMS] = { param_m_implicit_x, param_m_implicit_y, -#if NDIMS == 3 - param_m_implicit_z, -#endif }; const size_t glsizes[NDIMS] = { domain->glsizes[0], domain->glsizes[1], -#if NDIMS == 3 - domain->glsizes[2], -#endif }; if (0 != linear_system_init(domain->info, implicit, glsizes, &linear_system)) { return 1; } } - // compute increments | 25 + // compute increments { const double coef_a = rkcoefs[rkstep][rk_a]; const double coef_b = rkcoefs[rkstep][rk_b]; @@ -400,15 +246,8 @@ int update_uy( const double * restrict srcuyg = fluid->srcuy[rk_g].data; const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif double * restrict duy = linear_system.x1pncl; -#if NDIMS == 2 const size_t nitems = isize * jsize; -#else - const size_t nitems = isize * jsize * ksize; -#endif for (size_t n = 0; n < nitems; n++) { duy[n] = + coef_a * dt * srcuya[n] @@ -420,7 +259,7 @@ int update_uy( { const double prefactor = 0.5 * rkcoefs[rkstep][rk_g] * dt * fluid_compute_momentum_diffusivity(fluid); - // solve linear systems in x | 18 + // solve linear systems in x if (param_m_implicit_x) { tdm_info_t * tdm_info = linear_system.tdm_x; int size = 0; @@ -439,7 +278,7 @@ int update_uy( } tdm.solve(tdm_info, linear_system.x1pncl); } - // solve linear systems in y | 28 + // solve linear systems in y if (param_m_implicit_y) { sdecomp.transpose.execute( linear_system.transposer_x1_to_y1, @@ -468,53 +307,15 @@ int update_uy( linear_system.x1pncl ); } -#if NDIMS == 3 - // solve linear systems in z | 28 - if (param_m_implicit_z) { - sdecomp.transpose.execute( - linear_system.transposer_x1_to_z2, - linear_system.x1pncl, - linear_system.z2pncl - ); - tdm_info_t * tdm_info = linear_system.tdm_z; - int size = 0; - double * restrict tdm_l = NULL; - double * restrict tdm_c = NULL; - double * restrict tdm_u = NULL; - tdm.get_size(tdm_info, &size); - tdm.get_l(tdm_info, &tdm_l); - tdm.get_c(tdm_info, &tdm_c); - tdm.get_u(tdm_info, &tdm_u); - const laplacian_t * lapz = &laplacians.lapz; - for (int k = 0; k < size; k++) { - tdm_l[k] = - prefactor * (*lapz).l; - tdm_c[k] = 1. - prefactor * (*lapz).c; - tdm_u[k] = - prefactor * (*lapz).u; - } - tdm.solve(tdm_info, linear_system.z2pncl); - sdecomp.transpose.execute( - linear_system.transposer_z2_to_x1, - linear_system.z2pncl, - linear_system.x1pncl - ); - } -#endif } - // update velocity field | 19 + // update velocity field { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict duy = linear_system.x1pncl; double * restrict uy = fluid->uy.data; BEGIN -#if NDIMS == 2 UY(i, j) += duy[cnt]; -#else - UY(i, j, k) += duy[cnt]; -#endif END if (0 != fluid_update_boundaries_uy(domain, &fluid->uy)) { return 1; diff --git a/src/fluid/predict/uz.c b/src/fluid/predict/uz.c deleted file mode 100644 index 42ac9c9a..00000000 --- a/src/fluid/predict/uz.c +++ /dev/null @@ -1,431 +0,0 @@ -#if NDIMS == 3 -#include "param.h" -#include "memory.h" -#include "runge_kutta.h" -#include "linear_system.h" -#include "tdm.h" -#include "domain.h" -#include "fluid.h" -#include "fluid_solver.h" -#include "internal.h" -#include "array_macros/domain/hxxf.h" -#include "array_macros/domain/jdxf.h" -#include "array_macros/domain/jdxc.h" -#include "array_macros/fluid/ux.h" -#include "array_macros/fluid/uy.h" -#include "array_macros/fluid/uz.h" -#include "array_macros/fluid/p.h" - -static laplacians_t laplacians = { - .is_initialised = false, -}; - -// map [1 : isize] in code to [0 : isize - 1] in memory -#define LAPX(I) lapx[(I) - 1] - -static int init_laplacians ( - const domain_t * domain -) { - // vector laplacian in x | 15 - { - const int isize = domain->glsizes[0]; - const double * hxxf = domain->hxxf; - const double * jdxf = domain->jdxf; - const double * jdxc = domain->jdxc; - laplacians.lapx = memory_calloc(isize, sizeof(laplacian_t)); - for (int i = 1; i <= isize; i++) { - const double l = 1. / JDXC(i ) * JDXF(i ) / HXXF(i ) / HXXF(i ); - const double u = 1. / JDXC(i ) * JDXF(i+1) / HXXF(i+1) / HXXF(i+1); - const double c = - l - u; - laplacians.LAPX(i).l = l; - laplacians.LAPX(i).c = c; - laplacians.LAPX(i).u = u; - } - } - // vector laplacian in y | 9 - { - const double hy = domain->hy; - const double l = 1. / hy / hy; - const double u = 1. / hy / hy; - const double c = - l - u; - laplacians.lapy.l = l; - laplacians.lapy.c = c; - laplacians.lapy.u = u; - } - // vector laplacian in z | 9 - { - const double hz = domain->hz; - const double l = 1. / hz / hz; - const double u = 1. / hz / hz; - const double c = - l - u; - laplacians.lapz.l = l; - laplacians.lapz.c = c; - laplacians.lapz.u = u; - } - laplacians.is_initialised = true; - return 0; -} - -#define BEGIN \ - for (int cnt = 0, k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 1; i <= isize; i++, cnt++) { -#define END \ - } \ - } \ - } - -// advected in x | 33 -static int advection_x ( - const domain_t * domain, - const double * restrict uz, - const double * restrict ux, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double * restrict hxxf = domain->hxxf; - const double * restrict jdxf = domain->jdxf; - const double * restrict jdxc = domain->jdxc; - BEGIN - const double hx_xm = HXXF(i ); - const double hx_xp = HXXF(i+1); - const double jd_xm = JDXF(i ); - const double jd_x0 = JDXC(i ); - const double jd_xp = JDXF(i+1); - const double ux_xm = + 0.5 * jd_xm / hx_xm * UX(i , j , k-1) - + 0.5 * jd_xm / hx_xm * UX(i , j , k ); - const double ux_xp = + 0.5 * jd_xp / hx_xp * UX(i+1, j , k-1) - + 0.5 * jd_xp / hx_xp * UX(i+1, j , k ); - const double l = - 0.5 * ux_xm; - const double u = + 0.5 * ux_xp; - const double c = - l - u; - src[cnt] -= 1. / jd_x0 * ( - + l * UZ(i-1, j , k ) - + c * UZ(i , j , k ) - + u * UZ(i+1, j , k ) - ); - END - return 0; -} - -// advected in y | 28 -static int advection_y ( - const domain_t * domain, - const double * restrict uz, - const double * restrict uy, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hy = domain->hy; - const double * restrict jdxc = domain->jdxc; - BEGIN - const double jd = JDXC(i ); - const double uy_ym = + 0.5 * jd / hy * UY(i , j , k-1) - + 0.5 * jd / hy * UY(i , j , k ); - const double uy_yp = + 0.5 * jd / hy * UY(i , j+1, k-1) - + 0.5 * jd / hy * UY(i , j+1, k ); - const double l = - 0.5 * uy_ym; - const double u = + 0.5 * uy_yp; - const double c = - l - u; - src[cnt] -= 1. / jd * ( - + l * UZ(i , j-1, k ) - + c * UZ(i , j , k ) - + u * UZ(i , j+1, k ) - ); - END - return 0; -} - -// advected in z | 27 -static int advection_z ( - const domain_t * domain, - const double * restrict uz, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict jdxc = domain->jdxc; - BEGIN - const double jd = JDXC(i ); - const double uz_zm = + 0.5 * jd / hz * UZ(i , j , k-1) - + 0.5 * jd / hz * UZ(i , j , k ); - const double uz_zp = + 0.5 * jd / hz * UZ(i , j , k ) - + 0.5 * jd / hz * UZ(i , j , k+1); - const double l = - 0.5 * uz_zm; - const double u = + 0.5 * uz_zp; - const double c = - l - u; - src[cnt] -= 1. / jd * ( - + l * UZ(i , j , k-1) - + c * UZ(i , j , k ) - + u * UZ(i , j , k+1) - ); - END - return 0; -} - -// pressure gradient effect | 17 -static int pressure ( - const domain_t * domain, - const double * restrict p, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - BEGIN - src[cnt] -= 1. / hz * ( - - P(i , j , k-1) - + P(i , j , k ) - ); - END - return 0; -} - -// diffused in x | 19 -static int diffusion_x ( - const domain_t * domain, - const double diffusivity, - const double * restrict uz, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const laplacian_t * lapx = laplacians.lapx; - BEGIN - src[cnt] += diffusivity * ( - + LAPX(i).l * UZ(i-1, j , k ) - + LAPX(i).c * UZ(i , j , k ) - + LAPX(i).u * UZ(i+1, j , k ) - ); - END - return 0; -} - -// diffused in y | 19 -static int diffusion_y ( - const domain_t * domain, - const double diffusivity, - const double * restrict uz, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const laplacian_t * lapy = &laplacians.lapy; - BEGIN - src[cnt] += diffusivity * ( - + (*lapy).l * UZ(i , j-1, k ) - + (*lapy).c * UZ(i , j , k ) - + (*lapy).u * UZ(i , j+1, k ) - ); - END - return 0; -} - -// diffused in z | 19 -static int diffusion_z ( - const domain_t * domain, - const double diffusivity, - const double * restrict uz, - double * restrict src -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const laplacian_t * lapz = &laplacians.lapz; - BEGIN - src[cnt] += diffusivity * ( - + (*lapz).l * UZ(i , j , k-1) - + (*lapz).c * UZ(i , j , k ) - + (*lapz).u * UZ(i , j , k+1) - ); - END - return 0; -} - -// compute right-hand-side terms, which are added to buffers | 30 -int compute_rhs_uz ( - const domain_t * domain, - fluid_t * fluid -) { - if (!laplacians.is_initialised) { - if (0 != init_laplacians(domain)) { - return 1; - } - } - const double * restrict ux = fluid->ux.data; - const double * restrict uy = fluid->uy.data; - const double * restrict uz = fluid->uz.data; - const double * restrict p = fluid-> p.data; - // buffer for explicit terms - double * restrict srca = fluid->srcuz[rk_a].data; - // buffer for implicit terms - double * restrict srcg = fluid->srcuz[rk_g].data; - const double diffusivity = fluid_compute_momentum_diffusivity(fluid); - // advective contributions, always explicit - advection_x(domain, uz, ux, srca); - advection_y(domain, uz, uy, srca); - advection_z(domain, uz, srca); - // pressure-gradient contribution, always implicit - pressure(domain, p, srcg); - // diffusive contributions, can be explicit or implicit - diffusion_x(domain, diffusivity, uz, param_m_implicit_x ? srcg : srca); - diffusion_y(domain, diffusivity, uz, param_m_implicit_y ? srcg : srca); - diffusion_z(domain, diffusivity, uz, param_m_implicit_z ? srcg : srca); - return 0; -} - -// update z velocity field -int update_uz ( - const domain_t * domain, - const size_t rkstep, - const double dt, - fluid_t * fluid -) { - static linear_system_t linear_system = { - .is_initialised = false, - }; - if (!linear_system.is_initialised) { - // if not initialised yet, prepare linear solver - // for implicit diffusive term treatment - const bool implicit[NDIMS] = { - param_m_implicit_x, - param_m_implicit_y, - param_m_implicit_z, - }; - const size_t glsizes[NDIMS] = { - domain->glsizes[0], - domain->glsizes[1], - domain->glsizes[2], - }; - if (0 != linear_system_init(domain->info, implicit, glsizes, &linear_system)) { - return 1; - } - } - // compute increments | 19 - { - const double coef_a = rkcoefs[rkstep][rk_a]; - const double coef_b = rkcoefs[rkstep][rk_b]; - const double coef_g = rkcoefs[rkstep][rk_g]; - const double * restrict srcuza = fluid->srcuz[rk_a].data; - const double * restrict srcuzb = fluid->srcuz[rk_b].data; - const double * restrict srcuzg = fluid->srcuz[rk_g].data; - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - double * restrict duz = linear_system.x1pncl; - const size_t nitems = isize * jsize * ksize; - for (size_t n = 0; n < nitems; n++) { - duz[n] = - + coef_a * dt * srcuza[n] - + coef_b * dt * srcuzb[n] - + coef_g * dt * srcuzg[n]; - } - } - // solve linear systems if necessary - { - const double prefactor = - 0.5 * rkcoefs[rkstep][rk_g] * dt * fluid_compute_momentum_diffusivity(fluid); - // solve linear systems in x | 18 - if (param_m_implicit_x) { - tdm_info_t * tdm_info = linear_system.tdm_x; - int size = 0; - double * restrict tdm_l = NULL; - double * restrict tdm_c = NULL; - double * restrict tdm_u = NULL; - tdm.get_size(tdm_info, &size); - tdm.get_l(tdm_info, &tdm_l); - tdm.get_c(tdm_info, &tdm_c); - tdm.get_u(tdm_info, &tdm_u); - const laplacian_t * lapx = laplacians.lapx; - for (int i = 0; i < size; i++) { - tdm_l[i] = - prefactor * lapx[i].l; - tdm_c[i] = 1. - prefactor * lapx[i].c; - tdm_u[i] = - prefactor * lapx[i].u; - } - tdm.solve(tdm_info, linear_system.x1pncl); - } - // solve linear systems in y | 28 - if (param_m_implicit_y) { - sdecomp.transpose.execute( - linear_system.transposer_x1_to_y1, - linear_system.x1pncl, - linear_system.y1pncl - ); - tdm_info_t * tdm_info = linear_system.tdm_y; - int size = 0; - double * restrict tdm_l = NULL; - double * restrict tdm_c = NULL; - double * restrict tdm_u = NULL; - tdm.get_size(tdm_info, &size); - tdm.get_l(tdm_info, &tdm_l); - tdm.get_c(tdm_info, &tdm_c); - tdm.get_u(tdm_info, &tdm_u); - const laplacian_t * lapy = &laplacians.lapy; - for (int j = 0; j < size; j++) { - tdm_l[j] = - prefactor * (*lapy).l; - tdm_c[j] = 1. - prefactor * (*lapy).c; - tdm_u[j] = - prefactor * (*lapy).u; - } - tdm.solve(tdm_info, linear_system.y1pncl); - sdecomp.transpose.execute( - linear_system.transposer_y1_to_x1, - linear_system.y1pncl, - linear_system.x1pncl - ); - } - // solve linear systems in z | 28 - if (param_m_implicit_z) { - sdecomp.transpose.execute( - linear_system.transposer_x1_to_z2, - linear_system.x1pncl, - linear_system.z2pncl - ); - tdm_info_t * tdm_info = linear_system.tdm_z; - int size = 0; - double * restrict tdm_l = NULL; - double * restrict tdm_c = NULL; - double * restrict tdm_u = NULL; - tdm.get_size(tdm_info, &size); - tdm.get_l(tdm_info, &tdm_l); - tdm.get_c(tdm_info, &tdm_c); - tdm.get_u(tdm_info, &tdm_u); - const laplacian_t * lapz = &laplacians.lapz; - for (int k = 0; k < size; k++) { - tdm_l[k] = - prefactor * (*lapz).l; - tdm_c[k] = 1. - prefactor * (*lapz).c; - tdm_u[k] = - prefactor * (*lapz).u; - } - tdm.solve(tdm_info, linear_system.z2pncl); - sdecomp.transpose.execute( - linear_system.transposer_z2_to_x1, - linear_system.z2pncl, - linear_system.x1pncl - ); - } - } - // update velocity field | 13 - { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double * restrict duz = linear_system.x1pncl; - double * restrict uz = fluid->uz.data; - BEGIN - UZ(i, j, k) += duz[cnt]; - END - if (0 != fluid_update_boundaries_uz(domain, &fluid->uz)) { - return 1; - } - } - return 0; -} -#endif diff --git a/src/fluid/save.c b/src/fluid/save.c index b320d727..981c91f9 100644 --- a/src/fluid/save.c +++ b/src/fluid/save.c @@ -21,9 +21,6 @@ int fluid_save( // collective array.dump(domain, dirname, "ux", fileio.npy_double, &fluid->ux); array.dump(domain, dirname, "uy", fileio.npy_double, &fluid->uy); -#if NDIMS == 3 - array.dump(domain, dirname, "uz", fileio.npy_double, &fluid->uz); -#endif array.dump(domain, dirname, "p", fileio.npy_double, &fluid-> p); array.dump(domain, dirname, "t", fileio.npy_double, &fluid-> t); return 0; diff --git a/src/fluid/update_pressure.c b/src/fluid/update_pressure.c index f1dc74c4..41c65d93 100644 --- a/src/fluid/update_pressure.c +++ b/src/fluid/update_pressure.c @@ -9,47 +9,29 @@ #include "array_macros/fluid/p.h" #include "array_macros/fluid/psi.h" -#if NDIMS == 2 #define BEGIN \ for (int j = 1; j <= jsize; j++) { \ for (int i = 1; i <= isize; i++) { #define END \ } \ } -#else -#define BEGIN \ - for (int k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 1; i <= isize; i++) { -#define END \ - } \ - } \ - } -#endif -// explicit contribution | 20 +// explicit contribution static int explicit_contribution ( const domain_t * domain, const fluid_t * fluid ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict psi = fluid->psi.data; double * restrict p = fluid->p.data; BEGIN -#if NDIMS == 2 P(i, j) += PSI(i, j); -#else - P(i, j, k) += PSI(i, j, k); -#endif END return 0; } -// x implicit contribution | 43 +// x implicit contribution static int implicit_x_contribution ( const domain_t * domain, const double prefactor, @@ -57,9 +39,6 @@ static int implicit_x_contribution ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; const double * restrict jdxc = domain->jdxc; @@ -74,17 +53,10 @@ static int implicit_x_contribution ( const double l = 1. / jd_x0 * jd_xm / hx_xm / hx_xm; const double u = 1. / jd_x0 * jd_xp / hx_xp / hx_xp; const double c = - l - u; -#if NDIMS == 2 const double psi_xm = PSI(i-1, j ); const double psi_x0 = PSI(i , j ); const double psi_xp = PSI(i+1, j ); double * pre = &P(i, j); -#else - const double psi_xm = PSI(i-1, j , k ); - const double psi_x0 = PSI(i , j , k ); - const double psi_xp = PSI(i+1, j , k ); - double * pre = &P(i, j, k); -#endif *pre -= prefactor * ( + l * psi_xm + c * psi_x0 @@ -94,7 +66,7 @@ static int implicit_x_contribution ( return 0; } -// y implicit contribution | 36 +// y implicit contribution static int implicit_y_contribution ( const domain_t * domain, const double prefactor, @@ -102,9 +74,6 @@ static int implicit_y_contribution ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; const double * restrict psi = fluid->psi.data; double * restrict p = fluid->p.data; @@ -112,17 +81,10 @@ static int implicit_y_contribution ( const double l = 1. / hy / hy; const double u = 1. / hy / hy; const double c = - l - u; -#if NDIMS == 2 const double psi_ym = PSI(i , j-1); const double psi_y0 = PSI(i , j ); const double psi_yp = PSI(i , j+1); double * pre = &P(i, j); -#else - const double psi_ym = PSI(i , j-1, k ); - const double psi_y0 = PSI(i , j , k ); - const double psi_yp = PSI(i , j+1, k ); - double * pre = &P(i, j, k); -#endif *pre -= prefactor * ( + l * psi_ym + c * psi_y0 @@ -132,37 +94,7 @@ static int implicit_y_contribution ( return 0; } -#if NDIMS == 3 -// z implicit contribution | 26 -static int implicit_z_contribution ( - const domain_t * domain, - const double prefactor, - fluid_t * fluid -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict psi = fluid->psi.data; - double * restrict p = fluid->p.data; - BEGIN - const double l = 1. / hz / hz; - const double u = 1. / hz / hz; - const double c = - l - u; - const double psi_zm = PSI(i , j , k-1); - const double psi_z0 = PSI(i , j , k ); - const double psi_zp = PSI(i , j , k+1); - P(i, j, k) -= prefactor * ( - + l * psi_zm - + c * psi_z0 - + u * psi_zp - ); - END - return 0; -} -#endif - -// update pressure field using scalar potential | 28 +// update pressure field using scalar potential int fluid_update_pressure ( const domain_t * domain, const size_t rkstep, @@ -180,11 +112,6 @@ int fluid_update_pressure ( if (param_m_implicit_y) { implicit_y_contribution(domain, prefactor, fluid); } -#if NDIMS == 3 - if (param_m_implicit_z) { - implicit_z_contribution(domain, prefactor, fluid); - } -#endif // impose boundary conditions and communicate halo cells if (0 != fluid_update_boundaries_p(domain, &fluid->p)) { return 1; diff --git a/src/halo.c b/src/halo.c index a632577c..c7c43c13 100644 --- a/src/halo.c +++ b/src/halo.c @@ -30,9 +30,6 @@ int halo_communicate_in_y( // array size (with halo and boundary cells) const int isize_ = domain->mysizes[0] + array->nadds[0][0] + array->nadds[0][1]; const int jsize_ = domain->mysizes[1] + array->nadds[1][0] + array->nadds[1][1]; -#if NDIMS == 3 - const int ksize_ = domain->mysizes[2] + array->nadds[2][0] + array->nadds[2][1]; -#endif // number of halo cells // this function assumes same number of halo cells // in the negative / positive directions @@ -42,38 +39,21 @@ int halo_communicate_in_y( return 1; } const int nhalos_y = array->nadds[1][0]; - // define datatype in y | 18 + // define datatype in y if(dtype_default == *dtype){ -#if NDIMS == 2 MPI_Type_contiguous( isize_ * nhalos_y, *dtype, dtype ); -#else - MPI_Type_vector( - ksize_, - isize_ * nhalos_y, - isize_ * jsize_, - *dtype, - dtype - ); -#endif MPI_Type_commit(dtype); } // send to positive, receive from negative { -#if NDIMS == 2 const int sindices[NDIMS] = {0, jsize_ - 2 * nhalos_y}; const int rindices[NDIMS] = {0, 0 * nhalos_y}; const size_t soffset = sindices[0] + isize_ * sindices[1]; const size_t roffset = rindices[0] + isize_ * rindices[1]; -#else - const int sindices[NDIMS] = {0, jsize_ - 2 * nhalos_y, 0}; - const int rindices[NDIMS] = {0, 0 * nhalos_y, 0}; - const size_t soffset = sindices[0] + isize_ * (sindices[1] + jsize_ * sindices[2]); - const size_t roffset = rindices[0] + isize_ * (rindices[1] + jsize_ * rindices[2]); -#endif MPI_Sendrecv( (char *)array->data + array->size * soffset, nitems, *dtype, neighbours[1], tag, (char *)array->data + array->size * roffset, nitems, *dtype, neighbours[0], tag, @@ -82,17 +62,10 @@ int halo_communicate_in_y( } // send to negative, receive from positive { -#if NDIMS == 2 const int sindices[NDIMS] = {0, 1 * nhalos_y}; const int rindices[NDIMS] = {0, jsize_ - 1 * nhalos_y}; const size_t soffset = sindices[0] + isize_ * sindices[1]; const size_t roffset = rindices[0] + isize_ * rindices[1]; -#else - const int sindices[NDIMS] = {0, 1 * nhalos_y, 0}; - const int rindices[NDIMS] = {0, jsize_ - 1 * nhalos_y, 0}; - const size_t soffset = sindices[0] + isize_ * (sindices[1] + jsize_ * sindices[2]); - const size_t roffset = rindices[0] + isize_ * (rindices[1] + jsize_ * rindices[2]); -#endif MPI_Sendrecv( (char *)array->data + array->size * soffset, nitems, *dtype, neighbours[0], tag, (char *)array->data + array->size * roffset, nitems, *dtype, neighbours[1], tag, @@ -102,67 +75,3 @@ int halo_communicate_in_y( return 0; } -#if NDIMS == 3 -// communicate halo cells with the z-neighbour processes -// NOTE: send boundary cells for simplicity -int halo_communicate_in_z( - const domain_t * domain, - MPI_Datatype * dtype, - array_t * array -){ - // extract communicator - const sdecomp_info_t * info = domain->info; - MPI_Comm comm_cart = MPI_COMM_NULL; - sdecomp.get_comm_cart(info, &comm_cart); - // check negative / positive neighbour ranks - int neighbours[2] = {MPI_PROC_NULL, MPI_PROC_NULL}; - sdecomp.get_neighbours(info, SDECOMP_X1PENCIL, SDECOMP_ZDIR, neighbours); - // array size (with halo and boundary cells) - const int isize_ = domain->mysizes[0] + array->nadds[0][0] + array->nadds[0][1]; - const int jsize_ = domain->mysizes[1] + array->nadds[1][0] + array->nadds[1][1]; - const int ksize_ = domain->mysizes[2] + array->nadds[2][0] + array->nadds[2][1]; - // number of halo cells - // this function assumes same number of halo cells - // in the negative / positive directions - if(array->nadds[2][0] != array->nadds[2][1]){ - printf("%s: number of halo cells in z (%d and %d) mismatch\n", - __func__, array->nadds[2][0], array->nadds[2][1]); - return 1; - } - const int nhalos_z = array->nadds[2][0]; - // define datatype in z | 8 - if(dtype_default == *dtype){ - MPI_Type_contiguous( - isize_ * jsize_ * nhalos_z, - *dtype, - dtype - ); - MPI_Type_commit(dtype); - } - // send to positive, receive from negative - { - const int sindices[NDIMS] = {0, 0, ksize_ - 2 * nhalos_z}; - const int rindices[NDIMS] = {0, 0, 0 * nhalos_z}; - const size_t soffset = sindices[0] + isize_ * (sindices[1] + jsize_ * sindices[2]); - const size_t roffset = rindices[0] + isize_ * (rindices[1] + jsize_ * rindices[2]); - MPI_Sendrecv( - (char *)array->data + array->size * soffset, nitems, *dtype, neighbours[1], tag, - (char *)array->data + array->size * roffset, nitems, *dtype, neighbours[0], tag, - comm_cart, MPI_STATUS_IGNORE - ); - } - // send to negative, receive from positive - { - const int sindices[NDIMS] = {0, 0, 1 * nhalos_z}; - const int rindices[NDIMS] = {0, 0, ksize_ - 1 * nhalos_z}; - const size_t soffset = sindices[0] + isize_ * (sindices[1] + jsize_ * sindices[2]); - const size_t roffset = rindices[0] + isize_ * (rindices[1] + jsize_ * rindices[2]); - MPI_Sendrecv( - (char *)array->data + array->size * soffset, nitems, *dtype, neighbours[0], tag, - (char *)array->data + array->size * roffset, nitems, *dtype, neighbours[1], tag, - comm_cart, MPI_STATUS_IGNORE - ); - } - return 0; -} -#endif diff --git a/src/integrate.c b/src/integrate.c index b7779402..8acea628 100644 --- a/src/integrate.c +++ b/src/integrate.c @@ -18,24 +18,24 @@ int integrate( // Runge-Kutta iterations // max iteration, should be three for(size_t rkstep = 0; rkstep < RKSTEPMAX; rkstep++){ - // predict flow field | 5 + // predict flow field // NOTE: while the temperature is fully updated here, // the velocity field is still non-solenoidal if(0 != fluid_predict_field(domain, rkstep, *dt, fluid)){ return 1; } - // compute scalar potential | 6 + // compute scalar potential // now the temperature field has been updated, // while the velocity field is not divergence free // and thus the following correction step is needed if(0 != fluid_compute_potential(domain, rkstep, *dt, fluid)){ return 1; } - // correct velocity field to satisfy mass conservation | 3 + // correct velocity field to satisfy mass conservation if(0 != fluid_correct_velocity(domain, rkstep, *dt, fluid)){ return 1; } - // update pressure | 3 + // update pressure if(0 != fluid_update_pressure(domain, rkstep, *dt, fluid)){ return 1; } diff --git a/src/linear_system.c b/src/linear_system.c index dd81a606..011465e6 100644 --- a/src/linear_system.c +++ b/src/linear_system.c @@ -39,88 +39,47 @@ int linear_system_init( // pencils (and their sizes) to store input and output of linear systems double * restrict * x1pncl = &linear_system->x1pncl; double * restrict * y1pncl = &linear_system->y1pncl; -#if NDIMS == 3 - double * restrict * z2pncl = &linear_system->z2pncl; -#endif // check size first size_t * x1pncl_mysizes = linear_system->x1pncl_mysizes; size_t * y1pncl_mysizes = linear_system->y1pncl_mysizes; -#if NDIMS == 3 - size_t * z2pncl_mysizes = linear_system->z2pncl_mysizes; -#endif for(int dim = 0; dim < NDIMS; dim++){ if(0 != sdecomp.get_pencil_mysize(info, SDECOMP_X1PENCIL, dim, glsizes[dim], x1pncl_mysizes + dim)) return 1; if(0 != sdecomp.get_pencil_mysize(info, SDECOMP_Y1PENCIL, dim, glsizes[dim], y1pncl_mysizes + dim)) return 1; -#if NDIMS == 3 - if(0 != sdecomp.get_pencil_mysize(info, SDECOMP_Z2PENCIL, dim, glsizes[dim], z2pncl_mysizes + dim)) return 1; -#endif } - // allocate pencils if needed | 6 + // allocate pencils if needed // NOTE: x1pncl is not needed for fully-explicit case, // but I always allocate it here for simplicity (to store delta values) *x1pncl = memory_calloc(get_nitems(x1pncl_mysizes), sizeof(double)); *y1pncl = implicit[1] ? memory_calloc(get_nitems(y1pncl_mysizes), sizeof(double)) : NULL; -#if NDIMS == 3 - *z2pncl = implicit[2] ? memory_calloc(get_nitems(z2pncl_mysizes), sizeof(double)) : NULL; -#endif // initialise parallel matrix transpose if needed - // between x1 and y1 | 6 + // between x1 and y1 if(implicit[1]){ sdecomp_transpose_plan_t ** plan_f = &linear_system->transposer_x1_to_y1; sdecomp_transpose_plan_t ** plan_b = &linear_system->transposer_y1_to_x1; if(0 != sdecomp.transpose.construct(info, SDECOMP_X1PENCIL, SDECOMP_Y1PENCIL, glsizes, sizeof(double), plan_f)) return 1; if(0 != sdecomp.transpose.construct(info, SDECOMP_Y1PENCIL, SDECOMP_X1PENCIL, glsizes, sizeof(double), plan_b)) return 1; } -#if NDIMS == 3 - // between x1 and z2 | 6 - if(implicit[2]){ - sdecomp_transpose_plan_t ** plan_f = &linear_system->transposer_x1_to_z2; - sdecomp_transpose_plan_t ** plan_b = &linear_system->transposer_z2_to_x1; - if(0 != sdecomp.transpose.construct(info, SDECOMP_X1PENCIL, SDECOMP_Z2PENCIL, glsizes, sizeof(double), plan_f)) return 1; - if(0 != sdecomp.transpose.construct(info, SDECOMP_Z2PENCIL, SDECOMP_X1PENCIL, glsizes, sizeof(double), plan_b)) return 1; - } -#endif // initialise tri-diagonal matrix solvers - // Thomas algorithm in x direction | 13 + // Thomas algorithm in x direction if(implicit[0]){ if(0 != tdm.construct( /* size of system */ (int)(x1pncl_mysizes[0]), -#if NDIMS == 2 /* number of rhs */ (int)(x1pncl_mysizes[1]), -#else - /* number of rhs */ (int)(x1pncl_mysizes[1] * x1pncl_mysizes[2]), -#endif /* is periodic */ false, /* is complex */ false, /* output */ &linear_system->tdm_x )) return 1; } - // Thomas algorithm in y direction | 13 + // Thomas algorithm in y direction if(implicit[1]){ if(0 != tdm.construct( /* size of system */ (int)(y1pncl_mysizes[1]), -#if NDIMS == 2 /* number of rhs */ (int)(y1pncl_mysizes[0]), -#else - /* number of rhs */ (int)(y1pncl_mysizes[2] * y1pncl_mysizes[0]), -#endif /* is periodic */ true, /* is complex */ false, /* output */ &linear_system->tdm_y )) return 1; } -#if NDIMS == 3 - // Thomas algorithm in z direction | 9 - if(implicit[2]){ - if(0 != tdm.construct( - /* size of system */ (int)(z2pncl_mysizes[2]), - /* number of rhs */ (int)(z2pncl_mysizes[0] * z2pncl_mysizes[1]), - /* is periodic */ true, - /* is complex */ false, - /* output */ &linear_system->tdm_z - )) return 1; - } -#endif linear_system->is_initialised = true; return 0; } @@ -142,14 +101,6 @@ int linear_system_finalise( sdecomp.transpose.destruct(linear_system->transposer_y1_to_x1); tdm.destruct(linear_system->tdm_y); } -#if NDIMS == 3 - if(implicit[2]){ - memory_free(linear_system->z2pncl); - sdecomp.transpose.destruct(linear_system->transposer_x1_to_z2); - sdecomp.transpose.destruct(linear_system->transposer_z2_to_x1); - tdm.destruct(linear_system->tdm_z); - } -#endif return 0; } diff --git a/src/logging/dissipated_squared_temperature.c b/src/logging/dissipated_squared_temperature.c index a5a5d37d..32feff38 100644 --- a/src/logging/dissipated_squared_temperature.c +++ b/src/logging/dissipated_squared_temperature.c @@ -8,7 +8,7 @@ #include "array_macros/fluid/t.h" #include "internal.h" -// dtdx component | 41 +// dtdx component static int get_dtdx ( const domain_t * domain, const fluid_t * fluid, @@ -16,14 +16,10 @@ static int get_dtdx ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; const double * restrict t = fluid->t.data; const double diffusivity = fluid_compute_temperature_diffusivity(fluid); -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize + 1; i++) { const double hx = HXXF(i); @@ -34,24 +30,10 @@ static int get_dtdx ( *quantity += diffusivity * jd * pow(1. / hx * dt, 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize + 1; i++) { - const double hx = HXXF(i); - const double jd = JDXF(i); - const double dt = - - T(i-1, j , k ) - + T(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hx * dt, 2.); - } - } - } -#endif return 0; } -// dtdy component | 39 +// dtdy component static int get_dtdy ( const domain_t * domain, const fluid_t * fluid, @@ -59,14 +41,10 @@ static int get_dtdy ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; const double * restrict jdxc = domain->jdxc; const double * restrict t = fluid->t.data; const double diffusivity = fluid_compute_temperature_diffusivity(fluid); -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize; i++) { const double jd = JDXC(i); @@ -76,50 +54,8 @@ static int get_dtdy ( *quantity += diffusivity * jd * pow(1. / hy * dt, 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double jd = JDXC(i); - const double dt = - - T(i , j-1, k ) - + T(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hy * dt, 2.); - } - } - } -#endif - return 0; -} - -#if NDIMS == 3 -// dtdz component | 25 -static int get_dtdz ( - const domain_t * domain, - const fluid_t * fluid, - double * quantity -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict jdxc = domain->jdxc; - const double * restrict t = fluid->t.data; - const double diffusivity = fluid_compute_temperature_diffusivity(fluid); - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double jd = JDXC(i); - const double dt = - - T(i , j , k-1) - + T(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hz * dt, 2.); - } - } - } return 0; } -#endif /** * @brief compute dissipation of squared temperature @@ -143,9 +79,6 @@ int logging_check_dissipated_squared_temperature ( double quantity = 0.; get_dtdx(domain, fluid, &quantity); get_dtdy(domain, fluid, &quantity); -#if NDIMS == 3 - get_dtdz(domain, fluid, &quantity); -#endif const void * sendbuf = root == myrank ? MPI_IN_PLACE : &quantity; void * recvbuf = &quantity; MPI_Reduce(sendbuf, recvbuf, 1, MPI_DOUBLE, MPI_SUM, root, comm_cart); diff --git a/src/logging/dissipated_squared_velocity.c b/src/logging/dissipated_squared_velocity.c index be5c09f2..d0867ae9 100644 --- a/src/logging/dissipated_squared_velocity.c +++ b/src/logging/dissipated_squared_velocity.c @@ -8,12 +8,9 @@ #include "array_macros/domain/jdxc.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "internal.h" -// duxdx component | 42 +// duxdx component static int get_duxdx ( const domain_t * domain, const fluid_t * fluid, @@ -21,14 +18,10 @@ static int get_duxdx ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxc = domain->hxxc; const double * restrict jdxc = domain->jdxc; const double * restrict ux = fluid->ux.data; const double diffusivity = fluid_compute_momentum_diffusivity(fluid); -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize; i++) { const double hx = HXXC(i); @@ -39,24 +32,10 @@ static int get_duxdx ( *quantity += diffusivity * jd * pow(1. / hx * dux, 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double hx = HXXC(i); - const double jd = JDXC(i); - const double dux = - - UX(i , j , k ) - + UX(i+1, j , k ); - *quantity += diffusivity * jd * pow(1. / hx * dux, 2.); - } - } - } -#endif return 0; } -// duxdy component | 40 +// duxdy component static int get_duxdy ( const domain_t * domain, const fluid_t * fluid, @@ -64,14 +43,10 @@ static int get_duxdy ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; const double * restrict jdxf = domain->jdxf; const double * restrict ux = fluid->ux.data; const double diffusivity = fluid_compute_momentum_diffusivity(fluid); -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize + 1; i++) { const double jd = JDXF(i); @@ -81,52 +56,10 @@ static int get_duxdy ( *quantity += diffusivity * jd * pow(1. / hy * dux, 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize + 1; i++) { - const double jd = JDXF(i); - const double dux = - - UX(i , j-1, k ) - + UX(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hy * dux, 2.); - } - } - } -#endif - return 0; -} - -#if NDIMS == 3 -// duxdz component | 25 -static int get_duxdz ( - const domain_t * domain, - const fluid_t * fluid, - double * quantity -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict jdxf = domain->jdxf; - const double * restrict ux = fluid->ux.data; - const double diffusivity = fluid_compute_momentum_diffusivity(fluid); - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize + 1; i++) { - const double jd = JDXF(i); - const double dux = - - UX(i , j , k-1) - + UX(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hz * dux, 2.); - } - } - } return 0; } -#endif -// duydx component | 42 +// duydx component static int get_duydx ( const domain_t * domain, const fluid_t * fluid, @@ -134,14 +67,10 @@ static int get_duydx ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; const double * restrict uy = fluid->uy.data; const double diffusivity = fluid_compute_momentum_diffusivity(fluid); -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize + 1; i++) { const double hx = HXXF(i); @@ -152,24 +81,10 @@ static int get_duydx ( *quantity += diffusivity * jd * pow(1. / hx * duy, 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize + 1; i++) { - const double hx = HXXF(i); - const double jd = JDXF(i); - const double duy = - - UY(i-1, j , k ) - + UY(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hx * duy, 2.); - } - } - } -#endif return 0; } -// duydy component | 40 +// duydy component static int get_duydy ( const domain_t * domain, const fluid_t * fluid, @@ -177,14 +92,10 @@ static int get_duydy ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double hy = domain->hy; const double * restrict jdxc = domain->jdxc; const double * restrict uy = fluid->uy.data; const double diffusivity = fluid_compute_momentum_diffusivity(fluid); -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize; i++) { const double jd = JDXC(i); @@ -194,138 +105,8 @@ static int get_duydy ( *quantity += diffusivity * jd * pow(1. / hy * duy, 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double jd = JDXC(i); - const double duy = - - UY(i , j , k ) - + UY(i , j+1, k ); - *quantity += diffusivity * jd * pow(1. / hy * duy, 2.); - } - } - } -#endif - return 0; -} - -#if NDIMS == 3 -// duydz component | 25 -static int get_duydz ( - const domain_t * domain, - const fluid_t * fluid, - double * quantity -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict jdxc = domain->jdxc; - const double * restrict uy = fluid->uy.data; - const double diffusivity = fluid_compute_momentum_diffusivity(fluid); - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double jd = JDXC(i); - const double duy = - - UY(i , j , k-1) - + UY(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hz * duy, 2.); - } - } - } - return 0; -} -#endif - -#if NDIMS == 3 -// duzdx component | 26 -static int get_duzdx ( - const domain_t * domain, - const fluid_t * fluid, - double * quantity -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double * restrict hxxf = domain->hxxf; - const double * restrict jdxf = domain->jdxf; - const double * restrict uz = fluid->uz.data; - const double diffusivity = fluid_compute_momentum_diffusivity(fluid); - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize + 1; i++) { - const double hx = HXXF(i); - const double jd = JDXF(i); - const double duz = - - UZ(i-1, j , k ) - + UZ(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hx * duz, 2.); - } - } - } - return 0; -} -#endif - -#if NDIMS == 3 -// duzdy component | 25 -static int get_duzdy ( - const domain_t * domain, - const fluid_t * fluid, - double * quantity -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hy = domain->hy; - const double * restrict jdxc = domain->jdxc; - const double * restrict uz = fluid->uz.data; - const double diffusivity = fluid_compute_momentum_diffusivity(fluid); - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double jd = JDXC(i); - const double duz = - - UZ(i , j-1, k ) - + UZ(i , j , k ); - *quantity += diffusivity * jd * pow(1. / hy * duz, 2.); - } - } - } - return 0; -} -#endif - -#if NDIMS == 3 -// duzdz component | 25 -static int get_duzdz ( - const domain_t * domain, - const fluid_t * fluid, - double * quantity -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - const double hz = domain->hz; - const double * restrict jdxc = domain->jdxc; - const double * restrict uz = fluid->uz.data; - const double diffusivity = fluid_compute_momentum_diffusivity(fluid); - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - const double jd = JDXC(i); - const double duz = - - UZ(i , j , k ) - + UZ(i , j , k+1); - *quantity += diffusivity * jd * pow(1. / hz * duz, 2.); - } - } - } return 0; } -#endif /** * @brief compute dissipation of squared velocity @@ -349,19 +130,8 @@ int logging_check_dissipated_squared_velocity ( double quantity = 0.; get_duxdx(domain, fluid, &quantity); get_duxdy(domain, fluid, &quantity); -#if NDIMS == 3 - get_duxdz(domain, fluid, &quantity); -#endif get_duydx(domain, fluid, &quantity); get_duydy(domain, fluid, &quantity); -#if NDIMS == 3 - get_duydz(domain, fluid, &quantity); -#endif -#if NDIMS == 3 - get_duzdx(domain, fluid, &quantity); - get_duzdy(domain, fluid, &quantity); - get_duzdz(domain, fluid, &quantity); -#endif const void * sendbuf = root == myrank ? MPI_IN_PLACE : &quantity; void * recvbuf = &quantity; MPI_Reduce(sendbuf, recvbuf, 1, MPI_DOUBLE, MPI_SUM, root, comm_cart); diff --git a/src/logging/heat_transfer.c b/src/logging/heat_transfer.c index 750f069e..cd10ac06 100644 --- a/src/logging/heat_transfer.c +++ b/src/logging/heat_transfer.c @@ -6,19 +6,10 @@ #include "array_macros/fluid/t.h" #include "internal.h" -#if NDIMS == 2 #define BEGIN \ for (int j = 1; j <= jsize; j++) { #define END \ } -#else -#define BEGIN \ - for (int k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { -#define END \ - } \ - } -#endif /** * @brief compute net heat transfer on the walls @@ -41,13 +32,10 @@ int logging_check_heat_transfer ( sdecomp.get_comm_cart(domain->info, &comm_cart); const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; const double * restrict t = fluid->t.data; - // compute heat transfer on the walls | 22 + // compute heat transfer on the walls const double diffusivity = fluid_compute_temperature_diffusivity(fluid); // on the bottom and top walls double energies[2] = {0., 0.}; @@ -56,13 +44,8 @@ int logging_check_heat_transfer ( const double hx_xp = HXXF(isize + 1); const double jd_xm = JDXF( 1); const double jd_xp = JDXF(isize + 1); -#if NDIMS == 2 const double dt_xm = - T( 0, j) + T( 1, j); const double dt_xp = - T(isize, j) + T(isize + 1, j); -#else - const double dt_xm = - T( 0, j, k) + T( 1, j, k); - const double dt_xp = - T(isize, j, k) + T(isize + 1, j, k); -#endif energies[0] -= diffusivity * jd_xm / hx_xm / hx_xm * dt_xm; energies[1] -= diffusivity * jd_xp / hx_xp / hx_xp * dt_xp; END diff --git a/src/logging/injected_squared_velocity.c b/src/logging/injected_squared_velocity.c index f445879b..ab9f3676 100644 --- a/src/logging/injected_squared_velocity.c +++ b/src/logging/injected_squared_velocity.c @@ -5,23 +5,12 @@ #include "array_macros/fluid/t.h" #include "internal.h" -#if NDIMS == 2 #define BEGIN \ for (int j = 1; j <= jsize; j++) { \ for (int i = 2; i <= isize; i++) { #define END \ } \ } -#else -#define BEGIN \ - for (int k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 2; i <= isize; i++) { -#define END \ - } \ - } \ - } -#endif /** * @brief compute injected squared velocity @@ -44,27 +33,17 @@ int logging_check_injected_squared_velocity ( sdecomp.get_comm_cart(domain->info, &comm_cart); const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict jdxf = domain->jdxf; const double * restrict ux = fluid->ux.data; const double * restrict t = fluid-> t.data; - // compute injected squared velocity | 19 + // compute injected squared velocity double quantity = 0.; BEGIN const double jd_x0 = JDXF(i); -#if NDIMS == 2 const double ux_x0 = UX(i, j); const double t_x0 = + 0.5 * T(i-1, j ) + 0.5 * T(i , j ); -#else - const double ux_x0 = UX(i, j, k); - const double t_x0 = - + 0.5 * T(i-1, j , k ) - + 0.5 * T(i , j , k ); -#endif quantity += jd_x0 * ux_x0 * t_x0; END const void * sendbuf = root == myrank ? MPI_IN_PLACE : &quantity; diff --git a/src/logging/main.c b/src/logging/main.c index 1fd0bc50..87ca5b1c 100644 --- a/src/logging/main.c +++ b/src/logging/main.c @@ -62,7 +62,7 @@ static void show_progress ( if (root == myrank) { FILE * fp = fileio.fopen(fname, "a"); if (NULL != fp) { - // show progress to standard output and file | 8 + // show progress to standard output and file // output to stdout and file #define MPRINT(...) { \ fprintf(fp, __VA_ARGS__); \ diff --git a/src/logging/max_divergence.c b/src/logging/max_divergence.c index 9582b5ae..b7788d20 100644 --- a/src/logging/max_divergence.c +++ b/src/logging/max_divergence.c @@ -6,28 +6,14 @@ #include "array_macros/domain/jdxc.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "internal.h" -#if NDIMS == 2 #define BEGIN \ for (int cnt = 0, j = 1; j <= jsize; j++) { \ for (int i = 1; i <= isize; i++, cnt++) { #define END \ } \ } -#else -#define BEGIN \ - for (int cnt = 0, k = 1; k <= ksize; k++) { \ - for (int j = 1; j <= jsize; j++) { \ - for (int i = 1; i <= isize; i++, cnt++) { -#define END \ - } \ - } \ - } -#endif /** * @brief check maximum divergence and write it to a file @@ -50,22 +36,13 @@ int logging_check_max_divergence ( sdecomp.get_comm_cart(domain->info, &comm_cart); const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double hy = domain->hy; -#if NDIMS == 3 - const double hz = domain->hz; -#endif const double * restrict jdxf = domain->jdxf; const double * restrict jdxc = domain->jdxc; const double * restrict ux = fluid->ux.data; const double * restrict uy = fluid->uy.data; -#if NDIMS == 3 - const double * restrict uz = fluid->uz.data; -#endif - // check max local divergence | 30 + // check max local divergence double divmax = 0.; BEGIN const double hx_xm = HXXF(i ); @@ -73,25 +50,13 @@ int logging_check_max_divergence ( const double jd_xm = JDXF(i ); const double jd_x0 = JDXC(i ); const double jd_xp = JDXF(i+1); -#if NDIMS == 2 const double ux_xm = UX(i , j ); const double ux_xp = UX(i+1, j ); const double uy_ym = UY(i , j ); const double uy_yp = UY(i , j+1); -#else - const double ux_xm = UX(i , j , k ); - const double ux_xp = UX(i+1, j , k ); - const double uy_ym = UY(i , j , k ); - const double uy_yp = UY(i , j+1, k ); - const double uz_zm = UZ(i , j , k ); - const double uz_zp = UZ(i , j , k+1); -#endif const double div = 1. / jd_x0 * ( - jd_xm / hx_xm * ux_xm + jd_xp / hx_xp * ux_xp - jd_x0 / hy * uy_ym + jd_x0 / hy * uy_yp -#if NDIMS == 3 - - jd_x0 / hz * uz_zm + jd_x0 / hz * uz_zp -#endif ); // check maximum divmax = fmax(divmax, fabs(div)); diff --git a/src/logging/total_energy.c b/src/logging/total_energy.c index 089c85b0..1a000d10 100644 --- a/src/logging/total_energy.c +++ b/src/logging/total_energy.c @@ -5,9 +5,6 @@ #include "array_macros/domain/jdxc.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "array_macros/fluid/t.h" #include "internal.h" @@ -32,77 +29,31 @@ int logging_check_total_energy( sdecomp.get_comm_cart(domain->info, &comm_cart); const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict jdxf = domain->jdxf; const double * restrict jdxc = domain->jdxc; const double * restrict ux = fluid->ux.data; const double * restrict uy = fluid->uy.data; -#if NDIMS == 3 - const double * restrict uz = fluid->uz.data; -#endif const double * restrict t = fluid->t.data; // velocity for each dimension and scalar double quantities[NDIMS + 1] = {0.}; // compute quadratic quantity in x direction -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 2; i <= isize; i++) { quantities[0] += JDXF(i ) * 0.5 * pow(UX(i, j), 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 2; i <= isize; i++) { - quantities[0] += JDXF(i ) * 0.5 * pow(UX(i, j, k), 2.); - } - } - } -#endif // compute quadratic quantity in y direction -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize; i++) { quantities[1] += JDXC(i ) * 0.5 * pow(UY(i, j), 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - quantities[1] += JDXC(i ) * 0.5 * pow(UY(i, j, k), 2.); - } - } - } -#endif -#if NDIMS == 3 - // compute quadratic quantity in z direction - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - quantities[2] += JDXC(i ) * 0.5 * pow(UZ(i, j, k), 2.); - } - } - } -#endif // compute quadratic quantity of scalar -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize; i++) { quantities[NDIMS] += JDXC(i ) * 0.5 * pow(T(i, j), 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - quantities[NDIMS] += JDXC(i ) * 0.5 * pow(T(i, j, k), 2.); - } - } - } -#endif // output information const size_t nitems = sizeof(quantities) / sizeof(quantities[0]); const void * sendbuf = root == myrank ? MPI_IN_PLACE : quantities; diff --git a/src/logging/total_momentum.c b/src/logging/total_momentum.c index 06a81e66..4fa97fdb 100644 --- a/src/logging/total_momentum.c +++ b/src/logging/total_momentum.c @@ -4,9 +4,6 @@ #include "array_macros/domain/jdxc.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "internal.h" /** @@ -30,59 +27,23 @@ int logging_check_total_momentum ( sdecomp.get_comm_cart(domain->info, &comm_cart); const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict jdxf = domain->jdxf; const double * restrict jdxc = domain->jdxc; const double * restrict ux = fluid->ux.data; const double * restrict uy = fluid->uy.data; -#if NDIMS == 3 - const double * restrict uz = fluid->uz.data; -#endif double momenta[NDIMS] = {0.}; - // compute total x-momentum | 15 -#if NDIMS == 2 + // compute total x-momentum for (int j = 1; j <= jsize; j++) { for (int i = 2; i <= isize; i++) { momenta[0] += JDXF(i) * UX(i, j); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 2; i <= isize; i++) { - momenta[0] += JDXF(i) * UX(i, j, k); - } - } - } -#endif - // compute total y-momentum | 15 -#if NDIMS == 2 + // compute total y-momentum for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize; i++) { momenta[1] += JDXC(i) * UY(i, j); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - momenta[1] += JDXC(i) * UY(i, j, k); - } - } - } -#endif -#if NDIMS == 3 - // compute total z-momentum | 7 - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize; i++) { - momenta[2] += JDXC(i) * UZ(i, j, k); - } - } - } -#endif const size_t nitems = sizeof(momenta) / sizeof(momenta[0]); const void * sendbuf = root == myrank ? MPI_IN_PLACE : momenta; void * recvbuf = momenta; diff --git a/src/main.c b/src/main.c index 35717208..65c5ed94 100644 --- a/src/main.c +++ b/src/main.c @@ -23,13 +23,13 @@ int main ( int argc, char * argv[] ) { - // launch MPI, start timer | 5 + // launch MPI, start timer MPI_Init(NULL, NULL); const int root = 0; int myrank = root; MPI_Comm_rank(MPI_COMM_WORLD, &myrank); const double tic = timer(); - // find name of directory where IC is stored | 7 + // find name of directory where IC is stored if (2 != argc) { if (root == myrank) { printf("directory name should be given as input\n"); @@ -41,7 +41,7 @@ int main ( if (0 != fileio.init()) { goto abort; } - // initialise time step and time units | 8 + // initialise time step and time units size_t step = 0; if (0 != fileio.r_serial(dirname_ic, "step", 0, NULL, fileio.npy_size_t, sizeof(size_t), &step)) { goto abort; @@ -50,7 +50,7 @@ int main ( if (0 != fileio.r_serial(dirname_ic, "time", 0, NULL, fileio.npy_double, sizeof(double), &time)) { goto abort; } - // initialise structures | 8 + // initialise structures domain_t domain = {0}; if (0 != domain_init(dirname_ic, &domain)) { goto abort; @@ -59,7 +59,7 @@ int main ( if (0 != fluid_init(dirname_ic, &domain, &fluid)) { goto abort; } - // initialise auxiliary objects | 9 + // initialise auxiliary objects if (0 != logging.init(&domain, time)) { goto abort; } @@ -90,11 +90,11 @@ int main ( if (0 != integrate(&domain, &fluid, &dt)) { goto abort; } - // update step and simulation / wall time | 3 + // update step and simulation / wall time step += 1; time += dt; const double toc = timer(); - // terminate if one of the following conditions is met | 8 + // terminate if one of the following conditions is met // the simulation is finished if (timemax < time) { break; @@ -103,25 +103,25 @@ int main ( if (wtimemax < toc - tic) { break; } - // compute and output log regularly | 3 + // compute and output log regularly if (logging.get_next_time() < time) { logging.check_and_output(&domain, step, time, dt, toc - tic, &fluid); } - // save flow fields regularly | 3 + // save flow fields regularly if (save.get_next_time() < time) { save.output(&domain, step, time, &fluid); } - // collect statistics regularly | 3 + // collect statistics regularly if (statistics.get_next_time() < time) { statistics.collect(&domain, &fluid); } } // finalisation - // save final flow fields | 1 + // save final flow fields save.output(&domain, step, time, &fluid); - // save collected statistics | 1 + // save collected statistics statistics.output(&domain, step); - // finalise MPI | 2 + // finalise MPI abort: MPI_Finalize(); return 0; diff --git a/src/param/boundary-condition.c b/src/param/boundary-condition.c index 1ae4662f..030a7587 100644 --- a/src/param/boundary-condition.c +++ b/src/param/boundary-condition.c @@ -2,10 +2,6 @@ const double param_uy_xm = 0.; const double param_uy_xp = 0.; -#if NDIMS == 3 -const double param_uz_xm = 0.; -const double param_uz_xp = 0.; -#endif const double param_t_xm = + 0.5; const double param_t_xp = - 0.5; diff --git a/src/param/implicit.c b/src/param/implicit.c index 37f3def8..1907b943 100644 --- a/src/param/implicit.c +++ b/src/param/implicit.c @@ -2,13 +2,7 @@ const bool param_m_implicit_x = true; const bool param_m_implicit_y = false; -#if NDIMS == 3 -const bool param_m_implicit_z = false; -#endif const bool param_t_implicit_x = true; const bool param_t_implicit_y = false; -#if NDIMS == 3 -const bool param_t_implicit_z = false; -#endif diff --git a/src/runge_kutta.c b/src/runge_kutta.c index 512906cc..c649aaef 100644 --- a/src/runge_kutta.c +++ b/src/runge_kutta.c @@ -4,7 +4,7 @@ const uint_fast8_t rk_a = 0; const uint_fast8_t rk_b = 1; const uint_fast8_t rk_g = 2; -// coefficients of three-stage Runge-Kutta scheme | 8 +// coefficients of three-stage Runge-Kutta scheme static const double a0 = +32. / 60., b0 = 0. / 60.; static const double a1 = +25. / 60., b1 = -17. / 60.; static const double a2 = +45. / 60., b2 = -25. / 60.; diff --git a/src/statistics.c b/src/statistics.c index a0b39e8d..0b1e326c 100644 --- a/src/statistics.c +++ b/src/statistics.c @@ -14,18 +14,11 @@ #include "array_macros/domain/jdxf.h" #include "array_macros/fluid/ux.h" #include "array_macros/fluid/uy.h" -#if NDIMS == 3 -#include "array_macros/fluid/uz.h" -#endif #include "array_macros/fluid/t.h" #include "array_macros/statistics/ux1.h" #include "array_macros/statistics/ux2.h" #include "array_macros/statistics/uy1.h" #include "array_macros/statistics/uy2.h" -#if NDIMS == 3 -#include "array_macros/statistics/uz1.h" -#include "array_macros/statistics/uz2.h" -#endif #include "array_macros/statistics/t1.h" #include "array_macros/statistics/t2.h" #include "array_macros/statistics/adv.h" @@ -49,10 +42,6 @@ static array_t g_ux1 = {0}; static array_t g_ux2 = {0}; static array_t g_uy1 = {0}; static array_t g_uy2 = {0}; -#if NDIMS == 3 -static array_t g_uz1 = {0}; -static array_t g_uz2 = {0}; -#endif static array_t g_t1 = {0}; static array_t g_t2 = {0}; static array_t g_adv = {0}; @@ -89,10 +78,6 @@ static int init ( if (0 != array.create(domain, UX2_NADDS, sizeof(double), &g_ux2)) return 1; if (0 != array.create(domain, UY1_NADDS, sizeof(double), &g_uy1)) return 1; if (0 != array.create(domain, UY2_NADDS, sizeof(double), &g_uy2)) return 1; -#if NDIMS == 3 - if (0 != array.create(domain, UZ1_NADDS, sizeof(double), &g_uz1)) return 1; - if (0 != array.create(domain, UZ2_NADDS, sizeof(double), &g_uz2)) return 1; -#endif if (0 != array.create(domain, T1_NADDS, sizeof(double), &g_t1 )) return 1; if (0 != array.create(domain, T2_NADDS, sizeof(double), &g_t2 )) return 1; if (0 != array.create(domain, ADV_NADDS, sizeof(double), &g_adv)) return 1; @@ -124,28 +109,14 @@ static void collect_mean_ux ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif double * restrict ux1 = g_ux1.data; double * restrict ux2 = g_ux2.data; -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize + 1; i++) { UX1(i, j) += pow(UX(i, j), 1.); UX2(i, j) += pow(UX(i, j), 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize + 1; i++) { - UX1(i, j, k) += pow(UX(i, j, k), 1.); - UX2(i, j, k) += pow(UX(i, j, k), 2.); - } - } - } -#endif } static void collect_mean_uy ( @@ -154,50 +125,15 @@ static void collect_mean_uy ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif double * restrict uy1 = g_uy1.data; double * restrict uy2 = g_uy2.data; -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 0; i <= isize + 1; i++) { UY1(i, j) += pow(UY(i, j), 1.); UY2(i, j) += pow(UY(i, j), 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 0; i <= isize + 1; i++) { - UY1(i, j, k) += pow(UY(i, j, k), 1.); - UY2(i, j, k) += pow(UY(i, j, k), 2.); - } - } - } -#endif -} - -#if NDIMS == 3 -static void collect_mean_uz ( - const domain_t * domain, - const double * restrict uz -) { - const int isize = domain->mysizes[0]; - const int jsize = domain->mysizes[1]; - const int ksize = domain->mysizes[2]; - double * restrict uz1 = g_uz1.data; - double * restrict uz2 = g_uz2.data; - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 0; i <= isize + 1; i++) { - UZ1(i, j, k) += pow(UZ(i, j, k), 1.); - UZ2(i, j, k) += pow(UZ(i, j, k), 2.); - } - } - } } -#endif static void collect_mean_t ( const domain_t * domain, @@ -205,28 +141,14 @@ static void collect_mean_t ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif double * restrict t1 = g_t1.data; double * restrict t2 = g_t2.data; -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 0; i <= isize + 1; i++) { T1(i, j) += pow(T(i, j), 1.); T2(i, j) += pow(T(i, j), 2.); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 0; i <= isize + 1; i++) { - T1(i, j, k) += pow(T(i, j, k), 1.); - T2(i, j, k) += pow(T(i, j, k), 2.); - } - } - } -#endif } static void collect_adv ( @@ -236,27 +158,14 @@ static void collect_adv ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; double * restrict adv = g_adv.data; -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize + 1; i++) { ADV(i, j) += JDXF(i) / HXXF(i) * UX(i, j) * (0.5 * T(i-1, j ) + 0.5 * T(i , j )); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize + 1; i++) { - ADV(i, j, k) += JDXF(i) / HXXF(i) * UX(i, j, k) * (0.5 * T(i-1, j , k ) + 0.5 * T(i , j , k )); - } - } - } -#endif } static void collect_dif ( @@ -266,13 +175,9 @@ static void collect_dif ( ) { const int isize = domain->mysizes[0]; const int jsize = domain->mysizes[1]; -#if NDIMS == 3 - const int ksize = domain->mysizes[2]; -#endif const double * restrict hxxf = domain->hxxf; const double * restrict jdxf = domain->jdxf; double * restrict dif = g_dif.data; -#if NDIMS == 2 for (int j = 1; j <= jsize; j++) { for (int i = 1; i <= isize + 1; i++) { const double t_xm = T(i-1, j ); @@ -280,17 +185,6 @@ static void collect_dif ( DIF(i, j) -= diffusivity * JDXF(i) / HXXF(i) / HXXF(i) * (t_xp - t_xm); } } -#else - for (int k = 1; k <= ksize; k++) { - for (int j = 1; j <= jsize; j++) { - for (int i = 1; i <= isize + 1; i++) { - const double t_xm = T(i-1, j , k ); - const double t_xp = T(i , j , k ); - DIF(i, j, k) -= diffusivity * JDXF(i) / HXXF(i) / HXXF(i) * (t_xp - t_xm); - } - } - } -#endif } /** @@ -306,9 +200,6 @@ static int collect ( // collect temporally-averaged quantities collect_mean_ux(domain, fluid->ux.data); collect_mean_uy(domain, fluid->uy.data); -#if NDIMS == 3 - collect_mean_uz(domain, fluid->uz.data); -#endif collect_mean_t(domain, fluid->t.data); collect_adv(domain, fluid->ux.data, fluid->t.data); collect_dif(domain, fluid_compute_temperature_diffusivity(fluid), fluid->t.data); @@ -369,10 +260,6 @@ static int output( {.name = "ux2", .array = &g_ux2}, {.name = "uy1", .array = &g_uy1}, {.name = "uy2", .array = &g_uy2}, -#if NDIMS == 3 - {.name = "uz1", .array = &g_uz1}, - {.name = "uz2", .array = &g_uz2}, -#endif {.name = "t1", .array = &g_t1 }, {.name = "t2", .array = &g_t2 }, {.name = "adv", .array = &g_adv}, diff --git a/src/tdm.c b/src/tdm.c index 0d9a2b03..0635893c 100644 --- a/src/tdm.c +++ b/src/tdm.c @@ -111,7 +111,7 @@ GTSV(fftw_complex) TDM_SOLVE(double) TDM_SOLVE(fftw_complex) -// definition of tdm_info_t_ | 22 +// definition of tdm_info_t_ /** * @struct tdm_info_t_ * @brief struct to keep information about tri-diagonal system and internal buffers