|
| 1 | + |
| 2 | +class _EntityNearestEntityQueries: |
| 3 | + _mapdl = None |
| 4 | + |
| 5 | + def nnear(self, n: int) -> int: |
| 6 | + """Returns the selected node nearest node `n`. |
| 7 | +
|
| 8 | + Parameters |
| 9 | + ---------- |
| 10 | + n : int |
| 11 | + Node number |
| 12 | +
|
| 13 | + Returns |
| 14 | + ------- |
| 15 | + int |
| 16 | + Node number |
| 17 | +
|
| 18 | + Examples |
| 19 | + -------- |
| 20 | + In this example we construct a solid box and mesh it. Then we |
| 21 | + use the ``Query`` method ``node`` to find the node closest to |
| 22 | + the centre of the block and finally use ``nnear`` to find the |
| 23 | + node nearest to that. |
| 24 | +
|
| 25 | + >>> from ansys.mapdl.core import launch_mapdl |
| 26 | + >>> mapdl = launch_mapdl() |
| 27 | + >>> mapdl.prep7() |
| 28 | + >>> mapdl.et(1, 'SOLID5') |
| 29 | + >>> mapdl.block(0, 10, 0, 10, 0, 10) |
| 30 | + >>> mapdl.esize(3) |
| 31 | + >>> mapdl.vmesh('ALL') |
| 32 | + >>> q = mapdl.query() |
| 33 | + >>> node_number = q.node(5., 5., 5.) |
| 34 | + >>> nearest_node = q.nnear(node_number) |
| 35 | + >>> node_number, nearest_node |
| 36 | + (112, 103) |
| 37 | + """ |
| 38 | + response = self._mapdl.run(f'_=NNEAR({n})') |
| 39 | + integer = self._parse_parameter_integer_response(response) |
| 40 | + return integer |
| 41 | + |
| 42 | + def knear(self, k: int) -> int: |
| 43 | + """Returns the selected keypoint nearest keypoint `k`. |
| 44 | +
|
| 45 | + Parameters |
| 46 | + ---------- |
| 47 | + k : int |
| 48 | + Keypoint number |
| 49 | +
|
| 50 | + Returns |
| 51 | + ------- |
| 52 | + int |
| 53 | + Keypoint number |
| 54 | +
|
| 55 | + Examples |
| 56 | + -------- |
| 57 | + In this example we construct two keypoints and then verify that |
| 58 | + the nearest keypoint to one is the other. |
| 59 | +
|
| 60 | + >>> from ansys.mapdl.core import launch_mapdl |
| 61 | + >>> mapdl = launch_mapdl() |
| 62 | + >>> mapdl.prep7() |
| 63 | + >>> k1 = mapdl.k(1, 0, 0, 0) |
| 64 | + >>> k2 = mapdl.k(2, 1, 1, 1) |
| 65 | + >>> q = mapdl.query() |
| 66 | + >>> q.knear(k1) |
| 67 | + 1 |
| 68 | +
|
| 69 | + >>> q.knear(k1) == k2 |
| 70 | + True |
| 71 | + """ |
| 72 | + response = self._mapdl.run(f'_=KNEAR({k})') |
| 73 | + integer = self._parse_parameter_integer_response(response) |
| 74 | + return integer |
| 75 | + |
| 76 | + def enearn(self, n: int) -> int: |
| 77 | + """Returns the selected element nearest node `n`. |
| 78 | +
|
| 79 | + The element position is calculated from the selected nodes. |
| 80 | +
|
| 81 | + Parameters |
| 82 | + ---------- |
| 83 | + n : int |
| 84 | + Node number |
| 85 | +
|
| 86 | + Returns |
| 87 | + ------- |
| 88 | + int |
| 89 | + Element number |
| 90 | +
|
| 91 | + Examples |
| 92 | + -------- |
| 93 | + In this example we construct a solid box and mesh it. Then we |
| 94 | + use the ``Query`` method ``node`` to find the node closest to |
| 95 | + the centre of the block and finally use ``enearn`` to find the |
| 96 | + element nearest to that node. |
| 97 | +
|
| 98 | + >>> from ansys.mapdl.core import launch_mapdl |
| 99 | + >>> mapdl = launch_mapdl() |
| 100 | + >>> mapdl.prep7() |
| 101 | + >>> mapdl.et(1, 'SOLID5') |
| 102 | + >>> mapdl.block(0, 10, 0, 10, 0, 10) |
| 103 | + >>> mapdl.esize(3) |
| 104 | + >>> mapdl.vmesh('ALL') |
| 105 | + >>> q = mapdl.query() |
| 106 | + >>> node_number = q.node(5., 5., 5.) |
| 107 | + >>> nearest_element = q.enearn(node_number) |
| 108 | + >>> node_number, nearest_element |
| 109 | + (112, 22) |
| 110 | + """ |
| 111 | + response = self._mapdl.run(f'_=ENEARN({n})') |
| 112 | + integer = self._parse_parameter_integer_response(response) |
| 113 | + return integer |
| 114 | + |
0 commit comments