1
$\begingroup$

I am trying to figure out how to do a convective derivative in Mathematica in the context of the Navier-Stokes equation. The issue is, I have no clue how dot product a vector with the gradient operator. The below syntax doesn't work. Can anyone provide advice? The specific part of the Navier-Stokes equation I'm having trouble with is the term labeled "acceleration" in the link above.

\[Rho] (D[u, t] + Dot[u, \[Del]]*u)
$\endgroup$

1 Answer 1

3
$\begingroup$

Instead of the Del symbol (which has no built-in meaning) you need the gradient operator. What you're looking for can be achieved by using Map to apply the dot product of $\vec{u}$ and Grad to each row of the vector. I define this as the convective derivative dConvect and apply it to a test vector uVec:

uVec = Through[{Subscript[u, \[ScriptX]], Subscript[u, \[ScriptY]], 
     Subscript[u, \[ScriptZ]]}[x, y, z, t]];
dConvect[vec_] := D[vec, t] + ((vec.Grad[#, {x, y, z}]) & /@ vec)
dConvect[uVec] // MatrixForm // TraditionalForm

The output is a little ugly, so I'll add some better formatting before displaying the result:

Derivative /:MakeBoxes[Derivative[\[Alpha]__][f1_][vars__?AtomQ], 
  TraditionalForm] := 
 Module[{bb, dd, sp}, 
  MakeBoxes[dd, _] ^= 
   If[Length[{\[Alpha]}] == 1, "\[DifferentialD]", "\[PartialD]"];
  MakeBoxes[sp, _] ^= "\[ThinSpace]";
  bb /: MakeBoxes[bb[x__], _] := RowBox[Map[ToBoxes[#] &, {x}]];
  TemplateBox[{ToBoxes[bb[dd^Plus[\[Alpha]], f1]], 
    ToBoxes[Apply[bb, 
      Riffle[Map[
        bb[dd, #] &, (Pick[{vars}, #]^Pick[{\[Alpha]}, #] &[
          Thread[{\[Alpha]} > 0]])], sp]]], 
    ToBoxes[Derivative[\[Alpha]][f1][vars]]}, "ShortFraction", 
   DisplayFunction :> (FractionBox[#1, #2] &), 
   InterpretationFunction :> (#3 &), Tooltip -> Automatic]]

Format[Subscript[u, s_][x, y, z, t]] := Subscript[u, s];

dConvect[uVec] // MatrixForm // TraditionalForm

vec

The formatting uses this answer.

$\endgroup$
1
  • $\begingroup$ Not sure if I am supposed to do this - but dConvect won't find all the terms if I try it in Spherical Coordinates. I wonder how you'd do this? $\endgroup$ Commented Feb 3, 2021 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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