# Time-independent Usage for MOLFiniteDifference()

**URL:** <https://discourse.julialang.org/t/time-independent-usage-for-molfinitedifference/75132>\
**Category:** General Usage\
**Tags:** diffeq\
**Created:** [January 24, 2022, 3:40pm UTC](https://discourse.julialang.org/t/time-independent-usage-for-molfinitedifference/75132 "2022-01-24T15:40:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fathya.Salih](https://avatars.discourse-cdn.com/v4/letter/f/47e85d/32.png) [@Fathya.Salih](https://discourse.julialang.org/u/Fathya.Salih)\
**Post date:** [January 24, 2022, 3:40pm UTC](https://discourse.julialang.org/t/time-independent-usage-for-molfinitedifference/75132/1 "2022-01-24T15:40:42Z")

</div>

Hello,

I am trying to use MOLFiniteDifference() to solve a stationary PDE. In the [documentation](https://github.com/SciML/MethodOfLines.jl), 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:

```julia
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

```julia
## 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?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 24, 2022, 5:57pm UTC](https://discourse.julialang.org/t/time-independent-usage-for-molfinitedifference/75132/2 "2022-01-24T17:57:27Z")

</div>

The docs should be up soonish. For the answer right now though, see [https://github.com/SciML/MethodOfLines.jl/blob/master/test/pde\_systems/MOL\_NonlinearProblem.jl#L64-L65](https://github.com/SciML/MethodOfLines.jl/blob/master/test/pde_systems/MOL_NonlinearProblem.jl#L64-L65) . The result of a time-independent problem is a `NonlinearProblem` to be solved via [NonlinearSolve.jl](https://nonlinearsolve.sciml.ai/dev/).

---

<div class="post-metadata">

**Author:** ![Fathya.Salih](https://avatars.discourse-cdn.com/v4/letter/f/47e85d/32.png) [@Fathya.Salih](https://discourse.julialang.org/u/Fathya.Salih)\
**Post date:** [January 24, 2022, 10:58pm UTC](https://discourse.julialang.org/t/time-independent-usage-for-molfinitedifference/75132/3 "2022-01-24T22:58:31Z")

</div>

That worked. Thanks!

```julia
	## 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

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 24, 2022, 10:59pm UTC](https://discourse.julialang.org/t/time-independent-usage-for-molfinitedifference/75132/4 "2022-01-24T22:59:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MengkeLuLu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mengkelulu/32/38442_2.png) [@MengkeLuLu](https://discourse.julialang.org/u/MengkeLuLu)\
**Post date:** [August 1, 2022, 6:47pm UTC](https://discourse.julialang.org/t/time-independent-usage-for-molfinitedifference/75132/5 "2022-08-01T18:47:28Z")

</div>

Hi Chris, when I tried the codes from [Fathya.Salih](https://discourse.julialang.org/u/Fathya.Salih) on Mac (M1 chip), it showed “UndefVarError: MOLFiniteDifference not defined”. What could be the reasons? Thanks.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 1, 2022, 6:57pm UTC](https://discourse.julialang.org/t/time-independent-usage-for-molfinitedifference/75132/6 "2022-08-01T18:57:36Z")

</div>

Make a new issue. What did you try? What versions are you on (]st)? Etc.
