![Page 1: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/1.jpg)
SolidsPy: Teaching Computational Modeling with Python
Nicolás Guarín-Zapata – @nicoguaro
February 9, 2018
![Page 2: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/2.jpg)
What am I sharing today?
Our teaching experience in computational modeling with Python using a finite element module/program.
![Page 3: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/3.jpg)
Outline
● Introduction
● Finite Element Method
● SolidsPy
● Examples of use
![Page 4: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/4.jpg)
Introduction
![Page 5: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/5.jpg)
Teaching goals
● Computational modeling
● Computing with Python
● Numerical methods
![Page 6: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/6.jpg)
Computational Modeling
● Second year, undergraduate course
● Use of computing to solve engineering problems
● Use SolidsPy building-blocks to perform mechanical simulations
![Page 7: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/7.jpg)
Introduction to Finite Element Method
● First year, graduate-level course
● Mathematical details of the method
● Step-by-step construction of a Finite Element program
![Page 8: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/8.jpg)
The Finite Element Method
![Page 9: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/9.jpg)
What is the Finite Element Method?
A method for solving problems of engineering and mathematical physics that involve partial differential equations.
![Page 10: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/10.jpg)
Let’s see an example
Bridge location
![Page 11: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/11.jpg)
The differential equation
μ∇2u+(μ+λ)∇ (∇⋅u)+F=0
And boundary conditions
![Page 12: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/12.jpg)
The solution
Low High
Vertical displacement
![Page 13: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/13.jpg)
Different steps involved
● Geometry discretization
● Interpolation
● Numerical integration
● Equations solution
● Post-processing / Visualization
![Page 14: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/14.jpg)
Geometry discretization
![Page 15: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/15.jpg)
Interpolation
![Page 16: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/16.jpg)
Numerical integration
Using interpolation and numerical integration, the
problem translates into solving a linear system.
f ( x )
x
![Page 17: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/17.jpg)
Equations solution
SciPy has several solvers that can be used for the solution of the system.
[K ]{U }={F }
Stiffnessmatrix
Nodaldisplacements
Nodalforces
![Page 18: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/18.jpg)
Visualization
Once we have the solution, we visualize the results to check
that it makes sense.
![Page 19: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/19.jpg)
SolidsPy
![Page 20: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/20.jpg)
Open-source ecosystem
Python libraries:
● Numpy
● Scipy
● SymPy
● Matplotlib
● meshio
External software:
● Gmsh
● ParaView
![Page 21: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/21.jpg)
Open-source ecosystem
GmshSolidsPy(Pythonlibraries)
Paraview
Pre-processing Processing Post-processing
![Page 22: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/22.jpg)
Simple input files
Let’s consider this simple model.
![Page 23: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/23.jpg)
Simple input files
nodes.txt0 0.00 0.00 0 -11 2.00 0.00 0 -12 2.00 2.00 0 03 0.00 2.00 0 04 1.00 0.00 -1 -15 2.00 1.00 0 06 1.00 2.00 0 07 0.00 1.00 0 08 1.00 1.00 0 0
mater.txt1.0 0.3
eles.txt0 1 1 0 4 8 71 1 1 4 1 5 82 1 1 7 8 6 33 1 1 8 5 2 6
loads.txt3 0.0 1.06 0.0 2.02 0.0 1.0
![Page 24: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/24.jpg)
Gmsh for more complicated models
We use Gmsh for complicated geometries and then convert them to SolidsPy’s format using meshio.
![Page 25: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/25.jpg)
Paraview for complex visualizations
We can use meshio to export
results to Paraview
![Page 26: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/26.jpg)
Examples of use
![Page 27: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/27.jpg)
SolidsPy as a standalone FE program
Just requires the path to input files to complete an analysis
![Page 28: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/28.jpg)
Let’s see an example
![Page 29: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/29.jpg)
import matplotlib.pyplot as plt
from solidspy import solids_GUI
disp = solids_GUI()
plt.show()
![Page 30: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/30.jpg)
SolidsPy as a standalone FE program
Several input files for different models in examples in the following repo:
https://github.com/AppliedMechanics-EAFIT/SolidsPy-meshes
![Page 31: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/31.jpg)
Building-blocks for a Finite Element Analysis
● Mesh import/export
● Elements library
● Assembler
● Solver
![Page 32: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/32.jpg)
Let’s see an example
![Page 33: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/33.jpg)
import solidspy as solids
# Reading the datanodes, mats, elements, loads = solids.preprocesor.readin()
# Forming the system of equationsDME, IBC, neq = solids.assemutil.DME(nodes, elements)KG = solids.assemutil.assembler(elements, mats, nodes, neq, DME)RHSG = solids.assemutil.loadasem(loads, IBC, neq)
# System solutionUG = solids.solutil.static_sol(KG, RHSG)
# Post-processingUC = solids.postprocesor.complete_disp(IBC, nodes, UG)E_nodes, S_nodes = solids.postprocesor.strain_nodes(nodes, elements, mats, UC)solids.postprocesor.fields_plot(elements, nodes, UC, E_nodes=E_nodes, S_nodes=S_nodes)
![Page 34: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/34.jpg)
Summary
![Page 35: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/35.jpg)
SolidsPy is …
● FEM code in an open-source ecosystem● Easy to use● Used to teach
– Computational modeling for undergrads– Finite element method for grads
![Page 36: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018](https://reader035.vdocuments.site/reader035/viewer/2022071100/5fd8e74b64d7665e8524a7e4/html5/thumbnails/36.jpg)
SolidsPy
https://github.com/AppliedMechanics-EAFIT/SolidsPy