4
$\begingroup$
NDSolveValue[{-\!\(
\*SubsuperscriptBox[\(\[Del]\), \({x, y}\), \(2\)]\(u[x, y]\)\) == 
       NeumannValue[1., x == 5], 
     DirichletCondition[
    u[x, y] == 
     Piecewise[{{x, y == -1 || y == 1}, {x, x == 1 || x == -1}}], 
    True]}, u, {x, y} \[Element] 
    mesh];
Plot3D[%[x, y], {x, y} \[Element] mesh]

From the code above resulting in this plot: enter image description here

Where as my mesh looks like this: enter image description here

What I expected from the plot is that by setting the Neumann value to 1 on the edges, I would get an inclined plane (with a square hole). I suspect the Dirichlet condition is overriding and setting 0 everywhere on the boundary.

$\endgroup$

1 Answer 1

7
$\begingroup$

The wrong part of your code is :

DirichletCondition[
u[x, y] == Piecewise[{{x, y==-1 || y==1}, {x, x==1 || x==-1}}]
,True]  

which should be something like :

DirichletCondition[
u[x, y] == x
, (-1.1 < x < 1.1) && (-1.1 < y < 1.1)]   

The first argument of DirichletCondition specifies the value at the boundary. The second argument specifies where to apply the value. In fact it suffices to give a domain that contains the related boundary (and not the others boundaries).

By the way I have cleaned your code so that it becomes friendly in the StackExchange context :

<< NDSolve`FEM`
region1 = Rectangle[{-5, -5}, {5, 5}];
region2 = Rectangle[{-1, -1}, {1, 1}];
region = RegionDifference[region1, region2];
(*RegionPlot[region,ImageSize\[Rule]200]*)

mesh = ToElementMesh[region, "MaxBoundaryCellMeasure" -> 0.05];
(*Show[mesh["Wireframe"] ,ImageSize\[Rule]200]*)  

NDSolveValue[{-Laplacian[u[x, y], {x, y}] == NeumannValue[1., x == 5], 
        DirichletCondition[
    u[x, y] == x, (-1.1 < x < 1.1) && (-1.1 < y < 1.1)]}
  , u
  , Element[{x, y}, mesh]];
Plot3D[%[x, y], Element[{x, y}, mesh]]  

enter image description here

$\endgroup$

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.