22 const double dh_inv[3][3],
int *bounds) {
30 const int kgmin = ceil(-1e-8 - disr_radius * dh_inv[2][2]);
32 bounds[ibound] = kgmin;
35 for (
int kg = kgmin; kg <= 0; kg++) {
36 const int kd = (2 * kg - 1) / 2;
37 const double kr = kd * dh[2][2];
38 const double kremain = disr_radius * disr_radius - kr * kr;
39 const int jgmin = ceil(-1e-8 - sqrt(fmax(0.0, kremain)) * dh_inv[1][1]);
41 bounds[ibound] = jgmin;
44 for (
int jg = jgmin; jg <= 0; jg++) {
45 const int jd = (2 * jg - 1) / 2;
46 const double jr = jd * dh[1][1];
47 const double jremain = kremain - jr * jr;
48 const int igmin = ceil(-1e-8 - sqrt(fmax(0.0, jremain)) * dh_inv[0][0]);
50 bounds[ibound] = igmin;
63 const double dh[3][3],
64 const double dh_inv[3][3],
73 entry->
offsets = malloc(max_imr *
sizeof(
int));
75 int nbounds_total = 0;
76 for (
int imr = 1; imr <= max_imr; imr++) {
77 const double radius = imr * drmin;
79 entry->
offsets[imr - 1] = nbounds_total;
80 nbounds_total += nbounds;
84 entry->
storage = malloc(nbounds_total *
sizeof(
int));
86 for (
int imr = 1; imr <= max_imr; imr++) {
87 const double radius = imr * drmin;
88 const int offset = entry->
offsets[imr - 1];
99 const double dh_inv[3][3],
int **sphere_bounds,
100 double *discr_radius) {
106 const double dr0 = dh[0][0], dr1 = dh[1][1], dr2 = dh[2][2];
113 if (entry->
dr[0] == dr0 && entry->
dr[1] == dr1 && entry->
dr[2] == dr2) {
120 for (
int i = 0;
i < cache->
size;
i++) {
122 if (entry->
dr[0] == dr0 && entry->
dr[1] == dr1 && entry->
dr[2] == dr2) {
136 assert(cache->
entries != NULL);
137 memcpy(cache->
entries, old_entries, (cache->
size - 1) * entry_size);
146 entry->
drmin = fmin(dr0, fmin(dr1, dr2));
151 const int imr =
imax(1, (
int)ceil(radius * entry->
drmin_inv));
152 *discr_radius = entry->
drmin * imr;
158 const int offset = entry->
offsets[imr - 1];
159 *sphere_bounds = &entry->
storage[offset];
167 for (
int i = 0;
i < cache->
size;
i++) {
static int imax(int x, int y)
Returns the larger of two given integers (missing from the C standard)
static void const int const int i
grid_sphere_cache * grid_library_get_sphere_cache(void)
Returns a pointer to the thread local sphere cache.
void grid_sphere_cache_lookup(const double radius, const double dh[3][3], const double dh_inv[3][3], int **sphere_bounds, double *discr_radius)
Lookup the sphere bound from cache and compute them as needed. See grid_sphere_cache....
static void rebuild_cache_entry(const int max_imr, const double drmin, const double dh[3][3], const double dh_inv[3][3], grid_sphere_cache_entry *entry)
Rebuild a cache entry for a given cell and max radius.
void grid_sphere_cache_free(grid_sphere_cache *cache)
Free the memory of the sphere cache.
static int single_sphere_bounds(const double disr_radius, const double dh[3][3], const double dh_inv[3][3], int *bounds)
Compute the sphere bounds for a given single radius.
Struct holding the sphere cache for one grid as specified by dr[3].
Struct holding the entire sphere cache, ie. for all grids.
grid_sphere_cache_entry * entries