示例#1
0
        def changeName(bnd, target):
            found = False

            for val in bnd:
                if val == bName:
                    found = True
                elif found:
                    bnd[bnd.index(bName)] = nName
                    break

            if not found:
                self.warning("Boundary", bName, "not found in", bnd[::2])
                return None
            else:
                if self.opts.timestep:
                    print_("Updating the files of timestep",
                           self.opts.timestep)
                    td = TimeDirectory(path.join(target, ".."),
                                       self.opts.timestep,
                                       yieldParsedFiles=True)

                    for f in td:
                        try:
                            print_("Updating", f.name)
                            f["boundaryField"][nName] = f["boundaryField"][
                                bName]
                            del f["boundaryField"][bName]
                            f.writeFile()
                        except KeyError:
                            print_("No boundary", bName, "Skipping")
                return bnd
示例#2
0
 def __iter__(self):
     self.reread()
     for key in self.times:
         yield TimeDirectory(self.name,
                             self.fullPath(key),
                             region=self.region,
                             tolerant=self.tolerant)
示例#3
0
    def __getitem__(self,key):
        self.reread()

        ind=self.timeName(key)
        if ind==None:
            raise KeyError(key)
        else:
            return TimeDirectory(self.name, self.fullPath(ind), region=self.region)
示例#4
0
    def __setitem__(self,key,value):
        self.reread()
        if type(key)!=str:
            raise TypeError(type(key),"of",key,"is not 'str'")

        if type(value)!=TimeDirectory:
            raise TypeError(type(value),"is not TimeDirectory")

        dest=TimeDirectory(self.name, self.fullPath(key), create=True,region=self.region)
        dest.copy(value)

        self.reread(force=True)
 def polyMeshDir(self, region=None, time=None, processor=None):
     """:param region: Specify the region for cases with more than 1 mesh
     :return: the name of the C{polyMesh}
     :param time: Time for which the  mesh should be looked at
     :param processor: Name of the processor directory for decomposed cases
     :rtype: str"""
     if region == None and self.region != None:
         region = self.region
     if time == None:
         return path.join(
             self.constantDir(region=region, processor=processor),
             "polyMesh")
     else:
         return path.join(
             TimeDirectory(self.name,
                           time,
                           region=region,
                           processor=processor).name, "polyMesh")
示例#6
0
    def modifyGGIPatchDefinitionInTimeDirs(self, caseDir, patchName, ggiType, timeDirs):
        description="""\
Modify the definition of a ggi patch in the time directories
        """
        regex = fnmatch.translate(timeDirs)

        reobj = re.compile(regex)

        for timeDir in listdir(caseDir):
            if reobj.match(timeDir):
                print_("    Modifying ggi boundaryFields in timeDir", timeDir, "for patch", patchName)

                td=TimeDirectory(caseDir, timeDir, yieldParsedFiles=True)

                for f in td:
                    print_("        Modifying field", f.name)
                    f["boundaryField"][patchName]["type"]=ggiType
                    f.writeFile()
示例#7
0
    def run(self):
        fName=self.parser.getArgs()[0]
        bName=self.parser.getArgs()[1]
        nName=self.parser.getArgs()[2]

        boundary=ParsedParameterFile(path.join(".",fName,"constant","polyMesh","boundary"),debug=False,boundaryDict=True)

        bnd=boundary.content

        if type(bnd)!=list:
            self.error("Problem with boundary file (not a list)")

        found=False

        for val in bnd:
            if val==bName:
                found=True
            elif found:
                bnd[bnd.index(bName)]=nName
                break

        if not found:
            self.error("Boundary",bName,"not found in",bnd[::2])

        if self.opts.test:
            print_(boundary)
        else:
            boundary.writeFile()
            self.addToCaseLog(fName)

            if self.opts.timestep:
                print_("Updating the files of timestep",self.opts.timestep)
                td=TimeDirectory(fName,self.opts.timestep,
                                 yieldParsedFiles=True)

                for f in td:
                    print_("Updating",f.name)
                    f["boundaryField"][nName]=f["boundaryField"][bName]
                    del f["boundaryField"][bName]
                    f.writeFile()
示例#8
0
 def testTimeDirectoryCreating(self):
     self.assertEqual(len(SolutionDirectory(self.theFile)), 1)
     test = TimeDirectory(self.theFile, "42", create=True)
     self.assertEqual(len(test), 0)
     self.assertEqual(len(SolutionDirectory(self.theFile)), 2)