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
d806b395
Commit
d806b395
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Moved the 'kick' operation to a separate file for clarity.
parent
dcdce6fb
No related branches found
No related tags found
1 merge request
!167
Kick task for fixdt and proper treatment of conserved quantities
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Makefile.am
+1
-1
1 addition, 1 deletion
src/Makefile.am
src/kick.h
+110
-0
110 additions, 0 deletions
src/kick.h
src/runner.c
+10
-121
10 additions, 121 deletions
src/runner.c
with
121 additions
and
122 deletions
src/Makefile.am
+
1
−
1
View file @
d806b395
...
@@ -47,7 +47,7 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
...
@@ -47,7 +47,7 @@ AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
# Include files for distribution, not installation.
# Include files for distribution, not installation.
nobase_noinst_HEADERS
=
approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h
\
nobase_noinst_HEADERS
=
approx_math.h atomic.h cycle.h error.h inline.h kernel_hydro.h kernel_gravity.h
\
vector.h runner_doiact.h runner_doiact_grav.h units.h intrinsics.h minmax.h
\
vector.h runner_doiact.h runner_doiact_grav.h units.h intrinsics.h minmax.h
kick.h
\
gravity.h gravity_io.h
\
gravity.h gravity_io.h
\
gravity/Default/gravity.h gravity/Default/gravity_iact.h gravity/Default/gravity_io.h
\
gravity/Default/gravity.h gravity/Default/gravity_iact.h gravity/Default/gravity_io.h
\
gravity/Default/gravity_debug.h gravity/Default/gravity_part.h
\
gravity/Default/gravity_debug.h gravity/Default/gravity_part.h
\
...
...
This diff is collapsed.
Click to expand it.
src/kick.h
0 → 100644
+
110
−
0
View file @
d806b395
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2016 Matthieu Schaller (matthieu.schaller@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_KICK_H
#define SWIFT_KICK_H
/* Config parameters. */
#include
"../config.h"
/**
* @brief Perform the 'kick' operation on a #gpart
*
* @param gp The #gpart to kick.
* @param new_dti The (integer) time-step for this kick.
* @param timeBase The minimal allowed time-step size.
*/
__attribute__
((
always_inline
))
INLINE
static
void
kick_gpart
(
struct
gpart
*
gp
,
int
new_dti
,
double
timeBase
)
{
/* Compute the time step for this kick */
const
int
ti_start
=
(
gp
->
ti_begin
+
gp
->
ti_end
)
/
2
;
const
int
ti_end
=
gp
->
ti_end
+
new_dti
/
2
;
const
double
dt
=
(
ti_end
-
ti_start
)
*
timeBase
;
const
double
half_dt
=
(
ti_end
-
gp
->
ti_end
)
*
timeBase
;
/* Move particle forward in time */
gp
->
ti_begin
=
gp
->
ti_end
;
gp
->
ti_end
=
gp
->
ti_begin
+
new_dti
;
/* Kick particles in momentum space */
gp
->
v_full
[
0
]
+=
gp
->
a_grav
[
0
]
*
dt
;
gp
->
v_full
[
1
]
+=
gp
->
a_grav
[
1
]
*
dt
;
gp
->
v_full
[
2
]
+=
gp
->
a_grav
[
2
]
*
dt
;
/* Extra kick work */
gravity_kick_extra
(
gp
,
dt
,
half_dt
);
}
/**
* @brief Perform the 'kick' operation on a #part
*
* @param p The #part to kick.
* @param xp The #xpart of the particle.
* @param new_dti The (integer) time-step for this kick.
* @param timeBase The minimal allowed time-step size.
*/
__attribute__
((
always_inline
))
INLINE
static
void
kick_part
(
struct
part
*
p
,
struct
xpart
*
xp
,
int
new_dti
,
double
timeBase
)
{
/* Compute the time step for this kick */
const
int
ti_start
=
(
p
->
ti_begin
+
p
->
ti_end
)
/
2
;
const
int
ti_end
=
p
->
ti_end
+
new_dti
/
2
;
const
double
dt
=
(
ti_end
-
ti_start
)
*
timeBase
;
const
double
half_dt
=
(
ti_end
-
p
->
ti_end
)
*
timeBase
;
/* Move particle forward in time */
p
->
ti_begin
=
p
->
ti_end
;
p
->
ti_end
=
p
->
ti_begin
+
new_dti
;
if
(
p
->
gpart
!=
NULL
)
{
p
->
gpart
->
ti_begin
=
p
->
ti_begin
;
p
->
gpart
->
ti_end
=
p
->
ti_end
;
}
/* Get the acceleration */
float
a_tot
[
3
]
=
{
p
->
a_hydro
[
0
],
p
->
a_hydro
[
1
],
p
->
a_hydro
[
2
]};
if
(
p
->
gpart
!=
NULL
)
{
a_tot
[
0
]
+=
p
->
gpart
->
a_grav
[
0
];
a_tot
[
1
]
+=
p
->
gpart
->
a_grav
[
1
];
a_tot
[
1
]
+=
p
->
gpart
->
a_grav
[
2
];
}
/* Kick particles in momentum space */
xp
->
v_full
[
0
]
+=
a_tot
[
0
]
*
dt
;
xp
->
v_full
[
1
]
+=
a_tot
[
1
]
*
dt
;
xp
->
v_full
[
2
]
+=
a_tot
[
2
]
*
dt
;
if
(
p
->
gpart
!=
NULL
)
{
p
->
gpart
->
v_full
[
0
]
=
xp
->
v_full
[
0
];
p
->
gpart
->
v_full
[
1
]
=
xp
->
v_full
[
1
];
p
->
gpart
->
v_full
[
2
]
=
xp
->
v_full
[
2
];
}
/* Go back by half-step for the hydro velocity */
p
->
v
[
0
]
=
xp
->
v_full
[
0
]
-
half_dt
*
a_tot
[
0
];
p
->
v
[
1
]
=
xp
->
v_full
[
1
]
-
half_dt
*
a_tot
[
1
];
p
->
v
[
2
]
=
xp
->
v_full
[
2
]
-
half_dt
*
a_tot
[
2
];
/* Extra kick work */
hydro_kick_extra
(
p
,
xp
,
dt
,
half_dt
);
if
(
p
->
gpart
!=
NULL
)
gravity_kick_extra
(
p
->
gpart
,
dt
,
half_dt
);
}
#endif
/* SWIFT_KICK_H */
This diff is collapsed.
Click to expand it.
src/runner.c
+
10
−
121
View file @
d806b395
...
@@ -47,6 +47,7 @@
...
@@ -47,6 +47,7 @@
#include
"gravity.h"
#include
"gravity.h"
#include
"hydro_properties.h"
#include
"hydro_properties.h"
#include
"hydro.h"
#include
"hydro.h"
#include
"kick.h"
#include
"minmax.h"
#include
"minmax.h"
#include
"scheduler.h"
#include
"scheduler.h"
#include
"space.h"
#include
"space.h"
...
@@ -941,35 +942,20 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) {
...
@@ -941,35 +942,20 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) {
/* No children? */
/* No children? */
if
(
!
c
->
split
)
{
if
(
!
c
->
split
)
{
/* Loop over the g-particles and kick
the active
one
s
. */
/* Loop over the g-particles and kick
every
one. */
for
(
int
k
=
0
;
k
<
gcount
;
k
++
)
{
for
(
int
k
=
0
;
k
<
gcount
;
k
++
)
{
/* Get a handle on the part. */
/* Get a handle on the part. */
struct
gpart
*
const
gp
=
&
gparts
[
k
];
struct
gpart
*
const
gp
=
&
gparts
[
k
];
/* If the g-particle has no counterpart
and needs to be kicked
*/
/* If the g-particle has no counterpart */
if
(
gp
->
id
<
0
)
{
if
(
gp
->
id
<
0
)
{
/* First, finish the force calculation */
/* First, finish the force calculation */
gravity_end_force
(
gp
);
gravity_end_force
(
gp
);
/* Compute the time step for this kick */
/* Kick the g-particle forward */
const
int
ti_start
=
(
gp
->
ti_begin
+
gp
->
ti_end
)
/
2
;
kick_gpart
(
gp
,
new_dti
,
timeBase
);
const
int
ti_end
=
gp
->
ti_end
+
new_dti
/
2
;
const
double
dt
=
(
ti_end
-
ti_start
)
*
timeBase
;
const
double
half_dt
=
(
ti_end
-
gp
->
ti_end
)
*
timeBase
;
/* Move particle forward in time */
gp
->
ti_begin
=
gp
->
ti_end
;
gp
->
ti_end
=
gp
->
ti_begin
+
new_dti
;
/* Kick particles in momentum space */
gp
->
v_full
[
0
]
+=
gp
->
a_grav
[
0
]
*
dt
;
gp
->
v_full
[
1
]
+=
gp
->
a_grav
[
1
]
*
dt
;
gp
->
v_full
[
2
]
+=
gp
->
a_grav
[
2
]
*
dt
;
/* Extra kick work */
gravity_kick_extra
(
gp
,
dt
,
half_dt
);
/* Number of updated g-particles */
/* Number of updated g-particles */
g_updated
++
;
g_updated
++
;
...
@@ -982,7 +968,7 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) {
...
@@ -982,7 +968,7 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) {
/* Now do the hydro ones... */
/* Now do the hydro ones... */
/* Loop over the particles and kick
the active
one
s
. */
/* Loop over the particles and kick
every
one. */
for
(
int
k
=
0
;
k
<
count
;
k
++
)
{
for
(
int
k
=
0
;
k
<
count
;
k
++
)
{
/* Get a handle on the part. */
/* Get a handle on the part. */
...
@@ -996,47 +982,8 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) {
...
@@ -996,47 +982,8 @@ void runner_do_kick_fixdt(struct runner *r, struct cell *c, int timer) {
hydro_end_force
(
p
);
hydro_end_force
(
p
);
if
(
p
->
gpart
!=
NULL
)
gravity_end_force
(
p
->
gpart
);
if
(
p
->
gpart
!=
NULL
)
gravity_end_force
(
p
->
gpart
);
/* Compute the time step for this kick */
/* Kick the particle forward */
const
int
ti_start
=
(
p
->
ti_begin
+
p
->
ti_end
)
/
2
;
kick_part
(
p
,
xp
,
new_dti
,
timeBase
);
const
int
ti_end
=
p
->
ti_end
+
new_dti
/
2
;
const
double
dt
=
(
ti_end
-
ti_start
)
*
timeBase
;
const
double
half_dt
=
(
ti_end
-
p
->
ti_end
)
*
timeBase
;
/* Move particle forward in time */
p
->
ti_begin
=
p
->
ti_end
;
p
->
ti_end
=
p
->
ti_begin
+
new_dti
;
if
(
p
->
gpart
!=
NULL
)
{
p
->
gpart
->
ti_begin
=
p
->
ti_begin
;
p
->
gpart
->
ti_end
=
p
->
ti_end
;
}
/* Get the acceleration */
float
a_tot
[
3
]
=
{
p
->
a_hydro
[
0
],
p
->
a_hydro
[
1
],
p
->
a_hydro
[
2
]};
if
(
p
->
gpart
!=
NULL
)
{
a_tot
[
0
]
+=
p
->
gpart
->
a_grav
[
0
];
a_tot
[
1
]
+=
p
->
gpart
->
a_grav
[
1
];
a_tot
[
1
]
+=
p
->
gpart
->
a_grav
[
2
];
}
/* Kick particles in momentum space */
xp
->
v_full
[
0
]
+=
a_tot
[
0
]
*
dt
;
xp
->
v_full
[
1
]
+=
a_tot
[
1
]
*
dt
;
xp
->
v_full
[
2
]
+=
a_tot
[
2
]
*
dt
;
if
(
p
->
gpart
!=
NULL
)
{
p
->
gpart
->
v_full
[
0
]
=
xp
->
v_full
[
0
];
p
->
gpart
->
v_full
[
1
]
=
xp
->
v_full
[
1
];
p
->
gpart
->
v_full
[
2
]
=
xp
->
v_full
[
2
];
}
/* Go back by half-step for the hydro velocity */
p
->
v
[
0
]
=
xp
->
v_full
[
0
]
-
half_dt
*
a_tot
[
0
];
p
->
v
[
1
]
=
xp
->
v_full
[
1
]
-
half_dt
*
a_tot
[
1
];
p
->
v
[
2
]
=
xp
->
v_full
[
2
]
-
half_dt
*
a_tot
[
2
];
/* Extra kick work */
hydro_kick_extra
(
p
,
xp
,
dt
,
half_dt
);
if
(
p
->
gpart
!=
NULL
)
gravity_kick_extra
(
p
->
gpart
,
dt
,
half_dt
);
/* Number of updated particles */
/* Number of updated particles */
updated
++
;
updated
++
;
...
@@ -1209,24 +1156,7 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) {
...
@@ -1209,24 +1156,7 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) {
}
}
/* Now we have a time step, proceed with the kick */
/* Now we have a time step, proceed with the kick */
kick_gpart
(
gp
,
new_dti
,
timeBase
);
/* Compute the time step for this kick */
const
int
ti_start
=
(
gp
->
ti_begin
+
gp
->
ti_end
)
/
2
;
const
int
ti_end
=
gp
->
ti_end
+
new_dti
/
2
;
const
double
dt
=
(
ti_end
-
ti_start
)
*
timeBase
;
const
double
half_dt
=
(
ti_end
-
gp
->
ti_end
)
*
timeBase
;
/* Move particle forward in time */
gp
->
ti_begin
=
gp
->
ti_end
;
gp
->
ti_end
=
gp
->
ti_begin
+
new_dti
;
/* Kick particles in momentum space */
gp
->
v_full
[
0
]
+=
gp
->
a_grav
[
0
]
*
dt
;
gp
->
v_full
[
1
]
+=
gp
->
a_grav
[
1
]
*
dt
;
gp
->
v_full
[
2
]
+=
gp
->
a_grav
[
2
]
*
dt
;
/* Extra kick work */
gravity_kick_extra
(
gp
,
dt
,
half_dt
);
/* Number of updated g-particles */
/* Number of updated g-particles */
g_updated
++
;
g_updated
++
;
...
@@ -1309,48 +1239,7 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) {
...
@@ -1309,48 +1239,7 @@ void runner_do_kick(struct runner *r, struct cell *c, int timer) {
}
}
/* Now we have a time step, proceed with the kick */
/* Now we have a time step, proceed with the kick */
kick_part
(
p
,
xp
,
new_dti
,
timeBase
);
/* Compute the time step for this kick */
const
int
ti_start
=
(
p
->
ti_begin
+
p
->
ti_end
)
/
2
;
const
int
ti_end
=
p
->
ti_end
+
new_dti
/
2
;
const
double
dt
=
(
ti_end
-
ti_start
)
*
timeBase
;
const
double
half_dt
=
(
ti_end
-
p
->
ti_end
)
*
timeBase
;
/* Move particle forward in time */
p
->
ti_begin
=
p
->
ti_end
;
p
->
ti_end
=
p
->
ti_begin
+
new_dti
;
if
(
p
->
gpart
!=
NULL
)
{
p
->
gpart
->
ti_begin
=
p
->
ti_begin
;
p
->
gpart
->
ti_end
=
p
->
ti_end
;
}
/* Get the acceleration */
float
a_tot
[
3
]
=
{
p
->
a_hydro
[
0
],
p
->
a_hydro
[
1
],
p
->
a_hydro
[
2
]};
if
(
p
->
gpart
!=
NULL
)
{
a_tot
[
0
]
+=
p
->
gpart
->
a_grav
[
0
];
a_tot
[
1
]
+=
p
->
gpart
->
a_grav
[
1
];
a_tot
[
1
]
+=
p
->
gpart
->
a_grav
[
2
];
}
/* Kick particles in momentum space */
xp
->
v_full
[
0
]
+=
a_tot
[
0
]
*
dt
;
xp
->
v_full
[
1
]
+=
a_tot
[
1
]
*
dt
;
xp
->
v_full
[
2
]
+=
a_tot
[
2
]
*
dt
;
if
(
p
->
gpart
!=
NULL
)
{
p
->
gpart
->
v_full
[
0
]
=
xp
->
v_full
[
0
];
p
->
gpart
->
v_full
[
1
]
=
xp
->
v_full
[
1
];
p
->
gpart
->
v_full
[
2
]
=
xp
->
v_full
[
2
];
}
/* Go back by half-step for the hydro velocity */
p
->
v
[
0
]
=
xp
->
v_full
[
0
]
-
half_dt
*
a_tot
[
0
];
p
->
v
[
1
]
=
xp
->
v_full
[
1
]
-
half_dt
*
a_tot
[
1
];
p
->
v
[
2
]
=
xp
->
v_full
[
2
]
-
half_dt
*
a_tot
[
2
];
/* Extra kick work */
hydro_kick_extra
(
p
,
xp
,
dt
,
half_dt
);
if
(
p
->
gpart
!=
NULL
)
gravity_kick_extra
(
p
->
gpart
,
dt
,
half_dt
);
/* Number of updated particles */
/* Number of updated particles */
updated
++
;
updated
++
;
...
...
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