Guest User

Untitled

a guest
Oct 25th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. Needs["NDSolve`FEM`"]
  2.  
  3. (*constants*)
  4. ballRadiusSquared = 0.5;
  5. rmax = 10.;
  6. zmin = 0.;
  7. zinit = 4.;
  8. pa = 1.;
  9. g = 9.8;
  10. rho = 1.;
  11. tmax = 0.2;
  12.  
  13. (*time dependent variable*)
  14. zBallCentre[t_] := -0.5*g*t^2 + zinit + Sqrt[ballRadiusSquared];
  15.  
  16. (*define region coordinates*)
  17. n = 1000;
  18. (*circle coordinates*)
  19. circTbl = Table[{Sqrt[ballRadiusSquared]*Cos[t], Sqrt[ballRadiusSquared]*Sin[t]}, {t, -Pi/2, Pi/2 - 2 Pi/(2 n), 2 Pi/(2 n)}];
  20. Do[circTbl = ReplacePart[circTbl, {{i, 2}} -> circTbl[[i, 2]] + zBallCentre[0.7]], {i, Length[circTbl]}];
  21. Do[If[circTbl[[i, 2]] > zinit, circTbl = Delete[circTbl, i], circTbl = circTbl], {i, Length[circTbl], 1, -1}];
  22.  
  23. (*surface coorinates*)
  24. surfaceTbl = Table[{x, zinit}, {x, 0., rmax, 1/n}];
  25. If[Length[circTbl] == n, surfaceTbl = surfaceTbl,
  26. Do[If[circTbl[[Length[circTbl], 1]] > surfaceTbl[[1, 1]],surfaceTbl = Delete[surfaceTbl, 1],surfaceTbl = surfaceTbl],
  27. {i, 1, n}]];
  28.  
  29. (*put everything together*)
  30. coordTbl = Join[circTbl, surfaceTbl];
  31. coordTbl = Prepend[coordTbl, {0., zmin}];
  32. coordTbl = Append[coordTbl, {rmax, zmin}];
  33. lineTbl = Partition[Range[Length[coordTbl]], 2, 1];
  34. lineTbl = Prepend[lineTbl, {Length[coordTbl], 1}];
  35.  
  36. (*mesh the region where de PDE will be solved*)
  37. bmesh = ToBoundaryMesh["Coordinates" -> coordTbl, "BoundaryElements" -> {LineElement[lineTbl]}];
  38. mesh = ToElementMesh[bmesh, MaxCellMeasure -> 0.1];
  39. mesh["Wireframe"]
  40.  
  41. DirCond = DirichletCondition[[Phi][r, z] == 0., r == rmax];
  42. NeumCond = NeumannValue[0., r == 0] + NeumannValue[0., r == rmax] + NeumannValue[0., z == zmin];
  43.  
  44. solution = NDSolveValue[{D[r*D[[Phi][r, z], r], r]/r + D[[Phi][r, z], {z, 2}] == NeumCond, DirCond}, [Phi], {r, z} [Element] mesh, "ExtrapolationHandler" -> {Automatic, "WarningMessage" -> False}]
Add Comment
Please, Sign In to add comment