⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.asv

📁 efg code with matlab
💻 ASV
📖 第 1 页 / 共 2 页
字号:
% *************************************************************************
%                 TWO DIMENSIONAL ELEMENT FREE GALERKIN CODE
%                            Nguyen Vinh Phu
%                        LTDS, ENISE, Juillet 2006
% *************************************************************************

% Description:
% This is a simple Matlab code of the EFG method which is the most familiar 
% meshless methods using MLS approximation and Galerkin procedure to derive
% the discrete equations.
% Domain of influence can be : (1) circle and (2) rectangle
% Weight function : cubic or quartic spline function
% Nodes can be uniformly distributed nodes or randomly distributed 
% (in the latter case, this is read from a finite element mesh file)
% Numerical integration is done with background mesh
% Essential boundary condition is imposed using Lagrange multipliers or
% penalty method. 
% In case of Lagrange multipliers, but use the Dirac delta function to
% approximate lamda, we obtain the boundary point collocation method

% *************************************************************************

% Problem: the Timoshenko beam problem as given in EFG paper

% +++++++++++++++++++++++++++++++++++++
%          PROBLEM INPUT DATA
% +++++++++++++++++++++++++++++++++++++

clear all
clc
state = 0;
tic;           % help us to see the time required for each step

% Dimension of the domain (it is simply a rectangular region L x W)
L = 48 ;
D = 12 ;

% Material properties
E  = 30e6 ;
nu = 0.3 ;

% Chargement
P = 1000 ;

% Inputs special to meshless methods, domain of influence

shape = 'circle' ;         % shape of domain of influence
dmax  = 1.5 ;              % radius = dmax * nodal spacing
form  = 'cubic_spline' ;   % using cubic spline weight function

% Choose method to impose essential boundary condition
% disp_bc_method = 1 : Lagrange multiplier method
% disp_bc_method = 2 : Penalty method

disp_bc_method = 2 ;

% If Lagrange multiplier is used, choose approximation to be used for lamda
if disp_bc_method == 1
    %la_approx = 100 ;        % using finite element approximation
    la_approx = 200 ;         % using point collocation method    
end

% If penalty function is used, then choose "smart" penalty number :-)
if disp_bc_method == 2
    alpha = 1e5 ;           % penalty number
end

% +++++++++++++++++++++++++++++++++++++
%            NODE GENERATION
% +++++++++++++++++++++++++++++++++++++
% Steps:
%  1. Node coordinates
%  2. Nodes' weight function including : shape (circle or rectangle), size
%  and form (quartic spline or the other)

disp([num2str(toc),'   NODE GENERATION'])

% Node density defined by number of nodes along two directions
nnx = 11 ;
nny = 7  ;

% node generation, node is of size (nnode x 2)
node = square_node_array([0 -D/2],[L -D/2],[L D/2],[0 D/2],nnx,nny);
numnode = size(node,1);

% Boundary nodes
% 1. Displacement condition on the left edge with x = 0
% 2. Traction condition on the right edge with x = L

disp_nodes = find(node(:,1)==0) ;
trac_nodes = find(node(:,1)==L) ;
num_disp_nodes = length(disp_nodes);
num_trac_nodes = length(trac_nodes);

ubar = zeros(2*num_disp_nodes,1); % initialize of vector u bar
f    = zeros(2*numnode,1);        % nodal force vector

% +++++++++++++++++++++++++++++++++++++
%            GAUSS POINTS
% +++++++++++++++++++++++++++++++++++++
% Steps:
% 1. Mesh generation using available meshing algorithm of FEM
% 2. Using isoparametric mapping to transform Gauss points defined in each
%   element (background element) to global coordinates

disp([num2str(toc),'   BUILD GAUSS POINT FOR DOMAIN '])

% Meshing, Q4 elements
inc_u = 1;
inc_v = nnx;
node_pattern = [ 1 2 nnx+2 nnx+1 ];
element = make_elem(node_pattern,nnx-1,nny-1,inc_u,inc_v);

% Building Gauss points
[w,q]=quadrature(4, 'GAUSS', 2 );  % 4x4 Gaussian quadrature for each cell
W = [];
Q = [];
J = [];
for e = 1 : size(element,1)        % element loop
    sctr=element(e,:);             % element scatter vector
    for i = 1:size(w,1)                        % quadrature loop
        pt=q(i,:);                             % quadrature point
        wt=w(i);                               % quadrature weight
        [N,dNdxi]=lagrange_basis('Q4',pt);     % Q4 shape functions
        J0=node(sctr,:)'*dNdxi;                % element Jacobian matrix
        Q = [Q; N' * node(sctr,:)];            % global Gauss point
        W = [W; wt];                           % global Gauss point
        J = [J; det(J0)];
    end
end
clear w,q ;

% +++++++++++++++++++++++++++++++++++++
%  PLOT NODES,BACKGROUND MESH, GPOINTS
% +++++++++++++++++++++++++++++++++++++
disp([num2str(toc),'   PLOT NODES AND GAUSS POINTS'])
figure
hold on
cntr = plot([0,L,L,0,0],[-D/2,-D/2,D/2,D/2,-D/2]);
set(cntr,'LineWidth',3)
h = plot(node(:,1),node(:,2),'bo');
set(h,'MarkerSize',10.5);
AXIS([-1 L -D D])
axis off

figure
hold on
cntr = plot([0,L,L,0,0],[-D/2,-D/2,D/2,D/2,-D/2]);
set(cntr,'LineWidth',3)
plot_mesh(node,element,'Q4','--');
%plot(Q(:,1),Q(:,2),'r*');
axis auto
axis off

% +++++++++++++++++++++++++++++++++++++
%          DOMAIN ASSEMBLY
% +++++++++++++++++++++++++++++++++++++
disp([num2str(toc),'   DOMAIN ASSEMBLY'])
% Initialisation
K = sparse(2*numnode,2*numnode);
di = dmax * (L/(nnx-1));

% Plane stress matrix
C = (E/(1-nu*nu)) * [1 nu 0 ;
                     nu 1 0
                     0 0 0.5*(1-nu)] ;
% ----------------------------------------------
%             Loop on Gauss points
% ----------------------------------------------
for igp = 1 : size(W,1)
    pt = Q(igp,:);                             % quadrature point
    wt = W(igp);                               % quadrature weight

    % ----------------------------------------------
    % find nodes in neighbouring of Gauss point pt
    % ----------------------------------------------
    [index] = define_support(node,pt,di);

    % --------------------------------------
    %   compute B matrix, K matrix
    % --------------------------------------
    % Loop on nodes within the support, compute dPhi of each node
    % Then get the B matrix
    % Finally assemble to the K matrix

    B = zeros(3,2*size(index,2)) ;
    en = zeros(1,2*size(index,2));  
    [phi,dphidx,dphidy] = MLS_ShapeFunction(pt,index,node,di,form);
    for m = 1 : size(index,2)      
        B(1:3,2*m-1:2*m) = [dphidx(m) 0 ; 
                           0 dphidy(m);
                           dphidy(m) dphidx(m)];
        en(2*m-1) = 2*index(m)-1;
        en(2*m  ) = 2*index(m)  ;
    end
    K(en,en) = K(en,en) + B'*C*B * W(igp)*J(igp) ;
end

% +++++++++++++++++++++++++++++++++++++
%    INTEGRATE ON TRACTION BOUNDARY
% +++++++++++++++++++++++++++++++++++++
% Steps:
% 1. Build up Gauss points on the boundary, 4 GPs are used
% 2. Loop on these GPs to form the f vector
disp([num2str(toc),'   INTEGRATION ON TRACTION BOUNDARY'])

% --------------------------------------
%   Generation of Gauss points
% --------------------------------------

% 4 point quadrature for each "1D element"
[W1,Q1]=quadrature(4, 'GAUSS', 1 ); 

Wt = [];
Qt = [];
Jt = [];

for i = 1 : (num_trac_nodes - 1)
    sctr = [trac_nodes(i) trac_nodes(i+1)]; 
    for q = 1:size(W1,1)                            
        pt = Q1(q,:);                               
        wt = W1(q);                                 
        [N,dNdxi] = lagrange_basis('L2',pt);        
        J0=dNdxi'*node(sctr,:);                    
        Qt = [Qt; N' * node(sctr,:)];              
        Wt = [Wt; wt];                             
        Jt = [Jt; norm(J0)];
    end % of quadrature loop
end

% --------------------------------------
%   Form the nodal force vector f
% --------------------------------------
I = (1/12)*D^3;
f = zeros(2*numnode,1);
for igp = 1 : size(Wt,1)
    pt = Qt(igp,:);                             % quadrature point
    wt = Wt(igp);                               % quadrature weight
    [index] = define_support(node,pt,di);
    en = zeros(1,2*size(index,2));              
    force = zeros(1,2*size(index,2));
    [phi,dphidx,dphidy] = MLS_ShapeFunction(pt,index,node,di,form);
    tx = 0.0 ;
    ty = -(P/(2*I))*((D*D)/4-pt(1,2)^2);
    for j = 1 : size(index,2)
        en(2*j-1) = 2*index(j)-1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -