Time-independent Usage for MOLFiniteDifference()

Hello,

I am trying to use MOLFiniteDifference() to solve a stationary PDE. In the documentation, it says that the continuous or time variable is optional, but I couldn’t find any examples of someone using it for a steady state problem. I tried to recreate the documentation example without the time parameter, but I got the following error:

MethodError: no method matching DiffEqOperators.MOLFiniteDifference(::Vector{Pair{Symbolics.Num, Float64}}; centered_order=2)

Closest candidates are:

DiffEqOperators.MOLFiniteDifference(::Any, !Matched::Any; upwind_order, centered_order, grid_align) at C:\Users\User\.julia\packages\DiffEqOperators\PH6oI\src\MOLFiniteDifference\MOL_discretization.jl:17

DiffEqOperators.MOLFiniteDifference(::T, !Matched::T2, !Matched::Int64, !Matched::Int64, !Matched::DiffEqOperators.GridAlign) where {T, T2} at C:\Users\User\.julia\packages\DiffEqOperators\PH6oI\src\MOLFiniteDifference\MOL_discretization.jl:9 got unsupported keyword argument "centered_order"

This is the code I used to generate this error

## 2D Diffusion
begin
# Dependencies
using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators, DomainSets

# Variables, parameters, and derivatives
@parameters x y
@variables u(..)
Dxx = Differential(x)^2
Dyy = Differential(y)^2

# Domain edges
x_min = -2.
x_max = 2.
y_min = -2.
y_max = 2.

#Source term
S(x,y) = x^2 + y^2
	
# Discretization parameters
dx = 0.1; dy = 0.2
order = 2

# Equation
eq  = S(x,y) ~ Dxx(u(x, y)) + Dyy(u(x, y))

# Initial and boundary conditions
bcs = [u(x_min, y) ~ 0,
    	u(x_max, y) ~ 0,
        u(x,y_min) ~ 0,
        u(x, y_max) ~ 0]

# Space and time domains
domains = [x ∈ Interval(x_min, x_max),
           y ∈ Interval(y_min, y_max)]

# PDE system
@named pdesys = PDESystem([eq], bcs, domains, [x, y], [u(x, y)])

# Method of lines discretization
discretization = MOLFiniteDifference([x=>dx,y=>dy];centered_order=order)
prob = ModelingToolkit.discretize(pdesys,discretization)

# Solution of the ODE system
sol = solve(prob,Tsit5())
end

Could someone give me an example of how it should be used for a stationary problem?

The docs should be up soonish. For the answer right now though, see MethodOfLines.jl/MOL_NonlinearProblem.jl at master · SciML/MethodOfLines.jl · GitHub . The result of a time-independent problem is a NonlinearProblem to be solved via NonlinearSolve.jl.

That worked. Thanks!

	## 2D Diffusion
begin
	# Dependencies
	using NonlinearSolve, OrdinaryDiffEq, ModelingToolkit, DiffEqOperators, DomainSets
	
	# Variables, parameters, and derivatives
	@parameters x y
	@variables u(..)
	Dxx = Differential(x)^2
	Dyy = Differential(y)^2
	
	# Domain edges
	x_min = -2.
	x_max = 2.
	y_min = -2.
	y_max = 2.
	
	#Source term
	S(x,y) = x^2 + y^2
		
	# Discretization parameters
	dx = 0.1; dy = 0.2
	order = 2
	
	# Equation
	eq  = S(x,y) ~ Dxx(u(x, y)) + Dyy(u(x, y))
	
	# Initial and boundary conditions
	bcs = [u(x_min, y) ~ 0,
	    	u(x_max, y) ~ 0,
	        u(x,y_min) ~ 0,
	        u(x, y_max) ~ 0]
	
	# Space and time domains
	domains = [x ∈ Interval(x_min, x_max),
	           y ∈ Interval(y_min, y_max)]
	
	# PDE system
	@named pdesys = PDESystem([eq], bcs, domains, [x, y], [u(x, y)])
	
	# Method of lines discretization
	discretization = MOLFiniteDifference([x=>dx,y=>dy], nothing;centered_order=order)
	prob = ModelingToolkit.discretize(pdesys,discretization)
	
	# Solution of the ODE system
	sol = NonlinearSolve.solve(prob,NewtonRaphson());

end
1 Like

Mark it as solution so it shows up for future searches.