Skip to content

Commit 54ee6a7

Browse files
committed
Update tutorial for version 2.1 of meshio
1 parent d7f7fdd commit 54ee6a7

File tree

6 files changed

+160
-84
lines changed

6 files changed

+160
-84
lines changed

docs/tutorials/brazilian_test.rst

+11-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Geometry in Gmsh and solution with SolidsPy
33
==========================================================================
44

55
:Author: Nicolás Guarín-Zapata
6-
:Date: April, 208
6+
:Date: September, 2018
77

88
This document is a tutorial on how to generate a (specific) geometry
99
using Gmsh [Gmsh2009]_ and its subsequent processing for the generation
@@ -206,13 +206,14 @@ Run the finite element program in Python.
206206

207207
.. code-block:: python
208208
209-
from __future__ import division, print_function
210209
import meshio
211210
import numpy as np
212211
213-
214-
points, cells, point_data, cell_data, field_data = \
215-
meshio.read("Prueba_brasilera.msh")
212+
mesh = meshio.read("Prueba_brasilera.msh")
213+
points = mesh.points
214+
cells = mesh.cells
215+
point_data = mesh.point_data
216+
cell_data = mesh.cell_data
216217
217218
# Element data
218219
eles = cells["triangle"]
@@ -277,13 +278,15 @@ same directory as the Python file that will process it.
277278

278279
.. code:: python
279280
280-
from __future__ import division, print_function
281281
import meshio
282282
import numpy as np
283283
284284
285-
points, cells, point_data, cell_data, field_data = \
286-
meshio.read("Prueba_brasilera.msh")
285+
mesh = meshio.read("Prueba_brasilera.msh")
286+
points = mesh.points
287+
cells = mesh.cells
288+
point_data = mesh.point_data
289+
cell_data = mesh.cell_data
287290
288291
Element data
289292
------------

docs/tutorials/template_input.py

+28-29
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,54 @@
11
# -*- coding: utf-8 -*-
22
"""
3-
Template to generate the input files for the FEM code solids_ISO.
4-
The script uses module meshio.py to read a GMSH mesh and produce
3+
Template to generate the input files for the FEM code SolidsPy.
4+
The script uses meshio to read a GMSH mesh and produce
55
text files nodes.txt, eles.txt , mater.txt and loads.txt
66
77
@authors: Juan Gomez
88
Nicolas Guarin-Zapata
99
"""
10-
from __future__ import division, print_function
1110
import meshio
1211
import numpy as np
1312
#
1413
# Read the GMSH file using meshio
1514
#
16-
points, cells, point_data, cell_data, field_data = \
17-
meshio.read("template.msh")
18-
#
15+
mesh = meshio.read("template.msh")
16+
points = mesh.points
17+
cells = mesh.cells
18+
point_data = mesh.point_data
19+
cell_data = mesh.cell_data
20+
21+
1922
# Process element data. In this case we have used 3-noded triangles.
20-
# (In solids_ISO 1 stands for quad; 2 for triangle6; 3 for triangle)
21-
#
23+
# (In SolidsPy 1 stands for quad; 2 for triangle6; 3 for triangle)
2224
eles = cells["triangle"]
2325
els_array = np.zeros([eles.shape[0], 6], dtype=int)
24-
els_array[:, 0] = range(eles.shape[0]) # Asigns element id
25-
els_array[:, 1] = 3 # Assigns element type according to solids_ISO.py
26-
els_array[:, 3::] = eles # Assign element connectivities
27-
#
26+
# Asigns element id
27+
els_array[:, 0] = range(eles.shape[0])
28+
# Assigns element type according to SolidsPy
29+
els_array[:, 1] = 3
30+
# Assign element connectivities
31+
els_array[:, 3::] = eles
32+
# Creates the materials array and assigns a profile (either 0 or 1) to
33+
# each element according to the physical surface
2834
mater_array = np.array([[1.0, 0.30],
29-
[5.0, 0.30]]) # Creates the materials array and assigns a profile (either 0 or 1) to
30-
# each element according to the physical surface
31-
maters = cell_data["triangle"]["physical"]
35+
[5.0, 0.30]])
36+
maters = cell_data["triangle"]["gmsh:physical"]
3237
els_array[:, 2] = [0 if mater == 100 else 1 for mater in maters]
33-
#
38+
3439
# Process nodal data
35-
#
3640
nodes_array = np.zeros([points.shape[0], 5])
37-
nodes_array[:, 0] = range(points.shape[0]) # Assigns nodal id
38-
nodes_array[:, 1:3] = points[:, :2] # Assigns space coordinates
39-
#
41+
nodes_array[:, 0] = range(points.shape[0]) # Assigns nodal id
42+
nodes_array[:, 1:3] = points[:, :2] # Assigns space coordinates
43+
4044
# Process physical lines to assign displacement boundary conditions
4145
# and nodal point loads
4246
#
4347
# Displacement boundary conditions
44-
#
4548
lines = cells["line"]
46-
bounds = cell_data["line"]["physical"] # Bounds contains data corresponding to the physical line.
47-
#
49+
# Bounds contains data corresponding to the physical line.
50+
bounds = cell_data["line"]["gmsh:physical"]
4851
# (-1 means a restraint degree of freedom)
49-
#
5052
id_frontera_lat = [cont for cont in range(len(bounds)) if bounds[cont] == 300]
5153
nodes_frontera_lat = lines[id_frontera_lat]
5254
nodes_frontera_lat = nodes_frontera_lat.flatten()
@@ -57,9 +59,7 @@
5759
nodes_frontera_abajo = nodes_frontera_abajo.flatten()
5860
nodes_frontera_abajo = list(set(nodes_frontera_abajo))
5961
nodes_array[nodes_frontera_abajo, 4] = -1
60-
#
6162
# Nodal point loads
62-
#
6363
id_carga = [cont for cont in range(len(bounds)) if bounds[cont] == 500]
6464
nodes_carga = lines[id_carga]
6565
nodes_carga = nodes_carga.flatten()
@@ -69,10 +69,9 @@
6969
cargas = np.zeros((ncargas, 3))
7070
cargas[:, 0] = nodes_carga
7171
cargas[:, 2] = carga_total/ncargas
72-
#
72+
7373
# Write the model .txt files
74-
#
7574
np.savetxt("eles.txt" , els_array , fmt="%d")
7675
np.savetxt("loads.txt", cargas, fmt=("%d", "%.6f", "%.6f"))
7776
np.savetxt("nodes.txt", nodes_array , fmt=("%d", "%.4f", "%.4f", "%d", "%d"))
78-
np.savetxt("mater.txt", mater_array , fmt="%.6f")
77+
np.savetxt("mater.txt", mater_array , fmt="%.6f")

examples/simple_truss/simple_truss.ipynb

+34-47
Large diffs are not rendered by default.

paper/paper.bib

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@book{bathe,
2+
title={Finite element procedures},
3+
author={Bathe, Klaus-J{\"u}rgen},
4+
year={2006},
5+
publisher={Klaus-Jurgen Bathe}
6+
}
7+
8+
@article{gmsh,
9+
title={Gmsh: A 3-D finite element mesh generator with built-in pre-and post-processing facilities},
10+
author={Geuzaine, Christophe and Remacle, Jean-Fran{\c{c}}ois},
11+
journal={International journal for numerical methods in engineering},
12+
volume={79},
13+
number={11},
14+
pages={1309--1331},
15+
year={2009},
16+
publisher={Wiley Online Library}
17+
}
18+
19+
@Misc{scipy,
20+
author = {Eric Jones and Travis Oliphant and Pearu Peterson and others},
21+
title = {{SciPy}: Open source scientific tools for {Python}},
22+
year = {2001--},
23+
url = "http://www.scipy.org/",
24+
note = {[Online; accessed June 12, 2018]}
25+
}
26+
27+
@Misc{meshio,
28+
author = {Nico Schlömer et al.},
29+
title = {{meshio v1.11.7. Zenodo. http://doi.org/10.5281/zenodo.1173116}},
30+
year = {2016--},
31+
url = "https://github.com/nschloe/meshio",
32+
note = {[Online; accessed June 12, 2018]}
33+
}

paper/paper.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: 'SolidsPy: 2D-Finite Element Analysis with Python'
3+
tags:
4+
- Python
5+
- finite elements
6+
- computational mechanics
7+
- scientific computing
8+
authors:
9+
- name: Nicolás Guarín-Zapata
10+
orcid: 0000-0002-9435-1914
11+
affiliation: 1
12+
- name: Juan D. Gómez
13+
orcid: 0000-0000-0000-0000
14+
affiliation: 1
15+
affiliations:
16+
- name: Departamento de Ingeniería Civil, Universidad EAFIT, Medellín-Colombia
17+
index: 1
18+
date: 12 June 2018
19+
bibliography: paper.bib
20+
---
21+
22+
# Summary
23+
24+
25+
JOSS welcomes submissions from broadly diverse research areas. For this reason, we request that authors include in the paper some sentences that would explain the software functionality and domain of use to a non-specialist reader. Your submission should probably be somewhere between 250-1000 words.
26+
27+
A list of the authors of the software and their affiliations
28+
A summary describing the high-level functionality and purpose of the software for a diverse, non-specialist audience
29+
A clear statement of need that illustrates the purpose of the software
30+
A list of key references including a link to the software archive
31+
Mentions (if applicable) of any ongoing research projects using the software or recent scholarly publications enabled by it
32+
33+
34+
![Displacement and von Mises stress for a wrench under bending.](wrench.png)
35+
36+
The Finite Element Method is a numerical method for the solution of problems in engineering and physics [@bathe]. These problems are commonly written as boundary value problems and involve partial differential equations.
37+
38+
``SolidsPy`` is a simple finite element analysis code for 2D elasticity problems and was designed to be used by researchers in computational mechanics and by
39+
students in courses on Computational modeling. It has also been used in graduate
40+
courses on Introduction to the Finite Element Method. It uses as input simple-to-create text files defining a model in terms of nodal, element, material and load data. Some feature of ``SolidsPy`` are:
41+
- It is based on an open-source environment.
42+
- It is easy to use.
43+
- The code allows to find displacement, strain and stress solutions for arbitrary two-dimensional domains discretized into finite elements and subject to point loads.
44+
- The code is organized in independent modules for pre-processing, assembly and post-processing allowing the user to easily modify it or add features like new elements or analyses pipelines.
45+
46+
``SolidsPy`` uses SciPy [@scipy] for matrix (sparse/dense) storage and solution of systems of equations. For the creation of complex meshes it is suggested to utilize ``Gmsh`` [@gmsh] and then take advantage of ``meshio`` [@meshio] as interface to Gmsh.
47+
48+
49+
# Acknowledgements
50+
51+
We acknowledge contributions from Edward Villegas.
52+
53+
54+
# References

paper/wrench.png

96.6 KB
Loading

0 commit comments

Comments
 (0)