|
1 | 1 |
|
2 | | -# coding: utf-8 |
3 | | - |
4 | | -# <a href="http://landlab.github.io"><img style="float: left" src="https://raw.githubusercontent.com/landlab/tutorials/master/landlab_header.png"></a> |
5 | | -# |
6 | | - |
7 | 2 | # # Using the Landlab flexure component |
8 | 3 | # |
9 | | -# <hr> |
10 | | -# <small> For instructions on how to run an interactive iPython notebook, click here: <a href="https://github.com/landlab/tutorials/blob/master/README.md">https://github.com/landlab/tutorials/blob/master/README.md</a></small><br> |
11 | | -# <small>For the unexpanded version to download and run, click here: <a href="http://nbviewer.jupyter.org/github/landlab/tutorials/blob/master/flexure/lots_of_loads_unexpanded.ipynb">http://nbviewer.jupyter.org/github/landlab/tutorials/blob/master/flexure/lots_of_loads_unexpanded.ipynb</a></small><br> |
12 | | -# <small>For more Landlab tutorials, click here: <a href="https://github.com/landlab/landlab/wiki/Tutorials">https://github.com/landlab/landlab/wiki/Tutorials</a></small> |
13 | | -# <hr> |
14 | | -# |
| 4 | + |
15 | 5 | # In this example we will: |
16 | 6 | # * create a Landlab component that solves the flexure equation |
17 | | -# * apply a point loads all over the place |
| 7 | +# * apply randomly distributed point loads |
18 | 8 | # * run the component |
19 | 9 | # * plot some output |
20 | 10 |
|
21 | | -# A bit of magic so that we can plot within this notebook. |
22 | | - |
23 | | -# In[1]: |
24 | 11 |
|
25 | | -# get_ipython().magic(u'pylab inline') |
| 12 | +import numpy as np |
26 | 13 |
|
27 | 14 |
|
28 | | -# ## Create the component |
| 15 | +# ## Create the grid |
29 | 16 | # |
30 | | -# We are going to build a uniform rectilinear grid with a node spacing of 10 km in each direction on which we will solve the flexure equation. |
| 17 | +# We are going to build a uniform rectilinear grid with a node spacing of 10 km in the *y*-direction and 20 km in the *x*-direction on which we will solve the flexure equation. |
| 18 | +# |
| 19 | +# First we nee to import *RasterModelGrid*. We also import the Landlab plotting function *imshow_grid* to view the grids. |
| 20 | + |
31 | 21 |
|
32 | | -# In[2]: |
| 22 | +from landlab import RasterModelGrid |
| 23 | +from landlab.plot.imshow import imshow_grid |
33 | 24 |
|
34 | | -(n_rows, n_cols) = (200, 400) |
35 | | -(dy, dx) = (10e3, 10e3) |
36 | 25 |
|
| 26 | +# Create a rectilinear grid with a spacing of 10 km between rows and 20 km between columns. The numbers of rows and columms are provided as a `tuple` of `(n_rows, n_cols)`, in the same manner as similar numpy functions. The spacing is also a `tuple`, `(dy, dx)`. |
37 | 27 |
|
38 | | -# In[3]: |
39 | 28 |
|
40 | | -from landlab import RasterModelGrid |
41 | | -grid = RasterModelGrid((n_rows, n_cols), dx) |
| 29 | +grid = RasterModelGrid((200, 400), spacing=(10e3, 20e3)) |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +grid.dy, grid.dx |
42 | 34 |
|
43 | 35 |
|
44 | | -# Now we create the flexure component and tell it to use our newly-created grid. |
| 36 | +# ## Create the component |
| 37 | + |
| 38 | +# Now we create the flexure component and tell it to use our newly-created grid. First, though, we'll examine the Flexure component a bit. |
| 39 | + |
45 | 40 |
|
46 | | -# In[4]: |
47 | 41 |
|
48 | 42 | from landlab.components.flexure import Flexure |
| 43 | + |
| 44 | + |
| 45 | +# The Flexure component, as with most landlab components, will require our grid to have some data that it will use. We can get the names of these data fields with the `intput_var_names` attribute of the component *class*. |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | +Flexure.input_var_names |
| 50 | + |
| 51 | + |
| 52 | +# We see that flexure uses just 1 data field: the change in lithospheric loading. landlab component classes can provide additional information about each of these fields. For instance, to the the units for a field, use the `var_units` method. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +Flexure.var_units('lithosphere__overlying_pressure_increment') |
| 57 | + |
| 58 | + |
| 59 | +# To print a more detailed description of a field, use `var_help`. |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +Flexure.var_help('lithosphere__overlying_pressure_increment') |
| 64 | + |
| 65 | + |
| 66 | +# What about the data that `Flexure` provides? Use the `output_var_names` attribute. |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +Flexure.output_var_names |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +Flexure.var_help('lithosphere_surface__elevation_increment') |
| 76 | + |
| 77 | + |
| 78 | +# Now that we understand the component a little more, create it using our grid. |
| 79 | + |
| 80 | + |
| 81 | + |
49 | 82 | flex = Flexure(grid, method='flexure') |
50 | 83 |
|
51 | 84 |
|
52 | 85 | # ## Add some loading |
53 | | -# We will add some loading at the center of the grid. For this component, the name of the variable that hold the applied loads is call, `lithosphere__overlying_pressure`. We add loads of random magnitude at every node of the grid. |
| 86 | +# We will add loads to the grid. As we saw above, for this component, the name of the variable that hold the applied loads is call, `lithosphere__overlying_pressure`. We add loads of random magnitude at every node of the grid. |
54 | 87 |
|
55 | | -# In[5]: |
| 88 | + |
56 | 89 |
|
57 | | -loads = np.random.normal(1e9, 1e12, grid.number_of_nodes) |
58 | | -grid.at_node['lithosphere__overlying_pressure_increment'][:] = loads |
| 90 | +load = np.random.normal(0, 100 * 2650. * 9.81, grid.number_of_nodes) |
| 91 | +grid.at_node['lithosphere__overlying_pressure_increment'] = load |
59 | 92 |
|
60 | 93 |
|
61 | | -# In[6]: |
| 94 | + |
62 | 95 |
|
63 | | -grid.imshow('node', 'lithosphere__overlying_pressure_increment', symmetric_cbar=True, |
64 | | - cmap='spectral', show=True, shrink=.75) |
| 96 | +imshow_grid(grid, 'lithosphere__overlying_pressure_increment', symmetric_cbar=True, |
| 97 | + cmap='spectral', show=True) |
65 | 98 |
|
66 | 99 |
|
67 | 100 | # ## Update the component to solve for deflection |
68 | 101 | # If you have more than one processor on your machine you may want to use several of them. |
69 | 102 |
|
70 | | -# In[7]: |
| 103 | + |
71 | 104 |
|
72 | 105 | flex.update(n_procs=4) |
73 | 106 |
|
74 | 107 |
|
| 108 | +# As we saw above, the flexure component creates an output field (`lithosphere_surface__elevation_increment`) that contains surface deflections for the applied loads. |
| 109 | + |
75 | 110 | # # Plot the output |
76 | | -# The name of the variable that holds elevations is called `lithosphere__elevation`. |
77 | 111 |
|
78 | | -# In[8]: |
| 112 | +# We now plot these deflections with the `imshow` method, which is available to all landlab components. |
79 | 113 |
|
80 | | -grid.imshow('node', 'lithosphere_surface__elevation_increment', symmetric_cbar=True, |
81 | | - cmap='spectral', show=True, shrink=.75) |
| 114 | + |
| 115 | + |
| 116 | +imshow_grid(grid, 'lithosphere_surface__elevation_increment', symmetric_cbar=True, |
| 117 | + cmap='spectral', show=True) |
| 118 | + |
| 119 | + |
| 120 | +# Maintain the same loading distribution but double the effective elastic thickness. |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +flex.eet *= 2. |
| 125 | +flex.update(n_procs=4) |
| 126 | +imshow_grid(grid, 'lithosphere_surface__elevation_increment', symmetric_cbar=True, |
| 127 | + cmap='spectral', show=True) |
| 128 | + |
| 129 | + |
| 130 | +# Now let's add a vertical rectangular load to the middle of the grid. We plot the load grid first to make sure we did this correctly. |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | +load[np.where(np.logical_and(grid.node_x>3000000, grid.node_x<5000000))]= load[np.where(np.logical_and(grid.node_x>3000000, grid.node_x<5000000))]+1e7 |
| 135 | +imshow_grid(grid, 'lithosphere__overlying_pressure_increment', symmetric_cbar=True, |
| 136 | + cmap='spectral', show=True) |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +flex.update(n_procs=4) |
| 142 | +imshow_grid(grid, 'lithosphere_surface__elevation_increment', symmetric_cbar=True, |
| 143 | + cmap='spectral', show=True) |
82 | 144 |
|
83 | 145 |
|
84 | 146 | # ### Click here for more <a href="https://github.com/landlab/landlab/wiki/Tutorials">Landlab tutorials</a> |
0 commit comments