Closed anliangw closed 4 years ago
Difference only makes sense with two arguments. I guess you want to use union somewhere there.
forexample, We have one rectangle,one triangle and one circle. The rectangle is big enough to cover the triangle and circle. Then we would like to subtract the area encircled by the triangle and the circle from the rectangle. Is this able to be approached by the function “union”?
diff(rect, union(triangle, circle)) would make sense.
I tried the way you mentioned. It seems dmsh.Difference works well, but the dmsh.generate() failed. The error message and my code are listed below: (1) code r = dmsh.Rectangle(60, 330, 380, 650) geo1 = dmsh.Union( [dmsh.Circle([194, 543], 51), dmsh.Rectangle(143, 245, 440, 543)] ) geo = dmsh.Difference(r, geo1) geo.plot( ) show( )
np.random.seed(0) x, cells = dmsh.generate( geo, 10, tol=1.0e-5 ) ### lower tol to reduce the computation cost
plt.triplot(x[:,0], x[:,1], cells) plt.show()
(2) error mesage x, cells = dmsh.generate( geo, 10, tol=1.0e-5 ) ### lower tol to reduce the computation cost File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\dmsh\main.py", line 163, in generate pts[is_outside] = geo.boundary_step(pts[is_outside].T).T File "C:\Users\User\AppData\Roaming\Python\Python36\site-packages\dmsh\geometry\difference.py", line 48, in boundary_step assert k <= max_steps, "Exceeded maximum number of boundary steps." AssertionError: Exceeded maximum number of boundary steps.
Thank you for your help!
Please always post the complete code with all imports and such. Also please use fenced code blocks. https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks
Sorry for my code. The complete codes are listed below:
from pylab import *
from scipy.interpolate import griddata
##from helpers import assert_norm_equality
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
import dmsh
r = dmsh.Rectangle(60, 330, 380, 650) ##50, 360, 350, 710
c = dmsh.Circle([194, 543], 51) ###Diameter=51
r1 = dmsh.Rectangle(143, 245, 492, 594)
geo1 = dmsh.Union( [dmsh.Circle([194, 543], 51), dmsh.Rectangle(143, 245, 440, 543)] )
geo = dmsh.Difference(r, geo1)
geo.plot( )
show( )
np.random.seed(0)
x, cells = dmsh.generate( geo, 10, tol=1.0e-5 ) ### lower tol to reduce the computation cost
plt.triplot(x[:,0], x[:,1], cells)
plt.show()
Thanks again @anliangw for the report. There was an issue with how dmsh finds the boundary in Unions, and it's fixed now. Update to 0.1.5 and try again. Let me know if you have any more problems.
How could I accomplish Difference(Geo0, Geo1, Geo2)? Directly, I tried Difference(Geo0, Geo1, Geo2), and it does not work for this manipulation. Actually, I tried GeoTemp = Difference(Geo0, Geo1), Geo = Difference(GeoTemp, Geo2), it still failed. I check out the code of Difference, multi-operation seems not to be supported. Does this function only support the Difference for two geometries? Is there any other option for several times of Difference? Thank you!