Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
daklauss committed Sep 4, 2024
1 parent 3b0661d commit 33f697f
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 98 deletions.
2 changes: 1 addition & 1 deletion CADETPythonSimulator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Version information
name = "CADET-Python-Simulator"
__version__ = "0.0.1"
__version__ = "0.0.1"
4 changes: 2 additions & 2 deletions CADETPythonSimulator/coupling_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from CADETPythonSimulator.unit_operation import UnitOperationBase


class coupling_interface(abc.ABC):
class CouplingInterface(abc.ABC):
@abc.abstractmethod
def get_coupled_state(self,
origin_list: list[(dict, float)],
Expand All @@ -13,7 +13,7 @@ def get_coupled_state(self,



class average_coupling(coupling_interface):
class AverageCoupling(CouplingInterface):

def get_coupled_state(self,
origin_list: list[(dict, float)],
Expand Down
4 changes: 3 additions & 1 deletion CADETPythonSimulator/exception.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class CADETPythonSimError(Exception):
"""Typical Exception for Error Handling"""
"""Typical Exception for Error Handling."""

pass


class NotInitializedError(CADETPythonSimError):
"""Exception raised when a unit operation is not yet initialized."""

pass
7 changes: 5 additions & 2 deletions CADETPythonSimulator/rejection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class RejectionBase(Structure):

@abstractmethod
def get_rejection(self, mw: float) -> float:
"""Get rejection for a species with specific molecular weight.
"""
Get rejection for a species with specific molecular weight.
Parameters
----------
Expand All @@ -34,12 +35,14 @@ class StepCutOff(RejectionBase):
cutoff_weight : float
Cutoff size. All molecules smaller than the size will pass through the filter.
All molecules larger or equal than the cutoff will be retained.
"""

cutoff_weight = UnsignedFloat()

def get_rejection(self, mw: float) -> float:
"""Get rejection for a species with specific molecular weight.
"""
Get rejection for a species with specific molecular weight.
Parameters
----------
Expand Down
25 changes: 16 additions & 9 deletions CADETPythonSimulator/residual.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ def calculate_residual_volume_cstr(
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
Residual of the Flow equation of the CSTR with dimensions like the input
"""
if V < 0:
raise CADETPythonSimError("V can't be less then zero")
Expand Down Expand Up @@ -63,6 +65,7 @@ def calculate_residual_concentration_cstr(
Volume leaving the Unit
c_in : np.ndarray
Initial concentration
"""
if V < 0:
raise CADETPythonSimError("V can't be less then zero")
Expand Down Expand Up @@ -91,12 +94,15 @@ def calculate_residual_cake_vol_def(
----------
V_dot_f : float
Flowrate of incoming feed
rejection : float
rejection : np.ndarray
Rejection of the filter
gamma : float
Portion of suspended material
molar_volume : np.ndarray
Volume of suspended material
c_in : np.array
Incoming Concentration
V_dot_C : float
Change of Cake Volume
"""
return -V_dot_C + np.sum(rejection * molar_volume * c_in * V_dot_f)

Expand All @@ -111,8 +117,10 @@ def calculate_residual_press_easy_def(
alpha: float
) -> float:
"""
Calculate the residual equations fo a dead end filtration equation for the pressure
in the easy model.
Calculate the residual equations.
Calculates the residual equation for a dead end filtration equation
for the pressure in the easy model.
Parameters
----------
Expand All @@ -130,6 +138,7 @@ def calculate_residual_press_easy_def(
resistance of the medium
alpha : float
Specific cake resistance
"""
hyd_resistance = (Rm + alpha*V_C/A) * mu

Expand All @@ -138,9 +147,7 @@ def calculate_residual_press_easy_def(


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

return 0
12 changes: 9 additions & 3 deletions CADETPythonSimulator/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@


class Solver(Structure):
"""Solver Class to solve a System."""

def __init__(self, system: SystemBase, sections: list[dict]):
"""Construct the Solver Class."""
self.initialize_solver()

self._system = system
Expand All @@ -32,6 +35,7 @@ def initialize_solver(self, solver: str = 'ida') -> NoReturn:
----------
solver : str, optional
Solver to use for integration. The default is `ida`.
"""
if solver not in ['ida']:
raise ValueError(f"{solver} is not a supported solver.")
Expand All @@ -46,7 +50,7 @@ def _compute_residual(
r: np.ndarray
) -> NoReturn:
"""
Compute residual of the system
Compute residual of the system.
Parameters
----------
Expand All @@ -58,6 +62,7 @@ def _compute_residual(
State derivative to evaluate
r : np.ndarray
Array to save the calculated residual
"""
self._system.y = y
self._system.y_dot = y_dot
Expand Down Expand Up @@ -95,6 +100,7 @@ def write_solution(self, y: np.ndarray, y_dot: np.ndarray) -> NoReturn:
The current complete state of the system as a NumPy array.
y_dot : np.ndarray
The current complete derivative of the system's state as a NumPy array.
"""
for unit, unit_slice in self.unit_slices.items():
current_state = unit.y_split
Expand All @@ -116,7 +122,7 @@ def write_solution(self, y: np.ndarray, y_dot: np.ndarray) -> NoReturn:

def solve(self) -> NoReturn:
"""Simulate the system."""
self.initialize_system() #TODO: Has to point to system.initialize()
self.initialize_system() #TODO: Has to point to system.initialize()
self.initialize_solution_recorder()
self.write_solution()

Expand Down Expand Up @@ -145,6 +151,7 @@ def solve_section(
section : Dict
The time points at which the solution is sought.
#TODO: Consider creating a section class instead of using Addict
"""
self._update_unit_operation_parameters(
section.start,
Expand Down Expand Up @@ -174,7 +181,6 @@ def _update_unit_operation_parameters(
section_states: dict[UnitOperationBase, dict]
) -> np.ndarray:
"""
Update time dependent unit operation parameters.
Parameters
Expand Down
21 changes: 17 additions & 4 deletions CADETPythonSimulator/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class State(Structure):
The name of the state
s : np.ndarray
The state array, initialized as zeros based on the computed shape.
"""

name = String()
Expand Down Expand Up @@ -69,7 +70,7 @@ def n_dimensions(self) -> int:

@property
def dimension_shape(self) -> tuple[int, ...]:
"""tuple of int: Return the shape derived from dimensions."""
"""Tuple of int: Return the shape derived from dimensions."""
return tuple(self.dimensions.values())

@property
Expand All @@ -84,7 +85,7 @@ def n_entries(self) -> int:

@property
def shape(self) -> tuple[int, ...]:
"""tuple of int: Return the complete shape of the state array."""
"""Tuple of int: Return the complete shape of the state array."""
shape = self.dimension_shape + (self.n_entries,)
if isinstance(shape, int):
shape = (shape, )
Expand Down Expand Up @@ -115,6 +116,7 @@ def s_split(self) -> dict[str, np.ndarray]:
Dict[str, np.ndarray]
A dictionary where each key is an entry name and the value is the
corresponding segment of the state array.
"""
s_split = {}
start_index = 0
Expand Down Expand Up @@ -180,7 +182,8 @@ def set_inlet_port_state(
Raises
------
Exception
If port index exceeds number of inlet ports.
If port index exceeds number of inlet ports.#
"""
if port_index > (self.n_inlet_ports - 1):
raise Exception("Port index exceeds number of inlet ports.")
Expand Down Expand Up @@ -229,6 +232,7 @@ def get_outlet_port_state(
------
Exception
If port index exceeds number of outlet ports.
"""
if port_index > (self.n_outlet_ports - 1):
raise ValueError("Port index exceeds number of outlet ports.")
Expand Down Expand Up @@ -265,7 +269,7 @@ def __getitem__(self, entry) -> np.ndarray:
Parameters
----------
state_name : str
entry : str
Name of the state entry.
Returns
Expand All @@ -277,6 +281,7 @@ def __getitem__(self, entry) -> np.ndarray:
------
KeyError
If entry not in State
"""
try:
return self.s_split[entry]
Expand All @@ -300,6 +305,7 @@ def __setitem__(self, entry, value: np.ndarray) -> None:
If entry is not in State.
ValueError
If the shape of the value does not match the expected shape for the entry.
"""
if entry not in self.entries:
raise KeyError('Not a valid state.')
Expand Down Expand Up @@ -347,6 +353,8 @@ def state_factory(
Parameters
----------
instance : Any
instance to initialize
name : str
Name of the state
dimensions : int or tuple
Expand All @@ -355,6 +363,11 @@ def state_factory(
entries : dict
The state entries at each cell. Individual elements can be either
integers or strings (indicating other instance parameters).
n_inlet_ports: int | str
Noumber of inlet Ports
n_outlet_ports: int | str
Number of outlet Ports
"""
dimensions = {
dim: getattr(instance, dim) for dim in dimensions
Expand Down
Loading

0 comments on commit 33f697f

Please sign in to comment.