-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move residual calculation to separate module
- Loading branch information
1 parent
75287b6
commit 8a4867f
Showing
6 changed files
with
271 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from CADETPythonSimulator.residual import ( | ||
calculate_residual_volume_cstr, calculate_residual_concentration_cstr | ||
) | ||
from CADETPythonSimulator.exception import CADETPythonSimError | ||
import pytest | ||
import numpy as np | ||
|
||
|
||
TestCaseConc = { | ||
"values" : { | ||
"c" : np.array([1, 2, 3]), | ||
"c_dot" : np.array([4, 5, 6]), | ||
"V" : 1, | ||
"V_dot" : 2, | ||
"Q_in" : 3, | ||
"Q_out" : 4, | ||
"c_in" : np.array([7, 8, 9]) | ||
}, | ||
"expected" : np.array([-11,-7,-3]) | ||
} | ||
|
||
|
||
|
||
@pytest.mark.parametrize( | ||
"parameters", | ||
[ | ||
TestCaseConc | ||
] | ||
) | ||
class TestResidualConcCSTR(): | ||
def test_calculation_concentration_cstr(self, parameters): | ||
|
||
param_vec_conc = parameters["values"].values() | ||
|
||
np.testing.assert_equal(calculate_residual_concentration_cstr(*param_vec_conc), parameters["expected"]) | ||
|
||
|
||
|
||
|
||
|
||
TestCaseVol = { | ||
"values" : { | ||
"V" : 1, | ||
"V_dot" : 2, | ||
"Q_in" : 3, | ||
"Q_out" : 4, | ||
}, | ||
"expected" : 3 | ||
} | ||
|
||
|
||
|
||
@pytest.mark.parametrize( | ||
"parameters", | ||
[ | ||
TestCaseVol | ||
] | ||
) | ||
|
||
class TestResidualVolCSTR(): | ||
def test_calculation_cstr(self, parameters): | ||
|
||
param_vec_volume = parameters["values"].values() | ||
|
||
np.testing.assert_equal(calculate_residual_volume_cstr(*param_vec_volume), parameters["expected"]) | ||
|
||
TestCaseConcError = { | ||
"values" : { | ||
"c" : np.array([1, 2, 3]), | ||
"c_dot" : np.array([4, 5, 6]), | ||
"V" : -1, | ||
"V_dot" : 2, | ||
"Q_in" : 3, | ||
"Q_out" : 4, | ||
"c_in" : np.array([7, 8, 9]) | ||
}, | ||
"expected" : np.array([-11,-7,-3]) | ||
} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"parameters", | ||
[ | ||
TestCaseConcError | ||
] | ||
) | ||
|
||
|
||
class TestResidualError(): | ||
|
||
def test_calculation_vol_cstr_error(self, parameters): | ||
|
||
param_vec_volume = parameters["values"].values() | ||
|
||
with pytest.raises(CADETPythonSimError): | ||
calculate_residual_volume_cstr(*list(param_vec_volume)[2:6]) | ||
|
||
def test_calculation_concentration_cstr_error(self, parameters): | ||
|
||
param_vec_volume = parameters["values"].values() | ||
|
||
with pytest.raises(CADETPythonSimError): | ||
calculate_residual_concentration_cstr(*param_vec_volume) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters