Skip to content

Commit

Permalink
handling of meshes in 2d
Browse files Browse the repository at this point in the history
  • Loading branch information
maltezfaria committed Oct 7, 2023
1 parent 1a43feb commit a2db9e1
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
18 changes: 18 additions & 0 deletions docs/src/geo_and_meshes.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,21 @@ more details on possible arguments):
```@example gmsh-sphere
poly(view(msh,Ω);strokewidth=1,color=:lightgray, transparency=true)
```

Two-dimensional meshes are very similar:

```@example gmsh-disk
using Inti
using Gmsh
using GLMakie
gmsh.initialize()
gmsh.option.setNumber("General.Verbosity", 2)
gmsh.model.add("Disk")
gmsh.model.occ.addDisk(0,0,0,1,1)
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(2)
Ω = Inti.gmsh_import_domain(;dim=2)
msh = Inti.gmsh_import_mesh(Ω;dim=2)
gmsh.finalize()
poly(view(msh,Ω);strokewidth=2)
```
2 changes: 1 addition & 1 deletion ext/IntiGmshExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function Inti.gmsh_import_mesh(Ω::Inti.Domain; dim=3)
if dim == 3
return msh
elseif dim == 2
return convert_to_2d(msh)
return Inti._convert_to_2d(msh)
else
error("`dim` value must be `2` or `3`")

Check warning on line 139 in ext/IntiGmshExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/IntiGmshExt.jl#L139

Added line #L139 was not covered by tests
end
Expand Down
32 changes: 32 additions & 0 deletions src/mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,38 @@ function Base.iterate(iter::ElementIterator{<:LagrangeElement,<:LagrangeMesh}, s
return iter[state], state + 1

Check warning on line 113 in src/mesh.jl

View check run for this annotation

Codecov / codecov/patch

src/mesh.jl#L111-L113

Added lines #L111 - L113 were not covered by tests
end

# convert a mesh to 2d by ignoring third component. Note that this also requires
# converting various element types to their 2d counterpart. These are needed
# because some meshers like gmsh always create three-dimensional objects, so we
# must convert after importing the mesh
function _convert_to_2d(mesh::LagrangeMesh{3,T}) where {T}
# create new dictionaries for elements and ent2tagsdict with 2d elements as keys
new_etype2mat = empty(mesh.etype2mat)
new_ent2tags = empty(mesh.ent2tags)
for (E, tags) in mesh.etype2mat
E2d = _convert_to_2d(E)
new_etype2mat[E2d] = tags
end
for (ent, dict) in mesh.ent2tags
new_dict = empty(dict)
for (E, tags) in dict
E2d = _convert_to_2d(E)
new_dict[E2d] = tags
end
new_ent2tags[ent] = new_dict
end
# construct new 2d mesh
return LagrangeMesh{2,T}(
[x[1:2] for x in mesh.nodes],
new_etype2mat,
new_ent2tags
)
end

function _convert_to_2d(::Type{LagrangeElement{R,N,SVector{3,T}}}) where {R,N,T}
return LagrangeElement{R,N,SVector{2,T}}
end

"""
struct SubMesh{N,T} <: AbstractMesh{N,T}
Expand Down
13 changes: 13 additions & 0 deletions test/gmsh_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ using Gmsh
using Test

# for now that check that the code below does not error
@test begin
gmsh.initialize()
gmsh.option.setNumber("General.Verbosity", 2)
gmsh.model.add("Disk")
gmsh.model.occ.addDisk(0,0,0,1,1)
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(2)
Ω = Inti.gmsh_import_domain(;dim=2)
msh = Inti.gmsh_import_mesh(Ω;dim=2)
gmsh.finalize()
return true
end

@test begin
gmsh.initialize()
gmsh.option.setNumber("General.Verbosity", 2)
Expand Down

0 comments on commit a2db9e1

Please sign in to comment.