2
$\begingroup$

Okay this is a very newbie question. I have coded a sample problem that solves the heat diffusion equation on an annulus. Here's what I have:

Dom = ImplicitRegion[x^2 + y^2 >= 1 && x^2 + y^2 <= 5, {x, y}];
C = {DirichletCondition[u[x, y] == 200., x^2 + y^2 == 1], DirichletCondition[u[x, y] == 0., x^2 + y^2 == 5]};

result = NDSolveValue[{\!\(\*SubsuperscriptBox[\(\[Del]\), \({x, y}\), \(2\)]\(u[x, y]\)\) ==  0, C}, u, {x, y} \[Element] Dom];

I can plot the data as a contour plot. All that is good. Now, say I want to get the mean of the temperature. How I do that? I imagine the data is contained in the variable 'result', but it is very opaque to me.

$\endgroup$
2
$\begingroup$

You can use NIntegrate to do that, like this

NIntegrate[result[x, y], {x, y} \[Element] Dom]/
  NIntegrate[1, {x, y} \[Element] Dom] // Chop // AbsoluteTiming
(*74.23246590163654`*)

Chop is nessary because the result contains a very small imaginary part

enter image description here

I'm sorry for that I don't know why these warnings occurs, but it seems harmless.

There is another way which can avoid the warnings but give a result with larger error and spend more time

dom = DiscretizeRegion[Dom, AccuracyGoal -> 2];
NIntegrate[result[x, y], {x, y} \[Element] dom]/
 NIntegrate[1, {x, y} \[Element] dom]
(*74.8653680261704`*)

Chose larger AccuaryGoal can improve the accuary of the result, but costs more time

enter image description here

$\endgroup$
3
$\begingroup$
Dom = ImplicitRegion[
   x^2 + y^2 >= 1 && x^2 + y^2 <= 5, {x, y}];

c = {
   DirichletCondition[u[x, y] == 200, x^2 + y^2 == 1], 
   DirichletCondition[u[x, y] == 0, x^2 + y^2 == 5]};

result = NDSolveValue[{\!\(
\*SubsuperscriptBox[\(\[Del]\), \({x, y}\), \(2\)]\(u[x, y]\)\) ==  0, c}, 
   u, {x, y} \[Element] Dom];

GraphicsRow[{
  ContourPlot[result[x, y],
   {x, -Sqrt[5], Sqrt[5]},
   {y, -Sqrt[5 - x^2], Sqrt[5 - x^2]},
   PlotPoints -> 75,
   Contours -> Range[0, 200, 25],
   ColorFunction -> "Temperature",
   RegionFunction ->
    Function[{x, y, z}, Dom[[1]]]],
  Plot3D[result[x, y],
   {x, -Sqrt[5], Sqrt[5]},
   {y, -Sqrt[5 - x^2], Sqrt[5 - x^2]},
   PlotPoints -> 50,
   ColorFunction -> "Temperature",
   RegionFunction ->
    Function[{x, y, z}, Dom[[1]]]]},
 ImageSize -> 500]

enter image description here

The area is given by RegionMeasure[Dom]

avg = NIntegrate[result[x, y], {x, y} \[Element] Dom]/
   RegionMeasure[Dom] // Quiet

74.2325

$\endgroup$

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.