Source code for Muscat.IO.DatReader

# -*- coding: utf-8 -*-
#
# This file is subject to the terms and conditions defined in
# file 'LICENSE.txt', which is part of this source code package.
#

"""
ds.dat based ansys reader.
returns an unstructured mesh (class from BasicTools)
"""

import re
import numpy as np
import copy
from typing import Tuple, List


[docs] def Get_Pressure_Loading_Elemental_Surface(file: str): # -> Tuple(List, ) """_summary_ Parameters ---------- file : str DAT file from Ansys to be read Returns ------- Tuple() _description_ """ if '.rst' in file: rst_name = re.search(r"[\w.rst]*$", file).group() file = file.replace(rst_name, '/ds.dat') elif '.dat' not in file and '.' not in file: file = file + '/ds.dat' elif '.dat' not in file and '.' in file: raise ValueError(f'The file ({file}) must be a .dat file type !') return fl = open(file, 'r') previous_line = fl.readline() loadings = list() info = dict() surf_name = dict() for item in fl: if 'Define Pressure Using Surface Effect Elements' in item: load_name = re.search(r"\"[\w ]+\"", item).group().replace('\"', '').replace(' ', '_') # print(load_name) item = fl.readline() if 'et' in item and ',154' in item: # print(item) el_type_ansys = re.search(r"[\w.-]+\n", item).group().replace('\n', '') # print(el_type_ansys) next_line = fl.readline() # print(next_line) key_opt = [] while '(15i9)' not in next_line: if 'eblock' in next_line and ',,,' in next_line: n_elements = int(re.search(r"[\w.-]+\n", next_line).group()) # print('Number of surface elements :', n_elements) if 'keyop' in next_line: keys = re.search(r",[\w.,-]+\s", next_line).group().split( ',') # .replace('\n','')#np.array(fl.readline().split(',')) # print(keys) key_opt.append([int(keys[2]), int(keys[3])]) next_line = fl.readline() # print('key :', key_opt) el_def = 0 # fl.readline() # jump a line sf_elements = {} while el_def < n_elements: ln = np.array(fl.readline().split()) # print(ln) sfel_id = int(ln[0]) sf_elements[sfel_id] = [int(c) for c in ln[5:]] el_def += 1 # print(sf_elements[sfel_id]) # print(el_def) ln = fl.readline() while 'esel,all' not in ln: if 'keyop' in ln: # print(ln) keys = re.search(r",[\w.,-]+\s", ln).group().split( ',') # .replace('\n','')#np.array(fl.readline().split(',')) key_opt.append([int(keys[2]), int(keys[3])]) ln = fl.readline() # print('Key :', key_opt)#print(el_type_ansys,n_elements, key_opt) fl.readline() ln = fl.readline() # while '/com,' not in ln: if '*DIM,' in ln: tb_name = re.search(r",[\w ]+,", ln).group().replace(',', '') # print(tb_name) info['load_name'] = tb_name.upper() # print('Surface read ended for', load_name, '\n') # print(sf_elements) # getting the selection internal name: info['load_type_name'] = load_name.upper() # table_name.upper() info['n_elem'] = n_elements info['el_type'] = el_type_ansys info['surface_elements'] = sf_elements info['key_opt'] = key_opt # try: info['loading'] = np.stack([np.array(time_steps), np.array(load_value)], axis = 1) # except : info['loading'] = None # info['loading'] = [0, 0] # print('\nINFO:', load_name, '\n', loadings) cp = copy.copy(info) # print('\n', 'info :', info['load_type_name'],info['load_name']) loadings.append(cp) # print('ld: ', loadings, '\n') elif 'Define Surface Elements for Imported Load' in item: load_name = re.search(r"\"[\w ]+\"", item).group().replace('\"', '').replace(' ', '_') # print(load_name) item = fl.readline() if 'et' in item and ',154' in item: # print(item) el_type_ansys = re.search(r"[\w.-]+\n", item).group().replace('\n', '') # print(el_type_ansys) next_line = fl.readline() # print(next_line) key_opt = [] while '(15i9)' not in next_line: if 'eblock' in next_line and ',,,' in next_line: n_elements = int(re.search(r"[\w.-]+\n", next_line).group()) # print('Number of surface elements :', n_elements) if 'keyop' in next_line: keys = re.search(r",[\w.,-]+\s", next_line).group().split( ',') # .replace('\n','')#np.array(fl.readline().split(',')) # print(keys) key_opt.append([int(keys[2]), int(keys[3])]) next_line = fl.readline() # print('key :', key_opt) el_def = 0 # fl.readline() # jump a line sf_elements = {} while el_def < n_elements: ln = np.array(fl.readline().split()) # print(ln) sfel_id = int(ln[0]) sf_elements[sfel_id] = [int(c) for c in ln[5:]] el_def += 1 # print(sf_elements[sfel_id]) # print(el_def) # print('Surface read ended for', load_name, '\n') # print(sf_elements) # getting the selection internal name: info['load_type_name'] = load_name.upper() # table_name.upper() info['n_elem'] = n_elements info['el_type'] = el_type_ansys info['surface_elements'] = sf_elements info['key_opt'] = key_opt info['load_name'] = '' # try: info['loading'] = np.stack([np.array(time_steps), np.array(load_value)], axis = 1) # except : info['loading'] = None # info['loading'] = [0, 0] # loadings[load_name] = info cp = copy.copy(info) # print('\n', 'info :', info['load_type_name']) loadings.append(cp) # print('ld: ', loadings, '\n') if '/com,*********** Create Imported Load' in item and 'Pressure' in item: load_name = re.search(r"\"[\w ]+\"", item).group().replace('\"', '').replace(' ', '_') ln = fl.readline() tb_name = re.search(r",[\w ]+,", ln).group().replace(',', '') # print(load_name, tb_name) surf_name[load_name.upper()] = tb_name.upper() previous_line = item # new_ln = fl.readline() # while 'TABLE' not in new_ln: # new_ln = fl.readline() # # ln = new_ln.split(',') # table_name = ln[1] # n_time_steps = int(ln[3]) # tp = 0 # load_value = [] # AssociatedLoading = fl.readline() # print(' Loading ? ', AssociatedLoading) # if '! Time values' in AssociatedLoading: # time_steps = [float(i) for i in fl.readline().replace('\n','').split(',')[int(-1*n_time_steps):]] # else: time_steps = [] # if '! Load values' in fl.readline() and len(time_steps)>0: # print('loadings') # while tp < n_time_steps: # # ln = fl.readline() # lv = re.search(r"[\d.]+\n",ln) # print(ln) # load_value.append(float(lv.group())) # # tp +=1 # else: load_name = [] # print('table name: ',table_name, # '\nnumber of time steps:', n_time_steps, # '\ntime steps: ', np.array(time_steps).shape, # '\nloadings: ', np.array(load_value).shape) # print('\n') try: return loadings, surf_name except: return
[docs] def CheckIntegrity(): return "OK"