amuse_tutorial_brussel2014: exercise2.py

File exercise2.py, 4.1 KB (added by jilkova, 5 years ago)
Line 
1# -*- coding: utf-8 -*-
2# <nbformat>3.0</nbformat>
3
4# <markdowncell>
5
6# # Radiative Transfer in AMUSE: example with Stellar Evolution
7#
8# In this exercise you will learn to design a simple numerical experiment using a radiative transfer code, coupled to stellar evolution (in highly idealized fashion).
9
10# <markdowncell>
11
12# ## imports
13#
14# first we import a radiative tranfer code and a stellar evolution code:
15
16# <codecell>
17
18from amuse.community.sphray.interface import SPHRay
19from amuse.community.seba.interface import SeBa
20
21# <markdowncell>
22
23# next, a simple initial condition for the gas:
24
25# <codecell>
26
27from amuse.ext.molecular_cloud import new_ism_cube
28
29# <markdowncell>
30
31# then the AMUSE units and constants module, and the Particle object:
32
33# <codecell>
34
35from amuse.units import units,constants
36from amuse.datamodel import Particle
37
38# <markdowncell>
39
40# take a moment to consider the following:
41#
42# 1. what are the pro's and con's of importing all the components seperately versus the:
43#
44#         from amuse.lab import *
45#
46#    statement used in the tutorial?
47
48# <markdowncell>
49
50# ## Getting started
51#
52# The above imports make available a number of classes, which you are probably unfamiliar with - there are a number of ways to get information about these
53# (without reading the manual!):
54#   
55#     print help(new_ism_cube)
56# for the community codes, it is always a good idea to readup on the respective code papers:
57#
58#     code=SPHRay()
59#     code.print_literature_references()
60# or print out its parameters:
61#
62#     print code.parameters
63# or:
64#
65#     help(code.parameters)
66#
67# 1. play around with these way to get information
68
69# <codecell>
70
71pass
72
73# <markdowncell>
74
75# ## coupling rad transfer and stellar evolution
76#
77# consider the code below (which is slightly modified from the code you have seen before in the tutorial 6):
78
79# <codecell>
80
81tend=5. | units.Myr
82
83gas = new_ism_cube(5000, 1 | units.kpc, 0.01 | (units.amu / units.cm**3))
84gas.h_smooth = 0.1 | units.kpc
85gas.xion = 0.00
86sources = Particle(1,position = [0,0,0] | units.parsec, luminosity = 1 | 1.e50 / units.s, SpcType=0).as_set()
87
88rad = SPHRay()
89rad.parameters.box_size = 2.0 | units.kpc
90rad.parameters.number_of_rays= 10000 | units.Myr**-1
91
92rad.gas_particles.add_particles(gas)
93rad.src_particles.add_particles(sources)
94rad.evolve_model(tend)
95scatter(rad.gas_particles.position.lengths().value_in(units.kpc), rad.gas_particles.xion)
96rad.stop()
97
98# <markdowncell>
99
100# ## including stellar evolution
101#
102# we are going to include sources based on a stellar evolution for a 30 MSun star.
103#
104# 1. copy and change the above code to set the ionizing luminosity to a value calculated from the initial model of the stellar evolution code using the function you wrote in the previous exercise. For this, you need to generate the source with a mass instead of a luminosity. Note that a particle in a stellar evolution code also has an attribute luminosity, but this is the total bolometric luminosity.
105
106# <codecell>
107
108pass
109
110# <markdowncell>
111
112# ## time dependence
113#
114# next, we want to add time dependence. This will be done by simply alternating stellar evolution and radiative transfer, updating the luminoisty of the source as the star evolves. For this we need a way to update the luminosity in SPHRay, this can be done using a channel:
115#     
116#     channel_to_rad=sources.new_channel_to(rad.src_particles)
117#     channel_to_rad.copy_attributes(["x","y","z","luminosity","SpcType"])
118#
119# similarly, we can copy the attributes needed for the calculation of the luminosity from the stellar evolution code se:
120#
121#     channel_from_se=se.particles.new_channel_to(sources)
122#     channel_from_se.copy_attributes(["radius","temperature"])
123#
124# 1. change the code to evolve the model taking substeps dt, and make a plot every dtplot
125# 2. change the code to co-evolve the stellar evolution
126# 3. change the code to update the ionizing luminosity (using the above channel) every dt
127
128# <codecell>
129
130pass
131
132# <markdowncell>
133
134# if you have time you can consider the following:
135#     
136# 1. change the code so that instead of a single star, it contains radiation from a population of stars.
137#     
138
139# <codecell>
140
141from amuse.ic.salpeter import new_salpeter_mass_distribution
142