This repository was archived by the owner on Jul 19, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 71
Add example using parameters #381
Merged
ChrisRackauckas
merged 2 commits into
SciML:master
from
valentinsulzer:issue-380-params
Apr 25, 2021
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -4,6 +4,5 @@ | |
| deps/deps.jl | ||
| Manifest.toml | ||
| *.png | ||
| docs/build | ||
| .vscode | ||
| .DS_store | ||
| *.gif | ||
| docs/build | ||
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 |
|---|---|---|
|
|
@@ -165,3 +165,42 @@ end | |
| display(plt) | ||
| savefig("plot.png") | ||
| ``` | ||
|
|
||
| ### Adding parameters | ||
|
|
||
| We can also build up more complicated systems with multiple dependent variables and parameters as follows | ||
|
|
||
| ```julia | ||
| @parameters t x | ||
| @parameters Dn, Dp | ||
| @variables u(..) v(..) | ||
| Dt = Differential(t) | ||
| Dx = Differential(x) | ||
| Dxx = Differential(x)^2 | ||
|
|
||
| eqs = [Dt(u(t,x)) ~ Dn * Dxx(u(t,x)) + u(t,x)*v(t,x), | ||
| Dt(v(t,x)) ~ Dp * Dxx(v(t,x)) - u(t,x)*v(t,x)] | ||
| bcs = [u(0,x) ~ sin(pi*x/2), | ||
| v(0,x) ~ sin(pi*x/2), | ||
| u(t,0) ~ 0.0, Dx(u(t,1)) ~ 0.0, | ||
| v(t,0) ~ 0.0, Dx(v(t,1)) ~ 0.0] | ||
|
|
||
| domains = [t ∈ IntervalDomain(0.0,1.0), | ||
| x ∈ IntervalDomain(0.0,1.0)] | ||
|
|
||
| pdesys = PDESystem(eqs,bcs,domains,[t,x],[u(t,x),v(t,x)],[Dn=>0.5, Dp=>2]) | ||
| discretization = MOLFiniteDifference([x=>0.1],t) | ||
| prob = discretize(pdesys,discretization) # This gives an ODEProblem since it's time-dependent | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should convert this to a test which right here checks if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the solution record which parameters it used? |
||
| sol = solve(prob,Tsit5()) | ||
|
|
||
| x = (0:0.1:1)[2:end-1] | ||
| t = sol.t | ||
|
|
||
| using Plots | ||
| anim = @animate for i in 1:length(t) | ||
| p1 = plot(x,sol.u[i][1:9],label="u, t=$(t[i])";legend=false,xlabel="x",ylabel="u",ylim=[0,1]) | ||
| p2 = plot(x,sol.u[i][10:end],label="v, t=$(t[i])";legend=false,xlabel="x",ylabel="v",ylim=[0,1]) | ||
| plot(p1,p2) | ||
| end | ||
| gif(anim, "plot.gif",fps=30) | ||
| ``` | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was told in a separate PR that such things (anything not generated by the package itself) should go into my global
.gitignoreinstead of the package's one. I checked and it was me who added these back in November. But I can leave them in if you prefer