mesh.Mesh.test#
- Mesh.test(nodes='all', dir=0, min=None, max=None, atol=0.0)#
Flag elements having nodal coordinates between min and max.
This is comparable with
coords.Coords.test()but operates at the Mesh element level. It tests the position of one or more nodes of the elements of theMeshwith respect to one or two parallel planes. This is very useful in clipping a mesh in a specified direction. In most cases the clipping direction is one of the global coordinate axes, but a general direction may be used as well.Testing along global axis directions is highly efficient. It tests whether the corresponding coordinate is above or equal to the min value and/or below or equal to the max value. Testing in a general direction tests whether the distance to the min plane is positive or zero and/or the distance to the max plane is negative or zero.
Parameters#
- nodes: int, list of ints or string
Specifies which points of the elements are taken into account in the tests. It should be one of the following:
a single node index (smaller than self.plexitude()),
a list of node indices (all smaller than self.plexitude()),
one of the special strings: ‘all’, ‘any’, ‘none’.
The default (‘all’) will flag the elements that have all their nodes between the planes x=min and x=max, i.e. the elements that fall completely between these planes.
- dir: a single int or a float array_like (3,)
The direction in which to measure distances. If an int, it is one of the global axes (0,1,2). Else it is a vector with 3 components. The default direction is the global x-axis.
- min: float or point-like, optional
Position of the minimal clipping plane. If dir is an int, this is a single float giving the coordinate along the specified global axis. If dir is a vector, this must be a point and the minimal clipping plane is defined by this point and the normal vector dir. If not provided, there is no clipping at the minimal side.
- max: float or point-like.
Position of the maximal clipping plane. If dir is an int, this is a single float giving the coordinate along the specified global axis. If dir is a vector, this must be a point and the maximal clipping plane is defined by this point and the normal vector dir. If not provided, there is no clipping at the maximal side.
- atol: float
Tolerance value added to the tests to account for accuracy and rounding errors. A min test will be ok if the point’s distance from the min clipping plane is > -atol and/or the distance from the max clipping plane is < atol. Thus a positive atol widens the clipping planes.
Returns#
- 1-dim bool array
Array with length
self.n_elems()flagging the elements that pass the test(s). The return value can directly be used as an index inselect()orremove_selected()to obtain aMeshwith the elements satisfying the test or not. Or you can usenp.where(result)[0]to get the indices of the elements passing the test.
Raises#
- ValueError: At least one of min or max have to be specified
If neither min nor max are provided.
See Also#
coords.Coords.test(): testing individual pointsgeometry.Geometry.select(): return only the selected elementsgeometry.Geometry.remove_selected(): return all but the selected elements
Examples#
>>> M = Mesh(eltype='tri3').subdivide(2) >>> M.coords Coords([[0. , 0. , 0. ], [0.5, 0. , 0. ], [1. , 0. , 0. ], [0. , 0.5, 0. ], [0.5, 0.5, 0. ], [0. , 1. , 0. ]]) >>> M.elems Elems([[0, 1, 3], [1, 2, 4], [3, 4, 5], [1, 4, 3]]..., eltype=Tri3) >>> M.test(min=0.0,max=0.5) array([ True, False, True, True])
>>> M.test(nodes=[0],min=0.0,max=0.2) array([ True, False, True, False]) >>> M.test(dir=(-1.,1.,0.), min=(0.,0.,0.)) array([False, False, True, False]) >>> M.test(dir=(-1.,1.,0.), min=(0.,0.,0.), nodes='any') array([ True, True, True, True]) >>> M.test(dir=(-1.,1.,0.), min=(0.,0.,0.), nodes='any', atol=-1.e-5) array([ True, False, True, True])