示例#1
0
    def set_dict(self, mesh_dict):
        """
        Set an mesh as returned by tools methods or generators.

        Mesh will be checked for validity.

        Parameters
        ----------
        mesh_dict : dict or None, optional
            Contains one '#FEM_MSH' block of an OGS5 mesh file
            with the following information (sorted by keys):

                mesh_data : dict
                    dictionary containing information about

                    - AXISYMMETRY (bool)
                    - CROSS_SECTION (bool)
                    - PCS_TYPE (str)
                    - GEO_TYPE (str)
                    - GEO_NAME (str)
                    - LAYER (int)

                nodes : ndarray
                    Array with all node postions
                elements : dict
                    contains nodelists for elements sorted by element types
                material_id : dict
                    contains material ids for each element sorted by types
                element_id : dict
                    contains element ids for each element sorted by types
        """
        if check_mesh_dict(mesh_dict):
            self._dict = mesh_dict
        else:
            print("given mesh is not valid")
示例#2
0
    def import_mesh(self, filepath, **kwargs):
        """
        Import an external unstructured mesh from diffrent file-formats.

        kwargs will be forwarded to "tools.import_mesh"

        Parameters
        ----------
        filepath : string
            path to the mesh file to import
        file_format : str, optional
            Here you can specify the fileformat. If 'None' it will be
            determined by file extension. Default: None
        ignore_unknown : bool, optional
            Unknown data in the file will be ignored. Default: False
        import_dim : iterable of int, optional
            State which elements should be imported by dimensionality.
            Can be used to sort out unneeded elements for example from gmsh.
            Default: (1, 2, 3)

        Notes
        -----
        This routine calls the 'read' function from the meshio package
        and converts the output (see here: https://github.com/nschloe/meshio)
        If there is any "vertex" (0D element) in the element data,
        it will be removed.
        """
        tmp = import_mesh(filepath, **kwargs)
        if check_mesh_dict(tmp):
            self._meshlist = [tmp]
        else:
            raise ValueError("MSH:" + filepath + ": given mesh is not valid")
示例#3
0
    def __init__(self, mesh_dict=None, **OGS_Config):
        super(MSHsgl, self).__init__(**OGS_Config)
        self.file_ext = ".msh"
        self.force_writing = True

        if mesh_dict is None:
            self.__dict = EMPTY_MSH
        else:
            if isinstance(mesh_dict, list):
                raise ValueError("The given mesh may contains a multi-layer " +
                                 "mesh. Try loading within " +
                                 "the multimesh class.")
            else:
                if check_mesh_dict(mesh_dict):
                    self.__dict = mesh_dict
                else:
                    print("given mesh is not valid")
        self._block = 0
示例#4
0
    def combine_mesh(self, ext_mesh, **kwargs):
        """
        Combine this mesh with an external mesh.

        The node list will be
        updated to eliminate duplicates.
        Element intersections are not checked.
        kwargs will be forwarded to "tools.combine"

        Parameters
        ----------
        ext_mesh: mesh, dict or file
            This is the mesh that should be added to the existing one.
        decimals : int, optional
            Number of decimal places to round the nodes to (default: 3).
            This will not round the output, it is just for comparison of the
            node vectors.
        fast : bool, optional
            If fast is True, the vector comparison is executed by a
            decimal comparison. If fast is False, all pairwise distances
            are calculated. Default: False
        """
        if isinstance(ext_mesh, MSH):
            tmp_mesh = ext_mesh()
        elif isinstance(ext_mesh, dict):
            tmp_mesh = ext_mesh
        else:
            try:
                tmp_mesh = load_ogs5msh(ext_mesh)
            except Exception:
                try:
                    tmp_mesh = import_mesh(ext_mesh)
                except Exception:
                    print("Could not interpret the mesh that should be added")
                    return

        if check_mesh_dict(tmp_mesh, verbose=False):
            self._dict = combine(self._dict, tmp_mesh, **kwargs)
        else:
            print("given mesh to add is not valid")