# Simple Time Domain Heat Transfer Modeling

**URL:** <https://community.freefem.org/t/simple-time-domain-heat-transfer-modeling/2983>\
**Category:** General Discussion\
**Created:** [February 21, 2024, 5:23pm UTC](https://community.freefem.org/t/simple-time-domain-heat-transfer-modeling/2983 "2024-02-21T17:23:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MehranK1](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@MehranK1](https://community.freefem.org/u/MehranK1)\
**Post date:** [February 21, 2024, 5:23pm UTC](https://community.freefem.org/t/simple-time-domain-heat-transfer-modeling/2983/1 "2024-02-21T17:23:09Z")

</div>

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(w_1000), int(h_1000), [w_x, h_y]); // 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)(  
rho_cp_(T/dt)_v - rho_cp\*(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

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [February 22, 2024, 9:07am UTC](https://community.freefem.org/t/simple-time-domain-heat-transfer-modeling/2983/2 "2024-02-22T09:07:11Z")

</div>

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](https://community.freefem.org/uploads/short-url/9duyoxRuU07BBu7EZAMquFZi69K.edp) (1.4 KB)
