Reads a triangle .ele file. First line is nElem 3 0 0 followed by nElem lines having elem_id node_id_1 node_id_2 node_id_3 Returns either a list of triangular element node IDs: (nid1,nid2,nid3) or, if Rod=True, a set of rod element IDs where one triangul
(File, # {{{
Rod=False)
| 68 | return np.array(points) |
| 69 | # }}} |
| 70 | def load_ele_file(File, # {{{ |
| 71 | Rod=False): |
| 72 | """ |
| 73 | Reads a triangle .ele file. First line is |
| 74 | nElem 3 0 0 |
| 75 | followed by nElem lines having |
| 76 | elem_id node_id_1 node_id_2 node_id_3 |
| 77 | |
| 78 | Returns either a list of triangular element node IDs: |
| 79 | (nid1,nid2,nid3) |
| 80 | or, if Rod=True, a set of rod element IDs where one |
| 81 | triangular element yields three rod elements: |
| 82 | (nid1,nid2) |
| 83 | (nid1,nid3) |
| 84 | (nid2,nid3) |
| 85 | Only unique pairs are returned. |
| 86 | |
| 87 | elem_id is ignored. |
| 88 | """ |
| 89 | if not os.path.isfile(File): |
| 90 | print(f'load_ele_file({File}): no such file') |
| 91 | return None |
| 92 | known_rods = {} # keyed by a set of two nid ID's |
| 93 | elements = [] |
| 94 | with open(File, 'r') as fh: |
| 95 | L = fh.readline() # header line; don't need it |
| 96 | for L in fh: |
| 97 | L = L.rstrip().lstrip() |
| 98 | if not L: continue # blank line |
| 99 | if L.startswith('#'): continue # comment line |
| 100 | words = L.split() |
| 101 | if words[0].startswith('#'): continue |
| 102 | nid1, nid2, nid3 = int(words[1]), int(words[2]), int(words[3]) |
| 103 | if Rod: |
| 104 | pair_1 = (nid1, nid2) if nid1 < nid2 else (nid2, nid1) |
| 105 | pair_2 = (nid1, nid3) if nid1 < nid3 else (nid3, nid1) |
| 106 | pair_3 = (nid2, nid3) if nid2 < nid3 else (nid3, nid2) |
| 107 | if pair_1 not in known_rods: |
| 108 | known_rods[pair_1] = True |
| 109 | elements.append( pair_1 ) |
| 110 | if pair_2 not in known_rods: |
| 111 | known_rods[pair_2] = True |
| 112 | elements.append( pair_2 ) |
| 113 | if pair_3 not in known_rods: |
| 114 | known_rods[pair_3] = True |
| 115 | elements.append( pair_3 ) |
| 116 | else: |
| 117 | elements.append( (nid1, nid2, nid3) ) |
| 118 | return np.array(elements) |
| 119 | # }}} |
| 120 | def load_model(base_file): # {{{ |
| 121 | """ |