• Tidak ada hasil yang ditemukan

Thư viện số Văn Lang: Finite Difference Computing with PDEs: A Modern Software Approach

N/A
N/A
Nguyễn Gia Hào

Academic year: 2023

Membagikan "Thư viện số Văn Lang: Finite Difference Computing with PDEs: A Modern Software Approach"

Copied!
92
0
0

Teks penuh

By simple insertion we can show that the mesh function Dtn2 is also a solution of the discrete equations. The convergence of the series r0; r1; ::: ; rm2 requires that the time steps be small enough for the error model Ei DC.ti/r to be valid.

Fig. 1.1 Empirical convergence rate curves with special slope marker
Fig. 1.1 Empirical convergence rate curves with special slope marker

Visualization of Long Time Simulations

  • Using a Moving Plot Window
  • Making Animations
  • Using Bokeh to Compare Graphs
  • Using a Line-by-Line Ascii Plotter
  • Empirical Analysis of the Solution

Visualize u and the exact solution vs. t using a moving plot window and continuous drawing of the curves as they evolve in time. In the analysis of very long time series, it is advantageous to calculate and plot and instead get an impression of the development of the fluctuations.

Analysis of the Numerical Scheme

  • Deriving a Solution of the Numerical Scheme
  • The Error in the Numerical Frequency
  • Empirical Convergence Rates and Adjusted !
  • Exact Discrete Solution
  • Convergence
  • The Global Error
  • Stability
  • About the Accuracy at the Stability Limit

A numerical frequency that is too large gives an oscillating curve that oscillates too quickly and thus "lags behind" the exact oscillations, a feature that can be seen in the left plot in Fig.1.2. Note that the approximate formula (1.19) is very inaccurate for this value of t as it predicts. !Q D2:34=pi, which is a 25 percent reduction.) The corresponding period of the numerical solution isPQ D2=!Q D2t, which means that there is only one time step between a peak (maximum) and through12 (minimum ) is. in the numerical solution.

Figure 1.4 plots the discrete frequency (1.18) and its approximation (1.19) for
Figure 1.4 plots the discrete frequency (1.18) and its approximation (1.19) for

Alternative Schemes Based on 1st-Order Equations

  • The Forward Euler Scheme
  • The Backward Euler Scheme
  • The Crank-Nicolson Scheme
  • Comparison of Schemes
  • Runge-Kutta Methods
  • Analysis of the Forward Euler Scheme

This scheme can also be compared to the second-order centered discretization of ODEs. 4.unC1C2unCun1/D !2unCO.t This means that Crank-Nicolson is equivalent to (1.7) for second-order ODEs except for the additional term sizet2, but this is an error of the same order as the finite-difference approximation on the left-hand side of Eq. Both schemes have the same order of accuracy O.t2/, but their differences in accuracy, which is important in a real physical application, are very clearly expressed in this case.

We can try to find exact solutions to the discrete equations in the Forward Euler method to better understand why this otherwise useful method has such poor performance on vibrational ODEs. We could have used a complex exponential formei!ntQ because we get oscillatory solutions, but the oscillations grow in the Forward Euler method, so the numerical frequency!Q will be complex anyway (and produce an exponentially growing amplitude). The error in the angular frequency is of the same order as in scheme (1.7) for the second order ODE, but the error in the amplitude is serious.

Fig. 1.7 Comparison of classical schemes in the phase plane for two time step values
Fig. 1.7 Comparison of classical schemes in the phase plane for two time step values

Energy Considerations

Derivation of the Energy Expression We start out with multiplying

The quantity E.t / derived above is not physically the mechanical energy of a vibrating mechanical system, but the energy per unit mass. To see this, we start with Newton's second law F Dma (F is the sum of the forces, mis is the mass of the system, and a is the acceleration). For this purpose, we multiply the equation meduDu0dtand integrate:. is the kinetic energy of the system, and Ep.t /D 1. The sum E.t /Q is the total mechanical energy.

The derivation demonstrates the famous energy principle that, under the right physical circumstances, any change in kinetic energy is due to a change in potential energy and vice versa. This principle breaks down when we introduce damping into the system, as we do in Section 1.10.). 2!2.sin2!tCcos2!t/D1 2!2: Energy Increase in the Forward Euler Scheme It is easy to show that the energy in the Forward Euler scheme increases when leaving the cohorntonC1 level.

An Error Measure Based on Energy

Alternatively, we can calculate other norms that involve integration over all grid points, but we are often interested in the worst-case energy deviation, and then the maximum value is particularly important. Below is a table showing the relative total energy error for different schemes (calculated with thevib_undamped_odespy.py program). We clearly see that the Crank-Nicolson and Runge-Kutta schemes outperform the forward and backward Euler schemes after only one period.

The Runge-Kutta and Crank-Nicolson methods hardly change their energy error with T, while the error in the forward Euler method grows to large levels and the relative error of 1 in the backward Euler method indicates that E.t. A striking fact from this table is that the error of Euler's forward method is reduced by the same factor by which it is reduced, while the error of the Crank-Nicolson method has a reduction proportional tot2 (we can't say anything backwards). ward Euler's method). However, for the RK2 method, halving reduces the error by almost a factor of 10 (!), and for the RK4 method, the reduction appears to be proportional only to tot2 (and the trend is confirmed by taking smaller time steps, so that for tD3:9104 the relative error of RK2 is a factor 10 less than the RK4 error!).

The Euler-Cromer Method

  • Forward-Backward Discretization
  • Equivalence with the Scheme for the Second-Order ODE We shall now show that the Euler-Cromer scheme for the system of first-order equa-
  • Implementation
  • The Störmer-Verlet Algorithm

Although the Euler-Cromer scheme and method (1.7) are equivalent, there may be differences in the way they handle the initial conditions. This means that the Euler-Cromer method based on corresponds to using only a first-order approximation to the initial condition in the method of Section 1.1.2. Solver Function The function below, found in invib_undamped_EulerCromer.py, implements the Euler-Cromer scheme.

Verification Since the Euler-Cromer scheme is equivalent to the finite difference method for ODEu00C!2uD0 of the second order (see Section 1.7.2), the performance of the solution function above is the same as for the solution function in Section 1.2. This deviation in the Euler-Cromer scheme means that the discrete solution listed in Section 1.4.4 is not a solution of the Euler-Cromer scheme. Another function, demonstration, visualizes the difference between the Euler-Cromer scheme and the scheme (1.7) for the second-order ODE arising from the mismatch at the first time level.

Staggered Mesh

The Euler-Cromer Scheme on a Staggered Mesh

The main difference is that the traditional Euler-Cromer exhibits first-order convergence int (due to less symmetry in the manner treated), while the others are O.t2/schemes. According to [6], it has better properties in this respect than the direct scheme for the second order ODE. The conclusion is that a distributed mesh is fully equivalent to that scheme, while the forward-backward version gives a small deviation in the calculation of u1.

Fig. 1.12 Examples on mesh functions on a staggered mesh in time
Fig. 1.12 Examples on mesh functions on a staggered mesh in time

Implementation of the Scheme on a Staggered Mesh

Implementation with half-integer indices Some prefer to see a closer connection between code and mathematics for quantities with half-integer indices. A possible solution is to define half of a separate object so that an integer plus half results in the integer, while an integer minushalf is equal to the integer minus 1. The verification of this code is easy since we can just compare the calculation to u produced by the solver function in vib_undamped .py (which solves u00C!2u D 0directly).

Exercises and Problems

Use linear/quadratic functions for verification Consider the ODE problem

Given a chosen solution to u (as a function of t implemented as a Python function), use the method of constructed solutions to compute the source term f and check that u also solves the discrete equations. The function is very similar to linear.) . e) Will a polynomial of the third degree satisfy the discrete equations?.

Show linear growth of the phase with time

Improve the accuracy by adjusting the frequency

See if adaptive methods improve the phase error

Derive and investigate the velocity Verlet method

Find the minimal resolution of an oscillatory function

Visualize the accuracy of finite differences for a cosine function We introduce the error fraction

Verify convergence rates of the error in energy

Use linear/quadratic functions for verification

Use an exact discrete solution for verification

Use analytical solution for convergence rate tests

Investigate the amplitude errors of many solvers

Minimize memory usage of a simple vibration solver

Create a test function that verifies the implementation by comparing it to the other code for the same problem.

Fig. 1.14 The amplitude as it changes over 100 periods for Crank-Nicolson and Backward 2 step
Fig. 1.14 The amplitude as it changes over 100 periods for Crank-Nicolson and Backward 2 step

Minimize memory usage of a general vibration solver

Implement the Euler-Cromer scheme for the generalized model We consider the generalized model problem

Analysis of the Euler-Cromer scheme

  • A Centered Scheme for Linear Damping
  • A Centered Scheme for Quadratic Damping
  • A Forward-Backward Discretization of the Quadratic Damping Term
  • Implementation
  • Visualization
  • User Interface
  • The Euler-Cromer Scheme for the Generalized Model
  • A Staggered Euler-Cromer Scheme for a Generalized Model
  • The PEFRL 4th-Order Accurate Algorithm
  • Exercises and Problems

The error in the geometric mean approximation is O.t2/, the same as in the approximation u00DtDtu. In the derivation of a special equation for the first time, we encounter difficulties: the insertion of (1.76) into (1.82) for n D 0 leads to a complicated non-linear equation foru1. However, this quadratic polynomial in t does not satisfy the discrete equations in the case of quadratic damping, because the geometric mean used in the approximation of this term introduces an error.

Catching errors How good are the constant and quadratic solutions at catching errors in the implementation. We realize that the constant solution is very useful for catching certain errors due to its simplicity (easy to predict what the various terms in the formula will evaluate to), while the quadratic solution seems to be able to to detect all (?) other types of typos in the scheme. 1.8.1) and search uat mesh pointstn (the numerical value is indicated by un) and vbetween mesh points attnC1=2. the numerical value is indicated by vnC12).

Fig. 1.16 Damped oscillator excited by a sinusoidal function
Fig. 1.16 Damped oscillator excited by a sinusoidal function

Implement the solver via classes

Use a backward difference for the damping term

Perform numerical experiments to investigate how much accuracy is lost by using backward differences.

Use the forward-backward scheme with quadratic damping We consider the generalized model with quadratic damping, expressed as a system

Applications of Vibration Models

  • Oscillating Mass Attached to a Spring
  • General Mechanical Vibrating System
  • A Sliding Mass Attached to a Spring
  • A Jumping Washing Machine
  • Motion of a Pendulum
  • Motion of an Elastic Pendulum
  • Two-Body Gravitational Problem
  • Electric Circuits

The basic physical principle that governs the motion of a body is Newton's second law of motion: F D ma, where F is the sum of the forces on the body, m is its mass, and a D Rr is the acceleration. Then the number is the ratio of the free vibration time scale to the forced time scale. In particular, the free-body diagram will show both the motion of the pendulum and the magnitude of the forces during the motion.

The length of the wire when it is not stretched is L0, while L.t /is the stretched length at times during motion. The main difference is that we have amodelforS in terms of movement (once we have expressedL byr). The motion of the inelastic pendulum, on the other hand, is constrained: the body must move along a circular path, and the forces on the strings are unknown.

For an inelastic pendulum with small angles, we know that the frequency of the oscillations is The special case of circular motion, r D 1, satisfies the equations, since the latter equation then gives P D-const and the former then gives P D 1, i.e. the motion isr .t / D1,.t / Dt, with unit angular frequency as expected and period2 as expected.

Fig. 1.17 Simple oscillating mass
Fig. 1.17 Simple oscillating mass

Exercises

Simulate resonance

Simulate oscillations of a sliding box

Simulate a bouncing ball

Although the term "mechanical vibration" is used in this book, we should mention that the same type of equations arise when modeling electrical circuits. To avoid this situation, a state variable can be introduced that holds the mode of motion: free fall, impact, or rest.

Simulate a simple pendulum

Simulate an elastic pendulum

If < 10 degrees, add a graph comparing the solutions of the scaled, classical, inelastic, and elastic pendulum (.t. Although the math here uses a bar over the scaled quantities, the code should contain simple names xforx,N yfory , andN tfortN(instead of x_bar, etc.) If you want to use Odespy to solve the equations, order the ODEs as PNx;x;PNN y;yN such that atoodespy.EulerCromer can be applied.

Begin by simplifying the ODEs for pure vertical motion and show that y.N t /N satisfies a vibration equation with frequency pˇ=.1ˇ/. There will be numerical approximation errors present in the results from the simulations, so you should trust the correct results and set a (low) tolerance that corresponds to the maximum calculated error.

Simulate an elastic pendulum with air resistance

Implement the PEFRL algorithm

Gambar

Fig. 1.1 Empirical convergence rate curves with special slope marker
Figure 1.2 shows a comparison of the exact and numerical solution for the scaled model (1.13) with t D 0:1; 0:05
Fig. 1.3 Empirical angular frequency (left) and amplitude (right) for three different time steps
Fig. 1.4 Exact discrete frequency and its second-order series expansion
+7

Referensi

Dokumen terkait

4.11 Vertical Motion of a Body in a Viscous Fluid 109 becomes a linear equation invnC1, and we can therefore easily solve forvnC1: vnC1D vnCt bnC12 1Ct anC12jvnj: 4.48 Using a