-
Notifications
You must be signed in to change notification settings - Fork 25
Add mesh tutorials to the main tutorials branch #1908
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
Merged
PProfizi
merged 65 commits into
doc/new-tutorials-section
from
tutorials/mesh/firsts-mesh-tutorials
May 14, 2025
Merged
Changes from 49 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
811adde
add new basic tutorial and jupyter_ sphinx extension
luisaFelixSalles 2266b73
add tutorials files and update index page
luisaFelixSalles 9da611a
add get_mesh_from_result_file.rst tutorial
luisaFelixSalles d02b96d
updates on the index
luisaFelixSalles 7480d30
updates on get_mesh_from_result_file.rst
luisaFelixSalles 3c31dd2
add create_a_mesh_from_scratch.rst tutorial
luisaFelixSalles 9a66fca
updates the read the mesh tut
luisaFelixSalles 8e10754
updates the read the mesh tut
luisaFelixSalles 6be9e21
add get_specific_part_mesh.rst and split_mesh.rst tutorials
luisaFelixSalles e2111e0
updates on thr get_specific_part_mesh.rst tutorial
luisaFelixSalles 29785f1
updates the create_a_mesh_from_scratch.rst tut
luisaFelixSalles 58e0364
erases add and plot data parts from the create_a_mesh_from_scratch.rs…
luisaFelixSalles b5f5365
update references in get_mesh_from_result_file.rst tutorial
luisaFelixSalles 79d57f8
update references in read_mesh.rst tutorial
luisaFelixSalles f34dd4d
add second approach to the split_mesh.rst tutorial
luisaFelixSalles 871f90d
updates on get_specific_part_mesh.rst
luisaFelixSalles 56bd290
put a tab for each solver
luisaFelixSalles 54476a9
update
luisaFelixSalles af705b2
put a tab for each solver in the get_specific_part_mesh.rst tutorial
luisaFelixSalles 9338b6e
put a tab for each solver in the split_mesh.rst tutorial
luisaFelixSalles 2e743e9
put a tab for each solver and update the read_mesh_metadata.rst tutorial
luisaFelixSalles 5791181
put a tab for each solver and update the explore_mesh.rst tutorial
luisaFelixSalles 1f7af61
put badge for each solver in the main page cards
luisaFelixSalles 189b308
put badge for each solver in the beginning of the tutorials
luisaFelixSalles 298f134
update title read_mesh_metadata.rst
luisaFelixSalles 4e6e043
update title get_specific_part_mesh.rst
luisaFelixSalles 56cbec3
update substitution text
luisaFelixSalles f1a9376
Update doc/source/user_guide/tutorials/mesh/explore_mesh.rst
luisaFelixSalles 8b5b5f9
use only the jupyter sphinx extension
luisaFelixSalles b9da160
updates the examples package references
luisaFelixSalles f03e48e
update badges in the index.rst
luisaFelixSalles 5c43ae4
change the section name
luisaFelixSalles 947f646
add badges in each tutorial
luisaFelixSalles e666e27
update2 the create_a_mesh_from_scratch.rst tutorial to the tutorials …
luisaFelixSalles 98d4a97
update the explore_mesh.rst to the tutorials guidelines
luisaFelixSalles ccc731b
update the extract_mesh_in_split_parts.rst to the tutorials guidelines
luisaFelixSalles 882c3a2
update the get_mesh_from_result_file.rst to the tutorials guidelines
luisaFelixSalles cc3325c
update the read_mesh_metadata.rst to the tutorials guidelines
luisaFelixSalles e708660
update the split_mesh.rst to the tutorials guidelines
luisaFelixSalles ea88101
update the index page of the mesh tutorials section
luisaFelixSalles 5684f6a
changes the name of the explore_mesh_metadata.rst tutorial
luisaFelixSalles a7c26d6
add explanation on the MeshesContainer labels when you use the split_…
luisaFelixSalles 11a44f4
add more explanation for each approach on the split_mesh.rst tutorial
luisaFelixSalles 4256566
add more explanation on the metadata info on the explore_mesh.rst tut…
luisaFelixSalles b44ea3d
add more explanation on the metadata info on the explore_mesh_metadat…
luisaFelixSalles 69b9c1b
updates on the text of create_a_mesh_from_scratch.rst turorial
luisaFelixSalles 4f3b349
Update doc/source/user_guide/tutorials/mesh/explore_mesh_metadata.rst
luisaFelixSalles ae30d91
Update doc/source/user_guide/tutorials/mesh/extract_mesh_in_split_par…
luisaFelixSalles 8ba9f0a
delete file basic_tutorial.rst
luisaFelixSalles 56e1a9f
correction of a reference in explore_mesh.rst
luisaFelixSalles 9361d95
Fix sentence.
PProfizi 9297626
Refactor search_sequence_numpy in mesh from scratch tutorial
PProfizi 2610acb
Fix unordered list
PProfizi a17ce53
Reference nodes, elements, faces, and named selections getters
PProfizi e65520d
Refactor query of element type field
PProfizi 724796c
Fix unordered list
PProfizi 603af49
parts -> regions
PProfizi dd83d0c
Fix unordered list
PProfizi 2ee7b1c
Fix unordered list
PProfizi 84b82b6
Fix typo
PProfizi 09e465c
Fix code snippets formatting
PProfizi c56f6ca
Fix unordered list
PProfizi ba4978c
Fix grammar
PProfizi 48a21a3
Fix sentence
PProfizi 70a32f7
Suggestion from Jorge
PProfizi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
doc/source/user_guide/tutorials/mesh/create_a_mesh_from_scratch.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
.. _ref_tutorials_create_a_mesh_from_scratch: | ||
|
||
========================== | ||
Create a mesh from scratch | ||
========================== | ||
|
||
.. include:: ../../../links_and_refs.rst | ||
|
||
This tutorial demonstrates how to build a |MeshedRegion| from the scratch. | ||
PProfizi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The mesh object in DPF is a |MeshedRegion|. You can create your own |MeshedRegion| object and use it | ||
with DPF operators. The ability to use scripting to create any DPF entity means | ||
that you are not dependent on result files and can connect the DPF environment | ||
with any Python tool. | ||
|
||
In this tutorial, we create a parallel piped mesh made of linear hexa elements. | ||
|
||
:jupyter-download-script:`Download tutorial as Python script<create_a_mesh_from_scratch>` | ||
jorgepiloto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:jupyter-download-notebook:`Download tutorial as Jupyter notebook<create_a_mesh_from_scratch>` | ||
|
||
Import the necessary modules | ||
---------------------------- | ||
|
||
Import the ``ansys.dpf.core`` module, including the operators module and the numpy library. | ||
luisaFelixSalles marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. jupyter-execute:: | ||
|
||
# Import the numpy library | ||
import numpy as np | ||
# Import the ``ansys.dpf.core`` module | ||
from ansys.dpf import core as dpf | ||
# Import the operators module | ||
from ansys.dpf.core import operators as ops | ||
|
||
Define the mesh dimensions | ||
-------------------------- | ||
|
||
.. jupyter-execute:: | ||
|
||
# Define the mesh dimensions | ||
length = 0.1 | ||
width = 0.05 | ||
depth = 0.1 | ||
luisaFelixSalles marked this conversation as resolved.
Show resolved
Hide resolved
|
||
num_nodes_in_length = 10 | ||
num_nodes_in_width = 5 | ||
num_nodes_in_depth = 10 | ||
# Create a MeshedRegion object | ||
my_meshed_region = dpf.MeshedRegion() | ||
|
||
Define the connectivity function | ||
-------------------------------- | ||
|
||
To create a mesh you must define the nodes connectivity. This means to define | ||
the nodes ids connected to each element. | ||
|
||
Here, we create a function that will find this connectivity. | ||
|
||
.. jupyter-execute:: | ||
|
||
def search_sequence_numpy(arr, seq): | ||
"""Find a sequence in an array and return its index.""" | ||
indexes = np.where(np.isclose(arr, seq[0])) | ||
for index in np.nditer(indexes[0]): | ||
if index % 3 == 0: | ||
if np.allclose(arr[index + 1], seq[1]) and np.allclose(arr[index + 2], seq[2]): | ||
return index | ||
return -1 | ||
PProfizi marked this conversation as resolved.
Show resolved
Hide resolved
PProfizi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Add nodes | ||
--------- | ||
|
||
Add |Nodes| to the |MeshedRegion| object. | ||
|
||
.. jupyter-execute:: | ||
|
||
node_id = 1 | ||
for i, x in enumerate( | ||
[float(i) * length / float(num_nodes_in_length) for i in range(0, num_nodes_in_length)] | ||
): | ||
for j, y in enumerate( | ||
[float(i) * width / float(num_nodes_in_width) for i in range(0, num_nodes_in_width)] | ||
): | ||
for k, z in enumerate( | ||
[float(i) * depth / float(num_nodes_in_depth) for i in range(0, num_nodes_in_depth)] | ||
): | ||
my_meshed_region.nodes.add_node(node_id, [x, y, z]) | ||
node_id += 1 | ||
|
||
Get the nodes coordinates field. | ||
|
||
.. jupyter-execute:: | ||
|
||
my_nodes_coordinates = my_meshed_region.nodes.coordinates_field | ||
|
||
Set the mesh properties | ||
----------------------- | ||
|
||
Set the mesh unit. | ||
|
||
.. jupyter-execute:: | ||
|
||
my_meshed_region.unit = "mm" | ||
|
||
Set the nodes coordinates. | ||
|
||
.. jupyter-execute:: | ||
|
||
# Get the nodes coordinates data | ||
my_nodes_coordinates_data = my_nodes_coordinates.data | ||
# As we use the connectivity function we need to get the data as a list | ||
my_nodes_coordinates_data_list = my_nodes_coordinates.data_as_list | ||
# Set the nodes scoping | ||
my_coordinates_scoping = my_nodes_coordinates.scoping | ||
|
||
Add elements | ||
------------ | ||
Add |Elements| to the |MeshedRegion| object. | ||
|
||
.. jupyter-execute:: | ||
|
||
element_id = 1 | ||
for i, x in enumerate( | ||
[float(i) * length / float(num_nodes_in_length) for i in range(num_nodes_in_length - 1)] | ||
): | ||
for j, y in enumerate( | ||
[float(i) * width / float(num_nodes_in_width) for i in range(num_nodes_in_width - 1)] | ||
): | ||
for k, z in enumerate( | ||
[float(i) * depth / float(num_nodes_in_depth) for i in range(num_nodes_in_depth - 1)] | ||
): | ||
coord1 = np.array([x, y, z]) | ||
connectivity = [] | ||
for xx in [x, x + length / float(num_nodes_in_length)]: | ||
for yy in [y, y + width / float(num_nodes_in_width)]: | ||
for zz in [z, z + depth / float(num_nodes_in_depth)]: | ||
data_index = search_sequence_numpy(my_nodes_coordinates_data_list, [xx, yy, zz]) | ||
scoping_index = int(data_index / 3) # 3components | ||
PProfizi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
connectivity.append(scoping_index) | ||
# rearrange connectivity | ||
tmp = connectivity[2] | ||
connectivity[2] = connectivity[3] | ||
connectivity[3] = tmp | ||
tmp = connectivity[6] | ||
connectivity[6] = connectivity[7] | ||
connectivity[7] = tmp | ||
my_meshed_region.elements.add_solid_element(element_id, connectivity) | ||
element_id += 1 | ||
PProfizi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Plot the mesh | ||
------------- | ||
|
||
You can check the mesh we just created with a plot. For more information on how to plot a mesh see | ||
the :ref:`ref_tutorials_plotting_meshes` tutorial. | ||
|
||
.. jupyter-execute:: | ||
|
||
# Plot the mesh | ||
luisaFelixSalles marked this conversation as resolved.
Show resolved
Hide resolved
|
||
my_meshed_region.plot() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.