Beispiel #1
0
def apply(f, coords):
    x, y = symbols("x y")
    return lambdify((x, y), f.subs({R.x: x, R.y: y}))(*coords)


u_exact = 1 + R.x + 2 * R.y  # exact solution
f = -divergence(q(u_exact) * gradient(u_exact))  # manufactured RHS

mesh = MeshTri()
mesh.refine(3)

V = InteriorBasis(mesh, ElementTriP1())

boundary = V.get_dofs().all()
interior = V.complement_dofs(boundary)


@LinearForm
def load(v, w):
    return v * apply(f, w.x)


b = asm(load, V)


@BilinearForm
def diffusion_form(u, v, w):
    return sum(v.grad * (q(w["w"]) * u.grad))

W = 0.2
mu = 1.0
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")