3
$\begingroup$

In a simple pde-problem, which I solve in a predefined mesh using NDSolveValue I would like to plot the result in the mesh NDSolve uses:

<< NDSolve`FEM`
netz = ToElementMesh[Rectangle[], "MeshElementType" -> TriangleElement, MaxCellMeasure -> {"Length" -> .1}]

u = NDSolveValue[{Laplacian[\[Psi][x, y], {x, y}] ==1 + \[Psi][x, y] + NeumannValue[0, x == 1] ,\[Psi][0, y] == 0, \[Psi][x, 0] == 0, \[Psi][x, 1] == 0}, \[Psi] ,Element[{x, y}, netz], Method -> "FiniteElement"] 

If I plot the result u[x,y]

Plot3D[u[x, y], {x, 0, 1}, {y, 0, 1}, Mesh -> All]

Vierecknetz I get a foursided mesh even though the solution mesh

u["ElementMesh"]["Wireframe"]

is triangular. How can I force Plot3D to show the right mesh?

$\endgroup$
  • 1
    $\begingroup$ A good point. This is easy to make with the ContourPlot such as Show[{ContourPlot[u[x, y], {x, 0, 1}, {y, 0, 1}], netz["Wireframe"] }] but this is not what you are asking about. $\endgroup$ – Alexei Boulbitch Dec 15 '17 at 14:53
  • $\begingroup$ @Alexei Boulbitch: Thanks, something like Plot3D[u[x, y] , Element[{x, y}, netz]] would help $\endgroup$ – Ulrich Neumann Dec 15 '17 at 16:20
6
$\begingroup$

You can use:

Plot3D[u[x, y], {x, y} \[Element] u["ElementMesh"], Mesh -> All, 
 MaxRecursion -> 0]

enter image description here

In version 11.0 there was a bug that you can work around with something like:

Plot3D[u[x, y], {x, y} \[Element] 
  MeshRegion[u["ElementMesh"]]["MakeLinear"], Mesh -> All, 
 MaxRecursion -> 0]
$\endgroup$
  • $\begingroup$ Thank you, this is the answer I'm looking for. In Mathematica v11.0.1.0 I get the error Plot3D::idomdim: {x,y}\[Element]u[ElementMesh] does not have a valid dimension as a plotting domain. Which is the version you use? $\endgroup$ – Ulrich Neumann Dec 28 '17 at 12:43
  • $\begingroup$ @UlrichNeumann, I am using 11.2 and I vaguely remember that there was such a bug. See if the edit helps you. $\endgroup$ – user21 Dec 28 '17 at 13:00
  • $\begingroup$ That's it, thank you! $\endgroup$ – Ulrich Neumann Dec 28 '17 at 13:18
1
$\begingroup$

Plot3D will resample points. If you want to maintain the mesh structure of netz, you could specify z-coords using u function. I specify "MeshOrder" -> 1 to get triangles:

<< NDSolve`FEM`
netz = ToElementMesh[Rectangle[], 
  "MeshElementType" -> TriangleElement, 
  MaxCellMeasure -> {"Length" -> .1}, "MeshOrder" -> 1]

u = NDSolveValue[{Laplacian[\[Psi][x, y], {x, y}] == 
    1 + \[Psi][x, y] + NeumannValue[0, x == 1], \[Psi][0, y] == 
    0, \[Psi][x, 0] == 0, \[Psi][x, 1] == 0}, \[Psi], 
  Element[{x, y}, netz], Method -> "FiniteElement"]

triangles = u["ElementMesh"]["MeshElements"][[1, 1]];
coords = u["ElementMesh"]["Coordinates"];

Graphics3D[
 GraphicsComplex[{##, u[##]} & @@@ 
   coords, {EdgeForm[{GrayLevel[0.2]}], 
   Directive[Specularity[GrayLevel[1], 3], RGBColor[
    0.880722, 0.611041, 0.142051], 
    Lighting -> {{"Ambient", RGBColor[
       0.30100577, 0.22414668499999998`, 
        0.090484535]}, {"Directional", RGBColor[
       0.2642166, 0.18331229999999998`, 0.04261530000000001], 
       ImageScaled[{0, 2, 2}]}, {"Directional", RGBColor[
       0.2642166, 0.18331229999999998`, 0.04261530000000001], 
       ImageScaled[{2, 2, 2}]}, {"Directional", RGBColor[
       0.2642166, 0.18331229999999998`, 0.04261530000000001], 
       ImageScaled[{2, 0, 2}]}}], Polygon[triangles]}], 
 BoxRatios -> {1, 1, .4}]
$\endgroup$
  • $\begingroup$ Thank you for your answer. Trying to understand the look at the 3D-Plot shows a regular mesh structure with holes inside??? In triangles I would have expected some triples of knots , but I found sublists of length 6. $\endgroup$ – Ulrich Neumann Dec 15 '17 at 15:46
  • $\begingroup$ Now I got it! The holes disappear with Polygon[triangles[[All,{1,2,3}]] ] . But the solution obtained in this way is unfortunately only a workaround. What I'm looking for is the projection of the triangle mesh onto the surface u[x,y] $\endgroup$ – Ulrich Neumann Dec 15 '17 at 16:11
  • $\begingroup$ did you specify "MeshOrder" -> 1 in netz? $\endgroup$ – halmir Dec 15 '17 at 18:43
  • $\begingroup$ Not in my first attempt... $\endgroup$ – Ulrich Neumann Dec 16 '17 at 12:45

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.