Commit ab806acd authored by Volker Springel's avatar Volker Springel

applied clang-formatter with our default style in (.clang-format)

parent 9fa6bfe2
---
Language: Cpp
BasedOnStyle: Google
BreakBeforeBraces: GNU
SpaceBeforeParens: Never
AllowShortLoopsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AlignConsecutiveAssignments: true
ColumnLimit: 135
ReflowComments: true
SortUsingDeclarations: true
...
......@@ -26,30 +26,25 @@
* int add_backgroundgrid(void)
* void modify_boxsize(double new_val)
* void prepare_domain_backgroundgrid(void)
*
*
*
*
* \par Major modifications and contributions:
*
*
* - DD.MM.YYYY Description
* - 11.05.2018 Prepared file for public release -- Rainer Weinberger
*/
#include "add_bggrid.h"
#include "../domain/domain.h"
#include "../main/allvars.h"
#include "../main/proto.h"
#include "../domain/domain.h"
#include "add_bggrid.h"
#ifdef ADDBACKGROUNDGRID
static void modify_boxsize(double new_val);
MyIDType IDNew;
/*! \brief Re-gridding of ICs onto oct-tree nodes.
*
* If this is active, no simulation is performed.
......@@ -79,9 +74,9 @@ int add_backgroundgrid(void)
domain_free();
domain_Decomposition(); /* do new domain decomposition, will also make a new chained-list of synchronized particles */
domain_Decomposition(); /* do new domain decomposition, will also make a new chained-list of synchronized particles */
numnodes = construct_forcetree(1, 1, 0, 0); /* build tree only with gas cells */
numnodes = construct_forcetree(1, 1, 0, 0); /* build tree only with gas cells */
for(i = Tree_MaxPart, vol = 0; i < numnodes + Tree_MaxPart; i++)
{
......@@ -91,19 +86,16 @@ int add_backgroundgrid(void)
}
}
for(i = 0; i < NumGas; i++)
{
no = Father[i];
vol += Nodes[no].len * Nodes[no].len * Nodes[no].len / 8;
}
MPI_Allreduce(&vol, &voltot, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
mpi_printf("\nADD BACKGROUND GRID: voltot=%g %g\n", voltot, pow(DomainLen, 3));
int count_leaves = 0, count_leaves_all;
for(i = Tree_MaxPart, vol = 0; i < numnodes + Tree_MaxPart; i++)
......@@ -121,7 +113,6 @@ int add_backgroundgrid(void)
mpi_printf("ADD BACKGROUND GRID: count_leaves_all=%d\n\n", count_leaves_all);
if((NumGas + count_leaves >= All.MaxPartSph) || (NumPart + count_leaves >= All.MaxPart))
flag = 1;
......@@ -163,7 +154,7 @@ int add_backgroundgrid(void)
// newid is now the maxid+total of count_leaves over all previous tasks
IDNew = maxid + 1; /* old gas particles will have IDs below this */
IDNew = maxid + 1; /* old gas particles will have IDs below this */
// move all particle and sph particle data down the arrays by
// count_leaves.
......@@ -192,10 +183,9 @@ int add_backgroundgrid(void)
P[count_leaves].Vel[1] = 0;
P[count_leaves].Vel[2] = 0;
P[count_leaves].Mass = 0;
P[count_leaves].Mass = 0;
P[count_leaves].TimeBinHydro = 0;
P[count_leaves].TimeBinGrav = 0;
P[count_leaves].TimeBinGrav = 0;
P[count_leaves].Ti_Current = All.Ti_Current;
......@@ -206,15 +196,15 @@ int add_backgroundgrid(void)
SphP[count_leaves].DivB = 0;
#endif /* #ifdef MHD */
P[count_leaves].Type = 0;
P[count_leaves].Type = 0;
P[count_leaves].SofteningType = All.SofteningTypeOfPartType[0];
// this puts the new ID at the right spot
P[count_leaves].ID = newid++;
SphP[count_leaves].Volume = Nodes[i].len * Nodes[i].len * Nodes[i].len;
SphP[count_leaves].Utherm = 0;
SphP[count_leaves].Energy = 0;
SphP[count_leaves].Volume = Nodes[i].len * Nodes[i].len * Nodes[i].len;
SphP[count_leaves].Utherm = 0;
SphP[count_leaves].Energy = 0;
SphP[count_leaves].Momentum[0] = 0;
SphP[count_leaves].Momentum[1] = 0;
SphP[count_leaves].Momentum[2] = 0;
......@@ -224,7 +214,7 @@ int add_backgroundgrid(void)
}
}
/* Delete the force tree */
/* Delete the force tree */
myfree(Father);
myfree(Nextnode);
myfree(Tree_Points);
......@@ -242,7 +232,7 @@ int add_backgroundgrid(void)
{
// remove particle i by swapping in the last sph particle
// and then swap the last particle to that spot
P[i] = P[NumGas - 1];
P[i] = P[NumGas - 1];
P[NumGas - 1] = P[NumPart - 1];
SphP[i] = SphP[NumGas - 1];
......@@ -258,12 +248,10 @@ int add_backgroundgrid(void)
if(P[i].Mass > 0)
{
SphP[i].Utherm = SphP[i].Energy / P[i].Mass;
P[i].Vel[0] = SphP[i].Momentum[0] / P[i].Mass;
P[i].Vel[1] = SphP[i].Momentum[1] / P[i].Mass;
P[i].Vel[2] = SphP[i].Momentum[2] / P[i].Mass;
P[i].Vel[0] = SphP[i].Momentum[0] / P[i].Mass;
P[i].Vel[1] = SphP[i].Momentum[1] / P[i].Mass;
P[i].Vel[2] = SphP[i].Momentum[2] / P[i].Mass;
}
}
}
......@@ -288,15 +276,15 @@ int add_backgroundgrid(void)
savepositions(0, 0);
mpi_printf("\nADD BACKGROUND GRID: GridSize = %d\n", All.GridSize);
mpi_printf("ADD BACKGROUND GRID: Suggested value for MeanVolume = %g\nADD BACKGROUND GRID: Suggested value for ReferenceGasPartMass = %g\n",
pow(All.BoxSize / All.GridSize, 3), mtot / ngas_count_all_old);
mpi_printf(
"ADD BACKGROUND GRID: Suggested value for MeanVolume = %g\nADD BACKGROUND GRID: Suggested value for ReferenceGasPartMass = %g\n",
pow(All.BoxSize / All.GridSize, 3), mtot / ngas_count_all_old);
mpi_printf("ADD BACKGROUND GRID: Suggested value for BoxSize = %g\n", All.BoxSize);
mpi_printf("ADD BACKGROUND GRID: Done!\n\n");
return 0;
}
/*! \brief Changes the box size to a new value.
*
* LONG_X, LONG_Y and LONG_Z are still active as specified in Config file.
......@@ -325,7 +313,6 @@ void modify_boxsize(double new_val)
#endif /* #ifdef LONG_Z */
}
/*! \brief Prepares computational box; makes sure simulation volume is large
* enough.
*
......@@ -339,7 +326,6 @@ void prepare_domain_backgroundgrid(void)
double len_gas, xmin_gas[3], xmax_gas[3], xmin_gas_glob[3], xmax_gas_glob[3];
double min_box_size, max_box_size;
mpi_printf("\n\nADD BACKGROUND GRID: preparing domain for first domain decomposition\n");
/* Checking GridSize limits */
......@@ -354,7 +340,7 @@ void prepare_domain_backgroundgrid(void)
/* Now checking it is a power of two. If not assign the closest value (is this required?) */
bit_num = 0;
size = ADDBACKGROUNDGRIDMAX;
size = ADDBACKGROUNDGRIDMAX;
while(((size & 1) == 0) && size > 1)
{
size >>= 1;
......@@ -381,8 +367,8 @@ void prepare_domain_backgroundgrid(void)
/* determine local extension */
for(j = 0; j < 3; j++)
{
xmin[j] = MAX_REAL_NUMBER;
xmax[j] = -MAX_REAL_NUMBER;
xmin[j] = MAX_REAL_NUMBER;
xmax[j] = -MAX_REAL_NUMBER;
xmin_gas[j] = MAX_REAL_NUMBER;
xmax_gas[j] = -MAX_REAL_NUMBER;
}
......@@ -416,14 +402,13 @@ void prepare_domain_backgroundgrid(void)
MPI_Allreduce(xmin_gas, xmin_gas_glob, 3, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD);
MPI_Allreduce(xmax_gas, xmax_gas_glob, 3, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
mpi_printf("ADD BACKGROUND GRID: Min and max coordinates.\n");
mpi_printf("ADD BACKGROUND GRID: xmin|ymin|zmin=% g|% g|% g.\n", xmin_glob[0], xmin_glob[1], xmin_glob[2]);
mpi_printf("ADD BACKGROUND GRID: xmax|ymax|zmax=% g|% g|% g.\n", xmax_glob[0], xmax_glob[1], xmax_glob[2]);
mpi_printf("ADD BACKGROUND GRID: xmin_gas|ymin_gas|zmin_gas=% g|% g|% g.\n", xmin_gas_glob[0], xmin_gas_glob[1], xmin_gas_glob[2]);
mpi_printf("ADD BACKGROUND GRID: xmax_gas|ymax_gas|zmax_gas=% g|% g|% g.\n", xmax_gas_glob[0], xmax_gas_glob[1], xmax_gas_glob[2]);
len = 0;
len = 0;
len_gas = 0;
for(j = 0; j < 3; j++)
{
......@@ -460,7 +445,7 @@ void prepare_domain_backgroundgrid(void)
while(min_topleave_num < NTask && (All.BoxSize / len_gas) > All.GridSize && All.GridSize < ADDBACKGROUNDGRIDMAX)
{
All.GridSize <<= 1;
min_topleave_num = (int) pow(len_gas * All.GridSize / All.BoxSize, 3.0);
min_topleave_num = (int)pow(len_gas * All.GridSize / All.BoxSize, 3.0);
mpi_printf("ADD BACKGROUND GRID: GridSize=%3d, min_topleave_num=%6d, NTask=%6d, BoxSize/GridSize=%g, len_gas/GridSize=%g\n",
All.GridSize, min_topleave_num, NTask, All.BoxSize / All.GridSize, len_gas / All.BoxSize);
}
......@@ -468,7 +453,7 @@ void prepare_domain_backgroundgrid(void)
else
{
All.GridSize <<= 1;
min_topleave_num = (int) pow(len_gas * All.GridSize / All.BoxSize, 3.0);
min_topleave_num = (int)pow(len_gas * All.GridSize / All.BoxSize, 3.0);
mpi_printf("ADD BACKGROUND GRID: GridSize=%3d, min_topleave_num=%6d, NTask=%6d, BoxSize/GridSize=%g, len_gas/GridSize=%g\n",
All.GridSize, min_topleave_num, NTask, All.BoxSize / All.GridSize, len_gas / All.BoxSize);
}
......@@ -476,14 +461,18 @@ void prepare_domain_backgroundgrid(void)
if(min_topleave_num < NTask)
{
char buf[500];
sprintf(buf, "min_topleave_num=%d < NTask=%d, MaxGridSize=%d. Try either to run with less task or to set the BoxSize to a smaller value\n", min_topleave_num, NTask, ADDBACKGROUNDGRIDMAX);
sprintf(buf,
"min_topleave_num=%d < NTask=%d, MaxGridSize=%d. Try either to run with less task or to set the BoxSize to a smaller "
"value\n",
min_topleave_num, NTask, ADDBACKGROUNDGRIDMAX);
terminate(buf);
}
if(len_gas / All.BoxSize > All.GridSize)
{
char buf[500];
sprintf(buf, "len_gas/BoxSize=%g > GridSize=%d, MaxGridSize=%d. GridSize should be increased if possible\n", len_gas / All.BoxSize, All.GridSize, ADDBACKGROUNDGRIDMAX);
sprintf(buf, "len_gas/BoxSize=%g > GridSize=%d, MaxGridSize=%d. GridSize should be increased if possible\n",
len_gas / All.BoxSize, All.GridSize, ADDBACKGROUNDGRIDMAX);
terminate(buf);
}
......@@ -499,5 +488,4 @@ void prepare_domain_backgroundgrid(void)
}
}
#endif /* #ifdef ADDBACKGROUNDGRID */
......@@ -35,32 +35,24 @@
* - 11.05.2018 Prepared file for public release -- Rainer Weinberger
*/
#ifndef ADD_BGGRID_H
#define ADD_BGGRID_H
#include "../main/allvars.h"
#ifdef ADDBACKGROUNDGRID
#define ADDBACKGROUNDGRIDMAX 256
#define FACTOR_MAX_BOX_SIZE 15.0
#define FACTOR_MIN_BOX_SIZE 2.0
#define ADDBACKGROUNDGRIDMAX 256
#define FACTOR_MAX_BOX_SIZE 15.0
#define FACTOR_MIN_BOX_SIZE 2.0
extern MyIDType IDNew;
int add_backgroundgrid(void);
void prepare_domain_backgroundgrid(void);
void calculate_weights();
void distribute_particles();
#endif /* #ifdef ADDBACKGROUNDGRID */
#endif /* ADD_BGGRID_H */
......@@ -28,30 +28,25 @@
* static void kernel_imported(void)
* void calculate_weights()
* int find_cells_evaluate(int target, int mode, int thread_id)
*
*
*
*
* \par Major modifications and contributions:
*
*
* - DD.MM.YYYY Description
* - 11.05.2018 Prepared file for public release -- Rainer Weinberger
*/
#include <mpi.h>
#include "../domain/domain.h"
#include "../main/allvars.h"
#include "../main/proto.h"
#include "../domain/domain.h"
#include "add_bggrid.h"
#ifdef ADDBACKGROUNDGRID
static int find_cells_evaluate(int target, int mode, int thread_id);
/*! \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.
......@@ -66,7 +61,6 @@ typedef struct
static data_in *DataIn, *DataGet;
/*! \brief Routine that fills the relevant particle/cell data into the input
* structure defined above. Needed by generic_comm_helpers2.
*
......@@ -76,7 +70,7 @@ static data_in *DataIn, *DataGet;
*
* \return void
*/
static void particle2in(data_in * in, int i, int firstnode)
static void particle2in(data_in *in, int i, int firstnode)
{
in->Pos[0] = P[i].Pos[0];
in->Pos[1] = P[i].Pos[1];
......@@ -87,7 +81,6 @@ 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.
......@@ -99,7 +92,6 @@ typedef struct
static data_out *DataResult, *DataOut;
/*! \brief Routine to store or combine result data. Needed by
* generic_comm_helpers2.
*
......@@ -111,22 +103,20 @@ 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) /* initial store */
if(mode == MODE_LOCAL_PARTICLES) /* initial store */
{
SphP[i].Weight = out->Weight;
}
else /* combine */
else /* combine */
{
SphP[i].Weight += out->Weight;
}
}
#include "../utils/generic_comm_helpers2.h"
/*! \brief Routine that defines what to do with local particles.
*
* Calls the *_evaluate function in MODE_LOCAL_PARTICLES.
......@@ -161,7 +151,6 @@ static void kernel_local(void)
}
}
/*! \brief Routine that defines what to do with imported particles.
*
* Calls the *_evaluate function in MODE_IMPORTED_PARTICLES.
......@@ -187,7 +176,6 @@ static void kernel_imported(void)
}
}
/*! \brief Calculates SPH weights of each cell.
*
* \return void
......@@ -195,7 +183,7 @@ static void kernel_imported(void)
void calculate_weights()
{
domain_free();
domain_Decomposition(); /* do new domain decomposition, will also make a new chained-list of synchronized particles */
domain_Decomposition(); /* do new domain decomposition, will also make a new chained-list of synchronized particles */
ngb_treeallocate();
ngb_treebuild(NumGas);
......@@ -222,7 +210,6 @@ void calculate_weights()
mpi_printf("ADD BACKGROUND GRID: done\n");
}
/*! \brief finds cells and adds up weights in an SPH fashion
*
* \param[in] target Index of particle/cell
......@@ -249,7 +236,7 @@ int find_cells_evaluate(int target, int mode, int thread_id)
particle2in(&local, target, 0);
target_data = &local;
numnodes = 1;
numnodes = 1;
firstnode = NULL;
}
else
......@@ -259,13 +246,13 @@ int find_cells_evaluate(int target, int mode, int thread_id)
generic_get_numnodes(target, &numnodes, &firstnode);
}
pos = target_data->Pos;
h = target_data->Hsml;
h2 = h * h;
pos = target_data->Pos;
h = target_data->Hsml;
h2 = h * h;
hinv = 1.0 / h;
#ifndef TWODIMS
hinv3 = hinv * hinv * hinv;
#else /* #ifndef TWODIMS */
#else /* #ifndef TWODIMS */
hinv3 = hinv * hinv / boxSize_Z;
#endif /* #ifndef TWODIMS #else */
......@@ -310,5 +297,4 @@ int find_cells_evaluate(int target, int mode, int thread_id)
return 0;
}
#endif /* #ifdef ADDBACKGROUNDGRID */
......@@ -28,29 +28,24 @@
* static void kernel_imported(void)
* void distribute_particles(void)
* int find_cells_evaluate(int target, int mode, int thread_id)
*
*
*
*
* \par Major modifications and contributions:
*
*
* - DD.MM.YYYY Description
* - 11.05.2018 Prepared file for public release -- Rainer Weinberger
*/
#include <mpi.h>
#include "../main/allvars.h"
#include "../main/proto.h"
#include "add_bggrid.h"
#ifdef ADDBACKGROUNDGRID
static int find_cells_evaluate(int target, int mode, int thread_id);
/*! \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.
......@@ -65,13 +60,12 @@ typedef struct
MyFloat Momentum[3];
#ifdef MHD
MyFloat B[3];
#endif /* #ifdef MHD */
#endif /* #ifdef MHD */
int Firstnode;
} data_in;
static data_in *DataIn, *DataGet;
/*! \brief Routine that fills the relevant particle/cell data into the input
* structure defined above. Needed by generic_comm_helpers2.
*
......@@ -81,7 +75,7 @@ static data_in *DataIn, *DataGet;
*
* \return void
*/
static void particle2in(data_in * in, int i, int firstnode)
static void particle2in(data_in *in, int i, int firstnode)
{
in->Pos[0] = P[i].Pos[0];
in->Pos[1] = P[i].Pos[1];
......@@ -89,8 +83,8 @@ static void particle2in(data_in * in, int i, int firstnode)
in->Hsml = SphP[i].Hsml;
in->Weight = SphP[i].Weight;
in->Mass = P[i].Mass;
in->Weight = SphP[i].Weight;
in->Mass = P[i].Mass;
in->InternalEnergy = SphP[i].Utherm * P[i].Mass;
int k;
......@@ -105,7 +99,6 @@ 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.
......@@ -117,7 +110,6 @@ typedef struct
static data_out *DataResult, *DataOut;
/*! \brief Routine to store or combine result data. Needed by
* generic_comm_helpers2.
*
......@@ -129,15 +121,10 @@ static data_out *DataResult, *DataOut;
*
* \return void
*/
static void out2particle(data_out * out, int i, int mode)
{
return;
}
static void out2particle(data_out *out, int i, int mode) { return; }
#include "../utils/generic_comm_helpers2.h"
/*! \brief Routine that defines what to do with local particles.
*
* Calls the *_evaluate function in MODE_LOCAL_PARTICLES.
......@@ -169,10 +156,8 @@ static void kernel_local(void)
find_cells_evaluate(i, MODE_LOCAL_PARTICLES, threadid);
}
}
}
/*! \brief Routine that defines what to do with imported particles.
*
* Calls the *_evaluate function in MODE_IMPORTED_PARTICLES.
......@@ -198,7 +183,6 @@ static void kernel_imported(void)
}
}
/*! \brief Main function to distribute hydro quantities over a kernel average.
*
* \return void
......@@ -233,7 +217,6 @@ void distribute_particles(void)
mpi_printf("ADD BACKGROUND GRID: done\n");
}
/*! \brief Distributes imported properties on neighbouring cells.
*
* \param[in] target Index of particle/cell.
......@@ -259,7 +242,7 @@ int find_cells_evaluate(int target, int mode, int thread_id)
particle2in(&local, target, 0);
target_data = &local;
numnodes = 1;
numnodes = 1;
firstnode = NULL;
}
else
......@@ -269,13 +252,13 @@ int find_cells_evaluate(int target, int mode, int thread_id)
generic_get_numnodes(target, &numnodes, &firstnode);
}
pos = target_data->Pos;
h = target_data->Hsml;
h2 = h * h;
pos = target_data->Pos;
h = target_data->Hsml;
h2 = h * h;
hinv = 1.0 / h;
#ifndef TWODIMS
#ifndef TWODIMS
hinv3 = hinv * hinv * hinv;
#else /* #ifndef TWODIMS */