Coupled PDE solver

I am trying to solve a coupled linear pde
I have attached my code below

using DifferentialEquations
using FiniteDifferences

Define your system of coupled linear partial differential equations

function coupled_pdes(du, u, x)
# Extracting variables
t, z = x
# Parameters
g = 1
n = 200
c = 1
gamma = 4

#psi = u[1]
#phi = u[2]

#dpsi/dt = deriv(u[1], (1,), Diferences(), (t,)) 
#dpsi/dz = deriv(u[1], (1,), Diferences(), (z,)) 

#dphi/dt = deriv(u[2], (1,), Diferences(), (t,))
#dphi/dz = deriv(u[2], (1,), Diferences(), (z,))

#g(y::Real) = [sin(y), cos(y), tan(y)];  # returns a vector
#julia> ForwardDiff.derivative(g, pi/4)

function theta(t1)
    return Base.Math.acot(100*(1-0.5*tanh(0.1*(t1-15))+0.5*Base.tanh(0.1*(t1-125))))
end

function fs(t1)
    return sin(theta(t1))
end

function fc(t1)
    return cos(theta(t1))
end

thetadot = ForwardDiff.derivative(theta,t)

#ForwardDiff.derivative(x -> ForwardDiff.derivative(f, x), 1.0)

sder2    = ForwardDiff.derivative(x -> ForwardDiff.derivative(fs, x), t)
cder2    = ForwardDiff.derivative(x -> ForwardDiff.derivative(fc, x), t)

# Define the PDEs
du[1] = -c*(cos(theta(t)))^2 * deriv(u[1], (1,), Diferences(), (z,)) - thetadot*u[2] - c*sin(theta(t))*cos(theta(t))*deriv(u[2], (1,), Diferences(), (z,))
du[2] = (1/(gamma*tan(theta(t))*cos(theta(t))))*(-g^2*N*u[2]*1/sin(theta(t))
         +((sec(theta(t)))^2*thetadot)*(-thetadot*cos(theta(t))*u[1]+sin(theta(t))*deriv(u[1], (1,), Diferences(), (t,)))
         -((sec(theta(t)))^2*thetadot)*(-thetadot*sin(theta(t))*u[2]+cos(theta(t))*deriv(u[2], (1,), Diferences(), (t,)))
         +tan(theta(t))*sder2*u[1]+tan(theta(t))*sin(theta(t))*deriv(u[1], (2,), Diferences(), (t,)) 
         -tan(theta(t))*cder2*u[2]-tan(theta(t))*cos(theta(t))*deriv(u[2], (2,), Diferences(), (t,)) 
         +gamma*tan(theta(t))*cos(theta(t))*thetadot*u[1]+gamma*tan(theta(t))*sin(theta(t))*deriv(u[1], (1,), Diferences(), (t,)) 
         +gamma*tan(theta(t))*sin(theta(t))*thetadot*u[2])

return du

end

Define initial conditions

u0 = [x → e(-x^2/2), x → cos(π*x)]

Define parameters

#p = [1.0, 200, 1.0, 4.0]

Define the range of independent variables

xspan = (0.0, 10.0)

prob = PDEProblem(coupled_pdes, u0, xspan)

Solve the problem

sol = solve(prob)

Access the solution

u = sol.u[5] # Get the solution at the final time

the error I get is: type PDEProblem has no field u0

1 Like

I’m not entirely sure what you’re trying to do here. Is this code generated by ChatGPT? PDEProblem is not exposed as a documented thing, and the function here should be an ODE?

1 Like