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
1802f8f5
Commit
1802f8f5
authored
9 years ago
by
Pedro Gonnet
Browse files
Options
Downloads
Patches
Plain Diff
first batch of functions in space.c.
parent
1b316fc5
No related branches found
No related tags found
2 merge requests
!136
Master
,
!123
Local variable cleanup
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/space.c
+19
-21
19 additions, 21 deletions
src/space.c
with
19 additions
and
21 deletions
src/space.c
+
19
−
21
View file @
1802f8f5
...
@@ -97,12 +97,10 @@ const int sortlistID[27] = {
...
@@ -97,12 +97,10 @@ const int sortlistID[27] = {
int
space_getsid
(
struct
space
*
s
,
struct
cell
**
ci
,
struct
cell
**
cj
,
int
space_getsid
(
struct
space
*
s
,
struct
cell
**
ci
,
struct
cell
**
cj
,
double
*
shift
)
{
double
*
shift
)
{
int
k
,
sid
=
0
,
periodic
=
s
->
periodic
;
struct
cell
*
temp
;
double
dx
[
3
];
/* Get the relative distance between the pairs, wrapping. */
/* Get the relative distance between the pairs, wrapping. */
for
(
k
=
0
;
k
<
3
;
k
++
)
{
const
int
periodic
=
s
->
periodic
;
double
dx
[
3
];
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
dx
[
k
]
=
(
*
cj
)
->
loc
[
k
]
-
(
*
ci
)
->
loc
[
k
];
dx
[
k
]
=
(
*
cj
)
->
loc
[
k
]
-
(
*
ci
)
->
loc
[
k
];
if
(
periodic
&&
dx
[
k
]
<
-
s
->
dim
[
k
]
/
2
)
if
(
periodic
&&
dx
[
k
]
<
-
s
->
dim
[
k
]
/
2
)
shift
[
k
]
=
s
->
dim
[
k
];
shift
[
k
]
=
s
->
dim
[
k
];
...
@@ -114,12 +112,13 @@ int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
...
@@ -114,12 +112,13 @@ int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
}
}
/* Get the sorting index. */
/* Get the sorting index. */
int
sid
=
0
;
for
(
k
=
0
;
k
<
3
;
k
++
)
for
(
k
=
0
;
k
<
3
;
k
++
)
sid
=
3
*
sid
+
((
dx
[
k
]
<
0
.
0
)
?
0
:
((
dx
[
k
]
>
0
.
0
)
?
2
:
1
));
sid
=
3
*
sid
+
((
dx
[
k
]
<
0
.
0
)
?
0
:
((
dx
[
k
]
>
0
.
0
)
?
2
:
1
));
/* Switch the cells around? */
/* Switch the cells around? */
if
(
runner_flip
[
sid
])
{
if
(
runner_flip
[
sid
])
{
temp
=
*
ci
;
const
cell
*
temp
=
*
ci
;
*
ci
=
*
cj
;
*
ci
=
*
cj
;
*
cj
=
temp
;
*
cj
=
temp
;
for
(
k
=
0
;
k
<
3
;
k
++
)
shift
[
k
]
=
-
shift
[
k
];
for
(
k
=
0
;
k
<
3
;
k
++
)
shift
[
k
]
=
-
shift
[
k
];
...
@@ -137,10 +136,8 @@ int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
...
@@ -137,10 +136,8 @@ int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
void
space_rebuild_recycle
(
struct
space
*
s
,
struct
cell
*
c
)
{
void
space_rebuild_recycle
(
struct
space
*
s
,
struct
cell
*
c
)
{
int
k
;
if
(
c
->
split
)
if
(
c
->
split
)
for
(
k
=
0
;
k
<
8
;
k
++
)
for
(
int
k
=
0
;
k
<
8
;
k
++
)
if
(
c
->
progeny
[
k
]
!=
NULL
)
{
if
(
c
->
progeny
[
k
]
!=
NULL
)
{
space_rebuild_recycle
(
s
,
c
->
progeny
[
k
]);
space_rebuild_recycle
(
s
,
c
->
progeny
[
k
]);
space_recycle
(
s
,
c
->
progeny
[
k
]);
space_recycle
(
s
,
c
->
progeny
[
k
]);
...
@@ -158,19 +155,19 @@ void space_rebuild_recycle(struct space *s, struct cell *c) {
...
@@ -158,19 +155,19 @@ void space_rebuild_recycle(struct space *s, struct cell *c) {
void
space_regrid
(
struct
space
*
s
,
double
cell_max
,
int
verbose
)
{
void
space_regrid
(
struct
space
*
s
,
double
cell_max
,
int
verbose
)
{
float
h_max
=
s
->
cell_min
/
kernel_gamma
/
space_stretch
,
dmin
;
float
h_max
=
s
->
cell_min
/
kernel_gamma
/
space_stretch
;
int
i
,
j
,
k
,
cdim
[
3
],
nr_parts
=
s
->
nr_parts
;
const
size_t
nr_parts
=
s
->
nr_parts
;
struct
cell
*
restrict
c
;
struct
cell
*
restrict
c
;
ticks
tic
=
getticks
();
ticks
tic
=
getticks
();
/* Run through the parts and get the current h_max. */
/* Run through the parts and get the current h_max. */
// tic = getticks();
// tic = getticks();
if
(
s
->
cells
!=
NULL
)
{
if
(
s
->
cells
!=
NULL
)
{
for
(
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
if
(
s
->
cells
[
k
].
h_max
>
h_max
)
h_max
=
s
->
cells
[
k
].
h_max
;
if
(
s
->
cells
[
k
].
h_max
>
h_max
)
h_max
=
s
->
cells
[
k
].
h_max
;
}
}
}
else
{
}
else
{
for
(
k
=
0
;
k
<
nr_parts
;
k
++
)
{
for
(
int
k
=
0
;
k
<
nr_parts
;
k
++
)
{
if
(
s
->
parts
[
k
].
h
>
h_max
)
h_max
=
s
->
parts
[
k
].
h
;
if
(
s
->
parts
[
k
].
h
>
h_max
)
h_max
=
s
->
parts
[
k
].
h
;
}
}
s
->
h_max
=
h_max
;
s
->
h_max
=
h_max
;
...
@@ -190,7 +187,8 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
...
@@ -190,7 +187,8 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
if
(
verbose
)
message
(
"h_max is %.3e (cell_max=%.3e)."
,
h_max
,
cell_max
);
if
(
verbose
)
message
(
"h_max is %.3e (cell_max=%.3e)."
,
h_max
,
cell_max
);
/* Get the new putative cell dimensions. */
/* Get the new putative cell dimensions. */
for
(
k
=
0
;
k
<
3
;
k
++
)
int
cdim
[
3
]
for
(
int
k
=
0
;
k
<
3
;
k
++
)
cdim
[
k
]
=
cdim
[
k
]
=
floor
(
s
->
dim
[
k
]
/
fmax
(
h_max
*
kernel_gamma
*
space_stretch
,
cell_max
));
floor
(
s
->
dim
[
k
]
/
fmax
(
h_max
*
kernel_gamma
*
space_stretch
,
cell_max
));
...
@@ -213,7 +211,7 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
...
@@ -213,7 +211,7 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
/* Free the old cells, if they were allocated. */
/* Free the old cells, if they were allocated. */
if
(
s
->
cells
!=
NULL
)
{
if
(
s
->
cells
!=
NULL
)
{
for
(
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
space_rebuild_recycle
(
s
,
&
s
->
cells
[
k
]);
space_rebuild_recycle
(
s
,
&
s
->
cells
[
k
]);
if
(
s
->
cells
[
k
].
sort
!=
NULL
)
free
(
s
->
cells
[
k
].
sort
);
if
(
s
->
cells
[
k
].
sort
!=
NULL
)
free
(
s
->
cells
[
k
].
sort
);
}
}
...
@@ -222,12 +220,12 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
...
@@ -222,12 +220,12 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
}
}
/* Set the new cell dimensions only if smaller. */
/* Set the new cell dimensions only if smaller. */
for
(
k
=
0
;
k
<
3
;
k
++
)
{
for
(
int
k
=
0
;
k
<
3
;
k
++
)
{
s
->
cdim
[
k
]
=
cdim
[
k
];
s
->
cdim
[
k
]
=
cdim
[
k
];
s
->
h
[
k
]
=
s
->
dim
[
k
]
/
cdim
[
k
];
s
->
h
[
k
]
=
s
->
dim
[
k
]
/
cdim
[
k
];
s
->
ih
[
k
]
=
1
.
0
/
s
->
h
[
k
];
s
->
ih
[
k
]
=
1
.
0
/
s
->
h
[
k
];
}
}
dmin
=
fminf
(
s
->
h
[
0
],
fminf
(
s
->
h
[
1
],
s
->
h
[
2
]));
const
float
dmin
=
fminf
(
s
->
h
[
0
],
fminf
(
s
->
h
[
1
],
s
->
h
[
2
]));
/* Allocate the highest level of cells. */
/* Allocate the highest level of cells. */
s
->
tot_cells
=
s
->
nr_cells
=
cdim
[
0
]
*
cdim
[
1
]
*
cdim
[
2
];
s
->
tot_cells
=
s
->
nr_cells
=
cdim
[
0
]
*
cdim
[
1
]
*
cdim
[
2
];
...
@@ -239,9 +237,9 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
...
@@ -239,9 +237,9 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
if
(
lock_init
(
&
s
->
cells
[
k
].
lock
)
!=
0
)
error
(
"Failed to init spinlock."
);
if
(
lock_init
(
&
s
->
cells
[
k
].
lock
)
!=
0
)
error
(
"Failed to init spinlock."
);
/* Set the cell location and sizes. */
/* Set the cell location and sizes. */
for
(
i
=
0
;
i
<
cdim
[
0
];
i
++
)
for
(
int
i
=
0
;
i
<
cdim
[
0
];
i
++
)
for
(
j
=
0
;
j
<
cdim
[
1
];
j
++
)
for
(
int
j
=
0
;
j
<
cdim
[
1
];
j
++
)
for
(
k
=
0
;
k
<
cdim
[
2
];
k
++
)
{
for
(
int
k
=
0
;
k
<
cdim
[
2
];
k
++
)
{
c
=
&
s
->
cells
[
cell_getid
(
cdim
,
i
,
j
,
k
)];
c
=
&
s
->
cells
[
cell_getid
(
cdim
,
i
,
j
,
k
)];
c
->
loc
[
0
]
=
i
*
s
->
h
[
0
];
c
->
loc
[
0
]
=
i
*
s
->
h
[
0
];
c
->
loc
[
1
]
=
j
*
s
->
h
[
1
];
c
->
loc
[
1
]
=
j
*
s
->
h
[
1
];
...
@@ -271,7 +269,7 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
...
@@ -271,7 +269,7 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
else
{
else
{
/* Free the old cells, if they were allocated. */
/* Free the old cells, if they were allocated. */
for
(
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
space_rebuild_recycle
(
s
,
&
s
->
cells
[
k
]);
space_rebuild_recycle
(
s
,
&
s
->
cells
[
k
]);
s
->
cells
[
k
].
sorts
=
NULL
;
s
->
cells
[
k
].
sorts
=
NULL
;
s
->
cells
[
k
].
nr_tasks
=
0
;
s
->
cells
[
k
].
nr_tasks
=
0
;
...
...
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