**sort_nset#

Description#

This command sorts a node set in increasing order with respect to the value of a user-specified function of the coordinates of the nodes.

Syntax#

The command has the following syntax:

**sort_nset \(~\,\) *nset_name nset-to-sort \(~\,\) *criterion function ; \(~\,\) [ *n2_sort ]

*nset_name

specifies the node set to sort. There is no default value.

*criterion

enter a function of the coordinates in order to sort by. It is a function of two points \(P_1 \left( x_1,y_1,z_1 \right)\) and \(P_2 \left( x_2,y_2,z_2 \right)\) within the nset (without the \(z_1\) and \(z_2\) for two-dimensional meshes). It may also compare node ids (the corresponding variables are named id1 and id2). The function must return whether \(P_1\) is “greater” than \(P_2\): criterion = -1 means \(P_1<P_2\) (no action taken), criterion = 0 means \(P_1=P_2\) (no action taken) and criterion = +1 means \(P_1>P_2\) (the order of the points will be changed). Do not forget the semicolon at the end. There is no default value.

*n2_sort

uses a brute-force \(O(n^2)\) sorting method, instead of the \(O(n\) log \(n)\) quicksort, which is used by default.

This option is included because the quicksort routine is broken on some systems.

Example#

**sort_nset
 *nset_name left
 *criterion x1<x2; % sort nset according to increasing x. Note the ;
**sort_nset
 *nset_name radial
 *criterion (x1*x1+y1*y1+z1*z1)>(x2*x2+y2*y2+z2*z2); % sort nset according
                   % to decreasing distance from the origin (0. 0. 0.).
                   % This generates an error message for 2-D meshes.

Example#

This second example will reorder opposite faces perio_x0 and perio_x1 in lexicographic order, to e.g. ensure they have the same order before applying an mpc2:

**sort_nset
 *nset_name perio_x0
 *criterion (y1>y2) + (y1==y2)*(x1>x2);
 *nset_name perio_x1
 *criterion (y1>y2) + (y1==y2)*(x1>x2);