Example #1
0
    def __init__(self, nodes, elements, edges, mesh_files):
        """
        Test case for a Lagrange mesh. Tries to test an Argyris mesh.
        """
        for mesh_file in mesh_files:
            self.nodes = nodes
            # The mesh classes try to flatten nodes if possible. Do it here too.
            if np.all(self.nodes[:, -1] == self.nodes[0, -1]):
                self.nodes = self.nodes[:,0:-1]
            self.elements = elements
            self.edges = edges
            mesh = meshes.mesh_factory(*mesh_file)
            parsed_mesh = parsers.parser_factory(*mesh_file)

            npt.assert_equal(self.nodes, mesh.nodes)
            npt.assert_equal(self.elements, mesh.elements)
            if parsed_mesh.edges:
                assert set(self.edges) == reduce(lambda a, b : a + b,
                                                 mesh.edge_collections.values())

            npt.assert_almost_equal(meshtools.project_nodes(lambda x : x[0:2],
                                                     self.elements, self.nodes),
                             self.nodes[:,0:2], decimal=10)

            if parsed_mesh.edges:
                assert set(map(lambda x : x[0:-1], self.edges)) == \
                       set(map(lambda x : x[0:-1],
                           meshtools.extract_boundary_edges(self.elements)))

            # Test Argyris stuff.
            if self.elements.shape[1] == 6:
                TestArgyrisCase(mesh_file, parsed_mesh)
Example #2
0
    def __init__(self, nodes, elements, edges, mesh_files):
        """
        Test case for a parsed mesh. Tries to test an Argyris mesh.
        """
        for mesh_file in mesh_files:
            self.nodes = nodes
            self.elements = elements
            self.edges = edges
            parsed_mesh = parsers.parser_factory(*mesh_file)

            npt.assert_almost_equal(self.nodes, parsed_mesh.nodes)
            npt.assert_equal(self.elements, parsed_mesh.elements)
            if parsed_mesh.edges:
                assert np.all(self.edges == parsed_mesh.edges)

            npt.assert_almost_equal(meshtools.project_nodes(lambda x : x[0:2],
                                                     self.elements, self.nodes),
                             self.nodes[:, 0:2], decimal=10)

            if parsed_mesh.edges:
                assert set(map(lambda x : x[0:-1], self.edges)) == \
                       set(map(lambda x : x[0:-1],
                           meshtools.extract_boundary_edges(self.elements)))

            # Test Argyris stuff.
            if self.elements.shape[1] == 6:
                TestArgyrisCase(mesh_file, parsed_mesh)
Example #3
0
    def __init__(self, nodes, elements, edges, mesh_files):
        """
        Test case for a Lagrange mesh. Tries to test an Argyris mesh.
        """
        for mesh_file in mesh_files:
            self.nodes = nodes
            # The mesh classes try to flatten nodes if possible. Do it here too.
            if np.all(self.nodes[:, -1] == self.nodes[0, -1]):
                self.nodes = self.nodes[:, 0:-1]
            self.elements = elements
            self.edges = edges
            mesh = meshes.mesh_factory(*mesh_file)
            parsed_mesh = parsers.parser_factory(*mesh_file)

            npt.assert_equal(self.nodes, mesh.nodes)
            npt.assert_equal(self.elements, mesh.elements)
            if parsed_mesh.edges:
                assert set(self.edges) == reduce(
                    lambda a, b: a + b, mesh.edge_collections.values())

            npt.assert_almost_equal(meshtools.project_nodes(
                lambda x: x[0:2], self.elements, self.nodes),
                                    self.nodes[:, 0:2],
                                    decimal=10)

            if parsed_mesh.edges:
                assert set(map(lambda x : x[0:-1], self.edges)) == \
                       set(map(lambda x : x[0:-1],
                           meshtools.extract_boundary_edges(self.elements)))

            # Test Argyris stuff.
            if self.elements.shape[1] == 6:
                TestArgyrisCase(mesh_file, parsed_mesh)
Example #4
0
    def __init__(self, nodes, elements, edges, mesh_files):
        """
        Test case for a parsed mesh. Tries to test an Argyris mesh.
        """
        for mesh_file in mesh_files:
            self.nodes = nodes
            self.elements = elements
            self.edges = edges
            parsed_mesh = parsers.parser_factory(*mesh_file)

            npt.assert_almost_equal(self.nodes, parsed_mesh.nodes)
            npt.assert_equal(self.elements, parsed_mesh.elements)
            if parsed_mesh.edges:
                assert np.all(self.edges == parsed_mesh.edges)

            npt.assert_almost_equal(meshtools.project_nodes(
                lambda x: x[0:2], self.elements, self.nodes),
                                    self.nodes[:, 0:2],
                                    decimal=10)

            if parsed_mesh.edges:
                assert set(map(lambda x : x[0:-1], self.edges)) == \
                       set(map(lambda x : x[0:-1],
                           meshtools.extract_boundary_edges(self.elements)))

            # Test Argyris stuff.
            if self.elements.shape[1] == 6:
                TestArgyrisCase(mesh_file, parsed_mesh)
Example #5
0
def mesh_factory(*args, **kwargs):
    """
    Parse a finite element mesh representation and then convert it to a
    Mesh or ArgyrisMesh object.

    Required Arguments
    ------------------
    * mesh_files      : text files comprising the finite element mesh.

    Keyword Arguments
    -----------------
    * argyris        : boolean to specify if the mesh should have
                       additional nodes added to transform it in to an
                       Argyris mesh. Defaults to False.

    * order          : Mesh element order. The nodes will be renumbered
                       appropriately (1 for linears, 2 for quadratics).
                       Defaults to None. This is not implemented yet.

    * projection     : function that projects nodes. Defaults to None
                       (no projection)

    * borders        : a dictionary correlating names with GMSH 'Physical
                       Line' attributes. For example,

                           borders = {'open' : (1, 2)}

                       will correlate edges on Physical Lines 1 and 2
                       with the 'open' edge collection.

    * default_border : the default edge collection for any edges that
                       are not in a special_border collection. Defaults
                       to 'land'.
    """
    parsed_mesh = parsers.parser_factory(*args)
    if 'argyris' in kwargs:
        keywords = kwargs.copy()
        del keywords['argyris']
        return ArgyrisMesh(parsed_mesh, **keywords)
    elif 'Argyris' in kwargs:
        keywords = kwargs.copy()
        del keywords['Argyris']
        return ArgyrisMesh(parsed_mesh, **keywords)
    else:
        return Mesh(parsed_mesh, **kwargs)
Example #6
0
def mesh_factory(*args, **kwargs):
    """
    Parse a finite element mesh representation and then convert it to a
    Mesh or ArgyrisMesh object.

    Required Arguments
    ------------------
    * mesh_files      : text files comprising the finite element mesh.

    Keyword Arguments
    -----------------
    * argyris        : boolean to specify if the mesh should have
                       additional nodes added to transform it in to an
                       Argyris mesh. Defaults to False.

    * order          : Mesh element order. The nodes will be renumbered
                       appropriately (1 for linears, 2 for quadratics).
                       Defaults to None. This is not implemented yet.

    * projection     : function that projects nodes. Defaults to None
                       (no projection)

    * borders        : a dictionary correlating names with GMSH 'Physical
                       Line' attributes. For example,

                           borders = {'open' : (1, 2)}

                       will correlate edges on Physical Lines 1 and 2
                       with the 'open' edge collection.

    * default_border : the default edge collection for any edges that
                       are not in a special_border collection. Defaults
                       to 'land'.
    """
    parsed_mesh = parsers.parser_factory(*args)
    if 'argyris' in kwargs:
        keywords = kwargs.copy()
        del keywords['argyris']
        return ArgyrisMesh(parsed_mesh, **keywords)
    elif 'Argyris' in kwargs:
        keywords = kwargs.copy()
        del keywords['Argyris']
        return ArgyrisMesh(parsed_mesh, **keywords)
    else:
        return Mesh(parsed_mesh, **kwargs)