Skip to content

Commit

Permalink
add mesh validation function
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrKryslUCSD committed May 26, 2024
1 parent d8bf110 commit d5215fb
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FinEtools"
uuid = "91bb5406-6c9a-523d-811d-0644c4229550"
authors = ["Petr Krysl <[email protected]>"]
version = "8.0.22"
version = "8.0.23"

[deps]
DataDrop = "aa547a04-dd37-49ab-8e73-656744f8a8fc"
Expand Down
6 changes: 4 additions & 2 deletions src/FinEtools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ using .MeshModificationModule:
distortblock,
outer_surface_of_solid,
reordermesh,
element_coloring
element_coloring,
validate_mesh
# Exported: extraction of boundary, fusing of nodes and merging of meshes, mesh smoothing, node partitioning
export meshboundary,
fusenodes,
Expand All @@ -323,7 +324,8 @@ export meshboundary,
distortblock,
outer_surface_of_solid,
reordermesh,
element_coloring
element_coloring,
validate_mesh

using .MeshImportModule: import_NASTRAN, import_ABAQUS, import_MESH, import_H5MESH
# Exported: mesh import functions
Expand Down
45 changes: 44 additions & 1 deletion src/MeshModificationModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ..FESetModule:
subset
import ..FENodeSetModule: FENodeSet
import ..BoxModule: boundingbox, inflatebox!, intersectboxes, inbox
import ..MeshSelectionModule: connectednodes, selectelem
import ..MeshSelectionModule: connectednodes, selectelem, findunconnnodes
import ..SurfaceNormalModule: SurfaceNormal, updatenormal!
using Base.Sort
using Base.Order
Expand Down Expand Up @@ -1357,4 +1357,47 @@ function element_coloring!(element_colors, unique_colors, color_counts, fes, n2e
return element_colors, unique_colors, color_counts
end

"""
validate_mesh(fens, fes)
Validate the given mesh by checking if it satisfies certain sanity criteria.
# Arguments
- `fens`: The finite element nodes of the mesh.
- `fes`: The finite elements of the mesh.
Validate finite element mesh.
A finite element mesh given by the node set and the finite element set is
validated by checking the sanity of the numbering:
- the node numbers need to be positive and in serial order
- the fe connectivity needs to refer to valid nodes
- the finite element nodes need to be connected to at least one finite element
An error is reported as soon as it is detected.
# Returns
A boolean indicating whether the mesh is valid or not.
"""
function validate_mesh(fens, fes)
totnfens = count(fens)
for i in eachindex(fes)
if (max(fes.conn[i]...) > totnfens)
error("Wrong connectivity (refers to nonexistent node): $(fes.conn[i])")
end
if (min(fes.conn[i]...) < 1)
error("Wrong connectivity (refers to nonexistent node): $(fes.conn[i])")
end
if (length(unique(fes.conn[i])) != length(fes.conn[i]))
error("Wrong connectivity (multiply referenced node): $(fes.conn[i])")
end
end
connected = findunconnnodes(fens, fes)
if (any(connected == 0))
error("Unconnected nodes present: $(sum(connected==0)) total")
end
return true
end


end # module
22 changes: 21 additions & 1 deletion test/test_basics.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
module mval001
using Test
using FinEtools
function test()
fens = FENodeSet(rand(5, 2))
fes = FESetT3([1 2 6; 3 4 5])
@test_throws ErrorException validate_mesh(fens, fes)
fes = FESetT3([1 2 6; -1 4 5])
@test_throws ErrorException validate_mesh(fens, fes)
fes = FESetT3([1 2 3; 0 4 5])
@test_throws ErrorException validate_mesh(fens, fes)
fes = FESetT3([1 2 3; 0 4 5])
@test_throws ErrorException validate_mesh(fens, fes)
fes = FESetT3([1 2 3; 2 4 5])
@test validate_mesh(fens, fes)
true
end
test()
nothing
end

module mbas113
using FinEtools
using Test
Expand Down Expand Up @@ -3015,4 +3036,3 @@ end
test()
nothing
end

2 comments on commit d5215fb

@PetrKryslUCSD
Copy link
Owner 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/107671

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 v8.0.23 -m "<description of version>" d5215fbed3ce177570430da7eef4be464e5382f1
git push origin v8.0.23

Please sign in to comment.