Skip to content
Snippets Groups Projects
Commit d12fde95 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Added documentation for the minimal SPH implementation such that it can be...

Added documentation for the minimal SPH implementation such that it can be used as a template for new versions of SPH.
parent c50f33ca
No related branches found
No related tags found
2 merge requests!136Master,!90Improved multi-timestep SPH
/******************************************************************************* /*******************************************************************************
* This file is part of SWIFT. * This file is part of SWIFT.
* Coypright (c) 2015 Matthieu Schaller (matthieu.schaller@durham.ac.uk) * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Lesser General Public License as published
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
/** /**
* @brief Computes the hydro time-step of a given particle * @brief Computes the hydro time-step of a given particle
* *
* This function returns the time-step of a particle given its hydro-dynamical
* state. A typical time-step calculation would be the use of the CFL condition.
*
* @param p Pointer to the particle data * @param p Pointer to the particle data
* @param xp Pointer to the extended particle data * @param xp Pointer to the extended particle data
* *
...@@ -39,7 +42,8 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep( ...@@ -39,7 +42,8 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep(
* @brief Initialises the particles for the first time * @brief Initialises the particles for the first time
* *
* This function is called only once just after the ICs have been * This function is called only once just after the ICs have been
* read in to do some conversions. * read in to do some conversions or assignments between the particle
* and extended particle fields.
* *
* @param p The particle to act upon * @param p The particle to act upon
* @param xp The extended particle data to act upon * @param xp The extended particle data to act upon
...@@ -54,7 +58,8 @@ __attribute__((always_inline)) ...@@ -54,7 +58,8 @@ __attribute__((always_inline))
* @brief Prepares a particle for the density calculation. * @brief Prepares a particle for the density calculation.
* *
* Zeroes all the relevant arrays in preparation for the sums taking place in * Zeroes all the relevant arrays in preparation for the sums taking place in
* the variaous density tasks * the various density loop over neighbours. Typically, all fields of the
* density sub-structure of a particle get zeroed in here.
* *
* @param p The particle to act upon * @param p The particle to act upon
*/ */
...@@ -71,6 +76,9 @@ __attribute__((always_inline)) ...@@ -71,6 +76,9 @@ __attribute__((always_inline))
* *
* Multiplies the density and number of neighbours by the appropiate constants * Multiplies the density and number of neighbours by the appropiate constants
* and add the self-contribution term. * and add the self-contribution term.
* Additional quantities such as velocity gradients will also get the final
*terms
* added to them here.
* *
* @param p The particle to act upon * @param p The particle to act upon
* @param time The current time * @param time The current time
...@@ -99,7 +107,12 @@ __attribute__((always_inline)) ...@@ -99,7 +107,12 @@ __attribute__((always_inline))
/** /**
* @brief Prepare a particle for the force calculation. * @brief Prepare a particle for the force calculation.
* *
* Computes viscosity term, conduction term and smoothing length gradient terms. * This function is called in the ghost task to convert some quantities coming
* from the density loop over neighbours into quantities ready to be used in the
* force loop over neighbours. Quantities are typically read from the density
* sub-structure and written to the force sub-structure.
* Examples of calculations done here include the calculation of viscosity term
* constants, thermal conduction terms, hydro conversions, etc.
* *
* @param p The particle to act upon * @param p The particle to act upon
* @param xp The extended particle data to act upon * @param xp The extended particle data to act upon
...@@ -115,7 +128,7 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force( ...@@ -115,7 +128,7 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
* @brief Reset acceleration fields of a particle * @brief Reset acceleration fields of a particle
* *
* Resets all hydro acceleration and time derivative fields in preparation * Resets all hydro acceleration and time derivative fields in preparation
* for the sums taking place in the variaous force tasks * for the sums taking place in the various force tasks.
* *
* @param p The particle to act upon * @param p The particle to act upon
*/ */
...@@ -136,6 +149,9 @@ __attribute__((always_inline)) ...@@ -136,6 +149,9 @@ __attribute__((always_inline))
/** /**
* @brief Predict additional particle fields forward in time when drifting * @brief Predict additional particle fields forward in time when drifting
* *
* Additional hydrodynamic quantites are drifted forward in time here. These
* include thermal quantities (thermal energy or total energy or entropy, ...).
*
* @param p The particle * @param p The particle
* @param xp The extended data of the particle * @param xp The extended data of the particle
* @param t0 The time at the start of the drift * @param t0 The time at the start of the drift
...@@ -160,7 +176,9 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra( ...@@ -160,7 +176,9 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra(
/** /**
* @brief Finishes the force calculation. * @brief Finishes the force calculation.
* *
* Multiplies the forces and accelerationsby the appropiate constants * Multiplies the force and accelerations by the appropiate constants
* and add the self-contribution term. In most cases, there is nothing
* to do here.
* *
* @param p The particle to act upon * @param p The particle to act upon
*/ */
...@@ -170,6 +188,9 @@ __attribute__((always_inline)) ...@@ -170,6 +188,9 @@ __attribute__((always_inline))
/** /**
* @brief Kick the additional variables * @brief Kick the additional variables
* *
* Additional hydrodynamic quantites are kicked forward in time here. These
* include thermal quantities (thermal energy or total energy or entropy, ...).
*
* @param p The particle to act upon * @param p The particle to act upon
* @param xp The particle extended data to act upon * @param xp The particle extended data to act upon
* @param dt The time-step for this kick * @param dt The time-step for this kick
...@@ -186,9 +207,12 @@ __attribute__((always_inline)) INLINE static void hydro_kick_extra( ...@@ -186,9 +207,12 @@ __attribute__((always_inline)) INLINE static void hydro_kick_extra(
} }
/** /**
* @brief Converts hydro quantity of a particle * @brief Converts hydro quantity of a particle at the start of a run
* *
* Requires the density to be known * This function is called once at the end of the engine_init_particle()
* routine (at the start of a calculation) after the densities of
* particles have been computed.
* This can be used to convert internal energy into entropy for instance.
* *
* @param p The particle to act upon * @param p The particle to act upon
*/ */
......
/******************************************************************************* /*******************************************************************************
* This file is part of SWIFT. * This file is part of SWIFT.
* Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk) * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
* Matthieu Schaller (matthieu.schaller@durham.ac.uk)
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Lesser General Public License as published
...@@ -27,24 +26,15 @@ ...@@ -27,24 +26,15 @@
#include "vector.h" #include "vector.h"
/** /**
* @brief SPH interaction functions following the Gadget-2 version of SPH. * @brief Minimal conservative implementation of SPH
* *
* The interactions computed here are the ones presented in the Gadget-2 paper * The thermal variable is the internal energy (u). No viscosity nor
*and use the same * thermal conduction terms are implemented.
* numerical coefficients as the Gadget-2 code. When used with the Spline-3
*kernel, the results
* should be equivalent to the ones obtained with Gadget-2 up to the rounding
*errors and interactions
* missed by the Gadget-2 tree-code neighbours search.
*
* The code uses internal energy instead of entropy as a thermodynamical
*variable.
*/ */
/** /**
* @brief Density loop * @brief Density loop
*/ */
__attribute__((always_inline)) INLINE static void runner_iact_density( __attribute__((always_inline)) INLINE static void runner_iact_density(
float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) { float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {
......
/******************************************************************************* /*******************************************************************************
* This file is part of SWIFT. * This file is part of SWIFT.
* Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk) * Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@durham.ac.uk)
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU Lesser General Public License as published
...@@ -17,88 +17,92 @@ ...@@ -17,88 +17,92 @@
* *
******************************************************************************/ ******************************************************************************/
/* Extra particle data not needed during the SPH loops over neighbours. */ /**
* @brief Particle fields not needed during the SPH loops over neighbours.
*
* This structure contains the particle fields that are not used in the
* density or force loops. Quantities should be used in the kick, drift and
* potentially ghost tasks only.
*/
struct xpart { struct xpart {
/* Old position, at last tree rebuild. */ double x_old[3]; /*!< Old position, at last tree rebuild. */
double x_old[3];
/* Velocity at the last full step. */ float v_full[3]; /*!< Velocity at the last full step. */
float v_full[3];
/* Thermal energy at the last full step. */ float u_full; /*!< Thermal energy at the last full step. */
float u_full;
} __attribute__((aligned(xpart_align))); } __attribute__((aligned(xpart_align)));
/* Data of a single particle. */ /**
* @brief Particle fields for the SPH particles
*
* The density and force substructures are used to contain variables only used
* within the density and force loops over neighbours. All more permanent
* variables should be declared in the main part of the part structure,
*/
struct part { struct part {
/* Particle position. */ double x[3]; /*!< Particle position. */
double x[3];
/* Particle predicted velocity. */ float v[3]; /*!< Particle predicted velocity. */
float v[3];
/* Particle acceleration. */ float a_hydro[3]; /*!< Particle acceleration. */
float a_hydro[3];
/* Particle mass. */ float mass; /*!< Particle mass. */
float mass;
/* Particle cutoff radius. */ float h; /*!< Particle smoothing length. */
float h;
/* Change in smoothing length over time. */ float h_dt; /*!< Time derivative of smoothing length */
float h_dt;
/* Particle time of beginning of time-step. */ float t_begin; /*!< Time at the beginning of time-step. */
float t_begin;
/* Particle time of end of time-step. */ float t_end; /*!< Time at the end of time-step. */
float t_end;
/* Particle internal energy. */ float u; /*!< Particle internal energy. */
float u;
/* Thermal energy time derivative */ float u_dt; /*!< Time derivative of the internal energy. */
float u_dt;
/* Particle density. */ float rho; /*!< Particle density. */
float rho;
/* Derivative of the density with respect to this particle's smoothing length. float rho_dh; /*!< Derivative of density with respect to h */
*/
float rho_dh;
/* Store density/force specific stuff. */ /* Store density/force specific stuff. */
union { union {
/**
* @brief Structure for the variables only used in the density loop over
* neighbours.
*
* Quantities in this sub-structure should only be accessed in the density
* loop over neighbours and the ghost task.
*/
struct { struct {
/* Particle number density. */ float wcount; /*!< Neighbour number count. */
float wcount;
/* Derivative of particle number density. */
float wcount_dh;
float wcount_dh; /*!< Derivative of the neighbour number with respect to
h. */
} density; } density;
/**
* @brief Structure for the variables only used in the force loop over
* neighbours.
*
* Quantities in this sub-structure should only be accessed in the force
* loop over neighbours and the ghost and kick tasks.
*/
struct { struct {
/* Pressure */ float pressure; /*!< Particle pressure. */
float pressure;
/* Signal velocity */ float v_sig; /*!< Particle signal velocity */
float v_sig;
} force; } force;
}; };
/* Particle ID. */ unsigned long long id; /*!< Particle unique ID. */
unsigned long long id;
/* Pointer to corresponding gravity part. */ struct gpart* gpart; /*!< Pointer to corresponding gravity part. */
struct gpart* gpart;
} __attribute__((aligned(part_align))); } __attribute__((aligned(part_align)));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment