Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
35bf96ad
Commit
35bf96ad
authored
Jun 13, 2016
by
Matthieu Schaller
Browse files
Moved the cell neighbour test function to the cell object
parent
e1b31a15
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/cell.c
View file @
35bf96ad
...
...
@@ -662,6 +662,35 @@ void cell_clean_links(struct cell *c, void *data) {
c
->
nr_force
=
0
;
}
/**
* @brief Checks whether the cells are direct neighbours ot not. Both cells have
* to be of the same size
*
* @param ci First #cell.
* @param cj Second #cell.
*
* @todo Deal with periodicity.
*/
int
cell_are_neighbours
(
const
struct
cell
*
restrict
ci
,
const
struct
cell
*
restrict
cj
)
{
#ifdef SANITY_CHECKS
if
(
ci
->
h
[
0
]
!=
cj
->
h
[
0
])
error
(
"Cells of different size !"
);
#endif
/* Maximum allowed distance */
const
double
min_dist
=
1
.
2
*
ci
->
h
[
0
];
/* 1.2 accounts for rounding errors */
/* (Manhattan) Distance between the cells */
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
const
double
center_i
=
ci
->
loc
[
k
];
const
double
center_j
=
cj
->
loc
[
k
];
if
(
fabsf
(
center_i
-
center_j
)
>
min_dist
)
return
0
;
}
return
1
;
}
/**
* @brief Computes the multi-pole brutally and compare to the
* recursively computed one.
...
...
src/cell.h
View file @
35bf96ad
...
...
@@ -188,6 +188,8 @@ void cell_init_parts(struct cell *c, void *data);
void
cell_init_gparts
(
struct
cell
*
c
,
void
*
data
);
void
cell_convert_hydro
(
struct
cell
*
c
,
void
*
data
);
void
cell_clean_links
(
struct
cell
*
c
,
void
*
data
);
int
cell_are_neighbours
(
const
struct
cell
*
restrict
ci
,
const
struct
cell
*
restrict
cj
);
void
cell_check_multipole
(
struct
cell
*
c
,
void
*
data
);
#endif
/* SWIFT_CELL_H */
src/engine.c
View file @
35bf96ad
...
...
@@ -1078,35 +1078,6 @@ void engine_exchange_strays(struct engine *e, size_t offset_parts,
#endif
}
/**
* @brief Checks whether two cells are direct neighbours or not.
*
* @param ci First #cell.
* @param cj Second #cell.
*
* @return 1 if the cell are touching (by a face, edge or corner), 0 otherwise.
*/
__attribute__
((
always_inline
))
INLINE
static
int
are_neighbours
(
const
struct
cell
*
restrict
ci
,
const
struct
cell
*
restrict
cj
)
{
#ifdef SANITY_CHECKS
if
(
ci
->
h
[
0
]
!=
cj
->
h
[
0
])
error
(
" Cells of different size in distance calculation."
);
#endif
/* Maximum allowed distance */
const
double
min_dist
=
1
.
2
*
ci
->
h
[
0
];
/* 1.2 accounts for rounding errors */
/* (Manhattan) Distance between the cells */
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
const
double
center_i
=
ci
->
loc
[
k
];
const
double
center_j
=
cj
->
loc
[
k
];
if
(
fabsf
(
center_i
-
center_j
)
>
min_dist
)
return
0
;
}
return
1
;
}
/**
* @brief Constructs the top-level pair tasks for the short-range gravity
* interactions.
...
...
@@ -1149,7 +1120,7 @@ void engine_make_gravity_tasks(struct engine *e) {
/* Is that neighbour local ? */
if
(
cj
->
nodeID
!=
nodeID
)
continue
;
if
(
are_neighbours
(
ci
,
cj
))
if
(
cell_
are_neighbours
(
ci
,
cj
))
scheduler_addtask
(
sched
,
task_type_pair
,
task_subtype_grav
,
0
,
0
,
ci
,
cj
,
1
);
else
...
...
src/runner_doiact_grav.h
View file @
35bf96ad
...
...
@@ -55,31 +55,6 @@ void runner_do_grav_up(struct runner *r, struct cell *c) {
}
}
/**
* @brief Checks whether the cells are direct neighbours ot not. Both cells have
* to be of the same size
*
* @param ci First #cell.
* @param cj Second #cell.
*
* @todo Deal with periodicity.
*/
__attribute__
((
always_inline
))
INLINE
static
int
are_neighbours
(
const
struct
cell
*
restrict
ci
,
const
struct
cell
*
restrict
cj
)
{
/* Maximum allowed distance */
const
double
min_dist
=
1
.
2
*
ci
->
h
[
0
];
/* 1.2 accounts for rounding errors */
/* (Manhattan) Distance between the cells */
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
const
double
center_i
=
ci
->
loc
[
k
];
const
double
center_j
=
cj
->
loc
[
k
];
if
(
fabsf
(
center_i
-
center_j
)
>
min_dist
)
return
0
;
}
return
1
;
}
/**
* @brief Computes the interaction of all the particles in a cell with the
* multipole of another cell.
...
...
@@ -354,7 +329,7 @@ static void runner_dopair_grav(struct runner *r, struct cell *ci,
"itself."
);
/* Are the cells direct neighbours? */
if
(
!
are_neighbours
(
ci
,
cj
))
if
(
!
cell_
are_neighbours
(
ci
,
cj
))
error
(
"Non-neighbouring cells ! ci->x=[%f %f %f] ci->h=%f cj->loc=[%f %f %f] "
"cj->h=%f"
,
...
...
@@ -394,7 +369,7 @@ static void runner_dopair_grav(struct runner *r, struct cell *ci,
for
(
int
k
=
0
;
k
<
8
;
k
++
)
{
if
(
cj
->
progeny
[
k
]
!=
NULL
)
{
if
(
are_neighbours
(
ci
->
progeny
[
j
],
cj
->
progeny
[
k
]))
{
if
(
cell_
are_neighbours
(
ci
->
progeny
[
j
],
cj
->
progeny
[
k
]))
{
/* Recurse */
runner_dopair_grav
(
r
,
ci
->
progeny
[
j
],
cj
->
progeny
[
k
]);
...
...
@@ -461,7 +436,8 @@ static void runner_dosub_grav(struct runner *r, struct cell *ci,
}
else
{
#ifdef SANITY_CHECKS
if
(
!
are_neighbours
(
ci
,
cj
))
error
(
"Non-neighbouring cells in pair task !"
);
if
(
!
cell_are_neighbours
(
ci
,
cj
))
error
(
"Non-neighbouring cells in pair task !"
);
#endif
runner_dopair_grav
(
r
,
ci
,
cj
);
...
...
@@ -472,36 +448,35 @@ static void runner_do_grav_mm(struct runner *r, struct cell *ci,
struct
cell
*
cj
)
{
#ifdef SANITY_CHECKS
if
(
are_neighbours
(
ci
,
cj
))
{
if
(
cell_are_neighbours
(
ci
,
cj
))
{
error
(
"Non-neighbouring cells in mm task !"
);
}
#endif
#if ICHECK > 0
for
(
int
pid
=
0
;
pid
<
ci
->
gcount
;
pid
++
)
{
for
(
int
pid
=
0
;
pid
<
ci
->
gcount
;
pid
++
)
{
/* Get a hold of the ith part in ci. */
struct
gpart
*
restrict
gp
=
&
ci
->
gparts
[
pid
];
/* Get a hold of the ith part in ci. */
struct
gpart
*
restrict
gp
=
&
ci
->
gparts
[
pid
];
if
(
gp
->
id
==
-
ICHECK
)
message
(
"id=%lld loc=[ %f %f %f ] size= %f count= %d"
,
gp
->
id
,
cj
->
loc
[
0
],
cj
->
loc
[
1
],
cj
->
loc
[
2
],
cj
->
h
[
0
],
cj
->
gcount
);
}
if
(
gp
->
id
==
-
ICHECK
)
message
(
"id=%lld loc=[ %f %f %f ] size= %f count= %d"
,
gp
->
id
,
cj
->
loc
[
0
],
cj
->
loc
[
1
],
cj
->
loc
[
2
],
cj
->
h
[
0
],
cj
->
gcount
);
}
for
(
int
pid
=
0
;
pid
<
cj
->
gcount
;
pid
++
)
{
for
(
int
pid
=
0
;
pid
<
cj
->
gcount
;
pid
++
)
{
/* Get a hold of the ith part in ci. */
struct
gpart
*
restrict
gp
=
&
cj
->
gparts
[
pid
];
/* Get a hold of the ith part in ci. */
struct
gpart
*
restrict
gp
=
&
cj
->
gparts
[
pid
];
if
(
gp
->
id
==
-
ICHECK
)
message
(
"id=%lld loc=[ %f %f %f ] size= %f count= %d"
,
gp
->
id
,
ci
->
loc
[
0
],
ci
->
loc
[
1
],
ci
->
loc
[
2
],
ci
->
h
[
0
],
ci
->
gcount
);
}
if
(
gp
->
id
==
-
ICHECK
)
message
(
"id=%lld loc=[ %f %f %f ] size= %f count= %d"
,
gp
->
id
,
ci
->
loc
[
0
],
ci
->
loc
[
1
],
ci
->
loc
[
2
],
ci
->
h
[
0
],
ci
->
gcount
);
}
#endif
runner_dopair_grav_pm
(
r
,
ci
,
cj
);
runner_dopair_grav_pm
(
r
,
cj
,
ci
);
}
runner_dopair_grav_pm
(
r
,
ci
,
cj
);
runner_dopair_grav_pm
(
r
,
cj
,
ci
);
}
#endif
/* SWIFT_RUNNER_DOIACT_GRAV_H */
tests/testKernelGrav.c
View file @
35bf96ad
...
...
@@ -30,6 +30,7 @@
* @brief The Gadget-2 gravity kernel function
*
* @param r The distance between particles
* @param h The cut-off distance of the kernel
*/
float
gadget
(
float
r
,
float
h
)
{
float
fac
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment