Implementation of MATLAB code for element stiffness matrix calculation of planar four-node isoparametric element and eight-node isoparametric element

(I’m very busy today, let’s talk about it first, the code is directly placed here, and a small amount of diagrams are attached, if I have time in the future, I will make a special article about finite elements)

The following is the stiffness matrix calculation program of the matlab plane four-node isoparametric element

The first one is test.mlx, this part is to calculate the symbol matrix of the stiffness matrix. First, for the four-node elements, the numbers are numbered counterclockwise, that is: for the four-node elements, the element stiffness matrix
insert image description here
is ​​an 8x8 matrix. Its sign matrix is ​​calculated as follows

test.mlx (this is for testing, just click on the new live script in the left file column for the mlx file)

% 四节点单元刚度矩阵函数 E杨氏模量, nu 泊松比, h板厚度
syms x 
syms y 
syms E nu h

M = [
    [1, x, y, x*y,0,0,0,0]
    [0,0,0,0, 1, x, y, x*y]
    ];

A = [
    [1 -1 -1 1 0 0 0 0]
    [0 0 0 0 1 -1 -1 1]
    [1 1 -1 -1 0 0 0 0]
    [0 0 0 0 1 1 -1 -1]
    [1 1 1 1 0 0 0 0]
    [0 0 0 0 1 1 1 1]
    [1 -1 1 -1 0 0 0 0]
    [0 0 0 0 1 -1 1 -1]
    ];

N = M/A;  % M * inv(A) , 为形状函数矩阵

% 对x, y等参变量求导并得到对应的应变矩阵

% 对x, y等参变量求导并得到对应的应变矩阵
N_x = diff(N,x);
N_y = diff(N,y);

B = [N_x(1,:)
     N_y(2,:)
     N_y(1,:) + N_x(2,:)];

clear N_x N_y

D = E /(1-nu^2) * [
[1 nu 0]
[nu 1 0]
[0 0 (1- nu)/2]
];

k_e = transpose(B) * D * B;
Ke = h*int(int(k_e,x,[-1, 1]), y, [-1,1]);  % 积分求解对应的四节点刚度矩阵
Ke2 = Ke/(E * h/(1-nu^2));
simplify(Ke2)

The solution result is like this (you can also use a .m file to run).
insert image description here
The correctness of this can refer to "Structural Finite Element Analysis" Liu Yongshou 2nd Edition, page 51, the stiffness matrix above is a/b = 1 after substituting and This stiffness matrix results in the same.
Therefore, to solve the element stiffness matrix, we only need to substitute the value into

Attached below is the MATLAB function code that can be directly copied and pasted. The
calling method of this function is K_e = elem401(E, nu, h)
where E is Young's modulus, nu is Poisson's ratio, and h is the thickness of the flat plate.
For example, elem401(2e5, 0.3, 10)the parameter is Young's modulus 200Gpa (due to the unit is mm, and Pa is N/m 2 N/m^2N/m2 , so2 × 1 0 11 P a = 2 × 1 0 5 N / mm 2 ) 2\times10^{11}Pa=2\times 10^5N/mm^2)2×1011Pa=2×105N/mm2 )
The unit of stiffness obtained by the above calling method isN/mm N/mmN / m m (you use mm as the unit to calculate)
of course, using m as the unit to calculate canelem401(2e11, 0.3, 0.01)directly return the corresponding stiffness matrix

elem401.m

% 四节点单元刚度矩阵函数 E杨氏模量, nu 泊松比, h板厚度
function Ke = elem401(E,nu,h)
syms x 
syms y 

M = [
    [1, x, y, x*y,0,0,0,0]
    [0,0,0,0, 1, x, y, x*y]
    ];

A = [
    [1 -1 -1 1 0 0 0 0]
    [0 0 0 0 1 -1 -1 1]
    [1 1 -1 -1 0 0 0 0]
    [0 0 0 0 1 1 -1 -1]
    [1 1 1 1 0 0 0 0]
    [0 0 0 0 1 1 1 1]
    [1 -1 1 -1 0 0 0 0]
    [0 0 0 0 1 -1 1 -1]
    ];

N = M/A;  % M * inv(A) , 为形状函数矩阵

% 对x, y等参变量求导并得到对应的应变矩阵
N_x = diff(N,x);
N_y = diff(N,y);

B = [N_x(1,:)
     N_y(2,:)
     N_y(1,:) + N_x(2,:)];

clear N_x N_y

D = E * h/(1-nu^2) * [
[1 nu 0]
[nu 1 0]
[0 0 (1- nu)/2]
];

k_e = transpose(B) * D * B;
Ke = int(int(k_e,x,[-1, 1]), y, [-1,1]);  % 积分求解对应的四节点刚度矩阵
end

In addition, it should be noted that the element stiffness matrix must be a singular matrix, that is, det ( K e ) = 0 det(K_e) = 0d e t ( Ke)=0 , if you need to display the matrix, youvpa(K_e)can use it, but note that this will lose precision and causedet detd e t is not 0

The following is the matlab code of the eight-node unit.
The calling method is K_e = Elem801(E,nu,h)
that the order of the node numbers is

insert image description here
Source program Elem801.m

function Ke = Elem801(E, nu,h)
    syms x y
    % 对于平面八节点单元,共有
    M = [
        [1 x y x^2 x*y y^2 x^2*y x*y^2 0 0 0 0 0 0 0 0]
        [0 0 0 0 0 0 0 0 1 x y x^2 x*y y^2 x^2*y x*y^2]
        ];
    
    
    % 定义八节点单元的x_e和y_e
    x_e = [-1 0 1 1 1 0 -1 -1];
    y_e = [-1 -1 -1 0 1 1 1 0];
    
    % 创建初始矩阵A
    A = zeros(16,16);
    for i = 1:8
        A(2*i-1:1:2 *i,:) = subs(M,[x,y],[x_e(i),y_e(i)]);
    end
    
    % 计算形状函数矩阵 
    N = M/A;
    
    % 使用求导方法求解对应的位移函数
    N_x = diff(N,x);
    N_y = diff(N,y);
    B = [N_x(1,:)
         N_y(2,:)
         N_y(1,:) + N_x(2,:)
         ];
    clear N_x N_y
    % 刚度矩阵D
    D = E/(1-nu^2) * [
        [1 nu 0]
        [nu 1 0]
        [0 0 (1- nu)/2]
        ];
    
    ke_pre = transpose(B)*D*B;  % 注意不能使用B'
    Ke = h * int(int(ke_pre,x,[-1, 1]), y, [-1,1]); % 积分得到刚度矩阵
    % 注意不能使用vpa函数, vpa函数会产生截断误差
    clear ke_pre
end
% Test Code: Elem801(2e5,0.3, 10)

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/sbsbsb666666/article/details/130395745