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
3a3d93ad
Commit
3a3d93ad
authored
2 months ago
by
Rahil Doshi
Browse files
Options
Downloads
Patches
Plain Diff
Store arrays in class PropertyArrayExtractor
parent
e81164a7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#77223
passed
2 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pymatlib/core/property_array_extractor.py
+68
-0
68 additions, 0 deletions
src/pymatlib/core/property_array_extractor.py
with
68 additions
and
0 deletions
src/pymatlib/core/property_array_extractor.py
0 → 100644
+
68
−
0
View file @
3a3d93ad
import
numpy
as
np
import
sympy
as
sp
from
dataclasses
import
dataclass
,
field
from
pymatlib.core.alloy
import
Alloy
from
pymatlib.core.typedefs
import
MaterialProperty
@dataclass
class
PropertyArrayExtractor
:
"""
Extracts arrays of property values from an Alloy at specified temperatures.
Attributes:
alloy (Alloy): The alloy object containing material properties.
temperature_array (np.ndarray): Array of temperature values to evaluate properties at.
symbol (sp.Symbol): Symbol to use for property evaluation (e.g., u.center()).
# density_array (np.ndarray): Extracted density values corresponding to temperature_array.
specific_enthalpy_array (np.ndarray): Extracted specific enthalpy values.
energy_density_array (np.ndarray): Extracted energy density values.
"""
alloy
:
Alloy
temperature_array
:
np
.
ndarray
symbol
:
sp
.
Symbol
# Arrays will be populated during extraction
# density_array: np.ndarray = field(default_factory=lambda: np.array([]))
specific_enthalpy_array
:
np
.
ndarray
=
field
(
default_factory
=
lambda
:
np
.
array
([]))
energy_density_array
:
np
.
ndarray
=
field
(
default_factory
=
lambda
:
np
.
array
([]))
def
__post_init__
(
self
):
"""
Initialize arrays after instance creation.
"""
# Extract property arrays after initialization if temperature array is provided.
if
len
(
self
.
temperature_array
)
>=
2
:
self
.
extract_all_arrays
()
def
extract_property_array
(
self
,
property_name
:
str
)
->
np
.
ndarray
:
"""
Extract array of property values at each temperature point using the provided symbol.
Args:
property_name (str): Name of the property to extract.
Returns:
np.ndarray: Array of property values corresponding to temperature_array.
Raises:
ValueError: If property doesn
'
t exist or isn
'
t a MaterialProperty.
"""
# Get the property from the alloy
property_obj
=
getattr
(
self
.
alloy
,
property_name
,
None
)
# Check if property exists
if
property_obj
is
None
:
raise
ValueError
(
f
"
Property
'
{
property_name
}
'
not found in alloy
"
)
# Check if it's a MaterialProperty
if
isinstance
(
property_obj
,
MaterialProperty
):
# Use the symbolic temperature variable from the MaterialProperty
print
(
f
"
self.symbol:
{
self
.
symbol
}
"
)
return
property_obj
.
evalf
(
self
.
symbol
,
self
.
temperature_array
)
else
:
raise
ValueError
(
f
"
Property
'
{
property_name
}
'
is not a MaterialProperty
"
)
def
extract_all_arrays
(
self
)
->
None
:
"""
Extract arrays for all supported properties.
"""
# Extract density array if available
# if hasattr(self.alloy, 'density') and self.alloy.density is not None:
# self.density_array = self.extract_property_array('density')
# Extract specific enthalpy array if available
if
hasattr
(
self
.
alloy
,
'
specific_enthalpy
'
)
and
self
.
alloy
.
specific_enthalpy
is
not
None
:
self
.
specific_enthalpy_array
=
self
.
extract_property_array
(
'
specific_enthalpy
'
)
# Extract energy density array if available
if
hasattr
(
self
.
alloy
,
'
energy_density
'
)
and
self
.
alloy
.
energy_density
is
not
None
:
self
.
energy_density_array
=
self
.
extract_property_array
(
'
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