4

A PDE with non-smooth inhomogeneity

Let $\mathcal{L}$ be a second-order, linear, elliptic differential operator acting on $\mathcal{C}^2([0,2]^2)$.

I'm numerically solving the inhomogeneous PDE \begin{align*} \mathcal{L}u(x,y)+(x-1)^+=0, \end{align*} where $(\cdot)^+$ denotes the positive part.

Put differently, I solve two PDEs which need to be connected at $x=1$: \begin{align*} \begin{cases} \mathcal{L}u(x,y)=0 & \text{for }(x,y)\in[0,1]\times[0,2], \\ \mathcal{L}u(x,y)+x-1=0& \text{for }(x,y)\in(1,2]\times[0,2]. \end{cases} \end{align*}

Approximating all partial derivatives by central differences, I get the nine-point stencil \begin{align*} c_1 u_{i-1,j-1} + c_2 u_{i,j-1} + c_3 u_{i+1,j-1} + c_4 u_{i-1,j} + c_5 u_{i,j} &\\ + c_6 u_{i+1,j}+ c_7 u_{i-1,j+1} + c_8 u_{i,j+1} + c_9 u_{i+1,j+1} + (x_i-1)^+ &=0. \end{align*} Thus, $u$ is the solution to a system of linear equations.

Problem

Plotting the solution $u$ for a fixed $y$, it all looks fine and perfect. However, a plot of $\frac{\partial u}{\partial x}$ as a function of $x$ shows that the derivative is not smooth at $x=1$. The above FD scheme works fine with value-matching (the solution $u$ is perfectly continuous) but struggles with smooth-pasting at $x=1$ (the derivative is not smooth).

enter image description here

Question

How do I ensure smooth-pasting with a finite difference scheme at $x=1$?


Some of my failed attempts include

  • Impose that forward and backward differences at $x=1$ equal each other (= 2nd order central difference is zero).
  • Use higher order approximations around $x=1$ such as $u_{xx}\approx \frac{-u(-2h)+16u(-h)-30u(0)+16u(h)-u(2h)}{12h^2}$ and $u_{x}\approx \frac{u(-2h)-8u(-h)+8u(h)-u(2h)}{12h}$ and central differences everywhere else.
  • Approximating partial derivatives using points only from one side of $x=1$ (i.e. only using either $u(0), u(h), u(2h)$ or instead $u(0),u(-h),u(-2h)$).
  • Imposing that $u_x\approx\frac{u_{i+1,j}-u_{i-1,j}}{2h}$ equals an average of partial derivatives at $1+h$ and $1-h$.

Note: This problem arises as part of a larger system of free boundary problems. Thus, it's necessary to solve the PDE numerically. This question is also posted here.

Alex
  • 703
  • 4
  • 19
  • What is “smooth pasting”? – A rural reader Feb 07 '21 at 22:50
  • 1
    It is not clear what you show in the picture above. In general case FDM numerical solution is set of points, not set of lines. We can suggest that you have used some interpolation to plot this lines. Is it correct? – Alex Trounev Feb 21 '21 at 23:38
  • @AlexTrounev The solution to the FDM are grid points $u_{i,j}$, where $(i,j)$ corresponds to $(x,y)$ in my notation. In the figure, I fix a $j$ and plot $x_i\mapsto u_{i,j}$. In the next panel, I plot the partial derivative for the same $j$, which I approximate by central differences, i.e. I plot $x_i\mapsto \frac{u_{i+1,j}-u_{i-1,j}}{x_{i+1}-x_{i-1}}$. Effectively, the FDM solution gives an approximation for $u(x,y)$. I just plot this function (and its partial derivative) as a function of $x$ while holding $y$ constant. – Alex Feb 21 '21 at 23:46
  • @AlexTrounev I didn't use a direct interpolation, but I suppose Matlab did. It uses linear interpolation for such plots, I think. But even if I choose $\Delta x$ very small, the big mismatch in slopes at $x=1$ remains – Alex Feb 21 '21 at 23:51
  • @Alex Did you try one PDE and special mesh around line $x=1$? – Alex Trounev Feb 22 '21 at 11:28
  • @AlexTrounev I'm sorry but I'm not sure what you mean with ''special mesh''? – Alex Feb 22 '21 at 11:37
  • 1
    @Alex In the case you considered it could be more dense mesh around line $x=1$. – Alex Trounev Feb 22 '21 at 14:36
  • @AlexTrounev So you suggest using a varying step size $\Delta x$ while keeping $\Delta y$ constant? Is there any special transformation of $x$ that you have in mind? Why do you think this could work, given that choosing $\Delta x$ very small everywhere did not work? – Alex Feb 22 '21 at 14:51
  • @Alex Can you explain your problem with equation and boundary conditions as well? – Alex Trounev Feb 22 '21 at 15:37
  • @AlexTrounev My actual problem is quite complicated actually. A stripped down version is $yu_{xx}+yu_{xy}+yu_{yy}+(x-1)^+=0$. The boundary conditions for $y=2$, $x=0$, $x=2$ are Dirichlet (known functions) whereas I impose the PDE as condition on the $y=0$ boundary, see here. – Alex Feb 22 '21 at 16:03
  • @AlexTrounev What makes you believe that a non-equal spacing of increments on the $x$-axis helps with smooth-pasting? – Alex Feb 22 '21 at 17:07
  • @Alex Can you provide link to some references with your model explanation? – Alex Trounev Feb 22 '21 at 17:40
  • @AlexTrounev Unfortunately, I do not have such a reference. I run into the problem without having seen something similar before. I wish I had a reference and knew how other people solved such PDE matching problems. It's a bit like a free boundary problem (where the boundary is known ex ante) – Alex Feb 22 '21 at 20:44
  • 1
    I believe @AlexTrounev is referring to an adaptive mesh, one that gets finer as you get nearer to interesting areas: boundaries, perforations, corners, and so forth. You then have to adapt your differencing templates accordingly; in a nutshell the weights will change. – A rural reader Feb 22 '21 at 21:43
  • @Alex It looks like your model is similar to that we discussed on https://mathematica.stackexchange.com/questions/239778/how-to-implement-fem-for-a-2d-pde-with-variable-coefficients/240035#240035 – Alex Trounev Feb 23 '21 at 13:08

3 Answers3

3

The solution will be continuous in both $u$ and $u_x$, but the latter won't be smooth at $x=1$. This means the centered difference there won't be second order.

  • Value matching is essentially continuity at $x=1$. The values of $u$ match there without a jump. Smooth pasting means that the derivative also agree at this point. So there’s a smooth transitioning at $x=1$. – Alex Feb 10 '21 at 02:57
  • The behavior you describe is precisely what I get! $u$ looks continuous but not smooth at $x=1$. Can you think of extra conditions to impose or how to adjust the finite difference scheme to ensure smooth pasting? – Alex Feb 10 '21 at 02:57
  • In the one dimensional case, the PDE would be an ODE and I can solve this ODE in closed form and use its free parameters to ensure value matching and smooth pasting at $x=1$. Thus I hope for a continuous solution for the PDE problem – Alex Feb 10 '21 at 03:01
  • 1
    You might consider using a noncentered difference at the discontinuity: $u_{xx}(0) \approx (2u(0) - 5u(h) + 4u(2h) - u(3h))/h^2$. – A rural reader Feb 10 '21 at 20:12
  • Thank you very much for the suggestion. Could you please expand a bit on the reasoning for this choice and why you suggested it? – Alex Feb 10 '21 at 22:27
  • 1
    Simply to maintain the second-order approximation of the second derivative, boundaries typically need special treatment. You might double-check that the conditions are met for the central differences approximation. – A rural reader Feb 10 '21 at 23:26
  • Why would a non-central approximation be better? In two dimensions, PDE contains $u_{xx}$, $u_{xy}$, $u_{yy}$, $u_x$ and $u_y$. Would you suggest to adjust all derivatives at $x=1$ or only the $u_{xx}$, necessary for smooth-pasting? Importantly, you'd only change the FD grid for this point, $x=1$, and nowhere else (where normal central differences work fine)? If you edit your answer to include all the details, I'll accept it immediately :) – Alex Feb 10 '21 at 23:39
  • 1
    If $f$ is smooth at 0, $f''(0) = (f(-h) - 2f(0) + f(h))/h^2 + O(h^2)$. This requires $f$, $f'$, $f''$ and $f'''$ are continuous at 0, and in exchange the discretization is $O(h^2)$. But if $f'''$ isn't, the best you get is $O(h)$. In your problem, if you know that $u_{xxx}$ is continuous at $x=1$ you're in good shape. I imagine $u_{xx}$ is. The one-sided discretization I shared is $O(h^2)$ and would only be used there. – A rural reader Feb 11 '21 at 01:36
  • Because the system is elliptic I believe theory guarantees all partial derivatives of a solution will be continuous, so no need to entertain the alternate I mentioned. – A rural reader Feb 11 '21 at 01:46
  • I really appreciate your help, you're helping me a lot! I wonder why you chose a ''three step forward'' difference at $x=1$? Like for $x=1-h$ and $x=1+h$, I use a central difference for all derivatives. But at $x=1$, I should use the points $1, 1+h, 1+2h$ and $1+3h$. How did you know to choose these points (instead of e.g. $1-h,1,1+h,1+2h$ or $1-2h,1-h,1,1+h,1+2h$). Also, we only use the non-central difference for $u_{xx}$ and not for other derivatives ($u_{xy}, u_x, u_{yy}, u_y$)? Sorry for asking so many question, it's just I really want like to understand how you came up with the solution – Alex Feb 11 '21 at 12:12
  • It seemed to me that there might be a loss of continuous derivatives at $x=1$, so that that area required special handling to keep the approximation of $(au_x)_x$ or $\Delta u$ second order. I don't think you need to do that, but that's where it came from. As far as choosing the template (the points to use) I knew I wanted to approximate the second derivative using only points from a region known to be smooth (one side or the other of $x=1$) so I picked one but could have picked the other. – A rural reader Feb 11 '21 at 15:21
  • Sorry, I was sick over the last days, so I couldn't come back to you :( I feel better now and implemented your suggestion. It doesn't quite work though. If I only use points from one side of $x=1$, then the solution loses both, value-matching and smooth-pasting: the solution simply jumps at $x=1$ as if both PDEs are completely independent of each other. Thus, I seem to need to tie both sides together. I then tried to use higher order approximations (using points at $1-2h,1-h,1,1+h,1+2h$) but that didn't succeed either :( – Alex Feb 15 '21 at 23:03
  • Hope you're feeling better @Alex. Did you try $(-f(-2h) + 8f(-h) -14f(0) + 8f(h) - f(2h))/(4h^2) + O(h^2)$, which straddles both sides of the $x=1$ divide? – A rural reader Feb 15 '21 at 23:13
  • I feel better now, yes thank you :) I don't think it was covid. I used $f_{xx}\approx \frac{-f(-2h)+16f(-h)-30f(0)+16f(h)-f(2h)}{12h^2}$ and $f_x\approx \frac{f(-2h)-8f(-h)+8f(h)-f(2h)}{12h}$ around $x=1$ and ''standard'' central differences everywhere else. – Alex Feb 15 '21 at 23:19
  • 1
    Make sure you're consistent in your approximations throughout the grid. The template $( -\tfrac{1}{12}, \tfrac{16}{12}, -\tfrac{30}{12}, \tfrac{16}{12}, -\tfrac{1}{12})$ for the second derivative is fourth order, as is $( \tfrac{1}{12}, -\tfrac{8}{12}, \tfrac{8}{12}, -\tfrac{1}{12})$ for the first derivative. You typically want to have the same order everywhere. I'll try to dig up an example. – A rural reader Feb 15 '21 at 23:49
  • What template would you suggest for $u_x$ and $u_{xx}$ (and I guess for $u_{xy}$?). I reckon I can stick with standard central differences for $u_{yy}$ and $u_y$? Also ''stay consistent throughout the grid'', so you'd advise not to use different approximations around $x=1$ but stay consistent throughout the grid? – Alex Feb 15 '21 at 23:56
2

I think you're running into theoretical limitations, but you're seeing the solution. The elliptic regularity theorem guarantees only so many continuous derivatives in the solution when the nonhomogeneous part is not completely smooth.

Take for example the similar but stripped-down problem $u_{xx}(x) = (x)_+$ on $(-1, 1)$ subject to $u(-1) = u(1) = 0$. For the left region ($-1 \leq x \leq 0$), $u^l(x) = a + ax$ for some constant $a$ satisfies the differential equation and the boundary condition at $x = -1$. And for the right region ($0 \leq x \leq 1$), $u^r(x) = A + Bx + x^3/6$ satisfies the differential equation. To ensure $u$ and $u_x$ are continuous at $x=0$ you need $A = a$ and $B = a$ so \begin{align*} u^l(x) &= a + a x, \\ u^r(x) &= a + a x + x^3/6. \end{align*} The right boundary condition requires $a + a + 1/6 = 0$, so $a = -1/12$.

You can see $u$, $u_{x}$, $u_{xx}$ all are continuous at $x = 0$, but $u_{xxx}$ isn't.

  • 1
    I think you are absolutely right. I too think it’s impossible to get a $\mathcal{C}^\infty$ function. I still hope for a function with smooth first derivative though. I can accept if higher derivatives are not smooth. Your example shows $u_{xxx}$ is okay. I’d confine myself to a smooth $u_x$. – Alex Feb 16 '21 at 09:05
2

Let's say your solution $u$ is continuous at $x=1$, as are $u_x$ and $u_{xx}$, but not $u_{xxx}$. I think that's the situation you have. Using the standard templates centered at $x=1$ won't give you the accuracy you might expect, so you need to adjust.

One way to explore this is to consider the function \begin{equation} f(z) = \begin{cases} a_0 + a_1z + a_2z^2 + f_3z^3 + f_4z^4 + \cdots &\text{ for } z < 0, \\ a_0 + a_1z + a_2z^2 + g_3z^3 + g_4z^4 + \cdots &\text{ for } z > 0. \end{cases} \end{equation} I've shifted from $x=1$ to $z=0$ just to make the typing a bit easier. It's pretty smooth and you can argue $f$, $f'$, and $f''$ are continuous from the left and right. The standard $(1, -2, 1)/h^2$ template, which usually gives an $O(h^2)$ estimate for the second derivative now yields only $O(h)$. Give it a try. And the template $(-\tfrac{1}{12}, \tfrac{16}{12}, -\tfrac{30}{12}, \tfrac{16}{12}, -\tfrac{1}{12})/h^2$, which you'd expect to deliver $O(h^3)$, doesn't, it's also $O(h)$.

Instead, you'll need to respect the differences between the two regions. One way to do this is with a template that does exactly that. Try $(-\tfrac{1}{4}, 2, -\tfrac{7}{2}, 2, -\tfrac{1}{4})/h^2$. You'll see it's $O(h^2)$.

For most of your grid the standard template works fine and is precisely what you want, but it's the loss of higher derivatives at $x=1$ that tells you closer attention is required there.