2
$\begingroup$

I'm trying to solve a very simple advection PDE

$\frac{\partial u}{\partial t}+c\frac{\partial u}{\partial x}=0$

where $c<0$.

I have been able to implement a simple Modelica code to solve the equation and it works just fine for $c>0$ with the exact same boundary conditions, though. So my question is why my code is not able to finish the simulation:

  1. Is it a mathematical issue? Like such PDE never has a solution for $c<0$?
  2. is it a finite difference limitation and maybe I should use other numerical methods?
  3. or there is some issue with the code or Modelica compiler?

I would appreciate if you could help me figure this issue out.

P.S. the goal for me is to learn how to solve PDEs in Modelica and this is just one example.

$\endgroup$
3
$\begingroup$

and it works just fine for c>0 with the exact same boundary conditions, though.

That's your issue. Look up the method of characteristics:

https://web.stanford.edu/class/math220a/handouts/firstorder.pdf

The characteristics for a 1D advection problem flow in one direction. So there are two things involved. One is that the BCs on one side of the interval matter since the characteristics are only flowing in one direction. Secondly,

https://en.wikipedia.org/wiki/Upwind_scheme

the upwind scheme has to change directions depending on the direction of the characteristics. So you need to change your implementation to match the direction as given by sign(c). When c<0, you need to use u[i+1] instead of u[i-1].

$\endgroup$
  • $\begingroup$ I'm not sure if I understand this correctly. would you be so kind to implement in Modelica? you may edit my post in SO? $\endgroup$ – Foad Aug 5 '17 at 22:07
  • 1
    $\begingroup$ Did you read the Wiki on the upwind scheme? u[i] = u[i + 1] + dx * ux[i] the direction changes when c changes sign. This means you'll have to treat the boundaries differently too, since the boundary is just the first/last term. The boundary is implicitly done by your loop being i in 2:N. You change that to i in 1:N-1. That should be more than enough hints to fix it. $\endgroup$ – Chris Rackauckas Aug 5 '17 at 22:12
  • $\begingroup$ I actually did the same thing and got the error : Variable ux[100] is not present in any equation. That's why I asked :) Should I also change the BC so it starts form the end? $\endgroup$ – Foad Aug 5 '17 at 22:19
  • $\begingroup$ I think I have figured the issue out. but yet to read your references to comprehend the issue. $\endgroup$ – Foad Aug 5 '17 at 22:24
  • $\begingroup$ I fixed the code based on your advice. It runs fine. I would appreciate if you could take a look and let me know if I had done everything correctly. $\endgroup$ – Foad Aug 5 '17 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.