Skip to content

Commit

Permalink
Fix tests to pass with Ferrite version 1. (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Jun 30, 2024
1 parent 1f627fe commit e014d03
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 52 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name = "FerriteGmsh"
uuid = "4f95f4f8-b27c-4ae5-9a39-ea55e634e36b"
authors = ["Maximilian Köhler <[email protected]>"]
version = "1.1.1"
version = "1.2.0"

[deps]
Ferrite = "c061ca5d-56c9-439f-9c0e-210fe06d3992"
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"

[compat]
Ferrite = "0.3"
Ferrite = "0.3, 1"
Gmsh = "0.2, 0.3"
julia = "1.6"

Expand Down
14 changes: 10 additions & 4 deletions src/FerriteGmsh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ using Gmsh: Gmsh, gmsh
const FacetIndex = isdefined(Ferrite, :FacetIndex) ? Ferrite.FacetIndex : Ferrite.FaceIndex
const facets = isdefined(Ferrite, :facets) ? Ferrite.facets : Ferrite.faces

if !isdefined(Ferrite, :SerendipityQuadraticHexahedron)
const SerendipityQuadraticHexahedron = Ferrite.Cell{3,20,6}
else
const SerendipityQuadraticHexahedron = Ferrite.SerendipityQuadraticHexahedron
end

const gmshtoferritecell = Dict("Line 2" => Ferrite.Line,
"Line 3" => Ferrite.QuadraticLine,
"Triangle 3" => Ferrite.Triangle,
Expand All @@ -17,7 +23,7 @@ const gmshtoferritecell = Dict("Line 2" => Ferrite.Line,
"Tetrahedron 4" => Ferrite.Tetrahedron,
"Tetrahedron 10" => Ferrite.QuadraticTetrahedron,
"Hexahedron 8" => Ferrite.Hexahedron,
"Hexahedron 20" => Ferrite.Cell{3,20,6})
"Hexahedron 20" => SerendipityQuadraticHexahedron)

function translate_elements(original_elements)
return original_elements
Expand All @@ -40,10 +46,10 @@ function translate_elements(original_elements::Vector{Ferrite.QuadraticTetrahedr
return ferrite_elements
end

function translate_elements(original_elements::Vector{Ferrite.Cell{3,20,6}})
ferrite_elements = Ferrite.Cell{3,20,6}[]
function translate_elements(original_elements::Vector{SerendipityQuadraticHexahedron})
ferrite_elements = SerendipityQuadraticHexahedron[]
for original_ele in original_elements
push!(ferrite_elements,Ferrite.Cell{3,20,6}((
push!(ferrite_elements, SerendipityQuadraticHexahedron((
original_ele.nodes[1],
original_ele.nodes[2],
original_ele.nodes[3],
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ using FerriteGmsh: Gmsh
using Test
using Ferrite

const FerriteV1 = isdefined(Ferrite, :FacetIndex)
if FerriteV1
const getfacetset = Ferrite.getfacetset
const FacetIndex = Ferrite.FacetIndex
else
const getfacetset = Ferrite.getfaceset
const FacetIndex = Ferrite.FaceIndex
end

include("test_jac.jl")
include("test_mixed_mesh.jl")
include("test_multiple_entities_group.jl")
Expand Down
20 changes: 15 additions & 5 deletions test/test_jac.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
@testset "det J test" begin
ip = Serendipity{3,RefCube,2}()
qr = QuadratureRule{3,RefCube}(2)
cv = CellScalarValues(qr,ip)
if FerriteV1
ip = Serendipity{RefHexahedron, 2}()
qr = QuadratureRule{RefHexahedron}(2)
cv = CellValues(qr, ip, ip)
else
ip = Serendipity{3,RefCube,2}()
qr = QuadratureRule{3,RefCube}(2)
cv = CellScalarValues(qr,ip)
end

grid = togrid("quadhex_serendipity1.msh")
dh = DofHandler(grid)
push!(dh, :u, 2)
if FerriteV1
add!(dh, :u, ip^2)
else
push!(dh, :u, 2)
end
close!(dh)

for cell in CellIterator(dh)
reinit!(cv,cell)
reinit!(cv, cell)
@test all(cv.detJdV .≈ 0.125)
end
end
12 changes: 8 additions & 4 deletions test/test_mixed_mesh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@
nodes = tonodes()
elements, gmsh_eleidx = toelements(2)
boundarydict = toboundary(1)
facesets = tofacetsets(boundarydict,elements)
facetsets = tofacetsets(boundarydict,elements)
cellsets = tocellsets(2,gmsh_eleidx)
grid = Grid(elements,nodes,facesets=facesets,cellsets=cellsets)
@test grid.facesets["bottom"] == Set([FaceIndex(15,1),FaceIndex(17,1)])
@test grid.facesets["top"] == Set([FaceIndex(3,3),FaceIndex(7,3)])
if FerriteV1
grid = Grid(elements,nodes,facetsets=facetsets,cellsets=cellsets)
else
grid = Grid(elements,nodes,facesets=facetsets,cellsets=cellsets)
end
@test getfacetset(grid, "bottom") == Set([FacetIndex(15,1),FacetIndex(17,1)])
@test getfacetset(grid, "top") == Set([FacetIndex(3,3),FacetIndex(7,3)])
@test grid.cellsets["triangle"] == Set([1,2,3,4,5,6,7,8,9,10,11,12,13,14])
@test grid.cellsets["quad"] == Set([15,16,17,18])
@test grid.nodes[12].x Vec{2}((0.0,1.0))
Expand Down
72 changes: 36 additions & 36 deletions test/test_multiple_entities_group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,42 @@
158,176,177,179,12,173,171,11,162,7,172,156,
2,10,167,157,169,180,160,9,161,159,152,170,163,
8,184,1,154,175,166,14,3,178,155,181,15,174,165])
@test grid.facesets["left"] == Set([Ferrite.FaceIndex((94, 3)),
Ferrite.FaceIndex((113, 3)),
Ferrite.FaceIndex((174, 3)),
Ferrite.FaceIndex((87, 3)),
Ferrite.FaceIndex((54, 3)),
Ferrite.FaceIndex((134, 3)),
Ferrite.FaceIndex((169, 2)),
Ferrite.FaceIndex((175, 3)),
Ferrite.FaceIndex((135, 3))])
@test grid.facesets["right"] == Set([Ferrite.FaceIndex((92, 3)),
Ferrite.FaceIndex((123, 3)),
Ferrite.FaceIndex((136, 3)),
Ferrite.FaceIndex((167, 3)),
Ferrite.FaceIndex((164, 2)),
Ferrite.FaceIndex((98, 3)),
Ferrite.FaceIndex((62, 3)),
Ferrite.FaceIndex((95, 3)),
Ferrite.FaceIndex((165, 3))])
@test grid.facesets["bottom"] == Set([Ferrite.FaceIndex((53, 3)),
Ferrite.FaceIndex((89, 3)),
Ferrite.FaceIndex((97, 3)),
Ferrite.FaceIndex((156, 1)),
Ferrite.FaceIndex((88, 3)),
Ferrite.FaceIndex((159, 3)),
Ferrite.FaceIndex((157, 3)),
Ferrite.FaceIndex((112, 3)),
Ferrite.FaceIndex((110, 3))])
@test grid.facesets["top"] == Set([Ferrite.FaceIndex((124, 3)),
Ferrite.FaceIndex((61, 3)),
Ferrite.FaceIndex((184, 2)),
Ferrite.FaceIndex((183, 3)),
Ferrite.FaceIndex((114, 3)),
Ferrite.FaceIndex((186, 3)),
Ferrite.FaceIndex((91, 3)),
Ferrite.FaceIndex((86, 3)),
Ferrite.FaceIndex((93, 3))])
@test getfacetset(grid, "left") == Set([FacetIndex((94, 3)),
FacetIndex((113, 3)),
FacetIndex((174, 3)),
FacetIndex((87, 3)),
FacetIndex((54, 3)),
FacetIndex((134, 3)),
FacetIndex((169, 2)),
FacetIndex((175, 3)),
FacetIndex((135, 3))])
@test getfacetset(grid, "right") == Set([FacetIndex((92, 3)),
FacetIndex((123, 3)),
FacetIndex((136, 3)),
FacetIndex((167, 3)),
FacetIndex((164, 2)),
FacetIndex((98, 3)),
FacetIndex((62, 3)),
FacetIndex((95, 3)),
FacetIndex((165, 3))])
@test getfacetset(grid, "bottom") == Set([FacetIndex((53, 3)),
FacetIndex((89, 3)),
FacetIndex((97, 3)),
FacetIndex((156, 1)),
FacetIndex((88, 3)),
FacetIndex((159, 3)),
FacetIndex((157, 3)),
FacetIndex((112, 3)),
FacetIndex((110, 3))])
@test getfacetset(grid, "top") == Set([FacetIndex((124, 3)),
FacetIndex((61, 3)),
FacetIndex((184, 2)),
FacetIndex((183, 3)),
FacetIndex((114, 3)),
FacetIndex((186, 3)),
FacetIndex((91, 3)),
FacetIndex((86, 3)),
FacetIndex((93, 3))])
@test all(x->x in grid.cells,[Ferrite.Triangle((51, 65, 64)),
Ferrite.Triangle((51, 64, 50)),
Ferrite.Triangle((63, 65, 54)),
Expand Down
6 changes: 5 additions & 1 deletion test/test_saveall_flag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@

# Convert the mesh to Ferrite Grid
grid_bad = FerriteGmsh.togrid()
vtk_save(vtk_grid("grid_bad", grid_bad))
if FerriteV1
close(VTKFile("grid_bad", grid_bad))
else
vtk_save(vtk_grid("grid_bad", grid_bad))
end

grid_good = mktempdir() do dir
path = joinpath(dir, "mesh.msh")
Expand Down

2 comments on commit e014d03

@fredrikekre
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/110091

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.2.0 -m "<description of version>" e014d0380861a0f395c5976fd5fcfe97dc149607
git push origin v1.2.0

Please sign in to comment.