pandoc xelatex

This commit is contained in:
ldlda committed 2025-06-26 23:08:46 +07:00
1 parent 96a3da2869
commit 6e738980af
2 files changed
+37 -43

No files matched your search

+37 -43
View File
@@ -10,20 +10,19 @@ $$
\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)
$$
Where:
* $T$: Temperature ($^{\circ}C$)
- $T$: Temperature ($^{\circ}C$)
* $\rho$: Mass density ($kg/m^3$)
- $\rho$: Mass density ($kg/m^3$)
* $c_p$: Specific heat capacity ($J/(kg \cdot ^{\circ}C)$)
- $c_p$: Specific heat capacity ($J/(kg \cdot ^{\circ}C)$)
* $\lambda$: Thermal conductivity ($W/(m \cdot ^{\circ}C)$)
- $\lambda$: Thermal conductivity ($W/(m \cdot ^{\circ}C)$)
* $x, y, z$: Spatial dimensions (m)
- $x, y, z$: Spatial dimensions (m)
* $t$: Time (s)
- $t$: Time (s)
For a 1D bar, assuming homogeneous and isotropic material and insulated sides (except for the ends), the equation simplifies to:
@@ -31,7 +30,6 @@ $$
\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}$:
$$
@@ -42,7 +40,7 @@ $$
The following sections address the specific questions posed in the project document.
### Question 1: Express the left term of the equation (\*) using numerical differentiation.
### 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$:
@@ -51,10 +49,9 @@ $$
\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.
### 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$:
@@ -63,10 +60,9 @@ $$
\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.
### Question 3: Reformulate the equation (\*) using the results of Question 1 and 2
Substitute the finite difference approximations into the 1D Heat Equation:
@@ -74,10 +70,9 @@ $$
\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}$.
### 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}$:
@@ -85,7 +80,6 @@ $$
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$:
@@ -94,7 +88,6 @@ $$
r = \alpha \frac{\Delta t}{(\Delta x)^2}
$$
So the update equation becomes:
$$
@@ -103,19 +96,19 @@ $$
### Question 5: What are the boundary conditions and initial temperature?
a. **Temperature on the left** $x=0$**,** $T_g$**:**
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$**:**
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$.
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.
### 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:
@@ -131,51 +124,52 @@ The algorithm to solve the 1D Heat Equation using the Explicit Finite Difference
6. **Set Up Time Loop:**
* Create a `time_vector` from `0` to `t_final_s_sim` with step `dt`.
- 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).
- 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`.
- 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`.
- 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.
- **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))`.
- **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.
- **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`.
- **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.
### 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.
- **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.
- **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.
- **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.
- **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.
- **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.
- **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:
- **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 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.
- 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.
- **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.
- **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)
![Temperature Profile Evolution](./Figure_1.png)
BIN
View File
Binary file not shown.