gridap / GridapGmsh.jl

Gmsh generated meshes for Gridap
MIT License
42 stars 19 forks source link

Using GridapGmsh with mixed triangle-quad meshes #63

Open gijswl opened 2 years ago

gijswl commented 2 years ago

Hi all,

I would like to use Gridap with a mesh consisting of regions of unstructured triangles and structured quads. The mesh is generated in Gmsh, so I would like to load it using GridapGmsh. Doing so at the moment results in an error:

Only one element type per dimension allowed for the moment.
Dimension 2 has 2 different element types

Digging through the GridapGmsh code a little bit, it seems that most of the required functionality is present to allow this mixed mesh to be imported. By modifying the _setup_reffe function, I managed to load the mesh and use Gridap to compute a simple problem (see this Jupyter Notebook).

function _setup_reffes(gmsh,d,orient_if_simplex)
    elemTypes, elemTags, nodeTags = gmsh.model.mesh.getElements(d)

    ncells, nmin, nmax = _check_cell_tags(elemTags)
    cell_to_type = fill(Int8(0), ncells)

    noffset = nmin - 1;
    for (i, etype) in enumerate(elemTypes)
        cell_to_type[elemTags[i] .- noffset] .= i   # Correctly fill the cell_to_type array, instead of filling '1'

        # Check that the elements are first order; higher-order elements are not yet supported
        name, dim, order::Int, numv, parv = gmsh.model.mesh.getElementProperties(etype)
        if order == 0 && etype == POINT
            order = 1
        end

        if order != 1
            gmsh.finalize()
            error("For the moment only for first-order elements")
        end
    end

    # Retrieve RefFEs for the element types
    reffes = [_reffe_from_etype(etype) for etype in elemTypes];

    # Check mesh orientation
    boo = [(is_simplex(get_polytope(reffe)) && orient_if_simplex) for reffe in reffes];
    orientation = any(boo) ? Oriented() : NonOriented()

    (cell_to_type, reffes, orientation)
end

However, I am unsure of whether the mesh being partially structured and partially unstructured has any effect on the orientation part. Could this lead to issues with other types of meshes?

jav-ed commented 1 year ago

I do not know the answer to your question, but I have a similar issue. A mesh generated with gmsh which contains 1d and 2d elements is unfortunately not able to be read by GridapGmsh for now