Skip to content

Commit 959c38c

Browse files
authored
Merge pull request #95 from WIAS-PDELib/feature/trim
Add trim! function
2 parents 34f21d5 + 569daef commit 959c38c

5 files changed

Lines changed: 166 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## unreleased
3+
4+
- add `trim!`/`trim` function to remove precomputed grid components for lightweight storage
5+
26
## [1.13.2] - 2025-06-22
37
- Allow Triangulate v3
48

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ExtendableGrids"
22
uuid = "cfc395e8-590f-11e8-1f13-43a2532b2fa8"
33
authors = ["Juergen Fuhrmann <juergen.fuhrmann@wias-berlin.de>", "Christian Merdon <christian.merdon@wias-berlin.de>", "Johannes Taraz <johannes.taraz@gmail.com>", "Patrick Jaap <patrick.jaap@wias-berlin.de>"]
4-
version = "1.13.2"
4+
version = "1.14.0"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/ExtendableGrids.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export num_cellregions, num_bfaceregions, num_bedgeregions
7878
export gridcomponents
7979
export isconsistent, dangling_nodes
8080
export seemingly_equal, numbers_match
81+
export trim!, trim
8182

8283
include("partitioning.jl")
8384
export PColorPartitions, PartitionCells, PartitionBFaces, PartitionNodes, NodePermutation, PartitionEdges

src/extendablegrid.jl

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,90 @@ function bbox(grid)
712712
e = extrema(grid)
713713
return map(a -> a[1], e), map(a -> a[2], e)
714714
end
715+
716+
717+
"""
718+
$(SIGNATURES)
719+
720+
Remove precomputed grid components for lightweight storage of the grid.
721+
722+
Use the `keep` list to exclude grid components from trimming.
723+
"""
724+
function trim!(grid::ExtendableGrid; keep = [])
725+
726+
components_for_trimming = [
727+
BEdgeAssemblyGroups,
728+
BEdgeEdges,
729+
BEdgeGeometries,
730+
BEdgeNodes,
731+
BEdgeRegions,
732+
BEdgeVolumes,
733+
BFaceAssemblyGroups,
734+
BFaceCellPos,
735+
BFaceCells,
736+
BFaceEdges,
737+
BFaceFaces,
738+
BFaceNormals,
739+
BFaceVolumes,
740+
CellAssemblyGroups,
741+
CellEdges,
742+
CellEdgeSigns,
743+
CellFaceOrientations,
744+
CellFaces,
745+
CellFaceSigns,
746+
CellVolumes,
747+
EdgeAssemblyGroups,
748+
EdgeCells,
749+
EdgeGeometries,
750+
EdgeNodes,
751+
EdgeRegions,
752+
EdgeTangents,
753+
EdgeVolumes,
754+
FaceAssemblyGroups,
755+
FaceCells,
756+
FaceEdges,
757+
FaceEdgeSigns,
758+
FaceGeometries,
759+
FaceNodes,
760+
FaceNormals,
761+
FaceRegions,
762+
FaceVolumes,
763+
NodeCells,
764+
NodeEdges,
765+
NodeFaces,
766+
NodePatchGroups,
767+
NumBEdgeRegions,
768+
NumBFaceRegions,
769+
NumCellRegions,
770+
UniqueBEdgeGeometries,
771+
UniqueBFaceGeometries,
772+
UniqueCellGeometries,
773+
UniqueEdgeGeometries,
774+
UniqueFaceGeometries,
775+
]
776+
777+
# filter out kept components
778+
filter!(!in(keep), components_for_trimming)
779+
780+
for component in components_for_trimming
781+
delete!(grid, component)
782+
end
783+
784+
return nothing
785+
end
786+
787+
788+
"""
789+
$(SIGNATURES)
790+
791+
Variant of [`trim!`](@ref) without modification of the original grid.
792+
793+
Returns a trimmed copy of the grid.
794+
"""
795+
function trim(grid::ExtendableGrid; keep = [])
796+
797+
grid_copy = deepcopy(grid)
798+
trim!(grid_copy; keep)
799+
800+
return grid_copy
801+
end

test/runtests.jl

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,76 @@ if VERSION < v"1.12.0-DEV.0"
491491
@testscripts(joinpath(@__DIR__, "..", "examples"), notebooks)
492492
end
493493
end
494+
495+
496+
@testset "trim!" begin
497+
498+
grid = grid_unitcube(Tetrahedron3D)
499+
500+
component_list = [
501+
BEdgeAssemblyGroups,
502+
BEdgeEdges,
503+
BEdgeGeometries,
504+
BEdgeNodes,
505+
BEdgeRegions,
506+
BEdgeVolumes,
507+
BFaceAssemblyGroups,
508+
BFaceCellPos,
509+
BFaceCells,
510+
BFaceEdges,
511+
BFaceFaces,
512+
BFaceNormals,
513+
BFaceVolumes,
514+
CellAssemblyGroups,
515+
CellEdges,
516+
CellEdgeSigns,
517+
CellFaceOrientations,
518+
CellFaces,
519+
CellFaceSigns,
520+
CellVolumes,
521+
EdgeAssemblyGroups,
522+
EdgeCells,
523+
EdgeGeometries,
524+
EdgeNodes,
525+
EdgeRegions,
526+
EdgeTangents,
527+
EdgeVolumes,
528+
FaceAssemblyGroups,
529+
FaceCells,
530+
FaceEdges,
531+
FaceEdgeSigns,
532+
FaceGeometries,
533+
FaceNodes,
534+
FaceNormals,
535+
FaceRegions,
536+
FaceVolumes,
537+
NodeCells,
538+
NodeEdges,
539+
NodeFaces,
540+
NodePatchGroups,
541+
NumBEdgeRegions,
542+
NumBFaceRegions,
543+
NumCellRegions,
544+
UniqueBEdgeGeometries,
545+
UniqueBFaceGeometries,
546+
UniqueCellGeometries,
547+
UniqueEdgeGeometries,
548+
UniqueFaceGeometries,
549+
]
550+
551+
# init components
552+
for c in component_list
553+
grid[c]
554+
end
555+
556+
# trim all components, except a few
557+
grid = ExtendableGrids.trim(grid, keep = [BFaceNormals, NodeCells])
558+
559+
@test haskey(grid, BFaceNormals)
560+
@test haskey(grid, NodeCells)
561+
562+
# trim everything
563+
grid = ExtendableGrids.trim(grid)
564+
565+
@test all([!haskey(grid, c) for c in component_list])
566+
end

0 commit comments

Comments
 (0)