Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start Framework for ExtendableGridsGmshExt #28

Closed
wants to merge 33 commits into from
Closed
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
619c28c
Start Framework for SimplexGridGmshExt
j-fu Jun 21, 2023
8ef7b98
[extras] section for 1.6 support
j-fu Jun 21, 2023
10e16db
Code I wrote sofar for the gmsh extension
jotaraz Jun 23, 2023
a82d359
Delete sto3d_pg_0.1.msh
jotaraz Jun 23, 2023
cdea770
Delete gsmh_to_extendablegrid.jl
jotaraz Jun 23, 2023
675a229
Delete test_extendablegrid_gmsh.jl
jotaraz Jun 23, 2023
470343d
testcode and test-msh-files for the gmsh extension
jotaraz Jun 23, 2023
aec02e1
code for the gmsh_extension for grid conversion
jotaraz Jun 23, 2023
88952b9
Merge pull request #29 from jotaraz/gmsh-extension
j-fu Jun 29, 2023
603ecc0
move gmsh interface code to the extension file
j-fu Jun 30, 2023
f1b355a
move gmsh rw tests directly into runtests
j-fu Jun 30, 2023
528453c
Add projects, fix gmsh interface API
j-fu Jun 30, 2023
6f2ad66
Introduce low confidence level for grid comparison as band-aid for CI
j-fu Jun 30, 2023
7b2ae72
Support extension mechanism also for 1.6 via Requires
j-fu Jun 30, 2023
d9859cf
fix requires handling
j-fu Jun 30, 2023
7e5625d
small modifictions, in particular don't call initialize/finalize duri…
j-fu Jul 3, 2023
fbc252c
Start Framework for SimplexGridGmshExt
j-fu Jun 21, 2023
7abb258
[extras] section for 1.6 support
j-fu Jun 21, 2023
099907a
Code I wrote sofar for the gmsh extension
jotaraz Jun 23, 2023
e778d59
Delete sto3d_pg_0.1.msh
jotaraz Jun 23, 2023
f908bf3
Delete gsmh_to_extendablegrid.jl
jotaraz Jun 23, 2023
c1d476f
Delete test_extendablegrid_gmsh.jl
jotaraz Jun 23, 2023
99ff50c
testcode and test-msh-files for the gmsh extension
jotaraz Jun 23, 2023
5e73008
code for the gmsh_extension for grid conversion
jotaraz Jun 23, 2023
1667868
move gmsh interface code to the extension file
j-fu Jun 30, 2023
2a5b631
move gmsh rw tests directly into runtests
j-fu Jun 30, 2023
a9b3061
Add projects, fix gmsh interface API
j-fu Jun 30, 2023
c2a216d
Introduce low confidence level for grid comparison as band-aid for CI
j-fu Jun 30, 2023
6f4bb01
Support extension mechanism also for 1.6 via Requires
j-fu Jun 30, 2023
98554b4
fix requires handling
j-fu Jun 30, 2023
df8aaed
small modifictions, in particular don't call initialize/finalize duri…
j-fu Jul 3, 2023
ca02006
Merge branch 'gmsh-extension' of github.com:j-fu/ExtendableGrids.jl i…
j-fu Jul 20, 2023
e8fd8e1
Merge branch 'master' into gmsh-extension
j-fu Jul 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -5,22 +5,38 @@ version = "1.0.0"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Bijections = "e2ed5e7c-b2de-5872-ae92-c73ca462fb04"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
ElasticArrays = "fdbdab4c-e67f-52f5-8c3f-e7b388dad3d4"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
AbstractTrees = "0.3,0.4"
Bijections = "0.1.4"
DocStringExtensions = "0.8,0.9"
ElasticArrays = "1"
Gmsh = "0.2.2"
Requires = "1.1.3"
StaticArrays = "1"
StatsBase = "0.34"
WriteVTK = "1.14"
julia = "1.6"

[extensions]
ExtendableGridsGmshExt = "Gmsh"

[extras]
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"

[weakdeps]
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
442 changes: 442 additions & 0 deletions ext/ExtendableGridsGmshExt.jl

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/ExtendableGrids.jl
Original file line number Diff line number Diff line change
@@ -183,4 +183,22 @@ export TokenStream, gettoken, expecttoken,trytoken
include("io.jl")
export writeVTK

#
# Extension support for Julia <1.9
# This works but fails to verify the gmsh version
#
if !isdefined(Base, :get_extension)
using Requires
end

@static if !isdefined(Base, :get_extension)
function __init__()
@require Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb" begin
include("../ext/ExtendableGridsGmshExt.jl")
end
end
end



end # module
35 changes: 24 additions & 11 deletions src/extendablegrid.jl
Original file line number Diff line number Diff line change
@@ -474,19 +474,32 @@ end
"""
$(SIGNATURES)
Recursively check seeming equality of two grids. Seemingly means
that long arrays are only compared via random samples
"""
function seemingly_equal(grid1::ExtendableGrid, grid2::ExtendableGrid)
for key in keys(grid1)
if !haskey(grid2,key)
return false
end
if !seemingly_equal(grid1[key],grid2[key])
return false
Recursively check seeming equality of two grids (for CI tests).
Confidence level:
- :low : Point numbers etc are the same
- :medium : long arrays are only compared via random samples
- :full : (TBD) all arrays are equal
"""
function seemingly_equal(grid1::ExtendableGrid, grid2::ExtendableGrid; confidence=:medium)
if confidence==:medium
for key in keys(grid1)
if !haskey(grid2,key)
return false
end
if !seemingly_equal(grid1[key],grid2[key])
return false
end
end
return true
elseif confidence==:low
grid1_data=(num_nodes(grid1),num_cells(grid1), num_bfaces(grid1))
grid2_data=(num_nodes(grid2),num_cells(grid2), num_bfaces(grid2))
return grid1_data==grid2_data
else
error("Confidence level $(confidence) not implemented")
return false
end
return true
end

"""
36 changes: 31 additions & 5 deletions src/simplexgrid.jl
Original file line number Diff line number Diff line change
@@ -651,13 +651,22 @@ $(TYPEDSIGNATURES)
Read grid from file. Currently for pdelib sg format only.
"""
function simplexgrid(file::String;format="")
Ti=Cint
(fbase,fext)=splitext(file)
if format==""
format=fext[2:end]
end
@assert format=="sg"


if format=="msh"
return simplexgrid_from_gmsh(file)
elseif format=="sg"
return simplexgrid_from_sg(file)
else
error("Format extension $(format) not supported")
end
end

function simplexgrid_from_sg(file)
Ti=Cint
tks=TokenStream(file)
expecttoken(tks,"SimplexGrid")
version=parse(Float64,gettoken(tks))
@@ -730,6 +739,15 @@ function simplexgrid(file::String;format="")
simplexgrid(coord,cells,regions,faces,bregions);
end

# Implementation in Gmsh ext
function simplexgrid_from_gmsh end

function write_gmsh end

function simplexgrid(mod::Module)

end

"""
$(TYPEDSIGNATURES)
@@ -740,8 +758,16 @@ function Base.write(fname::String, g::ExtendableGrid; format="")
if format==""
format=fext[2:end]
end
@assert format=="sg"

if format=="sg"
write_sg(fname,g)
elseif format=="msh"
write_gmsh(fname,g)
else
error("Format extension $(format) not supported")
end
end

function write_sg(fname,g)
dim_g=dim_grid(g)
dim_s=dim_space(g)
nn=num_nodes(g)
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Gmsh = "705231aa-382f-11e9-3f0c-b7cb4346fdeb"
GridVisualize = "5eed8a63-0fb0-45eb-886d-8d5a387d12b8"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
SimplexGridFactory = "57bfcd06-606e-45d6-baf4-4ba06da0efd5"
29 changes: 18 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ENV["MPLBACKEND"]="agg"

using Test, ExtendableGrids, GridVisualize, SHA, SimplexGridFactory, Triangulate
import Gmsh: gmsh # trigger extension
import CairoMakie

CairoMakie.activate!(type="svg",visible=false)
@@ -123,21 +124,27 @@ end

end

function testrw(grid,format;confidence=:medium)
ftmp=tempname()*"."*format
write(ftmp,grid)
grid1=simplexgrid(ftmp)
seemingly_equal(grid1,grid;confidence=confidence)
end


@testset "Read/Write sg" begin
X=collect(0:0.05:1)
@test testrw(simplexgrid(X),"sg")
@test testrw(simplexgrid(X,X),"sg")
@test testrw(simplexgrid(X,X,X),"sg")
end


@testset "Read/Write" begin
function testrw(grid)
ftmp=tempname()
write(ftmp,grid,format="sg")
grid1=simplexgrid(ftmp,format="sg")
seemingly_equal(grid1,grid)
end
@testset "Read/Write gmsh" begin
X=collect(0:0.05:1)
@test testrw(simplexgrid(X))
@test testrw(simplexgrid(X,X))
@test testrw(simplexgrid(X,X,X))
gmsh.initialize()
@test testrw(simplexgrid(X,X),"msh";confidence=:low)
@test testrw(simplexgrid(X,X,X),"msh";confidence=:low)
gmsh.finalize()
end

function testgrid(grid,testdata)
162 changes: 162 additions & 0 deletions test/sto_2d.msh
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
$MeshFormat
4.1 0 8
$EndMeshFormat
$PhysicalNames
5
0 7 "pts"
1 8 "bottom"
1 9 "left"
1 10 "diag"
2 11 "area"
$EndPhysicalNames
$Entities
3 3 1 0
1 0.1 0 0 1 7
2 1 0 0 1 7
3 0 1.1 0 1 7
12 0.09999999999999998 0 0 1 0 0 1 8 2 1 -2
13 0 0 0 0.1 1.1 0 1 9 2 1 -3
23 0 0 0 1 1.1 0 1 10 2 2 -3
1 0 0 0 1 1.1 0 1 11 3 12 23 -13
$EndEntities
$Nodes
7 30 1 30
0 1 0 1
1
0.1 0 0
0 2 0 1
2
1 0 0
0 3 0 1
3
0 1.1 0
1 12 0 5
4
5
6
7
8
0.1567801907822411 0 0
0.2355893020285959 0 0
0.3449738726783115 0 0
0.4967962137603849 0 0
0.7075208698844142 0 0
1 13 0 6
9
10
11
12
13
14
0.09524745181038846 0.05227803008572691 0
0.08879026377095686 0.1233070985194745 0
0.08001701805729272 0.2198128013697802 0
0.06809699030295172 0.3509331066675311 0
0.05190149933462875 0.5290835073190838 0
0.02989702048558225 0.7711327746585953 0
1 23 0 2
15
16
0.6666666666675561 0.3666666666656883 0
0.3333333333344565 0.7333333333320979 0
2 1 0 14
17
18
19
20
21
22
23
24
25
26
27
28
29
30
0.1419270947581633 0.1729666058904767 0
0.2902815873534537 0.08149025467686229 0
0.1578971408174753 0.4310076563829752 0
0.1973076172249919 0.05882799894860743 0
0.4139751849468026 0.1247355605751757 0
0.3212345343684614 0.2138882099534932 0
0.1856957300913129 0.2683640065185384 0
0.1472524575709624 0.09637099308676195 0
0.552576591396379 0.1606090550234558 0
0.2787291306620607 0.4307307101220553 0
0.4523263440900239 0.3252574397483093 0
0.2205789186995287 0.1420431435520539 0
0.1830561467445127 0.6021222871250107 0
0.1421002222025124 0.04507316972188376 0
$EndNodes
$Elements
7 61 1 61
0 1 15 1
1 1
0 2 15 1
2 2
0 3 15 1
3 3
1 12 1 6
4 1 4
5 4 5
6 5 6
7 6 7
8 7 8
9 8 2
1 13 1 7
10 1 9
11 9 10
12 10 11
13 11 12
14 12 13
15 13 14
16 14 3
1 23 1 3
17 2 15
18 15 16
19 16 3
2 1 2 42
20 8 15 25
21 22 23 28
22 16 14 29
23 7 8 25
24 4 5 20
25 5 6 18
26 13 12 19
27 14 13 29
28 22 21 27
29 11 10 17
30 12 11 23
31 10 9 24
32 9 1 30
33 1 4 30
34 6 7 21
35 5 18 20
36 19 12 23
37 17 10 24
38 11 17 23
39 23 22 26
40 21 25 27
41 4 20 30
42 24 20 28
43 18 22 28
44 17 24 28
45 18 21 22
46 24 9 30
47 13 19 29
48 18 6 21
49 20 18 28
50 19 23 26
51 21 7 25
52 26 22 27
53 25 15 27
54 20 24 30
55 2 15 8
56 15 16 27
57 3 14 16
58 16 26 27
59 26 16 29
60 23 17 28
61 19 26 29
$EndElements
2,560 changes: 2,560 additions & 0 deletions test/sto_3d.msh

Large diffs are not rendered by default.