Guest User

Untitled

a guest
Oct 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. from part import *
  2. from material import *
  3. from section import *
  4. from assembly import *
  5. from step import *
  6. from interaction import *
  7. from load import *
  8. from mesh import *
  9. from optimization import *
  10. from job import *
  11. from sketch import *
  12. from visualization import *
  13. from connectorBehavior import *
  14. import regionToolset
  15.  
  16. import numpy as np
  17. import os
  18.  
  19. model_name = "aba1" # enter model name
  20. part_name = "PART-1" # enter part name
  21.  
  22. radius = 1e-03 # radius of sphere to pick nodes within (default value for point selection = 1e-3)
  23. tol = 1e-6 # default tolerance value for finding the nodes 1e-6
  24.  
  25.  
  26. # CSV FILE INFO CONTAINING CO-ORDINATES OF RPs & MASS value
  27. directory = r"C:\Suvopam\ABA\08_vPumps_CD"
  28. file_name = "cog_mass"
  29. full_path = os.path.join(directory, file_name + ".csv")
  30. arr = np.genfromtxt(full_path, unpack=False, skip_header=1, filling_values=np.NaN, delimiter=";")
  31.  
  32. m = mdb.models[model_name]
  33. p = m.parts[part_name]
  34. a = m.rootAssembly
  35.  
  36.  
  37. def rp_coord_n_mass_creator(arr_):
  38. '''to create list of co-ordinates of RP and center of the sphere in the form of tuple'''
  39. arr_ = arr_[~np.isnan(arr_).any(axis=1)] # dropna() for numpy
  40. n_row, n_col = arr_.shape
  41. p_cog_ = []
  42. mass_ = []
  43. for x in range(n_row):
  44. temp = []
  45. for y in range(3):
  46. temp.append(arr_[x][y])
  47. p_cog_.append(tuple(temp))
  48. mass_.append(arr_[x][3])
  49. return (p_cog_, mass_)
  50.  
  51.  
  52. def rp_dict_creation(f_):
  53. '''creating RP dictionary'''
  54. f_dict = {}
  55. for i in f_.keys():
  56. try:
  57. redundant = f_[i].xValue # to clean PART number key from selection
  58. f_dict[f_[i].id] = []
  59. f_dict[f_[i].id].append(f_[i].name)
  60. f_dict[f_[i].id].append(f_[i].xValue)
  61. f_dict[f_[i].id].append(f_[i].yValue)
  62. f_dict[f_[i].id].append(f_[i].zValue)
  63. except AttributeError:
  64. pass
  65. return f_dict
  66.  
  67.  
  68. def sph_extrm(radius_, rp_coord_):
  69. '''to create extremes of the sphere '''
  70. p_extr_x_ = (rp_coord_[0] + radius_, rp_coord_[0] - radius_)
  71. p_extr_y_ = (rp_coord_[1] + radius_, rp_coord_[1] - radius_)
  72. p_extr_z_ = (rp_coord_[2] + radius_, rp_coord_[2] - radius_)
  73. return p_extr_x_, p_extr_y_, p_extr_z_
  74.  
  75.  
  76. def search_inside_vol_n_create_mass(rp_dict_, a_, p_mass_, p_extr_x_, p_extr_y_, p_extr_z_):
  77. '''searches if rp co-ordinate is inside the sphere and creates mass if true'''
  78. rp_key_list = rp_dict_.keys()
  79. for i in rp_key_list:
  80. x_flag = False
  81. y_flag = False
  82. z_flag = False
  83. if p_extr_x_[0] + tol >= rp_dict_[i][1] >= p_extr_x_[1] - tol or p_extr_x_[1] + tol >= rp_dict_[i][1] >= p_extr_x_[0] - tol:
  84. x_flag = True
  85. if p_extr_y_[0] + tol >= rp_dict_[i][2] >= p_extr_y_[1] - tol or p_extr_y_[1] + tol >= rp_dict_[i][2] >= p_extr_y_[0] - tol:
  86. y_flag = True
  87. if p_extr_z_[0] + tol >= rp_dict_[i][3] >= p_extr_z_[1] - tol or p_extr_z_[1] + tol >= rp_dict_[i][3] >= p_extr_z_[0] - tol:
  88. z_flag = True
  89. if x_flag and y_flag and z_flag:
  90. # creating region
  91. r1 = a.referencePoints
  92. refPoints1 = (r1[i],)
  93. region = regionToolset.Region(referencePoints=refPoints1)
  94. # creating inertia mass
  95. a_.engineeringFeatures.PointMassInertia(name='Inertia-x_{}'.format(i), region=region, mass=p_mass_, alpha=0.0, composite=0.0)
  96. else:
  97. pass
  98.  
  99.  
  100. def master_run():
  101. rp_dict = rp_dict_creation(f)
  102. p_cog, mass = rp_coord_n_mass_creator(arr)
  103. for x in range(len(mass)):
  104. p_extr_x, p_extr_y, p_extr_z = sph_extrm(radius, p_cog[x])
  105. search_inside_vol_n_create_mass(rp_dict, a, mass[x], p_extr_x, p_extr_y, p_extr_z) # multi run
  106.  
  107.  
  108. master_run()
Add Comment
Please, Sign In to add comment