Skip to content

Commit 1dd7404

Browse files
committed
Updated Jupyter Book folder to include wave1D_prog and vib_undamped.
1 parent 92821ce commit 1dd7404

3,011 files changed

Lines changed: 36683 additions & 453 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
262 Bytes
Binary file not shown.

fdm-jupyter-book/_build/html/genindex.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,58 @@ <h1 class="site-logo" id="site-title">The Devito Book</h1>
7979
</a>
8080
</li>
8181
</ul>
82+
<p class="caption">
83+
<span class="caption-text">
84+
Vibration ODEs
85+
</span>
86+
</p>
87+
<ul class="nav sidenav_l1">
88+
<li class="toctree-l1">
89+
<a class="reference internal" href="notebooks/vib/vib_undamped.html">
90+
Finite difference discretization
91+
</a>
92+
</li>
93+
<li class="toctree-l1">
94+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#implementation">
95+
Implementation
96+
</a>
97+
</li>
98+
<li class="toctree-l1">
99+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#visualization-of-long-time-simulations">
100+
Visualization of long time simulations
101+
</a>
102+
</li>
103+
<li class="toctree-l1">
104+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#analysis-of-the-numerical-scheme">
105+
Analysis of the numerical scheme
106+
</a>
107+
</li>
108+
<li class="toctree-l1">
109+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#alternative-schemes-based-on-1st-order-equations">
110+
Alternative schemes based on 1st-order equations
111+
</a>
112+
</li>
113+
<li class="toctree-l1">
114+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#energy-considerations">
115+
Energy considerations
116+
</a>
117+
</li>
118+
<li class="toctree-l1">
119+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#the-euler-cromer-method">
120+
The Euler-Cromer method
121+
</a>
122+
</li>
123+
<li class="toctree-l1">
124+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#staggered-mesh">
125+
Staggered mesh
126+
</a>
127+
</li>
128+
<li class="toctree-l1">
129+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#exercises-and-problems">
130+
Exercises and Problems
131+
</a>
132+
</li>
133+
</ul>
82134
<p class="caption">
83135
<span class="caption-text">
84136
Wave equations
@@ -95,6 +147,16 @@ <h1 class="site-logo" id="site-title">The Devito Book</h1>
95147
Verification
96148
</a>
97149
</li>
150+
<li class="toctree-l1">
151+
<a class="reference internal" href="notebooks/wave/wave1D_prog.html">
152+
Implementation
153+
</a>
154+
</li>
155+
<li class="toctree-l1">
156+
<a class="reference internal" href="notebooks/wave/wave1D_prog.html#exercises">
157+
Exercises
158+
</a>
159+
</li>
98160
</ul>
99161

100162
</nav>

fdm-jupyter-book/_build/html/index.html

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<script async="async" src="_static/sphinx-thebe.js"></script>
4040
<link rel="index" title="Index" href="genindex.html" />
4141
<link rel="search" title="Search" href="search.html" />
42-
<link rel="next" title="Simulation of waves on a string" href="notebooks/wave/wave1D_fd1.html" />
42+
<link rel="next" title="Finite difference discretization" href="notebooks/vib/vib_undamped.html" />
4343

4444
<meta name="viewport" content="width=device-width, initial-scale=1">
4545
<meta name="docsearch:language" content="en">
@@ -79,6 +79,58 @@ <h1 class="site-logo" id="site-title">The Devito Book</h1>
7979
</a>
8080
</li>
8181
</ul>
82+
<p class="caption">
83+
<span class="caption-text">
84+
Vibration ODEs
85+
</span>
86+
</p>
87+
<ul class="nav sidenav_l1">
88+
<li class="toctree-l1">
89+
<a class="reference internal" href="notebooks/vib/vib_undamped.html">
90+
Finite difference discretization
91+
</a>
92+
</li>
93+
<li class="toctree-l1">
94+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#implementation">
95+
Implementation
96+
</a>
97+
</li>
98+
<li class="toctree-l1">
99+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#visualization-of-long-time-simulations">
100+
Visualization of long time simulations
101+
</a>
102+
</li>
103+
<li class="toctree-l1">
104+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#analysis-of-the-numerical-scheme">
105+
Analysis of the numerical scheme
106+
</a>
107+
</li>
108+
<li class="toctree-l1">
109+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#alternative-schemes-based-on-1st-order-equations">
110+
Alternative schemes based on 1st-order equations
111+
</a>
112+
</li>
113+
<li class="toctree-l1">
114+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#energy-considerations">
115+
Energy considerations
116+
</a>
117+
</li>
118+
<li class="toctree-l1">
119+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#the-euler-cromer-method">
120+
The Euler-Cromer method
121+
</a>
122+
</li>
123+
<li class="toctree-l1">
124+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#staggered-mesh">
125+
Staggered mesh
126+
</a>
127+
</li>
128+
<li class="toctree-l1">
129+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#exercises-and-problems">
130+
Exercises and Problems
131+
</a>
132+
</li>
133+
</ul>
82134
<p class="caption">
83135
<span class="caption-text">
84136
Wave equations
@@ -95,6 +147,16 @@ <h1 class="site-logo" id="site-title">The Devito Book</h1>
95147
Verification
96148
</a>
97149
</li>
150+
<li class="toctree-l1">
151+
<a class="reference internal" href="notebooks/wave/wave1D_prog.html">
152+
Implementation
153+
</a>
154+
</li>
155+
<li class="toctree-l1">
156+
<a class="reference internal" href="notebooks/wave/wave1D_prog.html#exercises">
157+
Exercises
158+
</a>
159+
</li>
98160
</ul>
99161

100162
</nav>
@@ -188,6 +250,8 @@ <h1>Welcome to the Devito Book!<a class="headerlink" href="#welcome-to-the-devit
188250
<p>We would like to say a special thank you to H. P. Langtangen and S. Linge, the authors of the <a class="reference external" href="https://github.com/hplgit/fdm-book">book</a> that these tutorials were based upon (“Finite Difference Computing with PDEs - A Modern Software Approach”).</p>
189251
<div class="toctree-wrapper compound">
190252
</div>
253+
<div class="toctree-wrapper compound">
254+
</div>
191255
</div>
192256

193257
<script type="text/x-thebe-config">
@@ -218,7 +282,7 @@ <h1>Welcome to the Devito Book!<a class="headerlink" href="#welcome-to-the-devit
218282

219283
<div class='prev-next-bottom'>
220284

221-
<a class='right-next' id="next-link" href="notebooks/wave/wave1D_fd1.html" title="next page">Simulation of waves on a string</a>
285+
<a class='right-next' id="next-link" href="notebooks/vib/vib_undamped.html" title="next page">Finite difference discretization</a>
222286

223287
</div>
224288
<footer class="footer mt-5 mt-md-0">
50 Bytes
Binary file not shown.

fdm-jupyter-book/_build/html/search.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,58 @@ <h1 class="site-logo" id="site-title">The Devito Book</h1>
8383
</a>
8484
</li>
8585
</ul>
86+
<p class="caption">
87+
<span class="caption-text">
88+
Vibration ODEs
89+
</span>
90+
</p>
91+
<ul class="nav sidenav_l1">
92+
<li class="toctree-l1">
93+
<a class="reference internal" href="notebooks/vib/vib_undamped.html">
94+
Finite difference discretization
95+
</a>
96+
</li>
97+
<li class="toctree-l1">
98+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#implementation">
99+
Implementation
100+
</a>
101+
</li>
102+
<li class="toctree-l1">
103+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#visualization-of-long-time-simulations">
104+
Visualization of long time simulations
105+
</a>
106+
</li>
107+
<li class="toctree-l1">
108+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#analysis-of-the-numerical-scheme">
109+
Analysis of the numerical scheme
110+
</a>
111+
</li>
112+
<li class="toctree-l1">
113+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#alternative-schemes-based-on-1st-order-equations">
114+
Alternative schemes based on 1st-order equations
115+
</a>
116+
</li>
117+
<li class="toctree-l1">
118+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#energy-considerations">
119+
Energy considerations
120+
</a>
121+
</li>
122+
<li class="toctree-l1">
123+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#the-euler-cromer-method">
124+
The Euler-Cromer method
125+
</a>
126+
</li>
127+
<li class="toctree-l1">
128+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#staggered-mesh">
129+
Staggered mesh
130+
</a>
131+
</li>
132+
<li class="toctree-l1">
133+
<a class="reference internal" href="notebooks/vib/vib_undamped.html#exercises-and-problems">
134+
Exercises and Problems
135+
</a>
136+
</li>
137+
</ul>
86138
<p class="caption">
87139
<span class="caption-text">
88140
Wave equations
@@ -99,6 +151,16 @@ <h1 class="site-logo" id="site-title">The Devito Book</h1>
99151
Verification
100152
</a>
101153
</li>
154+
<li class="toctree-l1">
155+
<a class="reference internal" href="notebooks/wave/wave1D_prog.html">
156+
Implementation
157+
</a>
158+
</li>
159+
<li class="toctree-l1">
160+
<a class="reference internal" href="notebooks/wave/wave1D_prog.html#exercises">
161+
Exercises
162+
</a>
163+
</li>
102164
</ul>
103165

104166
</nav>

fdm-jupyter-book/_build/html/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fdm-jupyter-book/_toc.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
- file: index.md
22
numbered: true
33

4+
- chapter: Vibration ODEs
5+
sections:
6+
- file: notebooks/vib/vib_undamped.ipynb
7+
48
- chapter: Wave equations
59
sections:
610
- file: notebooks/wave/wave1D_fd1.ipynb
11+
- file: notebooks/wave/wave1D_prog.ipynb
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#import matplotlib.pyplot as plt
2+
import scitools.std as plt
3+
import odespy
4+
import numpy as np
5+
6+
def solver(alpha, ic, T, dt=0.05):
7+
def f(u, t):
8+
x_A, vx_A, y_A, vy_A, x_B, vx_B, y_B, vy_B = u
9+
distance3 = np.sqrt((x_B-x_A)**2 + (y_B-y_A)**2)**3
10+
system = [
11+
vx_A,
12+
1/(1.0 + alpha)*(x_B - x_A)/distance3,
13+
vy_A,
14+
1/(1.0 + alpha)*(y_B - y_A)/distance3,
15+
vx_B,
16+
-1/(1.0 + alpha**(-1))*(x_B - x_A)/distance3,
17+
vy_B,
18+
-1/(1.0 + alpha**(-1))*(y_B - y_A)/distance3,
19+
]
20+
return system
21+
22+
Nt = int(round(T/dt))
23+
t_mesh = np.linspace(0, Nt*dt, Nt+1)
24+
25+
solver = odespy.RK4(f)
26+
solver.set_initial_condition(ic)
27+
u, t = solver.solve(t_mesh)
28+
x_A = u[:,0]
29+
x_B = u[:,2]
30+
y_A = u[:,4]
31+
y_B = u[:,6]
32+
return x_A, x_B, y_A, y_B, t
33+
34+
def demo_circular():
35+
# Mass B is at rest at the origin,
36+
# mass A is at (1, 0) with vel. (0, 1)
37+
ic = [1, 0, 0, 1, 0, 0, 0, 0]
38+
x_A, x_B, y_A, y_B, t = solver(
39+
alpha=0.001, ic=ic, T=2*np.pi, dt=0.01)
40+
plt.plot(x_A, x_B, 'r2-', y_A, y_B, 'b2-',
41+
legend=['A', 'B'],
42+
daspectmode='equal') # x and y axis have same scaling
43+
plt.savefig('tmp_circular.png')
44+
plt.savefig('tmp_circular.pdf')
45+
plt.show()
46+
47+
def demo_two_stars(animate=True):
48+
# Initial condition
49+
ic = [0.6, 0, 0, 1, # star A: velocity (0,1)
50+
0, 0, 0, -0.5] # star B: velocity (0,-0.5)
51+
# Solve ODEs
52+
x_A, x_B, y_A, y_B, t = solver(
53+
alpha=0.5, ic=ic, T=4*np.pi, dt=0.05)
54+
if animate:
55+
# Animate motion and draw the objects' paths in time
56+
for i in range(len(x_A)):
57+
plt.plot(x_A[:i+1], x_B[:i+1], 'r-',
58+
y_A[:i+1], y_B[:i+1], 'b-',
59+
[x_A[0], x_A[i]], [x_B[0], x_B[i]], 'r2o',
60+
[y_A[0], y_A[i]], [y_B[0], y_B[i]], 'b4o',
61+
daspectmode='equal', # axes aspect
62+
legend=['A', 'B', 'A', 'B'],
63+
axis=[-1, 1, -1, 1],
64+
savefig='tmp_%04d.png' % i,
65+
title='t=%.2f' % t[i])
66+
else:
67+
# Make a simple static plot of the solution
68+
plt.plot(x_A, x_B, 'r-', y_A, y_B, 'b-',
69+
daspectmode='equal', legend=['A', 'B'],
70+
axis=[-1, 1, -1, 1], savefig='tmp_two_stars.png')
71+
#plt.axes().set_aspect('equal') # mpl
72+
plt.show()
73+
74+
if __name__ == '__main__':
75+
import sys
76+
if sys.argv[1] == 'circular':
77+
demo_circular()
78+
else:
79+
demo_two_stars(True)
80+
raw_input()

0 commit comments

Comments
 (0)