From 8dabd709f5bc6fecb4b490dc2b7bbc6bf8e0d0bb Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Tue, 18 Jun 2024 16:32:10 +0200 Subject: [PATCH 1/5] extended subgrid method --- src/ExtendableGrids.jl | 5 +++-- src/derived.jl | 38 +-------------------------------- src/subgrid.jl | 48 +++++++++++++++++++++++++++--------------- 3 files changed, 35 insertions(+), 56 deletions(-) diff --git a/src/ExtendableGrids.jl b/src/ExtendableGrids.jl index 2c051efb..004e9774 100644 --- a/src/ExtendableGrids.jl +++ b/src/ExtendableGrids.jl @@ -88,8 +88,8 @@ export AbstractPartitioningAlgorithm, TrivialPartitioning, PlainMetisPartitionin include("subgrid.jl") export subgrid export ParentGrid -export NodeParents, CellParents, FaceParents, BFaceParents -export ParentGridRelation, SubGrid, BoundarySubGrid, RefinedGrid +export NodeParents, CellParents, FaceParents, BFaceParents, EdgeParents, BEdgeParents +export ParentGridRelation, SubGrid, RefinedGrid include("shape_specs.jl") export refcoords_for_geometry @@ -99,6 +99,7 @@ export num_edges export local_cellfacenodes export local_celledgenodes export facetype_of_cellface +export Volume4ElemType export Normal4ElemType! export Tangent4ElemType! export xrefFACE2xrefCELL diff --git a/src/derived.jl b/src/derived.jl index 644c5eab..117e3cd7 100644 --- a/src/derived.jl +++ b/src/derived.jl @@ -125,42 +125,6 @@ GridComponent4TypeProperty(::Type{ITEMTYPE_BEDGE},::Type{PROPERTY_GEOMETRY}) = B GridComponent4TypeProperty(::Type{ITEMTYPE_BEDGE},::Type{PROPERTY_UNIQUEGEOMETRY}) = UniqueBEdgeGeometries GridComponent4TypeProperty(::Type{ITEMTYPE_BEDGE},::Type{PROPERTY_ASSEMBLYGROUP}) = BEdgeAssemblyGroups - -function get_facegrid(source_grid::ExtendableGrid{Tc,Ti}) where {Tc,Ti} - facegrid=ExtendableGrid{Tc,Ti}() - facegrid[Coordinates]=source_grid[Coordinates] - facegrid[CellNodes]=source_grid[FaceNodes] - facegrid[CoordinateSystem]=source_grid[CoordinateSystem] - facegrid[CellGeometries]=source_grid[FaceGeometries] - facegrid[UniqueCellGeometries]=source_grid[UniqueFaceGeometries] - facegrid[CellRegions] = source_grid[FaceRegions] - # todo: facegrid[CellFaces] = source_grid[FaceEdges] - return facegrid -end - -function get_bfacegrid(source_grid::ExtendableGrid{Tc,Ti}) where {Tc,Ti} - bfacegrid=ExtendableGrid{Tc,Ti}() - bfacegrid[Coordinates]=source_grid[Coordinates] - bfacegrid[CellNodes]=source_grid[BFaceNodes] - bfacegrid[CoordinateSystem]=source_grid[CoordinateSystem] - bfacegrid[CellGeometries]=source_grid[BFaceGeometries] - bfacegrid[UniqueCellGeometries]=source_grid[UniqueBFaceGeometries] - bfacegrid[CellRegions] = source_grid[BFaceRegions] - # todo: bfacegrid[CellFaces] = source_grid[BFaceEdges] (or sub-view of FaceEdges ?) - return bfacegrid -end - -function get_edgegrid(source_grid::ExtendableGrid{Tc,Ti}) where {Tc,Ti} - edgegrid=ExtendableGrid{Tc,Ti}() - edgegrid[Coordinates]=source_grid[Coordinates] - edgegrid[CellNodes]=source_grid[EdgeNodes] - edgegrid[CoordinateSystem]=source_grid[CoordinateSystem] - edgegrid[CellGeometries]=source_grid[EdgeGeometries] - edgegrid[UniqueCellGeometries]=source_grid[UniqueedgeGeometries] - edgegrid[CellRegions] = source_grid[EdgeRegions] - return edgegrid -end - # show function for ExtendableGrids and defined Components in its Dict function showmore(io::IO, xgrid::ExtendableGrid{Tc,Ti}) where {Tc,Ti} @@ -198,7 +162,7 @@ end function ExtendableGrids.instantiate(xgrid::ExtendableGrid{Tc,Ti}, ::Type{FaceNodes}) where {Tc,Ti} if haskey(xgrid, ParentGrid) && haskey(xgrid, ParentGridRelation) - if xgrid[ParentGridRelation] === SubGrid + if xgrid[ParentGridRelation] <: SubGrid{ON_CELLS} ## get FaceNodes from ParentGrid to keep ordering and orientation pgrid = xgrid[ParentGrid] pnodes = xgrid[NodeParents] diff --git a/src/subgrid.jl b/src/subgrid.jl index 24112ef9..ed85f3b5 100644 --- a/src/subgrid.jl +++ b/src/subgrid.jl @@ -46,21 +46,26 @@ $(TYPEDEF) Grid component key type for indicating that grid is a subgrid of the parentgrid """ -abstract type SubGrid <: ParentGridRelation end +abstract type SubGrid{based} <: ParentGridRelation where {based <: AssemblyType} end """ $(TYPEDEF) -Grid component key type for indicating that grid is a boundary subgrid of the parentgrid +Grid component key type for indicating that grid is a refinement of the parentgrid """ -abstract type BoundarySubGrid <: ParentGridRelation end +abstract type RefinedGrid <: ParentGridRelation end + """ -$(TYPEDEF) +$(TYPEDSIGNATURES) -Grid component key type for indicating that grid is a refinement of the parentgrid +Default transform for subgrid creation """ -abstract type RefinedGrid <: ParentGridRelation end +function _copytransform!(a::AbstractArray,b::AbstractArray) + for i=1:length(a) + a[i]=b[i] + end +end struct XIPair{Tv, Ti} x::Tv @@ -71,7 +76,6 @@ end Base.isless(x::XIPair, y::XIPair) = (x.x < y.x) - """ subgrid(parent, subregions::AbstractArray; @@ -84,7 +88,8 @@ Create subgrid from list of regions. - `parent`: parent grid - `subregions`: Array of subregions which define the subgrid -- `boundary`: if true, create codimension 1 subgrid from boundary regions. +- 'support': support of subgrid, default is ON_CELLS but can be also ON_FACES or ON_BFACES to create codimension 1 subgrid from face/bfaces region +- `boundary`: if true, create codimension 1 subgrid from boundary regions (same as support = ON_BFACES) - `transform` (kw parameter): transformation function between grid and subgrid coordinates acting on one point. - `coordinatesystem`: if `boundary==true`, specify coordinate system for the boundary. @@ -100,9 +105,16 @@ function subgrid(parent, subregions::AbstractArray; transform::T=function(a,b) @views a.=b[1:length(a)] end, boundary=false, + support=ON_CELLS, coordinatesystem=codim1_coordinatesystem(parent[CoordinateSystem]), project=true) where T + @assert support in [ON_CELLS, ON_FACES, ON_BFACES] "value ($based) for 'support' is not allowed" + + if boundary + support = ON_BFACES + end + Tc=coord_type(parent) Ti=index_type(parent) @@ -118,14 +130,19 @@ function subgrid(parent, return false end - - if boundary + if support == ON_BFACES xregions=parent[BFaceRegions] xnodes=parent[BFaceNodes] sub_gdim=dim_grid(parent)-1 xct=parent[BFaceGeometries] sub_gdim=dim_grid(parent)-1 - else + elseif support == ON_FACES + xregions=parent[FaceRegions] + xnodes=parent[FaceNodes] + sub_gdim=dim_grid(parent)-1 + xct=parent[FaceGeometries] + sub_gdim=dim_grid(parent)-1 + elseif support == ON_CELLS xregions=parent[CellRegions] xnodes=parent[CellNodes] xct=parent[CellGeometries] @@ -193,17 +210,14 @@ function subgrid(parent, subgrid[ParentGrid]=parent subgrid[NodeParents]=sub_nip subgrid[CellParents]=cellparents - subgrid[ParentGridRelation]=boundary ? BoundarySubGrid : SubGrid + subgrid[ParentGridRelation]=SubGrid{support} - if boundary + if support in [ON_BFACES, ON_FACES] subgrid[NumBFaceRegions]=0 subgrid[BFaceRegions]=Ti[] subgrid[BFaceGeometries]=ElementGeometries[] subgrid[BFaceNodes]=Matrix{Ti}(undef,sub_gdim,0) subgrid[NumBFaceRegions]=0 - if !isnothing(coordinatesystem) - subgrid[CoordinateSystem]=coordinatesystem - end else bfacenodes=parent[BFaceNodes] bfaceregions=parent[BFaceRegions] @@ -257,8 +271,8 @@ function subgrid(parent, subgrid[BFaceNodes]=zeros(Ti, 2, 0) subgrid[NumBFaceRegions]=0 end - subgrid[CoordinateSystem]=parent[CoordinateSystem] end + subgrid[CoordinateSystem]=parent[CoordinateSystem] if sub_gdim == 1 # Sort nodes of grid for easy plotting From 87c36c980be346cbaebf75a4d556cd91ab08dea2 Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Tue, 18 Jun 2024 16:35:24 +0200 Subject: [PATCH 2/5] removed export of removed functions --- src/ExtendableGrids.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ExtendableGrids.jl b/src/ExtendableGrids.jl index 004e9774..54aa8547 100644 --- a/src/ExtendableGrids.jl +++ b/src/ExtendableGrids.jl @@ -119,7 +119,6 @@ export CellAssemblyGroups, FaceAssemblyGroups, BFaceAssemblyGroups, EdgeAssembly export GridComponent4TypeProperty export ITEMTYPE_CELL, ITEMTYPE_FACE, ITEMTYPE_BFACE, ITEMTYPE_EDGE, ITEMTYPE_BEDGE export PROPERTY_NODES, PROPERTY_REGION, PROPERTY_VOLUME, PROPERTY_UNIQUEGEOMETRY, PROPERTY_GEOMETRY, PROPERTY_ASSEMBLYGROUP -export get_facegrid, get_bfacegrid, get_edgegrid export GridEGTypes export GridRegionTypes From 1e4741e7a06ab6e9590885db069e215e282610ca Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Tue, 18 Jun 2024 17:22:20 +0200 Subject: [PATCH 3/5] fixed some issues, test should run now --- src/ExtendableGrids.jl | 25 ++++++++++++------------- src/subgrid.jl | 5 ++++- test/runtests.jl | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/ExtendableGrids.jl b/src/ExtendableGrids.jl index 54aa8547..b5e5146f 100644 --- a/src/ExtendableGrids.jl +++ b/src/ExtendableGrids.jl @@ -85,10 +85,21 @@ export num_pcolors, num_partitions, pcolors, pcolor_partitions, partition_cells, export partition, num_partitions_per_color,check_partitioning export AbstractPartitioningAlgorithm, TrivialPartitioning, PlainMetisPartitioning +include("assemblytypes.jl") +export AssemblyType +export AT_NODES, ON_CELLS, ON_FACES, ON_IFACES, ON_BFACES, ON_EDGES, ON_BEDGES +export ItemType4AssemblyType +export GridComponentNodes4AssemblyType +export GridComponentVolumes4AssemblyType +export GridComponentGeometries4AssemblyType +export GridComponentRegions4AssemblyType +export GridComponentUniqueGeometries4AssemblyType +export GridComponentAssemblyGroups4AssemblyType + include("subgrid.jl") export subgrid export ParentGrid -export NodeParents, CellParents, FaceParents, BFaceParents, EdgeParents, BEdgeParents +export NodeParents, CellParents, FaceParents, BFaceParents export ParentGridRelation, SubGrid, RefinedGrid include("shape_specs.jl") @@ -99,7 +110,6 @@ export num_edges export local_cellfacenodes export local_celledgenodes export facetype_of_cellface -export Volume4ElemType export Normal4ElemType! export Tangent4ElemType! export xrefFACE2xrefCELL @@ -138,17 +148,6 @@ include("adaptive_meshrefinements.jl") export bulk_mark export RGB_refine -include("assemblytypes.jl") -export AssemblyType -export AT_NODES, ON_CELLS, ON_FACES, ON_IFACES, ON_BFACES, ON_EDGES, ON_BEDGES -export ItemType4AssemblyType -export GridComponentNodes4AssemblyType -export GridComponentVolumes4AssemblyType -export GridComponentGeometries4AssemblyType -export GridComponentRegions4AssemblyType -export GridComponentUniqueGeometries4AssemblyType -export GridComponentAssemblyGroups4AssemblyType - include("l2gtransformations.jl") export L2GTransformer, update_trafo!, eval_trafo!, mapderiv! diff --git a/src/subgrid.jl b/src/subgrid.jl index ed85f3b5..327ecf32 100644 --- a/src/subgrid.jl +++ b/src/subgrid.jl @@ -218,6 +218,9 @@ function subgrid(parent, subgrid[BFaceGeometries]=ElementGeometries[] subgrid[BFaceNodes]=Matrix{Ti}(undef,sub_gdim,0) subgrid[NumBFaceRegions]=0 + if !isnothing(coordinatesystem) + subgrid[CoordinateSystem]=coordinatesystem + end else bfacenodes=parent[BFaceNodes] bfaceregions=parent[BFaceRegions] @@ -271,8 +274,8 @@ function subgrid(parent, subgrid[BFaceNodes]=zeros(Ti, 2, 0) subgrid[NumBFaceRegions]=0 end + subgrid[CoordinateSystem]=parent[CoordinateSystem] end - subgrid[CoordinateSystem]=parent[CoordinateSystem] if sub_gdim == 1 # Sort nodes of grid for easy plotting diff --git a/test/runtests.jl b/test/runtests.jl index a9a43cd0..19ec7266 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -243,7 +243,7 @@ end grid = grid_unitsquare(Triangle2D) grid[CellRegions] = Int32[1,2,2,1] sgrid = subgrid(grid, [1]) - @test sgrid[ParentGridRelation] == SubGrid + @test sgrid[ParentGridRelation] == SubGrid{ON_CELLS} ## check if CellParents are assigned correctly @test sgrid[CellParents] == [1,4] From cca5a54c252c90d6ee9c5f67795f0b06cc7744d7 Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Tue, 18 Jun 2024 21:26:24 +0200 Subject: [PATCH 4/5] based -> support at two more spots --- src/subgrid.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/subgrid.jl b/src/subgrid.jl index 327ecf32..8ecf19f4 100644 --- a/src/subgrid.jl +++ b/src/subgrid.jl @@ -46,7 +46,7 @@ $(TYPEDEF) Grid component key type for indicating that grid is a subgrid of the parentgrid """ -abstract type SubGrid{based} <: ParentGridRelation where {based <: AssemblyType} end +abstract type SubGrid{support} <: ParentGridRelation where {support <: AssemblyType} end """ $(TYPEDEF) @@ -109,7 +109,7 @@ function subgrid(parent, coordinatesystem=codim1_coordinatesystem(parent[CoordinateSystem]), project=true) where T - @assert support in [ON_CELLS, ON_FACES, ON_BFACES] "value ($based) for 'support' is not allowed" + @assert support in [ON_CELLS, ON_FACES, ON_BFACES] "value ($support) for 'support' is not allowed" if boundary support = ON_BFACES From 2eabbea3bd84ab9915dd54ebc32fbea68b50b178 Mon Sep 17 00:00:00 2001 From: Christian Merdon Date: Wed, 19 Jun 2024 10:55:04 +0200 Subject: [PATCH 5/5] fixed default behaviour for coordinatesystem and restricted 1D coordinate sorting to project = true --- src/subgrid.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/subgrid.jl b/src/subgrid.jl index 8ecf19f4..30804383 100644 --- a/src/subgrid.jl +++ b/src/subgrid.jl @@ -106,8 +106,8 @@ function subgrid(parent, transform::T=function(a,b) @views a.=b[1:length(a)] end, boundary=false, support=ON_CELLS, - coordinatesystem=codim1_coordinatesystem(parent[CoordinateSystem]), - project=true) where T + project=true, + coordinatesystem=project ? codim1_coordinatesystem(parent[CoordinateSystem]) : parent[CoordinateSystem]) where T @assert support in [ON_CELLS, ON_FACES, ON_BFACES] "value ($support) for 'support' is not allowed" @@ -133,13 +133,11 @@ function subgrid(parent, if support == ON_BFACES xregions=parent[BFaceRegions] xnodes=parent[BFaceNodes] - sub_gdim=dim_grid(parent)-1 xct=parent[BFaceGeometries] sub_gdim=dim_grid(parent)-1 elseif support == ON_FACES xregions=parent[FaceRegions] xnodes=parent[FaceNodes] - sub_gdim=dim_grid(parent)-1 xct=parent[FaceGeometries] sub_gdim=dim_grid(parent)-1 elseif support == ON_CELLS @@ -277,7 +275,7 @@ function subgrid(parent, subgrid[CoordinateSystem]=parent[CoordinateSystem] end - if sub_gdim == 1 + if sub_gdim == 1 && project # Sort nodes of grid for easy plotting X=view(subgrid[Coordinates],1,:) nx=length(X)