Exemplo n.º 1
0
    def test_2d(self):
        law = c.LinearElastic(2000, 0.2, c.Constraint.PLANE_STRAIN)
        stress, tangent = law.evaluate([42., 0, 0])
        self.assertEqual(stress.shape[0], 3)
        self.assertEqual(tangent.shape, (3, 3))

        self.assertEqual(c.q_dim(c.Constraint.PLANE_STRAIN), 3)
        self.assertEqual(c.g_dim(c.Constraint.PLANE_STRAIN), 2)
Exemplo n.º 2
0
    def test_plate(self):
        L, radius = 4.0, 1.0

        prm = c.Parameters(c.Constraint.PLANE_STRESS)

        plate_with_hole = PlateWithHoleSolution(L=L, E=prm.E, nu=prm.nu, radius=radius)
        mesh = plate_with_hole.build_mesh(resolution=50)

        n = FacetNormal(mesh)
        stress = StressSolution(plate_with_hole, degree=2)
        traction = dot(stress, n)
  
        problem = c.MechanicsProblem(mesh, prm, c.LinearElastic(prm.E, prm.nu, prm.constraint))
        bc0 = DirichletBC(problem.Vd.sub(0), 0.0, boundary.plane_at(0, "x"))
        bc1 = DirichletBC(problem.Vd.sub(1), 0.0, boundary.plane_at(0, "y"))
        problem.set_bcs([bc0, bc1])
        problem.add_force_term(dot(TestFunction(problem.Vd), traction)*ds)
        u = problem.solve() 
        
        disp = DisplacementSolution(plate_with_hole, degree=2)
        error = errornorm(disp, u)
        self.assertLess(error, 1.e-6)
Exemplo n.º 3
0
 def test_1d(self):
     law = c.LinearElastic(2000, 0.2, c.Constraint.UNIAXIAL_STRAIN)
     stress, tangent = law.evaluate([42.])
     self.assertAlmostEqual(stress[0], 84000.)
     self.assertAlmostEqual(tangent[0, 0], 2000.)
def test_tensile_meso():

    mesh = df.Mesh()
    mvc = df.MeshValueCollection("size_t", mesh, 1)
    LX, LY = 80.0, 80.0  # magic!

    mesh_file = Path(__file__).parent / "mesh.xdmf"
    with df.XDMFFile(str(mesh_file)) as f:
        f.read(mesh)
        f.read(mvc, "gmsh:physical")

    subdomains = df.MeshFunction("size_t", mesh, mvc)

    if not TEST:
        import matplotlib.pyplot as plt
        df.plot(subdomains)
        plt.show()

    mat_l = 2.0
    Q = c.Q

    s = GDMSpaces(mesh, c.Constraint.PLANE_STRAIN, subdomains)
    s.create()
    R = df.inner(s.eps(s.d_), s.q[Q.SIGMA]) * s.dxm(1)
    dR = df.inner(s.eps(s.dd), s.q[Q.DSIGMA_DEPS] * s.eps(s.d_)) * s.dxm(1)

    R += s.e_ * (s.e - s.q[Q.EEQ]) * s.dxm(1)
    R += df.dot(df.grad(s.e_), mat_l**2 * df.grad(s.e)) * s.dxm(1)

    dR += s.de * df.dot(s.q[Q.DSIGMA_DE], s.eps(s.d_)) * s.dxm(1)
    dR += df.inner(s.eps(s.dd), -s.q[Q.DEEQ] * s.e_) * s.dxm(1)
    dR += s.de * s.e_ * s.dxm(1)
    dR += df.dot(df.grad(s.de), mat_l**2 * df.grad(s.e_)) * s.dxm(1)

    R += df.inner(s.eps(s.d_), s.q[Q.SIGMA]) * s.dxm(2)
    dR += df.inner(s.eps(s.dd), s.q[Q.DSIGMA_DEPS] * s.eps(s.d_)) * s.dxm(2)
    dR += s.de * s.e_ * s.dxm(2)

    R += df.inner(s.eps(s.d_), s.q[Q.SIGMA]) * s.dxm(3)
    dR += df.inner(s.eps(s.dd), s.q[Q.DSIGMA_DEPS] * s.eps(s.d_)) * s.dxm(3)
    dR += s.de * s.e_ * s.dxm(3)

    VQF, VQV, VQT = c.helper.spaces(s.mesh, s.deg_q, c.q_dim(s.constraint))
    calculate_eps = c.helper.LocalProjector(s.eps(s.d), VQV, s.dxm)
    calculate_e = c.helper.LocalProjector(s.e, VQF, s.dxm(1))

    F = 0.75  # interface reduction
    t = 0.5  # interface thickness
    lawAggreg = c.LinearElastic(2 * 26738, 0.18, s.constraint)
    lawInterf = c.LocalDamage(
        26738,
        0.18,
        s.constraint,
        c.DamageLawExponential(k0=F * 3.4 / 26738.0,
                               alpha=0.99,
                               beta=3.4 / 26738.0 / (0.12 * F / t)),
        c.ModMisesEeq(k=10, nu=0.18, constraint=s.constraint),
    )
    lawMatrix = c.GradientDamage(
        26738.0,
        0.18,
        s.constraint,
        c.DamageLawExponential(k0=3.4 / 26738.0,
                               alpha=0.99,
                               beta=3.4 / 26738.0 / 0.0216),
        c.ModMisesEeq(k=10, nu=0.18, constraint=s.constraint),
    )
    loop = c.IpLoop()
    loop.add_law(lawMatrix, np.where(s.ip_flags == 1)[0])
    loop.add_law(lawAggreg, np.where(s.ip_flags == 2)[0])
    loop.add_law(lawInterf, np.where(s.ip_flags == 3)[0])
    loop.resize(s.n)

    bot = boundary.plane_at(0, "y")
    top = boundary.plane_at(LY, "y")
    bc_expr = df.Expression("u", degree=0, u=0)
    bcs = []
    bcs.append(df.DirichletBC(s.Vd.sub(1), bc_expr, top))
    bcs.append(df.DirichletBC(s.Vd.sub(1), 0.0, bot))
    bcs.append(
        df.DirichletBC(s.Vd.sub(0),
                       0.0,
                       boundary.point_at((0, 0)),
                       method="pointwise"))

    # return

    assembler = df.SystemAssembler(dR, R, bcs)

    class SolveMe(df.NonlinearProblem):
        def F(self, b, x):
            calculate_eps(s.q_in[Q.EPS])
            calculate_e(s.q_in[Q.E])
            loop.evaluate(s.q_in[Q.EPS].vector().get_local(),
                          s.q_in[Q.E].vector().get_local())

            # ... and write the calculated values into their quadrature spaces.
            c.helper.set_q(s.q[Q.SIGMA], loop.get(c.Q.SIGMA))
            c.helper.set_q(s.q[Q.DSIGMA_DEPS], loop.get(c.Q.DSIGMA_DEPS))
            c.helper.set_q(s.q[Q.DEEQ], loop.get(c.Q.DEEQ))
            c.helper.set_q(s.q[Q.DSIGMA_DE], loop.get(c.Q.DSIGMA_DE))
            c.helper.set_q(s.q[Q.EEQ], loop.get(c.Q.EEQ))

            assembler.assemble(b, x)

        def J(self, A, x):
            assembler.assemble(A)

    linear_solver = df.LUSolver("mumps")
    solver = df.NewtonSolver(df.MPI.comm_world, linear_solver,
                             df.PETScFactory.instance())
    solver.parameters["linear_solver"] = "mumps"
    solver.parameters["maximum_iterations"] = 10
    solver.parameters["error_on_nonconvergence"] = False

    problem = SolveMe()

    def solve(t, dt):
        print(t, dt)
        bc_expr.u = 0.1 * t
        # try:
        return solver.solve(problem, s.u.vector())
        # except:
        # return -1, False

    ld = c.helper.LoadDisplacementCurve(bcs[0])
    if not TEST:
        ld.show()
    if not ld.is_root:
        df.set_log_level(df.LogLevel.ERROR)

    fff = df.XDMFFile("output.xdmf")
    fff.parameters["functions_share_mesh"] = True
    fff.parameters["flush_output"] = True

    plot_space = df.FunctionSpace(s.mesh, "DG", 0)
    k = df.Function(plot_space, name="kappa")

    def pp(t):
        calculate_eps(s.q_in[Q.EPS])
        calculate_e(s.q_in[Q.E])
        loop.update(s.q_in[Q.EPS].vector().get_local(),
                    s.q_in[Q.E].vector().get_local())

        # this fixes XDMF time stamps
        import locale

        locale.setlocale(locale.LC_NUMERIC, "en_US.UTF-8")
        d, e = s.u.split(0)
        d.rename("disp", "disp")
        e.rename("e", "e")

        all_kappa = lawInterf.kappa() + lawMatrix.kappa()
        k.vector().set_local(all_kappa[::s.nq])

        fff.write(d, t)
        fff.write(e, t)
        fff.write(k, t)

        ld(t, df.assemble(R))

    t_end = 1.
    if TEST:
        t_end = 0.02
    TimeStepper(solve, pp, s.u).adaptive(t_end, dt=0.02)
def law(prm):
    return c.LinearElastic(prm.E, prm.nu, prm.constraint)