内部惩罚不连续 Galerkin Matlab 实现

计算科学 matlab 不连续-galerkin
2021-12-23 06:55:06

我想使用内部惩罚不连续 Galerkin 方法解决 2D 泊松问题:

-∇a(x)(∇u)=0,单位为 Ω。

变分公式是这样的:

aϵ(u,v)=KThKauveΓhΓDe{aune}[v]+eΓhΓDeϵ{avne}[u]+eΓhΓDσ0|e|e[u][v]

我设法正确实现并计算和组装四边形元素的通量项。然而对于三角形,它变得有点难,我不知道该怎么做。有人能帮助我吗?

function Sigma = edgeT3_Lagrange(x_node_edge,y_node_edge,eps,alp,gam,bet,edge_data)

    %% Calculate normal outward poining normalized vector
    delta_x = x_node_edge(:,end)-x_node_edge(:,1); 
    delta_y = y_node_edge(:,end)-y_node_edge(:,1); 

    % Tangentiels 
    t1 = delta_x ; 
    t2 = delta_y ;  

    % Normal outward poining normalized vector 
    nv = [t2;-t1]/sqrt((t1^2)+(t2^2));

    % Calculate the trace : Length of the edge 
    trace_edge  = sqrt((delta_x)^2 + (delta_y)^2);

    % the average local mesh size 
    h_avg  = (h_E1 + h_E2)/2 ; /circumradius 
    h_avg_beta  = h_avg.^bet ; 

    %% Space allocation
    % Matrices Initiation 
    Sigma = [{zeros(DG_DATA.NN_elem)} {zeros(DG_DATA.NN_elem)} {zeros(DG_DATA.NN_elem)} {zeros(DG_DATA.NN_elem)}];

    %% Gauss points and weights
    N_GAUSS_POINT = 3; %total number of gauss points = (N_GAUSS_POINT)^2
    GAUSS_POINT   = [-1 1 0 ]*sqrt(3/5);
    GAUSS_WEIGHT  = [5 5 8 ]/9;

    %% Calculus Loop sur Sigma de s
    for ng=1:N_GAUSS_POINT

        %-----------------------------------------------------------------------
        %-----------------------------------------------------------------------
            s = GAUSS_POINT(ng);

            % Jacobian matrix for surface integral
            Jc     = trace_edge/2 ; 
            detJc  = det(Jc); 

        %-----------------------------------------------------------------------
        %-----------------------------------------------------------------------
        % Assignment of the edge
        %-------------------------------------
        %-------------------------------------
        % For     :      the edge {i} of E1 
        % Thereby >>     the edge {j} of E2 
        % And the integration is done on s
        %-------------------------------------
        %-------------------------------------

            S = (s+1)/2;    

        %   t  = [xi  nu]
            t  = [S        0;
                  1-S      S;
                   0       S;];

        %-----------------------------------------------------------------------
        %-----------------------------------------------------------------------

            % Legendre polynomials p=1
            % corresponding to the element E1 
            xi1        = t(edge_number(1),1);  
            nu1        = t(edge_number(1),2);  
            P1         = elemT3_Poly(xi1,nu1); 
            N_1        = P1{1,1}                ; % [N]
            N_dot_1    = [P1{1,2}; P1{1,3}]     ; % [N,xi ; N,nu]

            % Jacobian matrix for the reference element
            J1         = (N_dot_1*[x_node_1' y_node_1'])' ;
            j1         = inv(J1'); % (J')^-1
            N_dotp_1   = ( j1 * N_dot_1); 

            % 
            % Legendre polynomials p=1
            % corresponding to the element E2 

            xi2        = t(edge_number(2),1);  
            nu2        = t(edge_number(2),2);
            P2         = elemT3_Poly(xi2,nu2); 
            N_2        = P2{1,1}                ; % [N]
            N_dot_2    = [P2{1,2}; P2{1,3}]     ; % [N,xi ; N,nu]    

            % Jacobian matrix for the reference element
            J2         = (N_dot_2*[x_node_2' y_node_2'])';
            j2         = inv(J2'); % (J')^-1
            N_dotp_2   = ( j2 * N_dot_2) ; 

        %-----------------------------------------------------------------------
        %-----------------------------------------------------------------------

            % Flux expressions
            Sigma{1} = Sigma{1} + GAUSS_WEIGHT(ng)*( -0.5*N_1.'*(nv'*(N_dotp_1)) + (eps/2)*((N_dotp_1).'*nv)*N_1 + (alp/h_avg_beta)*(N_1.')*N_1 + (gam/h_avg_beta)*(N_dotp_1.')*N_dotp_1 )*detJc ; %B
            Sigma{2} = Sigma{2} + GAUSS_WEIGHT(ng)*( +0.5*N_2.'*(nv'*(N_dotp_2)) - (eps/2)*((N_dotp_2).'*nv)*N_2 + (alp/h_avg_beta)*(N_2.')*N_2 + (gam/h_avg_beta)*(N_dotp_2.')*N_dotp_2 )*detJc ; %C
            Sigma{3} = Sigma{3} + GAUSS_WEIGHT(ng)*( +0.5*N_2.'*(nv'*(N_dotp_1)) + (eps/2)*((N_dotp_2).'*nv)*N_1 - (alp/h_avg_beta)*(N_2.')*N_1 - (gam/h_avg_beta)*(N_dotp_2.')*N_dotp_1 )*detJc ; %D    
            Sigma{4} = Sigma{4} + GAUSS_WEIGHT(ng)*( -0.5*N_1.'*(nv'*(N_dotp_2)) - (eps/2)*((N_dotp_1).'*nv)*N_2 - (alp/h_avg_beta)*(N_1.')*N_2 - (gam/h_avg_beta)*(N_dotp_1.')*N_dotp_2 )*detJc ; %E

        %-----------------------------------------------------------------------
        %-----------------------------------------------------------------------

    end

end
1个回答

如果您坚持使用 MATLAB,以下书籍的第 14 章将使用三角形上的分段线性基函数来解决 2D IPDG Poisson 问题:

有限元方法:理论、实现和应用

本书中大多数示例使用的 MATLAB 代码可在 github 上免费获得:

https://github.com/Jumziey/FEM/tree/master/MatlabCodeFEMBook

IPDG 特定代码在脚本“dG1PoissonSolver2D.m”中

正如评论中提到的,研究有限元库可能是值得的,因为与您自己的问题相比,您可能更容易扩展您的问题(3D、不同元素、自适应性、高阶等) MATLAB 代码。