Пример #1
0
    if PDE.Dirichlet:
        U = PDE.unknown_dirichlet
    else:
        U = PDE.unknown
    # ...

    from pigasus.fem.utils import function

    # ...
    def func(U, x, y):
        _U = U.evaluate()
        return [4. * exp(_U)]

    # ...

    F = function(func, fields=[U])

    list_L2, list_H1 = PDE.solve(F,
                                 u0=None,
                                 maxiter=50,
                                 rtol=1.e-6,
                                 verbose=True)

    print("norm using Picard  ", PDE.norm(exact=u_exact))

    # ...
    if PLOT:
        fig = plt.figure()

        plt.subplot(121, aspect='equal')
        U.fast_plot()
Пример #2
0
print ">>> Solving using Picard <<<"
# ...
if PDE.Dirichlet:
    U = PDE.unknown_dirichlet
else:
    U = PDE.unknown
# ...

from pigasus.fem.utils import function
# ...
def func(U,x,y):
    _U = U.evaluate()
    return [4. * exp (_U)]
# ...

F = function(func, fields=[U])

list_L2, list_H1 = PDE.solve(F, u0=None, maxiter=50, rtol=1.e-6,
                                    verbose=True)

print "norm using Picard  ", PDE.norm(exact=u_exact)

# ...
if PLOT:
    fig = plt.figure()

    plt.subplot(121, aspect='equal')
    U.fast_plot() ; plt.colorbar(orientation='horizontal') ; plt.title('$u_h$')

    # plot error evolution
    plt.subplot(122)
Пример #3
0
    def solve(self, rho0, rho1, c_rho=None, u0=None, maxiter=100, rtol=1.e-6, rtol2=1.e-6 \
              , verbose=False, update=False):
        """
        solves the nonlinear poisson equation using PIcard algorithm
        rho0:
            the initial density
        rho1:
            the new density
        u0:
            this is the initial value for u. Default: all B-splines coeff = 0
        maxiter:
            the maximum number of iterations for the Picard algorithm. Default 100
        rtol:
            the relative tolerance. Default 1.e-6
        verbose:
            True => print the error for each iteration

        Returns:
            The residual error (as a numpy array)

        """
        PDE = self
        V   = self.space

#        print ">> solve-Monge Ampere"

        # ... compute the ratio int rho1 / int rho0
        if c_rho is None:
            # assembly the stifness matrix and bc terms
#            print "Entering assembly"
            PDE_picard.assembly(self, update=update)
#            print "Leaving assembly"
            if self.Dirichlet:
                U = self.unknown_dirichlet
            else:
                U = self.unknown
            U.reset()
            u_sqr = lambda x,y : [sqrt(rho0(x,y))]
            C0 = 1./PDE.norm(exact=u_sqr)**2
            u_sqr = lambda x,y : [sqrt(rho1(x,y))]
            C1 = 1./PDE.norm(exact=u_sqr)**2
            c_rho = C0/C1
        # ...

        self.rho0  = rho0
        self.rho1  = rho1
        self.c_rho = c_rho

        # ...
        from pigasus.fem.utils import function
        def _F (U,x,y):
            D    = U.evaluate(nderiv=2, parametric=False)

            _U   = D[0,0,:]
            Udx  = D[0,1,:]
            Udy  = D[0,2,:]
            Udxx = D[0,3,:]
            Udxy = D[0,4,:]
            Udyy = D[0,5,:]

            f_values = c_rho * rho0(x,y) / rho1 (Udx,Udy)
            return [-sqrt ( Udxx**2 + Udyy**2 + 2 * Udxy**2 + 2 * f_values)]
        # ...
        func_F = function(_F, fields=[U])

#        # ...
#        def F(U,x,y):
#
#            # ...
#            D    = U.evaluate(nderiv=2, parametric=False)
#
#            _U   = D[0,0,:]
#            Udx  = D[0,1,:]
#            Udy  = D[0,2,:]
#            Udxx = D[0,3,:]
#            Udxy = D[0,4,:]
#            Udyy = D[0,5,:]
#
#            f_values = c_rho * rho0(x,y) / rho1 (Udx,Udy)
#            _F = - np.sqrt ( Udxx**2 + Udyy**2 + 2 * Udxy**2 + 2 * f_values )
#
#            return [_F]
#        # ...

        return PDE_picard.solve(  self, func_F \
                             , u0=u0, maxiter=maxiter, rtol=rtol, rtol2=rtol2 \
                             , verbose=verbose, update=update)
Пример #4
0
def create_function(U):
    return function(func_field, fields=[U])