i need to do what to retrieve this document

This commit is contained in:
lda committed 2025-06-26 15:28:22 +00:00
1 parent 22fa53dfc5
commit 96a3da2869
1 file changed
+171 -16
+171 -16
View File
@@ -1,26 +1,181 @@
# Project
# Project: 1D Heat Transfer Simulation Report
## **Q1: Time Derivative ($\frac{\partial T}{\partial t}$)**
This report summarizes the solution to the 1D Heat Transfer Project, focusing on the numerical solution of the Heat Equation using the Explicit Finite Difference Method.
- This is approximated using a **forward finite difference** formula: $$\frac{T_i^{n+1} - T_i^n}{\Delta t}$$
## Introduction to the Heat Equation
## **Q2: Second Spatial Derivative ($\frac{\partial^2 T}{\partial x^2}$)**
The general 3D Heat Equation describes temperature distribution over time and space:
- This is approximated using a **central finite difference** formula: $$\frac{T_{i+1}^n - 2T_i^n + T_{i-1}^n}{(\Delta x)^2}$$
$$
\rho c_p \frac{\partial T}{\partial t} = \lambda \left( \frac{\partial^2 T}{\partial x^2} + \frac{\partial^2 T}{\partial y^2} + \frac{\partial^2 T}{\partial z^2} \right)
$$
## **Q3: Reformulate the Equation**
- Substitute the finite difference approximations into the 1D Heat Equation $ \frac{\partial T}{\partial t} = \alpha \frac{\partial^2 T}{\partial x^2} $:
$$\frac{T_i^{n+1} - T_i^n}{\Delta t} = \alpha \frac{T_{i+1}^n - 2T_i^n + T_{i-1}^n}{(\Delta x)^2}$$
Where:
## **Q4: Express $ T_i^{n+1} $**
* $T$: Temperature ($^{\circ}C$)
- Rearranging the reformulated equation to explicitly solve for temperature at the next time step:
$T_i^{n+1} = T_i^n + \alpha \frac{\Delta t}{(\Delta x)^2} (T_{i+1}^n - 2T_i^n + T_{i-1}^n)$.
- This can be simplified by defining $r = \alpha \frac{\Delta t}{(\Delta x)^2}$:
$T_i^{n+1} = T_i^n + r (T_{i+1}^n - 2T_i^n + T_{i-1}^n)$.
* $\rho$: Mass density ($kg/m^3$)
## **Q5: Boundary and Initial Conditions**
* $c_p$: Specific heat capacity ($J/(kg \cdot ^{\circ}C)$)
- **Initial Condition ($T_0$):** Defines the temperature of the _entire bar (internal nodes)_ at the starting time ($t=0$). For question 7 of this project, it's $0^{\circ}C$.
- **Boundary Conditions ($T_g$, $T_d$):** Define the fixed temperatures at the _ends of the bar_ ($x=0$ and $x=L$) for all times ($t>0$). These are $T_g=100^{\circ}C$ and $T_d=50^{\circ}C$ in question 7 of this project. These values are applied directly to the boundary nodes and are not updated by the finite difference equation.
* $\lambda$: Thermal conductivity ($W/(m \cdot ^{\circ}C)$)
* $x, y, z$: Spatial dimensions (m)
* $t$: Time (s)
For a 1D bar, assuming homogeneous and isotropic material and insulated sides (except for the ends), the equation simplifies to:
$$
\rho c_p \frac{\partial T}{\partial t} = \lambda \frac{\partial^2 T}{\partial x^2}
$$
This can be rewritten using thermal diffusivity $\alpha = \frac{\lambda}{\rho c_p}$:
$$
\frac{\partial T}{\partial t} = \alpha \frac{\partial^2 T}{\partial x^2}
$$
## Project Questions and Solutions
The following sections address the specific questions posed in the project document.
### Question 1: Express the left term of the equation (\*) using numerical differentiation.
The left term is the first partial derivative of temperature with respect to time, $\frac{\partial T}{\partial t}$.
Using a forward finite difference approximation for the time derivative at node $i$ and time step $n$:
$$
\frac{\partial T}{\partial t} \approx \frac{T_i^{n+1} - T_i^n}{\Delta t}
$$
This approximates the rate of temperature change at a specific spatial point $i$ from time $t_n$ to $t_{n+1}$.
### Question 2: Express the right term of the equation (\*) using numerical differentiation.
The right term is the second partial derivative of temperature with respect to space, $\frac{\partial^2 T}{\partial x^2}$.
Using a central finite difference approximation for the second spatial derivative at node $i$ and time step $n$:
$$
\frac{\partial^2 T}{\partial x^2} \approx \frac{T_{i+1}^n - 2T_i^n + T_{i-1}^n}{(\Delta x)^2}
$$
This relates the curvature of the temperature profile at node $i$ to the temperatures of its immediate neighbors at the current time step.
### Question 3: Reformulate the equation (\*) using the results of Question 1 and 2.
Substitute the finite difference approximations into the 1D Heat Equation:
$$
\frac{T_i^{n+1} - T_i^n}{\Delta t} = \alpha \frac{T_{i+1}^n - 2T_i^n + T_{i-1}^n}{(\Delta x)^2}
$$
Where $\alpha = \frac{\lambda}{\rho c_p}$ is the thermal diffusivity.
### Question 4: From the new formula of the equation, express $T_i^{n+1}$.
Rearranging the reformulated equation to explicitly solve for the temperature at the next time step $T_i^{n+1}$:
$$
T_i^{n+1} = T_i^n + \alpha \frac{\Delta t}{(\Delta x)^2} (T_{i+1}^n - 2T_i^n + T_{i-1}^n)
$$
This is the core update equation for each interior node.
For convenience, we define the Fourier number (or numerical stability parameter) $r$:
$$
r = \alpha \frac{\Delta t}{(\Delta x)^2}
$$
So the update equation becomes:
$$
T_i^{n+1} = T_i^n + r (T_{i+1}^n - 2T_i^n + T_{i-1}^n)
$$
### Question 5: What are the boundary conditions and initial temperature?
a. **Temperature on the left** $x=0$**,** $T_g$**:**
The temperature at the left end of the bar ($x=0$) is a fixed boundary condition: $T_g = 100^{\circ}C$.
This means $T_1^n = 100^{\circ}C$ for all time steps $n$.
b. **Temperature on the right** $x=L$**,** $T_d$**:**
The temperature at the right end of the bar ($x=L$) is a fixed boundary condition: $T_d = 50^{\circ}C$.
This means $T_{N_x}^n = 50^{\circ}C$ for all time steps $n$.
c. **Initial temperature** $T_0$**:**
The initial temperature of the *internal* nodes of the bar (at time $t=0$) is $T_0 = 0^{\circ}C$.
This means $T_i^0 = 0^{\circ}C$ for all internal nodes $i$.
### Question 6: Write the algorithm to calculate all temperatures at each point of the bar and at any time.
The algorithm to solve the 1D Heat Equation using the Explicit Finite Difference Method involves these steps:
1. **Define Parameters and Material Properties:** Set `L`, `dx`, `dt`, `Tg`, `Td`, `T0`, `rho`, `Cp`, `lambda`, and `t_final_s_sim`.
2. **Calculate Thermal Diffusivity (**$\alpha$**):** Compute `α = λ / (ρ * cp)`.
3. **Calculate Fourier Number (**$r$**) and Check Stability:** Compute `r = α * Δt / (Δx)^2`. For stability, `r` must be $\le 0.5$. A warning is issued if this condition is violated.
4. **Discretize Spatial Domain:** Create a vector `x` representing the spatial nodes from `0` to `L` with step `dx`. Determine `Nx`, the total number of nodes.
5. **Set Initial Condition:** Initialize a temperature array `T_current` of size `Nx`. Set all internal nodes to `T0`. Apply `Tg` and `Td` to the first and last nodes, respectively.
6. **Set Up Time Loop:**
* Create a `time_vector` from `0` to `t_final_s_sim` with step `dt`.
* Initialize storage for `T_midpoint_over_time` (temperature at the bar's midpoint over all time) and `all_profiles`/`all_profile_times` (full spatial profiles at specific time points for plotting).
* Capture the initial profile (`t=0`) if it's one of the `plot_time_points`.
7. **Main Time-Stepping Loop:**
* Iterate for each time step `n` from the start to `t_final_s_sim`.
* **Create `T_next`:** Initialize `T_next` by copying `T_current`. This implicitly carries over the fixed boundary conditions.
* **Apply Finite Difference Equation:** For each *internal* node `i` (from index 2 to `Nx-1`), calculate `T_next(i)` using the formula derived in Question 4: `T_next(i) = T_current(i) + r * (T_current(i+1) - 2*T_current(i) + T_current(i-1))`.
* **Update `T_current`:** Set `T_current = T_next` for the next iteration.
* **Store Data:** Record `T_current(mid_index)` into `T_midpoint_over_time`. If the current time matches a `plot_time_point` (using `ismembertol` with absolute tolerance), store the full `T_current` profile into `all_profiles`.
### Question 7: Use MATLAB to solve the equation.
The MATLAB code implements the algorithm described in Question 6 using the specified numerical values for parameters and material properties. The `fprintf` statements provide real-time output of derived constants (thermal diffusivity, Fourier number) and simulation progress.
**Key Features of the MATLAB Implementation:**
* **Parameter Definition:** All physical and numerical parameters are clearly defined at the beginning of the script.
* **Stability Check:** The Fourier number (`r`) is calculated, and a warning is issued if it exceeds `0.5`, indicating potential numerical instability.
* **Grid Initialization:** Spatial and temporal grids are set up, and the initial temperature profile is established with the specified boundary conditions.
* **Iterative Solution:** A `for` loop efficiently advances the temperature solution through time, updating each internal node based on its neighbors' temperatures from the previous time step.
* **Profile Capture:** Specific `plot_time_points` are strategically chosen to capture the temperature profiles during critical phases of heat transfer (early transient, middle, and approaching steady-state). The `unique()` function ensures these points are sorted and distinct.
* **Robust Data Storage:** `ismembertol` with an explicit absolute tolerance (`dt/2`, `'DataScale', 1`) is used to accurately match simulation times with `plot_time_points` for storing profiles, avoiding floating-point comparison issues.
* **Visualization:** The results are presented in a two-panel figure:
* The left panel displays multiple **temperature profiles across the bar (Temperature vs. Position)** at the selected `plot_time_points`, illustrating the evolution of the temperature distribution.
* The right panel shows the **temperature at the bar's midpoint as a function of time (Temperature vs. Time)**, providing a clear view of how a specific point heats up and approaches equilibrium.
* **Conditional Legend:** A conditional check prevents the legend from being displayed if too many lines are plotted, improving readability.
* **Figure Output:** The figure provides a comprehensive visualization of the simulation, demonstrating how the temperature profile changes over time until it reaches a steady-state (linear) distribution between the fixed boundary temperatures.
An example of the generated figure (`Figure_1.png`) would be:
![Figure 1](./Figure_1.png)