# Numerical Stability of a Generalized Spatial Discretization Scheme

After reading the matrix stability chapter (10) of Hirsch , I decided to dive in the reference list of the chapter. One of the papers , which is cited as reference shows an very interesting approach to stability analysis.

The paper shows an stability evaluation of a real world flow solution of a NACA0012 airfoil with artificial dissipation and all the bells and witless which are expected to solve this type of flowfield.

Basically, the matrix stability method, as explained in Hirsch and, apparently used in Ref. , is defined as follows:

If you have an discretized PDE, you end up with.

$$\frac{d \bf U }{d t} = \bf S \bf U + \bf Q$$.

If you compute the eigenvalues of the Jacobian $$\bf S$$, the maximum real part of the eigenvalues say to you if you spatial discretization scheme is stable or not. A positive real eigenvalue amplifies in time and ends up messing up with your stability.

I am trying to study the stability of some very simple cases, however, I do not want to use the defined banded matrix definitions of the matrices $$\bf S$$. I want to be able to derive it numerically so, when the cases become less trivial, I will still be able to evaluate the stability of my case. The problem I am facing right now is how to derive the matrix $$\bf S$$, since it is defined as:

$$\bf S = \frac{\partial\, \bf RHS}{\partial \, \bf U}$$

Where $$\bf RHS$$ represent my spatial discretization scheme, and $$\bf U$$ is my solution vector.

For a 1-D case, $$\bf RHS$$ is a vector with the same size as $$\bf U$$. I tried to use simple finite differences, however, they do not seen to be robust enough. Or, at least, trying to compute the derivatives with:

for i in range(1,n_points):
drhs_du = (rhs[i+1] - rhs[i-1]) / 2.0*(u[i+1] - u[i-1])


gives me a whole lot of by-zero-divisions.

I saw some references using Frechet derivatives to compute the $$\bf S$$ Jacobian, but the authors who used it, which I know in person, also reported that this type of numerical derivative is quite troublesome.

My question, finally, is related to robust suggestions to compute this Jacobian numerically. Which algorithms would you use or, even, which derivative definition would you guys use ? Are there reliable high performance libraries with the algorithms implemented ?

Thank you !

 Hirsch.C "Numerical Computation of Internal and External Flows Vol.01"

 Eriksson.L.E. Rizzi "A Computer Aided Analysis of the Convergence to Steady State of Discrete Approximations to the Euler Equations"

Edit # 01

Can the proper implementation of the method described in the second paragraph of the comment made below be translated as:

def frhs(unn,unm1,dx):
return (unn - unm1)/dx

eps = 0.0001

drhs_du = np.zeros((nx,nx))

for i in range(1,nx-1):
for j in range(1,nx-1):
drhs_du[i,j] = (frhs(un[i] + eps,un[i-1] + eps,dx) - frhs(un[j],un[j-1],dx))/eps


?

## 1 Answer

So it looks to me like there is a misunderstanding. your residual, or right hand side, presumably depends on multiple cells, so when building your jacobian, you should ask yourself how each entry in your residual depends on each cell. Now this should give you an nxn sparse matrix. If you in fact linearize this by hand, you should be able to store it in a vector that scales linearly with the number of cells. Given that you're 1d, I'm assuming it's size 3n, but that depends on your discretization. This is rather simple to do but rather tedious.

Another method is to calculate numerical derivatives, which you mentioned, and seem to be the source of your misunderstanding. It is not evaluated as you suggest, which is looking at different cells and taking a difference of the residuals and taking a difference of the cell values. Rather it is done through a cell by cell approach, where you perturb each cell's value individually and see how this affects the residual, and you take the difference between the residual from the perturbed and unperturbed states and divide by the perturbation. When doing this, you will discover that the stencil is pretty limited, and you should get a great deal of zeros as you fill out your matrix, and you will be able to store this sparse matrix in a vector as mentioned above.

The last possibility, is that you in fact do not need the jacobian matrix, you need the jacobian vector product. You can instead perturb the entire field by an infinitesimal complex perturbation in the direction of the vector you are multiplying the jacobian by, evaluate the residual of this perturbed state, and you will have obtained the frechet derivative without round-off error.

• The first approach you mentioned (2nd paragraph) seems like the definition of the Frechet derivative I find in some of the papers I am reading. The second approach (3rd paragraph) seems like the complex step method to compute the derivatives. However, in the second approach you mentioned, I did not quite got what you said. Should I perturb the $\bf U$ vector by a small complex part ? Like U = U + eps*i ? But how can I evaluate the eigenvalues of this vector ? – LM_O May 3 at 23:59
• The third method is the complex step method, but by using a vector perturbation you get the Jacobian vector product, rather than the cell by cell derivative. The second method is just also the complex step method, but to obtain each entry of the jacobian. But I guess they're both cases of the frechet derivative if I remember correctly.and yes that is how you would implement it. You would perturb each entry individually, and take the imaginary part of the residual when calculating the residual from the perturbed state and build your jacobian matrix that way. Then you calculate the eigenvalues – EMP May 4 at 13:10
{"ft_lang_label":"__label__en","ft_lang_prob":0.8989284,"math_prob":0.95880014,"size":2825,"snap":"2019-35-2019-39","text_gpt3_token_len":735,"char_repetition_ratio":0.101028,"word_repetition_ratio":0.0,"special_character_ratio":0.25946903,"punctuation_ratio":0.12776831,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99505824,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-24T22:50:13Z\",\"WARC-Record-ID\":\"<urn:uuid:fcaa6b13-6c55-48a3-9190-c04e18e7b0a3>\",\"Content-Length\":\"140367\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f1b3d323-5b16-40b1-9a4e-f84e52f1a8e6>\",\"WARC-Concurrent-To\":\"<urn:uuid:f2693b9a-a749-435c-ac40-1e83e39c0273>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://scicomp.stackexchange.com/questions/32572/numerical-stability-of-a-generalized-spatial-discretization-scheme/32574\",\"WARC-Payload-Digest\":\"sha1:K35TEKQLBCOP4DYU3DTQUYSNNPH4BC2M\",\"WARC-Block-Digest\":\"sha1:3ECGIW24GIN4EUSAYC4NQUHHKWANY3SE\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027321786.95_warc_CC-MAIN-20190824214845-20190825000845-00206.warc.gz\"}"}