Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
e7f9b9a1
Commit
e7f9b9a1
authored
Oct 15, 2015
by
Matthieu Schaller
Browse files
Faster way of generating ICs in python.
parent
bf19a904
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/UniformBox/makeIC.py
View file @
e7f9b9a1
...
...
@@ -27,7 +27,7 @@ from numpy import *
# Parameters
periodic
=
1
# 1 For periodic box
boxSize
=
1.
L
=
5
0
# Number of particles along one axis
L
=
10
0
# Number of particles along one axis
rho
=
2.
# Density
P
=
1.
# Pressure
gamma
=
5.
/
3.
# Gas adiabatic index
...
...
@@ -40,32 +40,19 @@ mass = boxSize**3 * rho / numPart
internalEnergy
=
P
/
((
gamma
-
1.
)
*
rho
)
#Generate particles
coords
=
zeros
((
numPart
,
3
))
ids
=
linspace
(
0
,
numPart
,
numPart
,
endpoint
=
False
,
dtype
=
'L'
).
reshape
((
numPart
,
1
))
v
=
zeros
((
numPart
,
3
))
m
=
zeros
((
numPart
,
1
))
h
=
zeros
((
numPart
,
1
))
u
=
zeros
((
numPart
,
1
))
ids
=
zeros
((
numPart
,
1
),
dtype
=
'L'
)
m
=
full
((
numPart
,
1
),
mass
)
h
=
full
((
numPart
,
1
),
2.251
*
boxSize
/
L
)
u
=
full
((
numPart
,
1
),
internalEnergy
)
for
i
in
range
(
L
):
for
j
in
range
(
L
):
for
k
in
range
(
L
):
index
=
i
*
L
*
L
+
j
*
L
+
k
x
=
i
*
boxSize
/
L
+
boxSize
/
(
2
*
L
)
y
=
j
*
boxSize
/
L
+
boxSize
/
(
2
*
L
)
z
=
k
*
boxSize
/
L
+
boxSize
/
(
2
*
L
)
coords
[
index
,
0
]
=
x
coords
[
index
,
1
]
=
y
coords
[
index
,
2
]
=
z
v
[
index
,
0
]
=
0.
v
[
index
,
1
]
=
0.
v
[
index
,
2
]
=
0.
m
[
index
]
=
mass
h
[
index
]
=
2.251
*
boxSize
/
L
u
[
index
]
=
internalEnergy
ids
[
index
]
=
index
x
=
ids
%
L
;
y
=
((
ids
-
x
)
/
L
)
%
L
;
z
=
(
ids
-
x
-
L
*
y
)
/
L
**
2
;
coords
=
zeros
((
numPart
,
3
))
coords
[:,
0
]
=
z
[:,
0
]
*
boxSize
/
L
+
boxSize
/
(
2
*
L
)
coords
[:,
1
]
=
y
[:,
0
]
*
boxSize
/
L
+
boxSize
/
(
2
*
L
)
coords
[:,
2
]
=
x
[:,
0
]
*
boxSize
/
L
+
boxSize
/
(
2
*
L
)
#--------------------------------------------------
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment