-
Notifications
You must be signed in to change notification settings - Fork 12
Mesh splitting and selection #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 100 commits
bbf18e7
6995be2
0bc4c45
d3add0e
d135076
dfb6983
87195ea
0fe0cdd
b7eb6c8
f575069
3b0edf0
d1ccfad
500d711
72accfc
94d9df0
1396828
955ef07
ce7fa1e
e746560
5fac5d7
2caad5b
07e37fd
5f254b7
85957ab
37814c6
f0a516d
50745c6
8eb03ab
9ecfcc5
e55da83
3f26763
2415afe
c732e38
a610f61
23d9989
913188c
1fd41aa
217777e
f107ab5
56f1c5d
d8e8414
7b64975
ccec46b
6dca2f8
befe782
5d56699
4eba411
e81da71
c9f07a2
0bde530
30f8186
4a38217
a1fd26c
97e13fe
15325e1
a9316a3
19a4452
354cd08
76507ba
29daf4a
c627349
d5e0630
474fbf3
c0e9e04
026cee4
b2611c8
cfacf69
b7ec61d
80bd4b6
44e00ad
8d26130
22f92cf
a925508
4438389
3e17d35
9d19ab6
0f22b79
91ba3aa
c09459b
f628c3f
9c6a732
7b2dc6d
98a070b
110efbe
2b6b351
8725827
9ba9345
8e5ff1a
d207d37
7fd3e0e
baeef13
a6aebe9
775433d
3dab0c5
f4dd528
d0bffb3
747b889
7536af0
a4bf121
9b215bf
83e35af
7ea1b89
c3ae713
7d132e7
19f2149
3e271a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| """ | ||
| .. _ref_mesh_exploration_example: | ||
|
|
||
| Explore the mesh | ||
| ================ | ||
| In this script a static simulation is used as an example to show how to | ||
| query mesh information such as connectivity, element IDs, element types and so on. | ||
| """ | ||
|
|
||
| ############################################################################### | ||
| # Perform required imports | ||
| # ------------------------ | ||
| # Perform required imports. # This example uses a supplied file that you can | ||
| # get by importing the DPF ``examples`` package. | ||
|
|
||
| from ansys.dpf import post | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as we discussed @ansys-akarcher, in my opinion this is not really an example, it's more an api display, if you could move these to the mesh docstrings, it would be great
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI @PProfizi
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cbellot000 yes, I just added examples in dosctrings of post.Mesh |
||
| from ansys.dpf.post import examples | ||
| from ansys.dpf.post.common import elemental_properties | ||
|
|
||
| ############################################################################### | ||
| # Get ``Simulation`` object | ||
| # ------------------------- | ||
| # Get the ``Simulation`` object that allows access to the result. The ``Simulation`` | ||
| # object must be instantiated with the path for the result file. For example, | ||
| # ``"C:/Users/user/my_result.rst"`` on Windows or ``"/home/user/my_result.rst"`` | ||
| # on Linux. | ||
|
|
||
| example_path = examples.download_all_kinds_of_complexity() | ||
| simulation = post.StaticMechanicalSimulation(example_path) | ||
|
|
||
| # print the simulation to get an overview of what's available | ||
| print(simulation) | ||
|
|
||
| ############################################################################### | ||
| # Get the mesh | ||
| # ------------ | ||
|
|
||
| # Retrieve the actual mesh | ||
| mesh = simulation.mesh | ||
|
|
||
| ############################################################################### | ||
| # Query basic information about the mesh | ||
| # -------------------------------------- | ||
|
|
||
| # Node IDs | ||
| n_ids = mesh.node_ids | ||
|
|
||
| # Element IDs | ||
| e_ids = mesh.element_ids | ||
|
|
||
| # Available named selection names | ||
| named_selections = mesh.named_selections.keys() | ||
|
|
||
| # Number of nodes | ||
| n_nodes = mesh.num_nodes | ||
|
|
||
| # Number of elements | ||
| n_elements = mesh.num_elements | ||
|
|
||
| # Number of named selections | ||
| n_ns = len(named_selections) | ||
|
|
||
| # Unit (get and set) | ||
| mesh_unit = mesh.unit | ||
| mesh.unit = "mm" | ||
|
|
||
| print(n_ids) | ||
| print(e_ids) | ||
| print(named_selections) | ||
| print(n_nodes) | ||
| print(n_elements) | ||
|
|
||
| ############################################################################### | ||
| # Get Named Selections | ||
| # -------------------- | ||
| ns_list = mesh.named_selections.keys() | ||
| first_key = ns_list[0] | ||
| named_selection = mesh.named_selections[first_key] | ||
|
|
||
| for k in mesh.named_selections.keys(): | ||
| print(k) | ||
| for v in mesh.named_selections.values(): | ||
| print(v) | ||
| for k, v in mesh.named_selections.items(): | ||
| print(f"{k} = {v}") | ||
|
|
||
| ############################################################################### | ||
| # Get elements | ||
| # ------------ | ||
|
|
||
| # Get an element by ID | ||
| el_by_id = mesh.elements.by_id[1] | ||
ansys-akarcher marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Get an element by index | ||
| index = el_by_id.index | ||
| print(mesh.elements[index]) | ||
|
|
||
| ############################################################################### | ||
| # Element Types and Materials | ||
| # --------------------------- | ||
|
|
||
| # Get the element types | ||
| el_types = mesh.element_types | ||
| print(el_types) | ||
|
|
||
| # Get the materials | ||
| e_materials = mesh.materials | ||
| print(e_materials) | ||
|
|
||
| ############################################################################### | ||
| # Query information about one particular element | ||
| # ---------------------------------------------- | ||
|
|
||
| # Get the nodes of an element | ||
| elem_0_nodes = mesh.elements[0].nodes | ||
|
|
||
| # Get the node IDs of an element | ||
| elem_0_nodes_ids = mesh.elements[0].node_ids | ||
|
|
||
| # Get the number of nodes of an element | ||
| num_nodes_elem_0 = mesh.elements[0].num_nodes | ||
|
|
||
| # Get the type of the element | ||
| elem_0_type_info = mesh.elements[0].type_info | ||
| elem_0_type = mesh.elements[0].type | ||
|
|
||
| # Get the shape of the element | ||
| elem_0_shape = mesh.elements[0].shape | ||
|
|
||
| ############################################################################### | ||
| # Get the elemental connectivity | ||
| # ------------------------------ | ||
|
|
||
| # get node indices from element index | ||
| conn1 = mesh.element_to_node_connectivity | ||
|
|
||
| # get node IDs from element index | ||
| conn2 = mesh.element_to_node_ids_connectivity | ||
|
|
||
| el_idx_5 = mesh.elements[5] | ||
| # get node IDS from element ID | ||
| node_ids = conn2.by_id[el_idx_5.id] | ||
|
|
||
| ############################################################################### | ||
| # Get nodes | ||
| # --------- | ||
|
|
||
| # Get a node by ID | ||
| node_by_id = mesh.nodes.by_id[1] | ||
|
|
||
| # Get a node by index | ||
| node_by_index = mesh.nodes[0] | ||
|
|
||
| # Get the coordinates of all nodes | ||
| print(mesh.coordinates) | ||
|
|
||
| ############################################################################### | ||
| # Query information about one particular node | ||
| # ------------------------------------------- | ||
|
|
||
| # Coordinates | ||
| node_1 = mesh.nodes[1].coordinates | ||
|
|
||
| # Get Nodal connectivity | ||
| conn3 = mesh.node_to_element_connectivity | ||
| conn4 = mesh.node_to_element_ids_connectivity | ||
|
|
||
| print(mesh.nodes[0]) | ||
|
|
||
| # elements indices to elem_id | ||
| print(conn3[0]) | ||
|
|
||
| # elements IDs from node index | ||
| print(conn4[0]) | ||
|
|
||
| ############################################################################### | ||
| # Splitting into meshes | ||
| # --------------------- | ||
|
|
||
| # Plot the mesh | ||
| mesh.plot() | ||
|
|
||
| # Split the global mesh according to mesh properties | ||
| meshes = simulation.split_mesh_by_properties( | ||
| properties=[elemental_properties.material, elemental_properties.element_shape] | ||
| ) | ||
| meshes.plot() | ||
|
|
||
| # Split the global mesh and select meshes for specific property values | ||
| print(meshes) | ||
| meshes = simulation.split_mesh_by_properties( | ||
| properties={ | ||
| elemental_properties.material: 1, | ||
| elemental_properties.element_shape: [0, 1], | ||
| } | ||
| ) | ||
|
|
||
| meshes.plot() | ||
|
|
||
| # Select a specific Mesh in the Meshes, by index | ||
| meshes[0].plot() | ||
| # or by property values | ||
| meshes[{"mat": 1, "elshape": 0}].plot() | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,145 @@ | ||||||
| """Module containing wrapper class for the connectivities property fields.""" | ||||||
|
|
||||||
| from __future__ import annotations | ||||||
|
|
||||||
| from abc import ABC, abstractmethod | ||||||
| from enum import Enum | ||||||
| from typing import List | ||||||
|
|
||||||
| from ansys.dpf.core.property_field import PropertyField | ||||||
| from ansys.dpf.core.scoping import Scoping | ||||||
|
|
||||||
|
|
||||||
| class ReturnMode(Enum): | ||||||
| """Enum made for internal use, to dictate the behavior of _ConnectivityList.""" | ||||||
|
|
||||||
| IDS = 1 | ||||||
| IDX = 2 | ||||||
|
|
||||||
|
|
||||||
| class _ConnectivityList(ABC): | ||||||
| """Abstract class for ConnectivityList objects.""" | ||||||
|
|
||||||
| def __init__( | ||||||
| self, | ||||||
| field: PropertyField, | ||||||
| mode: ReturnMode, | ||||||
| scoping: Scoping, | ||||||
| ): | ||||||
| """Constructs a _ConnectivityList by wrapping the given PropertyField. | ||||||
|
|
||||||
| Arguments: | ||||||
|
||||||
| Arguments: | |
| Parameters: |
Uh oh!
There was an error while loading. Please reload this page.