-
Notifications
You must be signed in to change notification settings - Fork 54
/
properties_toolbox.py
146 lines (130 loc) · 5.67 KB
/
properties_toolbox.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Copyright (c) 2020 by Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
import numpy as np
def calculate_mixture_viscosity(components_viscosities, components_molar_proportions,
components_molar_mass):
"""
Todo: Fill out parameters.
:param component_viscosities:
:type component_viscosities:
:param component_proportions:
:type component_proportions:
:param component_molar_mass:
:type component_molar_mass:
:return:
:rtype:
"""
shape = np.shape(components_viscosities)
if len(shape) == 1:
com_array = np.empty([shape[0], 5], dtype=np.float64)
com_array[:, 0] = components_viscosities
com_array[:, 1] = components_molar_proportions
com_array[:, 2] = components_molar_mass
com_array[:, 3] = com_array[:, 0] * com_array[:, 1] * np.sqrt(com_array[:, 2])
com_array[:, 4] = com_array[:, 1] * np.sqrt(com_array[:, 2])
res = com_array[:, 3].sum() / com_array[:, 4].sum()
else:
com_array = np.empty([shape[0], shape[1], 5], dtype=np.float64)
com_array[:, :, 0] = components_viscosities
com_array[:, :, 1] = np.reshape(components_molar_proportions.repeat(shape[1]), shape)
com_array[:, :, 2] = np.reshape(components_molar_mass.repeat(shape[1]), shape)
com_array[:, :, 3] = com_array[:, :, 0] * com_array[:, :, 1] * np.sqrt(com_array[:, :, 2])
com_array[:, :, 4] = com_array[:, :, 1] * np.sqrt(com_array[:, :, 2])
res = com_array[:, :, 3].sum(axis=0) / com_array[:, :, 4].sum(axis=0)
return res
def calculate_mixture_density(components_density, components_mass_proportions):
"""
Todo: Fill out parameters.
:param component_density:
:type component_density:
:param component_molar_proportions:
:type component_molar_proportions: ?, default None
:param component_mass_proportions:
:type component_mass_proportions: ?, default None
:return:
:rtype:
"""
shape = np.shape(components_density)
if len(shape) == 1:
com_array = np.empty([shape[0], 3], dtype=np.float64)
com_array[:, 0] = components_mass_proportions
com_array[:, 1] = components_density
com_array[:, 2] = com_array[:, 0] / com_array[:, 1]
res = 1 / com_array[:, 2].sum()
else:
com_array = np.empty([shape[0], shape[1], 3], dtype=np.float64)
com_array[:, :, 0] = np.reshape(components_mass_proportions.repeat(shape[1]), shape)
com_array[:, :, 1] = components_density
com_array[:, :, 2] = com_array[:, :, 0] / com_array[:, :, 1]
res = 1 / com_array[:, :, 2].sum(axis=0)
return res
def calculate_mixture_heat_capacity(components_capacity, components_mass_proportions):
"""
Todo: Fill out parameters.
:param components_capacity:
:type components_capacity:
:param components_mass_proportions:
:type components_mass_proportions:
:return:
:rtype:
"""
shape = np.shape(components_capacity)
if len(shape) == 1:
com_array = np.empty([shape[0], 3], dtype=np.float64)
com_array[:, 0] = components_mass_proportions
com_array[:, 1] = components_capacity
com_array[:, 2] = com_array[:, 1] * com_array[:, 0]
res = com_array[:, 2].sum()
else:
com_array = np.empty([shape[0], shape[1], 3], dtype=np.float64)
com_array[:, :, 0] = np.reshape(components_mass_proportions.repeat(shape[1]), shape)
com_array[:, :, 1] = components_capacity
com_array[:, :, 2] = com_array[:, :, 1] * com_array[:, :, 0]
res = com_array[:, :, 2].sum(axis=0)
return res
def calculate_mixture_molar_mass(components_molar_mass, components_molar_proportions=None,
components_mass_proportions=None):
"""
Todo: Fill out parameters.
:param component_molar_mass:
:type component_molar_mass:
:param component_molar_proportions:
:type component_molar_proportions: ?, default None
:param component_mass_proportions:
:type component_mass_proportions: ?, default None
:return:
:rtype:
"""
if components_molar_proportions is not None:
com_array = np.empty([len(components_molar_proportions), 3], dtype=np.float64)
com_array[:, 0] = components_molar_proportions
com_array[:, 1] = components_molar_mass
com_array[:, 2] = com_array[:, 0] * com_array[:, 1]
res = com_array[:, 2].sum()
elif components_mass_proportions is not None:
com_array = np.empty([len(components_mass_proportions), 3], dtype=np.float64)
com_array[:, 0] = components_mass_proportions
com_array[:, 1] = components_molar_mass
com_array[:, 2] = com_array[:, 0] / com_array[:, 1]
res = 1 / com_array[:, 2].sum()
else:
raise (AttributeError('at least one needs to be different from None: '
'component_molar_proportions, component_mass_proportions'))
return res
def calculate_mass_fraction_from_molar_fraction(component_molar_proportions, component_molar_mass):
"""
Todo: Fill out parameters.
:param component_molar_proportions:
:type component_molar_proportions:
:param component_molar_mass:
:type component_molar_mass:
:return:
:rtype:
"""
com_array = np.empty([len(component_molar_proportions), 4], dtype=np.float64)
com_array[:, 0] = component_molar_proportions
com_array[:, 1] = component_molar_mass
com_array[:, 2] = com_array[:, 0] * com_array[:, 1]
com_array[:, 3] = com_array[:, 2] / com_array[:, 2].sum()
return com_array[:, 3]