Skip to content

Commit

Permalink
update the create_a_mesh_from_scratch.rst tutorial to the tutorials g…
Browse files Browse the repository at this point in the history
…uidelines
  • Loading branch information
luisaFelixSalles committed Dec 3, 2024
1 parent d0e5a14 commit bd42cc2
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions doc/source/user_guide/tutorials/mesh/create_a_mesh_from_scratch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@
Create a mesh from scratch
==========================

.. |Field| replace:: :class:`Field<ansys.dpf.core.field.Field>`
.. |FieldsContainer| replace:: :class:`FieldsContainer<ansys.dpf.core.fields_container.FieldsContainer>`
.. |MeshedRegion| replace:: :class:`MeshedRegion <ansys.dpf.core.meshed_region.MeshedRegion>`
.. |Model| replace:: :class:`Model <ansys.dpf.core.model.Model>`
.. include:: ../../../links_and_refs.rst

The mesh object in DPF is a |MeshedRegion|. You can create your own |MeshedRegion| object to use DPF operators
with your own data. The ability to use scripting to create any DPF entity means
This tutorial demonstrates how to build a |MeshedRegion| from the scratch.

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.

This tutorial demonstrates how to build a |MeshedRegion| from the scratch.
Here, we create a parallel piped mesh made of linear hexa elements.

Here we create a parallel piped mesh made of linear hexa elements.
:jupyter-download-script:`Download tutorial as Python script<create_a_mesh_from_scratch>`
:jupyter-download-notebook:`Download tutorial as notebook<create_a_mesh_from_scratch>`

Import the necessary modules
----------------------------

Import the ``ansys.dpf.core`` module, including the operators subpackage and the numpy library
Import the ``ansys.dpf.core`` module, including the operators subpackage and the numpy library.

.. 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 subpackage
from ansys.dpf.core import operators as ops

Define the mesh dimensions
Expand All @@ -47,10 +50,10 @@ Define the mesh dimensions
Define the connectivity function
--------------------------------

To create a mesh we need to define the nodes connectivity. This means to define
the elements and nodes indices connected to each node.
To create a mesh you must define the nodes connectivity. This means to define
the nodes ids connected to each node.

Here we create a function that will find the connectivity of our entities.
Here we create a function that will find this connectivity.

.. jupyter-execute::

Expand All @@ -66,7 +69,7 @@ Here we create a function that will find the connectivity of our entities.
Add nodes
---------

Add nodes to the |MeshedRegion| object:
Add |Nodes| to the |MeshedRegion| object.

.. jupyter-execute::

Expand All @@ -83,34 +86,35 @@ Add nodes to the |MeshedRegion| object:
my_meshed_region.nodes.add_node(node_id, [x, y, z])
node_id += 1

Get the nodes coordinates field
Get the nodes coordinates field.

.. jupyter-execute::

my_nodes_coordinates = my_meshed_region.nodes.coordinates_field

Set the mesh node properties
----------------------------
Set the mesh properties
-----------------------

Set the mesh unit:
Set the mesh unit.

.. jupyter-execute::

my_meshed_region.unit = "mm"

Set the nodes coordinates:
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
# Get the nodes scoping
# Set the nodes scoping
my_coordinates_scoping = my_nodes_coordinates.scoping

Add the elements
----------------
Add elements
------------
Add |Elements| to the |MeshedRegion| object.

.. jupyter-execute::

Expand Down Expand Up @@ -141,9 +145,11 @@ Add the elements
connectivity[7] = tmp
my_meshed_region.elements.add_solid_element(element_id, connectivity)
element_id += 1

Plot the mesh
-------------

.. jupyter-execute::

# Plot the mesh you created
my_meshed_region.plot()

0 comments on commit bd42cc2

Please sign in to comment.