@@ -317,8 +317,16 @@ def add_field(
317317 show_min = False
318318 elif location == locations .overall :
319319 mesh_location = meshed_region .elements
320+ elif location == locations .elemental_nodal :
321+ mesh_location = meshed_region .elements
322+ # If ElementalNodal, first extend results to mid-nodes
323+ field = dpf .core .operators .averaging .extend_to_mid_nodes (
324+ field = field
325+ ).eval ()
320326 else :
321- raise ValueError ("Only elemental, nodal or faces location are supported for plotting." )
327+ raise ValueError (
328+ "Only elemental, elemental nodal, nodal or faces location are supported for plotting."
329+ )
322330
323331 # Treat multilayered shells
324332 if not isinstance (shell_layer , eshell_layers ):
@@ -333,13 +341,25 @@ def add_field(
333341 )
334342 field = change_shell_layer_op .get_output (0 , core .types .field )
335343
344+ location_data_len = meshed_region .location_data_len (location )
336345 component_count = field .component_count
337346 if component_count > 1 :
338- overall_data = np .full ((len ( mesh_location ) , component_count ), np .nan )
347+ overall_data = np .full ((location_data_len , component_count ), np .nan )
339348 else :
340- overall_data = np .full (len ( mesh_location ) , np .nan )
349+ overall_data = np .full (location_data_len , np .nan )
341350 if location != locations .overall :
342351 ind , mask = mesh_location .map_scoping (field .scoping )
352+
353+ # Rework ind and mask to take into account n_nodes per element if ElementalNodal
354+ if location == locations .elemental_nodal :
355+ n_nodes_list = meshed_region .get_elemental_nodal_size_list ().astype (np .int32 )
356+ first_index = np .insert (np .cumsum (n_nodes_list )[:- 1 ], 0 , 0 ).astype (np .int32 )
357+ mask_2 = np .asarray ([mask_i for i , mask_i in enumerate (mask )
358+ for _ in range (n_nodes_list [ind [i ]])])
359+ ind_2 = np .asarray ([first_index [ind_i ]+ j for ind_i in ind
360+ for j in range (n_nodes_list [ind_i ])]) # OK
361+ mask = mask_2
362+ ind = ind_2
343363 overall_data [ind ] = field .data [mask ]
344364 else :
345365 overall_data [:] = field .data [0 ]
@@ -354,6 +374,8 @@ def add_field(
354374 grid = meshed_region ._as_vtk (
355375 meshed_region .deform_by (deform_by , scale_factor ), as_linear
356376 )
377+ if location == locations .elemental_nodal :
378+ grid = grid .shrink (1.0 )
357379 grid .set_active_scalars (None )
358380 self ._plotter .add_mesh (grid , scalars = overall_data , ** kwargs_in )
359381
0 commit comments