Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SWIFT
SWIFTsim
Commits
35bf96ad
Commit
35bf96ad
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Moved the cell neighbour test function to the cell object
parent
e1b31a15
No related branches found
No related tags found
2 merge requests
!212
Gravity infrastructure
,
!172
[WIP] Self gravity (Barnes-Hut version)
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/cell.c
+29
-0
29 additions, 0 deletions
src/cell.c
src/cell.h
+2
-0
2 additions, 0 deletions
src/cell.h
src/engine.c
+1
-30
1 addition, 30 deletions
src/engine.c
src/runner_doiact_grav.h
+23
-48
23 additions, 48 deletions
src/runner_doiact_grav.h
tests/testKernelGrav.c
+1
-0
1 addition, 0 deletions
tests/testKernelGrav.c
with
56 additions
and
78 deletions
src/cell.c
+
29
−
0
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.
...
...
This diff is collapsed.
Click to expand it.
src/cell.h
+
2
−
0
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 */
This diff is collapsed.
Click to expand it.
src/engine.c
+
1
−
30
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
...
...
This diff is collapsed.
Click to expand it.
src/runner_doiact_grav.h
+
23
−
48
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 */
This diff is collapsed.
Click to expand it.
tests/testKernelGrav.c
+
1
−
0
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
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment