Skip to content

Commit

Permalink
Merge pull request #8 from cadet/add-dead-end-filtration
Browse files Browse the repository at this point in the history
Add dead end filtration
  • Loading branch information
daklauss authored Jul 18, 2024
2 parents 82076af + dd31d0b commit aeb139b
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 24 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: pipeline

on:
push:
branches:
- master
- dev
- add-dead-end-filtration
- test_ci
pull_request:


jobs:
test-job:
runs-on: ubuntu-latest

defaults:
run:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

env:
CONDA_FILE: environment.yml

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Setup Conda Environment
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Mambaforge
miniforge-version: latest
use-mamba: true
activate-environment: cadpythonsim
channels: conda-forge,

- name: install conda env
run: |
mamba env update -n cadpythonsim -f ${{ env.CONDA_FILE }}
- name: Install
run: |
python -m pip install --upgrade pip
pip install -e ./[testing]
- name: Test
run: |
pytest
10 changes: 10 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: ruff

name: Ruff
on: [ push, pull_request ]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: chartboost/ruff-action@v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__/
debug*
*.h5
*.egg-info
.vscode
9 changes: 7 additions & 2 deletions CADETPythonSimulator/exception.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class NotInitializedError(Exception):
"""Exception raised when a unit operation is not yet initialized."""

class CADETPythonSimError(Exception):
"""Typical Exception for Error Handling"""
pass

class NotInitializedError(CADETPythonSimError):
"""Exception raised when a unit operation is not yet initialized."""
pass
84 changes: 84 additions & 0 deletions CADETPythonSimulator/residual.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import numpy as np
from CADETPythonSimulator.exception import CADETPythonSimError
import warnings

def calculate_residual_volume_cstr(
V : float,
V_dot : float,
Q_in : float ,
Q_out : float
) -> float:
"""
Calculates the residual equations of the volume of a cstr.
Parameters
----------
V : float
Volume within the CSTR
V_dot : float
Volume change rate of the CSTR
Q_in : float
Volume entering the Unit
Q_out : float
Volume leaving the Unit
Returns
-------
float
Residual of the Flow equation of the CSTR with dimensions like the inpu
"""

if V < 0:
raise CADETPythonSimError("V can't be less then zero")

return V_dot - Q_in + Q_out

def calculate_residual_concentration_cstr(
c : np.ndarray,
c_dot : np.ndarray,
V : float,
V_dot : float,
Q_in : float,
Q_out : float,
c_in : np.ndarray
) -> np.ndarray :
"""
Calculates the residual equations of the concentration of a cstr
Parameters
----------
c : np.ndarray
Concentration
c_dot : np.ndarray
Changing of the concentration
V : float
Volume within the CSTR
V_dot : float
Volume change rate of the CSTR
Q_in : float
Volume entering the Unit
Q_out : float
Volume leaving the Unit
c_in : np.ndarray
Initial concentration
"""
if V < 0:
raise CADETPythonSimError("V can't be less then zero")


return c_dot * V + V_dot * c - Q_in * c_in + Q_out * c


def calculate_residuals_visc_cstr():
"""
Calculates the residual of the Viscosity equation of the CSTR
"""
warnings.warn("Viscosity of CSTR not yet implemented")

return 0


def calculate_residual_def():
"""
Calculates the residual equations fo a dead end filtration equation.
"""
raise NotImplementedError
24 changes: 16 additions & 8 deletions CADETPythonSimulator/unit_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
)
from CADETProcess.dynamicEvents import Section

from CADETPythonSimulator.exception import NotInitializedError
from CADETPythonSimulator.exception import NotInitializedError, CADETPythonSimError
from CADETPythonSimulator.state import State, state_factory
from CADETPythonSimulator.residual import (
calculate_residual_volume_cstr, calculate_residual_concentration_cstr, calculate_residuals_visc_cstr
)
from CADETPythonSimulator.rejection import RejectionBase
from CADETPythonSimulator.cake_compressibility import CakeCompressibilityBase
from CADETPythonSimulator.viscosity import LogarithmicMixingViscosity, ViscosityBase


class UnitOperationBase(Structure):
Expand Down Expand Up @@ -475,9 +479,9 @@ def compute_residual(
"""
# Inlet DOFs are simply copied to the residual.
for i in range(self.n_dof_coupling):
residual[i] = self.y[i]

self.residuals['outlet']['c_poly'] = self.states['outlet']['c_poly']
self.residuals['outlet']['viscosity'] = self.states['outlet']['viscosity']

class Outlet(UnitOperationBase):
"""System outlet."""
Expand Down Expand Up @@ -532,6 +536,7 @@ class Cstr(UnitOperationBase):
}
_state_structures = ['inlet', 'bulk']


def compute_residual(
self,
t: float,
Expand Down Expand Up @@ -565,12 +570,11 @@ def compute_residual(
# for i in range(self.n_comp):
# self.residuals['bulk']['c'][i] = c_dot[i] * V + V_dot * c[i] - Q_in * c_in[i] + Q_out * c[i]
# Alternative: Can we vectorize this?
self.residuals['bulk']['c'] = c_dot * V + V_dot * c - Q_in * c_in + Q_out * c

self.residuals['bulk']['Volume'] = V_dot - self.Q_in + Q_out
self.residuals['bulk']['c'] = calculate_residual_concentration_cstr(c, c_dot, V, V_dot, Q_in, Q_out, c_in)

# TODO: What about viscosities?
self.residuals['bulk']['Volume'] = calculate_residual_volume_cstr(V, V_dot, Q_in, Q_out)

self.residuals['inlet']['viscosity'] = calculate_residuals_visc_cstr()

class DeadEndFiltration(UnitOperationBase):
"""
Expand Down Expand Up @@ -653,6 +657,10 @@ def compute_residual(

residual[self.n_dof_coupling + 2] = ((self.c(t) * y_dot[0]) / (1-self.c(t)/self.density)) - y_dot[2]

self.residuals['retentate']
self.residuals['permeate']



class CrossFlowFiltration(UnitOperationBase):
"""
Expand Down Expand Up @@ -778,4 +786,4 @@ def compute_residual(
Residual of the unit operation.
"""
raise NotImplementedError()
raise NotImplementedError()
Binary file added environment.yml
Binary file not shown.
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ markers = [

[tool.setuptools.dynamic]
version = { attr = "CADETPythonSimulator.__version__" }

[tool.ruff]
# Same as Black.
line-length = 88
indent-width = 4
Loading

0 comments on commit aeb139b

Please sign in to comment.