コード例 #1
0
ファイル: grid.py プロジェクト: jpicau/metos3d4py
    def __init__(self, m3d):

        # get 'grid_mask' variable from file
        filepath = util.get_key(m3d, self, m3d.config, "Grid", str)
        gridfile = util.get_hdf5_file(m3d, self, filepath)
        grid = util.get_key(m3d, self, gridfile, "grid_mask",
                            Dataset)  #gridfile["grid_mask"]

        # masks
        self.mask3d = mask3d = (grid[...] != grid.fillvalue)
        self.mask2d = mask2d = mask3d[0, ...]

        # not needed any more
        gridfile.close()

        # vector and profiles
        self.nv = nv = mask3d.sum()  # vector length
        self.np = mask2d.sum()  # profile count
        self.npi = mask3d.sum(axis=0)[mask2d]  # each profile length

        # index permutation from nc/3d to tmm/1d
        nc3d = mask3d[...].astype(">i4")
        (nz, ny, nx) = nc3d.shape
        nc3d[mask3d] = range(nv)
        nc3d[mask3d] = nc3d[mask3d] + 1
        nc1d = nc3d.reshape(nz, ny * nx).T.flat
        self.nc2tmm = nc1d[nc1d != 0] - 1

        # debug
        util.debug(m3d, self, self, level=1)
コード例 #2
0
    def init_boundary_data(self, m3d):

        self.b = []
        self.nb = 0
        self.nbi = []

        config = self.config.get("Boundary data")
        if config is None:
            self.use_boundary = False
            return
        else:
            self.use_boundary = True

        self.boundary = boundary = util.get_key(
            m3d, self, config, "Name, Count, Description, Unit, File", list)
        self.boundary_path = util.get_key(m3d, self, config, "Path", str)

        np = m3d.grid.np
        nploc = m3d.load.nploc

        self.nb = nb = len(boundary)
        nbi = []
        b = []
        for i in range(nb):

            count = boundary[i][1]
            nbi.append(count)

            bi = util.create_petsc_vectors(nbi[i], (nploc, np))
            b.append(bi)

        self.nbi = nbi
        self.b = b
コード例 #3
0
    def init_domain_data(self, m3d):

        self.d = []
        self.nd = 0
        self.ndi = []

        config = self.config.get("Domain data")
        if config is None:
            self.use_domain = False
            return
        else:
            self.use_domain = True

        self.domain = domain = util.get_key(
            m3d, self, config, "Name, Count, Description, Unit, File", list)
        self.domain_path = util.get_key(m3d, self, config, "Path", str)

        nv = m3d.grid.nv
        nvloc = m3d.load.nvloc

        self.nd = nd = len(domain)
        ndi = []
        d = []
        for i in range(nd):

            count = domain[i][1]
            ndi.append(count)

            di = util.create_petsc_vectors(ndi[i], (nvloc, nv))
            d.append(di)

        self.ndi = ndi
        self.d = d
コード例 #4
0
    def __init__(self, m3d):

        config = util.get_key(m3d, self, m3d.config, "Solver", dict)

        self.type = util.get_key(m3d, self, config, "Type", str)
        self.nl = util.get_key(m3d, self, config, "Count", int)
        self.mon = util.get_key(m3d, self, config, "Monitor", bool)

        self.yl = []
        for y in m3d.tracer.y0:
            self.yl.append(y.duplicate())

        # debug
        util.debug(m3d, self, self, level=1)
コード例 #5
0
    def __init__(self, m3d):

        self.config = config = m3d.config.get("BGC")
        if config is None:
            self.use_bgc = False
        else:
            self.use_bgc = True
            self.name = util.get_key(m3d, self, config, "Name", str)

            # load bgc module
            # must be placed in metos3d/bgc/<<name>>/<<sources>>
            # must be compiled with: f2py -c <<sources>> -m <<name>>
            # call to bgc routine must apply to:
            # fortran: metos3dbgc(ny, nx, nu, nb, nd, dt, q, t, y, u, b, d)
            # python: metos3dbgc(dt,q,t,y,u,b,d,[ny,nx,nu,nb,nd])
            # module name: exchange '-' to '_'
            modname = self.name.replace("-", "_")
            self.mod = importlib.import_module("bgc." + self.name + "." +
                                               modname)

            self.init_parameter(m3d)
            self.init_boundary_data(m3d)
            self.init_domain_data(m3d)

        # debug
        util.debug(m3d, self, self, level=1)
コード例 #6
0
    def __init__(self, m3d):

        config = util.get_key(m3d, self, m3d.config, "Time", dict)

        self.t0 = util.get_key(m3d, self, config, "Start", float)
        self.nt = util.get_key(m3d, self, config, "Count", int)
        self.dt = util.get_key(m3d, self, config, "Step", float)

        tracer = m3d.tracer
        ny = tracer.ny
        y0 = tracer.y0

        bgc = m3d.bgc
        b = bgc.b
        nb = bgc.nb
        nbi = bgc.nbi
        bj = []
        for bi in b:
            bj.append(bi[0].duplicate())
        self.bj = bj

        d = bgc.d
        nd = bgc.nd
        ndi = bgc.ndi
        dj = []
        for di in d:
            dj.append(di[0].duplicate())
        self.dj = dj

        yj = []
        yexpj = []
        qj = []
        for yi in y0:
            yj.append(yi.duplicate())
            yexpj.append(yi.duplicate())
            qi = yi.duplicate()
            qi.zeroEntries()
            qi.assemble()
            qj.append(qi)
        self.yj = yj
        self.yexpj = yexpj
        self.qj = qj

        # debug
        util.debug(m3d, self, self, level=1)
コード例 #7
0
ファイル: tracer.py プロジェクト: jpicau/metos3d4py
    def __init__(self, m3d):

        config = util.get_key(m3d, self, m3d.config, "Tracer", dict)
        self.tracer = tracer = util.get_key(m3d, self, config,
                                            "Name, Value, Unit, Description",
                                            list)
        self.output = config.get("Output")
        self.input = config.get("Input")

        # global and local vector length
        nv = m3d.grid.nv
        nvloc = m3d.load.nvloc

        self.ny = ny = len(tracer)
        self.y0 = util.create_petsc_vectors(ny, (nvloc, nv))

        # debug
        util.debug(m3d, self, self, level=1)
コード例 #8
0
ファイル: tmm.py プロジェクト: jpicau/metos3d4py
    def __init__(self, m3d):

        self.config = config = m3d.config.get("TMM")
        if config is None:
            self.use_tmm = False
        else:
            self.use_tmm = True

            self.path = util.get_key(m3d, self, config, "Path", str)
            self.init_explicit(m3d)
            self.init_implicit(m3d)

        # debug
        util.debug(m3d, self, self, level=1)
コード例 #9
0
    def init_parameter(self, m3d):

        self.u = numpy.array([], dtype="f8")  # f2py, no copy as such
        self.nu = 0

        config = self.config.get("Parameter")
        if config is None:
            self.use_param = False
            return
        else:
            self.use_param = True

        self.parameter = parameter = util.get_key(
            m3d, self, config, "Name, Value, Unit, Description", list)

        self.nu = nu = len(parameter)
        u = []
        for i in range(nu):
            value = parameter[i][1]
            u.append(value)
        self.u = numpy.array(u)
コード例 #10
0
    def __init__(self, argv):
        """
            check computation model ...
            print version,
            print number of processes,
            attributes ...
            creates instances ...
            initialize metos3d context,

            Parameters:
                argv:   list with command arguments, file path of yaml conf file

        """

        # version and runtime context
        self.version = version = VERSION
        self.comm = comm = PETSc.COMM_WORLD
        self.size = size = comm.size
        self.rank = rank = comm.rank

        # config
        self.config = util.get_config_from_yaml_file(self, argv)

        # debug level
        self.debug = util.get_key(self, self, self.config, "Debug", int)
        util.debug(self, self, "--- init " + 100 * "-", level=1)
        util.debug(self, self, self, level=1)

        # init
        self.grid = Grid(self)
        self.load = Load(self)
        self.tracer = Tracer(self)
        self.bgc = BGC(self)
        self.tmm = TMM(self)
        self.time = Time(self)
        self.solver = Solver(self)