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
eba6375a
Commit
eba6375a
authored
8 years ago
by
Matthieu Schaller
Browse files
Options
Downloads
Patches
Plain Diff
Started a new script to generate all the derivatives of the gravitational potential
parent
a304d6cd
No related branches found
No related tags found
1 merge request
!328
Gravity multi dt
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
theory/Multipoles/gravity_derivatives.py
+63
-0
63 additions, 0 deletions
theory/Multipoles/gravity_derivatives.py
with
63 additions
and
0 deletions
theory/Multipoles/gravity_derivatives.py
0 → 100644
+
63
−
0
View file @
eba6375a
import
numpy
as
np
import
sys
SUFFIXES
=
{
1
:
'
st
'
,
2
:
'
nd
'
,
3
:
'
rd
'
}
def
ordinal
(
num
):
suffix
=
SUFFIXES
.
get
(
num
%
10
,
'
th
'
)
return
str
(
num
)
+
suffix
# Get the order
n
=
int
(
sys
.
argv
[
1
])
# All non-zero derivatives of u(r_x,r_y,r_z) = r_x^2 + r_y^2 + r_z^2
U_100
=
"
2. * r_x
"
U_200
=
"
2.
"
U_010
=
"
2. * r_y
"
U_020
=
"
2.
"
U_001
=
"
2. * r_z
"
U_002
=
"
2.
"
# Generate all partitions of {1....n}
partitions
=
[]
temp
=
[]
for
i
in
range
(
n
):
temp
.
append
(
1
)
partitions
.
extend
([
list
(
temp
)])
if
n
>
1
:
while
temp
!=
range
(
1
,
n
+
1
):
i
=
n
-
1
while
i
>=
0
and
temp
[
0
]
==
1
:
if
i
>
0
:
max_i
=
max
(
temp
[
0
:
i
])
else
:
max_i
=
0
if
temp
[
i
]
!=
n
and
not
max_i
+
1
<
temp
[
i
]
+
1
:
#print "ok"
temp
[
i
]
+=
1
for
j
in
range
(
i
+
1
,
n
):
temp
[
j
]
=
1
i
=
n
-
1
if
temp
[
0
]
==
1
:
partitions
.
extend
([
list
(
temp
)])
else
:
i
-=
1
# Print the partitions
print
"
Number of partitions:
"
,
len
(
partitions
)
for
i
in
range
(
len
(
partitions
)):
print
"
%3d)
"
%
(
i
+
1
),
partitions
[
i
],
"
-->
"
,
for
current
in
range
(
1
,
n
+
1
):
count
=
0
for
j
in
range
(
n
):
if
partitions
[
i
][
j
]
==
current
:
count
+=
1
if
count
>
0
:
print
"
[
"
,
for
j
in
range
(
n
):
if
partitions
[
i
][
j
]
==
current
:
print
range
(
n
)[
j
]
+
1
,
print
"
]
"
,
print
""
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