Пример #1
0
    def generateMesh(self):
        """
        Generates the CUBIT journal,
        and runs this with the pre- and post-commands that are useful
        for generating a mesh.
        
        Also saves the journal as mesh.jou for later reference
        
        Side-effect: Sets lockdown, and generates a solid if necessary
        
        Returns any keys not found. 
        """ 
        print "AcdOptiMeshInstance::generateMesh()"
        
        if not self.geometryInstance.lockdown:
            self.geometryInstance.generateGeometry()

        #Preparation        
        params = self.generatePattern()
        templateFile = self.meshTemplate.meshTemplateFile
        
        #Make the journal for later reference
        refJouFileName = os.path.join(self.folder, "mesh.jou")
        if os.path.isfile(refJouFileName):
            os.remove(refJouFileName)
        templateFile.writeJouFile(params,refJouFileName,self.cubitMeshPreCommands, self.cubitMeshPostCommands)
        
        #Make the mesh
        shutil.copy(os.path.join(self.geometryInstance.folder, "geom.cub"), os.getcwd())
        notFound = templateFile.runCubit(params, preCommands=self.cubitMeshPreCommands,\
                                         postCommands=self.cubitMeshPostCommands)
        os.rename("mesh.gen", os.path.join(self.folder, "mesh.gen"))
        
        #Convert the mesh to NetCDF
        (acdoutput, badelems) = AcdOptiAcdtoolWrapper.convertGenNcdf(os.path.join(self.folder, "mesh.gen"),
                                             os.path.join(self.folder, "mesh.ncdf"))

        self.setLockdown()

        if badelems > 0:
            self.meshBad = True
            self.write()
            raise AcdOptiException_meshInstance_generateFail("Mesh had ISOTEs -- not a good mesh! (mesh still generated)")
        else:
            self.meshBad = False
            self.write()
            
        return notFound
Пример #2
0
    def runAnalysis(self):
        print "RFpost_local::runAnalysis()"        
        assert not self.lockdown
        
        #Generate the setup file
        self.lockdown = True

        origResultDir = self.localSolver.metaSetup['RFField']['children']['ResultDir']['value'] #Subdirectory whith the data
        dataPath = os.path.join(self.folder, self.instName, "data") #Path to symlink to data folder
        dataPath2 = os.path.join(dataPath, origResultDir) #Path to O3P etc. results thorough symlink
        self.localSolver.metaSetup['RFField']['children']['ResultDir'].setValSingle("value", os.path.join("data", origResultDir))
        
        self.localSolver.generateSetup()
        self.localSolver.lockdown = True

        #Create a symlink to avoid long folder names (ACDtool doesn't like that)
        if os.path.islink(dataPath):
            os.unlink(dataPath)
        os.symlink(self.runConfig.finishedFolder, dataPath) #UNIX only!

        #Modify the postprocess.in file to the right path
        shutil.copy(os.path.join(dataPath2, "VECTOR", "postprocess.in"),\
                    os.path.join(self.folder, self.instName, "postprocess.in.bak"))
        
        postFile = AcdOptiFileParser_KVC(os.path.join(dataPath2, "VECTOR", "postprocess.in"),"rw")
        #print postFile.dataDict
        postFile.dataDict["ModelInfo"].setValSingle("File", os.path.join(dataPath, "mesh.ncdf"))
        postFile.dataDict["CheckPoint"].setValSingle("Directory", os.path.join(os.path.join(dataPath2, "VECTOR")))
        postFile.write()
        
        #Run AcdTool!
        try:
            AcdOptiAcdtoolWrapper.rfPost("rfPost.in", os.path.join(self.folder, self.instName))
        except:
            self.localSolver.metaSetup['RFField']['children']['ResultDir'].setValSingle("value", origResultDir)
            self.localSolver.write()
        
            shutil.copy(os.path.join(self.folder, self.instName, "postprocess.in.bak"),\
                        os.path.join(dataPath2, "VECTOR", "postprocess.in"))
            os.unlink(dataPath)
            
            raise

        #Restore stuff
        self.localSolver.metaSetup['RFField']['children']['ResultDir'].setValSingle("value", origResultDir)
        self.localSolver.write()
        
        shutil.copy(os.path.join(self.folder, self.instName, "postprocess.in.bak"),\
                    os.path.join(dataPath2, "VECTOR", "postprocess.in"))
        
        os.unlink(dataPath)
        
        #Parse output
        ifile = open(os.path.join(self.folder, self.instName, "rfpost.out"), 'r')
        fileData = ifile.read()
        ifile.close()
        
        #Save results
        try:
            L = float(self.settings["L"])
        except ValueError:
            print 'Couldnt parse self.settings["L"]'
            L = -1.0;
        addDic = self.parseData(fileData, L)
        for (k,v) in addDic:
            self.exportResults.pushBack(k,v)
        
        self.write()
Пример #3
0
    def runAnalysis(self):
        print "ModeFileRecalc::runAnalysis()"        
        assert not self.lockdown
        
        #Generate the setup file
        self.lockdown = True

        origResultDir = self.settings["ResultDir"] #Subdirectory whith the data
        dataPath = os.path.join(self.folder, self.instName, "data") #Path to symlink to data folder
        dataPath2 = os.path.join(dataPath, origResultDir) #Path to O3P etc. results thorough symlink
        
        #Create a symlink to avoid long folder names (ACDtool doesn't like that)
        if os.path.islink(dataPath):
            os.unlink(dataPath)
        os.symlink(self.runConfig.finishedFolder, dataPath) #UNIX only!
        
        #Modify the postprocess.in file to the right path
        shutil.copy(os.path.join(dataPath2, "VECTOR", "postprocess.in"),\
                    os.path.join(self.folder, self.instName, "postprocess.in.bak"))
        
        postFile = AcdOptiFileParser_KVC(os.path.join(dataPath2, "VECTOR", "postprocess.in"),"rw")
        postFile.dataDict["ModelInfo"].setValSingle("File", os.path.join(dataPath, "mesh.ncdf"))
        postFile.dataDict["CheckPoint"].setValSingle("Directory", os.path.join(os.path.join(dataPath2, "VECTOR")))
        postFile.write()
        
        #Check that we don't destroy any data...
        if os.path.isfile(os.path.join(dataPath, "acdtool.log")) or os.path.isfile(os.path.join(dataPath, "acdtool.warn")):
            #Restore stuff
            shutil.copy(os.path.join(self.folder, self.instName, "postprocess.in.bak"),\
                        os.path.join(dataPath2, "VECTOR", "postprocess.in"))
            os.unlink(dataPath)
            raise ModeFileRecalcException_runAna("acdtool log files already exists")
        
        #Move the old modefile out of the way...
        oldFilesFolder = os.path.join(self.folder,self.instName, "oldModes")
        if os.path.isdir(oldFilesFolder):
            offls = os.listdir(oldFilesFolder)
            if len(offls) > 0:
                shutil.copy(os.path.join(self.folder, self.instName, "postprocess.in.bak"),\
                            os.path.join(dataPath2, "VECTOR", "postprocess.in"))   
                raise ModeFileRecalcException_runAna
        else:
            os.mkdir(oldFilesFolder)
        files = os.listdir(dataPath2)
        movedFiles = []
        for f in files:
            if f.startswith("mode.") and f.endswith(".mod"):
                shutil.move( os.path.join(dataPath2,f), os.path.join(oldFilesFolder,f) )
                movedFiles.append(f)
        
        #Run AcdTool!
        try:
            AcdOptiAcdtoolWrapper.eigentomode(origResultDir, dataPath)
        except:
            shutil.move( os.path.join(dataPath,"acdtool.log"), os.path.join(self.folder,self.instName,"acdtool.log"))
            raise
        
        #Move newly created files to results dir
        files = os.listdir(dataPath2)
        for f in files:
            if f.startswith("mode.") and f.endswith(".mod"):
                shutil.move( os.path.join(dataPath2,f), os.path.join(self.folder,self.instName,f)) 
        shutil.move( os.path.join(dataPath,"acdtool.log"), os.path.join(self.folder,self.instName,"acdtool.log"))
        shutil.move( os.path.join(dataPath,"acdtool.warn"), os.path.join(self.folder,self.instName,"acdtool.warn"))
        
        #Restore stuff
        shutil.copy(os.path.join(self.folder, self.instName, "postprocess.in.bak"),\
                    os.path.join(dataPath2, "VECTOR", "postprocess.in"))
        
        for f in movedFiles:
            shutil.move(os.path.join(oldFilesFolder,f), os.path.join(dataPath2,f))
        os.rmdir(oldFilesFolder)
        
        os.unlink(dataPath)
        
        #Save results
        self.exportResults.pushBack("Job", "complete")
        
        self.write()