Cleanup the Cannon Readme's and Sim Tweaks of Clarity (#659)

* Delete a bunch of old png's.

* Make g (acceleration of gravity at sea-level) a parameter rather to make doc cleaner.

* Update Cannon READMEs to be more informative.
This commit is contained in:
jmpenn 2018-08-17 17:07:06 -05:00 committed by GitHub
parent 7b694931ef
commit 8c97db25f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 70 additions and 54 deletions

View File

@ -1,10 +1,13 @@
# SIM\_cannon\_analytic
---
This is first of eight Trick-based simulations that one builds in the Trick
Tutorial (Section 3). It's purpose is to introduce some of the fundamentals
Tutorial (Section 4). It's purpose is to introduce some of the fundamentals
of building a Trick simulation.
Here we simulate the flight of a cannon ball. We want to know the position and velocity of the cannon ball over time, given an initial position, and
Here we simulate the flight of a cannon ball. We want to know the position and
velocity of the cannon ball over time, given an initial position, and
velocity, and subject to the following assumptions and limitations:
* The **only** force acting on the cannon ball is gravity.
@ -14,45 +17,42 @@ velocity, and subject to the following assumptions and limitations:
![](images/CannonInit.png)
### Solution
## Parameterization
The following parameters are given default values in a "default_data" job called
**cannon\_default\_data**. Their values can be changed in the **input.py** file.
This problem has a closed-form solution, so that's what is used.
| Name | Sim Variable | Type | Units | Symbol | default |
|------------------|------------------------|-----------|---------|:---------------------------------:|---------|
| Barrel Angle | dyn.cannon.init\_angle | double | radians | ![theta](images/param_theta.png) | 30*(π/180) |
| Speed | dyn.cannon.init\_speed | double | m/s | ![speed](images/param_s.png) | 50.0 |
| Gravity | dyn.cannon.g | double | m/s | ![g](images/param_g.png) | 9.81 |
| Initial Position | dyn.cannon.pos0 | double[2] | m | ![x_0](images/init_position.png) | ![](images/zero_vector.png) |
## Initialization
The initial velocity is calculated in an "initialization" job.
| Name | Sim Variable | Type | Units | Calculation |
|------------------|:----------------|-----------|-------|-------------------------------|
| Initial Velocity | dyn.cannon.vel0 | double[2] | m/s | ![](images/init_velocity.png) |
## State Propagation
For each time-step, the following are calculated in a "scheduled" job. Though acceleration is
constant in this simulation, it usually isn't for "F=ma" type simulations.
| Name | Sim Variable | Type | Units | Calculation |
|------------------|:---------------|-----------|-----------|----------------------------------|
| Acceleration | dyn.cannon.acc | double[2] | m/s² | ![](images/acceleration.png) |
| Velocity(t) | dyn.cannon.vel | double[2] | m/s | ![](images/velocity_fn_of_t.png) |
| Position(t) | dyn.cannon.pos | double[2] | m | ![](images/position_fn_of_t.png) |
## Calculating When the Ball Impacts the Ground.
The cannon ball will impact the ground, when y-element of the position vector is zero.
| Name | Sim Variable | Type | Units | Calculation |
|------------------|:----------------------|--------|-------|--------------------------------|
| Time of Impact | dyn.cannon.impactTime | double | s | ![](images/time_of_impact.png) |
<!--
Tex: v_{x0}=S\cos\theta
t_{\textrm{impact}} = \frac{ -v_{0_y} - \sqrt{v_{0_y}^2 - 2 g x_{0_y} }}{g}
-->
![](images/init_v_x_0.png)
<!--
Tex: v_{y0}=S\sin\theta
-->
![](images/init_v_y_0.png)
![](images/init_a_x.png)
![](images/init_a_y.png)
![](images/solution_vx.png)
![v_{y}(t) = gt +v_{y0}](images/solution_vy.png)
![](images/solution_x.png)
![](images/solution_y.png)
The cannon ball will impact the ground, when y(t)=0 at:
![](images/time_of_impact.png)
### CANNON Object
Model Variable | Simulation Variable | Type | Units
--------------------------------------------|---------------------|---------|-------
![](images/x_0.png), ![](images/y_0.png) | CANNON.pos0[2] |double[2]| m
![](images/v_x_0.png), ![](images/v_y_0.png)| CANNON.vel0[2] |double[2]| m/s
![\theta](images/param_theta.png) | CANNON.init\_angle |double | r
![speed](images/param_s.png) | CANNON.init\_speed |double | m/s
![\vec{x}](images/vector_x.png) | CANNON.pos[2] |double[2]| m
![\vec{v}](images/vector_v.png) | CANNON.vel[2] |double[2]| m/s

Binary file not shown.

After

Width:  |  Height:  |  Size: 796 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 824 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 712 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 912 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 873 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 464 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 409 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

View File

@ -1,15 +1,31 @@
# SIM\_cannon\_integ
# SIM\_cannon\_numeric
---
This is the second in a series example cannon ball simulations that one builds in the Trick Tutorial (Sections 9, 10). It's purpose is to introduce Trick supported numerical methods.
Rather than using the analytic solutions of SIM\_cannon\_analytic, this simulation uses Trick's numerical integration, and root-finding methods to:
* Determine the cannon ball state (velocity, position) at each time step, and
* Determine when and where the cannon ball impacts the ground.
The simulation is otherwise the same as SIM\_cannon\_analytic.
![CannonPicture](images/CannonInit.png)
### The Simulation
## Parameterization
Same as in SIM\_cannon\_analytic.
This is a simulation of a cannon shooting a cannonball. Given the initial position of the cannon ball, the muzzle velocity (speed) of the cannon ball, and the elevation angle of the cannon barrel the simulation computes the cannon ball's trajectory and time of impact with the ground.
The acceleration of gravity is assumed to be -9.81 m/s<sup>2</sup>.
## Initialization
Same as in SIM\_cannon\_analytic.
## State Propagation
This Trick simulation calculates the cannonball state by numerical integration.
Acceleration is calculated in the "derivative" job **cannon\_deriv**. It is then
used in "integration" job **cannon\_integ** to calculate the cannonball's velocity and
position, using the Trick **integrate** function.
## When and Where the Ball Impacts the Ground
The time and position of impact is determined by the "dynamic\_event" event job
**cannon\_impact**, using the Trick **regula_falsi** function.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

@ -14,6 +14,7 @@ typedef struct {
double pos0[2] ; /* *i m Init position of cannonball */
double init_speed ; /* *i m/s Init barrel speed */
double init_angle ; /* *i rad Angle of cannon */
double g ; /* *i m/s2 acceleration of gravity */
double acc[2] ; /* m/s2 xy-acceleration */
double vel[2] ; /* m/s xy-velocity */

View File

@ -7,14 +7,14 @@ PURPOSE: ( Analytical Cannon )
int cannon_analytic( CANNON* C ) {
C->acc[0] = 0.00;
C->acc[1] = -9.81 ;
C->acc[0] = 0.0;
C->acc[1] = -C->g;
C->vel[0] = C->vel0[0] + C->acc[0] * C->time ;
C->vel[1] = C->vel0[1] + C->acc[1] * C->time ;
C->pos[0] = C->pos0[0] + (C->vel0[0] + (0.5) * C->acc[0] * C->time) * C->time ;
C->pos[1] = C->pos0[1] + (C->vel0[1] + (0.5) * C->acc[1] * C->time) * C->time ;
if (C->pos[1] < 0.0) {
C->impactTime = (- C->vel0[1] - sqrt( C->vel0[1] * C->vel0[1] - 2 * C->pos0[1]))/C->acc[1];
C->impactTime = (C->vel0[1] + sqrt( C->vel0[1] * C->vel0[1] - 2 * C->g * C->pos0[1])) / C->g;
C->pos[0] = C->impactTime * C->vel0[0];
C->pos[1] = 0.0;
C->vel[0] = 0.0;

View File

@ -10,8 +10,7 @@ PURPOSE: (Set the initial data values)
/* default data job */
int cannon_default_data( CANNON* C ) {
C->acc[0] = 0.0;
C->acc[1] = -9.81;
C->g = 9.81;
C->init_angle = M_PI/6 ;
C->init_speed = 50.0 ;
C->pos0[0] = 0.0 ;

View File

@ -9,8 +9,8 @@ PURPOSE: ( Numeric integration for SIM_cannon_numeric )
int cannon_deriv( CANNON* C ) {
if (!C->impact) {
C->acc[0] = 0.00 ;
C->acc[1] = -9.81 ;
C->acc[0] = 0.0;
C->acc[1] = -C->g;
C->timeRate = 1.00;
}
return 0 ;