/
example_beginner.py
137 lines (114 loc) · 5.86 KB
/
example_beginner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# This file is part of BurnMan - a thermoelastic and thermodynamic toolkit for the Earth and Planetary Sciences
# Copyright (C) 2012 - 2015 by the BurnMan team, released under the GNU
# GPL v2 or later.
"""
example_beginner
----------------
This example script is intended for absolute beginners to BurnMan.
We cover importing BurnMan modules, creating a composite material,
and calculating its seismic properties at lower mantle pressures and
temperatures. Afterwards, we plot it against a 1D seismic model
for visual comparison.
*Uses:*
* :doc:`mineral_database`
* :class:`burnman.Composite`
* :class:`burnman.seismic.PREM`
* :func:`burnman.geotherm.brown_shankland`
* :func:`burnman.Material.evaluate`
*Demonstrates:*
* creating basic composites
* calculating thermoelastic properties
* seismic comparison
"""
from __future__ import absolute_import
# Here we import standard python modules that are required for
# usage of BurnMan. In particular, numpy is used for handling
# numerical arrays and mathematical operations on them, and
# matplotlib is used for generating plots of results of calculations
import numpy as np
import matplotlib.pyplot as plt
# Here we import the relevant modules from BurnMan. The burnman
# module imports several of the most important functionalities of
# the library, including the ability to make composites, and compute
# thermoelastic properties of them. The minerals module includes
# the mineral physical parameters for the predefined minerals in
# BurnMan
import burnman_path # adds the local burnman directory to the path
import burnman
from burnman import minerals
assert burnman_path # silence pyflakes warning
if __name__ == "__main__":
# This is the first actual work done in this example. We define
# composite object and name it "rock". A composite is made by
# giving burnman.composite a list of minerals and their molar fractions.
# Here "rock" has two constituent minerals: it is 80% Mg perovskite
# and 20% periclase. More minerals may be added by simply extending
# the list given to burnman.composite
# For the preset minerals from the SLB_2011, the equation of state
# formulation from Stixrude and Lithgow-Bertolloni (2005) will be used.
rock = burnman.Composite([minerals.SLB_2011.mg_perovskite(),
minerals.SLB_2011.periclase()],
[0.8, 0.2], name='Simple lower mantle assemblage')
print(rock)
# Here we create and load the PREM seismic velocity model, which will be
# used for comparison with the seismic velocities of the "rock" composite
seismic_model = burnman.seismic.PREM()
# We create an array of 20 depths at which we want to evaluate PREM, and then
# query the seismic model for the pressure, density, P wave speed, S wave
# speed, and bulk sound velocity at those depths
depths = np.linspace(750e3, 2800e3, 20)
pressure, seis_rho, seis_vp, seis_vs, seis_vphi = seismic_model.evaluate(
['pressure', 'density', 'v_p', 'v_s', 'v_phi'], depths)
# Now we get an array of temperatures at which we compute
# the seismic properties of the rock. Here we use the Brown+Shankland (1981)
# geotherm for mapping depths to temperature.
temperature = burnman.geotherm.brown_shankland(depths)
# This is the step that does the heavy lifting. burnman.evaluate
# sets the state of the rock at each of the pressures and temperatures defined,
# then calculates the elastic moduli and density of each individual phase. After that,
# it calcalates all the variables asked for. For the composite a default averaging scheme
# of Voigt-Reuss-Hill is used (this can be changes with set_averaging
# scheme)
density, vp, vs, vphi = rock.evaluate(
['density', 'v_p', 'v_s', 'v_phi'], pressure, temperature)
# All the work is done except the plotting! Here we want to plot the seismic wave
# speeds and the density against PREM using the matplotlib plotting tools. We make
# a 2x2 array of plots. The fourth subplot plots the geotherm used for
# this calculation.
# First, we plot the s-wave speed verses the PREM s-wave speed
plt.subplot(2, 2, 1)
plt.plot(pressure / 1.e9, vs / 1.e3, color='b', linestyle='-',
marker='o', markerfacecolor='b', markersize=4, label='computation')
plt.plot(pressure / 1.e9, seis_vs / 1.e3, color='k', linestyle='-',
marker='o', markerfacecolor='k', markersize=4, label='reference')
plt.title("S wave speed (km/s)")
plt.xlim(min(pressure) / 1.e9, max(pressure) / 1.e9)
plt.legend(loc='lower right')
plt.ylim(5, 8.0)
# Next, we plot the p-wave speed verses the PREM p-wave speed
plt.subplot(2, 2, 2)
plt.plot(pressure / 1.e9, vp / 1.e3, color='b', linestyle='-',
marker='o', markerfacecolor='b', markersize=4)
plt.plot(pressure / 1.e9, seis_vp / 1.e3, color='k',
linestyle='-', marker='o', markerfacecolor='k', markersize=4)
plt.title("P wave speed (km/s)")
plt.xlim(min(pressure) / 1.e9, max(pressure) / 1.e9)
plt.ylim(10, 16)
# Next, we plot the density verses the PREM density
plt.subplot(2, 2, 3)
plt.plot(pressure / 1.e9, density / 1.e3, color='b',
linestyle='-', marker='o', markerfacecolor='b', markersize=4)
plt.plot(pressure / 1.e9, seis_rho / 1.e3, color='k',
linestyle='-', marker='o', markerfacecolor='k', markersize=4)
plt.xlim(min(pressure) / 1.e9, max(pressure) / 1.e9)
plt.xlabel("Pressure (GPa)")
plt.title("density (kg/m^3)")
# Finally, we plot the used geotherm
plt.subplot(2, 2, 4)
plt.plot(pressure / 1e9, temperature, color='r', linestyle='-',
marker='o', markerfacecolor='r', markersize=4)
plt.xlim(min(pressure) / 1.e9, max(pressure) / 1.e9)
plt.xlabel("Pressure (GPa)")
plt.title("temperature (K)")
# At long last, we show the results! We are done!
plt.show()