@@ -7,7 +7,7 @@ In this tutorial we will use the symbolic interface to solve the heat equation.
77### Dirichlet boundary conditions
88
99``` julia
10- using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators
10+ using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators, DomainSets
1111# Method of Manufactured Solutions: exact solution
1212u_exact = (x,t) -> exp .(- t) * cos .(x)
1313
@@ -59,7 +59,7 @@ savefig("plot.png")
5959### Neumann boundary conditions
6060
6161``` julia
62- using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators
62+ using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators, DomainSets
6363# Method of Manufactured Solutions: exact solution
6464u_exact = (x,t) -> exp .(- t) * cos .(x)
6565
@@ -114,7 +114,7 @@ savefig("plot.png")
114114### Robin boundary conditions
115115
116116``` julia
117- using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators
117+ using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators, DomainSets
118118# Method of Manufactured Solutions
119119u_exact = (x,t) -> exp .(- t) * sin .(x)
120120
@@ -204,3 +204,75 @@ anim = @animate for i in 1:length(t)
204204end
205205gif (anim, " plot.gif" ,fps= 30 )
206206```
207+
208+ ### Stationary Problems
209+
210+ ``` julia
211+ using ModelingToolkit,DiffEqOperators,LinearAlgebra,DomainSets
212+ using ModelingToolkit: Differential
213+ using DifferentialEquations
214+
215+ @parameters x
216+ @variables u (.. )
217+ Dxx = Differential (x)^ 2
218+
219+ eq = Dxx (u (x)) ~ 0
220+ dx = 0.1
221+
222+ bcs = [u (0 ) ~ 1 ,
223+ u (1 ) ~ 2 ]
224+
225+ # Space and time domains
226+ domains = [x ∈ Interval (0.0 ,1.0 )]
227+
228+ pdesys = PDESystem ([eq],bcs,domains,[x],[u (x)])
229+
230+ # Note that we pass in `nothing` for the time variable `t` here since we
231+ # are creating a stationary problem without a dependence on time, only space.
232+ discretization = MOLFiniteDifference ([x=> dx], nothing , centered_order= 2 )
233+ prob = discretize (pdesys,discretization)
234+ sol = solve (prob)
235+
236+ using Plots
237+ xs = domains[1 ]. domain. lower: dx: domains[1 ]. domain. upper
238+ plot (xs, sol. u)
239+
240+ ```
241+
242+ ``` julia
243+ using ModelingToolkit,DiffEqOperators,LinearAlgebra,DomainSets
244+ using ModelingToolkit: Differential
245+ using DifferentialEquations
246+
247+ @parameters x y
248+ @variables u (.. )
249+ Dxx = Differential (x)^ 2
250+ Dyy = Differential (y)^ 2
251+
252+ eq = Dxx (u (x, y)) + Dyy (u (x, y))~ 0
253+ dx = 0.1
254+ dy = 0.1
255+
256+ bcs = [u (0 ,y) ~ 0.0 ,
257+ u (1 ,y) ~ y,
258+ u (x,0 ) ~ 0.0 ,
259+ u (x,1 ) ~ x]
260+
261+ # Space and time domains
262+ domains = [x ∈ Interval (0.0 ,1.0 ),
263+ y ∈ Interval (0.0 ,1.0 )]
264+
265+ pdesys = PDESystem ([eq],bcs,domains,[x,y],[u (x,y)])
266+
267+ # Note that we pass in `nothing` for the time variable `t` here since we
268+ # are creating a stationary problem without a dependence on time, only space.
269+ discretization = MOLFiniteDifference ([x=> dx,y=> dy], nothing , centered_order= 2 )
270+
271+ prob = discretize (pdesys,discretization)
272+ sol = solve (prob)
273+
274+ using Plots
275+ xs,ys = [infimum (d. domain): dx: supremum (d. domain) for d in domains]
276+ u_sol = reshape (sol. u, (length (xs),length (ys)))
277+ plot (xs, ys, u_sol, linetype= :contourf ,title = " solution" )
278+ ```
0 commit comments