Skip to content

Commit

Permalink
don not push
Browse files Browse the repository at this point in the history
  • Loading branch information
daklauss committed Dec 6, 2024
1 parent 22e147c commit d6c4ebd
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 71 deletions.
142 changes: 71 additions & 71 deletions CADETProcess/processModel/componentSystem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import defaultdict
from functools import wraps
from typing import List, Dict as TypingDict
from typing import NoReturn

from addict import Dict

Expand Down Expand Up @@ -40,19 +40,19 @@ class Component(Structure):
Attributes
----------
name : String
name : str | None
Name of the component.
species : list
List of Subspecies.
n_species : int
Number of Subspecies.
label : list
Name of component (including species).
charge : list
charge : int | list[int | None]
Charge of component (including species).
molecular_weight : list
molecular_weight : float | list[float | None]
Molecular weight of component (including species).
density : list
density : float | list[float | None]
Density of component (including species).
See Also
Expand All @@ -64,29 +64,29 @@ class Component(Structure):
name: String = String()

def __init__(
self,
name: str | None = None,
species: str | List[str | None] = None,
charge: int | List[int | None] = None,
molecular_weight: float| List[float | None] = None,
density: List[float | None] = None
) -> None:
self,
name: str | None = None,
species: str | list[str | None] = None,
charge: int | list[int | None] = None,
molecular_weight: float| list[float | None] = None,
density: float | list[float | None] = None
) -> NoReturn:
"""
Parameters
----------
name : str, optional
name : str | None
Name of the component.
species : str or list of str, optional
species : str | list[str | None]
Names of the subspecies.
charge : int or list of int or None, optional
charge : int | list [int | None]
Charges of the subspecies.
molecular_weight : float or list of float or None, optional
molecular_weight : float | list[float | None]
Molecular weights of the subspecies.
density : list
density : float | list[float | None]
Density of component (including species).
"""
self.name: str | None = name
self._species: List[Species] = []
self._species: list[Species] = []

if species is None:
self.add_species(name, charge, molecular_weight, density)
Expand All @@ -105,17 +105,17 @@ def __init__(
raise CADETProcessError("Could not determine number of species")

@property
def species(self) -> List[Species]:
def species(self) -> list[Species]:
"""list: The subspecies of the component."""
return self._species

@wraps(Species.__init__)
def add_species(
self,
species: str| Species ,
*args,
**kwargs
) -> Species:
self,
species: str| Species ,
*args,
**kwargs
) -> Species:
"""
Add a subspecies to the component.
Expand All @@ -142,23 +142,23 @@ def n_species(self) -> int:
return len(self.species)

@property
def label(self) -> List[str]:
"""list of str: The names of the subspecies."""
def label(self) -> list[str]:
"""list[str]: The names of the subspecies."""
return [spec.name for spec in self.species]

@property
def charge(self) -> List[int | None]:
"""list of int or None: The charges of the subspecies."""
def charge(self) -> list[int | None]:
"""list[int | None]: The charges of the subspecies."""
return [spec.charge for spec in self.species]

@property
def molecular_weight(self) -> List[float | None]:
"""list of float or None: The molecular weights of the subspecies."""
def molecular_weight(self) -> list[float | None]:
"""list[float | None]: The molecular weights of the subspecies."""
return [spec.molecular_weight for spec in self.species]

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

def __str__(self) -> str:
Expand All @@ -179,25 +179,25 @@ class ComponentSystem(Structure):
----------
name : String
Name of the component system.
components : list
components : list[Component]
List of individual components.
n_species : int
Number of Subspecies.
n_comp : int
Number of all component species.
n_components : int
Number of components.
indices : dict
indices : dict[str, list[int]]
Component indices.
names : list
names : list[str]
Names of all components.
species : list
species : list[str]
Names of all component species.
charges : list
charges : list[int | None]
Charges of all components species.
molecular_weights : list
molecular_weights : list[float | None]
Molecular weights of all component species.
densities : list
densities : list[float | None]
Densities of all component species.
See Also
Expand All @@ -209,27 +209,27 @@ class ComponentSystem(Structure):
name: String = String()

def __init__(
self,
components: int | List[str | Component | None] = None,
name: str | None = None,
charges: List[int | None] = None,
molecular_weights: List[float | None] = None,
densities: List[float | None] = None
) -> None:
self,
components: int | list[str | Component | None] = None,
name: str | None = None,
charges: list[int | None] = None,
molecular_weights: list[float | None] = None,
densities: list[float | None] = None
) -> None:
"""Initialize the ComponentSystem object.
Parameters
----------
components : int, list, None
components : int | list[str | Component | None]
The number of components or the list of components to be added.
If None, no components are added.
name : str, None
The name of the ComponentSystem.
charges : list, None
charges : list[int | None]
The charges of each component.
molecular_weights : list, None
molecular_weights : list[float | None]
The molecular weights of each component.
densities : list, None
densities : list[float | None]
The densities of each component.
Raises
Expand All @@ -240,7 +240,7 @@ def __init__(
"""

self.name: str | None = name
self._components: List[Component] = []
self._components: list[Component] = []

if components is None:
return
Expand Down Expand Up @@ -269,12 +269,12 @@ def __init__(
)

@property
def components(self) -> List[Component]:
def components(self) -> list[Component]:
"""list: List of components in the system."""
return self._components

@property
def components_dict(self) -> TypingDict[str, Component]:
def components_dict(self) -> dict[str, Component]:
"""dict: Components indexed by name."""
return {
name: comp
Expand All @@ -298,11 +298,11 @@ def n_species(self) -> int:

@wraps(Component.__init__)
def add_component(
self,
component: str | Component,
*args: list,
**kwargs: dict
) -> None:
self,
component: str | Component,
*args: list,
**kwargs: dict
) -> NoReturn:
"""
Add a component to the system.
Expand All @@ -327,7 +327,7 @@ def add_component(

self._components.append(component)

def remove_component(self, component: str | Component) -> None:
def remove_component(self, component: str | Component) -> NoReturn:
"""Remove a component from the system.
Parameters
Expand All @@ -353,7 +353,7 @@ def remove_component(self, component: str | Component) -> None:
self._components.remove(component)

@property
def indices(self) -> TypingDict[str, List[int]]:
def indices(self) -> dict[str, list[int]]:
"""dict: List of species indices for each component name."""
indices = defaultdict(list)

Expand All @@ -366,7 +366,7 @@ def indices(self) -> TypingDict[str, List[int]]:
return Dict(indices)

@property
def species_indices(self) -> TypingDict[str, int]:
def species_indices(self) -> dict[str, int]:
"""dict: Indices for each species."""
indices = Dict()

Expand All @@ -379,8 +379,8 @@ def species_indices(self) -> TypingDict[str, int]:
return indices

@property
def names(self) -> List[str]:
"""list: List of component names."""
def names(self) -> list[str]:
"""list[str]: List of component names."""
names = [
comp.name if comp.name is not None else str(i)
for i, comp in enumerate(self.components)
Expand All @@ -389,8 +389,8 @@ def names(self) -> List[str]:
return names

@property
def species(self) -> List[str]:
"""list: List of species names."""
def species(self) -> list[str]:
"""list[str]: List of species names."""
species = []
index = 0
for comp in self.components:
Expand All @@ -405,26 +405,26 @@ def species(self) -> List[str]:
return species

@property
def charges(self) -> List[int | None]:
"""list: List of species charges."""
def charges(self) -> list[int | None]:
"""list[int | None]: List of species charges."""
charges = []
for comp in self.components:
charges += comp.charge

return charges

@property
def molecular_weights(self) -> List[float | None]:
"""list: List of species molecular weights."""
def molecular_weights(self) -> list[float | None]:
"""list[float | None]: List of species molecular weights."""
molecular_weights = []
for comp in self.components:
molecular_weights += comp.molecular_weight

return molecular_weights

@property
def densities(self) -> List[float | None]:
"""list: List of species densities."""
def densities(self) -> list[float | None]:
"""list[float | None]: List of species densities."""
densities = []
for comp in self.components:
densities += comp.density
Expand Down
6 changes: 6 additions & 0 deletions mytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import pytest



args = ["tests", "-m", "not slow"]
pytest.main(args)

0 comments on commit d6c4ebd

Please sign in to comment.