Commit 4be39aa8 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

extract space_getsid into a separate header since it is called a lot and should be inlined.

parent bd8e0449
......@@ -47,7 +47,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h \
dump.h logger.h active.h timeline.h xmf.h gravity_properties.h gravity_derivatives.h \
gravity_softened_derivatives.h vector_power.h collectgroup.h hydro_space.h sort_part.h \
chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h
chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h
# Common source files
AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
......@@ -132,7 +132,8 @@ nobase_noinst_HEADERS = align.h approx_math.h atomic.h barrier.h cycle.h error.h
chemistry/EAGLE/chemistry.h \
chemistry/EAGLE/chemistry_io.h \
chemistry/EAGLE/chemistry_struct.h\
chemistry/EAGLE/chemistry_iact.h
chemistry/EAGLE/chemistry_iact.h \
space_getsid.h
# Sources and flags for regular library
......
......@@ -60,6 +60,7 @@
#include "minmax.h"
#include "scheduler.h"
#include "space.h"
#include "space_getsid.h"
#include "timers.h"
/* Global variables. */
......
......@@ -125,6 +125,9 @@
#define _TIMER_DOPAIR_SUBSET(f) PASTE(timer_dopair_subset, f)
#define TIMER_DOPAIR_SUBSET _TIMER_DOPAIR_SUBSET(FUNCTION)
/* Local headers. */
#include "space_getsid.h"
/**
* @brief Compute the interactions between a cell pair (non-symmetric case).
*
......
......@@ -48,6 +48,7 @@
#include "queue.h"
#include "sort_part.h"
#include "space.h"
#include "space_getsid.h"
#include "task.h"
#include "timers.h"
#include "version.h"
......
......@@ -103,52 +103,6 @@ struct index_data {
int *ind;
};
/**
* @brief Get the shift-id of the given pair of cells, swapping them
* if need be.
*
* @param s The space
* @param ci Pointer to first #cell.
* @param cj Pointer second #cell.
* @param shift Vector from ci to cj.
*
* @return The shift ID and set shift, may or may not swap ci and cj.
*/
int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
double *shift) {
/* Get the relative distance between the pairs, wrapping. */
const int periodic = s->periodic;
double dx[3];
for (int k = 0; k < 3; k++) {
dx[k] = (*cj)->loc[k] - (*ci)->loc[k];
if (periodic && dx[k] < -s->dim[k] / 2)
shift[k] = s->dim[k];
else if (periodic && dx[k] > s->dim[k] / 2)
shift[k] = -s->dim[k];
else
shift[k] = 0.0;
dx[k] += shift[k];
}
/* Get the sorting index. */
int sid = 0;
for (int k = 0; k < 3; k++)
sid = 3 * sid + ((dx[k] < 0.0) ? 0 : ((dx[k] > 0.0) ? 2 : 1));
/* Switch the cells around? */
if (runner_flip[sid]) {
struct cell *temp = *ci;
*ci = *cj;
*cj = temp;
for (int k = 0; k < 3; k++) shift[k] = -shift[k];
}
sid = sortlistID[sid];
/* Return the sort ID. */
return sid;
}
/**
* @brief Recursively dismantle a cell tree.
*
......
......@@ -180,8 +180,6 @@ void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max,
void space_sparts_sort(struct space *s, int *ind, size_t N, int min, int max,
int verbose);
void space_getcells(struct space *s, int nr_cells, struct cell **cells);
int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
double *shift);
void space_init(struct space *s, const struct swift_params *params,
const struct cosmology *cosmo, double dim[3],
struct part *parts, struct gpart *gparts, struct spart *sparts,
......
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2018 Pedro Gonnet (pedro.gonnet@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_SPACE_GETSID_H
#define SWIFT_SPACE_GETSID_H
/* Config parameters. */
#include "../config.h"
/* Some standard headers. */
#include <stddef.h>
/* Includes. */
#include "cell.h"
#include "runner.h"
#include "space.h"
/**
* @brief Get the shift-id of the given pair of cells, swapping them
* if need be.
*
* @param s The space
* @param ci Pointer to first #cell.
* @param cj Pointer second #cell.
* @param shift Vector from ci to cj.
*
* @return The shift ID and set shift, may or may not swap ci and cj.
*/
__attribute__((always_inline)) INLINE static int space_getsid(struct space *s,
struct cell **ci,
struct cell **cj,
double *shift) {
/* Get the relative distance between the pairs, wrapping. */
const int periodic = s->periodic;
double dx[3];
for (int k = 0; k < 3; k++) {
dx[k] = (*cj)->loc[k] - (*ci)->loc[k];
if (periodic && dx[k] < -s->dim[k] / 2)
shift[k] = s->dim[k];
else if (periodic && dx[k] > s->dim[k] / 2)
shift[k] = -s->dim[k];
else
shift[k] = 0.0;
dx[k] += shift[k];
}
/* Get the sorting index. */
int sid = 0;
for (int k = 0; k < 3; k++)
sid = 3 * sid + ((dx[k] < 0.0) ? 0 : ((dx[k] > 0.0) ? 2 : 1));
/* Switch the cells around? */
if (runner_flip[sid]) {
struct cell *temp = *ci;
*ci = *cj;
*cj = temp;
for (int k = 0; k < 3; k++) shift[k] = -shift[k];
}
sid = sortlistID[sid];
/* Return the sort ID. */
return sid;
}
#endif /* SWIFT_SPACE_GETSID_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment