Discussion:
Logistic ODE as a source term
Derek Park
2018-06-12 20:09:13 UTC
Permalink
Hello Fipy,


I've run into a problem in designing/implementing my model and was wondering what the best practice would be.


Currently, I am trying to model a 1D PDE that is a cell species, H, along a linear axis, x:


\begin{equation}\label{FiPyFinal}
\underbrace{\frac{\delta H}{\delta t}}_{Transient} + \underbrace{(v_A + C_\Phi \Phi \frac{\delta S}{\delta x})\frac{\delta H}{\delta x}}_{Convection} = \underbrace{D\frac{\delta^2 H}{\delta x^2}}_{Diffusion} + \underbrace{r_H C_A A H\Big(1 - \frac{\bar{H}}{K_H}\Big) - \delta_H H - \delta_D S H}_{Source}
\end{equation}


H is the cell species I am interested in modeling, but S and A are also CellVariables. Currently they are invariant, but this will probably change as the model develops.


Importantly, \bar{H} is the total population of H. \Phi is also a globally calculated feedback function.


My questions pertain to uncertainty in how to implement the Convection and Source terms.


For the source term:


I see in the FiPy docs that for source terms, "The dependence can only be included in a linear manner".


So does this imply that the correct way to implement this source term would be:


ImplicitSourceTerm(coeff = r_H * C_A * A * (1 - H_bar()/K_H) - delta_H - delta_D * S)


With H_bar() being a function:


# Set up the summing of HSCs
def H_bar():
return H.cellVolumeAverage * mesh.cellVolumes.sum()



Am I incorrect in manually computing H_bar() at every timestep and then using it as the source term coefficient?


Also, will there be any problems with A and S also being CellVariables in this coupled PDE system?


For the Convection term:


And as another question, for the convection term, is it appropriate to have it as:


ConvectionTerm(coeff = v_A + C_phi + Phi() + S.faceGrad)


As in the source term, will there be issues with having Phi() as a function which changes at every timestep?




Thank you,

Derek Park

---------------------------
Derek Park | D. Phil student, University of Oxford
Guyer, Jonathan E. Dr. (Fed)
2018-06-13 13:49:02 UTC
Permalink
Hello Derek -

Thanks for your question.
Post by Derek Park
ImplicitSourceTerm(coeff = r_H * C_A * A * (1 - H_bar()/K_H) - delta_H - delta_D * S)
Yes
Post by Derek Park
# Set up the summing of HSCs
return H.cellVolumeAverage * mesh.cellVolumes.sum()
Am I incorrect in manually computing H_bar() at every timestep and then using it as the source term coefficient?
There's no reason to write a function here. Just define

H_bar = H.cellVolumeAverage * mesh.cellVolumes.sum()

and then use

(1 - H_bar / K_H)

in your source. FiPy will take care of updating the value as needed.
Post by Derek Park
Also, will there be any problems with A and S also being CellVariables in this coupled PDE system?
No
Post by Derek Park
ConvectionTerm(coeff = v_A + C_phi + Phi() + S.faceGrad)
Do you mean

ConvectionTerm(coeff = v_A + C_phi * Phi() * S.faceGrad)

?

ConvectionTerm represents $\nabla\cdot(\vec{u} H)$, but your expression is just $\vec{u} \cdot \nabla H$. You're missing $H \nabla\cdot\vec{u}$. Specifically, you have a source

ImplicitSourceTerm(coeff=C_phi * Phi() * S.faceGrad.divergence, var=H)
Post by Derek Park
As in the source term, will there be issues with having Phi() as a function which changes at every timestep?
Shouldn't be, but it depends how you define it. Basically, the thing to remember is that the function Phi() will not be called at each time step. The return value of the function will be evaluated at each time step. If the return value depends on your solution variable, then it will update. If the return value depends on the *value* of the solution variable, then it will not update.

You're generally better off just writing a variable expression, e.g.,

Phi = H * A * S + ...

than defining a function.


- Jon

Loading...