Пример #1
0
 def test_check_residuals(self):
     from spacetime_pod_utils import get_spacetimepodres
     iniv = np.r_[np.ones(((self.Nq - 1) / 2, 1)),
                  np.zeros(((self.Nq) / 2 + 1, 1))]
     ttvvec = np.random.randn(self.Nq * (self.Ns - 1), 1)
     # define the residual manually
     dmsz = self.dms[1:, :1]
     msz = self.ms[1:, :1]
     dmsI = self.dms[1:, 1:]
     msI = self.ms[1:, 1:]
     mydense = np.array(self.my.todense())
     aydense = np.array(self.ay.todense())
     solmat = np.kron(dmsI, mydense) + np.kron(msI, aydense)
     rhs = -np.kron(dmsz, np.dot(mydense, iniv)) \
         - np.kron(msz, np.dot(aydense, iniv))
     mres = np.dot(solmat, ttvvec) - rhs
     # define to the residual in burgers
     bres = get_spacetimepodres(tvvec=ttvvec,
                                dms=self.dms,
                                ms=self.ms,
                                my=mydense,
                                ared=aydense,
                                nfunc=None,
                                rhs=None,
                                retnorm=False,
                                iniv=iniv)
     self.assertTrue(np.allclose(mres, bres))
     self.assertTrue(norm(mres) > 1e-8)
Пример #2
0
def optifun(tvvec):
    allo = get_spacetimepodres(tvvec=tvvec.reshape((tvvec.size, 1)),
                               dms=hdms,
                               ms=hms,
                               my=mred,
                               ared=ared,
                               nfunc=evabrgquadterm,
                               rhs=None,
                               retnorm=False)
    return allo.flatten()
    def _nonlinres(tsvec):
        def evabrgquadterm(tvvec):
            return eva_burger_quadratic(tvvec=tvvec,
                                        htittl=htittl,
                                        uvvdxl=uvvdxl)

        bres = spu.get_spacetimepodres(tvvec=tsvec,
                                       dms=dms,
                                       ms=ms,
                                       my=my,
                                       ared=ay,
                                       nfunc=evabrgquadterm,
                                       rhs=None,
                                       retnorm=False,
                                       iniv=iniv)
        return bres[0 * lnq:, ].flatten()
    uvvdxl = dbs.get_burgertensor_spacecomp(podmat=Uky, **femp)
    htittl = bgu.get_burgertensor_timecomp(podmat=Uks,
                                           sdim=sdim,
                                           tmesh=tmesh,
                                           basfuntype='pl')

    # hsini = np.dot(Uks.T, sini)
    # hshyini = np.kron(hsini, inired.reshape((hydim, 1)))
    # iniproj = spu.expand_stpodsol(stpsol=hshyini, Uks=Uks, Uky=Uky)
    # plotmat(iniproj)
    hshysol = np.dot(Uks.T, np.dot(x.T, Uky)).\
        reshape((hsdim*hydim, 1), order='C')

    def evabrgquadterm(tvvec):
        return bgu.\
            eva_burger_quadratic(tvvec=tvvec, htittl=htittl, uvvdxl=uvvdxl)

    dms = gpu.get_dms(sdim=sdim, tmesh=tmesh, basfuntype='pl')
    hdms = np.dot(Uks.T, np.dot(dms, Uks))
    hms = np.dot(Uks.T, np.dot(ms, Uks))
    timespaceres = spu.get_spacetimepodres(tvvec=hshysol,
                                           dms=hdms,
                                           ms=hms,
                                           my=mred,
                                           ared=ared,
                                           nfunc=evabrgquadterm,
                                           rhs=None)
    print timespaceres
    # solproj = spu.expand_stpodsol(stpsol=hshysol, Uks=Uks, Uky=Uky)
    # plotmat(solproj)
Пример #5
0
simudict = dict(iniv=iniv, A=A, M=M, nfunc=None, rhs=rhs, tmesh=tmesh)
vv = dou.load_or_comp(filestr='data/' + datastr,
                      comprtn=gpu.time_int_semil,
                      comprtnargs=simudict,
                      arraytype='dense',
                      debug=True)
plotmat(vv)
ared, mred, nonlred, rhsred, inired, Uky = gpu.\
    get_podred_model(M=M, A=A, nonl=nfunc, rhs=rhs,
                     sol=vv.T, tmesh=tmesh, verbose=True,
                     poddim=hq, sdim=Ns, plotsvs=plotsvs,
                     genpod=True, basfuntype='pl')

(msx, ms) = gpu.get_genmeasuremat(sol=vv.T, tmesh=tmesh, sdim=Ns)
x = lau.apply_massinv(sps.csc_matrix(ms), msx.T).T
Uks = gpu.get_podmats(sol=x.T, poddim=hs, plotsvs=plotsvs, M=M)
hshysol = np.dot(Uks.T, np.dot(x.T, Uky)).\
    reshape((hs*hq, 1), order='C')
dms = gpu.get_dms(sdim=Ns, tmesh=tmesh, basfuntype='pl')
hdms = np.dot(Uks.T, np.dot(dms, Uks))
hms = np.dot(Uks.T, np.dot(ms, Uks))
nres, timespaceres = get_spacetimepodres(tvvec=hshysol,
                                         dms=hdms,
                                         ms=hms,
                                         my=mred,
                                         ared=None,
                                         nfunc=None,
                                         rhs=None)
trsrs = timespaceres.reshape((hq, hs))
plotmat((np.dot(Uky, np.dot(trsrs, Uks.T))).T, fignum=121)