Example #1
0
  def Read(self, filename, includeMc = False, subsample = 1):
    """
    Read a .stat file
    """
    
    def ParseRawS(s, delimiter):    
      newS = {}
      for key1 in s.keys():
        assert(not key1 in ["val", "value"])
        if isinstance(s[key1], dict):
          if len(s[key1].keys()) == 1 and s[key1].keys()[0] in ["val", "value"]:
            newS[str(key1)] = s[key1][s[key1].keys()[0]]
          else:
            subS = ParseRawS(s[key1], delimiter)
            newS[str(key1)] = {}
            for key2 in subS.keys():
              newS[str(key1)][str(key2)] = subS[key2]
        else:        
          rank = len(s[key1].shape)
          if rank > 1:
            assert(rank == 2)
            if includeMc:
              # Add in this vector
              
              # parser gives this in an inconvenient matrix order. Take the
              # transpose here to make life easier.
              newS[str(key1)] = s[key1].transpose()
              
            # Add in the vector field components
            for i in range(len(s[key1])):
              newS[str(key1) + delimiter + str(i + 1)] = s[key1][i]
          else:
            try:
              # Add in this scalar
              newS[str(key1)] = s[key1]
            except TypeError:
              debug.deprint("Type error for data " + str(s[key1]), 0)
              raise Exception("ParseRawS failure")
            except ValueError:
              debug.deprint("Value error for data " + str(s[key1]), 0)
              raise Exception("ParseRawS failure")
          
      return newS
        
    debug.dprint("Reading .stat file: " + filename)
    if subsample == 1:
      # Handle this case separately, as it's convenient to be backwards
      # compatible
      statParser = statfile.parser(filename)
    else:
      statParser = statfile.parser(filename, subsample = subsample)

    self._s = ParseRawS(statParser, self._delimiter)
    
    if "ElapsedTime" in self.keys():
      t = self["ElapsedTime"]
      if t.shape[0] > 0:
        debug.dprint("Time range: " + str((t[0], t[-1])))
      else:
        debug.dprint("Time range: No data")
    
    return
Example #2
0
def extract():
    table0 = []
    table0.append("\\begin{tabular}{c|ccccccc}\n")
    table0.append(
        "    & $\Nu$ & $v_{rms}$ & $\max(u|_{z=1})$ & $<u|_{z=1}>$ & $<T + \\bar{T}>$ & $<\phi>$ & $<W>$ \\\\\n"
    )
    table0.append("\hline\n")

    libspud.load_options(name + ".tfml")
    ioname = libspud.get_option("/io/output_base_name")
    Ra = libspud.get_option(
        "/system::Stokes/coefficient::RayleighNumber/type::Constant/rank::Scalar/value::WholeMesh/constant"
    )
    Di = libspud.get_option(
        "/system::Stokes/coefficient::DissipationNumber/type::Constant/rank::Scalar/value::WholeMesh/constant"
    )

    for n in ncells:
        dir_name = "run_" + ` n `
        chdir(dir_name)

        try:
            stat = parser(ioname + ".stat")
        except IOError:
            os.chdir("../")
            continue
        try:
            det = parser(ioname + ".det")
        except IOError:
            os.chdir("../")
            continue

        nu = -1.0 * (
            stat["Stokes"]["Temperature"]["FullTopSurfaceIntegral"][-1])
        v_rms = sqrt(stat["Stokes"]["Velocity"]["L2NormSquared"][-1]) * Ra
        v_surf_max = abs(det["Stokes"]["Velocity_0"]["Array"][:,
                                                              -1]).max() * Ra
        v_surf_int = stat["Stokes"]["Velocity"]["TopSurfaceIntegral"][-1] * Ra
        T_int = stat["Stokes"]["Temperature"]["FullIntegral"][-1]
        phi_int = stat["ViscousDissipation"]["ViscousDissipation"]["Integral"][
            -1] * Ra * Di
        W_int = stat["WorkDone"]["WorkDone"]["Integral"][-1] * Ra

        table0.append(
            "{0:2d}$\\times${0:2d} & {1:.3f} & {2:.3f} & {3:.3f} & {4:.3f} & {5:.3f} & {6:.3f} & {7:.3f} \\\\\n"
            .format(n, nu, v_rms, v_surf_max, v_surf_int, T_int, phi_int,
                    W_int))

        os.chdir("../")

    libspud.clear_options()

    Raind = int(round(Ra))
    Diind = '%d' % Di if Di == int(Di) else '%s' % Di
    f = file("../../../tables.dict", 'r')
    tables = pickle.load(f)
    f.close()

    table0.append("\hline\n")
    for code, values in tables[approx][Raind][Diind].iteritems():
        if len(values) > 0 and code in comparisoncodes:
            line = "Benchmark (" + code + ") & "
            for v in range(len(values) - 1):
                line += '%.3f' % values[v] + " & "
            line += '%.3f' % values[-1] + " \\\\\n"
            table0.append(line)
    table0.append("\\end{tabular}\n")

    for line in table0:
        print line[0:-1]

    filename = "table0.tex"
    filehandle = file(filename, 'w')
    filehandle.writelines(table0)
    filehandle.close()