def parse(self, nr=None, exactNr=True): """ parse the options @param nr: minimum number of arguments that are to be passed to the application 3 is default for pre-1.5 versions of OpenFOAM """ (self.options, self.args) = self.parse_args(args=self.argLine) if "foamVersion" in dir(self.options): if self.options.foamVersion != None: if self.options.force32 and self.options.force64: error("A version can't be 32 and 64 bit at the same time") self.__foamVersionChanged = True self.__oldEnvironment = deepcopy(environ) changeFoamVersion(self.options.foamVersion, force64=self.options.force64, force32=self.options.force32, compileOption=self.options.compileOption, foamCompiler=self.options.foamCompiler, wmCompiler=self.options.wmCompiler) elif self.options.force32 or self.options.force64: warning( "Forcing version to be 32 or 64 bit, but no version chosen. Doing nothing" ) elif self.options.compileOption: warning( "No OpenFOAM-version chosen. Can't set compile-option to", self.options.compileOption) if nr == None: if oldApp(): nr = 3 else: nr = 1 if len(self.args) < nr: self.error("Too few arguments (%d needed, %d given)" % (nr, len(self.args))) maxNr = nr if not oldApp(): if "-case" in self.args: maxNr += 2 if exactNr and len(self.args) > maxNr: self.error("Too many arguments (%d needed, %d given)" % (nr, len(self.args))) tmp = self.args self.args = [] for a in tmp: if a.find(" ") >= 0 or a.find("(") >= 0: a = "\"" + a + "\"" self.args.append(a)
def parse(self,nr=None,exactNr=True): """ parse the options :param nr: minimum number of arguments that are to be passed to the application 3 is default for pre-1.5 versions of OpenFOAM """ (self.options,self.args)=self.parse_args(args=self.argLine) if "foamVersion" in dir(self.options): if self.options.foamVersion!=None: if self.options.force32 and self.options.force64: error("A version can't be 32 and 64 bit at the same time") self.__foamVersionChanged=True self.__oldEnvironment=deepcopy(environ) changeFoamVersion(self.options.foamVersion, force64=self.options.force64, force32=self.options.force32, compileOption=self.options.compileOption, foamCompiler=self.options.foamCompiler, wmCompiler=self.options.wmCompiler) elif self.options.force32 or self.options.force64: warning("Forcing version to be 32 or 64 bit, but no version chosen. Doing nothing") elif self.options.compileOption: warning("No OpenFOAM-version chosen. Can't set compile-option to",self.options.compileOption) if nr==None: if oldApp(): nr=3 else: nr=1 if len(self.args)<nr: self.error("Too few arguments (%d needed, %d given)" %(nr,len(self.args))) maxNr=nr if not oldApp(): if "-case" in self.args: maxNr+=2 if exactNr and len(self.args)>maxNr: self.error("Too many arguments (%d needed, %d given)" %(nr,len(self.args))) tmp=self.args self.args=[] for a in tmp: if a.find(" ")>=0 or a.find("(")>=0: a="\""+a+"\"" self.args.append(a)
def __init__(self, basename, arrayJob=False, hardRestart=False, autoParallel=True, doAutoReconstruct=None, foamVersion=None, compileOption=None, useFoamMPI=False, multiRegion=False, parameters={}, isDecomposed=False): """Initializes the Job @param basename: Basis name of the job @param arrayJob: this job is a parameter variation. The tasks are identified by their task-id @param hardRestart: treat the job as restarted @param autoParallel: Parallelization is handled by the base-class @param doAutoReconstruct: Automatically reconstruct the case if autoParalellel is set. If the value is None then it is looked up from the configuration @param foamVersion: The foam-Version that is to be used @param compileOption: Forces compile-option (usually 'Opt' or 'Debug') @param useFoamMPI: Use the OpenMPI supplied with OpenFOAM @param multiRegion: This job consists of multiple regions @param parameters: Dictionary with parameters that are being passed to the Runner @param isDecomposed: Assume that the job is already decomposed""" # print_(os.environ) if not "JOB_ID" in os.environ: error("Not an SGE-job. Environment variable JOB_ID is missing") self.jobID=int(os.environ["JOB_ID"]) self.jobName=os.environ["JOB_NAME"] self.basename=path.join(path.abspath(path.curdir),basename) sgeRestarted=False if "RESTARTED" in os.environ: sgeRestarted=(int(os.environ["RESTARTED"])!=0) if sgeRestarted or hardRestart: self.restarted=True else: self.restarted=False if foamVersion==None: foamVersion=config().get("OpenFOAM","Version") changeFoamVersion(foamVersion,compileOption=compileOption) if not "WM_PROJECT_VERSION" in os.environ: error("No OpenFOAM-Version seems to be configured. Set the foamVersion-parameter") self.autoParallel=autoParallel self.doAutoReconstruct=doAutoReconstruct if self.doAutoReconstruct==None: self.doAutoReconstruct=config().getboolean("ClusterJob","doAutoReconstruct") self.multiRegion=multiRegion self.parameters=parameters self.hostfile=None self.nproc=1 if "NSLOTS" in os.environ: self.nproc=int(os.environ["NSLOTS"]) self.message("Running on",self.nproc,"CPUs") if self.nproc>1: # self.hostfile=os.environ["PE_HOSTFILE"] self.hostfile=path.join(os.environ["TMP"],"machines") if config().getboolean("ClusterJob","useMachineFile"): self.message("Using the machinefile",self.hostfile) self.message("Contents of the machinefile:",open(self.hostfile).readlines()) else: self.message("No machinefile used because switched off with 'useMachineFile'") self.ordinaryEnd=True self.listenToTimer=False self.taskID=None self.arrayJob=arrayJob if self.arrayJob: self.taskID=int(os.environ["SGE_TASK_ID"]) if not useFoamMPI and not foamVersion in eval(config().get("ClusterJob","useFoamMPI",default='[]')): ## prepend special paths for the cluster self.message("Adding Cluster-specific paths") os.environ["PATH"]=config().get("ClusterJob","path")+":"+os.environ["PATH"] os.environ["LD_LIBRARY_PATH"]=config().get("ClusterJob","ldpath")+":"+os.environ["LD_LIBRARY_PATH"] self.isDecomposed=isDecomposed
def execute(self,para,log): print_(" Changing OpenFOAM-Version to",self.version) changeFoamVersion(self.version) return True,None