-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathtest_unitCell.py
More file actions
67 lines (63 loc) · 2.73 KB
/
test_unitCell.py
File metadata and controls
67 lines (63 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from udkm1Dsim import Atom
from udkm1Dsim import UnitCell
from udkm1Dsim import u
u.default_format = '~P'
import numpy as np
def test_unit_cell():
Fe = Atom('Fe')
uc = UnitCell('uc', 'Unit Cell', 2.86*u.angstrom, heat_capacity=10*(u.J/u.kg/u.K),
lin_therm_exp=1e-6/u.K, therm_cond=1*(u.W/u.m/u.K),
opt_pen_depth=11*u.nm, sound_vel=5*(u.nm/u.ps))
uc.add_atom(Fe, '0*(s+1)')
uc.add_atom(Fe, '0.5*(s+1)')
assert uc.id == 'uc'
assert uc.name == 'Unit Cell'
assert uc.a_axis == 2.86*u.angstrom
assert uc.b_axis == 2.86*u.angstrom
assert uc.c_axis == 2.86*u.angstrom
assert uc.heat_capacity[0](300) == 10
assert uc.lin_therm_exp[0](300) == 1e-6
assert uc.therm_cond[0](300) == 1
assert uc.opt_pen_depth == 11*u.nm
assert uc.sound_vel == 5*(u.nm/u.ps)
# test temperature-dependent parameters for float input
uc.num_sub_systems = 2
uc.heat_capacity = [10, 1000]
uc.therm_cond = [10, 1000]
uc.lin_therm_exp = [10, 1000]
assert uc.heat_capacity_str == ['10', '1000']
assert uc.heat_capacity[0](300) == 10
assert uc.heat_capacity[1](300) == 1000
assert uc.therm_cond_str == ['10', '1000']
assert uc.therm_cond[0](300) == 10
assert uc.therm_cond[1](300) == 1000
assert uc.lin_therm_exp_str == ['10', '1000']
assert uc.lin_therm_exp[0](300) == 10
assert uc.lin_therm_exp[1](300) == 1000
# test temperature-dependent parameters for str function input
uc.heat_capacity = ['10*T', 'exp(300-T)+300']
uc.therm_cond = ['10*T', 'exp(300-T)+300']
uc.lin_therm_exp = ['10*T', 'exp(300-T)+300']
assert uc.heat_capacity_str == ['10*T', 'exp(300-T)+300']
assert uc.heat_capacity[0](300) == 3000
assert uc.heat_capacity[1](300) == 301
assert uc.therm_cond_str == ['10*T', 'exp(300-T)+300']
assert uc.therm_cond[0](300) == 3000
assert uc.therm_cond[1](300) == 301
assert uc.lin_therm_exp_str == ['10*T', 'exp(300-T)+300']
assert uc.lin_therm_exp[0](300) == 3000
assert uc.lin_therm_exp[1](300) == 301
# check backward compatibility
uc.heat_capacity = ['lambda T: 10*T', 'lambda T: exp(300-T)+300']
assert uc.heat_capacity_str == ['10*T', 'exp(300-T)+300']
assert uc.heat_capacity[0](300) == 3000
assert uc.heat_capacity[1](300) == 301
# check subsystem temperatures
uc.therm_cond = ['10*T_0 + 30*T_1', 'exp(300-T_1)+300']
assert uc.therm_cond[0](np.array([300, 300])) == 12000
assert uc.therm_cond[1](np.array([300, 300])) == 301
uc.sub_system_coupling = ['500*(T_0-T_1)', 'lambda T: -500*(T[0]-T[1])']
assert uc.sub_system_coupling[0](np.array([301, 300])) == 500
assert uc.sub_system_coupling[1](np.array([301, 300])) == -500