def _run_openmoc(self): """Print a variety of log messages to a log file.""" # Set a log level which precludes some messages from being printed openmoc.set_log_level('NORMAL') # Print messages using the pure C implementation openmoc.log_printf(openmoc.DEBUG, 'This is a debug message') openmoc.log_printf(openmoc.INFO, 'This is an info message') openmoc.log_printf(openmoc.NORMAL, 'This is a normal message') openmoc.log_printf(openmoc.SEPARATOR, 'This is a separator message') openmoc.log_printf(openmoc.HEADER, 'This is a header message') openmoc.log_printf(openmoc.TITLE, 'This is a title message') openmoc.log_printf(openmoc.WARNING, 'This is a warning message') openmoc.log_printf(openmoc.CRITICAL, 'This is a critical message') openmoc.log_printf(openmoc.RESULT, 'This is a result message') # Print messages using the Python-wrapped version py_printf('DEBUG', 'This is a debug message') py_printf('INFO', 'This is an info message') py_printf('NORMAL', 'This is a normal message') py_printf('SEPARATOR', 'This is a separator message') py_printf('HEADER', 'This is a header message') py_printf('TITLE', 'This is a title message') py_printf('WARNING', 'This is a warning message') py_printf('CRITICAL', 'This is a critical message') py_printf('RESULT', 'This is a result message: %d', 5)
def _run_openmoc(self): openmoc.set_log_level('NORMAL') c1 = openmoc.Cell() c2 = openmoc.Cell() s1 = openmoc.XPlane(-40.) s2 = openmoc.XPlane(-50.) s3 = openmoc.XPlane(-60.) s1.setBoundaryType(openmoc.VACUUM) s2.setBoundaryType(openmoc.PERIODIC) s3.setBoundaryType(openmoc.REFLECTIVE) c1.addSurface(+1, s1) c2.addSurface(+1, s2) c2.addSurface(+1, s3) u = openmoc.Universe() u.addCell(c1) u.addCell(c2) boundary = u.getMinXBoundaryType() if boundary == 0: boundary = 'VACUUM' elif boundary == 1: boundary = 'REFLECTIVE' elif boundary == 2: boundary = 'PERIODIC' else: boundary = 'BOUNDARY_NONE' py_printf('NORMAL', 'MinX: %f', u.getMinX()) py_printf('NORMAL', 'MinXBoundaryType: %s', boundary) py_printf('SEPARATOR', '') c1 = openmoc.Cell() c2 = openmoc.Cell() s1 = openmoc.YPlane(-40.) s2 = openmoc.YPlane(-50.) s3 = openmoc.YPlane(-60.) s1.setBoundaryType(openmoc.VACUUM) s2.setBoundaryType(openmoc.PERIODIC) s3.setBoundaryType(openmoc.REFLECTIVE) c1.addSurface(+1, s1) c2.addSurface(+1, s2) c2.addSurface(+1, s3) u = openmoc.Universe() u.addCell(c1) u.addCell(c2) boundary = u.getMinYBoundaryType() if boundary == 0: boundary = 'VACUUM' elif boundary == 1: boundary = 'REFLECTIVE' elif boundary == 2: boundary = 'PERIODIC' else: boundary = 'BOUNDARY_NONE' py_printf('NORMAL', 'MinY: %f', u.getMinY()) py_printf('NORMAL', 'MinYBoundaryType: %s', boundary) py_printf('SEPARATOR', '') c1 = openmoc.Cell() c2 = openmoc.Cell() s1 = openmoc.ZPlane(-40.) s2 = openmoc.ZPlane(-50.) s3 = openmoc.ZPlane(-60.) s1.setBoundaryType(openmoc.VACUUM) s2.setBoundaryType(openmoc.PERIODIC) s3.setBoundaryType(openmoc.REFLECTIVE) c1.addSurface(+1, s1) c2.addSurface(+1, s2) c2.addSurface(+1, s3) u = openmoc.Universe() u.addCell(c1) u.addCell(c2) boundary = u.getMinZBoundaryType() if boundary == 0: boundary = 'VACUUM' elif boundary == 1: boundary = 'REFLECTIVE' elif boundary == 2: boundary = 'PERIODIC' else: boundary = 'BOUNDARY_NONE' py_printf('NORMAL', 'MinZ: %f', u.getMinZ()) py_printf('NORMAL', 'MinZBoundaryType: %s', boundary) py_printf('SEPARATOR', '') c1 = openmoc.Cell() c2 = openmoc.Cell() s1 = openmoc.XPlane(40.) s2 = openmoc.XPlane(50.) s3 = openmoc.XPlane(60.) s1.setBoundaryType(openmoc.VACUUM) s2.setBoundaryType(openmoc.PERIODIC) s3.setBoundaryType(openmoc.REFLECTIVE) c1.addSurface(-1, s1) c2.addSurface(-1, s2) c2.addSurface(-1, s3) u = openmoc.Universe() u.addCell(c1) u.addCell(c2) boundary = u.getMaxXBoundaryType() if boundary == 0: boundary = 'VACUUM' elif boundary == 1: boundary = 'REFLECTIVE' elif boundary == 2: boundary = 'PERIODIC' else: boundary = 'BOUNDARY_NONE' py_printf('NORMAL', 'MaxX: %f', u.getMaxX()) py_printf('NORMAL', 'MaxXBoundaryType: %s', boundary) py_printf('SEPARATOR', '') c1 = openmoc.Cell() c2 = openmoc.Cell() s1 = openmoc.YPlane(40.) s2 = openmoc.YPlane(50.) s3 = openmoc.YPlane(60.) s1.setBoundaryType(openmoc.VACUUM) s2.setBoundaryType(openmoc.PERIODIC) s3.setBoundaryType(openmoc.REFLECTIVE) c1.addSurface(-1, s1) c2.addSurface(-1, s2) c2.addSurface(-1, s3) u = openmoc.Universe() u.addCell(c1) u.addCell(c2) boundary = u.getMaxYBoundaryType() if boundary == 0: boundary = 'VACUUM' elif boundary == 1: boundary = 'REFLECTIVE' elif boundary == 2: boundary = 'PERIODIC' else: boundary = 'BOUNDARY_NONE' py_printf('NORMAL', 'MaxY: %f', u.getMaxY()) py_printf('NORMAL', 'MaxYBoundaryType: %s', boundary) py_printf('SEPARATOR', '') c1 = openmoc.Cell() c2 = openmoc.Cell() s1 = openmoc.ZPlane(40.) s2 = openmoc.ZPlane(50.) s3 = openmoc.ZPlane(60.) s1.setBoundaryType(openmoc.VACUUM) s2.setBoundaryType(openmoc.PERIODIC) s3.setBoundaryType(openmoc.REFLECTIVE) c1.addSurface(-1, s1) c2.addSurface(-1, s2) c2.addSurface(-1, s3) u = openmoc.Universe() u.addCell(c1) u.addCell(c2) boundary = u.getMaxZBoundaryType() if boundary == 0: boundary = 'VACUUM' elif boundary == 1: boundary = 'REFLECTIVE' elif boundary == 2: boundary = 'PERIODIC' else: boundary = 'BOUNDARY_NONE' py_printf('NORMAL', 'MaxZ: %f', u.getMaxZ()) py_printf('NORMAL', 'MaxZBoundaryType: %s', boundary) py_printf('SEPARATOR', '') sW = openmoc.XPlane(10) sE = openmoc.XPlane(20) sS = openmoc.YPlane(30) sN = openmoc.YPlane(40) sB = openmoc.ZPlane(50) sT = openmoc.ZPlane(60) sW.setBoundaryType(openmoc.VACUUM) sE.setBoundaryType(openmoc.REFLECTIVE) sS.setBoundaryType(openmoc.VACUUM) sN.setBoundaryType(openmoc.REFLECTIVE) sB.setBoundaryType(openmoc.PERIODIC) sT.setBoundaryType(openmoc.REFLECTIVE) sX_mid = openmoc.XPlane(15) sY_mid = openmoc.YPlane(35) sZ_mid = openmoc.ZPlane(55) sX_mid.setBoundaryType(openmoc.BOUNDARY_NONE) sY_mid.setBoundaryType(openmoc.BOUNDARY_NONE) sZ_mid.setBoundaryType(openmoc.BOUNDARY_NONE) cell = openmoc.Cell() cell.addSurface(+1, sW) cell.addSurface(-1, sE) cell.addSurface(+1, sS) cell.addSurface(-1, sN) cell.addSurface(+1, sB) cell.addSurface(-1, sT) cell.addSurface(+1, sX_mid) cell.addSurface(-1, sX_mid) cell.addSurface(+1, sY_mid) cell.addSurface(-1, sY_mid) cell.addSurface(+1, sZ_mid) cell.addSurface(-1, sZ_mid) univ = openmoc.Universe() univ.addCell(cell) py_printf('NORMAL', 'MinX: %f', univ.getMinX()) py_printf('NORMAL', 'MinXBoundaryType: %s', univ.getMinXBoundaryType()) py_printf('NORMAL', 'MinY: %f', univ.getMinY()) py_printf('NORMAL', 'MinYBoundaryType: %s', univ.getMinYBoundaryType()) py_printf('NORMAL', 'MinZ: %f', univ.getMinZ()) py_printf('NORMAL', 'MinZBoundaryType: %s', univ.getMinZBoundaryType()) py_printf('NORMAL', 'MaxX: %f', univ.getMaxX()) py_printf('NORMAL', 'MaxXBoundaryType: %s', univ.getMaxXBoundaryType()) py_printf('NORMAL', 'MaxY: %f', univ.getMaxY()) py_printf('NORMAL', 'MaxYBoundaryType: %s', univ.getMaxYBoundaryType()) py_printf('NORMAL', 'MaxZ: %f', univ.getMaxZ()) py_printf('NORMAL', 'MaxZBoundaryType: %s', univ.getMaxZBoundaryType())
def set_log_level(level): if level == 'DEBUG': openmoc.set_log_level('DEBUG') elif level == 'INFO': openmoc.set_log_level('INFO') elif level == 'NORMAL': openmoc.set_log_level('NORMAL') elif level == 'SEPARATOR': openmoc.set_log_level('SEPARATOR') elif level == 'HEADER': openmoc.set_log_level('HEADER') elif level == 'TITLE': openmoc.set_log_level('TITLE') elif level == 'WARNING': openmoc.set_log_level('WARNING') elif level == 'CRITICAL': openmoc.set_log_level('CRITICAL') elif level == 'RESULT': openmoc.set_log_level('RESULT') elif level == 'UNITTEST': openmoc.set_log_level('UNITTEST') elif level == 'ERROR': openmoc.set_log_level('ERROR') else: py_printf('Cannot set log level to unsupported log level %s', str(level))
import signal, sys import _openmoc_gnu_single # For Python 2.X.X if (sys.version_info[0] == 2): import openmoc from openmoc_gnu_single import * # For Python 3.X.X else: import openmoc.openmoc as openmoc from openmoc.gnu.single.openmoc_gnu_single import * # Tell Python to recognize CTRL+C and stop the C++ extension module # when this is passed in from the keyboard signal.signal(signal.SIGINT, signal.SIG_DFL) openmoc.set_log_level(str(openmoc.get_log_level())) openmoc.set_output_directory(openmoc.get_output_directory()) openmoc.set_log_filename(openmoc.get_log_filename()) Timer = openmoc.Timer
def test_log_level(self): # Test setting log levels with the openmoc logs openmoc.set_log_level(openmoc.DEBUG) self.assertEqual(openmoc.get_log_level(), 0) openmoc.set_log_level(openmoc.INFO) self.assertEqual(openmoc.get_log_level(), 1) openmoc.set_log_level(openmoc.NORMAL) self.assertEqual(openmoc.get_log_level(), 3) openmoc.set_log_level(openmoc.SEPARATOR) self.assertEqual(openmoc.get_log_level(), 5) openmoc.set_log_level(openmoc.HEADER) self.assertEqual(openmoc.get_log_level(), 6) openmoc.set_log_level(openmoc.TITLE) self.assertEqual(openmoc.get_log_level(), 7) openmoc.set_log_level(openmoc.WARNING) self.assertEqual(openmoc.get_log_level(), 8) openmoc.set_log_level(openmoc.CRITICAL) self.assertEqual(openmoc.get_log_level(), 10) openmoc.set_log_level(openmoc.RESULT) self.assertEqual(openmoc.get_log_level(), 11) openmoc.set_log_level(openmoc.UNITTEST) self.assertEqual(openmoc.get_log_level(), 12) openmoc.set_log_level(openmoc.ERROR) self.assertEqual(openmoc.get_log_level(), 13) # Setting log level with an integer openmoc.set_log_level(3) self.assertEqual(openmoc.get_log_level(), 3)
def set_log_level(level): """Assign the lowest level logging message to be reported. Sets the lowest level logging message to print to the screen. This controls the lowest level for both logging messages in the C++ source code as well as the user's OpenMOC Python input file. Parameters ---------- level : str The minimum logging level (i.e., 'DEBUG', 'INFO') Examples -------- This routine may be called in an OpenMOC Python script as follows: >>> log.set_log_level('INFO') """ if level == 'DEBUG': openmoc.set_log_level('DEBUG') elif level == 'INFO': openmoc.set_log_level('INFO') elif level == 'NORMAL': openmoc.set_log_level('NORMAL') elif level == 'SEPARATOR': openmoc.set_log_level('SEPARATOR') elif level == 'HEADER': openmoc.set_log_level('HEADER') elif level == 'TITLE': openmoc.set_log_level('TITLE') elif level == 'WARNING': openmoc.set_log_level('WARNING') elif level == 'CRITICAL': openmoc.set_log_level('CRITICAL') elif level == 'RESULT': openmoc.set_log_level('RESULT') elif level == 'ERROR': openmoc.set_log_level('ERROR') else: py_printf('Cannot set log level to unsupported level %s', str(level))
def compute_sph_factors(mgxs_lib, max_sph_iters=30, sph_tol=1E-5, fix_src_tol=1E-5, num_azim=4, azim_spacing=0.1, zcoord=0.0, num_threads=1, throttle_output=True, geometry=None, track_generator=None, solver=None, sph_domains=None): """Compute SPH factors for an OpenMC multi-group cross section library. This routine coputes SuPerHomogenisation (SPH) factors for an OpenMC MGXS library. The SPH scheme is outlined by Alain Hebert in the following paper: Hebert, A., "A Consistent Technique for the Pin-by-Pin Homogenization of a Pressurized Water Reactor Assembly." Nuclear Science and Engineering, 113 (3), pp. 227-233, 1993. The SPH factors are needed to preserve reaction rates in heterogeneous geometries. The energy condensation process leads to a bias between ultrafine and coarse energy group calculations. This bias is a result of the use of scalar flux-weighting to compute MGXS without properly accounting for angular-dependence of the flux. Parameters ---------- mgxs_lib : openmc.mgxs.Library An OpenMC multi-group cross section library max_sph_iters : Integral The maximum number of SPH iterations (default is 30) sph_tol : Real The tolerance on the SPH factor convergence (default is 1E-5) fix_src_tol : Real The tolerance on the MOC fixed source calculations (default is 1E-5) num_azim : Integral The number of azimuthal angles (default is 4) azim_spacing : Real The track spacing (default is 0.1 centimeters) zcoord : Real The coordinate on the z-axis (default is 0.) num_threads : Real The number of OpenMP threads (default is 1) throttle_output : bool Whether to suppress output from fixed source calculations (default is True) geometry : openmoc.Geometry An optional openmoc geometry to compute SPH factors on track_generator : openmoc.TrackGenerator An optional track generator to avoid initializing it in this routine solver : openmoc.Solver An optional openmoc solver to compute SPH factors with sph_domains : list of int A list of domain (cell or material, based on mgxs_lib domain type) ids, in which SPH factors should be computed. Default is only fissonable FSRs Returns ------- fsrs_to_sph : numpy.ndarray of Real A NumPy array of SPH factors indexed by FSR and energy group sph_mgxs_lib : openmc.mgxs.Library An OpenMC MGXS library with the SPH factors applied to each MGXS sph_to_fsrs_indices : numpy.ndarray of Integral A NumPy array of all FSRs to which SPH factors were applied """ import openmc.mgxs cv.check_type('mgxs_lib', mgxs_lib, openmc.mgxs.Library) # For Python 2.X.X if sys.version_info[0] == 2: from openmc.openmoc_compatible import get_openmoc_geometry from process import get_scalar_fluxes # For Python 3.X.X else: from openmc.openmoc_compatible import get_openmoc_geometry from openmoc.process import get_scalar_fluxes py_printf('NORMAL', 'Computing SPH factors...') if not geometry: # Create an OpenMOC Geometry from the OpenMC Geometry geometry = get_openmoc_geometry(mgxs_lib.geometry) # Load the MGXS library data into the OpenMOC geometry load_openmc_mgxs_lib(mgxs_lib, geometry) if not track_generator: # Initialize an OpenMOC TrackGenerator track_generator = openmoc.TrackGenerator(geometry, num_azim, azim_spacing) track_generator.setZCoord(zcoord) track_generator.generateTracks() track_generator.initializeVolumes() else: track_generator.initializeVolumes() py_printf( 'WARNING', 'Using provided track generator, ignoring ' 'arguments for track generation settings') if not solver: # Initialize an OpenMOC Solver solver = openmoc.CPUSolver(track_generator) solver.setConvergenceThreshold(fix_src_tol) solver.setNumThreads(num_threads) else: py_printf( 'WARNING', 'Using provided solver, ignoring arguments for ' 'solver settings') # Get all OpenMOC domains if mgxs_lib.domain_type == 'material': openmoc_domains = geometry.getAllMaterials() elif mgxs_lib.domain_type == 'cell': openmoc_domains = geometry.getAllMaterialCells() else: py_printf( 'ERROR', 'SPH factors cannot be applied for an OpenMC MGXS ' 'library of domain type %s', mgxs_lib.domain_type) if not sph_domains: sph_domains = [] # If unspecified, apply sph factors in fissionable regions for openmoc_domain in openmoc_domains.values(): if openmoc_domain.isFissionable(): sph_domains.append(openmoc_domain.getId()) openmc_fluxes = _load_openmc_src(mgxs_lib, solver) # Initialize SPH factors num_groups = geometry.getNumEnergyGroups() num_fsrs = geometry.getNumFSRs() # Map FSRs to domains (and vice versa) to compute domain-averaged fluxes fsrs_to_domains = np.zeros(num_fsrs) domains_to_fsrs = collections.defaultdict(list) sph_to_fsr_indices = [] for fsr in range(num_fsrs): cell = geometry.findCellContainingFSR(fsr) if mgxs_lib.domain_type == 'material': domain = cell.getFillMaterial() else: domain = cell fsrs_to_domains[fsr] = domain.getId() domains_to_fsrs[domain.getId()].append(fsr) if domain.getId() in sph_domains: sph_to_fsr_indices.append(fsr) # Build a list of indices into the SPH array for fissionable domains sph_to_domain_indices = [] for i, openmc_domain in enumerate(mgxs_lib.domains): if openmc_domain.id in openmoc_domains: openmoc_domain = openmoc_domains[openmc_domain.id] if openmoc_domain.getId() in sph_domains: sph_to_domain_indices.append(i) py_printf('NORMAL', 'Computing SPH factors for %d "%s" domains', len(sph_to_domain_indices), mgxs_lib.domain_type) # Initialize array of domain-averaged fluxes and SPH factors num_domains = len(mgxs_lib.domains) openmoc_fluxes = np.zeros((num_domains, num_groups)) sph = np.ones((num_domains, num_groups)) # Store starting verbosity log level log_level = openmoc.get_log_level() # SPH iteration loop for i in range(max_sph_iters): # Run fixed source calculation with suppressed output if throttle_output: openmoc.set_log_level('WARNING') # Disable flux resets between SPH iterations for speed if i == 1: solver.setRestartStatus(True) # Fixed source calculation solver.computeFlux() # Restore log output level if throttle_output: openmoc.set_log_level('NORMAL') # Extract the FSR scalar fluxes fsr_fluxes = get_scalar_fluxes(solver) # Compute the domain-averaged flux in each energy group for j, openmc_domain in enumerate(mgxs_lib.domains): domain_fluxes = fsr_fluxes[fsrs_to_domains == openmc_domain.id, :] openmoc_fluxes[j, :] = np.mean(domain_fluxes, axis=0) # Compute SPH factors old_sph = np.copy(sph) sph = openmc_fluxes / openmoc_fluxes sph = np.nan_to_num(sph) sph[sph == 0.0] = 1.0 # Compute SPH factor residuals res = np.abs((sph - old_sph) / old_sph) res = np.nan_to_num(res) # Extract residuals for fissionable domains only res = res[sph_to_domain_indices, :] # Report maximum SPH factor residual py_printf('NORMAL', 'SPH Iteration %d:\tres = %1.3e', i, res.max()) # Create a new MGXS library with cross sections updated by SPH factors sph_mgxs_lib = _apply_sph_factors(mgxs_lib, geometry, sph, sph_domains) # Load the new MGXS library data into the OpenMOC geometry load_openmc_mgxs_lib(sph_mgxs_lib, geometry) # Check max SPH factor residual for this domain for convergence if res.max() < sph_tol and i > 0: break # Warn user if SPH factors did not converge else: py_printf('WARNING', 'SPH factors did not converge') # Collect SPH factors for each FSR, energy group fsrs_to_sph = np.ones((num_fsrs, num_groups), dtype=np.float) for i, openmc_domain in enumerate(mgxs_lib.domains): if openmc_domain.id in openmoc_domains: openmoc_domain = openmoc_domains[openmc_domain.id] if openmoc_domain.getId() in sph_domains: fsr_ids = domains_to_fsrs[openmc_domain.id] fsrs_to_sph[fsr_ids, :] = sph[i, :] return fsrs_to_sph, sph_mgxs_lib, np.array(sph_to_fsr_indices)
def _run_openmoc(self): """Instantiate a complex region Geometry.""" # ---------------- # / \ # --------------- c2 (p22,p23) - u2 - c2a (p11) # / / # u_r <- c_r (p1,p2) - u1 - c1 (p11,p12,p13) # \ \ # ------------- c3 root_universe = openmoc.Universe(name='root universe') root_cell = openmoc.Cell(name='root cell') u1 = openmoc.Universe(name='universe 1') u2 = openmoc.Universe(name='universe 2 in c2') root_cell.setFill(u1) # Z-bounds at root level p1 = openmoc.ZPlane(z=-2.0, name='zmin') p1.setBoundaryType(openmoc.REFLECTIVE) p2 = openmoc.ZPlane(z=+2.0, name='zmax') p2.setBoundaryType(openmoc.INTERFACE) root_cell.addSurface(halfspace=+1, surface=p1) root_cell.addSurface(halfspace=-1, surface=p2) # Cells in the root cell c1 = openmoc.Cell(name='intersection cell') c2 = openmoc.Cell(name='union cell') c2a = openmoc.Cell(name='union cell 2') c3 = openmoc.Cell(name='unbound cell') u1.addCell(c1) u1.addCell(c2) u1.addCell(c3) # Setting the parent cell helps to find boundaries (in Z here) c3.setParent(root_cell) # Cell c2a in c2, to further test arborescence c2.setFill(u2) u2.addCell(c2a) c2.setParent(root_cell) c2a.setParent(c2) # to test transitivity # Bounds for cell 1 : intersection region cell p11 = openmoc.XPlane(x=-2.0, name='xmin') p11.setBoundaryType(openmoc.REFLECTIVE) p12 = openmoc.YPlane(y=-2.0, name='ymin') p12.setBoundaryType(openmoc.VACUUM) p13 = openmoc.ZCylinder(x=0, y=0, radius=2.5, name='cylinder') p13.setBoundaryType(openmoc.INTERFACE) # addSurface assumes an intersection, which is what we want here c1.addSurface(halfspace=+1, surface=p11) c1.addSurface(halfspace=+1, surface=p12) c1.addSurface(halfspace=-1, surface=p13) # Bounds for cell 2 : union region cell p22 = openmoc.ZCylinder(x=4, y=4, radius=2.5, name='cylinder') p22.setBoundaryType(openmoc.INTERFACE) p23 = openmoc.ZCylinder(x=-2, y=-8, radius=3, name='cylinder') p23.setBoundaryType(openmoc.VACUUM) # To have a union, we need to use addLogicalNode and addSurfaceInRegion c2.addLogicalNode(1) c2.addSurfaceInRegion(halfspace=-1, surface=p22) c2.addSurfaceInRegion(halfspace=-1, surface=p23) # Plane limits area even more c2a.addLogicalNode(1) c2a.addSurfaceInRegion(halfspace=+1, surface=p11) openmoc.set_log_level('NORMAL') for cell in [root_cell, c1, c2, c2a, c3]: py_printf('NORMAL', 'Cell: %s', cell.getName()) py_printf('NORMAL', 'MinX: %f', cell.getMinX()) py_printf('NORMAL', 'MinXBoundaryType: %s', cell.getMinXBoundaryType()) py_printf('NORMAL', 'MinY: %f', cell.getMinY()) py_printf('NORMAL', 'MinYBoundaryType: %s', cell.getMinYBoundaryType()) py_printf('NORMAL', 'MinZ: %f', cell.getMinZ()) py_printf('NORMAL', 'MinZBoundaryType: %s', cell.getMinZBoundaryType()) py_printf('NORMAL', 'MaxX: %f', cell.getMaxX()) py_printf('NORMAL', 'MaxXBoundaryType: %s', cell.getMaxXBoundaryType()) py_printf('NORMAL', 'MaxY: %f', cell.getMaxY()) py_printf('NORMAL', 'MaxYBoundaryType: %s', cell.getMaxYBoundaryType()) py_printf('NORMAL', 'MaxZ: %f', cell.getMaxZ()) py_printf('NORMAL', 'MaxZBoundaryType: %s', cell.getMaxZBoundaryType()) py_printf('NORMAL', '')
def _run_openmoc(self): runtime = openmoc.RuntimeParameters() string_input = [ '-debug', '1', '-log_level', 'NORMAL', '-domain_decompose', '2,2,2', '-num_domain_modules', '1,1,1', '-num_threads', '1', '-log_filename', 'test_problem.log', '-geo_filename', 'geometry_file.geo', '-azim_spacing', '0.22 ', '-num_azim', '4', '-polar_spacing', '0.8', '-num_polar', '6', '-seg_zones', '-5.0,5.0', '-segmentation_type', '3', '-quadraturetype', '2', '-CMFD_group_structure', '1/2,3,4/5,6,7', '-CMFD_lattice', '2,3,3', '-widths_x', '1,2*1,1', '-widths_y', '1,2*1,1', '-widths_z', '3.5,2.5*2,1.5', '-CMFD_flux_update_on', '1', '-knearest', '2', '-CMFD_centroid_update_on', '1', '-use_axial_interpolation', '2', '-SOR_factor', '1.5', '-CMFD_relaxation_factor', '0.7', '-ls_solver', '1', '-max_iters', '15', '-MOC_src_residual_type', '1', '-MOC_src_tolerance', '1.0E-2', '-output_mesh_lattice', '-output_mesh_lattice', ' 5,5,9', ' -output_type', ' 0', '-output_mesh_lattice', '-output_mesh_lattice', ' 5,5,9', ' -output_type', ' 1', '-non_uniform_output', '1.26*3/1*3/4.*3/-1.,1.,-1.', ' -output_type 1 ', '-verbose_report', '1', '-time_report', '1' ] string_input = [s.encode('utf8') for s in string_input] runtime.setRuntimeParameters(string_input) print(string_input) # Define simulation parameters num_threads = runtime._num_threads # Set logging information if (runtime._log_filename): openmoc.set_log_filename(runtime._log_filename) openmoc.set_log_level(runtime._log_level) openmoc.set_line_length(120) py_printf('NORMAL', 'Geometry file = %s', runtime._geo_filename) py_printf('NORMAL', 'Azimuthal spacing = %f', runtime._azim_spacing) py_printf('NORMAL', 'Azimuthal angles = %d', runtime._num_azim) py_printf('NORMAL', 'Polar spacing = %f', runtime._polar_spacing) py_printf('NORMAL', 'Polar angles = %d', runtime._num_polar) # Create the geometry py_printf('NORMAL', 'Creating geometry...') geometry = openmoc.Geometry() self.input_set.geometry = geometry if (not runtime._geo_filename): py_printf('ERROR', 'No geometry file is provided') geometry.loadFromFile(runtime._geo_filename) if False: #FIXME geometry.setDomainDecomposition(runtime._NDx, runtime._NDy, runtime._NDz, MPI_COMM_WORLD) geometry.setNumDomainModules(runtime._NMx, runtime._NMy, runtime._NMz) if ((runtime._NCx > 0 and runtime._NCy > 0 and runtime._NCz > 0) or (not runtime._cell_widths_x.empty() and not runtime._cell_widths_y.empty() and not runtime._cell_widths_z.empty())): # Create CMFD mesh py_printf('NORMAL', 'Creating CMFD mesh...') cmfd = openmoc.Cmfd() cmfd.setSORRelaxationFactor(runtime._SOR_factor) cmfd.setCMFDRelaxationFactor(runtime._CMFD_relaxation_factor) if (runtime._cell_widths_x.empty() or runtime._cell_widths_y.empty() or runtime._cell_widths_z.empty()): cmfd.setLatticeStructure(runtime._NCx, runtime._NCy, runtime._NCz) else: cmfd_widths = [ runtime._cell_widths_x, runtime._cell_widths_y, runtime._cell_widths_z ] cmfd.setWidths(cmfd_widths) if (not runtime._CMFD_group_structure.empty()): cmfd.setGroupStructure(runtime._CMFD_group_structure) cmfd.setKNearest(runtime._knearest) cmfd.setCentroidUpdateOn(runtime._CMFD_centroid_update_on) cmfd.useAxialInterpolation(runtime._use_axial_interpolation) geometry.setCmfd(cmfd) geometry.initializeFlatSourceRegions() # Initialize track generator and generate tracks py_printf('NORMAL', 'Initializing the track generator...') if runtime._quadraturetype == 0: quad = openmoc.TYPolarQuad() if runtime._quadraturetype == 1: quad = openmoc.LeonardPolarQuad() if runtime._quadraturetype == 2: quad = openmoc.GLPolarQuad() if runtime._quadraturetype == 3: quad = openmoc.EqualWeightPolarQuad() if runtime._quadraturetype == 4: quad = openmoc.EqualAnglePolarQuad() quad.setNumAzimAngles(runtime._num_azim) quad.setNumPolarAngles(runtime._num_polar) track_generator = openmoc.TrackGenerator3D(geometry, runtime._num_azim, runtime._num_polar, runtime._azim_spacing, runtime._polar_spacing) track_generator.setNumThreads(num_threads) track_generator.setQuadrature(quad) track_generator.setSegmentFormation(runtime._segmentation_type) if (len(runtime._seg_zones) > 0): track_generator.setSegmentationZones(runtime._seg_zones) track_generator.generateTracks() self.track_generator = track_generator # Initialize solver and run simulation if (runtime._linear_solver): self.solver = openmoc.CPULSSolver(track_generator) else: self.solver = openmoc.CPUSolver(track_generator) if (runtime._verbose_report): self.solver.setVerboseIterationReport() self.solver.setNumThreads(num_threads) self.solver.setConvergenceThreshold(runtime._tolerance) self.solver.computeEigenvalue(runtime._max_iters, runtime._MOC_src_residual_type) if (runtime._time_report): self.solver.printTimerReport() # Extract reaction rates my_rank = 0 #if False: #FIXME #MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); rxtype = {'FISSION_RX', 'TOTAL_RX', 'ABSORPTION_RX', 'FLUX_RX'}