Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- << NDSolve`FEM`
- bm = ToBoundaryMesh[
- "Coordinates" -> {{0., 0.}, {1., 0.}, {2., 0.}, {2., 1.}, {1.,
- 1.}, {0., 1.}},
- "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4,
- 5}, {5, 6}, {6, 1}, {5, 2}}]}];
- em = ToElementMesh[bm,
- "RegionMarker" -> {{{0.5, 0.5}, 1}, {{1.5, 0.5}, 2}}];
- Show[{
- em["Wireframe"["MeshElementStyle" -> Directive[EdgeForm[Red], Thin],
- "MeshElementMarkerStyle" -> Blue]],
- bm["Wireframe"["MeshElementStyle" -> Black]]
- }, ImageSize -> 300]
- sigma = If[ElementMarker == 1, 1, 2];
- sl1 = NDSolveValue[{D[sigma*D[u[x, y], x], x] +
- D[sigma*D[u[x, y], y], y] == 0, DirichletCondition[u[x, y] == 0, x == 0],
- DirichletCondition[u[x, y] == 1, x == 2]}, u[x, y], {x, y} [Element] em]
- Plot3D[sl1, {x, y} [Element] em, ColorFunction -> "Rainbow",
- PlotRange -> {0, 1}, ImageSize -> 300]
- NIntegrate[
- Evaluate[sigma*(D[sl1, x]^2 + D[sl1, y]^2)], {x, y} [Element] em]
- (* 0.667 *)
- sigma*(D[sl1, x]^2 + D[sl1, y]^2) /. {x -> 0.5, y -> 0.5}
- (* 0.444 If[ElementMarker == 1, 1, 2] *)
- If[x < 1, 1, 2]*(D[sl1, x]^2 + D[sl1, y]^2) /. {x -> 0.5, y -> 0.5}
- (* 0.444 *)
- sl2 = NDSolveValue[{D[sigma*D[u[x, y], x], x] +
- D[sigma*D[u[x, y], y], y] == 0, jx[x, y] == sigma*D[u[x, y], x],
- jy[x, y] == sigma*D[u[x, y], y],
- DirichletCondition[u[x, y] == 0, x == 0],
- DirichletCondition[u[x, y] == 1, x == 2]}, {u[x, y], jx[x, y],
- jy[x, y]}, {x, y} [Element] em]
- Plot3D[sl2[[1]], {x, y} [Element] em, ColorFunction -> "Rainbow",
- PlotRange -> {0, 1}, ImageSize -> 300]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement