MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions | Variables
gravity.c File Reference
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "utils.h"
#include "gravity.h"
#include "shortrange-kernel.c"
Include dependency graph for gravity.c:

Go to the source code of this file.

Macros

#define NTAB   (sizeof(shortrange_force_kernels) / sizeof(shortrange_force_kernels[0]))
 

Functions

void gravshort_fill_ntab (const enum ShortRangeForceWindowType ShortRangeForceWindowType, const double Asmth)
 
int grav_apply_short_range_window (double r, double *fac, double *pot, const double cellsize)
 

Variables

static float shortrange_table [NTAB]
 
static float shortrange_table_potential [NTAB]
 
static float shortrange_table_tidal [NTAB]
 

Macro Definition Documentation

◆ NTAB

#define NTAB   (sizeof(shortrange_force_kernels) / sizeof(shortrange_force_kernels[0]))

Definition at line 17 of file gravity.c.

Function Documentation

◆ grav_apply_short_range_window()

int grav_apply_short_range_window ( double  r,
double *  fac,
double *  pot,
const double  cellsize 
)

Definition at line 55 of file gravity.c.

56 {
57  const double dx = shortrange_force_kernels[1][0];
58  double i = (r / cellsize / dx);
59  size_t tabindex = floor(i);
60  if(tabindex >= NTAB - 1)
61  return 1;
62  /* use a linear interpolation; */
63  *fac *= (tabindex + 1 - i) * shortrange_table[tabindex] + (i - tabindex) * shortrange_table[tabindex + 1];
64  *pot *= (tabindex + 1 - i) * shortrange_table_potential[tabindex] + (i - tabindex) * shortrange_table_potential[tabindex];
65  return 0;
66 }
#define NTAB
Definition: gravity.c:17
static float shortrange_table[NTAB]
Definition: gravity.c:20
static float shortrange_table_potential[NTAB]
Definition: gravity.c:20
const double shortrange_force_kernels[][5]

References NTAB, shortrange_force_kernels, shortrange_table, and shortrange_table_potential.

Referenced by apply_accn_to_output(), and grav_short_pair_ngbiter().

Here is the caller graph for this function:

◆ gravshort_fill_ntab()

void gravshort_fill_ntab ( const enum ShortRangeForceWindowType ShortRangeForceWindowType ShortRangeForceWindowType  ,
const double  Asmth 
)

Definition at line 23 of file gravity.c.

24 {
26  if(Asmth != 1.5) {
27  endrun(0, "The short range force window is calibrated for Asmth = 1.5, but running with %g\n", Asmth);
28  }
29  }
30 
31  size_t i;
32  for(i = 0; i < NTAB; i++)
33  {
34  /* force_kernels is in units of mesh points; */
35  double u = shortrange_force_kernels[i][0] * 0.5 / Asmth;
36  switch (ShortRangeForceWindowType) {
38  /* Notice that the table is only calibrated for smth of 1.25*/
39  shortrange_table[i] = shortrange_force_kernels[i][2]; /* ~ erfc(u) + 2.0 * u / sqrt(M_PI) * exp(-u * u); */
40  /* The potential of the calibrated kernel is a bit off, so we still use erfc here; we do not use potential anyways.*/
42  break;
44  shortrange_table[i] = erfc(u) + 2.0 * u / sqrt(M_PI) * exp(-u * u);
45  shortrange_table_potential[i] = erfc(u);
46  break;
47  }
48  /* we don't have a table for that and don't use it anyways. */
49  shortrange_table_tidal[i] = 4.0 * u * u * u / sqrt(M_PI) * exp(-u * u);
50  }
51 }
void endrun(int where, const char *fmt,...)
Definition: endrun.c:147
static float shortrange_table_tidal[NTAB]
Definition: gravity.c:20
ShortRangeForceWindowType
Definition: gravity.h:23
@ SHORTRANGE_FORCE_WINDOW_TYPE_ERFC
Definition: gravity.h:25
@ SHORTRANGE_FORCE_WINDOW_TYPE_EXACT
Definition: gravity.h:24

References endrun(), NTAB, shortrange_force_kernels, SHORTRANGE_FORCE_WINDOW_TYPE_ERFC, SHORTRANGE_FORCE_WINDOW_TYPE_EXACT, shortrange_table, shortrange_table_potential, and shortrange_table_tidal.

Referenced by begrun(), and do_force_test().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ shortrange_table

float shortrange_table[NTAB]
static

variables for short-range lookup table

Definition at line 20 of file gravity.c.

Referenced by grav_apply_short_range_window(), and gravshort_fill_ntab().

◆ shortrange_table_potential

float shortrange_table_potential[NTAB]
static

Definition at line 20 of file gravity.c.

Referenced by grav_apply_short_range_window(), and gravshort_fill_ntab().

◆ shortrange_table_tidal

float shortrange_table_tidal[NTAB]
static

Definition at line 20 of file gravity.c.

Referenced by gravshort_fill_ntab().