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
b11b3ea6
Commit
b11b3ea6
authored
9 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Softened gravity in the interactions
parent
0c8575ca
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!212
Gravity infrastructure
,
!172
[WIP] Self gravity (Barnes-Hut version)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/gravity/Default/gravity_iact.h
+73
-17
73 additions, 17 deletions
src/gravity/Default/gravity_iact.h
src/tools.c
+1
-13
1 addition, 13 deletions
src/tools.c
with
74 additions
and
30 deletions
src/gravity/Default/gravity_iact.h
+
73
−
17
View file @
b11b3ea6
...
...
@@ -33,40 +33,96 @@ __attribute__((always_inline)) INLINE static void runner_iact_grav_pp(
float
r2
,
const
float
*
dx
,
struct
gpart
*
gpi
,
struct
gpart
*
gpj
)
{
/* Apply the gravitational acceleration. */
const
float
ir
=
1
.
0
f
/
sqrtf
(
r2
);
const
float
w
=
ir
*
ir
*
ir
;
const
float
wdx
[
3
]
=
{
w
*
dx
[
0
],
w
*
dx
[
1
],
w
*
dx
[
2
]};
const
float
r
=
sqrtf
(
r2
);
const
float
ir
=
1
.
f
/
r
;
const
float
mi
=
gpi
->
mass
;
const
float
mj
=
gpj
->
mass
;
gpi
->
a_grav
[
0
]
-=
wdx
[
0
]
*
mj
;
gpi
->
a_grav
[
1
]
-=
wdx
[
1
]
*
mj
;
gpi
->
a_grav
[
2
]
-=
wdx
[
2
]
*
mj
;
const
float
hi
=
gpi
->
epsilon
;
const
float
hi_inv
=
1
.
f
/
hi
;
const
float
hi_inv3
=
hi_inv
*
hi_inv
*
hi_inv
;
const
float
hj
=
gpj
->
epsilon
;
const
float
hj_inv
=
1
.
f
/
hj
;
const
float
hj_inv3
=
hj_inv
*
hj_inv
*
hj_inv
;
const
float
ui
=
r
*
hi_inv
;
const
float
uj
=
r
*
hj_inv
;
float
fi
,
fj
,
W
;
if
(
r
>=
hi
)
{
/* Get Newtonian graavity */
fi
=
mj
*
ir
*
ir
*
ir
;
}
else
{
/* Get softened gravity */
kernel_grav_eval
(
ui
,
&
W
);
fi
=
mj
*
hi_inv3
*
W
;
}
if
(
r
>=
hj
)
{
/* Get Newtonian graavity */
fj
=
mi
*
ir
*
ir
*
ir
;
}
else
{
/* Get softened gravity */
kernel_grav_eval
(
uj
,
&
W
);
fj
=
mi
*
hj_inv3
*
W
;
}
const
float
fidx
[
3
]
=
{
fi
*
dx
[
0
],
fi
*
dx
[
1
],
fi
*
dx
[
2
]};
gpi
->
a_grav
[
0
]
-=
fidx
[
0
];
gpi
->
a_grav
[
1
]
-=
fidx
[
1
];
gpi
->
a_grav
[
2
]
-=
fidx
[
2
];
gpi
->
mass_interacted
+=
mj
;
gpj
->
a_grav
[
0
]
+=
wdx
[
0
]
*
mi
;
gpj
->
a_grav
[
1
]
+=
wdx
[
1
]
*
mi
;
gpj
->
a_grav
[
2
]
+=
wdx
[
2
]
*
mi
;
const
float
fjdx
[
3
]
=
{
fj
*
dx
[
0
],
fj
*
dx
[
1
],
fj
*
dx
[
2
]};
gpj
->
a_grav
[
0
]
+=
fjdx
[
0
];
gpj
->
a_grav
[
1
]
+=
fjdx
[
1
];
gpj
->
a_grav
[
2
]
+=
fjdx
[
2
];
gpj
->
mass_interacted
+=
mi
;
}
/**
* @brief Gravity forces between particles (non-symmetric version)
*/
__attribute__
((
always_inline
))
INLINE
static
void
runner_iact_grav_pp_nonsym
(
float
r2
,
const
float
*
dx
,
struct
gpart
*
gpi
,
const
struct
gpart
*
gpj
)
{
/* Apply the gravitational acceleration. */
const
float
ir
=
1
.
0
f
/
sqrtf
(
r2
);
const
float
w
=
ir
*
ir
*
ir
;
const
float
wdx
[
3
]
=
{
w
*
dx
[
0
],
w
*
dx
[
1
],
w
*
dx
[
2
]};
const
float
r
=
sqrtf
(
r2
);
const
float
ir
=
1
.
f
/
r
;
const
float
mj
=
gpj
->
mass
;
const
float
hi
=
gpi
->
epsilon
;
const
float
hi_inv
=
1
.
f
/
hi
;
const
float
hi_inv3
=
hi_inv
*
hi_inv
*
hi_inv
;
const
float
ui
=
r
*
hi_inv
;
float
f
,
W
;
gpi
->
a_grav
[
0
]
-=
wdx
[
0
]
*
mj
;
gpi
->
a_grav
[
1
]
-=
wdx
[
1
]
*
mj
;
gpi
->
a_grav
[
2
]
-=
wdx
[
2
]
*
mj
;
if
(
r
>=
hi
)
{
/* Get Newtonian graavity */
f
=
mj
*
ir
*
ir
*
ir
;
}
else
{
/* Get softened gravity */
kernel_grav_eval
(
ui
,
&
W
);
f
=
mj
*
hi_inv3
*
W
;
}
const
float
fdx
[
3
]
=
{
f
*
dx
[
0
],
f
*
dx
[
1
],
f
*
dx
[
2
]};
gpi
->
a_grav
[
0
]
-=
fdx
[
0
];
gpi
->
a_grav
[
1
]
-=
fdx
[
1
];
gpi
->
a_grav
[
2
]
-=
fdx
[
2
];
gpi
->
mass_interacted
+=
mj
;
}
/**
* @brief Gravity forces between particle
s
* @brief Gravity forces between particle
and multipole
*/
__attribute__
((
always_inline
))
INLINE
static
void
runner_iact_grav_pm
(
float
r2
,
const
float
*
dx
,
struct
gpart
*
gp
,
...
...
This diff is collapsed.
Click to expand it.
src/tools.c
+
1
−
13
View file @
b11b3ea6
...
...
@@ -506,13 +506,11 @@ void gravity_n2(struct gpart *gparts, const int gcount,
/* Get a hold of the ith part in ci. */
struct
gpart
*
restrict
gpi
=
&
gparts
[
pid
];
const
float
mi
=
gpi
->
mass
;
for
(
int
pjd
=
pid
+
1
;
pjd
<
gcount
;
pjd
++
)
{
/* Get a hold of the jth part in ci. */
struct
gpart
*
restrict
gpj
=
&
gparts
[
pjd
];
const
float
mj
=
gpj
->
mass
;
/* Compute the pairwise distance. */
const
float
dx
[
3
]
=
{
gpi
->
x
[
0
]
-
gpj
->
x
[
0
],
// x
...
...
@@ -521,17 +519,7 @@ void gravity_n2(struct gpart *gparts, const int gcount,
const
float
r2
=
dx
[
0
]
*
dx
[
0
]
+
dx
[
1
]
*
dx
[
1
]
+
dx
[
2
]
*
dx
[
2
];
/* Apply the gravitational acceleration. */
const
float
ir
=
1
.
0
f
/
sqrtf
(
r2
);
const
float
w
=
ir
*
ir
*
ir
;
const
float
wdx
[
3
]
=
{
w
*
dx
[
0
],
w
*
dx
[
1
],
w
*
dx
[
2
]};
gpi
->
a_grav
[
0
]
-=
wdx
[
0
]
*
mj
;
gpi
->
a_grav
[
1
]
-=
wdx
[
1
]
*
mj
;
gpi
->
a_grav
[
2
]
-=
wdx
[
2
]
*
mj
;
gpj
->
a_grav
[
0
]
+=
wdx
[
0
]
*
mi
;
gpj
->
a_grav
[
1
]
+=
wdx
[
1
]
*
mi
;
gpj
->
a_grav
[
2
]
+=
wdx
[
2
]
*
mi
;
runner_iact_grav_pp
(
r2
,
dx
,
gpi
,
gpj
);
}
}
...
...
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