示例#1
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")
示例#2
0
def grid_adapter3D(
        out_dim=(100.0, 100.0),
        in_dim=(50.0, 50.0),
        z_dim=-10.0,
        out_res=(10.0, 10.0, 10.0),
        in_res=(5.0, 5.0, 5.0),
        out_pos=(0.0, 0.0),
        in_pos=(25.0, 25.0),
        z_pos=0.0,
        in_mat=0,
        out_mat=0,
        fill=False,
):
    """
    Generate a grid adapter.

    3D adapter from an outer grid resolution
    to an inner grid resolution with gmsh.

    Parameters
    ----------
    out_dim : list of 2 float
        xy-Dimension of the outer block
    in_dim : list of 2 float
        xy-Dimension of the inner block
    z_dim : float
        z-Dimension of the whole block
    out_res : list of 3 float
        Grid resolution of the outer block
    in_res : list of 3 float
        Grid resolution of the inner block
    out_pos : list of 2 float
        xy-Position of the origin of the outer block
    in_pos : list of 2 float
        xy-Position of the origin of the inner block
    z_dim : float
        z-Position of the origin of the whole block
    in_mat : integer
        Material-ID of the inner block
    out_mat : integer
        Material-ID of the outer block
    fill : bool, optional
        State if the inner block should be filled with a rectangular mesh.
        Default: False.

    Returns
    -------
    result : dictionary
        Result contains one '#FEM_MSH' block of the OGS 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 element types
            element_id : dict
                contains element ids for each element sorted by element types

    """
    out = gmsh(
        gmsh_grid_adapt3D(out_dim, in_dim, z_dim, out_res, in_res, out_pos,
                          in_pos, z_pos),
        import_dim=3,
    )
    out["material_id"] = gen_std_mat_id(out["elements"], out_mat)

    if fill:
        element_no = [
            int(in_dim[0] / in_res[0]),
            int(in_dim[1] / in_res[1]),
            int(abs(z_dim) / in_res[2]),
        ]
        mesh_in = rectangular(
            dim=3,
            mesh_origin=in_pos + (z_pos + min(z_dim, 0.0), ),
            element_no=element_no,
            element_size=in_res,
        )
        mesh_in["material_id"] = gen_std_mat_id(mesh_in["elements"], in_mat)
        dec = int(np.ceil(-np.log10(min(min(in_res), min(out_res)))) + 2.0) * 2
        out = combine(mesh_in, out, dec)

    return out
示例#3
0
def grid_adapter2D(
    out_dim=(100.0, 100.0),
    in_dim=(50.0, 50.0),
    out_res=(10.0, 10.0),
    in_res=(1.0, 1.0),
    out_pos=(0.0, 0.0),
    in_pos=(25.0, 25.0),
    z_pos=0.0,
    in_mat=0,
    out_mat=0,
    fill=False,
):
    """
    generate a grid adapter in 2D from an outer grid resolution
    to an inner grid resolution with gmsh.

    Parameters
    ----------
    out_dim : list of 2 float
        xy-Dimension of the outer block
    in_dim : list of 2 float
        xy-Dimension of the inner block
    out_res : list of 2 float
        Grid resolution of the outer block
    in_res : list of 2 float
        Grid resolution of the inner block
    out_pos : list of 2 float
        xy-Position of the origin of the outer block
    in_pos : list of 2 float
        xy-Position of the origin of the inner block
    z_pos : float
        z-Position of the origin of the whole block
    in_mat : integer
        Material-ID of the inner block
    out_mat : integer
        Material-ID of the outer block
    fill : bool, optional
        State if the inner block should be filled with a rectangular mesh.
        Default: False.

    Returns
    -------
    result : dictionary
        Result contains one '#FEM_MSH' block of the OGS 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 element types
            element_id : dict
                contains element ids for each element sorted by element types

    """
    import pygmsh as pg

    geo = gmsh_grid_adapt2D(
        out_dim, in_dim, out_res, in_res, out_pos, in_pos, z_pos
    )
    points, cells, __, __, __ = pg.generate_mesh(
        geo,
        #        num_lloyd_steps=0,
        #        num_quad_lloyd_steps=0,
        dim=2,
    )
    out = convert_meshio(points, cells, import_dim=2)
    out["material_id"] = gen_std_mat_id(out["elements"], out_mat)

    if fill:
        element_no = [int(in_dim[0] / in_res[0]), int(in_dim[1] / in_res[1])]
        mesh_in = rectangular(
            dim=2,
            mesh_origin=in_pos + (z_pos,),
            element_no=element_no,
            element_size=in_res,
        )
        mesh_in["material_id"] = gen_std_mat_id(mesh_in["elements"], in_mat)
        out = combine(mesh_in, out)

    return out