<jupyter_start><jupyter_text>TMR4222 Thermal System Exercise 2  Problem 1A pipe made of steel with an inner diameter of 50 mm and with a wall thickness of 5 mm istransferring water of 83 oC. The pipe is insulated with a 2 cm pipe insulation materialwith a  thermal conductivity of 0.082 W/mK.  The average water flow speed is 2.5 m/s.Outer room temperature is assumed to be 20 ºC. The thermal contact resistance between the steeland the insulation can be assumed to be approximately 0.0001 m2K/W.Assuming that the wall temperature both inside and outside of the pipe are equal to the water and room temperature, i.e. no convection effects.  Create a function that returns thermal resistance of a cylinder for the following inputs:    - radius    - wall_thickness    - thermal_conductivity    - lengthThe function name should be `get_thermal_resistance_cylinder`. Please see the `thermal_system_calculation.py` file for the detailed guidance.Use the following code to test your function.<jupyter_code>import numpy as np

from thermal_system_calculation import get_thermal_resistance_cylinder, FinConfiguration

radius = 0.07
wall_thickness = 0.01
thermal_conductivity = 130
length = 1

answer = 0.000163478
value_to_test = get_thermal_resistance_cylinder(
    radius=radius,
    wall_thickness=wall_thickness,
    thermal_conductivity=thermal_conductivity,
    length=length
)
assert np.isclose(answer, value_to_test), f"Your value {value_to_test:.5e} is not close to the answer, {answer:.5e}"<jupyter_output><empty_output><jupyter_text>What is the heat loss pr meter for the pipe without insulation?  Known<jupyter_code># Known
inner_diameter = 0.05 # m
wall_thickness = 0.005 # m
temperature_water = 83 # degC
temperature_room = 20 # degC<jupyter_output><empty_output><jupyter_text>Find<jupyter_code>heat_loss_per_meter_bare = None<jupyter_output><empty_output><jupyter_text>Schematic![Pipe Wall Heat Transfer](pipe_wall_heat_transfer.svg)  Assumptions1. No convection is considered. The temperature of the inner wall is equal to the temperature ofwater and the temperature of the outer wall is equal to the room temperature.2. Steady state3. Material property of the steel is homogeneous and constant  Properties<jupyter_code>thermal_conductivity_steel = 15 # W/mK<jupyter_output><empty_output><jupyter_text>AnalysisWe can use the equation for the thermal resistance for a cylinder to calculate the heat loss. $$R_\mathrm{cond} = \frac{\ln(r_3/r_2)}{2 \pi L k}$$<jupyter_code>inner_radius_pipe = inner_diameter / 2

thermal_resistance_pipe_per_meter = get_thermal_resistance_cylinder(
    radius=inner_radius_pipe,
    wall_thickness=wall_thickness,
    thermal_conductivity=thermal_conductivity_steel,
    length=1
)
temperature_diff = temperature_water - temperature_room
heat_loss_per_meter_bare = 1 / thermal_resistance_pipe_per_meter * temperature_diff

print(f"Pipe loses {heat_loss_per_meter_bare:.2f}W/m to the room.")<jupyter_output>Pipe loses 32566.69W/m to the room.<jupyter_text>What is the heat loss pr meter for the pipe with insulation not considering the contactresistance?<jupyter_code>#### Known
insulation_thickness = 0.02 # m
#### Find
heat_loss_per_meter_insulated = None<jupyter_output><empty_output><jupyter_text>Schematic![pipe insulation heat transfer](pipe_insulation_heat_transfer.svg)  Assumptions1. No convection is considered. The temperature of the inner wall is equal to the temperature ofwater and the temperature of the outer wall is equal to the room temperature.2. Steady state3. Material property of steel is homogeneous and constant4. No thermal resistance between the pipe wall and the insulation  Properties<jupyter_code>thermal_conductivity_insulation = 0.082 # W/mK<jupyter_output><empty_output><jupyter_text>Analysis<jupyter_code># First calculate the thermal resistance of the insulation
outer_radius_pipe = radius + wall_thickness
outer_radius_insulation = outer_radius_pipe + insulation_thickness
thermal_resistance_insulation_per_meter = get_thermal_resistance_cylinder(
    radius=outer_radius_pipe,
    wall_thickness=insulation_thickness,
    thermal_conductivity=thermal_conductivity_insulation,
    length=1
)

# Then, calculate the heat loss considering total heat resistance
total_resistance_per_meter = thermal_resistance_pipe_per_meter + thermal_resistance_insulation_per_meter
heat_loss_insulation_no_contact_resistance = 1 / (total_resistance_per_meter) * temperature_diff

print(f"Heat loss with insulation without contact resistance is {heat_loss_insulation_no_contact_resistance:.3f} W/m.")<jupyter_output>Heat loss with insulation without contact resistance is 136.735 W/m.<jupyter_text>Calculate the the heat loss when the contact resistance considered.  Find<jupyter_code>heat_loss_insulation_contact_resistance_per_meter = None<jupyter_output><empty_output><jupyter_text>Schematic![pipe insulation heat transfer](pipe_insulation_contact_resistance_heat_transfer.svg)  AssumpationSame as above  Properties<jupyter_code>thermal_resistance_contact_per_area = 10**-4 # m2K/K<jupyter_output><empty_output><jupyter_text>Analysis<jupyter_code># First calculate the total thermal resistance
import numpy as np
thermal_resistance_contact_per_meter = thermal_resistance_contact_per_area * 2 * np.pi * outer_radius_pipe
total_resistance_per_meter = thermal_resistance_pipe_per_meter + \
                             thermal_resistance_contact_per_meter + \
                             thermal_resistance_insulation_per_meter

# Calculate heat loss
heat_loss_insulation_contact_resistance_per_meter = 1 / total_resistance_per_meter * temperature_diff

print(f"Heat loss with insulation and contact thermal resistance is "
      f"{heat_loss_insulation_contact_resistance_per_meter:.3f}")<jupyter_output>Heat loss with insulation and contact thermal resistance is 136.721<jupyter_text>We see that the thermal resistance for the contact does not change the heat loss. We can often neglect the part of the heat circuit which has very low thermal resistance.   Problem 2 Heat transfer from extended surface  Implement a function for the extended surface.Create a function called `get_heat_transfer_1D_fin_with_uniform_cross_section` , in `thermal_system_calculation.py` that returns a tuple of `(heat_transfer_rate, temperature)` for given x and given boundary conditions as follows.|Case|Tip Condition (x=L)|Temperature Distribution $\theta/\theta_b$|Fin Heat Transfer Rate $q_f$||----|-------------------|------------------------------------------|--------------------------||A   |Convection heat transfer| $\frac{\cosh m(L-x) + (h/mk)\sinh m(L-x)}{\cosh mL + (h/mk)\sinh mL}$ | $M \frac{\sinh mL + (h/mk)\cosh mL}{\cosh mL + (h/mk)\sinh mL}$||B   |Adiabatic          |$\frac{\cosh m(L-x)}{\cosh mL}$|$M \tanh mL$||C   |Prescrubed temperature|$\frac{(\theta_L / \theta_b)\sinh mx + \sinh m(L-x)}{\sinh mL}$| $M\frac{\cosh mL - \theta_L / \theta_b}{\sinh mL}$||D   |Infinite fin ($L \rightarrow \infty$)|$e^{-mx}$|$M$|The arguments should be- `x`: length along the axis [m],- `temp_base`: temperature at the base of the fin [K],- `temp_surr`: surrounding temperature [K],- `fin_configuration`: an instance of FinConfiguration containing members of `perimeter`,`area_cross_section` and `length`- `h`: convection heat transfer coefficient [W/m2K],- `k`: thermal conductivity of the materials [W/mK],- `boundary_condition`: kind of boundary condition to apply. See `TipBoundaryConditionForFin`  class in `thermal_system_calculation.py` given.- `temp_tip`: (Optional) tempeature at tip [K]. Only required when the boundary condition is  `boundary_condition == TipBoundaryConditionForFin.Temperature`For more details, please see the given `thermal_system_calculation.py` for the guidance.Use the following code to test your function.<jupyter_code>from thermal_system_calculation import TipBoundaryConditionForFin, get_heat_transfer_1D_fin_with_uniform_cross_section

parameters = {
    'x': 0.02,
    'temp_base': 500,
    'temp_surr': 300,
    'fin_configuration': FinConfiguration(perimeter=0.032, area_cross_section=0.00012,
                                          length=0.05),
    'h': 100,
    'k': 180,
}
temp_tip = 375

answers = [(30.2095, 477.706), (28.5584, 479.250), (66.3291, 443.931), (52.5814, 456.787)]

for boundary_condition, answer_pair in zip(TipBoundaryConditionForFin, answers):
    parameters['boundary_condition'] = boundary_condition
    if boundary_condition == TipBoundaryConditionForFin.Temperature:
        parameters['temp_tip'] = temp_tip
    value_pair_to_test = get_heat_transfer_1D_fin_with_uniform_cross_section(**parameters)
    print(value_pair_to_test)
    for value, answer in zip(value_pair_to_test, answer_pair):
        assert np.isclose(value, answer), \
        f"Your value {value:.5e} for {boundary_condition} is not close to the answer, {answer:.5e}"<jupyter_output>(30.209468920245385, 477.70643342160207)
(28.558369239653548, 479.25037344351244)
(66.32908240563623, 443.9310548108814)
(52.58136552049595, 456.78651748122303)<jupyter_text>Get the temperature distributionCreate a plot of temperature distribution for the each boundary condition as follows:<jupyter_code>import matplotlib.pyplot as plt

# We will plot for 0 <= x <= legnth
x = np.linspace(0, parameters['fin_configuration'].length, 101)
parameters['x'] = x

fig, ax = plt.subplots(figsize=(8, 6))
for boundary_condition in TipBoundaryConditionForFin:
    parameters['boundary_condition'] = boundary_condition
    if boundary_condition == TipBoundaryConditionForFin.Temperature:
        parameters['temp_tip'] = temp_tip
    heat_transfer_rate, temperature_vector = get_heat_transfer_1D_fin_with_uniform_cross_section(**parameters)
    ax.plot(x, temperature_vector, label=boundary_condition.name)
ax.set_xlabel('x [mm]')
ax.set_ylabel('Temeprature[K]')
ax.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08987624264556705, 'fraction_numerical': 0.03428687360519375, 'mean_word_length': 5.537798408488063, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '295637', 'license': 'MIT', 'n_tokens_mistral': 3336, 'n_tokens_neox': 2919, 'n_words': 834, 'path': 'Exercises/exercise2/solution/Exercise2.ipynb', 'repo_name': 'kevinksyTRD/HeatTransferCourse', 'size': '9858'}