From ef51e10a7f294407602049c2daf41df78f784351 Mon Sep 17 00:00:00 2001 From: Francesc Verdugo Date: Tue, 3 Oct 2023 14:36:41 +0200 Subject: [PATCH] Saving before refactoring --- src/GalerkinToolkit.jl | 140 ++++++++++++++++++++++++----------------- 1 file changed, 83 insertions(+), 57 deletions(-) diff --git a/src/GalerkinToolkit.jl b/src/GalerkinToolkit.jl index adeb93cd..ea4dcad2 100644 --- a/src/GalerkinToolkit.jl +++ b/src/GalerkinToolkit.jl @@ -85,6 +85,9 @@ lib_to_user_nodes(a) = a.lib_to_user_nodes interior_nodes(a) = a.interior_nodes face_permutation_ids(a) = a.face_permutation_ids face_permutation_ids(a,m,n) = face_permutation_ids(a)[m+1,n+1] +local_nodes(a) = a.local_nodes +local_node_colors(a) = a.local_node_colors + reference_faces(a,d) = reference_faces(a)[val_parameter(d)+1] face_nodes(a,d) = face_nodes(a)[val_parameter(d)+1] @@ -3155,7 +3158,7 @@ function partition_mesh_via_nodes(colorize,ranks,mesh) map(ranks,node_to_color) do rank,node_to_color onode_to_node = findall(color->color==rank,node_to_color) node_to_mask = fill(false,nnodes) - face_partition_mesh = map(face_nodes_mesh,node_faces_mesh) do face_to_nodes, node_to_faces + local_faces = map(face_nodes_mesh,node_faces_mesh) do face_to_nodes, node_to_faces nfaces = length(face_to_nodes) face_to_mask = fill(false,nfaces) for node in onode_to_node @@ -3175,8 +3178,11 @@ function partition_mesh_via_nodes(colorize,ranks,mesh) LocalIndices(nfaces,rank,lface_to_face,lface_to_color) end lnode_to_node = findall(node_to_mask) - lface_to_face_mesh = map(local_to_global,face_partition_mesh) - restrict_mesh(mesh,lnode_to_node,lface_to_face_mesh) + lnode_to_color = node_to_color[lnode_to_node] + local_nodes = LocalIndices(nnodes,rank,lnode_to_node,lnode_to_color) + lface_to_face_mesh = map(local_to_global,local_faces) + lmesh = restrict_mesh(mesh,lnode_to_node,lface_to_face_mesh) + setproperties(lmesh;local_nodes,local_faces) end end @@ -3197,7 +3203,7 @@ function partition_mesh_via_cells(colorize,ranks,mesh) colors end cell_to_color = emit(colors_root;source=root) - map(ranks,cell_to_color) do rank,cell_to_color + pmesh = map(ranks,cell_to_color) do rank,cell_to_color ocell_to_cell = findall(color->color==rank,cell_to_color) node_to_mask = fill(false,nnodes) for cell in ocell_to_cell @@ -3232,60 +3238,80 @@ function partition_mesh_via_cells(colorize,ranks,mesh) local_nodes = LocalIndices(nnodes,rank,lnode_to_node,lnode_to_owner) setproperties(lmesh;local_nodes,local_node_colors=lnode_to_colors) end -end + pmesh +end + +function coarse_objects_from_pmesh(pmesh) + ranks = linear_indices(pmesh) + lnode_to_colors = map(local_node_colors,pmesh) + node_partition = map(local_nodes,pmesh) + clnode_to_lnodes, clnode_to_owner, nown, clnode_to_type = map(ranks,lnode_to_colors) do rank,lnode_to_colors + interface_node_to_lnode = findall(colors->length(colors)!=1,lnode_to_colors) + interface_node_to_colors = view(lnode_to_colors,interface_node_to_lnode) + # assumes sorted colors + clnode_to_colors = unique(interface_node_to_colors) + nclnodes = length(clnode_to_colors) + interface_node_to_clnode = indexin(interface_node_to_colors,clnode_to_colors) + clnode_to_interface_nodes = inverse_index_map(interface_node_to_clnode,nclnodes) + f = interface_node->interface_node_to_lnode[interface_node] + clnode_to_interface_nodes.data .= f.(clnode_to_interface_nodes.data) + my_clnode_to_lnodes = clnode_to_interface_nodes + my_clnode_to_owner = map(maximum,clnode_to_colors) + CORNER = 0 + EDGE = 1 + FACE = 2 + my_clnode_to_type = fill(EDGE,nclnodes) + my_clnode_to_type[ map(i->length(i) == 2,clnode_to_colors) ] .= FACE + my_clnode_to_type[ map(i->length(i) == 1,my_clnode_to_lnodes) ] .= CORNER + my_nown = count(owner->owner==rank,my_clnode_to_owner) + my_clnode_to_lnodes, my_clnode_to_owner, my_nown, my_clnode_to_type + end |> tuple_of_arrays + ncnodes = sum(nown) + cnode_partition = variable_partition(nown,ncnodes) + v = PVector{Vector{Int}}(undef,node_partition) + map(ranks,cnode_partition,clnode_to_owner,clnode_to_lnodes,local_values(v)) do rank, conodes, clnode_to_owner, clnode_to_lnodes, lnode_to_v + conode_to_cnode = own_to_global(conodes) + conode = 0 + for (clnode,owner) in enumerate(clnode_to_owner) + if owner != rank + continue + end + conode += 1 + cnode = conode_to_cnode[conode] + lnodes = clnode_to_lnodes[clnode] + lnode_to_v[lnodes] .= cnode + end + end + consistent!(v) |> wait + clnode_to_cnode = map(ranks,clnode_to_lnodes,local_values(v)) do rank, clnode_to_lnodes, lnode_to_v + nclnodes = length(clnode_to_lnodes) + my_clnode_to_cnode = zeros(Int,nclnodes) + for clnode in 1:nclnodes + lnodes = clnode_to_lnodes[clnode] + cnode = lnode_to_v[first(lnodes)] + my_clnode_to_cnode[clnode] = cnode + end + my_clnode_to_cnode + end + rank_to_cnodes = gather(clnode_to_cnode,destination=MAIN) + rank_to_types = gather(clnode_to_type,destination=MAIN) + cnode_to_type = map(rank_to_types,rank_to_cnodes,ranks) do rank_clnode_to_type,rank_clnode_to_cnode,rank + if rank == MAIN + my_cnode_to_type = fill(Int(INVALID_ID),ncnodes) + for part in length(rank_clnode_to_type) + my_cnode_to_type[rank_clnode_to_cnode[part]] = rank_clnode_to_type[part] + end + my_cnode_to_type + else + my_cnode_to_type = Int[] + end + end + -#function generate_coarse_dof_glue_from_pmesh(pmesh) -# ranks = linear_indices(pmesh) -# lnode_to_colors = map(lmesh->lmesh.lnode_to_colors,pmesh) -# node_partition = map(lmesh->lmesh.local_nodes,pmesh) -# generate_coarse_objects(ranks,lnode_to_colors,node_partition) -# clnode_to_lnodes, clnode_to_cnode, ncnodes -# -#end -# -#function generate_coarse_objects(ranks,lnode_to_colors,node_partition) -# clnode_to_lnodes, clnode_to_owner, nown = map(ranks,lnode_to_colors) do rank,lnode_to_colors -# interface_node_to_lnode = findall(colors->length(colors)!=1,lnode_to_colors) -# interface_node_to_colors = view(lnode_to_colors,interface_node_to_lnode) -# # assumes sorted colors -# clnode_to_colors = unique(interface_node_to_colors) -# interface_node_to_clnode = indexin(interface_node_to_colors,clnode_to_colors) -# clnode_to_interface_nodes = inverse_index_map(interface_node_to_clnode) -# f = interface_node->interface_node_to_lnode[interface_node] -# clnode_to_interface_nodes.data .= f.(clnode_to_interface_nodes.data) -# clnode_to_lnodes = clnode_to_interface_nodes -# clnode_to_owner = map(maximum,clnode_to_colors) -# nown = count(owner->owner==rank,clnode_to_owner) -# clnode_to_lnodes, clnode_to_owner, nown -# end |> tuple_of_arrays -# ncnodes = sum(nown) -# cnode_partition = variable_partition(nown,ncnodes) -# v = PVector{Vector{Int}}(undef,node_partition) -# map(ranks,cnode_partition,clnode_to_owner,clnode_to_lnodes,local_values(v)) do rank, conodes, clnode_to_owner, clnode_to_lnodes lnode_to_v -# conode_to_cnode = own_to_global(conodes) -# conode = 0 -# for (clnode,owner) in enumerate(clnode_to_owner) -# if owner != rank -# continue -# end -# conode += 1 -# cnode = conode_to_cnode[conode] -# lnodes = clnode_to_lnodes[clnode] -# lnode_to_v[lnodes] .= cnode -# end -# end -# consistent!(v) |> wait -# clnode_to_cnode = map(ranks,clnode_to_lnodes,local_values(v)) do rank, clnode_to_lnodes, lnode_to_v -# nclnodes = length(clnode_to_lnodes) -# my_clnode_to_cnode = zeros(Int,nclnodes) -# for clnode in 1:nclnodes -# lnodes = clnode_to_lnodes[clnode] -# cnode = lnode_to_v[first(lnode)] -# my_clnode_to_cnode[clnode] = cnode -# end -# end -# clnode_to_lnodes, clnode_to_cnode, ncnodes -#end + map(clnode_to_lnodes,rank_to_cnodes,clnode_to_type,cnode_to_type) do clnode_to_lnodes,rank_to_cnodes,clnode_to_type,cnode_to_type + (;clnode_to_lnodes, rank_to_cnodes, num_cnodes = ncnodes,clnode_to_type,cnode_to_type) + end +end function inverse_index_map(a_to_b,nb) b_to_as_ptrs = zeros(Int32,nb+1)