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)

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]], 
        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


The formatting uses this answer.


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.