Skip to content

MATLAB BattMo: Incorrectly assigned variable and multiplication error (separate issues) when trying to use Optimisation with Dual Layer Capacity enabled #75

Description

@szopaw

Hello,

I've come across two errors when enabling "Interface.useDoubleLayerCapacity" and assigning "Interface.doubleLayerCapacitance" a value.

First error which occurs is:

Error using *
Incorrect dimensions for matrix multiplication. Check
that the number of columns in the first matrix
matches the number of rows in the second matrix. To
operate on each element of the matrix individually,
use TIMES (.*) for elementwise multiplication.

Error in [ * ](matlab:matlab.lang.internal.introspective.errorDocCallback('ADI/mtimes', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Externals\mrst\core\utils\ADI.m', 188)) ([line 188](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Externals\mrst\core\utils\ADI.m',188,0)))
h.val = uh.val;
^
Error in [Interface/updateReactionCapacityRateEquation](matlab:matlab.lang.internal.introspective.errorDocCallback('Interface/updateReactionCapacityRateEquation', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Electrochemistry\Interface.m', 437)) ([line 437](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Electrochemistry\Interface.m',437,0)))
state.capacityRequation = jDL - (cDL/(F
dt))*((dphi - dphi0) + (R.T./F)./c.(c - c0));
^

In my own simulation, with my own json setup, I've managed to override this by changing the "" operator to ".". I can then run the simulation itself.

However, when trying to run the Examples with no other changes aside from:

json.(pe).(co).(am).(itf).useDoubleLayerCapacity= true;
jsonstruct.(pe).(co).(am).(itf).doubleLayerCapacitance = 10;
json.(ne).(co).(am).(itf).useDoubleLayerCapacity= true;
jsonstruct.(ne).(co).(am).(itf).doubleLayerCapacitance = 10;

This issue is permanent and implementing the above change makes no difference.

A second issue occurs when trying to run the optimisation based on in "runParameterIdentification.m", please see attached MATLAB scripts. This works as intended without the Double Layer enabled, however when it is enabled (and the above fix to Interface is implemented), it runs into this error:

Solving timestep 1/5: -> 1 Second
Solving timestep 2/5: 1 Second -> 2 Seconds
Solving timestep 3/5: 2 Seconds -> 3 Seconds
Solving timestep 4/5: 3 Seconds -> 4 Seconds
Solving timestep 5/5: 4 Seconds -> 5 Seconds
*** Simulation complete. Solved 5 control steps in 185 Milliseconds ***
Solving timestep 1/5: -> 1 Second
Solving timestep 2/5: 1 Second -> 2 Seconds
Solving timestep 3/5: 2 Seconds -> 3 Seconds
Solving timestep 4/5: 3 Seconds -> 4 Seconds
Solving timestep 5/5: 4 Seconds -> 5 Seconds
*** Simulation complete. Solved 5 control steps in 138 Milliseconds ***
Solving reverse mode step 1 of 5
Solving reverse mode step 2 of 5
Unrecognized field name "cElectrolyte".

Error in [Interface/updateReactionCapacityRateEquation](matlab:matlab.lang.internal.introspective.errorDocCallback('Interface/updateReactionCapacityRateEquation', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Electrochemistry\Interface.m', 433)) ([line 433](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Electrochemistry\Interface.m',433,0)))
c0 = state0.cElectrolyte;
^^^^^^^^^^^^^^^^^^^
Error in [BaseModel/getEquations](matlab:matlab.lang.internal.introspective.errorDocCallback('BaseModel/getEquations', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Utilities\Various\BaseModel.m', 640)) ([line 640](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Utilities\Various\BaseModel.m',640,0)))
eval(funcCallList{ifunc});
^^^^^^^^^^^^^^^^^^^^^^^^^
Error in [PhysicalModel/getAdjointEquations](matlab:matlab.lang.internal.introspective.errorDocCallback('PhysicalModel/getAdjointEquations', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Externals\mrst\autodiff\ad-core\models\PhysicalModel.m', 230)) ([line 230](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Externals\mrst\autodiff\ad-core\models\PhysicalModel.m',230,0)))
[problem, state] = model.getEquations(state0, state, dt, forces, varargin{:});
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in [PhysicalModel/solveAdjoint](matlab:matlab.lang.internal.introspective.errorDocCallback('PhysicalModel/solveAdjoint', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Externals\mrst\autodiff\ad-core\models\PhysicalModel.m', 960)) ([line 960](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Externals\mrst\autodiff\ad-core\models\PhysicalModel.m',960,0)))
problem_p = model.getAdjointEquations(current, after, dt_next, forces_p,...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in [computeSensitivitiesAdjointADBattmo](matlab:matlab.lang.internal.introspective.errorDocCallback('computeSensitivitiesAdjointADBattmo', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Utilities\Adjoint\computeSensitivitiesAdjointADBattmo.m', 96)) ([line 96](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Utilities\Adjoint\computeSensitivitiesAdjointADBattmo.m',96,0)))
[lambda, lambdaVec]= setup.model.solveAdjoint(linsolve, getState, getObjectiveState, setup.schedule, lambdaVec, step);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in [evalObjectiveBattmoEXPAVG](matlab:matlab.lang.internal.introspective.errorDocCallback('evalObjectiveBattmoEXPAVG', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\GITT Diff\evalObjectiveBattmoEXPAVG.m', 139)) ([line 139](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\GITT Diff\evalObjectiveBattmoEXPAVG.m',139,0)))
sens = computeSensitivitiesAdjointADBattmo(setupNew, states, parameters, getObj, ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in [GITTautooptim>@(p)evalObjectiveBattmoEXPAVG(p,objective,simsetup,params,'objScaling',objScaling)](matlab:matlab.lang.internal.introspective.errorDocCallback('GITTautooptim>@(p)evalObjectiveBattmoEXPAVG(p,objective,simsetup,params,''objScaling'',objScaling)', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\GITT Diff\GITTautooptim.m', 141)) ([line 141](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\GITT Diff\GITTautooptim.m',141,0)))
objectiveGradient = @(p) evalObjectiveBattmoEXPAVG(p, objective, simsetup, params, 'objScaling', objScaling);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in [unitBoxBFGS](matlab:matlab.lang.internal.introspective.errorDocCallback('unitBoxBFGS', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Externals\mrst\autodiff\optimization\optim\unitBoxBFGS.m', 134)) ([line 134](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\Externals\mrst\autodiff\optimization\optim\unitBoxBFGS.m',134,0)))
[v0,g0] = f(u0);
^^^^^
Error in [GITTautooptim](matlab:matlab.lang.internal.introspective.errorDocCallback('GITTautooptim', 'C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\GITT Diff\GITTautooptim.m', 167)) ([line 167](matlab: opentoline('C:\Users\szopa\OneDrive - Swansea University\Daniel Reinowski PhD resources\SINTEF\BattMo\GITT Diff\GITTautooptim.m',167,0)))
[v, pOptTmp, history] = unitBoxBFGS(p0scaled , ....
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Upon inspection, state0 at that point contains solely the capacityR field, and nothing else. This is only occurring at the third pass through Interface/updateReactionCapacityRateEquation during that step, assigning properly at twice before.

I'm trying to add the .m scripts here, but this form isn't allowing to upload them. I am however using the optimisation routine from "runParameterIdentification.m". I'm also not sure how to check the version of BattMo I'm using, but I've cloned it roughly three weeks ago, at the end of July. I'm happy to share the script and other information if you tell me how, I'd be grateful.

Kind Regards,
Daniel Reinowski

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions