Now we are going to solve a 2D heat equation.
The difference between 1D and 2D heat equation is simply in 2D.
You have this additional parameter, which is the diffusion in the direction of Y.
So the change of u with or the temperature with T will equal.
If Alpha Square or let's say the whole thing is is just a factor that's going to be multiplied by the
diffusion or the second derivative of U with respect to X and the second derivative of U with respect
to Y.
So again, this is the temporal form or the temporal.
Well, you can say like component, which is a time based component or the change of U with respect
to T and all of this.
This one and this one is the spatial derivative or component, which is the derivative of U with respect
to x and the second derivative of U with respect to x and the second derivative of U with respect to
Y.
Of course, U is the most the heat equation is usually the temperature, but it's it's basically describe
a system that will have a diffusive property.
So.
So that's it.
And this just the coefficient.
Diffusion coefficient component.
It can be different for every one of them.
So we might have in the past I think it was K or A or V, I'm not sure.
But basically this component can be different for the X and different for Y.
Some materials will have a different coefficient regarding the diffusivity of or the heat transfer in
the x direction is different than the y direction.
So.
These things will will be different.
And but in this case, it will be taken very simple.
Simply in this example.
Actually, I'm going to I'm going to set it.
One is just I don't really want to study its effect or work about its effect.
The purpose of all of this is to simply explain how to solve heat equation, a 2D heat equation using
um, this basically the um.
A numeral neural neural networks.
So we we do pens.
So let's start.
Let's start defining the needed libraries.
And of course, um, the, the, the network.
This is what we're going to do first.
So the first thing is what we call it.
Like we can say heat.
Uh, to the.
Into the.
Bins mean main.
This function and then we start importing the needed library.
So import torch.
Import.
Import torch dot n.
N.
As n.
N.
Import.
This time it will be very simple network and very simple optimization algorithms.
We're going to just use Adam since just the out of the box very common.
Adam And because the accuracy is not really what we are looking for, we're looking for mainly the concept
and how can we do it like in a step by step manner.
This is, this is what we want to this is why we took this course.
So torch to Optim as Optim this one we will just we will take the Adam optimizer from it and see born
as SNS for the we use it before for the heat plot plot lap matplotlib.pyplot.
By plot as plt.
The usual guy.
The first thing we will do, we can call bins pens in n dot module, same as everything.
We always inherit the a neural network module and init.
Uh, sorry.
This one and then self.
And again, super.
Pins.
Bins.
Self.
Dot.
In it.
And now we will do the nut.
Not always like the usual thing, which is actually building the network in dot sequential is capital
letter seek when shell.
And we start in n dot.
Engineer.
Lean.
It.
We will have a three and 64.
This is we need to let a little bit relaxed.
Linear 64 means now we have 2D.
That means we have X, we have Y, and we have time.
This is we didn't have it before, so this is why we have this one.
And of course, of course we can do a.
Complicated network, but will take it very simple and very just, very simple neural network, which
is just three inputs expanding and then just.
Collapsing onto one, which is you.
So in a linear 364, I think like I like I like to write to, to, to write it like this.
So here linear 64 and then an N dot the activation function ten inch and we close and then an n dot
linear linear.
And this time the activation function will be 64 expanding into another 64.
I turn right here and this in.
Dot ten.
Etch Ten.
Etch.
And that I then itch and this time it will close.
Linear.
We'll get 64 and collapse onto one.
Three will have to go to 64.
The 64 has to go another 64 and then it will collapse into a.
Two into one.
So the neural network will be the first layer three.
Second layer is 64.
Third layer is going to be another 64.
And then the last layer will be one.
Which is what we're trying to predict, which is the the you forward.
Self.
And X.
Return.
Self dot net.
And that's it.
Then shift, enter.
So that's it.
This is how we.
A define our network.
Of course you can make it a little bit more.
Complicated, but usually because all of these problems so far is very simple problems, I would say.
So, of course, if you if you have a little bit more complex network, for example, you're solving
Navier-Stokes equations.
You might need to account more more than you might.
You need to build a bigger network.
It seems like it.
So.
However, we have only the heat equation and it is 2D.
So we this is the main changes.
We have three here input and this one as output.
So let's next class we will.
Define some of the losses.
And just same thing, initial condition, boundary condition, everything like building the the whole
system.