Skip to content

Commit

Permalink
import/export with labels
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrKryslUCSD committed Dec 7, 2020
1 parent 0095e4c commit 001b3f4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The package supports application packages, for instance:

## News

- 12/07/2020: Export of meshes in the .mesh format with the labels enabled.
- 08/02/2020: Enabled permuting of nodes in the field.
- 02/29/2020: Many new tests added. Code coverage enabled.
- 01/23/2020: Dependencies have been updated to work with Julia 1.3.1.
Expand Down
19 changes: 16 additions & 3 deletions src/MeshExportModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1273,15 +1273,28 @@ MESHtypemap = Dict{DataType, String}(FESetP1=>"P1", FESetL2=>"L2", FESetT3=>"T3"
function write_MESH(meshfile::String, fens::FENodeSet, fes::T) where {T<:AbstractFESet}
meshfilebase, ext = splitext(meshfile)
dinfo = [
meshfilebase * "-xyz.dat",
MESHtypemap[typeof(fes)],
meshfilebase * "-conn.dat"]
meshfilebase * "-xyz.dat",
MESHtypemap[typeof(fes)],
meshfilebase * "-conn.dat",
]
# write out a file with the coordinates of the nodes
open(dinfo[1], "w") do file
writedlm(file, fens.xyz, ' ')
end
# write out a file with the connectivity
open(dinfo[3], "w") do file
writedlm(file, connasarray(fes), ' ')
end
# if any label is different from the default (0), write out the labels
if any(i -> i != 0, fes.label)
push!(dinfo, meshfilebase * "-label.dat")
# write out a file with the labels
open(dinfo[4], "w") do file
writedlm(file, fes.label, ' ')
end
end

# write out a file with the metadata
open(meshfilebase * ".mesh", "w") do file
writedlm(file, dinfo)
end
Expand Down
10 changes: 9 additions & 1 deletion src/MeshImportModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ function import_MESH(filename)
X = open(Xfile, "r") do file
readdlm(file, ' ', Float64)
end
# RAW: should be able to handle multiple element sets.
# The second line is the name of the element name tag.
etype = datinfo[2]
Cfile = isfile(datinfo[3]) ? datinfo[3] : joinpath(meshfiledir, datinfo[3])
Expand Down Expand Up @@ -479,6 +478,15 @@ function import_MESH(filename)
push!(warnings, "Don't know how to handle " * etype)
fes = nothing
end

# Is an optional label file present?
if length(datinfo) >= 4
labelfile = isfile(datinfo[4]) ? datinfo[4] : joinpath(meshfiledir, datinfo[4])
lab = open(labelfile, "r") do file
readdlm(file, ' ', Int64)
end
setlabel!(fes, vec(lab))
end

output = FDataDict("fens"=>fens, "fesets"=>[fes], "warnings"=>warnings)
return output
Expand Down
34 changes: 34 additions & 0 deletions test/test_meshing.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
module mexpmeshx1ba3
using FinEtools
using FinEtools.MeshExportModule: MESH, MESH.write_MESH
using FinEtools.MeshImportModule
using LinearAlgebra: norm
using Test
function test()
rho=1.21*1e-9;# mass density
c =345.0*1000;# millimeters per second
bulk= c^2*rho;
Lx=1900.0;# length of the box, millimeters
Ly=800.0; # length of the box, millimeters

fens, fes = Q4block(Lx,Ly,4,2); # Mesh
setlabel!(fes, 3)

write_MESH("q4-4-2", fens, fes)

output = MeshImportModule.import_MESH("q4-4-2.mesh")
@test count(output["fens"]) == count(fens)
@test count(output["fesets"][1]) == count(fes)
@test norm(output["fesets"][1].label - fes.label) == 0

try rm("q4-4-2-conn.dat") catch end
try rm("q4-4-2-label.dat") catch end
try rm("q4-4-2-xyz.dat") catch end
try rm("q4-4-2.mesh") catch end
true
end
end
using .mexpmeshx1ba3
mexpmeshx1ba3.test()

# module mimptm2
# using FinEtools
Expand Down Expand Up @@ -4785,6 +4817,7 @@ function test()

File = "mef2nf2para12-coarse-nf-smoothed.vtk"
VTK.vtkexportmesh(File, fens, fes; scalars = [("nf", nf.values)])
try rm(File) catch end
File = "mef2nf2para12-coarse-ef-smoothed.vtk"
VTK.vtkexportmesh(File, fens, fes; scalars = [("ef", ef.values)])
try rm(File) catch end
Expand Down Expand Up @@ -5152,6 +5185,7 @@ function test()

File = "mef2nf2maxa12-coarse-nf-smoothed.vtk"
VTK.vtkexportmesh(File, fens, fes; scalars = [("nf", nf.values)])
try rm(File) catch end
File = "mef2nf2maxa12-coarse-ef-smoothed.vtk"
VTK.vtkexportmesh(File, fens, fes; scalars = [("ef", ef.values)])
try rm(File) catch end
Expand Down

0 comments on commit 001b3f4

Please sign in to comment.