diff --git a/src/Makefile.am b/src/Makefile.am index 6b663b9d4e50a3580238311ca45b13402f3067f3..095b11272dae027363628977c6b3098c3ab2a409 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -55,7 +55,7 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \ runner_doiact_fft.c threadpool.c cooling.c # Include files for distribution, not installation. -nobase_noinst_HEADERS = approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h \ +nobase_noinst_HEADERS = align.h approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h \ kernel_long_gravity.h vector.h runner_doiact.h runner_doiact_grav.h runner_doiact_fft.h \ units.h intrinsics.h minmax.h kick.h timestep.h drift.h adiabatic_index.h io_properties.h \ dimension.h equation_of_state.h \ diff --git a/src/align.h b/src/align.h new file mode 100644 index 0000000000000000000000000000000000000000..84e2909c0866c18f0f8378df9d0efc8d0f6545b5 --- /dev/null +++ b/src/align.h @@ -0,0 +1,27 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + ******************************************************************************/ +#ifndef SWIFT_ALIGN_H +#define SWIFT_ALIGN_H + +/** + * @brief Defines alignment of structures + */ +#define SWIFT_STRUCT_ALIGN __attribute__((aligned(32))) + +#endif /* SWIFT_ALIGN_H */ diff --git a/src/cell.h b/src/cell.h index 8e0494fa9db89b451a776140c18b57b54547120f..b78cc0a8f842770f60777e3986616a175d2f33ca 100644 --- a/src/cell.h +++ b/src/cell.h @@ -30,6 +30,7 @@ #include <stddef.h> /* Local includes. */ +#include "align.h" #include "lock.h" #include "multipole.h" #include "part.h" @@ -44,7 +45,7 @@ struct space; * The maximum was lowered by a further factor of 2 to be on the safe side.*/ #define cell_max_tag (1 << 29) -#define cell_align 32 +#define cell_align 128 /* Global variables. */ extern int cell_next_tag; @@ -74,7 +75,8 @@ struct pcell { /* Relative indices of the cell's progeny. */ int progeny[8]; -}; + +} SWIFT_STRUCT_ALIGN; /* Structure to store the data of a single cell. */ struct cell { @@ -208,7 +210,7 @@ struct cell { #endif -} __attribute__((aligned(cell_align))); +} SWIFT_STRUCT_ALIGN; /* Convert cell location to ID. */ #define cell_getid(cdim, i, j, k) \ diff --git a/src/gravity/Default/gravity_part.h b/src/gravity/Default/gravity_part.h index 1850ff0a1644d3593f78f150646eae8b2f074e1e..f06e65e5b30ebcd609c0c6204de33da17b770add 100644 --- a/src/gravity/Default/gravity_part.h +++ b/src/gravity/Default/gravity_part.h @@ -53,6 +53,6 @@ struct gpart { which this gpart is linked. */ long long id_or_neg_offset; -} __attribute__((aligned(gpart_align))); +} SWIFT_STRUCT_ALIGN; #endif /* SWIFT_DEFAULT_GRAVITY_PART_H */ diff --git a/src/hydro/Default/hydro_part.h b/src/hydro/Default/hydro_part.h index 1b9dd01b845c5e0e7c29381c5136ee8dded54479..c7464bcf338b1c5b81ffa91d92264c2bd35e9313 100644 --- a/src/hydro/Default/hydro_part.h +++ b/src/hydro/Default/hydro_part.h @@ -38,7 +38,7 @@ struct xpart { /* Old density. */ float omega; -} __attribute__((aligned(xpart_align))); +} SWIFT_STRUCT_ALIGN; /* Data of a single particle. */ struct part { @@ -125,6 +125,6 @@ struct part { /* Pointer to corresponding gravity part. */ struct gpart* gpart; -} __attribute__((aligned(part_align))); +} SWIFT_STRUCT_ALIGN; #endif /* SWIFT_DEFAULT_HYDRO_PART_H */ diff --git a/src/hydro/Gadget2/hydro_part.h b/src/hydro/Gadget2/hydro_part.h index 8ce279326e6aac7daace5006cffeca7735470395..0cdc1a8ab2b8d865f360dfba40486f3fb3056286 100644 --- a/src/hydro/Gadget2/hydro_part.h +++ b/src/hydro/Gadget2/hydro_part.h @@ -33,7 +33,7 @@ struct xpart { /* Additional data used to record cooling information */ struct cooling_xpart_data cooling_data; -} __attribute__((aligned(xpart_align))); +} SWIFT_STRUCT_ALIGN; /* Data of a single particle. */ struct part { diff --git a/src/hydro/Gizmo/hydro_io.h b/src/hydro/Gizmo/hydro_io.h index e5f221ae4345dc519a50d332131ecf296f318338..5de2260bf3046e0d09bf94aa56c4fb772045dac7 100644 --- a/src/hydro/Gizmo/hydro_io.h +++ b/src/hydro/Gizmo/hydro_io.h @@ -124,8 +124,8 @@ void hydro_write_particles(struct part* parts, struct io_props* list, UNIT_CONV_ACCELERATION, parts, a_hydro); list[7] = io_make_output_field("Density", FLOAT, 1, UNIT_CONV_DENSITY, parts, primitives.rho); - list[8] = io_make_output_field("Volume", FLOAT, 1, UNIT_CONV_VOLUME, parts, - geometry.volume); + list[8] = io_make_output_field("Volume", FLOAT, 1, UNIT_CONV_INV_VOLUME, + parts, geometry.volume); list[9] = io_make_output_field("GradDensity", FLOAT, 3, UNIT_CONV_DENSITY, parts, primitives.gradients.rho); list[10] = io_make_output_field_convert_part( diff --git a/src/hydro/Gizmo/hydro_part.h b/src/hydro/Gizmo/hydro_part.h index 781f078aa13c8ab4b02cb9509afe11fd47ed9774..16159bc8b958feaebf5fb9d17fb73832057d4573 100644 --- a/src/hydro/Gizmo/hydro_part.h +++ b/src/hydro/Gizmo/hydro_part.h @@ -33,7 +33,7 @@ struct xpart { /* Additional data used to record cooling information */ struct cooling_xpart_data cooling_data; -} __attribute__((aligned(xpart_align))); +} SWIFT_STRUCT_ALIGN; /* Data of a single particle. */ struct part { @@ -204,5 +204,3 @@ struct part { struct gpart *gpart; } __attribute__((aligned(part_align))); - -#endif /* SWIFT_GIZMO_HYDRO_PART_H */ diff --git a/src/hydro/Minimal/hydro_part.h b/src/hydro/Minimal/hydro_part.h index 8b1b2f74203b32809ed3f4d2305ce660ab3dd0b5..c83797b42b73f8cd8dd5bc993053769ba0cd354e 100644 --- a/src/hydro/Minimal/hydro_part.h +++ b/src/hydro/Minimal/hydro_part.h @@ -52,7 +52,7 @@ struct xpart { struct cooling_xpart_data cooling_data; /*!< Additional data used to record cooling information */ -} __attribute__((aligned(xpart_align))); +} SWIFT_STRUCT_ALIGN; /** * @brief Particle fields for the SPH particles diff --git a/src/part.h b/src/part.h index ea895e6e0295d6a8b63309c7bd6855daa2cf7d64..af39d10fafc11d4435ddbcc087fbf08178b18959 100644 --- a/src/part.h +++ b/src/part.h @@ -31,12 +31,13 @@ #endif /* Local headers. */ +#include "align.h" #include "const.h" /* Some constants. */ -#define part_align 64 -#define xpart_align 32 -#define gpart_align 32 +#define part_align 128 +#define xpart_align 128 +#define gpart_align 128 /* Import the right hydro particle definition */ #if defined(MINIMAL_SPH) diff --git a/src/task.h b/src/task.h index f070451fe4e79e0c16dc3dcca1ce145c08841c47..4928dc00bcd7958efdd6987b5aec90ab4b3e92fa 100644 --- a/src/task.h +++ b/src/task.h @@ -26,6 +26,7 @@ #include "../config.h" /* Includes. */ +#include "align.h" #include "cell.h" #include "cycle.h" @@ -149,7 +150,7 @@ struct task { /*! Is this task implicit (i.e. does not do anything) ? */ char implicit; -} __attribute__((aligned(32))); +} SWIFT_STRUCT_ALIGN; /* Function prototypes. */ void task_unlock(struct task *t); diff --git a/src/units.c b/src/units.c index f598b5ddf0b1a4b165648d5378915cd6f10f0bba..2241d441ec9af9b6d5083191e8f61010ebaccb20 100644 --- a/src/units.c +++ b/src/units.c @@ -319,6 +319,9 @@ void units_get_base_unit_exponants_array(float baseUnitsExp[5], break; case UNIT_CONV_VOLUME: + baseUnitsExp[UNIT_LENGTH] = 3.f; + + case UNIT_CONV_INV_VOLUME: baseUnitsExp[UNIT_LENGTH] = -3.f; } } diff --git a/src/units.h b/src/units.h index 26fa15a66528dd39ea232cdf94da2ff0230300cd..78fdf1c23c3c276607d5353ee3437d8eb1e96537 100644 --- a/src/units.h +++ b/src/units.h @@ -90,7 +90,8 @@ enum UnitConversionFactor { UNIT_CONV_MAGNETIC_FIELD, UNIT_CONV_MAGNETIC_INDUCTANCE, UNIT_CONV_TEMPERATURE, - UNIT_CONV_VOLUME + UNIT_CONV_VOLUME, + UNIT_CONV_INV_VOLUME }; void units_init_cgs(struct UnitSystem*); diff --git a/tests/testSPHStep.c b/tests/testSPHStep.c index fa49ed9d00c37393abd2f7e17ae628d79b4125f6..ff2ec841b27bd5ca6190517bc39f4da0c28fbc0c 100644 --- a/tests/testSPHStep.c +++ b/tests/testSPHStep.c @@ -102,10 +102,6 @@ int main() { int i, j, k, offset[3]; struct part *p; - struct hydro_props hp; - hp.target_neighbours = 48.; - hp.delta_neighbours = 1.; - hp.max_smoothing_iterations = 30; int N = 10; float dim = 1.; @@ -146,11 +142,24 @@ int main() { /* Create the infrastructure */ struct space space; space.periodic = 0; - space.h_max = 1.; + space.cell_min = 1.; + + struct phys_const prog_const; + prog_const.const_newton_G = 1.f; + + struct hydro_props hp; + hp.target_neighbours = 48.f; + hp.delta_neighbours = 2.; + hp.max_smoothing_iterations = 1; + hp.CFL_condition = 0.1; struct engine e; - e.s = &space; + bzero(&e, sizeof(struct engine)); e.hydro_properties = &hp; + e.physical_constants = &prog_const; + e.s = &space; + e.time = 0.1f; + e.ti_current = 1; struct runner r; r.e = &e;