View Issue Details
ID  Project  Category  View Status  Date Submitted  Last Update 

0003470  OpenFOAM  Feature  public  20200321 14:59  20200321 18:55 
Reporter  Federico Municchi  Assigned To  henry  
Priority  none  Severity  feature  Reproducibility  always 
Status  closed  Resolution  no change required  
Platform  Linux  OS  Ubuntu  OS Version  18.04 
Product Version  7  
Fixed in Version  
Summary  0003470: Inconsistent equation relaxation  
Description  The implications of line https://github.com/OpenFOAM/OpenFOAM7/blob/master/src/finiteVolume/fvMatrices/fvMatrix/fvMatrix.C#L630 are quite dramatic, to the point I have to remember to write every elliptic problem as ``` fvScalarMatrix ellipticM // Negative elliptic (  fvm::laplacian(U) ==  Q ); instead of fvScalarMatrix ellipticM //Positive elliptic ( fvm::laplacian(U) == Q ); if i need to use relaxation (and I often need to) and i want to avoid crashes. As in the attached code (relaxationTest), when one applies relaxation the two matrices differ quite a lot, and not just by their sign. Especially, the real part of the eigenvalues becomes always positive! In fact, relaxation works fine for the first matrix because the eigenvalues have a positive real part already, thus relaxation does not alter the nature of the problem. In the second matrix instead, the eigenvalues have negative real part, and thus relaxation changes the matrix from negative defined to positive defined. For your convenience, I attached a working example where this issue leads to a crash (is it the reason why the pressure equation is never relaxed?). I attached a version of icoFoam (icoPRelaxFoam) with a relaxation of the pressure equation and a switchable sign of the elliptic problem (that can be controlled from transportProperties) and a cavity test. You will see that when the relaxation is activated and the sign is positive, the solver crashes, while with negative sign the solver works just fine with the relaxed matrix. I implemented a simple fix in the attached relaxationTest.C, which consists in ensuring that the diagonal keeps the right sign. As you see, this can be trivially implemented in fvMatrix. I hope this was useful.  
Steps To Reproduce  Everything is packed in icoPRelaxFoam.zip Simply compile the solver and run the included cavity example. Switch the negativeElliptic keyword in transportProperties from true to false to reproduce the issue. You can also use the solver in relaxationTest.zip, which simply prints out small matrices before and after relaxation. The fix to this bug is implemented there. You can use the test folder (blockMesh followed by relaxationTest... I forgot the Allrun sorry) to check the effect on the matrix. The fix ensures that the relaxed matrices (positive and negative elliptic) are the same but with opposite sign, as it should be.  
Tags  No tags attached.  

icoPRelaxFoam.zip (9,051 bytes) relaxationTest.zip (6,283 bytes) 

It is essential to formulate the equation so that the diagonal is positive when applying relaxation. Testing the sign of the diagonal is too risky because for some equations the diagonal might be mixed positive and negative before relaxation and we have to assume what it should be after relaxation and we choose that it should be positive. 

Thank you for the kind comment. Why not just scaling the terms in the diagonal keeping the same (mixed) signature to ensure relax(A) =  relax(A)? In this case, the mixed nature would be preserved in the eigenvalues. Isn' t imposing that all the eigenvalues of A are positive a bit too dramatic since it leads to the aforementioned issues in the OpenFOAM API? 

There are many other parts of OpenFOAM which currently rely on the diagonal of the equation matrix being positive, are you planning to have special treatment in all of those? I think we would need a sign switch in all of those parts so that the implementer of the equation declares which the sign of the diagonal is expected to be. This would add an enormous amount of clutter and maintenance overhead, wouldn't it be better to arrange the equations so that the diagonal is positive? Why is this a problem? 

Well, it is clearly a very technical and subtle pitfall for anyone who writes code using OpenFOAM. Especially since one would not expect the relax() function to perform such a dramatic operation on the matrix and it is not so obvious why a matrix should possess such a feature. Perhaps this could be added to section 4.6.2 of the user guide, so that programmers are aware of that. 

This would not need to be discussed in the userguide which covers the usage of the solvers provided with OpenFOAM, it would need to be in a programmers guide. 

Changing OpenFOAM so that the diagonal of equation matrices can have either sign would be a significant development requiring funding and so far none of the sponsors of the project have requested it or even shown interest in it. 
Date Modified  Username  Field  Change 

20200321 14:59  Federico Municchi  New Issue  
20200321 14:59  Federico Municchi  File Added: icoPRelaxFoam.zip  
20200321 14:59  Federico Municchi  File Added: relaxationTest.zip  
20200321 15:52  henry  Note Added: 0011266  
20200321 15:53  henry  Priority  immediate => none 
20200321 15:53  henry  Severity  crash => feature 
20200321 15:53  henry  Category  Bug => Feature 
20200321 15:53  henry  Description Updated  View Revisions 
20200321 15:53  henry  Steps to Reproduce Updated  View Revisions 
20200321 16:22  Federico Municchi  Note Added: 0011267  
20200321 16:38  henry  Note Added: 0011268  
20200321 18:45  Federico Municchi  Note Added: 0011269  
20200321 18:53  henry  Note Added: 0011270  
20200321 18:55  henry  Assigned To  => henry 
20200321 18:55  henry  Status  new => closed 
20200321 18:55  henry  Resolution  open => no change required 
20200321 18:55  henry  Note Added: 0011271 