def addOptions(self): CommonStandardOutput.addOptions(self,logname="RunAtMultipleTimes") CommonParallel.addOptions(self) CommonServer.addOptions(self) CommonSelectTimesteps.addOptions(self,defaultUnique=True) CommonReportUsage.addOptions(self) CommonReportRunnerData.addOptions(self)
def addOptions(self): CommonClearCase.addOptions(self) CommonRestart.addOptions(self) CommonReportUsage.addOptions(self) CommonReportRunnerData.addOptions(self) CommonStandardOutput.addOptions(self) CommonParallel.addOptions(self) CommonPlotLines.addOptions(self) CommonSafeTrigger.addOptions(self) CommonWriteAllTrigger.addOptions(self) CommonServer.addOptions(self) CommonVCSCommit.addOptions(self)
def addOptions(self): pot=OptionGroup(self.parser, "Solver settings", "Basic settings for the potentialFoam-solver") pot.add_option("--non-orthogonal-correctors", type="int", dest="noCorr", default=None, help="The number of non-orthogonal corrections") pot.add_option("--tolerance", type="float", dest="tolerance", default=None, help="Overwrite the tolerance of the linear solver") pot.add_option("--relTol", type="float", dest="relTol", default=None, help="Overwrite the relative tolerance of the linear solver") pot.add_option("--no-write-p", action="store_false", dest="writep", default=True, help="Don't write pressure p") pot.add_option("--pRefCell", type="int", dest="pRefCell", default=None, help="Sets the number of the reference cell for closed cases") pot.add_option("--pRefValue", type="int", dest="pRefValue", default=None, help="Sets the pressure reference value for closed cases") self.parser.add_option_group(pot) CommonParallel.addOptions(self) CommonStandardOutput.addOptions(self) CommonServer.addOptions(self,False) CommonVCSCommit.addOptions(self)
def addOptions(self): CommonClearCase.addOptions(self) CommonPlotOptions.addOptions(self) self.parser.add_option("--steady-run", action="store_true", default=False, dest="steady", help="This is a steady run. Stop it after convergence") CommonReportUsage.addOptions(self) CommonReportRunnerData.addOptions(self) CommonStandardOutput.addOptions(self) CommonParallel.addOptions(self) CommonRestart.addOptions(self) CommonPlotLines.addOptions(self) CommonSafeTrigger.addOptions(self) CommonWriteAllTrigger.addOptions(self) CommonLibFunctionTrigger.addOptions(self) CommonServer.addOptions(self) CommonVCSCommit.addOptions(self)
def run(self, console_off=False): # Instantiate the server instance , and start it. self.server = CommonServer(self.addr, self.level, self.num_rthreads, self.dispatch_handlers, self.startup_functions) self.server.serve_forever(console_off)
class CommonHandler(): # Provide platform to write functions of two type , startup function and # request-based functions. FILENAME_CONFIG_DIR = os.path.join(ROYSTONEA_ROOT, "etc") FILENAME_DEFAULT_CONFIG = 'default_cfg.py' FILENAME_MY_CONFIG = None level = 'prototype' num_rthreads = 4 # Functions bound in startup_functions will perform at server start. def __init__(self, host, port): self.host = host self.port = int(port) self.addr = (host, int(port)) # Record Label, Addr, Parent Addr, Children Addrs and something about hierachy self.loadConfig() # load some static setting stored in file. # Functions bound in dispatch_handlers will be triggered by request to perform. self.dispatch_handlers = { 'CmdShutdownTheChildrenReq': self. CmdShutdownTheChildren, # Shutdown remote machine 's children. 'CmdShutdownChildrenReq': self.CmdShutdownChildren, # Shutdown self's children 'CmdShutdownTheReq': self.CmdShutdownThe, # Shutdown specific machine 'CmdShutdownReq': self.CmdShutdown, # Recv shutdown order. 'CmdFreezeRThreadReq': self. CmdFreezeRThread, # Freeze the current thread who catch this request. 'CmdGetPingReq': self. CmdGetPing, # Ping other CommonHandler-based machine, and return msg. 'CmdPingReq': self. CmdBePinged, # Be ping, just return emtpy for testing network status. 'CmdGetPMRelationReq': self.CmdGetPMRelation, # Return the current pm_relation. 'CmdSetPMRelationReq': self.CmdSetPMRelation, # Set the pm_relation. 'CmdGetThePMRelationReq': self.CmdGetThePMRelation, 'CmdSetThePMRelationReq': self.CmdSetThePMRelation, 'CmdGetChildrenPMRelationsReq': self.CmdGetChildrenPMRelations, 'CmdUpdatePMRelationReq': self.CmdUpdatePMRelation, 'CmdGetParentReq': self.CmdGetParent, # Get the parent address. 'CmdSetParentReq': self.CmdSetParent, # Set the parent address. 'CmdGetChildrenReq': self.CmdGetChildren, # Get the children addresses as list. 'CmdSetChildrenReq': self.CmdSetChildren, # Set the children addresses. 'CmdAddChildReq': self.CmdAddChild, } self.startup_functions = [ self.showPMRelation, ] def run(self, console_off=False): # Instantiate the server instance , and start it. self.server = CommonServer(self.addr, self.level, self.num_rthreads, self.dispatch_handlers, self.startup_functions) self.server.serve_forever(console_off) ''' base methods ''' def loadConfig(self): # Load default config first, then load my-config to overwrite data with the name # Let cfg_dict be the global_variable space in execfile method performing. cfg_dict = dict() cfg_abspath = os.path.join(self.FILENAME_CONFIG_DIR, self.FILENAME_DEFAULT_CONFIG) execfile(cfg_abspath, cfg_dict) # Let local setting overwrite default setting if self.FILENAME_MY_CONFIG: my_cfg_dict = dict() mycfg_abspath = os.path.join(self.FILENAME_CONFIG_DIR, self.FILENAME_MY_CONFIG) execfile(mycfg_abspath, my_cfg_dict) ''' Let local override global ''' for k in my_cfg_dict.keys(): cfg_dict[k] = my_cfg_dict[k] # clean up bulltin module in globals, it useless. del cfg_dict['__builtins__'] self.config = cfg_dict def setConfig(self, cfg_dict, overwrite=False): # set config if overwrite: self.config = cfg_dict else: self.config.update(cfg_dict) ''' Main methods ''' def setThePMRelation(self, addr, pm_relation): req = Message.CmdSetPMRelationReq(pm_relation=pm_relation) res = Client.send_message(addr, pm_relation) return res def getChildrenPMRelations(self): pm_relations = list() for addr in self.server.pm_relation.children_addrs: req = Message.CmdGetPMRelationReq() res = Client.send_message(addr, req) pm_relations.append(res) return pm_relations def getPMRelation(self): # I hope every function defined by user should use getPMRelation method to get # a of PMRelation by call-by-value to know its hierrachy. Because it may cause # inconsistent when pm_relation was modified during processing the request or # other works if you ref the self.server.pm_relation. return copy.deepcopy(self.server.pm_relation) def setPMRelation(self, relation): self.server.pm_relation.overwrite(relation) def updatePMRelation(self, relation): self.server.pm_relation.update(relation) def showPMRelation(self): print(self.server.pm_relation.dump_pretty()) ''' Requests-based Methods ''' def CmdShutdownChildren(self, req): req_shutdown = Message.CmdShutdownReq( chain_shutdown=req.chain_shutdown) for addr in self.server.pm_relation.children_addrs: res = Client.send_message(addr, req_shutdown) return Message.CmdShutdownTheRes() def CmdShutdownTheChildren(self, req): dest_addr = req.dest_addr req = Message.CmdShutdownChildrenReq(chain_shutdown=req.chain_shutdown) res = Client.send_message(dest_addr, req) return Message.CmdShutdownTheChildrenRes() def CmdShutdownThe(self, req): addr = req.dest_addr req = Message.CmdShutdownReq(chain_shutdown=req.chain_shutdown) res = Client.send_message(addr, req) return Message.CmdShutdownTheRes() def CmdShutdown(self, req): time.sleep(req.after_secs) if req.chain_shutdown: req_shutdown = Message.CmdShutdownReq() for addr in self.server.pm_relation.children_addrs: try: res = Client.send_message(addr, req_shutdown) print("child@{addr} closed.".format(addr='%s:%d' % (addr[0], addr[1]))) except Exception as e: print("child@{addr} failed to close. error msg: {msg}". format(addr='%s:%d' % (addr[0], addr[1]), msg='%s' % e)) self.server.threadCallShutdown() print('Ready to close self') return Message.CmdShutdownRes() def CmdFreezeRThread(self, req): time.sleep(req.secs) return Message.CmdFreezeRThreadRes() def CmdGetPing(self, req): from_addr = self.addr dest_addr = req.dest_addr times = req.times msg = '' req = Message.CmdPingReq() try: for i in xrange(times): start = time.time() res = Client.send_message(dest_addr, req) intval = time.time() - start msg += '{times} trial: from {fromaddr} pings {destaddr} in {secs}\n'.format( times=times, fromaddr=from_addr, destaddr=dest_addr, secs=intval) except socket.error: msg += 'Fail to connect to {destaddr}'.format(destaddr=dest_addr) return Message.CmdGetPingRes(msg=msg) def CmdBePinged(self, req): return Message.CmdPingRes() def CmdGetPMRelation(self, req): r = self.getPMRelation() return Message.CmdGetPMRelationRes( pm_relation=r, dump_one_row='%s' % r, dump_two_rows=r.dump_two_rows(), dump_children_rows=r.dump_children_rows(), dump_pretty=r.dump_pretty()) def CmdSetPMRelation(self, req): self.setPMRelation(req.pm_relation) return Message.CmdSetPMRelationRes() def CmdGetThePMRelation(self, req): # get specific machine's pm_relation @ addr addr = req.dest_addr req = Message.CmdGetPMRelationReq() res = Client.send_message(addr, req) return Message.CmdGetThePMRelationRes( pm_relation=res.pm_relation, dump_one_row=res.dump_one_row, dump_two_rows=res.dump_two_rows, dump_children_rows=res.dump_children_rows, dump_pretty=res.dump_pretty) def CmdSetThePMRelation(self, req): addr = req.dest_addr pm_relation = req.pm_relation res = self.setThePMRelation(addr, pm_relation) return Message.CmdSetThePMRelationRes() def CmdGetChildrenPMRelations(self, req): res_pm_relations = self.cmdGetChildrenPMRelations() return Message.CmdGetChildrenPMRelationsRes( res_pm_relations=res_pm_relations) def CmdUpdatePMRelation(self, req): self.updatePMRelation(req.pm_relation) return Message.CmdUpdatePMRelationRes() def CmdGetParent(self, req): parent = self.server.pm_relation.parent_addr return Message.CmdGetParentRes(parent_addr=parent) def CmdSetParent(self, req): parent = req.parent_addr self.server.pm_relation.setParentAddr(parent) return Message.CmdSetParentRes() def CmdGetChildren(self, req): children = self.server.pm_relation.children_addrs return Message.CmdGetChildrenRes(children_addrs=children) def CmdSetChildren(self, req): children = req.children_addrs self.server.pm_relation.setChildrenAddrs(children) return Message.CmdSetChildrenRes() def CmdAddChild(self, req): child_addr = req.child_addr if not child_addr in self.server.pm_relation.children_addrs: self.server.pm_relation.children_addrs.append(child_addr) return Message.CmdAddChildRes()
def addOptions(self): CommonLibFunctionTrigger.addOptions(self) CommonServer.addOptions(self,False) CommonVCSCommit.addOptions(self)
def addOptions(self): if foamVersion()>=(1,6): self.defaultMethod="scotch" self.decomposeChoices+=[self.defaultMethod] self.decomposeChoices+=["parMetis"] spec=OptionGroup(self.parser, "Decomposition Specification", "How the case should be decomposed") spec.add_option("--method", type="choice", default=self.defaultMethod, dest="method", action="store", choices=self.decomposeChoices, help="The method used for decomposing (Choices: "+string.join(self.decomposeChoices,", ")+") Default: %default") spec.add_option("--n", dest="n", action="store", default=None, help="Number of subdivisions in coordinate directions. A python list or tuple (for simple and hierarchical)") spec.add_option("--delta", dest="delta", action="store", type="float", default=None, help="Cell skew factor (for simple and hierarchical)") spec.add_option("--order", dest="order", action="store", default=None, help="Order of decomposition (for hierarchical)") spec.add_option("--processorWeights", dest="processorWeights", action="store", default=None, help="The weights of the processors. A python list. Used for metis, scotch and parMetis") spec.add_option("--globalFaceZones", dest="globalFaceZones", action="store", default=None, help="""Global face zones. A string with a python list or an OpenFOAM-list of words. Used for the GGI interface. Ex: '["GGI_Z1","GGI_Z2"]' or '(GGI_Z1 GGI_Z2)'""") spec.add_option("--dataFile", dest="dataFile", action="store", default=None, help="File with the allocations. (for manual)") self.parser.add_option_group(spec) behave=OptionGroup(self.parser, "Decomposition behaviour", "How the program should behave during decomposition") behave.add_option("--test", dest="test", action="store_true", default=False, help="Just print the resulting dictionary") behave.add_option("--clear", dest="clear", action="store_true", default=False, help="Clear the case of previous processor directories") behave.add_option("--no-decompose", dest="doDecompose", action="store_false", default=True, help="Don't run the decomposer (only writes the dictionary") behave.add_option("--decomposer", dest="decomposer", action="store", default="decomposePar", help="The decompose Utility that should be used") self.parser.add_option_group(behave) work=OptionGroup(self.parser, "Additional work", "What else should be done in addition to decomposing") work.add_option("--constant-link", dest="doConstantLinks", action="store_true", default=False, help="Add links to the contents of the constant directory to the constant directories of the processor-directories") self.parser.add_option_group(work) CommonMultiRegion.addOptions(self) CommonStandardOutput.addOptions(self) CommonServer.addOptions(self,False) CommonVCSCommit.addOptions(self)