# Diff of /trunk/doc/cookbook/example07.tex

revision 3003 by ahallam, Wed Apr 7 02:29:57 2010 UTC revision 3004 by ahallam, Wed Apr 14 05:27:30 2010 UTC
# Line 15  Line 15
15
16  The acoustic wave equation governs the propagation of pressure waves. Wave  The acoustic wave equation governs the propagation of pressure waves. Wave
17  types that obey this law tend to travel in liquids or gases where shear waves  types that obey this law tend to travel in liquids or gases where shear waves
18  or longitudinal style wave motion is not possible. The obvious example is sound  or longitudinal style wave motion is not possible. An obvious example is sound
19  waves.  waves.
20
21  The acoustic wave equation is;  The acoustic wave equation is defined as;
22
23   \nabla ^2 p - \frac{1}{c^2} \frac{\partial ^2 p}{\partial t^2} = 0   \nabla ^2 p - \frac{1}{c^2} \frac{\partial ^2 p}{\partial t^2} = 0
24  \label{eqn:acswave}  \label{eqn:acswave}
25
26  where $p$ is the pressure, $t$ is the time and $c$ is the wave velocity.  where $p$ is the pressure, $t$ is the time and $c$ is the wave velocity.

27
28    \section{The Laplacian in \esc}
29    The Laplacian opperator which can be written as $\Delta$ or $\nabla^2$  is
30    calculated via the divergence of the gradient of the object, which is in this
31    example $p$. Thus we can write;
32
33     \nabla^2 p = \nabla \cdot \nabla p = \frac{\partial^2 p}{\partial
34    x^2\hackscore{i}}
35     \label{eqn:laplacian}
36
37    For the two dimensional case in Cartesian coordinates \refEq{eqn:laplacian}
38    becomes;
39
40     \nabla^2 p = \frac{\partial^2 p}{\partial x^2}
41               + \frac{\partial^2 p}{\partial y^2}
42
43
44    In \esc the Laplacian is calculated using the divergence representation and the
45    intrinsic functions \textit{grad()} and \textit{trace()}. The fucntion
47    For a rank 0 solution, this is of the form;
48
49     \nabla p = \left[
50           \frac{\partial p}{\partial x \hackscore{0}},
51           \frac{\partial p}{\partial x \hackscore{1}}
52                      \right]
54
55    Larger ranked solution objects will return gradient tensors. For example, a
56    pressure field which acts in the directions $p \hackscore{0}$ and $p 57 \hackscore{1}$ would return;
58
59      \nabla p = \begin{bmatrix}
60           \frac{\partial p \hackscore{0}}{\partial x \hackscore{0}} &
61            \frac{\partial p \hackscore{1}}{\partial x \hackscore{0}} \\
62          \frac{\partial p \hackscore{0}}{\partial x \hackscore{1}} &
63            \frac{\partial p \hackscore{1}}{\partial x \hackscore{1}}
64                      \end{bmatrix}
66
67
68    \refEq{eqn:grad} corresponds to the Linear PDE general form value
69    $X$. Notice however that the gernal form contains the term $X \hackscore{i,j}$,
70    hence for a rank 0 object there is no need to do more than calculate the
71    gradient and submit it to the solver. In the case of the rank 1 or greater
72    object, it is nesscary to calculate the trace also. This is the sum of the
74
75    Thus when solving for equations containing the Laplacian one of two things must
76    be completed. If the object \verb p   is less than rank 1 the gradient is
77    calculated via;
78    \begin{verbatim}
80    \end{verbatim}
81    and if the object is greater thank or equal to a rank 1 tensor, the trace of
83    \begin{verbatim}
85    \end{verbatim}
86
87    These valuse can then be submitted to the PDE solver via the general form term
88    $X$. The Laplacian is then computed in the solution process by taking the
89    divergence of $X$.
90
91  \section{Numerical Solution Stability}  \section{Numerical Solution Stability}
92  Unfortunately, the wave equation is belongs to a class of equations called  Unfortunately, the wave equation belongs to a class of equations called
93  \textbf{stiff} PDEs. This types of equations can be difficult to solve  \textbf{stiff} PDEs. These types of equations can be difficult to solve
94  numerically as they tend to oscilate about the exact solution and can  numerically as they tend to oscilate about the exact solution and can
95  eventually blow up. To counter this problem, explicitly stable schemes like the  eventually fail. To counter this problem, explicitly stable schemes like
96  backwards Euler method are required. In terms of the wave equation, the  the backwards Euler method are required. There are two variables which must be
97    considered for stability when numerically trying to solve the wave equation.
98
99     \label{eqn:freqvel}
100    f=\frac{v}{\lambda}
101
102
103
104    Velocity is one of these variables. For stability the
105  analytical wave must not propagate faster than the numerical wave is able to,  analytical wave must not propagate faster than the numerical wave is able to,
106  and in general, needs to be much slower than the numerical wave.  and in general, needs to be much slower than the numerical wave.

107  For example, a line 100m long is discretised into 1m intervals or 101 nodes. If  For example, a line 100m long is discretised into 1m intervals or 101 nodes. If
108  a wave enters with a propagation velocity of 100m/s then the travel time for  a wave enters with a propagation velocity of 100m/s then the travel time for
109  the wave between each node will be 0.01 seconds. The time step, must therefore  the wave between each node will be 0.01 seconds. The time step, must therefore
110  be significantly less than this. Of the order $10E-4$ would be appropriate.  be significantly less than this. Of the order $10E-4$ would be appropriate.
111
112  This requirement for very small step sizes makes stiff equations difficult to  The wave frequency content also plays a part in numerical stability. The
113    nyquist-sampling theorem states that a signals bandwidth content will be
114    accurately represented when an equispaced sampling rate $f \hackscore{n}$ is
115    equal to or greater than twice the maximum frequency of the signal
116    $f\hackscore{s}$, or;
117     \label{eqn:samptheorem}
118     f\hackscore{n} \geqslant f\hackscore{s}
119
120    For example a 50Hz signal will require a sampling rate greater than 100Hz or
121    one sample every 0.01 seconds. The wave equation relies on a spatial frequency,
122    thus the sampling theorem in this case applies to the solution mesh spacing. In
123    this way, the frequency content of the input signal directly affects the time
124    discretisation of the problem.
125
126    To accurately model the wave equation with high resolutions and velocities
127    means that very fine spatial and time discretisation is necessary for most
128    problems.
129    This requirement makes the wave equation arduous to
130  solve numerically due to the large number of time iterations required in each  solve numerically due to the large number of time iterations required in each
131  solution. Models with very high velocities and fine meshes will be the worst  solution. Models with very high velocities and frequencies will be the worst
132  affected by this problem.  effected by this problem.

133
134  \section{Displacement Solution}  \section{Displacement Solution}
135  \sslist{example07a.py}  \sslist{example07a.py}
# Line 59  second derivative; Line 143  second derivative;
143  substituting \refEq{eqn:centdiff} for $\frac{\partial ^2 p }{\partial t ^2}$  substituting \refEq{eqn:centdiff} for $\frac{\partial ^2 p }{\partial t ^2}$
144  in \refEq{eqn:acswave};  in \refEq{eqn:acswave};
145
146   \nabla ^2 p - \frac{1}{c^2h^2} \left[p_{(t+1)} - 2p_{(t)} + p_{(t-1)} \right]   \nabla ^2 p - \frac{1}{c^2h^2} \left[p\hackscore{(t+1)} - 2p\hackscore{(t)} +
147    p\hackscore{(t-1)} \right]
148  = 0  = 0
149  \label{eqn:waveu}  \label{eqn:waveu}
150
151  Rearranging for $p_{(t+1)}$;  Rearranging for $p_{(t+1)}$;
152
153   p_{(t+1)} = c^2 h^2 \nabla ^2 p_{(t)} +2p_{(t)} - p_{(t-1)}   p\hackscore{(t+1)} = c^2 h^2 \nabla ^2 p\hackscore{(t)} +2p\hackscore{(t)} -
154    p\hackscore{(t-1)}
155
156  this can be compared with the general form of the \modLPDE module and it  this can be compared with the general form of the \modLPDE module and it
157  becomes clear that $D=1$, $X=-c^2 h^2 \nabla ^2 p_{(t)}$ and $Y=2p_{(t)} - becomes clear that$D=1$,$X\hackscore{i,j}=-c^2 h^2 \nabla ^2 p_{(t)}$and 158 p_{(t-1)}$.  $Y=2p_{(t)} - p_{(t-1)}$.
159
160    The solution script is similar to other that we have created in previous
161    chapters. The general steps are;
162    \begin{enumerate}
163     \item The necessary libraries must be imported.
164     \item The domain needs to be defined.
165     \item The time iteration and control parameters need to be defined.
166     \item The PDE is initialised with source and boundary conditions.
167     \item The time loop is started and the PDE is solved at consecutive time steps.
168     \item All or select solutions are saved to file for visualisation lated on.
169    \end{enumerate}
170
171    Parts of the script which warrant more attention are the definition of the
172    source, visualising the source, the solution time loop and the VTK data export.
173
174    \subsection{Pressure Sources}
175    As the pressure is a scalar, one need only define the pressure for two
176    time steps prior to the start of the solution loop. Two known solutions are
177    required because the wave equation contains a double partial derivative with
178    respect to time. This is often a good opportunity to introduce a source to the
179    solution. This model has the source located at it's centre. The source should
180    be smooth and cover a number of samples to satisfy the frequency stability
181    criterion. Small sources will generate high frequency signals. Here, the source
182    is defined by a cosine function.
183    \begin{verbatim}
184    U0=0.01 # amplitude of point source
185    xc=[500,500] #location of point source
186    # define small radius around point xc
188    # for first two time steps
190    us)
191    u_m1=u
192    \end{verbatim}
193    When using a rectangular domain
194
195  \section{Acceleration Solution}  \section{Acceleration Solution}
196  \sslist{example07b.py}  \sslist{example07b.py}
# Line 81  PDE solution. \refEq{eqn:waveu} is thus Line 202  PDE solution. \refEq{eqn:waveu} is thus
202    \nabla ^2 p - \frac{1}{c^2} a = 0    \nabla ^2 p - \frac{1}{c^2} a = 0
203  \label{eqn:wavea}  \label{eqn:wavea}
204
205  and can be solved directly with $Y=0$ and $X=-c^2 \nabla ^2 p_{(t)}$.  and can be solved directly with $Y=0$ and $X=-c^2 \nabla ^2 p\hackscore{(t)}$.
206  After each iteration the displacement is re-evaluated via;  After each iteration the displacement is re-evaluated via;
207
208   p_{(t+1)}=2p_{(t)} - p_{(t-1)} + h^2a   p\hackscore{(t+1)}=2p\hackscore{(t)} - p\hackscore{(t-1)} + h^2a
209
210
211    For \esc, the acceleration solution is prefered as it allows the use of matrix
212    lumping. Lumping or mass lumping as it is sometimes known, is the process of
213    aggressively approximating the density elements of a mass matrix into the main
214    diagonal. The use of Lumping is motivaed by the simplicity of diagonal matrix
215     inversion. As a result, Lumping can significantly reduce the computational
216    requirements of a problem.
217
218    To turn lumping on in \esc one can use the command;
219    \begin{verbatim}
220     mypde.getSolverOptions().setSolverMethod(mypde.getSolverOptions().LUMPING)
221    \end{verbatim}
222    It is also possible to check if lumping is set using;
223    \begin{verbatim}
224      print mypde.isUsingLumping()
225    \end{verbatim}
226
227    \section{Stability Investigation}
228    It is now prudent to investigate the stability limitations of this problem.
229    First, we let the frequency content of the source be very small. If the radius
230    of the source which equals the wavelength is 5 meters, than the frequency is
231    the inverse of the wavelength  The velocity is $c=380.0ms^{-1}$ thus the source
232    frequency is $f\hackscore{r} = \frac{380.0}{5} = 76.0 Hz$. The sampling
233    frequency must be at least twice this. Assuming a rectangular equispaced grid,
234    the sampling interval is $\Delta x = \frac{1000.0}{400} = 2.5$ and the sampling
235    frequency $f\hackscore{s}=\frac{380.0}{2.5}=152$ this is just equal to the
236    required rate satisfying \refeq{eqn:samptheorem}.
237
238
239
240

Legend:
 Removed from v.3003 changed lines Added in v.3004