Skip to content

Commit f3d3ae7

Browse files
committed
added test for uo def calc_residual
Wrote a test for the residual_calculation method of dead end filtration model deleted some todo/rememberance lines
1 parent 792faad commit f3d3ae7

File tree

4 files changed

+91
-39
lines changed

4 files changed

+91
-39
lines changed

CADETPythonSimulator/unit_operation.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,6 @@ class DeadEndFiltration(UnitOperationBase):
620620
membrane_area = UnsignedFloat()
621621
membrane_resistance = UnsignedFloat()
622622
specific_cake_resistance = UnsignedFloat()
623-
# molar_volume = SizedUnsignedNdArray(size = 'n_comp') => component system erben von cadet process
624623
rejection = Typed(ty=RejectionBase)
625624

626625
_parameters = [

CADETPythonSimulator/viscosity.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class ViscosityBase(Structure):
99
"""Base class for mixed viscosity calculations."""
1010

1111
@abstractmethod
12-
def get_mixture_viscosity(self, viscosities: np.ndarray, fractions: np.ndarray) -> float:
12+
def get_mixture_viscosity(
13+
self, viscosities: np.ndarray, fractions: np.ndarray
14+
) -> float:
1315
"""Calculate mixed viscosity with given viscosities and volume fractions.
1416
1517
Parameters
@@ -44,7 +46,9 @@ def _validate_viscosities_input(
4446
class AverageViscosity(ViscosityBase):
4547
"""Calculate mixed viscosity using the average mean."""
4648

47-
def get_mixture_viscosity(self, viscosities: np.ndarray, fractions: np.ndarray) -> float:
49+
def get_mixture_viscosity(
50+
self, viscosities: np.ndarray, fractions: np.ndarray
51+
) -> float:
4852
"""Calculate mixed viscosity using the arithmetic mean.
4953
5054
Parameters
@@ -68,7 +72,9 @@ def get_mixture_viscosity(self, viscosities: np.ndarray, fractions: np.ndarray)
6872
class LogarithmicMixingViscosity(ViscosityBase):
6973
"""Calculate mixed viscosity using the logarithmic mixing rule."""
7074

71-
def get_mixture_viscosity(self, viscosities: np.ndarray, fractions: np.ndarray) -> float:
75+
def get_mixture_viscosity(
76+
self, viscosities: np.ndarray, fractions: np.ndarray
77+
) -> float:
7278
"""Calculate mixed viscosity using the logarithmic mixing rule.
7379
7480
Parameters

tests/test_residual.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
)
1010
from CADETPythonSimulator.exception import CADETPythonSimError
1111

12-
"""
13-
q_in q_out, was sind physikalisch sinnvolle szenarien
14-
"""
1512

1613
# random number test
1714
TestCaseCSTRConc_level1 = {
@@ -101,7 +98,6 @@ def test_calculation_concentration_cstr(self, parameters):
10198

10299
np.testing.assert_array_almost_equal(calculate_residual_concentration_cstr(*param_vec_conc), parameters["expected"])
103100

104-
np.testing.assert_array_almost_equal(residual, parameters["expected"])
105101

106102

107103
# random number test

tests/test_unit_operation.py

Lines changed: 82 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
_2DGRM
1414
)
1515

16+
from CADETPythonSimulator.rejection import StepCutOff
1617

1718
# %% Unit Operation Fixtures
1819
class TwoComponentFixture(CPSComponentSystem):
1920
def __init__(self, *args, **kwargs):
2021
super().__init__(*args, **kwargs)
2122

22-
self.add_component('A', molecular_weight=1e3, density=1e3)
23-
self.add_component('B', molecular_weight=10e3, density=1e3)
23+
self.add_component('A', molecular_weight=1e3, density=1e3, molecular_volume=1)
24+
self.add_component('B', molecular_weight=10e3, density=1e3, molecular_volume=1)
2425

2526

2627
class UnitOperationFixture(UnitOperationBase):
@@ -76,14 +77,18 @@ def __init__(self,
7677
component_system=None,
7778
name='dead_end_filtration',
7879
membrane_area=1,
79-
membrane_resistance=1e-9,
80+
membrane_resistance=1,
81+
specific_cake_resistance=1,
82+
rejection=StepCutOff(cutoff_weight=0),
8083
*args,
8184
**kwargs
8285
):
8386
super().__init__(component_system, name, *args, **kwargs)
8487

8588
self.membrane_area = membrane_area
8689
self.membrane_resistance = membrane_resistance
90+
self.specific_cake_resistance = specific_cake_resistance
91+
self.rejection=rejection
8792

8893

8994
class CrossFlowFiltrationFixture(UnitOperationFixture, CrossFlowFiltration):
@@ -355,35 +360,35 @@ def test_initialize(self, unit_operation: UnitOperationBase, expected: dict):
355360
(
356361
CstrFixture(),
357362
{
358-
'states' : {
359-
'inlet' : {
360-
'c' : np.array([7, 8]),
361-
'viscosity' : [3]
363+
'states': {
364+
'inlet': {
365+
'c': np.array([7, 8]),
366+
'viscosity': [3]
362367
},
363-
'bulk' : {
364-
'c' : np.array([1, 2]),
365-
'Volume' : 1
368+
'bulk': {
369+
'c': np.array([1, 2]),
370+
'Volume': 1
366371
}
367372
},
368-
'state_derivatives' : {
369-
'inlet' : {
370-
'c' : [6, 7]
373+
'state_derivatives': {
374+
'inlet': {
375+
'c': [6, 7]
371376
},
372-
'bulk' : {
373-
'c' : np.array([4, 5]),
374-
'Volume' : 2
377+
'bulk': {
378+
'c': np.array([4, 5]),
379+
'Volume': 2
375380
}
376381
},
377-
'Q_in' : [3],
378-
'Q_out' : [4]
382+
'Q_in': [3],
383+
'Q_out': [4]
379384
},
380385
[
381386
("calculate_residual_concentration_cstr",
382387
lambda c, c_dot, V, V_dot, Q_in, Q_out, c_in:
383388
c_dot * V + V_dot * c - Q_in * c_in + Q_out * c
384389
),
385390
("calculate_residual_visc_cstr",
386-
lambda *args :
391+
lambda *args:
387392
0
388393
),
389394
("calculate_residual_volume_cstr",
@@ -392,23 +397,69 @@ def test_initialize(self, unit_operation: UnitOperationBase, expected: dict):
392397
)
393398
],
394399
{
395-
'inlet' : {
396-
'c' : np.array([7, 8]),
400+
'inlet': {
401+
'c': np.array([7, 8]),
397402
'viscosity' : 0
398403
},
399-
'bulk' : {
400-
'c' : np.array([-11,-7]),
401-
'Volume' : 3
404+
'bulk': {
405+
'c': np.array([-11,-7]),
406+
'Volume': 3
402407
}
403408
}
404409
),
405-
# (
406-
# DeadEndFiltrationFixture(),
407-
# {
408-
# 'expected_residual': {
409-
# },
410-
# },
411-
# ),
410+
(
411+
DeadEndFiltrationFixture(),
412+
{
413+
'states': {
414+
'cake': {
415+
'c': np.array([0.5, 0.5]),
416+
'viscosity': 1,
417+
'pressure': 1,
418+
'cakevolume': 1,
419+
'permeate': 1,
420+
},
421+
'permeate': {
422+
'c': np.array([0.5, 0.5]),
423+
'viscosity': 1,
424+
'Volume': 1,
425+
}
426+
},
427+
'state_derivatives': {
428+
'cake': {
429+
'c': np.array([0.5, 0.5]),
430+
'viscosity': 1,
431+
'pressure': 1,
432+
'cakevolume': 1,
433+
'permeate': 1,
434+
},
435+
'permeate': {
436+
'c': np.array([0.5, 0.5]),
437+
'viscosity': 1,
438+
'Volume': 1,
439+
}
440+
},
441+
'Q_in': [1],
442+
'Q_out': [1]
443+
},
444+
[
445+
('CPSComponentSystem.molecular_weights', [1, 1]),
446+
('CPSComponentSystem.molecular_volumes', [1, 1])
447+
],
448+
{
449+
'cake': {
450+
'c': np.array([0.5, 0.5]),
451+
'viscosity': 0,
452+
'pressure': 1,
453+
'cakevolume': 0,
454+
'permeate': 1,
455+
},
456+
'permeate': {
457+
'c': np.array([1.5, 1.5]),
458+
'viscosity': 0,
459+
'Volume': 1,
460+
}
461+
}
462+
),
412463
# (
413464
# CrossFlowFiltrationFixture(),
414465
# {

0 commit comments

Comments
 (0)