36
SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018

SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018

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

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

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

Introduction

Page 5: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018

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

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

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

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

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

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

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

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

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

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

Interpolation

Page 16: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018

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

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

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

SolidsPy

Page 20: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Summary

Page 35: SolidsPy: Teaching Computational Modeling ... - PyCon Colombia · SolidsPy: Teaching Computational Modeling with Python Nicolás Guarín-Zapata – @nicoguaro February 9, 2018

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

SolidsPy

https://github.com/AppliedMechanics-EAFIT/SolidsPy