Ultimate Example¶
Imports¶
import numpy as np
import math
import igl
import meshplot as mp
import wildmeshing as wm
import polyfempy as pf
Read the Mesh¶
V, F = igl.read_triangle_mesh("data/mesh.obj")
mp.plot(V, F, shading={"wireframe": True})
Tetrahedralization with Wildmeshing¶
wm.tetrahedralize("data/mesh.obj", "out.mesh", mute_log=True)
Loading the Mesh in Polyfem¶
minn = np.min(V, axis=0)
maxx = np.max(V, axis=0)
center = (minn+maxx)/2
Function to select sidesets:
- Sideset 2: z-component close to the bottom boundary
minn[2]
and larger than y of center - Sideset 3: z-component close to the bottom boundary
minn[2]
and smaller than y of center
def sideset(p):
if abs(p[2] - minn[2]) < 0.5:
if p[1] > center[1]:
return 2
else:
return 3
return 1
Loading and Visualizing Sidesets¶
solver.set_boundary_side_set_from_bary(sideset)
ps, ts, s = solver.get_boundary_sidesets()
col = np.zeros_like(s); col[s==2] = 2; col[s==3] = 3
mp.plot(ps, ts, col)
Setup Problem¶
settings = pf.Settings()
problem = pf.Problem()
settings.set_pde(pf.PDEs.LinearElasticity)
settings.set_material_params("E", 200)
settings.set_material_params("nu", 0.35)
problem.set_displacement(2, [0, 0, 0])
problem.set_force(3, [0, 0.5, 0])
settings.set_problem(problem)
Solve!¶
p, t, d = solver.get_sampled_solution()
m = np.linalg.norm(d, axis=1)
mp.plot(p+d, t, m)