Electrochemistry System

PhotovoltaicCell

To use PhotovoltaicCell(), we design a resistor called vari_Resistor whose resistance value changes with time. Then we can see the I-U curve of PhotovoltaicCell with different loads.

Equivalent circuit diagram of PhotovoltaicCell():

fig_ 1

using Ai4EComponentLib
using ModelingToolkit, DifferentialEquations
using Ai4EComponentLib.Electrochemistry
using Plots

function vari_Resistor(; name)
    @named oneport = OnePort()
    @unpack v, i = oneport
    eqs = [
        v ~ i * t
    ]
    extend(ODESystem(eqs, t, [], []; name=name), oneport)
end

@named Pv = PhotovoltaicCell()
@named R = vari_Resistor()
@named ground = Ground()

eqs = [
    connect(Pv.p, R.p)
    connect(Pv.n, R.n, ground.g)
]

@named OdeFun = ODESystem(eqs, t)
@named model = compose(OdeFun, [Pv, R, ground])
sys = structural_simplify(model)
prob = ODEProblem(sys, [], (0.0, 300.0))
sol = solve(prob)
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 55-element Vector{Float64}:
   0.0
   1.0e-6
   1.1e-5
   0.00011099999999999999
   0.0011109999999999998
   0.011110999999999996
   0.11111099999999996
   1.1111109999999995
   6.7961135535315815
   8.980368891201081
   ⋮
 159.08575236879807
 173.45494782328788
 189.14822118761276
 206.2874917403222
 225.0060062424784
 245.44929392621418
 267.7763299931738
 292.16079488532876
 300.0
u: 55-element Vector{Vector{Float64}}:
 [6.070161232179358]
 [6.070161218944301]
 [6.070161086382273]
 [6.070159760762311]
 [6.070146504594543]
 [6.070013946101201]
 [6.068688679524138]
 [6.055467772362445]
 [5.981230854593792]
 [5.921588397489081]
 ⋮
 [0.43499736539145617]
 [0.39920217314305095]
 [0.3662834500592582]
 [0.33602121398324586]
 [0.30821034771145095]
 [0.2826600806205459]
 [0.259193201861702]
 [0.237645305172514]
 [0.23145758331395122]
plot(sol[R.p.v], sol[R.p.i], color = "red")

fig_一

PEMElectrolyzer

Using above PhotovoltaicCell to drive Electrolyzer, then we build a PVEL system. In default paraments, we can know how the system works.

Equivalent circuit diagram of PEMElectrolyzer():

fig_ 2

using ModelingToolkit, DifferentialEquations
using Ai4EComponentLib
using Ai4EComponentLib.Electrochemistry

@named Pv = PhotovoltaicCell()
@named El = PEMElectrolyzer()
@named ground = Ground()
eqs = [
    connect(Pv.p, El.p)
    connect(Pv.n, El.n, ground.g)
]
@named OdeFun = ODESystem(eqs, t)
@named model = compose(OdeFun, [Pv, El, ground])
sys = structural_simplify(model)
u0 = [
    El.m_H_2 => 0.0
    El.∂_m_H_2 => 0.0
]
prob = ODEProblem(sys, u0, (0.0, 30.0))
sol = solve(prob)
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 29-element Vector{Float64}:
  0.0
  1.0e-6
  1.1e-5
  0.00011099999999999999
  0.0011109999999999998
  0.008439887065773926
  0.020796255796253802
  0.03442494139216535
  0.052116653461119405
  0.07210657583204284
  ⋮
  0.6700908105173512
  0.7799452514963259
  1.1065977951333883
  1.433250338770451
  2.0130301426881534
  3.83094485507726
  9.416466362176456
 28.63960936303355
 30.0
u: 29-element Vector{Vector{Float64}}:
 [0.0, 0.0, 6.063727595681834]
 [1.8307680149829605e-14, 3.661521505842432e-8, 6.063727595681835]
 [2.2150535613568343e-12, 4.027194379907009e-7, 6.063727595681835]
 [2.2537214333319222e-10, 4.058970969463909e-6, 6.063727595681835]
 [2.2399203441487435e-8, 4.014448437387311e-5, 6.063727595681835]
 [1.2189296098963561e-6, 0.00027901338737525, 6.063727595681835]
 [6.69070409685778e-6, 0.0005882354978314794, 6.063727595681835]
 [1.6362842524230887e-5, 0.0008126644963036136, 6.063727595681835]
 [3.224746590988311e-5, 0.0009592361733792569, 6.063727595681835]
 [5.185457979379085e-5, 0.0009818115051539883, 6.063727595681835]
 ⋮
 [0.00012667436955623627, 9.372195131969488e-7, 6.063727595681835]
 [0.00012671057762334218, -3.961253864584919e-8, 6.063727595681835]
 [0.00012669665417256172, 3.3533791773304226e-8, 6.063727595681835]
 [0.00012669753307424986, 1.0602925418996095e-9, 6.063727595681835]
 [0.00012669772793681163, -2.6321612945922677e-10, 6.063727595681835]
 [0.0001266977465289514, 6.3591890600861266e-12, 6.063727595681835]
 [0.00012669775281945505, 8.101659534891683e-12, 6.063727595681835]
 [0.00012669775355874052, 3.3013910993327334e-13, 6.063727595681835]
 [0.00012669775357165324, 6.77055735877549e-14, 6.063727595681835]

Get states of system by states()

states(sys)
3-element Vector{Any}:
 El₊m_H_2(t)
 El₊∂_m_H_2(t)
 El₊i(t)

Check voltage, current and mass yield of electrolyzer. The working point (El.v,El.i) can be found in I-U curve above.

sol[El.v]
29-element Vector{Float64}:
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 ⋮
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
 2.9460329264949316
sol[El.i]
29-element Vector{Float64}:
 6.063727595681834
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 ⋮
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
 6.063727595681835
sol[El.m_H_2]
29-element Vector{Float64}:
 0.0
 1.8307680149829605e-14
 2.2150535613568343e-12
 2.2537214333319222e-10
 2.2399203441487435e-8
 1.2189296098963561e-6
 6.69070409685778e-6
 1.6362842524230887e-5
 3.224746590988311e-5
 5.185457979379085e-5
 ⋮
 0.00012667436955623627
 0.00012671057762334218
 0.00012669665417256172
 0.00012669753307424986
 0.00012669772793681163
 0.0001266977465289514
 0.00012669775281945505
 0.00012669775355874052
 0.00012669775357165324

Lithium battery

Equivalent circuit diagram of Lithium_ion_batteries():

fig_ 3

using ModelingToolkit, DifferentialEquations
using Ai4EComponentLib
using Ai4EComponentLib.Electrochemistry
using Plots

@named batter = Lithium_ion_batteries()
@named Pv = PhotovoltaicCell()
@named ground = Ground()

eqs = [
    connect(batter.p, Pv.p)
    connect(batter.n, Pv.n, ground.g)
]

@named OdeFun = ODESystem(eqs, t)
@named model = compose(OdeFun, [Pv, batter, ground])
sys = structural_simplify(model)
u0 = [
    batter.v_f => 0.5
    batter.v_s => 0.5
    batter.v_soc => 0.5
]
prob = ODEProblem(sys, u0, (0.0, 3600.0))
sol = solve(prob)
retcode: Success
Interpolation: specialized 3rd order "free" stiffness-aware interpolation
t: 37-element Vector{Float64}:
    0.0
    1.0e-6
    1.1e-5
    0.00011099999999999999
    0.0011109999999999998
    0.011110999999999996
    0.11111099999999996
    1.1111109999999995
    6.770870617087571
   16.44501650526439
    ⋮
  968.431960149021
 1120.9137369255204
 1300.0222274681566
 1514.5457681595656
 1775.8153482798052
 2103.9186165403125
 2533.885743801293
 3135.5824342225555
 3600.0
u: 37-element Vector{Vector{Float64}}:
 [0.5, 0.5, 0.5, 2.32613574386297, 6.065081346069112]
 [0.4999999977573967, 0.49999999142936485, 0.5000000000468989, 2.3261357547108465, 6.065081346025329]
 [0.4999999753313647, 0.4999999057230212, 0.500000000515888, 2.3261358628577637, 6.065081345789154]
 [0.49999975107109407, 0.4999990486603213, 0.5000000052057781, 2.3261369443261497, 6.06508134342741]
 [0.4999975084733217, 0.49999047810697717, 0.5000000521046789, 2.326147758931427, 6.065081319810146]
 [0.4999750829890147, 0.49990477993861454, 0.5000005210936259, 2.326255897126056, 6.065081083654659]
 [0.4997508774802967, 0.49904853433725055, 0.500005210977118, 2.3273364936884677, 6.065078723814942]
 [0.49751374853205843, 0.49055926276750406, 0.5000521092147455, 2.3380643519959916, 6.065055295990901]
 [0.48501942343032445, 0.4449336279755472, 0.5003175216192808, 2.396192672661811, 6.064928353592024]
 [0.46430727696285484, 0.3757079289432439, 0.5007711082308799, 2.4861452253059944, 6.064731912465073]
 ⋮
 [-0.04897672771813481, -0.0485013437353536, 0.544995438958049, 3.4265827447411707, 6.0626781563367045]
 [-0.05429580048979839, -0.04850134760838481, 0.5520063053172003, 3.4326111065002944, 6.062664991416511]
 [-0.05753359643084064, -0.04850127070343426, 0.5602161626435621, 3.436755322675174, 6.062655941150852]
 [-0.05931472352283072, -0.04850120986004348, 0.5700135644421107, 3.439717270287006, 6.062649472759339]
 [-0.06016469489578691, -0.048501163262421966, 0.5818934200071098, 3.4421268115468626, 6.062644210729678]
 [-0.06050171228365624, -0.04850111905427858, 0.5967309851581306, 3.4445709095037045, 6.062638873234021]
 [-0.060603714410219396, -0.04850106605642565, 0.6160390567186836, 3.447589569419785, 6.06263228099246]
 [-0.0606240522360292, -0.04850099338911702, 0.6428019517206085, 3.4517338773407436, 6.062623230526458]
 [-0.06062584866684111, -0.04850094034912263, 0.6632558164458683, 3.454737752327897, 6.062616670572667]
plot(sol.t, sol[batter.v_soc], color = "red")

fig_3_1

plot(sol.t, sol[batter.v_s], color = "red")

fig_3_2

plot(sol.t, sol[batter.i_b], color = "red")

fig_3_3

Super capacity

Equivalent circuit diagram of Super_capacity():

fig_ 4

using Ai4EComponentLib
using ModelingToolkit, DifferentialEquations
using Ai4EComponentLib.Electrochemistry
using Plots

function charge_controller(; name)
    @named oneport = OnePort()
    @unpack v, i = oneport
    eqs = [∂(i) ~ 0]
    events = [
        [t ~ 5.0] => [i ~ -10],
        [t ~ 36.7] => [i ~ 0],
    ]
    return extend(ODESystem(eqs, t, [], []; name=name, continuous_events=events), oneport)
end

@named ground = Ground()
@named sc = Super_capacity()
@named cg = charge_controller()
eqs = [
    connect(sc.p, cg.p)
    connect(sc.n, cg.n, ground.g)
]

@named OdeFun = ODESystem(eqs, t)
@named model = compose(OdeFun, [sc, cg, ground])
sys = structural_simplify(model)
u0 = [
    sc.v_0 => 0.0
    sc.v_2 => 0.0
    cg.i   => 0.0
]

prob = ODEProblem(sys, u0, (0.0, 600))
sol = solve(prob)
retcode: Success
Interpolation: specialized 4th order "free" interpolation, specialized 2nd order "free" stiffness-aware interpolation
t: 20-element Vector{Float64}:
   0.0
   9.999999999999999e-5
   0.0010999999999999998
   0.011099999999999997
   0.11109999999999996
   1.1110999999999995
   4.999999999999999
   4.999999999999999
  14.999999999999993
  21.875164952568415
  35.28305857497855
  36.699999999999996
  36.699999999999996
  52.25812700270571
  99.90243310232333
 162.70171805985572
 244.82731082396603
 346.77342762079024
 471.5891188090726
 600.0
u: 20-element Vector{Vector{Float64}}:
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, 0.0]
 [0.0, 0.0, -10.0]
 [0.9431586021499807, 0.02431537859489335, -10.0]
 [1.4797312067402217, 0.06085143042431975, -10.0]
 [2.375476261233722, 0.16863755462232197, -10.0]
 [2.46160320038797, 0.1824660046197756, -10.0]
 [2.46160320038797, 0.1824660046197756, 0.0]
 [2.449367440013306, 0.32505283742484026, 0.0]
 [2.4166812799710233, 0.7042055853858823, 0.0]
 [2.3828324347791447, 1.0940261453446694, 0.0]
 [2.350611852729195, 1.4621103035605305, 0.0]
 [2.323926709454996, 1.7641755817646896, 0.0]
 [2.3040718943375342, 1.9863247646241289, 0.0]
 [2.2923683520080207, 2.115062170647424, 0.0]

fig_4_1

MPPT Controller

The MPPT controller can detect the generating voltage of the solar panel in real time, and track the maximum voltage current value (VI), so that the system can charge the battery at the maximum power output.

fig_ 1

using Ai4EComponentLib.Electrochemistry, Ai4EComponentLib
using ModelingToolkit
using IfElse: ifelse
using DifferentialEquations
using Plots

global power = zeros(1000).+50.0
global solar = [0.134588889,0.307388889,0.494766667,0.666464444,0.760082222,0.773202222,0.765344444,0.543993333,0.422606667,0.2673,0.1105,0.053308889,0.000384444,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.01498,0.080171111,0.229308889,0.443246667,0.607068889,0.645895556,0.729895556,0.585984444,0.644491111,0.52154,0.397646667,0.217877778,0.065024444,0.000295556,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.007548889,0.05546,0.101291111,0.19226,0.245717778,0.25434,0.275068889,0.342962222,0.288295556,0.274233333,0.172188889,0.068171111,0.027637778,0.000153333,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.019975556,0.160011111,0.312562222,0.412064444,0.493433333,0.62746,0.560811111,0.616402222,0.399442222,0.351353333,0.251548889,0.183904444,0.053468889,0.000135556,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.020437778,0.170197778,0.377557778,0.576135556,0.737717778,0.846126667,0.891886667,0.845575556,0.770962222,0.6393,0.419655556,0.241753333,0.062162222,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.01978,0.167122222,0.375406667,0.573095556,0.725095556,0.830268889,0.863833333,0.864508889,0.7793,0.63978,0.460828889,0.242908889,0.058891111,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.016508889,0.154144444,0.335015556,0.515406667,0.680544444,0.812686667,0.773504444,0.694108889,0.686997778,0.491673333,0.294624444,0.141362222,0.032402222,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.007655556,0.036668889,0.06202,0.120775556,0.115442222,0.200153333,0.171886667,0.25466,0.177664444,0.195122222,0.099797778,0.106251111,0.030731111,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.012331111,0.112331111,0.262731111,0.437095556,0.582464444,0.663815556,0.758891111,0.700508889,0.691726667,0.544348889,0.353682222,0.192864444,0.036331111,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.013397778,0.126748889,0.257344444,0.441486667,0.54266,0.632188889,0.610606667,0.552491111,0.517166667,0.453771111,0.362126667,0.187708889,0.038535556,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.011957778,0.117557778,0.292455556,0.445077778,0.562073333,0.675122222,0.757131111,0.739317778,0.588811111,0.551922222,0.379726667,0.185895556,0.037735556,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.013148889,0.124224444,0.30362,0.512171111,0.625877778,0.753255556,0.735104444,0.7321,0.617948889,0.54698,0.36842,0.173326667,0.038286667,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.012864444,0.13434,0.327051111,0.517237778,0.635335556,0.761148889,0.777415556,0.671975556,0.677948889,0.542766667,0.333771111,0.159993333,0.031033333,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.010464444,0.106002222,0.27114,0.356668889,0.509753333,0.567246667,0.599673333,0.512313333,0.336668889,0.281682222,0.209931111,0.13466,0.023264444,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.004171111,0.064811111,0.121522222,0.275264444,0.359513333,0.421184444,0.464828889,0.604953333,0.480224444,0.347797778,0.268597778,0.12666,0.026962222,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.009735556,0.099548889,0.248828889,0.333877778,0.583993333,0.662553333,0.617913333,0.497451111,0.507051111,0.359708889,0.150997778,0.057895556,0.012064444,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.002357778,0.017077778,0.04026,0.042446667,0.129077778,0.165504444,0.12458,0.122553333,0.077397778,0.083157778,0.090748889,0.097842222,0.013006667,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.004526667,0.049504444,0.142624444,0.152046667,0.283975556,0.347175556,0.317771111,0.363477778,0.210731111,0.139406667,0.097788889,0.049113333,0.012722222,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.001237778,0.017611111,0.044295556,0.083068889,0.102677778,0.226037778,0.177646667,0.12474,0.084633333,0.038624444,0.030908889,0.011477778,0.00186,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.00186,0.012775556,0.026766667,0.04106,0.056633333,0.119655556,0.070535556,0.08314,0.082304444,0.106108889,0.087762222,0.044046667,0.010482222,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.003762222,0.059673333,0.1721,0.355851111,0.40506,0.321611111,0.373077778,0.33098,0.256437778,0.221237778,0.216562222,0.098606667,0.016366667,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.007868889,0.116117778,0.303708889,0.515228889,0.660917778,0.749913333,0.751228889,0.744988889,0.637308889,0.521095556,0.339868889,0.15722,0.019726667,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.007602222,0.1281,0.338997778,0.508206667,0.643957778,0.766091111,0.820597778,0.791193333,0.459815556,0.257077778,0.246553333,0.109948889,0.011424444,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.004562222,0.078162222,0.159228889,0.236704444,0.391264444,0.434411111,0.546037778,0.540082222,0.3593,0.187477778,0.12842,0.064793333,0.006997778,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.006571111,0.116811111,0.310713333,0.493593333,0.656171111,0.754766667,0.752544444,0.681113333,0.670091111,0.501788889,0.298322222,0.130393333,0.013077778,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.006162222,0.119424444,0.311566667,0.502428889,0.66266,0.768508889,0.815068889,0.778624444,0.689024444,0.493895556,0.246411111,0.116526667,0.011068889,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.00266,0.03706,0.108971111,0.188526667,0.223495556,0.190997778,0.323353333,0.290482222,0.395246667,0.346091111,0.259904444,0.12906,0.009895556,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.00554,0.120437778,0.318677778,0.513415556,0.67194,0.766713333,0.804028889,0.774642222,0.677291111,0.528793333,0.339673333,0.140597778,0.010873333,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.005148889,0.117042222,0.31034,0.505148889,0.660775556,0.762411111,0.798553333,0.764757778,0.667673333,0.517735556,0.324828889,0.1201,0.008242222,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.003655556,0.06618,0.154855556,0.24106,0.305486667,0.30154,0.374962222,0.400295556,0.461522222,0.370464444,0.205433333,0.079904444,0.005344444,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.0001,0.002215556]
solar = solar .* 1000
@named pv_input = Secrete(solar,output_type = "min")
@named power_input = Secrete(power,output_type = "min")
@named pv = PhotovoltaicCell_secrete()
@named mppt = MPPT_Controller(Sampling_time = 0.5)
@named batter = Lithium_ion_batteries()
@named load = electronic_load()
@named dc_pv = DC2DC(value = 36, output_type = "voltage")
@named dc_batter = DC2DC(value = 36, output_type = "none")
@named ground = Ground()

eqs = [
    connect(pv_input.u, pv.u)
    connect(power_input.u, load.u)
    connect(pv.p, mppt.in.p)
    connect(pv.n, mppt.in.n)
    connect(mppt.out.p, dc_pv.in.p)
    connect(mppt.out.n, dc_pv.in.n)
    connect(dc_pv.out.p, dc_batter.out.p)
    connect(dc_pv.out.n, dc_batter.out.n)
    connect(dc_batter.in.p, batter.p)
    connect(dc_batter.in.n, batter.n)
    connect(dc_batter.out.p, load.p)
    connect(dc_batter.out.n, load.n)
    connect(pv.n, ground.g)
    connect(dc_pv.in.n, ground.g)
    connect(batter.n, ground.g)
    connect(dc_batter.out.n, ground.g)
    ]
@named OdeFun = ODESystem(eqs, t)
@named model = compose(OdeFun, [batter, ground, pv_input, power_input, pv, mppt, dc_pv, dc_batter, load])
sys = structural_simplify(model)
u0 = [
batter.v_s => 0.1,
batter.v_f => 0.1,
batter.v_soc => 0.3
    ]
prob = ODEProblem(sys, u0, (0.0,5000.0))
sol = solve(prob,Rosenbrock23())
retcode: Success
Interpolation: specialized 2nd order "free" stiffness-aware interpolation
t: 20072-element Vector{Float64}:
    0.0
    1.0e-6
    1.1e-5
    0.00011099999999999999
    0.0011109999999999998
    0.011110999999999996
    0.11111099999999996
    0.5
    0.5
    1.0
    ⋮
 4998.0
 4998.0
 4998.5
 4998.5
 4999.0
 4999.0
 4999.5
 4999.5
 5000.0
u: 20072-element Vector{Vector{Float64}}:
 [0.1, 0.1, 0.3, 1.0, 1.0, 1.0, 0.0, 2.880851936385435, -17.07314664560711, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.07314664560711, 2.880851936385435, 1.3888888888888888]
 [0.10000000028292587, 0.10000000057164334, 0.2999999998363597, 1.0, 1.0, 1.0, 0.0, 2.8808519354131676, -17.073146651369175, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.073146651369175, 2.8808519354131676, 1.3888888888888888]
 [0.10000000311218447, 0.10000000628807615, 0.29999999819995726, 1.0, 1.0, 1.0, 0.0, 2.880851925690499, -17.07314670898982, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.07314670898982, 2.880851925690499, 1.3888888888888888]
 [0.10000003140476556, 0.10000006345235912, 0.2999999818359323, 1.0, 1.0, 1.0, 0.0, 2.880851828463848, -17.073147285196075, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.073147285196075, 2.880851828463848, 1.3888888888888888]
 [0.10000031433008073, 0.10000063509067253, 0.29999981819565485, 1.0, 1.0, 1.0, 0.0, 2.8808508562025543, -17.0731530472297, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.0731530472297, 2.8808508562025543, 1.3888888888888888]
 [0.10000314353366577, 0.10000635102219714, 0.2999981817901126, 1.0, 1.0, 1.0, 0.0, 2.880841134110596, -17.07321066466676, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.07321066466676, 2.880841134110596, 1.3888888888888888]
 [0.10003143061318966, 0.10006346520560844, 0.29998181745805125, 1.0, 1.0, 1.0, 0.0, 2.880743965257149, -17.073786549309574, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.073786549309574, 2.880743965257149, 1.3888888888888888]
 [0.10014135031473874, 0.10028479802883107, 0.29991817359782963, 1.0, 1.0, 1.0, 0.0, 2.8803669831046244, -17.076021125206836, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.076021125206836, 2.8803669831046244, 1.3888888888888888]
 [0.10014135031473874, 0.10028479802883107, 0.29991817359782963, 1.0, 1.1, 0.8147924258102575, 1.0, 2.8803669831046244, -17.076021125206836, -0.8147924258102575  …  0.8147924258102575, 36.0, 0.8147924258102575, 1.0, -0.022633122939173817, -1.366255765949715, 36.0, 17.076021125206836, 2.8803669831046244, 1.3888888888888888]
 [0.10028187672745002, 0.10056569281008583, 0.29983647342382314, 1.0, 1.1, 0.8147924258102575, 1.0, 2.880185979416775, -17.048973721467007, -0.8145740427619635  …  0.8145740427619635, 36.0, 0.8145740427619635, 1.1, -0.024884333325688932, -1.3640045555631999, 36.0, 17.048973721467007, 2.880185979416775, 1.3888888888888888]
 ⋮
 [-0.11609768316687444, -0.011000203561436156, 0.27286631944150885, 53.60000000000049, 53.50000000000049, 10.775249128997192, 53.60000000000049, 3.245381263352336, -12.084604408442816, -0.20151928556139898  …  0.20151928556139898, 36.0, 0.20151928556139898, 53.5000000000005, -0.29946790459228406, -1.0894209842966045, 36.0, 12.084604408442816, 3.245381263352336, 1.3888888888888888]
 [-0.11609768316687444, -0.011000203561436156, 0.27286631944150885, 53.50000000000049, 53.40000000000049, 10.781281777534945, 53.50000000000049, 3.245381263352336, -12.084604408442816, -0.20151928556139898  …  0.20151928556139898, 36.0, 0.20151928556139898, 53.5000000000005, -0.29946790459228406, -1.0894209842966045, 36.0, 12.084604408442816, 3.245381263352336, 1.3888888888888888]
 [-0.11562425352990041, -0.010162203201038607, 0.27280784229903504, 53.50000000000049, 53.40000000000049, 10.781281777534945, 53.50000000000049, 3.244002350160778, -12.08809372985097, -0.20199656491028214  …  0.20199656491028214, 36.0, 0.20199656491028214, 53.40000000000048, -0.29961637257147783, -1.0892725163174115, 36.0, 12.08809372985097, 3.244002350160778, 1.3888888888888888]
 [-0.11562425352990041, -0.010162203201038607, 0.27280784229903504, 53.40000000000049, 53.30000000000049, 10.786616566209165, 53.40000000000049, 3.244002350160778, -12.08809372985097, -0.20199656491028214  …  0.20199656491028214, 36.0, 0.20199656491028214, 53.40000000000048, -0.29961637257147783, -1.0892725163174115, 36.0, 12.08809372985097, 3.244002350160778, 1.3888888888888888]
 [-0.11515169601014638, -0.009330494283401294, 0.272749348598594, 53.40000000000049, 53.30000000000049, 10.786616566209165, 53.40000000000049, 3.242628663864, -12.091773167341046, -0.20246307124255955  …  0.20246307124255955, 36.0, 0.20246307124255955, 53.30000000000049, -0.29974622736741785, -1.0891426615214708, 36.0, 12.091773167341046, 3.242628663864, 1.3888888888888888]
 [-0.11515169601014638, -0.009330494283401294, 0.272749348598594, 53.30000000000049, 53.200000000000486, 10.791281697228523, 53.30000000000049, 3.242628663864, -12.091773167341046, -0.20246307124255955  …  0.20246307124255955, 36.0, 0.20246307124255955, 53.30000000000049, -0.29974622736741785, -1.0891426615214708, 36.0, 12.091773167341046, 3.242628663864, 1.3888888888888888]
 [-0.11468000523455532, -0.008505016535355757, 0.272690837499094, 53.30000000000049, 53.200000000000486, 10.791281697228523, 53.30000000000049, 3.241260219995016, -12.095634552833015, -0.2029192512520797  …  0.2029192512520797, 36.0, 0.2029192512520797, 53.20000000000049, -0.29985821934607604, -1.0890306695428134, 36.0, 12.095634552833015, 3.241260219995016, 1.3888888888888888]
 [-0.11468000523455532, -0.008505016535355757, 0.272690837499094, 53.200000000000486, 53.100000000000485, 10.79530416661074, 53.200000000000486, 3.241260219995016, -12.095634552833015, -0.2029192512520797  …  0.2029192512520797, 36.0, 0.2029192512520797, 53.20000000000049, -0.29985821934607604, -1.0890306695428134, 36.0, 12.095634552833015, 3.241260219995016, 1.3888888888888888]
 [-0.11420917599684985, -0.007685710639009894, 0.2726323081956083, 53.200000000000486, 53.100000000000485, 10.79530416661074, 53.200000000000486, 3.239897031727938, -12.09967006820758, -0.2033655332400587  …  0.2033655332400587, 36.0, 0.2033655332400587, 53.10000000000048, -0.29995306676169914, -1.0889358221271894, 36.0, 12.09967006820758, 3.239897031727938, 1.3888888888888888]
plot(sol.t, sol[batter.v_soc])

fig_mppt1

plot(sol.t, sol[mppt.p_new])

fig_mppt2