Skip to content

Commit

Permalink
Deleted system_solver.py+final editing
Browse files Browse the repository at this point in the history
  • Loading branch information
daklauss committed Sep 11, 2024
1 parent a0abbed commit b320ce4
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 315 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
"""Version information."""
name = "CADET-Python-Simulator"
__version__ = "0.0.1"
4 changes: 4 additions & 0 deletions CADETPythonSimulator/cake_compressibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def specific_resistance(self, delta_p: float) -> float:
-------
float
Specific pressure difference.
"""
return

Expand Down Expand Up @@ -50,6 +51,7 @@ def specific_resistance(self, delta_p: float) -> float:
-------
float
Specific pressure difference.
"""
return self.cake_resistance

Expand All @@ -64,6 +66,7 @@ class LinearCakeCompressibility(CakeCompressibilityBase):
Base value of cake resistance factor.
cake_resistance_linear: float
Slope of cake resistance factor.
"""

cake_resistance_base = UnsignedFloat()
Expand All @@ -82,5 +85,6 @@ def specific_resistance(self, delta_p: float) -> float:
-------
float
Specific pressure difference.
"""
return self.cake_resistance_base + self.cake_resistance_linear * delta_p
1 change: 1 addition & 0 deletions CADETPythonSimulator/componentsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def __init__(self,
raise CADETPythonSimError("Could not determine number of species")

def add_species(self, species, *args, **kwargs):
"""Add a species to the component System."""
if not isinstance(species, CPSSpecies):
species = CPSSpecies(species, *args, **kwargs)
self._species.append(species)
Expand Down
2 changes: 1 addition & 1 deletion CADETPythonSimulator/coupling_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def get_coupled_state(
"""Calculate new state for destination_unit."""


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

def get_coupled_state(self,
Expand Down
6 changes: 0 additions & 6 deletions CADETPythonSimulator/residual.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def calculate_residual_volume_cstr(

return V_dot - Q_in + Q_out


def calculate_residual_concentration_cstr(
c: np.ndarray,
c_dot: np.ndarray,
Expand Down Expand Up @@ -72,14 +71,12 @@ def calculate_residual_concentration_cstr(

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


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

return 0


def calculate_residual_cake_vol_def(
V_dot_f: float,
rejection: np.ndarray,
Expand All @@ -106,7 +103,6 @@ def calculate_residual_cake_vol_def(
"""
return -V_dot_C + np.sum(rejection * molar_volume * c_in * V_dot_f)


def calculate_residual_press_easy_def(
V_dot_Perm: float,
V_C: float,
Expand Down Expand Up @@ -144,8 +140,6 @@ def calculate_residual_press_easy_def(

return -V_dot_Perm + deltap * A *hyd_resistance



def calculate_residual_visc_def():
"""Calculate the residual of the Viscosity equation of the CSTR."""
warnings.warn("Viscosity of def not yet implemented")
Expand Down
34 changes: 3 additions & 31 deletions CADETPythonSimulator/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ def __init__(self, system: SystemBase, sections: list[dict]):
self._system: Optional[SystemBase] = system
self._setup_sections(sections)


def _setup_sections(self, sections):
"""
Check Connections.
Set up sections.
Converts dict sections into addict.Dicts. Checks if start and end times
are continusly
Expand All @@ -41,7 +40,6 @@ def _setup_sections(self, sections):
previous_end = section.end
self.sections = sections


def initialize_solver(self, solver: str = 'ida') -> NoReturn:
"""
Initialize solver.
Expand Down Expand Up @@ -231,17 +229,15 @@ def get_section_solution_times(self, section: Dict) -> np.ndarray:
end = section.end
return np.arange(start, end, time_resolution)



def _update_unit_operation_parameters(
self,
start: float,
end: float,
unit_operation_parameters: dict[
UnitOperationBase | str,
dict[str, npt.ArrayLike]
]
) -> np.ndarray:
]
) -> np.ndarray:
"""
Update time dependent unit operation parameters.
Expand All @@ -266,27 +262,3 @@ def _update_unit_operation_parameters(
raise CADETPythonSimError(f"Unit {unit} is not Part of the System.")

unit.update_parameters(start, end, parameters)

# @property
# def port_mapping(self) -> dict[int, str]:
# """dict: Mapping of port indices to corresponding state entries."""
# # TODO: Let this be handled by the SystemSolver?
# port_mapping = defaultdict(dict)

# counter = 0
# for mapped_state, n_ports in self.inlet_ports.items():
# for port in range(n_ports):
# port_mapping['inlet'][counter] = {}
# port_mapping['inlet'][counter]['mapped_state'] = mapped_state
# port_mapping['inlet'][counter]['port_index'] = port
# counter += 1

# counter = 0
# for mapped_state, n_ports in self.outlet_ports.items():
# for port in range(n_ports):
# port_mapping['outlet'][counter] = {}
# port_mapping['outlet'][counter]['mapped_state'] = mapped_state
# port_mapping['outlet'][counter]['port_index'] = port
# counter += 1

# return dict(port_mapping)
13 changes: 6 additions & 7 deletions CADETPythonSimulator/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from scikits.odes.dae import dae

from CADETPythonSimulator.state import State, state_factory
from CADETPythonSimulator.coupling_interface import CouplingInterface, AverageCoupling
from CADETPythonSimulator.coupling_interface import (
CouplingInterface,
WeightedAverageCoupling
)

from CADETProcess.dataStructure import Structure
from CADETPythonSimulator.exception import NotInitializedError, CADETPythonSimError
Expand All @@ -30,7 +33,6 @@ def __init__(self, unit_operations: list[UnitOperationBase]):
= None
self._setup_unit_operations(unit_operations)


@property
def unit_operations(self) -> dict[str, UnitOperationBase]:
"""dict: Unit operations, indexed by name."""
Expand Down Expand Up @@ -304,7 +306,6 @@ def coupled_state_func(self, unit_Q_list: list[dict, float]) -> dict:
ret[state] = calc_method.get_coupled_state(unit_Q_list, state)
return ret


def _compute_connectivity_matrix(self, connections: list) -> np.ndarray:
# TODO: This could be the setter for `connectivity`
# Note, maybe we already adapt the interface s.t. we compute this matrix,
Expand Down Expand Up @@ -363,8 +364,6 @@ def _compute_connectivity_matrix(self, connections: list) -> np.ndarray:
self._connectivity = connections_matrix




class FlowSystem(SystemBase):
"""
SystemBase Class.
Expand All @@ -376,8 +375,8 @@ class FlowSystem(SystemBase):
def __init__(self, unit_operations: list[UnitOperationBase]):
"""Construct FlowSystem Object."""
self.coupling_state_structure={
'c': AverageCoupling(),
'viscosity': AverageCoupling()
'c': WeightedAverageCoupling(),
'viscosity': WeightedAverageCoupling()
}
super().__init__(unit_operations)

Expand Down
Loading

0 comments on commit b320ce4

Please sign in to comment.