hydro_iact.h 34.2 KB
Newer Older
1
2
/*******************************************************************************
 * This file is part of SWIFT.
3
 * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
4
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
5
 *
6
7
8
9
 * 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.
10
 *
11
12
13
14
 * 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.
15
 *
16
17
 * 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/>.
18
 *
19
 ******************************************************************************/
20
21
#ifndef SWIFT_GADGET2_HYDRO_IACT_H
#define SWIFT_GADGET2_HYDRO_IACT_H
22
23

/**
24
 * @file Gadget2/hydro_iact.h
25
26
 * @brief SPH interaction functions following the Gadget-2 version of SPH.
 *
27
 * The interactions computed here are the ones presented in the Gadget-2 paper
28
29
 * Springel, V., MNRAS, Volume 364, Issue 4, pp. 1105-1134.
 * We use the same numerical coefficients as the Gadget-2 code. When used with
30
31
32
 * 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.
33
34
 */

35
#include "cache.h"
James Willis's avatar
James Willis committed
36
#include "minmax.h"
37

38
39
40
/**
 * @brief Density loop
 */
41
42
43
__attribute__((always_inline)) INLINE static void runner_iact_density(
    float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {

44
45
  float wi, wi_dx;
  float wj, wj_dx;
46
  float dv[3], curlvr[3];
47

48
  /* Get the masses. */
49
  const float mi = pi->mass;
50
51
52
53
54
55
56
57
58
59
60
61
62
  const float mj = pj->mass;

  /* Get r and r inverse. */
  const float r = sqrtf(r2);
  const float r_inv = 1.0f / r;

  /* 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 density */
  pi->rho += mj * wi;
63
  pi->density.rho_dh -= mj * (hydro_dimension * wi + ui * wi_dx);
64

65
66
  /* Compute contribution to the number of neighbours */
  pi->density.wcount += wi;
67
  pi->density.wcount_dh -= (hydro_dimension * wi + ui * wi_dx);
68
69
70
71
72
73
74
75

  /* 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 density */
  pj->rho += mi * wj;
76
  pj->density.rho_dh -= mi * (hydro_dimension * wj + uj * wj_dx);
77

78
79
  /* Compute contribution to the number of neighbours */
  pj->density.wcount += wj;
80
  pj->density.wcount_dh -= (hydro_dimension * wj + uj * wj_dx);
81

82
83
  const float faci = mj * wi_dx * r_inv;
  const float facj = mi * wj_dx * r_inv;
84

85
86
87
88
  /* Compute dv dot r */
  dv[0] = pi->v[0] - pj->v[0];
  dv[1] = pi->v[1] - pj->v[1];
  dv[2] = pi->v[2] - pj->v[2];
89
90
  const float dvdr = dv[0] * dx[0] + dv[1] * dx[1] + dv[2] * dx[2];

91
92
  pi->density.div_v -= faci * dvdr;
  pj->density.div_v -= facj * dvdr;
93
94
95
96
97
98

  /* Compute dv cross r */
  curlvr[0] = dv[1] * dx[2] - dv[2] * dx[1];
  curlvr[1] = dv[2] * dx[0] - dv[0] * dx[2];
  curlvr[2] = dv[0] * dx[1] - dv[1] * dx[0];

99
100
101
  pi->density.rot_v[0] += faci * curlvr[0];
  pi->density.rot_v[1] += faci * curlvr[1];
  pi->density.rot_v[2] += faci * curlvr[2];
102

103
104
105
  pj->density.rot_v[0] += facj * curlvr[0];
  pj->density.rot_v[1] += facj * curlvr[1];
  pj->density.rot_v[2] += facj * curlvr[2];
106
  
107
#ifdef DEBUG_INTERACTIONS_SPH
108
  /* Update ngb counters */
109
  if(pi->num_ngb_density < MAX_NUM_OF_NEIGHBOURS) {
110
111
112
    pi->ids_ngbs_density[pi->num_ngb_density] = pj->id;
    ++pi->num_ngb_density;
  }
113
114
  else ++pi->num_ngb_density;

115
  if(pj->num_ngb_density < MAX_NUM_OF_NEIGHBOURS) {
116
117
118
    pj->ids_ngbs_density[pj->num_ngb_density] = pi->id;
    ++pj->num_ngb_density;
  }
119
  else ++pj->num_ngb_density;
120
121
#endif

122
123
}

124
125
126
/**
 * @brief Density loop (non-symmetric version)
 */
127
128
129
130
131
132
133
__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;
  float dv[3], curlvr[3];

  /* Get the masses. */
134
  const float mj = pj->mass;
135
136

  /* Get r and r inverse. */
137
  const float r = sqrtf(r2);
138
  const float r_inv = 1.0f / r;
139

140
  /* Compute the kernel function */
141
142
143
  const float hi_inv = 1.0f / hi;
  const float ui = r * hi_inv;
  kernel_deval(ui, &wi, &wi_dx);
144
145
146

  /* Compute contribution to the density */
  pi->rho += mj * wi;
147
  pi->density.rho_dh -= mj * (hydro_dimension * wi + ui * wi_dx);
148
149
150

  /* Compute contribution to the number of neighbours */
  pi->density.wcount += wi;
151
  pi->density.wcount_dh -= (hydro_dimension * wi + ui * wi_dx);
152

153
  const float fac = mj * wi_dx * r_inv;
154

155
156
157
158
159
  /* Compute dv dot r */
  dv[0] = pi->v[0] - pj->v[0];
  dv[1] = pi->v[1] - pj->v[1];
  dv[2] = pi->v[2] - pj->v[2];
  const float dvdr = dv[0] * dx[0] + dv[1] * dx[1] + dv[2] * dx[2];
160
  pi->density.div_v -= fac * dvdr;
161

162
163
164
165
166
  /* Compute dv cross r */
  curlvr[0] = dv[1] * dx[2] - dv[2] * dx[1];
  curlvr[1] = dv[2] * dx[0] - dv[0] * dx[2];
  curlvr[2] = dv[0] * dx[1] - dv[1] * dx[0];

167
168
169
  pi->density.rot_v[0] += fac * curlvr[0];
  pi->density.rot_v[1] += fac * curlvr[1];
  pi->density.rot_v[2] += fac * curlvr[2];
170
  
171
#ifdef DEBUG_INTERACTIONS_SPH
172
  /* Update ngb counters */
173
  if(pi->num_ngb_density < MAX_NUM_OF_NEIGHBOURS) {
174
175
176
    pi->ids_ngbs_density[pi->num_ngb_density] = pj->id;
    ++pi->num_ngb_density;
  }
177
  else ++pi->num_ngb_density;
178
179
#endif

180
181
}

182
#ifdef WITH_VECTORIZATION
183
184
185
186
187

/**
 * @brief Density interaction computed using 1 vector
 * (non-symmetric vectorized version).
 */
188
__attribute__((always_inline)) INLINE static void
Matthieu Schaller's avatar
Matthieu Schaller committed
189
190
191
192
193
194
195
runner_iact_nonsym_1_vec_density(vector *r2, vector *dx, vector *dy, vector *dz,
                                 vector hi_inv, vector vix, vector viy,
                                 vector viz, float *Vjx, float *Vjy, float *Vjz,
                                 float *Mj, vector *rhoSum, vector *rho_dhSum,
                                 vector *wcountSum, vector *wcount_dhSum,
                                 vector *div_vSum, vector *curlvxSum,
                                 vector *curlvySum, vector *curlvzSum,
196
                                 mask_t mask) {
197

198
  vector r, ri, ui, wi, wi_dx;
199
200
201
  vector dvx, dvy, dvz;
  vector dvdr;
  vector curlvrx, curlvry, curlvrz;
James Willis's avatar
James Willis committed
202

203
  /* Fill the vectors. */
204
205
206
207
  const vector mj = vector_load(Mj);
  const vector vjx = vector_load(Vjx);
  const vector vjy = vector_load(Vjy);
  const vector vjz = vector_load(Vjz);
208
209
210
211
212

  /* Get the radius and inverse radius. */
  ri = vec_reciprocal_sqrt(*r2);
  r.v = vec_mul(r2->v, ri.v);

213
  ui.v = vec_mul(r.v, hi_inv.v);
214
215

  /* Calculate the kernel for two particles. */
216
  kernel_deval_1_vec(&ui, &wi, &wi_dx);
217
218
219
220
221
222
223
224
225
226

  /* Compute dv. */
  dvx.v = vec_sub(vix.v, vjx.v);
  dvy.v = vec_sub(viy.v, vjy.v);
  dvz.v = vec_sub(viz.v, vjz.v);

  /* Compute dv dot r */
  dvdr.v = vec_fma(dvx.v, dx->v, vec_fma(dvy.v, dy->v, vec_mul(dvz.v, dz->v)));
  dvdr.v = vec_mul(dvdr.v, ri.v);

227
228
229
230
231
232
233
234
235
236
237
  /* Compute dv cross r */
  curlvrx.v =
      vec_fma(dvy.v, dz->v, vec_mul(vec_set1(-1.0f), vec_mul(dvz.v, dy->v)));
  curlvry.v =
      vec_fma(dvz.v, dx->v, vec_mul(vec_set1(-1.0f), vec_mul(dvx.v, dz->v)));
  curlvrz.v =
      vec_fma(dvx.v, dy->v, vec_mul(vec_set1(-1.0f), vec_mul(dvy.v, dx->v)));
  curlvrx.v = vec_mul(curlvrx.v, ri.v);
  curlvry.v = vec_mul(curlvry.v, ri.v);
  curlvrz.v = vec_mul(curlvrz.v, ri.v);

238
239
  vector wcount_dh_update;
  wcount_dh_update.v =
James Willis's avatar
James Willis committed
240
      vec_fma(vec_set1(hydro_dimension), wi.v, vec_mul(ui.v, wi_dx.v));
241

242
  /* Mask updates to intermediate vector sums for particle pi. */
243
  rhoSum->v = vec_mask_add(rhoSum->v, vec_mul(mj.v, wi.v), mask);
244
245
  rho_dhSum->v =
      vec_mask_sub(rho_dhSum->v, vec_mul(mj.v, wcount_dh_update.v), mask);
246
  wcountSum->v = vec_mask_add(wcountSum->v, wi.v, mask);
247
  wcount_dhSum->v = vec_mask_sub(wcount_dhSum->v, wcount_dh_update.v, mask);
James Willis's avatar
James Willis committed
248
249
250
251
252
253
254
255
  div_vSum->v =
      vec_mask_sub(div_vSum->v, vec_mul(mj.v, vec_mul(dvdr.v, wi_dx.v)), mask);
  curlvxSum->v = vec_mask_add(curlvxSum->v,
                              vec_mul(mj.v, vec_mul(curlvrx.v, wi_dx.v)), mask);
  curlvySum->v = vec_mask_add(curlvySum->v,
                              vec_mul(mj.v, vec_mul(curlvry.v, wi_dx.v)), mask);
  curlvzSum->v = vec_mask_add(curlvzSum->v,
                              vec_mul(mj.v, vec_mul(curlvrz.v, wi_dx.v)), mask);
256
257
}

258
/**
James Willis's avatar
James Willis committed
259
260
 * @brief Density interaction computed using 2 interleaved vectors
 * (non-symmetric vectorized version).
261
262
 */
__attribute__((always_inline)) INLINE static void
James Willis's avatar
James Willis committed
263
264
265
266
267
268
269
270
runner_iact_nonsym_2_vec_density(float *R2, float *Dx, float *Dy, float *Dz,
                                 vector hi_inv, vector vix, vector viy,
                                 vector viz, float *Vjx, float *Vjy, float *Vjz,
                                 float *Mj, vector *rhoSum, vector *rho_dhSum,
                                 vector *wcountSum, vector *wcount_dhSum,
                                 vector *div_vSum, vector *curlvxSum,
                                 vector *curlvySum, vector *curlvzSum,
                                 mask_t mask, mask_t mask2, short mask_cond) {
271

272
273
  vector r, ri, ui, wi, wi_dx;
  vector dvx, dvy, dvz;
274
275
  vector dvdr;
  vector curlvrx, curlvry, curlvrz;
276
277
  vector r_2, ri2, ui2, wi2, wi_dx2;
  vector dvx2, dvy2, dvz2;
278
279
280
  vector dvdr2;
  vector curlvrx2, curlvry2, curlvrz2;

James Willis's avatar
James Willis committed
281
  /* Fill the vectors. */
282
283
284
285
286
287
288
289
290
291
292
293
294
295
  const vector mj = vector_load(Mj);
  const vector mj2 = vector_load(&Mj[VEC_SIZE]);
  const vector vjx = vector_load(Vjx);
  const vector vjx2 = vector_load(&Vjx[VEC_SIZE]);
  const vector vjy = vector_load(Vjy);
  const vector vjy2 = vector_load(&Vjy[VEC_SIZE]);
  const vector vjz = vector_load(Vjz);
  const vector vjz2 = vector_load(&Vjz[VEC_SIZE]);
  const vector dx = vector_load(Dx);
  const vector dx2 = vector_load(&Dx[VEC_SIZE]);
  const vector dy = vector_load(Dy);
  const vector dy2 = vector_load(&Dy[VEC_SIZE]);
  const vector dz = vector_load(Dz);
  const vector dz2 = vector_load(&Dz[VEC_SIZE]);
296
297

  /* Get the radius and inverse radius. */
298
299
  const vector r2 = vector_load(R2);
  const vector r2_2 = vector_load(&R2[VEC_SIZE]);
300
301
  ri = vec_reciprocal_sqrt(r2);
  ri2 = vec_reciprocal_sqrt(r2_2);
302
303
304
  r.v = vec_mul(r2.v, ri.v);
  r_2.v = vec_mul(r2_2.v, ri2.v);

305
306
  ui.v = vec_mul(r.v, hi_inv.v);
  ui2.v = vec_mul(r_2.v, hi_inv.v);
307

James Willis's avatar
James Willis committed
308
  /* Calculate the kernel for two particles. */
309
  kernel_deval_2_vec(&ui, &wi, &wi_dx, &ui2, &wi2, &wi_dx2);
310
311
312
313
314
315
316
317
318
319
320

  /* Compute dv. */
  dvx.v = vec_sub(vix.v, vjx.v);
  dvx2.v = vec_sub(vix.v, vjx2.v);
  dvy.v = vec_sub(viy.v, vjy.v);
  dvy2.v = vec_sub(viy.v, vjy2.v);
  dvz.v = vec_sub(viz.v, vjz.v);
  dvz2.v = vec_sub(viz.v, vjz2.v);

  /* Compute dv dot r */
  dvdr.v = vec_fma(dvx.v, dx.v, vec_fma(dvy.v, dy.v, vec_mul(dvz.v, dz.v)));
James Willis's avatar
James Willis committed
321
322
  dvdr2.v =
      vec_fma(dvx2.v, dx2.v, vec_fma(dvy2.v, dy2.v, vec_mul(dvz2.v, dz2.v)));
323
324
325
326
  dvdr.v = vec_mul(dvdr.v, ri.v);
  dvdr2.v = vec_mul(dvdr2.v, ri2.v);

  /* Compute dv cross r */
James Willis's avatar
James Willis committed
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
  curlvrx.v =
      vec_fma(dvy.v, dz.v, vec_mul(vec_set1(-1.0f), vec_mul(dvz.v, dy.v)));
  curlvrx2.v =
      vec_fma(dvy2.v, dz2.v, vec_mul(vec_set1(-1.0f), vec_mul(dvz2.v, dy2.v)));
  curlvry.v =
      vec_fma(dvz.v, dx.v, vec_mul(vec_set1(-1.0f), vec_mul(dvx.v, dz.v)));
  curlvry2.v =
      vec_fma(dvz2.v, dx2.v, vec_mul(vec_set1(-1.0f), vec_mul(dvx2.v, dz2.v)));
  curlvrz.v =
      vec_fma(dvx.v, dy.v, vec_mul(vec_set1(-1.0f), vec_mul(dvy.v, dx.v)));
  curlvrz2.v =
      vec_fma(dvx2.v, dy2.v, vec_mul(vec_set1(-1.0f), vec_mul(dvy2.v, dx2.v)));
  curlvrx.v = vec_mul(curlvrx.v, ri.v);
  curlvrx2.v = vec_mul(curlvrx2.v, ri2.v);
  curlvry.v = vec_mul(curlvry.v, ri.v);
  curlvry2.v = vec_mul(curlvry2.v, ri2.v);
  curlvrz.v = vec_mul(curlvrz.v, ri.v);
  curlvrz2.v = vec_mul(curlvrz2.v, ri2.v);

346
347
  vector wcount_dh_update, wcount_dh_update2;
  wcount_dh_update.v =
James Willis's avatar
James Willis committed
348
      vec_fma(vec_set1(hydro_dimension), wi.v, vec_mul(ui.v, wi_dx.v));
349
  wcount_dh_update2.v =
James Willis's avatar
James Willis committed
350
      vec_fma(vec_set1(hydro_dimension), wi2.v, vec_mul(ui2.v, wi_dx2.v));
351

James Willis's avatar
James Willis committed
352
  /* Mask updates to intermediate vector sums for particle pi. */
353
  /* Mask only when needed. */
James Willis's avatar
James Willis committed
354
  if (mask_cond) {
355
356
    rhoSum->v = vec_mask_add(rhoSum->v, vec_mul(mj.v, wi.v), mask);
    rhoSum->v = vec_mask_add(rhoSum->v, vec_mul(mj2.v, wi2.v), mask2);
James Willis's avatar
James Willis committed
357
    rho_dhSum->v =
358
        vec_mask_sub(rho_dhSum->v, vec_mul(mj.v, wcount_dh_update.v), mask);
James Willis's avatar
James Willis committed
359
    rho_dhSum->v =
360
        vec_mask_sub(rho_dhSum->v, vec_mul(mj2.v, wcount_dh_update2.v), mask2);
361
362
    wcountSum->v = vec_mask_add(wcountSum->v, wi.v, mask);
    wcountSum->v = vec_mask_add(wcountSum->v, wi2.v, mask2);
363
364
    wcount_dhSum->v = vec_mask_sub(wcount_dhSum->v, wcount_dh_update.v, mask);
    wcount_dhSum->v = vec_mask_sub(wcount_dhSum->v, wcount_dh_update2.v, mask2);
James Willis's avatar
James Willis committed
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
    div_vSum->v = vec_mask_sub(div_vSum->v,
                               vec_mul(mj.v, vec_mul(dvdr.v, wi_dx.v)), mask);
    div_vSum->v = vec_mask_sub(
        div_vSum->v, vec_mul(mj2.v, vec_mul(dvdr2.v, wi_dx2.v)), mask2);
    curlvxSum->v = vec_mask_add(
        curlvxSum->v, vec_mul(mj.v, vec_mul(curlvrx.v, wi_dx.v)), mask);
    curlvxSum->v = vec_mask_add(
        curlvxSum->v, vec_mul(mj2.v, vec_mul(curlvrx2.v, wi_dx2.v)), mask2);
    curlvySum->v = vec_mask_add(
        curlvySum->v, vec_mul(mj.v, vec_mul(curlvry.v, wi_dx.v)), mask);
    curlvySum->v = vec_mask_add(
        curlvySum->v, vec_mul(mj2.v, vec_mul(curlvry2.v, wi_dx2.v)), mask2);
    curlvzSum->v = vec_mask_add(
        curlvzSum->v, vec_mul(mj.v, vec_mul(curlvrz.v, wi_dx.v)), mask);
    curlvzSum->v = vec_mask_add(
        curlvzSum->v, vec_mul(mj2.v, vec_mul(curlvrz2.v, wi_dx2.v)), mask2);
  } else {
382
383
    rhoSum->v = vec_add(rhoSum->v, vec_mul(mj.v, wi.v));
    rhoSum->v = vec_add(rhoSum->v, vec_mul(mj2.v, wi2.v));
384
385
    rho_dhSum->v = vec_sub(rho_dhSum->v, vec_mul(mj.v, wcount_dh_update.v));
    rho_dhSum->v = vec_sub(rho_dhSum->v, vec_mul(mj2.v, wcount_dh_update2.v));
386
387
    wcountSum->v = vec_add(wcountSum->v, wi.v);
    wcountSum->v = vec_add(wcountSum->v, wi2.v);
388
389
    wcount_dhSum->v = vec_sub(wcount_dhSum->v, wcount_dh_update.v);
    wcount_dhSum->v = vec_sub(wcount_dhSum->v, wcount_dh_update2.v);
390
    div_vSum->v = vec_sub(div_vSum->v, vec_mul(mj.v, vec_mul(dvdr.v, wi_dx.v)));
James Willis's avatar
James Willis committed
391
392
393
394
395
396
397
398
399
400
401
402
403
404
    div_vSum->v =
        vec_sub(div_vSum->v, vec_mul(mj2.v, vec_mul(dvdr2.v, wi_dx2.v)));
    curlvxSum->v =
        vec_add(curlvxSum->v, vec_mul(mj.v, vec_mul(curlvrx.v, wi_dx.v)));
    curlvxSum->v =
        vec_add(curlvxSum->v, vec_mul(mj2.v, vec_mul(curlvrx2.v, wi_dx2.v)));
    curlvySum->v =
        vec_add(curlvySum->v, vec_mul(mj.v, vec_mul(curlvry.v, wi_dx.v)));
    curlvySum->v =
        vec_add(curlvySum->v, vec_mul(mj2.v, vec_mul(curlvry2.v, wi_dx2.v)));
    curlvzSum->v =
        vec_add(curlvzSum->v, vec_mul(mj.v, vec_mul(curlvrz.v, wi_dx.v)));
    curlvzSum->v =
        vec_add(curlvzSum->v, vec_mul(mj2.v, vec_mul(curlvrz2.v, wi_dx2.v)));
405
  }
406
}
James Willis's avatar
James Willis committed
407
#endif
408

409
410
411
/**
 * @brief Force loop
 */
412
413
414
__attribute__((always_inline)) INLINE static void runner_iact_force(
    float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {

415
416
417
  float wi, wj, wi_dx, wj_dx;

  const float fac_mu = 1.f; /* Will change with cosmological integration */
418

419
420
421
422
  const float r = sqrtf(r2);
  const float r_inv = 1.0f / r;

  /* Get some values in local variables. */
423
  const float mi = pi->mass;
424
425
426
427
428
429
  const float mj = pj->mass;
  const float rhoi = pi->rho;
  const float rhoj = pj->rho;

  /* Get the kernel for hi. */
  const float hi_inv = 1.0f / hi;
430
  const float hid_inv = pow_dimension_plus_one(hi_inv); /* 1/h^(d+1) */
431
432
  const float ui = r * hi_inv;
  kernel_deval(ui, &wi, &wi_dx);
433
  const float wi_dr = hid_inv * wi_dx;
434
435
436

  /* Get the kernel for hj. */
  const float hj_inv = 1.0f / hj;
437
  const float hjd_inv = pow_dimension_plus_one(hj_inv); /* 1/h^(d+1) */
438
439
  const float xj = r * hj_inv;
  kernel_deval(xj, &wj, &wj_dx);
440
  const float wj_dr = hjd_inv * wj_dx;
441

442
443
444
445
446
  /* Compute h-gradient terms */
  const float f_i = pi->force.f;
  const float f_j = pj->force.f;

  /* Compute pressure terms */
447
448
  const float P_over_rho2_i = pi->force.P_over_rho2;
  const float P_over_rho2_j = pj->force.P_over_rho2;
449
450

  /* Compute sound speeds */
451
452
  const float ci = pi->force.soundspeed;
  const float cj = pj->force.soundspeed;
453

454
  /* Compute dv dot r. */
455
456
457
  const float dvdr = (pi->v[0] - pj->v[0]) * dx[0] +
                     (pi->v[1] - pj->v[1]) * dx[1] +
                     (pi->v[2] - pj->v[2]) * dx[2];
458

459
  /* Balsara term */
460
461
  const float balsara_i = pi->force.balsara;
  const float balsara_j = pj->force.balsara;
Matthieu Schaller's avatar
Matthieu Schaller committed
462

463
  /* Are the particles moving towards each others ? */
464
  const float omega_ij = (dvdr < 0.f) ? dvdr : 0.f;
465
466
467
468
469
470
471
472
473
  const float mu_ij = fac_mu * r_inv * omega_ij; /* This is 0 or negative */

  /* Signal velocity */
  const float v_sig = ci + cj - 3.f * mu_ij;

  /* Now construct the full viscosity term */
  const float rho_ij = 0.5f * (rhoi + rhoj);
  const float visc = -0.25f * const_viscosity_alpha * v_sig * mu_ij *
                     (balsara_i + balsara_j) / rho_ij;
474
475

  /* Now, convolve with the kernel */
476
  const float visc_term = 0.5f * visc * (wi_dr + wj_dr) * r_inv;
477
  const float sph_term =
478
      (f_i * P_over_rho2_i * wi_dr + f_j * P_over_rho2_j * wj_dr) * r_inv;
479
480
481
482
483

  /* Eventually got the acceleration */
  const float acc = visc_term + sph_term;

  /* Use the force Luke ! */
484
485
486
  pi->a_hydro[0] -= mj * acc * dx[0];
  pi->a_hydro[1] -= mj * acc * dx[1];
  pi->a_hydro[2] -= mj * acc * dx[2];
487

488
489
490
  pj->a_hydro[0] += mi * acc * dx[0];
  pj->a_hydro[1] += mi * acc * dx[1];
  pj->a_hydro[2] += mi * acc * dx[2];
491

492
  /* Get the time derivative for h. */
493
494
  pi->force.h_dt -= mj * dvdr * r_inv / rhoj * wi_dr;
  pj->force.h_dt -= mi * dvdr * r_inv / rhoi * wj_dr;
495

496
  /* Update the signal velocity. */
497
498
  pi->force.v_sig = (pi->force.v_sig > v_sig) ? pi->force.v_sig : v_sig;
  pj->force.v_sig = (pj->force.v_sig > v_sig) ? pj->force.v_sig : v_sig;
499

500
  /* Change in entropy */
501
502
  pi->entropy_dt += mj * visc_term * dvdr;
  pj->entropy_dt += mi * visc_term * dvdr;
503
  
504
#ifdef DEBUG_INTERACTIONS_SPH
505
  /* Update ngb counters */
506
  if(pi->num_ngb_force < MAX_NUM_OF_NEIGHBOURS) {
507
508
509
    pi->ids_ngbs_force[pi->num_ngb_force] = pj->id;
    ++pi->num_ngb_force;
  }
510
511
  else ++pi->num_ngb_force;

512
  if(pj->num_ngb_force < MAX_NUM_OF_NEIGHBOURS) {
513
514
515
    pj->ids_ngbs_force[pj->num_ngb_force] = pi->id;
    ++pj->num_ngb_force;
  }
516
  else ++pj->num_ngb_force;
517
518
#endif

519
}
520
521
522
523

/**
 * @brief Force loop (non-symmetric version)
 */
524
525
526
__attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
    float r2, float *dx, float hi, float hj, struct part *pi, struct part *pj) {

527
528
529
  float wi, wj, wi_dx, wj_dx;

  const float fac_mu = 1.f; /* Will change with cosmological integration */
530

531
532
533
534
  const float r = sqrtf(r2);
  const float r_inv = 1.0f / r;

  /* Get some values in local variables. */
535
  // const float mi = pi->mass;
536
537
538
539
540
541
  const float mj = pj->mass;
  const float rhoi = pi->rho;
  const float rhoj = pj->rho;

  /* Get the kernel for hi. */
  const float hi_inv = 1.0f / hi;
542
  const float hid_inv = pow_dimension_plus_one(hi_inv); /* 1/h^(d+1) */
543
544
  const float ui = r * hi_inv;
  kernel_deval(ui, &wi, &wi_dx);
545
  const float wi_dr = hid_inv * wi_dx;
546
547
548

  /* Get the kernel for hj. */
  const float hj_inv = 1.0f / hj;
549
  const float hjd_inv = pow_dimension_plus_one(hj_inv); /* 1/h^(d+1) */
550
551
  const float xj = r * hj_inv;
  kernel_deval(xj, &wj, &wj_dx);
552
  const float wj_dr = hjd_inv * wj_dx;
553

554
555
556
557
558
  /* Compute h-gradient terms */
  const float f_i = pi->force.f;
  const float f_j = pj->force.f;

  /* Compute pressure terms */
559
560
  const float P_over_rho2_i = pi->force.P_over_rho2;
  const float P_over_rho2_j = pj->force.P_over_rho2;
561
562

  /* Compute sound speeds */
563
564
  const float ci = pi->force.soundspeed;
  const float cj = pj->force.soundspeed;
565

566
  /* Compute dv dot r. */
567
568
569
  const float dvdr = (pi->v[0] - pj->v[0]) * dx[0] +
                     (pi->v[1] - pj->v[1]) * dx[1] +
                     (pi->v[2] - pj->v[2]) * dx[2];
570

571
  /* Balsara term */
572
573
  const float balsara_i = pi->force.balsara;
  const float balsara_j = pj->force.balsara;
574
575

  /* Are the particles moving towards each others ? */
576
  const float omega_ij = (dvdr < 0.f) ? dvdr : 0.f;
577
578
579
580
581
582
583
584
585
  const float mu_ij = fac_mu * r_inv * omega_ij; /* This is 0 or negative */

  /* Signal velocity */
  const float v_sig = ci + cj - 3.f * mu_ij;

  /* Now construct the full viscosity term */
  const float rho_ij = 0.5f * (rhoi + rhoj);
  const float visc = -0.25f * const_viscosity_alpha * v_sig * mu_ij *
                     (balsara_i + balsara_j) / rho_ij;
586
587

  /* Now, convolve with the kernel */
588
  const float visc_term = 0.5f * visc * (wi_dr + wj_dr) * r_inv;
589
  const float sph_term =
590
      (f_i * P_over_rho2_i * wi_dr + f_j * P_over_rho2_j * wj_dr) * r_inv;
591
592
593

  /* Eventually got the acceleration */
  const float acc = visc_term + sph_term;
594

595
  /* Use the force Luke ! */
596
597
598
  pi->a_hydro[0] -= mj * acc * dx[0];
  pi->a_hydro[1] -= mj * acc * dx[1];
  pi->a_hydro[2] -= mj * acc * dx[2];
599

600
  /* Get the time derivative for h. */
601
  pi->force.h_dt -= mj * dvdr * r_inv / rhoj * wi_dr;
602

603
  /* Update the signal velocity. */
604
  pi->force.v_sig = (pi->force.v_sig > v_sig) ? pi->force.v_sig : v_sig;
605

606
  /* Change in entropy */
607
  pi->entropy_dt += mj * visc_term * dvdr;
608
  
609
#ifdef DEBUG_INTERACTIONS_SPH
610
  /* Update ngb counters */
611
  if(pi->num_ngb_force < MAX_NUM_OF_NEIGHBOURS) {
612
613
614
    pi->ids_ngbs_force[pi->num_ngb_force] = pj->id;
    ++pi->num_ngb_force;
  }
615
  else ++pi->num_ngb_force;
616
617
#endif

618
}
619

620
#ifdef WITH_VECTORIZATION
James Willis's avatar
James Willis committed
621
622
static const vector const_viscosity_alpha_fac =
    FILL_VEC(-0.25f * const_viscosity_alpha);
623

James Willis's avatar
James Willis committed
624
625
626
627
/**
 * @brief Force interaction computed using 1 vector
 * (non-symmetric vectorized version).
 */
James Willis's avatar
James Willis committed
628
629
__attribute__((always_inline)) INLINE static void
runner_iact_nonsym_1_vec_force(
630
    vector *r2, vector *dx, vector *dy, vector *dz, vector vix, vector viy,
James Willis's avatar
James Willis committed
631
632
633
    vector viz, vector pirho, vector grad_hi, vector piPOrho2, vector balsara_i,
    vector ci, float *Vjx, float *Vjy, float *Vjz, float *Pjrho, float *Grad_hj,
    float *PjPOrho2, float *Balsara_j, float *Cj, float *Mj, vector hi_inv,
634
    vector hj_inv, vector *a_hydro_xSum, vector *a_hydro_ySum,
James Willis's avatar
James Willis committed
635
636
    vector *a_hydro_zSum, vector *h_dtSum, vector *v_sigSum,
    vector *entropy_dtSum, mask_t mask) {
637
638
639

#ifdef WITH_VECTORIZATION

640
  vector r, ri;
641
  vector dvx, dvy, dvz;
642
643
  vector xi, xj;
  vector hid_inv, hjd_inv;
644
  vector wi_dx, wj_dx, wi_dr, wj_dr, dvdr;
645
646
647
  vector piax, piay, piaz;
  vector pih_dt;
  vector v_sig;
648
  vector omega_ij, mu_ij, balsara;
649
650
651
  vector rho_ij, visc, visc_term, sph_term, acc, entropy_dt;

  /* Fill vectors. */
652
653
654
655
656
657
658
659
660
  const vector vjx = vector_load(Vjx);
  const vector vjy = vector_load(Vjy);
  const vector vjz = vector_load(Vjz);
  const vector mj = vector_load(Mj);
  const vector pjrho = vector_load(Pjrho);
  const vector grad_hj = vector_load(Grad_hj);
  const vector pjPOrho2 = vector_load(PjPOrho2);
  const vector balsara_j = vector_load(Balsara_j);
  const vector cj = vector_load(Cj);
661

662
663
  const vector fac_mu =
      vector_set1(1.f); /* Will change with cosmological integration */
664

James Willis's avatar
James Willis committed
665
  /* Load stuff. */
666
  balsara.v = vec_add(balsara_i.v, balsara_j.v);
667
668

  /* Get the radius and inverse radius. */
669
  ri = vec_reciprocal_sqrt(*r2);
670
  r.v = vec_mul(r2->v, ri.v);
671
672

  /* Get the kernel for hi. */
673
  hid_inv = pow_dimension_plus_one_vec(hi_inv);
674
  xi.v = vec_mul(r.v, hi_inv.v);
675
  kernel_eval_dWdx_force_vec(&xi, &wi_dx);
676
  wi_dr.v = vec_mul(hid_inv.v, wi_dx.v);
677
678
679

  /* Get the kernel for hj. */
  hjd_inv = pow_dimension_plus_one_vec(hj_inv);
680
  xj.v = vec_mul(r.v, hj_inv.v);
James Willis's avatar
James Willis committed
681

682
  /* Calculate the kernel. */
James Willis's avatar
James Willis committed
683
  kernel_eval_dWdx_force_vec(&xj, &wj_dx);
James Willis's avatar
James Willis committed
684

685
686
687
688
689
690
  wj_dr.v = vec_mul(hjd_inv.v, wj_dx.v);

  /* Compute dv. */
  dvx.v = vec_sub(vix.v, vjx.v);
  dvy.v = vec_sub(viy.v, vjy.v);
  dvz.v = vec_sub(viz.v, vjz.v);
691
692

  /* Compute dv dot r. */
693
  dvdr.v = vec_fma(dvx.v, dx->v, vec_fma(dvy.v, dy->v, vec_mul(dvz.v, dz->v)));
694
695
696

  /* Compute the relative velocity. (This is 0 if the particles move away from
   * each other and negative otherwise) */
697
  omega_ij.v = vec_fmin(dvdr.v, vec_setzero());
James Willis's avatar
James Willis committed
698
699
  mu_ij.v =
      vec_mul(fac_mu.v, vec_mul(ri.v, omega_ij.v)); /* This is 0 or negative */
700
701

  /* Compute signal velocity */
702
  v_sig.v = vec_fnma(vec_set1(3.f), mu_ij.v, vec_add(ci.v, cj.v));
703
704

  /* Now construct the full viscosity term */
705
  rho_ij.v = vec_mul(vec_set1(0.5f), vec_add(pirho.v, pjrho.v));
James Willis's avatar
James Willis committed
706
707
708
  visc.v = vec_div(vec_mul(const_viscosity_alpha_fac.v,
                           vec_mul(v_sig.v, vec_mul(mu_ij.v, balsara.v))),
                   rho_ij.v);
709
710

  /* Now, convolve with the kernel */
James Willis's avatar
James Willis committed
711
712
713
  visc_term.v =
      vec_mul(vec_set1(0.5f),
              vec_mul(visc.v, vec_mul(vec_add(wi_dr.v, wj_dr.v), ri.v)));
James Willis's avatar
James Willis committed
714

715
  sph_term.v =
James Willis's avatar
James Willis committed
716
717
718
      vec_mul(vec_fma(vec_mul(grad_hi.v, piPOrho2.v), wi_dr.v,
                      vec_mul(grad_hj.v, vec_mul(pjPOrho2.v, wj_dr.v))),
              ri.v);
James Willis's avatar
James Willis committed
719

720
  /* Eventually get the acceleration */
721
  acc.v = vec_add(visc_term.v, sph_term.v);
722
723

  /* Use the force, Luke! */
724
725
726
  piax.v = vec_mul(mj.v, vec_mul(dx->v, acc.v));
  piay.v = vec_mul(mj.v, vec_mul(dy->v, acc.v));
  piaz.v = vec_mul(mj.v, vec_mul(dz->v, acc.v));
727
728

  /* Get the time derivative for h. */
James Willis's avatar
James Willis committed
729
730
  pih_dt.v =
      vec_div(vec_mul(mj.v, vec_mul(dvdr.v, vec_mul(ri.v, wi_dr.v))), pjrho.v);
731
732

  /* Change in entropy */
733
  entropy_dt.v = vec_mul(mj.v, vec_mul(visc_term.v, dvdr.v));
734

735
  /* Store the forces back on the particles. */
736
737
738
739
  a_hydro_xSum->v = vec_mask_sub(a_hydro_xSum->v, piax.v, mask);
  a_hydro_ySum->v = vec_mask_sub(a_hydro_ySum->v, piay.v, mask);
  a_hydro_zSum->v = vec_mask_sub(a_hydro_zSum->v, piaz.v, mask);
  h_dtSum->v = vec_mask_sub(h_dtSum->v, pih_dt.v, mask);
740
  v_sigSum->v = vec_fmax(v_sigSum->v, vec_and_mask(v_sig.v, mask));
741
  entropy_dtSum->v = vec_mask_add(entropy_dtSum->v, entropy_dt.v, mask);
742
743
744
745
746
747
748
749
750
751

#else

  error(
      "The Gadget2 serial version of runner_iact_nonsym_force was called when "
      "the vectorised version should have been used.");

#endif
}

James Willis's avatar
James Willis committed
752
753
754
755
/**
 * @brief Force interaction computed using 2 interleaved vectors
 * (non-symmetric vectorized version).
 */
James Willis's avatar
James Willis committed
756
757
__attribute__((always_inline)) INLINE static void
runner_iact_nonsym_2_vec_force(
758
    float *R2, float *Dx, float *Dy, float *Dz, vector vix, vector viy,
James Willis's avatar
James Willis committed
759
760
761
762
763
764
    vector viz, vector pirho, vector grad_hi, vector piPOrho2, vector balsara_i,
    vector ci, float *Vjx, float *Vjy, float *Vjz, float *Pjrho, float *Grad_hj,
    float *PjPOrho2, float *Balsara_j, float *Cj, float *Mj, vector hi_inv,
    float *Hj_inv, vector *a_hydro_xSum, vector *a_hydro_ySum,
    vector *a_hydro_zSum, vector *h_dtSum, vector *v_sigSum,
    vector *entropy_dtSum, mask_t mask, mask_t mask_2, short mask_cond) {
765
766
767

#ifdef WITH_VECTORIZATION

768
769
  vector r, ri;
  vector dvx, dvy, dvz;
770
  vector ui, uj;
771
  vector hid_inv, hjd_inv;
772
  vector wi_dx, wj_dx, wi_dr, wj_dr, dvdr;
773
774
775
  vector piax, piay, piaz;
  vector pih_dt;
  vector v_sig;
776
  vector omega_ij, mu_ij, balsara;
777
778
  vector rho_ij, visc, visc_term, sph_term, acc, entropy_dt;

779
780
  vector r_2, ri_2;
  vector dvx_2, dvy_2, dvz_2;
781
  vector ui_2, uj_2;
782
  vector hjd_inv_2;
783
  vector wi_dx_2, wj_dx_2, wi_dr_2, wj_dr_2, dvdr_2;
784
785
786
787
788
789
790
  vector piax_2, piay_2, piaz_2;
  vector pih_dt_2;
  vector v_sig_2;
  vector omega_ij_2, mu_ij_2, balsara_2;
  vector rho_ij_2, visc_2, visc_term_2, sph_term_2, acc_2, entropy_dt_2;

  /* Fill vectors. */
791
792
793
794
795
796
797
798
799
800
801
802
803
804
  const vector mj = vector_load(Mj);
  const vector mj_2 = vector_load(&Mj[VEC_SIZE]);
  const vector vjx = vector_load(Vjx);
  const vector vjx_2 = vector_load(&Vjx[VEC_SIZE]);
  const vector vjy = vector_load(Vjy);
  const vector vjy_2 = vector_load(&Vjy[VEC_SIZE]);
  const vector vjz = vector_load(Vjz);
  const vector vjz_2 = vector_load(&Vjz[VEC_SIZE]);
  const vector dx = vector_load(Dx);
  const vector dx_2 = vector_load(&Dx[VEC_SIZE]);
  const vector dy = vector_load(Dy);
  const vector dy_2 = vector_load(&Dy[VEC_SIZE]);
  const vector dz = vector_load(Dz);
  const vector dz_2 = vector_load(&Dz[VEC_SIZE]);
James Willis's avatar
James Willis committed
805

806
  /* Get the radius and inverse radius. */
807
808
  const vector r2 = vector_load(R2);
  const vector r2_2 = vector_load(&R2[VEC_SIZE]);
809
810
811
812
  ri = vec_reciprocal_sqrt(r2);
  ri_2 = vec_reciprocal_sqrt(r2_2);
  r.v = vec_mul(r2.v, ri.v);
  r_2.v = vec_mul(r2_2.v, ri_2.v);
813

814
  /* Get remaining properties. */
815
816
817
818
819
820
821
822
823
824
825
826
  const vector pjrho = vector_load(Pjrho);
  const vector pjrho_2 = vector_load(&Pjrho[VEC_SIZE]);
  const vector grad_hj = vector_load(Grad_hj);
  const vector grad_hj_2 = vector_load(&Grad_hj[VEC_SIZE]);
  const vector pjPOrho2 = vector_load(PjPOrho2);
  const vector pjPOrho2_2 = vector_load(&PjPOrho2[VEC_SIZE]);
  const vector balsara_j = vector_load(Balsara_j);
  const vector balsara_j_2 = vector_load(&Balsara_j[VEC_SIZE]);
  const vector cj = vector_load(Cj);
  const vector cj_2 = vector_load(&Cj[VEC_SIZE]);
  const vector hj_inv = vector_load(Hj_inv);
  const vector hj_inv_2 = vector_load(&Hj_inv[VEC_SIZE]);
827

828
829
  const vector fac_mu =
      vector_set1(1.f); /* Will change with cosmological integration */
830

831
832
833
  /* Find the balsara switch. */
  balsara.v = vec_add(balsara_i.v, balsara_j.v);
  balsara_2.v = vec_add(balsara_i.v, balsara_j_2.v);
834
835

  /* Get the kernel for hi. */
836
  hid_inv = pow_dimension_plus_one_vec(hi_inv);
837
838
839
840
841
842
  ui.v = vec_mul(r.v, hi_inv.v);
  ui_2.v = vec_mul(r_2.v, hi_inv.v);
  kernel_eval_dWdx_force_vec(&ui, &wi_dx);
  kernel_eval_dWdx_force_vec(&ui_2, &wi_dx_2);
  wi_dr.v = vec_mul(hid_inv.v, wi_dx.v);
  wi_dr_2.v = vec_mul(hid_inv.v, wi_dx_2.v);
843
844
845
846

  /* Get the kernel for hj. */
  hjd_inv = pow_dimension_plus_one_vec(hj_inv);
  hjd_inv_2 = pow_dimension_plus_one_vec(hj_inv_2);
847
848
  uj.v = vec_mul(r.v, hj_inv.v);
  uj_2.v = vec_mul(r_2.v, hj_inv_2.v);
James Willis's avatar
James Willis committed
849

850
  /* Calculate the kernel for two particles. */
851
852
  kernel_eval_dWdx_force_vec(&uj, &wj_dx);
  kernel_eval_dWdx_force_vec(&uj_2, &wj_dx_2);
James Willis's avatar
James Willis committed
853

854
855
  wj_dr.v = vec_mul(hjd_inv.v, wj_dx.v);
  wj_dr_2.v = vec_mul(hjd_inv_2.v, wj_dx_2.v);
856

857
858
859
860
861
862
863
  /* Compute dv. */
  dvx.v = vec_sub(vix.v, vjx.v);
  dvx_2.v = vec_sub(vix.v, vjx_2.v);
  dvy.v = vec_sub(viy.v, vjy.v);
  dvy_2.v = vec_sub(viy.v, vjy_2.v);
  dvz.v = vec_sub(viz.v, vjz.v);
  dvz_2.v = vec_sub(viz.v, vjz_2.v);
864
865

  /* Compute dv dot r. */
866
  dvdr.v = vec_fma(dvx.v, dx.v, vec_fma(dvy.v, dy.v, vec_mul(dvz.v, dz.v)));
James Willis's avatar
James Willis committed
867
868
  dvdr_2.v = vec_fma(dvx_2.v, dx_2.v,
                     vec_fma(dvy_2.v, dy_2.v, vec_mul(dvz_2.v, dz_2.v)));
869
870
871
872
873

  /* Compute the relative velocity. (This is 0 if the particles move away from
   * each other and negative otherwise) */
  omega_ij.v = vec_fmin(dvdr.v, vec_setzero());
  omega_ij_2.v = vec_fmin(dvdr_2.v, vec_setzero());
James Willis's avatar
James Willis committed
874
875
876
877
  mu_ij.v =
      vec_mul(fac_mu.v, vec_mul(ri.v, omega_ij.v)); /* This is 0 or negative */
  mu_ij_2.v = vec_mul(
      fac_mu.v, vec_mul(ri_2.v, omega_ij_2.v)); /* This is 0 or negative */
878
879

  /* Compute signal velocity */
880
881
  v_sig.v = vec_fnma(vec_set1(3.f), mu_ij.v, vec_add(ci.v, cj.v));
  v_sig_2.v = vec_fnma(vec_set1(3.f), mu_ij_2.v, vec_add(ci.v, cj_2.v));
882
883

  /* Now construct the full viscosity term */
884
885
886
  rho_ij.v = vec_mul(vec_set1(0.5f), vec_add(pirho.v, pjrho.v));
  rho_ij_2.v = vec_mul(vec_set1(0.5f), vec_add(pirho.v, pjrho_2.v));

James Willis's avatar
James Willis committed
887
888
889
890
891
892
893
  visc.v = vec_div(vec_mul(const_viscosity_alpha_fac.v,
                           vec_mul(v_sig.v, vec_mul(mu_ij.v, balsara.v))),
                   rho_ij.v);
  visc_2.v =
      vec_div(vec_mul(const_viscosity_alpha_fac.v,
                      vec_mul(v_sig_2.v, vec_mul(mu_ij_2.v, balsara_2.v))),
              rho_ij_2.v);
894
895

  /* Now, convolve with the kernel */
James Willis's avatar
James Willis committed
896
897
898
899
900
901
902
  visc_term.v =
      vec_mul(vec_set1(0.5f),
              vec_mul(visc.v, vec_mul(vec_add(wi_dr.v, wj_dr.v), ri.v)));
  visc_term_2.v = vec_mul(
      vec_set1(0.5f),
      vec_mul(visc_2.v, vec_mul(vec_add(wi_dr_2.v, wj_dr_2.v), ri_2.v)));

903
904
905
  vector grad_hi_mul_piPOrho2;
  grad_hi_mul_piPOrho2.v = vec_mul(grad_hi.v, piPOrho2.v);

906
  sph_term.v =