Exemplo n.º 1
0
def creationSpaces(degree, grid):
    """
        Create the schoenberg spaces of degree @degree (and @degree-1)
        
        Parameters
        ----------
        @degree: int
			degree of the first schoenberg space         	

        @grid : list of float or numpy.ndarray
           	breakpoints of the domain

        Returns
        -------
        V : Class SplineSpace
            1D finite element space of schoenberg space of degree @degree
        
        W: Class SplineSpace
        	1D finite element space of schoenberg space of degree (@degree - 1)

        """

    V = SplineSpace(degree, grid=grid)
    W = SplineSpace(degree - 1, grid=grid)

    V.init_fem(quad_order=degree + 1)
    W.init_fem(quad_order=degree + 1)

    return V, W
Exemplo n.º 2
0
def test_pdes_2d_2():
    print('============ test_pdes_2d_2 =============')

    # ... abstract model
    V = H1Space('V', ldim=2)

    v = TestFunction(V, name='v')
    u = TestFunction(V, name='u')

    c = Constant('c', real=True, label='mass stabilization')

    a = BilinearForm((v, u), dot(grad(v), grad(u)) + c * v * u)
    # ...

    # ... discretization
    # Input data: degree, number of elements
    p1 = 1
    p2 = 1
    ne1 = 4
    ne2 = 4

    # Create uniform grid
    grid_1 = linspace(0., 1., num=ne1 + 1)
    grid_2 = linspace(0., 1., num=ne2 + 1)

    # Create 1D finite element spaces and precompute quadrature data
    V1 = SplineSpace(p1, grid=grid_1)
    V1.init_fem()
    V2 = SplineSpace(p2, grid=grid_2)
    V2.init_fem()

    # Create 2D tensor product finite element space
    V = TensorFemSpace(V1, V2)
    # ...

    # ...
    discretize_symbol(a, [V, V])
    #    print(mass.symbol.__doc__)
    # ...

    # ...
    n1 = 21
    n2 = 21

    t1 = linspace(-pi, pi, n1)
    t2 = linspace(-pi, pi, n2)
    x1 = linspace(0., 1., n1)
    x2 = linspace(0., 1., n2)

    xs = [x1, x2]
    ts = [t1, t2]

    e = a.symbol(*xs, *ts, 0.25)
    print('> c = 0.25 :: ', e.min(), e.max())

    e = a.symbol(*xs, *ts, 0.6)
    print('> c = 0.6 :: ', e.min(), e.max())
Exemplo n.º 3
0
def creation_spaces_2d(p1, p2, ne1, ne2):
	"""
		Creation of the different spaces used in our solver:
		
		Require:
		--------
			@p1 and @p2 are degrees of direction 1 and 2
			@ne1 and @ne2 are number of elements in direction 1 and 2
		
		Returns:
		--------
			@V TensorFem which represents H^1 space
			@W TensorFem which represents L^2 space
			@Wdiv1 and @Wdiv2 represent (H¹, div) space
			
	"""
	grid_1 = np.linspace( 0., 1., num=ne1+1 )
	grid_2 = np.linspace( 0., 1., num=ne2+1 )

	# Create 1D finite element spaces and precompute quadrature data
	V1 = SplineSpace( p1, grid=grid_1); V1.init_fem(quad_order=p1+1)
	W1 = SplineSpace(p1-1, grid=grid_1); W1.init_fem(quad_order=p1+1)
	V2 = SplineSpace( p2, grid=grid_2 ); V2.init_fem(quad_order=p2+1)
	W2 = SplineSpace(p2-1, grid=grid_2); W2.init_fem(quad_order=p2+1)

	# Create 2D tensor product finite element space
	V = TensorFemSpace(V1, V2 )
	W = TensorFemSpace(W1, W2)

	Wdiv1 = TensorFemSpace(V1, W2)
	Wdiv2 = TensorFemSpace(W1, V2)
	
	return V, Wdiv1, Wdiv2, W
Exemplo n.º 4
0
def test_pdes_1d_1():
    print('============ test_pdes_1d_1 =============')

    # ... abstract model
    V = H1Space('V', ldim=1)

    v = TestFunction(V, name='v')
    u = TestFunction(V, name='u')

    a = BilinearForm((v,u), dot(grad(v), grad(u)))
    # ...

    # ... discretization
    # Input data: degree, number of elements
    p1  = 1
    ne1 = 4

    # Create uniform grid
    grid_1 = linspace( 0., 1., num=ne1+1 )

    # Create 1D finite element spaces and precompute quadrature data
    V = SplineSpace( p1, grid=grid_1 ); V.init_fem()
    # ...

    # ...
    discretize_symbol( a, [V,V] )
#    print(mass.symbol.__doc__)
    # ...

    # ...
    n1 = 21

    t1 = linspace(-pi, pi, n1)
    x1 = linspace(0.,1., n1)

    xs = [x1]
    ts = [t1]

    e = a.symbol(*xs, *ts)
    print('> ', e.min(), e.max())
Exemplo n.º 5
0
def test_pdes_3d_1():
    print('============ test_pdes_3d_1 =============')

    # ... abstract model
    V = H1Space('V', ldim=3)

    v = TestFunction(V, name='v')
    u = TestFunction(V, name='u')

    a = BilinearForm((v, u), dot(grad(v), grad(u)))
    # ...

    # ... discretization
    # Input data: degree, number of elements
    p1 = 1
    p2 = 1
    p3 = 1
    ne1 = 4
    ne2 = 4
    ne3 = 4

    # Create uniform grid
    grid_1 = linspace(0., 1., num=ne1 + 1)
    grid_2 = linspace(0., 1., num=ne2 + 1)
    grid_3 = linspace(0., 1., num=ne3 + 1)

    # Create 1D finite element spaces and precompute quadrature data
    V1 = SplineSpace(p1, grid=grid_1)
    V1.init_fem()
    V2 = SplineSpace(p2, grid=grid_2)
    V2.init_fem()
    V3 = SplineSpace(p3, grid=grid_3)
    V3.init_fem()

    # Create 2D tensor product finite element space
    V = TensorFemSpace(V1, V2, V3)
    # ...

    # ...
    discretize_symbol(a, [V, V])
    #    print(mass.symbol.__doc__)
    # ...

    # ...
    n1 = 21
    n2 = 21
    n3 = 21

    t1 = linspace(-pi, pi, n1)
    t2 = linspace(-pi, pi, n2)
    t3 = linspace(-pi, pi, n3)
    x1 = linspace(0., 1., n1)
    x2 = linspace(0., 1., n2)
    x3 = linspace(0., 1., n3)

    xs = [x1, x2, x3]
    ts = [t1, t2, t3]

    e = a.symbol(*xs, *ts)
    print('> ', e.min(), e.max())
Exemplo n.º 6
0
    analytic = lambda x: np.sin(2 * np.pi * x)

    # define dirichlet boundary conditions
    dirichletleft = 0.
    dirichletright = 0.

    # SplineSpace
    p = 3
    ne = 60
    grid = np.linspace(0., 1., ne + 1)

    # Main part
    print("Programm running ... ")

    V = SplineSpace(p, grid=grid)
    V.init_fem()

    # building stiffness matrix in a sparse matrix
    stiff = StiffnessMatrix(V)
    stiff = stiff.todense()

    rhs = assemblyRhs(V, sec)

    # homogenous dirichlet boundary conditions
    stiff = stiff[1:-1, 1:-1]
    rhs = rhs[1:-1]

    u = np.linalg.solve(stiff, rhs)
    u = list(u)
    u.insert(0, dirichletleft)
    u.append(dirichletright)