Skip to content

Commit da005cf

Browse files
committed
Bugfix in Cartesian model with periodic BCs
This bug shows up in Julia 1.6 but not in 1.5
1 parent fc1e357 commit da005cf

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/Geometry/CartesianDiscreteModels.jl

+13-21
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ function _cartesian_grid_topology_with_periodic_bcs(grid::UnstructuredGrid,
408408
isperiodic::NTuple,
409409
partition)
410410

411-
cell_to_vertices, vertex_to_node =
411+
cell_to_vertices, vertex_to_node, =
412412
_generate_cell_to_vertices_from_grid(grid, isperiodic, partition)
413413
_generate_grid_topology_from_grid(grid,cell_to_vertices,vertex_to_node)
414414
end
@@ -418,8 +418,6 @@ function _generate_cell_to_vertices_from_grid(grid::UnstructuredGrid,
418418

419419
if is_first_order(grid)
420420
nodes = get_cell_node_ids(grid)
421-
cell_to_vertices = copy(nodes)
422-
423421
nnodes = num_nodes(grid)
424422
num_nodes_x_dir = [partition[i]+1 for i in 1:length(partition)]
425423
point_to_isperiodic, slave_point_to_point, slave_point_to_master_point =
@@ -443,37 +441,31 @@ end
443441
function _generate_slave_to_master_point(num_nodes_x_dir::Vector{Int},
444442
isperiodic::NTuple, num_nodes::Int)
445443

446-
point_to_isperiodic = fill(false,num_nodes)
447-
448-
slave_ijk_bounds = Array{Any,1}(undef,length(isperiodic))
449-
master_ijk_bounds = Array{Any,1}(undef,length(isperiodic))
450-
451-
linear_indices = LinearIndices(Tuple(num_nodes_x_dir))
452444
periodic_dirs = findall(x->x==true, isperiodic)
453-
for periodic_dir in periodic_dirs
454-
for i in 1:length(isperiodic)
455-
if i == periodic_dir
456-
slave_ijk_bounds[i] = num_nodes_x_dir[i]
457-
else
458-
slave_ijk_bounds[i] = 1:num_nodes_x_dir[i]
445+
linear_indices = LinearIndices(Tuple(num_nodes_x_dir))
446+
cartesian_indices = CartesianIndices(Tuple(num_nodes_x_dir))
447+
448+
point_to_isperiodic = fill(false,num_nodes)
449+
for point in 1:length(point_to_isperiodic)
450+
ci = Tuple(cartesian_indices[point])
451+
for dir in periodic_dirs
452+
if ci[dir] == num_nodes_x_dir[dir]
453+
point_to_isperiodic[point] = true
459454
end
460455
end
461-
slave_ijk_set = CartesianIndices(Tuple(slave_ijk_bounds))
462-
point_to_isperiodic[linear_indices[slave_ijk_set]] .= true
463456
end
464457

465-
slave_point_to_point = findall( point_to_isperiodic)
458+
slave_point_to_point = findall(point_to_isperiodic)
466459
slave_point_to_master_point = Array{Int32,1}(undef,length(slave_point_to_point))
467460

468-
cartesian_indices = CartesianIndices(Tuple(num_nodes_x_dir))
461+
ijk = zeros(Int,length(isperiodic))
469462
for (i,point) in enumerate(slave_point_to_point)
470-
ijk = collect(cartesian_indices[point].I)
463+
ijk .= Tuple(cartesian_indices[point])
471464
for i in periodic_dirs
472465
if ijk[i] == num_nodes_x_dir[i]
473466
ijk[i] = 1
474467
end
475468
end
476-
477469
master_point_ijk = CartesianIndex(Tuple(ijk))
478470
slave_point_to_master_point[i] = linear_indices[master_point_ijk]
479471
end

0 commit comments

Comments
 (0)