-
Notifications
You must be signed in to change notification settings - Fork 82
Adding interpol.jl, hyperbolic1D.jl and edit on Operators.jl #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jlbaranda
wants to merge
18
commits into
csrc-sdsu:main
Choose a base branch
from
jlbaranda:interpolator_branch2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4450bed
Adding interpol.jl, hyperbolic1D.jl and edit on Operators.jl
jlbaranda 5fd73e6
Completed hyperbolic1D and work in progress on burgers1D
jlbaranda 004906f
modified changes on interpol.jl
jlbaranda 4812961
removed comments print tstatements from burgers1D.jl
jlbaranda 01f115b
Added tests for interpol operator
jlbaranda 76d4407
adding interpol test
jlbaranda 102275d
Created function method for burgers, and added png and animation
jlbaranda d639c66
png and gif of Burgers1D
jlbaranda e8b0c82
Moved files to a new folder
jlbaranda 0a05951
Updated hyperbolic1D.jl file
jlbaranda 469afa0
outputs of hyperbolic1D.jl
jlbaranda d97784b
Hyperbolic Problems index.md
jlbaranda b6d0a8e
Documentation of 1D Hyperbolic problems Hyperbolic1D.md, Burgers1D.md…
jlbaranda d096d5d
Modified index.md in examples file to include hyperbolic problems
jlbaranda b345f3a
Added Hyperbolic Problems to src/index.md to include Burgers1D and Hy…
jlbaranda da39253
Modified index.md to include interpol operator
jlbaranda f9514bc
Removed output foler
jlbaranda 267c13f
Changed how documenation of interpol.jl is written to work on docs file
jlbaranda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
julia/MOLE.jl/docs/src/examples/Hyperbolic/1D/Burgers1D.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Burgers 1D | ||
|
|
||
| Solves the conservative form of the inviscid Burger's Equation in 1D. | ||
|
|
||
| ```math | ||
| \frac{\partial }{\partial t} U + \frac{\partial}{\partial x} \left(\frac{U^{2}}{2}\right)=0 | ||
| ``` | ||
|
|
||
| with $U = u(x,t)$ defined on the domain $x \in [-15,15]$, from time $t \in [0,10]$ and initial condition | ||
|
|
||
| ```math | ||
| u(x, 0) = e^{\frac{-x^{2}}{50}} | ||
| ``` | ||
|
|
||
| The wave is allowed to propagate across the domain while the area under the curve is calculated. | ||
|
|
||
|
|
||
| --- | ||
| This example is implemented in [`burgers1D.jl`](https://github.com/csrc-sdsu/mole/blob/main/julia/MOLE/jl/examples/hyperbolic/burgers1D.jl) |
36 changes: 36 additions & 0 deletions
36
julia/MOLE.jl/docs/src/examples/Hyperbolic/1D/Hyperbolic1D.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Hyperbolic 1D | ||
|
|
||
| Solves the 1D advection equation with periodic boundary conditions. | ||
|
|
||
| ```math | ||
| \frac{\partial }{\partial t} U + a \frac{\partial }{\partial x} U = 0 | ||
| ``` | ||
|
|
||
| where $U = u(x,t)$ and $a = 1$ is the advection velocity. The domain $x \in [0,1]$ and $t \in [0,1]$ with initial condition | ||
|
|
||
| ```math | ||
| u(x, 0) = \sin(2\pi x) | ||
| ``` | ||
|
|
||
| Periodic boundary conditions are used | ||
|
|
||
| ```math | ||
| u(0, t) = u(1, t) | ||
| ``` | ||
|
|
||
| Using finite differences for the time derivative | ||
|
|
||
| ```math | ||
| \frac{\partial U}{\partial t} = \frac{U^{n+1}_{i}-U^{n}_{i}}{\delta t} | ||
| ``` | ||
|
|
||
| where $U_{i}^{n}$ is $u(x_{i},t_{n})$ and the mimetic operator $\mathbf{D}$ for the space derivative. | ||
|
|
||
| ```math | ||
| \frac{U^{n+1}_{i}-U^{n}_{i}}{\delta t} + a \mathbf{D}U_{i}^{n} = 0\\ | ||
| \frac{U^{n+1}_{i}-U^{n}_{i}}{\delta t} = - a \mathbf{D}U_{i}^{n}\\ | ||
| U^{n+1}_{i} = U^{n}_{i} - a \delta t \mathbf{D} U_{i}^{n}\\ | ||
| ``` | ||
|
|
||
| --- | ||
| This example is implemented in [`hyperbolic1D.jl`](https://github.com/csrc-sdsu/mole/blob/main/julia/MOLE.jl/examples/hyperbolic/hyperbolic1D.jl) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # 1D Hyperbolic Problems | ||
|
|
||
| These examples demonstrate the solution of hyperbolic equations in one dimension. | ||
|
|
||
| ```@contents | ||
| :maxdepth: 1 | ||
|
|
||
| Hyperbolic1D | ||
| Burgers1D | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Hyperbolic Problems | ||
|
|
||
| Hyperbolic partial differential equations model wave propagation and transport phenomena where information travels along characteristic curves. Examples include the wave equation, transport equation, and conservation laws such as Burgers' equation. | ||
|
|
||
| ```@content | ||
| :maxdepth: 2 | ||
| :caption: Contents | ||
|
|
||
| 1D/index | ||
| ``` | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| #= | ||
| Solve the 1D Inviscid Burgers' equation | ||
| Upwind Scheme is used and the equation is written in conservative form. | ||
| Initial condition: exp(-x^2/50) | ||
| =# | ||
|
|
||
| using Plots | ||
| import MOLE: Operators, BCs | ||
|
|
||
|
|
||
| function upwind_burgers(u0, xgrid, T, k, m, dx) | ||
| #Solves Burgers equation using MOLE Operators | ||
| #= | ||
| INPUTS: | ||
| u0 : Initial condition | ||
| xgrid : staggered grid | ||
| T : final time | ||
| k : Operator order of accuarcy | ||
| m : number of cells | ||
| OUTPUTS: | ||
| U : solution | ||
| t : time interval | ||
| =# | ||
| #CFL Condition for explicit schemes | ||
| dt = dx; | ||
|
|
||
| #Create stepsize for time with given T | ||
| t = collect(0.0:dt:T) | ||
|
|
||
| #Use of MOLE Operators | ||
| D = Operators.div(k, m, dx) | ||
| I = Operators.interpol(m, 1.0) | ||
|
|
||
| #Premultiply out of time loop (does not change) | ||
| D = -dt/2*D*I | ||
|
|
||
| #Create an array that holds solution at each time step | ||
| U = zeros(length(t)+1,length(xgrid)) | ||
|
|
||
| #Set initial condition at first time element | ||
| U[1,:] .= u0.(xgrid) | ||
|
|
||
| for k in eachindex(t) | ||
| U[k+1,:] .= U[k,:] + D * U[k,:].^2; | ||
| end | ||
|
|
||
| return t, U | ||
|
|
||
| end | ||
|
|
||
| ### MAIN LOOP ### | ||
|
|
||
| #Domain limits | ||
| west = -15; | ||
| east = 15; | ||
|
|
||
| #number of cells | ||
| m = 300; | ||
|
|
||
| #stepsize | ||
| dx = (east - west)/m; | ||
|
|
||
| #Simulation time | ||
| T = 13 | ||
|
|
||
| #Operator's order of accuracy | ||
| k = 2; | ||
|
|
||
| # 1D Staggered grid | ||
| xgrid = [west; (west + (dx/2)):dx: (east - (dx/2)); east]; | ||
|
|
||
| # Initial Condition | ||
| u0(x) = exp.(-(x.^2)/50); | ||
|
|
||
| t, U = upwind_burgers(u0, xgrid, T, k, m, dx) | ||
|
|
||
| path = joinpath(@__DIR__, "output") # Output path to store generated plots | ||
| mkpath(path) | ||
|
|
||
|
|
||
| animation = Plots.@animate for k in eachindex(t) | ||
| Plots.plot(xgrid, U[k,:]; | ||
| label = "approximated", | ||
| xlabel = "x", | ||
| ylabel = "u(x,t)", | ||
| grid = true, | ||
| title = "1D Inviscid Burgers' Equation t = $(round(t[k]; digits=3))", | ||
| legend = :topleft | ||
| ) | ||
| end | ||
|
|
||
|
|
||
| Plots.gif(animation, joinpath(path,"burgers1D.gif"), fps=10) | ||
|
|
||
| Plots.png( | ||
| Plots.plot(xgrid, U[end,:]; | ||
| label = "approximated", | ||
| xlabel = "x", | ||
| ylabel = "u(x,t)", | ||
| grid = true, | ||
| title = "1D Inviscid Burgers' Equation t = $(round(t[end]; digits=3))", | ||
| legend = :topleft | ||
| ), | ||
| joinpath(path,"burgers_end.png"), | ||
| ) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| #= | ||
| Julia implementation of the 1D Advection equation with periodic boundary conditions | ||
| from MATLAB MOLE example using the Leapfrog Scheme | ||
| =# | ||
|
|
||
| using Plots | ||
| import MOLE: Operators, BCs | ||
|
|
||
| function advection_hyperbolic(u0, a, grid, T, k, m, dx) | ||
| #Solves the 1D Advection equation using MOLE Operators | ||
| #= | ||
| INPUTS: | ||
| u0 : Initial condition | ||
| a : velocity | ||
| grid : staggered grid | ||
| T : final time | ||
| k : Operator order of accuracy | ||
| m : number of cells | ||
| OUTPUTS: | ||
| U : solution | ||
| t : time interval | ||
| =# | ||
| #CFL condition for explicit schemes | ||
| dt = dx/abs(a); | ||
|
|
||
| #Create stepsize for time with given T | ||
| t = collect(0.0:dt:T) | ||
|
|
||
| #Use of MOLE Operators | ||
| D = Operators.div(k,m,dx); | ||
| I = Operators.interpol(m,0.5); | ||
|
|
||
| #Periodic Boundary Conditions imposed on Divergence Operator | ||
| D[1, 2] = 1/(2*dx); | ||
| D[1, end-1] = -1/(2*dx); | ||
| D[end, 2] = 1/(2*dx); | ||
| D[end, end-1] = -1/(2*dx); | ||
|
|
||
| #Premultiply out of time loop (does not change) | ||
| D = -a*dt*2 *D*I; | ||
|
|
||
| #Create an array that holds solution at each time step | ||
| U = zeros(length(t)+2, length(grid)) | ||
|
|
||
| #Set initial condition at first time element | ||
| U[1,:] .= u0.(grid) | ||
|
|
||
| #Leapfrog scheme requires two steps, hence we would use Euler's step | ||
| U[2,:] .= U[1,:] + D/2*U[1,:]; | ||
|
|
||
| for k in eachindex(t) | ||
| U[k+2,:] .= U[k,:] + D * U[k+1,:]; | ||
| end | ||
|
|
||
| return t, U | ||
| end | ||
|
|
||
| ### MAIN LOOP ### | ||
|
|
||
| #Domain limits | ||
| west = 0; | ||
| east = 1; | ||
|
|
||
| #velocity | ||
| a = 1; | ||
|
|
||
| #number of cells | ||
| m = 50; | ||
|
|
||
| #stepsize | ||
| dx = (east - west) / m; | ||
|
|
||
| #Simulation time | ||
| T = 1; | ||
|
|
||
| #Operator's order of accuracy | ||
| k = 2; | ||
|
|
||
| #1D Staggered grid | ||
| xgrid = [west; (west + (dx/2)):dx: (east - (dx/2)); east]; | ||
|
|
||
| #Initial Condition | ||
| u0(x) = sin.(2 * π * x); | ||
|
|
||
| t, U = advection_hyperbolic(u0, a, xgrid, T, k, m, dx) | ||
|
|
||
| #Output path to store generated plot | ||
| path = joinpath(@__DIR__, "output") | ||
|
|
||
| #Creation of animation | ||
| animation = Plots.@animate for k in eachindex(t) | ||
| Plots.plot(xgrid, U[k,:]; | ||
| label = "approximated", | ||
| xlabel = "x", | ||
| ylabel = "u(x,t)", | ||
| grid = true, | ||
| ls = :dot, | ||
| lw = 3, | ||
| title = "1D Advection Equation with Periodic BC t = $(round(t[k], sigdigits=2))", | ||
| legend = :bottomright, | ||
| xlims = (west, east), | ||
| ylims = (-1.5, 1.5) | ||
| ) | ||
| Plots.plot!(xgrid, sin.(2*π .*(xgrid .- a*t[k])); | ||
| label = "exact", | ||
| ) | ||
| end | ||
|
|
||
| #Storing animation as gif to output directory | ||
| Plots.gif(animation, joinpath(path, "hyperbolic1D.gif"), fps=10) | ||
|
|
||
| #Creating plot object for approximation | ||
| p1 = plot(xgrid, U[end-2,:]; #Due to length of t and U being off by 2 | ||
| label = "approximated", | ||
| xlabel = "x", | ||
| ylabel = "u(x,t)", | ||
| grid = true, | ||
| ls = :dot, | ||
| lw = 3, | ||
| title = "1D Advection Equation with Periodic BC t = $(round(t[end], sigdigits=2))", | ||
| legend = :bottomright, | ||
| xlims = (west, east), | ||
| ylims = (-1.5, 1.5) | ||
| ) | ||
| #Mutating plot to include exact solution | ||
| plot!(xgrid, sin.(2*π .*(xgrid .- a*t[end])); | ||
| label = "exact", | ||
| ) | ||
|
|
||
| #Storing png file of last iteration | ||
| Plots.png( | ||
| p1, | ||
| joinpath(path, "hyperbolic_end.png") | ||
| ) | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.