Skip to content

Commit

Permalink
Done changes suggested in PR #266
Browse files Browse the repository at this point in the history
* Minor changes in CartesianDescriptor documentation
* Renamed UnstructuredGridTopology used for numbering a grid with periodic BC
to _cartesian_grid_topology_with_periodic_bcs.
* Moved above function (and related) to CartesianGrids.jl
  • Loading branch information
Jesus Bonilla committed May 26, 2020
1 parent 78c53e8 commit 1fb958b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 83 deletions.
4 changes: 2 additions & 2 deletions src/Geometry/CartesianDiscreteModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct CartesianDiscreteModel{D,T,F} <: DiscreteModel{D,D}
grid = CartesianGrid(desc)
_grid = UnstructuredGrid(grid)
if any(desc.isperiodic)
topo = UnstructuredGridTopology(_grid, desc.isperiodic, desc.partition)
topo = _cartesian_grid_topology_with_periodic_bcs(_grid, desc.isperiodic, desc.partition)
else
topo = UnstructuredGridTopology(_grid)
end
Expand Down Expand Up @@ -47,7 +47,7 @@ struct CartesianDiscreteModel{D,T,F} <: DiscreteModel{D,D}
subpartition = Tuple(cmax) .- Tuple(cmin) .+ 1
subsizes = desc.sizes
subdesc =
CartesianDescriptor(Point(suborigin), subsizes, subpartition; map=desc.map)
CartesianDescriptor(Point(suborigin), subsizes, subpartition; map=desc.map, isperiodic=desc.isperiodic)

grid = CartesianGrid(subdesc)
_grid = UnstructuredGrid(grid)
Expand Down
83 changes: 81 additions & 2 deletions src/Geometry/CartesianGrids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct CartesianDescriptor{D,T,F<:Function} <: GridapType
CartesianDescriptor(
origin::Point{D},
sizes::NTuple{D},
partition,
partition;
map::Function=identity,
isperiodic::NTuple{D,Bool}=tfill(false,Val{D})) where D
Expand Down Expand Up @@ -50,7 +50,7 @@ end
"""
CartesianDescriptor(
domain,
partition,
partition;
map::Function=identity,
isperiodic::NTuple{D,Bool}=tfill(false,Val{D}))
Expand Down Expand Up @@ -272,3 +272,82 @@ end
function get_cell_map(grid::CartesianGrid{D,T,typeof(identity)} where {D,T})
CartesianMap(grid.node_coords.data)
end

# Cartesian grid topology with periodic BC

function _cartesian_grid_topology_with_periodic_bcs(grid::UnstructuredGrid,
isperiodic::NTuple,
partition)

cell_to_vertices, vertex_to_node =
_generate_cell_to_vertices_from_grid(grid, isperiodic, partition)
_generate_grid_topology_from_grid(grid,cell_to_vertices,vertex_to_node)
end

function _generate_cell_to_vertices_from_grid(grid::UnstructuredGrid,
isperiodic::NTuple, partition)

if is_first_order(grid)
nodes = get_cell_nodes(grid)
cell_to_vertices = copy(nodes)

nnodes = num_nodes(grid)
num_nodes_x_dir = [partition[i]+1 for i in 1:length(partition)]
point_to_isperiodic, slave_point_to_point, slave_point_to_master_point =
_generate_slave_to_master_point(num_nodes_x_dir,isperiodic, nnodes)

vertex_to_point = findall( .! point_to_isperiodic)
point_to_vertex = fill(-1,length(point_to_isperiodic))
point_to_vertex[vertex_to_point] = 1:length(vertex_to_point)
point_to_vertex[slave_point_to_point] = point_to_vertex[slave_point_to_master_point]

cell_to_vertices = Table(LocalToGlobalArray(nodes,point_to_vertex))

vertex_to_node = vertex_to_point
node_to_vertex = point_to_vertex
else
@notimplemented
end
(cell_to_vertices,vertex_to_node, node_to_vertex)
end

function _generate_slave_to_master_point(num_nodes_x_dir::Vector{Int},
isperiodic::NTuple, num_nodes::Int)

point_to_isperiodic = fill(false,num_nodes)

slave_ijk_bounds = Array{Any,1}(undef,length(isperiodic))
master_ijk_bounds = Array{Any,1}(undef,length(isperiodic))

linear_indices = LinearIndices(Tuple(num_nodes_x_dir))
periodic_dirs = findall(x->x==true, isperiodic)
for periodic_dir in periodic_dirs
for i in 1:length(isperiodic)
if i == periodic_dir
slave_ijk_bounds[i] = num_nodes_x_dir[i]
else
slave_ijk_bounds[i] = 1:num_nodes_x_dir[i]
end
end
slave_ijk_set = CartesianIndices(Tuple(slave_ijk_bounds))
point_to_isperiodic[linear_indices[slave_ijk_set]] .= true
end

slave_point_to_point = findall( point_to_isperiodic)
slave_point_to_master_point = Array{Int,1}(undef,length(slave_point_to_point))

cartesian_indices = CartesianIndices(Tuple(num_nodes_x_dir))
for (i,point) in enumerate(slave_point_to_point)
ijk = collect(cartesian_indices[point].I)
for i in periodic_dirs
if ijk[i] == num_nodes_x_dir[i]
ijk[i] = 1
end
end

master_point_ijk = CartesianIndex(Tuple(ijk))
slave_point_to_master_point[i] = linear_indices[master_point_ijk]
end

point_to_isperiodic, slave_point_to_point, slave_point_to_master_point
end
80 changes: 1 addition & 79 deletions src/Geometry/UnstructuredGrids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct UnstructuredGrid{Dc,Dp,Tp,O} <: Grid{Dc,Dp}
end
end

"""
"""
UnstructuredGrid(trian::Grid)
"""
function UnstructuredGrid(trian::Grid)
Expand Down Expand Up @@ -167,15 +167,6 @@ function UnstructuredGridTopology(grid::UnstructuredGrid)
_generate_grid_topology_from_grid(grid,cell_to_vertices,vertex_to_node)
end

function UnstructuredGridTopology(grid::UnstructuredGrid,
isperiodic::NTuple,
partition)

cell_to_vertices, vertex_to_node =
_generate_cell_to_vertices_from_grid(grid, isperiodic, partition)
_generate_grid_topology_from_grid(grid,cell_to_vertices,vertex_to_node)
end

function UnstructuredGridTopology(grid::UnstructuredGrid, cell_to_vertices::Table, vertex_to_node::AbstractVector)
_generate_grid_topology_from_grid(grid,cell_to_vertices,vertex_to_node)
end
Expand Down Expand Up @@ -222,74 +213,6 @@ function _generate_cell_to_vertices_from_grid(grid::UnstructuredGrid)
(cell_to_vertices, vertex_to_node, node_to_vertex)
end

function _generate_cell_to_vertices_from_grid(grid::UnstructuredGrid,
isperiodic::NTuple, partition)

if is_first_order(grid)
nodes = get_cell_nodes(grid)
cell_to_vertices = copy(nodes)

nnodes = num_nodes(grid)
num_nodes_x_dir = [partition[i]+1 for i in 1:length(partition)]
point_to_isperiodic, slave_point_to_point, slave_point_to_master_point =
_generate_slave_to_master_point(num_nodes_x_dir,isperiodic, nnodes)

vertex_to_point = findall( .! point_to_isperiodic)
point_to_vertex = fill(-1,length(point_to_isperiodic))
point_to_vertex[vertex_to_point] = 1:length(vertex_to_point)
point_to_vertex[slave_point_to_point] = point_to_vertex[slave_point_to_master_point]

cell_to_vertices = Table(LocalToGlobalArray(nodes,point_to_vertex))

vertex_to_node = vertex_to_point
node_to_vertex = point_to_vertex
else
@notimplemented
end
(cell_to_vertices,vertex_to_node, node_to_vertex)
end

function _generate_slave_to_master_point(num_nodes_x_dir::Vector{Int},
isperiodic::NTuple, num_nodes::Int)

point_to_isperiodic = fill(false,num_nodes)

slave_ijk_bounds = Array{Any,1}(undef,length(isperiodic))
master_ijk_bounds = Array{Any,1}(undef,length(isperiodic))

linear_indices = LinearIndices(Tuple(num_nodes_x_dir))
periodic_dirs = findall(x->x==true, isperiodic)
for periodic_dir in periodic_dirs
for i in 1:length(isperiodic)
if i == periodic_dir
slave_ijk_bounds[i] = num_nodes_x_dir[i]
else
slave_ijk_bounds[i] = 1:num_nodes_x_dir[i]
end
end
slave_ijk_set = CartesianIndices(Tuple(slave_ijk_bounds))
point_to_isperiodic[linear_indices[slave_ijk_set]] .= true
end

slave_point_to_point = findall( point_to_isperiodic)
slave_point_to_master_point = Array{Int,1}(undef,length(slave_point_to_point))

cartesian_indices = CartesianIndices(Tuple(num_nodes_x_dir))
for (i,point) in enumerate(slave_point_to_point)
ijk = collect(cartesian_indices[point].I)
for i in periodic_dirs
if ijk[i] == num_nodes_x_dir[i]
ijk[i] = 1
end
end

master_point_ijk = CartesianIndex(Tuple(ijk))
slave_point_to_master_point[i] = linear_indices[master_point_ijk]
end

point_to_isperiodic, slave_point_to_point, slave_point_to_master_point
end


function _generate_cell_to_vertices(
cell_to_nodes::Table,
Expand Down Expand Up @@ -419,4 +342,3 @@ function _refine_grid_connectivity(cell_to_points::Table, ltcell_to_lpoints)
ltcell_to_lpoints)
Table(data,ptrs)
end

0 comments on commit 1fb958b

Please sign in to comment.