-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_fem.m
51 lines (40 loc) · 1.51 KB
/
main_fem.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [u,f,x,y,conn] = main_fem(mesh_file,Ff,BC,sprop,ndim_out)
% Input : mesh_file = file name where mesh data is stored
% Ff = force vector function/expression
% BC = cell array containing BC information
% Output: u = solution vector
% f = force vector
% x = x coords
% y = y coords
% conn = connectivity array
% Get constants from solid properties structure
lambda = sprop.lambda;
mu = sprop.mu;
% Read mesh files
[x,y,conn,nx,ny,nelem,npe] = read_mesh(mesh_file);
Lx = max(x)-min(x); Ly = max(y)-min(y);
% Initialize global arrays (2D)
k = zeros(ndim_out*nx*ny); f = zeros(ndim_out*nx*ny,1);
% Set up Gauss pts (linear triangle, ng = 3)
ng = 3;
[ksi_G,eta_G,W_G] = tri_Gpts_3();
% Loop elements
for ne=1:nelem
% Order points correspond with convention, get node locations
[conn(ne,:),xl,yl] = tri_reorder(x,y,conn(ne,:));
% Calculate Jacobian for element
[J,J_mat] = tri_Jac(xl,yl);
% J_mat = [dx/dksi, dx/deta]
% [dy/dksi, dy/deta]
% Set up function handle for shape functions for parent element
shpg = @(n,J_mat) tri_shp_grad(n,J_mat);
shp = @(n,ksi,eta) tri_shp(n,ksi,eta);
% Compute local stiffness matrix
kl = tri_localk_les(J_mat,shpg,shpg,lambda,mu);
% Compute local force vector
fl = tri_localf(ng,ksi_G,eta_G,W_G,shp,Ff);
% Assemble local stiffness matrix and force vector into global
[k,f] = global_assemble(k,f,kl,fl,x,y,conn(ne,:),J,BC);
end
% Solve matrix equation
u = k\f;