View Issue Details

IDProjectCategoryView StatusLast Update
0003338OpenFOAMBugpublic2019-08-25 19:55
ReporterwyldckatAssigned Tohenry 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version7 
Fixed in Version7 
Summary0003338: porosityModel::adjustNegativeResistance doesn't properly check for when all values are negative
DescriptionThis is a somewhat peculiar issue, in method 'porosityModel::adjustNegativeResistance':

    scalar maxCmpt = max(0, cmptMax(resist.value()));

    if (maxCmpt < 0)
    {
        FatalErrorInFunction
            << "Cannot have all resistances set to negative, resistance = "
            << resist
            << exit(FatalError);
    }

Which means that 'maxCmpt' is always '>= 0', due to how the 'max' operation is being done. Therefore, someone could have used negative resistance values, gotten no resistance out of it and no fatal error accordingly...

This affects all versions of OpenFOAM, as far as I could search back into the past (seems to have been added somewhere between 1.4 and 1.5).

Attached at the following files as a proposal to fix this issue:

 - proposal_v1.patch - this provides the proposed changes, to properly both check if all values are not negative and then use the above 0 values only when needed.

 - porosityModel.C - modified file from OpenFOAM-dev to update 'src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C', which works on both OpenFOAM-dev, 7 and 6.
TagsNo tags attached.

Activities

wyldckat

2019-08-24 17:34

updater  

porosityModel.C (5,700 bytes)
proposal_v1.patch (1,486 bytes)
diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C
index e491bb2..9b50a9d 100644
--- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C
+++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     | Website:  https://openfoam.org
-    \\  /    A nd           | Copyright (C) 2012-2018 OpenFOAM Foundation
+    \\  /    A nd           | Copyright (C) 2012-2019 OpenFOAM Foundation
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
 License
@@ -39,16 +39,18 @@ namespace Foam
 
 void Foam::porosityModel::adjustNegativeResistance(dimensionedVector& resist)
 {
-    scalar maxCmpt = max(0, cmptMax(resist.value()));
+    scalar maxCmpt = cmptMax(resist.value());
 
     if (maxCmpt < 0)
     {
         FatalErrorInFunction
-            << "Negative resistances are invalid, resistance = " << resist
+            << "Cannot have all resistances set to negative, resistance = "
+            << resist
             << exit(FatalError);
     }
     else
     {
+        maxCmpt = max(0, maxCmpt);
         vector& val = resist.value();
         for (label cmpt = 0; cmpt < vector::nComponents; cmpt++)
         {
proposal_v1.patch (1,486 bytes)

henry

2019-08-25 19:55

manager   ~0010698

Thanks Bruno
Resolved in OpenFOAM-7 by commit ce67ac7f21d1edab96957a01a0b9cb5fbaff76a3
Resolved in OpenFOAM-dev by commit 9847140a8f021957a9471168e52b123136ee51e6

Issue History

Date Modified Username Field Change
2019-08-24 17:34 wyldckat New Issue
2019-08-24 17:34 wyldckat Status new => assigned
2019-08-24 17:34 wyldckat Assigned To => henry
2019-08-24 17:34 wyldckat File Added: porosityModel.C
2019-08-24 17:34 wyldckat File Added: proposal_v1.patch
2019-08-25 19:55 henry Status assigned => resolved
2019-08-25 19:55 henry Resolution open => fixed
2019-08-25 19:55 henry Fixed in Version => 7
2019-08-25 19:55 henry Note Added: 0010698