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
6eec891e
Commit
6eec891e
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Documentation
parent
1ec13633
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!143
Gravity particles
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/gravity/Default/gravity.h
+26
-11
26 additions, 11 deletions
src/gravity/Default/gravity.h
src/potentials.h
+28
-3
28 additions, 3 deletions
src/potentials.h
with
54 additions
and
14 deletions
src/gravity/Default/gravity.h
+
26
−
11
View file @
6eec891e
...
...
@@ -20,19 +20,20 @@
#include
<float.h>
#include
"potentials.h"
/**
* @brief Computes the gravity time-step of a given particle
*
* @param gp Pointer to the g-particle data
* @brief Computes the gravity time-step of a given particle.
*
* @param phys_cont The physical constants in internal units.
* @param gp Pointer to the g-particle data.
*/
__attribute__
((
always_inline
))
INLINE
static
float
gravity_compute_timestep
(
const
struct
phys_const
*
const
phys_const
,
const
struct
gpart
*
const
gp
)
{
__attribute__
((
always_inline
))
INLINE
static
float
gravity_compute_timestep
(
const
struct
phys_const
*
phys_const
,
struct
gpart
*
gp
)
{
float
dt
=
FLT_MAX
;
#ifdef EXTERNAL_POTENTIAL_POINTMASS
dt
=
fminf
(
dt
,
external_gravity_pointmass_timestep
(
phys_const
,
gp
));
#endif
return
dt
;
}
...
...
@@ -64,10 +65,27 @@ __attribute__((always_inline))
gp
->
a_grav
[
2
]
=
0
.
f
;
}
__attribute__
((
always_inline
))
INLINE
static
void
external_gravity
(
const
struct
phys_const
*
phys_const
,
struct
gpart
*
g
)
{
/**
* @brief Finishes the gravity calculation.
*
* Multiplies the forces and accelerations by the appropiate constants
*
* @param gp The particle to act upon
*/
__attribute__
((
always_inline
))
INLINE
static
void
gravity_end_force
(
struct
gpart
*
gp
)
{}
/**
* @brief Computes the gravitational acceleration induced by external potentials
*
* @param phys_const The physical constants in internal units.
* @param gp The particle to act upon.
*/
__attribute__
((
always_inline
))
INLINE
static
void
external_gravity
(
const
struct
phys_const
*
const
phys_const
,
struct
gpart
*
gp
)
{
#ifdef EXTERNAL_POTENTIAL_POINTMASS
external_gravity_pointmass
(
phys_const
,
g
);
external_gravity_pointmass
(
phys_const
,
g
p
);
#endif
}
...
...
@@ -80,6 +98,3 @@ __attribute__((always_inline)) INLINE static void external_gravity(const struct
*/
__attribute__
((
always_inline
))
INLINE
static
void
gravity_kick_extra
(
struct
gpart
*
gp
,
float
dt
,
float
half_dt
)
{}
__attribute__
((
always_inline
))
INLINE
static
void
gravity_end_force
(
struct
gpart
*
gp
)
{}
This diff is collapsed.
Click to expand it.
src/potentials.h
+
28
−
3
View file @
6eec891e
...
...
@@ -15,18 +15,26 @@ struct external_potential {
/* Properties of Point Mass */
#ifdef EXTERNAL_POTENTIAL_POINTMASS
#define External_Potential_X (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Y (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Z (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Mass \
(1e10 * SOLAR_MASS_IN_CGS / const_unit_mass_in_cgs)
/**
* @brief Computes the time-step due to the acceleration from a point mass
*
* @param phys_cont The physical constants in internal units.
* @param gp Pointer to the g-particle data.
*/
__attribute__
((
always_inline
))
INLINE
static
float
external_gravity_pointmass_timestep
(
const
struct
phys_const
*
phys_const
,
struct
gpart
*
g
)
{
const
struct
phys_const
*
const
phys_const
,
const
struct
gpart
*
const
g
)
{
const
double
G_newton
=
phys_const
->
newton_gravity
;
/* Currently no limit is imposed */
const
float
dx
=
g
->
x
[
0
]
-
External_Potential_X
;
const
float
dy
=
g
->
x
[
1
]
-
External_Potential_Y
;
const
float
dz
=
g
->
x
[
2
]
-
External_Potential_Z
;
...
...
@@ -47,8 +55,17 @@ __attribute__((always_inline))
return
0
.
03
f
*
sqrtf
(
a_2
/
dota_2
);
}
/**
* @brief Computes the gravitational acceleration of a particle due to a point
* mass
*
* @param phys_cont The physical constants in internal units.
* @param gp Pointer to the g-particle data.
*/
__attribute__
((
always_inline
))
INLINE
static
void
external_gravity_pointmass
(
const
struct
phys_const
*
phys_const
,
struct
gpart
*
g
)
{
const
struct
phys_const
*
const
phys_const
,
struct
gpart
*
g
)
{
const
double
G_newton
=
phys_const
->
newton_gravity
;
const
float
dx
=
g
->
x
[
0
]
-
External_Potential_X
;
const
float
dy
=
g
->
x
[
1
]
-
External_Potential_Y
;
...
...
@@ -60,6 +77,14 @@ __attribute__((always_inline)) INLINE static void external_gravity_pointmass(
g
->
a_grav
[
2
]
+=
-
G_newton
*
External_Potential_Mass
*
dz
*
rinv
*
rinv
*
rinv
;
}
#endif
/* EXTERNAL_POTENTIAL_POINTMASS */
/**
* @brief Initialises the external potential properties in the internal system
* of units.
*
* @param us The current internal system of units
* @param potential The external potential properties to initialize
*/
void
initPotentialProperties
(
struct
UnitSystem
*
us
,
struct
external_potential
*
potential
);
...
...
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