diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml new file mode 100644 index 0000000..8178685 --- /dev/null +++ b/.github/workflows/pipeline.yml @@ -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 diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000..780e902 --- /dev/null +++ b/.github/workflows/ruff.yml @@ -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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index fa31b95..26d5f8b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ __pycache__/ debug* *.h5 *.egg-info +.vscode diff --git a/environment.yml b/environment.yml new file mode 100644 index 0000000..0bd1f61 Binary files /dev/null and b/environment.yml differ diff --git a/tests/test_residual.py b/tests/test_residual.py index 1bca14c..61f3d99 100644 --- a/tests/test_residual.py +++ b/tests/test_residual.py @@ -5,8 +5,12 @@ import pytest import numpy as np +""" +q_in q_out, was sind physikalisch sinnvolle szenarien +""" -TestCaseConc = { +# random number test +TestCaseConc_level1 = { "values" : { "c" : np.array([1, 2, 3]), "c_dot" : np.array([4, 5, 6]), @@ -19,12 +23,71 @@ "expected" : np.array([-11,-7,-3]) } +# flow in and out are equal, concentrations to +TestCaseConc_equal = { + "values" : { + "c" : np.array([0.1,]), + "c_dot" : np.array([0,]), + "V" : 1, + "V_dot" : 0, + "Q_in" : 1, + "Q_out" : 1, + "c_in" : np.array([0.1,]) + }, + "expected" : np.array([0,]) +} + +# flow in and out are equal, but concentrations going into the unit is not +TestCaseConc_diffcin = { + "values" : { + "c" : np.array([0.1,]), + "c_dot" : np.array([0,]), + "V" : 1.0, + "V_dot" : 0.0, + "Q_in" : 1.0, + "Q_out" : 1.0, + "c_in" : np.array([0.2,]) + }, + "expected" : np.array([-0.1,]) +} + +#flow in and out are not equal, concentrantions going in are +TestCaseConc_diffvol = { + "values" : { + "c" : np.array([0.1,]), + "c_dot" : np.array([0,]), + "V" : 1.0, + "V_dot" : 1.0, + "Q_in" : 2.0, + "Q_out" : 1.0, + "c_in" : np.array([0.1,]) + }, + "expected" : np.array([0,]) +} + +#flow in and out are not, equal, concentrations aren't equal too +TestCaseConc_diffvolc = { + "values" : { + "c" : np.array([0.1,]), + "c_dot" : np.array([0.2,]), + "V" : 1.0, + "V_dot" : 1.0, + "Q_in" : 2.0, + "Q_out" : 1.0, + "c_in" : np.array([0.2,]) + }, + "expected" : np.array([0,]) +} @pytest.mark.parametrize( "parameters", [ - TestCaseConc + TestCaseConc_level1, + TestCaseConc_equal, + TestCaseConc_diffcin, + TestCaseConc_diffvol, + TestCaseConc_diffvolc ] ) class TestResidualConcCSTR(): @@ -32,12 +95,12 @@ 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"]) - + np.testing.assert_array_almost_equal(calculate_residual_concentration_cstr(*param_vec_conc), parameters["expected"]) +# random number test TestCaseVol = { "values" : { "V" : 1, @@ -48,12 +111,59 @@ def test_calculation_concentration_cstr(self, parameters): "expected" : 3 } +# Flow in and out are equal +TestCaseVol_equal = { + "values" : { + "V" : 1, + "V_dot" : 0, + "Q_in" : 1, + "Q_out" : 1, + }, + "expected" : 0 +} +# Flow in is larger than out +TestCaseVol_inge = { + "values" : { + "V" : 1, + "V_dot" : 1, + "Q_in" : 2, + "Q_out" : 1, + }, + "expected" : 0 +} + +# Flow in is lesser than out +TestCaseVol_inle = { + "values" : { + "V" : 1, + "V_dot" : -1, + "Q_in" : 1, + "Q_out" : 2, + }, + "expected" : 0 +} + +# Residual does not depend on Volumne + +TestCaseVol_vol = { + "values" : { + "V" : 1e10, + "V_dot" : 0, + "Q_in" : 0, + "Q_out" : 0, + }, + "expected" : 0 +} @pytest.mark.parametrize( "parameters", [ - TestCaseVol + TestCaseVol, + TestCaseVol_equal, + TestCaseVol_inge, + TestCaseVol_inle, + TestCaseVol_vol ] )