25
UNIVERSITY OF PATRAS - MEEES Dynamics by Finite Element Method Homework 1: Part 1 – Verification using Ramp-Constant Function Part 2 – Response Spectra Analysis Cameron Belliss 11/11/2014

Numerical Method Verification

  • Upload
    cam

  • View
    39

  • Download
    2

Embed Size (px)

DESCRIPTION

Verification of numerical methods for solving the equation of motion against analytical solutions.

Citation preview

Page 1: Numerical Method Verification

UNIVERSITY OF PATRAS - MEEES

Dynamics by Finite Element Method Homework 1:

Part 1 – Verification using Ramp-Constant Function Part 2 – Response Spectra Analysis

Cameron Belliss

11/11/2014

Page 2: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss

Part 1: Verification of numerical methods and an investigation into the Ramp-Constant function.

Part 1, of the following report outlines an investigation into three different methods of numerical analysis for the

modelling of a single-degree-of-freedom (SDOF), un-damped oscillating system, and uses them to investigate the

results of applying a ramp-constant forcing function to the SDOF with varying parameters. The three methods are

as follows;

-Duhamel’s Integral

-Central Difference Method

-Linear Acceleration Time-Stepping Method

After outlining the forcing function, the three methods are investigated separately on a particular forcing function,

and then more generally investigate how the response of the system changes with variations to the forcing

function.

The Ramp-Constant Function

The ramp-constant function is one which applies a force, increasing linearly from 0 at t=0, to Fo at t=t1, and then

remains constant at Fo for t>t1. What will be investigated later is the effects of varying the ratio of the ramp period,

t1, to the natural period of the SDOF system, T. For now we will consider just one ratio of t1/T=1.5, to demonstrate

the accuracy of the various numerical methods at predicting the response.

A feature of the ramp-constant function is that it has an analytical solution, separated into two sections for the

ramp and constant phases of the forcing, as follows;

𝑢(𝑡) = (𝑢𝑠𝑡)𝑜 {𝑡

𝑡1−

𝑠𝑖𝑛𝜔𝑛𝑡

𝜔𝑛𝑡1} 𝑡 ≤ 𝑡1

𝑢(𝑡) = (𝑢𝑠𝑡)𝑜 {1 +1

𝜔𝑛𝑡1

[(1 − 𝑐𝑜𝑠𝜔𝑛𝑡1)sinωn(𝑡 − 𝑡1) − 𝑠𝑖𝑛𝜔𝑛𝑡1𝑐𝑜𝑠𝜔𝑛(𝑡 − 𝑡1)]} 𝑡 > 𝑡1

The above equation is used to plot the following response shown in figure 1 below, for a SDOF with natural period

of 1 second, and static displacement 𝑢𝑠𝑡 = 1, and a ratio of t1/T=1.5. Note that all comparisons between methods

will now be made with this ratio of t1/T=1.5 until we move onto look further at variations in this ratio.

Page 3: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss

Figure 1 - Analytical solution to ramp-constant function, t1/T=1.5.

(i) Duhamel’s Integral

The first numerical method considered is Duhamel’s Integral, whereby the displacement at a given time-step is

given by the integral of the forcing function up until that time step, multiplied by an oscillating term. For a non-

damped system this is shown as follows;

𝑢(𝑡) =1

𝑚𝜔∫ 𝐹(𝜏)𝑠𝑖𝑛𝜔(𝑡 − 𝜏)𝑑𝜏

𝑡

0

Which, to be used as a numerical function is turned into a summation. In this case the rule of simple summation

is used and that following equation is formed;

𝑢(𝑡𝑛) =Δ𝑡

𝑚𝜔∑ 𝐹(𝑡𝑖)𝑠𝑖𝑛𝜔(𝑡𝑛 − 𝑡𝑖)

𝑛

𝑖=1

Given that this is a numerical approach to the solution, we expect there will be variation from the analytical result.

The plot in figure 2 below highlights the difference between the Duhamel Integral solution and the analytical, for

a time-step of Δ𝑡 = 0.2𝑠. We see here that while the solution tracks the form of the analytical, information is lost

and there is clear variation between the two.

Page 4: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss

Figure 2 - Variation between Duhamel Integral with dt=0.2s and analytical solution.

Figure 3 - Variation in error of Duhamel Integral with changes to time-step.

Page 5: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss To investigate this further we look at how the error between the analytical and the Duhamel Integral solution

develop with varying time-steps. Figure 3 shows how the error of the Duhamel integral solution reduces as the

time-step is reduced, and how the error develops with time. As expected, as the time-step is reduced the error is

subsequently reduced. While it is hard to see on the plot, when the time-step is reduced to 0.01 seconds, the error

of the solution becomes very small, and thus, as shown in figure 4, the numerical solution becomes effectively the

same as the analytical solution. We can also see from figure 3 that the solution still remains stable with large time-

steps of up to Δ𝑡 = 𝑇. Even though the errors become large, they tend to reach a plateau value and do not

increase unbounded as 𝑡 increases for this method.

Figure 4 - Duhamel Integral with dt = 0.01s, matches to analytical solution.

(ii) Central Difference Method

The central difference method is an implicit method, using equilibrium at point 𝑖 to determine the response of the

system at point 𝑖 + 1. While some manipulation of terms to get the analysis started is required, the following

equation is used from the subsequent time-steps to perform the analysis, whereby the displacement at time 𝑖 +

1 is a function of the force at time 𝑖, and the displacement at 𝑖 and 𝑖 − 1.

𝑚

Δ𝑡2𝑢𝑖+1 = 𝐹𝑖 − (𝑘 −

2𝑚

Δ𝑡2 ) 𝑢𝑖 −

𝑚

Δ𝑡2𝑢𝑖−1

Similarly to for the Duhamel Integral, we are able to plot the variation of the error that the central difference

method has in comparison to the analytical solution for various time-steps, this is shown in figure 5. As with the

Duhamel Integral method, a reduction in time-step is shown to lead to a clear reduction in error. This plot does

however reveal two clear differences in development of errors with the previous method. Firstly it is shown that

regardless of the time-step, the error between the method and the analytical solution increases with time, in an

oscillatory manor, as there is no apparent plateau of maximum value reached for a given time-step. Secondly, we

Page 6: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss see that the errors are larger for a smaller time-for this method. Also, what is not shown on this plot, but was

determined through analysis was that if the time-step was increased to 0.4s, the error began to increase

unbounded, and the solution lost all stability. This agrees with the expected loss of stability at a time-step of 𝑇𝑛

𝜋, in

contrast to the Duhamel Integral solution which remained stable at large time-steps. When the time-step is

reduced down to 0.1s, again we can see that the numerical method tends to match the analytical solution well,

as shown in figure 6.

Figure 5-Variation of error overtime with varying time-steps for Central Difference Method

Figure 6- Comparison of Central Limit Method and analytical solution for dt=0.01s.

Page 7: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss (iii) Linear Acceleration Method

The linear acceleration method is a method derived from a Taylor Series expansion, whereby an iterative

process is used to determine the state of the system at time 𝑖 + 1, using the state of the system at time 𝑖 and

the equations of equilibrium, and an assumption that the acceleration between the two points follows a linear

path.

𝑢𝑛+1 = 𝑢𝑛 + �̇�𝑛Δ𝑡 +Δ𝑡2

6(2�̈�𝑛 + �̈�𝑛+1)

�̇�𝑛+1 = �̇�𝑛 +Δ𝑡

2(�̈�𝑛 + �̈�𝑛+1)

�̈�𝑛+1 =1

𝑚(𝐹𝑛+1 − 𝑘𝑢𝑛+1)

Figure 7 below illustrates the development of errors over time for the linear acceleration method. This plot is

similar of that for the central difference method, in that the errors increase in an oscillatory manor with time,

however the magnitude of the errors for this case are lower. This is expected, with the formulation of the linear

acceleration method as an approximation to the solution with errors in the order of Δ𝑡4, while the central

difference has a lower order error.

Similarly to the central difference method there was also a loss of stability of the method. When the time-step

was increased to around 0.4s, the iterative process between time-steps would no longer converge and thus a

solution could not be formed.

Figure 7 - Variation of error overtime with varying time-steps for Linear Acceleration Method

Page 8: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss

Figure 8 - Comparison of Linear Acceleration Method and analytical solution for dt=0.01s.

Comparison of 3 Methods

Plotting the three methods on the same plot gives a good illustration of the variation between them. Figures 9,

10 and 11, show the three methods compared to each other with reducing timesteps. We see here that by

reducing the time-step to 0.01s, all three solutions converge to the same solution, which very closely follows the

analytical solution presented previously.

Figure 9 - Comparison of 3 methods, dt=0.2s.

Figure 10 - Comparison of 3 methods, dt=0.1s.

Page 9: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss

Figure 11 - Comparison of 3 methods, dt=0.01s.

Investigation of Ramp Constant Function

Following from looking into and verifying the three different numerical analysis methods, they can now be used

as tools to look more closely at the ramp-constant function. As all methods were shown to be virtually identical

for a time-step of 0.01 seconds, we will now illustrate the features of the ramp constant function using just one

method. The key outcome we are looking for, is to show the impact of the variation of the ratio of the ramp-time,

t1, to the natural period of the SDOF.

We first do this by first plotting the solution for 10 different ratios from 0.2 to 2.0. The result of this is plotted in

figure 12 and highlights the wide range of responses that are achieve depending on the time taken to reach

constant force on the system. As the system is un-damped, the oscillation of these would continue at the same

amplitude indefinitely with time.

Some key points that can be seen on this plot are that when the ration of 𝑡1/𝑇 is small, the peak is reached before

the first period of oscillation of the SDOF, and the displacement increase towards 2 times the static displacement,

these displacements reduce as the ratio nears 0. A second point we see, is that when the ratio 𝑡1/𝑇 is an integer

number, there is no oscillation in the constant force phase of the response.

Page 10: Numerical Method Verification

Assignment 1: Part 1 Verification using Ramp Constant Function

C Belliss

Figure 12- SDOF response to variety of ratios, t1/T.

To investigate this further, we have considered a wider range of ratios 𝑡1/𝑇 and plotted these against their

absolute maximum displacement, with the result plotted in figure 13. This figure illustrates further the two

comments made regarding figure 12, with the 3 main conclusions drawn being;

- When the period of the ramp is an integer multiple of the natural period of the system, there is no

amplification of the pseudo static displacement while the amplification increases to maximum values,

peaking in between these integer multiples of the ratio.

- As the period of the ramp drops closer to zero, the maximum amplification of the pseudo static

response tends towards 2.

- As the ratio of t1/Tn increases, the maximum amplification tends to decrease.

Figure 13 - Variation of maximum displacement with variations in ratio t1/T.

Page 11: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss

Part 2: Numerical analysis of displacement, velocity and acceleration response spectra

The following section of this report presents the numerical determination of the displacement, velocity and acceleration spectra from a recorded ground motion. The spectra are calculated using all three numerical methods presented in part 1, with comparisons made between the three. Acceleration data The following plot illustrates the recorded acceleration time history data that was used to obtain the spectra. The provided data had a time-step of 0.01 seconds between data points, and can be seen to reach a maximum acceleration of approximately 2.3𝑚/𝑠2.

Figure 14 - Record B ground acceleration data

Response Spectra

The response spectra for the ground motion presented in figure 12 has been calculated using three different

numerical methods. These spectra highlight the maximum absolute responses of the SDOF system as a function

of its natural vibration period 𝑇, and the damping ratio of the system, 𝜉.

𝑆𝑝𝑒𝑐𝑡𝑟𝑎𝑙 𝐷𝑖𝑠𝑝𝑙𝑎𝑐𝑒𝑚𝑒𝑛𝑡 − 𝑆𝐷 = max | 𝑢(𝑡) |

𝑆𝑝𝑒𝑐𝑡𝑟𝑎𝑙 𝑉𝑒𝑙𝑜𝑐𝑖𝑡𝑦 − 𝑆𝑉 = max | �̇�(𝑡) |

𝑆𝑝𝑒𝑐𝑡𝑟𝑎𝑙 𝐴𝑐𝑐𝑒𝑙𝑒𝑟𝑎𝑡𝑖𝑜𝑛 − 𝑆𝐴 = max | �̈�(𝑡) + �̈�𝑔(𝑡)|

Where 𝑢(𝑡), �̇�(𝑡), 𝑎𝑛𝑑 �̈�(𝑡) are the solution to the following equation of motion, subjected to ground

accelerations �̈�𝑔;

�̈�(𝑡) + 2𝜉𝜔�̇�(𝑡) + 𝜔2�̈�(𝑡) = −�̈�𝑔

Page 12: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss (i) Central Difference Method

The first method used is the central difference method, which uses the time stepping method as outlined in part

one, with the following terms used to obtain the velocity and accelerations at each time-step.

�̇�(𝑡) =𝑢𝑖+1−𝑢𝑖−1

2Δ𝑡 and �̈�(𝑡) =

𝑢𝑖+1−2𝑢𝑖+𝑢𝑖−1

Δ𝑡2

Using Δ𝑡 = 0.01𝑠, the time-step of the provided acceleration data, the following spectra were obtained. Note that

in order the spectral acceleration (SA) values, the ground acceleration had to first be added to �̈�(𝑡) before taking

the absolute maximum.

Figure 15 - Spectral displacement using central difference method, dt=0.01s.

Figure 16 - Spectral velocity using central difference method, dt=0.01s.

Page 13: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss

Figure 17 - Spectral acceleration using central difference method, dt=0.01s.

(ii) Linear Acceleration Method

As outlined in part one, the velocity and acceleration values at each time-step are calculated within the

iterations, so no further calculations are required to obtain the values for SV and SV. Secondly, similarly to the

central difference method, the ground acceleration had to first be added to �̈�(𝑡) before taking the absolute

maximum to obtain SA.

Figure 18 - Spectral displacement using linear acceleration method, dt=0.01s.

Page 14: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss

Figure 19 - Spectral velocity using linear acceleration method, dt=0.01s.

Figure 20 - Spectral acceleration using linear acceleration method, dt=0.01s.

(iii) Duhamel’s Integral

Finally looking at the Duhamel’s integral method. In order to obtain the velocity and acceleration at each time-

step, additional integrals had to be numerically calculated, as per the following,

𝑢(𝑡) =−1

𝜔𝑑∫ �̈�𝑔(𝜏)𝑒−𝜉𝜔(𝑡−𝜏)𝑠𝑖𝑛𝜔𝑑(𝑡 − 𝜏)𝑑𝜏

𝑡

0

Page 15: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss

�̇�(𝑡) =1

√1−𝜉2 ∫ �̈�𝑔(𝜏)𝑒−𝜉𝜔(𝑡−𝜏)𝑠𝑖𝑛[𝜔𝑑(𝑡 − 𝜏) − 𝛼] 𝑑𝜏𝑡

0 where 𝛼 = 𝑡𝑎𝑛−1 (

√1−𝜉2

𝜉)

�̈�(𝑡) + �̈�𝑔 =𝜔

√1−𝜉2∫ �̈�𝑔(𝜏)𝑒−𝜉𝜔(𝑡−𝜏)𝑠𝑖𝑛[𝜔𝑑(𝑡 − 𝜏) − 𝛽] 𝑑𝜏

𝑡

0 where 𝛽 = 𝑡𝑎𝑛−1 (

2𝜉√1−𝜉2

1−2𝜉2 )

Due to the large number of sums that are required to obtain these integrals, this is computationally expensive to

compute. In order to reduce the number of calculations require, the acceleration data was reduced by removing

a large amount of the zero-data before the significant shaking begins, and by removing the shaking data once the

significant shaking has finished. As when calculating spectra, it is the maximums values that we are concerned

with, this reduction in the data used does not impact the spectral plots.

Figure 21 - Spectral displacement using Duhamel's Integral, dt=0.01s.

Figure 22 - Spectral velocity using Duhamel's Integral, dt=0.01s.

Page 16: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss

Figure 23 - Spectral acceleration using Duhamel's Integral, dt=0.01s.

Comparison of Methods

When looking at the previous plots of the spectra obtained from the various methods it is evident that the results

obtained from each of the methods are similar. However to understand where any variations lie between the

methods, and the accuracy of them we must compare them on the same plot. The following plots show

comparisons between the three methods for damping ratios of 1% and 8% across all three spectra. These plots

are all shown using a time-step on the numerical methods of 0.01s.

Figure 24 - Comparison of spectral displacement of three methods, dt=0.01s.

Page 17: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss

Figure 25 - Comparison of spectral velocity of three methods, dt=0.01s.

Figure 26 - Comparison of spectral acceleration of three methods, dt=0.01s.

It can be seen from these plots that while the spectral displacement (figure 24) and spectral velocity (figure 25)

are very close between all three methods, for smaller periods, the differences in spectral acceleration (figure 26)

are noticeable at short periods. This makes sense as we showed in part 1, that as the ratio of Δ𝑡/𝑇 increases, the

errors in the numerical solutions increase. In this case, as we have a constant Δ𝑡, the increasing error occurs when

the period, 𝑇, decreases.

Page 18: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss As expected, if we reduced the time-step used for the numerical methods, the accuracy improves, and the

difference between the methods reduces. Figure 27 illustrates the spectral accelerations of each method, with a

reduction in time-step to dt=0.005s for periods less than 1.5s. The differences between the methods, particularly

for the 1% damping are clearly reduced. If the time-step is reduced further, then the difference between the two

methods for 1% damping become negligible, while there is still a small difference between the Duhamel Integral

and the other two methods for 8% damping. This further reduction is illustrated in figure 28, where the time-step

for periods of less than 1.5s is reduced to dt=0.0025s.

Figure 27 - Comparison of spectral acceleration of three methods, dt=0.005s for T<1.5s, dt=0.01 for T>1.5s.

Figure 28 - Comparison of spectral acceleration of three methods, dt=0.0025 for T<1.5s, dt=0.01 for T>1.5s.

Page 19: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss Approximate solution for Spectral Velocity and Spectral Acceleration

Based on the Duhamel Integral method, whereby the only difference between the displacement, velocity and

acceleration integrals are multiples of 𝜔 and phase shifts to the 𝑠𝑖𝑛 function, an approximate solution to obtain

pseudo spectral velocities and accelerations is obtained.

𝑃𝑠𝑒𝑢𝑑𝑜 𝑆𝑉 ≈ 𝜔𝑆𝐷

𝑃𝑠𝑒𝑢𝑑𝑜 𝑆𝐴 ≈ 𝜔2𝑆𝐷

To assess how well this approximate solution fits the actual solution for the spectral velocities and accelerations,

the pseudo values are plotted against the actual values obtained from analysis. This has been completed using

only one of the methods results, the Duhamel Integral, with which the approximate solution is based on, using

the reduced time-steps as outlined in the previous section.

Figure 29 - Comparison of spectral velocity to pseudo spectral velocity.

From figure 29 we can see that the pseudo spectral velocity provides a close approximation to the actual solution

at short time periods, less than 0.6s. However as the period of vibration increases beyond this point the

approximate solution becomes a poor fit to the actual solution. Figure 30 illustrates that the pseudo spectral

acceleration provides a very good approximation to the spectral acceleration, with very little difference between

the two methods evident across all time periods as the lines are effectively plotted on top of one another.

Page 20: Numerical Method Verification

Assignment 1: Part 2 Response Spectra Analysis

C Belliss

Figure 30 - Comparison of spectral acceleration to pseudo spectral acceleration.

Page 21: Numerical Method Verification

Assignment 1: Appendices C Belliss

Appendix A: MATLAB Codes for Ramp Constant Function

%Script for numerical analysis of an un-damped SDOF subject to %ramp-constant function using 3 different methods clear;clc %Input variables r=[0.2,0.4,0.6,0.8,1,1.2,1.4,1.6,1.8,2]; %Defines the different ratios to be used Tn=1; %Natural period of system m=1; %Mass Tf=5; %Time length of analysis dt=0.01; %Timestep Fo=1; %Constant force t=[0:dt:Tf]; %Sets the time array

%Calculated variables numsteps=Tf/dt; %Calculation of number of steps omega=2*pi/Tn; %Calclate omega from set parameters k=omega^2*m; %Calculate stiffness from set parameters tolerance=1e-10; %Setting the relative tolerance of the conergence

%Setting initial matrices to increase speed of computing finalF=zeros(length(t),10); linacc=zeros(length(t),10); centraldif=zeros(length(t),10); duhameli=zeros(length(t),10);

%Loop to iterate through the different values of the ratio t1/Tn for W=1:10 ratio=r(W); t1=ratio*Tn;

%Linear Acceleration Method u=zeros(length(t),1); du=zeros(length(t),1); d2u=zeros(length(t),1); u(1)=0; du(1)=0; F1=0; d2u(1)=(F1-k*u(1))/m; for I=1:1:numsteps Fi=rampconst(t1,t(I+1),Fo); d2ustar=d2u(I); for N=1:1:100000 ustar=u(I)+dt^2/6*(2*d2u(I)+d2ustar)+du(I)*dt; dustar=du(I)+dt/2*(d2u(I)+d2ustar); d2unew=(Fi-k*ustar)/m; if abs((d2unew-d2ustar)/d2ustar)<tolerance break elseif N==100000 display('No convergence') else d2ustar=d2unew; end end u(I+1)=ustar; du(I+1)=dustar; d2u(I+1)=d2unew; end linacc(:,W)=u/(Fo/k);

Page 22: Numerical Method Verification

Assignment 1: Appendices C Belliss

%Central Difference Method u=zeros(length(t),1); F=zeros(length(t),1); uo=0; duo=0; Fi=rampconst(t1,0,Fo); d2uo=1/m*(Fi-k*duo); uo1=uo-dt*duo+dt^2/2*d2uo; u(1)=uo; t(1)=0; F(1)=rampconst(t1,t(1),Fo); u(2)=(F(1)-(k-2*m/(dt^2))*u(1)-1/(dt^2)*m*uo1)/(1/(dt^2)*m); t(2)=dt; for I=3:1:numsteps; t(I)=dt*(I-1); F(I-1)=rampconst(t1,t(I-1),Fo); u(I)=(F(I-1)-(k-2*m/(dt^2))*u(I-1)-(1/(dt^2)*m)*u(I-2))/(1/(dt^2)*m); end finalF(:,W)=F; centraldif(:,W)=u/(Fo/k);

%Duhamel Integral Method u=zeros(length(t),1); u(1)=0; for I=1:1:numsteps sumA=0; for p=0:dt/10:t(I+1) if p <t1 Ft= Fo*p/t1; else Ft=Fo; end sumA=sumA+Ft*sin(omega*(t(I+1)-p)); end u(I+1)=sumA*dt/m/omega/10; end duhameli(:,W)=u/(Fo/k);

end

figure(1) plot(t,duhameli) xlabel('Time, t (s)') ylabel('R(t)=u(t)/(F_o/k)') title('Duhamel Integral Method') legend('t_1/T_n=0.2','0.4','0.6','0.8','1.0','1.2','1.4','1.6','1.8','2.0')

figure(2) plot(t,centraldif) xlabel('Time, t (s)') ylabel('R(t)=u(t)/(Fo/k)') title('Central Difference Method') legend('t_1/T_n=0.2','0.4','0.6','0.8','1.0','1.2','1.4','1.6','1.8','2.0')

figure(3) plot(t,linacc) xlabel('Time, t (s)') ylabel('R(t) = u(t)/(F_o/k)') title('Linear Acceleration Method') legend('t_1/T_n=0.2','0.4','0.6','0.8','1.0','1.2','1.4','1.6','1.8','2.0')

Page 23: Numerical Method Verification

Assignment 1: Appendices C Belliss

Appendix B: MATLAB code for Spectra

%Script file to compute the spectra from numerical eq records: CBelliss clear;

%Import the require forcing function file load brecord1.txt; ac1=zeros(1301,1);tf1=zeros(1301,1); for L=2200:1:3500 ac1(L-2199,1)=brecord1(L,2)/100; tf1(L-2199,1)=brecord1(L,1); end %Splitting into shorter dt steps and interpolating values inbetween data ac2=zeros(2*length(ac1)-1,1);tf2=zeros(2*length(ac1)-1,1); for F=1:1:2*length(ac1)-1 if rem(F,2)>0 ac2(F,1)=ac1((F+1)/2); tf2(F)=tf1((F+1)/2); else ac2(F,1)=(ac1(F/2)+ac1(F/2+1))/2; tf2(F)=(tf1(F/2)+tf1(F/2+1))/2; end end ac3=zeros(2*length(ac2)-1,1);tf3=zeros(2*length(ac2)-1,1); for F=1:1:2*length(ac2)-1 if rem(F,2)>0 ac3(F,1)=ac2((F+1)/2); tf3(F)=tf2((F+1)/2); else ac3(F,1)=(ac2(F/2)+ac2(F/2+1))/2; tf3(F)=(tf2(F/2)+tf2(F/2+1))/2; end end

numtimes=50; %Select number of time periods to consider psi=[0.01,0.03,0.05,0.08]; %Set chosen damping ratios.

%Initiate the spectra arrays time=zeros(numtimes,1); %Duhamel integral SDduhamel=zeros(numtimes,4); SVduhamel=zeros(numtimes,4); SAduhamel=zeros(numtimes,4); %Central difference method SDcentral=zeros(numtimes,4); SVcentral=zeros(numtimes,4); SAcentral=zeros(numtimes,4); %Linear Acceleration method SDlinear=zeros(numtimes,4); SVlinear=zeros(numtimes,4); SAlinear=zeros(numtimes,4); tolerance=1e-9; %Select iteration tolerance for d2u.

%Loop through selected damping ratios for R=1:length(psi) PSI=psi(R); %Calculate Duhamel Integral phase shifts alpha=atan2(sqrt(1-PSI^2),PSI); beta=atan2((2*PSI*sqrt(1-PSI^2)),(1-2*PSI^2)); %Loop through different periods for spectra for I=1:numtimes %Statement to focus periods on T<1.5s. if I<=35 T=I/35*1.5; else T=1.5+(I-35)/15*3.5; end time(I)=T;

Page 24: Numerical Method Verification

Assignment 1: Appendices C Belliss

%Statement to reduce dt values for lower periods if T>2 acc=ac1; t=tf1; dt=0.01; elseif T>1 acc=ac2; t=tf2; dt=0.005; else acc=ac3; t=tf3; dt=0.0025; end %Setting properties of SDOF numsteps=length(t); omega=2*pi/T;omegad=omega*sqrt(1-PSI^2); m=1; c=2*PSI*omega; k=omega^2;

%Inputting the initial conditions uo=0; duo=0; Fo=-acc(1)*m; d2uo=1/m*(Fo-c*duo-k*uo);

%DUHAMEL INTEGRAL METHOD u=zeros(1,length(t)); du=zeros(1,length(t)); d2u=zeros(1,length(t)); %Calculate initial conditions u(1)=uo; du(1)=duo; d2u(1)=d2uo; for H=1:numsteps-1 %Looping through timesteps sumu=zeros(H+1,1);sumdu=zeros(H+1,1);sumd2u=zeros(H+1,1); for Tau=1:1:H+1; %Looping through Tau values each timestep At=acc(Tau)*exp(-PSI*omega*(t(H+1)-t(Tau))); B=omegad*(t(H+1)-t(Tau)); sumu(Tau)=At*sin(B); sumdu(Tau)=At*sin(B-alpha); sumd2u(Tau)=At*sin(B-beta); end %Taking sums using trapezoidal rule u(H+1)=-dt/(2*omegad)*(2*sum(sumu)-sumu(1)-sumu(end)); du(H+1)=dt/(2*sqrt(1-PSI^2))*(2*sum(sumdu)-sumdu(1)-sumdu(end)); d2u(H+1)=dt*omega/(2*sqrt(1-PSI^2))*(2*sum(sumd2u)-sumd2u(1)-sumd2u(end)); end %Storing spectra values SDduhamel(I,R)=max(abs(u)); SVduhamel(I,R)=max(abs(du)); SAduhamel(I,R)=max(abs(d2u));

%CENTRAL DIFFERENCE METHOD u=zeros(1,length(t)); du=zeros(1,length(t)); d2u=zeros(1,length(t)); %Calculate initial conditions uo1=uo-dt*duo+dt^2/2*d2uo; u(1)=uo; du(1)=duo; d2u(1)=d2uo; u(2)=(Fo-(k-2*m/(dt^2))*uo-(m/(dt^2)-c/(2*dt))*uo1)/(m/(dt^2)+c/(2*dt)); for H=3:1:numsteps %Loop through timesteps Fi=-acc(H-1)*m; u(H)=(Fi-(k-2*m/(dt^2))*u(H-1)-(m/(dt^2)-c/(2*dt))*u(H-2))/(m/(dt^2)+c/(2*dt)); du(H-1)=(u(H)-u(H-2))/(2*dt);

Page 25: Numerical Method Verification

Assignment 1: Appendices C Belliss

d2u(H-1)=(u(H)-2*u(H-1)+u(H-2))/(dt^2); end d2u=d2u+transpose(acc); %add ground acceleration %Storing spectra values SDcentral(I,R)=max(abs(u)); SVcentral(I,R)=max(abs(du)); SAcentral(I,R)=max(abs(d2u));

%LINEAR ACCELERATION METHOD u=zeros(1,length(t)); du=zeros(1,length(t)); d2u=zeros(1,length(t)); %Calculate initial conditions u(1)=uo; du(1)=duo; d2u(1)=d2uo; for H=1:1:numsteps-1 %Loop through timesteps F=-acc(H+1)*m; d2ustar=d2u(H); for N=1:100000 %Loop to converge on d2u ustar=u(H)+du(H)*dt+dt^2/6*(2*d2u(H)+d2ustar); dustar=du(H)+dt/2*(d2u(H)+d2ustar); d2unew=(F-c*dustar-k*ustar)/m; if abs((d2unew-d2ustar)/d2ustar)<tolerance break elseif N==100000 display('No convergence in 100000 iterations') else d2ustar=d2unew; end end u(H+1)=ustar; du(H+1)=dustar; d2u(H+1)=d2unew; end d2u=d2u+transpose(acc); %adding ground acceleration %Stroing spectra values SDlinear(I,R)=max(abs(u)); SVlinear(I,R)=max(abs(du)); SAlinear(I,R)=max(abs(d2u)); end end %Form frequency array to use with plotting pseudo values OMEGA=2*pi./time; %Plotting of data done using another script file