Skip to content

Tutorials

Tutorial 1

""" This example shows how to simulate advection of temperature in a cylindrical tank without any bed material. """

import openterrace

ot = openterrace.Setup(t_end=60*10, dt=0.01, sim_name='tutorial1')

ot.fluid = ot.Phase(n=500, type='fluid')
ot.fluid.select_substance_on_the_fly(rho=1000, cp=4200, k=0.6)
ot.fluid.select_domain_shape(domain='cylinder_1d', D=0.3, H=1)
ot.fluid.select_schemes(diff='central_difference_1d', conv='upwind_1d')
ot.fluid.select_initial_conditions(T=273.15+100, mdot=0.1)
ot.fluid.select_bc(bc_type='fixedValue', parameter='T', position=(slice(None, None, None), 0), value=273.15+600)
ot.fluid.select_bc(bc_type='zeroGradient', parameter='T', position=(slice(None, None, None), -1), value=0)
ot.fluid.select_output(times=range(0, 10*60+60, 60), parameters=['T'])

ot.run_simulation()
ot.generate_plots()
ot.generate_animations()


# """ This example shows how to simulate advection of temperature in a cylindrical tank without any bed material. """

# import openterrace

# ot = openterrace.Simulate(t_end=60*10, dt=0.01, sim_name='tutorial1')

# ot.fluid = ot.Phase(n=500, type='fluid')
# ot.fluid.select_substance_on_the_fly(rho=1000, cp=4200, k=0.6)
# ot.fluid.select_domain_shape(domain='cylinder_1d', D=0.3, H=1)
# ot.fluid.select_schemes(diff='central_difference_1d', conv='upwind_1d')
# ot.fluid.select_initial_conditions(T=273.15+100, mdot=0.1)
# ot.fluid.select_bc(bc_type='fixedValue', parameter='T', position=(slice(None, None, None), 0), value=273.15+600)
# ot.fluid.select_bc(bc_type='zeroGradient', parameter='T', position=(slice(None, None, None), -1), value=0)
# ot.fluid.select_output(times=range(0, 10*60+60, 60), parameters=['T'])

# ot.run_simulation()
# ot.generate_plots()
# ot.generate_animations()

Tutorial 2

""" This example shows how to simulate heat diffusion in a sphere made out of swedish diabase stone. """

import openterrace

R = 0.025
T_init = 40+273.15
T_room = 80+273.15
h = 200

ot = openterrace.Simulate(t_end=15*60, dt=0.01, sim_name='tutorial2')

ot.bed = ot.Phase(n=50, type='bed')
ot.bed.select_substance('swedish_diabase')
ot.bed.select_domain_shape(domain='sphere_1d', R=R)
ot.bed.select_schemes(diff='central_difference_1d')
ot.bed.select_initial_conditions(T=T_init)
ot.bed.select_bc(bc_type='zeroGradient', parameter='T', position=(slice(None, None, None), 0))
ot.bed.select_bc(bc_type='zeroGradient', parameter='T', position=(slice(None, None, None), -1))
ot.bed.select_source_term(source_type='thermal_resistance', R=1/(h*4*3.14159*R**2), T_inf=T_room, position=(slice(None, None, None), -1))
ot.bed.select_output(times=range(0, 15*60+60, 60), parameters=['T'])

ot.run_simulation()
ot.generate_plots()
ot.generate_animations()

Tutorial 3

""" This example shows how to simulate heat diffusion in a hollow sphere made out of ATS58 (PCM material). """

import openterrace

Ri = 0.005
Ro = 0.025
T_init = 40+273.15
T_room = 80+273.15
h = 50

ot = openterrace.Simulate(t_end=7200, dt=0.05, sim_name='tutorial3')

ot.bed = ot.Phase(n=30, type='bed')
ot.bed.select_substance(substance='ATS58')
ot.bed.select_domain_shape(domain='hollow_sphere_1d', Rinner=Ri, Router=Ro)
ot.bed.select_schemes(diff='central_difference_1d')
ot.bed.select_initial_conditions(T=T_init)
ot.bed.select_bc(bc_type='zeroGradient', parameter='T', position=(slice(None, None, None), 0))
ot.bed.select_bc(bc_type='zeroGradient', parameter='T', position=(slice(None, None, None), -1))
ot.bed.select_source_term(source_type='thermal_resistance', R=1/(h*4*3.14159*Ro**2), T_inf=T_room, position=(slice(None, None, None), -1))
ot.bed.select_output(times=range(0, 7200, 300), parameters=['T'])

ot.run_simulation()
ot.generate_plots()
ot.generate_animations()

Tutorial 4

""" 
This example shows how to simulate a cylindrical thermal storage tank with air and spherical magnetite
stones as the bed material.
"""

import openterrace

t_end = 10*7200

ot = openterrace.Simulate(t_end=t_end, dt=0.05, sim_name='tutorial4')

ot.fluid = ot.Phase(n=100, type='fluid')
ot.fluid.select_substance(substance='air')
ot.fluid.select_domain_shape(domain='cylinder_1d', D=0.3, H=1)
ot.fluid.select_porosity(phi=0.4)
ot.fluid.select_schemes(diff='central_difference_1d', conv='upwind_1d')
ot.fluid.select_initial_conditions(T=273.15+25, mdot=0.001)
ot.fluid.select_bc(bc_type='fixedValue',
                   parameter='T',
                   position=(slice(None, None, None), 0),
                   value=273.15+500
                   )
ot.fluid.select_bc(bc_type='zeroGradient',
                   parameter='T',
                   position=(slice(None, None, None), -1)
                   )
ot.fluid.select_output(times=range(0, t_end+3600, 3600), parameters=['T'])

ot.bed = ot.Phase(n=10, n_other=100, type='bed')
ot.bed.select_substance(substance='magnetite')
ot.bed.select_domain_shape(domain='sphere_1d', R=0.05)
ot.bed.select_schemes(diff='central_difference_1d')
ot.bed.select_initial_conditions(T=273.15+25)
ot.bed.select_output(times=range(0, t_end+3600, 3600), parameters=['T'])
ot.bed.select_bc(bc_type='zeroGradient',
                   parameter='T',
                   position=(slice(None, None, None), 0)
                   )
ot.bed.select_bc(bc_type='zeroGradient',
                   parameter='T',
                   position=(slice(None, None, None), -1)
                   )

ot.select_coupling(fluid_phase=0, bed_phase=1, h_exp='constant', h_value=100)

ot.run_simulation()
ot.generate_plots()
ot.generate_animations()

Tutorial 5

""" 
This example shows how to simulate a cylindrical thermal storage tank with air and spherical magnetite
stones as the bed material. Same as other tutorial but with lumped stones.
"""

import openterrace

t_end = 10*7200

ot = openterrace.Simulate(t_end=t_end, dt=0.05, sim_name='tutorial5')

ot.fluid = ot.Phase(n=100, type='fluid')
ot.fluid.select_substance(substance='air')
ot.fluid.select_domain_shape(domain='cylinder_1d', D=0.3, H=1)
ot.fluid.select_porosity(phi=0.4)
ot.fluid.select_schemes(diff='central_difference_1d', conv='upwind_1d')
ot.fluid.select_initial_conditions(T=273.15+25, mdot=0.001)
ot.fluid.select_bc(bc_type='fixedValue',
                   parameter='T',
                   position=(slice(None, None, None), 0),
                   value=273.15+500
                   )
ot.fluid.select_bc(bc_type='zeroGradient',
                   parameter='T',
                   position=(slice(None, None, None), -1)
                   )
ot.fluid.select_output(times=range(0, t_end+3600, 3600), parameters=['T'])

ot.bed = ot.Phase(n=1, n_other=100, type='bed')
ot.bed.select_substance(substance='magnetite')
ot.bed.select_domain_shape(domain='lumped', A=4*3.14159*0.05**2, V=4/3*3.14159*0.05**3)
ot.bed.select_initial_conditions(T=273.15+25)
ot.bed.select_output(times=range(0, t_end+3600, 3600), parameters=['T'])

ot.select_coupling(fluid_phase=0, bed_phase=1, h_exp='constant', h_value=100)

ot.run_simulation()
ot.generate_plots()
ot.generate_animations()