From e435ebc70c35e11fc7edd818a14c9a40108fc9c2 Mon Sep 17 00:00:00 2001 From: paulasp Date: Wed, 27 Aug 2025 14:51:16 +0200 Subject: [PATCH] Assign values to returned variables in every condition in cython code - check if explicitFriction has valid values --- avaframe/com1DFA/DFAToolsCython.pyx | 6 +++++- avaframe/com1DFA/DFAfunctionsCython.pyx | 15 +++++++++++---- avaframe/com1DFA/checkCfg.py | 6 ++++++ avaframe/com1DFA/damCom1DFA.pyx | 3 ++- avaframe/tests/test_DFAfunctionsCython.py | 2 +- avaframe/tests/test_checkCfg.py | 7 +++++++ avaframe/tests/test_com1DFA.py | 3 +++ 7 files changed, 35 insertions(+), 7 deletions(-) diff --git a/avaframe/com1DFA/DFAToolsCython.pyx b/avaframe/com1DFA/DFAToolsCython.pyx index 1af339f92..63708e754 100644 --- a/avaframe/com1DFA/DFAToolsCython.pyx +++ b/avaframe/com1DFA/DFAToolsCython.pyx @@ -163,7 +163,11 @@ cpdef (double, double, double) normalize(double x, double y, double z): zn: numpy array z component of the normalized vector """ - cdef double norme, xn, yn, zn + cdef double norme + cdef double xn = 0.0 + cdef double yn = 0.0 + cdef double zn = 0.0 + norme = norm(x, y, z) if norme>0: xn = x / norme diff --git a/avaframe/com1DFA/DFAfunctionsCython.pyx b/avaframe/com1DFA/DFAfunctionsCython.pyx index 34fd07549..4afcad126 100644 --- a/avaframe/com1DFA/DFAfunctionsCython.pyx +++ b/avaframe/com1DFA/DFAfunctionsCython.pyx @@ -442,9 +442,11 @@ cpdef (double, double) computeEntMassAndForce(double dt, double entrMassCell, rhoEnt: float entrainement density """ - cdef double width, ABotSwiped, areaEntrPart + cdef double width, ABotSwiped # compute entrained mass - cdef double dm = 0 + cdef double dm = 0.0 + cdef double areaEntrPart = 0.0 + if entrMassCell > 0: # either erosion or ploughing but not both @@ -527,7 +529,7 @@ cpdef double computeResForce(double areaPart, double rho, double cResCell, resistance component for particle """ - cdef double cRecResPart + cdef double cRecResPart = 0.0 # explicit formulation (explicitFriction == 1) if explicitFriction == 1: if resistanceType == 1: @@ -1100,7 +1102,12 @@ cpdef (double, double, double, double) account4FrictionForce(double ux, double u dtStop : float time step (smaller then dt if the particle stops during this time step) """ - cdef double xDir, yDir, zDir, uxNew, uyNew, uzNew, uMagNew, dtStop + cdef double xDir, yDir, zDir + cdef double uxNew = 0.0 + cdef double uyNew = 0.0 + cdef double uzNew = 0.0 + cdef double uMagNew = 0.0 + cdef double dtStop = 0.0 if explicitFriction == 1: # explicite method diff --git a/avaframe/com1DFA/checkCfg.py b/avaframe/com1DFA/checkCfg.py index 6059a7228..205abb4cb 100644 --- a/avaframe/com1DFA/checkCfg.py +++ b/avaframe/com1DFA/checkCfg.py @@ -218,4 +218,10 @@ def checkCfgFrictionModel(cfg, inputSimFiles, relVolume=""): ) ) + # check if explicitFriction has valid values + if cfg["GENERAL"]["explicitFriction"] not in ["0", "1"]: + message = "explicitFriction should be either 0 (implicit method) or 1 (explicit method)." + log.error(message) + raise ValueError(message) + return cfg diff --git a/avaframe/com1DFA/damCom1DFA.pyx b/avaframe/com1DFA/damCom1DFA.pyx index c0c3a2e5c..f07ab5cb4 100644 --- a/avaframe/com1DFA/damCom1DFA.pyx +++ b/avaframe/com1DFA/damCom1DFA.pyx @@ -308,7 +308,8 @@ cpdef (int, int, double, double, double, double, double, double, double, double, zT: float z component of the tangent vector to the dam at the intersection point """ - cdef int i, intersection + cdef int i + cdef int intersection = 0 cdef double xF1, yF1, zF1, xF2, yF2, zF2 cdef double xF, yF, zF cdef double xC, yC, zC, xC1, yC1, zC1, xC2, yC2, zC2 diff --git a/avaframe/tests/test_DFAfunctionsCython.py b/avaframe/tests/test_DFAfunctionsCython.py index 047935c96..5567d80dc 100644 --- a/avaframe/tests/test_DFAfunctionsCython.py +++ b/avaframe/tests/test_DFAfunctionsCython.py @@ -88,7 +88,7 @@ def test_computeEntMassAndForce(capfd): ) # print(dm, areaEntrPart) assert dm == 0 - assert areaEntrPart == 1 + assert areaEntrPart == 0 entrMassCell = 200 entEroEnergy = 0 diff --git a/avaframe/tests/test_checkCfg.py b/avaframe/tests/test_checkCfg.py index 36ec4a6ac..7ca6e2a03 100644 --- a/avaframe/tests/test_checkCfg.py +++ b/avaframe/tests/test_checkCfg.py @@ -74,6 +74,7 @@ def test_checkCfgFrictionModel(): "Bsamosat": "4.13", "muvoellmy": "4000.", "xsivoellmy": "4000.", + "explicitFriction": "0", } } inputSimFiles = {} @@ -100,6 +101,7 @@ def test_checkCfgFrictionModel(): "Bsamosat": "9.13", "muvoellmy": "4000.", "xsivoellmy": "nan", + "explicitFriction": "0", } } @@ -125,6 +127,7 @@ def test_checkCfgFrictionModel(): "Bsamosat": "nan", "muvoellmy": "4000.", "xsivoellmy": "nan", + "explicitFriction": "0", } } @@ -144,6 +147,7 @@ def test_checkCfgFrictionModel(): "Bsamosat": "test", "muvoellmy": "4000.", "xsivoellmy": "nan", + "explicitFriction": "0", } } @@ -178,6 +182,7 @@ def test_checkCfgFrictionModel(): "volClassSmall": "25000.", "volClassMedium": "60000.", "meshCellSize": "5", + "explicitFriction": "1", } } @@ -219,6 +224,7 @@ def test_checkCfgFrictionModel(): "volClassSmall": "25000.", "volClassMedium": "60000.", "meshCellSize": "5", + "explicitFriction": "1", } } @@ -260,6 +266,7 @@ def test_checkCfgFrictionModel(): "volClassSmall": "25000.", "volClassMedium": "60000.", "meshCellSize": "5", + "explicitFriction": "1", } } diff --git a/avaframe/tests/test_com1DFA.py b/avaframe/tests/test_com1DFA.py index 369f5b467..fcb8f6b2b 100644 --- a/avaframe/tests/test_com1DFA.py +++ b/avaframe/tests/test_com1DFA.py @@ -1917,6 +1917,7 @@ def test_prepareVarSimDict(tmp_path, caplog): "muvoellmy": "4000.", "xsivoellmy": "4000.", "dam": "True", + "explicitFriction": 0, } standardCfg["INPUT"] = { "entThThickness": "1.", @@ -1978,6 +1979,7 @@ def test_prepareVarSimDict(tmp_path, caplog): "muvoellmy": "4000.", "xsivoellmy": "4000.", "dam": "True", + "explicitFriction": 0, } testCfg["INPUT"] = { @@ -2072,6 +2074,7 @@ def test_prepareVarSimDict(tmp_path, caplog): "muvoellmy": "4000.", "xsivoellmy": "4000.", "dam": "True", + "explicitFriction": 0, } testCfg2["INPUT"] = { "entThThickness": "1.",