diff --git a/src/add_backgroundgrid/add_bggrid.c b/src/add_backgroundgrid/add_bggrid.c index 22afa09091a98d89c415ce64d22200661ce52378..ea948801204ee3ce282131330e9eebc8d8813e7a 100644 --- a/src/add_backgroundgrid/add_bggrid.c +++ b/src/add_backgroundgrid/add_bggrid.c @@ -37,8 +37,8 @@ #include "../main/allvars.h" #include "../main/proto.h" -#include "add_bggrid.h" #include "../domain/domain.h" +#include "add_bggrid.h" #ifdef ADDBACKGROUNDGRID diff --git a/src/fof/fof.c b/src/fof/fof.c index b9b63177cd91c6272491aebc2683f7aaa76ab5cc..210f07f79c141a5e3196600bc192f5193d9e5b12 100644 --- a/src/fof/fof.c +++ b/src/fof/fof.c @@ -351,7 +351,7 @@ void fof_prepare_output_order(void) aux_sort[i].DM_BindingEnergy = PS[i].BindingEnergy; #endif /* #ifdef SUBFIND */ aux_sort[i].Type = P[i].Type; - aux_sort[i].ID = P[i].ID; + aux_sort[i].ID = P[i].ID; #if defined(RECOMPUTE_POTENTIAL_IN_SNAPSHOT) aux_sort[i].FileOrder = P[i].FileOrder; #endif /* #if defined(RECOMPUTE_POTENTIAL_IN_SNAPSHOT) */ diff --git a/src/gravity/pm/pm_mpi_fft.c b/src/gravity/pm/pm_mpi_fft.c index 7944d8719b2d761713e0126470d284920f2cc16e..866ef064595cebd0adf766ee11ad1f64533e257a 100644 --- a/src/gravity/pm/pm_mpi_fft.c +++ b/src/gravity/pm/pm_mpi_fft.c @@ -82,21 +82,17 @@ * - 26.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <math.h> #include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> - #include "../../main/allvars.h" #include "../../main/proto.h" - #if defined(PMGRID) - #ifndef FFT_COLUMN_BASED /*! \brief Initializes slab based FFT. * @@ -107,12 +103,12 @@ * * \return void */ -void my_slab_based_fft_init(fft_plan * plan, int NgridX, int NgridY, int NgridZ) +void my_slab_based_fft_init(fft_plan *plan, int NgridX, int NgridY, int NgridZ) { subdivide_evenly(NgridX, NTask, ThisTask, &plan->slabstart_x, &plan->nslab_x); subdivide_evenly(NgridY, NTask, ThisTask, &plan->slabstart_y, &plan->nslab_y); - plan->slab_to_task = (int *) mymalloc("slab_to_task", NgridX * sizeof(int)); + plan->slab_to_task = (int *)mymalloc("slab_to_task", NgridX * sizeof(int)); for(int task = 0; task < NTask; task++) { @@ -127,29 +123,28 @@ void my_slab_based_fft_init(fft_plan * plan, int NgridX, int NgridY, int NgridZ) MPI_Allreduce(&plan->nslab_x, &plan->largest_x_slab, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); MPI_Allreduce(&plan->nslab_y, &plan->largest_y_slab, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); - plan->slabs_x_per_task = (int *) mymalloc("slabs_x_per_task", NTask * sizeof(int)); + plan->slabs_x_per_task = (int *)mymalloc("slabs_x_per_task", NTask * sizeof(int)); MPI_Allgather(&plan->nslab_x, 1, MPI_INT, plan->slabs_x_per_task, 1, MPI_INT, MPI_COMM_WORLD); - plan->first_slab_x_of_task = (int *) mymalloc("first_slab_x_of_task", NTask * sizeof(int)); + plan->first_slab_x_of_task = (int *)mymalloc("first_slab_x_of_task", NTask * sizeof(int)); MPI_Allgather(&plan->slabstart_x, 1, MPI_INT, plan->first_slab_x_of_task, 1, MPI_INT, MPI_COMM_WORLD); - plan->slabs_y_per_task = (int *) mymalloc("slabs_y_per_task", NTask * sizeof(int)); + plan->slabs_y_per_task = (int *)mymalloc("slabs_y_per_task", NTask * sizeof(int)); MPI_Allgather(&plan->nslab_y, 1, MPI_INT, plan->slabs_y_per_task, 1, MPI_INT, MPI_COMM_WORLD); - plan->first_slab_y_of_task = (int *) mymalloc("first_slab_y_of_task", NTask * sizeof(int)); + plan->first_slab_y_of_task = (int *)mymalloc("first_slab_y_of_task", NTask * sizeof(int)); MPI_Allgather(&plan->slabstart_y, 1, MPI_INT, plan->first_slab_y_of_task, 1, MPI_INT, MPI_COMM_WORLD); plan->NgridX = NgridX; plan->NgridY = NgridY; plan->NgridZ = NgridZ; - int Ngridz = NgridZ / 2 + 1; /* dimension needed in complex space */ + int Ngridz = NgridZ / 2 + 1; /* dimension needed in complex space */ plan->Ngridz = Ngridz; plan->Ngrid2 = 2 * Ngridz; } - /*! \brief Transposes the array field. * * The array field is transposed such that the data in x direction is local @@ -164,7 +159,7 @@ void my_slab_based_fft_init(fft_plan * plan, int NgridX, int NgridY, int NgridZ) * * \return void */ -void my_slab_transposeA(fft_plan * plan, fft_real * field, fft_real * scratch) +void my_slab_transposeA(fft_plan *plan, fft_real *field, fft_real *scratch) { int n, prod, task, flag_big = 0, flag_big_all = 0; @@ -172,21 +167,21 @@ void my_slab_transposeA(fft_plan * plan, fft_real * field, fft_real * scratch) for(n = 0; n < prod; n++) { - int x = n / NTask; + int x = n / NTask; int task = n % NTask; int y; for(y = plan->first_slab_y_of_task[task]; y < plan->first_slab_y_of_task[task] + plan->slabs_y_per_task[task]; y++) - memcpy(scratch + ((size_t) plan->NgridZ) * (plan->first_slab_y_of_task[task] * plan->nslab_x - + x * plan->slabs_y_per_task[task] + (y - plan->first_slab_y_of_task[task])), - field + ((size_t) plan->Ngrid2) * (plan->NgridY * x + y), plan->NgridZ * sizeof(fft_real)); + memcpy(scratch + ((size_t)plan->NgridZ) * (plan->first_slab_y_of_task[task] * plan->nslab_x + + x * plan->slabs_y_per_task[task] + (y - plan->first_slab_y_of_task[task])), + field + ((size_t)plan->Ngrid2) * (plan->NgridY * x + y), plan->NgridZ * sizeof(fft_real)); } - size_t *scount = (size_t *) mymalloc("scount", NTask * sizeof(size_t)); - size_t *rcount = (size_t *) mymalloc("rcount", NTask * sizeof(size_t)); - size_t *soff = (size_t *) mymalloc("soff", NTask * sizeof(size_t)); - size_t *roff = (size_t *) mymalloc("roff", NTask * sizeof(size_t)); + size_t *scount = (size_t *)mymalloc("scount", NTask * sizeof(size_t)); + size_t *rcount = (size_t *)mymalloc("rcount", NTask * sizeof(size_t)); + size_t *soff = (size_t *)mymalloc("soff", NTask * sizeof(size_t)); + size_t *roff = (size_t *)mymalloc("roff", NTask * sizeof(size_t)); for(task = 0; task < NTask; task++) { @@ -210,7 +205,6 @@ void my_slab_transposeA(fft_plan * plan, fft_real * field, fft_real * scratch) myfree(scount); } - /*! \brief Undo the transposition of the array field. * * The transposition of the array field is undone such that the data in @@ -224,14 +218,14 @@ void my_slab_transposeA(fft_plan * plan, fft_real * field, fft_real * scratch) * * \return void */ -void my_slab_transposeB(fft_plan * plan, fft_real * field, fft_real * scratch) +void my_slab_transposeB(fft_plan *plan, fft_real *field, fft_real *scratch) { int n, prod, task, flag_big = 0, flag_big_all = 0; - size_t *scount = (size_t *) mymalloc("scount", NTask * sizeof(size_t)); - size_t *rcount = (size_t *) mymalloc("rcount", NTask * sizeof(size_t)); - size_t *soff = (size_t *) mymalloc("soff", NTask * sizeof(size_t)); - size_t *roff = (size_t *) mymalloc("roff", NTask * sizeof(size_t)); + size_t *scount = (size_t *)mymalloc("scount", NTask * sizeof(size_t)); + size_t *rcount = (size_t *)mymalloc("rcount", NTask * sizeof(size_t)); + size_t *soff = (size_t *)mymalloc("soff", NTask * sizeof(size_t)); + size_t *roff = (size_t *)mymalloc("roff", NTask * sizeof(size_t)); for(task = 0; task < NTask; task++) { @@ -258,18 +252,18 @@ void my_slab_transposeB(fft_plan * plan, fft_real * field, fft_real * scratch) for(n = 0; n < prod; n++) { - int x = n / NTask; + int x = n / NTask; int task = n % NTask; int y; for(y = plan->first_slab_y_of_task[task]; y < plan->first_slab_y_of_task[task] + plan->slabs_y_per_task[task]; y++) - memcpy(field + ((size_t) plan->Ngrid2) * (plan->NgridY * x + y), - scratch + ((size_t) plan->NgridZ) * (plan->first_slab_y_of_task[task] * plan->nslab_x + x * plan->slabs_y_per_task[task] + (y - plan->first_slab_y_of_task[task])), + memcpy(field + ((size_t)plan->Ngrid2) * (plan->NgridY * x + y), + scratch + ((size_t)plan->NgridZ) * (plan->first_slab_y_of_task[task] * plan->nslab_x + + x * plan->slabs_y_per_task[task] + (y - plan->first_slab_y_of_task[task])), plan->NgridZ * sizeof(fft_real)); } } - /* \brief Transpose a slab decomposed 3D field. * * Given a slab-decomposed 3D field a[...] with total dimension @@ -299,21 +293,21 @@ void my_slab_transposeB(fft_plan * plan, fft_real * field, fft_real * scratch) */ static void my_slab_transpose(void *av, void *bv, int *sx, int *firstx, int *sy, int *firsty, int nx, int ny, int nz, int mode) { - char *a = (char *) av; - char *b = (char *) bv; + char *a = (char *)av; + char *b = (char *)bv; - size_t *scount = (size_t *) mymalloc("scount", NTask * sizeof(size_t)); - size_t *rcount = (size_t *) mymalloc("rcount", NTask * sizeof(size_t)); - size_t *soff = (size_t *) mymalloc("soff", NTask * sizeof(size_t)); - size_t *roff = (size_t *) mymalloc("roff", NTask * sizeof(size_t)); + size_t *scount = (size_t *)mymalloc("scount", NTask * sizeof(size_t)); + size_t *rcount = (size_t *)mymalloc("rcount", NTask * sizeof(size_t)); + size_t *soff = (size_t *)mymalloc("soff", NTask * sizeof(size_t)); + size_t *roff = (size_t *)mymalloc("roff", NTask * sizeof(size_t)); int i, n, prod, flag_big = 0, flag_big_all = 0; for(i = 0; i < NTask; i++) { - scount[i] = sy[i] * sx[ThisTask] * ((size_t) nz); - rcount[i] = sy[ThisTask] * sx[i] * ((size_t) nz); - soff[i] = firsty[i] * sx[ThisTask] * ((size_t) nz); - roff[i] = sy[ThisTask] * firstx[i] * ((size_t) nz); + scount[i] = sy[i] * sx[ThisTask] * ((size_t)nz); + rcount[i] = sy[ThisTask] * sx[i] * ((size_t)nz); + soff[i] = firsty[i] * sx[ThisTask] * ((size_t)nz); + roff[i] = sy[ThisTask] * firstx[i] * ((size_t)nz); if(scount[i] * sizeof(fft_complex) > MPI_MESSAGE_SIZELIMIT_IN_BYTES) flag_big = 1; @@ -335,7 +329,8 @@ static void my_slab_transpose(void *av, void *bv, int *sx, int *firstx, int *sy, int j; for(j = 0; j < sy[i]; j++) - memcpy(b + (k * sy[i] + j + firsty[i] * sx[ThisTask]) * (nz * sizeof(fft_complex)), a + (k * ny + (firsty[i] + j)) * (nz * sizeof(fft_complex)), nz * sizeof(fft_complex)); + memcpy(b + (k * sy[i] + j + firsty[i] * sx[ThisTask]) * (nz * sizeof(fft_complex)), + a + (k * ny + (firsty[i] + j)) * (nz * sizeof(fft_complex)), nz * sizeof(fft_complex)); } /* tranfer the data */ @@ -350,7 +345,8 @@ static void my_slab_transpose(void *av, void *bv, int *sx, int *firstx, int *sy, int k; for(k = 0; k < sx[i]; k++) - memcpy(b + (j * nx + k + firstx[i]) * (nz * sizeof(fft_complex)), a + ((k + firstx[i]) * sy[ThisTask] + j) * (nz * sizeof(fft_complex)), nz * sizeof(fft_complex)); + memcpy(b + (j * nx + k + firstx[i]) * (nz * sizeof(fft_complex)), + a + ((k + firstx[i]) * sy[ThisTask] + j) * (nz * sizeof(fft_complex)), nz * sizeof(fft_complex)); } } else @@ -364,7 +360,8 @@ static void my_slab_transpose(void *av, void *bv, int *sx, int *firstx, int *sy, int k; for(k = 0; k < sx[i]; k++) - memcpy(b + ((k + firstx[i]) * sy[ThisTask] + j) * (nz * sizeof(fft_complex)), a + (j * nx + k + firstx[i]) * (nz * sizeof(fft_complex)), nz * sizeof(fft_complex)); + memcpy(b + ((k + firstx[i]) * sy[ThisTask] + j) * (nz * sizeof(fft_complex)), + a + (j * nx + k + firstx[i]) * (nz * sizeof(fft_complex)), nz * sizeof(fft_complex)); } /* tranfer the data */ @@ -379,7 +376,8 @@ static void my_slab_transpose(void *av, void *bv, int *sx, int *firstx, int *sy, int j; for(j = 0; j < sy[i]; j++) - memcpy(b + (k * ny + (firsty[i] + j)) * (nz * sizeof(fft_complex)), a + (k * sy[i] + j + firsty[i] * sx[ThisTask]) * (nz * sizeof(fft_complex)), nz * sizeof(fft_complex)); + memcpy(b + (k * ny + (firsty[i] + j)) * (nz * sizeof(fft_complex)), + a + (k * sy[i] + j + firsty[i] * sx[ThisTask]) * (nz * sizeof(fft_complex)), nz * sizeof(fft_complex)); } } /* now the result is in b[] */ @@ -390,7 +388,6 @@ static void my_slab_transpose(void *av, void *bv, int *sx, int *firstx, int *sy, myfree(scount); } - /*! \brief Performs a slab-based Fast Fourier transformation. * * \param[in] plan FFT plan. @@ -400,24 +397,24 @@ static void my_slab_transpose(void *av, void *bv, int *sx, int *firstx, int *sy, * * \return void */ -void my_slab_based_fft(fft_plan * plan, void *data, void *workspace, int forward) +void my_slab_based_fft(fft_plan *plan, void *data, void *workspace, int forward) { int n, prod; int slabsx = plan->slabs_x_per_task[ThisTask]; int slabsy = plan->slabs_y_per_task[ThisTask]; - int ngridx = plan->NgridX; - int ngridy = plan->NgridY; - int ngridz = plan->Ngridz; + int ngridx = plan->NgridX; + int ngridy = plan->NgridY; + int ngridz = plan->Ngridz; int ngridz2 = 2 * ngridz; - size_t ngridx_long = ngridx; - size_t ngridy_long = ngridy; - size_t ngridz_long = ngridz; + size_t ngridx_long = ngridx; + size_t ngridy_long = ngridy; + size_t ngridz_long = ngridz; size_t ngridz2_long = ngridz2; - fft_real *data_real = (fft_real *) data; - fft_complex *data_complex = (fft_complex *) data, *workspace_complex = (fft_complex *) workspace; + fft_real *data_real = (fft_real *)data; + fft_complex *data_complex = (fft_complex *)data, *workspace_complex = (fft_complex *)workspace; if(forward == 1) { @@ -425,10 +422,9 @@ void my_slab_based_fft(fft_plan * plan, void *data, void *workspace, int forward prod = slabsx * ngridy; for(n = 0; n < prod; n++) { - FFTW(execute_dft_r2c) (plan->forward_plan_zdir, data_real + n * ngridz2_long, workspace_complex + n * ngridz_long); + FFTW(execute_dft_r2c)(plan->forward_plan_zdir, data_real + n * ngridz2_long, workspace_complex + n * ngridz_long); } - /* do the y-direction FFT, complex to complex */ prod = slabsx * ngridz; for(n = 0; n < prod; n++) @@ -436,13 +432,15 @@ void my_slab_based_fft(fft_plan * plan, void *data, void *workspace, int forward int i = n / ngridz; int j = n % ngridz; - FFTW(execute_dft) (plan->forward_plan_ydir, workspace_complex + i * ngridz * ngridy_long + j, data_complex + i * ngridz * ngridy_long + j); + FFTW(execute_dft) + (plan->forward_plan_ydir, workspace_complex + i * ngridz * ngridy_long + j, data_complex + i * ngridz * ngridy_long + j); } /* now our data resides in data_complex[] */ /* do the transpose */ - my_slab_transpose(data_complex, workspace_complex, plan->slabs_x_per_task, plan->first_slab_x_of_task, plan->slabs_y_per_task, plan->first_slab_y_of_task, ngridx, ngridy, ngridz, 0); + my_slab_transpose(data_complex, workspace_complex, plan->slabs_x_per_task, plan->first_slab_x_of_task, plan->slabs_y_per_task, + plan->first_slab_y_of_task, ngridx, ngridy, ngridz, 0); /* now the data is in workspace_complex[] */ @@ -453,7 +451,8 @@ void my_slab_based_fft(fft_plan * plan, void *data, void *workspace, int forward int i = n / ngridz; int j = n % ngridz; - FFTW(execute_dft) (plan->forward_plan_xdir, workspace_complex + i * ngridz * ngridx_long + j, data_complex + i * ngridz * ngridx_long + j); + FFTW(execute_dft) + (plan->forward_plan_xdir, workspace_complex + i * ngridz * ngridx_long + j, data_complex + i * ngridz * ngridx_long + j); } /* now the result is in data_complex[] */ @@ -467,10 +466,12 @@ void my_slab_based_fft(fft_plan * plan, void *data, void *workspace, int forward int i = n / ngridz; int j = n % ngridz; - FFTW(execute_dft) (plan->backward_plan_xdir, data_complex + i * ngridz * ngridx_long + j, workspace_complex + i * ngridz * ngridx_long + j); + FFTW(execute_dft) + (plan->backward_plan_xdir, data_complex + i * ngridz * ngridx_long + j, workspace_complex + i * ngridz * ngridx_long + j); } - my_slab_transpose(workspace_complex, data_complex, plan->slabs_x_per_task, plan->first_slab_x_of_task, plan->slabs_y_per_task, plan->first_slab_y_of_task, ngridx, ngridy, ngridz, 1); + my_slab_transpose(workspace_complex, data_complex, plan->slabs_x_per_task, plan->first_slab_x_of_task, plan->slabs_y_per_task, + plan->first_slab_y_of_task, ngridx, ngridy, ngridz, 1); prod = slabsx * ngridz; @@ -479,21 +480,21 @@ void my_slab_based_fft(fft_plan * plan, void *data, void *workspace, int forward int i = n / ngridz; int j = n % ngridz; - FFTW(execute_dft) (plan->backward_plan_ydir, data_complex + i * ngridz * ngridy_long + j, workspace_complex + i * ngridz * ngridy_long + j); + FFTW(execute_dft) + (plan->backward_plan_ydir, data_complex + i * ngridz * ngridy_long + j, workspace_complex + i * ngridz * ngridy_long + j); } prod = slabsx * ngridy; for(n = 0; n < prod; n++) { - FFTW(execute_dft_c2r) (plan->backward_plan_zdir, workspace_complex + n * ngridz_long, data_real + n * ngridz2_long); + FFTW(execute_dft_c2r)(plan->backward_plan_zdir, workspace_complex + n * ngridz_long, data_real + n * ngridz2_long); } /* now the result is in data[] */ } } - /*! \brief Performs a slab-based complex to complex Fast Fourier * transformation. * @@ -504,7 +505,7 @@ void my_slab_based_fft(fft_plan * plan, void *data, void *workspace, int forward * * \return void */ -void my_slab_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int forward) +void my_slab_based_fft_c2c(fft_plan *plan, void *data, void *workspace, int forward) { int n, prod; int slabsx = plan->slabs_x_per_task[ThisTask]; @@ -518,8 +519,8 @@ void my_slab_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int for size_t ngridy_long = ngridy; size_t ngridz_long = ngridz; - fft_complex *data_start = (fft_complex *) data; - fft_complex *data_complex = (fft_complex *) data, *workspace_complex = (fft_complex *) workspace; + fft_complex *data_start = (fft_complex *)data; + fft_complex *data_complex = (fft_complex *)data, *workspace_complex = (fft_complex *)workspace; if(forward == 1) { @@ -527,7 +528,7 @@ void my_slab_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int for prod = slabsx * ngridy; for(n = 0; n < prod; n++) { - FFTW(execute_dft) (plan->forward_plan_zdir, data_start + n * ngridz, workspace_complex + n * ngridz); + FFTW(execute_dft)(plan->forward_plan_zdir, data_start + n * ngridz, workspace_complex + n * ngridz); } /* do the y-direction FFT, complex to complex */ @@ -537,13 +538,15 @@ void my_slab_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int for int i = n / ngridz; int j = n % ngridz; - FFTW(execute_dft) (plan->forward_plan_ydir, workspace_complex + i * ngridz * ngridy_long + j, data_complex + i * ngridz * ngridy_long + j); + FFTW(execute_dft) + (plan->forward_plan_ydir, workspace_complex + i * ngridz * ngridy_long + j, data_complex + i * ngridz * ngridy_long + j); } /* now our data resides in data_complex[] */ /* do the transpose */ - my_slab_transpose(data_complex, workspace_complex, plan->slabs_x_per_task, plan->first_slab_x_of_task, plan->slabs_y_per_task, plan->first_slab_y_of_task, ngridx, ngridy, ngridz, 0); + my_slab_transpose(data_complex, workspace_complex, plan->slabs_x_per_task, plan->first_slab_x_of_task, plan->slabs_y_per_task, + plan->first_slab_y_of_task, ngridx, ngridy, ngridz, 0); /* now the data is in workspace_complex[] */ @@ -554,7 +557,8 @@ void my_slab_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int for int i = n / ngridz; int j = n % ngridz; - FFTW(execute_dft) (plan->forward_plan_xdir, workspace_complex + i * ngridz * ngridx_long + j, data_complex + i * ngridz * ngridx_long + j); + FFTW(execute_dft) + (plan->forward_plan_xdir, workspace_complex + i * ngridz * ngridx_long + j, data_complex + i * ngridz * ngridx_long + j); } /* now the result is in data_complex[] */ @@ -568,10 +572,12 @@ void my_slab_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int for int i = n / ngridz; int j = n % ngridz; - FFTW(execute_dft) (plan->backward_plan_xdir, data_complex + i * ngridz * ngridx_long + j, workspace_complex + i * ngridz * ngridx_long + j); + FFTW(execute_dft) + (plan->backward_plan_xdir, data_complex + i * ngridz * ngridx_long + j, workspace_complex + i * ngridz * ngridx_long + j); } - my_slab_transpose(workspace_complex, data_complex, plan->slabs_x_per_task, plan->first_slab_x_of_task, plan->slabs_y_per_task, plan->first_slab_y_of_task, ngridx, ngridy, ngridz, 1); + my_slab_transpose(workspace_complex, data_complex, plan->slabs_x_per_task, plan->first_slab_x_of_task, plan->slabs_y_per_task, + plan->first_slab_y_of_task, ngridx, ngridy, ngridz, 1); prod = slabsx * ngridz; @@ -580,38 +586,36 @@ void my_slab_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int for int i = n / ngridz; int j = n % ngridz; - FFTW(execute_dft) (plan->backward_plan_ydir, data_complex + i * ngridz * ngridy_long + j, workspace_complex + i * ngridz * ngridy_long + j); + FFTW(execute_dft) + (plan->backward_plan_ydir, data_complex + i * ngridz * ngridy_long + j, workspace_complex + i * ngridz * ngridy_long + j); } prod = slabsx * ngridy; for(n = 0; n < prod; n++) { - FFTW(execute_dft) (plan->backward_plan_zdir, workspace_complex + n * ngridz, data_start + n * ngridz); + FFTW(execute_dft)(plan->backward_plan_zdir, workspace_complex + n * ngridz, data_start + n * ngridz); } /* now the result is in data[] */ } } - #else /* #ifndef FFT_COLUMN_BASED */ +static void my_fft_column_remap(fft_complex *data, int Ndims[3], int in_firstcol, int in_ncol, fft_complex *out, int perm[3], + int out_firstcol, int out_ncol, size_t *offset_send, size_t *offset_recv, size_t *count_send, + size_t *count_recv, size_t just_count_flag); -static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstcol, int in_ncol, - fft_complex * out, int perm[3], int out_firstcol, int out_ncol, - size_t * offset_send, size_t * offset_recv, size_t * count_send, size_t * count_recv, size_t just_count_flag); - -static void my_fft_column_transpose(fft_real * data, int Ndims[3], /* global dimensions of data cube */ - int in_firstcol, int in_ncol, /* first column and number of columns */ - fft_real * out, int perm[3], - int out_firstcol, int out_ncol, size_t * offset_send, size_t * offset_recv, size_t * count_send, size_t * count_recv, size_t just_count_flag); - -static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], /* global dimensions of data cube */ - int in_firstcol, int in_ncol, /* first column and number of columns */ - fft_complex * out, int perm[3], - int out_firstcol, int out_ncol, size_t * offset_send, size_t * offset_recv, size_t * count_send, size_t * count_recv, size_t just_count_flag); +static void my_fft_column_transpose(fft_real *data, int Ndims[3], /* global dimensions of data cube */ + int in_firstcol, int in_ncol, /* first column and number of columns */ + fft_real *out, int perm[3], int out_firstcol, int out_ncol, size_t *offset_send, + size_t *offset_recv, size_t *count_send, size_t *count_recv, size_t just_count_flag); +static void my_fft_column_transpose_c(fft_complex *data, int Ndims[3], /* global dimensions of data cube */ + int in_firstcol, int in_ncol, /* first column and number of columns */ + fft_complex *out, int perm[3], int out_firstcol, int out_ncol, size_t *offset_send, + size_t *offset_recv, size_t *count_send, size_t *count_recv, size_t just_count_flag); /*! \brief Initializes column based FFT. * @@ -622,7 +626,7 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], /* globa * * \return void */ -void my_column_based_fft_init(fft_plan * plan, int NgridX, int NgridY, int NgridZ) +void my_column_based_fft_init(fft_plan *plan, int NgridX, int NgridY, int NgridZ) { plan->NgridX = NgridX; plan->NgridY = NgridY; @@ -635,25 +639,25 @@ void my_column_based_fft_init(fft_plan * plan, int NgridX, int NgridY, int Ngrid int columns, avg, exc, tasklastsection, pivotcol; - columns = NgridX * NgridY; - avg = (columns - 1) / NTask + 1; - exc = NTask * avg - columns; + columns = NgridX * NgridY; + avg = (columns - 1) / NTask + 1; + exc = NTask * avg - columns; tasklastsection = NTask - exc; - pivotcol = tasklastsection * avg; + pivotcol = tasklastsection * avg; - plan->pivotcol = pivotcol; - plan->avg = avg; + plan->pivotcol = pivotcol; + plan->avg = avg; plan->tasklastsection = tasklastsection; if(ThisTask < tasklastsection) { plan->base_firstcol = ThisTask * avg; - plan->base_ncol = avg; + plan->base_ncol = avg; } else { plan->base_firstcol = ThisTask * avg - (ThisTask - tasklastsection); - plan->base_ncol = avg - 1; + plan->base_ncol = avg - 1; } plan->base_lastcol = plan->base_firstcol + plan->base_ncol - 1; @@ -666,101 +670,101 @@ void my_column_based_fft_init(fft_plan * plan, int NgridX, int NgridY, int Ngrid subdivide_evenly(plan->NgridY * plan->Ngrid2, NTask, ThisTask, &plan->firstcol_YZ, &plan->ncol_YZ); - plan->second_transposed_ncells = ((size_t) plan->NgridX) * plan->second_transposed_ncol; + plan->second_transposed_ncells = ((size_t)plan->NgridX) * plan->second_transposed_ncol; - plan->max_datasize = ((size_t) plan->Ngrid2) * plan->base_ncol; - plan->max_datasize = smax(plan->max_datasize, 2 * ((size_t) plan->NgridY) * plan->transposed_ncol); - plan->max_datasize = smax(plan->max_datasize, 2 * ((size_t) plan->NgridX) * plan->second_transposed_ncol); - plan->max_datasize = smax(plan->max_datasize, ((size_t) plan->ncol_XZ) * plan->NgridY); - plan->max_datasize = smax(plan->max_datasize, ((size_t) plan->ncol_YZ) * plan->NgridX); + plan->max_datasize = ((size_t)plan->Ngrid2) * plan->base_ncol; + plan->max_datasize = smax(plan->max_datasize, 2 * ((size_t)plan->NgridY) * plan->transposed_ncol); + plan->max_datasize = smax(plan->max_datasize, 2 * ((size_t)plan->NgridX) * plan->second_transposed_ncol); + plan->max_datasize = smax(plan->max_datasize, ((size_t)plan->ncol_XZ) * plan->NgridY); + plan->max_datasize = smax(plan->max_datasize, ((size_t)plan->ncol_YZ) * plan->NgridX); plan->fftsize = plan->max_datasize; - plan->offsets_send_A = mymalloc_clear("offsets_send_A", NTask * sizeof(size_t)); - plan->offsets_recv_A = mymalloc_clear("offsets_recv_A", NTask * sizeof(size_t)); - plan->offsets_send_B = mymalloc_clear("offsets_send_B", NTask * sizeof(size_t)); - plan->offsets_recv_B = mymalloc_clear("offsets_recv_B", NTask * sizeof(size_t)); - plan->offsets_send_C = mymalloc_clear("offsets_send_C", NTask * sizeof(size_t)); - plan->offsets_recv_C = mymalloc_clear("offsets_recv_C", NTask * sizeof(size_t)); - plan->offsets_send_D = mymalloc_clear("offsets_send_D", NTask * sizeof(size_t)); - plan->offsets_recv_D = mymalloc_clear("offsets_recv_D", NTask * sizeof(size_t)); - plan->offsets_send_13 = mymalloc_clear("offsets_send_13", NTask * sizeof(size_t)); - plan->offsets_recv_13 = mymalloc_clear("offsets_recv_13", NTask * sizeof(size_t)); - plan->offsets_send_23 = mymalloc_clear("offsets_send_23", NTask * sizeof(size_t)); - plan->offsets_recv_23 = mymalloc_clear("offsets_recv_23", NTask * sizeof(size_t)); + plan->offsets_send_A = mymalloc_clear("offsets_send_A", NTask * sizeof(size_t)); + plan->offsets_recv_A = mymalloc_clear("offsets_recv_A", NTask * sizeof(size_t)); + plan->offsets_send_B = mymalloc_clear("offsets_send_B", NTask * sizeof(size_t)); + plan->offsets_recv_B = mymalloc_clear("offsets_recv_B", NTask * sizeof(size_t)); + plan->offsets_send_C = mymalloc_clear("offsets_send_C", NTask * sizeof(size_t)); + plan->offsets_recv_C = mymalloc_clear("offsets_recv_C", NTask * sizeof(size_t)); + plan->offsets_send_D = mymalloc_clear("offsets_send_D", NTask * sizeof(size_t)); + plan->offsets_recv_D = mymalloc_clear("offsets_recv_D", NTask * sizeof(size_t)); + plan->offsets_send_13 = mymalloc_clear("offsets_send_13", NTask * sizeof(size_t)); + plan->offsets_recv_13 = mymalloc_clear("offsets_recv_13", NTask * sizeof(size_t)); + plan->offsets_send_23 = mymalloc_clear("offsets_send_23", NTask * sizeof(size_t)); + plan->offsets_recv_23 = mymalloc_clear("offsets_recv_23", NTask * sizeof(size_t)); plan->offsets_send_13back = mymalloc_clear("offsets_send_13back", NTask * sizeof(size_t)); plan->offsets_recv_13back = mymalloc_clear("offsets_recv_13back", NTask * sizeof(size_t)); plan->offsets_send_23back = mymalloc_clear("offsets_send_23back", NTask * sizeof(size_t)); plan->offsets_recv_23back = mymalloc_clear("offsets_recv_23back", NTask * sizeof(size_t)); - plan->count_send_A = mymalloc_clear("count_send_A", NTask * sizeof(size_t)); - plan->count_recv_A = mymalloc_clear("count_recv_A", NTask * sizeof(size_t)); - plan->count_send_B = mymalloc_clear("count_send_B", NTask * sizeof(size_t)); - plan->count_recv_B = mymalloc_clear("count_recv_B", NTask * sizeof(size_t)); - plan->count_send_C = mymalloc_clear("count_send_C", NTask * sizeof(size_t)); - plan->count_recv_C = mymalloc_clear("count_recv_C", NTask * sizeof(size_t)); - plan->count_send_D = mymalloc_clear("count_send_D", NTask * sizeof(size_t)); - plan->count_recv_D = mymalloc_clear("count_recv_D", NTask * sizeof(size_t)); - plan->count_send_13 = mymalloc_clear("count_send_13", NTask * sizeof(size_t)); - plan->count_recv_13 = mymalloc_clear("count_recv_13", NTask * sizeof(size_t)); - plan->count_send_23 = mymalloc_clear("count_send_23", NTask * sizeof(size_t)); - plan->count_recv_23 = mymalloc_clear("count_recv_23", NTask * sizeof(size_t)); + plan->count_send_A = mymalloc_clear("count_send_A", NTask * sizeof(size_t)); + plan->count_recv_A = mymalloc_clear("count_recv_A", NTask * sizeof(size_t)); + plan->count_send_B = mymalloc_clear("count_send_B", NTask * sizeof(size_t)); + plan->count_recv_B = mymalloc_clear("count_recv_B", NTask * sizeof(size_t)); + plan->count_send_C = mymalloc_clear("count_send_C", NTask * sizeof(size_t)); + plan->count_recv_C = mymalloc_clear("count_recv_C", NTask * sizeof(size_t)); + plan->count_send_D = mymalloc_clear("count_send_D", NTask * sizeof(size_t)); + plan->count_recv_D = mymalloc_clear("count_recv_D", NTask * sizeof(size_t)); + plan->count_send_13 = mymalloc_clear("count_send_13", NTask * sizeof(size_t)); + plan->count_recv_13 = mymalloc_clear("count_recv_13", NTask * sizeof(size_t)); + plan->count_send_23 = mymalloc_clear("count_send_23", NTask * sizeof(size_t)); + plan->count_recv_23 = mymalloc_clear("count_recv_23", NTask * sizeof(size_t)); plan->count_send_13back = mymalloc_clear("count_send_13back", NTask * sizeof(size_t)); plan->count_recv_13back = mymalloc_clear("count_recv_13back", NTask * sizeof(size_t)); plan->count_send_23back = mymalloc_clear("count_send_23back", NTask * sizeof(size_t)); plan->count_recv_23back = mymalloc_clear("count_recv_23back", NTask * sizeof(size_t)); - int dimA[3] = { plan->NgridX, plan->NgridY, plan->Ngridz }; - int permA[3] = { 0, 2, 1 }; + int dimA[3] = {plan->NgridX, plan->NgridY, plan->Ngridz}; + int permA[3] = {0, 2, 1}; - my_fft_column_remap(NULL, dimA, plan->base_firstcol, plan->base_ncol, NULL, permA, - plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_A, plan->offsets_recv_A, plan->count_send_A, plan->count_recv_A, 1); + my_fft_column_remap(NULL, dimA, plan->base_firstcol, plan->base_ncol, NULL, permA, plan->transposed_firstcol, plan->transposed_ncol, + plan->offsets_send_A, plan->offsets_recv_A, plan->count_send_A, plan->count_recv_A, 1); - int dimB[3] = { plan->NgridX, plan->Ngridz, plan->NgridY }; - int permB[3] = { 2, 1, 0 }; + int dimB[3] = {plan->NgridX, plan->Ngridz, plan->NgridY}; + int permB[3] = {2, 1, 0}; - my_fft_column_remap(NULL, dimB, plan->transposed_firstcol, plan->transposed_ncol, NULL, permB, - plan->second_transposed_firstcol, plan->second_transposed_ncol, plan->offsets_send_B, plan->offsets_recv_B, plan->count_send_B, plan->count_recv_B, 1); + my_fft_column_remap(NULL, dimB, plan->transposed_firstcol, plan->transposed_ncol, NULL, permB, plan->second_transposed_firstcol, + plan->second_transposed_ncol, plan->offsets_send_B, plan->offsets_recv_B, plan->count_send_B, plan->count_recv_B, + 1); - int dimC[3] = { plan->NgridY, plan->Ngridz, plan->NgridX }; - int permC[3] = { 2, 1, 0 }; + int dimC[3] = {plan->NgridY, plan->Ngridz, plan->NgridX}; + int permC[3] = {2, 1, 0}; my_fft_column_remap(NULL, dimC, plan->second_transposed_firstcol, plan->second_transposed_ncol, NULL, permC, - plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_C, plan->offsets_recv_C, plan->count_send_C, plan->count_recv_C, 1); + plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_C, plan->offsets_recv_C, plan->count_send_C, + plan->count_recv_C, 1); - int dimD[3] = { plan->NgridX, plan->Ngridz, plan->NgridY }; - int permD[3] = { 0, 2, 1 }; + int dimD[3] = {plan->NgridX, plan->Ngridz, plan->NgridY}; + int permD[3] = {0, 2, 1}; - my_fft_column_remap(NULL, dimD, plan->transposed_firstcol, plan->transposed_ncol, NULL, permD, - plan->base_firstcol, plan->base_ncol, plan->offsets_send_D, plan->offsets_recv_D, plan->count_send_D, plan->count_recv_D, 1); + my_fft_column_remap(NULL, dimD, plan->transposed_firstcol, plan->transposed_ncol, NULL, permD, plan->base_firstcol, plan->base_ncol, + plan->offsets_send_D, plan->offsets_recv_D, plan->count_send_D, plan->count_recv_D, 1); - int dim23[3] = { plan->NgridX, plan->NgridY, plan->Ngrid2 }; - int perm23[3] = { 0, 2, 1 }; + int dim23[3] = {plan->NgridX, plan->NgridY, plan->Ngrid2}; + int perm23[3] = {0, 2, 1}; - my_fft_column_transpose(NULL, dim23, plan->base_firstcol, plan->base_ncol, NULL, perm23, - plan->firstcol_XZ, plan->ncol_XZ, plan->offsets_send_23, plan->offsets_recv_23, plan->count_send_23, plan->count_recv_23, 1); + my_fft_column_transpose(NULL, dim23, plan->base_firstcol, plan->base_ncol, NULL, perm23, plan->firstcol_XZ, plan->ncol_XZ, + plan->offsets_send_23, plan->offsets_recv_23, plan->count_send_23, plan->count_recv_23, 1); - int dim23back[3] = { plan->NgridX, plan->Ngrid2, plan->NgridY }; - int perm23back[3] = { 0, 2, 1 }; + int dim23back[3] = {plan->NgridX, plan->Ngrid2, plan->NgridY}; + int perm23back[3] = {0, 2, 1}; - my_fft_column_transpose(NULL, dim23back, plan->firstcol_XZ, plan->ncol_XZ, NULL, perm23back, - plan->base_firstcol, plan->base_ncol, plan->offsets_send_23back, plan->offsets_recv_23back, plan->count_send_23back, plan->count_recv_23back, 1); + my_fft_column_transpose(NULL, dim23back, plan->firstcol_XZ, plan->ncol_XZ, NULL, perm23back, plan->base_firstcol, plan->base_ncol, + plan->offsets_send_23back, plan->offsets_recv_23back, plan->count_send_23back, plan->count_recv_23back, 1); - int dim13[3] = { plan->NgridX, plan->NgridY, plan->Ngrid2 }; - int perm13[3] = { 2, 1, 0 }; + int dim13[3] = {plan->NgridX, plan->NgridY, plan->Ngrid2}; + int perm13[3] = {2, 1, 0}; - my_fft_column_transpose(NULL, dim13, plan->base_firstcol, plan->base_ncol, NULL, perm13, - plan->firstcol_YZ, plan->ncol_YZ, plan->offsets_send_13, plan->offsets_recv_13, plan->count_send_13, plan->count_recv_13, 1); + my_fft_column_transpose(NULL, dim13, plan->base_firstcol, plan->base_ncol, NULL, perm13, plan->firstcol_YZ, plan->ncol_YZ, + plan->offsets_send_13, plan->offsets_recv_13, plan->count_send_13, plan->count_recv_13, 1); - int dim13back[3] = { plan->Ngrid2, plan->NgridY, plan->NgridX }; - int perm13back[3] = { 2, 1, 0 }; - - my_fft_column_transpose(NULL, dim13back, plan->firstcol_YZ, plan->ncol_YZ, NULL, perm13back, - plan->base_firstcol, plan->base_ncol, plan->offsets_send_13back, plan->offsets_recv_13back, plan->count_send_13back, plan->count_recv_13back, 1); + int dim13back[3] = {plan->Ngrid2, plan->NgridY, plan->NgridX}; + int perm13back[3] = {2, 1, 0}; + my_fft_column_transpose(NULL, dim13back, plan->firstcol_YZ, plan->ncol_YZ, NULL, perm13back, plan->base_firstcol, plan->base_ncol, + plan->offsets_send_13back, plan->offsets_recv_13back, plan->count_send_13back, plan->count_recv_13back, 1); } - /*! \brief Initializes complex to complex column based FFT. * * \param[out] plan FFT plan. @@ -770,7 +774,7 @@ void my_column_based_fft_init(fft_plan * plan, int NgridX, int NgridY, int Ngrid * * \return void */ -void my_column_based_fft_init_c2c(fft_plan * plan, int NgridX, int NgridY, int NgridZ) +void my_column_based_fft_init_c2c(fft_plan *plan, int NgridX, int NgridY, int NgridZ) { plan->NgridX = NgridX; plan->NgridY = NgridY; @@ -778,25 +782,25 @@ void my_column_based_fft_init_c2c(fft_plan * plan, int NgridX, int NgridY, int N int columns, avg, exc, tasklastsection, pivotcol; - columns = NgridX * NgridY; - avg = (columns - 1) / NTask + 1; - exc = NTask * avg - columns; + columns = NgridX * NgridY; + avg = (columns - 1) / NTask + 1; + exc = NTask * avg - columns; tasklastsection = NTask - exc; - pivotcol = tasklastsection * avg; + pivotcol = tasklastsection * avg; - plan->pivotcol = pivotcol; - plan->avg = avg; + plan->pivotcol = pivotcol; + plan->avg = avg; plan->tasklastsection = tasklastsection; if(ThisTask < tasklastsection) { plan->base_firstcol = ThisTask * avg; - plan->base_ncol = avg; + plan->base_ncol = avg; } else { plan->base_firstcol = ThisTask * avg - (ThisTask - tasklastsection); - plan->base_ncol = avg - 1; + plan->base_ncol = avg - 1; } plan->base_lastcol = plan->base_firstcol + plan->base_ncol - 1; @@ -809,101 +813,101 @@ void my_column_based_fft_init_c2c(fft_plan * plan, int NgridX, int NgridY, int N subdivide_evenly(plan->NgridY * plan->NgridZ, NTask, ThisTask, &plan->firstcol_YZ, &plan->ncol_YZ); - plan->second_transposed_ncells = ((size_t) plan->NgridX) * plan->second_transposed_ncol; + plan->second_transposed_ncells = ((size_t)plan->NgridX) * plan->second_transposed_ncol; - plan->max_datasize = 2 * ((size_t) plan->NgridZ) * plan->base_ncol; - plan->max_datasize = smax(plan->max_datasize, 2 * ((size_t) plan->NgridY) * plan->transposed_ncol); - plan->max_datasize = smax(plan->max_datasize, 2 * ((size_t) plan->NgridX) * plan->second_transposed_ncol); - plan->max_datasize = smax(plan->max_datasize, ((size_t) plan->ncol_XZ) * plan->NgridY); - plan->max_datasize = smax(plan->max_datasize, ((size_t) plan->ncol_YZ) * plan->NgridX); + plan->max_datasize = 2 * ((size_t)plan->NgridZ) * plan->base_ncol; + plan->max_datasize = smax(plan->max_datasize, 2 * ((size_t)plan->NgridY) * plan->transposed_ncol); + plan->max_datasize = smax(plan->max_datasize, 2 * ((size_t)plan->NgridX) * plan->second_transposed_ncol); + plan->max_datasize = smax(plan->max_datasize, ((size_t)plan->ncol_XZ) * plan->NgridY); + plan->max_datasize = smax(plan->max_datasize, ((size_t)plan->ncol_YZ) * plan->NgridX); plan->fftsize = plan->max_datasize; - plan->offsets_send_A = mymalloc_clear("offsets_send_A", NTask * sizeof(size_t)); - plan->offsets_recv_A = mymalloc_clear("offsets_recv_A", NTask * sizeof(size_t)); - plan->offsets_send_B = mymalloc_clear("offsets_send_B", NTask * sizeof(size_t)); - plan->offsets_recv_B = mymalloc_clear("offsets_recv_B", NTask * sizeof(size_t)); - plan->offsets_send_C = mymalloc_clear("offsets_send_C", NTask * sizeof(size_t)); - plan->offsets_recv_C = mymalloc_clear("offsets_recv_C", NTask * sizeof(size_t)); - plan->offsets_send_D = mymalloc_clear("offsets_send_D", NTask * sizeof(size_t)); - plan->offsets_recv_D = mymalloc_clear("offsets_recv_D", NTask * sizeof(size_t)); - plan->offsets_send_13 = mymalloc_clear("offsets_send_13", NTask * sizeof(size_t)); - plan->offsets_recv_13 = mymalloc_clear("offsets_recv_13", NTask * sizeof(size_t)); - plan->offsets_send_23 = mymalloc_clear("offsets_send_23", NTask * sizeof(size_t)); - plan->offsets_recv_23 = mymalloc_clear("offsets_recv_23", NTask * sizeof(size_t)); + plan->offsets_send_A = mymalloc_clear("offsets_send_A", NTask * sizeof(size_t)); + plan->offsets_recv_A = mymalloc_clear("offsets_recv_A", NTask * sizeof(size_t)); + plan->offsets_send_B = mymalloc_clear("offsets_send_B", NTask * sizeof(size_t)); + plan->offsets_recv_B = mymalloc_clear("offsets_recv_B", NTask * sizeof(size_t)); + plan->offsets_send_C = mymalloc_clear("offsets_send_C", NTask * sizeof(size_t)); + plan->offsets_recv_C = mymalloc_clear("offsets_recv_C", NTask * sizeof(size_t)); + plan->offsets_send_D = mymalloc_clear("offsets_send_D", NTask * sizeof(size_t)); + plan->offsets_recv_D = mymalloc_clear("offsets_recv_D", NTask * sizeof(size_t)); + plan->offsets_send_13 = mymalloc_clear("offsets_send_13", NTask * sizeof(size_t)); + plan->offsets_recv_13 = mymalloc_clear("offsets_recv_13", NTask * sizeof(size_t)); + plan->offsets_send_23 = mymalloc_clear("offsets_send_23", NTask * sizeof(size_t)); + plan->offsets_recv_23 = mymalloc_clear("offsets_recv_23", NTask * sizeof(size_t)); plan->offsets_send_13back = mymalloc_clear("offsets_send_13back", NTask * sizeof(size_t)); plan->offsets_recv_13back = mymalloc_clear("offsets_recv_13back", NTask * sizeof(size_t)); plan->offsets_send_23back = mymalloc_clear("offsets_send_23back", NTask * sizeof(size_t)); plan->offsets_recv_23back = mymalloc_clear("offsets_recv_23back", NTask * sizeof(size_t)); - plan->count_send_A = mymalloc_clear("count_send_A", NTask * sizeof(size_t)); - plan->count_recv_A = mymalloc_clear("count_recv_A", NTask * sizeof(size_t)); - plan->count_send_B = mymalloc_clear("count_send_B", NTask * sizeof(size_t)); - plan->count_recv_B = mymalloc_clear("count_recv_B", NTask * sizeof(size_t)); - plan->count_send_C = mymalloc_clear("count_send_C", NTask * sizeof(size_t)); - plan->count_recv_C = mymalloc_clear("count_recv_C", NTask * sizeof(size_t)); - plan->count_send_D = mymalloc_clear("count_send_D", NTask * sizeof(size_t)); - plan->count_recv_D = mymalloc_clear("count_recv_D", NTask * sizeof(size_t)); - plan->count_send_13 = mymalloc_clear("count_send_13", NTask * sizeof(size_t)); - plan->count_recv_13 = mymalloc_clear("count_recv_13", NTask * sizeof(size_t)); - plan->count_send_23 = mymalloc_clear("count_send_23", NTask * sizeof(size_t)); - plan->count_recv_23 = mymalloc_clear("count_recv_23", NTask * sizeof(size_t)); + plan->count_send_A = mymalloc_clear("count_send_A", NTask * sizeof(size_t)); + plan->count_recv_A = mymalloc_clear("count_recv_A", NTask * sizeof(size_t)); + plan->count_send_B = mymalloc_clear("count_send_B", NTask * sizeof(size_t)); + plan->count_recv_B = mymalloc_clear("count_recv_B", NTask * sizeof(size_t)); + plan->count_send_C = mymalloc_clear("count_send_C", NTask * sizeof(size_t)); + plan->count_recv_C = mymalloc_clear("count_recv_C", NTask * sizeof(size_t)); + plan->count_send_D = mymalloc_clear("count_send_D", NTask * sizeof(size_t)); + plan->count_recv_D = mymalloc_clear("count_recv_D", NTask * sizeof(size_t)); + plan->count_send_13 = mymalloc_clear("count_send_13", NTask * sizeof(size_t)); + plan->count_recv_13 = mymalloc_clear("count_recv_13", NTask * sizeof(size_t)); + plan->count_send_23 = mymalloc_clear("count_send_23", NTask * sizeof(size_t)); + plan->count_recv_23 = mymalloc_clear("count_recv_23", NTask * sizeof(size_t)); plan->count_send_13back = mymalloc_clear("count_send_13back", NTask * sizeof(size_t)); plan->count_recv_13back = mymalloc_clear("count_recv_13back", NTask * sizeof(size_t)); plan->count_send_23back = mymalloc_clear("count_send_23back", NTask * sizeof(size_t)); plan->count_recv_23back = mymalloc_clear("count_recv_23back", NTask * sizeof(size_t)); - int dimA[3] = { plan->NgridX, plan->NgridY, plan->NgridZ }; - int permA[3] = { 0, 2, 1 }; + int dimA[3] = {plan->NgridX, plan->NgridY, plan->NgridZ}; + int permA[3] = {0, 2, 1}; - my_fft_column_remap(NULL, dimA, plan->base_firstcol, plan->base_ncol, NULL, permA, - plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_A, plan->offsets_recv_A, plan->count_send_A, plan->count_recv_A, 1); + my_fft_column_remap(NULL, dimA, plan->base_firstcol, plan->base_ncol, NULL, permA, plan->transposed_firstcol, plan->transposed_ncol, + plan->offsets_send_A, plan->offsets_recv_A, plan->count_send_A, plan->count_recv_A, 1); - int dimB[3] = { plan->NgridX, plan->NgridZ, plan->NgridY }; - int permB[3] = { 2, 1, 0 }; + int dimB[3] = {plan->NgridX, plan->NgridZ, plan->NgridY}; + int permB[3] = {2, 1, 0}; - my_fft_column_remap(NULL, dimB, plan->transposed_firstcol, plan->transposed_ncol, NULL, permB, - plan->second_transposed_firstcol, plan->second_transposed_ncol, plan->offsets_send_B, plan->offsets_recv_B, plan->count_send_B, plan->count_recv_B, 1); + my_fft_column_remap(NULL, dimB, plan->transposed_firstcol, plan->transposed_ncol, NULL, permB, plan->second_transposed_firstcol, + plan->second_transposed_ncol, plan->offsets_send_B, plan->offsets_recv_B, plan->count_send_B, plan->count_recv_B, + 1); - int dimC[3] = { plan->NgridY, plan->NgridZ, plan->NgridX }; - int permC[3] = { 2, 1, 0 }; + int dimC[3] = {plan->NgridY, plan->NgridZ, plan->NgridX}; + int permC[3] = {2, 1, 0}; my_fft_column_remap(NULL, dimC, plan->second_transposed_firstcol, plan->second_transposed_ncol, NULL, permC, - plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_C, plan->offsets_recv_C, plan->count_send_C, plan->count_recv_C, 1); - - int dimD[3] = { plan->NgridX, plan->NgridZ, plan->NgridY }; - int permD[3] = { 0, 2, 1 }; + plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_C, plan->offsets_recv_C, plan->count_send_C, + plan->count_recv_C, 1); - my_fft_column_remap(NULL, dimD, plan->transposed_firstcol, plan->transposed_ncol, NULL, permD, - plan->base_firstcol, plan->base_ncol, plan->offsets_send_D, plan->offsets_recv_D, plan->count_send_D, plan->count_recv_D, 1); + int dimD[3] = {plan->NgridX, plan->NgridZ, plan->NgridY}; + int permD[3] = {0, 2, 1}; - int dim23[3] = { plan->NgridX, plan->NgridY, plan->NgridZ }; - int perm23[3] = { 0, 2, 1 }; + my_fft_column_remap(NULL, dimD, plan->transposed_firstcol, plan->transposed_ncol, NULL, permD, plan->base_firstcol, plan->base_ncol, + plan->offsets_send_D, plan->offsets_recv_D, plan->count_send_D, plan->count_recv_D, 1); - my_fft_column_transpose_c(NULL, dim23, plan->base_firstcol, plan->base_ncol, NULL, perm23, - plan->firstcol_XZ, plan->ncol_XZ, plan->offsets_send_23, plan->offsets_recv_23, plan->count_send_23, plan->count_recv_23, 1); + int dim23[3] = {plan->NgridX, plan->NgridY, plan->NgridZ}; + int perm23[3] = {0, 2, 1}; - int dim23back[3] = { plan->NgridX, plan->NgridZ, plan->NgridY }; - int perm23back[3] = { 0, 2, 1 }; + my_fft_column_transpose_c(NULL, dim23, plan->base_firstcol, plan->base_ncol, NULL, perm23, plan->firstcol_XZ, plan->ncol_XZ, + plan->offsets_send_23, plan->offsets_recv_23, plan->count_send_23, plan->count_recv_23, 1); - my_fft_column_transpose_c(NULL, dim23back, plan->firstcol_XZ, plan->ncol_XZ, NULL, perm23back, - plan->base_firstcol, plan->base_ncol, plan->offsets_send_23back, plan->offsets_recv_23back, plan->count_send_23back, plan->count_recv_23back, 1); + int dim23back[3] = {plan->NgridX, plan->NgridZ, plan->NgridY}; + int perm23back[3] = {0, 2, 1}; - int dim13[3] = { plan->NgridX, plan->NgridY, plan->NgridZ }; - int perm13[3] = { 2, 1, 0 }; + my_fft_column_transpose_c(NULL, dim23back, plan->firstcol_XZ, plan->ncol_XZ, NULL, perm23back, plan->base_firstcol, plan->base_ncol, + plan->offsets_send_23back, plan->offsets_recv_23back, plan->count_send_23back, plan->count_recv_23back, 1); - my_fft_column_transpose_c(NULL, dim13, plan->base_firstcol, plan->base_ncol, NULL, perm13, - plan->firstcol_YZ, plan->ncol_YZ, plan->offsets_send_13, plan->offsets_recv_13, plan->count_send_13, plan->count_recv_13, 1); + int dim13[3] = {plan->NgridX, plan->NgridY, plan->NgridZ}; + int perm13[3] = {2, 1, 0}; - int dim13back[3] = { plan->NgridZ, plan->NgridY, plan->NgridX }; - int perm13back[3] = { 2, 1, 0 }; + my_fft_column_transpose_c(NULL, dim13, plan->base_firstcol, plan->base_ncol, NULL, perm13, plan->firstcol_YZ, plan->ncol_YZ, + plan->offsets_send_13, plan->offsets_recv_13, plan->count_send_13, plan->count_recv_13, 1); - my_fft_column_transpose_c(NULL, dim13back, plan->firstcol_YZ, plan->ncol_YZ, NULL, perm13back, - plan->base_firstcol, plan->base_ncol, plan->offsets_send_13back, plan->offsets_recv_13back, plan->count_send_13back, plan->count_recv_13back, 1); + int dim13back[3] = {plan->NgridZ, plan->NgridY, plan->NgridX}; + int perm13back[3] = {2, 1, 0}; + my_fft_column_transpose_c(NULL, dim13back, plan->firstcol_YZ, plan->ncol_YZ, NULL, perm13back, plan->base_firstcol, plan->base_ncol, + plan->offsets_send_13back, plan->offsets_recv_13back, plan->count_send_13back, plan->count_recv_13back, 1); } - /*! \brief YZ column transpose. * * \param[in] plan FFT plan. @@ -912,16 +916,15 @@ void my_column_based_fft_init_c2c(fft_plan * plan, int NgridX, int NgridY, int N * * \return void */ -void my_fft_swap23(fft_plan * plan, fft_real * data, fft_real * out) +void my_fft_swap23(fft_plan *plan, fft_real *data, fft_real *out) { - int dim23[3] = { plan->NgridX, plan->NgridY, plan->Ngrid2 }; - int perm23[3] = { 0, 2, 1 }; + int dim23[3] = {plan->NgridX, plan->NgridY, plan->Ngrid2}; + int perm23[3] = {0, 2, 1}; - my_fft_column_transpose(data, dim23, plan->base_firstcol, plan->base_ncol, out, perm23, - plan->firstcol_XZ, plan->ncol_XZ, plan->offsets_send_23, plan->offsets_recv_23, plan->count_send_23, plan->count_recv_23, 0); + my_fft_column_transpose(data, dim23, plan->base_firstcol, plan->base_ncol, out, perm23, plan->firstcol_XZ, plan->ncol_XZ, + plan->offsets_send_23, plan->offsets_recv_23, plan->count_send_23, plan->count_recv_23, 0); } - /*! \brief Reverse YZ column transpose. * * \param[in] plan FFT plan. @@ -930,16 +933,15 @@ void my_fft_swap23(fft_plan * plan, fft_real * data, fft_real * out) * * \return void */ -void my_fft_swap23back(fft_plan * plan, fft_real * data, fft_real * out) +void my_fft_swap23back(fft_plan *plan, fft_real *data, fft_real *out) { - int dim23back[3] = { plan->NgridX, plan->Ngrid2, plan->NgridY }; - int perm23back[3] = { 0, 2, 1 }; + int dim23back[3] = {plan->NgridX, plan->Ngrid2, plan->NgridY}; + int perm23back[3] = {0, 2, 1}; - my_fft_column_transpose(data, dim23back, plan->firstcol_XZ, plan->ncol_XZ, out, perm23back, - plan->base_firstcol, plan->base_ncol, plan->offsets_send_23back, plan->offsets_recv_23back, plan->count_send_23back, plan->count_recv_23back, 0); + my_fft_column_transpose(data, dim23back, plan->firstcol_XZ, plan->ncol_XZ, out, perm23back, plan->base_firstcol, plan->base_ncol, + plan->offsets_send_23back, plan->offsets_recv_23back, plan->count_send_23back, plan->count_recv_23back, 0); } - /*! \brief XZ column transpose. * * \param[in] plan FFT plan. @@ -948,16 +950,15 @@ void my_fft_swap23back(fft_plan * plan, fft_real * data, fft_real * out) * * \return void */ -void my_fft_swap13(fft_plan * plan, fft_real * data, fft_real * out) +void my_fft_swap13(fft_plan *plan, fft_real *data, fft_real *out) { - int dim13[3] = { plan->NgridX, plan->NgridY, plan->Ngrid2 }; - int perm13[3] = { 2, 1, 0 }; + int dim13[3] = {plan->NgridX, plan->NgridY, plan->Ngrid2}; + int perm13[3] = {2, 1, 0}; - my_fft_column_transpose(data, dim13, plan->base_firstcol, plan->base_ncol, out, perm13, - plan->firstcol_YZ, plan->ncol_YZ, plan->offsets_send_13, plan->offsets_recv_13, plan->count_send_13, plan->count_recv_13, 0); + my_fft_column_transpose(data, dim13, plan->base_firstcol, plan->base_ncol, out, perm13, plan->firstcol_YZ, plan->ncol_YZ, + plan->offsets_send_13, plan->offsets_recv_13, plan->count_send_13, plan->count_recv_13, 0); } - /*! \brief Reverse XZ column transpose. * * \param[in] plan FFT plan. @@ -966,16 +967,15 @@ void my_fft_swap13(fft_plan * plan, fft_real * data, fft_real * out) * * \return void */ -void my_fft_swap13back(fft_plan * plan, fft_real * data, fft_real * out) +void my_fft_swap13back(fft_plan *plan, fft_real *data, fft_real *out) { - int dim13back[3] = { plan->Ngrid2, plan->NgridY, plan->NgridX }; - int perm13back[3] = { 2, 1, 0 }; + int dim13back[3] = {plan->Ngrid2, plan->NgridY, plan->NgridX}; + int perm13back[3] = {2, 1, 0}; - my_fft_column_transpose(data, dim13back, plan->firstcol_YZ, plan->ncol_YZ, out, perm13back, - plan->base_firstcol, plan->base_ncol, plan->offsets_send_13back, plan->offsets_recv_13back, plan->count_send_13back, plan->count_recv_13back, 0); + my_fft_column_transpose(data, dim13back, plan->firstcol_YZ, plan->ncol_YZ, out, perm13back, plan->base_firstcol, plan->base_ncol, + plan->offsets_send_13back, plan->offsets_recv_13back, plan->count_send_13back, plan->count_recv_13back, 0); } - /*! \brief Performs a column-based Fast Fourier transformation. * * \param[in] plan FFT plan. @@ -985,7 +985,7 @@ void my_fft_swap13back(fft_plan * plan, fft_real * data, fft_real * out) * * \return void */ -void my_column_based_fft(fft_plan * plan, void *data, void *workspace, int forward) +void my_column_based_fft(fft_plan *plan, void *data, void *workspace, int forward) { size_t n; fft_real *data_real = data, *workspace_real = workspace; @@ -995,27 +995,29 @@ void my_column_based_fft(fft_plan * plan, void *data, void *workspace, int forwa { /* do the z-direction FFT, real to complex */ for(n = 0; n < plan->base_ncol; n++) - FFTW(execute_dft_r2c) (plan->forward_plan_zdir, data_real + n * plan->Ngrid2, workspace_complex + n * plan->Ngridz); + FFTW(execute_dft_r2c)(plan->forward_plan_zdir, data_real + n * plan->Ngrid2, workspace_complex + n * plan->Ngridz); - int dimA[3] = { plan->NgridX, plan->NgridY, plan->Ngridz }; - int permA[3] = { 0, 2, 1 }; + int dimA[3] = {plan->NgridX, plan->NgridY, plan->Ngridz}; + int permA[3] = {0, 2, 1}; - my_fft_column_remap(workspace_complex, dimA, plan->base_firstcol, plan->base_ncol, data_complex, permA, plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_A, - plan->offsets_recv_A, plan->count_send_A, plan->count_recv_A, 0); + my_fft_column_remap(workspace_complex, dimA, plan->base_firstcol, plan->base_ncol, data_complex, permA, + plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_A, plan->offsets_recv_A, + plan->count_send_A, plan->count_recv_A, 0); /* do the y-direction FFT in 'data', complex to complex */ for(n = 0; n < plan->transposed_ncol; n++) - FFTW(execute_dft) (plan->forward_plan_ydir, data_complex + n * plan->NgridY, workspace_complex + n * plan->NgridY); + FFTW(execute_dft)(plan->forward_plan_ydir, data_complex + n * plan->NgridY, workspace_complex + n * plan->NgridY); - int dimB[3] = { plan->NgridX, plan->Ngridz, plan->NgridY }; - int permB[3] = { 2, 1, 0 }; + int dimB[3] = {plan->NgridX, plan->Ngridz, plan->NgridY}; + int permB[3] = {2, 1, 0}; - my_fft_column_remap(workspace_complex, dimB, plan->transposed_firstcol, plan->transposed_ncol, - data_complex, permB, plan->second_transposed_firstcol, plan->second_transposed_ncol, plan->offsets_send_B, plan->offsets_recv_B, plan->count_send_B, plan->count_recv_B, 0); + my_fft_column_remap(workspace_complex, dimB, plan->transposed_firstcol, plan->transposed_ncol, data_complex, permB, + plan->second_transposed_firstcol, plan->second_transposed_ncol, plan->offsets_send_B, plan->offsets_recv_B, + plan->count_send_B, plan->count_recv_B, 0); /* do the x-direction FFT in 'data', complex to complex */ for(n = 0; n < plan->second_transposed_ncol; n++) - FFTW(execute_dft) (plan->forward_plan_xdir, data_complex + n * plan->NgridX, workspace_complex + n * plan->NgridX); + FFTW(execute_dft)(plan->forward_plan_xdir, data_complex + n * plan->NgridX, workspace_complex + n * plan->NgridX); /* result is now in workspace */ } @@ -1023,31 +1025,32 @@ void my_column_based_fft(fft_plan * plan, void *data, void *workspace, int forwa { /* do inverse FFT in 'data' */ for(n = 0; n < plan->second_transposed_ncol; n++) - FFTW(execute_dft) (plan->backward_plan_xdir, data_complex + n * plan->NgridX, workspace_complex + n * plan->NgridX); + FFTW(execute_dft)(plan->backward_plan_xdir, data_complex + n * plan->NgridX, workspace_complex + n * plan->NgridX); - int dimC[3] = { plan->NgridY, plan->Ngridz, plan->NgridX }; - int permC[3] = { 2, 1, 0 }; + int dimC[3] = {plan->NgridY, plan->Ngridz, plan->NgridX}; + int permC[3] = {2, 1, 0}; - my_fft_column_remap(workspace_complex, dimC, plan->second_transposed_firstcol, plan->second_transposed_ncol, - data_complex, permC, plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_C, plan->offsets_recv_C, plan->count_send_C, plan->count_recv_C, 0); + my_fft_column_remap(workspace_complex, dimC, plan->second_transposed_firstcol, plan->second_transposed_ncol, data_complex, permC, + plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_C, plan->offsets_recv_C, + plan->count_send_C, plan->count_recv_C, 0); /* do inverse FFT in 'data' */ for(n = 0; n < plan->transposed_ncol; n++) - FFTW(execute_dft) (plan->backward_plan_ydir, data_complex + n * plan->NgridY, workspace_complex + n * plan->NgridY); + FFTW(execute_dft)(plan->backward_plan_ydir, data_complex + n * plan->NgridY, workspace_complex + n * plan->NgridY); - int dimD[3] = { plan->NgridX, plan->Ngridz, plan->NgridY }; - int permD[3] = { 0, 2, 1 }; + int dimD[3] = {plan->NgridX, plan->Ngridz, plan->NgridY}; + int permD[3] = {0, 2, 1}; - my_fft_column_remap(workspace_complex, dimD, plan->transposed_firstcol, plan->transposed_ncol, data_complex, permD, plan->base_firstcol, plan->base_ncol, plan->offsets_send_D, - plan->offsets_recv_D, plan->count_send_D, plan->count_recv_D, 0); + my_fft_column_remap(workspace_complex, dimD, plan->transposed_firstcol, plan->transposed_ncol, data_complex, permD, + plan->base_firstcol, plan->base_ncol, plan->offsets_send_D, plan->offsets_recv_D, plan->count_send_D, + plan->count_recv_D, 0); /* do complex-to-real inverse transform on z-coordinates */ for(n = 0; n < plan->base_ncol; n++) - FFTW(execute_dft_c2r) (plan->backward_plan_zdir, data_complex + n * plan->Ngridz, workspace_real + n * plan->Ngrid2); + FFTW(execute_dft_c2r)(plan->backward_plan_zdir, data_complex + n * plan->Ngridz, workspace_real + n * plan->Ngrid2); } } - /*! \brief Performs a slab-based complex to complex Fast Fourier * transformation. * @@ -1058,7 +1061,7 @@ void my_column_based_fft(fft_plan * plan, void *data, void *workspace, int forwa * * \return void */ -void my_column_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int forward) +void my_column_based_fft_c2c(fft_plan *plan, void *data, void *workspace, int forward) { size_t n; fft_complex *data_complex = data, *workspace_complex = workspace; @@ -1067,27 +1070,29 @@ void my_column_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int f { /* do the z-direction FFT, complex to complex */ for(n = 0; n < plan->base_ncol; n++) - FFTW(execute_dft) (plan->forward_plan_zdir, data_complex + n * plan->NgridZ, workspace_complex + n * plan->NgridZ); + FFTW(execute_dft)(plan->forward_plan_zdir, data_complex + n * plan->NgridZ, workspace_complex + n * plan->NgridZ); - int dimA[3] = { plan->NgridX, plan->NgridY, plan->NgridZ }; - int permA[3] = { 0, 2, 1 }; + int dimA[3] = {plan->NgridX, plan->NgridY, plan->NgridZ}; + int permA[3] = {0, 2, 1}; - my_fft_column_remap(workspace_complex, dimA, plan->base_firstcol, plan->base_ncol, data_complex, permA, plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_A, - plan->offsets_recv_A, plan->count_send_A, plan->count_recv_A, 0); + my_fft_column_remap(workspace_complex, dimA, plan->base_firstcol, plan->base_ncol, data_complex, permA, + plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_A, plan->offsets_recv_A, + plan->count_send_A, plan->count_recv_A, 0); /* do the y-direction FFT in 'data', complex to complex */ for(n = 0; n < plan->transposed_ncol; n++) - FFTW(execute_dft) (plan->forward_plan_ydir, data_complex + n * plan->NgridY, workspace_complex + n * plan->NgridY); + FFTW(execute_dft)(plan->forward_plan_ydir, data_complex + n * plan->NgridY, workspace_complex + n * plan->NgridY); - int dimB[3] = { plan->NgridX, plan->NgridZ, plan->NgridY }; - int permB[3] = { 2, 1, 0 }; + int dimB[3] = {plan->NgridX, plan->NgridZ, plan->NgridY}; + int permB[3] = {2, 1, 0}; - my_fft_column_remap(workspace_complex, dimB, plan->transposed_firstcol, plan->transposed_ncol, - data_complex, permB, plan->second_transposed_firstcol, plan->second_transposed_ncol, plan->offsets_send_B, plan->offsets_recv_B, plan->count_send_B, plan->count_recv_B, 0); + my_fft_column_remap(workspace_complex, dimB, plan->transposed_firstcol, plan->transposed_ncol, data_complex, permB, + plan->second_transposed_firstcol, plan->second_transposed_ncol, plan->offsets_send_B, plan->offsets_recv_B, + plan->count_send_B, plan->count_recv_B, 0); /* do the x-direction FFT in 'data', complex to complex */ for(n = 0; n < plan->second_transposed_ncol; n++) - FFTW(execute_dft) (plan->forward_plan_xdir, data_complex + n * plan->NgridX, workspace_complex + n * plan->NgridX); + FFTW(execute_dft)(plan->forward_plan_xdir, data_complex + n * plan->NgridX, workspace_complex + n * plan->NgridX); /* result is now in workspace */ } @@ -1095,31 +1100,32 @@ void my_column_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int f { /* do inverse FFT in 'data' */ for(n = 0; n < plan->second_transposed_ncol; n++) - FFTW(execute_dft) (plan->backward_plan_xdir, data_complex + n * plan->NgridX, workspace_complex + n * plan->NgridX); + FFTW(execute_dft)(plan->backward_plan_xdir, data_complex + n * plan->NgridX, workspace_complex + n * plan->NgridX); - int dimC[3] = { plan->NgridY, plan->NgridZ, plan->NgridX }; - int permC[3] = { 2, 1, 0 }; + int dimC[3] = {plan->NgridY, plan->NgridZ, plan->NgridX}; + int permC[3] = {2, 1, 0}; - my_fft_column_remap(workspace_complex, dimC, plan->second_transposed_firstcol, plan->second_transposed_ncol, - data_complex, permC, plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_C, plan->offsets_recv_C, plan->count_send_C, plan->count_recv_C, 0); + my_fft_column_remap(workspace_complex, dimC, plan->second_transposed_firstcol, plan->second_transposed_ncol, data_complex, permC, + plan->transposed_firstcol, plan->transposed_ncol, plan->offsets_send_C, plan->offsets_recv_C, + plan->count_send_C, plan->count_recv_C, 0); /* do inverse FFT in 'data' */ for(n = 0; n < plan->transposed_ncol; n++) - FFTW(execute_dft) (plan->backward_plan_ydir, data_complex + n * plan->NgridY, workspace_complex + n * plan->NgridY); + FFTW(execute_dft)(plan->backward_plan_ydir, data_complex + n * plan->NgridY, workspace_complex + n * plan->NgridY); - int dimD[3] = { plan->NgridX, plan->NgridZ, plan->NgridY }; - int permD[3] = { 0, 2, 1 }; + int dimD[3] = {plan->NgridX, plan->NgridZ, plan->NgridY}; + int permD[3] = {0, 2, 1}; - my_fft_column_remap(workspace_complex, dimD, plan->transposed_firstcol, plan->transposed_ncol, data_complex, permD, plan->base_firstcol, plan->base_ncol, plan->offsets_send_D, - plan->offsets_recv_D, plan->count_send_D, plan->count_recv_D, 0); + my_fft_column_remap(workspace_complex, dimD, plan->transposed_firstcol, plan->transposed_ncol, data_complex, permD, + plan->base_firstcol, plan->base_ncol, plan->offsets_send_D, plan->offsets_recv_D, plan->count_send_D, + plan->count_recv_D, 0); /* do complex-to-complex inverse transform on z-coordinates */ for(n = 0; n < plan->base_ncol; n++) - FFTW(execute_dft) (plan->backward_plan_zdir, data_complex + n * plan->NgridZ, workspace_complex + n * plan->NgridZ); + FFTW(execute_dft)(plan->backward_plan_zdir, data_complex + n * plan->NgridZ, workspace_complex + n * plan->NgridZ); } } - /*! \brief Remaps column-based FFT data. * * \param[in] data Data to be transposed. @@ -1142,8 +1148,9 @@ void my_column_based_fft_c2c(fft_plan * plan, void *data, void *workspace, int f * * \return void */ -static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstcol, int in_ncol, fft_complex * out, int perm[3], int out_firstcol, int out_ncol, size_t * offset_send, - size_t * offset_recv, size_t * count_send, size_t * count_recv, size_t just_count_flag) +static void my_fft_column_remap(fft_complex *data, int Ndims[3], int in_firstcol, int in_ncol, fft_complex *out, int perm[3], + int out_firstcol, int out_ncol, size_t *offset_send, size_t *offset_recv, size_t *count_send, + size_t *count_recv, size_t just_count_flag) { int j, target, origin, ngrp, recvTask, perm_rev[3], xyz[3], uvw[3]; size_t nimport, nexport; @@ -1152,7 +1159,7 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco for(j = 0; j < 3; j++) perm_rev[j] = perm[j]; - if(!(perm_rev[perm[0]] == 0 && perm_rev[perm[1]] == 1 && perm_rev[perm[2]] == 2)) /* not yet the inverse */ + if(!(perm_rev[perm[0]] == 0 && perm_rev[perm[1]] == 1 && perm_rev[perm[2]] == 2)) /* not yet the inverse */ { for(j = 0; j < 3; j++) perm_rev[j] = perm[perm[j]]; @@ -1161,19 +1168,19 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco terminate("bummer"); } - int in_colums = Ndims[0] * Ndims[1]; - int in_avg = (in_colums - 1) / NTask + 1; - int in_exc = NTask * in_avg - in_colums; + int in_colums = Ndims[0] * Ndims[1]; + int in_avg = (in_colums - 1) / NTask + 1; + int in_exc = NTask * in_avg - in_colums; int in_tasklastsection = NTask - in_exc; - int in_pivotcol = in_tasklastsection * in_avg; + int in_pivotcol = in_tasklastsection * in_avg; - int out_colums = Ndims[perm[0]] * Ndims[perm[1]]; - int out_avg = (out_colums - 1) / NTask + 1; - int out_exc = NTask * out_avg - out_colums; + int out_colums = Ndims[perm[0]] * Ndims[perm[1]]; + int out_avg = (out_colums - 1) / NTask + 1; + int out_exc = NTask * out_avg - out_colums; int out_tasklastsection = NTask - out_exc; - int out_pivotcol = out_tasklastsection * out_avg; + int out_pivotcol = out_tasklastsection * out_avg; - size_t i, ncells = ((size_t) in_ncol) * Ndims[2]; + size_t i, ncells = ((size_t)in_ncol) * Ndims[2]; xyz[0] = in_firstcol / Ndims[1]; xyz[1] = in_firstcol % Ndims[1]; @@ -1201,7 +1208,7 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco count_send[target]++; else { - size_t off = offset_send[target] + count_send[target]++; + size_t off = offset_send[target] + count_send[target]++; out[off][0] = data[i][0]; out[off][1] = data[i][1]; } @@ -1235,7 +1242,7 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco } if(nexport != ncells) - terminate("nexport=%lld != ncells=%lld", (long long) nexport, (long long) ncells); + terminate("nexport=%lld != ncells=%lld", (long long)nexport, (long long)ncells); } else { @@ -1250,7 +1257,8 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco { if(count_send[recvTask] > 0 || count_recv[recvTask] > 0) myMPI_Sendrecv(&out[offset_send[recvTask]], count_send[recvTask] * sizeof(fft_complex), MPI_BYTE, recvTask, TAG_DENS_A, - &data[offset_recv[recvTask]], count_recv[recvTask] * sizeof(fft_complex), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + &data[offset_recv[recvTask]], count_recv[recvTask] * sizeof(fft_complex), MPI_BYTE, recvTask, + TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); nimport += count_recv[recvTask]; } @@ -1272,7 +1280,7 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco if(first[1] + out_ncol >= Ndims[perm[1]]) { first[1] = 0; - last[1] = Ndims[perm[1]] - 1; + last[1] = Ndims[perm[1]] - 1; } /* now need to map this back to the old coordinates */ @@ -1282,7 +1290,7 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco for(j = 0; j < 3; j++) { xyz_first[j] = first[perm_rev[j]]; - xyz_last[j] = last[perm_rev[j]]; + xyz_last[j] = last[perm_rev[j]]; } memset(count_recv, 0, NTask * sizeof(size_t)); @@ -1310,10 +1318,10 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco else origin = (newcol - in_pivotcol) / (in_avg - 1) + in_tasklastsection; - size_t index = ((size_t) Ndims[perm[2]]) * (col - out_firstcol) + uvw[2]; + size_t index = ((size_t)Ndims[perm[2]]) * (col - out_firstcol) + uvw[2]; /* move data element from origin task */ - size_t off = offset_recv[origin] + count_recv[origin]++; + size_t off = offset_recv[origin] + count_recv[origin]++; out[index][0] = data[off][0]; out[index][1] = data[off][1]; @@ -1326,12 +1334,12 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco int fi = out_firstcol % Ndims[perm[1]]; int la = (out_firstcol + out_ncol - 1) % Ndims[perm[1]]; - terminate("count=%lld nimport=%lld ncol=%d fi=%d la=%d first=%d last=%d\n", (long long) count, (long long) nimport, out_ncol, fi, la, first[1], last[1]); + terminate("count=%lld nimport=%lld ncol=%d fi=%d la=%d first=%d last=%d\n", (long long)count, (long long)nimport, out_ncol, + fi, la, first[1], last[1]); } } } - /*! \brief Transposes column-based FFT data. * * \param[in] data Data to be transposed. @@ -1354,8 +1362,9 @@ static void my_fft_column_remap(fft_complex * data, int Ndims[3], int in_firstco * * \return void */ -static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstcol, int in_ncol, fft_real * out, int perm[3], int out_firstcol, int out_ncol, size_t * offset_send, - size_t * offset_recv, size_t * count_send, size_t * count_recv, size_t just_count_flag) +static void my_fft_column_transpose(fft_real *data, int Ndims[3], int in_firstcol, int in_ncol, fft_real *out, int perm[3], + int out_firstcol, int out_ncol, size_t *offset_send, size_t *offset_recv, size_t *count_send, + size_t *count_recv, size_t just_count_flag) { int j, target, origin, ngrp, recvTask, perm_rev[3], xyz[3], uvw[3]; size_t nimport, nexport; @@ -1364,7 +1373,7 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc for(j = 0; j < 3; j++) perm_rev[j] = perm[j]; - if(!(perm_rev[perm[0]] == 0 && perm_rev[perm[1]] == 1 && perm_rev[perm[2]] == 2)) /* not yet the inverse */ + if(!(perm_rev[perm[0]] == 0 && perm_rev[perm[1]] == 1 && perm_rev[perm[2]] == 2)) /* not yet the inverse */ { for(j = 0; j < 3; j++) perm_rev[j] = perm[perm[j]]; @@ -1373,19 +1382,19 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc terminate("bummer"); } - int in_colums = Ndims[0] * Ndims[1]; - int in_avg = (in_colums - 1) / NTask + 1; - int in_exc = NTask * in_avg - in_colums; + int in_colums = Ndims[0] * Ndims[1]; + int in_avg = (in_colums - 1) / NTask + 1; + int in_exc = NTask * in_avg - in_colums; int in_tasklastsection = NTask - in_exc; - int in_pivotcol = in_tasklastsection * in_avg; + int in_pivotcol = in_tasklastsection * in_avg; - int out_colums = Ndims[perm[0]] * Ndims[perm[1]]; - int out_avg = (out_colums - 1) / NTask + 1; - int out_exc = NTask * out_avg - out_colums; + int out_colums = Ndims[perm[0]] * Ndims[perm[1]]; + int out_avg = (out_colums - 1) / NTask + 1; + int out_exc = NTask * out_avg - out_colums; int out_tasklastsection = NTask - out_exc; - int out_pivotcol = out_tasklastsection * out_avg; + int out_pivotcol = out_tasklastsection * out_avg; - size_t i, ncells = ((size_t) in_ncol) * Ndims[2]; + size_t i, ncells = ((size_t)in_ncol) * Ndims[2]; xyz[0] = in_firstcol / Ndims[1]; xyz[1] = in_firstcol % Ndims[1]; @@ -1414,7 +1423,7 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc else { size_t off = offset_send[target] + count_send[target]++; - out[off] = data[i]; + out[off] = data[i]; } xyz[2]++; if(xyz[2] == Ndims[2]) @@ -1446,7 +1455,7 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc } if(nexport != ncells) - terminate("nexport=%lld != ncells=%lld", (long long) nexport, (long long) ncells); + terminate("nexport=%lld != ncells=%lld", (long long)nexport, (long long)ncells); } else { @@ -1461,7 +1470,8 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc { if(count_send[recvTask] > 0 || count_recv[recvTask] > 0) myMPI_Sendrecv(&out[offset_send[recvTask]], count_send[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_DENS_A, - &data[offset_recv[recvTask]], count_recv[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + &data[offset_recv[recvTask]], count_recv[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_DENS_A, + MPI_COMM_WORLD, MPI_STATUS_IGNORE); nimport += count_recv[recvTask]; } @@ -1483,7 +1493,7 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc if(first[1] + out_ncol >= Ndims[perm[1]]) { first[1] = 0; - last[1] = Ndims[perm[1]] - 1; + last[1] = Ndims[perm[1]] - 1; } /* now need to map this back to the old coordinates */ @@ -1493,7 +1503,7 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc for(j = 0; j < 3; j++) { xyz_first[j] = first[perm_rev[j]]; - xyz_last[j] = last[perm_rev[j]]; + xyz_last[j] = last[perm_rev[j]]; } memset(count_recv, 0, NTask * sizeof(size_t)); @@ -1521,7 +1531,7 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc else origin = (newcol - in_pivotcol) / (in_avg - 1) + in_tasklastsection; - size_t index = ((size_t) Ndims[perm[2]]) * (col - out_firstcol) + uvw[2]; + size_t index = ((size_t)Ndims[perm[2]]) * (col - out_firstcol) + uvw[2]; /* move data element from origin task */ size_t off = offset_recv[origin] + count_recv[origin]++; @@ -1531,18 +1541,17 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc } } - if(count != nimport) { int fi = out_firstcol % Ndims[perm[1]]; int la = (out_firstcol + out_ncol - 1) % Ndims[perm[1]]; - terminate("count=%lld nimport=%lld ncol=%d fi=%d la=%d first=%d last=%d\n", (long long) count, (long long) nimport, out_ncol, fi, la, first[1], last[1]); + terminate("count=%lld nimport=%lld ncol=%d fi=%d la=%d first=%d last=%d\n", (long long)count, (long long)nimport, out_ncol, + fi, la, first[1], last[1]); } } } - /*! \brief Transposes column-based complex FFT data. * * \param[in] data Data to be transposed. @@ -1565,10 +1574,9 @@ static void my_fft_column_transpose(fft_real * data, int Ndims[3], int in_firstc * * \return void */ -static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], - int in_firstcol, int in_ncol, - fft_complex * out, int perm[3], - int out_firstcol, int out_ncol, size_t * offset_send, size_t * offset_recv, size_t * count_send, size_t * count_recv, size_t just_count_flag) +static void my_fft_column_transpose_c(fft_complex *data, int Ndims[3], int in_firstcol, int in_ncol, fft_complex *out, int perm[3], + int out_firstcol, int out_ncol, size_t *offset_send, size_t *offset_recv, size_t *count_send, + size_t *count_recv, size_t just_count_flag) { int j, target, origin, ngrp, recvTask, perm_rev[3], xyz[3], uvw[3]; size_t nimport, nexport; @@ -1577,7 +1585,7 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], for(j = 0; j < 3; j++) perm_rev[j] = perm[j]; - if(!(perm_rev[perm[0]] == 0 && perm_rev[perm[1]] == 1 && perm_rev[perm[2]] == 2)) /* not yet the inverse */ + if(!(perm_rev[perm[0]] == 0 && perm_rev[perm[1]] == 1 && perm_rev[perm[2]] == 2)) /* not yet the inverse */ { for(j = 0; j < 3; j++) perm_rev[j] = perm[perm[j]]; @@ -1586,19 +1594,19 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], terminate("bummer"); } - int in_colums = Ndims[0] * Ndims[1]; - int in_avg = (in_colums - 1) / NTask + 1; - int in_exc = NTask * in_avg - in_colums; + int in_colums = Ndims[0] * Ndims[1]; + int in_avg = (in_colums - 1) / NTask + 1; + int in_exc = NTask * in_avg - in_colums; int in_tasklastsection = NTask - in_exc; - int in_pivotcol = in_tasklastsection * in_avg; + int in_pivotcol = in_tasklastsection * in_avg; - int out_colums = Ndims[perm[0]] * Ndims[perm[1]]; - int out_avg = (out_colums - 1) / NTask + 1; - int out_exc = NTask * out_avg - out_colums; + int out_colums = Ndims[perm[0]] * Ndims[perm[1]]; + int out_avg = (out_colums - 1) / NTask + 1; + int out_exc = NTask * out_avg - out_colums; int out_tasklastsection = NTask - out_exc; - int out_pivotcol = out_tasklastsection * out_avg; + int out_pivotcol = out_tasklastsection * out_avg; - size_t i, ncells = ((size_t) in_ncol) * Ndims[2]; + size_t i, ncells = ((size_t)in_ncol) * Ndims[2]; xyz[0] = in_firstcol / Ndims[1]; xyz[1] = in_firstcol % Ndims[1]; @@ -1626,7 +1634,7 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], count_send[target]++; else { - size_t off = offset_send[target] + count_send[target]++; + size_t off = offset_send[target] + count_send[target]++; out[off][0] = data[i][0]; out[off][1] = data[i][1]; } @@ -1660,7 +1668,7 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], } if(nexport != ncells) - terminate("nexport=%lld != ncells=%lld", (long long) nexport, (long long) ncells); + terminate("nexport=%lld != ncells=%lld", (long long)nexport, (long long)ncells); } else { @@ -1675,7 +1683,8 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], { if(count_send[recvTask] > 0 || count_recv[recvTask] > 0) myMPI_Sendrecv(&out[offset_send[recvTask]], count_send[recvTask] * sizeof(fft_complex), MPI_BYTE, recvTask, TAG_DENS_A, - &data[offset_recv[recvTask]], count_recv[recvTask] * sizeof(fft_complex), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + &data[offset_recv[recvTask]], count_recv[recvTask] * sizeof(fft_complex), MPI_BYTE, recvTask, + TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); nimport += count_recv[recvTask]; } @@ -1697,7 +1706,7 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], if(first[1] + out_ncol >= Ndims[perm[1]]) { first[1] = 0; - last[1] = Ndims[perm[1]] - 1; + last[1] = Ndims[perm[1]] - 1; } /* now need to map this back to the old coordinates */ @@ -1707,7 +1716,7 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], for(j = 0; j < 3; j++) { xyz_first[j] = first[perm_rev[j]]; - xyz_last[j] = last[perm_rev[j]]; + xyz_last[j] = last[perm_rev[j]]; } memset(count_recv, 0, NTask * sizeof(size_t)); @@ -1735,10 +1744,10 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], else origin = (newcol - in_pivotcol) / (in_avg - 1) + in_tasklastsection; - size_t index = ((size_t) Ndims[perm[2]]) * (col - out_firstcol) + uvw[2]; + size_t index = ((size_t)Ndims[perm[2]]) * (col - out_firstcol) + uvw[2]; /* move data element from origin task */ - size_t off = offset_recv[origin] + count_recv[origin]++; + size_t off = offset_recv[origin] + count_recv[origin]++; out[index][0] = data[off][0]; out[index][1] = data[off][1]; @@ -1746,19 +1755,17 @@ static void my_fft_column_transpose_c(fft_complex * data, int Ndims[3], } } - if(count != nimport) { int fi = out_firstcol % Ndims[perm[1]]; int la = (out_firstcol + out_ncol - 1) % Ndims[perm[1]]; - terminate("count=%lld nimport=%lld ncol=%d fi=%d la=%d first=%d last=%d\n", (long long) count, (long long) nimport, out_ncol, fi, la, first[1], last[1]); + terminate("count=%lld nimport=%lld ncol=%d fi=%d la=%d first=%d last=%d\n", (long long)count, (long long)nimport, out_ncol, + fi, la, first[1], last[1]); } } } - #endif /* #ifndef FFT_COLUMN_BASED #else */ - #endif /* #if defined(PMGRID) */ diff --git a/src/gravity/pm/pm_nonperiodic.c b/src/gravity/pm/pm_nonperiodic.c index e45e274c66e91d78ddce5066d1dc07ccf649f768..7346af2849fcb2f85a965a6f024631b81bedc9b9 100644 --- a/src/gravity/pm/pm_nonperiodic.c +++ b/src/gravity/pm/pm_nonperiodic.c @@ -48,64 +48,55 @@ * - 15.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <math.h> #include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> - #include "../../main/allvars.h" #include "../../main/proto.h" #if defined(PMGRID) && (defined(PLACEHIGHRESREGION) || defined(GRAVITY_NOT_PERIODIC)) - -#if defined(LONG_X) || defined(LONG_Y) || defined (LONG_Z) +#if defined(LONG_X) || defined(LONG_Y) || defined(LONG_Z) #error "LONG_X/Y/Z not supported for the non-periodic FFT gravity code" #endif /* #if defined(LONG_X) || defined(LONG_Y) || defined (LONG_Z) */ - #ifndef GRIDBOOST #define GRIDBOOST 2 #endif /* #ifndef GRIDBOOST */ +#define GRID (GRIDBOOST * PMGRID) +#define GRIDz (GRID / 2 + 1) +#define GRID2 (2 * GRIDz) -#define GRID (GRIDBOOST*PMGRID) -#define GRIDz (GRID/2 + 1) -#define GRID2 (2*GRIDz) - - -#if (GRID > 1024) -typedef long long large_array_offset; /* use a larger data type in this case so that we can always address all cells of the 3D grid with a single index */ -#else /* #if (GRID > 1024) */ +#if(GRID > 1024) +typedef long long large_array_offset; /* use a larger data type in this case so that we can always address all cells of the 3D grid + with a single index */ +#else /* #if (GRID > 1024) */ typedef unsigned int large_array_offset; -#endif /* #if (GRID > 1024) #else */ - +#endif /* #if (GRID > 1024) #else */ #ifdef NUMPART_PER_TASK_LARGE -typedef long long large_numpart_type; /* if there is a risk that the local particle number times 8 overflows a 32-bit integer, this data type should be used */ -#else /* #ifdef NUMPART_PER_TASK_LARGE */ +typedef long long large_numpart_type; /* if there is a risk that the local particle number times 8 overflows a 32-bit integer, this + data type should be used */ +#else /* #ifdef NUMPART_PER_TASK_LARGE */ typedef int large_numpart_type; -#endif /* #ifdef NUMPART_PER_TASK_LARGE */ - +#endif /* #ifdef NUMPART_PER_TASK_LARGE */ /* short-cut macros for accessing different 3D arrays */ -#define FI(x,y,z) (((large_array_offset) GRID2) * (GRID * (x) + (y)) + (z)) -#define FC(c,z) (((large_array_offset) GRID2) * ((c) - myplan.base_firstcol) + (z)) -#define TI(x,y,z) (((large_array_offset) GRID) * ((x) + (y) * myplan.nslab_x) + (z)) - - -static fft_plan myplan; /*!< In this structure, various bookkeeping variables for the distributed FFTs are stored */ +#define FI(x, y, z) (((large_array_offset)GRID2) * (GRID * (x) + (y)) + (z)) +#define FC(c, z) (((large_array_offset)GRID2) * ((c)-myplan.base_firstcol) + (z)) +#define TI(x, y, z) (((large_array_offset)GRID) * ((x) + (y)*myplan.nslab_x) + (z)) +static fft_plan myplan; /*!< In this structure, various bookkeeping variables for the distributed FFTs are stored */ /*! \var maxfftsize * \brief maximum size of the local fft grid among all tasks */ static size_t maxfftsize; - /*! \var rhogrid * \brief This array hold the local part of the density field and * after the FFTs the local part of the potential @@ -118,7 +109,6 @@ static size_t maxfftsize; */ static fft_real *rhogrid, *forcegrid, *workspace; - /*! \brief Array containing the FFT of 'rhogrid' * * This pointer points to the same array as 'rhogrid', @@ -129,7 +119,6 @@ static fft_complex *fft_of_rhogrid; static fft_real *kernel[2]; static fft_complex *fft_of_kernel[2]; - /*! \param Determine particle extent. * * This function determines the particle extension of all particles, and for @@ -201,7 +190,7 @@ void pm_init_regionsize(void) for(j = 0; j < 2; j++) { meshinner[j] = All.TotalMeshSize[j]; - All.TotalMeshSize[j] *= 2.001 * (GRID) / ((double) (GRID - 2 - 8)); + All.TotalMeshSize[j] *= 2.001 * (GRID) / ((double)(GRID - 2 - 8)); } /* move lower left corner by two cells to allow finite differencing of the potential by a 4-point function */ @@ -209,51 +198,53 @@ void pm_init_regionsize(void) for(j = 0; j < 2; j++) for(i = 0; i < 3; i++) { - All.Corner[j][i] = All.Xmintot[j][i] - 2.0005 * All.TotalMeshSize[j] / GRID; + All.Corner[j][i] = All.Xmintot[j][i] - 2.0005 * All.TotalMeshSize[j] / GRID; All.UpperCorner[j][i] = All.Corner[j][i] + (GRID / 2 - 1) * (All.TotalMeshSize[j] / GRID); } #ifdef PLACEHIGHRESREGION All.Asmth[1] = ASMTH * All.TotalMeshSize[1] / GRID; - All.Rcut[1] = RCUT * All.Asmth[1]; + All.Rcut[1] = RCUT * All.Asmth[1]; #endif /* #ifdef PLACEHIGHRESREGION */ #ifdef PLACEHIGHRESREGION if(2 * All.TotalMeshSize[1] / GRID < All.Rcut[0]) { - All.TotalMeshSize[1] = 2 * (meshinner[1] + 2 * All.Rcut[0]) * (GRID) / ((double) (GRID - 2)); + All.TotalMeshSize[1] = 2 * (meshinner[1] + 2 * All.Rcut[0]) * (GRID) / ((double)(GRID - 2)); for(i = 0; i < 3; i++) { - All.Corner[1][i] = All.Xmintot[1][i] - 1.0001 * All.Rcut[0]; + All.Corner[1][i] = All.Xmintot[1][i] - 1.0001 * All.Rcut[0]; All.UpperCorner[1][i] = All.Corner[1][i] + (GRID / 2 - 1) * (All.TotalMeshSize[1] / GRID); } if(2 * All.TotalMeshSize[1] / GRID > All.Rcut[0]) { - All.TotalMeshSize[1] = 2 * (meshinner[1] + 2 * All.Rcut[0]) * (GRID) / ((double) (GRID - 10)); + All.TotalMeshSize[1] = 2 * (meshinner[1] + 2 * All.Rcut[0]) * (GRID) / ((double)(GRID - 10)); for(i = 0; i < 3; i++) { - All.Corner[1][i] = All.Xmintot[1][i] - 1.0001 * (All.Rcut[0] + 2 * All.TotalMeshSize[1] / GRID); + All.Corner[1][i] = All.Xmintot[1][i] - 1.0001 * (All.Rcut[0] + 2 * All.TotalMeshSize[1] / GRID); All.UpperCorner[1][i] = All.Corner[1][i] + (GRID / 2 - 1) * (All.TotalMeshSize[1] / GRID); } } All.Asmth[1] = ASMTH * All.TotalMeshSize[1] / GRID; - All.Rcut[1] = RCUT * All.Asmth[1]; + All.Rcut[1] = RCUT * All.Asmth[1]; mpi_printf("PM-NONPERIODIC: All.Asmth[0]=%g All.Asmth[1]=%g\n", All.Asmth[0], All.Asmth[1]); } #endif /* #ifdef PLACEHIGHRESREGION */ #ifdef PLACEHIGHRESREGION - mpi_printf("PM-NONPERIODIC: Allowed region for isolated PM mesh (high-res): (%g|%g|%g) -> (%g|%g|%g) ext=%g totmeshsize=%g meshsize=%g\n\n", - All.Xmintot[1][0], All.Xmintot[1][1], All.Xmintot[1][2], All.Xmaxtot[1][0], All.Xmaxtot[1][1], All.Xmaxtot[1][2], meshinner[1], All.TotalMeshSize[1], All.TotalMeshSize[1] / GRID); + mpi_printf( + "PM-NONPERIODIC: Allowed region for isolated PM mesh (high-res): (%g|%g|%g) -> (%g|%g|%g) ext=%g totmeshsize=%g " + "meshsize=%g\n\n", + All.Xmintot[1][0], All.Xmintot[1][1], All.Xmintot[1][2], All.Xmaxtot[1][0], All.Xmaxtot[1][1], All.Xmaxtot[1][2], meshinner[1], + All.TotalMeshSize[1], All.TotalMeshSize[1] / GRID); #endif /* #ifdef PLACEHIGHRESREGION */ } - /*! \brief Initialization of the non-periodic PM routines. * * The plan-files for FFTW are created. Finally, the routine to set-up the @@ -264,43 +255,45 @@ void pm_init_regionsize(void) void pm_init_nonperiodic(void) { /* Set up the FFTW-3 plan files. */ - int ndim[1] = { GRID }; /* dimension of the 1D transforms */ + int ndim[1] = {GRID}; /* dimension of the 1D transforms */ /* temporarily allocate some arrays to make sure that out-of-place plans are created */ - rhogrid = (fft_real *) mymalloc("rhogrid", GRID2 * sizeof(fft_real)); - forcegrid = (fft_real *) mymalloc("forcegrid", GRID2 * sizeof(fft_real)); + rhogrid = (fft_real *)mymalloc("rhogrid", GRID2 * sizeof(fft_real)); + forcegrid = (fft_real *)mymalloc("forcegrid", GRID2 * sizeof(fft_real)); #ifdef DOUBLEPRECISION_FFTW int alignflag = 0; -#else /* #ifdef DOUBLEPRECISION_FFTW */ +#else /* #ifdef DOUBLEPRECISION_FFTW */ /* for single precision, the start of our FFT columns is presently only guaranteed to be 8-byte aligned */ int alignflag = FFTW_UNALIGNED; #endif /* #ifdef DOUBLEPRECISION_FFTW #else */ #ifndef FFT_COLUMN_BASED int stride = GRIDz; -#else /* #ifndef FFT_COLUMN_BASED */ - int stride = 1; +#else /* #ifndef FFT_COLUMN_BASED */ + int stride = 1; #endif /* #ifndef FFT_COLUMN_BASED #else */ - myplan.forward_plan_zdir = FFTW(plan_many_dft_r2c) (1, ndim, 1, rhogrid, 0, 1, GRID2, (fft_complex *) forcegrid, 0, 1, GRIDz, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + myplan.forward_plan_zdir = FFTW(plan_many_dft_r2c)(1, ndim, 1, rhogrid, 0, 1, GRID2, (fft_complex *)forcegrid, 0, 1, GRIDz, + FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myplan.forward_plan_xdir = - FFTW(plan_many_dft) (1, ndim, 1, (fft_complex *) rhogrid, 0, stride, GRIDz * GRID, (fft_complex *) forcegrid, 0, stride, GRIDz * GRID, FFTW_FORWARD, - FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + FFTW(plan_many_dft)(1, ndim, 1, (fft_complex *)rhogrid, 0, stride, GRIDz * GRID, (fft_complex *)forcegrid, 0, stride, + GRIDz * GRID, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myplan.forward_plan_ydir = - FFTW(plan_many_dft) (1, ndim, 1, (fft_complex *) rhogrid, 0, stride, GRIDz * GRID, (fft_complex *) forcegrid, 0, stride, GRIDz * GRID, FFTW_FORWARD, - FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + FFTW(plan_many_dft)(1, ndim, 1, (fft_complex *)rhogrid, 0, stride, GRIDz * GRID, (fft_complex *)forcegrid, 0, stride, + GRIDz * GRID, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); - myplan.backward_plan_zdir = FFTW(plan_many_dft_c2r) (1, ndim, 1, (fft_complex *) rhogrid, 0, 1, GRIDz, forcegrid, 0, 1, GRID2, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + myplan.backward_plan_zdir = FFTW(plan_many_dft_c2r)(1, ndim, 1, (fft_complex *)rhogrid, 0, 1, GRIDz, forcegrid, 0, 1, GRID2, + FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myplan.backward_plan_xdir = - FFTW(plan_many_dft) (1, ndim, 1, (fft_complex *) rhogrid, 0, stride, GRIDz * GRID, (fft_complex *) forcegrid, 0, stride, GRIDz * GRID, FFTW_BACKWARD, - FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + FFTW(plan_many_dft)(1, ndim, 1, (fft_complex *)rhogrid, 0, stride, GRIDz * GRID, (fft_complex *)forcegrid, 0, stride, + GRIDz * GRID, FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myplan.backward_plan_ydir = - FFTW(plan_many_dft) (1, ndim, 1, (fft_complex *) rhogrid, 0, stride, GRIDz * GRID, (fft_complex *) forcegrid, 0, stride, GRIDz * GRID, FFTW_BACKWARD, - FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + FFTW(plan_many_dft)(1, ndim, 1, (fft_complex *)rhogrid, 0, stride, GRIDz * GRID, (fft_complex *)forcegrid, 0, stride, + GRIDz * GRID, FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myfree(forcegrid); myfree(rhogrid); @@ -309,7 +302,7 @@ void pm_init_nonperiodic(void) my_slab_based_fft_init(&myplan, GRID, GRID, GRID); - maxfftsize = myplan.largest_x_slab * GRID * ((size_t) GRID2); + maxfftsize = myplan.largest_x_slab * GRID * ((size_t)GRID2); #else /* #ifndef FFT_COLUMN_BASED */ @@ -324,21 +317,20 @@ void pm_init_nonperiodic(void) size_t bytes, bytes_tot = 0; #if defined(GRAVITY_NOT_PERIODIC) - kernel[0] = (fft_real *) mymalloc("kernel[0]", bytes = maxfftsize * sizeof(fft_real)); + kernel[0] = (fft_real *)mymalloc("kernel[0]", bytes = maxfftsize * sizeof(fft_real)); bytes_tot += bytes; - fft_of_kernel[0] = (fft_complex *) kernel[0]; + fft_of_kernel[0] = (fft_complex *)kernel[0]; #endif /* #if defined(GRAVITY_NOT_PERIODIC) */ #if defined(PLACEHIGHRESREGION) - kernel[1] = (fft_real *) mymalloc("kernel[1]", bytes = maxfftsize * sizeof(fft_real)); + kernel[1] = (fft_real *)mymalloc("kernel[1]", bytes = maxfftsize * sizeof(fft_real)); bytes_tot += bytes; - fft_of_kernel[1] = (fft_complex *) kernel[1]; + fft_of_kernel[1] = (fft_complex *)kernel[1]; #endif /* #if defined(PLACEHIGHRESREGION) */ mpi_printf("\nPM-NONPERIODIC: Allocated %g MByte for FFT kernel(s).\n\n", bytes_tot / (1024.0 * 1024.0)); } - #ifdef PLACEHIGHRESREGION /*! \brief Is this a high res particle in high resolution region? * @@ -349,7 +341,7 @@ void pm_init_nonperiodic(void) * * \return 0: not high res; 1: high res. */ -int pmforce_is_particle_high_res(int type, MyDouble * Pos) +int pmforce_is_particle_high_res(int type, MyDouble *Pos) { int flag = 1; @@ -368,7 +360,7 @@ int pmforce_is_particle_high_res(int type, MyDouble * Pos) for(int j = 0; j < 3; j++) if(Pos[j] < All.Xmintot[1][j] || Pos[j] > All.Xmaxtot[1][j]) { - flag = 0; /* we are outside */ + flag = 0; /* we are outside */ break; } @@ -378,14 +370,11 @@ int pmforce_is_particle_high_res(int type, MyDouble * Pos) } #endif /* #ifdef PLACEHIGHRESREGION */ - - #ifdef PM_ZOOM_OPTIMIZED -static void mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp) (const void *, const void *)); +static void mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp)(const void *, const void *)); static int pm_periodic_compare_sortindex(const void *a, const void *b); - /*! \brief This structure links the particles to the mesh cells, to which they * contribute their mass. * @@ -395,17 +384,18 @@ static int pm_periodic_compare_sortindex(const void *a, const void *b); */ static struct part_slab_data { - large_array_offset globalindex; /*!< index in the global density mesh */ - large_numpart_type partindex; /*!< contains the local particle index shifted by 2^3, the first three bits encode to which part of the CIC assignment this item belongs to */ - large_array_offset localindex; /*!< index to a local copy of the corresponding mesh cell of the global density array (used during local mass and force assignment) */ -} *part; /*!< array of part_slab_data linking the local particles to their mesh cells */ + large_array_offset globalindex; /*!< index in the global density mesh */ + large_numpart_type partindex; /*!< contains the local particle index shifted by 2^3, the first three bits encode to which part of the + CIC assignment this item belongs to */ + large_array_offset localindex; /*!< index to a local copy of the corresponding mesh cell of the global density array (used during + local mass and force assignment) */ +} * part; /*!< array of part_slab_data linking the local particles to their mesh cells */ static size_t *localfield_sendcount, *localfield_first, *localfield_offset, *localfield_recvcount; static large_array_offset *localfield_globalindex, *import_globalindex; static fft_real *localfield_data, *import_data; static large_numpart_type num_on_grid; - /*! \brief Prepares density field for nonperiodic FFTs. * * \param[in] grnr (0, 1) 0 if full mesh, 1 if highres grid. @@ -420,8 +410,8 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) double to_slab_fac = GRID / All.TotalMeshSize[grnr]; - part = (struct part_slab_data *) mymalloc("part", 8 * (NumPart * sizeof(struct part_slab_data))); - large_numpart_type *part_sortindex = (large_numpart_type *) mymalloc("part_sortindex", 8 * (NumPart * sizeof(large_numpart_type))); + part = (struct part_slab_data *)mymalloc("part", 8 * (NumPart * sizeof(struct part_slab_data))); + large_numpart_type *part_sortindex = (large_numpart_type *)mymalloc("part_sortindex", 8 * (NumPart * sizeof(large_numpart_type))); int ngrid = 0; @@ -444,9 +434,9 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) if(pos[2] < All.Corner[grnr][2] || pos[2] >= All.UpperCorner[grnr][2]) continue; - int slab_x = (int) (to_slab_fac * (pos[0] - All.Corner[grnr][0])); - int slab_y = (int) (to_slab_fac * (pos[1] - All.Corner[grnr][1])); - int slab_z = (int) (to_slab_fac * (pos[2] - All.Corner[grnr][2])); + int slab_x = (int)(to_slab_fac * (pos[0] - All.Corner[grnr][0])); + int slab_y = (int)(to_slab_fac * (pos[1] - All.Corner[grnr][1])); + int slab_z = (int)(to_slab_fac * (pos[2] - All.Corner[grnr][2])); int myngrid; { @@ -454,7 +444,7 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) ngrid += 1; } - large_numpart_type index_on_grid = ((large_numpart_type) myngrid) * 8; + large_numpart_type index_on_grid = ((large_numpart_type)myngrid) * 8; int xx, yy, zz; @@ -475,15 +465,15 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) large_array_offset offset = FI(slab_xx, slab_yy, slab_zz); - part[index_on_grid].partindex = (i << 3) + (xx << 2) + (yy << 1) + zz; + part[index_on_grid].partindex = (i << 3) + (xx << 2) + (yy << 1) + zz; part[index_on_grid].globalindex = offset; - part_sortindex[index_on_grid] = index_on_grid; + part_sortindex[index_on_grid] = index_on_grid; index_on_grid++; } } /* note: num_on_grid will be 8 times larger than the particle number, but num_field_points will generally be much smaller */ - num_on_grid = ((large_numpart_type) ngrid) * 8; + num_on_grid = ((large_numpart_type)ngrid) * 8; /* bring the part-field into the order of the accessed cells. This allows the removal of duplicates */ mysort_pmperiodic(part_sortindex, num_on_grid, sizeof(large_numpart_type), pm_periodic_compare_sortindex); @@ -503,16 +493,17 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) } /* allocate the local field */ - localfield_globalindex = (large_array_offset *) mymalloc_movable(&localfield_globalindex, "localfield_globalindex", num_field_points * sizeof(large_array_offset)); - localfield_data = (fft_real *) mymalloc_movable(&localfield_data, "localfield_data", num_field_points * sizeof(fft_real)); - localfield_first = (size_t *) mymalloc_movable(&localfield_first, "localfield_first", NTask * sizeof(size_t)); - localfield_sendcount = (size_t *) mymalloc_movable(&localfield_sendcount, "localfield_sendcount", NTask * sizeof(size_t)); - localfield_offset = (size_t *) mymalloc_movable(&localfield_offset, "localfield_offset", NTask * sizeof(size_t)); - localfield_recvcount = (size_t *) mymalloc_movable(&localfield_recvcount, "localfield_recvcount", NTask * sizeof(size_t)); + localfield_globalindex = (large_array_offset *)mymalloc_movable(&localfield_globalindex, "localfield_globalindex", + num_field_points * sizeof(large_array_offset)); + localfield_data = (fft_real *)mymalloc_movable(&localfield_data, "localfield_data", num_field_points * sizeof(fft_real)); + localfield_first = (size_t *)mymalloc_movable(&localfield_first, "localfield_first", NTask * sizeof(size_t)); + localfield_sendcount = (size_t *)mymalloc_movable(&localfield_sendcount, "localfield_sendcount", NTask * sizeof(size_t)); + localfield_offset = (size_t *)mymalloc_movable(&localfield_offset, "localfield_offset", NTask * sizeof(size_t)); + localfield_recvcount = (size_t *)mymalloc_movable(&localfield_recvcount, "localfield_recvcount", NTask * sizeof(size_t)); for(i = 0; i < NTask; i++) { - localfield_first[i] = 0; + localfield_first[i] = 0; localfield_sendcount[i] = 0; } @@ -536,7 +527,7 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) #ifndef FFT_COLUMN_BASED int slab = part[part_sortindex[i]].globalindex / (GRID * GRID2); int task = myplan.slab_to_task[slab]; -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ int task, column = part[part_sortindex[i]].globalindex / (GRID2); if(column < myplan.pivotcol) @@ -575,9 +566,9 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) #endif /* #ifdef CELL_CENTER_GRAVITY */ pos = P[pindex].Pos; - int slab_x = (int) (to_slab_fac * (pos[0] - All.Corner[grnr][0])); - int slab_y = (int) (to_slab_fac * (pos[1] - All.Corner[grnr][1])); - int slab_z = (int) (to_slab_fac * (pos[2] - All.Corner[grnr][2])); + int slab_x = (int)(to_slab_fac * (pos[0] - All.Corner[grnr][0])); + int slab_y = (int)(to_slab_fac * (pos[1] - All.Corner[grnr][1])); + int slab_z = (int)(to_slab_fac * (pos[2] - All.Corner[grnr][2])); double dx = to_slab_fac * (pos[0] - All.Corner[grnr][0]) - slab_x; double dy = to_slab_fac * (pos[1] - All.Corner[grnr][1]) - slab_y; @@ -591,11 +582,11 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) localfield_data[part[i + 3].localindex] += weight * (1.0 - dx) * dy * dz; localfield_data[part[i + 4].localindex] += weight * (dx) * (1.0 - dy) * (1.0 - dz); localfield_data[part[i + 5].localindex] += weight * (dx) * (1.0 - dy) * dz; - localfield_data[part[i + 6].localindex] += weight * (dx) * dy * (1.0 - dz); - localfield_data[part[i + 7].localindex] += weight * (dx) * dy * dz; + localfield_data[part[i + 6].localindex] += weight * (dx)*dy * (1.0 - dz); + localfield_data[part[i + 7].localindex] += weight * (dx)*dy * dz; } - rhogrid = (fft_real *) mymalloc("rhogrid", maxfftsize * sizeof(fft_real)); + rhogrid = (fft_real *)mymalloc("rhogrid", maxfftsize * sizeof(fft_real)); /* clear local FFT-mesh density field */ large_array_offset ii; @@ -613,23 +604,25 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) { if(level > 0) { - import_data = (fft_real *) mymalloc("import_data", localfield_recvcount[recvTask] * sizeof(fft_real)); - import_globalindex = (large_array_offset *) mymalloc("import_globalindex", localfield_recvcount[recvTask] * sizeof(large_array_offset)); + import_data = (fft_real *)mymalloc("import_data", localfield_recvcount[recvTask] * sizeof(fft_real)); + import_globalindex = + (large_array_offset *)mymalloc("import_globalindex", localfield_recvcount[recvTask] * sizeof(large_array_offset)); if(localfield_sendcount[recvTask] > 0 || localfield_recvcount[recvTask] > 0) { - myMPI_Sendrecv(localfield_data + localfield_offset[recvTask], - localfield_sendcount[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, import_data, localfield_recvcount[recvTask] * sizeof(fft_real), MPI_BYTE, - recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); + myMPI_Sendrecv(localfield_data + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(fft_real), + MPI_BYTE, recvTask, TAG_NONPERIOD_A, import_data, localfield_recvcount[recvTask] * sizeof(fft_real), + MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); myMPI_Sendrecv(localfield_globalindex + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_B, - import_globalindex, localfield_recvcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_B, MPI_COMM_WORLD, &status); + import_globalindex, localfield_recvcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_B, MPI_COMM_WORLD, &status); } } else { - import_data = localfield_data + localfield_offset[ThisTask]; + import_data = localfield_data + localfield_offset[ThisTask]; import_globalindex = localfield_globalindex + localfield_offset[ThisTask]; } @@ -638,9 +631,10 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) { /* determine offset in local FFT slab */ #ifndef FFT_COLUMN_BASED - large_array_offset offset = import_globalindex[i] - myplan.first_slab_x_of_task[ThisTask] * GRID * ((large_array_offset) GRID2); -#else /* #ifndef FFT_COLUMN_BASED */ - large_array_offset offset = import_globalindex[i] - myplan.base_firstcol * ((large_array_offset) GRID2); + large_array_offset offset = + import_globalindex[i] - myplan.first_slab_x_of_task[ThisTask] * GRID * ((large_array_offset)GRID2); +#else /* #ifndef FFT_COLUMN_BASED */ + large_array_offset offset = import_globalindex[i] - myplan.base_firstcol * ((large_array_offset)GRID2); #endif /* #ifndef FFT_COLUMN_BASED #else */ rhogrid[offset] += import_data[i]; } @@ -654,7 +648,6 @@ void pmforce_nonperiodic_zoom_optimized_prepare_density(int grnr) } } - /*! \brief Reads out the force component corresponding to spatial dimension * 'dim'. * @@ -695,37 +688,40 @@ void pmforce_nonperiodic_zoom_optimized_readout_forces_or_potential(int grnr, in { if(level > 0) { - import_data = (fft_real *) mymalloc("import_data", localfield_recvcount[recvTask] * sizeof(fft_real)); - import_globalindex = (large_array_offset *) mymalloc("import_globalindex", localfield_recvcount[recvTask] * sizeof(large_array_offset)); + import_data = (fft_real *)mymalloc("import_data", localfield_recvcount[recvTask] * sizeof(fft_real)); + import_globalindex = + (large_array_offset *)mymalloc("import_globalindex", localfield_recvcount[recvTask] * sizeof(large_array_offset)); if(localfield_sendcount[recvTask] > 0 || localfield_recvcount[recvTask] > 0) { myMPI_Sendrecv(localfield_globalindex + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_C, - import_globalindex, localfield_recvcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_C, MPI_COMM_WORLD, &status); + import_globalindex, localfield_recvcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_C, MPI_COMM_WORLD, &status); } } else { - import_data = localfield_data + localfield_offset[ThisTask]; + import_data = localfield_data + localfield_offset[ThisTask]; import_globalindex = localfield_globalindex + localfield_offset[ThisTask]; } for(i = 0; i < localfield_recvcount[recvTask]; i++) { #ifndef FFT_COLUMN_BASED - large_array_offset offset = import_globalindex[i] - myplan.first_slab_x_of_task[ThisTask] * GRID * ((large_array_offset) GRID2); -#else /* #ifndef FFT_COLUMN_BASED */ - large_array_offset offset = import_globalindex[i] - myplan.base_firstcol * ((large_array_offset) GRID2); + large_array_offset offset = + import_globalindex[i] - myplan.first_slab_x_of_task[ThisTask] * GRID * ((large_array_offset)GRID2); +#else /* #ifndef FFT_COLUMN_BASED */ + large_array_offset offset = import_globalindex[i] - myplan.base_firstcol * ((large_array_offset)GRID2); #endif /* #ifndef FFT_COLUMN_BASED #else */ import_data[i] = grid[offset]; } if(level > 0) { - myMPI_Sendrecv(import_data, localfield_recvcount[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, - TAG_NONPERIOD_A, localfield_data + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, - &status); + myMPI_Sendrecv(import_data, localfield_recvcount[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, + localfield_data + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(fft_real), + MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); myfree(import_globalindex); myfree(import_data); @@ -739,7 +735,7 @@ void pmforce_nonperiodic_zoom_optimized_readout_forces_or_potential(int grnr, in for(k = 0; k < ngrid; k++) { - large_numpart_type j = (((large_numpart_type) k) << 3); + large_numpart_type j = (((large_numpart_type)k) << 3); int i = (part[j].partindex >> 3); @@ -758,22 +754,23 @@ void pmforce_nonperiodic_zoom_optimized_readout_forces_or_potential(int grnr, in continue; #endif /* #ifdef PLACEHIGHRESREGION */ - int slab_x = (int) (to_slab_fac * (pos[0] - All.Corner[grnr][0])); - double dx = to_slab_fac * (pos[0] - All.Corner[grnr][0]) - slab_x; + int slab_x = (int)(to_slab_fac * (pos[0] - All.Corner[grnr][0])); + double dx = to_slab_fac * (pos[0] - All.Corner[grnr][0]) - slab_x; - int slab_y = (int) (to_slab_fac * (pos[1] - All.Corner[grnr][1])); - double dy = to_slab_fac * (pos[1] - All.Corner[grnr][1]) - slab_y; + int slab_y = (int)(to_slab_fac * (pos[1] - All.Corner[grnr][1])); + double dy = to_slab_fac * (pos[1] - All.Corner[grnr][1]) - slab_y; - int slab_z = (int) (to_slab_fac * (pos[2] - All.Corner[grnr][2])); - double dz = to_slab_fac * (pos[2] - All.Corner[grnr][2]) - slab_z; + int slab_z = (int)(to_slab_fac * (pos[2] - All.Corner[grnr][2])); + double dz = to_slab_fac * (pos[2] - All.Corner[grnr][2]) - slab_z; - double value = +localfield_data[part[j + 0].localindex] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) - + localfield_data[part[j + 1].localindex] * (1.0 - dx) * (1.0 - dy) * dz - + localfield_data[part[j + 2].localindex] * (1.0 - dx) * dy * (1.0 - dz) - + localfield_data[part[j + 3].localindex] * (1.0 - dx) * dy * dz - + localfield_data[part[j + 4].localindex] * (dx) * (1.0 - dy) * (1.0 - dz) - + localfield_data[part[j + 5].localindex] * (dx) * (1.0 - dy) * dz + localfield_data[part[j + 6].localindex] * (dx) * dy * (1.0 - dz) + - localfield_data[part[j + 7].localindex] * (dx) * dy * dz; + double value = +localfield_data[part[j + 0].localindex] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) + + localfield_data[part[j + 1].localindex] * (1.0 - dx) * (1.0 - dy) * dz + + localfield_data[part[j + 2].localindex] * (1.0 - dx) * dy * (1.0 - dz) + + localfield_data[part[j + 3].localindex] * (1.0 - dx) * dy * dz + + localfield_data[part[j + 4].localindex] * (dx) * (1.0 - dy) * (1.0 - dz) + + localfield_data[part[j + 5].localindex] * (dx) * (1.0 - dy) * dz + + localfield_data[part[j + 6].localindex] * (dx)*dy * (1.0 - dz) + + localfield_data[part[j + 7].localindex] * (dx)*dy * dz; if(dim < 0) { @@ -786,26 +783,23 @@ void pmforce_nonperiodic_zoom_optimized_readout_forces_or_potential(int grnr, in } } - #else /* #ifdef PM_ZOOM_OPTIMIZED */ /* Here come the routines for a different communication algorithm that is better suited for a homogenuously loaded boxes. */ - /*! \brief Particle buffer structure */ static struct partbuf { MyFloat Mass; MyFloat Pos[3]; -} *partin, *partout; +} * partin, *partout; static size_t nimport, nexport; static size_t *Sndpm_count, *Sndpm_offset; static size_t *Rcvpm_count, *Rcvpm_offset; - /*! \brief Prepares density for pm calculation in algorithm optimized for * uniform densities. * @@ -824,9 +818,9 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) */ int multiNtask = roundup_to_multiple_of_cacheline_size(NTask * sizeof(size_t)) / sizeof(size_t); - Sndpm_count = mymalloc("Sndpm_count", MaxThreads * multiNtask * sizeof(size_t)); + Sndpm_count = mymalloc("Sndpm_count", MaxThreads * multiNtask * sizeof(size_t)); Sndpm_offset = mymalloc("Sndpm_offset", MaxThreads * multiNtask * sizeof(size_t)); - Rcvpm_count = mymalloc("Rcvpm_count", NTask * sizeof(size_t)); + Rcvpm_count = mymalloc("Rcvpm_count", NTask * sizeof(size_t)); Rcvpm_offset = mymalloc("Rcvpm_offset", NTask * sizeof(size_t)); /* determine the slabs/columns each particles accesses */ @@ -855,18 +849,18 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) if(pos[2] < All.Corner[grnr][2] || pos[2] >= All.UpperCorner[grnr][2]) continue; - int slab_x = (int) (to_slab_fac * (pos[0] - All.Corner[grnr][0])); + int slab_x = (int)(to_slab_fac * (pos[0] - All.Corner[grnr][0])); int slab_xx = slab_x + 1; #ifndef FFT_COLUMN_BASED - int task0 = myplan.slab_to_task[slab_x]; - int task1 = myplan.slab_to_task[slab_xx]; + int task0 = myplan.slab_to_task[slab_x]; + int task1 = myplan.slab_to_task[slab_xx]; send_count[task0]++; if(task0 != task1) send_count[task1]++; -#else /* #ifndef FFT_COLUMN_BASED */ - int slab_y = (int) (to_slab_fac * (pos[1] - All.Corner[grnr][1])); +#else /* #ifndef FFT_COLUMN_BASED */ + int slab_y = (int)(to_slab_fac * (pos[1] - All.Corner[grnr][1])); int slab_yy = slab_y + 1; int column0 = slab_x * GRID + slab_y; @@ -942,11 +936,11 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) } /* allocate import and export buffer */ - partin = (struct partbuf *) mymalloc("partin", nimport * sizeof(struct partbuf)); - partout = (struct partbuf *) mymalloc("partout", nexport * sizeof(struct partbuf)); + partin = (struct partbuf *)mymalloc("partin", nimport * sizeof(struct partbuf)); + partout = (struct partbuf *)mymalloc("partout", nexport * sizeof(struct partbuf)); { - size_t *send_count = Sndpm_count + get_thread_num() * multiNtask; + size_t *send_count = Sndpm_count + get_thread_num() * multiNtask; size_t *send_offset = Sndpm_offset + get_thread_num() * multiNtask; for(j = 0; j < NTask; j++) @@ -971,27 +965,27 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) if(pos[2] < All.Corner[grnr][2] || pos[2] >= All.UpperCorner[grnr][2]) continue; - int slab_x = (int) (to_slab_fac * (pos[0] - All.Corner[grnr][0])); + int slab_x = (int)(to_slab_fac * (pos[0] - All.Corner[grnr][0])); int slab_xx = slab_x + 1; #ifndef FFT_COLUMN_BASED - int task0 = myplan.slab_to_task[slab_x]; - int task1 = myplan.slab_to_task[slab_xx]; + int task0 = myplan.slab_to_task[slab_x]; + int task1 = myplan.slab_to_task[slab_xx]; - size_t ind0 = send_offset[task0] + send_count[task0]++; + size_t ind0 = send_offset[task0] + send_count[task0]++; partout[ind0].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind0].Pos[j] = pos[j]; if(task0 != task1) { - size_t ind1 = send_offset[task1] + send_count[task1]++; + size_t ind1 = send_offset[task1] + send_count[task1]++; partout[ind1].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind1].Pos[j] = pos[j]; } -#else /* #ifndef FFT_COLUMN_BASED */ - int slab_y = (int) (to_slab_fac * (pos[1] - All.Corner[grnr][1])); +#else /* #ifndef FFT_COLUMN_BASED */ + int slab_y = (int)(to_slab_fac * (pos[1] - All.Corner[grnr][1])); int slab_yy = slab_y + 1; int column0 = slab_x * GRID + slab_y; @@ -1021,28 +1015,28 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) else task3 = (column3 - myplan.pivotcol) / (myplan.avg - 1) + myplan.tasklastsection; - size_t ind0 = send_offset[task0] + send_count[task0]++; + size_t ind0 = send_offset[task0] + send_count[task0]++; partout[ind0].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind0].Pos[j] = pos[j]; if(task1 != task0) { - size_t ind1 = send_offset[task1] + send_count[task1]++; + size_t ind1 = send_offset[task1] + send_count[task1]++; partout[ind1].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind1].Pos[j] = pos[j]; } if(task2 != task1 && task2 != task0) { - size_t ind2 = send_offset[task2] + send_count[task2]++; + size_t ind2 = send_offset[task2] + send_count[task2]++; partout[ind2].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind2].Pos[j] = pos[j]; } if(task3 != task0 && task3 != task1 && task3 != task2) { - size_t ind3 = send_offset[task3] + send_count[task3]++; + size_t ind3 = send_offset[task3] + send_count[task3]++; partout[ind3].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind3].Pos[j] = pos[j]; @@ -1067,12 +1061,13 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) MPI_Allreduce(&flag_big, &flag_big_all, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); /* exchange particle data */ - myMPI_Alltoallv(partout, Sndpm_count, Sndpm_offset, partin, Rcvpm_count, Rcvpm_offset, sizeof(struct partbuf), flag_big_all, MPI_COMM_WORLD); + myMPI_Alltoallv(partout, Sndpm_count, Sndpm_offset, partin, Rcvpm_count, Rcvpm_offset, sizeof(struct partbuf), flag_big_all, + MPI_COMM_WORLD); myfree(partout); /* allocate density field */ - rhogrid = (fft_real *) mymalloc("rhogrid", maxfftsize * sizeof(fft_real)); + rhogrid = (fft_real *)mymalloc("rhogrid", maxfftsize * sizeof(fft_real)); /* clear local FFT-mesh density field */ large_array_offset ii; @@ -1091,9 +1086,9 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) for(i = 0; i < nimport; i++) { - int slab_y = (int) (to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1])); + int slab_y = (int)(to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1])); int slab_yy = slab_y + 1; - double dy = to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1]) - slab_y; + double dy = to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1]) - slab_y; int flag_slab_y, flag_slab_yy; if(slab_y >= first_y && slab_y <= last_y) @@ -1110,8 +1105,8 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) { double mass = partin[i].Mass; - int slab_x = (int) (to_slab_fac * (partin[i].Pos[0] - All.Corner[grnr][0])); - int slab_z = (int) (to_slab_fac * (partin[i].Pos[2] - All.Corner[grnr][2])); + int slab_x = (int)(to_slab_fac * (partin[i].Pos[0] - All.Corner[grnr][0])); + int slab_z = (int)(to_slab_fac * (partin[i].Pos[2] - All.Corner[grnr][2])); int slab_xx = slab_x + 1; int slab_zz = slab_z + 1; @@ -1175,16 +1170,16 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) { int col0, col1, col2, col3; double dx, dy; - } *aux; + } * aux; aux = mymalloc("aux", nimport * sizeof(struct data_cols)); for(i = 0; i < nimport; i++) { - int slab_x = (int) (to_slab_fac * (partin[i].Pos[0] - All.Corner[grnr][0])); + int slab_x = (int)(to_slab_fac * (partin[i].Pos[0] - All.Corner[grnr][0])); int slab_xx = slab_x + 1; - int slab_y = (int) (to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1])); + int slab_y = (int)(to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1])); int slab_yy = slab_y + 1; aux[i].dx = to_slab_fac * (partin[i].Pos[0] - All.Corner[grnr][0]) - slab_x; @@ -1240,7 +1235,7 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) double dx = aux[i].dx; double dy = aux[i].dy; - int slab_z = (int) (to_slab_fac * (partin[i].Pos[2] - All.Corner[grnr][2])); + int slab_z = (int)(to_slab_fac * (partin[i].Pos[2] - All.Corner[grnr][2])); int slab_zz = slab_z + 1; double dz = to_slab_fac * (partin[i].Pos[2] - All.Corner[grnr][2]) - slab_z; @@ -1277,7 +1272,6 @@ void pmforce_nonperiodic_uniform_optimized_prepare_density(int grnr) #endif /* #ifndef FFT_COLUMN_BASED #else */ } - /*! \brief If dim<0, this function reads out the potential, otherwise * Cartesian force components. * @@ -1295,8 +1289,8 @@ void pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(int grnr, double to_slab_fac = GRID / All.TotalMeshSize[grnr]; - double *flistin = (double *) mymalloc("flistin", nimport * sizeof(double)); - double *flistout = (double *) mymalloc("flistout", nexport * sizeof(double)); + double *flistin = (double *)mymalloc("flistin", nimport * sizeof(double)); + double *flistout = (double *)mymalloc("flistout", nexport * sizeof(double)); fft_real *grid; @@ -1310,9 +1304,9 @@ void pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(int grnr, { flistin[i] = 0; - int slab_x = (int) (to_slab_fac * (partin[i].Pos[0] - All.Corner[grnr][0])); - int slab_y = (int) (to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1])); - int slab_z = (int) (to_slab_fac * (partin[i].Pos[2] - All.Corner[grnr][2])); + int slab_x = (int)(to_slab_fac * (partin[i].Pos[0] - All.Corner[grnr][0])); + int slab_y = (int)(to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1])); + int slab_z = (int)(to_slab_fac * (partin[i].Pos[2] - All.Corner[grnr][2])); double dx = to_slab_fac * (partin[i].Pos[0] - All.Corner[grnr][0]) - slab_x; double dy = to_slab_fac * (partin[i].Pos[1] - All.Corner[grnr][1]) - slab_y; @@ -1327,22 +1321,22 @@ void pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(int grnr, { slab_x -= myplan.first_slab_x_of_task[ThisTask]; - flistin[i] += +grid[FI(slab_x, slab_y, slab_z)] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) - + grid[FI(slab_x, slab_y, slab_zz)] * (1.0 - dx) * (1.0 - dy) * (dz) - + grid[FI(slab_x, slab_yy, slab_z)] * (1.0 - dx) * (dy) * (1.0 - dz) - + grid[FI(slab_x, slab_yy, slab_zz)] * (1.0 - dx) * (dy) * (dz); + flistin[i] += +grid[FI(slab_x, slab_y, slab_z)] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) + + grid[FI(slab_x, slab_y, slab_zz)] * (1.0 - dx) * (1.0 - dy) * (dz) + + grid[FI(slab_x, slab_yy, slab_z)] * (1.0 - dx) * (dy) * (1.0 - dz) + + grid[FI(slab_x, slab_yy, slab_zz)] * (1.0 - dx) * (dy) * (dz); } if(myplan.slab_to_task[slab_xx] == ThisTask) { slab_xx -= myplan.first_slab_x_of_task[ThisTask]; - flistin[i] += +grid[FI(slab_xx, slab_y, slab_z)] * (dx) * (1.0 - dy) * (1.0 - dz) - + grid[FI(slab_xx, slab_y, slab_zz)] * (dx) * (1.0 - dy) * (dz) - + grid[FI(slab_xx, slab_yy, slab_z)] * (dx) * (dy) * (1.0 - dz) - + grid[FI(slab_xx, slab_yy, slab_zz)] * (dx) * (dy) * (dz); + flistin[i] += +grid[FI(slab_xx, slab_y, slab_z)] * (dx) * (1.0 - dy) * (1.0 - dz) + + grid[FI(slab_xx, slab_y, slab_zz)] * (dx) * (1.0 - dy) * (dz) + + grid[FI(slab_xx, slab_yy, slab_z)] * (dx) * (dy) * (1.0 - dz) + + grid[FI(slab_xx, slab_yy, slab_zz)] * (dx) * (dy) * (dz); } -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ int column0 = slab_x * GRID + slab_y; int column1 = slab_x * GRID + slab_yy; int column2 = slab_xx * GRID + slab_y; @@ -1350,16 +1344,19 @@ void pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(int grnr, if(column0 >= myplan.base_firstcol && column0 <= myplan.base_lastcol) { - flistin[i] += +grid[FC(column0, slab_z)] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) + grid[FC(column0, slab_zz)] * (1.0 - dx) * (1.0 - dy) * (dz); + flistin[i] += +grid[FC(column0, slab_z)] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) + + grid[FC(column0, slab_zz)] * (1.0 - dx) * (1.0 - dy) * (dz); } if(column1 >= myplan.base_firstcol && column1 <= myplan.base_lastcol) { - flistin[i] += +grid[FC(column1, slab_z)] * (1.0 - dx) * (dy) * (1.0 - dz) + grid[FC(column1, slab_zz)] * (1.0 - dx) * (dy) * (dz); + flistin[i] += + +grid[FC(column1, slab_z)] * (1.0 - dx) * (dy) * (1.0 - dz) + grid[FC(column1, slab_zz)] * (1.0 - dx) * (dy) * (dz); } if(column2 >= myplan.base_firstcol && column2 <= myplan.base_lastcol) { - flistin[i] += +grid[FC(column2, slab_z)] * (dx) * (1.0 - dy) * (1.0 - dz) + grid[FC(column2, slab_zz)] * (dx) * (1.0 - dy) * (dz); + flistin[i] += + +grid[FC(column2, slab_z)] * (dx) * (1.0 - dy) * (1.0 - dz) + grid[FC(column2, slab_zz)] * (dx) * (1.0 - dy) * (dz); } if(column3 >= myplan.base_firstcol && column3 <= myplan.base_lastcol) @@ -1381,14 +1378,14 @@ void pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(int grnr, MPI_Allreduce(&flag_big, &flag_big_all, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); /* exchange data */ - myMPI_Alltoallv(flistin, Rcvpm_count, Rcvpm_offset, flistout, Sndpm_count, Sndpm_offset, sizeof(double), flag_big_all, MPI_COMM_WORLD); - + myMPI_Alltoallv(flistin, Rcvpm_count, Rcvpm_offset, flistout, Sndpm_count, Sndpm_offset, sizeof(double), flag_big_all, + MPI_COMM_WORLD); /* now assign them to the correct particles */ int multiNtask = roundup_to_multiple_of_cacheline_size(NTask * sizeof(size_t)) / sizeof(size_t); { - size_t *send_count = Sndpm_count + get_thread_num() * multiNtask; + size_t *send_count = Sndpm_count + get_thread_num() * multiNtask; size_t *send_offset = Sndpm_offset + get_thread_num() * multiNtask; int j; @@ -1414,19 +1411,19 @@ void pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(int grnr, if(pos[2] < All.Corner[grnr][2] || pos[2] >= All.UpperCorner[grnr][2]) continue; - int slab_x = (int) (to_slab_fac * (pos[0] - All.Corner[grnr][0])); + int slab_x = (int)(to_slab_fac * (pos[0] - All.Corner[grnr][0])); int slab_xx = slab_x + 1; #ifndef FFT_COLUMN_BASED - int task0 = myplan.slab_to_task[slab_x]; - int task1 = myplan.slab_to_task[slab_xx]; + int task0 = myplan.slab_to_task[slab_x]; + int task1 = myplan.slab_to_task[slab_xx]; double value = flistout[send_offset[task0] + send_count[task0]++]; if(task0 != task1) value += flistout[send_offset[task1] + send_count[task1]++]; -#else /* #ifndef FFT_COLUMN_BASED */ - int slab_y = (int) (to_slab_fac * (pos[1] - All.Corner[grnr][1])); +#else /* #ifndef FFT_COLUMN_BASED */ + int slab_y = (int)(to_slab_fac * (pos[1] - All.Corner[grnr][1])); int slab_yy = slab_y + 1; int column0 = slab_x * GRID + slab_y; @@ -1496,7 +1493,6 @@ void pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(int grnr, } #endif /* #ifdef PM_ZOOM_OPTIMIZED #else */ - /*! \brief Calculates the long-range non-periodic forces using the PM method. * * The potential is Gaussian filtered with Asmth, given in mesh-cell units. @@ -1515,15 +1511,16 @@ int pmforce_nonperiodic(int grnr) double tstart = second(); - mpi_printf("PM-NONPERIODIC: Starting non-periodic PM calculation (grid=%d) presently allocated=%g MB).\n", grnr, AllocatedBytes / (1024.0 * 1024.0)); + mpi_printf("PM-NONPERIODIC: Starting non-periodic PM calculation (grid=%d) presently allocated=%g MB).\n", grnr, + AllocatedBytes / (1024.0 * 1024.0)); #ifndef NUMPART_PER_TASK_LARGE - if((((long long) NumPart) << 3) >= (((long long) 1) << 31)) + if((((long long)NumPart) << 3) >= (((long long)1) << 31)) terminate("We are dealing with a too large particle number per MPI rank - enabling NUMPART_PER_TASK_LARGE might help."); #endif /* #ifndef NUMPART_PER_TASK_LARGE */ - double fac = All.G / pow(All.TotalMeshSize[grnr], 4) * pow(All.TotalMeshSize[grnr] / GRID, 3); /* to get potential */ - fac *= 1 / (2 * All.TotalMeshSize[grnr] / GRID); /* for finite differencing */ + double fac = All.G / pow(All.TotalMeshSize[grnr], 4) * pow(All.TotalMeshSize[grnr] / GRID, 3); /* to get potential */ + fac *= 1 / (2 * All.TotalMeshSize[grnr] / GRID); /* for finite differencing */ /* first, check whether all particles lie in the allowed region */ for(i = 0, flag = 0; i < NumPart; i++) @@ -1547,7 +1544,8 @@ int pmforce_nonperiodic(int grnr) { if(flag == 0) { - printf("Particle Id=%llu on task=%d with coordinates (%g|%g|%g) lies outside PM mesh.\n", (unsigned long long) P[i].ID, ThisTask, pos[0], pos[1], pos[2]); + printf("Particle Id=%llu on task=%d with coordinates (%g|%g|%g) lies outside PM mesh.\n", + (unsigned long long)P[i].ID, ThisTask, pos[0], pos[1], pos[2]); myflush(stdout); } flag++; @@ -1561,31 +1559,31 @@ int pmforce_nonperiodic(int grnr) if(flagsum > 0) { mpi_printf("PM-NONPERIODIC: In total %d particles were outside allowed range.\n", flagsum); - return 1; /* error - need to return because particles were outside allowed range */ + return 1; /* error - need to return because particles were outside allowed range */ } #ifdef PM_ZOOM_OPTIMIZED pmforce_nonperiodic_zoom_optimized_prepare_density(grnr); -#else /* #ifdef PM_ZOOM_OPTIMIZED */ +#else /* #ifdef PM_ZOOM_OPTIMIZED */ pmforce_nonperiodic_uniform_optimized_prepare_density(grnr); #endif /* #ifdef PM_ZOOM_OPTIMIZED #else */ /* allocate the memory to hold the FFT fields */ - forcegrid = (fft_real *) mymalloc("forcegrid", maxfftsize * sizeof(fft_real)); + forcegrid = (fft_real *)mymalloc("forcegrid", maxfftsize * sizeof(fft_real)); workspace = forcegrid; #ifndef FFT_COLUMN_BASED - fft_of_rhogrid = (fft_complex *) & rhogrid[0]; -#else /* #ifndef FFT_COLUMN_BASED */ - fft_of_rhogrid = (fft_complex *) & workspace[0]; + fft_of_rhogrid = (fft_complex *)&rhogrid[0]; +#else /* #ifndef FFT_COLUMN_BASED */ + fft_of_rhogrid = (fft_complex *)&workspace[0]; #endif /* #ifndef FFT_COLUMN_BASED #else */ /* Do the FFT of the density field */ #ifndef FFT_COLUMN_BASED my_slab_based_fft(&myplan, &rhogrid[0], &workspace[0], 1); -#else /* #ifndef FFT_COLUMN_BASED */ - my_column_based_fft(&myplan, rhogrid, workspace, 1); /* result is in workspace, not in rhogrid ! */ +#else /* #ifndef FFT_COLUMN_BASED */ + my_column_based_fft(&myplan, rhogrid, workspace, 1); /* result is in workspace, not in rhogrid ! */ #endif /* #ifndef FFT_COLUMN_BASED #else */ /* multiply with kernel in Fourier space */ @@ -1595,7 +1593,7 @@ int pmforce_nonperiodic(int grnr) #ifdef FFT_COLUMN_BASED for(large_array_offset ip = 0; ip < myplan.second_transposed_ncells; ip++) { -#else /* #ifdef FFT_COLUMN_BASED */ +#else /* #ifdef FFT_COLUMN_BASED */ for(int x = 0; x < GRID; x++) for(int y = myplan.slabstart_y; y < myplan.slabstart_y + myplan.nslab_y; y++) for(int z = 0; z < GRIDz; z++) @@ -1603,21 +1601,21 @@ int pmforce_nonperiodic(int grnr) #endif /* #ifdef FFT_COLUMN_BASED #else */ #ifndef FFT_COLUMN_BASED - large_array_offset ip = ((large_array_offset) GRIDz) * (GRID * (y - myplan.slabstart_y) + x) + z; + large_array_offset ip = ((large_array_offset)GRIDz) * (GRID * (y - myplan.slabstart_y) + x) + z; #endif /* #ifndef FFT_COLUMN_BASED */ - double re = fft_of_rhogrid[ip][0] * fft_of_kernel[grnr][ip][0] - fft_of_rhogrid[ip][1] * fft_of_kernel[grnr][ip][1]; - double im = fft_of_rhogrid[ip][0] * fft_of_kernel[grnr][ip][1] + fft_of_rhogrid[ip][1] * fft_of_kernel[grnr][ip][0]; + double re = fft_of_rhogrid[ip][0] * fft_of_kernel[grnr][ip][0] - fft_of_rhogrid[ip][1] * fft_of_kernel[grnr][ip][1]; + double im = fft_of_rhogrid[ip][0] * fft_of_kernel[grnr][ip][1] + fft_of_rhogrid[ip][1] * fft_of_kernel[grnr][ip][0]; - fft_of_rhogrid[ip][0] = re; - fft_of_rhogrid[ip][1] = im; - } + fft_of_rhogrid[ip][0] = re; + fft_of_rhogrid[ip][1] = im; + } - /* Do the inverse FFT to get the potential */ + /* Do the inverse FFT to get the potential */ #ifndef FFT_COLUMN_BASED my_slab_based_fft(&myplan, rhogrid, workspace, -1); -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ my_column_based_fft(&myplan, workspace, rhogrid, -1); #endif /* #ifndef FFT_COLUMN_BASED #else */ @@ -1626,12 +1624,11 @@ int pmforce_nonperiodic(int grnr) #ifdef EVALPOTENTIAL #ifdef PM_ZOOM_OPTIMIZED pmforce_nonperiodic_zoom_optimized_readout_forces_or_potential(grnr, -1); -#else /* #ifdef PM_ZOOM_OPTIMIZED */ +#else /* #ifdef PM_ZOOM_OPTIMIZED */ pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(grnr, -1); #endif /* #ifdef PM_ZOOM_OPTIMIZED #else */ #endif /* #ifdef EVALPOTENTIAL */ - /* get the force components by finite differencing of the potential for each dimension, * and send the results back to the right CPUs */ @@ -1640,7 +1637,7 @@ int pmforce_nonperiodic(int grnr) /* we do the x component last, because for differencing the potential in the x-direction, we need to construct the transpose */ #ifndef FFT_COLUMN_BASED if(dim == 0) - my_slab_transposeA(&myplan, rhogrid, forcegrid); /* compute the transpose of the potential field for finite differencing */ + my_slab_transposeA(&myplan, rhogrid, forcegrid); /* compute the transpose of the potential field for finite differencing */ for(int y = 2; y < GRID / 2 - 2; y++) for(int x = 0; x < myplan.nslab_x; x++) @@ -1650,39 +1647,41 @@ int pmforce_nonperiodic(int grnr) int yrr = y, yll = y, yr = y, yl = y; int zrr = z, zll = z, zr = z, zl = z; - switch (dim) + switch(dim) { - case 0: /* note: for the x-direction, we difference the transposed direction (y) */ - case 1: - yr = y + 1; - yl = y - 1; - yrr = y + 2; - yll = y - 2; - - break; - case 2: - zr = z + 1; - zl = z - 1; - zrr = z + 2; - zll = z - 2; - - break; + case 0: /* note: for the x-direction, we difference the transposed direction (y) */ + case 1: + yr = y + 1; + yl = y - 1; + yrr = y + 2; + yll = y - 2; + + break; + case 2: + zr = z + 1; + zl = z - 1; + zrr = z + 2; + zll = z - 2; + + break; } if(dim == 0) - forcegrid[TI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[TI(x, yl, zl)] - rhogrid[TI(x, yr, zr)]) - (1.0 / 6) * (rhogrid[TI(x, yll, zll)] - rhogrid[TI(x, yrr, zrr)])); + forcegrid[TI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[TI(x, yl, zl)] - rhogrid[TI(x, yr, zr)]) - + (1.0 / 6) * (rhogrid[TI(x, yll, zll)] - rhogrid[TI(x, yrr, zrr)])); else - forcegrid[FI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[FI(x, yl, zl)] - rhogrid[FI(x, yr, zr)]) - (1.0 / 6) * (rhogrid[FI(x, yll, zll)] - rhogrid[FI(x, yrr, zrr)])); + forcegrid[FI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[FI(x, yl, zl)] - rhogrid[FI(x, yr, zr)]) - + (1.0 / 6) * (rhogrid[FI(x, yll, zll)] - rhogrid[FI(x, yrr, zrr)])); } if(dim == 0) - my_slab_transposeB(&myplan, forcegrid, rhogrid); /* reverse the transpose from above */ -#else /* #ifndef FFT_COLUMN_BASED */ + my_slab_transposeB(&myplan, forcegrid, rhogrid); /* reverse the transpose from above */ +#else /* #ifndef FFT_COLUMN_BASED */ fft_real *scratch = NULL, *forcep, *potp; if(dim != 2) { - scratch = mymalloc("scratch", myplan.fftsize * sizeof(fft_real)); /* need a third field as scratch space */ + scratch = mymalloc("scratch", myplan.fftsize * sizeof(fft_real)); /* need a third field as scratch space */ memcpy(scratch, rhogrid, myplan.fftsize * sizeof(fft_real)); if(dim == 1) @@ -1706,19 +1705,19 @@ int pmforce_nonperiodic(int grnr) if(dim != 2) { forcep = &scratch[GRID * i]; - potp = &forcegrid[GRID * i]; + potp = &forcegrid[GRID * i]; } else { forcep = &forcegrid[GRID2 * i]; - potp = &rhogrid[GRID2 * i]; + potp = &rhogrid[GRID2 * i]; } int z; for(z = 2; z < GRID / 2 - 2; z++) { - int zr = z + 1; - int zl = z - 1; + int zr = z + 1; + int zl = z - 1; int zrr = z + 2; int zll = z - 2; @@ -1735,16 +1734,16 @@ int pmforce_nonperiodic(int grnr) myfree(scratch); } -#endif /* #ifndef FFT_COLUMN_BASED #else */ +#endif /* #ifndef FFT_COLUMN_BASED #else */ #ifdef PM_ZOOM_OPTIMIZED pmforce_nonperiodic_zoom_optimized_readout_forces_or_potential(grnr, dim); -#else /* #ifdef PM_ZOOM_OPTIMIZED */ +#else /* #ifdef PM_ZOOM_OPTIMIZED */ pmforce_nonperiodic_uniform_optimized_readout_forces_or_potential(grnr, dim); #endif /* #ifdef PM_ZOOM_OPTIMIZED #else */ } -/* free stuff */ + /* free stuff */ myfree(forcegrid); myfree(rhogrid); @@ -1756,7 +1755,7 @@ int pmforce_nonperiodic(int grnr) myfree(localfield_data); myfree(localfield_globalindex); myfree(part); -#else /* #ifdef PM_ZOOM_OPTIMIZED */ +#else /* #ifdef PM_ZOOM_OPTIMIZED */ myfree(partin); myfree(Rcvpm_offset); myfree(Rcvpm_count); @@ -1771,7 +1770,6 @@ int pmforce_nonperiodic(int grnr) return 0; } - /*! \brief Sets-up the Greens function for the non-periodic potential in real * space, and then converts it to Fourier space by means of an FFT. * @@ -1782,63 +1780,64 @@ void pm_setup_nonperiodic_kernel(void) int i, j, k, x, y, z; double xx, yy, zz, r, u, fac; - mpi_printf("PM-NONPERIODIC: Setting up non-periodic PM kernel (GRID=%d) presently allocated=%g MB).\n", (int) GRID, AllocatedBytes / (1024.0 * 1024.0)); + mpi_printf("PM-NONPERIODIC: Setting up non-periodic PM kernel (GRID=%d) presently allocated=%g MB).\n", (int)GRID, + AllocatedBytes / (1024.0 * 1024.0)); /* now set up kernel and its Fourier transform */ #if defined(GRAVITY_NOT_PERIODIC) - for(i = 0; i < maxfftsize; i++) /* clear local field */ + for(i = 0; i < maxfftsize; i++) /* clear local field */ kernel[0][i] = 0; #ifndef FFT_COLUMN_BASED for(i = myplan.slabstart_x; i < (myplan.slabstart_x + myplan.nslab_x); i++) for(j = 0; j < GRID; j++) { -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ int c; for(c = myplan.base_firstcol; c < (myplan.base_firstcol + myplan.base_ncol); c++) { i = c / GRID; j = c % GRID; #endif /* #ifndef FFT_COLUMN_BASED #else */ - for(k = 0; k < GRID; k++) - { - xx = ((double) i) / GRID; - yy = ((double) j) / GRID; - zz = ((double) k) / GRID; + for(k = 0; k < GRID; k++) + { + xx = ((double)i) / GRID; + yy = ((double)j) / GRID; + zz = ((double)k) / GRID; - if(xx >= 0.5) - xx -= 1.0; - if(yy >= 0.5) - yy -= 1.0; - if(zz >= 0.5) - zz -= 1.0; + if(xx >= 0.5) + xx -= 1.0; + if(yy >= 0.5) + yy -= 1.0; + if(zz >= 0.5) + zz -= 1.0; - r = sqrt(xx * xx + yy * yy + zz * zz); + r = sqrt(xx * xx + yy * yy + zz * zz); - u = 0.5 * r / (((double) ASMTH) / GRID); + u = 0.5 * r / (((double)ASMTH) / GRID); - fac = 1 - erfc(u); + fac = 1 - erfc(u); #ifndef FFT_COLUMN_BASED - size_t ip = FI(i - myplan.slabstart_x, j, k); -#else /* #ifndef FFT_COLUMN_BASED */ + size_t ip = FI(i - myplan.slabstart_x, j, k); +#else /* #ifndef FFT_COLUMN_BASED */ size_t ip = FC(c, k); #endif /* #ifndef FFT_COLUMN_BASED #else */ - if(r > 0) - kernel[0][ip] = -fac / r; - else - kernel[0][ip] = -1 / (sqrt(M_PI) * (((double) ASMTH) / GRID)); - } - } + if(r > 0) + kernel[0][ip] = -fac / r; + else + kernel[0][ip] = -1 / (sqrt(M_PI) * (((double)ASMTH) / GRID)); + } + } { - fft_real *workspc = (fft_real *) mymalloc("workspc", maxfftsize * sizeof(fft_real)); + fft_real *workspc = (fft_real *)mymalloc("workspc", maxfftsize * sizeof(fft_real)); /* Do the FFT of the kernel */ #ifndef FFT_COLUMN_BASED my_slab_based_fft(&myplan, kernel[0], workspc, 1); -#else /* #ifndef FFT_COLUMN_BASED */ - my_column_based_fft(&myplan, kernel[0], workspc, 1); /* result is in workspace, not in kernel */ +#else /* #ifndef FFT_COLUMN_BASED */ + my_column_based_fft(&myplan, kernel[0], workspc, 1); /* result is in workspace, not in kernel */ memcpy(kernel[0], workspc, maxfftsize * sizeof(fft_real)); #endif /* #ifndef FFT_COLUMN_BASED #else */ myfree(workspc); @@ -1846,65 +1845,64 @@ void pm_setup_nonperiodic_kernel(void) #endif /* #if defined(GRAVITY_NOT_PERIODIC) */ - #if defined(PLACEHIGHRESREGION) - for(i = 0; i < maxfftsize; i++) /* clear local field */ + for(i = 0; i < maxfftsize; i++) /* clear local field */ kernel[1][i] = 0; #ifndef FFT_COLUMN_BASED for(i = myplan.slabstart_x; i < (myplan.slabstart_x + myplan.nslab_x); i++) for(j = 0; j < GRID; j++) { -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ int c; for(c = myplan.base_firstcol; c < (myplan.base_firstcol + myplan.base_ncol); c++) { i = c / GRID; j = c % GRID; #endif /* #ifndef FFT_COLUMN_BASED #else */ - for(k = 0; k < GRID; k++) - { - xx = ((double) i) / GRID; - yy = ((double) j) / GRID; - zz = ((double) k) / GRID; + for(k = 0; k < GRID; k++) + { + xx = ((double)i) / GRID; + yy = ((double)j) / GRID; + zz = ((double)k) / GRID; - if(xx >= 0.5) - xx -= 1.0; - if(yy >= 0.5) - yy -= 1.0; - if(zz >= 0.5) - zz -= 1.0; + if(xx >= 0.5) + xx -= 1.0; + if(yy >= 0.5) + yy -= 1.0; + if(zz >= 0.5) + zz -= 1.0; - r = sqrt(xx * xx + yy * yy + zz * zz); + r = sqrt(xx * xx + yy * yy + zz * zz); - u = 0.5 * r / (((double) ASMTH) / GRID); + u = 0.5 * r / (((double)ASMTH) / GRID); - fac = erfc(u * All.Asmth[1] / All.Asmth[0]) - erfc(u); + fac = erfc(u * All.Asmth[1] / All.Asmth[0]) - erfc(u); #ifndef FFT_COLUMN_BASED - size_t ip = FI(i - myplan.slabstart_x, j, k); -#else /* #ifndef FFT_COLUMN_BASED */ + size_t ip = FI(i - myplan.slabstart_x, j, k); +#else /* #ifndef FFT_COLUMN_BASED */ size_t ip = FC(c, k); #endif /* #ifndef FFT_COLUMN_BASED #else */ - if(r > 0) - kernel[1][ip] = -fac / r; - else - { - fac = 1 - All.Asmth[1] / All.Asmth[0]; - kernel[1][ip] = -fac / (sqrt(M_PI) * (((double) ASMTH) / GRID)); - } - } - } + if(r > 0) + kernel[1][ip] = -fac / r; + else + { + fac = 1 - All.Asmth[1] / All.Asmth[0]; + kernel[1][ip] = -fac / (sqrt(M_PI) * (((double)ASMTH) / GRID)); + } + } + } { - fft_real *workspc = (fft_real *) mymalloc("workspc", maxfftsize * sizeof(fft_real)); + fft_real *workspc = (fft_real *)mymalloc("workspc", maxfftsize * sizeof(fft_real)); /* Do the FFT of the kernel */ #ifndef FFT_COLUMN_BASED my_slab_based_fft(&myplan, kernel[1], workspc, 1); -#else /* #ifndef FFT_COLUMN_BASED */ - my_column_based_fft(&myplan, kernel[1], workspc, 1); /* result is in workspace, not in kernel */ +#else /* #ifndef FFT_COLUMN_BASED */ + my_column_based_fft(&myplan, kernel[1], workspc, 1); /* result is in workspace, not in kernel */ memcpy(kernel[1], workspc, maxfftsize * sizeof(fft_real)); #endif /* #ifndef FFT_COLUMN_BASED #else */ myfree(workspc); @@ -1920,78 +1918,76 @@ void pm_setup_nonperiodic_kernel(void) for(ip = 0; ip < myplan.second_transposed_ncells; ip++) { ipcell = ip + myplan.transposed_firstcol * GRID; - y = ipcell / (GRID * GRIDz); + y = ipcell / (GRID * GRIDz); int yr = ipcell % (GRID * GRIDz); - z = yr / GRID; - x = yr % GRID; -#else /* #ifdef FFT_COLUMN_BASED */ + z = yr / GRID; + x = yr % GRID; +#else /* #ifdef FFT_COLUMN_BASED */ for(x = 0; x < GRID; x++) for(y = myplan.slabstart_y; y < myplan.slabstart_y + myplan.nslab_y; y++) for(z = 0; z < GRIDz; z++) { #endif /* #ifdef FFT_COLUMN_BASED #else */ - double kx, ky, kz; + double kx, ky, kz; - if(x > GRID / 2) - kx = x - GRID; - else - kx = x; - if(y > GRID / 2) - ky = y - GRID; - else - ky = y; - if(z > GRID / 2) - kz = z - GRID; - else - kz = z; + if(x > GRID / 2) + kx = x - GRID; + else + kx = x; + if(y > GRID / 2) + ky = y - GRID; + else + ky = y; + if(z > GRID / 2) + kz = z - GRID; + else + kz = z; - double k2 = kx * kx + ky * ky + kz * kz; + double k2 = kx * kx + ky * ky + kz * kz; - if(k2 > 0) - { - double fx = 1, fy = 1, fz = 1; + if(k2 > 0) + { + double fx = 1, fy = 1, fz = 1; - if(kx != 0) - { - fx = (M_PI * kx) / GRID; - fx = sin(fx) / fx; - } - if(ky != 0) - { - fy = (M_PI * ky) / GRID; - fy = sin(fy) / fy; - } - if(kz != 0) - { - fz = (M_PI * kz) / GRID; - fz = sin(fz) / fz; - } + if(kx != 0) + { + fx = (M_PI * kx) / GRID; + fx = sin(fx) / fx; + } + if(ky != 0) + { + fy = (M_PI * ky) / GRID; + fy = sin(fy) / fy; + } + if(kz != 0) + { + fz = (M_PI * kz) / GRID; + fz = sin(fz) / fz; + } - double ff = 1 / (fx * fy * fz); - ff = ff * ff * ff * ff; + double ff = 1 / (fx * fy * fz); + ff = ff * ff * ff * ff; #ifndef FFT_COLUMN_BASED - large_array_offset ip = ((large_array_offset) GRIDz) * (GRID * (y - myplan.slabstart_y) + x) + z; + large_array_offset ip = ((large_array_offset)GRIDz) * (GRID * (y - myplan.slabstart_y) + x) + z; #endif /* #ifndef FFT_COLUMN_BASED */ #if defined(GRAVITY_NOT_PERIODIC) - fft_of_kernel[0][ip][0] *= ff; - fft_of_kernel[0][ip][1] *= ff; + fft_of_kernel[0][ip][0] *= ff; + fft_of_kernel[0][ip][1] *= ff; #endif /* #if defined(GRAVITY_NOT_PERIODIC) */ #if defined(PLACEHIGHRESREGION) - fft_of_kernel[1][ip][0] *= ff; - fft_of_kernel[1][ip][1] *= ff; + fft_of_kernel[1][ip][0] *= ff; + fft_of_kernel[1][ip][1] *= ff; #endif /* #if defined(PLACEHIGHRESREGION) */ - } } + } /* end deconvolution */ } - #ifdef PM_ZOOM_OPTIMIZED - /*! \brief Sort function for 'part' array indices. * * Sorts the indices into the 'part' array by the global index of the @@ -2004,16 +2000,15 @@ void pm_setup_nonperiodic_kernel(void) */ static int pm_periodic_compare_sortindex(const void *a, const void *b) { - if(part[*(int *) a].globalindex < part[*(int *) b].globalindex) + if(part[*(int *)a].globalindex < part[*(int *)b].globalindex) return -1; - if(part[*(int *) a].globalindex > part[*(int *) b].globalindex) + if(part[*(int *)a].globalindex > part[*(int *)b].globalindex) return +1; return 0; } - /*! \brief Implements the sorting function for mysort_pmperiodic() * * The index array is sorted using a merge sort algorithm. @@ -2024,7 +2019,7 @@ static int pm_periodic_compare_sortindex(const void *a, const void *b) * * \return void */ -static void msort_pmperiodic_with_tmp(large_numpart_type * b, size_t n, large_numpart_type * t) +static void msort_pmperiodic_with_tmp(large_numpart_type *b, size_t n, large_numpart_type *t) { large_numpart_type *tmp; large_numpart_type *b1, *b2; @@ -2063,7 +2058,6 @@ static void msort_pmperiodic_with_tmp(large_numpart_type * b, size_t n, large_nu memcpy(b, t, (n - n2) * sizeof(large_numpart_type)); } - /*! \brief Sorts the index array b of n entries using the sort kernel * cmp. * @@ -2078,17 +2072,16 @@ static void msort_pmperiodic_with_tmp(large_numpart_type * b, size_t n, large_nu * * \return void */ -static void mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp) (const void *, const void *)) +static void mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp)(const void *, const void *)) { const size_t size = n * s; - large_numpart_type *tmp = (large_numpart_type *) mymalloc("tmp", size); + large_numpart_type *tmp = (large_numpart_type *)mymalloc("tmp", size); - msort_pmperiodic_with_tmp((large_numpart_type *) b, n, tmp); + msort_pmperiodic_with_tmp((large_numpart_type *)b, n, tmp); myfree(tmp); } #endif /* #ifdef PM_ZOOM_OPTIMIZED */ - #endif /* #if defined(PMGRID) && (defined(PLACEHIGHRESREGION) || defined(GRAVITY_NOT_PERIODIC)) */ diff --git a/src/gravity/pm/pm_periodic.c b/src/gravity/pm/pm_periodic.c index 08b0c4a9e0009c0a60bc0b8ec3acd68e48c73472..319404f797b4f5420509dbbc00bc9920a8cab6b3 100644 --- a/src/gravity/pm/pm_periodic.c +++ b/src/gravity/pm/pm_periodic.c @@ -87,70 +87,60 @@ * - 15.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <math.h> #include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> - #include "../../main/allvars.h" #include "../../main/proto.h" - #if defined(PMGRID) - #define GRIDX (PMGRID * STRETCHX * DBX + DBX_EXTRA) #define GRIDY (PMGRID * STRETCHY * DBY + DBY_EXTRA) #define GRIDZ (PMGRID * STRETCHZ * DBZ + DBZ_EXTRA) +#define GRIDz (GRIDZ / 2 + 1) +#define GRID2 (2 * GRIDz) -#define GRIDz (GRIDZ/2 + 1) -#define GRID2 (2*GRIDz) - - -#if (GRIDX > 1024) || (GRIDY > 1024) || (GRIDZ > 1024) -typedef long long large_array_offset; /* use a larger data type in this case so that we can always address all cells of the 3D grid with a single index */ -#else /* #if (GRIDX > 1024) || (GRIDY > 1024) || (GRIDZ > 1024) */ +#if(GRIDX > 1024) || (GRIDY > 1024) || (GRIDZ > 1024) +typedef long long large_array_offset; /* use a larger data type in this case so that we can always address all cells of the 3D grid + with a single index */ +#else /* #if (GRIDX > 1024) || (GRIDY > 1024) || (GRIDZ > 1024) */ typedef unsigned int large_array_offset; -#endif /* #if (GRIDX > 1024) || (GRIDY > 1024) || (GRIDZ > 1024) #else */ - +#endif /* #if (GRIDX > 1024) || (GRIDY > 1024) || (GRIDZ > 1024) #else */ #ifdef NUMPART_PER_TASK_LARGE -typedef long long large_numpart_type; /* if there is a risk that the local particle number times 8 overflows a 32-bit integer, this data type should be used */ -#else /* #ifdef NUMPART_PER_TASK_LARGE */ +typedef long long large_numpart_type; /* if there is a risk that the local particle number times 8 overflows a 32-bit integer, this + data type should be used */ +#else /* #ifdef NUMPART_PER_TASK_LARGE */ typedef int large_numpart_type; -#endif /* #ifdef NUMPART_PER_TASK_LARGE #else */ - +#endif /* #ifdef NUMPART_PER_TASK_LARGE #else */ /* short-cut macros for accessing different 3D arrays */ -#define FI(x,y,z) (((large_array_offset) GRID2) * (GRIDY * (x) + (y)) + (z)) -#define FC(c,z) (((large_array_offset) GRID2) * ((c) - myplan.base_firstcol) + (z)) +#define FI(x, y, z) (((large_array_offset)GRID2) * (GRIDY * (x) + (y)) + (z)) +#define FC(c, z) (((large_array_offset)GRID2) * ((c)-myplan.base_firstcol) + (z)) #ifndef FFT_COLUMN_BASED -#define NI(x,y,z) (((large_array_offset) GRIDZ) * ((y) + (x) * myplan.nslab_y) + (z)) +#define NI(x, y, z) (((large_array_offset)GRIDZ) * ((y) + (x)*myplan.nslab_y) + (z)) #endif /* #ifndef FFT_COLUMN_BASED */ - /* variables for power spectrum estimation */ #ifndef BINS_PS -#define BINS_PS 2000 /* number of bins for power spectrum computation */ -#endif /* #ifndef BINS_PS */ +#define BINS_PS 2000 /* number of bins for power spectrum computation */ +#endif /* #ifndef BINS_PS */ #ifndef POWERSPEC_FOLDFAC -#define POWERSPEC_FOLDFAC 16. /* folding factor to obtain an estimate of the power spectrum on very small scales */ -#endif /* #ifndef POWERSPEC_FOLDFAC */ - - -static fft_plan myplan; /*!< In this structure, various bookkeeping variables for the distributed FFTs are stored */ +#define POWERSPEC_FOLDFAC 16. /* folding factor to obtain an estimate of the power spectrum on very small scales */ +#endif /* #ifndef POWERSPEC_FOLDFAC */ +static fft_plan myplan; /*!< In this structure, various bookkeeping variables for the distributed FFTs are stored */ /*! \var maxfftsize * \brief maximum size of the local fft grid among all tasks */ static size_t maxfftsize; - /*! \var rhogrid * \brief This array hold the local part of the density field and * after the FFTs the local part of the potential @@ -163,7 +153,6 @@ static size_t maxfftsize; */ static fft_real *rhogrid, *forcegrid, *workspace; - /*! \brief Array containing the FFT of #rhogrid * * This pointer points to the same array as #rhogrid, @@ -171,12 +160,10 @@ static fft_real *rhogrid, *forcegrid, *workspace; */ static fft_complex *fft_of_rhogrid; - /* Variable for power spectrum calculation */ static double power_spec_totmass, power_spec_totmass2; static long long power_spec_totnumpart; - /*! \brief This routine generates the FFT-plans to carry out the FFTs later on. * * Some auxiliary variables for bookkeeping are also initialized. @@ -186,66 +173,68 @@ static long long power_spec_totnumpart; void pm_init_periodic(void) { #ifdef LONG_X - if(LONG_X != (int) (LONG_X)) + if(LONG_X != (int)(LONG_X)) terminate("LONG_X must be an integer if used with PMGRID"); #endif /* #ifdef LONG_X */ #ifdef LONG_Y - if(LONG_Y != (int) (LONG_Y)) + if(LONG_Y != (int)(LONG_Y)) terminate("LONG_Y must be an integer if used with PMGRID"); #endif /* #ifdef LONG_Y */ #ifdef LONG_Z - if(LONG_Z != (int) (LONG_Z)) + if(LONG_Z != (int)(LONG_Z)) terminate("LONG_Z must be an integer if used with PMGRID"); #endif /* #ifdef LONG_Z */ All.Asmth[0] = ASMTH * All.BoxSize / PMGRID; - All.Rcut[0] = RCUT * All.Asmth[0]; + All.Rcut[0] = RCUT * All.Asmth[0]; /* Set up the FFTW-3 plan files. */ - int ndimx[1] = { GRIDX }; /* dimension of the 1D transforms */ - int ndimy[1] = { GRIDY }; /* dimension of the 1D transforms */ - int ndimz[1] = { GRIDZ }; /* dimension of the 1D transforms */ + int ndimx[1] = {GRIDX}; /* dimension of the 1D transforms */ + int ndimy[1] = {GRIDY}; /* dimension of the 1D transforms */ + int ndimz[1] = {GRIDZ}; /* dimension of the 1D transforms */ int max_GRID2 = 2 * (imax(imax(GRIDX, GRIDY), GRIDZ) / 2 + 1); /* temporarily allocate some arrays to make sure that out-of-place plans are created */ - rhogrid = (fft_real *) mymalloc("rhogrid", max_GRID2 * sizeof(fft_real)); - forcegrid = (fft_real *) mymalloc("forcegrid", max_GRID2 * sizeof(fft_real)); + rhogrid = (fft_real *)mymalloc("rhogrid", max_GRID2 * sizeof(fft_real)); + forcegrid = (fft_real *)mymalloc("forcegrid", max_GRID2 * sizeof(fft_real)); #ifdef DOUBLEPRECISION_FFTW int alignflag = 0; -#else /* #ifdef DOUBLEPRECISION_FFTW */ +#else /* #ifdef DOUBLEPRECISION_FFTW */ /* for single precision, the start of our FFT columns is presently only guaranteed to be 8-byte aligned */ int alignflag = FFTW_UNALIGNED; #endif /* #ifdef DOUBLEPRECISION_FFTW #else */ - myplan.forward_plan_zdir = FFTW(plan_many_dft_r2c) (1, ndimz, 1, rhogrid, 0, 1, GRID2, (fft_complex *) forcegrid, 0, 1, GRIDz, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + myplan.forward_plan_zdir = FFTW(plan_many_dft_r2c)(1, ndimz, 1, rhogrid, 0, 1, GRID2, (fft_complex *)forcegrid, 0, 1, GRIDz, + FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); #ifndef FFT_COLUMN_BASED int stride = GRIDz; -#else /* #ifndef FFT_COLUMN_BASED */ - int stride = 1; +#else /* #ifndef FFT_COLUMN_BASED */ + int stride = 1; #endif /* #ifndef FFT_COLUMN_BASED #else */ myplan.forward_plan_ydir = - FFTW(plan_many_dft) (1, ndimy, 1, (fft_complex *) rhogrid, 0, stride, GRIDz * GRIDY, (fft_complex *) forcegrid, 0, stride, GRIDz * GRIDY, FFTW_FORWARD, - FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + FFTW(plan_many_dft)(1, ndimy, 1, (fft_complex *)rhogrid, 0, stride, GRIDz * GRIDY, (fft_complex *)forcegrid, 0, stride, + GRIDz * GRIDY, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myplan.forward_plan_xdir = - FFTW(plan_many_dft) (1, ndimx, 1, (fft_complex *) rhogrid, 0, stride, GRIDz * GRIDX, (fft_complex *) forcegrid, 0, stride, GRIDz * GRIDX, FFTW_FORWARD, - FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + FFTW(plan_many_dft)(1, ndimx, 1, (fft_complex *)rhogrid, 0, stride, GRIDz * GRIDX, (fft_complex *)forcegrid, 0, stride, + GRIDz * GRIDX, FFTW_FORWARD, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myplan.backward_plan_xdir = - FFTW(plan_many_dft) (1, ndimx, 1, (fft_complex *) rhogrid, 0, stride, GRIDz * GRIDX, (fft_complex *) forcegrid, 0, stride, GRIDz * GRIDX, FFTW_BACKWARD, - FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + FFTW(plan_many_dft)(1, ndimx, 1, (fft_complex *)rhogrid, 0, stride, GRIDz * GRIDX, (fft_complex *)forcegrid, 0, stride, + GRIDz * GRIDX, FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myplan.backward_plan_ydir = - FFTW(plan_many_dft) (1, ndimy, 1, (fft_complex *) rhogrid, 0, stride, GRIDz * GRIDY, (fft_complex *) forcegrid, 0, stride, GRIDz * GRIDY, FFTW_BACKWARD, - FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + FFTW(plan_many_dft)(1, ndimy, 1, (fft_complex *)rhogrid, 0, stride, GRIDz * GRIDY, (fft_complex *)forcegrid, 0, stride, + GRIDz * GRIDY, FFTW_BACKWARD, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); - myplan.backward_plan_zdir = FFTW(plan_many_dft_c2r) (1, ndimz, 1, (fft_complex *) rhogrid, 0, 1, GRIDz, forcegrid, 0, 1, GRID2, FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); + myplan.backward_plan_zdir = FFTW(plan_many_dft_c2r)(1, ndimz, 1, (fft_complex *)rhogrid, 0, 1, GRIDz, forcegrid, 0, 1, GRID2, + FFTW_ESTIMATE | FFTW_DESTROY_INPUT | alignflag); myfree(forcegrid); myfree(rhogrid); @@ -254,7 +243,7 @@ void pm_init_periodic(void) my_slab_based_fft_init(&myplan, GRIDX, GRIDY, GRIDZ); - maxfftsize = imax(myplan.largest_x_slab * GRIDY, myplan.largest_y_slab * GRIDX) * ((size_t) GRID2); + maxfftsize = imax(myplan.largest_x_slab * GRIDY, myplan.largest_y_slab * GRIDX) * ((size_t)GRID2); #else /* #ifndef FFT_COLUMN_BASED */ @@ -263,10 +252,8 @@ void pm_init_periodic(void) maxfftsize = myplan.max_datasize; #endif /* #ifndef FFT_COLUMN_BASED #else */ - } - /* Below, the two functions * * pmforce_ ...... _prepare_density() @@ -278,10 +265,9 @@ void pm_init_periodic(void) * depending on the setting of PM_ZOOM_OPTIMIZED. */ #ifdef PM_ZOOM_OPTIMIZED -static void mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp) (const void *, const void *)); +static void mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp)(const void *, const void *)); static int pm_periodic_compare_sortindex(const void *a, const void *b); - /*! \brief This structure links the particles to the mesh cells, to which they * contribute their mass. * @@ -291,16 +277,17 @@ static int pm_periodic_compare_sortindex(const void *a, const void *b); */ static struct part_slab_data { - large_array_offset globalindex; /*!< index in the global density mesh */ - large_numpart_type partindex; /*!< contains the local particle index shifted by 2^3, the first three bits encode to which part of the CIC assignment this item belongs to */ - large_array_offset localindex; /*!< index to a local copy of the corresponding mesh cell of the global density array (used during local mass and force assignment) */ -} *part; /*!< array of part_slab_data linking the local particles to their mesh cells */ + large_array_offset globalindex; /*!< index in the global density mesh */ + large_numpart_type partindex; /*!< contains the local particle index shifted by 2^3, the first three bits encode to which part of the + CIC assignment this item belongs to */ + large_array_offset localindex; /*!< index to a local copy of the corresponding mesh cell of the global density array (used during + local mass and force assignment) */ +} * part; /*!< array of part_slab_data linking the local particles to their mesh cells */ static size_t *localfield_sendcount, *localfield_first, *localfield_offset, *localfield_recvcount; static large_array_offset *localfield_globalindex, *import_globalindex; static fft_real *localfield_data, *import_data; - /*! \brief Prepares density field for PM calculation in zoom-optimized * algorithm. * @@ -315,15 +302,16 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) int level, recvTask; MPI_Status status; - double to_slab_fac = PMGRID / All.BoxSize; /* note: This is the same as GRIDX / (All.BoxSize * LONG_X), and similarly for each dimension */ + double to_slab_fac = + PMGRID / All.BoxSize; /* note: This is the same as GRIDX / (All.BoxSize * LONG_X), and similarly for each dimension */ if(mode == 2) to_slab_fac *= POWERSPEC_FOLDFAC; if(mode == 3) to_slab_fac *= POWERSPEC_FOLDFAC * POWERSPEC_FOLDFAC; - part = (struct part_slab_data *) mymalloc("part", 8 * (NumPart * sizeof(struct part_slab_data))); - large_numpart_type *part_sortindex = (large_numpart_type *) mymalloc("part_sortindex", 8 * (NumPart * sizeof(large_numpart_type))); + part = (struct part_slab_data *)mymalloc("part", 8 * (NumPart * sizeof(struct part_slab_data))); + large_numpart_type *part_sortindex = (large_numpart_type *)mymalloc("part_sortindex", 8 * (NumPart * sizeof(large_numpart_type))); /* determine the cells each particle accesses */ for(i = 0; i < NumPart; i++) @@ -344,9 +332,9 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) #endif /* #ifdef CELL_CENTER_GRAVITY */ pos = P[i].Pos; - int slab_x = (int) (to_slab_fac * pos[0]); - int slab_y = (int) (to_slab_fac * pos[1]); - int slab_z = (int) (to_slab_fac * pos[2]); + int slab_x = (int)(to_slab_fac * pos[0]); + int slab_y = (int)(to_slab_fac * pos[1]); + int slab_z = (int)(to_slab_fac * pos[2]); if(mode >= 2) { @@ -364,7 +352,7 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) slab_z -= GRIDZ; } - large_numpart_type index_on_grid = ((large_numpart_type) i) << 3; + large_numpart_type index_on_grid = ((large_numpart_type)i) << 3; for(int xx = 0; xx < 2; xx++) for(int yy = 0; yy < 2; yy++) @@ -383,9 +371,9 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) large_array_offset offset = FI(slab_xx, slab_yy, slab_zz); - part[index_on_grid].partindex = (i << 3) + (xx << 2) + (yy << 1) + zz; + part[index_on_grid].partindex = (i << 3) + (xx << 2) + (yy << 1) + zz; part[index_on_grid].globalindex = offset; - part_sortindex[index_on_grid] = index_on_grid; + part_sortindex[index_on_grid] = index_on_grid; index_on_grid++; } } @@ -393,7 +381,7 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) /* note: num_on_grid will be 8 times larger than the particle number, but num_field_points will generally be much smaller */ large_array_offset num_field_points; - large_numpart_type num_on_grid = ((large_numpart_type) NumPart) << 3; + large_numpart_type num_on_grid = ((large_numpart_type)NumPart) << 3; /* bring the part-field into the order of the accessed cells. This allows the removal of duplicates */ mysort_pmperiodic(part_sortindex, num_on_grid, sizeof(large_numpart_type), pm_periodic_compare_sortindex); @@ -411,16 +399,17 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) } /* allocate the local field */ - localfield_globalindex = (large_array_offset *) mymalloc_movable(&localfield_globalindex, "localfield_globalindex", num_field_points * sizeof(large_array_offset)); - localfield_data = (fft_real *) mymalloc_movable(&localfield_data, "localfield_data", num_field_points * sizeof(fft_real)); - localfield_first = (size_t *) mymalloc_movable(&localfield_first, "localfield_first", NTask * sizeof(size_t)); - localfield_sendcount = (size_t *) mymalloc_movable(&localfield_sendcount, "localfield_sendcount", NTask * sizeof(size_t)); - localfield_offset = (size_t *) mymalloc_movable(&localfield_offset, "localfield_offset", NTask * sizeof(size_t)); - localfield_recvcount = (size_t *) mymalloc_movable(&localfield_recvcount, "localfield_recvcount", NTask * sizeof(size_t)); + localfield_globalindex = (large_array_offset *)mymalloc_movable(&localfield_globalindex, "localfield_globalindex", + num_field_points * sizeof(large_array_offset)); + localfield_data = (fft_real *)mymalloc_movable(&localfield_data, "localfield_data", num_field_points * sizeof(fft_real)); + localfield_first = (size_t *)mymalloc_movable(&localfield_first, "localfield_first", NTask * sizeof(size_t)); + localfield_sendcount = (size_t *)mymalloc_movable(&localfield_sendcount, "localfield_sendcount", NTask * sizeof(size_t)); + localfield_offset = (size_t *)mymalloc_movable(&localfield_offset, "localfield_offset", NTask * sizeof(size_t)); + localfield_recvcount = (size_t *)mymalloc_movable(&localfield_recvcount, "localfield_recvcount", NTask * sizeof(size_t)); for(i = 0; i < NTask; i++) { - localfield_first[i] = 0; + localfield_first[i] = 0; localfield_sendcount[i] = 0; } @@ -444,7 +433,7 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) #ifndef FFT_COLUMN_BASED int slab = part[part_sortindex[i]].globalindex / (GRIDY * GRID2); int task = myplan.slab_to_task[slab]; -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ int task, column = part[part_sortindex[i]].globalindex / (GRID2); if(column < myplan.pivotcol) @@ -489,9 +478,9 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) #endif /* #ifdef CELL_CENTER_GRAVITY */ pos = P[pindex].Pos; - int slab_x = (int) (to_slab_fac * pos[0]); - int slab_y = (int) (to_slab_fac * pos[1]); - int slab_z = (int) (to_slab_fac * pos[2]); + int slab_x = (int)(to_slab_fac * pos[0]); + int slab_y = (int)(to_slab_fac * pos[1]); + int slab_z = (int)(to_slab_fac * pos[2]); double dx = to_slab_fac * pos[0] - slab_x; double dy = to_slab_fac * pos[1] - slab_y; @@ -499,7 +488,7 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) double weight = P[pindex].Mass; - if(mode) /* only for power spectrum calculation */ + if(mode) /* only for power spectrum calculation */ if(typelist[P[pindex].Type] == 0) continue; @@ -509,11 +498,11 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) localfield_data[part[i + 3].localindex] += weight * (1.0 - dx) * dy * dz; localfield_data[part[i + 4].localindex] += weight * (dx) * (1.0 - dy) * (1.0 - dz); localfield_data[part[i + 5].localindex] += weight * (dx) * (1.0 - dy) * dz; - localfield_data[part[i + 6].localindex] += weight * (dx) * dy * (1.0 - dz); - localfield_data[part[i + 7].localindex] += weight * (dx) * dy * dz; + localfield_data[part[i + 6].localindex] += weight * (dx)*dy * (1.0 - dz); + localfield_data[part[i + 7].localindex] += weight * (dx)*dy * dz; } - rhogrid = (fft_real *) mymalloc("rhogrid", maxfftsize * sizeof(fft_real)); + rhogrid = (fft_real *)mymalloc("rhogrid", maxfftsize * sizeof(fft_real)); /* clear local FFT-mesh density field */ large_array_offset ii; @@ -531,23 +520,25 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) { if(level > 0) { - import_data = (fft_real *) mymalloc("import_data", localfield_recvcount[recvTask] * sizeof(fft_real)); - import_globalindex = (large_array_offset *) mymalloc("import_globalindex", localfield_recvcount[recvTask] * sizeof(large_array_offset)); + import_data = (fft_real *)mymalloc("import_data", localfield_recvcount[recvTask] * sizeof(fft_real)); + import_globalindex = + (large_array_offset *)mymalloc("import_globalindex", localfield_recvcount[recvTask] * sizeof(large_array_offset)); if(localfield_sendcount[recvTask] > 0 || localfield_recvcount[recvTask] > 0) { - myMPI_Sendrecv(localfield_data + localfield_offset[recvTask], - localfield_sendcount[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, import_data, localfield_recvcount[recvTask] * sizeof(fft_real), MPI_BYTE, - recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); + myMPI_Sendrecv(localfield_data + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(fft_real), + MPI_BYTE, recvTask, TAG_NONPERIOD_A, import_data, localfield_recvcount[recvTask] * sizeof(fft_real), + MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); myMPI_Sendrecv(localfield_globalindex + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_B, - import_globalindex, localfield_recvcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_B, MPI_COMM_WORLD, &status); + import_globalindex, localfield_recvcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_B, MPI_COMM_WORLD, &status); } } else { - import_data = localfield_data + localfield_offset[ThisTask]; + import_data = localfield_data + localfield_offset[ThisTask]; import_globalindex = localfield_globalindex + localfield_offset[ThisTask]; } @@ -556,9 +547,10 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) { /* determine offset in local FFT slab */ #ifndef FFT_COLUMN_BASED - large_array_offset offset = import_globalindex[i] - myplan.first_slab_x_of_task[ThisTask] * GRIDY * ((large_array_offset) GRID2); -#else /* #ifndef FFT_COLUMN_BASED */ - large_array_offset offset = import_globalindex[i] - myplan.base_firstcol * ((large_array_offset) GRID2); + large_array_offset offset = + import_globalindex[i] - myplan.first_slab_x_of_task[ThisTask] * GRIDY * ((large_array_offset)GRID2); +#else /* #ifndef FFT_COLUMN_BASED */ + large_array_offset offset = import_globalindex[i] - myplan.base_firstcol * ((large_array_offset)GRID2); #endif /* #ifndef FFT_COLUMN_BASED #else */ rhogrid[offset] += import_data[i]; } @@ -572,7 +564,6 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) } } - /* \brief Function to read out the force component corresponding to spatial * dimension 'dim'. * @@ -584,8 +575,8 @@ void pmforce_zoom_optimized_prepare_density(int mode, int *typelist) void pmforce_zoom_optimized_readout_forces_or_potential(int dim) { #ifdef EVALPOTENTIAL - double fac = 4 * M_PI * All.G / (pow(All.BoxSize, 3) * STRETCHX * STRETCHY * STRETCHZ); /* to get potential */ -#endif /* #ifdef EVALPOTENTIAL */ + double fac = 4 * M_PI * All.G / (pow(All.BoxSize, 3) * STRETCHX * STRETCHY * STRETCHZ); /* to get potential */ +#endif /* #ifdef EVALPOTENTIAL */ large_numpart_type i; int level, recvTask; @@ -608,37 +599,40 @@ void pmforce_zoom_optimized_readout_forces_or_potential(int dim) { if(level > 0) { - import_data = (fft_real *) mymalloc("import_data", localfield_recvcount[recvTask] * sizeof(fft_real)); - import_globalindex = (large_array_offset *) mymalloc("import_globalindex", localfield_recvcount[recvTask] * sizeof(large_array_offset)); + import_data = (fft_real *)mymalloc("import_data", localfield_recvcount[recvTask] * sizeof(fft_real)); + import_globalindex = + (large_array_offset *)mymalloc("import_globalindex", localfield_recvcount[recvTask] * sizeof(large_array_offset)); if(localfield_sendcount[recvTask] > 0 || localfield_recvcount[recvTask] > 0) { myMPI_Sendrecv(localfield_globalindex + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_C, - import_globalindex, localfield_recvcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_C, MPI_COMM_WORLD, &status); + import_globalindex, localfield_recvcount[recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_C, MPI_COMM_WORLD, &status); } } else { - import_data = localfield_data + localfield_offset[ThisTask]; + import_data = localfield_data + localfield_offset[ThisTask]; import_globalindex = localfield_globalindex + localfield_offset[ThisTask]; } for(i = 0; i < localfield_recvcount[recvTask]; i++) { #ifndef FFT_COLUMN_BASED - large_array_offset offset = import_globalindex[i] - myplan.first_slab_x_of_task[ThisTask] * GRIDY * ((large_array_offset) GRID2); -#else /* #ifndef FFT_COLUMN_BASED */ - large_array_offset offset = import_globalindex[i] - myplan.base_firstcol * ((large_array_offset) GRID2); + large_array_offset offset = + import_globalindex[i] - myplan.first_slab_x_of_task[ThisTask] * GRIDY * ((large_array_offset)GRID2); +#else /* #ifndef FFT_COLUMN_BASED */ + large_array_offset offset = import_globalindex[i] - myplan.base_firstcol * ((large_array_offset)GRID2); #endif /* #ifndef FFT_COLUMN_BASED #else */ import_data[i] = grid[offset]; } if(level > 0) { - myMPI_Sendrecv(import_data, localfield_recvcount[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, - TAG_NONPERIOD_A, localfield_data + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, - &status); + myMPI_Sendrecv(import_data, localfield_recvcount[recvTask] * sizeof(fft_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, + localfield_data + localfield_offset[recvTask], localfield_sendcount[recvTask] * sizeof(fft_real), + MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); myfree(import_globalindex); myfree(import_data); @@ -667,24 +661,23 @@ void pmforce_zoom_optimized_readout_forces_or_potential(int dim) #endif /* #ifdef CELL_CENTER_GRAVITY */ pos = P[i].Pos; - int slab_x = (int) (to_slab_fac * pos[0]); - double dx = to_slab_fac * pos[0] - slab_x; + int slab_x = (int)(to_slab_fac * pos[0]); + double dx = to_slab_fac * pos[0] - slab_x; - int slab_y = (int) (to_slab_fac * pos[1]); - double dy = to_slab_fac * pos[1] - slab_y; + int slab_y = (int)(to_slab_fac * pos[1]); + double dy = to_slab_fac * pos[1] - slab_y; - int slab_z = (int) (to_slab_fac * pos[2]); - double dz = to_slab_fac * pos[2] - slab_z; + int slab_z = (int)(to_slab_fac * pos[2]); + double dz = to_slab_fac * pos[2] - slab_z; - double value = - +localfield_data[part[j + 0].localindex] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) - + localfield_data[part[j + 1].localindex] * (1.0 - dx) * (1.0 - dy) * dz - + localfield_data[part[j + 2].localindex] * (1.0 - dx) * dy * (1.0 - dz) - + localfield_data[part[j + 3].localindex] * (1.0 - dx) * dy * dz - + localfield_data[part[j + 4].localindex] * (dx) * (1.0 - dy) * (1.0 - dz) - + localfield_data[part[j + 5].localindex] * (dx) * (1.0 - dy) * dz - + localfield_data[part[j + 6].localindex] * (dx) * dy * (1.0 - dz) - + localfield_data[part[j + 7].localindex] * (dx) * dy * dz; + double value = +localfield_data[part[j + 0].localindex] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) + + localfield_data[part[j + 1].localindex] * (1.0 - dx) * (1.0 - dy) * dz + + localfield_data[part[j + 2].localindex] * (1.0 - dx) * dy * (1.0 - dz) + + localfield_data[part[j + 3].localindex] * (1.0 - dx) * dy * dz + + localfield_data[part[j + 4].localindex] * (dx) * (1.0 - dy) * (1.0 - dz) + + localfield_data[part[j + 5].localindex] * (dx) * (1.0 - dy) * dz + + localfield_data[part[j + 6].localindex] * (dx)*dy * (1.0 - dz) + + localfield_data[part[j + 7].localindex] * (dx)*dy * dz; if(dim < 0) { @@ -697,30 +690,26 @@ void pmforce_zoom_optimized_readout_forces_or_potential(int dim) } } - #else /* #ifdef PM_ZOOM_OPTIMIZED */ - /* * Here come the routines for a different communication algorithm that is * better suited for a homogenuously loaded boxes. */ - /*! \brief Structure for particle buffer. */ static struct partbuf { MyFloat Mass; MyFloat Pos[3]; -} *partin, *partout; +} * partin, *partout; static size_t nimport, nexport; static size_t *Sndpm_count, *Sndpm_offset; static size_t *Rcvpm_count, *Rcvpm_offset; - /*! \brief Prepares density field for PM calculation in uniform box optimized * algorithm. * @@ -744,10 +733,10 @@ static void pmforce_uniform_optimized_prepare_density(int mode) */ int multiNtask = roundup_to_multiple_of_cacheline_size(NTask * sizeof(size_t)) / sizeof(size_t); - Sndpm_count = (size_t *) mymalloc("Sndpm_count", MaxThreads * multiNtask * sizeof(size_t)); - Sndpm_offset = (size_t *) mymalloc("Sndpm_offset", MaxThreads * multiNtask * sizeof(size_t)); - Rcvpm_count = (size_t *) mymalloc("Rcvpm_count", NTask * sizeof(size_t)); - Rcvpm_offset = (size_t *) mymalloc("Rcvpm_offset", NTask * sizeof(size_t)); + Sndpm_count = (size_t *)mymalloc("Sndpm_count", MaxThreads * multiNtask * sizeof(size_t)); + Sndpm_offset = (size_t *)mymalloc("Sndpm_offset", MaxThreads * multiNtask * sizeof(size_t)); + Rcvpm_count = (size_t *)mymalloc("Rcvpm_count", NTask * sizeof(size_t)); + Rcvpm_offset = (size_t *)mymalloc("Rcvpm_offset", NTask * sizeof(size_t)); /* determine the slabs/columns each particles accesses */ { @@ -775,7 +764,7 @@ static void pmforce_uniform_optimized_prepare_density(int mode) #endif /* #ifdef CELL_CENTER_GRAVITY */ pos = P[i].Pos; - int slab_x = (int) (to_slab_fac * pos[0]); + int slab_x = (int)(to_slab_fac * pos[0]); int slab_xx = slab_x + 1; if(mode >= 2) @@ -799,8 +788,8 @@ static void pmforce_uniform_optimized_prepare_density(int mode) send_count[task0]++; if(task0 != task1) send_count[task1]++; -#else /* #ifndef FFT_COLUMN_BASED */ - int slab_y = (int) (to_slab_fac * pos[1]); +#else /* #ifndef FFT_COLUMN_BASED */ + int slab_y = (int)(to_slab_fac * pos[1]); int slab_yy = slab_y + 1; if(mode >= 2) @@ -890,11 +879,11 @@ static void pmforce_uniform_optimized_prepare_density(int mode) } /* allocate import and export buffer */ - partin = (struct partbuf *) mymalloc("partin", nimport * sizeof(struct partbuf)); - partout = (struct partbuf *) mymalloc("partout", nexport * sizeof(struct partbuf)); + partin = (struct partbuf *)mymalloc("partin", nimport * sizeof(struct partbuf)); + partout = (struct partbuf *)mymalloc("partout", nexport * sizeof(struct partbuf)); { - size_t *send_count = Sndpm_count + get_thread_num() * multiNtask; + size_t *send_count = Sndpm_count + get_thread_num() * multiNtask; size_t *send_offset = Sndpm_offset + get_thread_num() * multiNtask; for(j = 0; j < NTask; j++) @@ -919,7 +908,7 @@ static void pmforce_uniform_optimized_prepare_density(int mode) #endif /* #ifdef CELL_CENTER_GRAVITY */ pos = P[i].Pos; - int slab_x = (int) (to_slab_fac * pos[0]); + int slab_x = (int)(to_slab_fac * pos[0]); int slab_xx = slab_x + 1; if(mode >= 2) @@ -940,20 +929,20 @@ static void pmforce_uniform_optimized_prepare_density(int mode) int task0 = myplan.slab_to_task[slab_x]; int task1 = myplan.slab_to_task[slab_xx]; - size_t ind0 = send_offset[task0] + send_count[task0]++; + size_t ind0 = send_offset[task0] + send_count[task0]++; partout[ind0].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind0].Pos[j] = pos[j]; if(task0 != task1) { - size_t ind1 = send_offset[task1] + send_count[task1]++; + size_t ind1 = send_offset[task1] + send_count[task1]++; partout[ind1].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind1].Pos[j] = pos[j]; } -#else /* #ifndef FFT_COLUMN_BASED */ - int slab_y = (int) (to_slab_fac * pos[1]); +#else /* #ifndef FFT_COLUMN_BASED */ + int slab_y = (int)(to_slab_fac * pos[1]); int slab_yy = slab_y + 1; if(mode >= 2) @@ -997,28 +986,28 @@ static void pmforce_uniform_optimized_prepare_density(int mode) else task3 = (column3 - myplan.pivotcol) / (myplan.avg - 1) + myplan.tasklastsection; - size_t ind0 = send_offset[task0] + send_count[task0]++; + size_t ind0 = send_offset[task0] + send_count[task0]++; partout[ind0].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind0].Pos[j] = pos[j]; if(task1 != task0) { - size_t ind1 = send_offset[task1] + send_count[task1]++; + size_t ind1 = send_offset[task1] + send_count[task1]++; partout[ind1].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind1].Pos[j] = pos[j]; } if(task2 != task1 && task2 != task0) { - size_t ind2 = send_offset[task2] + send_count[task2]++; + size_t ind2 = send_offset[task2] + send_count[task2]++; partout[ind2].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind2].Pos[j] = pos[j]; } if(task3 != task0 && task3 != task1 && task3 != task2) { - size_t ind3 = send_offset[task3] + send_count[task3]++; + size_t ind3 = send_offset[task3] + send_count[task3]++; partout[ind3].Mass = P[i].Mass; for(j = 0; j < 3; j++) partout[ind3].Pos[j] = pos[j]; @@ -1043,12 +1032,13 @@ static void pmforce_uniform_optimized_prepare_density(int mode) MPI_Allreduce(&flag_big, &flag_big_all, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); /* exchange particle data */ - myMPI_Alltoallv(partout, Sndpm_count, Sndpm_offset, partin, Rcvpm_count, Rcvpm_offset, sizeof(struct partbuf), flag_big_all, MPI_COMM_WORLD); + myMPI_Alltoallv(partout, Sndpm_count, Sndpm_offset, partin, Rcvpm_count, Rcvpm_offset, sizeof(struct partbuf), flag_big_all, + MPI_COMM_WORLD); myfree(partout); /* allocate density field */ - rhogrid = (fft_real *) mymalloc("rhogrid", maxfftsize * sizeof(fft_real)); + rhogrid = (fft_real *)mymalloc("rhogrid", maxfftsize * sizeof(fft_real)); /* clear local FFT-mesh density field */ large_array_offset ii; @@ -1066,9 +1056,9 @@ static void pmforce_uniform_optimized_prepare_density(int mode) for(i = 0; i < nimport; i++) { - int slab_y = (int) (to_slab_fac * partin[i].Pos[1]); + int slab_y = (int)(to_slab_fac * partin[i].Pos[1]); int slab_yy = slab_y + 1; - double dy = to_slab_fac * partin[i].Pos[1] - slab_y; + double dy = to_slab_fac * partin[i].Pos[1] - slab_y; if(mode >= 2) { @@ -1100,8 +1090,8 @@ static void pmforce_uniform_optimized_prepare_density(int mode) { double mass = partin[i].Mass; - int slab_x = (int) (to_slab_fac * partin[i].Pos[0]); - int slab_z = (int) (to_slab_fac * partin[i].Pos[2]); + int slab_x = (int)(to_slab_fac * partin[i].Pos[0]); + int slab_z = (int)(to_slab_fac * partin[i].Pos[2]); int slab_xx = slab_x + 1; int slab_zz = slab_z + 1; @@ -1185,16 +1175,16 @@ static void pmforce_uniform_optimized_prepare_density(int mode) { int col0, col1, col2, col3; double dx, dy; - } *aux; + } * aux; aux = mymalloc("aux", nimport * sizeof(struct data_cols)); for(i = 0; i < nimport; i++) { - int slab_x = (int) (to_slab_fac * partin[i].Pos[0]); + int slab_x = (int)(to_slab_fac * partin[i].Pos[0]); int slab_xx = slab_x + 1; - int slab_y = (int) (to_slab_fac * partin[i].Pos[1]); + int slab_y = (int)(to_slab_fac * partin[i].Pos[1]); int slab_yy = slab_y + 1; aux[i].dx = to_slab_fac * partin[i].Pos[0] - slab_x; @@ -1270,7 +1260,7 @@ static void pmforce_uniform_optimized_prepare_density(int mode) double dx = aux[i].dx; double dy = aux[i].dy; - int slab_z = (int) (to_slab_fac * partin[i].Pos[2]); + int slab_z = (int)(to_slab_fac * partin[i].Pos[2]); int slab_zz = slab_z + 1; double dz = to_slab_fac * partin[i].Pos[2] - slab_z; @@ -1321,7 +1311,6 @@ static void pmforce_uniform_optimized_prepare_density(int mode) #endif /* #ifndef FFT_COLUMN_BASED #else */ } - /* \brief Function to read out the force component corresponding to spatial * dimension 'dim'. * @@ -1333,13 +1322,13 @@ static void pmforce_uniform_optimized_prepare_density(int mode) static void pmforce_uniform_optimized_readout_forces_or_potential(int dim) { #ifdef EVALPOTENTIAL - double fac = 4 * M_PI * All.G / (pow(All.BoxSize, 3) * STRETCHX * STRETCHY * STRETCHZ); /* to get potential */ + double fac = 4 * M_PI * All.G / (pow(All.BoxSize, 3) * STRETCHX * STRETCHY * STRETCHZ); /* to get potential */ #endif /* #ifdef EVALPOTENTIAL */ double to_slab_fac = PMGRID / All.BoxSize; - double *flistin = (double *) mymalloc("flistin", nimport * sizeof(double)); - double *flistout = (double *) mymalloc("flistout", nexport * sizeof(double)); + double *flistin = (double *)mymalloc("flistin", nimport * sizeof(double)); + double *flistout = (double *)mymalloc("flistout", nexport * sizeof(double)); fft_real *grid; @@ -1353,9 +1342,9 @@ static void pmforce_uniform_optimized_readout_forces_or_potential(int dim) { flistin[i] = 0; - int slab_x = (int) (to_slab_fac * partin[i].Pos[0]); - int slab_y = (int) (to_slab_fac * partin[i].Pos[1]); - int slab_z = (int) (to_slab_fac * partin[i].Pos[2]); + int slab_x = (int)(to_slab_fac * partin[i].Pos[0]); + int slab_y = (int)(to_slab_fac * partin[i].Pos[1]); + int slab_z = (int)(to_slab_fac * partin[i].Pos[2]); double dx = to_slab_fac * partin[i].Pos[0] - slab_x; double dy = to_slab_fac * partin[i].Pos[1] - slab_y; @@ -1384,22 +1373,22 @@ static void pmforce_uniform_optimized_readout_forces_or_potential(int dim) { slab_x -= myplan.first_slab_x_of_task[ThisTask]; - flistin[i] += grid[FI(slab_x, slab_y, slab_z)] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) - + grid[FI(slab_x, slab_y, slab_zz)] * (1.0 - dx) * (1.0 - dy) * (dz) + grid[FI(slab_x, slab_yy, slab_z)] * (1.0 - dx) * (dy) * (1.0 - dz) + grid[FI(slab_x, slab_yy, slab_zz)] * (1.0 - - dx) * - (dy) * (dz); + flistin[i] += grid[FI(slab_x, slab_y, slab_z)] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) + + grid[FI(slab_x, slab_y, slab_zz)] * (1.0 - dx) * (1.0 - dy) * (dz) + + grid[FI(slab_x, slab_yy, slab_z)] * (1.0 - dx) * (dy) * (1.0 - dz) + + grid[FI(slab_x, slab_yy, slab_zz)] * (1.0 - dx) * (dy) * (dz); } if(myplan.slab_to_task[slab_xx] == ThisTask) { slab_xx -= myplan.first_slab_x_of_task[ThisTask]; - flistin[i] += grid[FI(slab_xx, slab_y, slab_z)] * (dx) * (1.0 - dy) * (1.0 - dz) - + grid[FI(slab_xx, slab_y, slab_zz)] * (dx) * (1.0 - dy) * (dz) - + grid[FI(slab_xx, slab_yy, slab_z)] * (dx) * (dy) * (1.0 - dz) - + grid[FI(slab_xx, slab_yy, slab_zz)] * (dx) * (dy) * (dz); + flistin[i] += grid[FI(slab_xx, slab_y, slab_z)] * (dx) * (1.0 - dy) * (1.0 - dz) + + grid[FI(slab_xx, slab_y, slab_zz)] * (dx) * (1.0 - dy) * (dz) + + grid[FI(slab_xx, slab_yy, slab_z)] * (dx) * (dy) * (1.0 - dz) + + grid[FI(slab_xx, slab_yy, slab_zz)] * (dx) * (dy) * (dz); } -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ int column0 = slab_x * GRIDY + slab_y; int column1 = slab_x * GRIDY + slab_yy; int column2 = slab_xx * GRIDY + slab_y; @@ -1407,25 +1396,24 @@ static void pmforce_uniform_optimized_readout_forces_or_potential(int dim) if(column0 >= myplan.base_firstcol && column0 <= myplan.base_lastcol) { - flistin[i] += grid[FC(column0, slab_z)] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) - + grid[FC(column0, slab_zz)] * (1.0 - dx) * (1.0 - dy) * (dz); + flistin[i] += grid[FC(column0, slab_z)] * (1.0 - dx) * (1.0 - dy) * (1.0 - dz) + + grid[FC(column0, slab_zz)] * (1.0 - dx) * (1.0 - dy) * (dz); } if(column1 >= myplan.base_firstcol && column1 <= myplan.base_lastcol) { - flistin[i] += grid[FC(column1, slab_z)] * (1.0 - dx) * (dy) * (1.0 - dz) - + grid[FC(column1, slab_zz)] * (1.0 - dx) * (dy) * (dz); + flistin[i] += + grid[FC(column1, slab_z)] * (1.0 - dx) * (dy) * (1.0 - dz) + grid[FC(column1, slab_zz)] * (1.0 - dx) * (dy) * (dz); } if(column2 >= myplan.base_firstcol && column2 <= myplan.base_lastcol) { - flistin[i] += grid[FC(column2, slab_z)] * (dx) * (1.0 - dy) * (1.0 - dz) - + grid[FC(column2, slab_zz)] * (dx) * (1.0 - dy) * (dz); + flistin[i] += + grid[FC(column2, slab_z)] * (dx) * (1.0 - dy) * (1.0 - dz) + grid[FC(column2, slab_zz)] * (dx) * (1.0 - dy) * (dz); } if(column3 >= myplan.base_firstcol && column3 <= myplan.base_lastcol) { - flistin[i] += grid[FC(column3, slab_z)] * (dx) * (dy) * (1.0 - dz) - + grid[FC(column3, slab_zz)] * (dx) * (dy) * (dz); + flistin[i] += grid[FC(column3, slab_z)] * (dx) * (dy) * (1.0 - dz) + grid[FC(column3, slab_zz)] * (dx) * (dy) * (dz); } #endif /* #ifndef FFT_COLUMN_BASED #else */ } @@ -1442,13 +1430,14 @@ static void pmforce_uniform_optimized_readout_forces_or_potential(int dim) MPI_Allreduce(&flag_big, &flag_big_all, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); /* exchange data */ - myMPI_Alltoallv(flistin, Rcvpm_count, Rcvpm_offset, flistout, Sndpm_count, Sndpm_offset, sizeof(double), flag_big_all, MPI_COMM_WORLD); + myMPI_Alltoallv(flistin, Rcvpm_count, Rcvpm_offset, flistout, Sndpm_count, Sndpm_offset, sizeof(double), flag_big_all, + MPI_COMM_WORLD); /* now assign them to the correct particles */ int multiNtask = roundup_to_multiple_of_cacheline_size(NTask * sizeof(size_t)) / sizeof(size_t); { - size_t *send_count = Sndpm_count + get_thread_num() * multiNtask; + size_t *send_count = Sndpm_count + get_thread_num() * multiNtask; size_t *send_offset = Sndpm_offset + get_thread_num() * multiNtask; int j; @@ -1474,7 +1463,7 @@ static void pmforce_uniform_optimized_readout_forces_or_potential(int dim) #endif /* #ifdef CELL_CENTER_GRAVITY */ pos = P[i].Pos; - int slab_x = (int) (to_slab_fac * pos[0]); + int slab_x = (int)(to_slab_fac * pos[0]); int slab_xx = slab_x + 1; if(slab_x >= GRIDX) @@ -1491,8 +1480,8 @@ static void pmforce_uniform_optimized_readout_forces_or_potential(int dim) if(task0 != task1) value += flistout[send_offset[task1] + send_count[task1]++]; -#else /* #ifndef FFT_COLUMN_BASED */ - int slab_y = (int) (to_slab_fac * pos[1]); +#else /* #ifndef FFT_COLUMN_BASED */ + int slab_y = (int)(to_slab_fac * pos[1]); int slab_yy = slab_y + 1; if(slab_y >= GRIDY) @@ -1561,7 +1550,6 @@ static void pmforce_uniform_optimized_readout_forces_or_potential(int dim) } #endif /* #ifdef PM_ZOOM_OPTIMIZED #else */ - /*! \brief Calculates the long-range periodic force given the particle * positions using the PM method. * @@ -1591,41 +1579,41 @@ void pmforce_periodic(int mode, int *typelist) mpi_printf("PM-PERIODIC: Starting periodic PM calculation. (presently allocated=%g MB)\n", AllocatedBytes / (1024.0 * 1024.0)); #ifndef NUMPART_PER_TASK_LARGE - if((((long long) NumPart) << 3) >= (((long long) 1) << 31)) + if((((long long)NumPart) << 3) >= (((long long)1) << 31)) terminate("We are dealing with a too large particle number per MPI rank - enabling NUMPART_PER_TASK_LARGE might help."); #endif /* #ifndef NUMPART_PER_TASK_LARGE */ double asmth2 = All.Asmth[0] * All.Asmth[0]; - double d = All.BoxSize / PMGRID; - double dhalf = 0.5 * d; + double d = All.BoxSize / PMGRID; + double dhalf = 0.5 * d; - double fac = 4 * M_PI * All.G / (pow(All.BoxSize, 3) * STRETCHX * STRETCHY * STRETCHZ); /* to get potential */ + double fac = 4 * M_PI * All.G / (pow(All.BoxSize, 3) * STRETCHX * STRETCHY * STRETCHZ); /* to get potential */ - fac *= 1 / (2 * d); /* for finite differencing */ + fac *= 1 / (2 * d); /* for finite differencing */ #ifdef PM_ZOOM_OPTIMIZED pmforce_zoom_optimized_prepare_density(mode, typelist); -#else /* #ifdef PM_ZOOM_OPTIMIZED */ +#else /* #ifdef PM_ZOOM_OPTIMIZED */ pmforce_uniform_optimized_prepare_density(mode); #endif /* #ifdef PM_ZOOM_OPTIMIZED #else */ /* allocate the memory to hold the FFT fields */ - forcegrid = (fft_real *) mymalloc("forcegrid", maxfftsize * sizeof(fft_real)); + forcegrid = (fft_real *)mymalloc("forcegrid", maxfftsize * sizeof(fft_real)); workspace = forcegrid; #ifndef FFT_COLUMN_BASED - fft_of_rhogrid = (fft_complex *) & rhogrid[0]; -#else /* #ifndef FFT_COLUMN_BASED */ - fft_of_rhogrid = (fft_complex *) & workspace[0]; + fft_of_rhogrid = (fft_complex *)&rhogrid[0]; +#else /* #ifndef FFT_COLUMN_BASED */ + fft_of_rhogrid = (fft_complex *)&workspace[0]; #endif /* #ifndef FFT_COLUMN_BASED #else */ /* Do the FFT of the density field */ #ifndef FFT_COLUMN_BASED my_slab_based_fft(&myplan, &rhogrid[0], &workspace[0], 1); -#else /* #ifndef FFT_COLUMN_BASED */ - my_column_based_fft(&myplan, rhogrid, workspace, 1); /* result is in workspace, not in rhogrid ! */ +#else /* #ifndef FFT_COLUMN_BASED */ + my_column_based_fft(&myplan, rhogrid, workspace, 1); /* result is in workspace, not in rhogrid ! */ #endif /* #ifndef FFT_COLUMN_BASED #else */ if(mode != 0) @@ -1643,87 +1631,87 @@ void pmforce_periodic(int mode, int *typelist) #ifdef FFT_COLUMN_BASED for(large_array_offset ip = 0; ip < myplan.second_transposed_ncells; ip++) { - large_array_offset ipcell = ip + ((large_array_offset) myplan.second_transposed_firstcol) * GRIDX; - y = ipcell / (GRIDX * GRIDz); - int yr = ipcell % (GRIDX * GRIDz); - z = yr / GRIDX; - x = yr % GRIDX; -#else /* #ifdef FFT_COLUMN_BASED */ + large_array_offset ipcell = ip + ((large_array_offset)myplan.second_transposed_firstcol) * GRIDX; + y = ipcell / (GRIDX * GRIDz); + int yr = ipcell % (GRIDX * GRIDz); + z = yr / GRIDX; + x = yr % GRIDX; +#else /* #ifdef FFT_COLUMN_BASED */ for(x = 0; x < GRIDX; x++) for(y = myplan.slabstart_y; y < myplan.slabstart_y + myplan.nslab_y; y++) for(z = 0; z < GRIDz; z++) { #endif /* #ifdef FFT_COLUMN_BASED #else */ - if(x >= (GRIDX / 2)) - xx = x - GRIDX; - else - xx = x; - if(y >= (GRIDY / 2)) - yy = y - GRIDY; - else - yy = y; - if(z >= (GRIDZ / 2)) - zz = z - GRIDZ; - else - zz = z; - - double kx = kfacx * xx; - double ky = kfacy * yy; - double kz = kfacz * zz; - - double k2 = kx * kx + ky * ky + kz * kz; - - if(k2 > 0) - { - double smth = -exp(-k2 * asmth2) / k2; + if(x >= (GRIDX / 2)) + xx = x - GRIDX; + else + xx = x; + if(y >= (GRIDY / 2)) + yy = y - GRIDY; + else + yy = y; + if(z >= (GRIDZ / 2)) + zz = z - GRIDZ; + else + zz = z; - /* do deconvolution */ + double kx = kfacx * xx; + double ky = kfacy * yy; + double kz = kfacz * zz; - double fx = 1, fy = 1, fz = 1; + double k2 = kx * kx + ky * ky + kz * kz; - if(xx != 0) - { - fx = kx * dhalf; - fx = sin(fx) / fx; - } - if(yy != 0) - { - fy = ky * dhalf; - fy = sin(fy) / fy; - } - if(zz != 0) - { - fz = kz * dhalf; - fz = sin(fz) / fz; - } + if(k2 > 0) + { + double smth = -exp(-k2 * asmth2) / k2; - double ff = 1 / (fx * fy * fz); - double deconv = ff * ff * ff * ff; + /* do deconvolution */ - smth *= deconv; /* deconvolution */ + double fx = 1, fy = 1, fz = 1; + + if(xx != 0) + { + fx = kx * dhalf; + fx = sin(fx) / fx; + } + if(yy != 0) + { + fy = ky * dhalf; + fy = sin(fy) / fy; + } + if(zz != 0) + { + fz = kz * dhalf; + fz = sin(fz) / fz; + } + + double ff = 1 / (fx * fy * fz); + double deconv = ff * ff * ff * ff; + + smth *= deconv; /* deconvolution */ #ifndef FFT_COLUMN_BASED - large_array_offset ip = ((large_array_offset) GRIDz) * (GRIDX * (y - myplan.slabstart_y) + x) + z; + large_array_offset ip = ((large_array_offset)GRIDz) * (GRIDX * (y - myplan.slabstart_y) + x) + z; #endif /* #ifndef FFT_COLUMN_BASED */ - fft_of_rhogrid[ip][0] *= smth; - fft_of_rhogrid[ip][1] *= smth; - } + fft_of_rhogrid[ip][0] *= smth; + fft_of_rhogrid[ip][1] *= smth; } + } #ifdef FFT_COLUMN_BASED if(myplan.second_transposed_firstcol == 0) fft_of_rhogrid[0][0] = fft_of_rhogrid[0][1] = 0.0; -#else /* #ifdef FFT_COLUMN_BASED */ +#else /* #ifdef FFT_COLUMN_BASED */ if(myplan.slabstart_y == 0) fft_of_rhogrid[0][0] = fft_of_rhogrid[0][1] = 0.0; #endif /* #ifdef FFT_COLUMN_BASED #else */ - /* Do the inverse FFT to get the potential/forces */ + /* Do the inverse FFT to get the potential/forces */ #ifndef FFT_COLUMN_BASED my_slab_based_fft(&myplan, &rhogrid[0], &workspace[0], -1); -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ my_column_based_fft(&myplan, workspace, rhogrid, -1); #endif /* #ifndef FFT_COLUMN_BASED #else */ @@ -1732,7 +1720,7 @@ void pmforce_periodic(int mode, int *typelist) #ifdef EVALPOTENTIAL #ifdef PM_ZOOM_OPTIMIZED pmforce_zoom_optimized_readout_forces_or_potential(-1); -#else /* #ifdef PM_ZOOM_OPTIMIZED */ +#else /* #ifdef PM_ZOOM_OPTIMIZED */ pmforce_uniform_optimized_readout_forces_or_potential(-1); #endif /* #ifdef PM_ZOOM_OPTIMIZED #else */ #endif /* #ifdef EVALPOTENTIAL */ @@ -1742,12 +1730,14 @@ void pmforce_periodic(int mode, int *typelist) */ for(int dim = 2; dim >= 0; dim--) /* Calculate each component of the force. */ { - /* we do the x component last, because for differencing the potential in the x-direction, we need to construct the transpose */ + /* we do the x component last, because for differencing the potential in the x-direction, we need to construct the transpose + */ #ifndef FFT_COLUMN_BASED if(dim == 0) { - my_slab_transposeA(&myplan, rhogrid, forcegrid); /* compute the transpose of the potential field for finite differencing */ + my_slab_transposeA(&myplan, rhogrid, + forcegrid); /* compute the transpose of the potential field for finite differencing */ /* note: for the x-direction, we difference the transposed field */ for(x = 0; x < GRIDX; x++) @@ -1764,10 +1754,11 @@ void pmforce_periodic(int mode, int *typelist) if(xll < 0) xll += GRIDX; - forcegrid[NI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[NI(xl, y, z)] - rhogrid[NI(xr, y, z)]) - (1.0 / 6) * (rhogrid[NI(xll, y, z)] - rhogrid[NI(xrr, y, z)])); + forcegrid[NI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[NI(xl, y, z)] - rhogrid[NI(xr, y, z)]) - + (1.0 / 6) * (rhogrid[NI(xll, y, z)] - rhogrid[NI(xrr, y, z)])); } - my_slab_transposeB(&myplan, forcegrid, rhogrid); /* reverse the transpose from above */ + my_slab_transposeB(&myplan, forcegrid, rhogrid); /* reverse the transpose from above */ } else { @@ -1787,7 +1778,8 @@ void pmforce_periodic(int mode, int *typelist) if(yll < 0) yll += GRIDY; - forcegrid[FI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[FI(x, yl, z)] - rhogrid[FI(x, yr, z)]) - (1.0 / 6) * (rhogrid[FI(x, yll, z)] - rhogrid[FI(x, yrr, z)])); + forcegrid[FI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[FI(x, yl, z)] - rhogrid[FI(x, yr, z)]) - + (1.0 / 6) * (rhogrid[FI(x, yll, z)] - rhogrid[FI(x, yrr, z)])); } else if(dim == 2) { @@ -1801,24 +1793,25 @@ void pmforce_periodic(int mode, int *typelist) if(zll < 0) zll += GRIDZ; - forcegrid[FI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[FI(x, y, zl)] - rhogrid[FI(x, y, zr)]) - (1.0 / 6) * (rhogrid[FI(x, y, zll)] - rhogrid[FI(x, y, zrr)])); + forcegrid[FI(x, y, z)] = fac * ((4.0 / 3) * (rhogrid[FI(x, y, zl)] - rhogrid[FI(x, y, zr)]) - + (1.0 / 6) * (rhogrid[FI(x, y, zll)] - rhogrid[FI(x, y, zrr)])); } } } -#else /* #ifndef FFT_COLUMN_BASED */ +#else /* #ifndef FFT_COLUMN_BASED */ if(dim == 2) { for(large_array_offset i = 0; i < myplan.base_ncol; i++) { fft_real *forcep = &forcegrid[GRID2 * i]; - fft_real *potp = &rhogrid[GRID2 * i]; + fft_real *potp = &rhogrid[GRID2 * i]; for(int z = 0; z < GRIDZ; z++) { - int zr = z + 1; - int zl = z - 1; + int zr = z + 1; + int zl = z - 1; int zrr = z + 2; int zll = z - 2; @@ -1837,7 +1830,7 @@ void pmforce_periodic(int mode, int *typelist) } else if(dim == 1) { - fft_real *scratch = mymalloc("scratch", myplan.fftsize * sizeof(fft_real)); /* need a third field as scratch space */ + fft_real *scratch = mymalloc("scratch", myplan.fftsize * sizeof(fft_real)); /* need a third field as scratch space */ memcpy(scratch, rhogrid, myplan.fftsize * sizeof(fft_real)); my_fft_swap23(&myplan, scratch, forcegrid); @@ -1845,12 +1838,12 @@ void pmforce_periodic(int mode, int *typelist) for(large_array_offset i = 0; i < myplan.ncol_XZ; i++) { fft_real *forcep = &scratch[GRIDY * i]; - fft_real *potp = &forcegrid[GRIDY * i]; + fft_real *potp = &forcegrid[GRIDY * i]; for(int y = 0; y < GRIDY; y++) { - int yr = y + 1; - int yl = y - 1; + int yr = y + 1; + int yl = y - 1; int yrr = y + 2; int yll = y - 2; @@ -1872,7 +1865,7 @@ void pmforce_periodic(int mode, int *typelist) } else if(dim == 0) { - fft_real *scratch = mymalloc("scratch", myplan.fftsize * sizeof(fft_real)); /* need a third field as scratch space */ + fft_real *scratch = mymalloc("scratch", myplan.fftsize * sizeof(fft_real)); /* need a third field as scratch space */ memcpy(scratch, rhogrid, myplan.fftsize * sizeof(fft_real)); my_fft_swap13(&myplan, scratch, forcegrid); @@ -1880,12 +1873,12 @@ void pmforce_periodic(int mode, int *typelist) for(large_array_offset i = 0; i < myplan.ncol_YZ; i++) { fft_real *forcep = &scratch[GRIDX * i]; - fft_real *potp = &forcegrid[GRIDX * i]; + fft_real *potp = &forcegrid[GRIDX * i]; for(int x = 0; x < GRIDX; x++) { - int xr = x + 1; - int xl = x - 1; + int xr = x + 1; + int xl = x - 1; int xrr = x + 2; int xll = x - 2; @@ -1909,11 +1902,10 @@ void pmforce_periodic(int mode, int *typelist) #ifdef PM_ZOOM_OPTIMIZED pmforce_zoom_optimized_readout_forces_or_potential(dim); -#else /* #ifdef PM_ZOOM_OPTIMIZED */ +#else /* #ifdef PM_ZOOM_OPTIMIZED */ pmforce_uniform_optimized_readout_forces_or_potential(dim); #endif /* #ifdef PM_ZOOM_OPTIMIZED #else */ } - } /* free stuff */ @@ -1929,7 +1921,7 @@ void pmforce_periodic(int mode, int *typelist) myfree(localfield_data); myfree(localfield_globalindex); myfree(part); -#else /* #ifdef PM_ZOOM_OPTIMIZED */ +#else /* #ifdef PM_ZOOM_OPTIMIZED */ myfree(partin); myfree(Rcvpm_offset); myfree(Rcvpm_count); @@ -1943,10 +1935,8 @@ void pmforce_periodic(int mode, int *typelist) mpi_printf("PM-PERIODIC: done. (took %g seconds)\n", timediff(tstart, tend)); } - #ifdef PM_ZOOM_OPTIMIZED - /*! \brief Sort function for 'part' array indices. * * Sorts the indices into the 'part' array by the global index of the @@ -1959,16 +1949,15 @@ void pmforce_periodic(int mode, int *typelist) */ static int pm_periodic_compare_sortindex(const void *a, const void *b) { - if(part[*(int *) a].globalindex < part[*(int *) b].globalindex) + if(part[*(int *)a].globalindex < part[*(int *)b].globalindex) return -1; - if(part[*(int *) a].globalindex > part[*(int *) b].globalindex) + if(part[*(int *)a].globalindex > part[*(int *)b].globalindex) return +1; return 0; } - /*! \brief Implements the sorting function for mysort_pmperiodic(). * * The index array is sorted using a merge sort algorithm. @@ -1979,7 +1968,7 @@ static int pm_periodic_compare_sortindex(const void *a, const void *b) * * \return void */ -static void msort_pmperiodic_with_tmp(large_numpart_type * b, size_t n, large_numpart_type * t) +static void msort_pmperiodic_with_tmp(large_numpart_type *b, size_t n, large_numpart_type *t) { large_numpart_type *tmp; large_numpart_type *b1, *b2; @@ -2018,7 +2007,6 @@ static void msort_pmperiodic_with_tmp(large_numpart_type * b, size_t n, large_nu memcpy(b, t, (n - n2) * sizeof(large_numpart_type)); } - /*! \brief Sort the index array b of n entries using the sort kernel * cmp. * @@ -2031,17 +2019,16 @@ static void msort_pmperiodic_with_tmp(large_numpart_type * b, size_t n, large_nu * \param[in] s Size of each entry (must be sizeof(int)). * \param[in] cmp Comparison function. */ -static void mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp) (const void *, const void *)) +static void mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp)(const void *, const void *)) { const size_t size = n * s; - large_numpart_type *tmp = (large_numpart_type *) mymalloc("tmp", size); + large_numpart_type *tmp = (large_numpart_type *)mymalloc("tmp", size); - msort_pmperiodic_with_tmp((large_numpart_type *) b, n, tmp); + msort_pmperiodic_with_tmp((large_numpart_type *)b, n, tmp); myfree(tmp); } #endif /* #ifdef PM_ZOOM_OPTIMIZED */ - #endif /* #if defined(PMGRID) */ diff --git a/src/gravity/pm/pm_periodic2d.c b/src/gravity/pm/pm_periodic2d.c index 5fa31b6f5db7b0d176c33447d7cd0b27ba2ba696..6ace982b68d562a52309d243289e450b0836befd 100644 --- a/src/gravity/pm/pm_periodic2d.c +++ b/src/gravity/pm/pm_periodic2d.c @@ -35,84 +35,68 @@ * fftw_real * scratch) * void pm2d_periodic_transposeB(fftw_real * field, * fftw_real * scratch) - * - * + * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 21.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <math.h> #include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> - #ifdef PMGRID #ifndef GRAVITY_NOT_PERIODIC #ifdef TWODIMS - #ifdef NOTYPEPREFIX_FFTW -#include <rfftw_mpi.h> +#include <rfftw_mpi.h> #else /* #ifdef NOTYPEPREFIX_FFTW */ #ifdef DOUBLEPRECISION_FFTW -#include <drfftw_mpi.h> /* double precision FFTW */ -#else /* #ifdef DOUBLEPRECISION_FFTW */ -#include <srfftw_mpi.h> +#include <drfftw_mpi.h> /* double precision FFTW */ +#else /* #ifdef DOUBLEPRECISION_FFTW */ +#include <srfftw_mpi.h> #endif /* #ifdef DOUBLEPRECISION_FFTW #else */ #endif /* #ifdef NOTYPEPREFIX_FFTW #else */ - #include "../../main/allvars.h" #include "../../main/proto.h" +#define PMGRID2 (2 * (PMGRID / 2 + 1)) -#define PMGRID2 (2*(PMGRID/2 + 1)) - - -#if (PMGRID > 1024) +#if(PMGRID > 1024) typedef long long large_array_offset; -#else /* #if (PMGRID > 1024) */ +#else /* #if (PMGRID > 1024) */ typedef unsigned int large_array_offset; #endif /* #if (PMGRID > 1024) #else */ - #define d_fftw_real fftw_real - static rfftwnd_mpi_plan fft_forward_plan, fft_inverse_plan; - static int slab_to_task[PMGRID]; static int *slabs_x_per_task; static int *first_slab_x_of_task; - static int slabstart_x, nslab_x, slabstart_y, nslab_y, smallest_slab; - static int fftsize, maxfftsize; - static fftw_real *rhogrid, *forcegrid, *workspace; static d_fftw_real *d_rhogrid, *d_forcegrid, *d_workspace; - static fftw_complex *fft_of_rhogrid; - static MyFloat to_slab_fac; - -void pm2d_periodic_transposeA(fftw_real * field, fftw_real * scratch); -void pm2d_periodic_transposeB(fftw_real * field, fftw_real * scratch); +void pm2d_periodic_transposeA(fftw_real *field, fftw_real *scratch); +void pm2d_periodic_transposeB(fftw_real *field, fftw_real *scratch); int pm2d_periodic_compare_sortindex(const void *a, const void *b); - /*! \brief Data for fft slab. */ static struct part_slab_data @@ -120,11 +104,10 @@ static struct part_slab_data large_array_offset globalindex; int partindex; int localindex; -} *part; +} * part; static int *part_sortindex; - /*! \brief This routines generates the FFTW-plans to carry out the parallel * FFTs later on. Some auxiliary variables are also initialized. * @@ -136,7 +119,7 @@ void pm2d_init_periodic(void) int slab_to_task_local[PMGRID]; All.Asmth[0] = ASMTH * All.BoxSize / PMGRID; - All.Rcut[0] = RCUT * All.Asmth[0]; + All.Rcut[0] = RCUT * All.Asmth[0]; /* Set up the FFTW plan files. */ @@ -157,21 +140,19 @@ void pm2d_init_periodic(void) MPI_Allreduce(&nslab_x, &smallest_slab, 1, MPI_INT, MPI_MIN, MPI_COMM_WORLD); - slabs_x_per_task = (int *) mymalloc("slabs_per_task", NTask * sizeof(int)); + slabs_x_per_task = (int *)mymalloc("slabs_per_task", NTask * sizeof(int)); MPI_Allgather(&nslab_x, 1, MPI_INT, slabs_x_per_task, 1, MPI_INT, MPI_COMM_WORLD); - first_slab_x_of_task = (int *) mymalloc("first_slab_of_task", NTask * sizeof(int)); + first_slab_x_of_task = (int *)mymalloc("first_slab_of_task", NTask * sizeof(int)); MPI_Allgather(&slabstart_x, 1, MPI_INT, first_slab_x_of_task, 1, MPI_INT, MPI_COMM_WORLD); to_slab_fac = PMGRID / All.BoxSize; MPI_Allreduce(&fftsize, &maxfftsize, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); - printf("maxfftsize=%d PMGRID=%d\n", maxfftsize, PMGRID); } - /*! \brief Allocates memory for 2d PM algorithm. * * This function allocates the memory neeed to compute the long-range PM @@ -190,31 +171,31 @@ void pm2d_init_periodic_allocate(void) /* allocate the memory to hold the FFT fields */ - rhogrid = (fftw_real *) mymalloc("rhogrid", bytes = maxfftsize * sizeof(d_fftw_real)); + rhogrid = (fftw_real *)mymalloc("rhogrid", bytes = maxfftsize * sizeof(d_fftw_real)); bytes_tot += bytes; - forcegrid = (fftw_real *) mymalloc("forcegrid", bytes = maxfftsize * sizeof(d_fftw_real)); + forcegrid = (fftw_real *)mymalloc("forcegrid", bytes = maxfftsize * sizeof(d_fftw_real)); bytes_tot += bytes; - part = (struct part_slab_data *) mymalloc("part", bytes = 4 * NumPart * sizeof(struct part_slab_data)); + part = (struct part_slab_data *)mymalloc("part", bytes = 4 * NumPart * sizeof(struct part_slab_data)); bytes_tot += bytes; - part_sortindex = (int *) mymalloc("part_sortindex", bytes = 4 * NumPart * sizeof(int)); + part_sortindex = (int *)mymalloc("part_sortindex", bytes = 4 * NumPart * sizeof(int)); bytes_tot += bytes; if(ThisTask == 0) - printf("Using %g MByte for periodic FFT computation. (presently allocated=%g MB)\n", bytes_tot / (1024.0 * 1024.0), AllocatedBytes / (1024.0 * 1024.0)); + printf("Using %g MByte for periodic FFT computation. (presently allocated=%g MB)\n", bytes_tot / (1024.0 * 1024.0), + AllocatedBytes / (1024.0 * 1024.0)); workspace = forcegrid; - fft_of_rhogrid = (fftw_complex *) & rhogrid[0]; + fft_of_rhogrid = (fftw_complex *)&rhogrid[0]; - d_rhogrid = (d_fftw_real *) rhogrid; - d_forcegrid = (d_fftw_real *) forcegrid; - d_workspace = (d_fftw_real *) workspace; + d_rhogrid = (d_fftw_real *)rhogrid; + d_forcegrid = (d_fftw_real *)forcegrid; + d_workspace = (d_fftw_real *)workspace; } - /*! \brief This routine frees the space allocated for the parallel FFT * algorithm. * @@ -229,7 +210,6 @@ void pm2d_init_periodic_free(void) myfree(rhogrid); } - /*! \brief Long range periodic 2d gravity. * * Calculates the long-range periodic force given the particle positions @@ -272,8 +252,8 @@ void pm2d_force_periodic(int mode) asmth2 = (2 * M_PI) * All.Asmth[0] / All.BoxSize; asmth2 *= asmth2; - fac = All.G / (M_PI * All.BoxSize); /* to get potential */ - fac *= 1 / (2 * All.BoxSize / PMGRID); /* for finite differencing */ + fac = All.G / (M_PI * All.BoxSize); /* to get potential */ + fac *= 1 / (2 * All.BoxSize / PMGRID); /* for finite differencing */ if(mode == 1) { @@ -294,8 +274,8 @@ void pm2d_force_periodic(int mode) /* determine the cells each particles accesses */ for(i = 0, num_on_grid = 0; i < N; i++) { - slab_x = (int) (to_slab_fac * P[i].Pos[0]); - slab_y = (int) (to_slab_fac * P[i].Pos[1]); + slab_x = (int)(to_slab_fac * P[i].Pos[0]); + slab_y = (int)(to_slab_fac * P[i].Pos[1]); if(slab_x >= PMGRID) slab_x = PMGRID - 1; @@ -315,9 +295,9 @@ void pm2d_force_periodic(int mode) offset = (PMGRID2 * slab_xx + slab_yy); - part[num_on_grid].partindex = (i << 2) + (xx << 1) + yy; + part[num_on_grid].partindex = (i << 2) + (xx << 1) + yy; part[num_on_grid].globalindex = offset; - part_sortindex[num_on_grid] = num_on_grid; + part_sortindex[num_on_grid] = num_on_grid; num_on_grid++; } } @@ -339,13 +319,13 @@ void pm2d_force_periodic(int mode) } /* allocate the local field */ - localfield_globalindex = (large_array_offset *) mymalloc("first_slab_of_task", num_field_points * sizeof(large_array_offset)); - localfield_d_data = (d_fftw_real *) mymalloc("localfield_d_data", num_field_points * sizeof(d_fftw_real)); - localfield_data = (fftw_real *) localfield_d_data; - localfield_first = (int *) mymalloc("localfield_d_data", NTask * sizeof(int)); - localfield_count = (int *) mymalloc("localfield_count", NTask * sizeof(int)); - localfield_offset = (int *) mymalloc("localfield_count", NTask * sizeof(int)); - localfield_togo = (int *) mymalloc("localfield_togo", NTask * NTask * sizeof(int)); + localfield_globalindex = (large_array_offset *)mymalloc("first_slab_of_task", num_field_points * sizeof(large_array_offset)); + localfield_d_data = (d_fftw_real *)mymalloc("localfield_d_data", num_field_points * sizeof(d_fftw_real)); + localfield_data = (fftw_real *)localfield_d_data; + localfield_first = (int *)mymalloc("localfield_d_data", NTask * sizeof(int)); + localfield_count = (int *)mymalloc("localfield_count", NTask * sizeof(int)); + localfield_offset = (int *)mymalloc("localfield_count", NTask * sizeof(int)); + localfield_togo = (int *)mymalloc("localfield_togo", NTask * NTask * sizeof(int)); for(i = 0; i < NTask; i++) { @@ -389,8 +369,8 @@ void pm2d_force_periodic(int mode) { pindex = (part[i].partindex >> 2); - slab_x = (int) (to_slab_fac * P[pindex].Pos[0]); - slab_y = (int) (to_slab_fac * P[pindex].Pos[1]); + slab_x = (int)(to_slab_fac * P[pindex].Pos[0]); + slab_y = (int)(to_slab_fac * P[pindex].Pos[1]); dx = to_slab_fac * P[pindex].Pos[0] - slab_x; dy = to_slab_fac * P[pindex].Pos[1] - slab_y; @@ -400,7 +380,7 @@ void pm2d_force_periodic(int mode) localfield_d_data[part[i + 0].localindex] += weight * (1.0 - dx) * (1.0 - dy); localfield_d_data[part[i + 1].localindex] += weight * (1.0 - dx) * dy; localfield_d_data[part[i + 2].localindex] += weight * (dx) * (1.0 - dy); - localfield_d_data[part[i + 3].localindex] += weight * (dx) * dy; + localfield_d_data[part[i + 3].localindex] += weight * (dx)*dy; } /* clear local FFT-mesh density field */ @@ -420,25 +400,28 @@ void pm2d_force_periodic(int mode) { if(level > 0) { - import_d_data = (d_fftw_real *) mymalloc("import_d_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(d_fftw_real)); - import_globalindex = (large_array_offset *) mymalloc("import_d_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(large_array_offset)); + import_d_data = + (d_fftw_real *)mymalloc("import_d_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(d_fftw_real)); + import_globalindex = (large_array_offset *)mymalloc( + "import_d_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(large_array_offset)); if(localfield_togo[sendTask * NTask + recvTask] > 0 || localfield_togo[recvTask * NTask + sendTask] > 0) { MPI_Sendrecv(localfield_d_data + localfield_offset[recvTask], - localfield_togo[sendTask * NTask + recvTask] * sizeof(d_fftw_real), - MPI_BYTE, recvTask, TAG_NONPERIOD_A, import_d_data, - localfield_togo[recvTask * NTask + sendTask] * sizeof(d_fftw_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); + localfield_togo[sendTask * NTask + recvTask] * sizeof(d_fftw_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, + import_d_data, localfield_togo[recvTask * NTask + sendTask] * sizeof(d_fftw_real), MPI_BYTE, recvTask, + TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); MPI_Sendrecv(localfield_globalindex + localfield_offset[recvTask], - localfield_togo[sendTask * NTask + recvTask] * sizeof(large_array_offset), - MPI_BYTE, recvTask, TAG_NONPERIOD_B, import_globalindex, - localfield_togo[recvTask * NTask + sendTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_B, MPI_COMM_WORLD, &status); + localfield_togo[sendTask * NTask + recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_B, import_globalindex, + localfield_togo[recvTask * NTask + sendTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_B, MPI_COMM_WORLD, &status); } } else { - import_d_data = localfield_d_data + localfield_offset[ThisTask]; + import_d_data = localfield_d_data + localfield_offset[ThisTask]; import_globalindex = localfield_globalindex + localfield_offset[ThisTask]; } @@ -458,7 +441,6 @@ void pm2d_force_periodic(int mode) } } - /* Do the FFT of the density field */ rfftwnd_mpi(fft_forward_plan, 1, rhogrid, workspace, FFTW_TRANSPOSED_ORDER); @@ -514,12 +496,10 @@ void pm2d_force_periodic(int mode) rfftwnd_mpi(fft_inverse_plan, 1, rhogrid, workspace, FFTW_TRANSPOSED_ORDER); - - -#ifdef EVALPOTENTIAL /* now read out the potential */ +#ifdef EVALPOTENTIAL /* now read out the potential */ if(mode == 0) { - for(level = 0; level < (1 << PTask); level++) /* note: for level=0, target is the same task */ + for(level = 0; level < (1 << PTask); level++) /* note: for level=0, target is the same task */ { sendTask = ThisTask; recvTask = ThisTask ^ level; @@ -528,37 +508,37 @@ void pm2d_force_periodic(int mode) { if(level > 0) { - import_data = (fftw_real *) mymalloc("import_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(fftw_real)); - import_globalindex = (large_array_offset *) mymalloc("import_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(large_array_offset)); + import_data = (fftw_real *)mymalloc("import_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(fftw_real)); + import_globalindex = (large_array_offset *)mymalloc( + "import_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(large_array_offset)); if(localfield_togo[sendTask * NTask + recvTask] > 0 || localfield_togo[recvTask * NTask + sendTask] > 0) { MPI_Sendrecv(localfield_globalindex + localfield_offset[recvTask], - localfield_togo[sendTask * NTask + - recvTask] * sizeof(large_array_offset), MPI_BYTE, - recvTask, TAG_NONPERIOD_C, import_globalindex, - localfield_togo[recvTask * NTask + sendTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_C, MPI_COMM_WORLD, &status); + localfield_togo[sendTask * NTask + recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_C, import_globalindex, + localfield_togo[recvTask * NTask + sendTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_C, MPI_COMM_WORLD, &status); } } else { - import_data = localfield_data + localfield_offset[ThisTask]; + import_data = localfield_data + localfield_offset[ThisTask]; import_globalindex = localfield_globalindex + localfield_offset[ThisTask]; } for(i = 0; i < localfield_togo[recvTask * NTask + sendTask]; i++) { - offset = import_globalindex[i] - first_slab_x_of_task[ThisTask] * ((large_array_offset) PMGRID2); + offset = import_globalindex[i] - first_slab_x_of_task[ThisTask] * ((large_array_offset)PMGRID2); import_data[i] = rhogrid[offset]; } if(level > 0) { - MPI_Sendrecv(import_data, - localfield_togo[recvTask * NTask + sendTask] * sizeof(fftw_real), MPI_BYTE, - recvTask, TAG_NONPERIOD_A, - localfield_data + localfield_offset[recvTask], - localfield_togo[sendTask * NTask + recvTask] * sizeof(fftw_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); + MPI_Sendrecv(import_data, localfield_togo[recvTask * NTask + sendTask] * sizeof(fftw_real), MPI_BYTE, recvTask, + TAG_NONPERIOD_A, localfield_data + localfield_offset[recvTask], + localfield_togo[sendTask * NTask + recvTask] * sizeof(fftw_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, + MPI_COMM_WORLD, &status); myfree(import_globalindex); myfree(import_data); @@ -575,18 +555,18 @@ void pm2d_force_periodic(int mode) while(j < num_on_grid && (part[j].partindex >> 2) != i) j++; - slab_x = (int) (to_slab_fac * P[i].Pos[0]); - dx = to_slab_fac * P[i].Pos[0] - slab_x; + slab_x = (int)(to_slab_fac * P[i].Pos[0]); + dx = to_slab_fac * P[i].Pos[0] - slab_x; - slab_y = (int) (to_slab_fac * P[i].Pos[1]); - dy = to_slab_fac * P[i].Pos[1] - slab_y; + slab_y = (int)(to_slab_fac * P[i].Pos[1]); + dy = to_slab_fac * P[i].Pos[1] - slab_y; - pot = - +localfield_data[part[j + 0].localindex] * (1.0 - dx) * (1.0 - dy) - + localfield_data[part[j + 1].localindex] * (1.0 - dx) * dy + localfield_data[part[j + 2].localindex] * dx * (1.0 - dy) + localfield_data[part[j + 3].localindex] * dx * dy; + pot = +localfield_data[part[j + 0].localindex] * (1.0 - dx) * (1.0 - dy) + + localfield_data[part[j + 1].localindex] * (1.0 - dx) * dy + localfield_data[part[j + 2].localindex] * dx * (1.0 - dy) + + localfield_data[part[j + 3].localindex] * dx * dy; P[i].PM_Potential += pot * fac * (2 * All.BoxSize / PMGRID); - /* compensate the finite differencing factor */ ; + /* compensate the finite differencing factor */; } } #endif /* #ifdef EVALPOTENTIAL */ @@ -595,9 +575,9 @@ void pm2d_force_periodic(int mode) and send back the results to the right CPUs */ for(dim = 1; dim >= 0; dim--) /* Calculate each component of the force. */ - { /* we do the x component last, because for differencing the potential in the x-direction, we need to contruct the transpose */ + { /* we do the x component last, because for differencing the potential in the x-direction, we need to contruct the transpose */ if(dim == 0) - pm2d_periodic_transposeA(rhogrid, forcegrid); /* compute the transpose of the potential field */ + pm2d_periodic_transposeA(rhogrid, forcegrid); /* compute the transpose of the potential field */ for(xx = slabstart_x; xx < (slabstart_x + nslab_x); xx++) for(y = 0; y < PMGRID; y++) @@ -606,8 +586,8 @@ void pm2d_force_periodic(int mode) yrr = yll = yr = yl = y; - yr = y + 1; - yl = y - 1; + yr = y + 1; + yl = y - 1; yrr = y + 2; yll = y - 2; if(yr >= PMGRID) @@ -621,21 +601,22 @@ void pm2d_force_periodic(int mode) if(dim == 0) { - forcegrid[x + y * nslab_x] - = fac * ((4.0 / 3) * (rhogrid[(x + yl * nslab_x)] - rhogrid[(x + yr * nslab_x)]) - (1.0 / 6) * (rhogrid[(x + yll * nslab_x)] - rhogrid[(x + yrr * nslab_x)])); + forcegrid[x + y * nslab_x] = fac * ((4.0 / 3) * (rhogrid[(x + yl * nslab_x)] - rhogrid[(x + yr * nslab_x)]) - + (1.0 / 6) * (rhogrid[(x + yll * nslab_x)] - rhogrid[(x + yrr * nslab_x)])); } else { - forcegrid[PMGRID2 * x + y] = fac * ((4.0 / 3) * (rhogrid[PMGRID2 * x + yl] - rhogrid[PMGRID2 * x + yr]) - (1.0 / 6) * (rhogrid[PMGRID2 * x + yll] - rhogrid[PMGRID2 * x + yrr])); + forcegrid[PMGRID2 * x + y] = fac * ((4.0 / 3) * (rhogrid[PMGRID2 * x + yl] - rhogrid[PMGRID2 * x + yr]) - + (1.0 / 6) * (rhogrid[PMGRID2 * x + yll] - rhogrid[PMGRID2 * x + yrr])); } } if(dim == 0) - pm2d_periodic_transposeB(forcegrid, rhogrid); /* compute the transpose of the potential field */ + pm2d_periodic_transposeB(forcegrid, rhogrid); /* compute the transpose of the potential field */ /* send the force components to the right processors */ - for(level = 0; level < (1 << PTask); level++) /* note: for level=0, target is the same task */ + for(level = 0; level < (1 << PTask); level++) /* note: for level=0, target is the same task */ { sendTask = ThisTask; recvTask = ThisTask ^ level; @@ -644,38 +625,38 @@ void pm2d_force_periodic(int mode) { if(level > 0) { - import_data = (fftw_real *) mymalloc("import_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(fftw_real)); - import_globalindex = (large_array_offset *) mymalloc("import_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(large_array_offset)); + import_data = (fftw_real *)mymalloc("import_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(fftw_real)); + import_globalindex = (large_array_offset *)mymalloc( + "import_data", localfield_togo[recvTask * NTask + ThisTask] * sizeof(large_array_offset)); if(localfield_togo[sendTask * NTask + recvTask] > 0 || localfield_togo[recvTask * NTask + sendTask] > 0) { MPI_Sendrecv(localfield_globalindex + localfield_offset[recvTask], - localfield_togo[sendTask * NTask + - recvTask] * sizeof(large_array_offset), MPI_BYTE, - recvTask, TAG_NONPERIOD_C, import_globalindex, - localfield_togo[recvTask * NTask + sendTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, TAG_NONPERIOD_C, MPI_COMM_WORLD, &status); + localfield_togo[sendTask * NTask + recvTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_C, import_globalindex, + localfield_togo[recvTask * NTask + sendTask] * sizeof(large_array_offset), MPI_BYTE, recvTask, + TAG_NONPERIOD_C, MPI_COMM_WORLD, &status); } } else { - import_data = localfield_data + localfield_offset[ThisTask]; + import_data = localfield_data + localfield_offset[ThisTask]; import_globalindex = localfield_globalindex + localfield_offset[ThisTask]; } for(i = 0; i < localfield_togo[recvTask * NTask + sendTask]; i++) { /* determine offset in local FFT slab */ - offset = import_globalindex[i] - first_slab_x_of_task[ThisTask] * PMGRID2; + offset = import_globalindex[i] - first_slab_x_of_task[ThisTask] * PMGRID2; import_data[i] = forcegrid[offset]; } if(level > 0) { - MPI_Sendrecv(import_data, - localfield_togo[recvTask * NTask + sendTask] * sizeof(fftw_real), MPI_BYTE, - recvTask, TAG_NONPERIOD_A, - localfield_data + localfield_offset[recvTask], - localfield_togo[sendTask * NTask + recvTask] * sizeof(fftw_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, MPI_COMM_WORLD, &status); + MPI_Sendrecv(import_data, localfield_togo[recvTask * NTask + sendTask] * sizeof(fftw_real), MPI_BYTE, recvTask, + TAG_NONPERIOD_A, localfield_data + localfield_offset[recvTask], + localfield_togo[sendTask * NTask + recvTask] * sizeof(fftw_real), MPI_BYTE, recvTask, TAG_NONPERIOD_A, + MPI_COMM_WORLD, &status); myfree(import_globalindex); myfree(import_data); @@ -690,15 +671,15 @@ void pm2d_force_periodic(int mode) while(j < num_on_grid && (part[j].partindex >> 2) != i) j++; - slab_x = (int) (to_slab_fac * P[i].Pos[0]); - dx = to_slab_fac * P[i].Pos[0] - slab_x; + slab_x = (int)(to_slab_fac * P[i].Pos[0]); + dx = to_slab_fac * P[i].Pos[0] - slab_x; - slab_y = (int) (to_slab_fac * P[i].Pos[1]); - dy = to_slab_fac * P[i].Pos[1] - slab_y; + slab_y = (int)(to_slab_fac * P[i].Pos[1]); + dy = to_slab_fac * P[i].Pos[1] - slab_y; - acc_dim = - +localfield_data[part[j + 0].localindex] * (1.0 - dx) * (1.0 - dy) - + localfield_data[part[j + 1].localindex] * (1.0 - dx) * dy + localfield_data[part[j + 2].localindex] * (dx) * (1.0 - dy) + localfield_data[part[j + 3].localindex] * (dx) * dy; + acc_dim = +localfield_data[part[j + 0].localindex] * (1.0 - dx) * (1.0 - dy) + + localfield_data[part[j + 1].localindex] * (1.0 - dx) * dy + + localfield_data[part[j + 2].localindex] * (dx) * (1.0 - dy) + localfield_data[part[j + 3].localindex] * (dx)*dy; P[i].GravPM[dim] += acc_dim; } @@ -717,7 +698,6 @@ void pm2d_force_periodic(int mode) mpi_printf("done PM-2d.\n"); } - /*! \brief Compares two objects of type part_slab_data. * * According to element globalindex. @@ -729,16 +709,15 @@ void pm2d_force_periodic(int mode) */ int pm2d_periodic_compare_sortindex(const void *a, const void *b) { - if(part[*(int *) a].globalindex < part[*(int *) b].globalindex) + if(part[*(int *)a].globalindex < part[*(int *)b].globalindex) return -1; - if(part[*(int *) a].globalindex > part[*(int *) b].globalindex) + if(part[*(int *)a].globalindex > part[*(int *)b].globalindex) return +1; return 0; } - /*! \brief Merge sort algorithm for 2d periodic particle mesh algorithm. * * \param[in, out] b Array to be sorted. @@ -786,7 +765,6 @@ static void pm2d_msort_pmperiodic_with_tmp(int *b, size_t n, int *t) memcpy(b, t, (n - n2) * sizeof(int)); } - /*! \brief Wrapper for sorting algorithm in 2d periodic PM algorithm. * * Uses pm2d_msort_pmperiodic_with_tmp. @@ -798,18 +776,17 @@ static void pm2d_msort_pmperiodic_with_tmp(int *b, size_t n, int *t) * * \return void */ -void pm2d_mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp) (const void *, const void *)) +void pm2d_mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp)(const void *, const void *)) { const size_t size = n * s; - int *tmp = (int *) mymalloc("tmp", size); + int *tmp = (int *)mymalloc("tmp", size); - pm2d_msort_pmperiodic_with_tmp((int *) b, n, tmp); + pm2d_msort_pmperiodic_with_tmp((int *)b, n, tmp); myfree(tmp); } - /*! \brief Transpose operation for 2d fft. * * Used for transposing rhogrid. @@ -819,7 +796,7 @@ void pm2d_mysort_pmperiodic(void *b, size_t n, size_t s, int (*cmp) (const void * * \return void */ -void pm2d_periodic_transposeA(fftw_real * field, fftw_real * scratch) +void pm2d_periodic_transposeA(fftw_real *field, fftw_real *scratch) { int x, y, task; @@ -827,25 +804,28 @@ void pm2d_periodic_transposeA(fftw_real * field, fftw_real * scratch) for(x = 0; x < nslab_x; x++) for(y = first_slab_x_of_task[task]; y < first_slab_x_of_task[task] + slabs_x_per_task[task]; y++) { - scratch[(first_slab_x_of_task[task] * nslab_x + x * slabs_x_per_task[task] + (y - first_slab_x_of_task[task]))] = field[PMGRID2 * x + y]; + scratch[(first_slab_x_of_task[task] * nslab_x + x * slabs_x_per_task[task] + (y - first_slab_x_of_task[task]))] = + field[PMGRID2 * x + y]; } #ifndef NO_ISEND_IRECV_IN_DOMAIN MPI_Request *requests; int nrequests = 0; - requests = (MPI_Request *) mymalloc(2 * NTask * sizeof(MPI_Request)); + requests = (MPI_Request *)mymalloc(2 * NTask * sizeof(MPI_Request)); for(task = 0; task < NTask; task++) { - MPI_Isend(scratch + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, TAG_KEY, MPI_COMM_WORLD, &requests[nrequests++]); + MPI_Isend(scratch + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, + TAG_KEY, MPI_COMM_WORLD, &requests[nrequests++]); - MPI_Irecv(field + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, TAG_KEY, MPI_COMM_WORLD, &requests[nrequests++]); + MPI_Irecv(field + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, + TAG_KEY, MPI_COMM_WORLD, &requests[nrequests++]); } MPI_Waitall(nrequests, requests, MPI_STATUSES_IGNORE); myfree(requests); -#else /* #ifndef NO_ISEND_IRECV_IN_DOMAIN */ +#else /* #ifndef NO_ISEND_IRECV_IN_DOMAIN */ int ngrp; for(ngrp = 0; ngrp < (1 << PTask); ngrp++) @@ -854,16 +834,15 @@ void pm2d_periodic_transposeA(fftw_real * field, fftw_real * scratch) if(task < NTask) { - MPI_Sendrecv(scratch + first_slab_x_of_task[task] * nslab_x, - nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), - MPI_BYTE, task, TAG_KEY, - field + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, TAG_KEY, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(scratch + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, + task, TAG_KEY, field + first_slab_x_of_task[task] * nslab_x, + nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, TAG_KEY, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); } } #endif /* #ifndef NO_ISEND_IRECV_IN_DOMAIN #else */ } - /*! \brief Transpose operation for 2d fft. * * Used for forcegrid transpose. @@ -873,7 +852,7 @@ void pm2d_periodic_transposeA(fftw_real * field, fftw_real * scratch) * * \return void */ -void pm2d_periodic_transposeB(fftw_real * field, fftw_real * scratch) +void pm2d_periodic_transposeB(fftw_real *field, fftw_real *scratch) { int x, y, task; @@ -881,20 +860,21 @@ void pm2d_periodic_transposeB(fftw_real * field, fftw_real * scratch) MPI_Request *requests; int nrequests = 0; - requests = (MPI_Request *) mymalloc(2 * NTask * sizeof(MPI_Request)); + requests = (MPI_Request *)mymalloc(2 * NTask * sizeof(MPI_Request)); for(task = 0; task < NTask; task++) { - MPI_Isend(field + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, TAG_KEY, MPI_COMM_WORLD, &requests[nrequests++]); + MPI_Isend(field + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, + TAG_KEY, MPI_COMM_WORLD, &requests[nrequests++]); - MPI_Irecv(scratch + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, TAG_KEY, MPI_COMM_WORLD, &requests[nrequests++]); + MPI_Irecv(scratch + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, + TAG_KEY, MPI_COMM_WORLD, &requests[nrequests++]); } - MPI_Waitall(nrequests, requests, MPI_STATUSES_IGNORE); myfree(requests); -#else /* #ifndef NO_ISEND_IRECV_IN_DOMAIN */ +#else /* #ifndef NO_ISEND_IRECV_IN_DOMAIN */ int ngrp; for(ngrp = 0; ngrp < (1 << PTask); ngrp++) @@ -903,10 +883,10 @@ void pm2d_periodic_transposeB(fftw_real * field, fftw_real * scratch) if(task < NTask) { - MPI_Sendrecv(field + first_slab_x_of_task[task] * nslab_x, - nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), - MPI_BYTE, task, TAG_KEY, - scratch + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, TAG_KEY, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(field + first_slab_x_of_task[task] * nslab_x, nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, + task, TAG_KEY, scratch + first_slab_x_of_task[task] * nslab_x, + nslab_x * slabs_x_per_task[task] * sizeof(fftw_real), MPI_BYTE, task, TAG_KEY, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); } } #endif /* #ifndef NO_ISEND_IRECV_IN_DOMAIN #else */ @@ -915,7 +895,8 @@ void pm2d_periodic_transposeB(fftw_real * field, fftw_real * scratch) for(x = 0; x < nslab_x; x++) for(y = first_slab_x_of_task[task]; y < first_slab_x_of_task[task] + slabs_x_per_task[task]; y++) { - field[PMGRID2 * x + y] = scratch[(first_slab_x_of_task[task] * nslab_x + x * slabs_x_per_task[task] + (y - first_slab_x_of_task[task]))]; + field[PMGRID2 * x + y] = + scratch[(first_slab_x_of_task[task] * nslab_x + x * slabs_x_per_task[task] + (y - first_slab_x_of_task[task]))]; } } diff --git a/src/mesh/voronoi/voronoi.c b/src/mesh/voronoi/voronoi.c index 76774d5465a14171a9d8a917e8292918a0cd07cb..cc6964c01be7c5e74efef6237dba579a99b2b34d 100644 --- a/src/mesh/voronoi/voronoi.c +++ b/src/mesh/voronoi/voronoi.c @@ -40,66 +40,56 @@ * int face_get_normals(tessellation * T, int i, struct * geometry *geom) * double distance_to_border(int cell) - * - * + * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 21.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - tessellation Mesh, DeRefMesh; - unsigned char *Edge_visited; struct area_list_data *AreaList; int Narea, MaxNarea; - -int DPinfinity; /* marker for special infinity point */ +int DPinfinity; /* marker for special infinity point */ double CentralOffsetX, CentralOffsetY, CentralOffsetZ, ConversionFac; - struct list_export_data *ListExports; struct list_P_data *List_P; int NumGasInMesh; int *List_InMesh; - int CountInSphereTests, CountInSphereTestsExact; int CountConvexEdgeTest, CountConvexEdgeTestExact; int Ninlist, MaxNinlist; - int CountFlips, Count_1_to_3_Flips2d, Count_2_to_4_Flips2d; int Count_1_to_4_Flips, Count_2_to_3_Flips, Count_3_to_2_Flips, Count_4_to_4_Flips; int Count_EdgeSplits, Count_FaceSplits; int Count_InTetra, Count_InTetraExact; int Largest_N_DP_Buffer; - long long TotCountInSphereTests, TotCountInSphereTestsExact; long long TotCountConvexEdgeTest, TotCountConvexEdgeTestExact; - long long TotCountFlips, TotCount_1_to_3_Flips2d, TotCount_2_to_4_Flips2d; long long TotCount_1_to_4_Flips, TotCount_2_to_3_Flips, TotCount_3_to_2_Flips, TotCount_4_to_4_Flips; long long TotCount_EdgeSplits, TotCount_FaceSplits; long long TotCount_InTetra, TotCount_InTetraExact; - /*! \brief Creates the Voronoi mesh. * * Routine which is called in run. @@ -121,7 +111,7 @@ void create_mesh(void) for(k = 0; k < NumPart; k++) { - buTimeBin[k] = P[k].TimeBinHydro; + buTimeBin[k] = P[k].TimeBinHydro; P[k].TimeBinHydro = 0; } @@ -169,20 +159,20 @@ void create_mesh(void) CountInSphereTests = CountInSphereTestsExact = 0; CountConvexEdgeTest = CountConvexEdgeTestExact = 0; CountFlips = Count_1_to_3_Flips2d = Count_2_to_4_Flips2d = 0; - Count_1_to_4_Flips = 0; - Count_2_to_3_Flips = 0; - Count_3_to_2_Flips = 0; - Count_4_to_4_Flips = 0; - Count_EdgeSplits = 0; - Count_FaceSplits = 0; + Count_1_to_4_Flips = 0; + Count_2_to_3_Flips = 0; + Count_3_to_2_Flips = 0; + Count_4_to_4_Flips = 0; + Count_EdgeSplits = 0; + Count_FaceSplits = 0; Count_InTetra = Count_InTetraExact = 0; - Largest_N_DP_Buffer = 0; + Largest_N_DP_Buffer = 0; - MaxNinlist = Mesh.Indi.AllocFacNinlist; + MaxNinlist = Mesh.Indi.AllocFacNinlist; ListExports = mymalloc_movable(&ListExports, "ListExports", MaxNinlist * sizeof(struct list_export_data)); NumGasInMesh = 0; - List_InMesh = mymalloc_movable(&List_InMesh, "List_InMesh", NumGas * sizeof(int)); + List_InMesh = mymalloc_movable(&List_InMesh, "List_InMesh", NumGas * sizeof(int)); List_P = mymalloc_movable(&List_P, "List_P", NumGas * sizeof(struct list_P_data)); @@ -222,11 +212,13 @@ void create_mesh(void) tend = second(); if(iter == 0) - mpi_printf("VORONOI: iter=%d: %llu local points, points/sec/task = %g, took %g secs\n", iter, ntot, ntot / (timediff(tstart, tend) + 1.0e-30) / NTask, timediff(tstart, tend)); + mpi_printf("VORONOI: iter=%d: %llu local points, points/sec/task = %g, took %g secs\n", iter, ntot, + ntot / (timediff(tstart, tend) + 1.0e-30) / NTask, timediff(tstart, tend)); else { if(ntot) - mpi_printf("VORONOI: iter=%d: %llu additional points, points/sec/task = %g, took %g secs\n", iter, ntot, ntot / (timediff(tstart, tend) + 1.0e-30) / NTask, timediff(tstart, tend)); + mpi_printf("VORONOI: iter=%d: %llu additional points, points/sec/task = %g, took %g secs\n", iter, ntot, + ntot / (timediff(tstart, tend) + 1.0e-30) / NTask, timediff(tstart, tend)); else mpi_printf("VORONOI: iter=%d: %llu additional points, took %g secs\n", iter, ntot, timediff(tstart, tend)); } @@ -263,7 +255,7 @@ void create_mesh(void) continue; SphP[i].Hsml *= HSML_INCREASE_FACTOR; } -#else /* #ifndef DOUBLE_STENCIL */ +#else /* #ifndef DOUBLE_STENCIL */ for(i = 0; i < Mesh.Ndp; i++) Mesh.DP[i].Hsml *= HSML_INCREASE_FACTOR; #endif /* #ifndef DOUBLE_STENCIL #else */ @@ -283,16 +275,16 @@ void create_mesh(void) } while(ntot > 0); -#if (REFLECTIVE_X == 2) || (REFLECTIVE_Y == 2) || (REFLECTIVE_Z == 2) +#if(REFLECTIVE_X == 2) || (REFLECTIVE_Y == 2) || (REFLECTIVE_Z == 2) for(i = 0; i < Mesh.Ndp; i++) { -#if (REFLECTIVE_X == 2) +#if(REFLECTIVE_X == 2) Mesh.DP[i].image_flags |= OUTFLOW_X; #endif /* #if (REFLECTIVE_X == 2) */ -#if (REFLECTIVE_Y == 2) +#if(REFLECTIVE_Y == 2) Mesh.DP[i].image_flags |= OUTFLOW_Y; #endif /* #if (REFLECTIVE_Y == 2) */ -#if (REFLECTIVE_Z == 2) +#if(REFLECTIVE_Z == 2) Mesh.DP[i].image_flags |= OUTFLOW_Z; #endif /* #if (REFLECTIVE_Z == 2) */ } @@ -316,40 +308,40 @@ void create_mesh(void) in[5] = Count_InTetra; in[6] = Count_InTetraExact; #ifndef TWODIMS - in[7] = Count_1_to_4_Flips; - in[8] = Count_2_to_3_Flips; - in[9] = Count_3_to_2_Flips; + in[7] = Count_1_to_4_Flips; + in[8] = Count_2_to_3_Flips; + in[9] = Count_3_to_2_Flips; in[10] = Count_4_to_4_Flips; in[11] = Count_FaceSplits; in[12] = Count_EdgeSplits; in[13] = CountConvexEdgeTest; in[14] = CountConvexEdgeTestExact; - n = 15; -#else /* #ifndef TWODIMS */ - in[7] = Count_1_to_3_Flips2d; - in[8] = Count_2_to_4_Flips2d; - n = 9; + n = 15; +#else /* #ifndef TWODIMS */ + in[7] = Count_1_to_3_Flips2d; + in[8] = Count_2_to_4_Flips2d; + n = 9; #endif /* #ifndef TWODIMS #else */ sumup_large_ints(n, in, out); - TotNdp = out[0]; - TotNdt = out[1]; - TotCountInSphereTests = out[2]; + TotNdp = out[0]; + TotNdt = out[1]; + TotCountInSphereTests = out[2]; TotCountInSphereTestsExact = out[3]; - TotCountFlips = out[4]; - TotCount_InTetra = out[5]; - TotCount_InTetraExact = out[6]; + TotCountFlips = out[4]; + TotCount_InTetra = out[5]; + TotCount_InTetraExact = out[6]; #ifndef TWODIMS - TotCount_1_to_4_Flips = out[7]; - TotCount_2_to_3_Flips = out[8]; - TotCount_3_to_2_Flips = out[9]; - TotCount_4_to_4_Flips = out[10]; - TotCount_FaceSplits = out[11]; - TotCount_EdgeSplits = out[12]; - TotCountConvexEdgeTest = out[13]; + TotCount_1_to_4_Flips = out[7]; + TotCount_2_to_3_Flips = out[8]; + TotCount_3_to_2_Flips = out[9]; + TotCount_4_to_4_Flips = out[10]; + TotCount_FaceSplits = out[11]; + TotCount_EdgeSplits = out[12]; + TotCountConvexEdgeTest = out[13]; TotCountConvexEdgeTestExact = out[14]; -#else /* #ifndef TWODIMS */ +#else /* #ifndef TWODIMS */ TotCount_1_to_3_Flips2d = out[7]; TotCount_2_to_4_Flips2d = out[8]; #endif /* #ifndef TWODIMS #else */ @@ -357,19 +349,25 @@ void create_mesh(void) if(ThisTask == 0) { #ifndef TWODIMS - printf("VORONOI: Average D-Points=%llu (NumGas=%llu) D-Tetrahedra=%llu InSphereTests=%llu InSphereTestsExact=%llu Flips=%llu\n", - TotNdp / NTask, All.TotNumGas / NTask, TotNdt / NTask, TotCountInSphereTests / NTask, TotCountInSphereTestsExact / NTask, TotCountFlips / NTask); + printf( + "VORONOI: Average D-Points=%llu (NumGas=%llu) D-Tetrahedra=%llu InSphereTests=%llu InSphereTestsExact=%llu " + "Flips=%llu\n", + TotNdp / NTask, All.TotNumGas / NTask, TotNdt / NTask, TotCountInSphereTests / NTask, TotCountInSphereTestsExact / NTask, + TotCountFlips / NTask); printf("VORONOI: 1_to_4_Flips=%llu 2_to_3_Flips=%llu 3_to_2_Flips=%llu 4_to_4_Flips=%llu FaceSplits=%llu EdgeSplits=%llu\n", - TotCount_1_to_4_Flips / NTask, TotCount_2_to_3_Flips / NTask, TotCount_3_to_2_Flips / NTask, TotCount_4_to_4_Flips / NTask, TotCount_FaceSplits / NTask, TotCount_EdgeSplits / NTask); + TotCount_1_to_4_Flips / NTask, TotCount_2_to_3_Flips / NTask, TotCount_3_to_2_Flips / NTask, + TotCount_4_to_4_Flips / NTask, TotCount_FaceSplits / NTask, TotCount_EdgeSplits / NTask); printf("VORONOI: InTetra=%llu InTetraExact=%llu ConvexEdgeTest=%llu ConvexEdgeTestExact=%llu\n", TotCount_InTetra, TotCount_InTetraExact / NTask, TotCountConvexEdgeTest / NTask, TotCountConvexEdgeTestExact / NTask); -#else /* #ifndef TWODIMS */ - printf("VORONOI: Average D-Points=%llu (NumGas=%llu) D-Triangles=%llu InCircleTests=%llu InCircleTestsExact=%llu Flips=%llu\n", - TotNdp / NTask, All.TotNumGas / NTask, TotNdt / NTask, TotCountInSphereTests / NTask, TotCountInSphereTestsExact / NTask, TotCountFlips / NTask); +#else /* #ifndef TWODIMS */ + printf( + "VORONOI: Average D-Points=%llu (NumGas=%llu) D-Triangles=%llu InCircleTests=%llu InCircleTestsExact=%llu Flips=%llu\n", + TotNdp / NTask, All.TotNumGas / NTask, TotNdt / NTask, TotCountInSphereTests / NTask, TotCountInSphereTestsExact / NTask, + TotCountFlips / NTask); printf("VORONOI: 1_to_3_Flips=%llu 2_to_4_Flips=%llu InTriangle=%llu InTriangleExact=%llu\n", TotCount_1_to_3_Flips2d / NTask, TotCount_2_to_4_Flips2d / NTask, TotCount_InTetra / NTask, TotCount_InTetraExact / NTask); #endif /* #ifndef TWODIMS #else */ - printf("VORONOI: Total D-Points: %llu Ratio=%g\n", TotNdp, ((double) TotNdp) / All.TotNumGas); + printf("VORONOI: Total D-Points: %llu Ratio=%g\n", TotNdp, ((double)TotNdp) / All.TotNumGas); } #endif /* #ifdef VERBOSE */ @@ -381,7 +379,7 @@ void create_mesh(void) if(i < 0) continue; - SphP[i].Volume = 0; + SphP[i].Volume = 0; SphP[i].SurfaceArea = 0; #if defined(REGULARIZE_MESH_FACE_ANGLE) || defined(OUTPUT_MESH_FACE_ANGLE) SphP[i].MaxFaceAngle = 0; @@ -419,7 +417,7 @@ void create_mesh(void) myfree(Mesh.DTF); - if(All.HighestActiveTimeBin == All.HighestOccupiedTimeBin) /* only do this for full steps */ + if(All.HighestActiveTimeBin == All.HighestOccupiedTimeBin) /* only do this for full steps */ { /* check whether we can reduce allocation factors */ while(Mesh.Ndp < ALLOC_DECREASE_FACTOR * Mesh.Indi.AllocFacNdp && Mesh.Indi.AllocFacNdp > MIN_ALLOC_NUMBER) @@ -434,7 +432,8 @@ void create_mesh(void) while(Ninlist < ALLOC_DECREASE_FACTOR * Mesh.Indi.AllocFacNinlist && Mesh.Indi.AllocFacNinlist > MIN_ALLOC_NUMBER) Mesh.Indi.AllocFacNinlist /= ALLOC_INCREASE_FACTOR; - while(Largest_N_DP_Buffer < ALLOC_DECREASE_FACTOR * Mesh.Indi.AllocFacN_DP_Buffer && Mesh.Indi.AllocFacN_DP_Buffer > MIN_ALLOC_NUMBER) + while(Largest_N_DP_Buffer < ALLOC_DECREASE_FACTOR * Mesh.Indi.AllocFacN_DP_Buffer && + Mesh.Indi.AllocFacN_DP_Buffer > MIN_ALLOC_NUMBER) Mesh.Indi.AllocFacN_DP_Buffer /= ALLOC_INCREASE_FACTOR; } @@ -451,7 +450,6 @@ void create_mesh(void) #endif /* #if defined(CREATE_FULL_MESH) */ } - /*! \brief Routine that fetches local gas cells. * * Runs through all active particles and inserts active gas cells into mesh @@ -475,9 +473,9 @@ int voronoi_get_local_particles(void) { Ngb_Marker[p] = Ngb_MarkerValue; - if((P[p].Mass == 0) && (P[p].ID == 0)) /* skip cells that have been swallowed or eliminated */ + if((P[p].Mass == 0) && (P[p].ID == 0)) /* skip cells that have been swallowed or eliminated */ { - List_P[p].firstexport = -1; + List_P[p].firstexport = -1; List_P[p].currentexport = -1; continue; } @@ -487,7 +485,8 @@ int voronoi_get_local_particles(void) Mesh.Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = Mesh.Indi.AllocFacNinlist; #ifdef VERBOSE - printf("VORONOI: Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, Mesh.Indi.AllocFacNinlist); + printf("VORONOI: Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, + Mesh.Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -500,15 +499,16 @@ int voronoi_get_local_particles(void) List_P[p].currentexport = List_P[p].firstexport = Ninlist++; ListExports[List_P[p].currentexport].image_bits = 1; ListExports[List_P[p].currentexport].nextexport = -1; - ListExports[List_P[p].currentexport].origin = ThisTask; - ListExports[List_P[p].currentexport].index = p; + ListExports[List_P[p].currentexport].origin = ThisTask; + ListExports[List_P[p].currentexport].index = p; if(Mesh.Ndp >= Mesh.MaxNdp) { Mesh.Indi.AllocFacNdp *= ALLOC_INCREASE_FACTOR; Mesh.MaxNdp = Mesh.Indi.AllocFacNdp; #ifdef VERBOSE - printf("VORONOI: Task=%d: increase memory allocation, MaxNdp=%d Indi.AllocFacNdp=%g\n", ThisTask, Mesh.MaxNdp, Mesh.Indi.AllocFacNdp); + printf("VORONOI: Task=%d: increase memory allocation, MaxNdp=%d Indi.AllocFacNdp=%g\n", ThisTask, Mesh.MaxNdp, + Mesh.Indi.AllocFacNdp); #endif /* #ifdef VERBOSE */ Mesh.DP -= 5; Mesh.DP = myrealloc_movable(Mesh.DP, (Mesh.MaxNdp + 5) * sizeof(point)); @@ -522,19 +522,19 @@ int voronoi_get_local_particles(void) point *dp = &Mesh.DP[Mesh.Ndp]; - dp->x = P[p].Pos[0]; - dp->y = P[p].Pos[1]; - dp->z = P[p].Pos[2]; - dp->ID = P[p].ID; - dp->task = ThisTask; - dp->index = p; + dp->x = P[p].Pos[0]; + dp->y = P[p].Pos[1]; + dp->z = P[p].Pos[2]; + dp->ID = P[p].ID; + dp->task = ThisTask; + dp->index = p; dp->originalindex = -1; - dp->timebin = P[p].TimeBinHydro; - dp->image_flags = 1; + dp->timebin = P[p].TimeBinHydro; + dp->image_flags = 1; #ifdef DOUBLE_STENCIL - dp->Hsml = SphP[p].Hsml; + dp->Hsml = SphP[p].Hsml; dp->first_connection = -1; - dp->last_connection = -1; + dp->last_connection = -1; #endif /* #ifdef DOUBLE_STENCIL */ Mesh.Ndp++; @@ -545,11 +545,9 @@ int voronoi_get_local_particles(void) return count; } - #ifdef REFINEMENT struct refdata *RefExch; - /*! \brief Structures that are freed before refinement and derefinement step. * * To Optimize the memory usage, this, in comubnation with @@ -567,7 +565,7 @@ void free_mesh_structures_not_needed_for_derefinement_refinement(void) myfree(GradExch); - RefExch = (struct refdata *) mymalloc_movable(&RefExch, "RefExch", Mesh_nimport * sizeof(struct refdata)); + RefExch = (struct refdata *)mymalloc_movable(&RefExch, "RefExch", Mesh_nimport * sizeof(struct refdata)); for(i = 0; i < Mesh_nimport; i++) { @@ -580,7 +578,6 @@ void free_mesh_structures_not_needed_for_derefinement_refinement(void) myfree_movable(PrimExch); } - /* \brief Structures that are freed after refinement and derefinement step. * * To Optimize the memory usage, this, in comubnation with @@ -596,7 +593,7 @@ void free_all_remaining_mesh_structures(void) myfree(RefExch); - myfree(Mesh.DTC); /* here we can free the centers of the Delaunay triangles again */ + myfree(Mesh.DTC); /* here we can free the centers of the Delaunay triangles again */ Mesh.DTC = NULL; myfree(List_P); myfree(List_InMesh); @@ -607,7 +604,6 @@ void free_all_remaining_mesh_structures(void) } #endif /* #ifdef REFINEMENT */ - /*! \brief Frees arrays associated with Voronoi-mesh. * * \return void @@ -628,12 +624,12 @@ void free_mesh(void) int q = Mesh.DP[i].first_connection; - if(q >= 0) /* we have connections, let's add them to the free list */ + if(q >= 0) /* we have connections, let's add them to the free list */ { while(q >= 0) { Nvc--; - DC[q].task = -1; /* mark that this is unused */ + DC[q].task = -1; /* mark that this is unused */ if(q == Mesh.DP[i].last_connection) break; @@ -643,10 +639,10 @@ void free_mesh(void) /* we add the new free spots at the beginning of the free list */ DC[Mesh.DP[i].last_connection].next = FirstUnusedConnection; - FirstUnusedConnection = Mesh.DP[i].first_connection; + FirstUnusedConnection = Mesh.DP[i].first_connection; Mesh.DP[i].first_connection = -1; - Mesh.DP[i].last_connection = -1; + Mesh.DP[i].last_connection = -1; } } mpi_printf("done with freeing double stencil connections.\n"); @@ -655,7 +651,7 @@ void free_mesh(void) myfree_movable(GradExch); myfree_movable(PrimExch); - myfree_movable(Mesh.DTC); /* here we can free the centers of the Delaunay triangles again */ + myfree_movable(Mesh.DTC); /* here we can free the centers of the Delaunay triangles again */ Mesh.DTC = NULL; myfree_movable(List_P); myfree_movable(List_InMesh); @@ -665,7 +661,6 @@ void free_mesh(void) myfree_movable(Mesh.VF); } - /*! \brief Get the maximum Delaunay radius for all active cells. * * Defined as the maximum distance between tetrahedron center and its @@ -693,13 +688,13 @@ int compute_max_delaunay_radius(void) SphP[i].MaxDelaunayRadius = 0; } - point *DP = Mesh.DP; - tetra *DT = Mesh.DT; + point *DP = Mesh.DP; + tetra *DT = Mesh.DT; tetra_center *DTC = Mesh.DTC; for(i = 0; i < Mesh.Ndt; i++) { - if(DT[i].t[0] < 0) /* deleted ? */ + if(DT[i].t[0] < 0) /* deleted ? */ continue; dx = DP[DT[i].p[0]].x - DTC[i].cx; @@ -722,7 +717,6 @@ int compute_max_delaunay_radius(void) return count; } - #ifndef ONEDIMS /*! \brief Computes interface areas volume of cells. * @@ -742,7 +736,7 @@ void compute_voronoi_faces_and_volumes(void) if(i < 0) continue; - SphP[i].Volume = 0; + SphP[i].Volume = 0; SphP[i].Center[0] = 0; SphP[i].Center[1] = 0; SphP[i].Center[2] = 0; @@ -757,16 +751,16 @@ void compute_voronoi_faces_and_volumes(void) Edge_visited[i] = 0; MaxNarea = Mesh.Indi.AllocFacNflux; - Narea = 0; + Narea = 0; AreaList = mymalloc_movable(&AreaList, "AreaList", MaxNarea * sizeof(struct area_list_data)); for(i = 0; i < Mesh.Ndt; i++) { - if(Mesh.DT[i].t[0] < 0) /* deleted ? */ + if(Mesh.DT[i].t[0] < 0) /* deleted ? */ continue; bit = 1; - nr = 0; + nr = 0; while(Edge_visited[i] != EDGE_ALL) { @@ -798,7 +792,6 @@ void compute_voronoi_faces_and_volumes(void) myfree(Edge_visited); } - /*! \brief Compare task of two area_list_data structures. * * \param[in] a Pointer to first area_list_data structure. @@ -808,16 +801,15 @@ void compute_voronoi_faces_and_volumes(void) */ int area_list_data_compare(const void *a, const void *b) { - if(((struct area_list_data *) a)->task < (((struct area_list_data *) b)->task)) + if(((struct area_list_data *)a)->task < (((struct area_list_data *)b)->task)) return -1; - if(((struct area_list_data *) a)->task > (((struct area_list_data *) b)->task)) + if(((struct area_list_data *)a)->task > (((struct area_list_data *)b)->task)) return +1; return 0; } - /*! \brief Sorts all interface areas and adds them to respective mesh * generating points (ActiveArea). * @@ -850,7 +842,7 @@ void apply_area_list(void) } } - struct area_list_data *AreaListGet = (struct area_list_data *) mymalloc("AreaListGet", nimport * sizeof(struct area_list_data)); + struct area_list_data *AreaListGet = (struct area_list_data *)mymalloc("AreaListGet", nimport * sizeof(struct area_list_data)); /* exchange particle data */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) @@ -862,10 +854,9 @@ void apply_area_list(void) if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the particles */ - MPI_Sendrecv(&AreaList[Send_offset[recvTask]], - Send_count[recvTask] * sizeof(struct area_list_data), MPI_BYTE, - recvTask, TAG_DENS_A, - &AreaListGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct area_list_data), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&AreaList[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct area_list_data), MPI_BYTE, recvTask, + TAG_DENS_A, &AreaListGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct area_list_data), + MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } @@ -880,7 +871,6 @@ void apply_area_list(void) myfree(AreaListGet); } - /*! \brief Calculates volumes of all cells that are created in refinement. * * \param[out] vol Volumes of cells. @@ -901,11 +891,11 @@ void derefine_refine_compute_volumes(double *vol) for(i = 0; i < DeRefMesh.Ndt; i++) { - if(DeRefMesh.DT[i].t[0] < 0) /* deleted ? */ + if(DeRefMesh.DT[i].t[0] < 0) /* deleted ? */ continue; bit = 1; - nr = 0; + nr = 0; while(Edge_visited[i] != EDGE_ALL) { @@ -920,10 +910,8 @@ void derefine_refine_compute_volumes(double *vol) myfree(Edge_visited); } - #endif /* #ifndef ONEDIMS */ - /*! \brief Nearest distance in x direction, accounting for periodicity. * * \param[in] d Distance to be checked. @@ -941,7 +929,6 @@ double nearest_x(double d) return d; } - /*! \brief Nearest distance in y direction, accounting for periodicity. * * \param[in] d Distance to be checked. @@ -959,7 +946,6 @@ double nearest_y(double d) return d; } - /* \brief Nearest distance in z direction, accounting for periodicity. * * \param[in] d Distance to be checked. @@ -977,7 +963,6 @@ double nearest_z(double d) return d; } - /*! \brief Gets "radius" of a cell. * * Defined as the radius of a sphere with the same volume as the Voronoi cell. @@ -996,17 +981,16 @@ double get_cell_radius(int i) #ifdef ONEDIMS #ifdef ONEDIMS_SPHERICAL cellrad = 0.5 * (Mesh.VF[i + 1].cx - Mesh.VF[i].cx); -#else /* #ifdef ONEDIMS_SPHERICAL */ +#else /* #ifdef ONEDIMS_SPHERICAL */ cellrad = 0.5 * SphP[i].Volume; #endif /* #ifdef ONEDIMS_SPHERICAL #else */ -#else /* #ifdef ONEDIMS */ +#else /* #ifdef ONEDIMS */ cellrad = pow(SphP[i].Volume * 3.0 / (4.0 * M_PI), 1.0 / 3); #endif /* #ifdef ONEDIMS #else */ #endif /* #ifdef TWODIMS */ return cellrad; } - /*! \brief Writes a file points_X.dat with Delaunay points. * * Writes position as in DP structure. @@ -1016,7 +1000,7 @@ double get_cell_radius(int i) * * \return void */ -void dump_points(tessellation * T) +void dump_points(tessellation *T) { FILE *fd; int i; @@ -1036,7 +1020,6 @@ void dump_points(tessellation * T) fclose(fd); } - /*! \brief Calculates the normals to given interfaces. * * \param[in] T Pointer to tesslation data. @@ -1045,14 +1028,14 @@ void dump_points(tessellation * T) * * \return 0 if success, -1 if interface can be ignored. */ -int face_get_normals(tessellation * T, int i, struct geometry *geom) +int face_get_normals(tessellation *T, int i, struct geometry *geom) { int li, ri; double surface, surface_l, surface_r; int present_left, present_right; double mm; - face *VF = T->VF; + face *VF = T->VF; point *DP = T->DP; li = DP[VF[i].p1].index; @@ -1145,7 +1128,6 @@ int face_get_normals(tessellation * T, int i, struct geometry *geom) return 0; } - /*! \brief Calculates distance of a cell to boundary of computational box. * * \param[in] cell Index of cell in P and SphP structure. @@ -1167,12 +1149,12 @@ double distance_to_border(int cell) d2 = P[cell].Pos[1]; double min2 = fmin(d1, d2); - min = fmin(min, min2); + min = fmin(min, min2); d1 = boxSize_Z - P[cell].Pos[2]; assert(d1 > 0); - d2 = P[cell].Pos[2]; + d2 = P[cell].Pos[2]; min2 = fmin(d1, d2); min = fmin(min, min2); diff --git a/src/mesh/voronoi/voronoi.h b/src/mesh/voronoi/voronoi.h index 2e2bb03d6e256df80237754a6873e101ba7839fc..5847a8f4f36ef957673ab4c4369b5518a277bf1d 100644 --- a/src/mesh/voronoi/voronoi.h +++ b/src/mesh/voronoi/voronoi.h @@ -20,36 +20,30 @@ * \file src/mesh/voronoi/voronoi.h * \date 05/2018 * \brief Header for Voronoi mesh-construcion - * \details - * - * + * \details + * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 29.05.2018 Prepared file for public release -- Rainer Weinberger */ - #ifndef HAVE_H_VORONOI #define HAVE_H_VORONOI - #include <gmp.h> - -#define STACKSIZE_TETRA 10000 -#define MIN_ALLOC_NUMBER 1000 -#define ALLOC_INCREASE_FACTOR 1.1 -#define ALLOC_DECREASE_FACTOR 0.7 +#define STACKSIZE_TETRA 10000 +#define MIN_ALLOC_NUMBER 1000 +#define ALLOC_INCREASE_FACTOR 1.1 +#define ALLOC_DECREASE_FACTOR 0.7 #define MAX_VORONOI_ITERATIONS 500 - #define GENTLE_DEREFINE_FACTOR 1.2 - #define USEDBITS 52 - #if USEDBITS > 31 typedef signed long long int IntegerMapType; void MY_mpz_set_si(mpz_t dest, signed long long int val); @@ -62,9 +56,7 @@ typedef signed long int IntegerMapType; #define MY_mpz_sub_ui mpz_sub_ui #endif /* #if USEDBITS > 31 #else */ - -#define DOUBLE_to_VORONOIINT(y) ((IntegerMapType)(((*((long long *) &y)) & 0xFFFFFFFFFFFFFllu) >> (52 - USEDBITS))) - +#define DOUBLE_to_VORONOIINT(y) ((IntegerMapType)(((*((long long *)&y)) & 0xFFFFFFFFFFFFFllu) >> (52 - USEDBITS))) /* Prerequisites for this function: * sizeof(double)==sizeof(unsigned long long) @@ -81,7 +73,6 @@ static inline IntegerMapType double_to_voronoiint(double d) return (u.ull & 0xFFFFFFFFFFFFFllu) >> (52 - USEDBITS); } - static inline double mask_voronoi_int(double x) { union @@ -89,53 +80,44 @@ static inline double mask_voronoi_int(double x) double d; unsigned long long ull; } u; - u.d = x; + u.d = x; u.ull = u.ull & (~((1llu << (52 - USEDBITS)) - 1)); return u.d; } - #ifndef TWODIMS - -#define EDGE_0 1 /* points 0-1 */ -#define EDGE_1 2 /* points 0-2 */ -#define EDGE_2 4 /* points 0-3 */ -#define EDGE_3 8 /* points 1-2 */ -#define EDGE_4 16 /* points 1-3 */ -#define EDGE_5 32 /* points 2-3 */ +#define EDGE_0 1 /* points 0-1 */ +#define EDGE_1 2 /* points 0-2 */ +#define EDGE_2 4 /* points 0-3 */ +#define EDGE_3 8 /* points 1-2 */ +#define EDGE_4 16 /* points 1-3 */ +#define EDGE_5 32 /* points 2-3 */ #define EDGE_ALL 63 - #else /* #ifndef TWODIMS */ - -#define EDGE_0 1 /* points 1-2 */ -#define EDGE_1 2 /* points 0-2 */ -#define EDGE_2 4 /* points 0-1 */ +#define EDGE_0 1 /* points 1-2 */ +#define EDGE_1 2 /* points 0-2 */ +#define EDGE_2 4 /* points 0-1 */ #define EDGE_ALL 7 - #endif /* #ifndef TWODIMS #else */ - #define HSML_INCREASE_FACTOR 1.3 - -#ifdef TWODIMS /* will only be compiled in 2D case */ +#ifdef TWODIMS /* will only be compiled in 2D case */ #define DIMS 2 #else /* #ifdef TWODIMS */ #define DIMS 3 #endif /*#ifdef TWODIMS #else */ - - typedef struct { - double x, y, z; // The 3-space position of the point + double x, y, z; // The 3-space position of the point MyIDType ID; - int task; // The MPI task owning this cell - int index; // The hydro quantity index of the cell + int task; // The MPI task owning this cell + int index; // The hydro quantity index of the cell int originalindex, timebin; unsigned int image_flags; @@ -150,77 +132,60 @@ typedef struct int last_connection; char flag_primary_triangle; #endif /* #ifdef DOUBLE_STENCIL */ -} -point; - +} point; typedef struct tetra_data { - int p[DIMS + 1]; /*!< oriented tetrahedron points */ - int t[DIMS + 1]; /*!< adjacent tetrahedrons, always opposite to corresponding point */ - unsigned char s[DIMS + 1]; /*!< gives the index of the point in the adjacent tetrahedron that - lies opposite to the common face */ + int p[DIMS + 1]; /*!< oriented tetrahedron points */ + int t[DIMS + 1]; /*!< adjacent tetrahedrons, always opposite to corresponding point */ + unsigned char s[DIMS + 1]; /*!< gives the index of the point in the adjacent tetrahedron that + lies opposite to the common face */ /* Note: if t[0] == -1, the tetrahedron has been deleted */ -} -tetra; - +} tetra; typedef struct tetra_center_data { #ifndef OPTIMIZE_MEMORY_USAGE - double cx, cy, cz; /*!< describes circumcircle center */ -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ + double cx, cy, cz; /*!< describes circumcircle center */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ MyFloat cx, cy, cz; -#endif /*#ifndef OPTIMIZE_MEMORY_USAGE */ -} -tetra_center; - +#endif /*#ifndef OPTIMIZE_MEMORY_USAGE */ +} tetra_center; typedef struct tri_data { double p[DIMS + 1][DIMS]; int owner; -} -triangle; - +} triangle; extern unsigned char *Edge_visited; - extern struct list_export_data { unsigned int image_bits; int origin, index; int nextexport; -} - *ListExports; - +} * ListExports; extern int Ninlist, MaxNinlist; - extern struct area_list_data { int task, index; double darea; -} - *AreaList; - +} * AreaList; extern int Narea, MaxNarea; - extern int NumGasInMesh; extern int *List_InMesh; - extern struct list_P_data { int firstexport, currentexport; -} *List_P; - +} * List_P; typedef struct connection_data { @@ -229,15 +194,13 @@ typedef struct connection_data int image_flags; int next; - int dp_index; /*!< this seems to be needed always the way voronoi_makeimage is implemented at the moment */ - int vf_index; /*!< index to the corresponding face */ + int dp_index; /*!< this seems to be needed always the way voronoi_makeimage is implemented at the moment */ + int vf_index; /*!< index to the corresponding face */ #if defined(TETRA_INDEX_IN_FACE) int dt_index; #endif /* #if defined(TETRA_INDEX_IN_FACE)*/ MyIDType ID; -} -connection; - +} connection; /*! This structure contains the points where a line segment intersects * the tetrahedron faces and the internal voronoi faces. Is returned @@ -245,12 +208,11 @@ connection; */ typedef struct intersection_list_data { - double s; /*!< the distance from the entry point (fraction of whole segment) */ - point p; /*!< the intersection point */ - int indA, indB; /*!< the indices of the tetra points (0-4) defining the face */ + double s; /*!< the distance from the entry point (fraction of whole segment) */ + point p; /*!< the intersection point */ + int indA, indB; /*!< the indices of the tetra points (0-4) defining the face */ } intersection_list; - extern int CountInSphereTests, CountInSphereTestsExact; extern int CountConvexEdgeTest, CountConvexEdgeTestExact; extern int CountFlips, Count_1_to_3_Flips2d, Count_2_to_4_Flips2d; @@ -259,10 +221,8 @@ extern int Count_EdgeSplits, Count_FaceSplits; extern int Count_InTetra, Count_InTetraExact; extern int Largest_N_DP_Buffer; - extern int Ninlist, MaxNinlist; - typedef struct individual_alloc_data { double AllocFacNdp; @@ -273,51 +233,43 @@ typedef struct individual_alloc_data double AllocFacNflux; double AllocFacNradinflux; double AllocFacNvc; -} -mesh_alloc_facs; - +} mesh_alloc_facs; typedef struct tessellation_data { - int Ndp; /*!< number of delaunay points */ - int MaxNdp; /*!< maximum number of delaunay points */ - point *DP; /*!< delaunay points */ + int Ndp; /*!< number of delaunay points */ + int MaxNdp; /*!< maximum number of delaunay points */ + point *DP; /*!< delaunay points */ int Ndt; - int MaxNdt; /*!< number of delaunary tetrahedra */ - tetra *DT; /*!< Delaunay tetrahedra */ - tetra_center *DTC; /*!< circumcenters of delaunay tetrahedra */ + int MaxNdt; /*!< number of delaunary tetrahedra */ + tetra *DT; /*!< Delaunay tetrahedra */ + tetra_center *DTC; /*!< circumcenters of delaunay tetrahedra */ char *DTF; - int Nvf; /*!< number of Voronoi faces */ - int MaxNvf; /*!< maximum number of Voronoi faces */ - face *VF; /*!< Voronoi faces */ + int Nvf; /*!< number of Voronoi faces */ + int MaxNvf; /*!< maximum number of Voronoi faces */ + face *VF; /*!< Voronoi faces */ mesh_alloc_facs Indi; -} -tessellation; - +} tessellation; extern tessellation Mesh, DeRefMesh; - extern int DPinfinity; - -extern int Nvc; /* number of connections */ -extern int MaxNvc; /* maximum number of connections */ +extern int Nvc; /* number of connections */ +extern int MaxNvc; /* maximum number of connections */ extern int Largest_Nvc; -extern connection *DC; /* Connections */ +extern connection *DC; /* Connections */ extern int FirstUnusedConnection; - extern double CentralOffsetX, CentralOffsetY, CentralOffsetZ, ConversionFac; - -int derefine_add_point_and_split_tri(int q, triangle * trilist, int n, int max_n, double vol); -void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr); +int derefine_add_point_and_split_tri(int q, triangle *trilist, int n, int max_n, double vol); +void derefine_refine_process_edge(tessellation *T, double *vol, int tt, int nr); void derefine_refine_compute_volumes(double *vol); -int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip, triangle * trilist, int ntri, int max_n_tri); +int derefine_refine_get_triangles(tessellation *T, int tt, int nr, point *dtip, triangle *trilist, int ntri, int max_n_tri); void create_mesh(void); void mesh_setup_exchange(void); void free_mesh(void); @@ -325,64 +277,62 @@ void free_mesh_structures_not_needed_for_derefinement_refinement(void); void free_all_remaining_mesh_structures(void); void apply_area_list(void); int area_list_data_compare(const void *a, const void *b); -void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTask); -void initialize_and_create_first_tetra(tessellation * T); +void write_voronoi_mesh(tessellation *T, char *fname, int writeTask, int lastTask); +void initialize_and_create_first_tetra(tessellation *T); void compute_voronoi_faces_and_volumes(void); void get_line_segments(int sphp_index, int dp_index, double *segments, unsigned int *nof_elements, unsigned int max_elements); double cross_section_plane_cell(int sphp_index, int dp_index, double *center, double *n); void intersections_plane_cell(int sphp_index, int dp_index, double *center, double *n, double *polygon, unsigned int *nof_elements); void intersection_plane_grid(double *center, double *n, const char *filename); -void process_edge_faces_and_volumes(tessellation * T, int tt, int nr); -int insert_point(tessellation * T, int pp, int ttstart); -void make_an_edge_split(tessellation * T, int tt0, int edge_nr, int count, int pp, int *ttlist); -void make_a_face_split(tessellation * T, int tt0, int face_nr, int pp, int tt1, int tt2, int qq1, int qq2); -double calculate_tetra_volume(point * p0, point * p1, point * p2, point * p3); -void make_a_4_to_4_flip(tessellation * T, int tt, int tip_index, int edge_nr); -double get_tri_volume(int i, triangle * trilist); -void make_a_1_to_4_flip(tessellation * T, int pp, int tt0, int tt1, int tt2, int tt3); -void make_a_3_to_2_flip(tessellation * T, int tt0, int tt1, int tt2, int tip, int edge, int bottom); -void make_a_2_to_3_flip(tessellation * T, int tt0, int tip, int tt1, int bottom, int qq, int tt2); -int get_tetra(tessellation * T, point * p, int *moves, int ttstart, int *flag, int *edgeface_nr); -int InTetra(tessellation * T, int tt, point * pp, int *edgeface_nr, int *nexttetra); -double InSphere(point * p0, point * p1, point * p2, point * p3, point * p); -void update_circumcircle(tessellation * T, int tt); -int test_tetra_orientation(point * p0, point * p1, point * p2, point * p3); -int voronoi_ghost_search_alternative(tessellation * T); -void compute_circumcircles(tessellation * T); +void process_edge_faces_and_volumes(tessellation *T, int tt, int nr); +int insert_point(tessellation *T, int pp, int ttstart); +void make_an_edge_split(tessellation *T, int tt0, int edge_nr, int count, int pp, int *ttlist); +void make_a_face_split(tessellation *T, int tt0, int face_nr, int pp, int tt1, int tt2, int qq1, int qq2); +double calculate_tetra_volume(point *p0, point *p1, point *p2, point *p3); +void make_a_4_to_4_flip(tessellation *T, int tt, int tip_index, int edge_nr); +double get_tri_volume(int i, triangle *trilist); +void make_a_1_to_4_flip(tessellation *T, int pp, int tt0, int tt1, int tt2, int tt3); +void make_a_3_to_2_flip(tessellation *T, int tt0, int tt1, int tt2, int tip, int edge, int bottom); +void make_a_2_to_3_flip(tessellation *T, int tt0, int tip, int tt1, int bottom, int qq, int tt2); +int get_tetra(tessellation *T, point *p, int *moves, int ttstart, int *flag, int *edgeface_nr); +int InTetra(tessellation *T, int tt, point *pp, int *edgeface_nr, int *nexttetra); +double InSphere(point *p0, point *p1, point *p2, point *p3, point *p); +void update_circumcircle(tessellation *T, int tt); +int test_tetra_orientation(point *p0, point *p1, point *p2, point *p3); +int voronoi_ghost_search_alternative(tessellation *T); +void compute_circumcircles(tessellation *T); int compute_max_delaunay_radius(void); -void check_for_min_distance(tessellation * T); -void check_links(tessellation * T); -void check_orientations(tessellation * T); -void check_tetras(tessellation * T, int npoints); +void check_for_min_distance(tessellation *T); +void check_links(tessellation *T); +void check_orientations(tessellation *T); +void check_tetras(tessellation *T, int npoints); int voronoi_get_local_particles(void); -int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr); +int convex_edge_test(tessellation *T, int tt, int tip, int *edgenr); void calculate_gradients(void); void limit_gradient(double *d, double phi, double min_phi, double max_phi, MySingle *dphi); void exchange_primitive_variables(void); void exchange_primitive_variables_and_gradients(void); int compare_primexch(const void *a, const void *b); - /* 2D voronoi routines */ -void check_edge_and_flip_if_needed(tessellation * T, int ip, int it); -int get_triangle(tessellation * T, int pp, int *moves, int *degenerate_flag, int ttstart); -double InCircle(point * p0, point * p1, point * p2, point * p); -void make_a_1_to_3_flip(tessellation * T, int pp, int tt0, int tt1, int tt2); -double test_triangle_orientation(tessellation * T, int pp0, int pp1, int pp2); -void make_a_2_to_4_flip(tessellation * T, int pp, int tt0, int tt1, int tt2, int tt3, int i0, int j0); -void dump_points(tessellation * T); -void set_integers_for_pointer(point * p); - +void check_edge_and_flip_if_needed(tessellation *T, int ip, int it); +int get_triangle(tessellation *T, int pp, int *moves, int *degenerate_flag, int ttstart); +double InCircle(point *p0, point *p1, point *p2, point *p); +void make_a_1_to_3_flip(tessellation *T, int pp, int tt0, int tt1, int tt2); +double test_triangle_orientation(tessellation *T, int pp0, int pp1, int pp2); +void make_a_2_to_4_flip(tessellation *T, int pp, int tt0, int tt1, int tt2, int tt3, int i0, int j0); +void dump_points(tessellation *T); +void set_integers_for_pointer(point *p); #if !defined(ONEDIMS) #ifndef OPTIMIZE_MEMORY_USAGE -static inline void set_integers_for_point(tessellation * T, int pp) +static inline void set_integers_for_point(tessellation *T, int pp) { point *p = &T->DP[pp]; set_integers_for_pointer(p); } -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ -static inline void get_integers_for_point(point * p, IntegerMapType ixyz[], double xyz[]) +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +static inline void get_integers_for_point(point *p, IntegerMapType ixyz[], double xyz[]) { xyz[0] = (p->x - CentralOffsetX) * ConversionFac + 1.0; xyz[1] = (p->y - CentralOffsetY) * ConversionFac + 1.0; @@ -398,37 +348,31 @@ static inline void get_integers_for_point(point * p, IntegerMapType ixyz[], doub } #endif /* #ifndef OPTIMIZE_MEMORY_USAGE #else */ -#else /* #if !defined(ONEDIMS) */ -void set_integers_for_point(tessellation * T, int pp); +#else /* #if !defined(ONEDIMS) */ +void set_integers_for_point(tessellation *T, int pp); #endif /* #if !defined(ONEDIMS) #else */ - /* quick function to compare a point to the infinity point */ -static inline int isInfinity(point * p) -{ - return p->x == MAX_DOUBLE_NUMBER; -} - +static inline int isInfinity(point *p) { return p->x == MAX_DOUBLE_NUMBER; } int solve_linear_equations(double *m, double *res); -void check_triangles(tessellation * T, int npoints); -int InCircle_Quick(tessellation * T, int pp0, int pp1, int pp2, int pp); -int InCircle_Errorbound(tessellation * T, int pp0, int pp1, int pp2, int pp); -int InCircle_Exact(tessellation * T, int pp0, int pp1, int pp2, int pp); -int Orient2d_Exact(tessellation * T, int pp0, int pp1, int pp2); -int Orient2d_Quick(tessellation * T, int pp0, int pp1, int pp2); -int FindTriangle(tessellation * T, int tt, int pp, int *degnerate_flag, int *nexttetra); -int InSphere_Exact(point * p0, point * p1, point * p2, point * p3, point * p); -int InSphere_Quick(point * p0, point * p1, point * p2, point * p3, point * p); -int InSphere_Errorbound(point * p0, point * p1, point * p2, point * p3, point * p); -int Orient3d_Quick(point * p0, point * p1, point * p2, point * p3); -int Orient3d(point * p0, point * p1, point * p2, point * p3); -int count_undecided_tetras(tessellation * T); -int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDouble refpos[3], MyFloat hsml, MyFloat maxdist, int target, int origin, int mode, int thread_id, int numnodes, - int *firstnode); -int voronoi_ghost_search_evaluate(tessellation * T, int target, int mode, int q, int thread_id); -int voronoi_ghost_search(tessellation * T); +void check_triangles(tessellation *T, int npoints); +int InCircle_Quick(tessellation *T, int pp0, int pp1, int pp2, int pp); +int InCircle_Errorbound(tessellation *T, int pp0, int pp1, int pp2, int pp); +int InCircle_Exact(tessellation *T, int pp0, int pp1, int pp2, int pp); +int Orient2d_Exact(tessellation *T, int pp0, int pp1, int pp2); +int Orient2d_Quick(tessellation *T, int pp0, int pp1, int pp2); +int FindTriangle(tessellation *T, int tt, int pp, int *degnerate_flag, int *nexttetra); +int InSphere_Exact(point *p0, point *p1, point *p2, point *p3, point *p); +int InSphere_Quick(point *p0, point *p1, point *p2, point *p3, point *p); +int InSphere_Errorbound(point *p0, point *p1, point *p2, point *p3, point *p); +int Orient3d_Quick(point *p0, point *p1, point *p2, point *p3); +int Orient3d(point *p0, point *p1, point *p2, point *p3); +int count_undecided_tetras(tessellation *T); +int ngb_treefind_ghost_search(tessellation *T, MyDouble searchcenter[3], MyDouble refpos[3], MyFloat hsml, MyFloat maxdist, int target, + int origin, int mode, int thread_id, int numnodes, int *firstnode); +int voronoi_ghost_search_evaluate(tessellation *T, int target, int mode, int q, int thread_id); +int voronoi_ghost_search(tessellation *T); double distance_to_border(int cell); - #endif /* HAVE_H_VORONOI */ diff --git a/src/mesh/voronoi/voronoi_1d.c b/src/mesh/voronoi/voronoi_1d.c index e955ccc2b8814529c5ac6ed059701d8ba5661393..54c325cd3b275dfd9bf3e425655bfb8d86604737 100644 --- a/src/mesh/voronoi/voronoi_1d.c +++ b/src/mesh/voronoi/voronoi_1d.c @@ -39,29 +39,25 @@ * void voronoi_1D_order(void) * int voronoi_1D_compare_key(const void *a, const void *b) * void voronoi_1D_reorder_gas(void) - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 21.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <gmp.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> -#include <gmp.h> - #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - -#if defined (ONEDIMS) && !defined (ONEDIMS_SPHERICAL) /* will only be compiled in 1D case */ - +#if defined(ONEDIMS) && !defined(ONEDIMS_SPHERICAL) /* will only be compiled in 1D case */ /*! \brief Output of Voroioi mesh to file. * @@ -69,12 +65,11 @@ * * \return void */ -void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTask) +void write_voronoi_mesh(tessellation *T, char *fname, int writeTask, int lastTask) { terminate("write_voronoi_mesh not supported in 1d case!"); } - /*! \brief Initialises 1d tessellation and create all-enclosing segment. * * \param[out] T Pointer to tessllation structure which is set and its arrays @@ -82,7 +77,7 @@ void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTa * * \return void */ -void initialize_and_create_first_tetra(tessellation * T) +void initialize_and_create_first_tetra(tessellation *T) { char msg[200]; @@ -106,7 +101,6 @@ void initialize_and_create_first_tetra(tessellation * T) T->Nvf = 0; T->Ndt = 0; - T->VF = mymalloc_movable(&T->VF, "VF", T->MaxNvf * sizeof(face)); T->DP = mymalloc_movable(&T->DP, "DP", (T->MaxNdp + 5) * sizeof(point)); @@ -115,7 +109,6 @@ void initialize_and_create_first_tetra(tessellation * T) T->DT = mymalloc_movable(&T->DT, "DT", T->MaxNdt * sizeof(tetra)); } - /*! \brief Computes circumcircles in 1d. * * Not necessary in 1d. However, this function has to exist for the 1d code @@ -125,10 +118,7 @@ void initialize_and_create_first_tetra(tessellation * T) * * \return void */ -void compute_circumcircles(tessellation * T) -{ -} - +void compute_circumcircles(tessellation *T) {} /*! \brief Empty funciton in 1d case. * @@ -137,10 +127,7 @@ void compute_circumcircles(tessellation * T) * * \return void */ -void set_integers_for_point(tessellation * T, int pp) -{ -} - +void set_integers_for_point(tessellation *T, int pp) {} /*! \brief Empty funciton in 1d case. * @@ -149,11 +136,7 @@ void set_integers_for_point(tessellation * T, int pp) * * \return 0 */ -int insert_point(tessellation * T, int pp, int ttstart) -{ - return 0; -} - +int insert_point(tessellation *T, int pp, int ttstart) { return 0; } /*! \brief Wrapper routine to search for ghost cells for boundary cells. * @@ -161,11 +144,7 @@ int insert_point(tessellation * T, int pp, int ttstart) * * \return 0 */ -int voronoi_ghost_search(tessellation * T) -{ - return voronoi_ghost_search_alternative(T); -} - +int voronoi_ghost_search(tessellation *T) { return voronoi_ghost_search_alternative(T); } /*! \brief Empty funciton in 1d case. * @@ -174,11 +153,7 @@ int voronoi_ghost_search(tessellation * T) * * \return 0 */ -int count_undecided_tetras(tessellation * T) -{ - return 0; -} - +int count_undecided_tetras(tessellation *T) { return 0; } /*! \brief Searches for ghost cells in 1d Voronoi mesh. * @@ -188,55 +163,54 @@ int count_undecided_tetras(tessellation * T) * * \return 0 */ -int voronoi_ghost_search_alternative(tessellation * T) +int voronoi_ghost_search_alternative(tessellation *T) { double xl, xr; int index_l, index_r; #if defined(REFLECTIVE_X) - xl = -P[0].Pos[0]; + xl = -P[0].Pos[0]; index_l = 0; - xr = boxSize_X + (boxSize_X - P[NumGas - 1].Pos[0]); + xr = boxSize_X + (boxSize_X - P[NumGas - 1].Pos[0]); index_r = NumGas - 1; -#else /* #if defined(REFLECTIVE_X) */ - xl = P[NumGas - 1].Pos[0] - boxSize_X; +#else /* #if defined(REFLECTIVE_X) */ + xl = P[NumGas - 1].Pos[0] - boxSize_X; index_l = NumGas - 1; - xr = P[0].Pos[0] + boxSize_X; + xr = P[0].Pos[0] + boxSize_X; index_r = 0; #endif /* #if defined(REFLECTIVE_X) #else */ point *DP = T->DP; - DP[-1].x = xl; - DP[-1].y = 0; - DP[-1].z = 0; - DP[-1].task = ThisTask; - DP[-1].ID = P[index_l].ID; - DP[-1].index = index_l + NumGas; /* this is a mirrored local point */ + DP[-1].x = xl; + DP[-1].y = 0; + DP[-1].z = 0; + DP[-1].task = ThisTask; + DP[-1].ID = P[index_l].ID; + DP[-1].index = index_l + NumGas; /* this is a mirrored local point */ #if defined(REFLECTIVE_X) DP[-1].image_flags = REFL_X_FLAGS; -#if (REFLECTIVE_X == 2) +#if(REFLECTIVE_X == 2) DP[-1].image_flags |= OUTFLOW_X; #endif /* #if (REFLECTIVE_X == 2) */ #endif /* #if defined(REFLECTIVE_X) */ - DP[NumGas].x = xr; - DP[NumGas].y = 0; - DP[NumGas].z = 0; - DP[NumGas].task = ThisTask; - DP[NumGas].ID = P[index_r].ID; - DP[NumGas].index = index_r + NumGas; /* this is a mirrored local point */ + DP[NumGas].x = xr; + DP[NumGas].y = 0; + DP[NumGas].z = 0; + DP[NumGas].task = ThisTask; + DP[NumGas].ID = P[index_r].ID; + DP[NumGas].index = index_r + NumGas; /* this is a mirrored local point */ #if defined(REFLECTIVE_X) DP[NumGas].image_flags = REFL_X_FLAGS; -#if (REFLECTIVE_X == 2) +#if(REFLECTIVE_X == 2) DP[NumGas].image_flags |= OUTFLOW_X; #endif /* #if (REFLECTIVE_X == 2) */ #endif /* #if defined(REFLECTIVE_X) */ return 0; } - /*! \brief Computes faces and volume of cells in 1d Voronoi mesh. * * Also computes the center of mass. @@ -249,9 +223,9 @@ void compute_voronoi_faces_and_volumes(void) tessellation *T = &Mesh; - T->Nvf = 0; + T->Nvf = 0; point *DP = T->DP; - face *VF = T->VF; + face *VF = T->VF; for(i = -1; i < NumGas; i++) { @@ -260,8 +234,8 @@ void compute_voronoi_faces_and_volumes(void) VF[T->Nvf].cx = 0.5 * (DP[i].x + DP[i + 1].x); - VF[T->Nvf].cy = 0; - VF[T->Nvf].cz = 0; + VF[T->Nvf].cy = 0; + VF[T->Nvf].cz = 0; VF[T->Nvf].area = 1; T->Nvf++; @@ -269,7 +243,7 @@ void compute_voronoi_faces_and_volumes(void) for(i = 0; i < NumGas; i++) { - SphP[i].Volume = VF[i + 1].cx - VF[i].cx; + SphP[i].Volume = VF[i + 1].cx - VF[i].cx; SphP[i].Center[0] = 0.5 * (VF[i + 1].cx + VF[i].cx); SphP[i].Center[1] = 0; SphP[i].Center[2] = 0; @@ -278,20 +252,16 @@ void compute_voronoi_faces_and_volumes(void) } } - /*! \brief Data for 1d Voronoi mesh. */ static struct voronoi_1D_data { double x; int index; -} - *mp; - +} * mp; static int *Id; - /*! \brief Sort cells by their position and reorder in P and SphP array. * * \return void @@ -304,18 +274,17 @@ void voronoi_1D_order(void) if(NumGas) { - mp = (struct voronoi_1D_data *) mymalloc("mp", sizeof(struct voronoi_1D_data) * NumGas); - Id = (int *) mymalloc("Id", sizeof(int) * NumGas); + mp = (struct voronoi_1D_data *)mymalloc("mp", sizeof(struct voronoi_1D_data) * NumGas); + Id = (int *)mymalloc("Id", sizeof(int) * NumGas); for(i = 0; i < NumGas; i++) { mp[i].index = i; - mp[i].x = P[i].Pos[0]; + mp[i].x = P[i].Pos[0]; } mysort(mp, NumGas, sizeof(struct voronoi_1D_data), voronoi_1D_compare_key); - for(i = 0; i < NumGas; i++) Id[mp[i].index] = i; @@ -328,7 +297,6 @@ void voronoi_1D_order(void) mpi_printf("1D order done.\n"); } - /*! \brief Compare x value of voronoi_1D_data objects. * * \param[in] a Pointer to first voronoi_1D_data object. @@ -338,16 +306,15 @@ void voronoi_1D_order(void) */ int voronoi_1D_compare_key(const void *a, const void *b) { - if(((struct voronoi_1D_data *) a)->x < (((struct voronoi_1D_data *) b)->x)) + if(((struct voronoi_1D_data *)a)->x < (((struct voronoi_1D_data *)b)->x)) return -1; - if(((struct voronoi_1D_data *) a)->x > (((struct voronoi_1D_data *) b)->x)) + if(((struct voronoi_1D_data *)a)->x > (((struct voronoi_1D_data *)b)->x)) return +1; return 0; } - /*! \brief Order the gas cells according to the index given in the ID array. * * \return void @@ -363,28 +330,28 @@ void voronoi_1D_reorder_gas(void) { if(Id[i] != i) { - Psource = P[i]; + Psource = P[i]; SphPsource = SphP[i]; idsource = Id[i]; - dest = Id[i]; + dest = Id[i]; do { - Psave = P[dest]; + Psave = P[dest]; SphPsave = SphP[dest]; - idsave = Id[dest]; + idsave = Id[dest]; - P[dest] = Psource; + P[dest] = Psource; SphP[dest] = SphPsource; - Id[dest] = idsource; + Id[dest] = idsource; if(dest == i) break; - Psource = Psave; + Psource = Psave; SphPsource = SphPsave; - idsource = idsave; + idsource = idsave; dest = idsource; } @@ -393,5 +360,4 @@ void voronoi_1D_reorder_gas(void) } } - #endif /* #if defined (ONEDIMS) && !defined (ONEDIMS_SPHERICAL) */ diff --git a/src/mesh/voronoi/voronoi_1d_spherical.c b/src/mesh/voronoi/voronoi_1d_spherical.c index 4e0e0bcdf2b82ef0a1bf3ded4e60c23c6b6705cc..c0212da41d57ba29a4a8ed84d0f3ef0f0b15c9a1 100644 --- a/src/mesh/voronoi/voronoi_1d_spherical.c +++ b/src/mesh/voronoi/voronoi_1d_spherical.c @@ -39,29 +39,25 @@ * void voronoi_1D_order(void) * int voronoi_1D_compare_key(const void *a, const void *b) * void voronoi_1D_reorder_gas(void) - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 21.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <gmp.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> -#include <gmp.h> - #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - -#if defined (ONEDIMS) && defined (ONEDIMS_SPHERICAL) /* will only be compiled in 1D spherical case */ - +#if defined(ONEDIMS) && defined(ONEDIMS_SPHERICAL) /* will only be compiled in 1D spherical case */ /*! \brief Output of Voroioi mesh to file. * @@ -69,12 +65,11 @@ * * \retur void */ -void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTask) +void write_voronoi_mesh(tessellation *T, char *fname, int writeTask, int lastTask) { terminate("write_voronoi_mesh not supported in 1d spherical case!"); } - /*! \brief Initialises spherical 1d tesslation and create all-enclosing * segment. * @@ -83,7 +78,7 @@ void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTa * * \return void */ -void initialize_and_create_first_tetra(tessellation * T) +void initialize_and_create_first_tetra(tessellation *T) { char msg[200]; @@ -106,7 +101,6 @@ void initialize_and_create_first_tetra(tessellation * T) T->Nvf = 0; T->Ndt = 0; - T->VF = mymalloc("VF", T->MaxNvf * sizeof(face)); T->DP = mymalloc("DP", (T->MaxNdp + 5) * sizeof(point)); @@ -115,7 +109,6 @@ void initialize_and_create_first_tetra(tessellation * T) T->DT = mymalloc("DT", T->MaxNdt * sizeof(tetra)); } - /*! \brief Computes circumcircles in 1d spherical coordinates. * * Not necessary in 1d spherical. However, this function has to exist for @@ -125,10 +118,7 @@ void initialize_and_create_first_tetra(tessellation * T) * * \return void */ -void compute_circumcircles(tessellation * T) -{ -} - +void compute_circumcircles(tessellation *T) {} /*! \brief Empty funciton in 1d spherical case. * @@ -137,10 +127,7 @@ void compute_circumcircles(tessellation * T) * * \return void */ -void set_integers_for_point(tessellation * T, int pp) -{ -} - +void set_integers_for_point(tessellation *T, int pp) {} /*! \brief Empty funciton in 1d spherical case. * @@ -149,11 +136,7 @@ void set_integers_for_point(tessellation * T, int pp) * * \return 0 */ -int insert_point(tessellation * T, int pp, int ttstart) -{ - return 0; -} - +int insert_point(tessellation *T, int pp, int ttstart) { return 0; } /*! \brief Wrapper routine to search for ghost cells for boundary cells. * @@ -161,11 +144,7 @@ int insert_point(tessellation * T, int pp, int ttstart) * * \return 0 */ -int voronoi_ghost_search(tessellation * T) -{ - return voronoi_ghost_search_alternative(T); -} - +int voronoi_ghost_search(tessellation *T) { return voronoi_ghost_search_alternative(T); } /*! \brief Empty funciton in 1d spherical case. * @@ -174,11 +153,7 @@ int voronoi_ghost_search(tessellation * T) * * \return 0 */ -int count_undecided_tetras(tessellation * T) -{ - return 0; -} - +int count_undecided_tetras(tessellation *T) { return 0; } /*! \brief Searches for ghost cells in 1d spherical Voronoi mesh. * @@ -188,30 +163,29 @@ int count_undecided_tetras(tessellation * T) * * \return 0 */ -int voronoi_ghost_search_alternative(tessellation * T) +int voronoi_ghost_search_alternative(tessellation *T) { point *DP = T->DP; /* reflective inner boundaries */ - DP[-1].x = 2. * All.CoreRadius - P[0].Pos[0]; - DP[-1].y = 0; - DP[-1].z = 0; - DP[-1].task = ThisTask; - DP[-1].ID = P[0].ID; - DP[-1].index = NumGas; /* this is a mirrored local point */ + DP[-1].x = 2. * All.CoreRadius - P[0].Pos[0]; + DP[-1].y = 0; + DP[-1].z = 0; + DP[-1].task = ThisTask; + DP[-1].ID = P[0].ID; + DP[-1].index = NumGas; /* this is a mirrored local point */ /* outflow outer boundaries */ - DP[NumGas].x = boxSize_X + (boxSize_X - P[NumGas - 1].Pos[0]); - DP[NumGas].y = 0; - DP[NumGas].z = 0; - DP[NumGas].task = ThisTask; - DP[NumGas].ID = P[NumGas - 1].ID; - DP[NumGas].index = NumGas - 1 + NumGas; /* this is a mirrored local point */ + DP[NumGas].x = boxSize_X + (boxSize_X - P[NumGas - 1].Pos[0]); + DP[NumGas].y = 0; + DP[NumGas].z = 0; + DP[NumGas].task = ThisTask; + DP[NumGas].ID = P[NumGas - 1].ID; + DP[NumGas].index = NumGas - 1 + NumGas; /* this is a mirrored local point */ return 0; } - /*! \brief Compute faces and volume of cells in 1d spherical Voronoi mesh. * * Also computes the center of mass. @@ -224,18 +198,18 @@ void compute_voronoi_faces_and_volumes(void) tessellation *T = &Mesh; - T->Nvf = 0; + T->Nvf = 0; point *DP = T->DP; - face *VF = T->VF; + face *VF = T->VF; for(i = -1; i < NumGas; i++) { VF[T->Nvf].p1 = i; VF[T->Nvf].p2 = i + 1; - VF[T->Nvf].cx = 0.5 * (DP[i].x + DP[i + 1].x); - VF[T->Nvf].cy = 0; - VF[T->Nvf].cz = 0; + VF[T->Nvf].cx = 0.5 * (DP[i].x + DP[i + 1].x); + VF[T->Nvf].cy = 0; + VF[T->Nvf].cz = 0; VF[T->Nvf].area = 4. * M_PI * VF[T->Nvf].cx * VF[T->Nvf].cx; T->Nvf++; @@ -243,29 +217,26 @@ void compute_voronoi_faces_and_volumes(void) for(i = 0; i < NumGas; i++) { - SphP[i].Volume = 4.0 / 3.0 * M_PI * (VF[i + 1].cx * VF[i + 1].cx * VF[i + 1].cx - VF[i].cx * VF[i].cx * VF[i].cx); + SphP[i].Volume = 4.0 / 3.0 * M_PI * (VF[i + 1].cx * VF[i + 1].cx * VF[i + 1].cx - VF[i].cx * VF[i].cx * VF[i].cx); SphP[i].Center[0] = 0.5 * (VF[i + 1].cx + VF[i].cx); SphP[i].Center[1] = 0; SphP[i].Center[2] = 0; SphP[i].SurfaceArea = VF[i].area + VF[i + 1].area; - SphP[i].ActiveArea = SphP[i].SurfaceArea; + SphP[i].ActiveArea = SphP[i].SurfaceArea; } } - /*! \brief Structure for 1d spherical Voronoi mesh. */ static struct voronoi_1D_data { double x; int index; -} - *mp; +} * mp; static int *Id; - /*! \brief Sort cells by their position (i.e. radius) and reorder in P and * SphP array. * @@ -279,13 +250,13 @@ void voronoi_1D_order(void) if(NumGas) { - mp = (struct voronoi_1D_data *) mymalloc("mp", sizeof(struct voronoi_1D_data) * NumGas); - Id = (int *) mymalloc("Id", sizeof(int) * NumGas); + mp = (struct voronoi_1D_data *)mymalloc("mp", sizeof(struct voronoi_1D_data) * NumGas); + Id = (int *)mymalloc("Id", sizeof(int) * NumGas); for(i = 0; i < NumGas; i++) { mp[i].index = i; - mp[i].x = P[i].Pos[0]; + mp[i].x = P[i].Pos[0]; } mysort(mp, NumGas, sizeof(struct voronoi_1D_data), voronoi_1D_compare_key); @@ -302,7 +273,6 @@ void voronoi_1D_order(void) mpi_printf("1D order done.\n"); } - /*! \brief Compare x value of voronoi_1D_data objects. * * \param[in] a Pointer to first voronoi_1D_data object. @@ -312,16 +282,15 @@ void voronoi_1D_order(void) */ int voronoi_1D_compare_key(const void *a, const void *b) { - if(((struct voronoi_1D_data *) a)->x < (((struct voronoi_1D_data *) b)->x)) + if(((struct voronoi_1D_data *)a)->x < (((struct voronoi_1D_data *)b)->x)) return -1; - if(((struct voronoi_1D_data *) a)->x > (((struct voronoi_1D_data *) b)->x)) + if(((struct voronoi_1D_data *)a)->x > (((struct voronoi_1D_data *)b)->x)) return +1; return 0; } - /*! \brief Order the gas cells according to the index given in the ID array. * * \return void @@ -337,28 +306,28 @@ void voronoi_1D_reorder_gas(void) { if(Id[i] != i) { - Psource = P[i]; + Psource = P[i]; SphPsource = SphP[i]; idsource = Id[i]; - dest = Id[i]; + dest = Id[i]; do { - Psave = P[dest]; + Psave = P[dest]; SphPsave = SphP[dest]; - idsave = Id[dest]; + idsave = Id[dest]; - P[dest] = Psource; + P[dest] = Psource; SphP[dest] = SphPsource; - Id[dest] = idsource; + Id[dest] = idsource; if(dest == i) break; - Psource = Psave; + Psource = Psave; SphPsource = SphPsave; - idsource = idsave; + idsource = idsave; dest = idsource; } @@ -367,5 +336,4 @@ void voronoi_1D_reorder_gas(void) } } - #endif /* #if defined (ONEDIMS) && defined (ONEDIMS_SPHERICAL) */ diff --git a/src/mesh/voronoi/voronoi_2d.c b/src/mesh/voronoi/voronoi_2d.c index d47eeb0a5689d156c87049ca3e086e98c7a07727..89a3a8f18e15a20fa9b6423bf2fd32f80f82b880 100644 --- a/src/mesh/voronoi/voronoi_2d.c +++ b/src/mesh/voronoi/voronoi_2d.c @@ -68,34 +68,29 @@ * void set_integers_for_pointer(point * p) * void write_voronoi_mesh(tessellation * T, char *fname, int * writeTask, int lastTask) - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 21.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <gmp.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> -#include <gmp.h> - #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - -#if defined(TWODIMS) && !defined(ONEDIMS) /* will only be compiled in 2D case */ - +#if defined(TWODIMS) && !defined(ONEDIMS) /* will only be compiled in 2D case */ #define INSIDE_EPS 1.0e-8 #define GAUSS_EPS 1.0e-8 - /*! \brief Initializes 2d tessellation and create all-enclosing triangle. * * \param[out] T Pointer to tessellation structure which is set and its arrays @@ -103,7 +98,7 @@ * * \return void */ -void initialize_and_create_first_tetra(tessellation * T) +void initialize_and_create_first_tetra(tessellation *T) { point *p; int i, n; @@ -132,11 +127,11 @@ void initialize_and_create_first_tetra(tessellation * T) box *= 1.05; - tetra_incircle = 2.001 * (1 + sqrt(3)) / 3.0 * box; /* to give room for ghost particles needed for periodic/reflective - boundary conditions, the incircle is twice as large, i.e. - [-0.5*box, 1.5*box,-0.5*box, 1.5*box] should be inside triangle */ + tetra_incircle = 2.001 * (1 + sqrt(3)) / 3.0 * box; /* to give room for ghost particles needed for periodic/reflective + boundary conditions, the incircle is twice as large, i.e. + [-0.5*box, 1.5*box,-0.5*box, 1.5*box] should be inside triangle */ tetra_sidelength = tetra_incircle * sqrt(12); - tetra_height = sqrt(3.0) / 2 * tetra_sidelength; + tetra_height = sqrt(3.0) / 2 * tetra_sidelength; if(ThisTask == 0) printf("side-length of enclosing triangle=%g tetra_height=%g box=%g\n", tetra_sidelength, tetra_height, box); @@ -165,19 +160,19 @@ void initialize_and_create_first_tetra(tessellation * T) for(i = -3, p = &DP[-3]; i < 0; i++, p++) { - p->index = -1; - p->task = ThisTask; + p->index = -1; + p->task = ThisTask; p->timebin = 0; } /* we also define a neutral element at infinity */ DPinfinity = -4; - DP[DPinfinity].x = MAX_DOUBLE_NUMBER; - DP[DPinfinity].y = MAX_DOUBLE_NUMBER; - DP[DPinfinity].z = MAX_DOUBLE_NUMBER; - DP[DPinfinity].index = -1; - DP[DPinfinity].task = ThisTask; + DP[DPinfinity].x = MAX_DOUBLE_NUMBER; + DP[DPinfinity].y = MAX_DOUBLE_NUMBER; + DP[DPinfinity].z = MAX_DOUBLE_NUMBER; + DP[DPinfinity].index = -1; + DP[DPinfinity].task = ThisTask; DP[DPinfinity].timebin = 0; /* now let's make the big triangle */ @@ -192,7 +187,7 @@ void initialize_and_create_first_tetra(tessellation * T) for(i = 0; i < 3; i++) { - n = i + 1; /* tetra index */ + n = i + 1; /* tetra index */ DT[0].t[i] = n; DT[0].s[i] = 2; @@ -226,7 +221,7 @@ void initialize_and_create_first_tetra(tessellation * T) DT[2].s[1] = 0; DT[3].s[0] = 1; - T->Ndt = 4; /* we'll start out with 4 triangles */ + T->Ndt = 4; /* we'll start out with 4 triangles */ CentralOffsetX = 0.5 * box - 0.5000001 * tetra_sidelength; CentralOffsetY = -0.5000001 * box; @@ -237,7 +232,6 @@ void initialize_and_create_first_tetra(tessellation * T) set_integers_for_point(T, i); } - /*! \brief Insert a point into mesh. * * Finds the triangle that contains this point, splits the triangle (usually @@ -252,7 +246,7 @@ void initialize_and_create_first_tetra(tessellation * T) * * \return Index of triangle containing point pp. */ -int insert_point(tessellation * T, int pp, int ttstart) +int insert_point(tessellation *T, int pp, int ttstart) { int tt0, tt1, tt2, tt3, ttetra_with_p; int moves, degenerate_flag; @@ -262,7 +256,7 @@ int insert_point(tessellation * T, int pp, int ttstart) ttetra_with_p = tt0; - if(degenerate_flag == 1) /* that's the normal split of a triangle into 3 */ + if(degenerate_flag == 1) /* that's the normal split of a triangle into 3 */ { /* we now need to split this triangle into three */ tt1 = T->Ndt++; @@ -275,7 +269,7 @@ int insert_point(tessellation * T, int pp, int ttstart) #ifdef VERBOSE printf("Task=%d: increase memory allocation, MaxNdt=%d Indi.AllocFacNdt=%g\n", ThisTask, T->MaxNdt, T->Indi.AllocFacNdt); #endif /* #ifdef VERBOSE */ - T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); + T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); T->DTC = myrealloc_movable(T->DTC, T->MaxNdt * sizeof(tetra_center)); T->DTF = myrealloc_movable(T->DTF, T->MaxNdt * sizeof(char)); @@ -313,7 +307,7 @@ int insert_point(tessellation * T, int pp, int ttstart) #ifdef VERBOSE printf("Task=%d: increase memory allocation, MaxNdt=%d Indi.AllocFacNdt=%g\n", ThisTask, T->MaxNdt, T->Indi.AllocFacNdt); #endif /* #ifdef VERBOSE */ - T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); + T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); T->DTC = myrealloc_movable(T->DTC, T->MaxNdt * sizeof(tetra_center)); T->DTF = myrealloc_movable(T->DTF, T->MaxNdt * sizeof(char)); @@ -340,7 +334,6 @@ int insert_point(tessellation * T, int pp, int ttstart) return ttetra_with_p; } - /*! \brief Make a 2 to 4 flip needed if point is on edge of a Delaunay * triangle. * @@ -361,7 +354,7 @@ int insert_point(tessellation * T, int pp, int ttstart) * * \return void */ -void make_a_2_to_4_flip(tessellation * T, int pp, int tt0, int tt1, int tt2, int tt3, int i0, int j0) +void make_a_2_to_4_flip(tessellation *T, int pp, int tt0, int tt1, int tt2, int tt3, int i0, int j0) { tetra *DT = T->DT; tetra *t0 = &DT[tt0]; @@ -420,7 +413,6 @@ void make_a_2_to_4_flip(tessellation * T, int pp, int tt0, int tt1, int tt2, int DT[t3->t[j1]].t[t3->s[j1]] = tt3; } - /*! \brief Makes a 1 to 3 flip needed if point is in a Delaunay triangle. * * If a new point is in a Delaunay triangle, this @@ -434,7 +426,7 @@ void make_a_2_to_4_flip(tessellation * T, int pp, int tt0, int tt1, int tt2, int * * \return void */ -void make_a_1_to_3_flip(tessellation * T, int pp, int tt0, int tt1, int tt2) +void make_a_1_to_3_flip(tessellation *T, int pp, int tt0, int tt1, int tt2) { tetra *DT = T->DT; tetra *t0 = &DT[tt0]; @@ -468,7 +460,6 @@ void make_a_1_to_3_flip(tessellation * T, int pp, int tt0, int tt1, int tt2) DT[t2->t[2]].t[t2->s[2]] = tt2; } - /*! \brief Flips trangle if needed. * * See Springel (2010) for detailed discussion how mesh is constructed. @@ -479,7 +470,7 @@ void make_a_1_to_3_flip(tessellation * T, int pp, int tt0, int tt1, int tt2) * * \return void */ -void check_edge_and_flip_if_needed(tessellation * T, int ip, int it) +void check_edge_and_flip_if_needed(tessellation *T, int ip, int it) { tetra *DT = T->DT; char *DTF = T->DTF; @@ -544,25 +535,25 @@ void check_edge_and_flip_if_needed(tessellation * T, int ip, int it) st2 = t->s[pi1]; /* change the points of the triangles */ - t->p[pi2] = pp; + t->p[pi2] = pp; DT[tt].p[ni2] = ip; /* change the pointers to the neighbouring triangles, and fix the adjency relations */ - t->t[pi1] = tt; + t->t[pi1] = tt; DT[tt].t[ni1] = it; - t->s[pi1] = ni1; + t->s[pi1] = ni1; DT[tt].s[ni1] = pi1; - t->t[pi] = t0; + t->t[pi] = t0; DT[t0].t[st0] = it; - t->s[pi] = st0; + t->s[pi] = st0; DT[t0].s[st0] = pi; - DT[tt].t[ni] = t2; + DT[tt].t[ni] = t2; DT[t2].t[st2] = tt; - DT[tt].s[ni] = st2; + DT[tt].s[ni] = st2; DT[t2].s[st2] = ni; DTF[tt] = 0; @@ -574,7 +565,6 @@ void check_edge_and_flip_if_needed(tessellation * T, int ip, int it) } } - /*! \brief Finds triangle in which new Delaunay point is located. * * Starts with a suggested triangle ttstart and checks if the point is @@ -589,7 +579,7 @@ void check_edge_and_flip_if_needed(tessellation * T, int ip, int it) * * \return Index of triangle in DT array. */ -int get_triangle(tessellation * T, int pp, int *moves, int *degenerate_flag, int ttstart) +int get_triangle(tessellation *T, int pp, int *moves, int *degenerate_flag, int ttstart) { int count_moves = 0; int ret; @@ -610,7 +600,7 @@ int get_triangle(tessellation * T, int pp, int *moves, int *degenerate_flag, int if(count_moves > MAX_COUNT_MOVES) { - printf("ta=%d triangle=%d xy=(%g|%g) ID=%d\n", ThisTask, (int) (tt), T->DP[pp].x, T->DP[pp].y, T->DP[pp].ID); + printf("ta=%d triangle=%d xy=(%g|%g) ID=%d\n", ThisTask, (int)(tt), T->DP[pp].x, T->DP[pp].y, T->DP[pp].ID); if(count_moves > MAX_COUNT_MOVES + 10) terminate("too many moves, problem to find triangle"); } @@ -623,7 +613,6 @@ int get_triangle(tessellation * T, int pp, int *moves, int *degenerate_flag, int return tt; } - /*! \brief Add row in matrix equation. * * Auxiliary function for solve_linear_equations_2d. @@ -643,7 +632,6 @@ static inline void add_row_2d(double *m, int r1, int r2, double fac) m[r1 * 3 + i] += fac * m[r2 * 3 + i]; } - /*! \brief Solve system of linear equations for 2d Voronoi construction. * * This is needed in get_triangle routine. @@ -679,7 +667,6 @@ int solve_linear_equations_2d(double *m, double *res) return 0; } - /*! \brief Does point lie in triangle? * * Tests whether point pp lies in the triangle, on an edge, or outside. In the @@ -695,12 +682,12 @@ int solve_linear_equations_2d(double *m, double *res) * * \return 1: point inside triangle; 0 outside; 10,11,12: on edge. */ -int FindTriangle(tessellation * T, int tt, int pp, int *degnerate_flag, int *nexttetra) +int FindTriangle(tessellation *T, int tt, int pp, int *degnerate_flag, int *nexttetra) { tetra *DT = T->DT; point *DP = T->DP; - tetra *t = &DT[tt]; - point *p = &DP[pp]; + tetra *t = &DT[tt]; + point *p = &DP[pp]; int pp0, pp1, pp2; point *p0, *p1, *p2; @@ -716,7 +703,7 @@ int FindTriangle(tessellation * T, int tt, int pp, int *degnerate_flag, int *nex if(pp0 == DPinfinity || pp1 == DPinfinity || pp2 == DPinfinity) { char buf[1000]; - sprintf(buf, "we are in a triangle with an infinity point. tetra=%d p=(%g|%g)\n", (int) (tt), p->x, p->y); + sprintf(buf, "we are in a triangle with an infinity point. tetra=%d p=(%g|%g)\n", (int)(tt), p->x, p->y); terminate(buf); } @@ -731,7 +718,7 @@ int FindTriangle(tessellation * T, int tt, int pp, int *degnerate_flag, int *nex double qx = p->xx - p0->xx; double qy = p->yy - p0->yy; - double mv_data[] = { ax, bx, qx, ay, by, qy }; + double mv_data[] = {ax, bx, qx, ay, by, qy}; double x[2]; int ivol, flag2, flag1, flag0; @@ -835,18 +822,20 @@ int FindTriangle(tessellation * T, int tt, int pp, int *degnerate_flag, int *nex { printf("flags=%d %d %d\n", flag0, flag1, flag2); - printf("points: %d %d %d %d\n", (int) (pp0), (int) (pp1), (int) (pp2), (int) (pp)); + printf("points: %d %d %d %d\n", (int)(pp0), (int)(pp1), (int)(pp2), (int)(pp)); printf("Ngas=%d\n", NumGas); - printf("xyz, p=%d: (%g|%g) index=%d task=%d ID=%d flags\n", (int) (pp0), p0->x, p0->y, p0->index, p0->task, P[p0->index % NumGas].ID); - printf("xyz, p=%d: (%g|%g) index=%d task=%d ID=%d flags\n", (int) (pp1), p1->x, p1->y, p1->index, p1->task, P[p1->index % NumGas].ID); - printf("xyz, p=%d: (%g|%g) index=%d task=%d ID=%d flags\n", (int) (pp2), p2->x, p2->y, p2->index, p2->task, P[p2->index % NumGas].ID); - printf("xyz, p=%d: (%g|%g) index=%d task=%d ID=%d flags\n", (int) (pp), p->x, p->y, p->index, p->task, P[p->index % NumGas].ID); + printf("xyz, p=%d: (%g|%g) index=%d task=%d ID=%d flags\n", (int)(pp0), p0->x, p0->y, p0->index, p0->task, + P[p0->index % NumGas].ID); + printf("xyz, p=%d: (%g|%g) index=%d task=%d ID=%d flags\n", (int)(pp1), p1->x, p1->y, p1->index, p1->task, + P[p1->index % NumGas].ID); + printf("xyz, p=%d: (%g|%g) index=%d task=%d ID=%d flags\n", (int)(pp2), p2->x, p2->y, p2->index, p2->task, + P[p2->index % NumGas].ID); + printf("xyz, p=%d: (%g|%g) index=%d task=%d ID=%d flags\n", (int)(pp), p->x, p->y, p->index, p->task, P[p->index % NumGas].ID); terminate("too many zeros - (perhaps identical points inserted?)"); } if(flag0 >= 0 && flag1 >= 0 && flag2 >= 0) { - /* we have a point inside the triangle, but it may still be on one of the edges */ if(count_zeros == 0) @@ -856,23 +845,23 @@ int FindTriangle(tessellation * T, int tt, int pp, int *degnerate_flag, int *nex return 1; } - if(count_zeros == 1) /* we lie on a face */ + if(count_zeros == 1) /* we lie on a face */ { if(flag2 == 0) { *degnerate_flag = 12; - return 12; /* point lies on side A */ + return 12; /* point lies on side A */ } if(flag1 == 0) { *degnerate_flag = 11; - return 11; /* point lies on side C */ + return 11; /* point lies on side C */ } if(flag0 == 0) { *degnerate_flag = 10; - return 10; /* point lies on side B */ + return 10; /* point lies on side B */ } } } @@ -938,7 +927,6 @@ int FindTriangle(tessellation * T, int tt, int pp, int *degnerate_flag, int *nex return 0; } - /*! \brief Tests whether point pp lies in the circumcircle around triangle * p0,p1,p2. * @@ -950,13 +938,13 @@ int FindTriangle(tessellation * T, int tt, int pp, int *degnerate_flag, int *nex * * \return (-1,0,1); -1: in circle; 0 on circle, 1: outside circle. */ -int InCircle_Quick(tessellation * T, int pp0, int pp1, int pp2, int pp) +int InCircle_Quick(tessellation *T, int pp0, int pp1, int pp2, int pp) { point *DP = T->DP; point *p0 = &DP[pp0]; point *p1 = &DP[pp1]; point *p2 = &DP[pp2]; - point *p = &DP[pp]; + point *p = &DP[pp]; double ax, ay, bx, by, cx, cy; double ab, bc, ca, a2, b2, c2, x; @@ -989,7 +977,6 @@ int InCircle_Quick(tessellation * T, int pp0, int pp1, int pp2, int pp) return 0; } - /*! \brief Tests whether point pp lies in the circumcircle around triangle * p0,p1,p2 with some error margin. * @@ -1005,13 +992,13 @@ int InCircle_Quick(tessellation * T, int pp0, int pp1, int pp2, int pp) * \return (-1,0,1); -1: in circle; 0 on circle (within tolerance), * 1: outside circle. */ -int InCircle_Errorbound(tessellation * T, int pp0, int pp1, int pp2, int pp) +int InCircle_Errorbound(tessellation *T, int pp0, int pp1, int pp2, int pp) { point *DP = T->DP; point *p0 = &DP[pp0]; point *p1 = &DP[pp1]; point *p2 = &DP[pp2]; - point *p = &DP[pp]; + point *p = &DP[pp]; if(pp0 == DPinfinity || pp1 == DPinfinity || pp2 == DPinfinity || pp == DPinfinity) return -1; @@ -1058,7 +1045,6 @@ int InCircle_Errorbound(tessellation * T, int pp0, int pp1, int pp2, int pp) return 0; } - /*! \brief Tests whether point pp lies in the circumcircle around triangle * p0,p1,p2 using arbitrary precision operations. * @@ -1074,13 +1060,13 @@ int InCircle_Errorbound(tessellation * T, int pp0, int pp1, int pp2, int pp) * \return (-1,0,1); -1: in circle; 0 on circle, * 1: outside circle. */ -int InCircle_Exact(tessellation * T, int pp0, int pp1, int pp2, int pp) +int InCircle_Exact(tessellation *T, int pp0, int pp1, int pp2, int pp) { point *DP = T->DP; point *p0 = &DP[pp0]; point *p1 = &DP[pp1]; point *p2 = &DP[pp2]; - point *p = &DP[pp]; + point *p = &DP[pp]; if(pp0 == DPinfinity || pp1 == DPinfinity || pp2 == DPinfinity || pp == DPinfinity) return -1; @@ -1182,7 +1168,6 @@ int InCircle_Exact(tessellation * T, int pp0, int pp1, int pp2, int pp) return sign; } - /*! \brief Returns the orientation of the triangle. * * Defined as the determinant of the matrix of the position of the three edge @@ -1198,7 +1183,7 @@ int InCircle_Exact(tessellation * T, int pp0, int pp1, int pp2, int pp) * * \return Determinant of orientation matrix. */ -double test_triangle_orientation(tessellation * T, int pp0, int pp1, int pp2) +double test_triangle_orientation(tessellation *T, int pp0, int pp1, int pp2) { point *DP = T->DP; point *p0 = &DP[pp0]; @@ -1208,7 +1193,6 @@ double test_triangle_orientation(tessellation * T, int pp0, int pp1, int pp2) return (p1->x - p0->x) * (p2->y - p0->y) - (p1->y - p0->y) * (p2->x - p0->x); } - /*! \brief Check if triangle is positively or negatively oriented. * * \param[in] T Pointer to tessellation. @@ -1219,7 +1203,7 @@ double test_triangle_orientation(tessellation * T, int pp0, int pp1, int pp2) * \return -1 if negatively, 0 if degenerate (in a line) and 1 if positively * oriented. */ -int Orient2d_Quick(tessellation * T, int pp0, int pp1, int pp2) +int Orient2d_Quick(tessellation *T, int pp0, int pp1, int pp2) { point *DP = T->DP; point *p0 = &DP[pp0]; @@ -1237,7 +1221,6 @@ int Orient2d_Quick(tessellation * T, int pp0, int pp1, int pp2) return 0; } - /*! \brief Check if triangle is positively or negatively oriented. * * Uses arbitrary precision operations, which is computationally expensive but @@ -1251,7 +1234,7 @@ int Orient2d_Quick(tessellation * T, int pp0, int pp1, int pp2) * \return -1 if negatively, 0 if degenerate (in a line) and 1 if positively * oriented. */ -int Orient2d_Exact(tessellation * T, int pp0, int pp1, int pp2) +int Orient2d_Exact(tessellation *T, int pp0, int pp1, int pp2) { point *DP = T->DP; point *p0 = &DP[pp0]; @@ -1288,7 +1271,7 @@ int Orient2d_Exact(tessellation * T, int pp0, int pp1, int pp2) return (sign); -#else /* #if USEDBITS > 31 */ +#else /* #if USEDBITS > 31 */ signed long long dx1, dy1, dx2, dy2, x; dx1 = (p1->ix - p0->ix); @@ -1306,10 +1289,8 @@ int Orient2d_Exact(tessellation * T, int pp0, int pp1, int pp2) #endif /* #if USEDBITS > 31 #else */ } - -const int edge_start[3] = { 1, 2, 0 }; -const int edge_end[3] = { 2, 0, 1 }; - +const int edge_start[3] = {1, 2, 0}; +const int edge_end[3] = {2, 0, 1}; /*! \brief Calculate cell volumes and face areas of mesh. * @@ -1319,7 +1300,7 @@ const int edge_end[3] = { 2, 0, 1 }; * * \return void */ -void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) +void process_edge_faces_and_volumes(tessellation *T, int tt, int nr) { int i, j, qq, p1, p2, k; face *f; @@ -1341,9 +1322,9 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) terminate("Nvf larger than MaxNvf"); } - tetra *DT = T->DT; - point *DP = T->DP; - face *VF = T->VF; + tetra *DT = T->DT; + point *DP = T->DP; + face *VF = T->VF; tetra_center *DTC = T->DTC; tetra *t = &DT[tt]; @@ -1376,9 +1357,9 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) #endif /* #ifdef TETRA_INDEX_IN_FACE */ #ifdef REFINEMENT_MERGE_CELLS - f->t = tt; - f->nr = nr; /* delaunay tetra and edge number that generated this face */ -#endif /* #ifdef REFINEMENT_MERGE_CELLS */ + f->t = tt; + f->nr = nr; /* delaunay tetra and edge number that generated this face */ +#endif /* #ifdef REFINEMENT_MERGE_CELLS */ nx = DTC[tt].cx - DTC[qq].cx; ny = DTC[tt].cy - DTC[qq].cy; @@ -1388,7 +1369,7 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) hx = 0.5 * (dpi->x - dpj->x); hy = 0.5 * (dpi->y - dpj->y); - h = sqrt(hx * hx + hy * hy); + h = sqrt(hx * hx + hy * hy); dvol = 0.5 * f->area * h; #if defined(REGULARIZE_MESH_FACE_ANGLE) || defined(OUTPUT_MESH_FACE_ANGLE) @@ -1459,24 +1440,24 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) if(DP[p1].ID < DP[p2].ID) { - low_p = p1; + low_p = p1; high_p = p2; } else { - low_p = p2; + low_p = p2; high_p = p1; } int this_task_responsible_flag = 0; - if(TimeBinSynchronized[DP[low_p].timebin]) /* the one with the lower ID is active */ + if(TimeBinSynchronized[DP[low_p].timebin]) /* the one with the lower ID is active */ { /* we need to check whether the one with the lower ID is a local particle */ if(DP[low_p].task == ThisTask && DP[low_p].index >= 0 && DP[low_p].index < NumGas) this_task_responsible_flag = 1; } - else if(TimeBinSynchronized[DP[high_p].timebin]) /* only the side with the higher ID is active */ + else if(TimeBinSynchronized[DP[high_p].timebin]) /* only the side with the higher ID is active */ { /* we need to check whether we hold the one with the higher ID, if yes, we'll do it */ if(DP[high_p].task == ThisTask && DP[high_p].index >= 0 && DP[high_p].index < NumGas) @@ -1523,7 +1504,7 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) terminate("Narea >= MaxNarea"); } - AreaList[Narea].task = DP[q].task; + AreaList[Narea].task = DP[q].task; AreaList[Narea].index = DP[q].originalindex; AreaList[Narea].darea = f->area; Narea++; @@ -1532,7 +1513,6 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) } } - /*! \brief Copies triangle information from DTC array to trilist. * * Performs an orientation check and swaps orientation if needed. @@ -1547,12 +1527,12 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) * * \return Next index in trilist array. */ -int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip, triangle * trilist, int ntri, int max_n_tri) +int derefine_refine_get_triangles(tessellation *T, int tt, int nr, point *dtip, triangle *trilist, int ntri, int max_n_tri) { - tetra *DT = T->DT; + tetra *DT = T->DT; tetra_center *DTC = T->DTC; - tetra *t = &DT[tt]; - int qq = t->t[nr]; + tetra *t = &DT[tt]; + int qq = t->t[nr]; if(ntri >= max_n_tri) terminate("ntri >= max_n_tri"); @@ -1581,7 +1561,6 @@ int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip return ntri; } - /*! \brief Add point and adjust triangles accordingly. * * \param[in] q Index of point in DP array. @@ -1592,7 +1571,7 @@ int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip * * \return Updated number of triangles. */ -int derefine_add_point_and_split_tri(int q, triangle * trilist, int ntri, int max_ntri, double vol) +int derefine_add_point_and_split_tri(int q, triangle *trilist, int ntri, int max_ntri, double vol) { double m[2], n[2], sc[3], *a; double cut[2][2], ed[2]; @@ -1639,109 +1618,108 @@ int derefine_add_point_and_split_tri(int q, triangle * trilist, int ntri, int ma flag[k] = 0; } - switch (count) + switch(count) { - case 0: /* the whole tetra is on the side of current owner - nothing to be done */ - break; - - case 3: /* the whole tetra is on the side of new point */ - trilist[i].owner = q; /* change owner */ - break; - - case 1: - case 2: - - if(nnew + 2 > max_ntri) - terminate("nnew + 2 > max_ntri"); - - trilist[nnew] = trilist[i]; - trilist[nnew + 1] = trilist[i]; - - /* find the point index that is on the other side */ - for(k = 0; k < 3; k++) - { - if(flag[k] == 1 && count == 1) - break; - if(flag[k] == 0 && count == 2) - break; - } - - for(j = 0; j < 2; j++) - { - kk = k + j + 1; - if(kk > 2) - kk -= 3; - - double *b = trilist[i].p[k]; - double *a = trilist[i].p[kk]; - - for(l = 0; l < 2; l++) - ed[l] = a[l] - b[l]; - - double prod = (ed[0] * n[0] + ed[1] * n[1]); - double t; - if(prod) - t = -sc[k] / prod; - else - t = 0.5; - - if(t < 0) - t = 0; - if(t > 1) - t = 1; - - for(l = 0; l < 2; l++) - cut[j][l] = b[l] + t * ed[l]; - } - - /* modify the tetra that's assigned to the new point */ - for(j = 0; j < 2; j++) - { - kk = k + j + 1; - if(kk > 2) - kk -= 3; - - for(l = 0; l < 2; l++) - trilist[i].p[kk][l] = cut[j][l]; - } - - oldq = trilist[i].owner; - - if(count == 1) - trilist[i].owner = q; - - /* modify the two new tetras */ - kk = k + 1; - if(kk > 2) - kk -= 3; - - for(l = 0; l < 2; l++) - { - trilist[nnew].p[k][l] = cut[0][l]; - - trilist[nnew + 1].p[k][l] = cut[1][l]; - trilist[nnew + 1].p[kk][l] = cut[0][l]; - } - - if(count == 1) - { - trilist[nnew].owner = oldq; - trilist[nnew + 1].owner = oldq; - } - else - { - trilist[nnew].owner = q; - trilist[nnew + 1].owner = q; - } - nnew += 2; - break; + case 0: /* the whole tetra is on the side of current owner - nothing to be done */ + break; + + case 3: /* the whole tetra is on the side of new point */ + trilist[i].owner = q; /* change owner */ + break; + + case 1: + case 2: + + if(nnew + 2 > max_ntri) + terminate("nnew + 2 > max_ntri"); + + trilist[nnew] = trilist[i]; + trilist[nnew + 1] = trilist[i]; + + /* find the point index that is on the other side */ + for(k = 0; k < 3; k++) + { + if(flag[k] == 1 && count == 1) + break; + if(flag[k] == 0 && count == 2) + break; + } + + for(j = 0; j < 2; j++) + { + kk = k + j + 1; + if(kk > 2) + kk -= 3; + + double *b = trilist[i].p[k]; + double *a = trilist[i].p[kk]; + + for(l = 0; l < 2; l++) + ed[l] = a[l] - b[l]; + + double prod = (ed[0] * n[0] + ed[1] * n[1]); + double t; + if(prod) + t = -sc[k] / prod; + else + t = 0.5; + + if(t < 0) + t = 0; + if(t > 1) + t = 1; + + for(l = 0; l < 2; l++) + cut[j][l] = b[l] + t * ed[l]; + } + + /* modify the tetra that's assigned to the new point */ + for(j = 0; j < 2; j++) + { + kk = k + j + 1; + if(kk > 2) + kk -= 3; + + for(l = 0; l < 2; l++) + trilist[i].p[kk][l] = cut[j][l]; + } + + oldq = trilist[i].owner; + + if(count == 1) + trilist[i].owner = q; + + /* modify the two new tetras */ + kk = k + 1; + if(kk > 2) + kk -= 3; + + for(l = 0; l < 2; l++) + { + trilist[nnew].p[k][l] = cut[0][l]; + + trilist[nnew + 1].p[k][l] = cut[1][l]; + trilist[nnew + 1].p[kk][l] = cut[0][l]; + } + + if(count == 1) + { + trilist[nnew].owner = oldq; + trilist[nnew + 1].owner = oldq; + } + else + { + trilist[nnew].owner = q; + trilist[nnew + 1].owner = q; + } + nnew += 2; + break; } } return nnew; } - /*! \brief Determines area of triangle (i.e. 2d Volume). * * \param i Index in trilist array. @@ -1749,7 +1727,7 @@ int derefine_add_point_and_split_tri(int q, triangle * trilist, int ntri, int ma * * \return Area of triangle. */ -double get_tri_volume(int i, triangle * trilist) +double get_tri_volume(int i, triangle *trilist) { double *p0 = &trilist[i].p[0][0]; double *p1 = &trilist[i].p[1][0]; @@ -1760,7 +1738,6 @@ double get_tri_volume(int i, triangle * trilist) return 0.5 * nz; } - /*! \brief Process edge for volume calculation. * * Calculates the contribution of edge to volumes of neighboring @@ -1773,10 +1750,10 @@ double get_tri_volume(int i, triangle * trilist) * * \return void */ -void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) +void derefine_refine_process_edge(tessellation *T, double *vol, int tt, int nr) { - tetra *DT = T->DT; - point *DP = T->DP; + tetra *DT = T->DT; + point *DP = T->DP; tetra_center *DTC = T->DTC; int i, j, qq, p1, p2; @@ -1808,7 +1785,7 @@ void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) hx = 0.5 * (dpi->x - dpj->x); hy = 0.5 * (dpi->y - dpj->y); - h = sqrt(hx * hx + hy * hy); + h = sqrt(hx * hx + hy * hy); dvol = 0.5 * area * h; if(p1 >= 0 && p1 < DeRefMesh.Ndp) @@ -1818,14 +1795,13 @@ void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) vol[p2] += dvol; } - /*! \brief Computes the circum-circle of all triangles in mesh. * * \param[in, out] T Pointer to tessellation. * * \return void */ -void compute_circumcircles(tessellation * T) +void compute_circumcircles(tessellation *T) { tetra *DT = T->DT; char *DTF = T->DTF; @@ -1849,7 +1825,6 @@ void compute_circumcircles(tessellation * T) } } - /*! \brief Computes the circum-circle of triangle tt. * * \param[in, out] T Pointer to tessellation. @@ -1857,11 +1832,11 @@ void compute_circumcircles(tessellation * T) * * \return void */ -void update_circumcircle(tessellation * T, int tt) +void update_circumcircle(tessellation *T, int tt) { - tetra *DT = T->DT; + tetra *DT = T->DT; tetra_center *DTC = T->DTC; - point *DP = T->DP; + point *DP = T->DP; tetra *t = &DT[tt]; point *p0, *p1, *p2; @@ -1891,7 +1866,7 @@ void update_circumcircle(tessellation * T, int tt) double aa = 0.5 * (ax * ax + ay * ay); double bb = 0.5 * (bx * bx + by * by); - double mv_data[] = { ax, ay, aa, bx, by, bb }; + double mv_data[] = {ax, ay, aa, bx, by, bb}; double x[2]; int status = solve_linear_equations_2d(mv_data, x); @@ -1911,14 +1886,13 @@ void update_circumcircle(tessellation * T, int tt) } } - /*! \brief Computes the integer coordinates from coordinates for a point. * * \pararm[in, out] p Pointer to point. * * \return void */ -void set_integers_for_pointer(point * p) +void set_integers_for_pointer(point *p) { p->xx = (p->x - CentralOffsetX) * ConversionFac + 1.0; p->yy = (p->y - CentralOffsetY) * ConversionFac + 1.0; @@ -1936,7 +1910,6 @@ void set_integers_for_pointer(point * p) p->yy = mask_voronoi_int(p->yy); } - /*! \brief Outputs Voronoi mesh to file. * * Outputs the Voronoi mesh data from task write Task to lastTask in file @@ -1949,7 +1922,7 @@ void set_integers_for_pointer(point * p) * * \return void */ -void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTask) +void write_voronoi_mesh(tessellation *T, char *fname, int writeTask, int lastTask) { CPU_Step[CPU_MISC] += measure_time(); @@ -1964,20 +1937,20 @@ void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTa tetra *q, *qstart; tetra_center *DTC = T->DTC; - tetra *DT = T->DT; - point *DP = T->DP; + tetra *DT = T->DT; + point *DP = T->DP; - MaxNel = 10 * NumGas; /* max edge list */ - Nel = 0; /* length of edge list */ + MaxNel = 10 * NumGas; /* max edge list */ + Nel = 0; /* length of edge list */ - EdgeList = mymalloc("EdgeList", MaxNel * sizeof(int)); - Nedges = mymalloc("Nedges", NumGas * sizeof(int)); + EdgeList = mymalloc("EdgeList", MaxNel * sizeof(int)); + Nedges = mymalloc("Nedges", NumGas * sizeof(int)); NedgesOffset = mymalloc("NedgesOffset", NumGas * sizeof(int)); - whichtetra = mymalloc("whichtetra", NumGas * sizeof(int)); - xyz_edges = mymalloc("xyz_edges", T->Ndt * DIMS * sizeof(float)); - ngas_list = mymalloc("ngas_list", sizeof(int) * NTask); - nel_list = mymalloc("nel_list", sizeof(int) * NTask); - ndt_list = mymalloc("ndt_list", sizeof(int) * NTask); + whichtetra = mymalloc("whichtetra", NumGas * sizeof(int)); + xyz_edges = mymalloc("xyz_edges", T->Ndt * DIMS * sizeof(float)); + ngas_list = mymalloc("ngas_list", sizeof(int) * NTask); + nel_list = mymalloc("nel_list", sizeof(int) * NTask); + ndt_list = mymalloc("ndt_list", sizeof(int) * NTask); for(i = 0; i < T->Ndt; i++) { @@ -1987,7 +1960,7 @@ void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTa for(i = 0; i < NumGas; i++) { - Nedges[i] = 0; + Nedges[i] = 0; whichtetra[i] = -1; } @@ -2035,8 +2008,8 @@ void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTa if(ThisTask == writeTask) { ngas_tot = NumGas; - nel_tot = Nel; - ndt_tot = T->Ndt; + nel_tot = Nel; + ndt_tot = T->Ndt; for(task = writeTask + 1; task <= lastTask; task++) { @@ -2134,5 +2107,4 @@ void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTa CPU_Step[CPU_MAKEIMAGES] += measure_time(); } - #endif /* #if defined(TWODIMS) && !defined(ONEDIMS) */ diff --git a/src/mesh/voronoi/voronoi_3d.c b/src/mesh/voronoi/voronoi_3d.c index 2a6dae81f4320e4dd9a49fb225a0abf7fce39f27..f8cc3ad712cc423731b434a6b17127e1194e240a 100644 --- a/src/mesh/voronoi/voronoi_3d.c +++ b/src/mesh/voronoi/voronoi_3d.c @@ -92,47 +92,36 @@ * char *fname, int writeTask, int lastTask) * void write_voronoi_mesh(tessellation * T, char *fname, * int writeTask, int lastTask) - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 21.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <gmp.h> +#include <gsl/gsl_linalg.h> +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> -#include <gsl/gsl_linalg.h> -#include <gmp.h> #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - -#if !defined(TWODIMS) && !defined(ONEDIMS) /* will only be compiled in 3D case */ - +#if !defined(TWODIMS) && !defined(ONEDIMS) /* will only be compiled in 3D case */ #define INSIDE_EPS 1.0e-6 #define GAUSS_EPS 1.0e-8 +const int access_triangles[4][3] = {{1, 3, 2}, {0, 2, 3}, {0, 3, 1}, {0, 1, 2}}; -const int access_triangles[4][3] = { - {1, 3, 2}, - {0, 2, 3}, - {0, 3, 1}, - {0, 1, 2} -}; - - -const int edge_start[6] = { 0, 0, 0, 1, 1, 2 }; -const int edge_end[6] = { 1, 2, 3, 2, 3, 3 }; -const int edge_opposite[6] = { 3, 1, 2, 3, 0, 1 }; -const int edge_nexttetra[6] = { 2, 3, 1, 0, 2, 0 }; - +const int edge_start[6] = {0, 0, 0, 1, 1, 2}; +const int edge_end[6] = {1, 2, 3, 2, 3, 3}; +const int edge_opposite[6] = {3, 1, 2, 3, 0, 1}; +const int edge_nexttetra[6] = {2, 3, 1, 0, 2, 0}; /*! \brief Initializes 3d tessellation and create all-enclosing tetrahedron. * @@ -141,7 +130,7 @@ const int edge_nexttetra[6] = { 2, 3, 1, 0, 2, 0 }; * * \return void */ -void initialize_and_create_first_tetra(tessellation * T) +void initialize_and_create_first_tetra(tessellation *T) { point *p; int i, n; @@ -171,9 +160,9 @@ void initialize_and_create_first_tetra(tessellation * T) if(box < boxSize_Z) box = boxSize_Z; - tetra_incircle = 1.5 * box; - tetra_sidelength = tetra_incircle * sqrt(24); - tetra_height = sqrt(2.0 / 3) * tetra_sidelength; + tetra_incircle = 1.5 * box; + tetra_sidelength = tetra_incircle * sqrt(24); + tetra_height = sqrt(2.0 / 3) * tetra_sidelength; tetra_face_height = sqrt(3.0) / 2.0 * tetra_sidelength; point *DP = T->DP; @@ -205,19 +194,19 @@ void initialize_and_create_first_tetra(tessellation * T) for(i = -4, p = &DP[-4]; i < 0; i++, p++) { - p->index = -1; - p->task = ThisTask; + p->index = -1; + p->task = ThisTask; p->timebin = 0; } /* we also define a neutral element at infinity */ DPinfinity = -5; - DP[DPinfinity].x = MAX_DOUBLE_NUMBER; - DP[DPinfinity].y = MAX_DOUBLE_NUMBER; - DP[DPinfinity].z = MAX_DOUBLE_NUMBER; - DP[DPinfinity].index = -1; - DP[DPinfinity].task = ThisTask; + DP[DPinfinity].x = MAX_DOUBLE_NUMBER; + DP[DPinfinity].y = MAX_DOUBLE_NUMBER; + DP[DPinfinity].z = MAX_DOUBLE_NUMBER; + DP[DPinfinity].index = -1; + DP[DPinfinity].task = ThisTask; DP[DPinfinity].timebin = 0; /* now let's make the big tetrahedron */ @@ -233,7 +222,7 @@ void initialize_and_create_first_tetra(tessellation * T) for(i = 0; i < 4; i++) { - n = i + 1; /* tetra index */ + n = i + 1; /* tetra index */ DT[0].t[i] = n; DT[0].s[i] = 3; @@ -289,7 +278,7 @@ void initialize_and_create_first_tetra(tessellation * T) DT[3].s[2] = 1; DT[4].s[1] = 2; - T->Ndt = 5; /* we'll start out with 5 tetras */ + T->Ndt = 5; /* we'll start out with 5 tetras */ CentralOffsetX = 0.5 * box - 0.5000001 * tetra_sidelength; CentralOffsetY = 0.5 * box - (1.0000001 / 3) * tetra_face_height; @@ -303,7 +292,6 @@ void initialize_and_create_first_tetra(tessellation * T) #endif /* #ifndef OPTIMIZE_MEMORY_USAGE */ } - #ifdef TETRA_INDEX_IN_FACE /*! \brief Gets the line segments of a Voronoi cell. * @@ -321,29 +309,29 @@ void initialize_and_create_first_tetra(tessellation * T) */ void get_line_segments(int sphp_index, int dp_index, double *segments, unsigned int *nof_elements, unsigned int max_elements) { - //index for segments array + // index for segments array unsigned int a = 0; - int edge = SphP[sphp_index].first_connection; + int edge = SphP[sphp_index].first_connection; int last_edge = SphP[sphp_index].last_connection; - //loop over all interfaces of the cell + // loop over all interfaces of the cell while(1) { int dq_index = DC[edge].dp_index; - //one of the tetrahedras around the Delaunay connection - int tt = DC[edge].dt_index; + // one of the tetrahedras around the Delaunay connection + int tt = DC[edge].dt_index; tetra *t = &Mesh.DT[tt]; - //find the local index of the edge + // find the local index of the edge int nr = 6; int e, dp_start_index, dp_end_index; for(e = 0; e < 6; e++) { dp_start_index = t->p[edge_start[e]]; - dp_end_index = t->p[edge_end[e]]; + dp_end_index = t->p[edge_end[e]]; if((dp_start_index == dp_index && dp_end_index == dq_index) || (dp_start_index == dq_index && dp_end_index == dp_index)) { @@ -352,10 +340,10 @@ void get_line_segments(int sphp_index, int dp_index, double *segments, unsigned } } - //ensure that the local edge index has been found + // ensure that the local edge index has been found assert(nr != 6); - //already set: t,tt,nr + // already set: t,tt,nr int i, j, k, l, m, ii, jj, kk, ll, nn; tetra *prev, *next; tetra_center *prevc, *nextc; @@ -365,13 +353,13 @@ void get_line_segments(int sphp_index, int dp_index, double *segments, unsigned k = edge_opposite[nr]; l = edge_nexttetra[nr]; - prev = t; + prev = t; prevc = &Mesh.DTC[tt]; do { - nn = prev->t[l]; - next = &Mesh.DT[nn]; + nn = prev->t[l]; + next = &Mesh.DT[nn]; nextc = &Mesh.DTC[nn]; if(a > max_elements - 7) @@ -401,14 +389,13 @@ void get_line_segments(int sphp_index, int dp_index, double *segments, unsigned kk = 6 - (ll + ii + jj); - prev = next; + prev = next; prevc = nextc; i = ii; l = ll; j = jj; k = kk; - } while(next != t); @@ -419,7 +406,7 @@ void get_line_segments(int sphp_index, int dp_index, double *segments, unsigned edge = DC[edge].next; - } //end of while loop + } // end of while loop *nof_elements = a; @@ -427,7 +414,6 @@ void get_line_segments(int sphp_index, int dp_index, double *segments, unsigned } #endif /* #ifdef TETRA_INDEX_IN_FACE */ - /*! \brief Calculate cell volumes and face areas of mesh. * * \param[in, out] T Pointer to tessellation. @@ -436,7 +422,7 @@ void get_line_segments(int sphp_index, int dp_index, double *segments, unsigned * * \return void */ -void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) +void process_edge_faces_and_volumes(tessellation *T, int tt, int nr) { int i, j, k, l, m, ii, jj, kk, ll, nn, count, nr_next, p1, p2; face *f; @@ -463,9 +449,9 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) terminate("Nvf larger than MaxNvf"); } - tetra *DT = T->DT; - point *DP = T->DP; - face *VF = T->VF; + tetra *DT = T->DT; + point *DP = T->DP; + face *VF = T->VF; tetra_center *DTC = T->DTC; tetra *t = &DT[tt]; @@ -483,8 +469,8 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) f = &VF[T->Nvf++]; f->area = 0; - f->p1 = p1; - f->p2 = p2; + f->p1 = p1; + f->p2 = p2; f->cx = 0; f->cy = 0; @@ -506,12 +492,12 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) count = 0; - prev = t; + prev = t; prevc = &DTC[tt]; do { - nn = prev->t[l]; - next = &DT[nn]; + nn = prev->t[l]; + next = &DT[nn]; nextc = &DTC[nn]; if(prev != t && next != t) @@ -569,12 +555,12 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) break; } - prev = next; + prev = next; prevc = nextc; - i = ii; - l = ll; - j = jj; - k = kk; + i = ii; + l = ll; + j = jj; + k = kk; count++; @@ -594,9 +580,9 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) } #ifdef REFINEMENT_MERGE_CELLS - f->t = tt; - f->nr = nr; /* delaunay tetra and edge number that generated this face */ -#endif /* #ifdef REFINEMENT_MERGE_CELLS */ + f->t = tt; + f->nr = nr; /* delaunay tetra and edge number that generated this face */ +#endif /* #ifdef REFINEMENT_MERGE_CELLS */ dvol = (1.0 / 3) * f->area * h; @@ -633,11 +619,9 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) SphP[DP[p1].index].Center[0] += dvol * sx; SphP[DP[p1].index].Center[1] += dvol * sy; SphP[DP[p1].index].Center[2] += dvol * sz; - } } - if(DP[p2].task == ThisTask && DP[p2].index >= 0 && DP[p2].index < NumGas) { if(TimeBinSynchronized[P[DP[p2].index].TimeBinHydro]) @@ -666,7 +650,6 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) SphP[DP[p2].index].Center[0] += dvol * sx; SphP[DP[p2].index].Center[1] += dvol * sy; SphP[DP[p2].index].Center[2] += dvol * sz; - } } @@ -674,24 +657,24 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) if(DP[p1].ID < DP[p2].ID) { - low_p = p1; + low_p = p1; high_p = p2; } else { - low_p = p2; + low_p = p2; high_p = p1; } int this_task_responsible_flag = 0; - if(TimeBinSynchronized[DP[low_p].timebin]) /* the one with the lower ID is active */ + if(TimeBinSynchronized[DP[low_p].timebin]) /* the one with the lower ID is active */ { /* we need to check whether the one with the lower ID is a local particle */ if(DP[low_p].task == ThisTask && DP[low_p].index >= 0 && DP[low_p].index < NumGas) this_task_responsible_flag = 1; } - else if(TimeBinSynchronized[DP[high_p].timebin]) /* only the side with the higher ID is active */ + else if(TimeBinSynchronized[DP[high_p].timebin]) /* only the side with the higher ID is active */ { /* we need to check whether we hold the one with the higher ID, if yes, we'll do it */ if(DP[high_p].task == ThisTask && DP[high_p].index >= 0 && DP[high_p].index < NumGas) @@ -738,7 +721,7 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) terminate("Narea >= MaxNarea"); } - AreaList[Narea].task = DP[q].task; + AreaList[Narea].task = DP[q].task; AreaList[Narea].index = DP[q].originalindex; AreaList[Narea].darea = f->area; Narea++; @@ -747,7 +730,6 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) } } - /*! \brief Gathers tetrahedron data as elements in array called 'trilist'. * * \param[in] T Pointer to tessellation. @@ -760,9 +742,9 @@ void process_edge_faces_and_volumes(tessellation * T, int tt, int nr) * * \return New length of trilist data. */ -int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip, triangle * trilist, int ntri, int max_n_tri) +int derefine_refine_get_triangles(tessellation *T, int tt, int nr, point *dtip, triangle *trilist, int ntri, int max_n_tri) { - tetra *DT = T->DT; + tetra *DT = T->DT; tetra_center *DTC = T->DTC; int i, j, k, l, m, ii, jj, kk, ll, nn, count; @@ -783,12 +765,12 @@ int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip count = 0; - prev = t; + prev = t; prevc = &DTC[tt]; do { - nn = prev->t[l]; - next = &DT[nn]; + nn = prev->t[l]; + next = &DT[nn]; nextc = &DTC[nn]; if(prev != t && next != t) @@ -842,12 +824,12 @@ int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip kk = 6 - (ll + ii + jj); - prev = next; + prev = next; prevc = nextc; - i = ii; - l = ll; - j = jj; - k = kk; + i = ii; + l = ll; + j = jj; + k = kk; count++; @@ -859,7 +841,6 @@ int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip return ntri; } - /*! \brief Returns volume of a tetrahedron. * * \param[in] i Index of tetrahedron in trilist. @@ -867,7 +848,7 @@ int derefine_refine_get_triangles(tessellation * T, int tt, int nr, point * dtip * * \return Volume of tetrahedron. */ -double get_tri_volume(int i, triangle * trilist) +double get_tri_volume(int i, triangle *trilist) { double nx, ny, nz; @@ -883,7 +864,6 @@ double get_tri_volume(int i, triangle * trilist) return (nx * (p3[0] - p0[0]) + ny * (p3[1] - p0[1]) + nz * (p3[2] - p0[2])) / 6.0; } - /*! \brief Add point and adjust tetrahedra accordingly. * * \param[in] q Index of point in DP array. @@ -894,7 +874,7 @@ double get_tri_volume(int i, triangle * trilist) * * \return Updated number of triangles. */ -int derefine_add_point_and_split_tri(int q, triangle * trilist, int ntri, int max_ntri, double vol) +int derefine_add_point_and_split_tri(int q, triangle *trilist, int ntri, int max_ntri, double vol) { #define MIN_VOL_FAC 1.0e-6 double m[3], n[3], sc[4], *a; @@ -946,409 +926,408 @@ int derefine_add_point_and_split_tri(int q, triangle * trilist, int ntri, int ma flag[k] = 0; } - switch (count) + switch(count) { - case 0: /* the whole tetra is on the side of current owner - nothing to be done */ - break; - - case 4: /* the whole tetra is on the side of new point */ - trilist[i].owner = q; /* change owner */ - break; - - case 1: - case 3: - - /* we have one point on either side */ - /* for count=1 the tip of the tetra is cut off and assigned to the new point. */ - /* the rest is subdivided into three tetras */ + case 0: /* the whole tetra is on the side of current owner - nothing to be done */ + break; - if(nnew + 3 > max_ntri) - { - terminate("nnew + 3 > max_ntri"); - } + case 4: /* the whole tetra is on the side of new point */ + trilist[i].owner = q; /* change owner */ + break; - trilist[nnew] = trilist[i]; - trilist[nnew + 1] = trilist[i]; - trilist[nnew + 2] = trilist[i]; + case 1: + case 3: - /* find the point index that is on the other side */ - for(k = 0; k < 4; k++) - { - if(flag[k] == 1 && count == 1) - break; - if(flag[k] == 0 && count == 3) - break; - } + /* we have one point on either side */ + /* for count=1 the tip of the tetra is cut off and assigned to the new point. */ + /* the rest is subdivided into three tetras */ - /* determine the cut-points on the corresponding edges */ + if(nnew + 3 > max_ntri) + { + terminate("nnew + 3 > max_ntri"); + } - for(j = 0; j < 3; j++) - { - double *b = trilist[i].p[k]; - double *a = trilist[i].p[access_triangles[k][j]]; + trilist[nnew] = trilist[i]; + trilist[nnew + 1] = trilist[i]; + trilist[nnew + 2] = trilist[i]; - for(l = 0; l < 3; l++) - ed[l] = a[l] - b[l]; + /* find the point index that is on the other side */ + for(k = 0; k < 4; k++) + { + if(flag[k] == 1 && count == 1) + break; + if(flag[k] == 0 && count == 3) + break; + } - double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); - double t; + /* determine the cut-points on the corresponding edges */ - if(prod) - t = -sc[k] / prod; - else - t = 0.5; + for(j = 0; j < 3; j++) + { + double *b = trilist[i].p[k]; + double *a = trilist[i].p[access_triangles[k][j]]; - if(t < 0) - t = 0; - if(t > 1) - t = 1; + for(l = 0; l < 3; l++) + ed[l] = a[l] - b[l]; - for(l = 0; l < 3; l++) - cut[j][l] = b[l] + t * ed[l]; - } + double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); + double t; - /* modify the tetra that's assigned to the new point */ - for(j = 0; j < 3; j++) - { - double *a = trilist[i].p[access_triangles[k][j]]; - for(l = 0; l < 3; l++) - a[l] = cut[j][l]; - } + if(prod) + t = -sc[k] / prod; + else + t = 0.5; - oldq = trilist[i].owner; + if(t < 0) + t = 0; + if(t > 1) + t = 1; - if(count == 1) - trilist[i].owner = q; + for(l = 0; l < 3; l++) + cut[j][l] = b[l] + t * ed[l]; + } - /* modify the three new tetras */ + /* modify the tetra that's assigned to the new point */ + for(j = 0; j < 3; j++) + { + double *a = trilist[i].p[access_triangles[k][j]]; + for(l = 0; l < 3; l++) + a[l] = cut[j][l]; + } - for(l = 0; l < 3; l++) - { - trilist[nnew].p[k][l] = cut[0][l]; + oldq = trilist[i].owner; - trilist[nnew + 1].p[access_triangles[k][0]][l] = cut[0][l]; - trilist[nnew + 1].p[k][l] = cut[2][l]; + if(count == 1) + trilist[i].owner = q; - trilist[nnew + 2].p[access_triangles[k][0]][l] = cut[0][l]; - trilist[nnew + 2].p[access_triangles[k][2]][l] = cut[2][l]; - trilist[nnew + 2].p[k][l] = cut[1][l]; - } + /* modify the three new tetras */ - if(count == 1) - { - trilist[nnew].owner = oldq; - trilist[nnew + 1].owner = oldq; - trilist[nnew + 2].owner = oldq; - } - else - { - trilist[nnew].owner = q; - trilist[nnew + 1].owner = q; - trilist[nnew + 2].owner = q; - } + for(l = 0; l < 3; l++) + { + trilist[nnew].p[k][l] = cut[0][l]; - nadd = 3; + trilist[nnew + 1].p[access_triangles[k][0]][l] = cut[0][l]; + trilist[nnew + 1].p[k][l] = cut[2][l]; - vvi = fabs(get_tri_volume(i, trilist)); - for(l = 0; l < nadd; l++) - vv[l] = fabs(get_tri_volume(nnew + l, trilist)); + trilist[nnew + 2].p[access_triangles[k][0]][l] = cut[0][l]; + trilist[nnew + 2].p[access_triangles[k][2]][l] = cut[2][l]; + trilist[nnew + 2].p[k][l] = cut[1][l]; + } - /* determine largest */ - ilargest = i; - vlargest = vvi; - for(l = 0; l < nadd; l++) - if(vv[l] > vlargest) + if(count == 1) { - vlargest = vv[l]; - ilargest = nnew + l; + trilist[nnew].owner = oldq; + trilist[nnew + 1].owner = oldq; + trilist[nnew + 2].owner = oldq; + } + else + { + trilist[nnew].owner = q; + trilist[nnew + 1].owner = q; + trilist[nnew + 2].owner = q; } - if(i != ilargest) - { - /* swap the largest to location i */ - triangle trisave = trilist[i]; - trilist[i] = trilist[ilargest]; - trilist[ilargest] = trisave; - vv[ilargest - nnew] = vvi; - } + nadd = 3; - for(l = 0; l < nadd; l++) - { - if(vv[l] < MIN_VOL_FAC * vol) + vvi = fabs(get_tri_volume(i, trilist)); + for(l = 0; l < nadd; l++) + vv[l] = fabs(get_tri_volume(nnew + l, trilist)); + + /* determine largest */ + ilargest = i; + vlargest = vvi; + for(l = 0; l < nadd; l++) + if(vv[l] > vlargest) { - vv[l] = vv[nadd - 1]; - trilist[nnew + l] = trilist[nnew + nadd - 1]; - l--; - nadd--; + vlargest = vv[l]; + ilargest = nnew + l; } - } - - nnew += nadd; - break; - - case 2: - /* we have two points on either side */ - - if(nnew + 5 > max_ntri) - terminate("nnew + 5 > max_ntri"); + if(i != ilargest) + { + /* swap the largest to location i */ + triangle trisave = trilist[i]; + trilist[i] = trilist[ilargest]; + trilist[ilargest] = trisave; - int kfirst, ksecond, jfirst, jsecond; + vv[ilargest - nnew] = vvi; + } - if(flag[2] == 1 && flag[3] == 1) - { - kfirst = 3; - ksecond = 2; - jfirst = 0; - jsecond = 1; - } - else if(flag[1] == 1 && flag[3] == 1) - { - kfirst = 3; - ksecond = 1; - jfirst = 2; - jsecond = 0; - } - else if(flag[0] == 1 && flag[3] == 1) - { - kfirst = 3; - ksecond = 0; - jfirst = 1; - jsecond = 2; - } - else if(flag[1] == 1 && flag[2] == 1) - { - kfirst = 1; - ksecond = 2; - jfirst = 3; - jsecond = 0; - } - else if(flag[0] == 1 && flag[2] == 1) - { - kfirst = 0; - ksecond = 2; - jfirst = 1; - jsecond = 3; - } - else if(flag[0] == 1 && flag[1] == 1) - { - kfirst = 0; - ksecond = 1; - jfirst = 3; - jsecond = 2; - } - else - terminate("can't be"); + for(l = 0; l < nadd; l++) + { + if(vv[l] < MIN_VOL_FAC * vol) + { + vv[l] = vv[nadd - 1]; + trilist[nnew + l] = trilist[nnew + nadd - 1]; + l--; + nadd--; + } + } - int next = 0; + nnew += nadd; + break; - for(l = 0; l < 3; l++) - p[next][l] = trilist[i].p[kfirst][l]; - next++; + case 2: + /* we have two points on either side */ - /* determine cuts with the corresponding two edges */ - { - double *b = trilist[i].p[kfirst]; - double *a = trilist[i].p[jfirst]; + if(nnew + 5 > max_ntri) + terminate("nnew + 5 > max_ntri"); - for(l = 0; l < 3; l++) - ed[l] = a[l] - b[l]; + int kfirst, ksecond, jfirst, jsecond; - double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); - double t; - - if(prod) - t = -sc[kfirst] / prod; + if(flag[2] == 1 && flag[3] == 1) + { + kfirst = 3; + ksecond = 2; + jfirst = 0; + jsecond = 1; + } + else if(flag[1] == 1 && flag[3] == 1) + { + kfirst = 3; + ksecond = 1; + jfirst = 2; + jsecond = 0; + } + else if(flag[0] == 1 && flag[3] == 1) + { + kfirst = 3; + ksecond = 0; + jfirst = 1; + jsecond = 2; + } + else if(flag[1] == 1 && flag[2] == 1) + { + kfirst = 1; + ksecond = 2; + jfirst = 3; + jsecond = 0; + } + else if(flag[0] == 1 && flag[2] == 1) + { + kfirst = 0; + ksecond = 2; + jfirst = 1; + jsecond = 3; + } + else if(flag[0] == 1 && flag[1] == 1) + { + kfirst = 0; + ksecond = 1; + jfirst = 3; + jsecond = 2; + } else - t = 0.5; + terminate("can't be"); - if(t < 0) - t = 0; - if(t > 1) - t = 1; + int next = 0; for(l = 0; l < 3; l++) - p[next][l] = b[l] + t * ed[l]; + p[next][l] = trilist[i].p[kfirst][l]; next++; - for(l = 0; l < 3; l++) - p[next][l] = a[l]; - next++; - } + /* determine cuts with the corresponding two edges */ + { + double *b = trilist[i].p[kfirst]; + double *a = trilist[i].p[jfirst]; - { - double *b = trilist[i].p[kfirst]; - double *a = trilist[i].p[jsecond]; + for(l = 0; l < 3; l++) + ed[l] = a[l] - b[l]; - for(l = 0; l < 3; l++) - ed[l] = a[l] - b[l]; + double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); + double t; - double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); - double t; + if(prod) + t = -sc[kfirst] / prod; + else + t = 0.5; - if(prod) - t = -sc[kfirst] / prod; - else - t = 0.5; + if(t < 0) + t = 0; + if(t > 1) + t = 1; - if(t < 0) - t = 0; - if(t > 1) - t = 1; + for(l = 0; l < 3; l++) + p[next][l] = b[l] + t * ed[l]; + next++; - for(l = 0; l < 3; l++) - p[next][l] = b[l] + t * ed[l]; - next++; + for(l = 0; l < 3; l++) + p[next][l] = a[l]; + next++; + } - for(l = 0; l < 3; l++) - p[next][l] = a[l]; - next++; - } + { + double *b = trilist[i].p[kfirst]; + double *a = trilist[i].p[jsecond]; - for(l = 0; l < 3; l++) - p[next][l] = trilist[i].p[ksecond][l]; - next++; + for(l = 0; l < 3; l++) + ed[l] = a[l] - b[l]; - { - double *b = trilist[i].p[ksecond]; - double *a = trilist[i].p[jfirst]; + double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); + double t; - for(l = 0; l < 3; l++) - ed[l] = a[l] - b[l]; + if(prod) + t = -sc[kfirst] / prod; + else + t = 0.5; - double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); - double t; + if(t < 0) + t = 0; + if(t > 1) + t = 1; - if(prod) - t = -sc[ksecond] / prod; - else - t = 0.5; + for(l = 0; l < 3; l++) + p[next][l] = b[l] + t * ed[l]; + next++; - if(t < 0) - t = 0; - if(t > 1) - t = 1; + for(l = 0; l < 3; l++) + p[next][l] = a[l]; + next++; + } for(l = 0; l < 3; l++) - p[next][l] = b[l] + t * ed[l]; + p[next][l] = trilist[i].p[ksecond][l]; next++; - } - - { - double *b = trilist[i].p[ksecond]; - double *a = trilist[i].p[jsecond]; - for(l = 0; l < 3; l++) - ed[l] = a[l] - b[l]; + { + double *b = trilist[i].p[ksecond]; + double *a = trilist[i].p[jfirst]; - double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); - double t; + for(l = 0; l < 3; l++) + ed[l] = a[l] - b[l]; - if(prod) - t = -sc[ksecond] / prod; - else - t = 0.5; + double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); + double t; - if(t < 0) - t = 0; - if(t > 1) - t = 1; + if(prod) + t = -sc[ksecond] / prod; + else + t = 0.5; - for(l = 0; l < 3; l++) - p[next][l] = b[l] + t * ed[l]; - next++; - } + if(t < 0) + t = 0; + if(t > 1) + t = 1; - oldq = trilist[i].owner; + for(l = 0; l < 3; l++) + p[next][l] = b[l] + t * ed[l]; + next++; + } - /* now let's initialize the new triangles */ - for(l = 0; l < 3; l++) { - /* first the ones that get to the new side */ - trilist[i].p[0][l] = p[0][l]; - trilist[i].p[1][l] = p[6][l]; - trilist[i].p[2][l] = p[5][l]; - trilist[i].p[3][l] = p[7][l]; - - trilist[nnew].p[0][l] = p[1][l]; - trilist[nnew].p[1][l] = p[3][l]; - trilist[nnew].p[2][l] = p[7][l]; - trilist[nnew].p[3][l] = p[0][l]; - - trilist[nnew + 1].p[0][l] = p[1][l]; - trilist[nnew + 1].p[1][l] = p[7][l]; - trilist[nnew + 1].p[2][l] = p[6][l]; - trilist[nnew + 1].p[3][l] = p[0][l]; - - /* now the ones that are on the old side */ - trilist[nnew + 2].p[0][l] = p[1][l]; - trilist[nnew + 2].p[1][l] = p[2][l]; - trilist[nnew + 2].p[2][l] = p[6][l]; - trilist[nnew + 2].p[3][l] = p[4][l]; - - trilist[nnew + 3].p[0][l] = p[3][l]; - trilist[nnew + 3].p[1][l] = p[1][l]; - trilist[nnew + 3].p[2][l] = p[6][l]; - trilist[nnew + 3].p[3][l] = p[4][l]; - - trilist[nnew + 4].p[0][l] = p[3][l]; - trilist[nnew + 4].p[1][l] = p[6][l]; - trilist[nnew + 4].p[2][l] = p[7][l]; - trilist[nnew + 4].p[3][l] = p[4][l]; - } + double *b = trilist[i].p[ksecond]; + double *a = trilist[i].p[jsecond]; + + for(l = 0; l < 3; l++) + ed[l] = a[l] - b[l]; - trilist[i].owner = q; - trilist[nnew].owner = q; - trilist[nnew + 1].owner = q; + double prod = (ed[0] * n[0] + ed[1] * n[1] + ed[2] * n[2]); + double t; - trilist[nnew + 2].owner = oldq; - trilist[nnew + 3].owner = oldq; - trilist[nnew + 4].owner = oldq; + if(prod) + t = -sc[ksecond] / prod; + else + t = 0.5; + + if(t < 0) + t = 0; + if(t > 1) + t = 1; - nadd = 5; + for(l = 0; l < 3; l++) + p[next][l] = b[l] + t * ed[l]; + next++; + } - vvi = fabs(get_tri_volume(i, trilist)); - for(l = 0; l < nadd; l++) - vv[l] = fabs(get_tri_volume(nnew + l, trilist)); + oldq = trilist[i].owner; - /* determine largest */ - ilargest = i; - vlargest = vvi; - for(l = 0; l < nadd; l++) - if(vv[l] > vlargest) + /* now let's initialize the new triangles */ + for(l = 0; l < 3; l++) { - vlargest = vv[l]; - ilargest = nnew + l; + /* first the ones that get to the new side */ + trilist[i].p[0][l] = p[0][l]; + trilist[i].p[1][l] = p[6][l]; + trilist[i].p[2][l] = p[5][l]; + trilist[i].p[3][l] = p[7][l]; + + trilist[nnew].p[0][l] = p[1][l]; + trilist[nnew].p[1][l] = p[3][l]; + trilist[nnew].p[2][l] = p[7][l]; + trilist[nnew].p[3][l] = p[0][l]; + + trilist[nnew + 1].p[0][l] = p[1][l]; + trilist[nnew + 1].p[1][l] = p[7][l]; + trilist[nnew + 1].p[2][l] = p[6][l]; + trilist[nnew + 1].p[3][l] = p[0][l]; + + /* now the ones that are on the old side */ + trilist[nnew + 2].p[0][l] = p[1][l]; + trilist[nnew + 2].p[1][l] = p[2][l]; + trilist[nnew + 2].p[2][l] = p[6][l]; + trilist[nnew + 2].p[3][l] = p[4][l]; + + trilist[nnew + 3].p[0][l] = p[3][l]; + trilist[nnew + 3].p[1][l] = p[1][l]; + trilist[nnew + 3].p[2][l] = p[6][l]; + trilist[nnew + 3].p[3][l] = p[4][l]; + + trilist[nnew + 4].p[0][l] = p[3][l]; + trilist[nnew + 4].p[1][l] = p[6][l]; + trilist[nnew + 4].p[2][l] = p[7][l]; + trilist[nnew + 4].p[3][l] = p[4][l]; } - if(i != ilargest) - { - /* swap the largest to location i */ - triangle trisave = trilist[i]; - trilist[i] = trilist[ilargest]; - trilist[ilargest] = trisave; - vv[ilargest - nnew] = vvi; - } + trilist[i].owner = q; + trilist[nnew].owner = q; + trilist[nnew + 1].owner = q; - for(l = 0; l < nadd; l++) - { - if(vv[l] < MIN_VOL_FAC * vol) + trilist[nnew + 2].owner = oldq; + trilist[nnew + 3].owner = oldq; + trilist[nnew + 4].owner = oldq; + + nadd = 5; + + vvi = fabs(get_tri_volume(i, trilist)); + for(l = 0; l < nadd; l++) + vv[l] = fabs(get_tri_volume(nnew + l, trilist)); + + /* determine largest */ + ilargest = i; + vlargest = vvi; + for(l = 0; l < nadd; l++) + if(vv[l] > vlargest) { - vv[l] = vv[nadd - 1]; - trilist[nnew + l] = trilist[nnew + nadd - 1]; - l--; - nadd--; + vlargest = vv[l]; + ilargest = nnew + l; } - } + if(i != ilargest) + { + /* swap the largest to location i */ + triangle trisave = trilist[i]; + trilist[i] = trilist[ilargest]; + trilist[ilargest] = trisave; - nnew += nadd; - break; + vv[ilargest - nnew] = vvi; + } + + for(l = 0; l < nadd; l++) + { + if(vv[l] < MIN_VOL_FAC * vol) + { + vv[l] = vv[nadd - 1]; + trilist[nnew + l] = trilist[nnew + nadd - 1]; + l--; + nadd--; + } + } + + nnew += nadd; + break; } } return nnew; } - /*! \brief Processes edge for volume calculation. * * Calculates the contribution of edge to volumes of neighboring @@ -1361,10 +1340,10 @@ int derefine_add_point_and_split_tri(int q, triangle * trilist, int ntri, int ma * * \return void */ -void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) +void derefine_refine_process_edge(tessellation *T, double *vol, int tt, int nr) { - tetra *DT = T->DT; - point *DP = T->DP; + tetra *DT = T->DT; + point *DP = T->DP; tetra_center *DTC = T->DTC; int i, j, k, l, m, ii, jj, kk, ll, nn, count, nr_next, p1, p2; @@ -1397,12 +1376,12 @@ void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) count = 0; - prev = t; + prev = t; prevc = &DTC[tt]; do { - nn = prev->t[l]; - next = &DT[nn]; + nn = prev->t[l]; + next = &DT[nn]; nextc = &DTC[nn]; if(prev != t && next != t) @@ -1450,12 +1429,12 @@ void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) break; } - prev = next; + prev = next; prevc = nextc; - i = ii; - l = ll; - j = jj; - k = kk; + i = ii; + l = ll; + j = jj; + k = kk; count++; @@ -1471,7 +1450,7 @@ void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) hhy = 0.5 * (DP[p1].y - DP[p2].y); hhz = 0.5 * (DP[p1].z - DP[p2].z); - h = sqrt(hhx * hhx + hhy * hhy + hhz * hhz); + h = sqrt(hhx * hhx + hhy * hhy + hhz * hhz); dvol = (1.0 / 3) * area * h; if(p1 >= 0 && p1 < DeRefMesh.Ndp) @@ -1481,7 +1460,6 @@ void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) vol[p2] += dvol; } - /*! \brief Insert a point into mesh. * * Finds the tetrahedron that contains this point, splits the tetrahedron. @@ -1495,7 +1473,7 @@ void derefine_refine_process_edge(tessellation * T, double *vol, int tt, int nr) * * \return index to tetra that (currently) contains the point pp. */ -int insert_point(tessellation * T, int pp, int ttstart) +int insert_point(tessellation *T, int pp, int ttstart) { int tt0, tt1, tt2, tt3, tt4, tetra_with_p, tt; int to_check[STACKSIZE_TETRA], freestack[STACKSIZE_TETRA]; @@ -1508,7 +1486,7 @@ int insert_point(tessellation * T, int pp, int ttstart) tetra_with_p = tt0; - if(flag == 1) /* that's the normal split of a tetrahedron into 4 */ + if(flag == 1) /* that's the normal split of a tetrahedron into 4 */ { if(n_faces_to_check >= STACKSIZE_TETRA - 4) terminate("stacksize exceeded"); @@ -1536,7 +1514,7 @@ int insert_point(tessellation * T, int pp, int ttstart) #ifdef VERBOSE printf("Task=%d: increase memory allocation, MaxNdt=%d Indi.AllocFacNdt=%g\n", ThisTask, T->MaxNdt, T->Indi.AllocFacNdt); #endif /* #ifdef VERBOSE */ - T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); + T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); T->DTC = myrealloc_movable(T->DTC, T->MaxNdt * sizeof(tetra_center)); T->DTF = myrealloc_movable(T->DTF, T->MaxNdt * sizeof(char)); @@ -1556,11 +1534,11 @@ int insert_point(tessellation * T, int pp, int ttstart) to_check[n_faces_to_check++] = tt1; to_check[n_faces_to_check++] = tt2; to_check[n_faces_to_check++] = tt3; - char *DTF = T->DTF; - DTF[tt0] = 0; - DTF[tt1] = 0; - DTF[tt2] = 0; - DTF[tt3] = 0; + char *DTF = T->DTF; + DTF[tt0] = 0; + DTF[tt1] = 0; + DTF[tt2] = 0; + DTF[tt3] = 0; } if(flag == 2) @@ -1593,7 +1571,7 @@ int insert_point(tessellation * T, int pp, int ttstart) #ifdef VERBOSE printf("Task=%d: increase memory allocation, MaxNdt=%d Indi.AllocFacNdt=%g\n", ThisTask, T->MaxNdt, T->Indi.AllocFacNdt); #endif /* #ifdef VERBOSE */ - T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); + T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); T->DTC = myrealloc_movable(T->DTC, T->MaxNdt * sizeof(tetra_center)); T->DTF = myrealloc_movable(T->DTF, T->MaxNdt * sizeof(char)); @@ -1610,18 +1588,18 @@ int insert_point(tessellation * T, int pp, int ttstart) to_check[n_faces_to_check++] = tt3; to_check[n_faces_to_check++] = tt4; - char *DTF = T->DTF; - DTF[tt0] = 0; + char *DTF = T->DTF; + DTF[tt0] = 0; DTF[T->DT[tt0].t[edgeface_nr]] = 0; - DTF[tt1] = 0; - DTF[tt2] = 0; - DTF[tt3] = 0; - DTF[tt4] = 0; + DTF[tt1] = 0; + DTF[tt2] = 0; + DTF[tt3] = 0; + DTF[tt4] = 0; make_a_face_split(T, tt0, edgeface_nr, pp, tt1, tt2, tt3, tt4); } - if(flag == 3) /* here we need to split an edge */ + if(flag == 3) /* here we need to split an edge */ { int i, j, k, l, ii, jj, kk, ll, m, count; int prev, next; @@ -1632,17 +1610,17 @@ int insert_point(tessellation * T, int pp, int ttstart) k = edge_opposite[edgeface_nr]; l = edge_nexttetra[edgeface_nr]; - count = 0; + count = 0; n_faces_to_check = 0; prev = tt0; do { to_check[n_faces_to_check++] = prev; - T->DTF[prev] = 0; + T->DTF[prev] = 0; tetra *DT = T->DT; - next = DT[prev].t[l]; + next = DT[prev].t[l]; for(m = 0, ll = ii = jj = -1; m < 4; m++) { @@ -1660,10 +1638,10 @@ int insert_point(tessellation * T, int pp, int ttstart) kk = 6 - (ll + ii + jj); prev = next; - i = ii; - l = ll; - j = jj; - k = kk; + i = ii; + l = ll; + j = jj; + k = kk; count++; @@ -1687,9 +1665,10 @@ int insert_point(tessellation * T, int pp, int ttstart) T->Indi.AllocFacNdt *= ALLOC_INCREASE_FACTOR; T->MaxNdt = T->Indi.AllocFacNdt; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNdt=%d Indi.AllocFacNdt=%g\n", ThisTask, T->MaxNdt, T->Indi.AllocFacNdt); + printf("Task=%d: increase memory allocation, MaxNdt=%d Indi.AllocFacNdt=%g\n", ThisTask, T->MaxNdt, + T->Indi.AllocFacNdt); #endif /* #ifdef VERBOSE */ - T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); + T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); T->DTC = myrealloc_movable(T->DTC, T->MaxNdt * sizeof(tetra_center)); T->DTF = myrealloc_movable(T->DTF, T->MaxNdt * sizeof(char)); @@ -1699,7 +1678,7 @@ int insert_point(tessellation * T, int pp, int ttstart) } to_check[n_faces_to_check++] = ttlist[i]; - T->DTF[ttlist[i]] = 0; + T->DTF[ttlist[i]] = 0; } make_an_edge_split(T, tt0, edgeface_nr, count, pp, ttlist); @@ -1715,21 +1694,21 @@ int insert_point(tessellation * T, int pp, int ttstart) if(iter > 200000) terminate("too many iterations"); - tt = to_check[--n_faces_to_check]; /* this is the current tetra to look at. - The facet in question lies opposite to q */ - if(T->DT[tt].t[0] < 0) /* deleted? */ + tt = to_check[--n_faces_to_check]; /* this is the current tetra to look at. + The facet in question lies opposite to q */ + if(T->DT[tt].t[0] < 0) /* deleted? */ continue; for(tip_index = 0; tip_index < 4; tip_index++) if(T->DT[tt].p[tip_index] == pp) break; - if(tip_index < 4) /* otherwise the facet has been removed in a 3-2 flip */ + if(tip_index < 4) /* otherwise the facet has been removed in a 3-2 flip */ { tetra *DT = T->DT; point *DP = T->DP; - int qq = DT[tt].t[tip_index]; /* tetrahedron that's opposite of ours and shares the facet */ - int ppp = DT[qq].p[DT[tt].s[tip_index]]; /* point that's opposite of the facet in the other tetrahedron */ + int qq = DT[tt].t[tip_index]; /* tetrahedron that's opposite of ours and shares the facet */ + int ppp = DT[qq].p[DT[tt].s[tip_index]]; /* point that's opposite of the facet in the other tetrahedron */ int ret, ret_exact; @@ -1745,13 +1724,13 @@ int insert_point(tessellation * T, int pp, int ttstart) CountInSphereTestsExact++; } - if(ret_exact > 0) /* facet is illegal, because point lies inside */ + if(ret_exact > 0) /* facet is illegal, because point lies inside */ { /* let's see whether the point lies in the triangle, or on a side, or opposite of one convex edge */ non_convex = convex_edge_test(T, tt, tip_index, &convex_edge); - if(non_convex == 0) /* we can make a 2-3 flip */ + if(non_convex == 0) /* we can make a 2-3 flip */ { int ww; @@ -1765,9 +1744,10 @@ int insert_point(tessellation * T, int pp, int ttstart) T->Indi.AllocFacNdt *= ALLOC_INCREASE_FACTOR; T->MaxNdt = T->Indi.AllocFacNdt; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNdt=%d Indi.AllocFacNdt=%g\n", ThisTask, T->MaxNdt, T->Indi.AllocFacNdt); + printf("Task=%d: increase memory allocation, MaxNdt=%d Indi.AllocFacNdt=%g\n", ThisTask, T->MaxNdt, + T->Indi.AllocFacNdt); #endif /* #ifdef VERBOSE */ - T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); + T->DT = myrealloc_movable(T->DT, T->MaxNdt * sizeof(tetra)); T->DTC = myrealloc_movable(T->DTC, T->MaxNdt * sizeof(tetra_center)); T->DTF = myrealloc_movable(T->DTF, T->MaxNdt * sizeof(char)); @@ -1783,11 +1763,11 @@ int insert_point(tessellation * T, int pp, int ttstart) to_check[n_faces_to_check++] = tt; to_check[n_faces_to_check++] = qq; to_check[n_faces_to_check++] = ww; - T->DTF[tt] = 0; - T->DTF[qq] = 0; - T->DTF[ww] = 0; + T->DTF[tt] = 0; + T->DTF[qq] = 0; + T->DTF[ww] = 0; } - else if(non_convex == 1) /* we might be able to make a 3-2 flip, or we deal with a convex edge on the outer hull */ + else if(non_convex == 1) /* we might be able to make a 3-2 flip, or we deal with a convex edge on the outer hull */ { /* test whether the reflex edge is surrounded by exactly three tetrahedra */ @@ -1805,8 +1785,8 @@ int insert_point(tessellation * T, int pp, int ttstart) terminate("not found"); } - if(DT[tt].t[i] == DT[qq].t[j]) /* this means there is exactly one tetrahedron between them, i.e. we have found the - third partner for the flip */ + if(DT[tt].t[i] == DT[qq].t[j]) /* this means there is exactly one tetrahedron between them, i.e. we have found the + third partner for the flip */ { int ww; @@ -1827,26 +1807,28 @@ int insert_point(tessellation * T, int pp, int ttstart) to_check[n_faces_to_check++] = tt; to_check[n_faces_to_check++] = qq; - T->DTF[tt] = 0; - T->DTF[qq] = 0; + T->DTF[tt] = 0; + T->DTF[qq] = 0; } else { if(DT[DT[tt].t[i]].p[DT[tt].s[i]] == DPinfinity && DT[DT[qq].t[j]].p[DT[qq].s[j]] == DPinfinity) { printf("convex edge between points=%d %d on outer hull found\n", - (int) (DT[tt].p[access_triangles[tip_index][convex_edge]]), (int) (DT[tt].p[access_triangles[tip_index][convex_edge < 2 ? convex_edge + 1 : 0]])); + (int)(DT[tt].p[access_triangles[tip_index][convex_edge]]), + (int)(DT[tt].p[access_triangles[tip_index][convex_edge < 2 ? convex_edge + 1 : 0]])); - terminate("inconsistency"); /* this should not occur since we have embedded the points into a convex big triangle */ + terminate("inconsistency"); /* this should not occur since we have embedded the points into a convex big + triangle */ } } } - else if(non_convex == 2) /* we might be able to make a 4-4 flip */ + else if(non_convex == 2) /* we might be able to make a 4-4 flip */ { i = convex_edge + 2; if(i >= 3) i -= 3; - i = access_triangles[tip_index][i]; /* this is the point opposite of edge (but not tip) */ + i = access_triangles[tip_index][i]; /* this is the point opposite of edge (but not tip) */ tetra *DT = T->DT; char *DTF = T->DTF; @@ -1863,14 +1845,13 @@ int insert_point(tessellation * T, int pp, int ttstart) to_check[n_faces_to_check++] = qq; to_check[n_faces_to_check++] = DT[tt].t[i]; to_check[n_faces_to_check++] = DT[qq].t[j]; - DTF[tt] = 0; - DTF[qq] = 0; - DTF[DT[tt].t[i]] = 0; - DTF[DT[qq].t[j]] = 0; + DTF[tt] = 0; + DTF[qq] = 0; + DTF[DT[tt].t[i]] = 0; + DTF[DT[qq].t[j]] = 0; make_a_4_to_4_flip(T, tt, tip_index, convex_edge); } - } } else @@ -1881,7 +1862,6 @@ int insert_point(tessellation * T, int pp, int ttstart) return tetra_with_p; } - /*! \brief Tests edges and detects if a flip is needed. * * \param[in] T Pointer to tessellation. @@ -1891,11 +1871,11 @@ int insert_point(tessellation * T, int pp, int ttstart) * * \return (-1,0,1,2), depending on which flip is necessary. */ -int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr) +int convex_edge_test(tessellation *T, int tt, int tip, int *edgenr) { tetra *DT = T->DT; point *DP = T->DP; - tetra *t = &DT[tt]; + tetra *t = &DT[tt]; int i0, i1, i2, i3; int vol, flag0, flag1, flag2; int count_zeros = 0; @@ -1929,7 +1909,7 @@ int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr) double qx = p4->xx - p0->xx; double qy = p4->yy - p0->yy; double qz = p4->zz - p0->zz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double ax, ay, az, bx, by, bz, cx, cy, cz, qx, qy, qz; double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -1957,7 +1937,7 @@ int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr) qz = pB_xyz[2] - pA_xyz[2]; #endif /* #ifndef OPTIMIZE_MEMORY_USAGE */ - double mv_data[] = { ax, bx, cx, qx, ay, by, cy, qy, az, bz, cz, qz }; + double mv_data[] = {ax, bx, cx, qx, ay, by, cy, qy, az, bz, cz, qz}; double x[3]; int status; @@ -2007,14 +1987,13 @@ int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr) } if(u < -INSIDE_EPS && v < -INSIDE_EPS && (1 - (u + v)) > INSIDE_EPS) - return -1; /* two reflex edges */ + return -1; /* two reflex edges */ if(u < -INSIDE_EPS && v > INSIDE_EPS && (1 - (u + v)) < -INSIDE_EPS) - return -1; /* two reflex edges */ + return -1; /* two reflex edges */ if(u > INSIDE_EPS && v < -INSIDE_EPS && (1 - (u + v)) < -INSIDE_EPS) - return -1; /* two reflex edges */ - + return -1; /* two reflex edges */ } CountConvexEdgeTestExact++; @@ -2027,10 +2006,10 @@ int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr) { printf("flat or negatively tetrahedron found (vol=%d)\n", vol); { - printf("p0=%d %g %g %g\n", (int) (p0 - DP), p0->x, p0->y, p0->z); - printf("p1=%d %g %g %g\n", (int) (p1 - DP), p1->x, p1->y, p1->z); - printf("p2=%d %g %g %g\n", (int) (p2 - DP), p2->x, p2->y, p2->z); - printf("p3=%d %g %g %g\n", (int) (p3 - DP), p3->x, p3->y, p3->z); + printf("p0=%d %g %g %g\n", (int)(p0 - DP), p0->x, p0->y, p0->z); + printf("p1=%d %g %g %g\n", (int)(p1 - DP), p1->x, p1->y, p1->z); + printf("p2=%d %g %g %g\n", (int)(p2 - DP), p2->x, p2->y, p2->z); + printf("p3=%d %g %g %g\n", (int)(p3 - DP), p3->x, p3->y, p3->z); dump_points(T); terminate("inconsistent tetrahedron"); } @@ -2070,7 +2049,6 @@ int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr) return 1; } - if(flag0 >= 0 && flag1 >= 0 && flag2 == 0) { // printf("4-4 flip around edge 0 may be possible\n"); @@ -2101,7 +2079,6 @@ int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr) return -1; } - /*! \brief Performs face split. * * \param[in, out] T Pointer to tessellation. @@ -2115,13 +2092,13 @@ int convex_edge_test(tessellation * T, int tt, int tip, int *edgenr) * * \return void */ -void make_a_face_split(tessellation * T, int tt0, int face_nr, int pp, int tt1, int tt2, int qq1, int qq2) +void make_a_face_split(tessellation *T, int tt0, int face_nr, int pp, int tt1, int tt2, int qq1, int qq2) { tetra *DT = T->DT; tetra *t0 = &DT[tt0]; tetra *t1 = &DT[tt1]; tetra *t2 = &DT[tt2]; - int qq0 = t0->t[face_nr]; + int qq0 = t0->t[face_nr]; tetra *q0 = &DT[qq0]; tetra *q1 = &DT[qq1]; tetra *q2 = &DT[qq2]; @@ -2140,28 +2117,28 @@ void make_a_face_split(tessellation * T, int tt0, int face_nr, int pp, int tt1, i3 = face_nr; j3 = t0->s[face_nr]; - switch (i3) + switch(i3) { - case 3: - i0 = 0; - i1 = 1; - i2 = 2; - break; - case 2: - i0 = 0; - i1 = 3; - i2 = 1; - break; - case 1: - i0 = 0; - i1 = 2; - i2 = 3; - break; - case 0: - i0 = 1; - i1 = 3; - i2 = 2; - break; + case 3: + i0 = 0; + i1 = 1; + i2 = 2; + break; + case 2: + i0 = 0; + i1 = 3; + i2 = 1; + break; + case 1: + i0 = 0; + i1 = 2; + i2 = 3; + break; + case 0: + i0 = 1; + i1 = 3; + i2 = 2; + break; } for(m = 0; m < 4; m++) @@ -2185,7 +2162,6 @@ void make_a_face_split(tessellation * T, int tt0, int face_nr, int pp, int tt1, q1->p[j0] = pp; q2->p[j2] = pp; - t0->t[i0] = tt1; t1->t[i2] = tt0; t0->s[i0] = i2; @@ -2240,7 +2216,6 @@ void make_a_face_split(tessellation * T, int tt0, int face_nr, int pp, int tt1, DT[q2->t[j2]].t[q2->s[j2]] = qq2; } - /*! \brief Performs edge split. * * \param[in, out] T Pointer to tessellation @@ -2250,7 +2225,7 @@ void make_a_face_split(tessellation * T, int tt0, int face_nr, int pp, int tt1, * \param[in] pp Index to point. * \param[in] ttlist List of indices in DT. */ -void make_an_edge_split(tessellation * T, int tt0, int edge_nr, int count, int pp, int *ttlist) +void make_an_edge_split(tessellation *T, int tt0, int edge_nr, int count, int pp, int *ttlist) { tetra *DT = T->DT; tetra *t0 = &DT[tt0]; @@ -2262,12 +2237,12 @@ void make_an_edge_split(tessellation * T, int tt0, int edge_nr, int count, int p Count_EdgeSplits++; CountFlips++; - tlist = mymalloc("tlist", count * sizeof(tetra *)); + tlist = mymalloc("tlist", count * sizeof(tetra *)); t_orig_list = mymalloc("t_orig_list", count * sizeof(tetra *)); - i_list = mymalloc("i_list", sizeof(int) * count); - j_list = mymalloc("j_list", sizeof(int) * count); - k_list = mymalloc("k_list", sizeof(int) * count); - l_list = mymalloc("l_list", sizeof(int) * count); + i_list = mymalloc("i_list", sizeof(int) * count); + j_list = mymalloc("j_list", sizeof(int) * count); + k_list = mymalloc("k_list", sizeof(int) * count); + l_list = mymalloc("l_list", sizeof(int) * count); for(i = 0; i < count; i++) tlist[i] = &DT[ttlist[i]]; @@ -2277,15 +2252,15 @@ void make_an_edge_split(tessellation * T, int tt0, int edge_nr, int count, int p k = edge_opposite[edge_nr]; l = edge_nexttetra[edge_nr]; - nr = 0; + nr = 0; prev = t0; do { t_orig_list[nr] = prev; - i_list[nr] = i; - j_list[nr] = j; - k_list[nr] = k; - l_list[nr] = l; + i_list[nr] = i; + j_list[nr] = j; + k_list[nr] = k; + l_list[nr] = l; next = &DT[prev->t[l]]; @@ -2305,10 +2280,10 @@ void make_an_edge_split(tessellation * T, int tt0, int edge_nr, int count, int p kk = 6 - (ll + ii + jj); prev = next; - i = ii; - l = ll; - j = jj; - k = kk; + i = ii; + l = ll; + j = jj; + k = kk; nr++; } @@ -2319,13 +2294,13 @@ void make_an_edge_split(tessellation * T, int tt0, int edge_nr, int count, int p *tlist[nr] = *t_orig_list[nr]; t_orig_list[nr]->p[j_list[nr]] = pp; - tlist[nr]->p[i_list[nr]] = pp; + tlist[nr]->p[i_list[nr]] = pp; t_orig_list[nr]->t[i_list[nr]] = tlist[nr] - DT; - tlist[nr]->t[j_list[nr]] = t_orig_list[nr] - DT; + tlist[nr]->t[j_list[nr]] = t_orig_list[nr] - DT; t_orig_list[nr]->s[i_list[nr]] = j_list[nr]; - tlist[nr]->s[j_list[nr]] = i_list[nr]; + tlist[nr]->s[j_list[nr]] = i_list[nr]; DT[tlist[nr]->t[i_list[nr]]].t[tlist[nr]->s[i_list[nr]]] = tlist[nr] - DT; @@ -2353,7 +2328,6 @@ void make_an_edge_split(tessellation * T, int tt0, int edge_nr, int count, int p myfree(tlist); } - /*! \brief Make a 4 to 4 flip. * * See Springel (2010) for discussion on flips. @@ -2366,7 +2340,7 @@ void make_an_edge_split(tessellation * T, int tt0, int edge_nr, int count, int p * * \return void */ -void make_a_4_to_4_flip(tessellation * T, int tt, int tip_index, int edge_nr) +void make_a_4_to_4_flip(tessellation *T, int tt, int tip_index, int edge_nr) { tetra *DT = T->DT; // printf("4-to-4 flip\n"); @@ -2382,13 +2356,13 @@ void make_a_4_to_4_flip(tessellation * T, int tt, int tip_index, int edge_nr) CountFlips++; uu = 0; - u = NULL; + u = NULL; for(j = 0; j < 4; j++) { - t_top[j] = NULL; + t_top[j] = NULL; t_bottom[j] = NULL; - s_top[j] = -1; + s_top[j] = -1; s_bottom[j] = -1; } @@ -2409,9 +2383,9 @@ void make_a_4_to_4_flip(tessellation * T, int tt, int tip_index, int edge_nr) s_top[1] = t->s[i1]; ww = t->t[i2]; - w = &DT[ww]; + w = &DT[ww]; qq = t->t[tip_index]; - q = &DT[qq]; + q = &DT[qq]; for(j = 0; j < 4; j++) { @@ -2430,7 +2404,7 @@ void make_a_4_to_4_flip(tessellation * T, int tt, int tip_index, int edge_nr) if(w->p[j] == t->p[tip_index]) { uu = w->t[j]; - u = &DT[uu]; + u = &DT[uu]; } } @@ -2526,48 +2500,47 @@ void make_a_4_to_4_flip(tessellation * T, int tt, int tip_index, int edge_nr) w->s[0] = 1; t->s[1] = 0; - t->t[2] = t_top[0] - DT; - t->s[2] = s_top[0]; + t->t[2] = t_top[0] - DT; + t->s[2] = s_top[0]; DT[t->t[2]].t[t->s[2]] = tt; DT[t->t[2]].s[t->s[2]] = 2; - t->t[3] = t_bottom[0] - DT; - t->s[3] = s_bottom[0]; + t->t[3] = t_bottom[0] - DT; + t->s[3] = s_bottom[0]; DT[t->t[3]].t[t->s[3]] = tt; DT[t->t[3]].s[t->s[3]] = 3; - q->t[2] = t_top[1] - DT; - q->s[2] = s_top[1]; + q->t[2] = t_top[1] - DT; + q->s[2] = s_top[1]; DT[q->t[2]].t[q->s[2]] = qq; DT[q->t[2]].s[q->s[2]] = 2; - q->t[3] = t_bottom[1] - DT; - q->s[3] = s_bottom[1]; + q->t[3] = t_bottom[1] - DT; + q->s[3] = s_bottom[1]; DT[q->t[3]].t[q->s[3]] = qq; DT[q->t[3]].s[q->s[3]] = 3; - u->t[2] = t_top[2] - DT; - u->s[2] = s_top[2]; + u->t[2] = t_top[2] - DT; + u->s[2] = s_top[2]; DT[u->t[2]].t[u->s[2]] = uu; DT[u->t[2]].s[u->s[2]] = 2; - u->t[3] = t_bottom[2] - DT; - u->s[3] = s_bottom[2]; + u->t[3] = t_bottom[2] - DT; + u->s[3] = s_bottom[2]; DT[u->t[3]].t[u->s[3]] = uu; DT[u->t[3]].s[u->s[3]] = 3; - w->t[2] = t_top[3] - DT; - w->s[2] = s_top[3]; + w->t[2] = t_top[3] - DT; + w->s[2] = s_top[3]; DT[w->t[2]].t[w->s[2]] = ww; DT[w->t[2]].s[w->s[2]] = 2; - w->t[3] = t_bottom[3] - DT; - w->s[3] = s_bottom[3]; + w->t[3] = t_bottom[3] - DT; + w->s[3] = s_bottom[3]; DT[w->t[3]].t[w->s[3]] = ww; DT[w->t[3]].s[w->s[3]] = 3; } - /*! \brief Make a 1 to 4 flip. * * See Springel (2010) for discussion on flips. @@ -2581,7 +2554,7 @@ void make_a_4_to_4_flip(tessellation * T, int tt, int tip_index, int edge_nr) * * \return void */ -void make_a_1_to_4_flip(tessellation * T, int pp, int tt0, int tt1, int tt2, int tt3) +void make_a_1_to_4_flip(tessellation *T, int pp, int tt0, int tt1, int tt2, int tt3) { tetra *DT = T->DT; @@ -2638,7 +2611,6 @@ void make_a_1_to_4_flip(tessellation * T, int pp, int tt0, int tt1, int tt2, int DT[t3->t[3]].t[t3->s[3]] = tt3; } - /*! \brief Make a 3 to 2 flip. * * See Springel (2010) for discussion on flips. @@ -2654,7 +2626,7 @@ void make_a_1_to_4_flip(tessellation * T, int pp, int tt0, int tt1, int tt2, int * * \return void */ -void make_a_3_to_2_flip(tessellation * T, int tt0, int tt1, int tt2, int tip, int edge, int bottom) +void make_a_3_to_2_flip(tessellation *T, int tt0, int tt1, int tt2, int tip, int edge, int bottom) { tetra *DT = T->DT; tetra *t0 = &DT[tt0]; @@ -2714,40 +2686,39 @@ void make_a_3_to_2_flip(tessellation * T, int tt0, int tt1, int tt2, int tip, in t0->s[2] = 1; t1->s[1] = 2; - t0->t[0] = tbak.t[j]; - t0->s[0] = tbak.s[j]; + t0->t[0] = tbak.t[j]; + t0->s[0] = tbak.s[j]; DT[t0->t[0]].s[t0->s[0]] = 0; DT[t0->t[0]].t[t0->s[0]] = tt0; - t0->t[3] = qbak.t[jj]; - t0->s[3] = qbak.s[jj]; + t0->t[3] = qbak.t[jj]; + t0->s[3] = qbak.s[jj]; DT[t0->t[3]].s[t0->s[3]] = 3; DT[t0->t[3]].t[t0->s[3]] = tt0; - t0->t[1] = wbak.t[jjj]; - t0->s[1] = wbak.s[jjj]; + t0->t[1] = wbak.t[jjj]; + t0->s[1] = wbak.s[jjj]; DT[t0->t[1]].s[t0->s[1]] = 1; DT[t0->t[1]].t[t0->s[1]] = tt0; - t1->t[0] = tbak.t[i]; - t1->s[0] = tbak.s[i]; + t1->t[0] = tbak.t[i]; + t1->s[0] = tbak.s[i]; DT[t1->t[0]].s[t1->s[0]] = 0; DT[t1->t[0]].t[t1->s[0]] = tt1; - t1->t[3] = qbak.t[ii]; - t1->s[3] = qbak.s[ii]; + t1->t[3] = qbak.t[ii]; + t1->s[3] = qbak.s[ii]; DT[t1->t[3]].s[t1->s[3]] = 3; DT[t1->t[3]].t[t1->s[3]] = tt1; - t1->t[2] = wbak.t[iii]; - t1->s[2] = wbak.s[iii]; + t1->t[2] = wbak.t[iii]; + t1->s[2] = wbak.s[iii]; DT[t1->t[2]].s[t1->s[2]] = 2; DT[t1->t[2]].t[t1->s[2]] = tt1; CountFlips++; } - /*! \brief Make a 2 to 3 flip * * See Springel (2010) for discussion on flips. @@ -2763,7 +2734,7 @@ void make_a_3_to_2_flip(tessellation * T, int tt0, int tt1, int tt2, int tip, in * * \return void */ -void make_a_2_to_3_flip(tessellation * T, int tt0, int tip, int tt1, int bottom, int qq, int tt2) +void make_a_2_to_3_flip(tessellation *T, int tt0, int tip, int tt1, int bottom, int qq, int tt2) { tetra *DT = T->DT; tetra *t0 = &DT[tt0]; @@ -2775,7 +2746,7 @@ void make_a_2_to_3_flip(tessellation * T, int tt0, int tip, int tt1, int bottom, Count_2_to_3_Flips++; tbak = *t0; - qbak = *t1; /* to save info */ + qbak = *t1; /* to save info */ *t1 = *t0; *t2 = *t0; @@ -2815,12 +2786,11 @@ void make_a_2_to_3_flip(tessellation * T, int tt0, int tip, int tt1, int bottom, else k = 2; - t0->t[tip] = qbak.t[access_triangles[bottom][k]]; - t0->s[tip] = qbak.s[access_triangles[bottom][k]]; + t0->t[tip] = qbak.t[access_triangles[bottom][k]]; + t0->s[tip] = qbak.s[access_triangles[bottom][k]]; DT[t0->t[tip]].t[t0->s[tip]] = tt0; DT[t0->t[tip]].s[t0->s[tip]] = tip; - if(qbak.p[access_triangles[bottom][0]] == tbak.p[access_triangles[tip][1]]) k = 0; else if(qbak.p[access_triangles[bottom][1]] == tbak.p[access_triangles[tip][1]]) @@ -2828,8 +2798,8 @@ void make_a_2_to_3_flip(tessellation * T, int tt0, int tip, int tt1, int bottom, else k = 2; - t1->t[tip] = qbak.t[access_triangles[bottom][k]]; - t1->s[tip] = qbak.s[access_triangles[bottom][k]]; + t1->t[tip] = qbak.t[access_triangles[bottom][k]]; + t1->s[tip] = qbak.s[access_triangles[bottom][k]]; DT[t1->t[tip]].t[t1->s[tip]] = tt1; DT[t1->t[tip]].s[t1->s[tip]] = tip; @@ -2840,16 +2810,14 @@ void make_a_2_to_3_flip(tessellation * T, int tt0, int tip, int tt1, int bottom, else k = 2; - t2->t[tip] = qbak.t[access_triangles[bottom][k]]; - t2->s[tip] = qbak.s[access_triangles[bottom][k]]; + t2->t[tip] = qbak.t[access_triangles[bottom][k]]; + t2->s[tip] = qbak.s[access_triangles[bottom][k]]; DT[t2->t[tip]].t[t2->s[tip]] = tt2; DT[t2->t[tip]].s[t2->s[tip]] = tip; } - static int ErrorFlag = 0; - /*! \brief Gets tetrahedron. * * Returns the index of the tetrahedron containing the point DP[pp]. @@ -2865,7 +2833,7 @@ static int ErrorFlag = 0; * * \return Index of tetrahedron. */ -int get_tetra(tessellation * T, point * p, int *moves, int ttstart, int *flag, int *edgeface_nr) +int get_tetra(tessellation *T, point *p, int *moves, int ttstart, int *flag, int *edgeface_nr) { int ret, count_moves = 0; int tt, next_tetra; @@ -2890,12 +2858,11 @@ int get_tetra(tessellation * T, point * p, int *moves, int ttstart, int *flag, i } *moves = count_moves; - *flag = ret; + *flag = ret; return tt; } - /*! \brief Is point in tetrahedron? * * Tests whether point DP[pp] lies in the tetrahedron DT[tt]. The @@ -2916,11 +2883,11 @@ int get_tetra(tessellation * T, point * p, int *moves, int ttstart, int *flag, i * \return Point in thetrahedron? * */ -int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetra) +int InTetra(tessellation *T, int tt, point *p, int *edgeface_nr, int *nexttetra) { tetra *DT = T->DT; point *DP = T->DP; - tetra *t = &DT[tt]; + tetra *t = &DT[tt]; point *p0 = &DP[t->p[0]]; point *p1 = &DP[t->p[1]]; @@ -2929,15 +2896,17 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr // test if we are in an "infinity tetra", which are the ones that // bound the tesselated volume. Arepo terminates if this happens, - // but for Sunrise this is a valid occurence so we'll return -1 to + // but for Sunrise this is a valid occurence so we'll return -1 to // indicate the point is outside the volume. XXX Actually it // shouldn't do this anymore because we now do box tests instead if(isInfinity(p0) || isInfinity(p1) || isInfinity(p2) || isInfinity(p3)) { #ifndef LONGIDS - printf("task=%d: we are in a tetraeder with an infinity point. tetra=%d, coordinates of point=(%g|%g|%g) ID=%d\n", ThisTask, tt, p->x, p->y, p->z, p->ID); -#else /* #ifndef LONGIDS */ - printf("task=%d: we are in a tetraeder with an infinity point. tetra=%d, coordinates of point=(%g|%g|%g) ID=%llu\n", ThisTask, tt, p->x, p->y, p->z, p->ID); + printf("task=%d: we are in a tetraeder with an infinity point. tetra=%d, coordinates of point=(%g|%g|%g) ID=%d\n", ThisTask, tt, + p->x, p->y, p->z, p->ID); +#else /* #ifndef LONGIDS */ + printf("task=%d: we are in a tetraeder with an infinity point. tetra=%d, coordinates of point=(%g|%g|%g) ID=%llu\n", ThisTask, + tt, p->x, p->y, p->z, p->ID); #endif /* #ifndef LONGIDS #else */ terminate("invalid tetrahedron"); } @@ -2960,7 +2929,7 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr double qx = p->xx - p0->xx; double qy = p->yy - p0->yy; double qz = p->zz - p0->zz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double ax, ay, az, bx, by, bz, cx, cy, cz, qx, qy, qz; double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -2988,7 +2957,7 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr qz = pB_xyz[2] - pA_xyz[2]; #endif /* #ifndef OPTIMIZE_MEMORY_USAGE #else */ - double mv_data[] = { ax, bx, cx, qx, ay, by, cy, qy, az, bz, cz, qz }; + double mv_data[] = {ax, bx, cx, qx, ay, by, cy, qy, az, bz, cz, qz}; double x[3]; int ivol, flag3, flag2, flag1, flag0; @@ -3012,13 +2981,13 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr if(ErrorFlag) { - ivol = Orient3d_Exact(p0, p1, p2, p3); + ivol = Orient3d_Exact(p0, p1, p2, p3); flag3 = Orient3d_Exact(p0, p1, p2, p); flag2 = Orient3d_Exact(p0, p3, p1, p); flag1 = Orient3d_Exact(p0, p2, p3, p); flag0 = Orient3d_Exact(p1, p3, p2, p); - printf("\n\nTetra=%d\n", (int) (t - DT)); + printf("\n\nTetra=%d\n", (int)(t - DT)); printf("ivol=%d flag0=%d %d %d %d\n", ivol, flag0, flag1, flag2, flag3); printf("xx = %g %g %g 1-sum=%g\n", x[0], x[1], x[2], 1 - (x[0] + x[1] + x[2])); printf("a= %g %g %g\n", ax, ay, az); @@ -3031,12 +3000,11 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr if(status >= 0) { - if(x[0] > INSIDE_EPS && x[1] > INSIDE_EPS && x[2] > INSIDE_EPS && (1 - (x[0] + x[1] + x[2])) > INSIDE_EPS) { /* looks like we are safely inside the tetrahedron */ - return 1; /* our point is really nicely inside the tetrahedron */ + return 1; /* our point is really nicely inside the tetrahedron */ } if(x[0] < -INSIDE_EPS || x[1] < -INSIDE_EPS || x[2] < -INSIDE_EPS || (1 - (x[0] + x[1] + x[2])) < -INSIDE_EPS) @@ -3121,7 +3089,7 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr if(ErrorFlag) { - printf("doing exact test for tetra=%d\n", (int) (t - DT)); + printf("doing exact test for tetra=%d\n", (int)(t - DT)); } Count_InTetraExact++; @@ -3151,15 +3119,19 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr if(count_zeros > 2) { - printf("task=%d flags=%d %d %d %d (axb)*c = %g\n", ThisTask, flag0, flag1, flag2, flag3, (ay * bz - az * by) * cx + (az * bx - ax * bz) * cy + (ax * by - ay * bx) * cz); + printf("task=%d flags=%d %d %d %d (axb)*c = %g\n", ThisTask, flag0, flag1, flag2, flag3, + (ay * bz - az * by) * cx + (az * bx - ax * bz) * cy + (ax * by - ay * bx) * cz); - printf - ("task=%d pp0=%ld pp1=%ld pp2=%ld pp3=%ld p=%ld IDs=(%llu %llu %llu %llu %llu) pos_0=(%g|%g|%g) pos_1=(%g|%g|%g) pos_2=(%g|%g|%g) pos_3=(%g|%g|%g) pos=(%g|%g|%g)\n", - ThisTask, p0 - DP, p1 - DP, p2 - DP, p3 - DP, p - DP, (long long) p0->ID, (long long) p1->ID, (long long) p2->ID, (long long) p3->ID, - (long long) p->ID, p0->x, p0->y, p0->z, p1->x, p1->y, p1->z, p2->x, p2->y, p2->z, p3->x, p3->y, p3->z, p->x, p->y, p->z); + printf( + "task=%d pp0=%ld pp1=%ld pp2=%ld pp3=%ld p=%ld IDs=(%llu %llu %llu %llu %llu) pos_0=(%g|%g|%g) pos_1=(%g|%g|%g) " + "pos_2=(%g|%g|%g) pos_3=(%g|%g|%g) pos=(%g|%g|%g)\n", + ThisTask, p0 - DP, p1 - DP, p2 - DP, p3 - DP, p - DP, (long long)p0->ID, (long long)p1->ID, (long long)p2->ID, + (long long)p3->ID, (long long)p->ID, p0->x, p0->y, p0->z, p1->x, p1->y, p1->z, p2->x, p2->y, p2->z, p3->x, p3->y, p3->z, + p->x, p->y, p->z); #if defined(REFLECTIVE_X) || defined(REFLECTIVE_Y) || defined(REFLECTIVE_Z) - printf("task=%d imageflags=(%d %d %d %d %d)\n", ThisTask, p0->image_flags, p1->image_flags, p2->image_flags, p3->image_flags, p->image_flags); + printf("task=%d imageflags=(%d %d %d %d %d)\n", ThisTask, p0->image_flags, p1->image_flags, p2->image_flags, p3->image_flags, + p->image_flags); #endif /* #if defined(REFLECTIVE_X) || defined(REFLECTIVE_Y) || defined(REFLECTIVE_Z) */ terminate("strange zero count"); } @@ -3174,7 +3146,7 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr return 1; } - if(count_zeros == 1) /* we lie on a face */ + if(count_zeros == 1) /* we lie on a face */ { if(flag0 == 0) { @@ -3201,7 +3173,7 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr } } - if(count_zeros == 2) /* we lie on an edge */ + if(count_zeros == 2) /* we lie on an edge */ { if(flag0 == 0 && flag1 == 0) { @@ -3304,7 +3276,6 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr if(get_random_number() < 0.5) ind = 2; } - } if(flag3 < 0) @@ -3322,14 +3293,13 @@ int InTetra(tessellation * T, int tt, point * p, int *edgeface_nr, int *nexttetr return 0; } - /*! \brief Computes the circum-circle of all tetrahedra in mesh. * * \param[in, out] T Pointer to tessellation. * * \return void */ -void compute_circumcircles(tessellation * T) +void compute_circumcircles(tessellation *T) { tetra *DT = T->DT; char *DTF = T->DTF; @@ -3341,7 +3311,7 @@ void compute_circumcircles(tessellation * T) continue; DTF[i] |= 1; - if(DT[i].t[0] < 0) /* deleted ? */ + if(DT[i].t[0] < 0) /* deleted ? */ continue; if(DT[i].p[0] == DPinfinity) @@ -3357,7 +3327,6 @@ void compute_circumcircles(tessellation * T) } } - /*! \brief Determinant calculation with arbitrary precision arithmetics. * * Auxiliary function for exact circum-circle calculation. @@ -3426,7 +3395,6 @@ void calc_mpz_determinant(mpz_t det, mpz_t ax, mpz_t ay, mpz_t az, mpz_t bx, mpz mpz_clear(bz_cy); } - /*! \brief Arbitrary precision calculation of circum-circle. * * \param[in, out] T Pointer to tessellation. @@ -3437,11 +3405,11 @@ void calc_mpz_determinant(mpz_t det, mpz_t ax, mpz_t ay, mpz_t az, mpz_t bx, mpz * * \return void */ -void get_circumcircle_exact(tessellation * T, int tt, double *x, double *y, double *z) +void get_circumcircle_exact(tessellation *T, int tt, double *x, double *y, double *z) { tetra *DT = T->DT; point *DP = T->DP; - tetra *t = &DT[tt]; + tetra *t = &DT[tt]; point *p0 = &DP[t->p[0]]; point *p1 = &DP[t->p[1]]; @@ -3500,7 +3468,7 @@ void get_circumcircle_exact(tessellation * T, int tt, double *x, double *y, doub MY_mpz_sub_ui(cy, tmp, p0->iy); MY_mpz_set_si(tmp, p3->iz); MY_mpz_sub_ui(cz, tmp, p0->iz); -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ IntegerMapType pA_ixyz[3], pB_ixyz[3]; double pA_xyz[3], pB_xyz[3]; @@ -3581,7 +3549,7 @@ void get_circumcircle_exact(tessellation * T, int tt, double *x, double *y, doub MY_mpz_set_si(tmp, p0->iz); mpz_add(CC, qz, tmp); -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ MY_mpz_set_si(tmp, pA_ixyz[0]); mpz_add(AA, qx, tmp); @@ -3636,7 +3604,6 @@ void get_circumcircle_exact(tessellation * T, int tt, double *x, double *y, doub mpz_clear(cz); } - /*! \brief Computes the circum-circle of tetrahedron tt. * * \param[in, out] T Pointer to tessellation. @@ -3644,15 +3611,15 @@ void get_circumcircle_exact(tessellation * T, int tt, double *x, double *y, doub * * \return void */ -void update_circumcircle(tessellation * T, int tt) +void update_circumcircle(tessellation *T, int tt) { - tetra *DT = T->DT; + tetra *DT = T->DT; tetra_center *DTC = T->DTC; - point *DP = T->DP; - tetra *t = &DT[tt]; - tetra_center *tc = &DTC[tt]; + point *DP = T->DP; + tetra *t = &DT[tt]; + tetra_center *tc = &DTC[tt]; - if(t->t[0] < 0) /* deleted ? */ + if(t->t[0] < 0) /* deleted ? */ return; point *p0 = &DP[t->p[0]]; @@ -3675,7 +3642,7 @@ void update_circumcircle(tessellation * T, int tt) double cx = p3->xx - p0->xx; double cy = p3->yy - p0->yy; double cz = p3->zz - p0->zz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double ax, ay, az, bx, by, bz, cx, cy, cz; double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -3702,7 +3669,7 @@ void update_circumcircle(tessellation * T, int tt) double bb = 0.5 * (bx * bx + by * by + bz * bz); double cc = 0.5 * (cx * cx + cy * cy + cz * cz); - double mv_data[] = { ax, ay, az, aa, bx, by, bz, bb, cx, cy, cz, cc }; + double mv_data[] = {ax, ay, az, aa, bx, by, bz, bb, cx, cy, cz, cc}; double x[3]; int status = solve_linear_equations(mv_data, x); @@ -3736,7 +3703,7 @@ void update_circumcircle(tessellation * T, int tt) x[0] += p0->xx; x[1] += p0->yy; x[2] += p0->zz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ x[0] += pA_xyz[0]; x[1] += pA_xyz[1]; x[2] += pA_xyz[2]; @@ -3748,7 +3715,6 @@ void update_circumcircle(tessellation * T, int tt) } } - /*! \brief Returns the orientation of the tetrahedron. * * \param[in] p0 Point spanning the tetrahedron. @@ -3758,7 +3724,7 @@ void update_circumcircle(tessellation * T, int tt) * * \return -1: negative orientation; +1 positive orientation. */ -int test_tetra_orientation(point * p0, point * p1, point * p2, point * p3) +int test_tetra_orientation(point *p0, point *p1, point *p2, point *p3) { double nx, ny, nz; @@ -3773,7 +3739,7 @@ int test_tetra_orientation(point * p0, point * p1, point * p2, point * p3) return +1; else return -1; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ IntegerMapType p0_ixyz[3], p1_ixyz[3], p2_ixyz[3], p3_ixyz[3]; double p0_xyz[3], p1_xyz[3], p2_xyz[3], p3_xyz[3]; @@ -3795,7 +3761,6 @@ int test_tetra_orientation(point * p0, point * p1, point * p2, point * p3) #endif /* #ifndef OPTIMIZE_MEMORY_USAGE #else */ } - /*! \brief Calculate the volume of a tetrahedron. * * \param[in] p0 Point spanning the tetrahedron. @@ -3805,7 +3770,7 @@ int test_tetra_orientation(point * p0, point * p1, point * p2, point * p3) * * \return Volume of the tetrahedron. */ -double calculate_tetra_volume(point * p0, point * p1, point * p2, point * p3) +double calculate_tetra_volume(point *p0, point *p1, point *p2, point *p3) { double nx, ny, nz; @@ -3819,7 +3784,6 @@ double calculate_tetra_volume(point * p0, point * p1, point * p2, point * p3) return nx * (p3->x - p0->x) + ny * (p3->y - p0->y) + nz * (p3->z - p0->z); } - /*! \brief Add row in matrix equation. * * Auxiliary function for solve_linear_equations. @@ -3839,7 +3803,6 @@ void add_row(double *m, int r1, int r2, double fac) m[r1 * 4 + i] += fac * m[r2 * 4 + i]; } - /*! \brief Solve system of linear equations for 3d Voronoi construction. * * \param[in, out] m Matrix. @@ -3878,8 +3841,8 @@ int solve_linear_equations(double *m, double *res) { /* swap iy/iz */ itmp = iy; - iy = iz; - iz = itmp; + iy = iz; + iz = itmp; } if(fabs(m[iy * 4 + 1]) < GAUSS_EPS) @@ -3907,7 +3870,6 @@ int solve_linear_equations(double *m, double *res) return 0; } - /*! \brief Converts coordinates of point p to integer values. * * \param[in, out] p Point. @@ -3915,7 +3877,7 @@ int solve_linear_equations(double *m, double *res) * \return void */ #ifndef OPTIMIZE_MEMORY_USAGE -void set_integers_for_pointer(point * p) +void set_integers_for_pointer(point *p) { p->xx = (p->x - CentralOffsetX) * ConversionFac + 1.0; p->yy = (p->y - CentralOffsetY) * ConversionFac + 1.0; @@ -3937,7 +3899,6 @@ void set_integers_for_pointer(point * p) } #endif /* #ifndef OPTIMIZE_MEMORY_USAGE */ - /*! \brief Checks if point is within a sphere using arbitrary precision * operations. * @@ -3949,7 +3910,7 @@ void set_integers_for_pointer(point * p) * * \return (-1,1); -1 in sphere, 1 outside. */ -int InSphere_Exact(point * p0, point * p1, point * p2, point * p3, point * p) +int InSphere_Exact(point *p0, point *p1, point *p2, point *p3, point *p) { IntegerMapType ax, bx, cx, dx; IntegerMapType ay, by, cy, dy; @@ -3974,7 +3935,7 @@ int InSphere_Exact(point * p0, point * p1, point * p2, point * p3, point * p) dx = p3->ix - p->ix; dy = p3->iy - p->iy; dz = p3->iz - p->iz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -4165,7 +4126,6 @@ int InSphere_Exact(point * p0, point * p1, point * p2, point * p3, point * p) return sign; } - /*! \brief Checks if point is within a sphere. * * \param p0 Point 1 of tetrahedron. @@ -4176,7 +4136,7 @@ int InSphere_Exact(point * p0, point * p1, point * p2, point * p3, point * p) * * \return (-1,0,1); -1: in sphere, 0: on surfrace, 1: outside. */ -int InSphere_Quick(point * p0, point * p1, point * p2, point * p3, point * p) +int InSphere_Quick(point *p0, point *p1, point *p2, point *p3, point *p) { double ax, bx, cx, dx; double ay, by, cy, dy; @@ -4205,7 +4165,7 @@ int InSphere_Quick(point * p0, point * p1, point * p2, point * p3, point * p) dx = p3->xx - p->xx; dy = p3->yy - p->yy; dz = p3->zz - p->zz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -4259,7 +4219,6 @@ int InSphere_Quick(point * p0, point * p1, point * p2, point * p3, point * p) return 0; } - /*! \brief Checks if point is within a sphere with some error margin. * * \param p0 Point 1 of tetrahedron. @@ -4271,7 +4230,7 @@ int InSphere_Quick(point * p0, point * p1, point * p2, point * p3, point * p) * \return (-1,0,1); -1: in sphere, 0: on surfrace (within error margin), * +1: outside. */ -int InSphere_Errorbound(point * p0, point * p1, point * p2, point * p3, point * p) +int InSphere_Errorbound(point *p0, point *p1, point *p2, point *p3, point *p) { double ax, bx, cx, dx; double ay, by, cy, dy; @@ -4300,7 +4259,7 @@ int InSphere_Errorbound(point * p0, point * p1, point * p2, point * p3, point * dx = p3->xx - p->xx; dy = p3->yy - p->yy; dz = p3->zz - p->zz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -4390,7 +4349,6 @@ int InSphere_Errorbound(point * p0, point * p1, point * p2, point * p3, point * return 0; } - /*! \brief Returns orientation of tetrahedron using arbitrary precision * floating point operations. * @@ -4402,7 +4360,7 @@ int InSphere_Errorbound(point * p0, point * p1, point * p2, point * p3, point * * \return (-1,0,1) -1 if negatively oriented, 0 if degenerate and 1 if * positively oriented. */ -int Orient3d_Exact(point * p0, point * p1, point * p2, point * p3) +int Orient3d_Exact(point *p0, point *p1, point *p2, point *p3) { IntegerMapType ax, bx, cx; IntegerMapType ay, by, cy; @@ -4420,7 +4378,7 @@ int Orient3d_Exact(point * p0, point * p1, point * p2, point * p3) cx = p2->ix - p3->ix; cy = p2->iy - p3->iy; cz = p2->iz - p3->iz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -4527,7 +4485,6 @@ int Orient3d_Exact(point * p0, point * p1, point * p2, point * p3) return sign; } - /*! \brief Returns orientation of tetrahedron. * * \param[in] p0 First point of tetrahedron. @@ -4538,7 +4495,7 @@ int Orient3d_Exact(point * p0, point * p1, point * p2, point * p3) * \return (-1,0,1) -1 if negatively oriented, 0 if degenerate and 1 if * positively oriented. */ -int Orient3d_Quick(point * p0, point * p1, point * p2, point * p3) +int Orient3d_Quick(point *p0, point *p1, point *p2, point *p3) { double ax, bx, cx; double ay, by, cy; @@ -4556,7 +4513,7 @@ int Orient3d_Quick(point * p0, point * p1, point * p2, point * p3) cx = p2->xx - p3->xx; cy = p2->yy - p3->yy; cz = p2->zz - p3->zz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -4588,7 +4545,6 @@ int Orient3d_Quick(point * p0, point * p1, point * p2, point * p3) return 0; } - /* \brief Returns orientation of tetrahedron. * * \param[in] p0 First point of tetrahedron. @@ -4599,7 +4555,7 @@ int Orient3d_Quick(point * p0, point * p1, point * p2, point * p3) * \return (-1,0,1) the orientation of the 4 points as +/-1. If either of the * points is an infinity point, return 0. */ -int Orient3d(point * p0, point * p1, point * p2, point * p3) +int Orient3d(point *p0, point *p1, point *p2, point *p3) { if(isInfinity(p0) || isInfinity(p1) || isInfinity(p2) || isInfinity(p3)) return 0; @@ -4616,7 +4572,7 @@ int Orient3d(point * p0, point * p1, point * p2, point * p3) double cx = p2->xx - p3->xx; double cy = p2->yy - p3->yy; double cz = p2->zz - p3->zz; -#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifndef OPTIMIZE_MEMORY_USAGE */ double ax, ay, az, bx, by, bz, cx, cy, cz; double pA_xyz[3], pB_xyz[3]; IntegerMapType pA_ixyz[3], pB_ixyz[3]; @@ -4648,7 +4604,8 @@ int Orient3d(point * p0, point * p1, point * p2, point * p3) double x = ax * (bzcy - bycz) + bx * (czay - cyaz) + cx * (azby - aybz); - double sizelimit = fabs(ax) * (fabs(bzcy) + fabs(bycz)) + fabs(bx) * (fabs(czay) + fabs(cyaz)) + fabs(cx) * (fabs(azby) + fabs(aybz)); + double sizelimit = + fabs(ax) * (fabs(bzcy) + fabs(bycz)) + fabs(bx) * (fabs(czay) + fabs(cyaz)) + fabs(cx) * (fabs(azby) + fabs(aybz)); double errbound = 1.0e-14 * sizelimit; @@ -4660,29 +4617,26 @@ int Orient3d(point * p0, point * p1, point * p2, point * p3) return Orient3d_Exact(p0, p1, p2, p3); } - /*! \brief Data structure for face sort */ -struct data_face_sort /* for sorting faces */ +struct data_face_sort /* for sorting faces */ { - MyIDType ID; /* ID of corresponding cell */ - float normal[3]; /* non-normalized normal vector */ - int start; /* start index into vertex list */ - int len; /* number of vertices */ + MyIDType ID; /* ID of corresponding cell */ + float normal[3]; /* non-normalized normal vector */ + int start; /* start index into vertex list */ + int len; /* number of vertices */ }; - -static int *VertexEntries; /* face index list */ -static float *VertexCoordinates; /* Voronoi vertex coordinates (circumsphere centers of delaunay tetras) */ -static float *FaceNormals; /* normal vectors */ -static int Nvertices; /* number of Voronoi vertices */ -static int Nnormals; /* number of normals */ -static int Nentries; /* number of entries in Voronoi face vertex list (including IDs and face vertex count) */ -static int Nsort; /* number of ID sorted faces */ -static int MaxEntries, MaxFaces; /* for allocation */ +static int *VertexEntries; /* face index list */ +static float *VertexCoordinates; /* Voronoi vertex coordinates (circumsphere centers of delaunay tetras) */ +static float *FaceNormals; /* normal vectors */ +static int Nvertices; /* number of Voronoi vertices */ +static int Nnormals; /* number of normals */ +static int Nentries; /* number of entries in Voronoi face vertex list (including IDs and face vertex count) */ +static int Nsort; /* number of ID sorted faces */ +static int MaxEntries, MaxFaces; /* for allocation */ static struct data_face_sort *FaceSort; - /*! \brief Face sorting kernel * * Compares ID of data_face_sort types. @@ -4694,23 +4648,22 @@ static struct data_face_sort *FaceSort; */ int compare_face_sort(const void *a, const void *b) { - if(((struct data_face_sort *) a)->ID < ((struct data_face_sort *) b)->ID) + if(((struct data_face_sort *)a)->ID < ((struct data_face_sort *)b)->ID) return -1; - if(((struct data_face_sort *) a)->ID > ((struct data_face_sort *) b)->ID) + if(((struct data_face_sort *)a)->ID > ((struct data_face_sort *)b)->ID) return +1; return 0; } - /*! \brief Gathers faces in list. * * \param[in] T Pointer to tessellation. * * \return void */ -void get_voronoi_face_vertex_indices(tessellation * T) +void get_voronoi_face_vertex_indices(tessellation *T) { int i, j, k, l, m, ii, jj, kk, ll, tetra_nr, edge_nr, next_tetra_nr, count, dp_1, dp_2; tetra *prev, *next; @@ -4721,11 +4674,11 @@ void get_voronoi_face_vertex_indices(tessellation * T) /* loop over tetras */ for(tetra_nr = 0; tetra_nr < Mesh.Ndt; tetra_nr++) { - if(Mesh.DT[tetra_nr].t[0] < 0) /* skip deleted tetras */ + if(Mesh.DT[tetra_nr].t[0] < 0) /* skip deleted tetras */ continue; /* edge flagging */ - bit = 1; + bit = 1; edge_nr = 0; /* loop over edges */ @@ -4762,7 +4715,8 @@ void get_voronoi_face_vertex_indices(tessellation * T) } /* skip ghost points (both local and foreign) */ - if((DP[dp_1].task != ThisTask || DP[dp_1].index < 0 || DP[dp_1].index >= NumGas) && (DP[dp_2].task != ThisTask || DP[dp_2].index < 0 || DP[dp_2].index >= NumGas)) + if((DP[dp_1].task != ThisTask || DP[dp_1].index < 0 || DP[dp_1].index >= NumGas) && + (DP[dp_2].task != ThisTask || DP[dp_2].index < 0 || DP[dp_2].index >= NumGas)) { bit <<= 1; edge_nr++; @@ -4771,13 +4725,13 @@ void get_voronoi_face_vertex_indices(tessellation * T) /* count number of face vertices */ count = 0; - prev = t; + prev = t; do { count++; next_tetra_nr = prev->t[l]; - next = &DT[next_tetra_nr]; + next = &DT[next_tetra_nr]; for(m = 0, ll = ii = jj = -1; m < 4; m++) { @@ -4793,10 +4747,10 @@ void get_voronoi_face_vertex_indices(tessellation * T) terminate("inconsistency"); kk = 6 - (ll + ii + jj); - i = ii; - l = ll; - j = jj; - k = kk; + i = ii; + l = ll; + j = jj; + k = kk; prev = next; } @@ -4813,21 +4767,21 @@ void get_voronoi_face_vertex_indices(tessellation * T) FaceNormals[Nnormals++] = (DP[dp_1].z - DP[dp_2].z); /* fill vertex entry list, first ID, count then tetra numbers */ - VertexEntries[Nentries++] = (int) DP[dp_1].ID; - VertexEntries[Nentries++] = (int) DP[dp_2].ID; - VertexEntries[Nentries++] = (int) count; - VertexEntries[Nentries++] = (int) tetra_nr; + VertexEntries[Nentries++] = (int)DP[dp_1].ID; + VertexEntries[Nentries++] = (int)DP[dp_2].ID; + VertexEntries[Nentries++] = (int)count; + VertexEntries[Nentries++] = (int)tetra_nr; /* get tetra indices of face vertices */ count = 0; - prev = t; + prev = t; do { count++; next_tetra_nr = prev->t[l]; - next = &DT[next_tetra_nr]; + next = &DT[next_tetra_nr]; - VertexEntries[Nentries++] = (int) next_tetra_nr; + VertexEntries[Nentries++] = (int)next_tetra_nr; for(m = 0, ll = ii = jj = -1; m < 4; m++) { @@ -4876,7 +4830,6 @@ void get_voronoi_face_vertex_indices(tessellation * T) } } - /*! \brief Set Vertex coordinates in the respective array. * * Copys the coordinates from the DTC array of the tessellation to a @@ -4886,7 +4839,7 @@ void get_voronoi_face_vertex_indices(tessellation * T) * * \return void */ -void get_voronoi_face_vertex_coordinates(tessellation * T) +void get_voronoi_face_vertex_coordinates(tessellation *T) { int tetra_nr = 0; @@ -4899,7 +4852,6 @@ void get_voronoi_face_vertex_coordinates(tessellation * T) } } - /*! \brief Function calls qsort for sorting faces by ID. * * Uses compare_face_sort as comparison function. Requires array FaceSort. @@ -4912,17 +4864,17 @@ void sort_faces_by_ID(void) do { - FaceSort[j].ID = VertexEntries[i + 0]; - FaceSort[j].start = i + 3; - FaceSort[j].len = VertexEntries[i + 2]; + FaceSort[j].ID = VertexEntries[i + 0]; + FaceSort[j].start = i + 3; + FaceSort[j].len = VertexEntries[i + 2]; FaceSort[j].normal[0] = FaceNormals[k++]; FaceSort[j].normal[1] = FaceNormals[k++]; FaceSort[j].normal[2] = FaceNormals[k++]; j++; - FaceSort[j].ID = VertexEntries[i + 1]; - FaceSort[j].start = i + 3; - FaceSort[j].len = VertexEntries[i + 2]; + FaceSort[j].ID = VertexEntries[i + 1]; + FaceSort[j].start = i + 3; + FaceSort[j].len = VertexEntries[i + 2]; FaceSort[j].normal[0] = FaceNormals[k++]; FaceSort[j].normal[1] = FaceNormals[k++]; FaceSort[j].normal[2] = FaceNormals[k++]; @@ -4932,7 +4884,6 @@ void sort_faces_by_ID(void) if(j > MaxFaces) terminate("j > MaxFaces"); - } while(i < Nentries); @@ -4942,7 +4893,6 @@ void sort_faces_by_ID(void) qsort(FaceSort, Nsort, sizeof(struct data_face_sort), compare_face_sort); } - /*! \brief Outputs Voronoi vertex indices to file. * * Outputs the Voronoi vertex indices from task writeTask to lastTask in file @@ -4956,7 +4906,7 @@ void sort_faces_by_ID(void) * * \return void */ -void write_voronoi_face_vertex_indices(tessellation * T, char *fname1, char *fname2, int writeTask, int lastTask) +void write_voronoi_face_vertex_indices(tessellation *T, char *fname1, char *fname2, int writeTask, int lastTask) { FILE *fd1, *fd2; MPI_Status status; @@ -4966,12 +4916,12 @@ void write_voronoi_face_vertex_indices(tessellation * T, char *fname1, char *fna struct data_face_sort *tmp_sort; VertexEntries = mymalloc("VertexEntries", MaxEntries * sizeof(int)); - FaceNormals = mymalloc("VertexEntries", MaxFaces * sizeof(int)); + FaceNormals = mymalloc("VertexEntries", MaxFaces * sizeof(int)); /* get faces */ get_voronoi_face_vertex_indices(T); - FaceSort = (struct data_face_sort *) mymalloc("face_sort", sizeof(struct data_face_sort) * MaxFaces); + FaceSort = (struct data_face_sort *)mymalloc("face_sort", sizeof(struct data_face_sort) * MaxFaces); /* sort faces */ sort_faces_by_ID(); @@ -4982,15 +4932,15 @@ void write_voronoi_face_vertex_indices(tessellation * T, char *fname1, char *fna /* I/O */ Nvertices_list = mymalloc("Nvertices_list", sizeof(int) * NTask); - Nentries_list = mymalloc("Nentries_list", sizeof(int) * NTask); - Nsort_list = mymalloc("Nsort_list", sizeof(int) * NTask); - Nnormals_list = mymalloc("Nnormals_list", sizeof(int) * NTask); + Nentries_list = mymalloc("Nentries_list", sizeof(int) * NTask); + Nsort_list = mymalloc("Nsort_list", sizeof(int) * NTask); + Nnormals_list = mymalloc("Nnormals_list", sizeof(int) * NTask); if(ThisTask == writeTask) { nVertices_tot = Nvertices; - nEntries_tot = Nentries; - nNormals_tot = Nnormals; + nEntries_tot = Nentries; + nNormals_tot = Nnormals; for(task = writeTask + 1; task <= lastTask; task++) { MPI_Recv(&Nvertices_list[task], 1, MPI_INT, task, TAG_LOCALN, MPI_COMM_WORLD, &status); @@ -5020,8 +4970,8 @@ void write_voronoi_face_vertex_indices(tessellation * T, char *fname1, char *fna for(task = writeTask + 1; task <= lastTask; task++) { - tmp_sort = (struct data_face_sort *) mymalloc("tmp_sort", sizeof(struct data_face_sort) * Nsort_list[task]); - tmp = mymalloc("tmp", sizeof(int) * Nentries_list[task]); + tmp_sort = (struct data_face_sort *)mymalloc("tmp_sort", sizeof(struct data_face_sort) * Nsort_list[task]); + tmp = mymalloc("tmp", sizeof(int) * Nentries_list[task]); MPI_Recv(tmp, Nentries_list[task], MPI_INT, task, TAG_N + 1, MPI_COMM_WORLD, &status); MPI_Recv(tmp_sort, Nsort_list[task] * sizeof(struct data_face_sort), MPI_BYTE, task, TAG_N + 2, MPI_COMM_WORLD, &status); @@ -5061,7 +5011,6 @@ void write_voronoi_face_vertex_indices(tessellation * T, char *fname1, char *fna myfree(VertexEntries); } - /*! \brief Outputs Voronoi vertex coordinates to file. * * Outputs the Voronoi vertex coordinates from task write Task to lastTask in @@ -5074,7 +5023,7 @@ void write_voronoi_face_vertex_indices(tessellation * T, char *fname1, char *fna * * \return void */ -void write_voronoi_face_vertex_coordinates(tessellation * T, char *fname, int writeTask, int lastTask) +void write_voronoi_face_vertex_coordinates(tessellation *T, char *fname, int writeTask, int lastTask) { FILE *fd; MPI_Status status; @@ -5121,7 +5070,6 @@ void write_voronoi_face_vertex_coordinates(tessellation * T, char *fname, int wr myfree(VertexCoordinates); } - /*! \brief Outputs Voronoi mesh to file. * * Outputs the Voronoi mesh data from task write Task to lastTask in file @@ -5134,12 +5082,12 @@ void write_voronoi_face_vertex_coordinates(tessellation * T, char *fname, int wr * * \return void */ -void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTask) +void write_voronoi_mesh(tessellation *T, char *fname, int writeTask, int lastTask) { char buf1[255], buf2[255]; MaxEntries = 1000 * NumGas; - MaxFaces = 100 * NumGas; + MaxFaces = 100 * NumGas; /* coordinates */ Nvertices = 0; @@ -5160,5 +5108,4 @@ void write_voronoi_mesh(tessellation * T, char *fname, int writeTask, int lastTa myfree(Edge_visited); } - #endif /* #if !defined(TWODIMS) && !defined(ONEDIMS) */ diff --git a/src/mesh/voronoi/voronoi_check.c b/src/mesh/voronoi/voronoi_check.c index 0974a168e363de374ff6411f4e3f24fbb462552d..42c6f06b1f7a314b6e05e6ced6dacbcd7147f585 100644 --- a/src/mesh/voronoi/voronoi_check.c +++ b/src/mesh/voronoi/voronoi_check.c @@ -29,31 +29,28 @@ * void check_triangles(tessellation * T, int npoints) * void check_orientations(tessellation * T) * void check_links(tessellation * T) - * - * + * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 22.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - -#if !defined(TWODIMS) && !defined(ONEDIMS) /* three-dimensional test code */ +#if !defined(TWODIMS) && !defined(ONEDIMS) /* three-dimensional test code */ int points_compare(const void *a, const void *b); - /*! \brief Checks minimum distance between Delaunay points making sure it is * nonzero. * @@ -61,7 +58,7 @@ int points_compare(const void *a, const void *b); * * \return void */ -void check_for_min_distance(tessellation * T) +void check_for_min_distance(tessellation *T) { point *DP = T->DP; int i, j; @@ -74,28 +71,29 @@ void check_for_min_distance(tessellation * T) for(j = i + 1; j < T->Ndp; j++) { - r2 = (DP[i].x - DP[j].x) * (DP[i].x - DP[j].x) + (DP[i].y - DP[j].y) * (DP[i].y - DP[j].y) + (DP[i].z - DP[j].z) * (DP[i].z - DP[j].z); + r2 = (DP[i].x - DP[j].x) * (DP[i].x - DP[j].x) + (DP[i].y - DP[j].y) * (DP[i].y - DP[j].y) + + (DP[i].z - DP[j].z) * (DP[i].z - DP[j].z); if(r2 < r2min) r2min = r2; if(r2min == 0) { sprintf(msg, "i=%d j=%d equal. DP[i].index=%d DP[j].index=%d\n", i, j, DP[i].index, DP[j].index); - terminate(msg)} + terminate(msg) + } } } printf("min distance=%g\n", sqrt(r2min)); } - /*! \brief Checks if tessellation links are correct. * * \param[in] T Pointer to tessellation. * * \return void */ -void check_links(tessellation * T) +void check_links(tessellation *T) { tetra *DT = T->DT; int i, j, s, c, flag = 0; @@ -104,14 +102,14 @@ void check_links(tessellation * T) for(i = 0; i < T->Ndt; i++) { - if(DT[i].t[0] < 0) /* deleted ? */ + if(DT[i].t[0] < 0) /* deleted ? */ continue; for(j = 0; j < 4; j++) { if(DT[DT[i].t[j]].t[DT[i].s[j]] != i) { - printf("LINK for tetra=%d j=%d DT[i].s[j]=%d incorrect %d\n", i, j, DT[i].s[j], (int) (DT[DT[i].t[j]].t[DT[i].s[j]])); + printf("LINK for tetra=%d j=%d DT[i].s[j]=%d incorrect %d\n", i, j, DT[i].s[j], (int)(DT[DT[i].t[j]].t[DT[i].s[j]])); } } @@ -147,14 +145,13 @@ void check_links(tessellation * T) printf("links ok\n"); } - /*! \brief Checks if orientations of tetrahedra are positive. * * \param[in] T Pointer to tessellation. * * \return void */ -void check_orientations(tessellation * T) +void check_orientations(tessellation *T) { tetra *DT = T->DT; point *DP = T->DP; @@ -171,18 +168,19 @@ void check_orientations(tessellation * T) point *p2 = &DP[t->p[2]]; point *p3 = &DP[t->p[3]]; - if(t->t[0] < 0) /* deleted ? */ + if(t->t[0] < 0) /* deleted ? */ continue; if(isInfinity(p0) || isInfinity(p1) || isInfinity(p2) || isInfinity(p3)) continue; - vol = calculate_tetra_volume(p0, p1, p2, p3); + vol = calculate_tetra_volume(p0, p1, p2, p3); ivol = Orient3d_Exact(p0, p1, p2, p3); if(ivol <= 0) { - sprintf(msg, "Tetra %d is NEGATIVE (%d %d %d %d) oriented or FLAT: ivol=%d vol=%g\n", i, (int) (t->p[0]), (int) (t->p[1]), (int) (t->p[2]), (int) (t->p[3]), ivol, vol); + sprintf(msg, "Tetra %d is NEGATIVE (%d %d %d %d) oriented or FLAT: ivol=%d vol=%g\n", i, (int)(t->p[0]), (int)(t->p[1]), + (int)(t->p[2]), (int)(t->p[3]), ivol, vol); terminate(msg); } @@ -193,7 +191,6 @@ void check_orientations(tessellation * T) printf("orientations ok, volmin=%g\n", volmin); } - /*! \brief Checks if tetrahedra are valid. * * \param[in] T pointer to tessellation. @@ -201,7 +198,7 @@ void check_orientations(tessellation * T) * * \return void */ -void check_tetras(tessellation * T, int npoints) +void check_tetras(tessellation *T, int npoints) { tetra *DT = T->DT; point *DP = T->DP; @@ -220,7 +217,7 @@ void check_tetras(tessellation * T, int npoints) point *p2 = &DP[t->p[2]]; point *p3 = &DP[t->p[3]]; - if(t->t[0] < 0) /* deleted ? */ + if(t->t[0] < 0) /* deleted ? */ continue; if(isInfinity(p0) || isInfinity(p1) || isInfinity(p2) || isInfinity(p3)) @@ -235,7 +232,6 @@ void check_tetras(tessellation * T, int npoints) terminate(msg); } - for(j = 0; j < npoints; j++) { if(t->p[0] != j) @@ -251,8 +247,8 @@ void check_tetras(tessellation * T, int npoints) if(res_exact > 0) { - sprintf(msg, "ERROR tetra=%d: point=%d in tetra with edges=%d|%d|%d|%d res=%d|%d\n", - i, j, (int) (t->p[0]), (int) (t->p[1]), (int) (t->p[2]), (int) (t->p[3]), res, res_exact); + sprintf(msg, "ERROR tetra=%d: point=%d in tetra with edges=%d|%d|%d|%d res=%d|%d\n", i, j, + (int)(t->p[0]), (int)(t->p[1]), (int)(t->p[2]), (int)(t->p[3]), res, res_exact); terminate(msg); } } @@ -263,7 +259,6 @@ void check_tetras(tessellation * T, int npoints) printf("Tetrahedra OK\n"); } - /*! \brief Compare integer value of two variables. * * \param[in] a Pointer to first value. @@ -273,21 +268,18 @@ void check_tetras(tessellation * T, int npoints) */ int points_compare(const void *a, const void *b) { - if(*((int *) a) < *((int *) b)) + if(*((int *)a) < *((int *)b)) return -1; - if(*((int *) a) > *((int *) b)) + if(*((int *)a) > *((int *)b)) return +1; return 0; } - #endif /* #if !defined(TWODIMS) && !defined(ONEDIMS) */ - -#ifdef TWODIMS /* two-dimensional test code */ - +#ifdef TWODIMS /* two-dimensional test code */ /*! \brief Check 2d Voronoi mesh triangles. * @@ -296,7 +288,7 @@ int points_compare(const void *a, const void *b) * * \return void */ -void check_triangles(tessellation * T, int npoints) +void check_triangles(tessellation *T, int npoints) { int i, j, res, res_exact; char msg[200]; @@ -332,7 +324,8 @@ void check_triangles(tessellation * T, int npoints) if(res_exact > 0) { - sprintf(msg, "ERROR: point=%d lies in triangle=%d with edges=%d|%d|%d res=%d|%d\n", j, i, (int) (DT[i].p[0]), (int) (DT[i].p[1]), (int) (DT[i].p[2]), res, res_exact); + sprintf(msg, "ERROR: point=%d lies in triangle=%d with edges=%d|%d|%d res=%d|%d\n", j, i, + (int)(DT[i].p[0]), (int)(DT[i].p[1]), (int)(DT[i].p[2]), res, res_exact); terminate(msg); } } @@ -343,14 +336,13 @@ void check_triangles(tessellation * T, int npoints) printf("triangles ok\n"); } - /*! \brief Check the orientations of triangles in 2d Voronoi mesh. * * \param[in] T Pointer to tessellation. * * \return void */ -void check_orientations(tessellation * T) +void check_orientations(tessellation *T) { int i, ivol; double vol, volmin = 1.0e30; @@ -367,14 +359,15 @@ void check_orientations(tessellation * T) if(DT[i].p[2] == DPinfinity) continue; - vol = test_triangle_orientation(T, DT[i].p[0], DT[i].p[1], DT[i].p[2]); + vol = test_triangle_orientation(T, DT[i].p[0], DT[i].p[1], DT[i].p[2]); ivol = Orient2d_Exact(T, DT[i].p[0], DT[i].p[1], DT[i].p[2]); if(ivol <= 0) { double vol2 = Orient2d_Quick(T, DT[i].p[0], DT[i].p[1], DT[i].p[2]); - sprintf(msg, "Triangle %d is NEGATIVE (%d %d %d) oriented or FLAT: ivol=%d vol=%g|%g\n", i, (int) (DT[i].p[0]), (int) (DT[i].p[1]), (int) (DT[i].p[2]), ivol, vol, vol2); + sprintf(msg, "Triangle %d is NEGATIVE (%d %d %d) oriented or FLAT: ivol=%d vol=%g|%g\n", i, (int)(DT[i].p[0]), + (int)(DT[i].p[1]), (int)(DT[i].p[2]), ivol, vol, vol2); terminate(msg); } @@ -385,14 +378,13 @@ void check_orientations(tessellation * T) printf("orientations ok, volmin=%g\n", volmin); } - /*! \brief Check links in 2d Voronoi mesh. * * \param[in] T Pointer to tesselation. * * \return void */ -void check_links(tessellation * T) +void check_links(tessellation *T) { int i, j; char msg[200]; @@ -412,5 +404,4 @@ void check_links(tessellation * T) } } - #endif /* #ifdef TWODIMS */ diff --git a/src/mesh/voronoi/voronoi_derefinement.c b/src/mesh/voronoi/voronoi_derefinement.c index 1a9954f033a3f54ad80880708001d4cb8bf7a5fd..99afd85cc09d50e827e1d7d5084e9303d659d6d0 100644 --- a/src/mesh/voronoi/voronoi_derefinement.c +++ b/src/mesh/voronoi/voronoi_derefinement.c @@ -34,30 +34,27 @@ * const void *b) * static void derefine_exchange_flag(void) * - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 22.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <math.h> #include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - #if defined(REFINEMENT_MERGE_CELLS) && !defined(ONEDIMS) #define DEREF_SA_FAC 1.0e-4 - int do_derefinements(void); static void derefine_add_ngb(int edge, int i, int j, double area, int tt, int nr); static int derefine_compare_seq_DP_ID(const void *a, const void *b); @@ -67,35 +64,28 @@ static void derefine_exchange_flag(void); static void derefine_apply_probe_list(void); static int derefine_probe_list_data_compare_task(const void *a, const void *b); - /*! \brief Data for derefinement: flag for de-refinement and index of cell. */ static struct derefine_particle_data { int Flag; int dp_index; -} - *deref_SphP; +} * deref_SphP; - - /*! \brief Data structure for communicating de-refinement flags. - */ +/*! \brief Data structure for communicating de-refinement flags. + */ static struct flagexch { int Flag; MyIDType ID; -} - *FlagExch; - +} * FlagExch; /*! \brief Data structure to flag Delaunay data. */ static struct flag_delaunay_data { int Flag; -} - *flag_DP; - +} * flag_DP; /*! \brief Structure defining auxiliary Delaunay data (for sorting). */ @@ -104,9 +94,7 @@ static struct seq_delaunay_data MyFloat rnd; int rank, index; MyIDType ID; -} - *seq_DP; - +} * seq_DP; /*! \brief Structure defining probe list element. */ @@ -115,9 +103,7 @@ static struct probe_list_data int task, index; int sendpart; int flag; -} - *ProbeList; - +} * ProbeList; /*! \brief Structure defining flux list element. */ @@ -127,51 +113,43 @@ static struct flux_list_data double dM, dP[3]; #ifdef MHD double dB[3]; -#endif /* #ifdef MHD */ +#endif /* #ifdef MHD */ #ifndef ISOTHERM_EQS double dEnergy; -#endif /* #ifndef ISOTHERM_EQS */ +#endif /* #ifndef ISOTHERM_EQS */ #ifdef MAXSCALARS double dConservedScalars[MAXSCALARS]; -#endif /* #ifdef MAXSCALARS */ -} - *FluxList; - +#endif /* #ifdef MAXSCALARS */ +} * FluxList; static int Nflux, MaxNflux; - static int *first_ngb, *last_ngb, first_free_ngb; - /*! \brief Structure defining neighbour data. */ static struct ngb_data { #ifdef OPTIMIZE_MEMORY_USAGE MyFloat area; -#else /* #ifdef OPTIMIZE_MEMORY_USAGE */ +#else /* #ifdef OPTIMIZE_MEMORY_USAGE */ double area; -#endif /* #ifdef OPTIMIZE_MEMORY_USAGE #else */ +#endif /* #ifdef OPTIMIZE_MEMORY_USAGE #else */ int index; int edge; int next_ngb; - int t, nr; /* delaunay tetra and edge number that generated this face */ -} - *ngb; - + int t, nr; /* delaunay tetra and edge number that generated this face */ +} * ngb; static int n_tri, max_n_tri; static triangle *trilist; - #ifdef REFINEMENT_SPLIT_CELLS extern char *FlagDoNotRefine; #endif /* #ifdef REFINEMENT_SPLIT_CELLS */ - /*! \brief Adds cell in list ngb. * * \param[in] edge Element 'edge' in ngb. @@ -187,7 +165,6 @@ static void derefine_add_ngb(int edge, int i, int j, double area, int t, int nr) { if(i >= 0 && j >= 0) { - if(i >= Mesh.Ndp || j >= Mesh.Ndp) { terminate("i>= Ndp || j>= Ndp"); @@ -196,24 +173,23 @@ static void derefine_add_ngb(int edge, int i, int j, double area, int t, int nr) if(first_ngb[i] >= 0) { ngb[last_ngb[i]].next_ngb = first_free_ngb; - last_ngb[i] = first_free_ngb; + last_ngb[i] = first_free_ngb; } else { first_ngb[i] = last_ngb[i] = first_free_ngb; } - ngb[first_free_ngb].area = area; - ngb[first_free_ngb].edge = edge; - ngb[first_free_ngb].t = t; - ngb[first_free_ngb].nr = nr; - ngb[first_free_ngb].index = j; + ngb[first_free_ngb].area = area; + ngb[first_free_ngb].edge = edge; + ngb[first_free_ngb].t = t; + ngb[first_free_ngb].nr = nr; + ngb[first_free_ngb].index = j; ngb[first_free_ngb].next_ngb = -1; first_free_ngb++; } } - /*! \brief Loop over all active cells and derefine the ones that need to be * derefined. * @@ -242,7 +218,7 @@ int do_derefinements(void) if(i >= NumGas) terminate("index of gas cell greater than NumGas"); - deref_SphP[i].Flag = 0; + deref_SphP[i].Flag = 0; deref_SphP[i].dp_index = -1; if(derefine_should_this_cell_be_merged(i, deref_SphP[i].Flag)) @@ -266,7 +242,7 @@ int do_derefinements(void) /* let's create an explicit list of the neighbors of each cell */ first_ngb = mymalloc("first_ngb", Mesh.Ndp * sizeof(int)); - ngb = mymalloc("ngb", 2 * Mesh.Nvf * sizeof(struct ngb_data)); + ngb = mymalloc("ngb", 2 * Mesh.Nvf * sizeof(struct ngb_data)); last_ngb = mymalloc("last_ngb", Mesh.Ndp * sizeof(int)); @@ -283,11 +259,11 @@ int do_derefinements(void) /* we now make a list of the delaunay points that we can sort in a globally unique way */ flag_DP = mymalloc_movable(&flag_DP, "flag_DP", Mesh.Ndp * sizeof(struct flag_delaunay_data)); - seq_DP = mymalloc("seq_DP", Mesh.Ndp * sizeof(struct seq_delaunay_data)); + seq_DP = mymalloc("seq_DP", Mesh.Ndp * sizeof(struct seq_delaunay_data)); for(i = 0; i < Mesh.Ndp; i++) { - seq_DP[i].rank = i; + seq_DP[i].rank = i; seq_DP[i].index = Mesh.DP[i].index; if(Mesh.DP[i].task == ThisTask) @@ -296,28 +272,28 @@ int do_derefinements(void) if(li < 0) { flag_DP[i].Flag = 0; - seq_DP[i].ID = 0; - seq_DP[i].rnd = 0; + seq_DP[i].ID = 0; + seq_DP[i].rnd = 0; } else { if(li < NumGas) if(deref_SphP[li].dp_index < 0) - deref_SphP[li].dp_index = i; /* only guaranteed to be set for active cells */ + deref_SphP[li].dp_index = i; /* only guaranteed to be set for active cells */ if(li >= NumGas) li -= NumGas; flag_DP[i].Flag = deref_SphP[li].Flag; - seq_DP[i].ID = P[li].ID; - seq_DP[i].rnd = get_random_number(); + seq_DP[i].ID = P[li].ID; + seq_DP[i].rnd = get_random_number(); } } else { flag_DP[i].Flag = FlagExch[Mesh.DP[i].index].Flag; - seq_DP[i].ID = FlagExch[Mesh.DP[i].index].ID; - seq_DP[i].rnd = get_random_number(); + seq_DP[i].ID = FlagExch[Mesh.DP[i].index].ID; + seq_DP[i].rnd = get_random_number(); } } @@ -335,12 +311,12 @@ int do_derefinements(void) { j = seq_DP[i].rank; - if(flag_DP[j].Flag == 1) /* this cell is still eligible for derefinement */ + if(flag_DP[j].Flag == 1) /* this cell is still eligible for derefinement */ { /* go through its neighbours and check whether one of them is already up for derefinement */ int n = 0; - k = first_ngb[j]; + k = first_ngb[j]; while(k >= 0) { /* we only need to consider neighboring cells if they are active */ @@ -361,7 +337,7 @@ int do_derefinements(void) { #ifndef OPTIMIZE_MESH_MEMORY_FOR_REFINEMENT timebin = PrimExch[Mesh.DP[q].index].TimeBinHydro; -#else /* #ifndef OPTIMIZE_MESH_MEMORY_FOR_REFINEMENT */ +#else /* #ifndef OPTIMIZE_MESH_MEMORY_FOR_REFINEMENT */ timebin = RefExch[Mesh.DP[q].index].TimeBinHydro; #endif /* #ifndef OPTIMIZE_MESH_MEMORY_FOR_REFINEMENT #else */ } @@ -374,13 +350,12 @@ int do_derefinements(void) if(Mesh.DP[q].ID == seq_DP[i].ID) /* same ID, so we have a mirrored particle */ n++; } - } k = ngb[k].next_ngb; } - if(n == 0) /* ok, none have been found. This means this cell is allowed to be refined */ + if(n == 0) /* ok, none have been found. This means this cell is allowed to be refined */ flag_DP[j].Flag = 2; else flag_DP[j].Flag = 3; @@ -416,8 +391,8 @@ int do_derefinements(void) avoid de-refining two neighboring cells. If such a pair is found, both cells will not be derefined. */ - MaxNflux = Mesh.Indi.AllocFacNflux; - Nflux = 0; + MaxNflux = Mesh.Indi.AllocFacNflux; + Nflux = 0; ProbeList = mymalloc_movable(&ProbeList, "ProbeList", MaxNflux * sizeof(struct probe_list_data)); count = 0; @@ -430,7 +405,7 @@ int do_derefinements(void) if(deref_SphP[i].Flag == 2) { - j = deref_SphP[i].dp_index; /* this is the delaunay point of this cell */ + j = deref_SphP[i].dp_index; /* this is the delaunay point of this cell */ if(j < 0) terminate("j < 0"); @@ -451,7 +426,7 @@ int do_derefinements(void) if(p < 0) terminate("p < 0"); - if(p >= NumGas) /* this is a local ghost point */ + if(p >= NumGas) /* this is a local ghost point */ p -= NumGas; if(TimeBinSynchronized[P[p].TimeBinHydro]) @@ -466,7 +441,8 @@ int do_derefinements(void) Mesh.Indi.AllocFacNflux *= ALLOC_INCREASE_FACTOR; MaxNflux = Mesh.Indi.AllocFacNflux; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNflux=%d Indi.AllocFacNflux=%g\n", ThisTask, MaxNflux, Mesh.Indi.AllocFacNflux); + printf("Task=%d: increase memory allocation, MaxNflux=%d Indi.AllocFacNflux=%g\n", ThisTask, MaxNflux, + Mesh.Indi.AllocFacNflux); #endif /* #ifdef VERBOSE */ ProbeList = myrealloc_movable(ProbeList, MaxNflux * sizeof(struct probe_list_data)); @@ -474,10 +450,10 @@ int do_derefinements(void) terminate("Nflux >= MaxNflux"); } - ProbeList[Nflux].task = Mesh.DP[q].task; - ProbeList[Nflux].index = Mesh.DP[q].originalindex; + ProbeList[Nflux].task = Mesh.DP[q].task; + ProbeList[Nflux].index = Mesh.DP[q].originalindex; ProbeList[Nflux].sendpart = i; - ProbeList[Nflux].flag = 0; + ProbeList[Nflux].flag = 0; Nflux++; } @@ -514,12 +490,13 @@ int do_derefinements(void) in[1] = count; MPI_Reduce(in, out, 2, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - mpi_printf("DEREFINE: Number of cells that we could de-refine: %d, number of cells we exclude from this set: %d\n", out[0], out[1]); + mpi_printf("DEREFINE: Number of cells that we could de-refine: %d, number of cells we exclude from this set: %d\n", out[0], + out[1]); /* we now distribute the conserved quantities of the cell among the neighbours */ MaxNflux = Mesh.Indi.AllocFacNflux; - Nflux = 0; + Nflux = 0; FluxList = mymalloc_movable(&FluxList, "FluxList", MaxNflux * sizeof(struct flux_list_data)); for(idx = 0; idx < TimeBinsHydro.NActiveParticles; idx++) @@ -530,12 +507,12 @@ int do_derefinements(void) if(deref_SphP[i].Flag == 2) { - j = deref_SphP[i].dp_index; /* this is the delaunay point of this cell */ + j = deref_SphP[i].dp_index; /* this is the delaunay point of this cell */ if(j < 0) terminate("j < 0"); max_n_tri = 300000; - n_tri = 0; + n_tri = 0; trilist = mymalloc("trilist", max_n_tri * sizeof(triangle)); @@ -549,7 +526,7 @@ int do_derefinements(void) } /* assign the first point as owner to all tetras */ - k = first_ngb[j]; + k = first_ngb[j]; int q = ngb[k].index; int t; for(t = 0; t < n_tri; t++) @@ -566,7 +543,7 @@ int do_derefinements(void) { int q = ngb[k].index; n_tri = derefine_add_point_and_split_tri(q, trilist, n_tri, max_n_tri, vol); - k = ngb[k].next_ngb; + k = ngb[k].next_ngb; } if(n_tri > max_assumed_ntri) @@ -578,9 +555,9 @@ int do_derefinements(void) k = first_ngb[j]; while(k >= 0) { - int q = ngb[k].index; + int q = ngb[k].index; volume[q] = 0; - k = ngb[k].next_ngb; + k = ngb[k].next_ngb; } /* now assign the volume of the triangles to the neighbors */ @@ -594,7 +571,7 @@ int do_derefinements(void) /* first, let's establish the surface area sum for this cell */ double voltot = 0; - k = first_ngb[j]; + k = first_ngb[j]; while(k >= 0) { if(ngb[k].area > DEREF_SA_FAC * SphP[i].SurfaceArea) @@ -607,7 +584,7 @@ int do_derefinements(void) /* now, distribute conserved quantities proportional to the gained volume */ double facsum = 0; - k = first_ngb[j]; + k = first_ngb[j]; while(k >= 0) { if(ngb[k].area > DEREF_SA_FAC * SphP[i].SurfaceArea) @@ -620,7 +597,7 @@ int do_derefinements(void) { warn("strange: fac=%g\n", fac); fac = 0; - //terminate("strange"); + // terminate("strange"); } facsum += fac; @@ -631,7 +608,7 @@ int do_derefinements(void) if(p < 0) terminate("p < 0"); - if(p >= NumGas) /* this is a local ghost point */ + if(p >= NumGas) /* this is a local ghost point */ p -= NumGas; P[p].Mass += fac * P[i].Mass; SphP[p].Momentum[0] += fac * SphP[i].Momentum[0]; @@ -650,7 +627,8 @@ int do_derefinements(void) #ifdef MAXSCALARS for(int s = 0; s < N_Scalar; s++) - *(MyFloat *) (((char *) (&SphP[p])) + scalar_elements[s].offset_mass) += fac * (*(MyFloat *) (((char *) (&SphP[i])) + scalar_elements[s].offset_mass)); + *(MyFloat *)(((char *)(&SphP[p])) + scalar_elements[s].offset_mass) += + fac * (*(MyFloat *)(((char *)(&SphP[i])) + scalar_elements[s].offset_mass)); #endif /* #ifdef MAXSCALARS */ #ifdef REFINEMENT_SPLIT_CELLS @@ -672,7 +650,8 @@ int do_derefinements(void) Mesh.Indi.AllocFacNflux *= ALLOC_INCREASE_FACTOR; MaxNflux = Mesh.Indi.AllocFacNflux; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNflux=%d Indi.AllocFacNflux=%g\n", ThisTask, MaxNflux, Mesh.Indi.AllocFacNflux); + printf("Task=%d: increase memory allocation, MaxNflux=%d Indi.AllocFacNflux=%g\n", ThisTask, MaxNflux, + Mesh.Indi.AllocFacNflux); #endif /* #ifdef VERBOSE */ FluxList = myrealloc_movable(FluxList, MaxNflux * sizeof(struct flux_list_data)); @@ -680,9 +659,9 @@ int do_derefinements(void) terminate("Nflux >= MaxNflux"); } - FluxList[Nflux].task = Mesh.DP[q].task; + FluxList[Nflux].task = Mesh.DP[q].task; FluxList[Nflux].index = Mesh.DP[q].originalindex; - FluxList[Nflux].dM = fac * P[i].Mass; + FluxList[Nflux].dM = fac * P[i].Mass; FluxList[Nflux].dP[0] = fac * SphP[i].Momentum[0]; FluxList[Nflux].dP[1] = fac * SphP[i].Momentum[1]; FluxList[Nflux].dP[2] = fac * SphP[i].Momentum[2]; @@ -698,7 +677,8 @@ int do_derefinements(void) #ifdef MAXSCALARS for(int s = 0; s < N_Scalar; s++) - FluxList[Nflux].dConservedScalars[s] = fac * (*(MyFloat *) (((char *) (&SphP[i])) + scalar_elements[s].offset_mass)); + FluxList[Nflux].dConservedScalars[s] = + fac * (*(MyFloat *)(((char *)(&SphP[i])) + scalar_elements[s].offset_mass)); #endif /* #ifdef MAXSCALARS */ Nflux++; } @@ -720,8 +700,8 @@ int do_derefinements(void) /* we set the dissolved cell to zero mass and zero ID. It will be eliminated from the list * of cells in the next domain decomposition */ - P[i].Mass = 0; - P[i].ID = 0; + P[i].Mass = 0; + P[i].ID = 0; P[i].Vel[0] = 0; P[i].Vel[1] = 0; P[i].Vel[2] = 0; @@ -761,7 +741,6 @@ int do_derefinements(void) return countall; } - /*! \brief Communicates probe list data if needed. * * \return void @@ -796,7 +775,7 @@ static void derefine_apply_probe_list(void) } } - struct probe_list_data *ProbeListGet = (struct probe_list_data *) mymalloc("ProbeListGet", nimport * sizeof(struct probe_list_data)); + struct probe_list_data *ProbeListGet = (struct probe_list_data *)mymalloc("ProbeListGet", nimport * sizeof(struct probe_list_data)); /* exchange particle data */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) @@ -808,10 +787,10 @@ static void derefine_apply_probe_list(void) if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the particles */ - MPI_Sendrecv(&ProbeList[Send_offset[recvTask]], - Send_count[recvTask] * sizeof(struct probe_list_data), MPI_BYTE, - recvTask, TAG_DENS_A, - &ProbeListGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct probe_list_data), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&ProbeList[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct probe_list_data), MPI_BYTE, + recvTask, TAG_DENS_A, &ProbeListGet[Recv_offset[recvTask]], + Recv_count[recvTask] * sizeof(struct probe_list_data), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); } } } @@ -838,10 +817,10 @@ static void derefine_apply_probe_list(void) if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the particles */ - MPI_Sendrecv(&ProbeListGet[Recv_offset[recvTask]], - Recv_count[recvTask] * sizeof(struct probe_list_data), MPI_BYTE, - recvTask, TAG_DENS_A, - &ProbeList[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct probe_list_data), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&ProbeListGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct probe_list_data), MPI_BYTE, + recvTask, TAG_DENS_A, &ProbeList[Send_offset[recvTask]], + Send_count[recvTask] * sizeof(struct probe_list_data), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); } } } @@ -849,7 +828,6 @@ static void derefine_apply_probe_list(void) myfree(ProbeListGet); } - /*! \brief Communicate flux list data if needed. * * \return void @@ -884,7 +862,7 @@ static void derefine_apply_flux_list(void) } } - struct flux_list_data *FluxListGet = (struct flux_list_data *) mymalloc("FluxListGet", nimport * sizeof(struct flux_list_data)); + struct flux_list_data *FluxListGet = (struct flux_list_data *)mymalloc("FluxListGet", nimport * sizeof(struct flux_list_data)); /* exchange particle data */ for(ngrp = 1; ngrp < (1 << PTask); ngrp++) @@ -896,10 +874,9 @@ static void derefine_apply_flux_list(void) if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the particles */ - MPI_Sendrecv(&FluxList[Send_offset[recvTask]], - Send_count[recvTask] * sizeof(struct flux_list_data), MPI_BYTE, - recvTask, TAG_DENS_A, - &FluxListGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct flux_list_data), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&FluxList[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct flux_list_data), MPI_BYTE, recvTask, + TAG_DENS_A, &FluxListGet[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct flux_list_data), + MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } @@ -915,7 +892,7 @@ static void derefine_apply_flux_list(void) char buf[1000]; #ifndef LONGIDS printf("On task=%d flux to ID=%d, but this is already deleted (index p=%d)\n", ThisTask, P[p].ID, p); -#else /* #ifndef LONGIDS */ +#else /* #ifndef LONGIDS */ printf("On task=%d flux to ID=%llu, but this is already deleted (index p=%d)\n", ThisTask, P[p].ID, p); #endif /* #ifndef LONGIDS #else */ terminate(buf); @@ -934,7 +911,7 @@ static void derefine_apply_flux_list(void) #ifdef MAXSCALARS int k; for(k = 0; k < N_Scalar; k++) - *(MyFloat *) (((char *) (&SphP[p])) + scalar_elements[k].offset_mass) += FluxListGet[i].dConservedScalars[k]; + *(MyFloat *)(((char *)(&SphP[p])) + scalar_elements[k].offset_mass) += FluxListGet[i].dConservedScalars[k]; #endif /* #ifdef MAXSCALARS */ #ifndef ISOTHERM_EQS @@ -949,7 +926,6 @@ static void derefine_apply_flux_list(void) myfree(FluxListGet); } - /*! \brief Compares flux list data task of two elements. * * \param[in] a Pointer to first flux list data object. @@ -959,16 +935,15 @@ static void derefine_apply_flux_list(void) */ static int derefine_flux_list_data_compare(const void *a, const void *b) { - if(((struct flux_list_data *) a)->task < (((struct flux_list_data *) b)->task)) + if(((struct flux_list_data *)a)->task < (((struct flux_list_data *)b)->task)) return -1; - if(((struct flux_list_data *) a)->task > (((struct flux_list_data *) b)->task)) + if(((struct flux_list_data *)a)->task > (((struct flux_list_data *)b)->task)) return +1; return 0; } - /*! \brief Compares probe list data task of two elements. * * \param[in] a Pointer to first probe list data object. @@ -978,16 +953,15 @@ static int derefine_flux_list_data_compare(const void *a, const void *b) */ static int derefine_probe_list_data_compare_task(const void *a, const void *b) { - if(((struct probe_list_data *) a)->task < (((struct probe_list_data *) b)->task)) + if(((struct probe_list_data *)a)->task < (((struct probe_list_data *)b)->task)) return -1; - if(((struct probe_list_data *) a)->task > (((struct probe_list_data *) b)->task)) + if(((struct probe_list_data *)a)->task > (((struct probe_list_data *)b)->task)) return +1; return 0; } - /*! \brief Compares seq delaunay data task of two elements. * * Comparison criteria (most important first) @@ -1003,34 +977,33 @@ static int derefine_probe_list_data_compare_task(const void *a, const void *b) */ static int derefine_compare_seq_DP_ID(const void *a, const void *b) { - if(((struct seq_delaunay_data *) a)->rnd < (((struct seq_delaunay_data *) b)->rnd)) + if(((struct seq_delaunay_data *)a)->rnd < (((struct seq_delaunay_data *)b)->rnd)) return -1; - if(((struct seq_delaunay_data *) a)->rnd > (((struct seq_delaunay_data *) b)->rnd)) + if(((struct seq_delaunay_data *)a)->rnd > (((struct seq_delaunay_data *)b)->rnd)) return +1; - if(((struct seq_delaunay_data *) a)->ID < (((struct seq_delaunay_data *) b)->ID)) + if(((struct seq_delaunay_data *)a)->ID < (((struct seq_delaunay_data *)b)->ID)) return -1; - if(((struct seq_delaunay_data *) a)->ID > (((struct seq_delaunay_data *) b)->ID)) + if(((struct seq_delaunay_data *)a)->ID > (((struct seq_delaunay_data *)b)->ID)) return +1; - if(((struct seq_delaunay_data *) a)->index < (((struct seq_delaunay_data *) b)->index)) + if(((struct seq_delaunay_data *)a)->index < (((struct seq_delaunay_data *)b)->index)) return -1; - if(((struct seq_delaunay_data *) a)->index > (((struct seq_delaunay_data *) b)->index)) + if(((struct seq_delaunay_data *)a)->index > (((struct seq_delaunay_data *)b)->index)) return +1; - if(((struct seq_delaunay_data *) a)->rank < (((struct seq_delaunay_data *) b)->rank)) + if(((struct seq_delaunay_data *)a)->rank < (((struct seq_delaunay_data *)b)->rank)) return -1; - if(((struct seq_delaunay_data *) a)->rank > (((struct seq_delaunay_data *) b)->rank)) + if(((struct seq_delaunay_data *)a)->rank > (((struct seq_delaunay_data *)b)->rank)) return +1; return 0; } - /*! \brief Sets exchange flag in de-refinement algorithm. * * Loops through gas cells in mesh, sets set export flag and communicates this @@ -1048,10 +1021,9 @@ static void derefine_exchange_flag(void) { int Flag; MyIDType ID; - } - *tmpExch, *tmpRecv; + } * tmpExch, *tmpRecv; - tmpExch = (struct exchange_data *) mymalloc("tmpExch", Mesh_nexport * sizeof(struct exchange_data)); + tmpExch = (struct exchange_data *)mymalloc("tmpExch", Mesh_nexport * sizeof(struct exchange_data)); /* prepare data for export */ for(j = 0; j < NTask; j++) @@ -1067,10 +1039,10 @@ static void derefine_exchange_flag(void) if((task = ListExports[listp].origin) != ThisTask) { place = ListExports[listp].index; - off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; + off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; tmpExch[off].Flag = 0; - tmpExch[off].ID = P[place].ID; + tmpExch[off].ID = P[place].ID; if(P[place].Type == 0) if(TimeBinSynchronized[P[place].TimeBinHydro]) @@ -1090,19 +1062,19 @@ static void derefine_exchange_flag(void) { if(Mesh_Send_count[recvTask] > 0 || Mesh_Recv_count[recvTask] > 0) { - tmpRecv = (struct exchange_data *) mymalloc("tmpRecv", Mesh_Recv_count[recvTask] * sizeof(struct exchange_data)); + tmpRecv = (struct exchange_data *)mymalloc("tmpRecv", Mesh_Recv_count[recvTask] * sizeof(struct exchange_data)); /* get the values */ - MPI_Sendrecv(&tmpExch[Mesh_Send_offset[recvTask]], - Mesh_Send_count[recvTask] * sizeof(struct exchange_data), MPI_BYTE, - recvTask, TAG_DENS_A, tmpRecv, Mesh_Recv_count[recvTask] * sizeof(struct exchange_data), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&tmpExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] * sizeof(struct exchange_data), MPI_BYTE, + recvTask, TAG_DENS_A, tmpRecv, Mesh_Recv_count[recvTask] * sizeof(struct exchange_data), MPI_BYTE, recvTask, + TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); for(i = 0; i < Mesh_Recv_count[recvTask]; i++) { if(Mesh_Recv_offset[recvTask] + i >= Mesh_nimport) terminate("number of imported mesh points grater than Mesh_nimport"); FlagExch[Mesh_Recv_offset[recvTask] + i].Flag = tmpRecv[i].Flag; - FlagExch[Mesh_Recv_offset[recvTask] + i].ID = tmpRecv[i].ID; + FlagExch[Mesh_Recv_offset[recvTask] + i].ID = tmpRecv[i].ID; } myfree(tmpRecv); @@ -1113,5 +1085,4 @@ static void derefine_exchange_flag(void) myfree(tmpExch); } - #endif /* #if defined(REFINEMENT_MERGE_CELLS) && !defined(ONEDIMS) */ diff --git a/src/mesh/voronoi/voronoi_dynamic_update.c b/src/mesh/voronoi/voronoi_dynamic_update.c index c6ff92bc6fd0f7b2d189d0a75504f95ce2e45b7b..7640029045978571d61fbaa47ad3547b712fbd2c 100644 --- a/src/mesh/voronoi/voronoi_dynamic_update.c +++ b/src/mesh/voronoi/voronoi_dynamic_update.c @@ -26,31 +26,28 @@ * void voronoi_update_connectivity(tessellation * T) * void voronoi_remove_connection(int i) * int compare_foreign_connection(const void *a, const void *b) - * - * + * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 22.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - -int Nvc; /* number of connections */ -int MaxNvc; /* maximum number of connections */ +int Nvc; /* number of connections */ +int MaxNvc; /* maximum number of connections */ int Largest_Nvc; -connection *DC; /* Connections */ - +connection *DC; /* Connections */ /*! Data structure for non-local connection. */ @@ -60,28 +57,25 @@ struct foreign_connection int origin; int index; int image_flags; -} *ForeignDC, *ImportedDC; - - -#define MASK_X_SHIFT_RIGHT 38347922 -#define MASK_X_SHIFT_LEFT 76695844 -#define MASK_Y_SHIFT_RIGHT 14708792 -#define MASK_Y_SHIFT_LEFT 117670336 -#define MASK_Z_SHIFT_RIGHT 261632 -#define MASK_Z_SHIFT_LEFT 133955584 -#define MASK ((1<<27)-1) +} * ForeignDC, *ImportedDC; +#define MASK_X_SHIFT_RIGHT 38347922 +#define MASK_X_SHIFT_LEFT 76695844 +#define MASK_Y_SHIFT_RIGHT 14708792 +#define MASK_Y_SHIFT_LEFT 117670336 +#define MASK_Z_SHIFT_RIGHT 261632 +#define MASK_Z_SHIFT_LEFT 133955584 +#define MASK ((1 << 27) - 1) int FirstUnusedConnection; - /*! \brief Gets connected active cells from a mesh. * * \param[in] T Pointer to tesselation. * * \return Number of cells. */ -int voronoi_get_connected_particles(tessellation * T) +int voronoi_get_connected_particles(tessellation *T) { int idx, i, j, p, q, count = 0, duplicates, image_flags, listp, nexport, nimport, origin; int ngrp, recvTask; @@ -99,9 +93,9 @@ int voronoi_get_connected_particles(tessellation * T) { Ngb_Marker[p] = Ngb_MarkerValue; - if(P[p].Mass == 0 && P[p].ID == 0) /* skip cells that have been swallowed or eliminated */ + if(P[p].Mass == 0 && P[p].ID == 0) /* skip cells that have been swallowed or eliminated */ { - List_P[p].firstexport = -1; + List_P[p].firstexport = -1; List_P[p].currentexport = -1; continue; } @@ -111,7 +105,8 @@ int voronoi_get_connected_particles(tessellation * T) T->Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = T->Indi.AllocFacNinlist; #ifdef VERBOSE - printf("VORONOI: Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, T->Indi.AllocFacNinlist); + printf("VORONOI: Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, + T->Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -124,15 +119,16 @@ int voronoi_get_connected_particles(tessellation * T) List_P[p].currentexport = List_P[p].firstexport = Ninlist++; ListExports[List_P[p].currentexport].image_bits = 1; ListExports[List_P[p].currentexport].nextexport = -1; - ListExports[List_P[p].currentexport].origin = ThisTask; - ListExports[List_P[p].currentexport].index = p; + ListExports[List_P[p].currentexport].origin = ThisTask; + ListExports[List_P[p].currentexport].index = p; if(T->Ndp >= T->MaxNdp) { T->Indi.AllocFacNdp *= ALLOC_INCREASE_FACTOR; T->MaxNdp = T->Indi.AllocFacNdp; #ifdef VERBOSE - printf("VORONOI: Task=%d: increase memory allocation, MaxNdp=%d Indi.AllocFacNdp=%g\n", ThisTask, T->MaxNdp, T->Indi.AllocFacNdp); + printf("VORONOI: Task=%d: increase memory allocation, MaxNdp=%d Indi.AllocFacNdp=%g\n", ThisTask, T->MaxNdp, + T->Indi.AllocFacNdp); #endif /* #ifdef VERBOSE */ T->DP -= 5; T->DP = myrealloc_movable(T->DP, (T->MaxNdp + 5) * sizeof(point)); @@ -146,19 +142,19 @@ int voronoi_get_connected_particles(tessellation * T) point *dp = &T->DP[T->Ndp]; - dp->x = P[p].Pos[0]; - dp->y = P[p].Pos[1]; - dp->z = P[p].Pos[2]; - dp->ID = P[p].ID; - dp->task = ThisTask; - dp->index = p; + dp->x = P[p].Pos[0]; + dp->y = P[p].Pos[1]; + dp->z = P[p].Pos[2]; + dp->ID = P[p].ID; + dp->task = ThisTask; + dp->index = p; dp->originalindex = -1; - dp->timebin = P[p].TimeBinHydro; - dp->image_flags = 1; + dp->timebin = P[p].TimeBinHydro; + dp->image_flags = 1; #ifdef DOUBLE_STENCIL - dp->Hsml = SphP[p].Hsml; + dp->Hsml = SphP[p].Hsml; dp->first_connection = -1; - dp->last_connection = -1; + dp->last_connection = -1; #endif /* #ifdef DOUBLE_STENCIL */ T->Ndp++; count++; @@ -187,15 +183,14 @@ int voronoi_get_connected_particles(tessellation * T) if(DC[q].task >= 0 && DC[q].task < NTask) { - if(ThisTask == DC[q].task) /* this one is local */ + if(ThisTask == DC[q].task) /* this one is local */ { - p = DC[q].index; /* particle index */ + p = DC[q].index; /* particle index */ if(P[p].Type == 0) { - if(!(P[p].Mass == 0 && P[p].ID == 0)) /* skip cells that have been swallowed or dissolved */ + if(!(P[p].Mass == 0 && P[p].ID == 0)) /* skip cells that have been swallowed or dissolved */ { - if(P[p].Ti_Current != All.Ti_Current) { drift_particle(p, All.Ti_Current); @@ -212,8 +207,8 @@ int voronoi_get_connected_particles(tessellation * T) if(Ngb_Marker[p] != Ngb_MarkerValue) { - Ngb_Marker[p] = Ngb_MarkerValue; - List_P[p].firstexport = -1; + Ngb_Marker[p] = Ngb_MarkerValue; + List_P[p].firstexport = -1; List_P[p].currentexport = -1; } @@ -233,7 +228,8 @@ int voronoi_get_connected_particles(tessellation * T) T->Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = T->Indi.AllocFacNinlist; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, T->Indi.AllocFacNinlist); + printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, + MaxNinlist, T->Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -246,12 +242,11 @@ int voronoi_get_connected_particles(tessellation * T) List_P[p].currentexport = List_P[p].firstexport = Ninlist++; ListExports[List_P[p].currentexport].image_bits = 0; ListExports[List_P[p].currentexport].nextexport = -1; - ListExports[List_P[p].currentexport].origin = ThisTask; - ListExports[List_P[p].currentexport].index = p; + ListExports[List_P[p].currentexport].origin = ThisTask; + ListExports[List_P[p].currentexport].index = p; } - - if(!(ListExports[List_P[p].currentexport].image_bits & image_flags)) /* already in list */ + if(!(ListExports[List_P[p].currentexport].image_bits & image_flags)) /* already in list */ { ListExports[List_P[p].currentexport].image_bits |= image_flags; @@ -260,7 +255,8 @@ int voronoi_get_connected_particles(tessellation * T) T->Indi.AllocFacNdp *= ALLOC_INCREASE_FACTOR; T->MaxNdp = T->Indi.AllocFacNdp; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNdp=%d Indi.AllocFacNdp=%g\n", ThisTask, T->MaxNdp, T->Indi.AllocFacNdp); + printf("Task=%d: increase memory allocation, MaxNdp=%d Indi.AllocFacNdp=%g\n", ThisTask, T->MaxNdp, + T->Indi.AllocFacNdp); #endif /* #ifdef VERBOSE */ T->DP -= 5; T->DP = myrealloc_movable(T->DP, (T->MaxNdp + 5) * sizeof(point)); @@ -276,14 +272,15 @@ int voronoi_get_connected_particles(tessellation * T) MyDouble y = P[p].Pos[1]; MyDouble z = P[p].Pos[2]; - /* for each coordinates there are three possibilities. They are encoded in image_flag to basis three, i.e. x*3^0 + y*3^1 + z*3^2 */ + /* for each coordinates there are three possibilities. They are encoded in image_flag to basis three, + * i.e. x*3^0 + y*3^1 + z*3^2 */ #ifndef REFLECTIVE_X if((image_flags & MASK_X_SHIFT_RIGHT)) x += boxSize_X; else if((image_flags & MASK_X_SHIFT_LEFT)) x -= boxSize_X; -#else /* #ifndef REFLECTIVE_X */ +#else /* #ifndef REFLECTIVE_X */ if((image_flags & MASK_X_SHIFT_RIGHT)) x = -x; else if((image_flags & MASK_X_SHIFT_LEFT)) @@ -294,7 +291,7 @@ int voronoi_get_connected_particles(tessellation * T) y += boxSize_Y; else if((image_flags & MASK_Y_SHIFT_LEFT)) y -= boxSize_Y; -#else /* #ifndef REFLECTIVE_Y */ +#else /* #ifndef REFLECTIVE_Y */ if((image_flags & MASK_Y_SHIFT_RIGHT)) y = -y; else if((image_flags & MASK_Y_SHIFT_LEFT)) @@ -305,7 +302,7 @@ int voronoi_get_connected_particles(tessellation * T) z += boxSize_Z; else if((image_flags & MASK_Z_SHIFT_LEFT)) z -= boxSize_Z; -#else /* #ifndef REFLECTIVE_Z */ +#else /* #ifndef REFLECTIVE_Z */ if((image_flags & MASK_Z_SHIFT_RIGHT)) z = -z; else if((image_flags & MASK_Z_SHIFT_LEFT)) @@ -319,19 +316,19 @@ int voronoi_get_connected_particles(tessellation * T) dp->z = z; dp->task = ThisTask; - dp->ID = P[p].ID; + dp->ID = P[p].ID; if(image_flags != 1) dp->index = p + NumGas; /* this is a replicated/mirrored local point */ else - dp->index = p; /* this is actually a local point that wasn't made part of the mesh yet */ + dp->index = p; /* this is actually a local point that wasn't made part of the mesh yet */ dp->originalindex = p; - dp->timebin = P[p].TimeBinHydro; + dp->timebin = P[p].TimeBinHydro; dp->image_flags = image_flags; #ifdef DOUBLE_STENCIL - dp->Hsml = SphP[p].Hsml; + dp->Hsml = SphP[p].Hsml; dp->first_connection = -1; - dp->last_connection = -1; + dp->last_connection = -1; #endif /* #ifdef DOUBLE_STENCIL */ T->Ndp++; count++; @@ -373,13 +370,13 @@ int voronoi_get_connected_particles(tessellation * T) { if(DC[q].task >= 0 && DC[q].task < NTask) { - if(ThisTask != DC[q].task) /* this one is not local */ + if(ThisTask != DC[q].task) /* this one is not local */ { p = DC[q].index; - ForeignDC[count_foreign].task = DC[q].task; - ForeignDC[count_foreign].origin = ThisTask; - ForeignDC[count_foreign].index = DC[q].index; + ForeignDC[count_foreign].task = DC[q].task; + ForeignDC[count_foreign].origin = ThisTask; + ForeignDC[count_foreign].index = DC[q].index; ForeignDC[count_foreign].image_flags = (DC[q].image_flags & MASK); /* here we have a foreign neighbor that we want */ @@ -455,14 +452,15 @@ int voronoi_get_connected_particles(tessellation * T) { if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { - MPI_Sendrecv(&ForeignDC[Send_offset[recvTask]], - Send_count[recvTask] * sizeof(struct foreign_connection), MPI_BYTE, recvTask, - TAG_DENS_B, &ImportedDC[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(struct foreign_connection), MPI_BYTE, recvTask, TAG_DENS_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&ForeignDC[Send_offset[recvTask]], Send_count[recvTask] * sizeof(struct foreign_connection), MPI_BYTE, + recvTask, TAG_DENS_B, &ImportedDC[Recv_offset[recvTask]], + Recv_count[recvTask] * sizeof(struct foreign_connection), MPI_BYTE, recvTask, TAG_DENS_B, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); } } } - point *DP_Buffer = (point *) mymalloc_movable(&DP_Buffer, "DP_Buffer", nimport * sizeof(point)); + point *DP_Buffer = (point *)mymalloc_movable(&DP_Buffer, "DP_Buffer", nimport * sizeof(point)); /* now we prepare the points */ for(j = 0; j < NTask; j++) @@ -470,8 +468,8 @@ int voronoi_get_connected_particles(tessellation * T) for(i = 0; i < nimport; i++) { - p = ImportedDC[i].index; - origin = ImportedDC[i].origin; + p = ImportedDC[i].index; + origin = ImportedDC[i].origin; image_flags = ImportedDC[i].image_flags; /* it could happen that the requested point has been refined or was turned into a star, that's why @@ -481,7 +479,7 @@ int voronoi_get_connected_particles(tessellation * T) continue; if(P[p].Mass == 0 && P[p].ID == 0) - continue; /* skip cells that have been swallowed or dissolved */ + continue; /* skip cells that have been swallowed or dissolved */ if(P[p].Ti_Current != All.Ti_Current) { @@ -492,8 +490,8 @@ int voronoi_get_connected_particles(tessellation * T) if(Ngb_Marker[p] != Ngb_MarkerValue) { - Ngb_Marker[p] = Ngb_MarkerValue; - List_P[p].firstexport = -1; + Ngb_Marker[p] = Ngb_MarkerValue; + List_P[p].firstexport = -1; List_P[p].currentexport = -1; } @@ -517,7 +515,8 @@ int voronoi_get_connected_particles(tessellation * T) T->Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = T->Indi.AllocFacNinlist; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, T->Indi.AllocFacNinlist); + printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, + T->Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -525,12 +524,12 @@ int voronoi_get_connected_particles(tessellation * T) terminate("Ninlist >= MaxNinlist"); } - List_P[p].currentexport = Ninlist++; + List_P[p].currentexport = Ninlist++; ListExports[List_P[p].currentexport].image_bits = 0; ListExports[List_P[p].currentexport].nextexport = -1; - ListExports[List_P[p].currentexport].origin = origin; - ListExports[List_P[p].currentexport].index = p; - ListExports[listp].nextexport = List_P[p].currentexport; + ListExports[List_P[p].currentexport].origin = origin; + ListExports[List_P[p].currentexport].index = p; + ListExports[listp].nextexport = List_P[p].currentexport; break; } listp = ListExports[listp].nextexport; @@ -546,7 +545,8 @@ int voronoi_get_connected_particles(tessellation * T) T->Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = T->Indi.AllocFacNinlist; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, T->Indi.AllocFacNinlist); + printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, + T->Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -559,8 +559,8 @@ int voronoi_get_connected_particles(tessellation * T) List_P[p].currentexport = List_P[p].firstexport = Ninlist++; ListExports[List_P[p].currentexport].image_bits = 0; ListExports[List_P[p].currentexport].nextexport = -1; - ListExports[List_P[p].currentexport].origin = origin; - ListExports[List_P[p].currentexport].index = p; + ListExports[List_P[p].currentexport].origin = origin; + ListExports[List_P[p].currentexport].index = p; } ListExports[List_P[p].currentexport].image_bits |= image_flags; @@ -569,13 +569,14 @@ int voronoi_get_connected_particles(tessellation * T) MyDouble y = P[p].Pos[1]; MyDouble z = P[p].Pos[2]; - /* for each coordinates there are three possibilities. They are encoded in image_flag to basis three, i.e. x*3^0 + y*3^1 + z*3^2 */ + /* for each coordinates there are three possibilities. They are encoded in image_flag to basis three, i.e. x*3^0 + y*3^1 + z*3^2 + */ #ifndef REFLECTIVE_X if((image_flags & MASK_X_SHIFT_RIGHT)) x += boxSize_X; else if((image_flags & MASK_X_SHIFT_LEFT)) x -= boxSize_X; -#else /* #ifndef REFLECTIVE_X */ +#else /* #ifndef REFLECTIVE_X */ if((image_flags & MASK_X_SHIFT_RIGHT)) x = -x; else if((image_flags & MASK_X_SHIFT_LEFT)) @@ -587,7 +588,7 @@ int voronoi_get_connected_particles(tessellation * T) y += boxSize_Y; else if((image_flags & MASK_Y_SHIFT_LEFT)) y -= boxSize_Y; -#else /* #ifndef REFLECTIVE_Y */ +#else /* #ifndef REFLECTIVE_Y */ if((image_flags & MASK_Y_SHIFT_RIGHT)) y = -y; else if((image_flags & MASK_Y_SHIFT_LEFT)) @@ -599,7 +600,7 @@ int voronoi_get_connected_particles(tessellation * T) z += boxSize_Z; else if((image_flags & MASK_Z_SHIFT_LEFT)) z -= boxSize_Z; -#else /* #ifndef REFLECTIVE_Z */ +#else /* #ifndef REFLECTIVE_Z */ if((image_flags & MASK_Z_SHIFT_RIGHT)) z = -z; else if((image_flags & MASK_Z_SHIFT_LEFT)) @@ -610,20 +611,20 @@ int voronoi_get_connected_particles(tessellation * T) SphP[p].ActiveArea = 0; - DP_Buffer[k].x = x; - DP_Buffer[k].y = y; - DP_Buffer[k].z = z; - DP_Buffer[k].ID = P[p].ID; - DP_Buffer[k].task = ThisTask; - DP_Buffer[k].index = p; + DP_Buffer[k].x = x; + DP_Buffer[k].y = y; + DP_Buffer[k].z = z; + DP_Buffer[k].ID = P[p].ID; + DP_Buffer[k].task = ThisTask; + DP_Buffer[k].index = p; DP_Buffer[k].originalindex = p; - DP_Buffer[k].timebin = P[p].TimeBinHydro; + DP_Buffer[k].timebin = P[p].TimeBinHydro; DP_Buffer[k].image_flags = image_flags; #ifdef DOUBLE_STENCIL - DP_Buffer[k].Hsml = SphP[p].Hsml; + DP_Buffer[k].Hsml = SphP[p].Hsml; DP_Buffer[k].first_connection = -1; - DP_Buffer[k].last_connection = -1; + DP_Buffer[k].last_connection = -1; #endif /* #ifdef DOUBLE_STENCIL */ } @@ -669,9 +670,9 @@ int voronoi_get_connected_particles(tessellation * T) { /* get the Delaunay points */ - MPI_Sendrecv(&DP_Buffer[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(point), - MPI_BYTE, recvTask, TAG_DENS_B, - &T->DP[T->Ndp + Send_offset[recvTask]], Send_count[recvTask] * sizeof(point), MPI_BYTE, recvTask, TAG_DENS_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&DP_Buffer[Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(point), MPI_BYTE, recvTask, TAG_DENS_B, + &T->DP[T->Ndp + Send_offset[recvTask]], Send_count[recvTask] * sizeof(point), MPI_BYTE, recvTask, + TAG_DENS_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } @@ -699,22 +700,20 @@ int voronoi_get_connected_particles(tessellation * T) return count; } - - /*! \brief Initialises connectivity. * * \param[in] T Pointer to tessellation. * * \return void */ -void voronoi_init_connectivity(tessellation * T) +void voronoi_init_connectivity(tessellation *T) { int i; mpi_printf("VORONOI: init connectivity\n"); MaxNvc = T->Indi.AllocFacNvc; - DC = mymalloc_movable(&DC, "DC", MaxNvc * sizeof(connection)); + DC = mymalloc_movable(&DC, "DC", MaxNvc * sizeof(connection)); Nvc = 0; @@ -724,7 +723,7 @@ void voronoi_init_connectivity(tessellation * T) for(i = 0; i < MaxNvc - 1; i++) { DC[i].next = i + 1; - DC[i].task = -1; /* mark that this is unused */ + DC[i].task = -1; /* mark that this is unused */ } DC[MaxNvc - 1].next = -1; DC[MaxNvc - 1].task = -1; @@ -736,14 +735,13 @@ void voronoi_init_connectivity(tessellation * T) mpi_printf("VORONOI: done with init of connectivity\n"); } - /*! \brief Updates connectivity. * * \param[in] T Pointer to tessellation. * * \return void */ -void voronoi_update_connectivity(tessellation * T) +void voronoi_update_connectivity(tessellation *T) { int idx, i, k, q, p_task, p_index, q_task, q_index, q_dp_index, q_image_flags; MyIDType p_ID; @@ -762,12 +760,12 @@ void voronoi_update_connectivity(tessellation * T) q = SphP[i].first_connection; - if(q >= 0) /* we have connections, let's add them to the free list */ + if(q >= 0) /* we have connections, let's add them to the free list */ { while(q >= 0) { Nvc--; - DC[q].task = -1; /* mark that this is unused */ + DC[q].task = -1; /* mark that this is unused */ if(q == SphP[i].last_connection) break; @@ -777,10 +775,10 @@ void voronoi_update_connectivity(tessellation * T) /* we add the new free spots at the beginning of the free list */ DC[SphP[i].last_connection].next = FirstUnusedConnection; - FirstUnusedConnection = SphP[i].first_connection; + FirstUnusedConnection = SphP[i].first_connection; SphP[i].first_connection = -1; - SphP[i].last_connection = -1; + SphP[i].last_connection = -1; } } @@ -789,26 +787,26 @@ void voronoi_update_connectivity(tessellation * T) for(k = 0; k < 2; k++) { point *DP = T->DP; - face *VF = T->VF; + face *VF = T->VF; if(k == 0) { - p_task = DP[VF[i].p1].task; - p_index = DP[VF[i].p1].index; - p_ID = DP[VF[i].p1].ID; - q_task = DP[VF[i].p2].task; - q_index = DP[VF[i].p2].index; - q_dp_index = VF[i].p2; + p_task = DP[VF[i].p1].task; + p_index = DP[VF[i].p1].index; + p_ID = DP[VF[i].p1].ID; + q_task = DP[VF[i].p2].task; + q_index = DP[VF[i].p2].index; + q_dp_index = VF[i].p2; q_image_flags = (DP[VF[i].p2].image_flags & MASK); } else { - p_task = DP[VF[i].p2].task; - p_index = DP[VF[i].p2].index; - p_ID = DP[VF[i].p2].ID; - q_task = DP[VF[i].p1].task; - q_index = DP[VF[i].p1].index; - q_dp_index = VF[i].p1; + p_task = DP[VF[i].p2].task; + p_index = DP[VF[i].p2].index; + p_ID = DP[VF[i].p2].ID; + q_task = DP[VF[i].p1].task; + q_index = DP[VF[i].p1].index; + q_dp_index = VF[i].p1; q_image_flags = (DP[VF[i].p1].image_flags & MASK); } @@ -820,7 +818,7 @@ void voronoi_update_connectivity(tessellation * T) continue; if(P[p_index].Mass == 0 && P[p_index].ID == 0) - continue; /* skip cells that have been swallowed or dissolved */ + continue; /* skip cells that have been swallowed or dissolved */ /* need to add the connection to the other point to this particle */ @@ -837,7 +835,8 @@ void voronoi_update_connectivity(tessellation * T) T->Indi.AllocFacNvc *= ALLOC_INCREASE_FACTOR; MaxNvc = T->Indi.AllocFacNvc; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNvc=%d Indi.AllocFacNvc=%g\n", ThisTask, MaxNvc, T->Indi.AllocFacNvc); + printf("Task=%d: increase memory allocation, MaxNvc=%d Indi.AllocFacNvc=%g\n", ThisTask, MaxNvc, + T->Indi.AllocFacNvc); #endif /* #ifdef VERBOSE */ DC = myrealloc_movable(DC, MaxNvc * sizeof(connection)); DP = T->DP; @@ -856,20 +855,20 @@ void voronoi_update_connectivity(tessellation * T) if(SphP[p_index].last_connection >= 0) { DC[SphP[p_index].last_connection].next = FirstUnusedConnection; - SphP[p_index].last_connection = FirstUnusedConnection; + SphP[p_index].last_connection = FirstUnusedConnection; } else { - SphP[p_index].last_connection = FirstUnusedConnection; + SphP[p_index].last_connection = FirstUnusedConnection; SphP[p_index].first_connection = FirstUnusedConnection; } FirstUnusedConnection = DC[FirstUnusedConnection].next; Nvc++; - DC[SphP[p_index].last_connection].task = q_task; + DC[SphP[p_index].last_connection].task = q_task; DC[SphP[p_index].last_connection].image_flags = q_image_flags; - DC[SphP[p_index].last_connection].ID = p_ID; + DC[SphP[p_index].last_connection].ID = p_ID; if(q_task == ThisTask && q_index >= NumGas) DC[SphP[p_index].last_connection].index = q_index - NumGas; @@ -879,8 +878,8 @@ void voronoi_update_connectivity(tessellation * T) DC[SphP[p_index].last_connection].dp_index = q_dp_index; #ifdef TETRA_INDEX_IN_FACE DC[SphP[p_index].last_connection].dt_index = VF[i].dt_index; -#endif /* #ifdef TETRA_INDEX_IN_FACE */ - DC[SphP[p_index].last_connection].vf_index = i; /* index to the corresponding face */ +#endif /* #ifdef TETRA_INDEX_IN_FACE */ + DC[SphP[p_index].last_connection].vf_index = i; /* index to the corresponding face */ if(SphP[p_index].last_connection >= MaxNvc) { @@ -913,7 +912,8 @@ void voronoi_update_connectivity(tessellation * T) T->Indi.AllocFacNvc *= ALLOC_INCREASE_FACTOR; MaxNvc = T->Indi.AllocFacNvc; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNvc=%d Indi.AllocFacNvc=%g\n", ThisTask, MaxNvc, T->Indi.AllocFacNvc); + printf("Task=%d: increase memory allocation, MaxNvc=%d Indi.AllocFacNvc=%g\n", ThisTask, MaxNvc, + T->Indi.AllocFacNvc); #endif /* #ifdef VERBOSE */ DC = myrealloc_movable(DC, MaxNvc * sizeof(connection)); DP = T->DP; @@ -932,20 +932,20 @@ void voronoi_update_connectivity(tessellation * T) if(DP[index].last_connection >= 0) { DC[DP[index].last_connection].next = FirstUnusedConnection; - DP[index].last_connection = FirstUnusedConnection; + DP[index].last_connection = FirstUnusedConnection; } else { - DP[index].last_connection = FirstUnusedConnection; + DP[index].last_connection = FirstUnusedConnection; DP[index].first_connection = FirstUnusedConnection; } FirstUnusedConnection = DC[FirstUnusedConnection].next; Nvc++; - DC[DP[index].last_connection].task = q_task; + DC[DP[index].last_connection].task = q_task; DC[DP[index].last_connection].image_flags = q_image_flags; - DC[DP[index].last_connection].ID = p_ID; + DC[DP[index].last_connection].ID = p_ID; if(q_task == ThisTask && q_index >= NumGas) DC[DP[index].last_connection].index = q_index - NumGas; @@ -954,7 +954,7 @@ void voronoi_update_connectivity(tessellation * T) DC[DP[index].last_connection].dp_index = q_dp_index; - DC[DP[index].last_connection].vf_index = i; /* index to the corresponding face */ + DC[DP[index].last_connection].vf_index = i; /* index to the corresponding face */ if(DP[index].last_connection >= MaxNvc) { @@ -970,7 +970,6 @@ void voronoi_update_connectivity(tessellation * T) CPU_Step[CPU_MESH_DYNAMIC] += measure_time(); } - /*! \brief Remove connection from cell. * * \param[in] i Index of cell. @@ -980,12 +979,12 @@ void voronoi_update_connectivity(tessellation * T) void voronoi_remove_connection(int i) { int q; - if((q = SphP[i].first_connection) >= 0) /* we have connections, let's add them to the free list */ + if((q = SphP[i].first_connection) >= 0) /* we have connections, let's add them to the free list */ { while(q >= 0) { Nvc--; - DC[q].task = -1; /* mark that this is unused */ + DC[q].task = -1; /* mark that this is unused */ if(q == SphP[i].last_connection) break; @@ -995,14 +994,13 @@ void voronoi_remove_connection(int i) /* we add the new free spots at the beginning of the free list */ DC[SphP[i].last_connection].next = FirstUnusedConnection; - FirstUnusedConnection = SphP[i].first_connection; + FirstUnusedConnection = SphP[i].first_connection; SphP[i].first_connection = -1; - SphP[i].last_connection = -1; + SphP[i].last_connection = -1; } } - /*! \brief Compares two foreign connection objects. * * Compares (highest priority first): @@ -1017,22 +1015,22 @@ void voronoi_remove_connection(int i) */ int compare_foreign_connection(const void *a, const void *b) { - if(((struct foreign_connection *) a)->task < (((struct foreign_connection *) b)->task)) + if(((struct foreign_connection *)a)->task < (((struct foreign_connection *)b)->task)) return -1; - if(((struct foreign_connection *) a)->task > (((struct foreign_connection *) b)->task)) + if(((struct foreign_connection *)a)->task > (((struct foreign_connection *)b)->task)) return +1; - if(((struct foreign_connection *) a)->index < (((struct foreign_connection *) b)->index)) + if(((struct foreign_connection *)a)->index < (((struct foreign_connection *)b)->index)) return -1; - if(((struct foreign_connection *) a)->index > (((struct foreign_connection *) b)->index)) + if(((struct foreign_connection *)a)->index > (((struct foreign_connection *)b)->index)) return +1; - if(((struct foreign_connection *) a)->image_flags < (((struct foreign_connection *) b)->image_flags)) + if(((struct foreign_connection *)a)->image_flags < (((struct foreign_connection *)b)->image_flags)) return -1; - if(((struct foreign_connection *) a)->image_flags > (((struct foreign_connection *) b)->image_flags)) + if(((struct foreign_connection *)a)->image_flags > (((struct foreign_connection *)b)->image_flags)) return +1; return 0; diff --git a/src/mesh/voronoi/voronoi_exchange.c b/src/mesh/voronoi/voronoi_exchange.c index f87df3f6465d24046409f00c79ce7113db61f66b..9b2f79684e8603774bf47865e66cdbf7dacfb9dc 100644 --- a/src/mesh/voronoi/voronoi_exchange.c +++ b/src/mesh/voronoi/voronoi_exchange.c @@ -27,36 +27,33 @@ * void exchange_primitive_variables_and_gradients(void) * int compare_primexch(const void *a, const void *b) * void voronoi_update_ghost_velvertex(void) - * - * + * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 22.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <gsl/gsl_math.h> +#include <math.h> #include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> -#include <gsl/gsl_math.h> #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - /*! \brief Auxiliary data structure for communication of primitive variables. * */ struct data_primexch_compare { int rank, task, index; -} *SortPrimExch, *SortPrimExch2; - +} * SortPrimExch, *SortPrimExch2; /*! \brief Prepares exchange of primitive variables. * @@ -73,7 +70,7 @@ void mesh_setup_exchange(void) struct indexexch { int task, index; - } *tmpIndexExch, *IndexExch; + } * tmpIndexExch, *IndexExch; int i, j, p, task, off, count; int ngrp, recvTask, place; @@ -109,8 +106,8 @@ void mesh_setup_exchange(void) } } - IndexExch = (struct indexexch *) mymalloc("IndexExch", Mesh_nimport * sizeof(struct indexexch)); - tmpIndexExch = (struct indexexch *) mymalloc("tmpIndexExch", Mesh_nexport * sizeof(struct indexexch)); + IndexExch = (struct indexexch *)mymalloc("IndexExch", Mesh_nimport * sizeof(struct indexexch)); + tmpIndexExch = (struct indexexch *)mymalloc("tmpIndexExch", Mesh_nexport * sizeof(struct indexexch)); /* prepare data for export */ for(j = 0; j < NTask; j++) @@ -126,9 +123,9 @@ void mesh_setup_exchange(void) if((task = ListExports[listp].origin) != ThisTask) { place = ListExports[listp].index; - off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; + off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; - tmpIndexExch[off].task = ThisTask; + tmpIndexExch[off].task = ThisTask; tmpIndexExch[off].index = place; } listp = ListExports[listp].nextexport; @@ -145,9 +142,10 @@ void mesh_setup_exchange(void) if(Mesh_Send_count[recvTask] > 0 || Mesh_Recv_count[recvTask] > 0) { /* get the particles */ - MPI_Sendrecv(&tmpIndexExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] - * sizeof(struct indexexch), MPI_BYTE, recvTask, TAG_DENS_A, - &IndexExch[Mesh_Recv_offset[recvTask]], Mesh_Recv_count[recvTask] * sizeof(struct indexexch), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&tmpIndexExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] * sizeof(struct indexexch), MPI_BYTE, + recvTask, TAG_DENS_A, &IndexExch[Mesh_Recv_offset[recvTask]], + Mesh_Recv_count[recvTask] * sizeof(struct indexexch), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); } } } @@ -156,26 +154,26 @@ void mesh_setup_exchange(void) /* now we need to associate the imported data with the points stored in the DP[] array */ - SortPrimExch = (struct data_primexch_compare *) mymalloc("SortPrimExch", Mesh_nimport * sizeof(struct data_primexch_compare)); + SortPrimExch = (struct data_primexch_compare *)mymalloc("SortPrimExch", Mesh_nimport * sizeof(struct data_primexch_compare)); for(i = 0; i < Mesh_nimport; i++) { - SortPrimExch[i].rank = i; - SortPrimExch[i].task = IndexExch[i].task; + SortPrimExch[i].rank = i; + SortPrimExch[i].task = IndexExch[i].task; SortPrimExch[i].index = IndexExch[i].index; } /* let sort the data according to task and index */ mysort(SortPrimExch, Mesh_nimport, sizeof(struct data_primexch_compare), compare_primexch); - SortPrimExch2 = (struct data_primexch_compare *) mymalloc("SortPrimExch2", Mesh.Ndp * sizeof(struct data_primexch_compare)); + SortPrimExch2 = (struct data_primexch_compare *)mymalloc("SortPrimExch2", Mesh.Ndp * sizeof(struct data_primexch_compare)); for(i = 0, count = 0; i < Mesh.Ndp; i++) { if(Mesh.DP[i].task != ThisTask) { - SortPrimExch2[count].rank = i; - SortPrimExch2[count].task = Mesh.DP[i].task; + SortPrimExch2[count].rank = i; + SortPrimExch2[count].task = Mesh.DP[i].task; SortPrimExch2[count].index = Mesh.DP[i].index; count++; } @@ -195,7 +193,8 @@ void mesh_setup_exchange(void) if(j >= Mesh_nimport) terminate("j >= Mesh_nimport"); - Mesh.DP[SortPrimExch2[i].rank].index = SortPrimExch[j].rank; /* note: this change is now permanent and available for next exchange */ + Mesh.DP[SortPrimExch2[i].rank].index = + SortPrimExch[j].rank; /* note: this change is now permanent and available for next exchange */ } myfree(SortPrimExch2); @@ -203,13 +202,12 @@ void mesh_setup_exchange(void) myfree(IndexExch); /* allocate structures needed to exchange the actual information for ghost cells */ - PrimExch = (struct primexch *) mymalloc_movable(&PrimExch, "PrimExch", Mesh_nimport * sizeof(struct primexch)); - GradExch = (struct grad_data *) mymalloc_movable(&GradExch, "GradExch", Mesh_nimport * sizeof(struct grad_data)); + PrimExch = (struct primexch *)mymalloc_movable(&PrimExch, "PrimExch", Mesh_nimport * sizeof(struct primexch)); + GradExch = (struct grad_data *)mymalloc_movable(&GradExch, "GradExch", Mesh_nimport * sizeof(struct grad_data)); TIMER_STOP(CPU_MESH_EXCHANGE); } - /*! \brief Communicate primitive variables across MPI tasks. * * This routine is called before gradient calculation, afterwards, @@ -229,7 +227,7 @@ void exchange_primitive_variables(void) int i, j, p, task, off; int ngrp, recvTask, place; - tmpPrimExch = (struct primexch *) mymalloc("tmpPrimExch", Mesh_nexport * sizeof(struct primexch)); + tmpPrimExch = (struct primexch *)mymalloc("tmpPrimExch", Mesh_nexport * sizeof(struct primexch)); /* prepare data for export */ for(j = 0; j < NTask; j++) @@ -245,7 +243,7 @@ void exchange_primitive_variables(void) if((task = ListExports[listp].origin) != ThisTask) { place = ListExports[listp].index; - off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; + off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; tmpPrimExch[off].Volume = SphP[place].Volume; @@ -262,14 +260,14 @@ void exchange_primitive_variables(void) #endif /* #ifdef MHD_POWELL */ #endif /* #ifdef MHD */ - tmpPrimExch[off].OldMass = SphP[place].OldMass; - tmpPrimExch[off].SurfaceArea = SphP[place].SurfaceArea; - tmpPrimExch[off].ActiveArea = SphP[place].ActiveArea; + tmpPrimExch[off].OldMass = SphP[place].OldMass; + tmpPrimExch[off].SurfaceArea = SphP[place].SurfaceArea; + tmpPrimExch[off].ActiveArea = SphP[place].ActiveArea; tmpPrimExch[off].TimeBinHydro = P[place].TimeBinHydro; #ifdef MAXSCALARS for(j = 0; j < N_Scalar; j++) - tmpPrimExch[off].Scalars[j] = *(MyFloat *) (((char *) (&SphP[place])) + scalar_elements[j].offset); + tmpPrimExch[off].Scalars[j] = *(MyFloat *)(((char *)(&SphP[place])) + scalar_elements[j].offset); #endif /* #ifdef MAXSCALARS */ tmpPrimExch[off].TimeLastPrimUpdate = SphP[place].TimeLastPrimUpdate; @@ -295,9 +293,10 @@ void exchange_primitive_variables(void) if(Mesh_Send_count[recvTask] > 0 || Mesh_Recv_count[recvTask] > 0) { /* get the particles */ - MPI_Sendrecv(&tmpPrimExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] - * sizeof(struct primexch), MPI_BYTE, recvTask, TAG_DENS_A, - &PrimExch[Mesh_Recv_offset[recvTask]], Mesh_Recv_count[recvTask] * sizeof(struct primexch), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&tmpPrimExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] * sizeof(struct primexch), MPI_BYTE, + recvTask, TAG_DENS_A, &PrimExch[Mesh_Recv_offset[recvTask]], + Mesh_Recv_count[recvTask] * sizeof(struct primexch), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); } } } @@ -307,7 +306,6 @@ void exchange_primitive_variables(void) TIMER_STOP(CPU_MESH_EXCHANGE); } - /*! \brief Communicate primitive variables and gradients across MPI tasks. * * This routine is called after gradient calculation. @@ -328,8 +326,8 @@ void exchange_primitive_variables_and_gradients(void) int i, j, p, task, off; int ngrp, recvTask, place; - tmpPrimExch = (struct primexch *) mymalloc("tmpPrimExch", Mesh_nexport * sizeof(struct primexch)); - tmpGradExch = (struct grad_data *) mymalloc("tmpGradExch", Mesh_nexport * sizeof(struct grad_data)); + tmpPrimExch = (struct primexch *)mymalloc("tmpPrimExch", Mesh_nexport * sizeof(struct primexch)); + tmpGradExch = (struct grad_data *)mymalloc("tmpGradExch", Mesh_nexport * sizeof(struct grad_data)); /* prepare data for export */ for(j = 0; j < NTask; j++) @@ -339,7 +337,8 @@ void exchange_primitive_variables_and_gradients(void) { p = List_InMesh[i]; - /* in case previous steps already lowered the Mass, update OldMass to yield together with metallicity vector conservative estimate of metal mass of each species contained in cell */ + /* in case previous steps already lowered the Mass, update OldMass to yield together with metallicity vector conservative + * estimate of metal mass of each species contained in cell */ if(P[p].Mass < SphP[p].OldMass) SphP[p].OldMass = P[p].Mass; @@ -349,10 +348,10 @@ void exchange_primitive_variables_and_gradients(void) if((task = ListExports[listp].origin) != ThisTask) { place = ListExports[listp].index; - off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; + off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; - tmpPrimExch[off].Volume = SphP[place].Volume; - tmpPrimExch[off].Density = SphP[place].Density; + tmpPrimExch[off].Volume = SphP[place].Volume; + tmpPrimExch[off].Density = SphP[place].Density; tmpPrimExch[off].Pressure = SphP[place].Pressure; #ifdef MHD @@ -364,23 +363,23 @@ void exchange_primitive_variables_and_gradients(void) #endif /* #ifdef MHD_POWELL */ #endif /* #ifdef MHD */ - tmpPrimExch[off].OldMass = SphP[place].OldMass; + tmpPrimExch[off].OldMass = SphP[place].OldMass; tmpPrimExch[off].SurfaceArea = SphP[place].SurfaceArea; - tmpPrimExch[off].ActiveArea = SphP[place].ActiveArea; + tmpPrimExch[off].ActiveArea = SphP[place].ActiveArea; tmpPrimExch[off].TimeBinHydro = P[place].TimeBinHydro; #ifdef MAXSCALARS for(j = 0; j < N_Scalar; j++) - tmpPrimExch[off].Scalars[j] = *(MyFloat *) (((char *) (&SphP[place])) + scalar_elements[j].offset); + tmpPrimExch[off].Scalars[j] = *(MyFloat *)(((char *)(&SphP[place])) + scalar_elements[j].offset); #endif /* #ifdef MAXSCALARS */ tmpPrimExch[off].TimeLastPrimUpdate = SphP[place].TimeLastPrimUpdate; for(j = 0; j < 3; j++) { - tmpPrimExch[off].VelGas[j] = P[place].Vel[j]; - tmpPrimExch[off].Center[j] = SphP[place].Center[j]; + tmpPrimExch[off].VelGas[j] = P[place].Vel[j]; + tmpPrimExch[off].Center[j] = SphP[place].Center[j]; tmpPrimExch[off].VelVertex[j] = SphP[place].VelVertex[j]; } @@ -402,13 +401,15 @@ void exchange_primitive_variables_and_gradients(void) if(Mesh_Send_count[recvTask] > 0 || Mesh_Recv_count[recvTask] > 0) { /* exchange the data */ - MPI_Sendrecv(&tmpPrimExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] - * sizeof(struct primexch), MPI_BYTE, recvTask, TAG_DENS_A, - &PrimExch[Mesh_Recv_offset[recvTask]], Mesh_Recv_count[recvTask] * sizeof(struct primexch), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - - MPI_Sendrecv(&tmpGradExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] - * sizeof(struct grad_data), MPI_BYTE, recvTask, TAG_HYDRO_A, - &GradExch[Mesh_Recv_offset[recvTask]], Mesh_Recv_count[recvTask] * sizeof(struct grad_data), MPI_BYTE, recvTask, TAG_HYDRO_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&tmpPrimExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] * sizeof(struct primexch), MPI_BYTE, + recvTask, TAG_DENS_A, &PrimExch[Mesh_Recv_offset[recvTask]], + Mesh_Recv_count[recvTask] * sizeof(struct primexch), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + + MPI_Sendrecv(&tmpGradExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] * sizeof(struct grad_data), MPI_BYTE, + recvTask, TAG_HYDRO_A, &GradExch[Mesh_Recv_offset[recvTask]], + Mesh_Recv_count[recvTask] * sizeof(struct grad_data), MPI_BYTE, recvTask, TAG_HYDRO_A, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); } } } @@ -421,7 +422,6 @@ void exchange_primitive_variables_and_gradients(void) /* note: because the sequence is the same as before, we don't have to do the sorts again */ } - /*! \brief Compare two data primexch compare objects. * * The following variables (most important first): @@ -435,22 +435,21 @@ void exchange_primitive_variables_and_gradients(void) */ int compare_primexch(const void *a, const void *b) { - if(((struct data_primexch_compare *) a)->task < ((struct data_primexch_compare *) b)->task) + if(((struct data_primexch_compare *)a)->task < ((struct data_primexch_compare *)b)->task) return -1; - if(((struct data_primexch_compare *) a)->task > ((struct data_primexch_compare *) b)->task) + if(((struct data_primexch_compare *)a)->task > ((struct data_primexch_compare *)b)->task) return +1; - if(((struct data_primexch_compare *) a)->index < ((struct data_primexch_compare *) b)->index) + if(((struct data_primexch_compare *)a)->index < ((struct data_primexch_compare *)b)->index) return -1; - if(((struct data_primexch_compare *) a)->index > ((struct data_primexch_compare *) b)->index) + if(((struct data_primexch_compare *)a)->index > ((struct data_primexch_compare *)b)->index) return +1; return 0; } - /*! \brief Communicates vertex velocity divergence data across MPI tasks. * * \return 0 @@ -466,10 +465,9 @@ void voronoi_update_ghost_velvertex(void) struct velvertex_data { MyFloat VelVertex[3]; - } - *tmpVelVertexExch, *tmpVelVertexRecv; + } * tmpVelVertexExch, *tmpVelVertexRecv; - tmpVelVertexExch = (struct velvertex_data *) mymalloc("tmpVelVertexExch", Mesh_nexport * sizeof(struct velvertex_data)); + tmpVelVertexExch = (struct velvertex_data *)mymalloc("tmpVelVertexExch", Mesh_nexport * sizeof(struct velvertex_data)); /* prepare data for export */ for(j = 0; j < NTask; j++) @@ -485,7 +483,7 @@ void voronoi_update_ghost_velvertex(void) if((task = ListExports[listp].origin) != ThisTask) { place = ListExports[listp].index; - off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; + off = Mesh_Send_offset[task] + Mesh_Send_count[task]++; for(j = 0; j < 3; j++) { @@ -505,12 +503,13 @@ void voronoi_update_ghost_velvertex(void) { if(Mesh_Send_count[recvTask] > 0 || Mesh_Recv_count[recvTask] > 0) { - tmpVelVertexRecv = (struct velvertex_data *) mymalloc("tmpVelVertexRecv", Mesh_Recv_count[recvTask] * sizeof(struct velvertex_data)); + tmpVelVertexRecv = + (struct velvertex_data *)mymalloc("tmpVelVertexRecv", Mesh_Recv_count[recvTask] * sizeof(struct velvertex_data)); /* get the values */ - MPI_Sendrecv(&tmpVelVertexExch[Mesh_Send_offset[recvTask]], - Mesh_Send_count[recvTask] * sizeof(struct velvertex_data), MPI_BYTE, - recvTask, TAG_DENS_A, tmpVelVertexRecv, Mesh_Recv_count[recvTask] * sizeof(struct velvertex_data), MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&tmpVelVertexExch[Mesh_Send_offset[recvTask]], Mesh_Send_count[recvTask] * sizeof(struct velvertex_data), + MPI_BYTE, recvTask, TAG_DENS_A, tmpVelVertexRecv, Mesh_Recv_count[recvTask] * sizeof(struct velvertex_data), + MPI_BYTE, recvTask, TAG_DENS_A, MPI_COMM_WORLD, MPI_STATUS_IGNORE); for(i = 0; i < Mesh_Recv_count[recvTask]; i++) { diff --git a/src/mesh/voronoi/voronoi_ghost_search.c b/src/mesh/voronoi/voronoi_ghost_search.c index bcc9ee08953aae394008b7cdabe9634ad97c6975..6c147b7901d05008b84b41292dfb066faf92dfac 100644 --- a/src/mesh/voronoi/voronoi_ghost_search.c +++ b/src/mesh/voronoi/voronoi_ghost_search.c @@ -38,36 +38,31 @@ * maxdist, int target, int origin, int mode, int thread_id, * int numnodes, int *firstnode) * int count_undecided_tetras(tessellation * T) - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 24.05.2018 Prepared file for public release -- Rainer Weinberger */ - +#include <gsl/gsl_math.h> +#include <math.h> #include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> -#include <gsl/gsl_math.h> #include "../../main/allvars.h" #include "../../main/proto.h" #include "voronoi.h" - #if !defined(ONEDIMS) - static void voronoi_pick_up_additional_DP_points(void); - static tessellation *T; - /*! \brief Local data structure for collecting particle/cell data that is sent * to other processors if needed. Type called data_in and static * pointers DataIn and DataGet needed by generic_comm_helpers2. @@ -83,12 +78,11 @@ typedef struct #ifdef EXTENDED_GHOST_SEARCH unsigned char BitFlagList[NODELISTLENGTH]; -#endif /* #ifdef EXTENDED_GHOST_SEARCH */ +#endif /* #ifdef EXTENDED_GHOST_SEARCH */ } data_in; static data_in *DataGet, *DataIn; - /*! \brief Routine that fills the relevant particle/cell data into the input * structure defined above. Needed by generic_comm_helpers2. * @@ -98,10 +92,10 @@ static data_in *DataGet, *DataIn; * * \return void */ -static void particle2in(data_in * in, int i, int firstnode) +static void particle2in(data_in *in, int i, int firstnode) { - point *DP = T->DP; - tetra *DT = T->DT; + point *DP = T->DP; + tetra *DT = T->DT; tetra_center *DTC = T->DTC; int k, q; @@ -118,7 +112,7 @@ static void particle2in(data_in * in, int i, int firstnode) break; } } -#else /* #ifndef DOUBLE_STENCIL */ +#else /* #ifndef DOUBLE_STENCIL */ if(DP[DT[i].p[k]].flag_primary_triangle && DT[i].p[k] >= 0) { q = DT[i].p[k]; @@ -145,19 +139,17 @@ static void particle2in(data_in * in, int i, int firstnode) in->Firstnode = firstnode; } - /*! \brief Local data structure that holds results acquired on remote * processors. Type called data_out and static pointers DataResult and * DataOut needed by generic_comm_helpers2. */ typedef struct { - int Count; /* counts how many have been found */ + int Count; /* counts how many have been found */ } data_out; static data_out *DataResult, *DataOut; - /*! \brief Routine to store or combine result data. Needed by * generic_comm_helpers2. * @@ -169,33 +161,29 @@ static data_out *DataResult, *DataOut; * * \return void */ -static void out2particle(data_out * out, int i, int mode) +static void out2particle(data_out *out, int i, int mode) { if(mode == MODE_LOCAL_PARTICLES || mode == MODE_IMPORTED_PARTICLES) if(out->Count) T->DTF[i] -= (T->DTF[i] & 2); } - #include "../../utils/generic_comm_helpers2.h" - #ifdef EXTENDED_GHOST_SEARCH /*! Data structure for extended ghost search. */ static struct data_nodelist_special { unsigned char BitFlagList[NODELISTLENGTH]; -} *DataNodeListSpecial; +} * DataNodeListSpecial; #endif /* #ifdef EXTENDED_GHOST_SEARCH */ - static point *DP_Buffer; static int MaxN_DP_Buffer, N_DP_Buffer; static int NadditionalPoints; static int *send_count_new; - /*! \brief Routine that defines what to do with local particles. * * Calls the *_evaluate function in MODE_LOCAL_PARTICLES. @@ -223,14 +211,14 @@ static void kernel_local(void) if(i >= T->Ndt) break; - if((T->DTF[i] & 2) == 0) /* DT that is not flagged as tested ok */ + if((T->DTF[i] & 2) == 0) /* DT that is not flagged as tested ok */ { - T->DTF[i] |= 2; /* if we find a particle, need to clear this flag again! */ + T->DTF[i] |= 2; /* if we find a particle, need to clear this flag again! */ point *DP = T->DP; tetra *DT = T->DT; - if(DT[i].t[0] < 0) /* deleted ? */ + if(DT[i].t[0] < 0) /* deleted ? */ continue; if(DT[i].p[0] == DPinfinity || DT[i].p[1] == DPinfinity || DT[i].p[2] == DPinfinity) @@ -255,12 +243,12 @@ static void kernel_local(void) } } - if(j == (NUMDIMS + 1)) /* this triangle does not have a local point. No need to test it */ + if(j == (NUMDIMS + 1)) /* this triangle does not have a local point. No need to test it */ continue; if(q == -1) terminate("q==-1"); -#else /* #ifndef DOUBLE_STENCIL */ +#else /* #ifndef DOUBLE_STENCIL */ /* here comes the check for a double stencil */ for(j = 0, q = -1; j < (NUMDIMS + 1); j++) { @@ -271,7 +259,9 @@ static void kernel_local(void) } } - if(j == (NUMDIMS + 1)) /* this triangle does not have a point which is not at least neighbor to a primary point. No need to test it */ + if(j == + (NUMDIMS + + 1)) /* this triangle does not have a point which is not at least neighbor to a primary point. No need to test it */ continue; if(q == -1) @@ -283,7 +273,6 @@ static void kernel_local(void) } } - /*! \brief Routine that defines what to do with imported particles. * * Calls the *_evaluate function in MODE_IMPORTED_PARTICLES. @@ -309,14 +298,13 @@ static void kernel_imported(void) } } - /*! \brief Main routine to perform ghost search. * * \param[in, out] TT Pointer to tessellation. * * \return Number of additional points. */ -int voronoi_ghost_search(tessellation * TT) +int voronoi_ghost_search(tessellation *TT) { T = TT; int j, ndone, ndone_flag; @@ -325,10 +313,10 @@ int voronoi_ghost_search(tessellation * TT) /* allocate buffers to arrange communication */ - send_count_new = (int *) mymalloc_movable(&send_count_new, "send_count_new", NTask * sizeof(int)); + send_count_new = (int *)mymalloc_movable(&send_count_new, "send_count_new", NTask * sizeof(int)); MaxN_DP_Buffer = T->Indi.AllocFacN_DP_Buffer; - DP_Buffer = (point *) mymalloc_movable(&DP_Buffer, "DP_Buffer", MaxN_DP_Buffer * sizeof(point)); + DP_Buffer = (point *)mymalloc_movable(&DP_Buffer, "DP_Buffer", MaxN_DP_Buffer * sizeof(point)); #ifdef DOUBLE_STENCIL { @@ -349,7 +337,7 @@ int voronoi_ghost_search(tessellation * TT) break; } - if(j != (NUMDIMS + 1)) /* this triangle does have a local point, so mark all its points */ + if(j != (NUMDIMS + 1)) /* this triangle does have a local point, so mark all its points */ { for(j = 0; j < (NUMDIMS + 1); j++) DP[DT[i].p[j]].flag_primary_triangle = 1; @@ -400,7 +388,6 @@ int voronoi_ghost_search(tessellation * TT) return NadditionalPoints; } - /*! \brief Gets additional Delaunay points. * * \return void @@ -436,7 +423,7 @@ static void voronoi_pick_up_additional_DP_points(void) MPI_Alltoall(Send_count, 1, MPI_INT, Recv_count, 1, MPI_INT, MPI_COMM_WORLD); Recv_offset[0] = 0; - nimport = Recv_count[0]; + nimport = Recv_count[0]; for(int j = 1; j < NTask; j++) { @@ -469,9 +456,9 @@ static void voronoi_pick_up_additional_DP_points(void) if(Send_count[recvTask] > 0 || Recv_count[recvTask] > 0) { /* get the particles */ - MPI_Sendrecv(&DP_Buffer[Send_offset[recvTask]], Send_count[recvTask] * sizeof(point), - MPI_BYTE, recvTask, TAG_DENS_B, - &T->DP[T->Ndp + Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(point), MPI_BYTE, recvTask, TAG_DENS_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Sendrecv(&DP_Buffer[Send_offset[recvTask]], Send_count[recvTask] * sizeof(point), MPI_BYTE, recvTask, TAG_DENS_B, + &T->DP[T->Ndp + Recv_offset[recvTask]], Recv_count[recvTask] * sizeof(point), MPI_BYTE, recvTask, + TAG_DENS_B, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } } } @@ -483,7 +470,6 @@ static void voronoi_pick_up_additional_DP_points(void) Largest_N_DP_Buffer = N_DP_Buffer; } - /*! \brief Evaluate function for voronoi_ghost_search. * * Called in both mode local particles and then in mode imported particles. @@ -496,7 +482,7 @@ static void voronoi_pick_up_additional_DP_points(void) * * \return 0 */ -int voronoi_ghost_search_evaluate(tessellation * T, int target, int mode, int q, int thread_id) +int voronoi_ghost_search_evaluate(tessellation *T, int target, int mode, int q, int thread_id) { int origin, numnodes, *firstnode; int numngb; @@ -506,33 +492,33 @@ int voronoi_ghost_search_evaluate(tessellation * T, int target, int mode, int q, if(mode == MODE_LOCAL_PARTICLES) { - pos[0] = T->DTC[target].cx; - pos[1] = T->DTC[target].cy; - pos[2] = T->DTC[target].cz; + pos[0] = T->DTC[target].cx; + pos[1] = T->DTC[target].cy; + pos[2] = T->DTC[target].cz; refpos[0] = T->DP[q].x; refpos[1] = T->DP[q].y; refpos[2] = T->DP[q].z; #ifndef DOUBLE_STENCIL maxdist = SphP[T->DP[q].index].Hsml; -#else /* #ifndef DOUBLE_STENCIL */ +#else /* #ifndef DOUBLE_STENCIL */ maxdist = T->DP[q].Hsml; #endif /* #ifndef DOUBLE_STENCIL #else */ origin = ThisTask; - numnodes = 1; + numnodes = 1; firstnode = NULL; } else { /* note: we do not use a pointer here to VoroDataGet[target].Pos, because VoroDataGet may be moved in a realloc operation */ - pos[0] = DataGet[target].Pos[0]; - pos[1] = DataGet[target].Pos[1]; - pos[2] = DataGet[target].Pos[2]; + pos[0] = DataGet[target].Pos[0]; + pos[1] = DataGet[target].Pos[1]; + pos[2] = DataGet[target].Pos[2]; refpos[0] = DataGet[target].RefPos[0]; refpos[1] = DataGet[target].RefPos[1]; refpos[2] = DataGet[target].RefPos[2]; - maxdist = DataGet[target].MaxDist; - origin = DataGet[target].Origin; + maxdist = DataGet[target].MaxDist; + origin = DataGet[target].Origin; generic_get_numnodes(target, &numnodes, &firstnode); } @@ -545,7 +531,9 @@ int voronoi_ghost_search_evaluate(tessellation * T, int target, int mode, int q, if(mode == MODE_LOCAL_PARTICLES) if(maxdist < 2 * h) - T->DTF[target] -= (T->DTF[target] & 2); /* since we restrict the search radius, we are not guaranteed to search the full circumcircle of the triangle */ + T->DTF[target] -= + (T->DTF[target] & + 2); /* since we restrict the search radius, we are not guaranteed to search the full circumcircle of the triangle */ numngb = ngb_treefind_ghost_search(T, pos, refpos, h, maxdist, target, origin, mode, thread_id, numnodes, firstnode); @@ -559,8 +547,7 @@ int voronoi_ghost_search_evaluate(tessellation * T, int target, int mode, int q, return 0; } - -#ifdef EXTENDED_GHOST_SEARCH /* this allowes for mirrored images in a full 3x3 grid in terms of the principal domain */ +#ifdef EXTENDED_GHOST_SEARCH /* this allowes for mirrored images in a full 3x3 grid in terms of the principal domain */ /*! \brief Tree-search algorithm for ghost cells in EXTENDED_GHOST_SEARCH mode. * * \param[in] T Pointer to tessellation. @@ -578,8 +565,8 @@ int voronoi_ghost_search_evaluate(tessellation * T, int target, int mode, int q, * * \return Number of points found. */ -int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDouble refpos[3], - MyFloat hsml, MyFloat maxdist, int target, int origin, int *startnode, int bitflags, int mode, int *nexport, int *nsend_local) +int ngb_treefind_ghost_search(tessellation *T, MyDouble searchcenter[3], MyDouble refpos[3], MyFloat hsml, MyFloat maxdist, int target, + int origin, int *startnode, int bitflags, int mode, int *nexport, int *nsend_local) { int i, numngb, no, p, task, nexport_save, ndp_save, nadditionalpoints_save; int image_flag; @@ -593,10 +580,10 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub MyFloat refsearch_min[3], refsearch_max[3]; nadditionalpoints_save = NadditionalPoints; - ndp_save = T->Ndp; - nexport_save = *nexport; + ndp_save = T->Ndp; + nexport_save = *nexport; - numngb = 0; + numngb = 0; mindistance = 1.0e70; int repx, repy, repz = 0; @@ -645,7 +632,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub repz_A = repz_B = 0; } - hsml2 = hsml * hsml; + hsml2 = hsml * hsml; maxdist2 = maxdist * maxdist; for(repx = repx_A; repx <= repx_B; repx++) @@ -654,9 +641,9 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub for(repz = repz_A; repz <= repz_B; repz++) #endif /* #if !defined(TWODIMS) */ { - image_flag = 0; /* for each coordinate there are three possibilities. - We encodee them to basis three, i.e. x*3^0 + y*3^1 + z*3^2 - */ + image_flag = 0; /* for each coordinate there are three possibilities. + We encodee them to basis three, i.e. x*3^0 + y*3^1 + z*3^2 + */ if(repx == 0) { newcenter[0] = searchcenter[0]; @@ -667,20 +654,20 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub #ifndef REFLECTIVE_X newcenter[0] = searchcenter[0] - boxSize_X; newrefpos[0] = refpos[0] - boxSize_X; -#else /* #ifndef REFLECTIVE_X */ - newcenter[0] = -searchcenter[0]; - newrefpos[0] = -refpos[0]; +#else /* #ifndef REFLECTIVE_X */ + newcenter[0] = -searchcenter[0]; + newrefpos[0] = -refpos[0]; #endif /* #ifndef REFLECTIVE_X #else */ image_flag += 1; } - else /* repx == 1 */ + else /* repx == 1 */ { #ifndef REFLECTIVE_X newcenter[0] = searchcenter[0] + boxSize_X; newrefpos[0] = refpos[0] + boxSize_X; -#else /* #ifndef REFLECTIVE_X */ - newcenter[0] = -searchcenter[0] + 2 * boxSize_X; - newrefpos[0] = -refpos[0] + 2 * boxSize_X; +#else /* #ifndef REFLECTIVE_X */ + newcenter[0] = -searchcenter[0] + 2 * boxSize_X; + newrefpos[0] = -refpos[0] + 2 * boxSize_X; #endif /* #ifndef REFLECTIVE_X #else */ image_flag += 2; } @@ -695,20 +682,20 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub #ifndef REFLECTIVE_Y newcenter[1] = searchcenter[1] - boxSize_Y; newrefpos[1] = refpos[1] - boxSize_Y; -#else /* #ifndef REFLECTIVE_Y */ - newcenter[1] = -searchcenter[1]; - newrefpos[1] = -refpos[1]; +#else /* #ifndef REFLECTIVE_Y */ + newcenter[1] = -searchcenter[1]; + newrefpos[1] = -refpos[1]; #endif /* #ifndef REFLECTIVE_Y #else */ image_flag += 1 * 3; } - else /* repy == 1 */ + else /* repy == 1 */ { #ifndef REFLECTIVE_Y newcenter[1] = searchcenter[1] + boxSize_Y; newrefpos[1] = refpos[1] + boxSize_Y; -#else /* #ifndef REFLECTIVE_Y */ - newcenter[1] = -searchcenter[1] + 2 * boxSize_Y; - newrefpos[1] = -refpos[1] + 2 * boxSize_Y; +#else /* #ifndef REFLECTIVE_Y */ + newcenter[1] = -searchcenter[1] + 2 * boxSize_Y; + newrefpos[1] = -refpos[1] + 2 * boxSize_Y; #endif /* #ifndef REFLECTIVE_Y #else */ image_flag += 2 * 3; } @@ -724,18 +711,18 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub #ifndef REFLECTIVE_Z newcenter[2] = searchcenter[2] - boxSize_Z; newrefpos[2] = refpos[2] - boxSize_Z; -#else /* #ifndef REFLECTIVE_Z */ +#else /* #ifndef REFLECTIVE_Z */ newcenter[2] = -searchcenter[2]; newrefpos[2] = -refpos[2]; #endif /* #ifndef REFLECTIVE_Z #else */ image_flag += 1 * 9; } - else /* repz == 1 */ + else /* repz == 1 */ { #ifndef REFLECTIVE_Z newcenter[2] = searchcenter[1] + boxSize_Z; newrefpos[2] = refpos[1] + boxSize_Z; -#else /* #ifndef REFLECTIVE_Z */ +#else /* #ifndef REFLECTIVE_Z */ newcenter[2] = -searchcenter[2] + 2 * boxSize_Z; newrefpos[2] = -refpos[2] + 2 * boxSize_Z; #endif /* #ifndef REFLECTIVE_Z #else */ @@ -745,8 +732,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub for(i = 0; i < 3; i++) { - search_min[i] = newcenter[i] - hsml; - search_max[i] = newcenter[i] + hsml; + search_min[i] = newcenter[i] - hsml; + search_max[i] = newcenter[i] + hsml; refsearch_min[i] = newrefpos[i] - maxdist; refsearch_max[i] = newrefpos[i] + maxdist; } @@ -758,22 +745,22 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub terminate("problem"); } - no = *startnode; + no = *startnode; count = 0; while(no >= 0) { count++; - if(no < Ngb_MaxPart) /* single particle */ + if(no < Ngb_MaxPart) /* single particle */ { - p = no; + p = no; no = Ngb_Nextnode[no]; if(P[p].Type > 0) continue; if(P[p].Mass == 0 && P[p].ID == 0) - continue; /* skip cells that have been swallowed or dissolved */ + continue; /* skip cells that have been swallowed or dissolved */ dx = P[p].Pos[0] - newcenter[0]; dy = P[p].Pos[1] - newcenter[1]; @@ -797,8 +784,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub if(Ngb_Marker[p] != Ngb_MarkerValue) { - Ngb_Marker[p] = Ngb_MarkerValue; - List_P[p].firstexport = -1; + Ngb_Marker[p] = Ngb_MarkerValue; + List_P[p].firstexport = -1; List_P[p].currentexport = -1; } @@ -819,21 +806,21 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub } if(listp >= 0) - if((ListExports[listp].image_bits & (1 << image_flag))) /* already in list */ + if((ListExports[listp].image_bits & (1 << image_flag))) /* already in list */ continue; } else { - if((ListExports[List_P[p].currentexport].image_bits & (1 << image_flag))) /* already in list */ + if((ListExports[List_P[p].currentexport].image_bits & (1 << image_flag))) /* already in list */ continue; } } /* here we have found a new closest particle that has not been inserted yet */ - numngb = 1; - mindistance = thisdistance; - min_p = p; + numngb = 1; + mindistance = thisdistance; + min_p = p; min_imageflag = image_flag; /* determine the point coordinates in min_x, min_y, min_z */ @@ -843,16 +830,16 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub { #ifndef REFLECTIVE_X min_x = P[p].Pos[0] + boxSize_X; -#else /* #ifndef REFLECTIVE_X */ - min_x = -P[p].Pos[0]; +#else /* #ifndef REFLECTIVE_X */ + min_x = -P[p].Pos[0]; #endif /* #ifndef REFLECTIVE_X #else */ } else if(repx == 1) { #ifndef REFLECTIVE_X min_x = P[p].Pos[0] - boxSize_X; -#else /* #ifndef REFLECTIVE_X */ - min_x = -P[p].Pos[0] + 2 * boxSize_X; +#else /* #ifndef REFLECTIVE_X */ + min_x = -P[p].Pos[0] + 2 * boxSize_X; #endif /* #ifndef REFLECTIVE_X #else */ } @@ -862,20 +849,19 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub { #ifndef REFLECTIVE_Y min_y = P[p].Pos[1] + boxSize_Y; -#else /* #ifndef REFLECTIVE_Y */ - min_y = -P[p].Pos[1]; +#else /* #ifndef REFLECTIVE_Y */ + min_y = -P[p].Pos[1]; #endif /* #ifndef REFLECTIVE_Y #else */ } else if(repy == 1) { #ifndef REFLECTIVE_Y min_y = P[p].Pos[1] - boxSize_Y; -#else /* #ifndef REFLECTIVE_Y */ - min_y = -P[p].Pos[1] + 2 * boxSize_Y; +#else /* #ifndef REFLECTIVE_Y */ + min_y = -P[p].Pos[1] + 2 * boxSize_Y; #endif /* #ifndef REFLECTIVE_Y #else */ } - if(repz == 0) min_z = P[p].Pos[2]; #if !defined(TWODIMS) @@ -883,7 +869,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub { #ifndef REFLECTIVE_Z min_z = P[p].Pos[2] + boxSize_Z; -#else /* #ifndef REFLECTIVE_Z */ +#else /* #ifndef REFLECTIVE_Z */ min_z = -P[p].Pos[2]; #endif /* #ifndef REFLECTIVE_Z #else */ } @@ -891,24 +877,25 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub { #ifndef REFLECTIVE_Z min_z = P[p].Pos[2] - boxSize_Z; -#else /* #ifndef REFLECTIVE_Z */ +#else /* #ifndef REFLECTIVE_Z */ min_z = -P[p].Pos[2] + 2 * boxSize_Z; #endif /* #ifndef REFLECTIVE_Z #else */ } #endif /* #if !defined(TWODIMS) */ } - else if(no < Ngb_MaxPart + Ngb_MaxNodes) /* internal node */ + else if(no < Ngb_MaxPart + Ngb_MaxNodes) /* internal node */ { if(mode == 1) { - if(no < Ngb_FirstNonTopLevelNode) /* we reached a top-level node again, which means that we are done with the branch */ + if(no < Ngb_FirstNonTopLevelNode) /* we reached a top-level node again, which means that we are done with the + branch */ { break; } } current = &Ngb_Nodes[no]; - no = current->u.d.sibling; /* in case the node can be discarded */ + no = current->u.d.sibling; /* in case the node can be discarded */ if(search_min[0] > current->u.d.range_max[0]) continue; @@ -937,18 +924,18 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub if(refsearch_max[2] < current->u.d.range_min[2]) continue; - no = current->u.d.nextnode; /* ok, we need to open the node */ + no = current->u.d.nextnode; /* ok, we need to open the node */ } - else /* pseudo particle */ + else /* pseudo particle */ { if(mode == 1) terminate("mode == 1"); - if(target >= 0) /* if no target is given, export will not occur */ + if(target >= 0) /* if no target is given, export will not occur */ { if(Exportflag[task = DomainTask[no - (Ngb_MaxPart + Ngb_MaxNodes)]] != target) { - Exportflag[task] = target; + Exportflag[task] = target; Exportnodecount[task] = NODELISTLENGTH; } @@ -956,28 +943,30 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub { if(*nexport >= All.BunchSize) { - T->Ndp = ndp_save; + T->Ndp = ndp_save; NadditionalPoints = nadditionalpoints_save; - *nexport = nexport_save; + *nexport = nexport_save; if(nexport_save == 0) - terminate("nexport_save == 0"); /* in this case, the buffer is too small to process even a single particle */ + terminate( + "nexport_save == 0"); /* in this case, the buffer is too small to process even a single particle */ for(task = 0; task < NTask; task++) nsend_local[task] = 0; for(no = 0; no < nexport_save; no++) nsend_local[DataIndexTable[no].Task]++; return -1; } - Exportnodecount[task] = 0; - Exportindex[task] = *nexport; - DataIndexTable[*nexport].Task = task; - DataIndexTable[*nexport].Index = target; + Exportnodecount[task] = 0; + Exportindex[task] = *nexport; + DataIndexTable[*nexport].Task = task; + DataIndexTable[*nexport].Index = target; DataIndexTable[*nexport].IndexGet = *nexport; - *nexport = *nexport + 1; + *nexport = *nexport + 1; nsend_local[task]++; } DataNodeListSpecial[Exportindex[task]].BitFlagList[Exportnodecount[task]] = image_flag; - DataNodeListSpecial[Exportindex[task]].NodeList[Exportnodecount[task]++] = Ngb_DomainNodeIndex[no - (Ngb_MaxPart + Ngb_MaxNodes)]; + DataNodeListSpecial[Exportindex[task]].NodeList[Exportnodecount[task]++] = + Ngb_DomainNodeIndex[no - (Ngb_MaxPart + Ngb_MaxNodes)]; if(Exportnodecount[task] < NODELISTLENGTH) DataNodeListSpecial[Exportindex[task]].NodeList[Exportnodecount[task]] = -1; @@ -999,8 +988,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub if(Ngb_Marker[p] != Ngb_MarkerValue) { - Ngb_Marker[p] = Ngb_MarkerValue; - List_P[p].firstexport = -1; + Ngb_Marker[p] = Ngb_MarkerValue; + List_P[p].firstexport = -1; List_P[p].currentexport = -1; } @@ -1024,7 +1013,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub T->Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = T->Indi.AllocFacNinlist; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, T->Indi.AllocFacNinlist); + printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, + T->Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -1032,12 +1022,12 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub terminate("Ninlist >= MaxNinlist"); } - List_P[p].currentexport = Ninlist++; + List_P[p].currentexport = Ninlist++; ListExports[List_P[p].currentexport].image_bits = 0; ListExports[List_P[p].currentexport].nextexport = -1; - ListExports[List_P[p].currentexport].origin = origin; - ListExports[List_P[p].currentexport].index = p; - ListExports[listp].nextexport = List_P[p].currentexport; + ListExports[List_P[p].currentexport].origin = origin; + ListExports[List_P[p].currentexport].index = p; + ListExports[listp].nextexport = List_P[p].currentexport; break; } listp = ListExports[listp].nextexport; @@ -1053,7 +1043,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub T->Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = T->Indi.AllocFacNinlist; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, T->Indi.AllocFacNinlist); + printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, + T->Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -1066,8 +1057,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub List_P[p].currentexport = List_P[p].firstexport = Ninlist++; ListExports[List_P[p].currentexport].image_bits = 0; ListExports[List_P[p].currentexport].nextexport = -1; - ListExports[List_P[p].currentexport].origin = origin; - ListExports[List_P[p].currentexport].index = p; + ListExports[List_P[p].currentexport].origin = origin; + ListExports[List_P[p].currentexport].index = p; } if((ListExports[List_P[p].currentexport].image_bits & (1 << image_flag))) @@ -1100,23 +1091,23 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub SphP[p].ActiveArea = 0; point *dp = &T->DP[T->Ndp]; - dp->x = min_x; - dp->y = min_y; - dp->z = min_z; - dp->task = ThisTask; - dp->ID = P[p].ID; + dp->x = min_x; + dp->y = min_y; + dp->z = min_z; + dp->task = ThisTask; + dp->ID = P[p].ID; if(image_flag) - dp->index = p + NumGas; /* this is a replicated/mirrored local point */ + dp->index = p + NumGas; /* this is a replicated/mirrored local point */ else - dp->index = p; /* this is actually a local point that wasn't made part of the mesh yet */ + dp->index = p; /* this is actually a local point that wasn't made part of the mesh yet */ dp->originalindex = p; - dp->timebin = P[p].TimeBinHydro; - dp->image_flags = (1 << image_flag); + dp->timebin = P[p].TimeBinHydro; + dp->image_flags = (1 << image_flag); #ifdef DOUBLE_STENCIL - dp->Hsml = SphP[p].Hsml; + dp->Hsml = SphP[p].Hsml; dp->first_connection = -1; - dp->last_connection = -1; + dp->last_connection = -1; #endif /* #ifdef DOUBLE_STENCIL */ T->Ndp++; NadditionalPoints++; @@ -1131,9 +1122,10 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub T->Indi.AllocFacN_DP_Buffer *= ALLOC_INCREASE_FACTOR; MaxN_DP_Buffer = T->Indi.AllocFacN_DP_Buffer; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxN_DP_Buffer=%d Indi.AllocFacN_DP_Buffer=%g\n", ThisTask, MaxN_DP_Buffer, T->Indi.AllocFacN_DP_Buffer); + printf("Task=%d: increase memory allocation, MaxN_DP_Buffer=%d Indi.AllocFacN_DP_Buffer=%g\n", ThisTask, MaxN_DP_Buffer, + T->Indi.AllocFacN_DP_Buffer); #endif /* #ifdef VERBOSE */ - DP_Buffer = (point *) myrealloc_movable(DP_Buffer, MaxN_DP_Buffer * sizeof(point)); + DP_Buffer = (point *)myrealloc_movable(DP_Buffer, MaxN_DP_Buffer * sizeof(point)); if(N_DP_Buffer >= MaxN_DP_Buffer) terminate("(N_DP_Buffer >= MaxN_DP_Buffer"); @@ -1141,19 +1133,19 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub SphP[p].ActiveArea = 0; - DP_Buffer[N_DP_Buffer].x = min_x; - DP_Buffer[N_DP_Buffer].y = min_y; - DP_Buffer[N_DP_Buffer].z = min_z; - DP_Buffer[N_DP_Buffer].ID = P[p].ID; - DP_Buffer[N_DP_Buffer].task = ThisTask; - DP_Buffer[N_DP_Buffer].index = p; + DP_Buffer[N_DP_Buffer].x = min_x; + DP_Buffer[N_DP_Buffer].y = min_y; + DP_Buffer[N_DP_Buffer].z = min_z; + DP_Buffer[N_DP_Buffer].ID = P[p].ID; + DP_Buffer[N_DP_Buffer].task = ThisTask; + DP_Buffer[N_DP_Buffer].index = p; DP_Buffer[N_DP_Buffer].originalindex = p; - DP_Buffer[N_DP_Buffer].timebin = P[p].TimeBinHydro; - DP_Buffer[N_DP_Buffer].image_flags = (1 << image_flag); + DP_Buffer[N_DP_Buffer].timebin = P[p].TimeBinHydro; + DP_Buffer[N_DP_Buffer].image_flags = (1 << image_flag); #ifdef DOUBLE_STENCIL - DP_Buffer[N_DP_Buffer].Hsml = SphP[p].Hsml; + DP_Buffer[N_DP_Buffer].Hsml = SphP[p].Hsml; DP_Buffer[N_DP_Buffer].first_connection = -1; - DP_Buffer[N_DP_Buffer].last_connection = -1; + DP_Buffer[N_DP_Buffer].last_connection = -1; #endif /* #ifdef DOUBLE_STENCIL */ send_count_new[origin]++; N_DP_Buffer++; @@ -1165,7 +1157,6 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub #else /* #ifdef EXTENDED_GHOST_SEARCH */ - /*! \brief Tree-search algorithm for ghost cells without EXTENDED_GHOST_SEARCH. * * \param[in] T Pointer to tessellation. @@ -1182,8 +1173,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub * * \return Number of points found. */ -int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDouble refpos[3], MyFloat hsml, MyFloat maxdist, int target, int origin, int mode, int thread_id, int numnodes, - int *firstnode) +int ngb_treefind_ghost_search(tessellation *T, MyDouble searchcenter[3], MyDouble refpos[3], MyFloat hsml, MyFloat maxdist, int target, + int origin, int mode, int thread_id, int numnodes, int *firstnode) { int i, k, numngb, no, p; int image_flag = 0; @@ -1210,9 +1201,9 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub search_min_Ladd[0] = search_min[0] + boxSize_X; refsearch_max_Lsub[0] = refsearch_max[0] - boxSize_X; refsearch_min_Ladd[0] = refsearch_min[0] + boxSize_X; -#else /* #if !defined(REFLECTIVE_X) */ - search_max_Lsub[0] = 2 * boxSize_X - search_max[0]; - search_min_Ladd[0] = -search_min[0]; +#else /* #if !defined(REFLECTIVE_X) */ + search_max_Lsub[0] = 2 * boxSize_X - search_max[0]; + search_min_Ladd[0] = -search_min[0]; refsearch_max_Lsub[0] = 2 * boxSize_X - refsearch_max[0]; refsearch_min_Ladd[0] = -refsearch_min[0]; #endif /* #if !defined(REFLECTIVE_X) #else */ @@ -1222,9 +1213,9 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub search_min_Ladd[1] = search_min[1] + boxSize_Y; refsearch_max_Lsub[1] = refsearch_max[1] - boxSize_Y; refsearch_min_Ladd[1] = refsearch_min[1] + boxSize_Y; -#else /* #if !defined(REFLECTIVE_Y) */ - search_max_Lsub[1] = 2 * boxSize_Y - search_max[1]; - search_min_Ladd[1] = -search_min[1]; +#else /* #if !defined(REFLECTIVE_Y) */ + search_max_Lsub[1] = 2 * boxSize_Y - search_max[1]; + search_min_Ladd[1] = -search_min[1]; refsearch_max_Lsub[1] = 2 * boxSize_Y - refsearch_max[1]; refsearch_min_Ladd[1] = -refsearch_min[1]; #endif /* #if !defined(REFLECTIVE_Y) #else */ @@ -1234,9 +1225,9 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub search_min_Ladd[2] = search_min[2] + boxSize_Z; refsearch_max_Lsub[2] = refsearch_max[2] - boxSize_Z; refsearch_min_Ladd[2] = refsearch_min[2] + boxSize_Z; -#else /* #if !defined(REFLECTIVE_Z) */ - search_max_Lsub[2] = 2 * boxSize_Z - search_max[2]; - search_min_Ladd[2] = -search_min[2]; +#else /* #if !defined(REFLECTIVE_Z) */ + search_max_Lsub[2] = 2 * boxSize_Z - search_max[2]; + search_min_Ladd[2] = -search_min[2]; refsearch_max_Lsub[2] = 2 * boxSize_Z - refsearch_max[2]; refsearch_min_Ladd[2] = -refsearch_min[2]; #endif /* #if !defined(REFLECTIVE_Z) #else */ @@ -1256,7 +1247,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub { if(mode == MODE_LOCAL_PARTICLES) { - no = Ngb_MaxPart; /* root node */ + no = Ngb_MaxPart; /* root node */ #ifdef EXTENDED_GHOST_SEARCH bitflags = 0; @@ -1269,13 +1260,13 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub #ifdef EXTENDED_GHOST_SEARCH bitflags = first_bitflag[k]; #endif /* #ifdef EXTENDED_GHOST_SEARCH */ - no = Ngb_Nodes[no].u.d.nextnode; /* open it */ + no = Ngb_Nodes[no].u.d.nextnode; /* open it */ } while(no >= 0) { count++; - if(no < Ngb_MaxPart) /* single particle */ + if(no < Ngb_MaxPart) /* single particle */ { p = no; no = Ngb_Nextnode[no]; @@ -1284,7 +1275,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub continue; if(P[p].Mass == 0 && P[p].ID == 0) - continue; /* skip cells that have been swallowed or eliminated */ + continue; /* skip cells that have been swallowed or eliminated */ if(P[p].Ti_Current != All.Ti_Current) { @@ -1293,8 +1284,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub offx = offy = offz = 0; - image_flag = 0; /* for each coordinates there are three possibilities. We - encode them to basis three, i.e. x*3^0 + y*3^1 + z*3^2 */ + image_flag = 0; /* for each coordinates there are three possibilities. We + encode them to basis three, i.e. x*3^0 + y*3^1 + z*3^2 */ #if !defined(REFLECTIVE_X) if(P[p].Pos[0] - refpos[0] < -boxHalf_X) @@ -1352,7 +1343,6 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub for(repz = -1; repz <= 1; repz++, offz = 0) #endif /* #if defined(REFLECTIVE_Z) && !defined(TWODIMS) */ { - image_flag = image_flag_periodic_bnds; x = P[p].Pos[0]; @@ -1373,7 +1363,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub x = -x; #endif /* #if defined(REFLECTIVE_X) */ -#if defined(REFLECTIVE_Y) +#if defined(REFLECTIVE_Y) if(repy == 1) { offy = 2 * boxSize_Y; @@ -1387,7 +1377,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub y = -y; #endif /* #if defined(REFLECTIVE_Y) */ -#if defined(REFLECTIVE_Z) && !defined(TWODIMS) +#if defined(REFLECTIVE_Z) && !defined(TWODIMS) if(repz == 1) { offz = 2 * boxSize_Z; @@ -1449,12 +1439,12 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub } if(listp >= 0) - if((ListExports[listp].image_bits & (1 << image_flag))) /* already in list */ + if((ListExports[listp].image_bits & (1 << image_flag))) /* already in list */ continue; } else { - if((ListExports[List_P[p].currentexport].image_bits & (1 << image_flag))) /* already in list */ + if((ListExports[List_P[p].currentexport].image_bits & (1 << image_flag))) /* already in list */ continue; } } @@ -1474,16 +1464,17 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub } } } - else if(no < Ngb_MaxPart + Ngb_MaxNodes) /* internal node */ + else if(no < Ngb_MaxPart + Ngb_MaxNodes) /* internal node */ { if(mode == MODE_IMPORTED_PARTICLES) { - if(no < Ngb_FirstNonTopLevelNode) /* we reached a top-level node again, which means that we are done with the branch */ + if(no < + Ngb_FirstNonTopLevelNode) /* we reached a top-level node again, which means that we are done with the branch */ break; } current = &Ngb_Nodes[no]; - no = current->u.d.sibling; /* in case the node can be discarded */ + no = current->u.d.sibling; /* in case the node can be discarded */ if(current->Ti_Current != All.Ti_Current) { @@ -1495,7 +1486,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub continue; if(search_min_Ladd[0] > current->u.d.range_max[0] && search_max[0] < current->u.d.range_min[0]) continue; -#else /* #if !defined(REFLECTIVE_X) */ +#else /* #if !defined(REFLECTIVE_X) */ if(search_min[0] > current->u.d.range_max[0] && search_max_Lsub[0] > current->u.d.range_max[0]) continue; if(search_min_Ladd[0] < current->u.d.range_min[0] && search_max[0] < current->u.d.range_min[0]) @@ -1507,7 +1498,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub continue; if(search_min_Ladd[1] > current->u.d.range_max[1] && search_max[1] < current->u.d.range_min[1]) continue; -#else /* #if !defined(REFLECTIVE_Y) */ +#else /* #if !defined(REFLECTIVE_Y) */ if(search_min[1] > current->u.d.range_max[1] && search_max_Lsub[1] > current->u.d.range_max[1]) continue; if(search_min_Ladd[1] < current->u.d.range_min[1] && search_max[1] < current->u.d.range_min[1]) @@ -1519,21 +1510,21 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub continue; if(search_min_Ladd[2] > current->u.d.range_max[2] && search_max[2] < current->u.d.range_min[2]) continue; -#else /* #if !defined(REFLECTIVE_Z) */ +#else /* #if !defined(REFLECTIVE_Z) */ if(search_min[2] > current->u.d.range_max[2] && search_max_Lsub[2] > current->u.d.range_max[2]) continue; if(search_min_Ladd[2] < current->u.d.range_min[2] && search_max[2] < current->u.d.range_min[2]) continue; #endif /* #if !defined(REFLECTIVE_Z) #else */ - /* now deal with the search region of the reference point */ + /* now deal with the search region of the reference point */ #if !defined(REFLECTIVE_X) if(refsearch_min[0] > current->u.d.range_max[0] && refsearch_max_Lsub[0] < current->u.d.range_min[0]) continue; if(refsearch_min_Ladd[0] > current->u.d.range_max[0] && refsearch_max[0] < current->u.d.range_min[0]) continue; -#else /* #if !defined(REFLECTIVE_X) */ +#else /* #if !defined(REFLECTIVE_X) */ if(refsearch_min[0] > current->u.d.range_max[0] && refsearch_max_Lsub[0] > current->u.d.range_max[0]) continue; if(refsearch_min_Ladd[0] < current->u.d.range_min[0] && refsearch_max[0] < current->u.d.range_min[0]) @@ -1545,7 +1536,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub continue; if(refsearch_min_Ladd[1] > current->u.d.range_max[1] && refsearch_max[1] < current->u.d.range_min[1]) continue; -#else /* #if !defined(REFLECTIVE_Y) */ +#else /* #if !defined(REFLECTIVE_Y) */ if(refsearch_min[1] > current->u.d.range_max[1] && refsearch_max_Lsub[1] > current->u.d.range_max[1]) continue; if(refsearch_min_Ladd[1] < current->u.d.range_min[1] && refsearch_max[1] < current->u.d.range_min[1]) @@ -1557,16 +1548,16 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub continue; if(refsearch_min_Ladd[2] > current->u.d.range_max[2] && refsearch_max[2] < current->u.d.range_min[2]) continue; -#else /* #if !defined(REFLECTIVE_Z) */ +#else /* #if !defined(REFLECTIVE_Z) */ if(refsearch_min[2] > current->u.d.range_max[2] && refsearch_max_Lsub[2] > current->u.d.range_max[2]) continue; if(refsearch_min_Ladd[2] < current->u.d.range_min[2] && refsearch_max[2] < current->u.d.range_min[2]) continue; #endif /* #if !defined(REFLECTIVE_Z) #else */ - no = current->u.d.nextnode; /* ok, we need to open the node */ + no = current->u.d.nextnode; /* ok, we need to open the node */ } - else /* pseudo particle */ + else /* pseudo particle */ { if(mode == 1) terminate("mode == 1"); @@ -1574,7 +1565,7 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub if(mode == MODE_IMPORTED_PARTICLES) terminate("mode == MODE_IMPORTED_PARTICLES should not occur here"); - if(target >= 0) /* if no target is given, export will not occur */ + if(target >= 0) /* if no target is given, export will not occur */ ngb_treefind_export_node_threads(no, target, thread_id, image_flag); no = Ngb_Nextnode[no - Ngb_MaxNodes]; @@ -1616,7 +1607,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub T->Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = T->Indi.AllocFacNinlist; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, T->Indi.AllocFacNinlist); + printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, + T->Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -1645,7 +1637,8 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub T->Indi.AllocFacNinlist *= ALLOC_INCREASE_FACTOR; MaxNinlist = T->Indi.AllocFacNinlist; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, T->Indi.AllocFacNinlist); + printf("Task=%d: increase memory allocation, MaxNinlist=%d Indi.AllocFacNinlist=%g\n", ThisTask, MaxNinlist, + T->Indi.AllocFacNinlist); #endif /* #ifdef VERBOSE */ ListExports = myrealloc_movable(ListExports, MaxNinlist * sizeof(struct list_export_data)); @@ -1701,9 +1694,9 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub dp->task = ThisTask; dp->ID = P[p].ID; if(image_flag) - dp->index = p + NumGas; /* this is a replicated/mirrored local point */ + dp->index = p + NumGas; /* this is a replicated/mirrored local point */ else - dp->index = p; /* this is actually a local point that wasn't made part of the mesh yet */ + dp->index = p; /* this is actually a local point that wasn't made part of the mesh yet */ dp->originalindex = p; dp->timebin = P[p].TimeBinHydro; dp->image_flags = (1 << image_flag); @@ -1725,9 +1718,10 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub T->Indi.AllocFacN_DP_Buffer *= ALLOC_INCREASE_FACTOR; MaxN_DP_Buffer = T->Indi.AllocFacN_DP_Buffer; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxN_DP_Buffer=%d Indi.AllocFacN_DP_Buffer=%g\n", ThisTask, MaxN_DP_Buffer, T->Indi.AllocFacN_DP_Buffer); + printf("Task=%d: increase memory allocation, MaxN_DP_Buffer=%d Indi.AllocFacN_DP_Buffer=%g\n", ThisTask, MaxN_DP_Buffer, + T->Indi.AllocFacN_DP_Buffer); #endif /* #ifdef VERBOSE */ - DP_Buffer = (point *) myrealloc_movable(DP_Buffer, MaxN_DP_Buffer * sizeof(point)); + DP_Buffer = (point *)myrealloc_movable(DP_Buffer, MaxN_DP_Buffer * sizeof(point)); if(N_DP_Buffer >= MaxN_DP_Buffer) terminate("(N_DP_Buffer >= MaxN_DP_Buffer"); @@ -1757,17 +1751,15 @@ int ngb_treefind_ghost_search(tessellation * T, MyDouble searchcenter[3], MyDoub return numngb; } - #endif /* #ifdef EXTENDED_GHOST_SEARCH #else */ - /*! \brief Counts up undecided tetrahedra. * * \param[in] T Pointer to tessellation. * * \return (Local) number of undecided tetrahedra. */ -int count_undecided_tetras(tessellation * T) +int count_undecided_tetras(tessellation *T) { int i, count; @@ -1778,5 +1770,4 @@ int count_undecided_tetras(tessellation * T) return count; } - #endif /* #if !defined(ONEDIMS) */ diff --git a/src/mesh/voronoi/voronoi_gradients_lsf.c b/src/mesh/voronoi/voronoi_gradients_lsf.c index 19c205613b42aaa43c2c6d1010255e0f4f37a004..f85729d86ff28c40edbd8f7bb935e741df7ccd28 100644 --- a/src/mesh/voronoi/voronoi_gradients_lsf.c +++ b/src/mesh/voronoi/voronoi_gradients_lsf.c @@ -39,38 +39,31 @@ * double boundaryX(double dx) * double boundaryY(double dx) * double boundaryZ(double dx) - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 23.05.2018 Prepared file for public release -- Rainer Weinberger */ - #include "../../main/allvars.h" #include "../../main/proto.h" - #if !defined(ONEDIMS) - static double *minvalues, *maxvalues; - static void limit_gradients(); static void correct_for_reflective_boundaries(double *ValueOther, double Value, int type, unsigned int *image_flags); - static double boundaryX(double dx); static double boundaryY(double dy); static double boundaryZ(double dz); - #if defined(OUTPUT_DIVVEL) || defined(MHD) static void compute_divergences(); #endif /* #if defined(OUTPUT_DIVVEL) || defined(MHD) */ - /*! \brief Adds row to another one in matrix equation. * * Auxiliary routine to solve_matrix_problem. @@ -93,7 +86,6 @@ static void inline add_row(double X[NUMDIMS][NUMDIMS], double y[NUMDIMS], int so } } - /*! \brief Solve a matrix problem X*grad = y. * * Note that we know here that X is symmetric, and that we can pivot on the @@ -106,7 +98,7 @@ static void inline add_row(double X[NUMDIMS][NUMDIMS], double y[NUMDIMS], int so */ static void solve_matrix_problem(double X[NUMDIMS][NUMDIMS], double y[NUMDIMS], double grad[NUMDIMS]) { -#if NUMDIMS==2 +#if NUMDIMS == 2 int perm[NUMDIMS]; if(fabs(X[0][0]) > fabs(X[1][1])) @@ -153,7 +145,7 @@ static void solve_matrix_problem(double X[NUMDIMS][NUMDIMS], double y[NUMDIMS], if(fabs(X[perm[1]][perm[1]]) < fabs(X[perm[2]][perm[2]])) { - int p = perm[1]; + int p = perm[1]; perm[1] = perm[2]; perm[2] = p; } @@ -167,7 +159,6 @@ static void solve_matrix_problem(double X[NUMDIMS][NUMDIMS], double y[NUMDIMS], #endif /* #if NUMDIMS==2 #else */ } - /*! \brief Loop through all active cells and calculate gradients. * * \return void @@ -186,8 +177,7 @@ void calculate_gradients(void) double X[NUMDIMS][NUMDIMS]; /* input matrix */ double y[NUMDIMS]; /* input vector */ double grad[NUMDIMS]; /* output */ - } - *mdata; + } * mdata; mdata = mymalloc("mdata", N_Grad * sizeof(struct matrix_vec_data)); @@ -204,12 +194,13 @@ void calculate_gradients(void) minvalues[i * N_Grad + k] = +MAX_REAL_NUMBER; maxvalues[i * N_Grad + k] = -MAX_REAL_NUMBER; - if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || (grad_elements[k].type == GRADIENT_TYPE_VELZ)) + if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || + (grad_elements[k].type == GRADIENT_TYPE_VELZ)) { - Value[k] = *(MyFloat *) (((char *) (&P[i])) + grad_elements[k].offset) / All.cf_atime; + Value[k] = *(MyFloat *)(((char *)(&P[i])) + grad_elements[k].offset) / All.cf_atime; } else - Value[k] = *(MyFloat *) (((char *) (&SphP[i])) + grad_elements[k].offset); + Value[k] = *(MyFloat *)(((char *)(&SphP[i])) + grad_elements[k].offset); } MyDouble *Center = SphP[i].Center; @@ -231,8 +222,8 @@ void calculate_gradients(void) while(q >= 0) { - int dp = DC[q].dp_index; - int vf = DC[q].vf_index; + int dp = DC[q].dp_index; + int vf = DC[q].vf_index; int particle = Mesh.DP[dp].index; if(particle < 0) @@ -292,9 +283,9 @@ void calculate_gradients(void) double py = Center[1] - ff * ny; double pz = Center[2] - ff * nz; - Mirror[0] = 2. * px - Center[0]; - Mirror[1] = 2. * py - Center[1]; - Mirror[2] = 2. * pz - Center[2]; + Mirror[0] = 2. * px - Center[0]; + Mirror[1] = 2. * py - Center[1]; + Mirror[2] = 2. * pz - Center[2]; CenterOther = Mirror; } else @@ -308,7 +299,7 @@ void calculate_gradients(void) norm[1] = boundaryY(CenterOther[1] - Center[1]); norm[2] = boundaryZ(CenterOther[2] - Center[2]); - double dist = sqrt(norm[0] * norm[0] + norm[1] * norm[1] + norm[2] * norm[2]); + double dist = sqrt(norm[0] * norm[0] + norm[1] * norm[1] + norm[2] * norm[2]); double distinv = 1.0 / dist; norm[0] *= distinv; norm[1] *= distinv; @@ -322,19 +313,21 @@ void calculate_gradients(void) if(Mesh.DP[dp].task == ThisTask) { - if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || (grad_elements[k].type == GRADIENT_TYPE_VELZ)) + if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || + (grad_elements[k].type == GRADIENT_TYPE_VELZ)) { - ValueOther = *(MyFloat *) (((char *) (&P[particle])) + grad_elements[k].offset); + ValueOther = *(MyFloat *)(((char *)(&P[particle])) + grad_elements[k].offset); } else - ValueOther = *(MyFloat *) (((char *) (&SphP[particle])) + grad_elements[k].offset); + ValueOther = *(MyFloat *)(((char *)(&SphP[particle])) + grad_elements[k].offset); } else { - ValueOther = *(MyFloat *) (((char *) (&PrimExch[particle])) + grad_elements[k].offset_exch); + ValueOther = *(MyFloat *)(((char *)(&PrimExch[particle])) + grad_elements[k].offset_exch); } - if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || (grad_elements[k].type == GRADIENT_TYPE_VELZ)) + if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || + (grad_elements[k].type == GRADIENT_TYPE_VELZ)) { ValueOther /= All.cf_atime; @@ -377,7 +370,7 @@ void calculate_gradients(void) { solve_matrix_problem(mdata[k].X, mdata[k].y, mdata[k].grad); - MySingle *data = (MySingle *) (((char *) (&(SphP[i].Grad))) + grad_elements[k].offset_grad); + MySingle *data = (MySingle *)(((char *)(&(SphP[i].Grad))) + grad_elements[k].offset_grad); for(int j = 0; j < NUMDIMS; j++) data[j] = mdata[k].grad[j]; for(int j = NUMDIMS; j < 3; j++) @@ -441,7 +434,6 @@ void calculate_gradients(void) TIMER_STOP(CPU_GRADIENTS); } - #if defined(OUTPUT_DIVVEL) || defined(MHD) /*! \brief Computes divergences applying the Gauss' law. * @@ -478,15 +470,15 @@ void compute_divergences() struct grad_data *GradOther; #endif /* #ifdef MHD */ #if defined(EVALPOTENTIAL) - SphP[i].PotentialPeak = 1; /* starts off true */ + SphP[i].PotentialPeak = 1; /* starts off true */ double PotenOther; #endif /* #if defined(EVALPOTENTIAL) */ int q = SphP[i].first_connection; while(q >= 0) { - int dp = DC[q].dp_index; - int vf = DC[q].vf_index; + int dp = DC[q].dp_index; + int vf = DC[q].vf_index; int particle = Mesh.DP[dp].index; if(particle < 0) @@ -524,16 +516,16 @@ void compute_divergences() nx /= nn; ny /= nn; nz /= nn; - double fx = (SphP[i].Center[0] - Mesh.VF[vf].cx); - double fy = (SphP[i].Center[1] - Mesh.VF[vf].cy); - double fz = (SphP[i].Center[2] - Mesh.VF[vf].cz); - double ff = (fx * nx + fy * ny + fz * nz); - double px = SphP[i].Center[0] - ff * nx; - double py = SphP[i].Center[1] - ff * ny; - double pz = SphP[i].Center[2] - ff * nz; - Mirror[0] = 2. * px - SphP[i].Center[0]; - Mirror[1] = 2. * py - SphP[i].Center[1]; - Mirror[2] = 2. * pz - SphP[i].Center[2]; + double fx = (SphP[i].Center[0] - Mesh.VF[vf].cx); + double fy = (SphP[i].Center[1] - Mesh.VF[vf].cy); + double fz = (SphP[i].Center[2] - Mesh.VF[vf].cz); + double ff = (fx * nx + fy * ny + fz * nz); + double px = SphP[i].Center[0] - ff * nx; + double py = SphP[i].Center[1] - ff * ny; + double pz = SphP[i].Center[2] - ff * nz; + Mirror[0] = 2. * px - SphP[i].Center[0]; + Mirror[1] = 2. * py - SphP[i].Center[1]; + Mirror[2] = 2. * pz - SphP[i].Center[2]; CenterOther = Mirror; } else @@ -544,7 +536,7 @@ void compute_divergences() #endif /* #if defined(OUTPUT_DIVVEL) */ #ifdef MHD GradOther = &SphP[particle].Grad; - BOther = SphP[particle].B; + BOther = SphP[particle].B; #endif /* #ifdef MHD */ #if defined(EVALPOTENTIAL) PotenOther = P[particle].Potential; @@ -558,7 +550,7 @@ void compute_divergences() #endif /* #if defined(OUTPUT_DIVVEL) */ #ifdef MHD GradOther = &GradExch[particle]; - BOther = PrimExch[particle].B; + BOther = PrimExch[particle].B; #endif /* #ifdef MHD */ #if defined(EVALPOTENTIAL) PotenOther = PrimExch[particle].Potential; @@ -613,7 +605,6 @@ void compute_divergences() } #endif /* #if defined(OUTPUT_DIVVEL) || defined(MHD) */ - /*! \brief Correct values for gradient calculation for reflective boundary * conditions. * @@ -658,7 +649,6 @@ void correct_for_reflective_boundaries(double *ValueOther, double Value, int typ #endif /* #if defined(REFLECTIVE_Z) */ } - /*! \brief Loops through mesh and limits associated gradients. * * \return void @@ -668,7 +658,7 @@ void limit_gradients(void) mpi_printf("VORONOI: Limiting gradients...\n"); point *DP = Mesh.DP; - face *VF = Mesh.VF; + face *VF = Mesh.VF; for(int i = 0; i < Mesh.Nvf; i++) { @@ -713,15 +703,16 @@ void limit_gradients(void) { for(int k = 0; k < N_Grad; k++) { - if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || (grad_elements[k].type == GRADIENT_TYPE_VELZ)) + if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || + (grad_elements[k].type == GRADIENT_TYPE_VELZ)) { - value = *(MyFloat *) (((char *) (&P[q])) + grad_elements[k].offset); + value = *(MyFloat *)(((char *)(&P[q])) + grad_elements[k].offset); value /= All.cf_atime; } else - value = *(MyFloat *) (((char *) (&SphP[q])) + grad_elements[k].offset); + value = *(MyFloat *)(((char *)(&SphP[q])) + grad_elements[k].offset); - data = (MySingle *) (((char *) (&(SphP[q].Grad))) + grad_elements[k].offset_grad); + data = (MySingle *)(((char *)(&(SphP[q].Grad))) + grad_elements[k].offset_grad); if(grad_elements[k].type != GRADIENT_TYPE_RTF) limit_gradient(d, value, minvalues[q * N_Grad + k], maxvalues[q * N_Grad + k], data); @@ -777,9 +768,9 @@ void limit_gradients(void) if(VF[i].area > 1.0e-10 * SphP[q].SurfaceArea) { /* let's now limit the overall size of the velocity gradient */ - MySingle *grad_vx = (MySingle *) (((char *) (&(SphP[q].Grad))) + GVelx->offset_grad); - MySingle *grad_vy = (MySingle *) (((char *) (&(SphP[q].Grad))) + GVely->offset_grad); - MySingle *grad_vz = (MySingle *) (((char *) (&(SphP[q].Grad))) + GVelz->offset_grad); + MySingle *grad_vx = (MySingle *)(((char *)(&(SphP[q].Grad))) + GVelx->offset_grad); + MySingle *grad_vy = (MySingle *)(((char *)(&(SphP[q].Grad))) + GVely->offset_grad); + MySingle *grad_vz = (MySingle *)(((char *)(&(SphP[q].Grad))) + GVelz->offset_grad); limit_vel_gradient(d, grad_vx, grad_vy, grad_vz, get_sound_speed(q)); } } @@ -789,7 +780,6 @@ void limit_gradients(void) #endif /* #ifndef DISABLE_VELOCITY_CSND_SLOPE_LIMITING */ } - /*! \brief Limits velocity gradient. * * Limit velocity change to the sound speed. @@ -802,7 +792,7 @@ void limit_gradients(void) * * \return void */ -void limit_vel_gradient(double *d, MySingle * grad_vx, MySingle * grad_vy, MySingle * grad_vz, double csnd) +void limit_vel_gradient(double *d, MySingle *grad_vx, MySingle *grad_vy, MySingle *grad_vz, double csnd) { #define VEL_GRADIENT_LIMIT_FAC 1.0 if(All.ComovingIntegrationOn) @@ -849,7 +839,6 @@ void limit_vel_gradient(double *d, MySingle * grad_vx, MySingle * grad_vy, MySin } } - /*! \brief Limits gradients. * * Slope limiter. @@ -862,7 +851,7 @@ void limit_vel_gradient(double *d, MySingle * grad_vx, MySingle * grad_vy, MySin * * \return void */ -void limit_gradient(double *d, double phi, double min_phi, double max_phi, MySingle * dphi) +void limit_gradient(double *d, double phi, double min_phi, double max_phi, MySingle *dphi) { double dp = dphi[0] * d[0] + dphi[1] * d[1] + dphi[2] * d[2]; @@ -902,7 +891,6 @@ void limit_gradient(double *d, double phi, double min_phi, double max_phi, MySin } } - /*! \brief Distance in x direction. * * Taking into account periodicity of simulation box, if given. @@ -923,7 +911,6 @@ double boundaryX(double dx) return dx; } - /*! \brief Distance in y direction. * * Taking into account periodicity of simulation box, if given. @@ -944,7 +931,6 @@ double boundaryY(double dy) return dy; } - /*! \brief Distance in z direction. * * Taking into account periodicity of simulation box, if given. @@ -965,5 +951,4 @@ double boundaryZ(double dz) return dz; } - #endif /* #if !defined(ONEDIMS) */ diff --git a/src/mesh/voronoi/voronoi_gradients_onedims.c b/src/mesh/voronoi/voronoi_gradients_onedims.c index 6420fbcab29bf956abf1363a216300d861f8a75b..d3e770a0da9f13c73e66d186750f9d18fc33ee8d 100644 --- a/src/mesh/voronoi/voronoi_gradients_onedims.c +++ b/src/mesh/voronoi/voronoi_gradients_onedims.c @@ -24,26 +24,22 @@ * double getValue(int i, int k) * void calculate_gradients(void) * void compute_divvel() - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 23.05.2018 Prepared file for public release -- Rainer Weinberger */ - #include "../../main/allvars.h" #include "../../main/proto.h" - #if defined(ONEDIMS) - #ifdef OUTPUT_DIVVEL static void compute_divvel(); #endif /* #ifdef OUTPUT_DIVVEL */ - /*! \brief Gets a value of a quantity. * * \param[i] Index of cell in P and SphP array. @@ -53,13 +49,13 @@ static void compute_divvel(); */ double getValue(int i, int k) { - if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || (grad_elements[k].type == GRADIENT_TYPE_VELZ)) - return *(MyFloat *) (((char *) (&P[i])) + grad_elements[k].offset); + if((grad_elements[k].type == GRADIENT_TYPE_VELX) || (grad_elements[k].type == GRADIENT_TYPE_VELY) || + (grad_elements[k].type == GRADIENT_TYPE_VELZ)) + return *(MyFloat *)(((char *)(&P[i])) + grad_elements[k].offset); else - return *(MyFloat *) (((char *) (&SphP[i])) + grad_elements[k].offset); + return *(MyFloat *)(((char *)(&SphP[i])) + grad_elements[k].offset); } - /*! \brief Calculates gradients in a 1d simulation. * * \return void @@ -80,12 +76,12 @@ void calculate_gradients(void) for(k = 0; k < N_Grad; k++) { double Value = getValue(i, k); - double Pos = P[i].Pos[0]; + double Pos = P[i].Pos[0]; -#if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) +#if defined(ONEDIMS_SPHERICAL) || defined(REFLECTIVE_X) if(i == 0 || i == NumGas - 1) { - MySingle *data = (MySingle *) (((char *) (&(SphP[i].Grad))) + grad_elements[k].offset_grad); + MySingle *data = (MySingle *)(((char *)(&(SphP[i].Grad))) + grad_elements[k].offset_grad); memset(data, 0, 3 * sizeof(MySingle)); continue; } @@ -108,10 +104,10 @@ void calculate_gradients(void) double grad = (ValueL - ValueR) / (PosL - PosR); - MySingle *data = (MySingle *) (((char *) (&(SphP[i].Grad))) + grad_elements[k].offset_grad); - data[0] = grad; - data[1] = 0; - data[2] = 0; + MySingle *data = (MySingle *)(((char *)(&(SphP[i].Grad))) + grad_elements[k].offset_grad); + data[0] = grad; + data[1] = 0; + data[2] = 0; double ValueMin = dmin(ValueL, ValueR); double ValueMax = dmax(ValueL, ValueR); @@ -159,7 +155,6 @@ void calculate_gradients(void) CPU_Step[CPU_GRADIENTS] += measure_time(); } - #ifdef OUTPUT_DIVVEL /*! \brief Calculates velocity divergence in 1d simulation. * @@ -181,9 +176,9 @@ void compute_divvel() if(i == 0) { -#if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) +#if defined(ONEDIMS_SPHERICAL) || defined(REFLECTIVE_X) VelxL = P[i].Vel[0]; -#else /* #if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) */ +#else /* #if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) */ VelxL = P[NumGas - 1].Vel[0]; #endif /* #if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) #else */ } @@ -192,9 +187,9 @@ void compute_divvel() if(i == NumGas - 1) { -#if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) +#if defined(ONEDIMS_SPHERICAL) || defined(REFLECTIVE_X) VelxR = P[i].Vel[0]; -#else /* #if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) */ +#else /* #if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) */ VelxR = P[0].Vel[0]; #endif /* #if defined (ONEDIMS_SPHERICAL) || defined (REFLECTIVE_X) #else */ } @@ -206,5 +201,4 @@ void compute_divvel() } #endif /* #ifdef OUTPUT_DIVVEL */ - #endif /* #if defined(ONEDIMS) */ diff --git a/src/mesh/voronoi/voronoi_refinement.c b/src/mesh/voronoi/voronoi_refinement.c index ee9c6375b06f926c9901d5d302d857c5c5f6290f..8077b9b0a032831921885ac28581836c7d190031 100644 --- a/src/mesh/voronoi/voronoi_refinement.c +++ b/src/mesh/voronoi/voronoi_refinement.c @@ -23,25 +23,21 @@ * \details contains functions: * static void refine_add_ngb(int i, int j) * int do_refinements(void) - * + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 23.05.2018 Prepared file for public release -- Rainer Weinberger */ - #include "../../main/allvars.h" #include "../../main/proto.h" - #ifdef REFINEMENT_SPLIT_CELLS - static int *ref_SphP_dp_index; static int *first_ngb, *last_ngb, first_free_ngb; - /*! \brief Linked list for neighbor data. * */ @@ -49,9 +45,7 @@ static struct ngb_data { int index; int next_ngb; -} - *ngb; - +} * ngb; /*! \brief Add element to linked neighbor list. * @@ -64,7 +58,6 @@ static void refine_add_ngb(int i, int j) { if(i >= 0 && j >= 0) { - if(i >= Mesh.Ndp || j >= Mesh.Ndp) { terminate("i>= Ndp || j>= Ndp"); @@ -73,20 +66,19 @@ static void refine_add_ngb(int i, int j) if(first_ngb[i] >= 0) { ngb[last_ngb[i]].next_ngb = first_free_ngb; - last_ngb[i] = first_free_ngb; + last_ngb[i] = first_free_ngb; } else { first_ngb[i] = last_ngb[i] = first_free_ngb; } - ngb[first_free_ngb].index = j; + ngb[first_free_ngb].index = j; ngb[first_free_ngb].next_ngb = -1; first_free_ngb++; } } - /*! \brief Loops through active cells and refine cells if needed. * * Splits the cell in random direction; moves mesh-generating point by @@ -106,7 +98,7 @@ int do_refinements(void) ref_SphP_dp_index = mymalloc_movable(&ref_SphP_dp_index, "ref_SphP_dp_index", NumGas * sizeof(int)); - int NActiveParticles = TimeBinsHydro.NActiveParticles; /* save this since refinement is going to change it */ + int NActiveParticles = TimeBinsHydro.NActiveParticles; /* save this since refinement is going to change it */ for(idx = 0, count = 0; idx < NActiveParticles; idx++) { i = TimeBinsHydro.ActiveParticleList[idx]; @@ -129,17 +121,19 @@ int do_refinements(void) if(NumPart + count >= All.MaxPart) { - sprintf(buf, "On Task=%d with NumPart=%d we try to produce %d cells. Sorry, no space left...(All.MaxPart=%d)\n", ThisTask, NumPart, count, All.MaxPart); + sprintf(buf, "On Task=%d with NumPart=%d we try to produce %d cells. Sorry, no space left...(All.MaxPart=%d)\n", ThisTask, + NumPart, count, All.MaxPart); terminate(buf); } if(NumGas + count >= All.MaxPartSph) { - sprintf(buf, "On Task=%d with NumGas=%d we try to produce %d cells. Sorry, no space left...(All.MaxPartSph=%d)\n", ThisTask, NumGas, count, All.MaxPartSph); + sprintf(buf, "On Task=%d with NumGas=%d we try to produce %d cells. Sorry, no space left...(All.MaxPartSph=%d)\n", ThisTask, + NumGas, count, All.MaxPartSph); terminate(buf); } - if(All.MaxID == 0) /* MaxID not calculated yet */ + if(All.MaxID == 0) /* MaxID not calculated yet */ calculate_maxid(); int *list = mymalloc("list", NTask * sizeof(int)); @@ -156,14 +150,14 @@ int do_refinements(void) myfree(list); Ngb_MarkerValue++; - int nchanged = 0; - int *nodelist = (int *) mymalloc("nodelist", NTopleaves * sizeof(int)); + int nchanged = 0; + int *nodelist = (int *)mymalloc("nodelist", NTopleaves * sizeof(int)); /* create explicit list of neighbors */ first_ngb = mymalloc("first_ngb", Mesh.Ndp * sizeof(int)); - ngb = mymalloc("ngbs", 2 * Mesh.Nvf * sizeof(struct ngb_data)); - last_ngb = mymalloc("last_ngb", Mesh.Ndp * sizeof(int)); + ngb = mymalloc("ngbs", 2 * Mesh.Nvf * sizeof(struct ngb_data)); + last_ngb = mymalloc("last_ngb", Mesh.Ndp * sizeof(int)); for(i = 0; i < Mesh.Ndp; i++) { @@ -174,7 +168,7 @@ int do_refinements(void) int li = Mesh.DP[i].index; if(li >= 0 && li < NumGas) if(ref_SphP_dp_index[li] < 0) - ref_SphP_dp_index[li] = i; /* only guaranteed to be set for active cells */ + ref_SphP_dp_index[li] = i; /* only guaranteed to be set for active cells */ } } @@ -202,7 +196,7 @@ int do_refinements(void) if(TimeBinSynchronized[P[NumPart + count].TimeBinGrav] && P[i].Mass > 0) addToGravList = 0; - /* there is already an entry in the list of active particles for + /* there is already an entry in the list of active particles for gravity that points to the index that we will use for our new cell */ } @@ -210,7 +204,7 @@ int do_refinements(void) j = NumGas + count; - P[j] = P[i]; + P[j] = P[i]; SphP[j] = SphP[i]; P[j].ID = newid++; @@ -224,9 +218,9 @@ int do_refinements(void) dir[0] = cos(phi); dir[1] = sin(phi); dir[2] = 0; -#else /* #ifdef TWODIMS */ +#else /* #ifdef TWODIMS */ double theta = acos(2 * get_random_number() - 1); - double phi = 2 * M_PI * get_random_number(); + double phi = 2 * M_PI * get_random_number(); dir[0] = sin(theta) * cos(phi); dir[1] = sin(theta) * sin(phi); @@ -242,9 +236,9 @@ int do_refinements(void) SphP[j].SepVector[1] = SphP[i].SepVector[1] = dir[1]; SphP[j].SepVector[2] = SphP[i].SepVector[2] = dir[2]; - /**** create the voronoi cell of i as an auxiliary mesh */ + /**** create the voronoi cell of i as an auxiliary mesh */ - int jj = ref_SphP_dp_index[i]; /* this is the delaunay point of this cell */ + int jj = ref_SphP_dp_index[i]; /* this is the delaunay point of this cell */ if(jj < 0) terminate("jj < 0"); @@ -267,7 +261,8 @@ int do_refinements(void) DeRefMesh.Indi.AllocFacNdp *= ALLOC_INCREASE_FACTOR; DeRefMesh.MaxNdp = DeRefMesh.Indi.AllocFacNdp; #ifdef VERBOSE - printf("Task=%d: increase memory allocation, MaxNdp=%d Indi.AllocFacNdp=%g\n", ThisTask, DeRefMesh.MaxNdp, DeRefMesh.Indi.AllocFacNdp); + printf("Task=%d: increase memory allocation, MaxNdp=%d Indi.AllocFacNdp=%g\n", ThisTask, DeRefMesh.MaxNdp, + DeRefMesh.Indi.AllocFacNdp); #endif /* #ifdef VERBOSE */ DeRefMesh.DP -= 5; DeRefMesh.DP = myrealloc_movable(DeRefMesh.DP, (DeRefMesh.MaxNdp + 5) * sizeof(point)); @@ -276,7 +271,9 @@ int do_refinements(void) DeRefMesh.DP[DeRefMesh.Ndp] = Mesh.DP[q]; - double r = sqrt(pow(DeRefMesh.DP[DeRefMesh.Ndp].x - P[i].Pos[0], 2) + pow(DeRefMesh.DP[DeRefMesh.Ndp].y - P[i].Pos[1], 2) + pow(DeRefMesh.DP[DeRefMesh.Ndp].z - P[i].Pos[2], 2)); + double r = + sqrt(pow(DeRefMesh.DP[DeRefMesh.Ndp].x - P[i].Pos[0], 2) + pow(DeRefMesh.DP[DeRefMesh.Ndp].y - P[i].Pos[1], 2) + + pow(DeRefMesh.DP[DeRefMesh.Ndp].z - P[i].Pos[2], 2)); if(r < 2 * fac) terminate("We are trying to split a heavily distorted cell... We better stop. Check your refinement criterion."); @@ -301,9 +298,9 @@ int do_refinements(void) /* and finally, add the newly generated point */ - DeRefMesh.DP[DeRefMesh.Ndp].x = P[j].Pos[0]; - DeRefMesh.DP[DeRefMesh.Ndp].y = P[j].Pos[1]; - DeRefMesh.DP[DeRefMesh.Ndp].z = P[j].Pos[2]; + DeRefMesh.DP[DeRefMesh.Ndp].x = P[j].Pos[0]; + DeRefMesh.DP[DeRefMesh.Ndp].y = P[j].Pos[1]; + DeRefMesh.DP[DeRefMesh.Ndp].z = P[j].Pos[2]; DeRefMesh.DP[DeRefMesh.Ndp].ID = P[j].ID; #ifndef OPTIMIZE_MEMORY_USAGE set_integers_for_point(&DeRefMesh, DeRefMesh.Ndp); @@ -348,7 +345,10 @@ int do_refinements(void) for(k = 0; k < 3; k++) { SphP[i].B[k] = SphP[i].BConserved[k] / (voli + volj); - SphP[j].B[k] = SphP[i].B[k] + SphP[i].Grad.dB[k][0] * (P[j].Pos[0] - P[i].Pos[0]) + SphP[i].Grad.dB[k][1] * (P[j].Pos[1] - P[i].Pos[1]) + SphP[i].Grad.dB[k][2] * (P[j].Pos[2] - P[i].Pos[2]); /* extrapolate B to the position of the new cell */ + SphP[j].B[k] = + SphP[i].B[k] + SphP[i].Grad.dB[k][0] * (P[j].Pos[0] - P[i].Pos[0]) + + SphP[i].Grad.dB[k][1] * (P[j].Pos[1] - P[i].Pos[1]) + + SphP[i].Grad.dB[k][2] * (P[j].Pos[2] - P[i].Pos[2]); /* extrapolate B to the position of the new cell */ /* update conserved variables */ SphP[i].BConserved[k] = SphP[i].B[k] * voli; @@ -368,24 +368,25 @@ int do_refinements(void) #endif /* #ifdef USE_SFR */ #ifdef MAXSCALARS - for(int s = 0; s < N_Scalar; s++) /* Note, the changes in MATERIALS, HIGHRESGASMASS, etc., are treated as part of the Scalars */ + for(int s = 0; s < N_Scalar; + s++) /* Note, the changes in MATERIALS, HIGHRESGASMASS, etc., are treated as part of the Scalars */ { - *(MyFloat *) (((char *) (&SphP[i])) + scalar_elements[s].offset_mass) *= faci; - *(MyFloat *) (((char *) (&SphP[j])) + scalar_elements[s].offset_mass) *= facj; + *(MyFloat *)(((char *)(&SphP[i])) + scalar_elements[s].offset_mass) *= faci; + *(MyFloat *)(((char *)(&SphP[j])) + scalar_elements[s].offset_mass) *= facj; } #endif /* #ifdef MAXSCALARS */ #ifdef REFINEMENT_HIGH_RES_GAS /* the change in the SphP[].HighResMass is treated as part of the Scalars loop above */ - SphP[i].AllowRefinement += 2; /* increment the refinement "generation" of both cells */ + SphP[i].AllowRefinement += 2; /* increment the refinement "generation" of both cells */ SphP[j].AllowRefinement += 2; #endif /* #ifdef REFINEMENT_HIGH_RES_GAS */ /* add the new particle into the neighbour tree */ - int no = Ngb_Nextnode[i]; + int no = Ngb_Nextnode[i]; Ngb_Nextnode[i] = j; Ngb_Nextnode[j] = no; - Ngb_Father[j] = Ngb_Father[i]; + Ngb_Father[j] = Ngb_Father[i]; ngb_update_rangebounds(j, &nchanged, nodelist); @@ -395,7 +396,7 @@ int do_refinements(void) timebin_add_particle(&TimeBinsGravity, j, i, P[i].TimeBinGrav, addToGravList); SphP[j].first_connection = -1; - SphP[j].last_connection = -1; + SphP[j].last_connection = -1; count++; } @@ -421,5 +422,4 @@ int do_refinements(void) return countall; } - #endif /* REFINEMENT_SPLIT_CELLS */ diff --git a/src/mesh/voronoi/voronoi_utils.c b/src/mesh/voronoi/voronoi_utils.c index ca415d54396684096b55fc5a72edb0e436715749..94ce5623987df05ed0a9386f1eb575ef59fe0a51 100644 --- a/src/mesh/voronoi/voronoi_utils.c +++ b/src/mesh/voronoi/voronoi_utils.c @@ -22,16 +22,14 @@ * \brief Utilities for 3d Voronoi mesh * \details contains functions: * double cross_section_plane_cell(int sphp_index, int dp_index, double *center, double *n) - * void intersections_plane_cell(int sphp_index, int dp_index, double *center, double *n, double *polygon, unsigned int *nof_polygon_elements) - * void intersection_plane_grid(double *center, double *n, const char *filename) - * static double polygon_area(double *polygon, unsigned int nof_elements) - * static int qs_partition(double *A, int p, int r, double *B) - * static void qs_sort(double *A, int p, int r, double *B) - * static double calc_phi(double x, double y) - * static void rotate_z(double *vec, const double alpha) - * + * void intersections_plane_cell(int sphp_index, int dp_index, double *center, double *n, double *polygon, unsigned int + * *nof_polygon_elements) void intersection_plane_grid(double *center, double *n, const char *filename) static double + * polygon_area(double *polygon, unsigned int nof_elements) static int qs_partition(double *A, int p, int r, double *B) static void + * qs_sort(double *A, int p, int r, double *B) static double calc_phi(double x, double y) static void rotate_z(double *vec, const + * double alpha) + * * \par Major modifications and contributions: - * + * * - DD.MM.YYYY Description * - 23.05.2018 Prepared file for public release -- Rainer Weinberger */ @@ -39,23 +37,19 @@ #include "../../main/allvars.h" #include "../../main/proto.h" - #if !defined(TWODIMS) && !defined(ONEDIMS) - -//helper functions for cross_section_plane_cell and intersections_plane_cell: +// helper functions for cross_section_plane_cell and intersections_plane_cell: static int qs_partition(double *A, int p, int r, double *B); static void qs_sort(double *A, int p, int r, double *B); static double calc_phi(double x, double y); static void rotate_z(double *vec, const double alpha); static void rotate_y(double *vec, const double alpha); - #ifdef TETRA_INDEX_IN_FACE static double polygon_area(double *polygon, unsigned int nof_elements); static const unsigned int max_poly_elements = 128; - /*! \brief Calculates the cross section between a plane and a Voronoi cell(3D). * * \param[in] sphp_index The hydro index of the cell. @@ -72,7 +66,7 @@ double cross_section_plane_cell(int sphp_index, int dp_index, double *center, do intersections_plane_cell(sphp_index, dp_index, center, n, polygon, &nof_elements); - //polygon has to contain at least 3 points + // polygon has to contain at least 3 points if(nof_elements < 6) { return 0; @@ -83,7 +77,6 @@ double cross_section_plane_cell(int sphp_index, int dp_index, double *center, do } } - /*! \brief Calculates the intersections between a plane and a cell. * * \param[in] sphp_index The hydro index of the cell. @@ -96,18 +89,19 @@ double cross_section_plane_cell(int sphp_index, int dp_index, double *center, do * * \return void */ -void intersections_plane_cell(int sphp_index, int dp_index, double *center, double *n, double *polygon, unsigned int *nof_polygon_elements) +void intersections_plane_cell(int sphp_index, int dp_index, double *center, double *n, double *polygon, + unsigned int *nof_polygon_elements) { - //memory for the line segments + // memory for the line segments unsigned int line_segments_max = 2000; - double *ls = (double *) mymalloc("line_segments", line_segments_max * sizeof(double)); + double *ls = (double *)mymalloc("line_segments", line_segments_max * sizeof(double)); - //get the line segments + // get the line segments unsigned int nof_elements = 0; get_line_segments(sphp_index, dp_index, ls, &nof_elements, line_segments_max); - assert(nof_elements % 6 == 0); //6 doubles represent one line segment + assert(nof_elements % 6 == 0); // 6 doubles represent one line segment - //start the calculation + // start the calculation unsigned int i; double phi; @@ -124,60 +118,58 @@ void intersections_plane_cell(int sphp_index, int dp_index, double *center, doub assert(r > 0); double theta = acos(n[2] / r); - double lambda; //z1 + lambda * (z2 - z1) = 0 + double lambda; // z1 + lambda * (z2 - z1) = 0 unsigned int max_phi_elms = max_poly_elements / 2; - double phi_values[max_phi_elms]; //phi coordinates of the points of the polygon - unsigned int p = 0; //number of points of the polygon + double phi_values[max_phi_elms]; // phi coordinates of the points of the polygon + unsigned int p = 0; // number of points of the polygon - //balance point of the polygon + // balance point of the polygon double bal_p_x = 0; double bal_p_y = 0; for(i = 0; i < nof_elements; i += 6) { - //transform line segment to the center frame - ls[i] -= center[0]; //x1 - ls[i + 1] -= center[1]; //y1 - ls[i + 2] -= center[2]; //z1 - ls[i + 3] -= center[0]; //x2 - ls[i + 4] -= center[1]; //y2 - ls[i + 5] -= center[2]; //z2 - - //rotate line segment such that the cross secting plane is in the x-y plane / the normal vector of the plane is on the z-axis + // transform line segment to the center frame + ls[i] -= center[0]; // x1 + ls[i + 1] -= center[1]; // y1 + ls[i + 2] -= center[2]; // z1 + ls[i + 3] -= center[0]; // x2 + ls[i + 4] -= center[1]; // y2 + ls[i + 5] -= center[2]; // z2 + + // rotate line segment such that the cross secting plane is in the x-y plane / the normal vector of the plane is on the z-axis rotate_z(&ls[i], -phi); rotate_y(&ls[i], -theta); rotate_z(&ls[i + 3], -phi); rotate_y(&ls[i + 3], -theta); - if(ls[i + 2] == ls[i + 5]) //same z-coords + if(ls[i + 2] == ls[i + 5]) // same z-coords { - if(ls[i + 2] != 0) //no intersection + if(ls[i + 2] != 0) // no intersection { lambda = -1; } else { - lambda = 0; //take first point as intersection + lambda = 0; // take first point as intersection } - } else { lambda = ls[i + 2] / (ls[i + 2] - ls[i + 5]); } - if(lambda >= 0 && lambda <= 1) //line segment intersects plane + if(lambda >= 0 && lambda <= 1) // line segment intersects plane { - if(p == max_phi_elms) { terminate("termination in voronoi_utils.c: intersections_plane_cell: not enough memory!\n"); } - polygon[2 * p] = ls[i] + lambda * (ls[i + 3] - ls[i]); //x coordinate of the intersection - polygon[2 * p + 1] = ls[i + 1] + lambda * (ls[i + 4] - ls[i + 1]); //y coordinate of the intersection + polygon[2 * p] = ls[i] + lambda * (ls[i + 3] - ls[i]); // x coordinate of the intersection + polygon[2 * p + 1] = ls[i + 1] + lambda * (ls[i + 4] - ls[i + 1]); // y coordinate of the intersection bal_p_x += polygon[2 * p]; bal_p_y += polygon[2 * p + 1]; @@ -186,16 +178,16 @@ void intersections_plane_cell(int sphp_index, int dp_index, double *center, doub } } - //free memory + // free memory myfree(ls); - //polygon has to contain at least 3 points + // polygon has to contain at least 3 points if(p < 3) { return; } - //switch frame to balance point of the polygon + // switch frame to balance point of the polygon bal_p_x /= p; bal_p_y /= p; @@ -204,20 +196,20 @@ void intersections_plane_cell(int sphp_index, int dp_index, double *center, doub polygon[2 * i] -= bal_p_x; polygon[2 * i + 1] -= bal_p_y; - //calculate the phi values + // calculate the phi values phi_values[i] = calc_phi(polygon[2 * i], polygon[2 * i + 1]); } - //sort polygon + // sort polygon qs_sort(phi_values, 0, p - 1, polygon); - //close polygon - polygon[2 * p] = polygon[0]; + // close polygon + polygon[2 * p] = polygon[0]; polygon[2 * p + 1] = polygon[1]; - phi_values[p] = phi_values[0]; + phi_values[p] = phi_values[0]; p++; - //transform back + // transform back for(i = 0; i < p; i++) { polygon[2 * i] += bal_p_x; @@ -227,7 +219,6 @@ void intersections_plane_cell(int sphp_index, int dp_index, double *center, doub *nof_polygon_elements = 2 * p; } - /*! \brief Write out the intersections between a plane and the grid * (for plotting). * @@ -272,9 +263,9 @@ void intersection_plane_grid(double *center, double *n, const char *filename) assert(r > 0); double theta = acos(n[2] / r); - double xaxis[3] = { 1, 0, 0 }; - double yaxis[3] = { 0, 1, 0 }; - double zaxis[3] = { 0, 0, 1 }; + double xaxis[3] = {1, 0, 0}; + double yaxis[3] = {0, 1, 0}; + double zaxis[3] = {0, 0, 1}; rotate_y(xaxis, theta); rotate_z(xaxis, phi); @@ -293,12 +284,12 @@ void intersection_plane_grid(double *center, double *n, const char *filename) printf("z-axis: (%f, %f, %f)\n", zaxis[0], zaxis[1], zaxis[2]); const int cells_max_elms = NumGas; - int *nof_intersections = (int *) mymalloc("number of intersections", cells_max_elms * sizeof(int)); - unsigned int l = 0; + int *nof_intersections = (int *)mymalloc("number of intersections", cells_max_elms * sizeof(int)); + unsigned int l = 0; const int polygons_max_elms = NumGas * 5; - double *polygons = (double *) mymalloc("polygons", polygons_max_elms * 5 * sizeof(int)); - unsigned int j = 0; + double *polygons = (double *)mymalloc("polygons", polygons_max_elms * 5 * sizeof(int)); + unsigned int j = 0; unsigned int nof_polygon_elements = 0; @@ -311,7 +302,7 @@ void intersection_plane_grid(double *center, double *n, const char *filename) if(nof_polygon_elements != 0) { - nof_intersections[l] = (int) nof_polygon_elements; + nof_intersections[l] = (int)nof_polygon_elements; l++; j += nof_polygon_elements; @@ -323,13 +314,13 @@ void intersection_plane_grid(double *center, double *n, const char *filename) } } - //binary output + // binary output FILE *pFile; pFile = fopen(filename, "wb"); - fwrite(&l, sizeof(int), 1, pFile); //number of intersected cells - fwrite(&j, sizeof(int), 1, pFile); //number of elements in polygons array + fwrite(&l, sizeof(int), 1, pFile); // number of intersected cells + fwrite(&j, sizeof(int), 1, pFile); // number of elements in polygons array fwrite(nof_intersections, sizeof(int), l, pFile); fwrite(polygons, sizeof(double), j, pFile); @@ -339,7 +330,6 @@ void intersection_plane_grid(double *center, double *n, const char *filename) myfree(nof_intersections); } - /*! \brief Calculate the area of a 2D polygon. * * Formula (wikipedia):A = 0.5 * sum_i=0^{n-1}(x_i * y_{i+1} - x_{i+1} * y_i). @@ -362,7 +352,6 @@ static double polygon_area(double *polygon, unsigned int nof_elements) for(k = 0; k < nof_elements - 2; k += 2) { result += polygon[k] * polygon[k + 3] - polygon[k + 2] * polygon[k + 1]; - } result *= 0.5; @@ -372,10 +361,8 @@ static double polygon_area(double *polygon, unsigned int nof_elements) return result; } - #endif /* #ifdef TETRA_INDEX_IN_FACE */ - /*! \brief Quicksort partitioning function, helper for qs_sort. * * \param[in, out] A array to be sorted, usually angle phi. @@ -397,41 +384,40 @@ static int qs_partition(double *A, int p, int r, double *B) { if(A[j] <= x) { - //switch phi values ( i <-> j ) + // switch phi values ( i <-> j ) i++; - tmp = A[i]; + tmp = A[i]; A[i] = A[j]; A[j] = tmp; - //switch coordinates ( 2i, 2i+1 <-> 2j, 2j+1) - tmp = B[2 * i]; - tmp2 = B[2 * i + 1]; - B[2 * i] = B[2 * j]; + // switch coordinates ( 2i, 2i+1 <-> 2j, 2j+1) + tmp = B[2 * i]; + tmp2 = B[2 * i + 1]; + B[2 * i] = B[2 * j]; B[2 * i + 1] = B[2 * j + 1]; - B[2 * j] = tmp; + B[2 * j] = tmp; B[2 * j + 1] = tmp2; } } - //switch phi values - tmp = A[i + 1]; + // switch phi values + tmp = A[i + 1]; A[i + 1] = A[r]; - A[r] = tmp; + A[r] = tmp; - //switch coordinates - tmp = B[(i + 1) * 2]; + // switch coordinates + tmp = B[(i + 1) * 2]; tmp2 = B[(i + 1) * 2 + 1]; - B[(i + 1) * 2] = B[2 * r]; + B[(i + 1) * 2] = B[2 * r]; B[(i + 1) * 2 + 1] = B[2 * r + 1]; - B[2 * r] = tmp; + B[2 * r] = tmp; B[2 * r + 1] = tmp2; return i + 1; } - /*! \brief Quick-sorts the points of the polygon with respect to phi. * * \param[in, out] A array to be sorted, usually angle phi. @@ -454,7 +440,6 @@ static void qs_sort(double *A, int p, int r, double *B) } } - /*! \brief Calculates the phi coordinate of a point. * * Calculates polar angle in a 2d coordinate system from Cartesian coordinate @@ -467,14 +452,14 @@ static void qs_sort(double *A, int p, int r, double *B) */ static double calc_phi(double x, double y) { - //if both arguments are zero an error occurs in atan2 + // if both arguments are zero an error occurs in atan2 if((x == 0) && (y == 0)) { fprintf(stderr, "ERROR in calc_phi: both arguments are zero\n"); return 0; } - double p = atan2(y, x); //in [-pi,pi] + double p = atan2(y, x); // in [-pi,pi] if(p < 0) { @@ -484,7 +469,6 @@ static double calc_phi(double x, double y) return p; } - /*! \brief Rotate a vector around the z axis. * * \param[in, out] vec Array to 3 dimensional vector to be rotated. @@ -495,11 +479,10 @@ static double calc_phi(double x, double y) static void rotate_z(double *vec, const double alpha) { double vx_tmp = vec[0]; - vec[0] = cos(alpha) * vec[0] - sin(alpha) * vec[1]; - vec[1] = sin(alpha) * vx_tmp + cos(alpha) * vec[1]; + vec[0] = cos(alpha) * vec[0] - sin(alpha) * vec[1]; + vec[1] = sin(alpha) * vx_tmp + cos(alpha) * vec[1]; } - /*! \brief Rotate a vector around the y axis. * * \param[in, out] vec Array to 3 dimensional vector to be rotated. @@ -515,5 +498,4 @@ static void rotate_y(double *vec, const double alpha) vec[2] = -sin(alpha) * vx_tmp + cos(alpha) * vec[2]; } - #endif /* #if !defined(TWODIMS) && !defined(ONEDIMS) */ diff --git a/src/star_formation/sfr_eEOS.c b/src/star_formation/sfr_eEOS.c index 10e2d894083379b1c6fbe952baba0c55cac119d8..7e9fbef4983ccb613436fb7b7c6a8efdbaf59774 100644 --- a/src/star_formation/sfr_eEOS.c +++ b/src/star_formation/sfr_eEOS.c @@ -47,7 +47,6 @@ #include "../gravity/forcetree.h" - #ifdef USE_SFR /*! \brief Main driver for star formation and gas cooling.