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.

#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.

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