def write_zones(mesh, output_file): """Write the volume and zone lines to the ALARA geometry output Parameters ---------- mesh : ScdMesh object or iMesh.Mesh object Mesh object to read materials data from output_file : file object Opened file for writing contents of ALARA geometry """ output_file.write('geometry rectangular\n\n') output_file.write('volume\n') if isinstance(mesh, ScdMesh): for idx, vol in enumerate(mesh.iterateHexVolumes('xyz')): output_file.write("\t{0}\tzone_{1}\n".format(vol, idx)) else: for idx, voxel in enumerate( \ mesh.iterate(iBase.Type.region, iMesh.Topology.all)): vol = calc_volume(mesh, voxel) output_file.write("\t{0}\tzone_{1}\n".format(vol, idx)) output_file.write('end\n\n')
numergbins = 0 # We now go through all photon energy groups and sum the individual bins # to get the total source strength in each voxel for i in xrange(2,1000): #~ Arbitrary: we look for up to 1000 groups try: grouptag = mesh.getTagHandle("phtn_src_group_{0:03d}".format(i)) for cnt, vox in enumerate(voxels): meshstrengths[cnt] += float(grouptag[vox]) except iBase.TagNotFoundError: numergbins = i - 1 break print "Found tags for {0} photon energy bins.".format(numergbins) vols = [calc_volume(mesh, voxel) for voxel in voxels] # We calculate the normalization factor as the sum over all voxels of: # voxel volumetric source strength * voxel volume # Divided by the volume of all voxels with non-zero source strength. # This applies for variable voxel sizes in a structured mesh. numactivatedcells = 0 # number of voxels that have nonzero source strength sumvoxelsourcestrengths = 0 # total photon source strength in entire model sourcevolumetotal = 0 # total activated volume in model for cnt, meshstr in enumerate(meshstrengths): if meshstr > 0: numactivatedcells += 1 sumvoxelsourcestrengths += vols[cnt] * meshstr sourcevolumetotal += vols[cnt] if tag_srcsum:
numergbins = 0 # We now go through all photon energy groups and sum the individual bins # to get the total source strength in each voxel for i in xrange(2, 1000): #~ Arbitrary: we look for up to 1000 groups try: grouptag = mesh.getTagHandle("phtn_src_group_{0:03d}".format(i)) for cnt, vox in enumerate(voxels): meshstrengths[cnt] += float(grouptag[vox]) except iBase.TagNotFoundError: numergbins = i - 1 break print "Found tags for {0} photon energy bins.".format(numergbins) vols = [calc_volume(mesh, voxel) for voxel in voxels] # We calculate the normalization factor as the sum over all voxels of: # voxel volumetric source strength * voxel volume # Divided by the volume of all voxels with non-zero source strength. # This applies for variable voxel sizes in a structured mesh. numactivatedcells = 0 # number of voxels that have nonzero source strength sumvoxelsourcestrengths = 0 # total photon source strength in entire model sourcevolumetotal = 0 # total activated volume in model for cnt, meshstr in enumerate(meshstrengths): if meshstr > 0: numactivatedcells += 1 sumvoxelsourcestrengths += vols[cnt] * meshstr sourcevolumetotal += vols[cnt] if tag_srcsum: