This repository has been archived by the owner on Jul 19, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 74
MOLFiniteDifference : Adding support for higher derivative orders in bcs #435
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
acd83f3
supporting higher derivative orders in bcs
mjsheikh a302e40
supporting higher order derivatives in BCs
mjsheikh 0a8837b
fix no. of unique differentials
mjsheikh ed55832
tests added
mjsheikh f9dbbff
added symbolic test for KdV
mjsheikh 888a36a
added symbolic test for KdV
mjsheikh e00fee9
tests added
mjsheikh 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 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 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 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 |
---|---|---|
|
@@ -59,6 +59,37 @@ using ModelingToolkit: Differential | |
@test all(isapprox.(u_approx, exact, atol=0.01)) | ||
end | ||
end | ||
|
||
@parameters t x | ||
|
||
# BCs with 2nd order Neumann | ||
bcs = [u(0,x) ~ cos(x), | ||
Dxx(u(t,0)) ~ -exp(-t), | ||
Dxx(u(t,Float64(π))) ~ exp(-t)] | ||
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. You can't specify a 2nd order BC on a 2nd order system. See #382 (comment) 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. Yes, this was just to show that desired operation gets carried out safely and in correct manner. |
||
|
||
pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)]) | ||
|
||
for disc in [discretization, discretization_edge, discretization_centered, discretization_centered_order4] | ||
# Convert the PDE problem into an ODE problem | ||
prob = discretize(pdesys,disc) | ||
|
||
# Solve ODE problem | ||
sol = solve(prob,Tsit5(),saveat=0.1) | ||
|
||
if disc.grid_align == center_align | ||
x = dx[2:end-1] | ||
else | ||
x = (dx[1:end-1]+dx[2:end])/2 | ||
end | ||
t = sol.t | ||
|
||
# Test against exact solution | ||
for i in 1:length(sol) | ||
exact = u_exact(x, t[i]) | ||
u_approx = sol.u[i] | ||
@test all(isapprox.(u_approx, exact, atol=0.01)) | ||
end | ||
end | ||
end | ||
|
||
|
||
|
@@ -496,7 +527,7 @@ end | |
end | ||
end | ||
|
||
@testset "Test 10: linear diffusion, two variables, mixed BCs" begin | ||
@testset "Test 10: linear diffusion, two variables, mixed & higher order BCs" begin | ||
# Method of Manufactured Solutions | ||
u_exact = (x,t) -> exp.(-t) * cos.(x) | ||
v_exact = (x,t) -> exp.(-t) * sin.(x) | ||
|
@@ -507,6 +538,7 @@ end | |
Dt = Differential(t) | ||
Dx = Differential(x) | ||
Dxx = Dx^2 | ||
Dxxx = Dx^3 | ||
|
||
# 1D PDE and boundary conditions | ||
eqs = [Dt(u(t,x)) ~ Dxx(u(t,x)), | ||
|
@@ -545,6 +577,33 @@ end | |
@test all(isapprox.(u_exact(x_sol, t_sol[i]), sol.u[i][1:l-2], atol=0.01)) | ||
@test all(isapprox.(v_exact(x_sol, t_sol[i]), sol.u[i][l-1:end], atol=0.01)) | ||
end | ||
|
||
@parameters t x | ||
|
||
# BCs with 3rd order Neumann | ||
bcs = [u(0,x) ~ cos(x), | ||
v(0,x) ~ sin(x), | ||
u(t,0) ~ exp(-t), | ||
Dxxx(u(t,1)) ~ exp(-t) * sin(1), | ||
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. BC order should be <= 1 |
||
Dxxx(v(t,0)) ~ -exp(-t), | ||
v(t,1) ~ exp(-t) * sin(1)] | ||
|
||
pdesys = PDESystem(eqs,bcs,domains,[t,x],[u(t,x),v(t,x)]) | ||
|
||
prob = discretize(pdesys,discretization) | ||
|
||
# Solve ODE problem | ||
sol = solve(prob,Tsit5(),saveat=0.1) | ||
|
||
x_sol = dx[2:end-1] | ||
t_sol = sol.t | ||
|
||
# Test against exact solution | ||
for i in 1:length(sol) | ||
@test all(isapprox.(u_exact(x_sol, t_sol[i]), sol.u[i][1:l-2], atol=0.01)) | ||
@test all(isapprox.(v_exact(x_sol, t_sol[i]), sol.u[i][l-1:end], atol=0.01)) | ||
end | ||
|
||
end | ||
|
||
@testset "Test 11: linear diffusion, two variables, mixed BCs, with parameters" begin | ||
|
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.
can remove these two comments imo
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.
Yeah, so the support is for higher ordered Neumann in 1D systems.
Perhaps a test should be added in :
https://github.com/SciML/DiffEqOperators.jl/blob/master/test/MOL/MOL_1D_HigherOrder.jl ?
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 think that is still a TODO