mathLab/PINA

Time Dependency

LoveFrootLoops opened this issue · 6 comments

Hello,

I would like to inquire about how to implement an increasing force on one of the boundaries using the TimeDependentProblem class. I am currently facing difficulties in achieving this objective.

Here is the relevant code snippet:

def gamma_right(input_, output_):
    u1 = output_.extract(["u1"])
    return  u1 - 0.05* input_.extract(["t"])   # For t=0 I would have have 0 and for t=1 I would have the maximum of 0.05

class Mechanics(SpatialProblem, TimeDependentProblem):
    output_variables = ['u1', 'u2']
    spatial_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]})
    temporal_domain =  CartesianDomain({'t': [0, 1]})
    conditions = {
        'D': Condition(
            location=CartesianDomain({'x': [0, 1], 'y': [0, 1], 't': [0, 1]}),
            equation=Equation(equilibrium)),
        'gamma_right': Condition(
                  location=CartesianDomain({'x': 1, 'y': [0, 1], 't': [0, 1]}),
                  equation=Equation(equilibrium))
    }

Let me know if there's anything else I can provide.

Hello👋🏻 Can you specify where are you getting the error?

Apologies for the confusion. I have two issues regarding the working code. Firstly, how can I define the time domain differently spaced from the spatial domain? Currently, if I want 500 collocation points i.e.

bvp_problem = Mechanics()
bvp_problem.discretise_domain(500, 'grid', locations=['D'])

I would create 500 timesteps right? So my final mesh would be 500x500x500. How can I define for example a mesh of 500x500x10 i.e. only 10 timesteps? Do the number of collocation points and timesteps always have to be the same? If yes, then the paradigm is not very efficient for time-dependent problems.

My second issue is related to defining a dependency. I would like to establish that the output at timestep t depends on the output at timestep t-1. Is this possible?

Hi! Regarding the first issue, we have a parameter variables used in sampling. However, at the moment it doesn't work and we will fix it before the official release. As the PR is still in draft there are some things that unfortunately do not work...

Regarding the second question, I am still not sure what you want to do, but it seems something not related to the PINN but more with the model you are passing to the PINN... It's not a very standard task, so maybe you will need to implement a solver or model for the specific task.

@dario-coscia Yes, I'm willing to give it a try. However, please note that I'm currently occupied, and I have limited experience working with GitHub. Therefore, it might take me some time to complete the task.

In the meanwhile I fixed the issue with:

size1, size2, size3 = 50, 50, 10
tensor1, tensor2 = torch.rand(size1), torch.rand(size2)
tensor3 = torch.linspace(0, 1, size3)
inp_points = torch.cartesian_prod(tensor1, tensor2, tensor3)
inp_points.requires_grad = True

class Mechanics(SpatialProblem, TimeDependentProblem):
    output_variables = ['u1', 'u2']
    spatial_domain = CartesianDomain({'x': [0, 1], 'y': [0, 1]})
    temporal_domain = CartesianDomain({'t': [0, 1]})

    conditions = {
        #'D': Condition(
        #    location=CartesianDomain({'x': [0, 1], 'y': [0, 1], 't': [0, 1]}),
        #    equation=Equation(equilibrium))
        'D': Condition(
            input_points=LabelTensor(inp_points, ['x', 'y', 't']),
            equation=Equation(equilibrium))
    }

Hi! This is a nice work around and it can work. I opened a pull request in #139 since the issues was smaller than what I thought. Once merged I will informed you :)

Hey @LoveFrootLoops we made the merged in b3f7b16 . Thanks again for spotting the bug 😄