tl;dr: want to integrate (average) the dependent variable within NDSolve.
I am currently trying to implement a basic diffusion-advection equation for a reactant, A. The species is converted between A and B, and the total amount is conserved. I am attempting to smooth local non-uniformities in B, which should always be uniformly distributed. My attempt is below, and includes a mathematically usual normalisation integral (see line (*****)). However, mathematica appears to 'ignore' this normalisation.
I know NDSolve builds interpolating functions, and initially assumed that at each iteration I would be able to average over the available interpolating data. However, I've tried reading further on the methods NDSolve uses and have concluded that NDSolve leaves the integral as symbolic, until at least the very end where the function is evaluated. I have also tried forcing a numerical integration by replacing the Integrate[] with a user defined NIntegrate function outside NDSolve (see commented out, line 4).
Is my reasoning correct? If so, is it possible to implement an average of this kind within NDSolve, as it is solving? And if not, is there either a solver that will do this, or a way to circumvent the difficulties whilst still using NDSolve (such as manually access the interpolation data and average it)? With regards to the latter I know you can access the interpolation data of the full solution.
total = 200;
L = 10;
(*fn[lm_]:=NIntegrate[lm,{x,-L/2,L/2}]*)
soln = NDSolve[{
D[A[x,t],{t,1}]== Plus[
0.005 D[A[x,t],{x,2}],
D[0.1 Exp[-0.5(x-0.5)^2] A[x,t],{x,1}],
0.1 B[x,t]-0.2 A[x,t]
],
B[x, t]==(total - Integrate[A[x,t], {x,-L/2,L/2}])/L (*****),
A[x,0] == 10,
B[x,0] == (total - Integrate[A[x,0], {x,-L/2,L/2}])/L,
A[-L/2,t] == A[L/2,t],
B[-L/2,t] == B[L/2,t]}, {A,B}, {x,-L/2,L/2}, {t,0,100}]
NIntegrate[Evaluate[(B[x, t]) /. soln /. t -> 0], {x, -5, 5}]
NIntegrate[Evaluate[(A[x, t]) /. soln /. t -> 0], {x, -5, 5}]
Table[Plot[Evaluate[A[x,t]/.soln/.t ->(i*100/10)], {x,-5,5},
AxesLabel->{"x", "t= " <> ToString[i*10]}], {i, 0, 10}]
Table[Plot[Evaluate[B[x, t] /. soln /. t -> (i*100/10)], {x, -5, 5},
AxesLabel -> {"x", "t= " <> ToString[i*10]}], {i, 0, 10}]
Desirable output: Though both plots make sense and uphold conservancy, if the average I wanted to implement was upheld, I would expect the B[x,t] plots (second down) to be constant along x, but with different values for different t.
Any kind of solution welcome, even if in the form of a known 'not possible'. Thanks.