예제 #1
0
파일: f3d.py 프로젝트: samfordin/TurbPlasma
    def __init__(self, shelldirname="", data_type=""):
        # If no rundir specified
        if len(shelldirname) == 0:  # Start init prompt
            shelldirname = raw_input('Please enter the rundir: ')
        self.rundir = opexp(shelldirname)
        # If data type not specified
        if len(data_type) == 0:
            self.data_type = raw_input(
                "Data Type? [(b)yte/ (d)ouble precision] ")
        else:
            self.data_type = data_type
# Parameters to load
        self.readparams=['Nx0_tot', 'Ny0_tot', 'Nz0_tot', 'ALX_TOT', 'ALY_TOT',\
        'ALZ_TOT', 'DTP', 'NOUTMOV', 'NPTS', 'SD', 'TEMPF','BX0','BY0','BZ0',\
        'DENLOBE']
        self.params=['nx', 'ny', 'nz', 'lx', 'ly', 'lz', 'dt', 'NOUTMOV', \
        'npts', 'SD', 'Temp','b0x','b0y','b0z','n_0']
        # Read parameters from file
        for i in range(len(self.readparams)):
            comm = "awk '/^ " + self.readparams[
                i] + " / {print $3}' " + self.rundir + "/paramfile"
            if syscomout(comm)[1].endswith(','):
                print self.params[i], '=', float(syscomout(comm)[1][:-1])
            else:
                print self.params[i], '=', float(syscomout(comm)[1])
            if syscomout("grep " + self.readparams[i] + " " + self.rundir +
                         "/paramfile")[0] == 0:
                if syscomout(comm)[1].endswith(','):
                    exec('self.' + self.params[i] +
                         '=float(syscomout(comm)[1][:-1])')
                else:
                    exec('self.' + self.params[i] +
                         '=float(syscomout(comm)[1])')
            else:
                exec('self.' + self.params[i] + '=float(0.)')
# Derive some others
        self.nx = int(self.nx)
        self.ny = int(self.ny)
        self.nz = int(self.nz)
        self.dx = self.lx / self.nx
        self.dy = self.ly / self.ny
        self.dz = self.lz / self.nz
        self.xx = np.linspace(0., self.lx, self.nx)
        self.yy = np.linspace(0., self.ly, self.ny)
        self.zz = np.linspace(0., self.lz, self.nz)
        self.xxt = np.linspace(0., 2 * pi, self.nx)
        self.yyt = np.linspace(0., 2 * pi, self.ny)
        self.zzt = np.linspace(0., 2 * pi, self.nz)
        self.beta = 2 * self.n_0 * self.Temp / (self.b0x**2 + self.b0y**2 +
                                                self.b0z**2)
예제 #2
0
    def __init__(self, shelldirname="", data_type="", filenum=""):
        # If no rundir specified
        if len(shelldirname) == 0:  # Start init prompt
            shelldirname = raw_input('Please enter the rundir: ')
        self.rundir = opexp(shelldirname)
        # If Git version of the code AND filenum not given
        if len(filenum) == 0:
            self.filenum = raw_input(
                "Please enter the file number to load (e.g. 000): ")
        else:
            self.filenum = filenum
# If data type not specified
        if len(data_type) == 0:
            self.data_type = raw_input(
                "Data Type? [(b)yte/ double (bb)yte/ (f)our byte/ (d)ouble precision] "
            )
        else:
            self.data_type = data_type
# Parameters to load
        self.params=['pex','pey','pez','nx','ny','nz','lx','ly','lz',\
        'n_movieout','dt','T_i','T_e','n_0','b0x','b0y','b0z','m_e']
        # Read parameters from file
        for i in self.params:
            comm = "awk '/^#define/ && / " + i + " / {print $3}' " + self.rundir + "/paramfile"
            if syscomout("grep " + i + " " + self.rundir +
                         "/paramfile")[0] == 0:
                exec('self.' + i + '=float(syscomout(comm)[1])')
            else:
                exec('self.' + i + '=float(0.)')
        self.dtmovie = self.n_movieout * self.dt
        # Derive some others
        self.nx = int(self.pex * self.nx)
        self.ny = int(self.pey * self.ny)
        self.nz = int(self.pez * self.nz)
        self.dx = self.lx / self.nx
        self.dy = self.ly / self.ny
        self.dz = self.lz / self.nz
        self.xx = np.linspace(0., self.lx, self.nx)
        self.yy = np.linspace(0., self.ly, self.ny)
        self.zz = np.linspace(0., self.lz, self.nz)
        self.xxt = np.linspace(0., 2 * np.pi, self.nx)
        self.yyt = np.linspace(0., 2 * np.pi, self.ny)
        self.zzt = np.linspace(0., 2 * np.pi, self.nz)
        self.B0 = np.sqrt(self.b0x**2 + self.b0y**2 + self.b0z**2)
        self.betai = 2 * self.n_0 * self.T_i / self.B0
        self.betae = 2 * self.n_0 * self.T_e / self.B0
        self.nprocs = int(self.pex * self.pey * self.pez)
        # If byte or double byte data, open the log file.
        if self.data_type in ("b", "bb"):
            print self.rundir + '/staging/movie.log.' + self.filenum
            self.logfile = open(
                self.rundir + "/staging/movie.log." + self.filenum, "r")
            self.logvars=['rho', 'jx', 'jy', 'jz', 'bx', 'by', 'bz', 'ex', 'ey'\
            , 'ez', 'ne', 'jex', 'jey', 'jez', 'pexx', 'peyy', 'pezz', 'pexy', \
            'peyz', 'pexz', 'ni', 'jix', 'jiy', 'j*z', 'pixx', 'piyy', 'pizz', \
            'pixy', 'piyz', 'pixz']
            self.szl = np.size(self.logvars)
예제 #3
0
    def __loadparams__(self):
        ## Parameters to load
        self.params=['pex','pey','pez','nx','ny','nz','lx','ly','lz',\
        'movieout_full','dt','T_i','T_e','n_0','b0x','b0y','b0z','m_e'\
        ,'d_e2','c_2','ppg']
        # Read parameters from file
        for i in self.params:
            comm = "awk '/^#define/ && / " + i + " / {print $3}' " + self.paramfile
            if syscomout("grep " + i + " " + self.paramfile)[0] == 0:
                exec('self.' + i + '=float(syscomout(comm)[1])')
            else:
                exec('self.' + i + '=float(0.)')

        ## For hybrid code, set electron mass to extremely small
        ## and speed of light to extremely large.
        HYBRID = syscomout("grep 'define hybrid' " + self.paramfile +
                           " |awk '{print $2}'")[1]
        if HYBRID != '':
            self.m_e = self.d_e2
            self.c_2 = 1e9

        self.dtmovie = self.movieout_full
        # Derive some others
        self.nx = int(self.pex * self.nx)
        self.ny = int(self.pey * self.ny)
        self.nz = int(self.pez * self.nz)
        self.dx = self.lx / self.nx
        self.dy = self.ly / self.ny
        self.dz = self.lz / self.nz
        self.xx = np.linspace(0., self.lx, self.nx)
        self.yy = np.linspace(0., self.ly, self.ny)
        self.zz = np.linspace(0., self.lz, self.nz)
        self.xxt = np.linspace(0., 2 * np.pi, self.nx)
        self.yyt = np.linspace(0., 2 * np.pi, self.ny)
        self.zzt = np.linspace(0., 2 * np.pi, self.nz)
        self.B0 = np.sqrt(self.b0x**2 + self.b0y**2 + self.b0z**2)
        self.betai = 2 * self.n_0 * self.T_i / self.B0**2
        self.betae = 2 * self.n_0 * self.T_e / self.B0**2
        self.nprocs = int(self.pex * self.pey * self.pez)
        self.lambdae = np.sqrt(self.T_e / (self.n_0 * self.c_2))
예제 #4
0
    def __loadparams__(self):
        def _convert(val):
            constructors = [int, float, str]
            for c in constructors:
                try:
                    return c(val)
                except ValueError:
                    pass

        with open(self.paramfile) as f:
            content = f.readlines()

        for item in content:
            if '#define' in item and item[0] != '!':
                if len(item.split()) > 2:
                    key = item.split()[1]
                    val = item.split()[2]
                    val = _convert(item.split()[2])
                else:
                    key = item.split()[1]
                    val = True
                self.__dict__[key] = val

        ## For hybrid code, set electron mass to extremely small
        ## and speed of light to extremely large.
        HYBRID = syscomout("grep 'define hybrid' " + self.paramfile +
                           " |awk '{print $2}'")[1]
        if HYBRID != '': self.c_2 = 1e9

        self.dtmovie = self.n_movieout * self.dt
        # Derive some others
        self.nx = int(self.pex * self.nx)
        self.ny = int(self.pey * self.ny)
        self.nz = int(self.pez * self.nz)
        self.dx = self.lx / self.nx
        self.dy = self.ly / self.ny
        self.dz = self.lz / self.nz
        self.xx = np.linspace(0., self.lx, self.nx)
        self.yy = np.linspace(0., self.ly, self.ny)
        self.zz = np.linspace(0., self.lz, self.nz)
        self.xxt = np.linspace(0., 2 * np.pi, self.nx)
        self.yyt = np.linspace(0., 2 * np.pi, self.ny)
        self.zzt = np.linspace(0., 2 * np.pi, self.nz)
        self.B0 = np.sqrt(self.b0x**2 + self.b0y**2 + self.b0z**2)
        self.betai = 2 * self.n_0 * self.T_i / self.B0**2
        self.betae = 2 * self.n_0 * self.T_e / self.B0**2
        self.nprocs = int(self.pex * self.pey * self.pez)
        self.lambdae = np.sqrt(self.T_e / (self.n_0 * self.c_2))