#### View Issue Details

ID Project Category View Status Date Submitted Last Update 0002938 OpenFOAM Bug public 2018-05-16 07:45 2018-05-22 20:05 ole henry normal minor always resolved fixed GNU/Linux Ubuntu 14.04 dev dev 0002938: layerParameters.C: Number of iterations insufficient Dear OpenFOAMers, This is related to issue 0001918, where you increased the maximum number of iterations from 10 to 20. This seems sufficient for moderate number of layers, but I noticed that when inserting more layers (maybe unreasoably many...) this is still not sufficient. For trying I have re-implemented in python, see attached notebook. I would suggest to increase the maximum number of iterations to 200 or even more, as this costs hardly any CPU time and anyway it is just the maximum number of iterations. Thanks!

#### Activities

 2018-05-16 07:45 reporter LayerCalc.html (257,084 bytes)     LayerCalc
In [2]:
from math import *
In [39]:
def layerExpansionRatio(n,totalOverFirst):     maxIters = 200     tol = 1e-8       if (abs(n-totalOverFirst) < tol):          return 1.0       # // Calculate the bounds of the solution       if (totalOverFirst < n):          minR = 0.0          maxR = pow(totalOverFirst/n, 1/(n-1))     else:          minR = pow(totalOverFirst/n, 1/(n-1))          maxR = totalOverFirst/(n - 1);       # // Starting guess     r = 0.5*(minR + maxR);       for i in range(maxIters):         prevr = r;           fx = pow(r, n) - totalOverFirst*r - (1 - totalOverFirst);         dfx = n*pow(r, n - 1) - totalOverFirst;         r -= fx/dfx;          print 'Iter=',i,' r=',r         if (abs(r - prevr) < tol):              break     return r
In [48]:
nLayers = 16 desiredExpansionRatio = 1.3 firstLayerThickness = 0.003 totalThickness = firstLayerThickness*((1.-pow(desiredExpansionRatio,nLayers))/(1.-desiredExpansionRatio)-1.) print 'totalThickness', totalThickness finalLayerThickness = firstLayerThickness * pow(desiredExpansionRatio,nLayers -1 )  print layerExpansionRatio(nLayers,totalOverFirst=totalThickness/firstLayerThickness)
totalThickness 0.652416609183 Iter= 0  r= 7.26475634566 Iter= 1  r= 6.81070907407 Iter= 2  r= 6.38503975696 Iter= 3  r= 5.98597477221 Iter= 4  r= 5.61185134908 Iter= 5  r= 5.2611106401 Iter= 6  r= 4.93229122591 Iter= 7  r= 4.62402302628 Iter= 8  r= 4.33502159194 Iter= 9  r= 4.06408275407 Iter= 10  r= 3.81007761001 Iter= 11  r= 3.57194782704 Iter= 12  r= 3.34870125055 Iter= 13  r= 3.13940781266 Iter= 14  r= 2.94319575786 Iter= 15  r= 2.75924824865 Iter= 16  r= 2.58680052001 Iter= 17  r= 2.42513799285 Iter= 18  r= 2.27359630126 Iter= 19  r= 2.13156540152 Iter= 20  r= 1.99850257441 Iter= 21  r= 1.87396470467 Iter= 22  r= 1.75768132611 Iter= 23  r= 1.64970973591 Iter= 24  r= 1.55074028734 Iter= 25  r= 1.46262385274 Iter= 26  r= 1.38905017869 Iter= 27  r= 1.33568101213 Iter= 28  r= 1.30739430053 Iter= 29  r= 1.29995911775 Iter= 30  r= 1.29950094128 Iter= 31  r= 1.29949928276 Iter= 32  r= 1.29949928274 1.29949928274
 LayerCalc.html (257,084 bytes) 2018-05-17 16:02 manager   ~0009591 Last edited: 2018-05-17 16:04 Why do you think that 200 is an appropriate maximum number of iterations? Under what conditions do you believe up to 200 is needed? In the example you provided 32 appears to be sufficient. Do you think the maximum number should depend on the number of layers? 2018-05-18 10:20 reporter   ~0009604 Hi Henry, Thanks for taking care of this! I had suggested 200 as a large number which should never be reached. Furthermore, the iterations hardly cost anything. Even 1000 would not be a problem and put us on the safe side. When I play around with the python code, the larger the ratio between the first and the last layer cell is (which equals the aspect ratio of the first layer cell, assuming a cubic final cell), the more iterations are required. For an aspect ratio of about 200, which seems not unreasonable for layers on smooth geometries, I need about 40 iterations. With 100 iterations I can reach an aspect ratio of ~ 1200. Even this might be acceptable for LowRe meshes. With 200 iterations I have an aspect ratio of 17000, which seems out of sensible range. But I would suggest an unreasonable high maximum number of iterations to ensure that it is never reached. An alternative would be to throw an error if the maximum number is reached. Currently no warning is given but only a wrong (too large) expansion ratio is used. We noticed the problem because snappyHexMesh crashed on some meshes with face matching problems at processor boundaries. The reason was that it tried to make a mesh with a first layer thickness of 1e-8 meter instead of 3 mm. But implementing an error message seems by far more effort than just increasing the maximum number of iterations. BR Ole 2018-05-22 20:05 manager   ~0009624 Resolved by commit 5caa5a3e9b8be651d34175d0923092f8aed55d05

#### Issue History

Date Modified Username Field Change
2018-05-16 07:45 ole New Issue
2018-05-16 07:45 ole File Added: LayerCalc.html
2018-05-16 07:45 ole Tag Attached: snappyHexMesh
2018-05-17 16:02 henry Note Added: 0009591
2018-05-17 16:03 henry Note Edited: 0009591
2018-05-17 16:04 henry Note Edited: 0009591
2018-05-18 10:20 ole Note Added: 0009604
2018-05-22 20:05 henry Assigned To => henry
2018-05-22 20:05 henry Status new => resolved
2018-05-22 20:05 henry Resolution open => fixed
2018-05-22 20:05 henry Fixed in Version => dev
2018-05-22 20:05 henry Note Added: 0009624