Skip to content

Commit e0ce661

Browse files
committed
Use new package ExtensionErrors
1 parent bbe61b7 commit e0ce661

File tree

2 files changed

+9
-57
lines changed

2 files changed

+9
-57
lines changed

Project.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ExtendableGrids"
22
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
3-
authors = ["Juergen Fuhrmann <[email protected]>", "Christian Merdon <[email protected]>", "Johannes Taraz <[email protected]>", "Patrick Jaap <[email protected]>"]
43
version = "1.14.2"
4+
authors = ["Juergen Fuhrmann <[email protected]>", "Christian Merdon <[email protected]>", "Johannes Taraz <[email protected]>", "Patrick Jaap <[email protected]>"]
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
@@ -10,6 +10,7 @@ Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
1010
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1111
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1212
ElasticArrays = "fdbdab4c-e67f-52f5-8c3f-e7b388dad3d4"
13+
ExtensionErrors = "b7d44a4a-b691-4b61-aae1-e3eded184641"
1314
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1415
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1516
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -27,6 +28,9 @@ Metis = "2679e427-3c69-5b7f-982b-ece356f1e94b"
2728
TetGen = "c5d3f3f7-f850-59f6-8a2e-ffc6dc1317ea"
2829
Triangulate = "f7e6ffb2-c36d-4f8f-a77e-16e897189344"
2930

31+
[sources]
32+
ExtensionErrors = {rev = "main", url = "[email protected]:jpthiele/ExtensionErrors.jl.git"}
33+
3034
[extensions]
3135
ExtendableGridsGmshExt = "Gmsh"
3236
ExtendableGridsMetisExt = "Metis"
@@ -40,6 +44,7 @@ Compat = "4.10"
4044
Dates = "1.9"
4145
DocStringExtensions = "0.8,0.9"
4246
ElasticArrays = "1"
47+
ExtensionErrors = "1.0.0"
4348
Gmsh = "0.2.2,0.3"
4449
Graphs = "1.11.1"
4550
InteractiveUtils = "1.9"

src/io.jl

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,12 @@
11
using WriteVTK
2-
2+
using ExtensionErrors
33
# conversion from AbstractElementGeometry to WriteVTK.VTKCellTypes
44
WriteVTK.VTKCellType(::Type{<:AbstractElementGeometry1D}) = VTKCellTypes.VTK_LINE
55
WriteVTK.VTKCellType(::Type{<:Triangle2D}) = VTKCellTypes.VTK_TRIANGLE
66
WriteVTK.VTKCellType(::Type{<:Quadrilateral2D}) = VTKCellTypes.VTK_QUAD
77
WriteVTK.VTKCellType(::Type{<:Tetrahedron3D}) = VTKCellTypes.VTK_TETRA
88
WriteVTK.VTKCellType(::Type{<:Hexahedron3D}) = VTKCellTypes.VTK_HEXAHEDRON
99

10-
struct ExtensionLoadError <: Exception
11-
fname::Symbol
12-
weakdeps::Vector{Symbol}
13-
end
14-
15-
Base.showerror(io::IO, e::ExtensionLoadError) =
16-
print(
17-
io,
18-
"ExtensionLoadError: "
19-
* "The function " * String(e.fname) * " is part of an extension.\n"
20-
* "Suggestion: Install and load the following modules:"
21-
* mapreduce(x -> "\n" * x, *, String.(e.weakdeps))
22-
)
23-
24-
struct ExtensionMethodError <: Exception
25-
fn::Function
26-
args::Tuple
27-
end
28-
29-
30-
function Base.showerror(io::IO, e::ExtensionMethodError)
31-
fname = String(nameof(e.fn))
32-
argtypes = typeof.(e.args)
33-
println(io,
34-
"ExtensionMethodError: no method matching " * fname
35-
* "(" * join(map(x-> "::"*String(nameof(x)),argtypes),',')
36-
* ")")
37-
println(io,"The function " * fname * " exists in a loaded extension,"
38-
*" but no method is defined for this combination of argument types.\n"
39-
* "\nCandidates are:\n"
40-
)
41-
println.(io, filter(x -> x != which(e.fn, (argtypes...,)), methods(e.fn)))
42-
return nothing
43-
end
44-
45-
function prepare_extension_function(fname::Symbol, weakdeps::Vector{Symbol}, args::Vector{Symbol})
46-
expr = quote
47-
function $fname($(args...); kwargs...)
48-
if mapreduce(x -> isdefined(Main, x) && isa(getfield(Main,x),Module), &, $weakdeps)
49-
throw(ExtensionMethodError($fname, ($(args...),)))
50-
else
51-
throw(ExtensionLoadError(nameof($fname), $weakdeps))
52-
end
53-
return nothing
54-
end
55-
end
56-
return eval(expr)
57-
end
58-
5910
"""
6011
$(TYPEDSIGNATURES)
6112
@@ -313,14 +264,10 @@ function simplexgrid(file::String, ::Type{Val{:sg}}; kwargs...)
313264
return g
314265
end
315266

316-
prepare_extension_function(:simplexgrid_from_gmsh, [:Gmsh], [:filename])
317-
# function simplexgrid_from_gmsh(filename; incomplete = false, Tc = Float32, Ti = Int32)
318-
# throw(ErrorException("Missing Gmsh extension. Add Gmsh.jl to your environment and import it to read msh or geo files."))
319-
# end
320-
267+
@extensionfunction simplexgrid_from_gmsh(filename;incomplete=false,Tc = Float32,Ti=Int32) Gmsh
321268

322269
function simplexgrid_to_gmsh end
323270

324-
function mixedgrid_from_gmsh end
271+
@extensionfunction mixedgrid_from_gmsh(filename;Tc = Float32, Ti = Int32)
325272

326273
function mixedgrid_to_gmsh end

0 commit comments

Comments
 (0)