5
$\begingroup$

I solve a Dirichlet problem on a parallelepiped in 3D

p = Parallelepiped[{0, 0, 0}, {{1, 0, 0}, {1, 1, 0}, {0, 1, 1}}];
sol = NDSolve[{Laplacian[u[x, y, z], {x, y, z}] == 0, 
DirichletCondition[u[x, y, z] == x^4 + y^2 + z, True]}, u[x, y, z], {x, y, z} \[Element] p]

{{u[x,y,z]->InterpolatingFunction[Domain: {{0.,2.},{0.,2.},{0.,1.}} Output: scalar][x,y,z]}}

I'd like to vizualize that solution. Following the documentation (see the Applications section), I try

DensityPlot3D[ u[x, y, z] /. sol, {x, 0, 2}, {y, 0, 2}, {z, 0, 1}]

The above command works, but produces an empty plot without any error messages. My next attempt is

Clear[x,y,z,u];DensityPlot3D[Evaluate[u[x, y, z] /. sol], {x, 0, 2}, {y, 0, 2}, {z, 0, 1}]

enter image description here

with an unsatisfactory result as well as

Clear[x,y,z,u];DensityPlot3D[Evaluate[u[x, y, z] /. sol], {x, 0, 2}, {y, 0, 2}, {z, 0, 1}, 
 PlotPoints -> 20, WorkingPrecision -> 12]

enter image description here

The slices of sol are plotted well, for example,

Plot3D[(u[x, y, z] /. sol) /. z -> 0.2, {x, 0, 2}, {y, 0, 2}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Clear[x, y, z, u]; sol1 = NDSolveValue[{Laplacian[u[x, y, z], {x, y, z}] == 0, DirichletCondition[u[x, y, z] == x^4 + y^2 + z, True]}, u[x, y, z], {x, y, z} \[Element] p];DensityPlot3D[u[x, y,z] /. sol1, {x, 0, 2}, {y, 0, 2}, {z, 0, 1}] also produces an empty plot. $\endgroup$
    – user64494
    Mar 3, 2021 at 15:51
  • 1
    $\begingroup$ this is because you should use NDSolve here if you want to use it a as rule. $\endgroup$
    – chris
    Mar 4, 2021 at 7:10

1 Answer 1

2
$\begingroup$

This seems to work?

Clear[x, y, z, u,p,U];
p = Parallelepiped[{0, 0, 0}, {{1, 0, 0}, {1, 1, 0}, {0, 1, 1}}];
U = NDSolveValue[{Laplacian[u[x, y, z], {x, y, z}] == 0, 
    DirichletCondition[u[x, y, z] == x^4 + y^2 + z, True]}, 
   u, {x, y, z} \[Element] p];

Then

U[x, y, z] // Evaluate, {x, y, 
  z} \[Element] p, Contours -> 5, MeshFunctions -> (Norm[{#1, #2, \
#3}] &)]

enter image description here


Update

As requested by OP, you can find the range of values via:

   NMaximize[U[x, y, z], {x, y, z} \[Element] p] // Quiet

{12.713,{x->1.80957,y->1.28142,z->0.30654}}

   NMinimize[U[x, y, z], {x, y, z} \[Element] p] // Quiet

{1.07235,{x->0.996752,y->0.101257,z->0.0664789}}

So that

  ContourPlot3D[U[x, y, z] // Evaluate, {x, y, z} \[Element] p, 
 Contours -> (val = {1,2,5}), 
 MeshFunctions -> (Norm[{#1, #2, #3}] &), 
 ContourStyle -> ColorData["Heat"] /@ (Range[5]/5.), 
 PlotLegends -> val]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you. You first plot is a duplication of my first plot. Which surfaces are drawn in your second plot? Can you demonstrate more such surfaces? The behavior of the solution near the origin is not clear to me. Unfortunately, I cannot accept your answer in its present form. $\endgroup$
    – user64494
    Mar 4, 2021 at 7:13
  • $\begingroup$ +1. However, there are still deficiences: some surfaces are partly out of p and the levels of U are not known. $\endgroup$
    – user64494
    Mar 4, 2021 at 7:32
  • $\begingroup$ ContourPlot3D[U[x, y, z] // Evaluate, {x, y, z} \[Element] p, Contours -> {1, 2, 5}] suits better to me. I'll be wating some time for other answers (maybe, through ListDensityPlot3D). $\endgroup$
    – user64494
    Mar 4, 2021 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.