diff --git a/configure.ac b/configure.ac index 74fede99f4fbf578af4e703cedaa42f2c278b037..a411e8a8eed4fc3f65eca54d6782add1f7632588 100644 --- a/configure.ac +++ b/configure.ac @@ -627,7 +627,7 @@ fi # Hydro scheme. AC_ARG_WITH([hydro], [AS_HELP_STRING([--with-hydro=<scheme>], - [Hydro dynamics to use @<:@gadget2, minimal, hopkins, default, gizmo, shadowfax default: gadget2@:>@] + [Hydro dynamics to use @<:@gadget2, minimal, hopkins, default, gizmo, shadowfax debug default: gadget2@:>@] )], [with_hydro="$withval"], [with_hydro="gadget2"] @@ -639,6 +639,9 @@ case "$with_hydro" in minimal) AC_DEFINE([MINIMAL_SPH], [1], [Minimal SPH]) ;; + debug) + AC_DEFINE([DEBUG_INTERACTIONS_SPH], [1], [Debug SPH]) + ;; hopkins) AC_DEFINE([HOPKINS_PE_SPH], [1], [Pressure-Entropy SPH]) ;; diff --git a/examples/SedovBlast_3D/sedov.yml b/examples/SedovBlast_3D/sedov.yml index 1cc4aced9af3314cadde44f768016225426addf6..ff43a0ed414585e31f4166d475eda7a284a7ef88 100644 --- a/examples/SedovBlast_3D/sedov.yml +++ b/examples/SedovBlast_3D/sedov.yml @@ -32,4 +32,5 @@ SPH: # Parameters related to the initial conditions InitialConditions: file_name: ./sedov.hdf5 # The file to read + h_scaling: 3.3 diff --git a/src/debug.c b/src/debug.c index c9f12370f0e59f812afc72eb55b0bdaa032edfe1..ac886fc8d75a03ac67b213e0639cd384f0980529 100644 --- a/src/debug.c +++ b/src/debug.c @@ -21,16 +21,15 @@ ******************************************************************************/ /* Config parameters. */ -#include "../config.h" + +/* This object's header. */ +#include "debug.h" /* Some standard headers. */ #include <float.h> #include <stdio.h> #include <unistd.h> -/* This object's header. */ -#include "debug.h" - /* Local includes. */ #include "active.h" #include "cell.h" @@ -41,7 +40,9 @@ #include "space.h" /* Import the right hydro definition */ -#if defined(MINIMAL_SPH) +#if defined(DEBUG_INTERACTIONS_SPH) +#include "./hydro/DebugInteractions/hydro_debug.h" +#elif defined(MINIMAL_SPH) #include "./hydro/Minimal/hydro_debug.h" #elif defined(GADGET2_SPH) #include "./hydro/Gadget2/hydro_debug.h" diff --git a/src/debug.h b/src/debug.h index 7bea11de6ac3fe82ae9b3f1be84249f75742ecaf..20ae8fc2c20fa458b7be82f75b2fbb3be9acd32f 100644 --- a/src/debug.h +++ b/src/debug.h @@ -19,6 +19,9 @@ #ifndef SWIFT_DEBUG_H #define SWIFT_DEBUG_H +/* Config parameters. */ +#include "../config.h" + /* Includes. */ #include "cell.h" #include "part.h" diff --git a/src/engine.c b/src/engine.c index 8f2ce85a970233178eebaa9ffd0f6598f7c2b467..c6fcf2099b207138f142a92668daeb5bd42d6d49 100644 --- a/src/engine.c +++ b/src/engine.c @@ -4762,14 +4762,14 @@ void engine_compute_next_snapshot_time(struct engine *e) { */ void engine_clean(struct engine *e) { -#ifdef WITH_VECTORIZATION for (int i = 0; i < e->nr_threads; ++i) { +#ifdef WITH_VECTORIZATION cache_clean(&e->runners[i].ci_cache); cache_clean(&e->runners[i].cj_cache); +#endif gravity_cache_clean(&e->runners[i].ci_gravity_cache); gravity_cache_clean(&e->runners[i].cj_gravity_cache); } -#endif free(e->runners); free(e->snapshotUnits); free(e->links); diff --git a/src/hydro.h b/src/hydro.h index abb49d35b204bbaf986f502d796883e7eb778e7f..cbe26761e2470bea73028d1e2ed12204ac730d0e 100644 --- a/src/hydro.h +++ b/src/hydro.h @@ -27,7 +27,11 @@ #include "kernel_hydro.h" /* Import the right functions */ -#if defined(MINIMAL_SPH) +#if defined(DEBUG_INTERACTIONS_SPH) +#include "./hydro/DebugInteractions/hydro.h" +#include "./hydro/DebugInteractions/hydro_iact.h" +#define SPH_IMPLEMENTATION "Debug SELF/PAIR" +#elif defined(MINIMAL_SPH) #include "./hydro/Minimal/hydro.h" #include "./hydro/Minimal/hydro_iact.h" #define SPH_IMPLEMENTATION "Minimal version of SPH (e.g. Price 2010)" diff --git a/src/hydro/DebugInteractions/hydro.h b/src/hydro/DebugInteractions/hydro.h new file mode 100644 index 0000000000000000000000000000000000000000..dfffab642ae99e3bbb1928984e8daaf44d76c8eb --- /dev/null +++ b/src/hydro/DebugInteractions/hydro.h @@ -0,0 +1,313 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2017 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_DEBUG_INTERACTIONS_HYDRO_H +#define SWIFT_DEBUG_INTERACTIONS_HYDRO_H + +/** + * @file DebugInteractions/hydro.h + * @brief Empty SPH implementation used solely to test the SELF/PAIR routines. + */ + +#include "hydro_properties.h" +#include "hydro_space.h" +#include "part.h" + +#include <float.h> + +/** + * @brief Returns the internal energy of a particle + * + * @param p The particle of interest + */ +__attribute__((always_inline)) INLINE static float hydro_get_internal_energy( + const struct part *restrict p) { + + return 0.f; +} + +/** + * @brief Returns the pressure of a particle + * + * @param p The particle of interest + */ +__attribute__((always_inline)) INLINE static float hydro_get_pressure( + const struct part *restrict p) { + + return 0.f; +} + +/** + * @brief Returns the entropy of a particle + * + * @param p The particle of interest + */ +__attribute__((always_inline)) INLINE static float hydro_get_entropy( + const struct part *restrict p) { + + return 0.f; +} + +/** + * @brief Returns the sound speed of a particle + * + * @param p The particle of interest + */ +__attribute__((always_inline)) INLINE static float hydro_get_soundspeed( + const struct part *restrict p) { + + return 0.f; +} + +/** + * @brief Returns the density of a particle + * + * @param p The particle of interest + */ +__attribute__((always_inline)) INLINE static float hydro_get_density( + const struct part *restrict p) { + + return 0.f; +} + +/** + * @brief Returns the mass of a particle + * + * @param p The particle of interest + */ +__attribute__((always_inline)) INLINE static float hydro_get_mass( + const struct part *restrict p) { + return 0.f; +} + +/** + * @brief Returns the time derivative of internal energy of a particle + * + * We assume a constant density. + * + * @param p The particle of interest + */ +__attribute__((always_inline)) INLINE static float hydro_get_internal_energy_dt( + const struct part *restrict p) { + return 0.f; +} + +/** + * @brief Returns the time derivative of internal energy of a particle + * + * We assume a constant density. + * + * @param p The particle of interest. + * @param du_dt The new time derivative of the internal energy. + */ +__attribute__((always_inline)) INLINE static void hydro_set_internal_energy_dt( + struct part *restrict p, float du_dt) {} + +/** + * @brief Computes the hydro time-step of a given particle + * + * @param p Pointer to the particle data + * @param xp Pointer to the extended particle data + * + */ +__attribute__((always_inline)) INLINE static float hydro_compute_timestep( + const struct part *restrict p, const struct xpart *restrict xp, + const struct hydro_props *restrict hydro_properties) { + + return FLT_MAX; +} + +/** + * @brief Does some extra hydro operations once the actual physical time step + * for the particle is known. + * + * @param p The particle to act upon. + * @param dt Physical time step of the particle during the next step. + */ +__attribute__((always_inline)) INLINE static void hydro_timestep_extra( + struct part *p, float dt) {} + +/** + * @brief Prepares a particle for the density calculation. + * + * Zeroes all the relevant arrays in preparation for the sums taking place in + * the variaous density tasks + * + * @param p The particle to act upon + * @param hs #hydro_space containing hydro specific space information. + */ +__attribute__((always_inline)) INLINE static void hydro_init_part( + struct part *restrict p, const struct hydro_space *hs) { + + for (int i = 0; i < 256; ++i) p->ids_ngbs_density[i] = -1; + p->num_ngb_density = 0; + + p->density.wcount = 0.f; + p->density.wcount_dh = 0.f; +} + +/** + * @brief Finishes the density calculation. + * + * Multiplies the density and number of neighbours by the appropiate constants + * and add the self-contribution term. + * + * @param p The particle to act upon + */ +__attribute__((always_inline)) INLINE static void hydro_end_density( + struct part *restrict p) { + + /* Some smoothing length multiples. */ + const float h = p->h; + const float h_inv = 1.0f / h; /* 1/h */ + const float h_inv_dim = pow_dimension(h_inv); /* 1/h^d */ + const float h_inv_dim_plus_one = h_inv_dim * h_inv; /* 1/h^(d+1) */ + + /* Final operation on the density (add self-contribution). */ + p->density.wcount += kernel_root; + p->density.wcount_dh -= hydro_dimension * kernel_root; + + /* Finish the calculation by inserting the missing h-factors */ + p->density.wcount *= h_inv_dim; + p->density.wcount_dh *= h_inv_dim_plus_one; +} + +/** + * @brief Sets all particle fields to sensible values when the #part has 0 ngbs. + * + * @param p The particle to act upon + * @param xp The extended particle data to act upon + */ +__attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( + struct part *restrict p, struct xpart *restrict xp) { + + /* Some smoothing length multiples. */ + const float h = p->h; + const float h_inv = 1.0f / h; /* 1/h */ + const float h_inv_dim = pow_dimension(h_inv); /* 1/h^d */ + + /* Re-set problematic values */ + p->density.wcount = kernel_root * kernel_norm * h_inv_dim; + p->density.wcount_dh = 0.f; +} + +/** + * @brief Prepare a particle for the force calculation. + * + * Computes viscosity term, conduction term and smoothing length gradient terms. + * + * @param p The particle to act upon + * @param xp The extended particle data to act upon + * @param ti_current The current time (on the timeline) + * @param timeBase The minimal time-step size + */ +__attribute__((always_inline)) INLINE static void hydro_prepare_force( + struct part *restrict p, struct xpart *restrict xp) {} + +/** + * @brief Reset acceleration fields of a particle + * + * Resets all hydro acceleration and time derivative fields in preparation + * for the sums taking place in the variaous force tasks + * + * @param p The particle to act upon + */ +__attribute__((always_inline)) INLINE static void hydro_reset_acceleration( + struct part *restrict p) { + + for (int i = 0; i < 256; ++i) p->ids_ngbs_force[i] = -1; + p->num_ngb_force = 0; + + p->force.h_dt = 0.f; +} + +/** + * @brief Sets the values to be predicted in the drifts to their values at a + * kick time + * + * @param p The particle. + * @param xp The extended data of this particle. + */ +__attribute__((always_inline)) INLINE static void hydro_reset_predicted_values( + struct part *restrict p, const struct xpart *restrict xp) {} + +/** + * @brief Predict additional particle fields forward in time when drifting + * + * @param p The particle + * @param xp The extended data of the particle + * @param dt The drift time-step. + * @param t0 The time at the start of the drift + * @param t1 The time at the end of the drift + * @param timeBase The minimal time-step size + */ +__attribute__((always_inline)) INLINE static void hydro_predict_extra( + struct part *restrict p, const struct xpart *restrict xp, float dt) {} + +/** + * @brief Finishes the force calculation. + * + * Multiplies the forces and accelerationsby the appropiate constants + * + * @param p The particle to act upon + */ +__attribute__((always_inline)) INLINE static void hydro_end_force( + struct part *restrict p) {} + +/** + * @brief Kick the additional variables + * + * @param p The particle to act upon + * @param xp The particle extended data to act upon + * @param dt The time-step for this kick + */ +__attribute__((always_inline)) INLINE static void hydro_kick_extra( + struct part *restrict p, struct xpart *restrict xp, float dt) {} + +/** + * @brief Converts hydro quantity of a particle at the start of a run + * + * Requires the density to be known + * + * @param p The particle to act upon + */ +__attribute__((always_inline)) INLINE static void hydro_convert_quantities( + struct part *restrict p, struct xpart *restrict xp) {} + +/** + * @brief Initialises the particles for the first time + * + * This function is called only once just after the ICs have been + * read in to do some conversions. + * + * @param p The particle to act upon + * @param xp The extended particle data to act upon + */ +__attribute__((always_inline)) INLINE static void hydro_first_init_part( + struct part *restrict p, struct xpart *restrict xp) { + + p->time_bin = 0; + xp->v_full[0] = p->v[0]; + xp->v_full[1] = p->v[1]; + xp->v_full[2] = p->v[2]; + + hydro_reset_acceleration(p); + hydro_init_part(p, NULL); +} + +#endif /* SWIFT_DEBUG_INTERACTIONS_HYDRO_H */ diff --git a/src/hydro/DebugInteractions/hydro_debug.h b/src/hydro/DebugInteractions/hydro_debug.h new file mode 100644 index 0000000000000000000000000000000000000000..5420f9cece2415fb5e2438b551eb605187741c13 --- /dev/null +++ b/src/hydro/DebugInteractions/hydro_debug.h @@ -0,0 +1,39 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2017 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_DEBUG_INTERACTIONS_HYDRO_DEBUG_H +#define SWIFT_DEBUG_INTERACTIONS_HYDRO_DEBUG_H + +/** + * @file DebugInteractions/hydro_debug.h + * @brief Empty SPH implementation used solely to test the SELF/PAIR routines. + */ + +__attribute__((always_inline)) INLINE static void hydro_debug_particle( + const struct part* p, const struct xpart* xp) { + printf( + "x=[%.3e,%.3e,%.3e], " + "v=[%.3e,%.3e,%.3e],v_full=[%.3e,%.3e,%.3e] \n a=[%.3e,%.3e,%.3e],\n " + "h=%.3e, wcount=%.3f, wcount_dh=%.3e, dh/dt=%.3e time_bin=%d\n", + p->x[0], p->x[1], p->x[2], p->v[0], p->v[1], p->v[2], xp->v_full[0], + xp->v_full[1], xp->v_full[2], p->a_hydro[0], p->a_hydro[1], p->a_hydro[2], + p->h, p->density.wcount, p->density.wcount_dh, p->force.h_dt, + p->time_bin); +} + +#endif /* SWIFT_DEBUG_INTERACTIONS_HYDRO_DEBUG_H */ diff --git a/src/hydro/DebugInteractions/hydro_iact.h b/src/hydro/DebugInteractions/hydro_iact.h new file mode 100644 index 0000000000000000000000000000000000000000..89613f4902f0f9ab476110a7532664135b7b74ed --- /dev/null +++ b/src/hydro/DebugInteractions/hydro_iact.h @@ -0,0 +1,113 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2017 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_DEBUG_INTERACTIONS_HYDRO_IACT_H +#define SWIFT_DEBUG_INTERACTIONS_HYDRO_IACT_H + +/** + * @file DebugInteractions/hydro_iact.h + * @brief Empty SPH implementation used solely to test the SELF/PAIR routines. + */ + +/** + * @brief Density loop + */ +__attribute__((always_inline)) INLINE static void runner_iact_density( + float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) { + + float wi, wi_dx; + float wj, wj_dx; + + /* Get r and r inverse. */ + const float r = sqrtf(r2); + + /* Compute the kernel function for pi */ + const float hi_inv = 1.f / hi; + const float ui = r * hi_inv; + kernel_deval(ui, &wi, &wi_dx); + + /* Compute contribution to the number of neighbours */ + pi->density.wcount += wi; + pi->density.wcount_dh -= (hydro_dimension * wi + ui * wi_dx); + + /* Compute the kernel function for pj */ + const float hj_inv = 1.f / hj; + const float uj = r * hj_inv; + kernel_deval(uj, &wj, &wj_dx); + + /* Compute contribution to the number of neighbours */ + pj->density.wcount += wj; + pj->density.wcount_dh -= (hydro_dimension * wj + uj * wj_dx); + + /* Update ngb counters */ + pi->ids_ngbs_density[pi->num_ngb_density] = pj->id; + ++pi->num_ngb_density; + pj->ids_ngbs_density[pj->num_ngb_density] = pi->id; + ++pj->num_ngb_density; +} + +/** + * @brief Density loop (non-symmetric version) + */ +__attribute__((always_inline)) INLINE static void runner_iact_nonsym_density( + float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) { + + float wi, wi_dx; + + /* Get r and r inverse. */ + const float r = sqrtf(r2); + + /* Compute the kernel function */ + const float hi_inv = 1.0f / hi; + const float ui = r * hi_inv; + kernel_deval(ui, &wi, &wi_dx); + + /* Compute contribution to the number of neighbours */ + pi->density.wcount += wi; + pi->density.wcount_dh -= (hydro_dimension * wi + ui * wi_dx); + + /* Update ngb counters */ + pi->ids_ngbs_density[pi->num_ngb_density] = pj->id; + ++pi->num_ngb_density; +} + +/** + * @brief Force loop + */ +__attribute__((always_inline)) INLINE static void runner_iact_force( + float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) { + + /* Update ngb counters */ + pi->ids_ngbs_force[pi->num_ngb_force] = pj->id; + ++pi->num_ngb_force; + pj->ids_ngbs_force[pj->num_ngb_force] = pi->id; + ++pj->num_ngb_force; +} + +/** + * @brief Force loop (non-symmetric version) + */ +__attribute__((always_inline)) INLINE static void runner_iact_nonsym_force( + float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) { + + /* Update ngb counters */ + pi->ids_ngbs_force[pi->num_ngb_force] = pj->id; + ++pi->num_ngb_force; +} + +#endif /* SWIFT_DEBUG_INTERACTIONS_HYDRO_IACT_H */ diff --git a/src/hydro/DebugInteractions/hydro_io.h b/src/hydro/DebugInteractions/hydro_io.h new file mode 100644 index 0000000000000000000000000000000000000000..61b391a0c711edd5ad8acdbb6b914c070470992a --- /dev/null +++ b/src/hydro/DebugInteractions/hydro_io.h @@ -0,0 +1,114 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Coypright (c) 2017 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_DEBUG_INTERACTIONS_HYDRO_IO_H +#define SWIFT_DEBUG_INTERACTIONS_HYDRO_IO_H + +/** + * @file DebugInteractions/hydro_io.h + * @brief Empty SPH implementation used solely to test the SELF/PAIR routines. + */ + +#include "adiabatic_index.h" +#include "hydro.h" +#include "io_properties.h" +#include "kernel_hydro.h" + +/** + * @brief Specifies which particle fields to read from a dataset + * + * @param parts The particle array. + * @param list The list of i/o properties to read. + * @param num_fields The number of i/o fields to read. + */ +void hydro_read_particles(struct part* parts, struct io_props* list, + int* num_fields) { + + *num_fields = 4; + + /* List what we want to read */ + list[0] = io_make_input_field("Coordinates", DOUBLE, 3, COMPULSORY, + UNIT_CONV_LENGTH, parts, x); + list[1] = io_make_input_field("Velocities", FLOAT, 3, COMPULSORY, + UNIT_CONV_SPEED, parts, v); + list[2] = io_make_input_field("SmoothingLength", FLOAT, 1, COMPULSORY, + UNIT_CONV_LENGTH, parts, h); + list[3] = io_make_input_field("ParticleIDs", ULONGLONG, 1, COMPULSORY, + UNIT_CONV_NO_UNITS, parts, id); +} + +float convert_u(struct engine* e, struct part* p) { + + return hydro_get_internal_energy(p); +} + +float convert_P(struct engine* e, struct part* p) { + + return hydro_get_pressure(p); +} + +/** + * @brief Specifies which particle fields to write to a dataset + * + * @param parts The particle array. + * @param list The list of i/o properties to write. + * @param num_fields The number of i/o fields to write. + */ +void hydro_write_particles(struct part* parts, struct io_props* list, + int* num_fields) { + + *num_fields = 8; + + /* List what we want to write */ + list[0] = io_make_output_field("Coordinates", DOUBLE, 3, UNIT_CONV_LENGTH, + parts, x); + list[1] = + io_make_output_field("Velocities", FLOAT, 3, UNIT_CONV_SPEED, parts, v); + list[2] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH, + parts, h); + list[3] = io_make_output_field("ParticleIDs", ULONGLONG, 1, + UNIT_CONV_NO_UNITS, parts, id); + list[4] = io_make_output_field("Num_ngb_density", INT, 1, UNIT_CONV_NO_UNITS, + parts, num_ngb_density); + list[5] = io_make_output_field("Num_ngb_force", INT, 1, UNIT_CONV_NO_UNITS, + parts, num_ngb_force); + list[6] = io_make_output_field("Ids_ngb_density", LONGLONG, 256, + UNIT_CONV_NO_UNITS, parts, ids_ngbs_density); + list[7] = io_make_output_field("Ids_ngb_force", LONGLONG, 256, + UNIT_CONV_NO_UNITS, parts, ids_ngbs_force); +} + +/** + * @brief Writes the current model of SPH to the file + * @param h_grpsph The HDF5 group in which to write + */ +void writeSPHflavour(hid_t h_grpsph) { + + /* Viscosity and thermal conduction */ + io_write_attribute_s(h_grpsph, "Thermal Conductivity Model", "None"); + io_write_attribute_s(h_grpsph, "Viscosity Model", "None"); +} + +/** + * @brief Are we writing entropy in the internal energy field ? + * + * @return 1 if entropy is in 'internal energy', 0 otherwise. + */ +int writeEntropyFlag() { return 0; } + +#endif /* SWIFT_DEBUG_INTERACTIONS_HYDRO_IO_H */ diff --git a/src/hydro/DebugInteractions/hydro_part.h b/src/hydro/DebugInteractions/hydro_part.h new file mode 100644 index 0000000000000000000000000000000000000000..85410b2f3f9f11409398aeebc7bfe824c71cf217 --- /dev/null +++ b/src/hydro/DebugInteractions/hydro_part.h @@ -0,0 +1,110 @@ +/******************************************************************************* + * This file is part of SWIFT. + * Copyright (c) 2017 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_DEBUG_INTERACTIONS_HYDRO_PART_H +#define SWIFT_DEBUG_INTERACTIONS_HYDRO_PART_H + +/** + * @file DebugInteractions/hydro_part.h + * @brief Empty SPH implementation used solely to test the SELF/PAIR routines. + */ + +#include "cooling_struct.h" + +/* Extra particle data not needed during the SPH loops over neighbours. */ +struct xpart { + + /* Offset between current position and position at last tree rebuild. */ + float x_diff[3]; + + /* Offset between the current position and position at the last sort. */ + float x_diff_sort[3]; + + /* Velocity at the last full step. */ + float v_full[3]; + + /* Additional data used to record cooling information */ + struct cooling_xpart_data cooling_data; + +} SWIFT_STRUCT_ALIGN; + +/* Data of a single particle. */ +struct part { + + /* Particle ID. */ + long long id; + + /* Pointer to corresponding gravity part. */ + struct gpart* gpart; + + /* Particle position. */ + double x[3]; + + /* Particle predicted velocity. */ + float v[3]; + + /* Particle acceleration. */ + float a_hydro[3]; + + /* Particle cutoff radius. */ + float h; + + struct { + + /* Number of neighbours. */ + float wcount; + + /* Number of neighbours spatial derivative. */ + float wcount_dh; + + } density; + + struct { + + float h_dt; + + } force; + + /* Time-step length */ + timebin_t time_bin; + +#ifdef SWIFT_DEBUG_CHECKS + + /* Time of the last drift */ + integertime_t ti_drift; + + /* Time of the last kick */ + integertime_t ti_kick; + +#endif + + /*! List of interacting particles in the density SELF and PAIR */ + long long ids_ngbs_density[256]; + + /*! List of interacting particles in the force SELF and PAIR */ + long long ids_ngbs_force[256]; + + /*! Number of interactions in the density SELF and PAIR */ + int num_ngb_density; + + /*! Number of interactions in the force SELF and PAIR */ + int num_ngb_force; + +} SWIFT_STRUCT_ALIGN; + +#endif /* SWIFT_DEBUG_INTERACTIONS_HYDRO_PART_H */ diff --git a/src/hydro_io.h b/src/hydro_io.h index 202d724f821b570b427210bb48b7070563513458..29044de30960d1e80590d63609063c9552c79308 100644 --- a/src/hydro_io.h +++ b/src/hydro_io.h @@ -19,10 +19,13 @@ #ifndef SWIFT_HYDRO_IO_H #define SWIFT_HYDRO_IO_H -#include "./const.h" +/* Config parameters. */ +#include "../config.h" /* Import the right functions */ -#if defined(MINIMAL_SPH) +#if defined(DEBUG_INTERACTIONS_SPH) +#include "./hydro/DebugInteractions/hydro_io.h" +#elif defined(MINIMAL_SPH) #include "./hydro/Minimal/hydro_io.h" #elif defined(GADGET2_SPH) #include "./hydro/Gadget2/hydro_io.h" diff --git a/src/part.h b/src/part.h index 1b40aee0db3deb4790e07e3da9807060900d0c55..ebe0ae41c6a292e5ec140dcaf32c4620c7f8586f 100644 --- a/src/part.h +++ b/src/part.h @@ -42,7 +42,10 @@ #define gpart_align 128 /* Import the right hydro particle definition */ -#if defined(MINIMAL_SPH) +#if defined(DEBUG_INTERACTIONS_SPH) +#include "./hydro/DebugInteractions/hydro_part.h" +#define hydro_need_extra_init_loop 0 +#elif defined(MINIMAL_SPH) #include "./hydro/Minimal/hydro_part.h" #define hydro_need_extra_init_loop 0 #elif defined(GADGET2_SPH) diff --git a/src/vector.h b/src/vector.h index 70dbd16710837831230567f6eb0fcaeef453cd28..e463bbd2e62f0c6b51446d22a9805670b134e684 100644 --- a/src/vector.h +++ b/src/vector.h @@ -91,7 +91,8 @@ #define vec_init_mask_true(mask) ({ mask = 0xFFFF; }) #define vec_zero_mask(mask) ({ mask = 0; }) #define vec_create_mask(mask, cond) ({ mask = cond; }) -#define vec_combine_masks(mask1, mask2) ({ mask1 = vec_mask_and(mask1,mask2); }) +#define vec_combine_masks(mask1, mask2) \ + ({ mask1 = vec_mask_and(mask1, mask2); }) #define vec_pad_mask(mask, pad) ({ mask = mask >> (pad); }) #define vec_blend(mask, a, b) _mm512_mask_blend_ps(mask, a, b) #define vec_todbl_lo(a) _mm512_cvtps_pd(_mm512_extract128_ps(a, 0)) @@ -187,7 +188,8 @@ #define vec_and_mask(a, mask) _mm256_and_ps(a, mask.v) #define vec_init_mask_true(mask) mask.m = vec_setint1(0xFFFFFFFF) #define vec_create_mask(mask, cond) mask.v = cond -#define vec_combine_masks(mask1, mask2) ({ mask1.v = vec_mask_and(mask1,mask2); }) +#define vec_combine_masks(mask1, mask2) \ + ({ mask1.v = vec_mask_and(mask1, mask2); }) #define vec_zero_mask(mask) mask.v = vec_setzero() #define vec_pad_mask(mask, pad) \ for (int i = VEC_SIZE - (pad); i < VEC_SIZE; i++) mask.i[i] = 0 diff --git a/src/xmf.c b/src/xmf.c index 67682b4794ade773c39a748eddf765e392c74865..3c8bb257cca224a06e5b516be46e92dd0006183a 100644 --- a/src/xmf.c +++ b/src/xmf.c @@ -205,6 +205,7 @@ void xmf_write_groupfooter(FILE* xmfFile, enum part_type ptype) { */ int xmf_precision(enum IO_DATA_TYPE type) { switch (type) { + case INT: case FLOAT: return 4; break; @@ -233,6 +234,7 @@ const char* xmf_type(enum IO_DATA_TYPE type) { case DOUBLE: return "Float"; break; + case INT: case ULONGLONG: case LONGLONG: return "Int";