Why does the gmsh.model.addPhysicalGroup method slow down as the number of physical groups added in the past grows ?
I'm using gmsh with the Python API to mesh hundreds of thousands of surfaces per execution. Adding all those surfaces does not raise any time processing issue, but adding physical groups for each of them does.
Here is a simple code which looks like mine :
for i in range(10**6):
gmsh.model.addPhysicalGroup(2, [i], something_that_does_not_matter)
I've added a few lines in order to note the time every 5000 iterations:
a = time.time()
for i in range(10**6):
gmsh.model.addPhysicalGroup(2, [i], something_that_does_not_matter)
if i % 5000 == 0:
print("time to add the 5000 physicalGroups between indexes " + str(i - 5000) + " and " + str(i) + " = " + str(time.time() - a) + " sec")
a = time.time()
And here is a result :
time to add the 5000 physicalGroups between indexes 0 and 5000 = 0.5739531517028809 sec
time to add the 5000 physicalGroups between indexes 5000 and 10000 = 0.9146430492401123 sec
time to add the 5000 physicalGroups between indexes 10000 and 15000 = 1.5506558418273926 sec
time to add the 5000 physicalGroups between indexes 15000 and 20000 = 2.2221176624298096 sec
time to add the 5000 physicalGroups between indexes 20000 and 25000 = 2.888765573501587 sec
time to add the 5000 physicalGroups between indexes 25000 and 30000 = 3.5762274265289307 sec
time to add the 5000 physicalGroups between indexes 30000 and 35000 = 4.295364141464233 sec
time to add the 5000 physicalGroups between indexes 35000 and 40000 = 5.376680135726929 sec
time to add the 5000 physicalGroups between indexes 40000 and 45000 = 6.3387157917022705 sec
time to add the 5000 physicalGroups between indexes 45000 and 50000 = 7.365874767303467 sec
time to add the 5000 physicalGroups between indexes 50000 and 55000 = 8.327742099761963 sec
time to add the 5000 physicalGroups between indexes 55000 and 60000 = 10.032728672027588 sec
time to add the 5000 physicalGroups between indexes 60000 and 65000 = 12.319071769714355 sec
time to add the 5000 physicalGroups between indexes 65000 and 70000 = 14.125726461410522 sec
time to add the 5000 physicalGroups between indexes 70000 and 75000 = 15.161083936691284 sec
time to add the 5000 physicalGroups between indexes 75000 and 80000 = 16.389020442962646 sec
time to add the 5000 physicalGroups between indexes 80000 and 85000 = 16.479230880737305 sec
time to add the 5000 physicalGroups between indexes 85000 and 90000 = 17.253931045532227 sec
time to add the 5000 physicalGroups between indexes 90000 and 95000 = 18.239039421081543 sec
time to add the 5000 physicalGroups between indexes 95000 and 100000 = 20.08899474143982 sec
time to add the 5000 physicalGroups between indexes 100000 and 105000 = 21.992425441741943 sec
time to add the 5000 physicalGroups between indexes 105000 and 110000 = 22.5928316116333 sec
time to add the 5000 physicalGroups between indexes 110000 and 115000 = 24.1432147026062 sec
time to add the 5000 physicalGroups between indexes 115000 and 120000 = 26.368208169937134 sec
time to add the 5000 physicalGroups between indexes 120000 and 125000 = 27.39620876312256 sec
time to add the 5000 physicalGroups between indexes 125000 and 130000 = 29.076743364334106 sec
time to add the 5000 physicalGroups between indexes 130000 and 135000 = 31.327500581741333 sec
time to add the 5000 physicalGroups between indexes 135000 and 140000 = 32.503684282302856 sec
time to add the 5000 physicalGroups between indexes 140000 and 145000 = 33.54697942733765 sec
time to add the 5000 physicalGroups between indexes 145000 and 150000 = 35.205891847610474 sec
time to add the 5000 physicalGroups between indexes 150000 and 155000 = 36.67985653877258 sec
time to add the 5000 physicalGroups between indexes 155000 and 160000 = 39.13882255554199 sec
time to add the 5000 physicalGroups between indexes 160000 and 165000 = 39.95758247375488 sec
time to add the 5000 physicalGroups between indexes 165000 and 170000 = 41.61710453033447 sec
I'm wondering why it is slowing down and if it is possible to do the same thing with a speed which is not dependant on the number of physical groups added in the past.
edit : I've got a similar issue when extruding meshes, maybe it's the same cause ?
Edited by Stepan Parant