コード例 #1
0
def main():
    height = 100
    width = 600
    delta = width / height

    # Create the mesh to solve linear elasticity on.
    mesh = Mesh("meshes/bridge.xml")

    scale_mesh(mesh, width, height)

    # Define the function space
    V = VectorFunctionSpace(mesh, "P", 1)
    # Mark boundary subdomians
    boundary_parts = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
    boundary_parts.set_all(0)

    # Tolarance of boundary near checks.
    tol = 2e-4

    class BottomBoundary(SubDomain):
        """ Constrain the bottom to not move. """
        def inside(self, x, on_boundary):
            return ((near(x[0], 0.1, 10) or near(x[0], width - 0.1, 10)) and
                near(x[1], 0, tol))
    gamma_bottom = BottomBoundary()

    class PointLoad(SubDomain):
        """ Add a point load to the top center. """
        def inside(self, x, on_boundary):
            return (near(x[0], width / 2.0, width / 50) and
                near(x[1], height, tol))
    gamma_point = PointLoad()
    gamma_point.mark(boundary_parts, 2)

    B = Constant((0.0, 0.0)) # Body force per unit volume
    T = Constant((0.0, delta * 0)) # Point load on the boundary

    # Boundary conditions on the subdomains
    bct = DirichletBC(V, Constant((0.0, 0.0)), gamma_bottom, method="pointwise")
    bcp = DirichletBC(V, T, gamma_point, method="pointwise")
    bcs = [bct, bcp]

    dss = ds(subdomain_data=boundary_parts)
    L = lambda v: dot(B, v) * dx + dot(T, v) * dss(2)

    u = linear_elasticity(V, L, bcs)
    File("output/MBB/displacement.pvd") << u

    # Compute magnitude of displacement
    V = FunctionSpace(mesh, "P", 1)
    u_magnitude = sqrt(dot(u, u))
    u_magnitude = project(u_magnitude, V)
    File("output/MBB/magnitude.pvd") << u_magnitude

    print("min/max u: {:g}, {:g}".format(
        u_magnitude.vector().get_local().min(),
        u_magnitude.vector().get_local().max()))

    # Save solution to file in VTK format
    File("output/MBB/von_mises.pvd") << von_Mises_stress(mesh, u)
コード例 #2
0
class MBBBoundaryConditions(BoundaryConditions):
    def get_fixed(self):
        width, height, tol = self.width, self.height, self.tol

        class BottomBoundary(SubDomain):
            """ Constrain the bottom to not move. """
            def inside(self, x, on_boundary):
                return ((near(x[0], 0.1, 2e1) or near(x[0], width - 0.1, 2e1))
                        and near(x[1], 0, tol))

        return [BottomBoundary()]

    def get_forces(self):
        width, height, tol = self.width, self.height, self.tol

        class PointLoad(SubDomain):
            """ Add a point load to the top center. """
            def inside(self, x, on_boundary):
                return (near(x[0], width / 2.0, width / 50)
                        and near(x[1], height, tol))

        return [PointLoad()], [Constant((0.0, -2e-1))]


if __name__ == "__main__":
    width, height, tol = 600, 100, 5e-2
    bc = MBBBoundaryConditions(width, height, tol)
    mesh = Mesh("meshes/bridge.xml")
    scale_mesh(mesh, width, height)
    run_simulation(mesh, bc, "MBB/bridge-single-load-", E=1e1)
コード例 #3
0
def main():
    height = 100
    width = 600
    delta = width / height

    # Create the mesh to solve linear elasticity on.
    mesh = Mesh("meshes/bridge.xml")

    scale_mesh(mesh, width, height)

    # Define the function space
    V = VectorFunctionSpace(mesh, "P", 1)
    # Mark boundary subdomians
    boundary_parts = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
    boundary_parts.set_all(0)

    # Tolarance of boundary near checks.
    tol = 2e-4

    class BottomBoundary(SubDomain):
        """ Constrain the bottom to not move. """
        def inside(self, x, on_boundary):
            return ((near(x[0], 0.1, 10) or near(x[0], width - 0.1, 10))
                    and near(x[1], 0, tol))

    gamma_bottom = BottomBoundary()

    class PointLoad(SubDomain):
        """ Add a point load to the top center. """
        def inside(self, x, on_boundary):
            return (near(x[0], width / 2.0, width / 50)
                    and near(x[1], height, tol))

    gamma_point = PointLoad()
    gamma_point.mark(boundary_parts, 2)

    B = Constant((0.0, 0.0))  # Body force per unit volume
    T = Constant((0.0, delta * 0))  # Point load on the boundary

    # Boundary conditions on the subdomains
    bct = DirichletBC(V,
                      Constant((0.0, 0.0)),
                      gamma_bottom,
                      method="pointwise")
    bcp = DirichletBC(V, T, gamma_point, method="pointwise")
    bcs = [bct, bcp]

    dss = ds(subdomain_data=boundary_parts)
    L = lambda v: dot(B, v) * dx + dot(T, v) * dss(2)

    u = linear_elasticity(V, L, bcs)
    File("output/MBB/displacement.pvd") << u

    # Compute magnitude of displacement
    V = FunctionSpace(mesh, "P", 1)
    u_magnitude = sqrt(dot(u, u))
    u_magnitude = project(u_magnitude, V)
    File("output/MBB/magnitude.pvd") << u_magnitude

    print("min/max u: {:g}, {:g}".format(
        u_magnitude.vector().get_local().min(),
        u_magnitude.vector().get_local().max()))

    # Save solution to file in VTK format
    File("output/MBB/von_mises.pvd") << von_Mises_stress(mesh, u)
コード例 #4
0
            def inside(self, x, on_boundary):
                return near(x[0], width, tol) and near(x[1], height / 3., tol)

        return [PointLoad()], [Constant((0.0, -3e-1))]


if __name__ == "__main__":
    bc = LBracketBoundaryConditions(1, 1, 5e-2)

    # Create the mesh to solve linear elasticity on.
    large_quad = mshr.Polygon(
        [Point(0, 0), Point(1, 0),
         Point(1, 1), Point(0, 1)])
    small_quad = mshr.Polygon([
        Point(1 / 3., 1 / 3.),
        Point(1, 1 / 3.),
        Point(1, 1),
        Point(1 / 3., 1)
    ])
    domain = large_quad - small_quad
    mesh = mshr.generate_mesh(domain, 30)
    run_simulation(mesh, bc, "L-bracket/v100-")

    mesh = Mesh("meshes/L-bracket-v20.xml")
    scale_mesh(mesh, 1, 1)
    run_simulation(mesh, bc, "L-bracket/v20-")

    mesh = Mesh("meshes/L-bracket-v10.xml")
    scale_mesh(mesh, 1, 1)
    run_simulation(mesh, bc, "L-bracket/v10-")