Esempio n. 1
0
    def diagnostics(self, var, t):
        """ should provide at least 'maxspeed' (for cfl determination) """

        if t == 0.:
            # since the flow is prescribed, compute it only at t=0
            u = var.get('u')
            v = var.get('v')
            ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh)

            cst = self.mpitools.local_to_global([(maxu, 'max'), (ke, 'sum')])
            self.diags['maxspeed'] = cst[0]
            self.diags['ke'] = cst[1] / self.area
            self.diags['enstrophy'] = 0.

        trac = var.get('tracer')

        z, z2 = fd.computesumandnorm(self.msk, trac, self.nh)

        cst = self.mpitools.local_to_global([(z, 'sum'), (z2, 'sum')])

        z = cst[0] / self.area
        z2 = cst[1] / self.area

        self.diags['mean'] = z
        self.diags['rms'] = np.sqrt(z2)
Esempio n. 2
0
    def diagnostics(self, var, t):
        """ Integral diagnostics for the QG model

        should provide at least 'maxspeed' (for cfl determination) """

        u = var.get('u')
        v = var.get('v')
        trac = var.get('pv')
        psi = var.get('psi')

        fo.cornertocell(psi, self.ope.work)
        psim, psi2 = fd.computesumandnorm(self.msk, self.ope.work, self.nh)
        ape = 0.5 * psi2 / self.Rd**2

        ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh)

        z, z2 = fd.computesumandnorm(self.msk, trac, self.nh)

        cst = self.mpitools.local_to_global([(maxu, 'max'),
                                             (ke, 'sum'),
                                             (z, 'sum'),
                                             (z2, 'sum'),
                                             (ape, 'sum')])

        self.diags['maxspeed'] = cst[0]
        self.diags['ke'] = cst[1] / self.area
        self.diags['pv'] = cst[2] / self.area
        self.diags['pv2'] = 0.5*cst[3] / self.area
        self.diags['ape'] = cst[4] / self.area
        self.diags['energy'] = (cst[1]+cst[4]) / self.area
Esempio n. 3
0
    def diagnostics(self, var, t):
        """ should provide at least 'maxspeed' (for cfl determination) """

        nh = self.nh
        u = var.get('u')
        v = var.get('v')
        vort = var.get('vorticity')
        buoy = var.get('buoyancy')

        ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh)

        z, z2 = fd.computesumandnorm(self.msk, vort, self.nh)

        b, b2 = fd.computesumandnorm(self.msk, buoy, self.nh)

        #  potential energy (minus sign because buoyancy is minus density)
        pe = -self.gravity * fd.computesum(self.msk, buoy * self.yr, nh)

        cst = self.mpitools.local_to_global([(maxu, 'max'), (ke, 'sum'),
                                             (z, 'sum'), (z2, 'sum'),
                                             (pe, 'sum'), (b, 'sum'),
                                             (b2, 'sum')])

        self.diags['maxspeed'] = cst[0]
        self.diags['ke'] = cst[1] / self.area
        self.diags['pe'] = cst[4] / self.area
        self.diags['energy'] = (cst[1] + cst[4]) / self.area
        self.diags['vorticity'] = cst[2] / self.area
        self.diags['enstrophy'] = 0.5 * cst[3] / self.area
        self.diags['buoyancy'] = cst[5] / self.area
        self.diags['brms'] = np.sqrt(cst[6] / self.area -
                                     (cst[5] / self.area)**2)
Esempio n. 4
0
    def diagnostics(self, var, t):
        """ should provide at least 'maxspeed' (for cfl determination) """

        nh = self.nh
        u = var.get('u')
        v = var.get('v')
        vort = var.get('vorticity')
        buoy = var.get('buoyancy')
        V = var.get('V')
        qE = var.get('qE')
        qEneg = qE.copy()
        qEneg[qE > 0] = 0.

        ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh)

        z, z2 = fd.computesumandnorm(self.msk, vort, self.nh)

        b, b2 = fd.computesumandnorm(self.msk, buoy, self.nh)

        vm, v2 = fd.computesumandnorm(self.msk, V, self.nh)

        q, q2 = fd.computesumandnorm(self.msk, qE, self.nh)
        qn, qn2 = fd.computesumandnorm(self.msk, qEneg, self.nh)

        # potential energy (minus sign because buoyancy is minus density)
        pe = fd.computesum(self.msk, buoy * self.yr, nh)
        pe = -self.gravity * pe

        cst = self.mpitools.local_to_global([(maxu, 'max'), (ke, 'sum'),
                                             (z, 'sum'), (z2, 'sum'),
                                             (pe, 'sum'), (b, 'sum'),
                                             (b2, 'sum'), (q, 'sum'),
                                             (q2, 'sum'), (qn, 'sum'),
                                             (qn2, 'sum'), (v2, 'sum')])

        a = self.area
        self.diags['maxspeed'] = cst[0]
        self.diags['ke'] = (cst[1]) / a
        self.diags['keV'] = (0.5 * cst[11]) / a
        self.diags['pe'] = cst[4] / a
        self.diags[
            'energy'] = self.diags['ke'] + self.diags['pe'] + self.diags['keV']

        self.diags['vorticity'] = cst[2] / a
        self.diags['enstrophy'] = 0.5 * cst[3] / a

        bm = cst[5] / a
        self.diags['buoyancy'] = bm
        self.diags['brms'] = sqrt(cst[6] / a - bm**2)

        pvm = cst[7] / a
        pvneg_mean = cst[9] / a
        self.diags['pv_mean'] = pvm
        self.diags['pv_std'] = sqrt(cst[8] / a - pvm**2)
        self.diags['pvneg_mean'] = pvneg_mean
        self.diags['pvneg_std'] = sqrt(cst[10] / a - pvneg_mean**2)
Esempio n. 5
0
    def integrals(self, state):
        u = state.get('u')
        v = state.get('v')
        vort = state.get('vorticity')

#        u2,umax = computenormmaxu(self.msk,u,self.nh)
#        v2,vmax = computenormmaxv(self.msk,v,self.nh)

        ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh)
        # ke = computekewithpsi(self.msk,psi,vort,self.nh)


        z, z2 = fd.computesumandnorm(self.msk, vort, self.nh)

#        u2 = u2 / self.area
#        v2 = v2 / self.area
        ke = ke / self.area
        z  = z / self.area
        z2 = z2 / self.area

        if self.mpi == -1:  # TODO
            cst = np.zeros((6,))
            cst[0] = u2
            cst[1] = v2
            cst[2] = z
            cst[3] = z2
            cst[4] = umax
            cst[5] = vmax

            cst_glo = np.array(MPI.COMM_WORLD.allgather(cst))

            u2, v2, z, z2, umax, vmax = (
                0., 0., 0., 0., 0., 0.)

            for k in range(self.npx*self.npy):
                u2 += cst_glo[k][0]
                v2 += cst_glo[k][1]
                z += cst_glo[k][2]
                z2 += cst_glo[k][3]
                umax = max(umax, cst_glo[k][4])
                vmax = max(vmax, cst_glo[k][5])

        # todo: add potential energy for the Boussinesq model
        self.ke = ke   # 0.5*(u2+v2)
        self.vorticity = z
        self.enstrophy = 0.5*z2
        # self.umax = umax
        # self.vmax = vmax
        self.maxspeed = maxu  # max([umax,vmax])
Esempio n. 6
0
    def diagnostics(self, var, t):
        """ Integral diagnostics for the QG model

        should provide at least 'maxspeed' (for cfl determination) """

        u = var.get('u')
        v = var.get('v')
        trac = var.get('pv')

        ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh)

        z, z2 = fd.computesumandnorm(self.msk, trac, self.nh)

        cst = self.mpitools.local_to_global([(maxu, 'max'),
                                             (ke, 'sum'),
                                             (z, 'sum'),
                                             (z2, 'sum')])

        self.diags['maxspeed'] = cst[0]
        self.diags['ke'] = cst[1] / self.area
        self.diags['pv'] = cst[2] / self.area
        self.diags['pv2'] = cst[3] / self.area
Esempio n. 7
0
    def diagnostics(self, var, t):
        """ should provide at least 'maxspeed' (for cfl determination) """
        self.timers.tic('diag')
        u = var.get('u')
        v = var.get('v')
        trac = var.get('vorticity')
        psi = var.get('psi')
        source = self.var.get('source')

        xr = self.xr
        yr = self.yr

        ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh)
        # ke = fd.computekewithpsi(self.msk, trac, psi, self.nh)

        z, z2 = fd.computesumandnorm(self.msk, trac, self.nh)

        px = fd.computedotprod(self.msk, trac, xr, self.nh)
        py = fd.computedotprod(self.msk, trac, yr, self.nh)

        angmom = fd.computesum(self.msk, psi, self.nh)
        sce = fd.computedotprod(self.msk, trac, source, self.nh)

        cst = self.mpitools.local_to_global([(maxu, 'max'), (ke, 'sum'),
                                             (z, 'sum'), (z2, 'sum'),
                                             (px, 'sum'), (py, 'sum'),
                                             (angmom, 'sum'), (sce, 'sum')])

        self.diags['maxspeed'] = cst[0]
        self.diags['ke'] = cst[1] / self.area
        self.diags['vorticity'] = cst[2] / self.area
        self.diags['enstrophy'] = 0.5 * cst[3] / self.area
        self.diags['px'] = cst[4] / self.area
        self.diags['py'] = cst[5] / self.area
        self.diags['angmom'] = cst[6] / self.area
        self.diags['source'] = cst[7] / self.area

        self.timers.toc('diag')
Esempio n. 8
0
    def diagnostics(self, var, t):
        """Integral diagnostics for the SQG model

        should provide at least 'maxspeed' (for cfl determination)

        WARNING: the diag for KE and APE are wrong. A SQG flow is 3D
        the integration should be carried over in the Fourier space

        The total PV should be conserved (in the absence of external
        forcing) and the enstrophy should be conserved as long as the
        flow is not developping filaments (grid-scale enstrophy). The
        numerical dissipation wipes out Filaments which yields
        enstrophy dissipation.

        """

        u = var.get('u')
        v = var.get('v')
        trac = var.get('pv')
        psi = var.get('psi')

        #fo.cornertocell(psi, self.ope.work)
        #psim, psi2 = fd.computesumandnorm(self.msk, self.ope.work, self.nh)
        #ape = 0.5 * psi2 / self.Rd**2

        ke, maxu = fd.computekemaxu(self.msk, u, v, self.nh)

        z, z2 = fd.computesumandnorm(self.msk, trac, self.nh)

        cst = self.mpitools.local_to_global([(maxu, 'max'), (ke, 'sum'),
                                             (z, 'sum'), (z2, 'sum')])

        self.diags['maxspeed'] = cst[0]
        self.diags['ke'] = cst[1] / self.area
        self.diags['pv'] = cst[2] / self.area
        self.diags['pv2'] = 0.5 * cst[3] / self.area