Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymatlib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rahil Doshi
pymatlib
Commits
2fd67529
Commit
2fd67529
authored
3 months ago
by
Rahil Doshi
Browse files
Options
Downloads
Patches
Plain Diff
Update specific enthalpy models
parent
6a96db24
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pymatlib/core/models.py
+79
-14
79 additions, 14 deletions
src/pymatlib/core/models.py
with
79 additions
and
14 deletions
src/pymatlib/core/models.py
+
79
−
14
View file @
2fd67529
...
@@ -163,28 +163,93 @@ def thermal_diffusivity_by_heat_conductivity(
...
@@ -163,28 +163,93 @@ def thermal_diffusivity_by_heat_conductivity(
# TODO: Add models for specific_enthalpy (h)
# TODO: Add models for specific_enthalpy (h)
def
specific_enthalpy_sensible
(
def
specific_enthalpy_sensible
(
temperature
:
Union
[
float
,
sp
.
Symbol
],
T
:
Union
[
float
,
sp
.
Symbol
],
temperature_array
:
np
.
ndarray
,
heat_capacity
:
Union
[
float
,
MaterialProperty
])
\
heat_capacity
:
Union
[
float
,
MaterialProperty
])
\
->
MaterialProperty
:
->
MaterialProperty
:
"""
Calculate specific enthalpy array using heat capacity only.
h(T_i) = h(T_(i-1)) + c_p(T_i)*(T_i - T_(i-1))
"""
print
(
"
Entering specific_enthalpy_sensible
"
)
# Validate temperature array is sorted
if
not
np
.
all
(
temperature_array
[:
-
1
]
<=
temperature_array
[
1
:]):
raise
ValueError
(
"
Temperature array must be sorted in ascending order for correct enthalpy calculation.
"
)
# print(temperature_array)
print
(
temperature_array
.
shape
)
# Initialize enthalpy array
enthalpy_array
=
np
.
zeros_like
(
temperature_array
)
# Calculate initial enthalpy at the first temperature
T_0
=
temperature_array
[
0
]
cp_0
=
heat_capacity
.
evalf
(
T
,
T_0
)
print
(
T_0
,
cp_0
)
heat_capacity_expr
,
sub_assignments
\
# Calculate enthalpy at first temperature point
=
_prepare_material_expressions
(
heat_capacity
)
enthalpy_array
[
0
]
=
cp_0
*
T_0
specific_enthalpy_expr
=
temperature
*
heat_capacity_expr
# Iterate through temperature points to calculate enthalpy incrementally
return
MaterialProperty
(
specific_enthalpy_expr
,
sub_assignments
)
for
i
in
range
(
1
,
len
(
temperature_array
)):
T_i
=
temperature_array
[
i
]
T_prev
=
temperature_array
[
i
-
1
]
# Evaluate material properties at current temperature
cp_i
=
heat_capacity
.
evalf
(
T
,
T_i
)
def
specific_enthalpy_with_latent_heat
(
# Calculate enthalpy increment
temperature
:
Union
[
float
,
sp
.
Symbol
],
sensible_heat
=
cp_i
*
(
T_i
-
T_prev
)
heat_capacity
:
Union
[
float
,
MaterialProperty
],
latent_heat
:
Union
[
float
,
MaterialProperty
])
\
->
MaterialProperty
:
(
heat_capacity_expr
,
latent_heat_expr
),
sub_assignments
\
# Update enthalpy
=
_prepare_material_expressions
(
heat_capacity
,
latent
_heat
)
enthalpy_array
[
i
]
=
enthalpy_array
[
i
-
1
]
+
sensible
_heat
specific_enthalpy_expr
=
temperature
*
heat_capacity_expr
+
latent_heat_expr
from
pymatlib.core.interpolators
import
interpolate_property
return
MaterialProperty
(
specific_enthalpy_expr
,
sub_assignments
)
return
interpolate_property
(
T
,
temperature_array
,
enthalpy_array
)
def
specific_enthalpy_with_latent_heat
(
T
:
Union
[
float
,
sp
.
Symbol
],
temperature_array
:
np
.
ndarray
,
heat_capacity
:
MaterialProperty
,
latent_heat
:
MaterialProperty
)
->
MaterialProperty
:
"""
Calculate specific enthalpy array using heat capacity and latent heat.
h(T_i) = h(T_(i-1)) + c_p(T_i)*(T_i - T_(i-1)) + [L(T_i) - L(T_(i-1))]
"""
print
(
"
Entering specific_enthalpy_with_latent_heat
"
)
# Validate temperature array is sorted
if
not
np
.
all
(
temperature_array
[:
-
1
]
<=
temperature_array
[
1
:]):
raise
ValueError
(
"
Temperature array must be sorted in ascending order for correct enthalpy calculation.
"
)
# print(temperature_array)
print
(
temperature_array
.
shape
)
# Initialize enthalpy array
enthalpy_array
=
np
.
zeros_like
(
temperature_array
)
# Calculate initial enthalpy at the first temperature
T_0
=
temperature_array
[
0
]
cp_0
=
heat_capacity
.
evalf
(
T
,
T_0
)
L_0
=
latent_heat
.
evalf
(
T
,
T_0
)
print
(
T_0
,
cp_0
,
L_0
)
# Calculate enthalpy at first temperature point
enthalpy_array
[
0
]
=
cp_0
*
T_0
+
L_0
# Iterate through temperature points to calculate enthalpy incrementally
for
i
in
range
(
1
,
len
(
temperature_array
)):
T_i
=
temperature_array
[
i
]
T_prev
=
temperature_array
[
i
-
1
]
# Evaluate material properties at current temperature
cp_i
=
heat_capacity
.
evalf
(
T
,
T_i
)
L_i
=
latent_heat
.
evalf
(
T
,
T_i
)
L_prev
=
latent_heat
.
evalf
(
T
,
T_prev
)
# Calculate enthalpy increment
sensible_heat
=
cp_i
*
(
T_i
-
T_prev
)
latent_heat_change
=
L_i
-
L_prev
# Update enthalpy
enthalpy_array
[
i
]
=
enthalpy_array
[
i
-
1
]
+
sensible_heat
+
latent_heat_change
from
pymatlib.core.interpolators
import
interpolate_property
return
interpolate_property
(
T
,
temperature_array
,
enthalpy_array
)
def
energy_density
(
def
energy_density
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment