Skip to content
2 changes: 1 addition & 1 deletion .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- name: Install
run: |
python -m pip install --upgrade pip
pip install -e ./[testing]
pip install -e . --group testing

- name: Test
if: always()
Expand Down
18 changes: 8 additions & 10 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
name: Ruff
on: [ push, pull_request ]
on:
push:
branches:
- master
- dev
pull_request:
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
- uses: astral-sh/ruff-action@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
- name: Run Ruff
run: ruff check --output-format=github .
args: check --output-format=github
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.11.7
hooks:
# Run the linter.
- id: ruff
1 change: 1 addition & 0 deletions CADETPythonSimulator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Version information."""

name = "CADET-Python-Simulator"
__version__ = "0.0.1"
59 changes: 30 additions & 29 deletions CADETPythonSimulator/componentsystem.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from CADETProcess.processModel import ComponentSystem, Component, Species
from CADETProcess.processModel import ComponentSystem, Component
from CADETProcess.dataStructure import UnsignedFloat, String, Integer
from CADETProcess.dataStructure import Structure

Expand Down Expand Up @@ -81,16 +81,18 @@ class CPSComponent(Component):

"""

def __init__(self,
name=None,
species=None,
charge=None,
molecular_weight=None,
density=None,
molecular_volume=None,
viscosity=None,
pure_density=None,
specific_cake_resistance=None):
def __init__(
self,
name=None,
species=None,
charge=None,
molecular_weight=None,
density=None,
molecular_volume=None,
viscosity=None,
pure_density=None,
specific_cake_resistance=None,
):
"""Construct CPSComponent."""
self.name = name
self._species = []
Expand All @@ -104,7 +106,7 @@ def __init__(self,
molecular_volume,
viscosity,
pure_density,
specific_cake_resistance
specific_cake_resistance,
)
elif isinstance(species, str):
self.add_species(
Expand All @@ -115,7 +117,7 @@ def __init__(self,
molecular_volume,
viscosity,
pure_density,
specific_cake_resistance
specific_cake_resistance,
)
elif isinstance(species, list):
if charge is None:
Expand All @@ -141,7 +143,7 @@ def __init__(self,
molecular_volume[i],
viscosity[i],
pure_density[i],
specific_cake_resistance[i]
specific_cake_resistance[i],
)
else:
raise CADETPythonSimError("Could not determine number of species")
Expand Down Expand Up @@ -182,6 +184,7 @@ def specific_cake_resistance(self):
"""List of float or None: specific cake resistance of the subspecies."""
return [spec.specific_cake_resistance for spec in self.species]


class CPSComponentSystem(ComponentSystem):
"""
Component System Class.
Expand Down Expand Up @@ -228,16 +231,16 @@ class CPSComponentSystem(ComponentSystem):
"""

def __init__(
self,
components=None,
name=None,
charges=None,
molecular_weights=None,
densities=None,
molecular_volume=None,
viscosities=None,
specific_cake_resistances=None
):
self,
components=None,
name=None,
charges=None,
molecular_weights=None,
densities=None,
molecular_volume=None,
viscosities=None,
specific_cake_resistances=None,
):
"""
Initialize the ComponentSystem object.

Expand Down Expand Up @@ -295,7 +298,6 @@ def __init__(
if specific_cake_resistances is None:
specific_cake_resistances = n_comp * [None]


for i, comp in enumerate(components):
self.add_component(
comp,
Expand All @@ -304,7 +306,7 @@ def __init__(
density=densities[i],
molecular_volume=molecular_volume[i],
viscosity=viscosities[i],
specific_cake_resistance=specific_cake_resistances[i]
specific_cake_resistance=specific_cake_resistances[i],
)

@wraps(CPSComponent.__init__)
Expand All @@ -327,8 +329,7 @@ def add_component(self, component, *args, **kwargs):

if component.name in self.names:
raise CADETPythonSimError(
f"Component '{component.name}' "
"already exists in ComponentSystem."
f"Component '{component.name}' already exists in ComponentSystem."
)

self._components.append(component)
Expand Down Expand Up @@ -356,7 +357,7 @@ def viscosities(self):
"""list: List of species viscosity."""
viscosities = []
for comp in self.components:
viscosities +=comp.viscosity
viscosities += comp.viscosity

return viscosities

Expand Down
14 changes: 7 additions & 7 deletions CADETPythonSimulator/coupling_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import abc
import numpy as np
from CADETPythonSimulator.unit_operation import UnitOperationBase


class CouplingInterface(abc.ABC):
Expand All @@ -10,18 +9,19 @@ class CouplingInterface(abc.ABC):
def get_coupled_state(
self,
origin_list: list[(dict, float)],
state: str
) -> np.ndarray:
state: str,
) -> np.ndarray:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add trailing comma to avoid line break. (See https://docs.astral.sh/ruff/settings/#format_skip-magic-trailing-comma).

"""Calculate new state for destination_unit."""


class WeightedAverageCoupling(CouplingInterface):
"""Implements the Coupling Interface for average Coupling."""

def get_coupled_state(self,
origin_list: list[(dict, float)],
state: str
) -> np.ndarray:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add trailing comma to avoid line break. (See https://docs.astral.sh/ruff/settings/#format_skip-magic-trailing-comma)

def get_coupled_state(
self,
origin_list: list[(dict, float)],
state: str,
) -> np.ndarray:
"""Calculate new state for destination_unit with average Coupling."""
ret = np.zeros(origin_list[0][0][state].shape)
rate_tot = 0
Expand Down
36 changes: 12 additions & 24 deletions CADETPythonSimulator/distribution_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from CADETPythonSimulator.componentsystem import CPSComponentSystem
from CADETPythonSimulator.exception import CADETPythonSimError


class DistributionBase:
"""Small wrapper class for implementing Distributions for Boundary Conditions."""

def get_distribution(t: float, section_nr: int)->np.ndarray:
def get_distribution(t: float, section_nr: int) -> np.ndarray:
"""Abtract class to call."""
pass


class ConstantVolumeDistribution(DistributionBase):
"""Implements DistributionBase for a Constant Volume Distribution."""

Expand All @@ -29,26 +31,19 @@ def __init__(self, component_system: CPSComponentSystem, c: npt.ArrayLike):

n = [i for i in self.c]
m = [
n_i * self.component_system.molecular_weights[i]
for i, n_i in enumerate(n)
]
V = [
m_i / self.component_system.densities[i]
for i, m_i in enumerate(m)
n_i * self.component_system.molecular_weights[i] for i, n_i in enumerate(n)
]
V = [m_i / self.component_system.densities[i] for i, m_i in enumerate(m)]
V_solvent = 1 - sum(V)

if V_solvent<0:
if V_solvent < 0:
raise CADETPythonSimError(
"Last species Volume is negative. Misconfigured Simulation"
)
)

V.append(V_solvent)

self.V_dist = [
i / sum(V)
for i in V
]
self.V_dist = [i / sum(V) for i in V]

def get_distribution(self, t, sec) -> list[float]:
"""Return Constant Volume Distribution."""
Expand All @@ -72,27 +67,20 @@ def __init__(self, component_system: CPSComponentSystem, c: npt.ArrayLike):
self.component_system = component_system

n = [i for i in c]
m = [
n_i * component_system.molecular_weights[i]
for i, n_i in enumerate(n)
]
V = [
m_i / component_system.densities[i]
for i, m_i in enumerate(m)
]
m = [n_i * component_system.molecular_weights[i] for i, n_i in enumerate(n)]
V = [m_i / component_system.densities[i] for i, m_i in enumerate(m)]
V_solvent = 1 - sum(V)

if V_solvent<0:
if V_solvent < 0:
raise CADETPythonSimError(
"Last species Volume is negative. Misconfigured Simulation"
)
)

m_solvent = component_system.densities[-1] * V_solvent
n_solvent = m_solvent / component_system.molecular_weights[-1]

self.c = [*c, n_solvent]


def get_distribution(self, t, sec) -> list[float]:
"""Return Constant Concentrations."""
return self.c
3 changes: 1 addition & 2 deletions CADETPythonSimulator/field.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import NoReturn, Optional, Union
from typing import Optional, Union

import numpy as np
import numpy.typing as npt
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.interpolate import RegularGridInterpolator


Expand Down
Loading
Loading