예제 #1
0
    def test_run(self):
        root_folder = os.path.join(
            "..",
            "3rdparty.nosync" if platform.system() == 'Darwin' else "3rdparty",
            "data")

        solver = pf.Solver()

        #some setup
        dir_path = os.path.dirname(os.path.realpath(__file__))
        mesh_path = os.path.join(dir_path, root_folder, "circle2.msh")

        settings = pf.Settings(discr_order=2, pde=pf.PDEs.Laplacian)

        problem = pf.Problem(rhs=0)
        problem.add_dirichlet_value("all", 10)
        settings.set_problem(problem)

        solver.settings(settings)
        solver.load_mesh_from_path(mesh_path,
                                   normalize_mesh=True,
                                   vismesh_rel_area=0.00001)

        solver.solve()
        sol = solver.get_solution()
        ##########################################################################

        # now we got the solution of the first laplacian, we use it as rhs for the second one
        # setup zero bc and use sol as rhs
        problem = pf.Problem(rhs=0)
        problem.add_dirichlet_value("all", 0)
        settings.problem = problem

        #reload the parameters and mesh
        solver.settings(settings)
        solver.load_mesh_from_path(mesh_path,
                                   normalize_mesh=True,
                                   vismesh_rel_area=0.00001)

        #set the rhs as prev sol
        solver.set_rhs(sol)

        solver.solve()

        #get the solution on a densly sampled mesh
        vertices, tris, sol = solver.get_sampled_solution()

        #the dense mesh is disconnected, so we need to connecit it back
        _, res = np.unique(vertices, axis=0, return_inverse=True)
        vertices, resi = np.unique(vertices, axis=0, return_index=True)

        faces = np.ndarray([len(tris), 3], dtype=np.int64)
        vv = np.ndarray([len(vertices), 3], dtype=np.float64)

        for i in range(len(tris)):
            faces[i] = np.array(
                [res[tris[i][0]], res[tris[i][1]], res[tris[i][2]]])

        for i in range(len(vv)):
            vv[i] = np.array([vertices[i][0], vertices[i][1], sol[resi[i]][0]])
예제 #2
0
    def test_run(self):
        root_folder = os.path.join(
            "..",
            "3rdparty.nosync" if platform.system() == 'Darwin' else "3rdparty",
            "data")
        dir_path = os.path.dirname(os.path.realpath(__file__))
        mesh_path = os.path.join(dir_path, root_folder, "square_beam_h.HYBRID")

        settings = pf.Settings(discr_order=1,
                               pde=pf.PDEs.NonLinearElasticity,
                               nl_solver_rhs_steps=5)

        settings.set_material_params("E", 200)
        settings.set_material_params("nu", 0.35)

        problem = pf.Torsion(fixed_boundary=5,
                             turning_boundary=6,
                             axis_coordiante=2,
                             n_turns=0.5)
        settings.problem = problem

        solver = pf.Solver()
        solver.settings(settings)
        solver.load_mesh_from_path(mesh_path,
                                   normalize_mesh=False,
                                   vismesh_rel_area=0.001)

        solver.solve()

        pts, tets, disp = solver.get_sampled_solution()
        vertices = pts + disp
        mises, _ = solver.get_sampled_mises_avg()
예제 #3
0
    def test_run(self):
        n_pts = 3

        extend = np.linspace(0, 1, n_pts)
        x, y = np.meshgrid(extend, extend, sparse=False, indexing='xy')
        pts = np.column_stack((x.ravel(), y.ravel()))

        # Create connectivity
        faces = np.ndarray([(n_pts - 1)**2, 4], dtype=np.int32)

        index = 0
        for i in range(n_pts - 1):
            for j in range(n_pts - 1):
                faces[index, :] = np.array([
                    j + i * n_pts, j + 1 + i * n_pts, j + 1 + (i + 1) * n_pts,
                    j + (i + 1) * n_pts
                ])
                index = index + 1

        # create settings
        # We use a linear material model and linear elments
        settings = pf.Settings(discr_order=1, pde=pf.PDEs.LinearElasticity)

        settings.set_material_params("E", 2100)
        settings.set_material_params("nu", 0.3)

        problem = pf.Gravity(force=0.1)
        settings.problem = problem

        solver = pf.Solver()
        solver.settings(settings)

        # This time we are using pts and faces instead of loading from the disk
        solver.set_mesh(pts, faces)

        solver.solve()

        #Animation frame, last one
        frame = -1

        # Get the solution
        pts = solver.get_sampled_points_frames()
        tets = solver.get_sampled_connectivity_frames()
        disp = solver.get_sampled_solution_frames()

        # diplace the mesh
        vertices = pts[frame] + disp[frame]

        # and get the stresses
        mises = solver.get_sampled_mises_avg_frames()
예제 #4
0
    def test_run(self):
        root_folder = os.path.join(
            "..",
            "3rdparty.nosync" if platform.system() == 'Darwin' else "3rdparty",
            "data")

        dir_path = os.path.dirname(os.path.realpath(__file__))
        mesh_path = os.path.join(dir_path, root_folder, "square_beam.mesh")
        tag_path = os.path.join(dir_path, root_folder, "square_beam.txt")

        settings = pf.Settings(discr_order=1, pde=pf.PDEs.LinearElasticity)

        settings.set_material_params("E", 200000)
        settings.set_material_params("nu", 0.35)

        settings.pde = pf.PDEs.LinearElasticity

        problem = pf.Problem()
        problem.add_dirichlet_value(2, [0, 0, 0])
        problem.add_neumann_value(1, [0, -100, 0])

        settings.problem = problem

        solver = pf.Solver()

        solver.settings(settings)
        solver.load_mesh_from_path_and_tags(mesh_path,
                                            tag_path,
                                            normalize_mesh=False,
                                            vismesh_rel_area=0.1)

        solver.solve()

        pts, tets, disp = solver.get_sampled_solution()
        vertices = pts + disp
        mises, _ = solver.get_sampled_mises_avg()

        vs, fs, tr = solver.get_sampled_traction_forces()
        assert (vs.shape[0] > 0)
        assert (vs.shape[1] == 3)

        assert (fs.shape[0] > 0)
        assert (fs.shape[1] == 3)

        assert (tr.shape[0] == fs.shape[0])
        assert (tr.shape[1] == 3)
예제 #5
0
    def test_run(self):
    #     self.run_one(1)
    #     self.run_one(2)

    # def run_one(self, discr_order):
        discr_order = 2
        root_folder = os.path.join("..", "3rdparty.nosync" if platform.system() == 'Darwin' else "3rdparty", "data")

        dir_path = os.path.dirname(os.path.realpath(__file__))
        mesh_path = os.path.join(dir_path, root_folder, "plane_hole.obj")

        settings = pf.Settings(discr_order=discr_order, pde=pf.PDEs.LinearElasticity)

        settings.set_material_params("E", 210000)
        settings.set_material_params("nu", 0.3)

        problem = pf.Problem()
        problem.set_x_symmetric(1)
        problem.set_y_symmetric(4)

        problem.add_neumann_value(3, [100, 0])
        # problem.add_neumann_value(3, lambda x,y,z: [100, 0, 0])

        settings.problem = problem

        solver = pf.Solver()

        solver.settings(settings)
        solver.load_mesh_from_path(mesh_path, normalize_mesh=True)

        solver.solve()

        pts, tets, disp = solver.get_sampled_solution()
        vertices = pts + disp
        mises, _ = solver.get_sampled_mises_avg()

        solver.compute_errors()