PyDPF and Mechanical produce different current density results.

Member Posts: 7
Name Dropper First Comment First Anniversary
**

I wrote the code below, but the current density value in the automation program using PyDPF and the current density value in Mechanical are different, so how can I output the same?


`
def plot_result(self):
try:
self.plotter.clear()
rst = runpath2+"/WB/Busbar_files/dp0/SYS/MECH/file.rst"
model = dpf.Model(rst)
meshed=model.metadata.meshed_region
t_f=model.metadata.time_freq_support

  1. time_1 = list(t_f.time_frequencies.data)
  2.  
  3. dt_times=[str(round(items,2)) for items in time_1]
  4.  
  5. if self.dt_box.currentText()=="Last Time":
  6. index = -1
  7. if self.dt_box.count() == 1:
  8. self.dt_box.addItems(dt_times)
  9. self.dt_box.removeItem(0)
  10. else:
  11. index = self.dt_box.currentIndex()
  12.  
  13. if self.model_box.currentText()=="Full Model":
  14. part_name = "MESH_SZ"
  15. else:
  16. part_name = self.model_box.currentText()
  17. part_name = part_name.upper()
  18. part_name = "NS_" + part_name
  19.  
  20. if self.radio_temp.isChecked():
  21. my_mesh_scoping = model.metadata.named_selection(part_name)
  22. scoping_op = dpf.operators.mesh.from_scoping()
  23. scoping_op.inputs.scoping.connect(my_mesh_scoping)
  24. scoping_op.inputs.mesh.connect(meshed)
  25. my_mesh = scoping_op.outputs.mesh()
  26.  
  27. if index == 0:
  28. index2 = 0
  29. get_all_temp = model.results.temperature.on_all_time_freqs
  30. get_fieldContents_temp = get_all_temp(mesh_scoping=my_mesh_scoping).eval()
  31. get_field_temp = get_fieldContents_temp[index2]
  32. elif index == -1:
  33. index2 = -1
  34. get_all_temp = model.results.temperature.on_last_time_freq
  35. get_fieldContents_temp = get_all_temp(mesh_scoping=my_mesh_scoping).eval()
  36. get_field_temp = get_fieldContents_temp[0]
  37. else:
  38. index2 = index * 2
  39. get_all_temp = model.results.temperature.on_all_time_freqs
  40. get_fieldContents_temp = get_all_temp(mesh_scoping=my_mesh_scoping).eval()
  41. get_field_temp = get_fieldContents_temp[index2]
  42.  
  43. res_nodal_op=dpf.operators.averaging.elemental_nodal_to_nodal()
  44. my_field = get_field_temp
  45.  
  46. res_nodal_op.inputs.field.connect(my_field)
  47. get_field_temp=res_nodal_op.outputs.field()
  48.  
  49. field = get_field_temp
  50.  
  51. meshed_region = my_mesh
  52.  
  53. mesh_location = meshed_region.nodes
  54. component_count = field.component_count
  55.  
  56. overall_data = np.full((len(mesh_location), component_count), np.nan)
  57. ind, mask = mesh_location.map_scoping(field.scoping)
  58. value_array = field.data[mask].reshape(-1, 1)
  59. overall_data[ind] = value_array
  60.  
  61. grid = meshed_region.grid
  62.  
  63. max_temp = max(overall_data)
  64. min_temp = min(overall_data)
  65.  
  66. self.pd = pv.UnstructuredGrid(grid.cells,grid.celltypes, grid.points)
  67.  
  68. title2= "Temperature($^\circ$C) \n"+"Time ="+str(round(time_1[index],2))
  69.  
  70. sbar_kwargs =dict(title_font_size=18, label_font_size=15, height=0.8, width=0.12, vertical=True, interactive=False, position_x=0.05, position_y=0.1, color="black", title=title2, n_labels=6, fmt="%10.3f")
  71. self.plotter.enable_point_picking(left_clicking=True,pickable_window=False)
  72. self.plotter.add_mesh(self.pd,pickable=True, scalars=overall_data, show_scalar_bar=True, scalar_bar_args=sbar_kwargs, show_edges=False, cmap='jet', rng=(min_temp, max_temp))
  73.  
  74.  
  75.  
  76. elif self.radio_hf.isChecked():
  77. my_mesh_scoping = model.metadata.named_selection(part_name)
  78. scoping_op = dpf.operators.mesh.from_scoping()
  79. scoping_op.inputs.scoping.connect(my_mesh_scoping)
  80. scoping_op.inputs.mesh.connect(meshed)
  81.  
  82. my_mesh = scoping_op.outputs.mesh()
  83.  
  84. if index == 0:
  85. index = 0
  86. get_all_currentdensity = model.results.current_density.on_all_time_freqs
  87. get_fieldContents_currentdensity = get_all_currentdensity(mesh_scoping=my_mesh_scoping).eval()
  88. get_field_currentdensity = get_fieldContents_currentdensity[index]
  89. elif index == -1:
  90. index = -1
  91. get_all_currentdensity = model.results.current_density.on_last_time_freq
  92. get_fieldContents_currentdensity = get_all_currentdensity(mesh_scoping=my_mesh_scoping).eval()
  93. get_field_currentdensity = get_fieldContents_currentdensity[0]
  94. else:
  95. get_all_currentdensity = model.results.current_density.on_all_time_freqs
  96. get_fieldContents_currentdensity = get_all_currentdensity(mesh_scoping=my_mesh_scoping).eval()
  97. get_field_currentdensity = get_fieldContents_currentdensity[index]
  98.  
  99. res_nodal_op=dpf.operators.averaging.elemental_nodal_to_nodal()
  100. my_field = get_field_currentdensity
  101. res_nodal_op.inputs.field.connect(my_field)
  102. get_field_currentdensity=res_nodal_op.outputs.field()
  103.  
  104. field = get_field_currentdensity
  105. meshed_region = my_mesh
  106.  
  107. mesh_location = meshed_region.nodes
  108. component_count = field.component_count
  109.  
  110. overall_data = np.full((len(mesh_location), component_count), np.nan)
  111. ind, mask = mesh_location.map_scoping(field.scoping)
  112. overall_data[ind] = field.data[mask]
  113.  
  114. grid = meshed_region.grid
  115. grid.set_active_scalars(None)
  116.  
  117. scaling = 5e-4
  118. grid["my_vectors"] = overall_data * scaling
  119. grid.set_active_vectors("my_vectors")
  120. vector_magnitudes = np.linalg.norm(overall_data, axis=1)
  121. max_temp = max(vector_magnitudes)
  122. min_temp = min(vector_magnitudes)
  123.  
  124. title2= " Current Density(A/m\u00B2) \n"+"Time ="+str(round(time_1[index],2))
  125.  
  126. sbar_kwargs =dict(title_font_size=18, label_font_size=15, height=0.8, width=0.12, vertical=True, interactive=False, position_x=0.05, position_y=0.1, color="black", title=title2, n_labels=6)#, fmt="%10.3f")
  127. self.plotter.add_mesh(grid.arrows, lighting=False, show_scalar_bar=False)
  128. self.plotter.add_mesh(grid, scalars= overall_data, show_edges=False, scalar_bar_args=sbar_kwargs, cmap='jet', rng=(min_temp, max_temp))
  129.  
  130. self.plotter.window_size = [859, 429]
  131. self.plotter.add_camera_orientation_widget()
  132. self.plotter.camera_position='xy'

`

Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Moderator, Employee Posts: 130
    100 Comments 25 Likes Second Anniversary 5 Answers
    ✭✭✭✭

    @jwkim is this resolved? If not, can you share the workbench project?

  • Member Posts: 7
    Name Dropper First Comment First Anniversary
    **

    @Rajesh Meena We haven't solved it yet. I've uploaded the workbench file you requested, please check it out.

  • Moderator, Employee Posts: 130
    100 Comments 25 Likes Second Anniversary 5 Answers
    ✭✭✭✭

    @jwkim Sorry for delay.

    The results for current density are on elemental location .Which means you are getting elemental mean result from PyDPF. I verified it at my end and it is matching with Mechanical. Please confirm at your end.

Welcome!

It looks like you're new here. Sign in or register to get started.