Simple Time Domain Heat Transfer Modeling

Hello Everyone,

I am trying to model a very simple copper bar the has temperature difference between its both vertical sides. Here is the code. I dont know what is wrong that it gives me an error. I would appreciate it if someone could please help me figure the problem out.

// Parameters for copper
real k = 401; // Thermal conductivity of copper in W/(m·K)
real rho = 8960; // Density of copper in kg/m^3
real cp = 385; // Specific heat capacity of copper in J/(kg·K)
real Tleft = 70; // Temperature at the left boundary in Celsius
real Tright = 0; // Temperature at the right boundary in Celsius
real h = 0.01; // Height of the bar in meters
real w = 0.03; // Width of the bar in meters
real Tfinal = 10; // Total time in seconds
real dt = 0.1; // Time step in seconds

// Mesh
mesh Th = square(int(w1000), int(h1000), [wx, hy]); // Creating a mesh based on the dimensions

// Fespace
fespace Vh(Th, P1);
Vh T, Told, v;

// Initial condition: Assuming initial temperature is T_right
T = Tright;
Told = T;

// Problem definition
problem heatTransfer(T, v) =
int2d(Th)(
rhocp(T/dt)v - rhocp*(Told/dt)v + k(dx(T) * dx(v) + dy(T) * dy(v))
)
+ on(1, T=T_left) // Apply boundary condition on the left vertical boundary
+ on(2, T=T_right) // Apply boundary condition on the right vertical boundary
+ on(3, 4, dx(T)=0); // Apply insulated boundary conditions on the top and bottom horizontal boundaries

// Time-stepping loop
for (real t=0; t<=Tfinal; t+=dt) {
Told = T; // Update the old temperature
heatTransfer.solve(); // Solve the heat transfer problem

// Optional: Output or visualization code here
cout << "Time: " << t << " s" << endl;
plot(T, fill=true, value=true, wait=true); // Visualize the temperature distribution

}

Regards,
Mehran

You do lot mistake:

  1. you must split linear (rhs) and bilinear (matrix) term
    in problem<.
  2. the dx(T) =0 imply zero neumann B.C so non extra term in the variational formulation

my correction :

Mehran.edp (1.4 KB)