pymapdl
pymapdl copied to clipboard
Unmatch between ``mapdl.mesh.grid`` and ``mapdl.mesh``
In the attached model, mapdl.mesh and mapdl.mesh.grid give different results:
In [68]: mapdl.mesh.grid
Out[68]:
UnstructuredGrid (0x2a900402f40)
N Cells: 7360
N Points: 28477
X Bounds: -3.175e-02, 3.175e-02
Y Bounds: -7.620e-03, 6.858e-02
Z Bounds: -3.180e-03, 1.524e-02
N Arrays: 10
In [69]: mapdl.mesh
Out[69]:
ANSYS Mesh
Number of Nodes: 7879
Number of Elements: 7891
Number of Element Types: 7
Number of Node Components: 0
Number of Element Components: 0
This mainly because TARGE170 is missing in _parse_vtk in the pymapdl-reader.
See https://github.com/pyansys/pymapdl-reader/pull/129
However, using a pymapdl-reader development branch (feat/adding-target170-elements), I still have different numbers:
In [2]: mapdl.mesh
Out[2]:
ANSYS Mesh
Number of Nodes: 7879
Number of Elements: 7891
Number of Element Types: 7
Number of Node Components: 0
Number of Element Components: 0
In [3]: mapdl.mesh.grid
Out[3]:
UnstructuredGrid (0x2390d88be80)
N Cells: 7891
N Points: 28479
X Bounds: -3.175e-02, 3.175e-02
Y Bounds: -7.620e-03, 6.858e-02
Z Bounds: -3.180e-03, 1.524e-02
N Arrays: 10
The issue is mainly with the number of nodes. Without matching numbers, we cannot do:
>>> temp = mapdl.post_processing.nodal_temperatures()
>>> grid = mapdl.mesh.grid
>>> grid.plot(scalars=temp)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [5], in <module>
1 temp = mapdl.post_processing.nodal_temperature()
3 grid = mapdl.mesh.grid
----> 4 grid.plot(scalars=temp)
File c:\users\gayuso\other_projects\pyvista\pyvista\plotting\helpers.py:241, in plot(var_item, off_screen, full_screen, screenshot, interactive, cpos, window_size, show_bounds, show_axes, notebook, background, text, return_img, eye_dome_lighting, volume, parallel_projection, use_ipyvtk, jupyter_backend, return_viewer, return_cpos, jupyter_kwargs, theme, hidden_line_removal, anti_aliasing, zoom, **kwargs)
239 plotter.add_volume(var_item, **kwargs)
240 else:
--> 241 plotter.add_mesh(var_item, **kwargs)
243 if text:
244 plotter.add_text(text)
File c:\users\gayuso\other_projects\pyvista\pyvista\plotting\plotting.py:2228, in BasePlotter.add_mesh(self, mesh, color, style, scalars, clim, show_edges, edge_color, point_size, line_width, opacity, flip_scalars, lighting, n_colors, interpolate_before_map, cmap, label, reset_camera, scalar_bar_args, show_scalar_bar, multi_colors, name, texture, render_points_as_spheres, render_lines_as_tubes, smooth_shading, split_sharp_edges, ambient, diffuse, specular, specular_power, nan_color, nan_opacity, culling, rgb, categories, silhouette, use_transparency, below_color, above_color, annotations, pickable, preference, log_scale, pbr, metallic, roughness, render, component, **kwargs)
2226 # Scalars formatting ==================================================
2227 if scalars is not None:
-> 2228 show_scalar_bar, n_colors, clim = self.mapper.set_scalars(
2229 mesh,
2230 scalars,
2231 scalar_bar_args,
2232 rgb,
2233 component,
2234 preference,
2235 interpolate_before_map,
2236 custom_opac,
2237 annotations,
2238 log_scale,
2239 nan_color,
2240 above_color,
2241 below_color,
2242 cmap,
2243 flip_scalars,
2244 opacity,
2245 categories,
2246 n_colors,
2247 clim,
2248 self._theme,
2249 show_scalar_bar,
2250 )
2251 elif custom_opac: # no scalars but custom opacity
2252 self.mapper.set_custom_opacity(
144 _custom_opac,
145 )
146 table = self.GetLookupTable()
148 if _using_labels:
File c:\users\gayuso\other_projects\pyvista\pyvista\plotting\mapper.py:263, in make_mapper.<locals>.MapperHelper.configure_scalars_mode(self, scalars, mesh, title, n_colors, preference, interpolate_before_map, rgb, _custom_opac) 261 self.SetScalarModeToUseCellData() 262 else:
--> 263 raise_not_matching(scalars, mesh)
265 self.GetLookupTable().SetNumberOfTableValues(n_colors)
266 if interpolate_before_map:
File c:\users\gayuso\other_projects\pyvista\pyvista\utilities\helpers.py:1097, in raise_not_matching(scalars, dataset)
1093 if isinstance(dataset, _vtk.vtkTable):
1094 raise ValueError(
1095 f'Number of scalars ({scalars.size}) must match number of rows ({dataset.n_rows}).'
1096 )
-> 1097 raise ValueError(
1098 f'Number of scalars ({scalars.size}) '
1099 f'must match either the number of points ({dataset.n_points}) '
1100 f'or the number of cells ({dataset.n_cells}).'
1101 )
ValueError: Number of scalars (7879) must match either the number of points (28479) or the number of cells (7891).
Basically it complains of:
ValueError: Number of scalars (7879) must match either the number of points (28479) or the number of cells (7891).
Possible ideas:
- Are we generating middle-side nodes??
It seems related to elements 170 and 174. Probably related to: https://github.com/pyansys/pymapdl-reader/pull/129