示例#1
0
    def __init__(self, filename, tst=False):
        a = -1.  #left border limit
        b = 10.  #right border limit
        self.n = n = 41
        self.p = p = 3

        #prepare vx, vy (can also be retrieved from an external file)
        vx = np.linspace(a, b, n)
        vy = []
        for xx in vx:
            vy.append(f11(xx))

        self.x = x = symbols('x')
        N = np.zeros(n - p - 1)
        self.lam_base = []  # the lambdified basis expressions
        self.sym_base = []  # the symbolic basis expressions
        knots = create_knots(a, b, n, p)
        print("Prepare Kennlinien Base-Fct...")
        for k in range(n - p - 1):
            #print k
            u = bspline_basis(p, knots, k, x)
            f = lambdify(x, u)
            self.lam_base.append(f)
            self.sym_base.append(u)

        for xx in vx:
            line = []
            for k in range(n - p - 1):
                line = np.hstack((line, self.lam_base[k](xx)))
            N = np.vstack((N, line))
        N = N[1:]

        #    line = np.hstack(line, )
        Ntr = np.transpose(N)

        #solve the Gauss-Problem:
        NTN = np.dot(Ntr, N)
        NTN_inv = np.linalg.inv(NTN)
        Ps_inv = np.dot(NTN_inv, Ntr)
        self.C = np.dot(Ps_inv, vy)
        # Test:
        if tst:
            self.x_dense = np.linspace(a, b, 200)
            self.y_dense = []
            for xx in self.x_dense:
                self.y_dense.append(self.myfunc(xx))
            lines = plt.plot(vx, vy, self.x_dense, self.y_dense)
            plt.show()

        self.gl = n - p - 1
 def __init__(self, filename, tst = False):
     a = -1.  #left border limit
     b = 10. #right border limit
     self.n = n = 41
     self.p = p = 3
     
     #prepare vx, vy (can also be retrieved from an external file)
     vx = np.linspace(a, b, n)
     vy = []
     for xx in vx:
         vy.append(f11(xx)) 
     
     self.x = x = symbols('x')
     N = np.zeros(n-p-1)
     self.lam_base = [] # the lambdified basis expressions
     self.sym_base = [] # the symbolic basis expressions
     knots = create_knots(a,b,n,p)
     print( "Prepare Kennlinien Base-Fct..." )
     for k in range(n-p-1):
         #print k
         u = bspline_basis(p, knots, k, x)
         f = lambdify(x,u)
         self.lam_base.append(f)
         self.sym_base.append(u)
         
     for xx in vx:
         line = []
         for k in range(n-p-1):
             line = np.hstack((line, self.lam_base[k](xx)))
         N = np.vstack((N, line))
     N = N[1:]
         
     #    line = np.hstack(line, )
     Ntr = np.transpose(N)
     
     #solve the Gauss-Problem:
     NTN = np.dot(Ntr, N)
     NTN_inv = np.linalg.inv(NTN)
     Ps_inv = np.dot(NTN_inv, Ntr)
     self.C = np.dot(Ps_inv, vy)
     # Test:
     if tst:
         self.x_dense = np.linspace(a, b, 200)
         self.y_dense = []
         for xx in self.x_dense:
             self.y_dense.append(self.myfunc(xx))            
         lines = plt.plot(vx, vy, self.x_dense, self.y_dense )
         plt.show()
         
     self.gl = n-p-1
示例#3
0
    def test_bspline_solution3(self):
        r, theta, phi = symbols("r theta phi", real=True)
        sp = Spherical()
        ## We try to build an analytic solution for the stokes system with solenoidal basisfunctions that
        ## furthermore fulfill the boundary conditions for a rigid lid
        ##
        ## let the basisfunction be vb
        ## first we create the radial part
        ## To this end we use splines that we combine from the b-spline basis
        ## One of the advantages of b-spline basis functions is that they and their derivatives
        ## vanish at the ends of their support interval
        ## Therefore it is very easy to fulfill the boundary conditions
        ##
        r_min = 10
        r_max = 20
        # cubic splines should be smooth enough for the stokes problem since only 2 derivatives are needed
        # on the other hand the radial part of the soluton composed of the bsplines are differentiated
        # once before to  build up the 3d Field. So
        degree = 3
        knotnumber = degree + 2
        bs = []
        for i in range(r_min, r_max + 2 - knotnumber):
            knots = range(i, i + knotnumber)
            b = bspline_basis(degree, knots, 0, r)
            bs.append(b)
        #print(bs)
        # we now combine the basisfunctions to a singe radial function
        T = piecewise_fold(bs[0] + bs[-1])
        #print(T)

        ### we have to show that the functions are solenoidal
        l = 1
        m = 1
        vb = pol_real(l, m, T)
        res = sp.div(vb)
        testnumshell(res, r_min, r_max, 10**-7)
        #print("vb=",vb)
        #print("res=",res)

        ### now we test for the boundary conditions
        ### vanishing of T at the inner and outer surface.
        self.assertTrue(T.subs(r, r_min) == 0)
        self.assertTrue(T.subs(r, r_max) == 0)
        print(T.subs(r, r_max))
        ### vanishing of T' at the inner and outer surface.
        dT = diff(T, r)
        self.assertTrue(dT.subs(r, r_min) == 0)
        self.assertTrue(dT.subs(r, r_max) == 0)
示例#4
0
文件: glt.py 项目: johndpope/GeLaTo
    def eval(cls, n, p, t):
        # ...
        if not 0 <= p:
            raise ValueError("must have 0 <= p")
        if not 0 <= n:
            raise ValueError("must have 0 <= n")
        # ...

        # ...
        r = Symbol('r')

        pp = 2 * p + 1
        N = pp + 1
        L = list(range(0, N + pp + 1))

        b0 = bspline_basis(pp, L, 0, r)
        b0_r = diff(b0, r)
        b0_rr = diff(b0_r, r)
        b0_rrr = diff(b0_rr, r)
        b0_rrrr = diff(b0_rrr, r)
        bsp = lambdify(r, b0_rrrr)
        # ...

        # ... we use nsimplify to get the rational number
        phi = []
        for i in range(0, p + 1):
            y = bsp(p + 1 - i)
            y = nsimplify(y, tolerance=TOLERANCE, rational=True)
            phi.append(y)
        # ...

        # ...
        m = phi[0] * cos(S.Zero)
        for i in range(1, p + 1):
            m += 2 * phi[i] * cos(i * t)
        # ...

        # ... scaling
        m *= n**3
        # ...

        return m
示例#5
0
文件: glt.py 项目: johndpope/GeLaTo
    def eval(cls, p, t):

        if p is S.Infinity:
            raise NotImplementedError('Add symbol limit for p -> oo')

        elif isinstance(p, Symbol):
            return Bilaplacian(p, t, evaluate=False)

        elif isinstance(p, int):

            # ...
            r  = Symbol('r')

            pp = 2*p + 1
            N = pp + 1
            L = list(range(0, N + pp + 1))

            b0    = bspline_basis(pp, L, 0, r)
            b0_r  = diff(b0, r)
            b0_rr = diff(b0_r, r)
            b0_rrr = diff(b0_rr, r)
            b0_rrrr = diff(b0_rrr, r)
            bsp   = lambdify(r, b0_rrrr)
            # ...

            # ... we use nsimplify to get the rational number
            phi = []
            for i in range(0, p+1):
                y = bsp(p+1-i)
                y = nsimplify(y, tolerance=TOLERANCE, rational=True)
                phi.append(y)
            # ...

            # ...
            m = phi[0] * cos(S.Zero)
            for i in range(1, p+1):
                m += 2 * phi[i] * cos(i * t)
            # ...

            return m
示例#6
0
def bspline_basis(x):
    return diffify(sympy.bspline_basis(x))