[PYTHON] Add a function to heat transfer + heat input by temperature to heatrapy

What i did

Added the function to input heat by heat transfer coefficient and temperature in one-dimensional unsteady heat transfer analysis with heatrapy. Originally, it was a specification that allows heat to be input to any position, so I used that.

Repair points

--I'm tinkering with class single_object in system.py

Set the input conditions with set_input_heat_transfer and heat up when calculating with compute. Heat is input at each time step according to the temperature difference for each hour.

henko.py


class single_object(object):
    def __init__(self, amb_temperature, materials=('Cu',), borders=(1, 11),
                 materials_order=(0,), dx=0.001, dt=0.1, file_name='data.txt',
                 boundaries=(0, 0), Q=[], Q0=[], heat_points=(1, -2),
                 initial_state=False, h_left=50000., h_right=50000.,
                 materials_path=False):

[Omitted]

        self.input_heat_transfer = False #When this is set to True, the heat transfer coefficient+Put in heat at temperature

[Omitted]

    def set_input_heat_transfer(self,input_heat_transfer_point,Heat_transfer_coefficient,Heat_transfer_temparature):
        """Add heat transfer coefficient and temperature to any position. Currently, it is heat input to only one point
        
        Arguments:
            input_heat_transfer_point {int} --It is a point to heat up. 1 for the top
            Heat_transfer_coefficient {float} --Heat transfer coefficient[W/(m2K)]
            Heat_transfer_temparature {float} --The temperature used for heat transfer[K]
        """
        self.input_heat_transfer=True
        self.input_heat_transfer_point = input_heat_transfer_point
        self.Heat_transfer_coefficient = Heat_transfer_coefficient
        self.Heat_transfer_temparature = Heat_transfer_temparature

[Omitted]

    def compute(self, timeInterval, write_interval, solver='explicit_k(x)',
                modeTemp=False, numFlag=0.5, modeTempPoint=1):

            #When inputting by heat transfer coefficient and temperature
            if self.input_heat_transfer:
                td = self.temperature[self.input_heat_transfer_point][0]
                self.Q0[self.input_heat_transfer_point] = self.Heat_transfer_coefficient * (self.Heat_transfer_temparature - td)/self.dx
                print(td,self.Q0)

Where I got stuck

I didn't get the heat I expected. The reason was simple and a mistake in the unit. In the Q0 calculation, I am dividing by self.dx. The unit of heat transfer coefficient is [W / (m2 K)].

test

I tried it with copper. 【input】

--Initial temperature: 293 [K] --Material: Copper (Physical property values are included in heatrapy) --Length: 20mm --Boundary condition: Insulation at both ends --Heat input point: end (x = 0) --Heat transfer coefficient: 700 [W / (m2K)] --Atmosphere temperature: 900 [K] --Analysis time: 30 seconds

heat_transfer_test.py


import heatrapy as ht
import pandas as pd
import os

if os.path.exists("heat_transfer.txt"):
    os.remove("heat_transfer.txt")
    
example = ht.single_object(amb_temperature=293, materials=('Cu',), borders=(1,21),materials_order=(0,),
                            dx=0.001, dt=0.001, file_name='heat_transfer.txt',boundaries=(0,0), Q=[], Q0=[],initial_state=False)

example.set_input_heat_transfer(1,700,900)

example.compute(timeInterval=30, write_interval=10, solver='implicit_k(x)')

df = pd.read_csv("heat_transfer.txt")
df=df.drop("heat[1](W)",axis=1)
df=df.drop("heat[-2](J)",axis=1)
df = df.set_index("time(s)")
df.plot(figsize=(15,8))

【result】 It feels good. Be careful with the value of dt. Decreasing dt will improve the accuracy, but will increase the analysis time. It is necessary to search for a good dt value while turning.

image.png

Source code

The source code is below. https://github.com/myao9494/heatrapy The test is heat_transfer_test.ipynb

Recommended Posts

Add a function to heat transfer + heat input by temperature to heatrapy
Add a function to tell the weather of today to slack bot (made by python)
Add a dictionary to MeCab
How to call a function
A handy function to add a column anywhere in a Pandas DataFrame
Attempt to extend a function in the library (add copy function to pathlib)
To add a C module to MicroPython ...
How to make a recursive function
Add a new issue to GitHub by email (Amazon SES utilization version)
Add a GPIO board to your computer. (1)
How to add a package with PyCharm
Function to save images by date [python3]
A simple IDAPython script to name a function
Assigned to a laboratory by integer programming
Add a Python virtual environment to VSCode
[Python] Add comments to standard input files
Add conversation function to slack bot (made by python) using Recruit's Talk API
[Circuit x Python] How to find the transfer function of a circuit using Lcapy