mathLab / PINA

Physics-Informed Neural networks for Advanced modeling
https://mathlab.github.io/PINA/
MIT License
395 stars 66 forks source link

Aggregation of the equations on the boundary #363

Open luAndre00 opened 1 month ago

luAndre00 commented 1 month ago

I am trying to solve an optimal control problem constrained with the stokes equation. After writing the Lagrange system of equation I get many boundary conditions:

` def dirichlet1ad(input, output): return output.extract(['zx'])

def dirichlet2_ad(input_, output_):
    return output_.extract(['zy'])

def neumann1_ad(input_, output_):
    return -output_.extract(['r']) + 0.1 * grad(output_, input_, components=['zx'], d=['x'])

def neumann2_ad(input_, output_):
    return output_.extract(['zy'])

def dirichlet1(input_, output_):
    return output_.extract(['vx']) - input_.extract(['y'])

def dirichlet2(input_, output_):
    return output_.extract(['vy'])

def neumann1(input_, output_):
    return -output_.extract(['p']) + 0.1 * grad(output_, input_, components=['vx'], d=['x'])

def neumann2(input_, output_):
    return output_.extract(['vy'])`

With

conditions = {
    'gamma_above': Condition(location=CartesianDomain({'x': xrange, 'y': 2, 'mu': murange}),
                             equation=SystemEquation([dirichlet1, dirichlet2, dirichlet1_ad, dirichlet2_ad], reduction = "none")),
    # Dirichlet
    'gamma_left': Condition(location=CartesianDomain({'x': 0, 'y': yrange, 'mu': murange}),
                            equation=SystemEquation([dirichlet1, dirichlet2, dirichlet1_ad, dirichlet2_ad], reduction = "none")),
    # Dirichlet
    'gamma_below': Condition(location=CartesianDomain({'x': xrange, 'y': 0, 'mu': murange}),
                             equation=SystemEquation([dirichlet1, dirichlet2, dirichlet1_ad, dirichlet2_ad], reduction = "none")),
    # Dirichlet
    'gamma_right': Condition(location=CartesianDomain({'x': 1, 'y': yrange, 'mu': murange}),
                             equation=SystemEquation([neumann1, neumann2, neumann1_ad, neumann2_ad], reduction = "none")),  # Neumann
    'D': Condition(location=CartesianDomain({'x': xrange, 'y': yrange, 'mu': murange}),
                   equation=SystemEquation([momentum_x, momentum_y, continuity,
                                            momentum_ad_x, momentum_ad_y, continuity_ad], reduction = "none"))
}

I was wondering if it is correct to define the boundaries as a System of equation with reduction = None, because I have problems on the boundary conditions and I do not understand why.

Another doubt I had concerns the definition of the momentum equation: I wrote them considering one components at a time, so I have momentum_x, momentum_y and not only one equation of the momentum with length 2. The same is true for the momentum of the adjoint variables. My question is: is it different if I define only one momentum with length 2? Should I get the same results?

Thank you for you help!

dario-coscia commented 1 month ago

Hi! Can you provide in latex form the problem you are trying to solve? What time of problem you are getting with the boundaries (code error or not converging)?

luAndre00 commented 1 month ago

$$ \begin{cases} \displaystyle-0.1\Delta z(x,\mu) + \nabla r(x,\mu) = [x_2 - v_1(x,\mu),0]^T \ \displaystyle\nabla\cdot z(x,\mu) = 0 \ \displaystyle\alpha u(x,\mu) = z(x,\mu) \ \displaystyle-0.1\Delta v(x,\mu) + \nabla p(x,\mu) = f(x,\mu) + u(x,\mu) \ \displaystyle\nabla\cdot v(x,\mu) = 0\ \displaystyle z_1(x,\mu) = z_2(x,\mu) = 0 \ \displaystyle v_1(x,\mu) = x_2 \text{and} v_2(x,\mu) = 0 \ \displaystyle-r(x,\mu) + 0.1\frac{\partial z(x,\mu)}{\partial n} = 0 \text{and} z_2(x,\mu) = 0 \ \displaystyle-p(x,\mu) + 0.1\frac{\partial v(x,\mu)}{\partial n} = 0 \text{and} v_2(x,\mu) = 0
\end{cases} $$

sorry for some problem of visualization, I don't know how to fix them. Actually at the moment I got a good solution of this problem but I had to use eq 3 to change all z into u and solve the problem not considering z. The reconstruction of z was made after redefining the forward of the net imposing the third equation strongly. The problem I had before was that the boundary conditions were not converging. I don't know if there was something about PINA that I was not considering/out of my knowledge, or if these results (solving with u plus z = bad, solving only using u = good) are totally reasonable.

Thank you for your help!