Beispiel #1
0
    def add_phase_dist(self, tsr, rho, tmax):
#        tsr.cohere = pyts.cohereModels.main.none()
        tsr.cohere = pyts.cohereModels.main.nwtc()
        tsr.stress = pyts.stressModels.main.uniform(0,0,0)
        tsr.phase = Rinker(rho, self.mu)
        cg = tsr.grid
        tsr.grid = tsGrid(center=cg.center, ny=cg.n_y, nz=cg.n_z,
                          height=cg.height, width=cg.width,
                          time_sec=tmax, dt=cg.dt)
        
        return tsr
Beispiel #2
0
    def add_phase_dist(self, tsr, rho, tmax):
        #        tsr.cohere = pyts.cohereModels.main.none()
        tsr.cohere = pyts.cohereModels.main.nwtc()
        tsr.stress = pyts.stressModels.main.uniform(0, 0, 0)
        tsr.phase = Rinker(rho, self.mu)
        cg = tsr.grid
        tsr.grid = tsGrid(center=cg.center,
                          ny=cg.n_y,
                          nz=cg.n_z,
                          height=cg.height,
                          width=cg.width,
                          time_sec=tmax,
                          dt=cg.dt)

        return tsr
Beispiel #3
0
def turbsim(fname):
    """
    Read TurbSim format (.bts) full-field time-series binary
    data files.

    Parameters
    ----------
    fname : str
            The filename from which to read the data.

    Returns
    -------
    tsdata : :class:`tsdata <pyts.main.tsdata>`
             The TurbSim data contained in the binary data file.

    """
    fname = checkname(fname, ['.bts'])
    u_scl = np.zeros(3, np.float32)
    u_off = np.zeros(3, np.float32)
    # fl = file(fname, 'rb')
    fl = open(fname, 'rb')
    (junk, n_z, n_y, n_tower, n_t, dz, dy, dt, uhub, zhub, z0, u_scl[0],
     u_off[0], u_scl[1], u_off[1], u_scl[2], u_off[2],
     strlen) = unpack(e + 'h4l12fl', fl.read(70))
    center = z0 + (n_z - 1) * dz / 2.0
    #print fname, u_scl, u_off
    desc_str = fl.read(strlen)  # skip these bytes.
    nbt = 3 * n_y * n_z * n_t
    dat = np.rollaxis(
        np.fromstring(fl.read(2 * nbt), dtype=np.int16).astype(
            np.float32).reshape([3, n_y, n_z, n_t], order='F'), 2, 1)
    dat -= u_off[:, None, None, None]
    dat /= u_scl[:, None, None, None]
    # Create the tsdata object.
    grid = tsGrid(
        center=center,
        ny=n_y,
        nz=n_z,
        dy=dy,
        dz=dz,
        dt=dt,
        nt=n_t,
    )
    out = tsdata(grid)
    out.uprof = dat.mean(-1)
    out.uturb = dat - out.uprof[:, :, :, None]
    return out
Beispiel #4
0
def run2():
    tsinput = ptsin.read(fname)
    tsinput['URef'] = 16.0
    tsr = ptsm.cfg2tsrun(tsinput)

    tsr.cohere = pyts.cohereModels.main.nwtc()
    tsr.stress = pyts.stressModels.main.uniform(0,0,0)
    rho = 0.5
    tmax = 50.0
    tsr.phase = Rinker(rho, np.pi)  ### pgraf turned it off for testing!
    cg = tsr.grid
    tsr.grid = tsGrid(center=cg.center, ny=cg.n_y, nz=cg.n_z,
                      height=cg.height, width=cg.width,
                      time_sec=tmax, dt=cg.dt)
    tm0 = time.time()
    tsdata = tsr()  ## actually runs turbsim
    ptsm.write(tsdata, tsinput, fname=outname+"2")
    print('TurbSim exited normally, runtime was %g seconds' % (time.time() - tm0))
Beispiel #5
0
def run2():
    tsinput = ptsin.read(fname)
    tsinput['URef'] = 16.0
    tsr = ptsm.cfg2tsrun(tsinput)

    tsr.cohere = pyts.cohereModels.main.nwtc()
    tsr.stress = pyts.stressModels.main.uniform(0, 0, 0)
    rho = 0.5
    tmax = 50.0
    tsr.phase = Rinker(rho, np.pi)  ### pgraf turned it off for testing!
    cg = tsr.grid
    tsr.grid = tsGrid(center=cg.center,
                      ny=cg.n_y,
                      nz=cg.n_z,
                      height=cg.height,
                      width=cg.width,
                      time_sec=tmax,
                      dt=cg.dt)
    tm0 = time.time()
    tsdata = tsr()  ## actually runs turbsim
    ptsm.write(tsdata, tsinput, fname=outname + "2")
    print('TurbSim exited normally, runtime was %g seconds' %
          (time.time() - tm0))
            ### the random seed:
            ### bug somewhere in complicated pyts use of numpy (only when called inside multiprocessing)
            ### Success via cutting out the middle man!:
            if rs is None:
                tsr.randgen.seed(tsr.RandSeed)
            else:
                tsr.randgen.seed(rs)  ## this does nothing!
                np.random.seed(rs)  ### this does the trick!

            ###tsr = self.add_phase_dist(tsr, rho, tmax)
            tsr.cohere = pyts.cohereModels.main.nwtc()
            tsr.stress = pyts.stressModels.main.uniform(0,0,0)
            tsr.phase = Rinker(rho, np.pi)
            cg = tsr.grid
            tsr.grid = tsGrid(center=cg.center, ny=cg.n_y, nz=cg.n_z,
                         height=cg.height, width=cg.width,
                         time_sec=tmax, dt=cg.dt)

            tsdata = tsr()  ## actually runs turbsim
            ptsm.write(tsdata, tsinput, fname=tsoutname)

        # here we provide the means to link turbsim to fast:
        self.tswind_file = tsoutname
        self.tswind_dir = run_dir

if __name__ == "__main__":

    case_inputs = {}
    case_inputs[("TMax")] = {'vals':[10.], 'group':0}
    case_inputs[("Vhub")] = {'vals':[10., 11., 12.], 'group':1}
    case_inputs[("Rho")] = {'vals':[.2, .25, .3], 'group':1}
Beispiel #7
0
def bladed(fname, ):
    """
    Read Bladed format (.wnd, .bl) full-field time-series binary data files.

    Parameters
    ----------
    fname : str
            The filename from which to read the data.

    Returns
    -------
    tsdata : :class:`tsdata <pyts.main.tsdata>`
             The TurbSim data contained in the binary data file.

    """
    fname = checkname(fname, ['.wnd', '.bl'])
    with file(fname, 'rb') as fl:
        junk, nffc, ncomp, lat, z0, center = unpack(e + '2hl3f', fl.read(20))
        if junk != -99 or nffc != 4:
            raise IOError(
                "The file %s does not appear to be a valid 'bladed (.bts)' format file."
                % fname)
        ti = np.array(unpack(e + '3f', fl.read(12))) / 100
        dz, dy, dx, n_f, uhub = unpack(e + '3flf', fl.read(20))
        n_t = int(2 * n_f)
        fl.seek(12, 1)  # Unused bytes
        clockwise, randseed, n_z, n_y = unpack(e + '4l', fl.read(16))
        fl.seek(24, 1)  # Unused bytes
        nbt = ncomp * n_y * n_z * n_t
        dat = np.rollaxis(
            np.fromstring(fl.read(2 * nbt), dtype=np.int16).astype(
                np.float32).reshape([ncomp, n_y, n_z, n_t], order='F'), 2, 1)
    dat[0] += 1000.0 / ti[0]
    dat /= 1000. / (uhub * ti[:, None, None, None])
    # Create the grid object:
    dt = dx / uhub
    # Determine the clockwise value.
    if clockwise == 0:
        try:
            d = sum_scan(convname(fname, '.sum'))
            clockwise = d['clockwise']
        except IOError:
            warn("Value of 'CLOCKWISE' not specified in binary file, "
                 "and no .sum file found. Assuming CLOCKWISE = True.")
            clockwise = True
        except KeyError:
            warn("Value of 'CLOCKWISE' not specified in binary file, "
                 "and %s has no line containing 'clockwise'. Assuming "
                 "CLOCKWISE = True." % convname(fname, '.sum'))
            clockwise = True
    else:
        clockwise = bool(clockwise - 1)
    if clockwise:
        # flip the data back
        dat = dat[:, :, ::-1, :]
    # Create the tsdata object.
    grid = tsGrid(center=center,
                  ny=n_y,
                  nz=n_z,
                  dy=dy,
                  dz=dz,
                  dt=dt,
                  nt=n_t,
                  clockwise=clockwise)
    out = tsdata(grid)
    out.uprof = dat.mean(-1)
    out.uturb = dat - out.uprof[:, :, :, None]
    return out