Hello,
I am trying to understand the MMS and also solving the heat equation for the first time.
So, I have a working code built on the equation below. I understand the superficial structure of MMS, and how the individual components of the python code below come together, but I am not able to make sense of the entire process with heat eq. comprehensively. So we chose a solution, then project it on the mesh as initial condition at t=0, then the heat source derived from the solution is used in bilinear form, and the selected solution is also used a BC (updated with time).
It would be very kind if someone could explain this concept in brief to make sense out of it. I have a basic idea which makes sense of the fact that we use this approach to verify the code, but still if anyone could put in a few words of conceptual simplicity, it would be awesome.
In context to the heat equation, how is the physics working here? I mean, we have an initial condition of heat distribution on the mesh given by u0, and we are controlling the heat value on Boundary using the solution by updating it with time, then we are also heating the mesh from source 'f'. So the heat distribution in mesh changes from u0 at t= 0 to u1 at t = T under the influence of given source. Is that correct?
This is the code and below that is the output I get:
mesh = UnitSquareMesh (8, 8)
V = FunctionSpace (mesh, "Lagrange", 1)
dt = Constant (0.3) ; t = float (dt) ; T = 1.8
t0 = 0
I = Expression ("exp(-4*DOLFIN_PI*DOLFIN_PI*t)*cos(2* DOLFIN_PI *x[0])*cos(2* DOLFIN_PI *x[1])", t=t0 )
u0 = interpolate (I, V)
u1 = Function (V)
u = TrialFunction (V)
v = TestFunction (V)
f = Expression ("4*DOLFIN_PI*DOLFIN_PI *exp( -4* DOLFIN_PI * DOLFIN_PI *t) *cos(2* DOLFIN_PI *x[0]) *cos(2* DOLFIN_PI *x[1])",t=t0 )
a = u*v*dx + dt* inner (grad(u), grad(v))*dx
L = u0*v*dx + dt*f*v*dx
bc = DirichletBC (V, I ,"on_boundary")
while (t <= T):
I.t = t
f.t = t
solve (a == L , u1 , bc)
u0.assign (u1) # Update
t += float (dt)
plot (u1 , title = "Approximated final solution", interactive =True)