Skip to content

Commit

Permalink
more in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierr committed Dec 20, 2024
1 parent 813c384 commit 0497f91
Show file tree
Hide file tree
Showing 42 changed files with 233 additions and 60 deletions.
Binary file modified Documentation/publishedExamples/runBatteryP2D.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runBatteryP2D_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Documentation/publishedExamples/runBatteryP3D.png
Binary file not shown.
Binary file not shown.
Binary file modified Documentation/publishedExamples/runGasSupply.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runGasSupply_09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Documentation/publishedExamples/runProtonicCell.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ we plot the inlet faces
.. code-block:: matlab
figure('position', [337, 757, 3068, 557])
plotGrid(model.Electrolyser.grid, 'facecolor', 'none', 'edgecolor', 'none')
plotGrid(model.Electrolyser.grid, 'facecolor', 'red', 'edgecolor', 'none')
plotGrid(model.GasSupply.grid, 'facecolor', 'none', 'edgealpha', 0.2)
plotFaces(model.GasSupply.grid, model.GasSupply.couplingTerms{1}.couplingfaces, opts{:});
Expand Down
Binary file modified Documentation/publishedExamples/runProtonicCell_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_03.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_04.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_06.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_07.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_08.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_09.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Documentation/publishedExamples/runProtonicCell_11.png
Binary file modified Documentation/publishedExamples/runProtonicCell_12.png
Binary file modified Documentation/publishedExamples/runProtonicCell_13.png
2 changes: 1 addition & 1 deletion Documentation/publishedExamples/runProtonicCell_source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Source code for runProtonicCell
%%
% we plot the inlet faces
figure('position', [337, 757, 3068, 557])
plotGrid(model.Electrolyser.grid, 'facecolor', 'none', 'edgecolor', 'none')
plotGrid(model.Electrolyser.grid, 'facecolor', 'red', 'edgecolor', 'none')
plotGrid(model.GasSupply.grid, 'facecolor', 'none', 'edgealpha', 0.2)
plotFaces(model.GasSupply.grid, model.GasSupply.couplingTerms{1}.couplingfaces, opts{:});
%%
Expand Down
Binary file modified Documentation/publishedExamples/runProtonicMembrane.png
154 changes: 123 additions & 31 deletions Documentation/publishedExamples/runProtonicMembrane.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Protonic Membrane model

Load and parse input from given json files
==========================================
The source of the json files can be seen in :battmofile:`protonicMembrane<ProtonicMembrane/jsonfiles/protonicMembrane.json>` and :battmofile:`1d-PM-geometry.json<ProtonicMembrane/jsonfiles/1d-PM-geometry.json>`
The source of the json files can be seen in :battmofile:`protonicMembrane.json<ProtonicMembrane/jsonfiles/protonicMembrane.json>` and :battmofile:`1d-PM-geometry.json<ProtonicMembrane/jsonfiles/1d-PM-geometry.json>`

.. code-block:: matlab
Expand All @@ -30,10 +30,13 @@ We setup the input parameter structure which will we be used to instantiate the

.. code-block:: matlab
inputparams = ProtonicMembraneCellInputParams(jsonstruct);
% We setup the grid, which is done by calling the function :battmo:`setupProtonicMembraneCellGrid`
[inputparams, gen] = setupProtonicMembraneCellGrid(inputparams, jsonstruct);
inputparams = ProtonicMembraneInputParams(jsonstruct);
We setup the grid, which is done by calling the function :battmo:`setupProtonicMembraneGrid`

.. code-block:: matlab
[inputparams, gen] = setupProtonicMembraneGrid(inputparams, jsonstruct);
Model setup
Expand All @@ -42,7 +45,7 @@ We instantiate the model for the protonic membrane cell

.. code-block:: matlab
model = ProtonicMembraneCell(inputparams);
model = ProtonicMembrane(inputparams);
The model is equipped for simulation using the following command (this step may become unnecessary in future versions)

Expand All @@ -60,20 +63,14 @@ We setup the initial state using a default setup included in the model
state0 = model.setupInitialState();
Schedule schedule
=================
We setup the schedule, which means the timesteps and also the control we want to use. In this case we use current control and the current equal to zero (see here :battmofile:`here<ProtonicMembrane/protonicMembrane.json#86>`).
We compute the steady-state solution so that the time stepping here is more an artifact to reach the steady-state solution. In particular, it governs the pace at which we increase the non-linearity (not detailed here).

.. code-block:: matlab
schedule = model.Control.setupSchedule(inputparams.jsonstruct);
We change the default tolerance
Schedule
========
We setup the schedule, which means the timesteps and also the control we want to use. In this case we use current control and the current equal to zero (see :battmofile:`here <ProtonicMembrane/jsonfiles/protonicMembrane.json#118>`).
We compute the steady-state solution and the time stepping here does not correspond to time values but should be seen as step-wise increase of the effect of the non-linearity (in particular in the expression of the conductivity which includes highly nonlineaer effect with the exponential terms. We do not detail here the method).

.. code-block:: matlab
model.nonlinearTolerance = 1e-8;
schedule = model.Control.setupSchedule(jsonstruct);
Simulation
Expand All @@ -87,7 +84,7 @@ We run the simulation
Plotting
========
We setup som shortcuts for convenience
We setup som shortcuts for convenience and introduce plotting options

.. code-block:: matlab
Expand All @@ -105,47 +102,142 @@ We recover the position of the mesh cell of the discretization grid. This is use
xc = model.(elyte).grid.cells.centroids(:, 1);
We consider the solution obtained at the last time step, which corresponds to the solution at steady-state.
We consider the solution obtained at the last time step, which corresponds to the solution at steady-state. The second line adds to the state variable all the variables that are derived from our primary unknowns.

.. code-block:: matlab
state = states{end};
state = model.addVariables(state, schedule.control);
figure(1)
Plot of electromotive potential

.. code-block:: matlab
figure
plot(xc, state.(elyte).pi)
title('Electromotive potential (\pi)')
xlabel('x / m')
ylabel('\pi / V')
figure(2)
.. figure:: runProtonicMembrane_01.png
:figwidth: 100%

Plot of electronic chemical potential

.. code-block:: matlab
figure
plot(xc, state.(elyte).pi - state.(elyte).phi)
title('Electronic chemical potential (E)')
xlabel('x / m')
ylabel('E / V')
figure(3)
.. figure:: runProtonicMembrane_02.png
:figwidth: 100%

Plot of electrostatic potential

.. code-block:: matlab
figure
plot(xc, state.(elyte).phi)
title('Electrostatic potential (\phi)')
xlabel('x / m')
ylabel('\phi / V')
figure(4)
.. figure:: runProtonicMembrane_03.png
:figwidth: 100%

Plot of the conductivity

.. code-block:: matlab
figure
plot(xc, log(state.(elyte).sigmaEl))
title('logarithm of conductivity (\sigma)')
xlabel('x / m')
xlabel('log(\sigma/Siemens)')
.. figure:: runProtonicMembrane_01.png
.. figure:: runProtonicMembrane_04.png
:figwidth: 100%

.. figure:: runProtonicMembrane_02.png

Evolution of the Faradic efficiency
===================================
We increase the current density from 0 to 1 A/cm^2 and plot the faraday efficiency.
We sample the current value from 0 to 1 A/cm^2.

.. code-block:: matlab
Is = linspace(0, 1*ampere/((centi*meter)^2), 20);
We run the simulation for each current value and collect the results in the :code:`endstates`.

.. code-block:: matlab
endstates = {};
for iI = 1 : numel(Is)
model.Control.I = Is(iI);
[~, states, report] = simulateScheduleAD(state0, model, schedule);
state = states{end};
state = model.addVariables(state, schedule.control);
endstates{iI} = state;
end
We plot the profile of the electromotive potential for the mininum and maximum current values.

.. code-block:: matlab
figure
hold on
unit = ampere/((centi*meter)^2); % shortcut
state = endstates{1};
plot(xc, state.(elyte).pi, 'displayname', sprintf('I=%g A/cm^2', Is(1)/unit));
state = endstates{end};
plot(xc, state.(elyte).pi, 'displayname', sprintf('I=%g A/cm^2', Is(end)/unit));
title('Electromotive potential (\pi)')
xlabel('x / m')
ylabel('\pi / V')
legend
.. figure:: runProtonicMembrane_05.png
:figwidth: 100%

.. figure:: runProtonicMembrane_03.png
We retrieve and plot the cell potential

.. code-block:: matlab
E = cellfun(@(state) state.(an).pi - state.(ct).pi, endstates);
figure
plot(Is/unit, E, '*-');
xlabel('Current density / A/cm^2')
ylabel('E / V')
title('Cell potential');
.. figure:: runProtonicMembrane_06.png
:figwidth: 100%

.. figure:: runProtonicMembrane_04.png
We retrieve and plot the Faradic efficiency

.. code-block:: matlab
feff = cellfun(@(state) state.(an).iHp/state.(an).i, endstates);
figure
plot(Is/unit, feff, '*-');
xlabel('Current density / A/cm^2')
ylabel('Faradic efficiency / -')
title('Faradic efficiency');
.. figure:: runProtonicMembrane_07.png
:figwidth: 100%


Expand Down
Binary file modified Documentation/publishedExamples/runProtonicMembrane_01.png
Binary file modified Documentation/publishedExamples/runProtonicMembrane_02.png
Binary file modified Documentation/publishedExamples/runProtonicMembrane_03.png
Binary file modified Documentation/publishedExamples/runProtonicMembrane_04.png
Binary file modified Documentation/publishedExamples/runProtonicMembrane_05.png
Binary file modified Documentation/publishedExamples/runProtonicMembrane_06.png
Binary file modified Documentation/publishedExamples/runProtonicMembrane_07.png
Loading

0 comments on commit 0497f91

Please sign in to comment.