Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the list output instead of the string with "mapdl.ndist". #823

Closed
RomanIlchenko1308 opened this issue Jan 11, 2022 · 0 comments · Fixed by #826
Closed

Get the list output instead of the string with "mapdl.ndist". #823

RomanIlchenko1308 opened this issue Jan 11, 2022 · 0 comments · Fixed by #826
Assignees

Comments

@RomanIlchenko1308
Copy link
Contributor

RomanIlchenko1308 commented Jan 11, 2022

Describe the bug

During the simulation of VM8 #820 with pymapdl I have figured out that:

https://github.com/pyansys/pymapdl/blob/d8c70c26c7dd973ca12611ba76aed56dbe052650/ansys/mapdl/core/_commands/preproc/keypoints.py#L198

mapdl.kdist - calculates and lists ([X, Y, Z] coordinates) the distance between two keypoints using →

def parse_kdist(msg):
    """Parse the keypoint value from a keypoint message"""
    finds = re.findall(NUM_PATTERN, msg)[-3:]
    if len(finds) == 3:
        return [float(val) for val in finds]

calculates and lists ([X, Y, Z] coordinates) the distance between two keypoints.
It is really and really helpful and useful.

But if you try to obtain the distances between the nodes using mapdl.ndist, you will obtain string output!

To Reproduce
To see the string output with mapdl.ndist run the code below:

###############################################################################
# Import and start MAPDL

from ansys.mapdl.core import launch_mapdl

mapdl = launch_mapdl()
mapdl.finish()
mapdl.run("/CLEAR,all")
mapdl.prep7()


###############################################################################
# Simple class with coordinate attributes and the method to create nodes
# and get the distance between them.

class Create:
    def __init__(self, x1, y1, z1, x2, y2, z2):
        # Attributes
        print("Define Distance")
        self.x1 = x1
        self.y1 = y1
        self.z1 = z1
        self.x2 = x2
        self.y2 = y2
        self.z2 = z2

    def create_node_method(self):
        node1 = mapdl.n(x=self.x1, y=self.y1, z=self.z1)
        node2 = mapdl.n(x=self.x2, y=self.y2, z=self.z2)
        dist_xyz_n = mapdl.ndist(node1, node2)
        return dist_xyz_n

node = Create(1, 2, 3, 10, 20, 30)
node_dist = node.create_node_method()
print(node_dist)
print(f"The Data Type is: {type(node_dist)}")


###############################################################################

Expected results form mapdl.ndist
image

HOW IT WORKS FOR mapdl.kdist

  ###############################################################################
  # Import and start MAPDL.
  
  import math
  from ansys.mapdl.core import launch_mapdl
  
  mapdl = launch_mapdl()
  mapdl.finish()
  mapdl.run("/CLEAR,all")
  mapdl.prep7()
  
  # Simple class with coordinate attributes and the method to create keypoints and get the distance between them.
  class Create:
      def __init__(self, x1, y1, z1, x2, y2, z2):
          # Attributes
          print("Define Distance")
          self.x1 = x1
          self.y1 = y1
          self.z1 = z1
          self.x2 = x2
          self.y2 = y2
          self.z2 = z2
  
      def create_kp_method(self):
          kp1 = mapdl.k(x=self.x1, y=self.y1, z=self.z1)
          kp2 = mapdl.k(x=self.x2, y=self.y2, z=self.z2)
          list_dist_output = mapdl.kdist(kp1, kp2)
          print(f"The LIST of X, Y, Z coordinate distances between keypoints: {list_dist_output}")
          kp_x, kp_y, kp_z = list_dist_output
          dist_kp = math.sqrt(kp_x ** 2 + kp_y ** 2 + kp_z ** 2)
          mapdl.kplot(show_keypoint_numbering=True,
                      background="black",
                      show_bounds=True,
                      font_size=26)
          return dist_kp
  
  
  kp = Create(1, 2, 3, 10, 20, 30)
  kp_dist = kp.create_kp_method()
  print(f"Distance between keypoints is: {kp_dist}")
  
  
  ###############################################################################

**Expected results from mapdl.kdist **
Screenshots
image

SUGGESTIONS

We can add one more parsing script for mapdl.ndist as it was done for mapdl.kdist:

locatin of the mapdl.kdist:

https://github.com/pyansys/pymapdl/blob/d8c70c26c7dd973ca12611ba76aed56dbe052650/ansys/mapdl/core/_commands/preproc/keypoints.py#L198

Location of the parsing script for mapdl.kdist:

https://github.com/pyansys/pymapdl/blob/d8c70c26c7dd973ca12611ba76aed56dbe052650/ansys/mapdl/core/_commands/parse.py#L21

image

System Information:

  • OS: [Windows10]
  • Ansys version (21.2)
  • PyMAPDL version (0.60.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants