DHI/mikeio

Write mesh from points and cells

Closed this issue · 2 comments

I have the points and cells of an unstructured triangle mesh that I've generated via https://github.com/CHLNDDEV/oceanmesh

I'd like to write these to the MIKE mesh format. Is there a way to write a MIKE mesh with just points and cells?

Thank you

It's not something that is supported in a simple function, but it's relatively easy to do using the mikecore library (which mikeio uses). Assuming you node coordinates are in a n-by-3 array called nc, the boundary codes are in codes and the element table (1-based) is in elem_table, you should be able to do this:

    from mikecore.MeshBuilder import MeshBuilder
    from mikeio.eum import EUMType, EUMUnit        
    
    builder = MeshBuilder()
    builder.SetNodes(nc[:, 0], nc[:, 1], nc[:, 2], codes)
    builder.SetElements(elem_table)
    builder.SetProjection(projection_string)

    quantity = eumQuantity.Create(EUMType.Bathymetry, EUMUnit.meter)
    builder.SetEumQuantity(quantity)

    newMesh = builder.CreateMesh()
    newMesh.Write(outfilename)

Thank you for the code!