Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91511945
main.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Nov 11, 19:22
Size
3 KB
Mime Type
text/x-python
Expires
Wed, Nov 13, 19:22 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
22276065
Attached To
R9490 Homework_sp4e_Peruzzo_SáezUribe
main.py
View Options
#!/bin/env python3
import
sys
import
argparse
import
pypart
from
pypart
import
MaterialPointsFactory
,
ParticlesFactoryInterface
from
pypart
import
PingPongBallsFactory
,
PlanetsFactory
from
pypart
import
CsvWriter
from
pypart
import
ComputeTemperature
from
pypart
import
ComputeGravity
from
pypart
import
ComputeVerletIntegration
# help(pypart)
def
main
(
nsteps
,
freq
,
filename
,
particle_type
,
timestep
):
#print(pypart.__file__)
if
particle_type
==
"planet"
:
PlanetsFactory
.
getInstance
()
elif
particle_type
==
"ping_pong"
:
PingPongBallsFactory
.
getInstance
()
elif
particle_type
==
"material_point"
:
MaterialPointsFactory
.
getInstance
()
else
:
print
(
"Unknown particle type: "
,
particle_type
)
sys
.
exit
(
-
1
)
factory
=
ParticlesFactoryInterface
.
getInstance
()
def
createComputes
(
self
,
timestep
):
if
particle_type
==
"planet"
:
try
:
compute_grav
=
ComputeGravity
()
compute_verlet
=
ComputeVerletIntegration
(
timestep
)
G
=
6.67384e-11
# m^3 * kg^-1 * s^-2
UA
=
149597870.700
# km
earth_mass
=
5.97219e24
# kg
G
/=
(
UA
*
1e3
)
**
3
# UA^3 * kg^-1 * s^-2
G
*=
earth_mass
# UA^3 * earth_mass^-1 * s^-2
G
*=
(
60
*
60
*
24
)
**
2
# UA^3 * earth_mass^-1 * day^-2
compute_grav
.
setG
(
G
)
compute_verlet
.
addInteraction
(
compute_grav
)
self
.
system_evolution
.
addCompute
(
compute_verlet
)
except
Exception
as
e
:
help
(
compute_grav
)
raise
e
elif
particle_type
==
'material_points'
:
try
:
compute_temp
=
ComputeTemperature
()
compute_temp
.
conductivity
=
1
compute_temp
.
L
=
2
compute_temp
.
capacity
=
1
compute_temp
.
density
=
1
compute_temp
.
deltat
=
1
self
.
system_evolution
.
addCompute
(
compute_temp
)
except
Exception
as
e
:
help
(
compute_temp
)
raise
e
evol
=
factory
.
createSimulation
(
filename
,
timestep
,
createComputes
)
dumper
=
CsvWriter
(
"out.csv"
)
dumper
.
write
(
evol
.
getSystem
())
evol
.
setNSteps
(
nsteps
)
evol
.
setDumpFreq
(
freq
)
evol
.
evolve
()
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
(
description
=
'Particles code'
)
parser
.
add_argument
(
'nsteps'
,
type
=
int
,
help
=
'specify the number of steps to perform'
)
parser
.
add_argument
(
'freq'
,
type
=
int
,
help
=
'specify the frequency for dumps'
)
parser
.
add_argument
(
'filename'
,
type
=
str
,
help
=
'start/input filename'
)
parser
.
add_argument
(
'particle_type'
,
type
=
str
,
help
=
'particle type'
)
parser
.
add_argument
(
'timestep'
,
type
=
float
,
help
=
'timestep'
)
args
=
parser
.
parse_args
()
nsteps
=
args
.
nsteps
freq
=
args
.
freq
filename
=
args
.
filename
particle_type
=
args
.
particle_type
timestep
=
args
.
timestep
main
(
nsteps
,
freq
,
filename
,
particle_type
,
timestep
)
Event Timeline
Log In to Comment