This package is a module for simulating dynamic heat transfer processes involving caloric effects in 1.5D systems by using the finite difference method. It is focused on heat conduction, and includes two subpackages for computing caloric systems. The python library physplotlib can be used for the visualization of the output data.
author: Daniel Silva (djsilva99@gmail.com)
current version: v1.0.0
To install heatrapy use the pip package manager:
$ pip install heatrapy
To import the heatrapy module type in the python shell:
>>> import heatrapy as ht
This module allows to create thermal objects, establish thermal contact between them, activate or deactivate part of the materials, and compute the respective heat transfer processes, in 1D. The computation uses the finite difference method. It includes two system models for the computation of caloric systems.
The package is based on three classes that create generic models:
object
This class only creates a single thermal object. It includes two methods: material activation and material deactivation, of part of the object.
system_objects
This class creates a system of objects that can be in contact to each other and computes the respective heat transfer processes. It uses the class object for the creation of each thermal object.
single_object
This class computes the heat transfer processes involved in only one thermal object. It uses the class object for activating and deactivating the material.
At this moment there are two types of caloric systems (functions) that can be computed:
solid_active_regenerator
This function creates and computes an active regenerative system used for refrigeration and heat pumps. The heat exchanger is the solid material itself. It can be used to compute caloric systems, e.g. magnetocaloric, electrocaloric, elastocaloric, and barocaloric.
fluid_active_regenerator
This function creates and computes an active regenerative system used for magnetocaloric refrigeration and heat pumps. The heat exchanger is a fluid. It can be used to compute caloric systems, e.g. magnetocaloric, electrocaloric, elastocaloric, and barocaloric.
1D thermal objects incorporates all thermal physical properties (temperature, specific heat, thermal conductivity and density) and boundary conditions, for a discretized length. Thermal objects can include heat sources and can be in contact with other thermal objects. There are three classes for thermal objects. The object
class is responsible for creating thermal objects, the system_objects
class is responsible for creating systems of thermal objects and compute the respective system, and the single_object
class is responsible for computing single objects made of several materials.
The object
class is the building block of the whole package. It creates thermal objects to be used in the more complex systems when the system_objects
and single_object
classes are called. It includes two methods to apply and remove fields. To create a thermal object type:
>>> foo = ht.object(amb_temperature, materials=('Cu',), borders=(1, 11),
... materials_order=(0,), dx=0.01, dt=0.1, file_name='data.txt',
... boundaries=(0, 0), Q=[], Q0=[], initial_state=False,
... heat_save=False)
The input variables are the following:
amb_temperature
: ambient temperature of the whole systemmaterials
: tuple of strings of all the used materials present in the folder materialsborders
: tuple of the points where there is a change of materialmaterials_order
: tuple of thematerials
tuple index that defines the material properties given byborders
dx
: the space stepdt
: the times stepfile_name
: file name where the temperature and heat flux are savedboundaries
: tuple of two entries that define the boundary condition for temperature. If 0 the boundary condition is insulationQ
: list of fixed heat source coefficient.Q0
: list of temperature dependent heat source coefficient.initial_state
: initial state of the materials.True
if the field is applied andFalse
if the field is removed.heat_save
:True
if saving the heat at the two borders.
In this case, the foo
object will have the following main array attributes:
temperature
: temperaturek
: thermal conductivityCp
: specific heatrho
: densityQ
: fixed heat source coefficientQ0
: temperature dependent heat source coefficient
Following the last subsection, to activate a piece of foo
type:
foo.activate(initial_point, final_point)
This command will activate the material from the initial_point
to the final_point
.
To deactivate a piece of material type:
foo.deactivate(initial_point, final_point)
This command will deactivate the material from the initial_point
to the final_point
.
The system_objects
class can be used to compute heat transfer processes between solids. It creates a system of thermal objects, establishes contact between them and computes the respective thermal processes. To create a system of thermal objects type:
>>> foo = ht.system_objects(number_objects=2, materials=('Cu', 'Cu'),
... objects_length=(10, 10), amb_temperature=293, dx=0.01,
... dt=0.1, file_name='data', initial_state=False,
... boundaries=((2, 0), (3, 0)))
The input variables are the following:
amb_temperature
: ambient temperature of the whole systemmaterials
: tuple of strings of all the used materials present in the folder materialsnumber_objects
: integer for the number of thermal objectsobjects_length
: tuple of the object lengths (spacial steps)dx
: the space stepdt
: the times stepfile_name
: file name where the temperature and heat flux are savedboundaries
: tuple of two entries that define the boundary condition for temperature. The first corresponds to the thermal object while the second defines the temperature. If 0 the boundary condition is insulationinitial_state
: initial state of the materials. True if applied field and False is removed field.
To add a contact between thermal objects type
>>> foo.contactAdd(contact)
The contact
input parameter is a tuple of length 2 (one for thermal object A and one for thermal object B) in which each element is a tuple of length 2 as well where the first element is the index of the thermal object and the second is the index spatial point.
To remove a specific contact
type
>>> foo.contactRemove(contact)
To filer all contacts of a material type
>>> foo.contactFilter(object)
where object
is the thermal object index.
Finally, to compute the overall system type
>>> foo.compute(time_interval, write_interval, solver='implicit_k'))
This method computes the system for time_interval
, and writes into the file_name
file every write_interval
time steps. Four different solvers
can be used: 'explicit_general'
, 'explicit_k(x)'
, 'implicit_general'
, and 'implicit_k(x)'
. The implicit solvers use the Crank-Nicholsen method. While the solvers ending with general is only suited to x-independent thermal conductivities, the solvers ending with k(x) take into account x-dependent thermal conductivities. In general, the solver implicit_k(x)
works for all the systems but is computationally more heavy (more time consuming)
The single_object
class solves numerically the heat conduction equation for a single thermal object, in which domains can have different materials. This class inherits the methods of the object
class. To create a single thermal object type
>>> foo = ht.single_object(amb_temperature, materials=('Cu',), borders=(1, 11),
... materials_order=(0,), dx=0.01, 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.)
The input variables are the following:
amb_temperature
: ambient temperature of the whole systemmaterials
: tuple of strings of all the used materials present in the folder materialsborders
: tuple of the points where there is a change of materialmaterials_order
: tuple of thematerials
list indexes that defines the material properties given byborders
dx
: the space stepdt
: the times stepfile_name
: file name where the temperature and heat flux are savedboundaries
: tuple of two entries that define the boundary condition for temperature. If 0 the boundary condition is insulationQ
: list of fixed heat source coefficient.Q0
: list of temperature dependent heat source coefficient.heat_points
: tuple of the space indexes where we want to extract the heat flux. Normally, the first term is the heat flux of the hot end and the second term is the heat flux of the cold endinitial_state
: initial state of the materials.True
if the field is applied andFalse
if the field is removed.h_left
: left heat transfer coefficienth_right
: right heat transfer coefficient
To compute the single_object
type
>>> foo.compute(time_interval, write_interval, solver='explicit_k(x)',
... modeTemp=False, numFlag=0.5, modeTempPoint=1):
This method computes the system for time_interval
, and writes into the file_name
file every write_interval
time steps. The four different solvers pointed out for the system_objects
class can be used. heat_points
is a list that defines the points where the heat flux are calculated if modeTemp
is True
the compute method stops when the point modeTempPoint
changes numFlag
relative to the initial value
The following example computes a simple 1-dimensional model with 0.5 m of gadolinium (Gd). The system is initial at 293 K. One end of the system is at a fixed temperature of 300 K, while the other end is insulated. The used time step is 1 second, and the used space step is 0.05 m, so that the overall number of space points is 10. The system is initially deactivated. To create the model we initialize the object example
:
>>> example = ht.single_object(293, materials=['Gd'], borders=[1,11], materialsOrder=[0],
... dx=0.05, dt=1., fileName='example.txt', boundaries=[300,0],
... Q=[], Q0=[], initialState=False)
Then we compute the system for 30000 s, write the output values every 300 s, using the 'implicit_k(x)' solver:
>>> example.compute(30000, 300, solver='implicit_k(x)')
Afterwards we activate the whole system:
example.activate(1, 10)
and we compute the system for 30000 s one more time:
>>> example.compute(30000, 300, solver='implicit_k(x)')
The output data is stored in file example.txt. To visualize the temperature as a function of time for the point index 3 we use the physplotlib library and write:
>>> import physplotlib as pp
>>> example_visualization = pp.statplot()
>>> example_visualization.loadFile('example.txt')
>>> example_visualization.verticalPlot([0], [0], [[3]], y_title='temperature (K)')
This code will output the following time-dependent temperature plot:
As expected the temperature will tend to the 300 K fixed temperature. The activation of the material at 30000 s makes the temperature to jump to ~ 302 K.The purpose of the heatrapy package is to provide a framework in computing heat transfer processes in solids involving caloric effects, so that different systems can be computed. The developed model systems are included in the systems folder. At the momento it includes two different systems for caloric devices: a fully solid state device and an hydraulic active regenerative device. The computation is performed by executing the respective function, which is described for both systems below.
To compute a fully solid state caloric system the function solid_active_regenerator
must be called. The active regenerative processes can be used with the several allowed modes for application and removal of fields. Cascades of materials can also be computed. To run one simulation type
>>> ht.solid_active_regenerator(file_name, amb_temperature=293,
... left_thermalswitch_length=2,
... right_thermalswitch_length=2, MCM_length=20,
... right_reservoir_length=3, left_reservoir_length=3,
... MCM_material=((0.002, 'Gd'),),
... left_thermalswitch_material='idealTS_hot',
... right_thermalswitch_material='idealTS_cold',
... left_reservoir_material='Cu',
... right_reservoir_material='Cu',
... freq=.1, dt=.01, dx=0.002, stop_criteria=5e-3,
... solver='implicit_k(x)', min_cycle_number=30,
... max_cycle_number=31, field_removal_steps=3,
... field_applied_steps=1,
... field_removal_mode='accelerated_right',
... field_applied_mode='accelerated_left',
... cycle_points=25, boundaries=(293, 293), note=None,
... temperature_sensor='default',
... heat_points='default', mode='refrigerator',
... version=None, resting_time_hot='default',
... resting_time_cold='default',
... starting_field='applied',
... type_study='fixed_temperature_span',
... h_left=50000., h_right=50000.,
... mod_freq='default')
The input variables are the following:
file_name
: file name where the temperature and heat flux are savedamb_temperature
: ambient temperature of the whole systemleft_thermalswitch_length
: length of the left thermal switchright_thermalswitch_length
: length of the right thermal switchleft_thermalswitch_material
: string for the material of the left thermal switchright_thermalswitch_material
: string for the material of the right thermal switchMCM_length
: length of the caloric materialMCM_material
: string for the material of the caloric materialleft_reservoir_length
: length of the left reservoirright_reservoir_length
: length of the right reservoirleft_reservoir_material
: string for the material of the left reservoirright_reservoir_material
: string for the material of the right reservoirfreq
: operating frequencydt
: times stepdx
: space stepstop_criteria
: error threshold to stop the simulationsolver
: solvermin_cycle_number
: minimum number of cycles that has to be computedmax_cycle_number
: maximum number of cycles that has to be computedfield_removal_steps
: number of steps during the field removalfield_applied_steps
: number of steps during the application of fieldfield_removal_mode
: mode of field removal modes can beconstant_right
,constant_left
,accelerated_right
,accelerated_left
,decelerated_right
, anddecelerated_left
field_applied_mode
: the mode of the application of field modes can beconstant_right
,constant_left
,accelerated_right
,accelerated_left
,decelerated_right
, anddecelerated_left
cycle_points
: number of points recorded for each position for each cycleboundaries
: tuple with the boundary conditionstemperature_sensor
: tuple of two space indexes used to determine the temperature span at the end of the simulation. The first term is the sensor at the hot end and the second at the cold endheat_points
: tuple of two space indexes used to determine the heat flux for the hot end (first term) and cold end (second term)mode
: mode used for the power calculations (e.g. COP) performed at the end of the simulation. It can be'refrigerator'
or'heat_pump'
version
: heatrapy version (default is None)type_study
: 'no_load' or 'fixed_temperature_span'h_left
: left heat transfer coefficienth_right
: right heat transfer coefficientmod_freq
: if not'default'
, i.e. if tuple, allows to modulate the frequency according to a specific temperature. The first element is the file_name, and second the sensor point.
To compute a hydraulic active caloric regenerative system the function fluid_active_regenerator
must be called. The active regenerative processes can be used with the several allowed modes for application and removal of fields. Cascades of materials can also be computed. To run one simulation type
>>> ht.fluid_active_regenerator(file_name, amb_temperature=298, fluid_length=160,
... MCM_length=50, right_reservoir_length=20,
... left_reservoir_length=20,
... MCM_material=((0.000, 'Gd'),),
... fluid_material='water',
... left_reservoir_material='Cu',
... right_reservoir_material='Cu', freq=0.17, dt=0.1,
... dx=0.001, stop_criteria=1e-6,
... solver='implicit_k(x)', min_cycle_number=1,
... max_cycle_number=5000, cycle_points=25, note=None,
... boundaries=((2, 298), (3, 0)), mode='heat_pump',
... version=None, leftHEXpositions=10,
... rightHEXpositions=10, starting_field='applied',
... temperature_sensor=(3, -3), field_removal_steps=1,
... field_applied_steps=1,
... field_removal_mode='accelerated_left',
... field_applied_mode='accelerated_right',
... applied_static_field_time_ratio=(0., 0.),
... removed_static_field_time_ratio=(0., 0.),
... h_mcm_fluid=1,
... h_leftreservoir_fluid=1,
... h_rightreservoir_fluid=1,
... mcm_discontinuity='default',
... type_study='no_load', stroke=.02,
... mod_freq='default'):
The input variables are the following:
file_name
: file name where the temperature and heat flux are savedamb_temperature
: ambient temperature of the whole systemfluid_length
: length of the fluidfluid_material
: string for the material of the fluidMCM_length
: length of the magnetocaloric materialMCM_material
: string for the material of the magnetocaloric materialleft_reservoir_length
: length of the left reservoirright_reservoir_length
: length of the right reservoirleft_reservoir_material
: string for the material of the left reservoirright_reservoir_material
: string for the material of the right reservoirfreq
: operating frequencydt
: times stepdx
: space stepstop_criteria
: error threshold to stop the simulationsolver
: solvermin_cycle_number
: minimum number of cycles that has to be computedmax_cycle_number
: maximum number of cycles that has to be computedfield_removal_steps
: number of steps during the field removalfield_applied_steps
: number of steps during the application of fieldfield_removal_mode
: mode of the field removal modes can beconstant_right
,constant_left
,accelerated_right
,accelerated_left
,decelerated_right
, anddecelerated_left
field_applied_mode
is the mode of the application of field modes can beconstant_right
,constant_left
,accelerated_right
,accelerated_left
,decelerated_right
, anddecelerated_left
cycle_points
: number of points recorded for each position for each cycleboundaries
: tuple of two entries that define the boundary condition for temperature. The first corresponds to the thermal object while the second defines the temperature. If 0 the boundary condition is insulationtemperature_sensor
: tuple of two space indexes used to determine the temperature span at the end of the simulation. The first term is the sensor at the hot end and the second at the cold endmode
: mode used for the power calculations (e.g. COP) performed at the end of the simulation. It can be'refrigerator'
or'heat_pump'
version
: heatrapy version (default is None)type_study
:'no_load'
or'fixed_temperature_span'
h_mcm_fluid
: heat transfer coefficient for fluid - MCMh_leftreservoir_fluid
: heat transfer coefficient for fluid - left reservoirh_rigthreservoir_fluid
: heat transfer coefficient for fluid - right reservoirmod_freq
: if not'default'
, i.e. if a tuple, it allows to modulate the frequency according to a specific temperature. The first element of the tuple is the file_name, and second the sensor point.velocity
: velocity of the fluidleftHEXpositions
: distance in points from the left reservoir to the MCMrightHEXpositions
: distance in points from the right reservoir to the MCM.applied_static_field_time_ratio
: tuple with the resting time ratios before and after the application of the field.removed_static_field_time_ratio
: tuple with the resting time ratios before and after the removal of the field.mcm_discontinuity
: if not'default'
the MCM is divided into n pieces. The input is a tuple where the first entry is the number of discontinuities, while the second is the thickness of each discontinuity in meters.