### Can mshr.generate_mesh be stuck in infinte loop?

215
views
0
11 months ago by

I use mshr to create meshes for the computation of shape functions in a ms-gfem with oversampling.

Therefore i use the csg interface of mshr to specify domains with inclusions and an inner area using subdomains.

Here is an abridged code sample, where setting

number

high enough will cause

generate_mesh

to run seemlingly forever.

from dolfin import *
from mshr import *
import numpy as np
import numpy.random as rnd

resolution=2**5
number=1000

nodes = []
count = 0
while count < number:
tmp = 2*rnd.rand(2)-1
ok = True
for ii in range(len(nodes)):
dist = np.sqrt((tmp-nodes[ii])@(tmp-nodes[ii]))
ok = False
break
if ok:
nodes.append(tmp)
count += 1

print('creating csg objects')
domain = Rectangle(Point(-1,-1),Point(1,1))
inside = Circle(Point(0,0),0.5,200)
outside = domain-inside
for ii in range(1,number):

domain.set_subdomain(1, inside*inclusions)
domain.set_subdomain(2, outside-inclusions)
domain.set_subdomain(3, outside*inclusions)

print('meshing')
mesh = generate_mesh(domain, resolution)
mf = MeshFunction('size_t', mesh, 2, mesh.domains())

print('write')
out = XDMFFile(mpi_comm_world(), 'cells.xdmf')
out.write(mf)
del out

print('done')

It appears to me that

generate_mesh(domain, resolution)

seems to be stuck in an infinite loop or frozen or deadlocked.

From what i've seen the process still seems to be running, but I have no clue to what and if to a finite end.

Is the method guaranteed to terminate, i.e. do I only have to wait longer?

Or is it possible that there is a freeze/deadlock/infinite loop somewhere?

Most importantly, can I "configure" mshr/generate_mesh such that the method is guaranteed to terminate?

Community: FEniCS Project

0
11 months ago by
Hello Sa Wu, the resolution parameter you are giving has something to do with (not sure exactly how) with the amount of elements in the boundary. Even if this happens at a gobal level (might be per geometric element, then you would be  utterly lost), you are giving 1000 inclusions... so that even if those inclusions (circles) were approximated by squares, you would have 4000 nodes in the interior boundary only, without even considering the resolution you are trying to impose! Answer: Reduce resolution and number to 5 - 10 and it will work. Always test your code with small entries first and slowly increase until your computer can't continue... I have used that method many times and it has always worked hahah. Best Regards!
0
11 months ago by
Hello Sa Wu, the resolution parameter you are giving has something to do with (not sure exactly how) with the amount of elements in the boundary. Even if this happens at a gobal level (might be per geometric element, then you would be  utterly lost), you are giving 1000 inclusions... so that even if those inclusions (circles) were approximated by squares, you would have 4000 nodes in the interior boundary only, without even considering the resolution you are trying to impose! Answer: Reduce resolution and number to 5 - 10 and it will work. Always test your code with small entries first and slowly increase until your computer can't continue... I have used that method many times and it has always worked hahah. Best Regards!
0
10 months ago by

Thanks, I am well aware of the code sample working for small numbers.

I am, however, interested in a large number of inclusions, i.e. number > 1000, because that's the interesting case for the application, composite materials, I'm working on.

Also, I have no idea if or if not mshr is still working on my computer because the process is still running, memory consumption is still far from the computer's limits and I simply have no clue if the process is going to finish or not.

Then if it works for small numbers, it is ok. For such applications you would do better with a homogenization scheme, but it is just an opinion. If not, I would simply keep increasing the number of holes and keep track of how long it takes, that would be your limit. Keep in mind that afterwards you will have to solve that problem, so having 10^6 nodes won't make too much sense , even if you computer does finish (or maybe you have a huge cluster at your disposal).
written 10 months ago by Nicolás Barnafi