Skip to content

Commit

Permalink
Add density to ComponentSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
schmoelder committed Aug 26, 2024
1 parent 31590d5 commit 7734a40
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions CADETProcess/processModel/componentSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ class Species(Structure):
The charge of the species. Default is 0.
molecular_weight : float
The molecular weight of the species.
density : float
Density of the species.
"""
name = String()
charge = Integer(default=0)
molecular_weight = UnsignedFloat()
density = UnsignedFloat()


class Component(Structure):
Expand All @@ -50,6 +53,8 @@ class Component(Structure):
Charge of component (including species).
molecular_weight : list
Molecular weight of component (including species).
density : list
Density of component (including species).
See Also
--------
Expand All @@ -60,7 +65,13 @@ class Component(Structure):
name = String()

def __init__(
self, name=None, species=None, charge=None, molecular_weight=None):
self,
name=None,
species=None,
charge=None,
molecular_weight=None,
density=None
):
"""
Parameters
----------
Expand All @@ -72,14 +83,16 @@ def __init__(
Charges of the subspecies.
molecular_weight : float or list of float or None, optional
Molecular weights of the subspecies.
density : list
Density of component (including species).
"""
self.name = name
self._species = []

if species is None:
self.add_species(name, charge, molecular_weight)
self.add_species(name, charge, molecular_weight, density)
elif isinstance(species, str):
self.add_species(species, charge, molecular_weight)
self.add_species(species, charge, molecular_weight, density)
elif isinstance(species, list):
if charge is None:
charge = len(species) * [None]
Expand Down Expand Up @@ -136,6 +149,11 @@ def molecular_weight(self):
"""list of float or None: The molecular weights of the subspecies."""
return [spec.molecular_weight for spec in self.molecular_weight]

@property
def density(self):
"""list of float or None: The density of the subspecies."""
return [spec.density for spec in self.density]

def __str__(self):
"""String representation of the component."""
return self.name
Expand Down Expand Up @@ -379,6 +397,15 @@ def molecular_weights(self):

return molecular_weights

@property
def densities(self):
"""list: List of species densities."""
densities = []
for comp in self.components:
densities += comp.density

return densities

def __repr__(self):
return f'{self.__class__.__name__}({self.names})'

Expand Down

0 comments on commit 7734a40

Please sign in to comment.