Python wrapper for running instances of trisurf-ng
Samo Penic
2019-07-15 7f64589f9f172b7965a086bcceed8c47a51daca7
trisurf/trisurf.py
@@ -20,6 +20,9 @@
TS_RUNNING=2 # process is running
TS_COMPLETED=3 #simulation is completed
#namespace variable. Seems the best place to put the variable in :)
_analysis_list={}
class FileContent:
   '''
   Class is helpful for reading and writting the specific files.
@@ -258,6 +261,35 @@
      fields=shlex.split(lines[1])
      epoch2=fields[0]
      return (fields[1])
   def getColumn(self,n=0):
      lines=self.readText().splitlines()
      col=[]
      name=lines[0].split()[n]
      for line in lines:
         col.append(line.split()[n])
      return col[2:],name
   def getTable(self):
      lines=self.readText().splitlines()
      keys=lines[0].split()
      table={}
      def num(s):
         try:
            return int(s)
         except ValueError:
            return float(s)
      for key in keys:
         table[key]=[]
      for line in lines:
         fields=line.split()
         for i in range(0,len(keys)):
            try:
               value=num(fields[i])
               table[keys[i]].append(value)
            except:
               pass
      return table
      
   def readText(self):
@@ -433,12 +465,7 @@
   def setMaindir(self,prefix,variables):
      maindir=""
      for p,v in zip(prefix,variables):
         if(v=="xk0"):
            tv=str(round(float(self.Tape.config[v])))
            if sys.version_info<(3,0):
               tv=str(int(float(self.Tape.config[v])))
         else:
            tv=self.Tape.config[v]
         tv=str(self.Tape.config[v])
         maindir=maindir+p+tv
      self.maindir=maindir
      return
@@ -487,13 +514,24 @@
      self.Comment.writefile(data,mode=mode)
   def getLastVTU(self):
   def getLastVTUold(self):
      vtuidx=self.getLastIteration()-int(self.Tape.getValue("inititer"))
      if vtuidx<0:
         return None
      else:
         return  'timestep_{:06d}.vtu'.format(vtuidx)
   def getLastVTU(self):
      flist=[]
      for file in os.listdir(self.Dir.fullpath()):
         if file.endswith(".vtu"):
            flist.append(file)
      flist.sort()
      if(len(flist)==0):
         return(-1)
      else:
         return(flist[-1])
   def __str__(self):
      if(self.getStatus()==0):
         str=" not running."