Comments (7)
Fixed now.
from dmsh.
Can you try and simplify this more? E.g., is optimesh required for this? How about the tolerance? A simpler mesh?
In any case, duplicate points are bad and should indeed now happen.
Edit: Also, which points are duplicated?
from dmsh.
I have tried various values for r
, setting tol=1.0e-14
and eliminating optimesh
, but still get duplicate points.
The following function removes duplicates from the pts array, but that still leaves the associated cells to be removed.
def testForDups(pts) :
# ref: https://stackoverflow.com/questions/31097247/remove-duplicate-rows-of-a-numpy-array
new_array = [tuple(row) for row in pts]
pts_unique = np.unique(new_array,axis=0)
return pts_unique
And the following function returns the indices of duplicate rows,
def findDups(pts) :
# Ref: https://stackoverflow.com/questions/48099479/how-do-you-find-and-save-duplicated-rows-in-a-numpy-array
unq, count = np.unique(pts, axis=0, return_counts=True)
repeated_groups = unq[count > 1]
pts_dupIndices = []
for repeated_group in repeated_groups:
repeated_idx = np.argwhere(np.all(pts == repeated_group, axis=1))
pts_dupIndices.append(repeated_idx.ravel())
return(np.array(pts_dupIndices))
for the above example, it returns,
[[ 1 13]
[ 2 16]]
Which indicates that rows 1
and 13
of pts
are duplicated and rows 2
and 16
are also duplicated.
from dmsh.
Further experimentation shows that in the above example, the duplicate points are generated due to the union of two objects which have part of their boundaries exactly overlapping. By moving the overlapping boundary part of one object so that it lies within the other object boundary, duplicate points are avoided. Therefore, changing the above example to,
import dmsh
import optimesh
geo = dmsh.Union([dmsh.Rectangle(-1.0, +0.9,-0.2, +0.2),
dmsh.Rectangle(+0.5, +1.0,-0.6, +1.0),
dmsh.Circle([-0.5, 0.0], 0.4)])
geo = dmsh.Difference(geo, dmsh.Circle([+0.5, 0.2], 0.2))
r = 0.1
pts, cells = dmsh.generate(geo, edge_size=r, tol=1.0e-10)
# optionally optimize the mesh
pts, cells = optimesh.optimize_points_cells(pts, cells, "CVT (full)",
1.0e-10, 100)
dmsh.helpers.show(pts, cells, geo)
avoids this particular problem. However, this approach is unlikely to solve all problems.
from dmsh.
Yeah, I have another example which doesn't have overlapping boundaries but still has duplicate points. The geometry is that of DFG benchmark 2D-2, as reused in the FEniCS tutorial. Looking to redo that in pure Python, without mshr (gdmcbain/fenics-tuto-in-skfem#5), I tried dmsh but with current main this generates 1670 points of which only 1662 are unique.
import dmsh
import numpy as np
geo = dmsh.Difference(
dmsh.Rectangle(0.0, 2.2, 0.0, 0.41),
dmsh.Circle([.2, .2], 0.05)
)
points, triangles = dmsh.generate(geo, 0.025, tol=1e-9)
tmp = np.ascontiguousarray(points) # test from skfem.Mesh._validate
if points.shape[0] != np.unique(tmp.view([('', tmp.dtype)] * tmp.shape[1])).shape[0]:
print(points.shape[0], np.unique(tmp.view([('', tmp.dtype)] * tmp.shape[1])).shape[0])
from dmsh.
I should add that this example was working (no duplicate points) last year; I only noticed it broken a couple of weeks ago. It still works with
pip install -U dmsh==0.2.2 meshplex==0.13.6
(Not pinning meshplex raises AttributeError: 'MeshTri' object has no attribute 'node_coords'.)
from dmsh.
Intermediate note: This happens because there are points which are not part of any cell:
is_part_of_cell = np.zeros(len(points), dtype=bool)
is_part_of_cell[cells.flat] = True
assert np.all(is_part_of_cell)
Kicking out those points should work for you while I'm working on a solution. (Note that the cells array has to be updated, too.)
from dmsh.
Related Issues (20)
- It would be super useful if you could specify the number of nodes you wanted in your mesh HOT 1
- update expected test results for meshplex 0.15.4 HOT 2
- Boundary Node Identification HOT 6
- Upgrade results in error
- coordinates and elements array in poisson problem HOT 1
- How to order boundary points/edges HOT 10
- create_edges can no longer be found from MeshTri HOT 1
- Could this generate mesh on an arbitrary contour? HOT 4
- bending?
- MeshTri troubles
- Mesh 2 surfaces in different planes HOT 1
- potentially better force function HOT 7
- use median for scaling factor?
- can't import dmsh HOT 2
- Further documentation please HOT 1
- Anaconda - dmsh installation problem HOT 2
- missing attribute 'node_coords' HOT 6
- Problems with install HOT 1
- Issue with custom geometries and max boundary steps
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dmsh.