Coordinate-Based Selections
Defining a Ball Selection Node
The Ball selection node is defined by a centerpoint and a radius. The selection can include geometric entities that are completely or partially inside the ball. The selection can be set up by using either the COMSOL API directly or the mphselectcoords function. There are different ways to define the ball selections: Ball Selection Using the COMSOL API or Ball Selection Using mphselectcoords.
Ball Selection Using the COMSOL API
To add a ball selection to a model object enter:
model.component(<ctag>).selection.create(<seltag>, 'Ball')
To set the coordinates (<x0>, <y0>, <z0>) of the selection centerpoint, enter:
sel.set('posx', <x0>)
sel.set('posy', <y0>)
sel.set('posz', <z0>)
where sel is a link to a Ball Selection node and <x0>, <y0>, <z0> are double values.
Specify the ball radius <r0> with the command:
sel.set('r', <r0>)
where <r0> is a double floating-point value.
To specify the geometric entity level, enter:
sel.set('entitydim', edim)
where edim is an integer defining the space dimension value (3 for domains, 2 for boundaries/domains, 1 for edges/boundaries, and 0 for points).
The selection also specifies the condition for geometric entities to be selected:
sel.set('condition', condition)
where condition can be:
'inside', to select all geometric entities completely inside the ball,
'intersects', to select all geometric entities that intersect the ball (default),
'somevertex', to select all geometric entities where at least some vertex is inside the ball, or
'allvertices', to select all geometric entities where all vertices are inside the ball.
Ball Selection Using mphselectcoords
The function mphselectcoords retrieves geometric entities enclosed by a ball.
To get the geometric entities enclosed by a ball of radius r0, with its center positioned at (x0,y0,z0) enter the command:
idx = mphselectcoords(model, <geomtag>, [<x0>,<y0>,<z0>], ...
entitytype,'radius',<r0>)
where <geomtag> is the tag of geometry where the selection, and entitytype, can be one of 'point', 'edge', 'boundary', or 'domain'.
The above function returns the entity indices list. Use it to specify a feature selection or to create an explicit selection as described in Setting an Explicit Selection.
You can also refine the search using several search ball. To do so set the coordinates as a NxM array where N corresponds of the number of point to use and M the space dimension of the geometry as in the command below:
idx = mphselectcoords(model, <geomtag>, ...
[<x0>,<y0>,<z0>; <x1>,<y1>,<z1>;...], entitytype)
This returns the geometric entity indices that have vertices near both the given coordinates using the tolerance radius.
To include any geometric entities in the selection that have at least one vertex inside the search ball, set the property include to 'any':
idx = mphselectcoords(model, <geomtag>, ...
[<x0>,<y0>,<z0>; <x1>,<y1>,<z1>], entitytype, 'include', 'any');
In case the model geometry is finalized as an assembly, you have distinct geometric entities for each part of the assembly (pair). Specify the adjacent domain index to avoid selection of any overlapping geometric entities. Set the adjnumber property with the domain index:
idx = mphselectcoords(model, <geomtag>, [<x0>,<y0>,<z0>], ...
entitytype,'radius',<r0>,'adjnumber',<idx>)
where <idx> is the domain index adjacent to the desired geometric entities.
Defining a Box Selection Node
The Box selection node is defined by two diagonally opposite points of a box (in 3D) or rectangle (in 2D). There are different ways to define the box selections: Box Selection Using the COMSOL API or Box Selection Using mphselectbox
Box Selection Using the COMSOL API
This command adds a box selection to the model object:
model.component(<ctag>).selection.create(<seltag>, 'Box')
To specify the points (<x0>, <y0>, <z0>) and (<x1>, <y1>, <z1>), enter:
sel.set('xmin', <x0>)
sel.set('ymin', <y0>)
sel.set('zmin', <z0>)
sel.set('xmax', <x1>)
sel.set('ymax', <y1>)
sel.set('zmax', <z1>)
where sel is a link to a Box Selection node and <x0>, <y0>, <z0>, <x1>, <y1>, <z1> are double values.
To specify the geometric entities levels use the command:
sel.set('entitydim', edim)
where edim is an integer defining the space dimension value (3 for domains, 2 for boundaries/domains, 1 for edges/boundaries, and 0 for points).
The selection also specifies the condition for geometric entities to be selected:
sel.set('condition', condition)
where condition can be:
'inside', to select all geometric entities completely inside the ball,
'intersects', to select all geometric entities that intersect the ball (default),
'somevertex', to select all geometric entities where at least some vertex is inside the ball, or
'allvertices', to select all geometric entities where all vertices are inside the ball.
Box Selection Using mphselectbox
The function mphselectbox retrieves geometric entities enclosed by a box (in 3D) or rectangle (in 2D).
To get the geometric entities of type entitytype enclosed by the box defined by the points (x0,y0,z0) and (x1,y1,z1), enter the command:
idx = mphselectbox(model,<geomtag>,...
[<x0> <x1>;<y0> <y1>;<z0> <z1>], entitytype)
where <geomtag> is the geometry tag where the selection is applied, and entitytype can be one of 'point', 'edge', 'boundary', or 'domain'.
The above function returns the entity indices list. Use it to specify a feature selection or to create an explicit selection as described in Setting an Explicit Selection.
By default the function searches for the geometric entity vertices near these coordinates using the tolerance radius. It returns only the geometric entities that have all vertices inside the box or rectangle. To include any geometric entities in the selection that have at least one vertex inside the search ball, set the property include to 'any':
idx = mphselectbox(model,<geomtag>,...
[<x0> <x1>;<y0> <y1>;<z0> <z1>], entitytype,'include','any')
In case the model geometry is finalized as an assembly (pair), you have distinct geometric entities for each part of the assembly. Specify the adjacent domain index to avoid selection of overlapping geometric entities. Set the adjnumber property with the domain index:
idx = mphselectbox(model,<geomtag>,...
[<x0> <x1>;<y0> <y1>;<z0> <z1>], entitytype, 'adjnumber', <idx>)
where <idx> is the domain index adjacent to the desired geometric entities.
Retrieving point coordinates using a selection
Use mphgetcoords to retrieve coordinates of the points that belong to a given geometry. Run the command below to get the coordinates of the points that belong to the desired geometric entity:
c = mphgetcoords(model,<geomtag>,entitytype,<idx>)
where <geomtag> is the geometry tag where the selection is applied, entitytype can be one of 'point', 'edge', 'boundary', or 'domain' and <idx> is a integer array containing the geometric entity indices. c is a Nx2 double array containing the point coordinates where N is the number of points.