3

I encountered this when trying to solve the PDE mentioned here. I've transformed the equation to the following:

With[{u = u[x, t]}, 
 neweq = D[u, t] == Inactive[Div][{{u^2}}.Inactive[Grad][u, {x}], {x}] + 
                    {1}.Inactive[Grad][Sign[x] u, {x}]]

This is the formal PDE for FiniteElement method as far as I can tell, but it doesn't lead to the correct solution. After checking with GetInactivePDE, I found the Inactive[Grad][Sign[x] u, {x}]] term is simply lost in parsing stage:

(* Definition of GetInactivePDE isn't included in this post,
   please find it in the link above. *)
showFormalPDE[a__] := 
  Module[{state}, {state} = NDSolve`ProcessEquations[a];
   GetInactivePDE[state["FiniteElementData"]@"PDECoefficientData", 
      state@"VariableData"] == 0 // Thread];

{bc, ic} = {{u[-7, t] == 0, u[7, t] == 0}, u[x, 0] == Exp[-x^2]}; showFormalPDE[{neweq, ic, bc}, u, {t, 0, 2}, {x, -7, 7}] (* {Inactive[Div][-{{u[x]^2}} . Inactive[Grad][u[t, x], {x}], {x}] + Derivative[1, 0][u][t, x] == 0} *)

Is this a bug? Or separate Inactive[Grad][……] term in PDE is not allowed at the moment?

Tested on v12.1.1.


Just a simpler sample reflecting the underlying issue:

eq = D[u[x, t], t] == Inactive[Grad][aaaa[x], {x}];
ic = u[x, 0] == 0;
showFormalPDE[{eq, ic}, u, {x, 0, 1}, {t, 0, 2}]
(* {Derivative[1, 0][u][t, x] == 0} *)
xzczd
  • 65,995
  • 9
  • 163
  • 468

1 Answers1

2

No, this is not a bug. You can not have Inactive[Grad][Sign[x] u[x], {x}] you can only have Inactive[Grad][u[x], {x}] the rest needs to go into some coefficient.

user21
  • 39,710
  • 8
  • 110
  • 167
  • Oh, I see… but I'd argue that a warning should be generated in this case. – xzczd Sep 23 '20 at 06:09
  • 2
    Yes, a warning probably would be good. The problem is when I first wrote that parser I wrote it in a way that would look at the entire equation and then extract the components it recognizes. However, it does not 'subtract' what it recognizes from the argument given and in the end I have no knowledge of what did not get parsed. Trust me I would not do it this way again, but re-writing the parser would be quite a thing. Maybe something in the future. Sorry about that. – user21 Sep 23 '20 at 06:14
  • It is not clear why we need inactive form of equation for FEM. And also we don't know what is inactive form in every case. – Alex Trounev Sep 23 '20 at 14:06
  • @AlexTrounev Have a look at the documentation. The main point of Inactive is to prevent premature evaluation - that's necessary for a variety of reasons, have a look here, here and here. – user21 Sep 23 '20 at 15:26
  • @user21 I read documentation during last several years, but I don't understand why we need inactive form at all. Is it connected with some algorithm implemented in NDSolve? – Alex Trounev Sep 23 '20 at 15:34
  • @AlexTrounev, it's not clear to me what information you are looking for regarding Inactive that is not on the above pages. Can you clarify? Give me a specific sentence or section that you do not understand. – user21 Sep 24 '20 at 05:55
  • Ok, let me explain. Suppose we have an equation containing D, Derivative, Div, Grad, Curl, Laplacian. We can made it inactive simply used Inactivate[equation, D| Derivative| Div| Grad| Curl| Laplacian]. This can be done automatically without users efforts. Then why we doing this every time? – Alex Trounev Sep 24 '20 at 12:07
  • @AlexTrounev, This could only be done for functions with Attribute HoldFirst or HoldAll. NDSolve and NDEigensystem are not. – user21 Sep 24 '20 at 12:30
  • @user21 What do you mean? Can we use some automatic option to convert any equation in a form suitable for FEM? It looks like unsolved problem in Wolfram language. :) – Alex Trounev Sep 24 '20 at 14:46
  • @AlexTrounev, NDSolve[Laplancian[u[x],{x}],...] can not automatically be converted to NDSolve[Inactive[Laplacian][u[x],{x}],...] – user21 Sep 24 '20 at 15:20
  • @user21 Ok! I see your point. Thank you! – Alex Trounev Sep 24 '20 at 16:00
  • @AlexTrounev, I have used the content of this conversation to make another example to further explain the need of Inactive. – user21 Sep 25 '20 at 06:34