Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. << NDSolve`FEM`
  2. bm = ToBoundaryMesh[
  3. "Coordinates" -> {{0., 0.}, {1., 0.}, {2., 0.}, {2., 1.}, {1.,
  4. 1.}, {0., 1.}},
  5. "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4,
  6. 5}, {5, 6}, {6, 1}, {5, 2}}]}];
  7. em = ToElementMesh[bm,
  8. "RegionMarker" -> {{{0.5, 0.5}, 1}, {{1.5, 0.5}, 2}}];
  9.  
  10. Show[{
  11. em["Wireframe"["MeshElementStyle" -> Directive[EdgeForm[Red], Thin],
  12. "MeshElementMarkerStyle" -> Blue]],
  13. bm["Wireframe"["MeshElementStyle" -> Black]]
  14. }, ImageSize -> 300]
  15.  
  16. sigma = If[ElementMarker == 1, 1, 2];
  17. sl1 = NDSolveValue[{D[sigma*D[u[x, y], x], x] +
  18. D[sigma*D[u[x, y], y], y] == 0, DirichletCondition[u[x, y] == 0, x == 0],
  19. DirichletCondition[u[x, y] == 1, x == 2]}, u[x, y], {x, y} [Element] em]
  20.  
  21. Plot3D[sl1, {x, y} [Element] em, ColorFunction -> "Rainbow",
  22. PlotRange -> {0, 1}, ImageSize -> 300]
  23.  
  24. NIntegrate[
  25. Evaluate[sigma*(D[sl1, x]^2 + D[sl1, y]^2)], {x, y} [Element] em]
  26.  
  27. (* 0.667 *)
  28.  
  29. sigma*(D[sl1, x]^2 + D[sl1, y]^2) /. {x -> 0.5, y -> 0.5}
  30.  
  31. (* 0.444 If[ElementMarker == 1, 1, 2] *)
  32.  
  33. If[x < 1, 1, 2]*(D[sl1, x]^2 + D[sl1, y]^2) /. {x -> 0.5, y -> 0.5}
  34. (* 0.444 *)
  35.  
  36. sl2 = NDSolveValue[{D[sigma*D[u[x, y], x], x] +
  37. D[sigma*D[u[x, y], y], y] == 0, jx[x, y] == sigma*D[u[x, y], x],
  38. jy[x, y] == sigma*D[u[x, y], y],
  39. DirichletCondition[u[x, y] == 0, x == 0],
  40. DirichletCondition[u[x, y] == 1, x == 2]}, {u[x, y], jx[x, y],
  41. jy[x, y]}, {x, y} [Element] em]
  42.  
  43. Plot3D[sl2[[1]], {x, y} [Element] em, ColorFunction -> "Rainbow",
  44. PlotRange -> {0, 1}, ImageSize -> 300]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement