Advertisement
Guest User

Projective phase portrait

a guest
Jan 7th, 2019
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. Clear[x, y, z, t]
  2.  
  3. vf2ode[vf_, vars_List] :=(* vector field to ode *)
  4. D[Through[vars@t], t] == (vf /. Thread[vars -> Through[vars@t]]);
  5.  
  6. vectorfield = D[x^3 + y^3 - 6 x y z, {{x, y, z}}]
  7.  
  8. (* cross section: orthogonal trajectory of stream lines *)
  9. xsects = Table[
  10. NDSolveValue[{
  11. Most /@ vf2ode[Cross[vectorfield, {x, y, z}], {x, y, z}],
  12. D[#.# &@Through[{x, y, z}[t]], t] == 0,
  13. Through[{x, y, z}[0]] == p,
  14. WhenEvent[x[t] == 10^-8, "StopIntegration"],
  15. WhenEvent[y[t] == 10^-8, "StopIntegration"],
  16. s[0] == 0, s'[t] == Norm@D[Through[{x, y, z}[t]], t]},
  17. Through[{x, y, z, s}[t]],
  18. {t, -4.7, 4.6}, WorkingPrecision -> 32],
  19. {p,(*Normalize/@*){(*{10.^-3,0,1},{-10.^-3,0,1},*)
  20. {0.6882472016116790823335886688654122506559492649690596732314`32.5,
  21. 0.6882472016116790823335886688654122506559492649690596732314`32.5,
  22. 0.2294157338705990582354499674677542627510776019718367978717`32.5}}}];
  23.  
  24. ClearAll[rangeSubdivide];
  25. rangeSubdivide[f_InterpolatingFunction | (f_InterpolatingFunction)[_],
  26. n_Integer] := Module[{tI, tF, fI, fF, t},
  27. {{tI, tF}} = f["Domain"];
  28. fI = f@tI; fF = f@tF;
  29. t /. FindRoot[
  30. f[t] == SetPrecision[Subdivide[fI, fF, n], Precision@f], {t,
  31. Subdivide[tI, tF, n], ConstantArray[tI, n + 1],
  32. ConstantArray[tF, n + 1]}, WorkingPrecision -> Precision@f]
  33. ];
  34.  
  35. {state} = NDSolve`ProcessEquations[{
  36. Most /@ vf2ode[vectorfield, {x, y, z}],
  37. D[#.# &@Through[{x, y, z}[t]], t] == 0,
  38. Through[{x, y, z}[0]] == Normalize[{1, 2, 3}] // Thread,
  39. WhenEvent[z[t] < 10^-8, "StopIntegration"],
  40. WhenEvent[Evaluate[#.# &@D[Through[{x, y, z}[t]], t] < 10^-4],
  41. "StopIntegration"]},
  42. {x, y, z},
  43. {t, -3, 3},
  44. WorkingPrecision -> 32,
  45. "ExtrapolationHandler" -> {Indeterminate &,
  46. "WarningMessage" -> False}];
  47. rhs = state@"NumericalFunction";
  48.  
  49. ClearAll[iterate, iterate`interval];
  50.  
  51. iterate[refl_Integer: - 1] := iterate[iterate`interval, refl];
  52. iterate[int_List, refl_Integer: - 1][sols_?MatrixQ] :=
  53. iterate[int, refl] /@ sols;
  54. iterate[int_List, refl_Integer: - 1][
  55. sol : {HoldPattern[InterpolatingFunction[___][t_]] ..}] :=
  56. iterate[int][
  57. SetPrecision[(sol /. t -> "ValuesOnGrid")[[All, -1]], 32]];
  58. iterate[int_List, refl_Integer: - 1][
  59. p : {_?NumericQ, _?NumericQ, _?NumericQ}] := Module[{newstate},
  60. {newstate} =
  61. NDSolve`Reinitialize[
  62. state, {Through[{x, y, z}[0]] == p {refl, refl, 1} // Thread}];
  63. NDSolve`Iterate[newstate, int];
  64. {x[t], y[t], z[t]} /. NDSolve`ProcessSolutions[newstate]
  65. ];
  66. iterate`interval = {0, 2};
  67.  
  68. ndsep = Join @@ NestList[
  69. iterate[]@Take[#, -3] &,
  70. iterate[{-3, 3}, 1][
  71. Normalize /@ {{-1, -1, 1}, {1, 1, 1}, {3, 3,
  72. 1}, {0, 0, 1} + {-1, 1, 0}/10^6, {0, 0, 1} - {-1, 1, 0}/
  73. 10^6}],
  74. 1]; // AbsoluteTiming
  75. ndsep2 = {};
  76.  
  77. (* ICs along xsects *)
  78. nlines = 10;
  79. ndsol0 = Join @@ NestList[
  80. iterate[],
  81. ndsol1 = iterate[{-2, 2}, 1][
  82. SetPrecision[
  83. Normalize /@
  84. Transpose[
  85. xsects[[1, ;; 3]] /.
  86. t -> Drop[
  87. rangeSubdivide[xsects[[1, 4]], 2 nlines + 2][[
  88. 2 ;; -2]], {nlines + 1}]],
  89. 32]
  90. ],
  91. 3
  92. ]; // AbsoluteTiming
  93. ndsol2 = ndsol3 = ndsol4 = {};
  94.  
  95. cp = Normalize /@ ({x, y, z} /.
  96. Solve[{Most@D[x^3 + y^3 - 6 x y z, {{x, y, z}}] == 0,
  97. x^2 + y^2 + z^2 == 1}, {x, y, z}, Reals])
  98.  
  99. paths = Show@Table[
  100. Check[
  101. foo = ParametricPlot3D[sol[[k]],
  102. Evaluate@Flatten@{t, sol[[k, 1]] /. t -> "Domain"},
  103. PlotStyle -> Directive[Hue[k/Length@sol], Tube[0.01]],
  104. PlotRange -> All(*,WorkingPrecision\[Rule]32*)],
  105. Print[
  106. k -> Evaluate@Flatten@{t, Block[{t = "Domain"}, sol[[k, 1]]]}];
  107. foo],
  108. {sol, Partition[ndsol0, 2*nlines]},
  109. {k, Length@sol}]; // AbsoluteTiming
  110.  
  111. xpaths = Show[
  112. Table[
  113. ParametricPlot3D[Normalize@sol[[;; 3]],
  114. Evaluate@Flatten@{t, sol[[1]] /. t -> "Domain"},
  115. PlotStyle -> Directive[LightPink, Tube[0.015]],
  116. PlotRange -> All],
  117. {sol, Join[ndsep, ndsep2]}],
  118. Table[
  119. ParametricPlot3D[Normalize@sol[[;; 3]],
  120. Evaluate@Flatten@{t, sol[[1]] /. t -> "Domain"},
  121. PlotStyle -> Directive[Green, Tube[0.01]], PlotRange -> All],
  122. {sol, xsects; {}}]
  123. ]; // AbsoluteTiming
  124.  
  125. projpl = Show[
  126. Graphics3D[{
  127. {Opacity[0.5], Sphere[]},
  128. {Green, Sphere[#, 0.03] & /@ cp[[{2, 3}]],
  129. Red, Sphere[#, 0.03] & /@ cp[[{1, 4}]],
  130. Orange, Sphere[#, 0.03] & /@ ({{1, -1, 0}, {-1, 1, 0}}/Sqrt[2])},
  131. {Black, Tube[{{1, 1, 0}, {-1, -1, 0}}, 0.008],
  132. Tube[{{-1, 1, 0}, {1, -1, 0}}, 0.008],
  133. Tube[{{0, 0, -1}, {0, 0, 1}}, 0.008]}
  134. }],
  135. paths,
  136. paths /. GraphicsComplex[p_, r___] :> GraphicsComplex[-p, r],
  137. xpaths,
  138. xpaths /. GraphicsComplex[p_, r___] :> GraphicsComplex[-p, r],
  139. Axes -> True, AxesLabel -> {x, y, z}
  140. ];
  141.  
  142. GraphicsRow[
  143. {Show[projpl, ViewPoint -> {0, 0, Infinity}, ImagePadding -> 28],
  144. Show[projpl,
  145. ViewPoint -> {3.0161462828375654`, -0.5317690764169934`,
  146. 1.4387783880402685`}]}, ImageSize -> Large]
  147.  
  148. StreamDensityPlot[{{3 x^2 - 6 y, 3 y^2 - 6 x},
  149. x^3 + y^3 - 6 x y}, {x, -100, 100}, {y, -100, 100},
  150. StreamPoints -> {{{{10, 10}, Red}, {{-10, -10}, Green}, {{5, -2},
  151. Green}, {{-2, 5}, Green}, Automatic}},
  152. Epilog -> {Red, PointSize[0.03], Point[{2, 2}], Green,
  153. Point[{0, 0}]}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement