@@ -861,15 +861,25 @@ def prepare():
861861 )
862862
863863 else : # decomposed mesh filters
864+ mcdc ["technique" ]["dd_xsum" ] = len (input_deck .mesh_tallies [i ].x ) - 1
865+ mcdc ["technique" ]["dd_ysum" ] = len (input_deck .mesh_tallies [i ].y ) - 1
866+ mcdc ["technique" ]["dd_zsum" ] = len (input_deck .mesh_tallies [i ].z ) - 1
867+
864868 mxn , mxp , myn , myp , mzn , mzp = dd_mesh_bounds (i )
865869
866870 # Filters
867871 new_x = input_deck .mesh_tallies [i ].x [mxn :mxp ]
868872 new_y = input_deck .mesh_tallies [i ].y [myn :myp ]
869873 new_z = input_deck .mesh_tallies [i ].z [mzn :mzp ]
870- mcdc ["mesh_tallies" ][i ]["filter" ]["x" ] = new_x
871- mcdc ["mesh_tallies" ][i ]["filter" ]["y" ] = new_y
872- mcdc ["mesh_tallies" ][i ]["filter" ]["z" ] = new_z
874+ xlen = len (new_x )
875+ ylen = len (new_y )
876+ zlen = len (new_z )
877+ mcdc ["mesh_tallies" ][i ]["filter" ]["x" ][:xlen ] = new_x
878+ mcdc ["mesh_tallies" ][i ]["filter" ]["y" ][:ylen ] = new_y
879+ mcdc ["mesh_tallies" ][i ]["filter" ]["z" ][:zlen ] = new_z
880+ mcdc ["technique" ]["dd_xlen" ] = xlen - 1
881+ mcdc ["technique" ]["dd_ylen" ] = ylen - 1
882+ mcdc ["technique" ]["dd_zlen" ] = zlen - 1
873883 for name in ["t" , "mu" , "azi" , "g" ]:
874884 N = len (getattr (input_deck .mesh_tallies [i ], name ))
875885 mcdc ["mesh_tallies" ][i ]["filter" ][name ][:N ] = getattr (
@@ -1632,9 +1642,9 @@ def dd_mergetally(mcdc, data):
16321642 d_Nz = input_deck .technique ["dd_mesh" ]["z" ].size - 1
16331643
16341644 # capture tally lengths for reorganizing later
1635- xlen = len ( mcdc ["mesh_tallies " ][0 ][ "filter" ][ "x" ]) - 1
1636- ylen = len ( mcdc ["mesh_tallies " ][0 ][ "filter" ][ "y" ]) - 1
1637- zlen = len ( mcdc ["mesh_tallies " ][0 ][ "filter" ][ "z" ]) - 1
1645+ xlen = mcdc ["technique " ]["dd_xlen" ]
1646+ ylen = mcdc ["technique " ]["dd_ylen" ]
1647+ zlen = mcdc ["technique " ]["dd_zlen" ]
16381648
16391649 # MPI gather
16401650 if (d_Nx * d_Ny * d_Nz ) == MPI .COMM_WORLD .Get_size ():
@@ -1648,6 +1658,10 @@ def dd_mergetally(mcdc, data):
16481658 MPI .COMM_WORLD .Gatherv (
16491659 sendbuf = tally [i ], recvbuf = (dd_tally [i ], sendcounts ), root = 0
16501660 )
1661+ # gather tally lengths for proper recombination
1662+ xlens = MPI .COMM_WORLD .gather (xlen , root = 0 )
1663+ ylens = MPI .COMM_WORLD .gather (ylen , root = 0 )
1664+ zlens = MPI .COMM_WORLD .gather (zlen , root = 0 )
16511665
16521666 # MPI gather for multiprocessor subdomains
16531667 else :
@@ -1669,6 +1683,10 @@ def dd_mergetally(mcdc, data):
16691683 # gather tallies
16701684 for i , t in enumerate (tally ):
16711685 dd_comm .Gatherv (tally [i ], (dd_tally [i ], sendcounts ), root = 0 )
1686+ # gather tally lengths for proper recombination
1687+ xlens = dd_comm .gather (xlen , root = 0 )
1688+ ylens = dd_comm .gather (ylen , root = 0 )
1689+ zlens = dd_comm .gather (zlen , root = 0 )
16721690 dd_group .Free ()
16731691 if MPI .COMM_NULL != dd_comm :
16741692 dd_comm .Free ()
@@ -1678,20 +1696,39 @@ def dd_mergetally(mcdc, data):
16781696 # reorganize tally data
16791697 # TODO: find/develop a more efficient algorithm for this
16801698 tally_idx = 0
1699+ offset = 0
1700+ ysum = mcdc ["technique" ]["dd_ysum" ]
1701+ zsum = mcdc ["technique" ]["dd_zsum" ]
16811702 for di in range (0 , d_Nx * d_Ny * d_Nz ):
16821703 dz = di // (d_Nx * d_Ny )
16831704 dy = (di % (d_Nx * d_Ny )) // d_Nx
16841705 dx = di % d_Nx
1706+
1707+ offset = 0
1708+ # calculate subdomain offset
1709+ for i in range (0 , dx ):
1710+ offset += xlens [i ] * ysum * zsum
1711+
1712+ for i in range (0 , dy ):
1713+ y_ind = i * d_Nx
1714+ offset += ylens [y_ind ] * zsum
1715+
1716+ for i in range (0 , dz ):
1717+ z_ind = i * d_Nx * d_Ny
1718+ offset += zlens [z_ind ]
1719+
1720+ # calculate index within subdomain
1721+ xlen = xlens [di ]
1722+ ylen = ylens [di ]
1723+ zlen = zlens [di ]
16851724 for xi in range (0 , xlen ):
16861725 for yi in range (0 , ylen ):
16871726 for zi in range (0 , zlen ):
16881727 # calculate reorganized index
1689- ind_x = xi * (ylen * d_Ny * zlen * d_Nz ) + dx * (
1690- xlen * ylen * d_Ny * zlen * d_Nz
1691- )
1692- ind_y = yi * (xlen * d_Nx ) + dy * (ylen * xlen * d_Nx )
1693- ind_z = zi + dz * zlen
1694- buff_idx = ind_x + ind_y + ind_z
1728+ ind_x = xi * ysum * zsum
1729+ ind_y = yi * zsum
1730+ ind_z = zi
1731+ buff_idx = offset + ind_x + ind_y + ind_z
16951732 # place tally value in correct position
16961733 buff [:, buff_idx ] = dd_tally [:, tally_idx ]
16971734 tally_idx += 1
@@ -1716,11 +1753,11 @@ def dd_mergemesh(mcdc, data):
17161753 MPI .COMM_WORLD .gather (len (mcdc ["mesh_tallies" ][0 ]["filter" ]["x" ]), root = 0 )
17171754 )
17181755 if mcdc ["mpi_master" ]:
1719- x_filter = np .zeros ((mcdc ["mesh_tallies" ].shape , sum (sendcounts )))
1756+ x_filter = np .zeros ((mcdc ["mesh_tallies" ].shape [ 0 ] , sum (sendcounts )))
17201757 else :
1721- x_filter = np .empty ((mcdc ["mesh_tallies" ].shape )) # dummy tally
1758+ x_filter = np .empty ((mcdc ["mesh_tallies" ].shape [ 0 ] )) # dummy tally
17221759 # gather mesh
1723- for i in range (mcdc ["mesh_tallies" ].shape ):
1760+ for i in range (mcdc ["mesh_tallies" ].shape [ 0 ] ):
17241761 MPI .COMM_WORLD .Gatherv (
17251762 sendbuf = mcdc ["mesh_tallies" ][i ]["filter" ]["x" ],
17261763 recvbuf = (x_filter [i ], sendcounts ),
@@ -1740,7 +1777,7 @@ def dd_mergemesh(mcdc, data):
17401777 else :
17411778 y_filter = np .empty ((mcdc ["mesh_tallies" ].shape [0 ])) # dummy tally
17421779 # gather mesh
1743- for i in range (mcdc ["mesh_tallies" ].shape ):
1780+ for i in range (mcdc ["mesh_tallies" ].shape [ 0 ] ):
17441781 MPI .COMM_WORLD .Gatherv (
17451782 sendbuf = mcdc ["mesh_tallies" ][i ]["filter" ]["y" ],
17461783 recvbuf = (y_filter [i ], sendcounts ),
@@ -1786,7 +1823,7 @@ def dd_mergemesh(mcdc, data):
17861823 if d_Nz > 1 :
17871824 dd_mesh .append (z_final )
17881825 else :
1789- dd_mesh .append ("z" , mcdc ["mesh_tallies" ][:]["filter" ]["z" ])
1826+ dd_mesh .append (mcdc ["mesh_tallies" ][:]["filter" ]["z" ])
17901827 return dd_mesh
17911828
17921829
@@ -1876,9 +1913,9 @@ def generate_hdf5(data, mcdc):
18761913 # Set tally shape
18771914 N_score = tally ["N_score" ]
18781915 if mcdc ["technique" ]["domain_decomposition" ]:
1879- Nx *= input_deck . technique [ "dd_mesh " ]["x" ]. size - 1
1880- Ny *= input_deck . technique [ "dd_mesh " ]["y" ]. size - 1
1881- Nz *= input_deck . technique [ "dd_mesh " ]["z" ]. size - 1
1916+ Nx = mcdc [ "technique " ]["dd_xsum" ]
1917+ Ny = mcdc [ "technique " ]["dd_ysum" ]
1918+ Nz = mcdc [ "technique " ]["dd_zsum" ]
18821919 if not mcdc ["technique" ]["uq" ]:
18831920 shape = (3 , Nmu , N_azi , Ng , Nt , Nx , Ny , Nz , N_score )
18841921 else :
0 commit comments