1
$\begingroup$

I am trying to check if mass conservation holds by integrating the area under a curve but to no avail.

Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"]; 
Needs["VectorAnalysis`"]

Clear[Eq0, EvapThickFilm, h, Bo, ϵ, K1, δ, Bi, m, r]
Eq0[h_, {Bo_, ϵ_, K1_, δ_, Bi_, m_, r_}] :=
  D[h, t] + Div[(-h^3)*Bo*Grad[h] + h^3*Grad[Laplacian[h]] + ((δ*h^3)/(Bi*h + K1)^3)*Grad[h]
  + m*(h/(K1 + Bi*h))^2*Grad[h]] + ϵ/(Bi*h + K1) + r*D[D[h^2/(K1 + Bi*h), x]*h^3, x] == 0;

L = 2*92.389; 
TMax = 2491.29*100; 
Off[NDSolve::mxsst]; 
hSol[x_, y_, t_] = h[x, y, t] /. 
   NDSolve[{EvapThickFilm[0.003, 0, 1, 0, 1, 0.025, 0], 
      h[0, y, t] == h[L, y, t], h[x, 0, t] == h[x, L, t], 
      h[x, y, 0] == 1 + (-0.25*Cos[2*Pi*(x/L)] - 0.25*Sin[2*Pi*(x/L)])*
         Cos[2*Pi*(y/L)]}, h, {x, 0, L}, {y, 0, L}, {t, 0, TMax}, 
     MaxStepFraction -> 1/60][[1]]

When I use NIntegrate[...] to integrate under the area of the curve for a single value of TMax, I don't get a single valued number. In fact, my variables are reset! What gives?

NIntegrate[hSol[x, y, 0.1*TMax], {x, 0, L}, {y, 0, L}]

I've tried it with simpler 2D cases instead of 3D and this works fine.

FOOTNOTE: Is there some way I could host this code elsewhere? Any websites that support mathematica code format?

EDIT 1:

The error that NIntegrate[..] gives me is that x = L is not a valid limit of integration. whilst L has actually been defined in the problem previously.

$\endgroup$
10
  • 1
    $\begingroup$ Please don't post your entire assignment/project and ask us to debug. It's not easy to do, especially when we don't know the background to your problem. It might be better if you can reduce the issue to a small, readable code snippet and people can think over it and give you a solution over a coffee break :) $\endgroup$
    – rm -rf
    Mar 28, 2012 at 17:56
  • $\begingroup$ @R.M Yes, I realize that. I don't know where else I could post the code itself so as to focus on the problem that the code is stricken by here! :( $\endgroup$
    – dearN
    Mar 28, 2012 at 17:58
  • $\begingroup$ Also, code in box form, e.g. with SubscriptBox, etc, is extremely difficult to read. Can you convert it to InputForm and repost? To do so, select the cell, right click (ctrl-click on mac), and Convert To -> InputForm. $\endgroup$
    – rcollyer
    Mar 28, 2012 at 17:59
  • $\begingroup$ @rcollyer did that. Still is an ugly mass of text. Boy mathematica sure can be an ugly environment. Anyway... $\endgroup$
    – dearN
    Mar 28, 2012 at 18:02
  • $\begingroup$ Actually, that's readable now. $\endgroup$
    – rcollyer
    Mar 28, 2012 at 18:10

1 Answer 1

6
$\begingroup$

Some of the symbols you're using depend on the VectorAnalysis package. So, be sure to execute the following from a fresh kernel.

Needs["VectorAnalysis`"]

Also, be sure to define your hSol function for only numeric values.

hSol[x_?NumericQ,y_?NumericQ,t_?NumericQ] := ...
$\endgroup$
1
  • $\begingroup$ This is the answer. However, I couldn't ever have known of the _?NumericQ thingy! I'll have to look it up. Aah, the trials and tribulations of being a paper and pencil engineer! $\endgroup$
    – dearN
    Mar 28, 2012 at 18:33

Your Answer

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

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