drift.h 4.74 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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_DRIFT_H
#define SWIFT_DRIFT_H

/* Config parameters. */
#include "../config.h"

/* Local headers. */
#include "const.h"
#include "debug.h"
28
#include "dimension.h"
Matthieu Schaller's avatar
Matthieu Schaller committed
29
30
#include "hydro.h"
#include "part.h"
31
32

/**
33
 * @brief Perform the 'drift' operation on a #gpart.
34
35
 *
 * @param gp The #gpart to drift.
36
37
38
 * @param dt_drift The drift time-step.
 * @param ti_old Integer start of time-step (for debugging checks).
 * @param ti_current Integer end of time-step (for debugging checks).
39
 */
40
__attribute__((always_inline)) INLINE static void drift_gpart(
41
    struct gpart *restrict gp, double dt_drift, integertime_t ti_old,
42
    integertime_t ti_current) {
43
44
45
46
47
48
49
50
51
52
53
54

#ifdef SWIFT_DEBUG_CHECKS
  if (gp->ti_drift != ti_old)
    error(
        "g-particle has not been drifted to the current time "
        "gp->ti_drift=%lld, "
        "c->ti_old=%lld, ti_current=%lld",
        gp->ti_drift, ti_old, ti_current);

  gp->ti_drift = ti_current;
#endif

55
  /* Drift... */
56
57
58
  gp->x[0] += gp->v_full[0] * dt_drift;
  gp->x[1] += gp->v_full[1] * dt_drift;
  gp->x[2] += gp->v_full[2] * dt_drift;
59
60
61
62
63
64
65
}

/**
 * @brief Perform the 'drift' operation on a #part
 *
 * @param p The #part to drift.
 * @param xp The #xpart of the particle.
66
67
68
 * @param dt_drift The drift time-step
 * @param dt_kick_grav The kick time-step for gravity accelerations.
 * @param dt_kick_hydro The kick time-step for hydro accelerations.
69
 * @param dt_therm The drift time-step for thermodynamic quantities.
70
71
 * @param ti_old Integer start of time-step (for debugging checks).
 * @param ti_current Integer end of time-step (for debugging checks).
72
 */
Matthieu Schaller's avatar
Matthieu Schaller committed
73
__attribute__((always_inline)) INLINE static void drift_part(
74
    struct part *restrict p, struct xpart *restrict xp, double dt_drift,
75
76
    double dt_kick_hydro, double dt_kick_grav, double dt_therm,
    integertime_t ti_old, integertime_t ti_current) {
77

78
79
80
#ifdef SWIFT_DEBUG_CHECKS
  if (p->ti_drift != ti_old)
    error(
81
        "particle has not been drifted to the current time p->ti_drift=%lld, "
82
83
84
85
86
87
        "c->ti_old=%lld, ti_current=%lld",
        p->ti_drift, ti_old, ti_current);

  p->ti_drift = ti_current;
#endif

88
  /* Drift... */
89
90
91
  p->x[0] += xp->v_full[0] * dt_drift;
  p->x[1] += xp->v_full[1] * dt_drift;
  p->x[2] += xp->v_full[2] * dt_drift;
92
93

  /* Predict velocities (for hydro terms) */
94
95
96
97
98
99
100
  p->v[0] += p->a_hydro[0] * dt_kick_hydro;
  p->v[1] += p->a_hydro[1] * dt_kick_hydro;
  p->v[2] += p->a_hydro[2] * dt_kick_hydro;

  p->v[0] += xp->a_grav[0] * dt_kick_grav;
  p->v[1] += xp->a_grav[1] * dt_kick_grav;
  p->v[2] += xp->a_grav[2] * dt_kick_grav;
101
102

  /* Predict the values of the extra fields */
103
  hydro_predict_extra(p, xp, dt_drift, dt_therm);
104

105
  /* Compute offsets since last cell construction */
106
  for (int k = 0; k < 3; k++) {
107
    const float dx = xp->v_full[k] * dt_drift;
108
109
110
    xp->x_diff[k] -= dx;
    xp->x_diff_sort[k] -= dx;
  }
111
112
}

113
114
115
116
/**
 * @brief Perform the 'drift' operation on a #spart
 *
 * @param sp The #spart to drift.
117
118
119
 * @param dt_drift The drift time-step.
 * @param ti_old Integer start of time-step (for debugging checks).
 * @param ti_current Integer end of time-step (for debugging checks).
120
121
 */
__attribute__((always_inline)) INLINE static void drift_spart(
122
    struct spart *restrict sp, double dt_drift, integertime_t ti_old,
123
124
    integertime_t ti_current) {

125
126
127
128
129
130
131
132
133
134
135
#ifdef SWIFT_DEBUG_CHECKS
  if (sp->ti_drift != ti_old)
    error(
        "s-particle has not been drifted to the current time "
        "sp->ti_drift=%lld, "
        "c->ti_old=%lld, ti_current=%lld",
        sp->ti_drift, ti_old, ti_current);

  sp->ti_drift = ti_current;
#endif

136
  /* Drift... */
137
138
139
  sp->x[0] += sp->v[0] * dt_drift;
  sp->x[1] += sp->v[1] * dt_drift;
  sp->x[2] += sp->v[2] * dt_drift;
Loic Hausammann's avatar
Loic Hausammann committed
140
141
142
143
144

  /* Compute offsets since last cell construction */
  for (int k = 0; k < 3; k++) {
    const float dx = sp->v[k] * dt_drift;
    sp->x_diff[k] -= dx;
Loic Hausammann's avatar
Loic Hausammann committed
145
    sp->x_diff_sort[k] -= dx;
Loic Hausammann's avatar
Loic Hausammann committed
146
  }
147
148
}

149
#endif /* SWIFT_DRIFT_H */