This page was generated from wta/elasticity3D.ipynb.

3D Solid Mechanics

[1]:
from netgen.occ import *
from netgen.webgui import Draw as DrawGeo
import ngsolve
[2]:
box = Box((0,0,0), (3,0.6,1))
box.faces.name="outer"
cyl = sum( [Cylinder((0.5+i,0,0.5), Y, 0.25,0.8) for i in range(3)] )
cyl.faces.name="cyl"
geo = box-cyl

DrawGeo(geo);

find edges between box and cylinder, and build chamfers (requires OCC 7.4 or newer):

[3]:
cylboxedges = geo.faces["outer"].edges * geo.faces["cyl"].edges
cylboxedges.name = "cylbox"
geo = geo.MakeChamfer(cylboxedges, 0.03)

name faces for boundary conditions:

[4]:
geo.faces.Min(X).name = "fix"
geo.faces.Max(X).name = "force"

DrawGeo(geo);
[5]:
from ngsolve import *
from ngsolve.webgui import Draw
mesh = Mesh(OCCGeometry(geo).GenerateMesh(maxh=0.1)).Curve(3)
Draw (mesh);

Linear elasticity

Displacement: \(u : \Omega \rightarrow R^3\)

Linear strain:

\[\varepsilon(u) := \tfrac{1}{2} ( \nabla u + (\nabla u)^T )\]

Stress by Hooke’s law:

\[\sigma = 2 \mu \varepsilon + \lambda \operatorname{tr} \varepsilon I\]

Equilibrium of forces:

\[\operatorname{div} \sigma = f\]

Displacement boundary conditions:

\[u = u_D \qquad \text{on} \, \Gamma_D\]

Traction boundary conditions:

\[\sigma n = g \qquad \text{on} \, \Gamma_N\]

Variational formulation:

Find: \(u \in H^1(\Omega)^3\) such that \(u = u_D\) on \(\Gamma_D\)

\[\int_\Omega \sigma(\varepsilon(u)) : \varepsilon(v) \, dx = \int_\Omega f v dx + \int_{\Gamma_N} g v ds\]

holds for all \(v = 0\) on \(\Gamma_D\).

[6]:
E, nu = 210, 0.2
mu  = E / 2 / (1+nu)
lam = E * nu / ((1+nu)*(1-2*nu))

def Stress(strain):
    return 2*mu*strain + lam*Trace(strain)*Id(3)
[7]:
fes = VectorH1(mesh, order=3, dirichlet="fix")
u,v = fes.TnT()
gfu = GridFunction(fes)

with TaskManager():
    a = BilinearForm(InnerProduct(Stress(Sym(Grad(u))), Sym(Grad(v))).Compile()*dx)
    pre = Preconditioner(a, "bddc")
    a.Assemble()
[8]:
force = CF( (1e-3,0,0) )
f = LinearForm(force*v*ds("force")).Assemble()
[9]:
from ngsolve.krylovspace import CGSolver
inv = CGSolver(a.mat, pre, printrates=True, tol=1e-8)
gfu.vec.data = inv * f.vec
CG iteration 1, residual = 0.00017982731508198383
CG iteration 2, residual = 7.527505823604945e-05
CG iteration 3, residual = 8.667360647586835e-05
CG iteration 4, residual = 6.611763953432798e-05
CG iteration 5, residual = 6.009530495083381e-05
CG iteration 6, residual = 4.240151181641347e-05
CG iteration 7, residual = 3.174659664109268e-05
CG iteration 8, residual = 2.700717685976357e-05
CG iteration 9, residual = 2.00934990707544e-05
CG iteration 10, residual = 1.6202784652567393e-05
CG iteration 11, residual = 1.1164241035834946e-05
CG iteration 12, residual = 8.707361209404897e-06
CG iteration 13, residual = 6.263300218968349e-06
CG iteration 14, residual = 4.827662227893163e-06
CG iteration 15, residual = 3.5048301823912143e-06
CG iteration 16, residual = 2.6744872507307845e-06
CG iteration 17, residual = 1.9959626253864036e-06
CG iteration 18, residual = 1.4173939614999705e-06
CG iteration 19, residual = 1.0735929420644774e-06
CG iteration 20, residual = 7.342807879181117e-07
CG iteration 21, residual = 6.364131834883669e-07
CG iteration 22, residual = 4.1303078290544055e-07
CG iteration 23, residual = 3.6675837210493945e-07
CG iteration 24, residual = 2.5942494636524836e-07
CG iteration 25, residual = 1.8056292944594613e-07
CG iteration 26, residual = 1.364254168219712e-07
CG iteration 27, residual = 9.965383340157404e-08
CG iteration 28, residual = 7.638450216780134e-08
CG iteration 29, residual = 5.282418030039657e-08
CG iteration 30, residual = 4.016696599502585e-08
CG iteration 31, residual = 2.853050965153194e-08
CG iteration 32, residual = 2.1713860987773953e-08
CG iteration 33, residual = 1.6955931220410977e-08
CG iteration 34, residual = 1.130961739162179e-08
CG iteration 35, residual = 8.11458969294064e-09
CG iteration 36, residual = 5.851886240034641e-09
CG iteration 37, residual = 4.02666935520167e-09
CG iteration 38, residual = 3.0617221322999536e-09
CG iteration 39, residual = 2.524397997539255e-09
CG iteration 40, residual = 1.64199339795755e-09
CG iteration 41, residual = 1.1584821077665425e-09
CG iteration 42, residual = 9.166212047289275e-10
CG iteration 43, residual = 6.365473095921317e-10
CG iteration 44, residual = 4.2304394415039934e-10
CG iteration 45, residual = 4.2574798646903924e-10
CG iteration 46, residual = 2.669586400759799e-10
CG iteration 47, residual = 1.928377085561849e-10
CG iteration 48, residual = 1.492658991012547e-10
CG iteration 49, residual = 1.2679821434832127e-10
CG iteration 50, residual = 9.144051069330677e-11
CG iteration 51, residual = 6.538918550184701e-11
CG iteration 52, residual = 4.127519295599013e-11
CG iteration 53, residual = 3.09615255206534e-11
CG iteration 54, residual = 2.0256105584379848e-11
CG iteration 55, residual = 1.507068480973578e-11
CG iteration 56, residual = 1.182953774698648e-11
CG iteration 57, residual = 7.406491081569494e-12
CG iteration 58, residual = 5.294034574380214e-12
CG iteration 59, residual = 3.4532583731824637e-12
CG iteration 60, residual = 2.3826115815423207e-12
CG iteration 61, residual = 1.5976935100008915e-12
[10]:
with TaskManager():
    fesstress = MatrixValued(H1(mesh,order=3), symmetric=True)
    gfstress = GridFunction(fesstress)
    gfstress.Interpolate (Stress(Sym(Grad(gfu))))
[11]:
Draw (5e4*gfu, mesh);
[12]:
Draw (Norm(gfstress), mesh, deformation=1e4*gfu, draw_vol=False, order=3);
[ ]: