当前位置: 首页>>代码示例>>Python>>正文


Python mesh.mesh函数代码示例

本文整理汇总了Python中pySDC.datatype_classes.mesh.mesh函数的典型用法代码示例。如果您正苦于以下问题:Python mesh函数的具体用法?Python mesh怎么用?Python mesh使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mesh函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __eval_fexpl

    def __eval_fexpl(self, u, t):
        """
        Helper routine to evaluate the explicit part of the RHS

        Args:
            u: current values (not used here)
            t: current time

        Returns:
            explicit part of RHS
        """

        fexpl = mesh(self.nvars)

        # Copy values of u into pyClaw state object
        self.state.q[0, :] = u.values[0, :]

        # Evaluate right hand side
        tmp = self.solver.dqdt(self.state)
        fexpl.values[0, :] = tmp.reshape(self.nvars[1:])

        # Copy values of u into pyClaw state object
        self.state.q[0, :] = u.values[1, :]

        # Evaluate right hand side
        tmp = self.solver.dqdt(self.state)
        fexpl.values[1, :] = tmp.reshape(self.nvars[1:])

        # DEBUGGING
        # fexpl.values[0,:] = 0.0*self.mesh
        # fexpl.values[1,:] = 0.0*self.mesh
        return fexpl
开发者ID:kidaa,项目名称:pySDC,代码行数:32,代码来源:ProblemClass.py

示例2: solve_system

    def solve_system(self,rhs,factor,u0,t):
        """
        Simple linear solver for (I-dtA)u = rhs

        Args:
            rhs: right-hand side for the nonlinear system
            factor: abbrev. for the node-to-node stepsize (or any other factor required)
            u0: initial guess for the iterative solver (not used here so far)
            t: current time (e.g. for time-dependent BCs)

        Returns:
            solution as mesh
        """

        b         = rhs.values.flatten()
        cb        = Callback()

        sol, info = LA.gmres( self.Id - factor*self.M, b, x0=u0.values.flatten(), tol=self.gmres_tol, restart=self.gmres_restart, maxiter=self.gmres_maxiter, callback=cb)
        # If this is a dummy call with factor==0.0, do not log because it should not be counted as a solver call
        if factor!=0.0:
          #print "SDC: Number of GMRES iterations: %3i --- Final residual: %6.3e" % ( cb.getcounter(), cb.getresidual() )
          self.logger.add(cb.getcounter())
        me        = mesh(self.nvars)
        me.values = unflatten(sol, 4, self.N[0], self.N[1])

        return me
开发者ID:lelou6666,项目名称:pySDC,代码行数:26,代码来源:ProblemClass.py

示例3: solve_system

    def solve_system(self, rhs, factor, u0, t):
        """
        Simple linear solver for (I-dtA)u = rhs

        Args:
            rhs: right-hand side for the nonlinear system
            factor: abbrev. for the node-to-node stepsize (or any other factor required)
            u0: initial guess for the iterative solver (not used here so far)
            t: current time (e.g. for time-dependent BCs)

        Returns:
            solution as mesh
        """

        M1 = sp.hstack((sp.eye(self.nvars[1]), -factor * self.A))
        M2 = sp.hstack((-factor * self.A, sp.eye(self.nvars[1])))
        M = sp.vstack((M1, M2))

        b = np.concatenate((rhs.values[0, :], rhs.values[1, :]))

        sol = LA.spsolve(M, b)

        me = mesh(self.nvars)
        me.values[0, :], me.values[1, :] = np.split(sol, 2)

        return me
开发者ID:kidaa,项目名称:pySDC,代码行数:26,代码来源:ProblemClass.py

示例4: __eval_fexpl

    def __eval_fexpl(self,u,t):
        """
        Helper routine to evaluate the explicit part of the RHS

        Args:
            u: current values (not used here)
            t: current time

        Returns:
            explicit part of RHS
        """


        fexpl        = mesh(self.nvars)

        # Copy values of u into pyClaw state object
        self.state.q[0,:,:] = u.values[0,:,:]

        # Evaluate right hand side
        self.solver.before_step(self.solver, self.state)
        tmp = self.solver.dqdt(self.state)
        
        fexpl.values[0,:,:] = unflatten(tmp, 1, self.nvars[1], self.nvars[2])


        # Copy values of u into pyClaw state object
        #self.state.q[0,:,:] = u.values[1,:,:]

        # Evaluate right hand side
        #tmp = self.solver.dqdt(self.state)
        #fexpl.values[1,:,:] = tmp.reshape(self.nvars[1:])

        return fexpl
开发者ID:kidaa,项目名称:pySDC,代码行数:33,代码来源:ProblemClass.py

示例5: u_exact

    def u_exact(self,t):
        """
        Routine to compute the exact solution at time t

        Args:
            t: current time

        Returns:
            exact solution
        """
        
        dtheta = 0.01
        H      = 10.0
        a      = 5.0
        x_c    = -50.0
        
        me        = mesh(self.nvars)
        me.values[0,:,:] = 0.0*self.xx
        me.values[1,:,:] = 0.0*self.xx
        #me.values[2,:,:] = 0.0*self.xx
        #me.values[3,:,:] = np.exp(-0.5*(self.xx-0.0)**2.0/0.15**2.0)*np.exp(-0.5*(self.zz-0.5)**2/0.15**2)
        #me.values[2,:,:] = np.exp(-0.5*(self.xx-0.0)**2.0/0.05**2.0)*np.exp(-0.5*(self.zz-0.5)**2/0.2**2)
        me.values[2,:,:] = dtheta*np.sin( np.pi*self.zz/H )/( 1.0 + np.square(self.xx - x_c)/(a*a))
        me.values[3,:,:] = 0.0*self.xx
        return me
开发者ID:lelou6666,项目名称:pySDC,代码行数:25,代码来源:ProblemClass.py

示例6: check_datatypes_mesh

def check_datatypes_mesh(init):
    import pySDC.datatype_classes.mesh as m


    m1 = m.mesh(init)
    m2 = m.mesh(m1)


    m1.values[:] = 1.0
    m2.values[:] = 2.0

    m3 = m1 + m2
    m4 = m1 - m2
    m5 = 0.1*m1
    m6 = m1

    m7 = abs(m1)

    m8 = m.mesh(m1)

    assert isinstance(m3,type(m1))
    assert isinstance(m4,type(m1))
    assert isinstance(m5,type(m1))
    assert isinstance(m6,type(m1))
    assert isinstance(m7,float)

    assert m2 is not m1
    assert m3 is not m1
    assert m4 is not m1
    assert m5 is not m1
    assert m6 is m1

    assert np.shape(m3.values) == np.shape(m1.values)
    assert np.shape(m4.values) == np.shape(m1.values)
    assert np.shape(m5.values) == np.shape(m1.values)

    assert np.all(m1.values==1.0)
    assert np.all(m2.values==2.0)
    assert np.all(m3.values==3.0)
    assert np.all(m4.values==-1.0)
    assert np.all(m5.values==0.1)
    assert np.all(m8.values==1.0)
    assert m7 >= 0
开发者ID:kidaa,项目名称:pySDC,代码行数:43,代码来源:tests_core.py

示例7: u_exact

    def u_exact(self,t):
        """
        Routine to compute the exact solution at time t

        Args:
            t: current time

        Returns:
            exact solution
        """

        me = mesh(self.nvars)
        me.values = np.cos(2.0*np.pi*(self.mesh-self.c*t))
        return me
开发者ID:kidaa,项目名称:pySDC,代码行数:14,代码来源:ProblemClass.py

示例8: u_exact

    def u_exact(self,t):
        """
        Routine to compute the exact solution at time t

        Args:
            t: current time

        Returns:
            exact solution
        """
        
        me             = mesh(self.nvars)
        me.values[0,:] = 0.5*u_initial( self.mesh - (self.cadv + self.cs)*t , self.waveno) - 0.5*u_initial( self.mesh - (self.cadv - self.cs)*t , self.waveno)
        me.values[1,:] = 0.5*u_initial( self.mesh - (self.cadv + self.cs)*t , self.waveno) + 0.5*u_initial( self.mesh - (self.cadv - self.cs)*t , self.waveno)
        return me
开发者ID:lelou6666,项目名称:pySDC,代码行数:15,代码来源:ProblemClass_conv.py

示例9: __eval_fimpl

    def __eval_fimpl(self,u,t):
        """
        Helper routine to evaluate the implicit part of the RHS

        Args:
            u: current values
            t: current time (not used here)

        Returns:
            implicit part of RHS
        """

        fimpl = mesh(self.nvars)
        fimpl.values = self.A.dot(u.values)
        return fimpl
开发者ID:kidaa,项目名称:pySDC,代码行数:15,代码来源:ProblemClass.py

示例10: u_exact

    def u_exact(self, t):
        """
        Dummy routine for the exact solution, currently only passes the initial values

        Args:
            t: current time
        Returns:
            mesh type containing the initial values
        """

        # thou shall not call this at time > 0
        assert t is 0
        me = mesh(2)
        me.values = self.u0
        return me
开发者ID:kidaa,项目名称:pySDC,代码行数:15,代码来源:ProblemClass.py

示例11: prolong_space

    def prolong_space(self, G):
        """
        Dummy prolongation routine

        Args:
            G: the coarse level data (easier to access than via the coarse attribute)
        """

        if isinstance(G, mesh):
            F = mesh(G)
        elif isinstance(G, rhs_imex_mesh):
            F = rhs_imex_mesh(G)
        else:
            print("Transfer error")
            exit()
        return F
开发者ID:kidaa,项目名称:pySDC,代码行数:16,代码来源:TransferClass.py

示例12: solve_system

    def solve_system(self,rhs,factor,u0,t):
        """
        Simple linear solver for (I-dtA)u = rhs

        Args:
            rhs: right-hand side for the nonlinear system
            factor: abbrev. for the node-to-node stepsize (or any other factor required)
            u0: initial guess for the iterative solver (not used here so far)
            t: current time (e.g. for time-dependent BCs)

        Returns:
            solution as mesh
        """

        me = mesh(self.nvars)
        me.values = LA.spsolve(sp.eye(self.nvars)-factor*self.A,rhs.values)
        return me
开发者ID:kidaa,项目名称:pySDC,代码行数:17,代码来源:ProblemClass.py

示例13: u_exact

    def u_exact(self,t):
        """
        Routine to compute the exact solution at time t

        Args:
            t: current time

        Returns:
            exact solution
        """
        
        xc,yc = self.state.grid.p_centers
        me        = mesh(self.nvars)
        me.values[0,:,:] = np.sin(2*np.pi*xc)*np.sin(2*np.pi*yc)
        me.values[1,:,:] = np.sin(2*np.pi*xc)*np.sin(2*np.pi*yc)

        return me
开发者ID:torbjoernk,项目名称:pySDC,代码行数:17,代码来源:ProblemClass.py

示例14: eval_f

    def eval_f(self,u,t):
        """
        Routine to compute the RHS for both components simultaneously

        Args:
            t: current time (not used here)
            u: the current values
        Returns:
            RHS, 2 components
        """

        x1 = u.values[0]
        x2 = u.values[1]
        f = mesh(2)
        f.values[0] = -x2 + x1*(1 - x1**2 - x2**2)
        f.values[1] = x1 + 3*x2*(1 - x1**2 - x2**2)
        return f
开发者ID:kidaa,项目名称:pySDC,代码行数:17,代码来源:ProblemClass.py

示例15: prolong_space

    def prolong_space(self,G):
        """
        Prolongation implementation

        Args:
            G: the coarse level data (easier to access than via the coarse attribute)
        """

        if isinstance(G,mesh):
            u_fine = mesh(self.init_c,val=0)
            u_fine.values = self.Pspace.dot(G.values)
        elif isinstance(G,rhs_imex_mesh):
            u_fine = rhs_imex_mesh(self.init_c)
            u_fine.impl.values = self.Pspace.dot(G.impl.values)
            u_fine.expl.values = self.Pspace.dot(G.expl.values)

        return u_fine
开发者ID:lelou6666,项目名称:pySDC,代码行数:17,代码来源:TransferClass.py


注:本文中的pySDC.datatype_classes.mesh.mesh函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。