mapping = MappingMortar.init_2D(m, M, m.boundaries['contact'], M.facets_satisfying(lambda x: x[0] == 1.0), np.array([0.0, 1.0])) mb = [ FacetBasis(m, e, mapping=mapping, intorder=4, side=0), FacetBasis(M, E, mapping=mapping, intorder=4, side=1), ] # define bilinear forms E = 1000.0 nu = 0.3 Lambda, Mu = lame_parameters(E, nu) weakform1 = linear_elasticity(Lambda, Mu) weakform2 = linear_elasticity(Lambda, Mu) C = linear_stress(Lambda, Mu) alpha = 1000 limit = 0.3 # assemble the stiffness matrices K1 = asm(weakform1, ib) K2 = asm(weakform2, Ib) K = [[K1, 0.], [0., K2]] f = [None] * 2 def gap(x): """Initial gap between the bodies."""
from scipy.sparse.linalg import eigsh import numpy as np m1 = MeshLine(np.linspace(0, 5, 50)) m2 = MeshLine(np.linspace(0, 1, 10)) m = m1 * m2 e1 = ElementQuad1() mapping = MappingIsoparametric(m, e1) e = ElementVectorH1(e1) gb = InteriorBasis(m, e, mapping, 2) K = asm(linear_elasticity(1.0, 1.0), gb) @bilinear_form def mass(u, du, v, dv, w): return u[0] * v[0] + u[1] * v[1] M = asm(mass, gb) D = gb.get_dofs(lambda x: x[0] == 0.0).all() y = np.zeros(gb.N) I = gb.complement_dofs(D) L, x = eigsh(K[I].T[I].T, k=6, M=M[I].T[I].T, which='SM')
""" from skfem import * from skfem.models.elasticity import linear_elasticity,\ lame_parameters import numpy as np from pathlib import Path m = MeshTet.load(Path(__file__).parent / 'meshes' / 'beams.msh') e1 = ElementTetP2() e = ElementVectorH1(e1) ib = Basis(m, e) K = asm(linear_elasticity(*lame_parameters(200.0e9, 0.3)), ib) rho = 8050.0 @BilinearForm def mass(u, v, w): from skfem.helpers import dot return dot(rho * u, v) M = asm(mass, ib) L, x = solve( *condense(K, M, D=ib.find_dofs()["fixed"]), solver=solver_eigen_scipy_sym() )
weak form of the linear elasticity problem is defined in :func:`skfem.models.elasticity.linear_elasticity`. """ import numpy as np from skfem import * from skfem.models.elasticity import linear_elasticity, lame_parameters m = MeshHex() m.refine(3) e1 = ElementHex1() e = ElementVectorH1(e1) ib = InteriorBasis(m, e, MappingIsoparametric(m, e1), 3) K = asm(linear_elasticity(*lame_parameters(1e3, 0.3)), ib) dofs = { 'left' : ib.get_dofs(lambda x: x[0] == 0.0), 'right': ib.get_dofs(lambda x: x[0] == 1.0), } u = np.zeros(K.shape[0]) u[dofs['right'].nodal['u^1']] = 0.3 I = ib.complement_dofs(dofs) u = solve(*condense(K, 0*u, I=I, x=u)) sf = 1.0 m.p += sf * u[ib.nodal_dofs]
mapping = MappingMortar.init_2D(m, M, m.boundaries['contact'], M.facets_satisfying(lambda x: x[0] == 1.0), np.array([0.0, 1.0])) mb = [ MortarFacetBasis(m, e, mapping=mapping, intorder=4, side=0, dofs=dofs1), MortarFacetBasis(M, E, mapping=mapping, intorder=4, side=1, dofs=dofs2), ] # define bilinear forms youngs_modulus = 1000.0 poisson_ratio = 0.3 Lambda, Mu = lame_parameters(youngs_modulus, poisson_ratio) weakform = linear_elasticity(Lambda, Mu) C = linear_stress(Lambda, Mu) alpha = 1000 limit = 0.3 # mortar forms @BilinearForm def bilin_mortar(u, v, w): # jumps ju = (-1.) ** w.idx[0] * dot(u, w.n) jv = (-1.) ** w.idx[1] * dot(v, w.n) nxn = prod(w.n, w.n) mu = .5 * ddot(nxn, C(sym_grad(u))) mv = .5 * ddot(nxn, C(sym_grad(v))) return ((1. / (alpha * w.h) * ju * jv - mu * jv - mv * ju)
m1 = MeshLine(np.linspace(0, 5, 50)) m2 = MeshLine(np.linspace(0, 1, 10)) m = m1 * m2 e1 = ElementQuad1() mapping = MappingIsoparametric(m, e1) e = ElementVector(e1) gb = Basis(m, e, mapping, 2) lam = 1. mu = 1. K = asm(linear_elasticity(lam, mu), gb) @BilinearForm def mass(u, v, w): return dot(u, v) M = asm(mass, gb) D = gb.find_dofs({'left': m.facets_satisfying(lambda x: x[0] == 0.)}) y = gb.zeros() I = gb.complement_dofs(D) L, x = solve(*condense(K, M, I=I), solver=solver_eigen_scipy_sym(k=6, sigma=0.0))
E1 = 1000.0 E2 = 1000.0 nu1 = 0.3 nu2 = 0.3 Mu1 = E1 / (2.0 * (1.0 + nu1)) Mu2 = E2 / (2.0 * (1.0 + nu2)) Lambda1 = E1 * nu1 / ((1.0 + nu1) * (1.0 - 2.0 * nu1)) Lambda2 = E2 * nu2 / ((1.0 + nu2) * (1.0 - 2.0 * nu2)) Mu = Mu1 Lambda = Lambda1 weakform1 = linear_elasticity(Lambda=Lambda1, Mu=Mu1) weakform2 = linear_elasticity(Lambda=Lambda2, Mu=Mu2) alpha = 1 K1 = asm(weakform1, ib) K2 = asm(weakform2, Ib) L = 0 for i in range(2): for j in range(2): @bilinear_form def bilin_penalty(u, du, v, dv, w): n = w.n ju = (-1.0)**i * (u[0] * n[0] + u[1] * n[1]) jv = (-1.0)**j * (v[0] * n[0] + v[1] * n[1])
rho = 1.0 delta = W / L gamma = 0.4 * delta**2 beta = 1.25 lambda_ = beta g = gamma mesh = MeshTet.init_tensor(np.linspace(0, L, 10 + 1), np.linspace(0, W, 3 + 1), np.linspace(0, W, 3 + 1)) basis = InteriorBasis(mesh, ElementVectorH1(ElementTetP1())) clamped = basis.get_dofs(lambda x: x[0] == 0.0).all() free = basis.complement_dofs(clamped) K = asm(linear_elasticity(lambda_, mu), basis) @LinearForm def load(v, w): return -rho * g * v.value[2] f = asm(load, basis) u = solve(*condense(K, f, I=free)) deformed = MeshTet(mesh.p + u[basis.nodal_dofs], mesh.t) deformed.save("deformed.xdmf") u_magnitude = np.linalg.norm(u.reshape((-1, 3)), axis=1)