I have a function that I want to max out at a certain value, say 1 for simplicity. There is a pump that will heat in a certain area, but once its reaches the cap, it no longer heats past this (as if it it were in thermal equilibrium). As it is just diffusion that occurs, no other point would therefore be able to go above this cap, but when I try to introduce it, either I can't specify a range of points for this cap to apply to, or I have tried to code it incorrectly.
I have based my code from Solve a one dimensional heat transfer problem with NDSolve which adds the time component of heating, but allows it to increase indefinitely. My code adds a Gaussian element rather than the referenced time based element, but I know this bit works. There are two ways I see to solve this, either turn off the "heating" at that point when the capped is reached or force a boundary condition where no point can go above this cap, therefore avoiding the heating issue. However, when trying to do this either way, my code doesn't seem to like it, any advice? My code is shown below, should you want to see what it currently looks like (without any cap in place). Any advice would be appreciated.
ModelGaussian = A*Exp[-((r - r01)^2/w^2)];(*Gaussian model*)
opts = (Method -> {"PDEDiscretization" -> {"MethodOfLines",
"SpatialDiscretization" -> {"FiniteElement",
"MeshOptions" -> {"MaxCellMeasure" -> 0.001},
"IntegrationOrder" -> 5}}});
rat = 1;(Scaling Ratio)
maxTime = 4;
SizeOfPump = 20;(How large an size the pump effects)
SizeOfModel = 3;(How many times larger the model is compared to pump)
MidInGauss = 0;(Where Gauss peak starts-0 is middle)
wInGauss = 20;(Width of Gaussian Peak ([Sigma]/Sqrt[2]))
AmpInGauss = 1;(Peak for Gauss)
(If within the pump span,add the Gaussian pump,else don't add anything)
g[x_, t_] =
If[Abs[x] <= SizeOfPump,
ModelGaussian /. {r -> x, r01 -> MidInGauss, w -> wInGauss,
A -> AmpInGauss}, 0];
s = NDSolve[{ratD[T[t, x], t] - D[D[T[t, x], x], x] == g[x, t],
T[0, x] == 0}, T, {t, 0, maxTime}, {x, 0, SizeOfModelSizeOfPump},
opts];
imgs = Plot[
Evaluate[
If[x > 0, T[#, x] /. s, T[#, -x] /. s]], {x, -SizeOfModel*
SizeOfPump, SizeOfModel*SizeOfPump}, PlotRange -> All] & /@
Subdivide[0, maxTime, 100];
ListAnimate@imgs
WhenEventdocumentation. – Tim Laska Jul 16 '21 at 02:13g[x_, t_] = If[Abs[x] <= SizeOfQD, OnOffMode[x]*ModelGaussian /. {r -> x, r01 -> MidInGauss, w -> wInGauss, A -> AmplInGauss }, 0];and` s = NDSolve[ {rat*D[T[t, x], t] - D[D[T[t, x], x], x] == g[x, t],
T[0, x] == 0, WhenEvent[T[t, x] >= 1 , OnOffMode[x] -> 0], WhenEvent[T[t, x] < 1 , OnOffMode[x] -> 1]}, T, {t, 0, maxTime}, {x, 0, SizeOfModel*SizeOfQD}, opts]`
However, it gives the warning OnOffMode won't directly set the state due to the LHS not being a list of state variables. Any advice?
– Xyive Jul 19 '21 at 09:29