# Modelling constant phase elements with ModellingToolkit

Hi all,

I’m attempting to very slightly extend the example given [here](https://mtk.sciml.ai/dev/tutorials/acausal_components/) to include a constant phase element. The constant phase element simulation in the time domain can be modelled as a current dependent voltage source, with the voltage gain/drop given by the convolution integral

V_{CPE}(t)=\frac{1}{\Gamma(\alpha)Q}\int_0^t (t-u)^{\alpha-1}I(u)du.

This can be approximated (with constant dt) using

V_{CPE}(t_n)=\frac{\Delta t}{\Gamma(\alpha)Q}\sum_{k=1}^{n-1}(t_n-t_k)^{\alpha-1}I(t_k)

To model this using the framework in the link above, I need to find some way of tracking the history of both the time and current state variables for each CPE modelled. If I was working in Python, the function I’d pass to the ODE solver would be wrapped in a class that could record the state variables passed to it. However, this does not seem to be compatible with the Julia philosophy, so I was wondering what the preferred solution would be?

There’s GitHub - SciML/DelayDiffEq.jl: Delay differential equation solvers for the SciML scientific machine learning ecosystem
that handles the state history for you.

And ModelingToolkit hasn’t set this up at the symbolic level at this point, but it’s planned to use DelayDiffEq.jl to do so.

Ah ok - does that mean it’s not possible to use a DDE with ModellingToolkit as present?

Yes, it’s not possible at present. Right now, directly use DelayDiffEq.jl

Apologies for being dense, but does that mean I won’t be able to use modelling toolkit to construct and reduce a DAE system?

Yes, the analysis would need to be adjusted to handle delays anyways.

Ok, after some thought, in the meantime I would like to try and implement this as a current-controlled voltage source. Is it possible to provide an equation to the symbolic toolkit (such as

eqs =[
v~ v+CCVS_gain()
])
and then provide the function to calculate CCVS_gain() from the current and time state variable history to ODAEProblem()?

Additionally, apologies if this is a foolish question, but if there are multiple @named elements with the same component (e.g. multiple capacitors with a C parameter), would those multiple instances of the C parameter be treated as the same when calling structural_simplify()?

You mean like v~ v+CCVS_gain(v(t-tau),t)? That’s exactly what’s missing in the symbolic form right now.

No, they are namedspaced. See the component-based modeling example: Acausal Component-Based Modeling the RC Circuit · ModelingToolkit.jl