def _calculateAxialSurfAndBoundaryCon(self, tabNum, surfaces): """Helper function for exportCore to calculate axial surface and define\ # boundary conditions """ result = "" model = self.core.owningModel() zRangesOfAssy = [] for group in model.groups(): rggType = group.stringProperty('rggType')[0] if (rggType == '_rgg_assembly'): assembly = Assembly(group) segs = assembly.calculateAssemblySegs() zRangesOfAssy.append(segs[0]) zRangesOfAssy.append(segs[-1]) if (len(zRangesOfAssy) == 0): return result zMin, zMax = min(zRangesOfAssy), max(zRangesOfAssy) zMinName, zMaxName = "z" + str(zMin), "z" + str(zMax) zMinName, zMaxName = zMinName.replace(".", "_"), zMaxName.replace(".", "_") surfaces["plane"].add((zMinName, zMin)) surfaces["plane"].add((zMaxName, zMax)) result += prefixTabs(tabNum) + "lower_axial_surf = %s\n" % (zMinName) result += prefixTabs(tabNum) + \ "lower_boundary_condition = extrapolated\n\n" result += prefixTabs(tabNum) + "upper_axial_surf = %s\n" % (zMaxName) result += prefixTabs(tabNum) + \ "upper_boundary_condition = extrapolated\n" return result
def _generateRelatedAssysString(self, tabNum, surfaces): model = self.core.owningModel() result = "" for group in model.groups(): if (group.stringProperty('rggType')[0] == '_rgg_assembly'): assembly = Assembly(group) result += assembly.exportAssembly(tabNum, surfaces) return result
def getAllSubAssyNames(self): model = self.core.owningModel() names = [] for group in model.groups(): if (group.stringProperty('rggType')[0] == '_rgg_assembly'): assembly = Assembly(group) names.extend(assembly.getAllSubAssyNames()) return names
def operateInternal(self): # Access the PyARC SON file filename = self.specification().findFile('filename').value(0) # Access the associated model associatedEntities = self.associatedEntities() model = smtk.model.Model(next(iter(associatedEntities))) isHex = model.integerProperty("hex")[0] if not isHex: smtk.InfoMessage(self.log(), 'Cannot export a non hex nuclear core!') return self.createResult(smtk.operation.Operation.Outcome.FAILED) mgr = model.manager() # Awesome print message smtk.InfoMessage(self.log(), 'Executing export_to_pyarc') materials = model.stringProperty('materials') materialDescriptions = model.stringProperty('material_descriptions') # TODO: export materials tabNum = 0 surfaces = dict() # (name, orientation, normal, pitch) surfaces["hexagon"] = set() # (name, axis, radius) surfaces["cylinder"] = set() # (name, z) surfaces["plane"] = set() content = "=arc\ngeometry{\n" materialsS, surfacesS, coreS, calculationsS = "", "", "", "" for group in model.groups(): rggType = group.stringProperty('rggType')[0] if (rggType == '_rgg_core'): smtk.InfoMessage(self.log(), "processing core " + group.name()) core = Core(group) coreS = core.exportCore(tabNum + 1, surfaces) break surfacesS += surfacesToString(tabNum + 1, surfaces) content += materialsS content += surfacesS content += coreS content += calculationsS content += "}" writeFile(filename, content) # Return with success result = self.createResult(smtk.operation.Operation.Outcome.SUCCEEDED) return result
outletBC = asys.createAttribute('outletBC', outletBCDef) matProp = asys.createAttribute('fluid', matDef) # -- 5 -- # VI. Now tie these to the model # ++ 6 ++ # Read in an SMTK-native B-Rep model: # TODO: Replace with resource.readModel() jsonFile = open(modelFileName, 'r') json = jsonFile.read() smtk.io.LoadJSON.intoModelManager(json, mmgr) # Now find groups corresponding to IC/BCs: models = mmgr.findEntitiesByProperty('name', 'Test Model') model = smtk.model.Model(models[0]) groups = model.groups() if groups and len(groups): wallGroup = (g for g in groups if g.name() == 'wall').next() inletGroup = (g for g in groups if g.name() == 'inlet').next() outletGroup = (g for g in groups if g.name() == 'outlet').next() fluidGroup = (g for g in groups if g.name() == 'fluid').next() fluidIC.associateEntity(fluidGroup) outletBC.associateEntity(outletGroup) inletBC.associateEntity(inletGroup) wallBC.associateEntity(wallGroup) # -- 6 -- # VII. Loop over conditions of interest and create # an input deck for each. # ++ 7 ++
outletBC = ares.createAttribute('outletBC', outletBCDef) matProp = ares.createAttribute('fluid', matDef) # -- 5 -- # VI. Now tie these to the model # ++ 6 ++ # Read in an SMTK-native B-Rep model: # TODO: Replace with resource.readModel() jsonFile = open(modelFileName, 'r') json = jsonFile.read() smtk.model.SessionIOJSON.loadModelRecords(json, mmgr) # Now find groups corresponding to IC/BCs: models = mmgr.findEntitiesByProperty('name', 'Test Model') model = smtk.model.Model(models[0]) groups = model.groups() if groups and len(groups): wallGroup = (g for g in groups if g.name() == 'wall').next() inletGroup = (g for g in groups if g.name() == 'inlet').next() outletGroup = (g for g in groups if g.name() == 'outlet').next() fluidGroup = (g for g in groups if g.name() == 'fluid').next() fluidIC.associateEntity(fluidGroup) outletBC.associateEntity(outletGroup) inletBC.associateEntity(inletGroup) wallBC.associateEntity(wallGroup) # -- 6 -- # VII. Loop over conditions of interest and create # an input deck for each. # ++ 7 ++
# Add cells to the group, the group and cells to the model, submodels # to the model: [store.findOrAddEntityToGroup(group.entity(), x) for x in [u00, u01, u02, u03, u04]] [model.addCell(smtk.model.CellEntity(x)) for x in group.members()] store.assignDefaultNames() model.addGroup(group) model.addSubmodel(model2) model.addSubmodel(model3) # Does the model contain the cells we just added? enames = sorted([x.name() for x in model.cells()]) print('\n'.join(enames)) status = status or len(enames) != 5 or \ (enames[0] != 'face 0') # Does the model contain the group we added? status = status or len(model.groups()) != 1 or \ model.groups()[0].name() != 'Test Group' # Does the model contain the submodels we added? status = status or len(model.submodels()) != 2 or \ sorted([x.name() for x in model.submodels()])[0] != 'Submodel A' except Exception, ex: print('Exception:') exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print() print('Exception: ', exc_type, fname, 'line', exc_tb.tb_lineno) print() print(ex) print() status = True
# Add cells to the group, the group and cells to the model, submodels # to the model: [store.findOrAddEntityToGroup(group.entity(), x) for x in [u00, u01, u02, u03, u04]] [model.addCell(smtk.model.CellEntity(x)) for x in group.members()] store.assignDefaultNames() model.addGroup(group) model.addSubmodel(model2) model.addSubmodel(model3) # Does the model contain the cells we just added? enames = sorted([x.name() for x in model.cells()]) print('\n'.join(enames)) status = status or len(enames) != 5 or \ (enames[0] != 'face 0') # Does the model contain the group we added? status = status or len(model.groups()) != 1 or \ model.groups()[0].name() != 'Test Group' # Does the model contain the submodels we added? status = status or len(model.submodels()) != 2 or \ sorted([x.name() for x in model.submodels()])[0] != 'Submodel A' except (Exception, ex): print('Exception:') exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print() print('Exception: ', exc_type, fname, 'line', exc_tb.tb_lineno) print() print(ex) print() status = True