• No se han encontrado resultados

POST-GR.4.20.30.20.10 EVALUACIÓN ANUAL DEL DOCENTE

In document Sistema de Gestión de la Calidad ESIC (página 93-97)

POST-GR4.20.30.20 Evaluación del Desempeño de

POST-GR.4.20.30.20.10 EVALUACIÓN ANUAL DEL DOCENTE

% w_y for j=1:ny

wty(:,j)=i*(wt(:,j).*k y);

end

wy=ifft2(wty*N );

% transform w_x*psi_y and w_y*psi_x and reshape wxpyt=fft2(wx.*psiy)/N;

wypxt=fft2(wy.*psix)/N;

wxpyt2=reshape(wxpyt,N,1);

wypxt2=reshape(wypxt,N,1);

% Laplacian Terms for j=1:nx

wtxx(j,:)=-wt(j,:).*(kx.^2)’;

end

for j=1:ny

wtyy(:,j)=-wt(:,j).*(ky.^2);

end

wtxx2=reshape(wtxx,N, 1);

wtyy2=reshape(wtyy,N, 1);

rhs=(nu*(wtxx2+wtyy2)-wypxt2+wxpyt2);

The code will quickly and efficiently solve the advection-diffusion equations in two dimensions. Figure 14 demonstrates the evolution of the initial stretched Gaussian vortex over t ∈ [0, 8].

4.4 Pseudo-spectral techniques with filtering

The decomposition of the solution into Fourier mode components does not al- ways lead to high performance computing. Specifically when some form of nu- merical stiffness is present, computational performance can suffer dramatically.

However, there are methods available which can effectively eliminate some of the numerical stiffness by making use of analytic insight into the problem.

We consider again the example of hyper-diffusion for which the governing equations are

∂u

∂t In the Fourier domain, this becomes

du

4u

= − ∂x4 . (4.4.1)

= (ik)4u = k4u (4.4.2)

dt

max

k4

− −

which has the solution

u = u0 exp(−k4t) . (4.4.3)

However, a time-stepping scheme would obviously solve (4.4.2) directly without making use of the analytic solution.

For n = 128 Fourier modes, the wavenumber k ranges in values from k ∈ [−64, 64]. Thus the largest value of k for the hyper-diffusion equation is

k4 max = (64) = 16, 777, 216 , 4 (4.4.4) or roughly k4 = 1.7 × 107. For n = 1024 Fourier modes, this is

max = 6.8 × 1010. (4.4.5)

Thus even if our solution is small at the high wavenumbers, this can create problems. For instance, if the solution at high wavenumbers is O(10−6), then

du = (1010)(10−6) = 104 . (4.4.6) dt

Such large numbers on the right hand side of the equations forces time-stepping schemes like ode23 and ode45 to take much smaller time-steps in order to main- tain tolerance constraints. This is a form of numerical stiffness which can be circumvented.

Filtered Pseudo-Spectral

There are a couple of ways to help get around the above mentioned numerical stiffness. We again consider the very general partial differential equation

∂u = Lu + N (u) (4.4.7)

∂t

where as before L is a linear, constant coefficient operator, i.e. it can take the form L = ad2/dx2 + bd/dx + c where a, b, and c are constants. The second term N (u) includes the nonlinear and non-constant coefficient terms. An example of this would be N (u) = u3 + f (x)u + g(x)d2 u/dx2.

Previously, we transformed the equation by Fourier transforming and con- structing a system of differential equations. However, there is a better way to handle this general equation and remove some numerical stiffness at the same time. To introduce the technique, we consider the first-order differential equa- tion

dy + p(t)y = g(t) . (4.4.8)

dt

We can multiply by the integrating factor µ(t) so that

µ dy + µp(t)y = µg(t) . (4.4.9) dt

We note from the chain rule that (µy)t = µty + µyt where the prime denotes differentiation with respect to t. Thus the differential equation becomes

d (µy) = µg(t) , (4.4.10)

dt

provided dµ/dt = µp(t). The solution then becomes

1 l

y = µ(t)g(t)dt + c µ

\

µ(t) = exp p(t)dt (4.4.11) which is the standard integrating factor method of a first course on differential equations.

We use the key ideas of the integrating factor method to help solve the general partial differential equation and remove stiffness. Fourier transforming (4.4.7) results in the spectral system of differential equations

This can be rewritten

du = α(k)u + N (u) . (4.4.12) dt

du

dt − α(k)u = N (u) . (4.4.13)

Multiplying by exp(−α(k)t) gives du

dt exp(−α(k)t) − α(k)u exp(−α(k)t) = exp(−α(k)t)N (u) d

dt [u exp(−α(k)t)] = exp(−α(k)t)N (u) .

By defining v = u exp(−α(k)t), the system of equations reduces to dv

dt = exp(−α(k)t)N (u) (4.4.14a)

u = v exp(α(k)t) . (4.4.14b)

Thus the linear, constant coefficient terms are solved for explicitly, and the numerical stiffness associated with the Lu term is effectively eliminated.

Example: Fisher-Kolmogorov Equation

As an example of the implementation of the the filtered pseudo-spectral scheme, we consider the Fisher-Kolmogorov equation

∂u ∂2u

∂t = ∂x2 + u3 + cu . (4.4.15)

− − Fourier transforming the equation yields

du

which can be rewritten

Thus α(k) = c − k2 and

= (ik)2 u + u3 + cu (4.4.16) dt

du + (k2 c)u = u3 . (4.4.17) dt

dv = exp[ (c k2)t]u3 (4.4.18a) dt

u = v exp[(c − k2)t] . (4.4.18b) It should be noted that the solutions u must continually be updating the value of u3 which is being transformed in the right hand side of the equations. Thus after every time-step ∆t, the new u should be used to evaluate u3.

There are a couple of practical issues that should be considered when imple- menting this technique

• When solving the general equation

∂u = Lu + N (u) (4.4.19)

∂t

it is important to only step forward ∆t in time with dv

dt = exp(−α(k)t)N (u) u = v exp(α(k)t) before the nonlinear term N (u) is updated.

• The computational savings for this method generally does not manifest itself unless there are more than two spatial derivatives in the highest derivative of Lu.

• Care must be taken in handling your time-step ∆t in MATLAB since it uses adaptive time-stepping.

Comparison of Spectral and Finite Difference Methods

Before closing the discussion on the spectral method, we investigate the ad- vantages and disadvantages associated with the spectral and finite difference schemes. Of particular interest are the issues of accuracy, implementation, com- putational efficiency, and boundary conditions. The strengths and weaknesses of the schemes will be discussed.

A. Accuracy

• Finite Differences: Accuracy is determined by the ∆x and ∆y chosen in the discretization. Accuracy is fairly easy to compute and generally much worse than spectral methods.

• Spectral Method: Spectral methods rely on a global expansion and are often called spectrally accurate. In particular, spectral methods have infinite order accuracy. Although the details of what this means will not be discussed here, it will suffice to say that they are generally of much higher accuracy than finite differences.

B. Implementation

• Finite Differences: The greatest difficulty in implementing the finite difference schemes is generating the correct sparse matrices.

Many of these matrices are very complicated with higher order schemes and in higher dimensions. Further, when solving the resulting system Ax = b, it should always be checked whether det A = 0. The MAT- LAB command cond(A) checks the condition number of the matrix.

If cond(A)> 1015, then det A ≈ 0 and steps must be taken in order to solve the problem correctly.

• Spectral Method: The difficulty with using FFTs is the continual switching between the time or space domain and the spectral do- main. Thus it is imperative to know exactly when and where in the algorithm this switching must take place.

C. Computational Efficiency

• Finite Differences: The computational time for finite differences is determined by the size of the matrices and vectors in solving Ax = b.

Generally speaking, you can guarantee O(N 2 ) efficiency by using LU decomposition. At times, iterative schemes can lower the operation count, but there are no guarantees about this.

• Spectral Method: The FFT algorithm is an O(N log N ) operation.

Thus it is almost always guaranteed to be faster than the finite dif- ference solution method which is O(N 2). Recall that this efficiency improvement comes with an increased accuracy as well. Thus making the spectral highly advantageous when implemented.

D. Boundary Conditions

• Finite Differences: Of the above categories, spectral methods are generally better in every regard. However, finite differences are clearly

superior when considering boundary conditions. Implementing the generic boundary conditions

αu(L) + β du(L)

dx = γ (4.4.20)

is easily done in the finite difference framework. Also, more com- plicated computational domains may be considered. Generally any computational domain which can be constructed of rectangles is eas- ily handled by finite difference methods.

• Spectral Method: Boundary conditions are the critical limitation on using the FFT method. Specifically, only periodic boundary con- ditions can be considered. The use of the discrete sine or cosine transform allows for the consideration of pinned or no-flux boundary conditions, but only odd or even solutions are admitted respectively.

In document Sistema de Gestión de la Calidad ESIC (página 93-97)