Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
project and notebooks ready to deploy
  • Loading branch information
rcc02007 committed Jan 14, 2020
1 parent d2bb68d commit 054ae6d
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 27 deletions.
69 changes: 69 additions & 0 deletions README.html
@@ -0,0 +1,69 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>README</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
</style>
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js" type="text/javascript"></script>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<h1 id="computational-mechanics-01---getting-started">Computational Mechanics 01 - Getting Started</h1>
<h2 id="working-with-python-and-numerical-methods">Working with Python and Numerical Methods</h2>
<p>Welcome to Computational Mechanics Module #1 - Getting Started!</p>
<p>There are three modules and one final project. The modules will get us started on our exploration of computational mechanics using Python, listed below each module are the learning objectives.</p>
<ol type="1">
<li><a href="./notebooks/01_Interacting_with_Python.ipynb">01_Interacting_with_Python</a></li>
</ol>
<ul>
<li>Using the <code>print()</code> function. The concept of <em>function</em>.</li>
<li>Using Python as a calculator.</li>
<li>Concepts of variable, type, assignment.</li>
<li>Special variables: <code>True</code>, <code>False</code>, <code>None</code>.</li>
<li>Supported operations, logical operations.</li>
<li>Reading error messages.</li>
</ul>
<ol start="2" type="1">
<li><a href="./notebooks/02_Working_with_Python.ipynb">02_Working_with_Python</a></li>
</ol>
<ul>
<li>Good coding habits and file naming</li>
<li>How to define a function and return outputs</li>
<li>How to import libraries</li>
<li>Multidimensional arrays using NumPy</li>
<li>Accessing values and slicing in NumPy arrays</li>
<li><code>%%time</code> magic to time cell execution.</li>
<li>Performance comparison: lists vs NumPy arrays</li>
<li>Basic plotting with <code>pyplot</code>.</li>
</ul>
<ol start="3" type="1">
<li><a href="./notebooks/03-Numerical_error.ipynb">03-Numerical_error</a></li>
</ol>
<ul>
<li>Numerical integration with the Euler approximation</li>
<li>The source of truncation errors</li>
<li>The source of roundoff errors</li>
<li>How to time a numerical solution or a function</li>
<li>How to compare solutions</li>
<li>The definition of absolute error and relative error</li>
<li>How a numerical solution converges</li>
</ul>
<h2 id="computational-mechanics-project-01---heat-transfer-in-forensic-science"><a href="./project/01_Getting-started-project.ipynb">Computational Mechanics Project #01 - Heat Transfer in Forensic Science</a></h2>
<p>We can use our current skillset for a macabre application. We can predict the time of death based upon the current temperature and change in temperature of a corpse.</p>
<p>Forensic scientists use Newton’s law of cooling to determine the time elapsed since the loss of life,</p>
<p><span class="math inline">\(\frac{dT}{dt} = -K(T-T_a)\)</span>,</p>
<p>where <span class="math inline">\(T\)</span> is the current temperature, <span class="math inline">\(T_a\)</span> is the ambient temperature, <span class="math inline">\(t\)</span> is the elapsed time in hours, and <span class="math inline">\(K\)</span> is an empirical constant.</p>
<p>Suppose the temperature of the corpse is 85<span class="math inline">\(^o\)</span>F at 11:00 am. Then, 2 hours later the temperature is 74<span class="math inline">\(^{o}\)</span>F.</p>
<p>Assume ambient temperature is a constant 65<span class="math inline">\(^{o}\)</span>F.</p>
</body>
</html>
21 changes: 20 additions & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@

Welcome to Computational Mechanics Module #1 - Getting Started!

There are three modules to get us started on our exploration of computational
There are three modules and one final project. The modules will get us started on our exploration of computational
mechanics using Python, listed below each module are the learning objectives.

1. [01_Interacting_with_Python](./notebooks/01_Interacting_with_Python.ipynb)
Expand Down Expand Up @@ -33,3 +33,22 @@ mechanics using Python, listed below each module are the learning objectives.
* The definition of absolute error and relative error
* How a numerical solution converges

## [Computational Mechanics Project #01 - Heat Transfer in Forensic Science](./project/01_Getting-started-project.ipynb)

We can use our current skillset for a macabre application. We can predict the
time of death based upon the current temperature and change in temperature of a
corpse.

Forensic scientists use Newton's law of cooling to determine the time elapsed
since the loss of life,

$\frac{dT}{dt} = -K(T-T_a)$,

where $T$ is the current temperature, $T_a$ is the ambient temperature, $t$ is
the elapsed time in hours, and $K$ is an empirical constant.

Suppose the temperature of the corpse is 85$^o$F at 11:00 am. Then, 2 hours
later the temperature is 74$^{o}$F.

Assume ambient temperature is a constant 65$^{o}$F.

52 changes: 37 additions & 15 deletions notebooks/.ipynb_checkpoints/03-Numerical_error-checkpoint.ipynb
@@ -1,5 +1,12 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"###### Content modified under Creative Commons Attribution license CC-BY 4.0, code under BSD 3-Clause License © 2020 R.C. Cooper"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand All @@ -8,8 +15,8 @@
}
},
"source": [
"# Freefall Model\n",
"## Computational solution\n",
"# Numerical Error\n",
"## Freefall Model Computational solution\n",
"\n",
"<img src=\"../images/freefall.png\" style=\"width: 200px;\"/> \n",
"\n",
Expand Down Expand Up @@ -383,7 +390,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note:** In the above plot, the numerical solution is given discrete points connected by lines, while the analytical solution is drawn as a line. A helpful convention is to plot discrete data such as numerical solutions or measured data as points and lines while analytical solutions are drawn as lines. \n",
"**Note:** In the above plot, the numerical solution is given at discrete points connected by lines, while the analytical solution is drawn as a line. This is a helpful convention. We plot discrete data such as numerical solutions or measured data as points and lines while analytical solutions are drawn as lines. \n",
"\n",
"## Exercise\n",
"\n",
Expand Down Expand Up @@ -708,7 +715,9 @@
"\n",
"In the following example, we judge the **convergence** of our solution with the new knowledge of truncation error and roundoff error. \n",
"\n",
"**Convergence is the trend that our solution progressively moves to a final *true* solution as we increase the fidelity of the model** ???\n",
"**The definition for convergence in mathematics is the limit of a sequence exists.** \n",
"\n",
"In the case of the Euler approximation, the sequence is smaller timesteps, $\\Delta t$, should converge to the analytical solution. \n",
"\n",
"Define time from 0 to 12 seconds with `N` timesteps \n",
"function defined as `freefall`\n",
Expand Down Expand Up @@ -1026,32 +1035,38 @@
" c. Use a growth rate of $k_g=0.013$ [1/years] and compare the analytical solution (use initial condition p(1900) = 1578000000) to the Euler integration for time steps of 20 years from 1900 to 2020 (Hint: use method (1)- plot the two solutions together with the given data) \n",
" \n",
" d. Discussion question: If you decrease the time steps further and the solution converges, will it converge to the actual world population? Why or why not? \n",
"\n"
"\n",
"**Note: We have used a new function `np.loadtxt` here. Use the `help` or `?` to learn about what this function does and how the arguments can change the output. In the next module, we will go into more details on how to load data, plot data, and present trends.**"
]
},
{
"cell_type": "code",
"execution_count": 301,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" year population\n",
"0 1900 1578000000\n",
"1 1950 2526000000\n",
"2 2000 6127000000\n",
"3 2020 7795482000\n"
"years= [1900. 1950. 2000. 2020.]\n",
"population = [1.578000e+09 2.526000e+09 6.127000e+09 7.795482e+09]\n"
]
}
],
"source": [
"import pandas as pd\n",
"data = pd.read_csv('../data/world_population_1900-2020.csv')\n",
"print(data)"
"import numpy as np\n",
"year,pop=np.loadtxt('../data/world_population_1900-2020.csv',skiprows=1,delimiter=',',unpack=True)\n",
"print('years=',year)\n",
"print('population =', pop)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -1071,7 +1086,7 @@
},
{
"cell_type": "code",
"execution_count": 273,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1090,6 +1105,13 @@
" return ex\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
21 changes: 10 additions & 11 deletions notebooks/03-Numerical_error.ipynb
Expand Up @@ -390,7 +390,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Note:** In the above plot, the numerical solution is given discrete points connected by lines, while the analytical solution is drawn as a line. A helpful convention is to plot discrete data such as numerical solutions or measured data as points and lines while analytical solutions are drawn as lines. \n",
"**Note:** In the above plot, the numerical solution is given at discrete points connected by lines, while the analytical solution is drawn as a line. This is a helpful convention. We plot discrete data such as numerical solutions or measured data as points and lines while analytical solutions are drawn as lines. \n",
"\n",
"## Exercise\n",
"\n",
Expand Down Expand Up @@ -1035,30 +1035,29 @@
" c. Use a growth rate of $k_g=0.013$ [1/years] and compare the analytical solution (use initial condition p(1900) = 1578000000) to the Euler integration for time steps of 20 years from 1900 to 2020 (Hint: use method (1)- plot the two solutions together with the given data) \n",
" \n",
" d. Discussion question: If you decrease the time steps further and the solution converges, will it converge to the actual world population? Why or why not? \n",
"\n"
"\n",
"**Note: We have used a new function `np.loadtxt` here. Use the `help` or `?` to learn about what this function does and how the arguments can change the output. In the next module, we will go into more details on how to load data, plot data, and present trends.**"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" year population\n",
"0 1900 1578000000\n",
"1 1950 2526000000\n",
"2 2000 6127000000\n",
"3 2020 7795482000\n"
"years= [1900. 1950. 2000. 2020.]\n",
"population = [1.578000e+09 2.526000e+09 6.127000e+09 7.795482e+09]\n"
]
}
],
"source": [
"import pandas as pd\n",
"data = pd.read_csv('../data/world_population_1900-2020.csv')\n",
"print(data)"
"import numpy as np\n",
"year,pop=np.loadtxt('../data/world_population_1900-2020.csv',skiprows=1,delimiter=',',unpack=True)\n",
"print('years=',year)\n",
"print('population =', pop)"
]
},
{
Expand Down

0 comments on commit 054ae6d

Please sign in to comment.