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
a7765ee0
Commit
a7765ee0
authored
3 months ago
by
Rahil Doshi
Browse files
Options
Downloads
Patches
Plain Diff
Add models for specific enthalpy
parent
3dcaa20d
No related branches found
No related tags found
No related merge requests found
Pipeline
#77256
passed
3 months ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pymatlib/core/models.py
+37
-7
37 additions, 7 deletions
src/pymatlib/core/models.py
src/pymatlib/core/yaml_parser.py
+19
-0
19 additions, 0 deletions
src/pymatlib/core/yaml_parser.py
with
56 additions
and
7 deletions
src/pymatlib/core/models.py
+
37
−
7
View file @
a7765ee0
...
@@ -75,15 +75,17 @@ def _prepare_material_expressions(*properties):
...
@@ -75,15 +75,17 @@ def _prepare_material_expressions(*properties):
"""
Prepare expressions and collect assignments from material properties.
"""
"""
Prepare expressions and collect assignments from material properties.
"""
sub_assignments
=
[]
sub_assignments
=
[]
expressions
=
[]
expressions
=
[]
for
prop
in
properties
:
for
prop
in
properties
:
if
isinstance
(
prop
,
MaterialProperty
):
if
isinstance
(
prop
,
MaterialProperty
):
sub_assignments
.
extend
(
prop
.
assignments
)
sub_assignments
.
extend
(
prop
.
assignments
)
expressions
.
append
(
prop
.
expr
)
expressions
.
append
(
prop
.
expr
)
else
:
else
:
expressions
.
append
(
sympy_wrapper
(
prop
))
expressions
.
append
(
sympy_wrapper
(
prop
))
# If there's only one expression, return it directly instead of in a list
return
expressions
,
sub_assignments
if
len
(
expressions
)
==
1
:
return
expressions
[
0
],
sub_assignments
else
:
return
expressions
,
sub_assignments
def
density_by_thermal_expansion
(
def
density_by_thermal_expansion
(
...
@@ -119,10 +121,12 @@ def density_by_thermal_expansion(
...
@@ -119,10 +121,12 @@ def density_by_thermal_expansion(
# raise ValueError(f"Thermal expansion coefficient must be between -3e-5 and 0.001, got {thermal_expansion_coefficient}")
# raise ValueError(f"Thermal expansion coefficient must be between -3e-5 and 0.001, got {thermal_expansion_coefficient}")
try
:
try
:
tec_expr
=
thermal_expansion_coefficient
.
expr
if
isinstance
(
thermal_expansion_coefficient
,
MaterialProperty
)
else
sympy_wrapper
(
thermal_expansion_coefficient
)
tec_expr
,
sub_assignments
\
sub_assignments
=
thermal_expansion_coefficient
.
assignments
if
isinstance
(
thermal_expansion_coefficient
,
MaterialProperty
)
else
[]
=
_prepare_material_expressions
(
thermal_expansion_coefficient
)
density
=
density_base
*
(
1
+
tec_expr
*
(
temperature
-
temperature_base
))
**
(
-
3
)
# tec_expr = thermal_expansion_coefficient.expr if isinstance(thermal_expansion_coefficient, MaterialProperty) else sympy_wrapper(thermal_expansion_coefficient)
return
MaterialProperty
(
density
,
sub_assignments
)
# sub_assignments = thermal_expansion_coefficient.assignments if isinstance(thermal_expansion_coefficient, MaterialProperty) else []
density_expr
=
density_base
*
(
1
+
tec_expr
*
(
temperature
-
temperature_base
))
**
(
-
3
)
return
MaterialProperty
(
density_expr
,
sub_assignments
)
except
ZeroDivisionError
:
except
ZeroDivisionError
:
raise
ValueError
(
"
Division by zero encountered in density calculation
"
)
raise
ValueError
(
"
Division by zero encountered in density calculation
"
)
...
@@ -157,6 +161,32 @@ def thermal_diffusivity_by_heat_conductivity(
...
@@ -157,6 +161,32 @@ def thermal_diffusivity_by_heat_conductivity(
raise
ValueError
(
"
Division by zero encountered in thermal diffusivity calculation
"
)
raise
ValueError
(
"
Division by zero encountered in thermal diffusivity calculation
"
)
# TODO: Add models for specific_enthalpy (h)
def
specific_enthalpy_sensible
(
temperature
:
Union
[
float
,
sp
.
Symbol
],
heat_capacity
:
Union
[
float
,
MaterialProperty
])
\
->
MaterialProperty
:
heat_capacity_expr
,
sub_assignments
\
=
_prepare_material_expressions
(
heat_capacity
)
specific_enthalpy_expr
=
temperature
*
heat_capacity_expr
return
MaterialProperty
(
specific_enthalpy_expr
,
sub_assignments
)
def
specific_enthalpy_with_latent_heat
(
temperature
:
Union
[
float
,
sp
.
Symbol
],
heat_capacity
:
Union
[
float
,
MaterialProperty
],
latent_heat
:
Union
[
float
,
MaterialProperty
])
\
->
MaterialProperty
:
(
heat_capacity_expr
,
latent_heat_expr
),
sub_assignments
\
=
_prepare_material_expressions
(
heat_capacity
,
latent_heat
)
specific_enthalpy_expr
=
temperature
*
heat_capacity_expr
+
latent_heat_expr
return
MaterialProperty
(
specific_enthalpy_expr
,
sub_assignments
)
def
energy_density
(
def
energy_density
(
density
:
Union
[
float
,
MaterialProperty
],
density
:
Union
[
float
,
MaterialProperty
],
specific_enthalpy
:
Union
[
float
,
MaterialProperty
])
\
specific_enthalpy
:
Union
[
float
,
MaterialProperty
])
\
...
...
This diff is collapsed.
Click to expand it.
src/pymatlib/core/yaml_parser.py
+
19
−
0
View file @
a7765ee0
...
@@ -14,6 +14,10 @@ from ruamel.yaml import YAML, constructor, scanner
...
@@ -14,6 +14,10 @@ from ruamel.yaml import YAML, constructor, scanner
from
difflib
import
get_close_matches
from
difflib
import
get_close_matches
from
enum
import
Enum
,
auto
from
enum
import
Enum
,
auto
from
pymatlib.core.models
import
specific_enthalpy_sensible
from
pymatlib.core.models
import
specific_enthalpy_with_latent_heat
class
PropertyType
(
Enum
):
class
PropertyType
(
Enum
):
CONSTANT
=
auto
()
CONSTANT
=
auto
()
...
@@ -1023,6 +1027,17 @@ class MaterialConfigParser:
...
@@ -1023,6 +1027,17 @@ class MaterialConfigParser:
alloy
.
heat_capacity
alloy
.
heat_capacity
)
)
},
},
'
specific_enthalpy
'
:
{
'
default
'
:
lambda
:
specific_enthalpy_sensible
(
T
,
alloy
.
heat_capacity
),
'
latent_heat_based
'
:
lambda
:
specific_enthalpy_with_latent_heat
(
T
,
alloy
.
heat_capacity
,
alloy
.
latent_heat_of_fusion
)
},
'
energy_density
'
:
{
'
energy_density
'
:
{
'
default
'
:
lambda
:
energy_density
(
'
default
'
:
lambda
:
energy_density
(
alloy
.
density
,
alloy
.
density
,
...
@@ -1046,6 +1061,10 @@ class MaterialConfigParser:
...
@@ -1046,6 +1061,10 @@ class MaterialConfigParser:
'
thermal_diffusivity
'
:
{
'
thermal_diffusivity
'
:
{
'
default
'
:
[
'
heat_conductivity
'
,
'
density
'
,
'
heat_capacity
'
],
'
default
'
:
[
'
heat_conductivity
'
,
'
density
'
,
'
heat_capacity
'
],
},
},
'
specific_enthalpy
'
:
{
'
default
'
:
[
'
heat_capacity
'
],
'
latent_heat_based
'
:
[
'
heat_capacity
'
,
'
latent_heat_of_fusion
'
],
},
'
energy_density
'
:
{
'
energy_density
'
:
{
'
default
'
:
[
'
density
'
,
'
specific_enthalpy
'
],
'
default
'
:
[
'
density
'
,
'
specific_enthalpy
'
],
# 'enthalpy_based': ['density', 'specific_enthalpy', 'latent_heat_of_fusion'],
# 'enthalpy_based': ['density', 'specific_enthalpy', 'latent_heat_of_fusion'],
...
...
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