Updating a variable every time step using NeuralPDE.jl and Physics-Informed NN

Hey all,

I am trying to solve a finite volume problem with PINN and I am having trouble defining one of the boundary conditions. I have a variable that depends on the value of the function and I want to assign values to the variable based on previous solution steps. This is what I have in mind:

@parameters x, y, z, θ
@variables u(..)
@derivatives Dx'~x
@derivatives Dy'~y
@derivatives Dz'~z

function foo(u) #function takes value of the variable from a previous iteration
      P=  c*u^4/n1
      return P
      # where n1 and c are constants and 'P' is the changing variable
end
for i in 1:i_max
       P = foo(u)
       bc[i] = P*n2 ~ Dx(u)+Dy(u)+Dz(u)    #n2 is some other constant
end

I’m not sure how to implement this using PINN. I am following these examples.

Is there an issue with just writing that?

I tried with one of the examples

#2D PDE
eq  = Dt(u(t,x,θ)) + u(t,x,θ)*Dx(u(t,x,θ)) - (0.01/pi)*Dxx(u(t,x,θ)) ~ 0

function foo(u)
    a = u^2
    return a
end

# Initial and boundary conditions
X = collect(range(-1, 1, step=0.1))
U = -sin.(pi*X)
bcs = Vector{ModelingToolkit.Equation}(undef, length(U)+2)
for i in eachindex(U)
    a = foo(u)
    bcs[i] = u(0,X[i],θ) ~ -a*sin(X[i]*pi)
end
bcs[length(U)+1] = u(t,-1,θ) ~ 0.
bcs[length(U)+2] = u(t,1,θ) ~ 0.

and I get this error
ERROR: LoadError: MethodError: no method matching ^(::Variable{Number}, ::Int64)

Also, I don’t know what value of the variable it is taking. I don’t want the definitions to be circular or over-constrained.

@shashi is this fixed in v4?

I think this is wrong (doesn’t matter which version), it’s because u is a function-like object. Calling it will return a number like object.

So either use u(something, something) or define @variables u instead of @variables u(..)

Thank you!
Using u(something) worked.

function foo(u)
    a = u(t,x,θ)^2
    return a
end

# Initial and boundary conditions
X = collect(range(-1, 1, step=0.1))
bcs = Vector{ModelingToolkit.Equation}(undef, length(U)+2)
for i in eachindex(X)
    a = foo(u)
    bcs[i] = u(0,X[i],θ) ~ -a*sin(X[i]*pi)
end
1 Like