-
Notifications
You must be signed in to change notification settings - Fork 26
/
FEM_Cantilever.m
68 lines (56 loc) · 1.43 KB
/
FEM_Cantilever.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function FEM_Cantilever
clc;clear;close all
addpath(genpath(fileparts(mfilename('fullpath'))))
%file = 'test2d_triangle';
%a.fileName = file;
% s = FemDataContainer(a);
% Generate coordinates
x1 = linspace(0,2,20);
x2 = linspace(1,2,20);
% Create the grid
[xv,yv] = meshgrid(x1,x2);
% Triangulate the mesh to obtain coordinates and connectivities
[F,V] = mesh2tri(xv,yv,zeros(size(xv)),'x');
s.coord = V(:,1:2);
s.connec = F;
mesh = Mesh.create(s);
s.mesh = mesh;
s.type = 'ELASTIC';
s.scale = 'MACRO';
s.material = createMaterial(mesh,1);
s.dim = '2D';
s.bc = createBoundaryConditions(mesh);
fem = FEM.create(s);
fem.solve();
figure(1)
fem.uFun.plot()
figure(2)
fem.stressFun.plot()
figure(3)
fem.strainFun.plot()
fem.print('results_fem', 'Paraview') % print using Paraview
end
function bc = createBoundaryConditions(mesh)
dirichletNodes = abs(mesh.coord(:,1)-0) < 1e-12;
rightSide = max(mesh.coord(:,1));
isInRight = abs(mesh.coord(:,1)-rightSide)< 1e-12;
isInMiddleEdge = abs(mesh.coord(:,2)-1.5) < 0.1;
forceNodes = isInRight & isInMiddleEdge;
nodes = 1:mesh.nnodes;
bc.dirichlet = nodes(dirichletNodes);
bc.pointload(:,1) = nodes(forceNodes);
bc.pointload(:,2) = 2;
bc.pointload(:,3) = -1;
end
function material = createMaterial(mesh,ngaus)
I = ones(mesh.nelem,ngaus);
s.ptype = 'ELASTIC';
s.pdim = '2D';
s.nelem = mesh.nelem;
s.mesh = mesh;
s.kappa = .9107*I;
s.mu = .3446*I;
mat = Material.create(s);
mat.compute(s);
material = mat;
end