Вы находитесь на странице: 1из 19

Report on Computer Homework 1

MECH_ENG 426: Advanced Finite Elements I

Sourav Saha
PhD student, Theoretical and Applied Mechanics
Northwestern University

i
Table of Contents
Page
Introduction 3
Problem Description 3
Result and Discussion 4
Solution of Problem 1 4
Solution of Problem 2 7
Solution of Problem 3 9
Conclusions 15
MATLAB CODE 16
List of Figures
Fig. 1 Figure for problem 1 and 2 with the specified boundary conditions. 3

Fig. 2 Figure for problem 3 with the proper conditions. 3


Fig. 3 Stress field of the one-dimensional bar at the end of 3 passes of the wave. (a) 4
50 elements, (b) 100 elements, (c) 150 elements, and (d) 200 elements.
Fig. 4 Time history of mid-point stress field of the one-dimensional bar for 3 passes 5
of the wave. (a) 50 elements, (b) 100 elements, (c) 150 elements, and (d) 200
elements.
Fig. 5 Time history of mid-point displacement of the one-dimensional bar for 3 6
passes of the wave. (a) 50 elements, (b) 100 elements, (c) 150 elements, and
(d) 200 elements.
Fig. 6 Time history of left-point velocity of the one-dimensional bar for 3 passes of 7
the wave. (a) 50 elements, (b) 100 elements, (c) 150 elements, and (d) 200
elements.
Fig. 7 Comparison of (a) mid-point displacement of the bar for 200 element and 4 8
pass waves with (b) closed form solution
𝑙
Fig. 8 Unstable solution for problem 2 with critical time step of and damping 9
𝑐
parameter of of 0.2 with 150 mesh elements. (a) Stress field. (b) Mid-point
stress with time. (c) Mid-point displacement with time, (d) Energy output
from system.
𝑙
Fig. 9 Stable solution for problem 2 with critical time step of 99% of (√1 − 𝜉 2 − 10
𝑐
𝜉) and damping parameter of of 0.2 with 150 mesh elements. (a) Stress field.
(b) Mid-point displacement with time. (c) Mid-point stress with time, (d)
Energy output from system (wave passes 3 times in the entire domain.)
Fig. 10 Stable solution for problem 2 with different critical time steps less than 11
𝑙
(√1 − 𝜉 2 − 𝜉) and damping parameter of of 0.2 with 150 mesh elements.
𝑐
𝑙
(a) 99%, (b) 97%, (c) 95%, (d) 90% of (√1 − 𝜉 2 − 𝜉) in terms of stress field
𝑐
(after 3 passes of waves).
𝑙
Fig. 11 Stable solution for problem 3 with critical time step (√1 − 𝜉 2 − 𝜉) and 13
𝑐
damping parameter of of 0.2 with 150 mesh elements. (a) Stress field, (b) Mid-
point deisplacement, (c) Mid-point stress, (d) Total energy of system. (after 3
passes of waves).
𝑙
Fig. 12 Stable solution for problem 3 with critical time step (√1 − 𝜉 2 − 𝜉) and damping
𝑐
14
parameter of of 0.2 with 150 mesh elements. (a) Stress field, (b) Mid-point
deisplacement, (c) Mid-point stress, (d) Total energy of system. (after 3 passes of
waves).

ii
Introduction
Nonliear FEM is an advanced stage to our previous course of ME 327. The focus of the course
revolves around teaching the students solving non-linear problems with FEM technique. As an
introduction, we are given to solve 3 problems with total Lagrange formulation and explicit
time integration technique. All of the problems deal with vibration analysis inside 1D bar under
different initial and boundary conditions. In the current homework, we solved 1D bar under
axial load and analyzed its vibrational responses over the time. We considered the impact of
Rayleigh damping parameter on the behaviour of the vibration of the bar and also how ciritcal
timestep controls the stability of the solution. As a check against the instability of solution, we
measured the energy balance for each problem and obsered how the total, internal, external,
and kinetic energies change with time.
Problem Description
The first problem in this homework deals with 1D bar shown in Fig.1. The load is applied at
the left edge as denoted by P and right end is fixed. For the problem 1 and 2, P(t) = 250 H(t),
where H(t) is the Heaviside step function. This is applied as the boundary condition for this
problem. The Young’s modulus of the material is 200 GPa, and density is given by 7850 kg/m3.
The sectional area and length are mentioned in the figure. Problem 1 involves simple solution
of the problem with different elements sizes and reflection of the waves. Initial conditions for
the problems are v (0) = u (0) = 0. Problem 2 involves adding a damping coefficient in the
problem with Rayleigh damping parameter. We need to check whether the solution is stable or
not for the problem.

Fig. 1 Figure for problem 1 and 2 with the specified boundary conditions.

3
Fig. 2 Figure for problem 3 with the proper conditions.
Problem 3 (shown in Fig. 2) involves a more complicated task. It describes a falling rod which
falls on to the ground. The boundary condition is given so that there is no penetration from the
bottom of the rod. We needed to add an external load at the bottom of the rod as f(x) = kx1 so
that there is no penetration of the rod at the bottom when it falls on to the ground. Unlike the
previous problem, there will be a body force equal to the weight of the rod per unit length. Also
I am taking the x = 0 as the initial condition. This gives u (0) = 0 but there will be an initial
velocity of √2𝑔ℎ in the problem. Moreover, there is an initial acceleration of -9.81ms2 acting
in the body. To solve all the problems the number of elements were varied from 50 to 200. For
all the cases, the problem is solved for 2-3 wave passes.
Results and Discussion
Solution of Problem 1

x 10
8
Stress Field 8
Stress Field
(a) -1.5 (b) -1.5
x 10

-2
-2
Stress, Pa

Stress, Pa

-2.5

-2.5
-3

-3.5 -3

-4 -3.5
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Position, m Position, m

x 10
8
Stress Field x 10
8
Stress Field
-1.5 -1.5
(c) (d)
-2 -2
Stress, Pa
Stress, Pa

-2.5 -2.5

-3 -3

-3.5 -3.5
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Position, m Position, m
Fig 3. Stress field of the one-dimensional bar at the end of 3 passes of the wave. (a) 50
elements, (b) 100 elements, (c) 150 elements, and (d) 200 elements.

4
Problem 1 asks for the solution of the shock loaded beam for 50-200 elements. In Figure 3, I
have shown the stress field after 3 passes of waves inside the rod for all the elements. The
solution are obained for a timestep of half the critical timestepw which ensures stability. As we
can observe, the stress is a compressive one and it actually moves back and forth. Since I have
shown the figure at the last time step it may not be visible, but the shows show that the stress
actually goes back and forth inside the rod. This will be more clear from Fig 4 where we can
see the time history of stress at the midpoint of the bar. Fig. 4 shows that for 3 passes of the
wave inside the rod, the midplane stress actually oscilates. It also shows a low frequency waves
at any stress jumps which is also known as the Gibb’s phenomenon. Definition of Gibb’s
phenomenon is that at a jump discontinuity a piecewise continuously differentiable function
has a peculiar behaviour of showing signs of vibration. As the number of elements is raised the

x 10
8 Mid-point stress 8 Mid-point stress
(a) 0 (b) 0
x 10

-1
-1
Stress, Pa

-2
Stress, Pa
-2

-3
-3

-4
-4

-5
-5

-6
0 2 4 6 -6
0 2 4 6
Time, s x 10
-4
Time, s x 10
-4

8 Mid-point stress x 10
8 Mid-point stress
(c) 0
x 10 (d) 0

-1 -1
Stress, Pa
Stress, Pa

-2 -2

-3 -3

-4 -4

-5 -5

-6 -6
0 2 4 6 0 2 4 6
Time, s x 10
-4 Time, s x 10
-4

Fig 4. Time history of mid-point stress field of the one-dimensional bar for 3 passes of the
wave. (a) 50 elements, (b) 100 elements, (c) 150 elements, and (d) 200 elements.

5
resolution of stress has increased. But other than that the pattern is similar. Fig 5. shows the
midplane displacement for problem 1 with different elements for 3 reflections of waves. As we
can obsevere from the figure that, the midpoint displacement for three passes of the system. As
we can observe, the displacement at the midpoint of the bar reaches a maximum while passing
of the wave and after comes down to. This is a normal representation of passing of a wave
inside a bar.

x 10
-3 Mid-point displacement
1.4 -3 Mid-point displacement
(a) (b) 1.4
x 10

1.2
Displacement, m

1.2

Displacement, m
1
1
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
0 2 4 6 0
0 2 4 6
Time, s x 10
-4

Time, s x 10
-4

x 10
-3 Mid-point displacement -3 Mid-point displacement
(c) 1.4 (d) 1.4
x 10

1.2
Displacement, m

1.2
Displacement, m

1
1
0.8
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0
0 2 4 6 0
0 2 4 6
Time, s x 10
-4
Time, s x 10
-4

Fig 5. Time history of mid-point displacement of the one-dimensional bar for 3 passes of the
wave. (a) 50 elements, (b) 100 elements, (c) 150 elements, and (d) 200 elements.
Fig. 6 shows the displacement at the left node of the rod with time as the wave goes back and
forth. From the figure it is obvious that there is an increase in the velocity as the waves passes
through the left point and with the cycles of wave passing, there is a decrease.

6
(a) 2.5
x 10
-3 Left-point velocity (b) 2.5
x 10
-3 Left-point velocity

2 2
Velocity, ms!1

Velocity, ms!1
1.5 1.5

1 1

0.5 0.5

0 0
0 2 4 6 0 2 4 6
Time, s x 10
-4
Time, s x 10
-4

(c) x 10
-3 Left-point velocity (d)
2.5 x 10
-3 Left-point velocity
2.5

2
Velocity, ms!1

2
Velocity, ms!1

1.5
1.5

1
1

0.5
0.5

0
0 2 4 6 0
0 2 4 6
Time, s x 10
-4

Time, s x 10
-4

Fig 6. Time history of left-point velocity of the one-dimensional bar for 3 passes of the wave.
(a) 50 elements, (b) 100 elements, (c) 150 elements, and (d) 200 elements.
In order to compare the accuracy of the solution, I have chosen to compare the solution of 4
pass waves wih that of the closed form solution in terms of the mid-point velocity (see Fig. 7).
We can observe that there is a similarity with the closed form solution for the problem. Equal
amount of rise time, stay time, and also drop time per cycle are observed from both the solutions
of the problem.
Solution of Problem 2
Problem 2 asks to modify the constitutive law by adding a damping term to the equation.
𝑑𝜀
𝜎 = 𝐸𝜀 + 𝛼2 𝐸
𝑑𝑡
Here, α2 is the co-efficient of Rayleigh damping parameter. This damping introduces a velocity
dependent term in the equation and has a significant effect on the critical time.

7
x 10
-4 Mid-point displacement
14
(a) (b)
12
Displacement, m

10

-2
0 2 4 6 8
Time, s x 10
-4

Fig 7. Comparison of (a) mid-point displacement of the bar for 200 element and 4 pass
waves with (b) closed form solution.

The critical time step actually governs the stabilty of the solution. The definition α2 in the
2𝜉
problem is given by, 𝛼2 = where ω is the maximum frequency. In the simulation I have
𝜔
controlled the value of ξ in order to find out how the damping effects the stability of the
solution. As asked by the question, at first, the value of ξ = 0.2 while the critical time step is
not modified by the damping effect and kept as usual like what was done to solve the problem
1. The results for that are shown in the Figure 8. We can clearly see that the solution actually
blows up with time. It will be more apparent if we take a look at the total energy scenario of
the problem where, the energy kind of blows up unpropotionately with time at the end of the
simulation. Later, according to the instruction of the question, I modified the critical timesep
incoporating the effect of ξ. After that I tested to see whether the solution is stable. The question
asks to reduce the time step from 1% to 5% and I found for each case the simulation is stable.
Figure 9 shows the the results for stress field, mid-point displacement, mid-point stress and
energy balance for each case. The figure shows result for 150 mesh elements and after 3 passes
of waves with 99% of the modified critical time-step. The energy balance plot shows that the
energy for the problem is conserved. Hence the solution is stable and converged. Figure 10
exhibits the stress field after 3 passes of waves inside the bar for different sizes of critical time
step. As we can observe, there is a consistency of solution in the problem with timestep within
the range of 1-5% of the modified critical time step of the problem. Actually, the solutiom
remains stable if the critical time step is less than the modified critical time step. For example,
if ξ = 0.2, the actual crtical time-step is equal to approximately 81% of the unmodified or
original time step (as in problem 1). If this specific time-step is exceeded we will observe
unstable solution.

8
x 10
137
Stress Field 199 Mid-point stress
(a) 1 (b) 2 x 10
1
0.5
0

Stress, Pa
Stress, Pa

-1
0
-2

-3
-0.5
-4

-1 -5
0 0.2 0.4 0.6 0.8 1 0 2 4 6
Position, m Time, s x 10
-4

185 Mid-point displacement


x 10
(c) 2 (d)
1
Displacement, m

-1

-2

-3

-4

-5
0 2 4 6
Time, s x 10
-4

𝑙
Fig 8. Unstable solution for problem 2 with critical time step of 𝑐 and damping parameter of
of 0.2 with 150 mesh elements. (a) Stress field. (b) Mid-point stress with time. (c) Mid-point
displacement with time, (d) Energy output from system.

Solution of Problem 3
Problem 3 involves a more complex situation in hand. In this problem, we are treating a falling
vertical bar on the ground and there will be impact force from the ground. The bar is falling
from a height of 500 mm. So the initial point of simulaiton can be regarded as a barpoint 500
mm above from ground or just after impact. I considered the starting point at the point of
impact. Now for this problem, there will be additional body force which is equal to the weight
of the bar. Additionally, there will be an initial acceleration of -9.81 ms-2. Considering all of
these factors and also the damping effect, the solution of the problem is presented in Fig. 11

9
x 10
8
Stress Field x 10
-3 Mid-point displacement
(a) -2.4 (b) 1.4

1.2

Displacement, m
-2.6
1
Stress, Pa

-2.8 0.8

-3 0.6

0.4
-3.2
0.2

-3.4 0
0 0.2 0.4 0.6 0.8 1 0 2 4 6
Position, m Time, s x 10
-4

8 Mid-point stress Test of Energy Convergence


x 10
(c) 0 (d) 5000 Internal Energy
External Energy
-1
Kinetic Energy
Total Energy
Stress, Pa

-2
Work J

-3 0

-4

-5

-6 -5000
0 2 4 6 0 2 4 6
Time, s x 10
-4
Time, s x 10
-4

𝑙
Fig 9. Stable solution for problem 2 with critical time step of 99% of 𝑐 (√1 − 𝜉 2 − 𝜉) and
damping parameter of of 0.2 with 150 mesh elements. (a) Stress field. (b) Mid-point
displacement with time. (c) Mid-point stress with time, (d) Energy output from system (wave
passes 3 times in the entire domain.)

for a stable time step solution (after 3 passes of wave and 150 mesh elements). From Fig. 11
we can oberve that clearly there is a point of impact at the left end of the bar. But since the plot
is taken after 3 wave passing, there is actually zero stress at that end. But the part is obsecured
by the vibration motion. This will be aparent if we observe the midpoint displacement of the
bar. We can see that there is a growing and pulsating upwards movement of the midpoint due
the immense force acting from the left end of the bar. The upwards movement suggests that
the bar will move up vertically after the impact.

10
x 10
8
Stress Field (b) -2.45 x 10
8
Stress Field
(a) -2.4

-2.6 -2.5

Stress, Pa
Stress, Pa

-2.8 -2.55

-3 -2.6

-3.2 -2.65

-3.4 -2.7
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Position, m Position, m

8
Stress Field x 10
8
Stress Field
(c) -2.4
x 10 (d) -2.495

-2.5
-2.5
-2.505
Stress, Pa
Stress, Pa

-2.6
-2.51
-2.7
-2.515
-2.8 -2.52

-2.9 -2.525

-3 -2.53
0 0.2 0.4 0.6 0.8 1 0 0.2 0.4 0.6 0.8 1
Position, m Position, m
𝑙
Fig 10. Stable solution for problem 2 with different critical time steps less than (√1 − 𝜉 2 −
𝑐
𝜉) and damping parameter of of 0.2 with 150 mesh elements. (a) 99%, (b) 97%, (c) 95%, (d)
𝑙
90% of 𝑐 (√1 − 𝜉 2 − 𝜉) in terms of stress field (after 3 passes of waves).

The motion and stress both are pulstaing in nature due to the vibrational nature of the solution.
Had it been a perfectly elastic deflection the displacement would be straight line going
upwards.

11
(a) (b)
x 10
10
Stress Field Mid-point displacement
8 0.14

6 0.12

Displacement, m
4 0.1
Stress, Pa

2 0.08

0 0.06

-2 0.04

-4 0.02

-6 0

-8 -0.02
0 0.2 0.4 0.6 0.8 1 0 2 4 6
Position, m Time, s x 10
-4

(c) (d)
x 10
11 Mid-point stress x 10 Test of Energy Convergence
8
1 1
Internal Energy
External Energy
0.5 Kinetic Energy
0.5 Total Energy
Stress, Pa

Work J

0
0
-0.5

-0.5
-1

-1.5 -1
0 2 4 6 0 2 4 6
Time, s x 10
-4
Time, s x 10
-4

𝑙
Fig 11. Stable solution for problem 3 with critical time step (√1 − 𝜉 2 − 𝜉) and damping
𝑐
parameter of of 0.2 with 150 mesh elements. (a) Stress field, (b) Mid-point deisplacement, (c)
Mid-point stress, (d) Total energy of system. (after 3 passes of waves).
Fig. 12 shows the unstable solution the question asks to investigate. Here, I gave the critical
timestep the usual l/c form while adding a damping of 0.2. Just like the case of Problem 2

12
(a) (b)
x 10
206
Stress Field x 10
189 Mid-point displacement
1.5 2

Displacement, m
1
0
Stress, Pa

0.5
-1
0
-2
-0.5
-3
-1 -4

-1.5 -5
0 0.2 0.4 0.6 0.8 1 0 2 4 6
Position, m Time, s x 10
-4

(c) x 10
203 Mid-point stress (d) x 10 Test of Energy Convergence
307
2
6 Internal Energy
External Energy
1 5 Kinetic Energy
4 Total Energy
Stress, Pa

0
Work J

3
-1 2
1
-2
0
-3 -1
-2
-4
0 2 4 6 0 2 4 6
Time, s x 10
-4
Time, s x 10
-4

𝑙
Fig 12. Unstable solution for problem 3 with critical time step and damping parameter of
𝑐
0.2 with 150 mesh elements. (a) Stress field, (b) Mid-point deisplacement, (c) Mid-point
stress, (d) Total energy of system. (after 3 passes of waves).
solution seems to blow up due to instablity. My analysis of the critical time step and the stability
of the system suggests that we should not exceed the value of the critical time step. If we are
considering the damping of 0.2, the maximum limit of the time step is 81% of the critical time
step. If we go beyond that time step the solution blows up.

13
Conlcusion
By working on this project, I have gained a clear picture of how to program and solve a 1D
nonlinear FEM problem in the computer. This has enabled me to further explore to further
explore other types of FEM problem using computer programming. Additionally, solving these
problems also has provided me with the insight on how stability, critical time-step controls the
FEM solution. Besides the instructor was kind enough to permit us an ample amount of time
to solve the problem which helped me immensely. I am extremely interested in working on
computational mechanics field as my PhD thesis. This project has tremendously helped me to
gain insight into these problems.

14
MATLAB CODE
Problem 1 and 2
%%%%%%%%%%%%%%%%%%% CEE 426-1 : Computer homework 1 %%%%%%%%%%%%%%%%%%%%%%%
% Instructions:
% Use the provided code to construct a total Lagrangian nonlinear 1D FEA
% analysis. Sections that need to be complete by you are marked in block
% comments. e.g.
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % Do something here
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [] = HW2_mycopyW()
%% Input parameters.
nn = 151; % Number of nodes.
bar_length = 1; % Length of the computational domain.
runtime = 3.0; % Number of times for wave to cross domain.
youngs = 2e11; % Modulus of elasticity (for linear).
rho = 7850; % Density per unit length.
A = 100e-6; % Cross-sectional area
el = bar_length/(nn-1);
Be = (1/el)*[-1 1];
damp = 0.2;
v_p = zeros(nn-1,1);
P_e = zeros(nn-1,1);

%% Calculated parameters.
c = sqrt(youngs/rho); % Wave speed.
%disp(c)
t_crit = (((1+damp^2)^0.5)-damp)*(bar_length/(nn-1)/c); % Critical timestep.
% t_crit = (bar_length/(nn-1)/c);
alpha2 = damp*bar_length/c/(nn-1);
dt = t_crit; % Timestep size.
%dt = 0.5*t_crit;
num_timesteps = round(runtime*bar_length/c/dt); % Number of time steps.
%nt = floor(num_timesteps);
W_gp = [1, 1]; %weights of each gaussian point
ksi_gp = [(1/3)^.5, -(1/3)^.5]; %natural coordinates of each gaussian point
%% Preprocessing.
% Nodal coordinates in reference configuration.
X = linspace(0, bar_length, nn)';
%---------------------------------------------------------------------
% Initialize nodal variables to zero.
u = zeros(nn,1); %position
v = zeros(nn,1); %velocity
a = zeros(nn,1); %acceleration
B = zeros(nn,1);
f_int = zeros(nn,1);
f_ext = zeros(nn,1);
u2 = zeros(nn,1);
connect = [ 1:length(X)-1; 2:length(X)]';
fl_int = zeros(nn,1);
fl_ext = zeros(nn,1);
W_int = zeros(floor(num_timesteps),1);
W_ext = zeros(floor(num_timesteps),1); % beam external energy
W_kin = zeros(floor(num_timesteps),1); % beam kinetic energy
W_tot = zeros(floor(num_timesteps),1); % system energy
W_int2 = zeros(nn,1);
W_ext2 = zeros(nn,1);
W_kin2 = zeros(nn,1);
W_tot2 = zeros(nn,1);
Wi_t = zeros(num_timesteps,1);
We_t = zeros(num_timesteps,1);
Wk_t = zeros(num_timesteps,1);
WT_t = zeros(num_timesteps,1);
%---------------------------------------------------------------------
% Defines the element shape functions.
% See MATLAB help for "anonymous function" if you don't understand.
N = @(x) ( 0.5*[1-x, 1+x] );
% Defines the stress as a function of strain.
%stressfunction = @(eps,v) ( youngs * eps+ youngs* alpha2 * Be * v);
stressfunction = @(eps,deps) ( youngs * eps+ youngs* alpha2 *deps);
%msf = @(eps,v)(youngs * eps+ alpha2 * B * v);
% Defines the applied load as a function of time.
applied_load = @(t) (250*A*1e6*(t<Inf).*(t>=0));

15
%% Compute mass matrix.
% Allocate space for mass matrix, assumes 3 nonzeros per row.
M = spalloc(nn,nn,3*nn);
%disp(M)
ngp = 2;
Conn = connect';
for conn = connect'
Me = zeros(2,2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute Me (the element mass matrix here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:ngp
Me = Me + (1-(-1))/2*W_gp(i)*rho*N(ksi_gp(i))'*N(ksi_gp(i))*(bar_length/(nn-
1))*A/2;
end
M(conn,conn) = M(conn,conn) + Me;
end
% disp(M)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute lumped mass matrix by summing rows.
R_sum = sum(M,2);
%Compute the inverse of the lumped mass matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M_lumped = diag(R_sum');
%dM = diag(M_lumped);
%mass_diff = abs(sum(sum(M))-bar_length*rho);
% assert(mass_diff < 1e-8, 'Mass matrix does not add to total mass.');
%disp(M_lumped)
for e=1:(nn-1) %(e loops for the number of elements)
% build element stiffness matrix, will change for quadratic S
% contribution to Element force vector due to body force
% assembly (i loops for the nodes)
for i=1:2
I = connect(e,i); % assemble force vector
B(I) = B(I) + Be(i);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Allocate arrays for output.
figure(1);
u_mid = zeros(num_timesteps,1);
v_mid = zeros(num_timesteps,1);

%% Loop over time steps.


for ts = 1:num_timesteps
%% Displacement update
t = (ts-1)*dt;
t2 = t+dt;
t3 = 0.5*(t+t2); %tn+0.5
f = zeros(nn,1);
fe = zeros(nn,1);
f(1) = applied_load(t2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
v = v + (t3-t).*a;
% Apply boundary conditions here.
v(nn) = 0;
%u2 = u;
u = u + v.*dt;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Element nodal force loop.
for conn = connect'
He = range(X(conn)); % Compute element reference length.
eps = Be * u(conn);
deps = Be*v(conn);
P = stressfunction(eps,deps);
P_e(conn(1)) = P;
fe(conn) = Be'*P*A*He;
f_int(conn) = fe(conn);
f(conn) = f(conn) - fe(conn);
end
f_ext = f -f_int;
if ts == 1
W_int(ts) = (sum((1/2)*(u - u2).*(f_int + fl_int)));
W_ext(ts) = (sum((1/2)*(u - u2).*(f_ext + fl_ext)));
W_kin(ts) = sum(1/2)* dot(v.^2,R_sum');
W_tot = W_kin(ts) + W_int(ts) - W_ext(ts);
else

16
W_int(ts) = W_int(ts-1) + (sum(1 / 2) * sum((u - u2).*(f_int + fl_int)));
W_ext(ts) = W_ext(ts-1) + (sum(1 / 2) * sum((u - u2).*(f_ext + fl_ext)));
W_kin(ts) = sum(1/2)* dot(v.^2,R_sum');
W_tot = W_kin(ts) + W_int(ts) - W_ext(ts);
end
a2 = M_lumped^-1*f;
fl_int = f_int;
fl_ext = f_ext;
u2 = u;
v = v + (t2-t3).*a2;
v(nn) = 0;
a = a2;
%%%%%%%%%% Post processing.%%%%%%%%%%%%%%%%%%%%
if (mod(ts,5) == 0)
Xe = 0.5*(X(2:end)+X(1:end-1));
eps = (u(2:end)-u(1:end-1)) / (bar_length/(nn-1));
deps = (v(2:end)-v(1:end-1)) / (bar_length/(nn-1));
P = stressfunction(eps,deps);
plot(Xe, P,'Linewidth',3);
axis square
set(gca,'FontSize',15,'XTick', 0:0.2:1);
title('Stress Field','FontUnits', 'points', 'interpreter', 'latex',
'FontSize',20, 'FontName','Times', 'FontWeight','b')
xlabel('Position, m', 'FontUnits', 'points', 'interpreter', 'latex',
'FontSize',25, 'FontName','Times', 'FontWeight','b');
ylabel({'Stress, Pa'}, 'FontUnits', 'points', 'interpreter', 'latex',
'FontSize',25, 'FontName','Times', 'FontWeight','b');
%print('99Stable_stress_150.emf','-dmeta','-r600')
pause(0.001);
end
eps = (u(ceil(end/2))-u(ceil(end/2)-1)) / (bar_length/(nn-1));
P_mid(ts) = P_e(ceil(end/2));
u_mid(ts) = u(ceil(end/2));
end
figure(2);
t = (1:num_timesteps)'*dt;
plot(t, u_mid,'Linewidth',3);
axis square
set(gca,'FontSize',15);
title('Mid-point displacement','FontUnits', 'points', 'interpreter', 'latex',
'FontSize',15, 'FontName','Times', 'FontWeight','b')
xlabel('Time, s', 'FontUnits', 'points', 'interpreter', 'latex', 'FontSize',25,
'FontName','Times', 'FontWeight','b');
ylabel({'Displacement, m'}, 'FontUnits', 'points', 'interpreter', 'latex',
'FontSize',25, 'FontName','Times', 'FontWeight','b');
%print('99Stable_150_mpd3r.emf','-dmeta','-r600')
figure(3);
plot(t, P_mid,'Linewidth',3);
axis square
set(gca,'FontSize',15);
title('Mid-point stress','FontUnits', 'points', 'interpreter', 'latex', 'FontSize',15,
'FontName','Times', 'FontWeight','b')
xlabel('Time, s', 'FontUnits', 'points', 'interpreter', 'latex', 'FontSize',25,
'FontName','Times', 'FontWeight','b');
ylabel({'Stress, Pa'}, 'FontUnits', 'points', 'interpreter', 'latex', 'FontSize',25,
'FontName','Times', 'FontWeight','b');
%print('99Stable_150_mds3r.emf','-dmeta','-r600')
figure(4);
hold on
plot(t, W_int,'.-','Linewidth',3);
plot(t, W_ext,'--','Linewidth',3);
plot(t, W_kin,'Linewidth',3);
plot(t, W_tot, '*','Linewidth',3);
axis square
set(gca,'FontSize',15);
title('Test of Energy Convergence','FontUnits', 'points', 'interpreter', 'latex',
'FontSize',15, 'FontName','Times', 'FontWeight','b')
xlabel('Time, s','FontUnits', 'points', 'interpreter', 'latex', 'FontSize',25,
'FontName','Times', 'FontWeight','b')
ylabel('Work J','FontUnits', 'points', 'interpreter', 'latex', 'FontSize',25,
'FontName','Times', 'FontWeight','b')
legend('Internal Energy','External Energy','Kinetic Energy','Total Energy'
,'Location','northwest')
print('unstable_W_150.emf','-dmeta','-r600')
hold off
%% Energy calculation%%%
end

17
Problem 3 (only modified part)
for conn = connect'
Me = zeros(2,2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute Me (the element mass matrix here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:ngp
Me = Me + (1-(-1))/2*W_gp(i)*rho*N(ksi_gp(i))'*N(ksi_gp(i))*(bar_length/(nn-
1))*A/2;
end
M(conn,conn) = M(conn,conn) + Me;
end
% disp(M)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute lumped mass matrix by summing rows.
R_sum = sum(M,2);
%Compute the inverse of the lumped mass matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M_lumped = diag(R_sum');
mass_diff = abs(sum(sum(M))-bar_length*rho);
% assert(mass_diff < 1e-8, 'Mass matrix does not add to total mass.');
%disp(M_lumped)
for e=1:(nn-1) %(e loops for the number of elements)
% build element stiffness matrix, will change for quadratic S
% contribution to Element force vector due to body force
% assembly (i loops for the nodes)
for i=1:2
I = connect(e,i); % assemble force vector
B(I) = B(I) + Be(i);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Allocate arrays for output.
figure(1);
u_mid = zeros(num_timesteps,1);
v_mid = zeros(num_timesteps,1);

% a_mid = zeros(num_timesteps,1);
% v_half = zeros(num_timesteps,1);
%% Loop over time steps.
for ts = 1:num_timesteps
%% Displacement update
t = (ts-1)*dt;
t2 = t+dt;
t3 = 0.5*(t+t2); %tn+0.5
f = zeros(nn,1);
fe = zeros(nn,1);
be = zeros(nn,1);
if ts ==1
f(1) = applied_load(X(1));
f(nn) = 0;
disp(f)
else
f(1) = 0;
f(nn) = 0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
v = v + (t3-t).*a;
% Apply boundary conditions here.
%v(nn) = 0;
u = u + v.*dt;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Element nodal force loop.
for conn = connect'
He = range(X(conn)); % Compute element reference length.
eps = Be * u(conn);
deps = Be*v(conn);
P = stressfunction(eps,deps);
P_e(conn(1)) = P;
%P_e(conn(1)) = P;
fe(conn) = Be'*P*A*He;
be(conn) = b*el*[0.5;0.5];
f_int(conn) = fe(conn) + be(conn);
f(conn) = f(conn) - fe(conn)-be(conn); % Scatter element internal forces
%disp(f)

18
end
f_ext = f -f_int;
if ts == 1
W_int(ts) = (sum((1/2)*(u - u2).*(f_int + fl_int)));
W_ext(ts) = (sum((1/2)*(u - u2).*(f_ext + fl_ext)));
W_kin(ts) = sum(1/2)* dot(v.^2,R_sum');
W_tot = W_kin(ts) + W_int(ts) - W_ext(ts);
else
W_int(ts) = W_int(ts-1) + (sum(1 / 2) * sum((u - u2).*(f_int + fl_int)));
W_ext(ts) = W_ext(ts-1) + (sum(1 / 2) * sum((u - u2).*(f_ext + fl_ext)));
W_kin(ts) = sum(1/2)* dot(v.^2,R_sum');
W_tot = W_kin(ts) + W_int(ts) - W_ext(ts);
end
a2 = M_lumped^-1*f;
fl_int = f_int;
fl_ext = f_ext;
u2 = u;
v = v + (t2-t3).*a2;
%v(nn) = 0;
a = a2;

19

Вам также может понравиться