11
$\begingroup$

I'm plotting the stream lines of fluid flow past a cylinder, and I would like the colors to increase with contour curvature (i.e. increase as the velocity of the flow increases. Here's a MWE that seems to color it based on the the y-axis value:

ψ[r_, θ_] := U (r - a^2/r) Sin[θ]
r = Sqrt[x^2 + y^2];
θ = ArcSin[y/r];

stream = ContourPlot[
            ψ[r, θ] /. {U -> 10, a -> 1}, 
            {x, -5,5}, {y, -5, 5}, 
            Contours -> 10 Table[i, {i, -10, 10, 0.025}]
         ];

cyl = Graphics[Disk[{0, 0}, 1]];

Show[stream, cyl]

stream lines around a cylinder

$\endgroup$
14
$\begingroup$
f = {ψ[r, θ]} /. {U -> 10, a -> 1};
gradf = D[f, {{x, y}, 1}];
Hessf = D[f, {{x, y}, 2}];
normal = gradf[[1]]/Sqrt[gradf[[1]].gradf[[1]]] // Simplify;
secondfundamentalform = -PseudoInverse[gradf].Hessf // ComplexExpand // Simplify;
tangent = RotationMatrix[Pi/2].normal;
curvaturevector = (secondfundamentalform.tangent).tangent // Simplify;
signedcurvature = curvaturevector.normal // Simplify;

stream = ContourPlot[
   ψ[r, θ] /. {U -> 10, a -> 1}, {x, -5, 5}, {y, -5, 5},
   Contours -> 10 Table[i, {i, -10, 10, 0.2}],
   ContourShading -> None
   ];
curvatureplot = DensityPlot[signedcurvature, {x, -5, 5}, {y, -5, 5},
   ColorFunction -> "RedGreenSplit",
   ClippingStyle -> Automatic,
   PlotPoints -> 100,
   PlotRange -> {-1, 1}
   ];
Show[
 curvatureplot,
 stream,
 cyl
 ]

enter image description here

$\endgroup$

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.