Display modules

This module is used to accurately plot the figures.

calculate_simulation_error(Ucell, U_exp_t)

This function calculates the simulation error between the simulated cell voltage and the experimental cell voltage. It is calculated as the maximum relative difference between the two voltages (in %).

Parameters:
  • Ucell (ndarray) –

    Simulated cell voltage.

  • U_exp_t (ndarray) –

    Experimental cell voltage.

Returns:
  • float

    Simulation error between the simulated cell voltage and the experimental cell voltage (in %).

Source code in modules/display_modules.py
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
def calculate_simulation_error(Ucell, U_exp_t):
    """This function calculates the simulation error between the simulated cell voltage and the experimental cell
    voltage. It is calculated as the maximum relative difference between the two voltages (in %).

    Parameters
    ----------
    Ucell : numpy.ndarray
        Simulated cell voltage.
    U_exp_t : numpy.ndarray
        Experimental cell voltage.

    Returns
    -------
    float
        Simulation error between the simulated cell voltage and the experimental cell voltage (in %).
    """
    return np.round(np.max(np.abs(Ucell - U_exp_t) / U_exp_t * 100), 2)  # in %.

make_Fourier_transformation(variables, operating_inputs, parameters)

This function calculates the Fourier transformation of both cell voltage and current density. It will be used to display the Nyquist and Bode diagrams. To generate it at each frequency change, the cell voltage and the current density are recorded. The time for which these points are captured is determined using the following approach: at the beginning of each frequency change, a delta_t_break_EIS time is observed to ensure the dynamic stability of the stack's variables. Subsequently, a delta_t_measurement_EIS time is needed to record the cell voltage and the current density.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

Returns:
  • dict

    Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points used in the FT.

Source code in modules/display_modules.py
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
def make_Fourier_transformation(variables, operating_inputs, parameters):
    """
    This function calculates the Fourier transformation of both cell voltage and current density. It will be used to
    display the Nyquist and Bode diagrams.
    To generate it at each frequency change, the cell voltage and the current density are recorded. The time for which
    these points are captured is determined using the following approach: at the beginning of each frequency change, a
    delta_t_break_EIS time is observed to ensure the dynamic stability of the stack's variables. Subsequently, a
    delta_t_measurement_EIS time is needed to record the cell voltage and the current density.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.

    Returns
    -------
    dict
        Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude
        values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the
        perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points
        used in the FT.
    """

    # Extraction of the variables
    t, Ucell_t = np.array(variables['t']), np.array(variables['Ucell'])
    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    t_EIS = parameters['t_EIS']

    # Creation of ifc
    ifc_t = np.zeros(len(t))
    for i in range(len(t)):
        ifc_t[i] = current_density(t[i], parameters)

    # Identify the areas where Ucell and ifc can be measured for the EIS: after equilibrium and at each frequency change
    t0_EIS, t_new_start_EIS, tf_EIS, delta_t_break_EIS, delta_t_measurement_EIS = t_EIS
    n_inf = np.where(t_new_start_EIS <= t[0])[0][-1]  # The number of frequency changes which has been mad so far.
    Ucell_EIS_measured = Ucell_t[np.where((t > (t[0] + delta_t_break_EIS[n_inf])) &
                                          (t < (t[0] + delta_t_break_EIS[n_inf] + delta_t_measurement_EIS[n_inf])))]
    ifc_EIS_measured = ifc_t[np.where((t > (t[0] + delta_t_break_EIS[n_inf])) &
                                      (t < (t[0] + delta_t_break_EIS[n_inf] + delta_t_measurement_EIS[n_inf])))]

    # Determination of the Fourier transformation
    N = Ucell_EIS_measured.size  # Number of points used for the Fourier transformation
    Ucell_Fourier = fft(Ucell_EIS_measured)  # Ucell Fourier transformation
    ifc_Fourier = fft(ifc_EIS_measured)  # ifc Fourier transformation
    A_period_t = np.concatenate(
        ([np.abs(Ucell_Fourier)[0] / N], np.abs(Ucell_Fourier[1:N // 2]) * 2 / N))  # Recovery of
    #                                                                             all amplitude values calculated by fft
    A = max(A_period_t[1:])  # Amplitude at the frequency of the perturbation
    freq_t = fftfreq(N)[:N // 2]  # Recovery of all frequency values used by fft
    f = freq_t[np.argmax(A_period_t == A)]  # Recovery of the studied frequency

    return {'Ucell_Fourier': Ucell_Fourier, 'ifc_Fourier': ifc_Fourier, 'A_period_t': A_period_t, 'A': A,
            'freq_t': freq_t, 'f': f, 'N': N}

plot_Bode_amplitude_instructions(f_EIS, type_fuel_cell, ax)

This function adds the instructions for amplitude Bode plots according to the type_input to the ax object.

Parameters:
  • type_fuel_cell (str) –

    Type of fuel cell configuration.

  • ax (Axes) –

    Axes on which the instructions will be added.

Source code in modules/display_modules.py
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
def plot_Bode_amplitude_instructions(f_EIS, type_fuel_cell, ax):
    """This function adds the instructions for amplitude Bode plots according to the type_input to the ax object.

    Parameters
    ----------
    type_fuel_cell : str
        Type of fuel cell configuration.
    ax : matplotlib.axes.Axes
        Axes on which the instructions will be added.
    """

    # Commun instructions
    f_power_min_EIS, f_power_max_EIS, nb_f_EIS, nb_points_EIS = f_EIS  # They are the frequency parameters for the EIS
    #                                                                    simulation.
    ax.set_xscale('log') # set logarithmic scale for the x-axis
    # Configure the appearance of major and minor ticks
    ax.tick_params(axis='both', which='major', size=10, width=1.5, direction='out')
    ax.tick_params(axis='both', which='minor', size=5, width=1.5, direction='out')
    plt.tight_layout()  # Adjust layout to prevent overlap between labels and the figure
    plt.show()  # Show the figure

    # For EH-31 fuel cell
    if type_fuel_cell == "EH-31_1.5" or type_fuel_cell == "EH-31_2.0" or \
            type_fuel_cell == "EH-31_2.25" or type_fuel_cell == "EH-31_2.5":
        ax.xaxis.set_major_locator(LogLocator(base=10.0, numticks=f_power_max_EIS - f_power_min_EIS + 1))
        ax.xaxis.set_minor_locator(LogLocator(base=10.0, subs=np.arange(2, 10) * .1,
                                              numticks=(f_power_max_EIS - f_power_min_EIS + 1) * len(np.arange(2, 10))))
        ax.yaxis.set_major_locator(mpl.ticker.MultipleLocator(30))
        ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(30 / 5))
        ax.set_xlim([10**f_power_min_EIS, 10**f_power_max_EIS])

plot_Bode_phase_instructions(f_EIS, type_fuel_cell, ax)

This function adds the instructions for phase Bode plots according to the type_input to the ax object.

Parameters:
  • type_fuel_cell (str) –

    Type of fuel cell configuration.

  • ax (Axes) –

    Axes on which the instructions will be added.

Source code in modules/display_modules.py
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
def plot_Bode_phase_instructions(f_EIS, type_fuel_cell, ax):
    """This function adds the instructions for phase Bode plots according to the type_input to the ax object.

    Parameters
    ----------
    type_fuel_cell : str
        Type of fuel cell configuration.
    ax : matplotlib.axes.Axes
        Axes on which the instructions will be added.
    """

    # Commun instructions
    f_power_min_EIS, f_power_max_EIS, nb_f_EIS, nb_points_EIS = f_EIS  # They are the frequency parameters for the EIS
    #                                                                    simulation.
    ax.set_xscale('log')  # set logarithmic scale for the x-axis
    if not ax.yaxis_inverted():
        ax.invert_yaxis()  # Invert the y-axis
    # Configure the appearance of major and minor ticks
    ax.tick_params(axis='both', which='major', size=10, width=1.5, direction='out')
    ax.tick_params(axis='both', which='minor', size=5, width=1.5, direction='out')
    plt.tight_layout()  # Adjust layout to prevent overlap between labels and the figure
    plt.show()  # Show the figure

    # For EH-31 fuel cell
    if type_fuel_cell == "EH-31_1.5" or type_fuel_cell == "EH-31_2.0" or \
            type_fuel_cell == "EH-31_2.25" or type_fuel_cell == "EH-31_2.5":
        ax.xaxis.set_major_locator(LogLocator(base=10.0, numticks = f_power_max_EIS-f_power_min_EIS+1))
        ax.xaxis.set_minor_locator(LogLocator(base=10.0, subs=np.arange(2, 10) * .1,
                                              numticks = (f_power_max_EIS-f_power_min_EIS+1)*len(np.arange(2, 10))))
        ax.yaxis.set_major_locator(mpl.ticker.MultipleLocator(5))
        ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(5 / 5))
        ax.set_xlim([10**f_power_min_EIS, 10**f_power_max_EIS])

plot_C_H2(variables, parameters, ax)

This function plots the hydrogen concentration at different spatial localisations, as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the hydrogen concentration will be plotted.

Source code in modules/display_modules.py
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
def plot_C_H2(variables, parameters, ax):
    """This function plots the hydrogen concentration at different spatial localisations, as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the hydrogen concentration will be plotted.
    """

    # Extraction of the parameters
    nb_gc, nb_gdl, nb_mpl, type_current, type_plot = parameters['nb_gc'], parameters['nb_gdl'], parameters['nb_mpl'], parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    C_H2_agc_t = np.array(variables[f'C_H2_agc_{int(np.ceil(nb_gc / 2))}'])[mask]
    C_H2_agdl_t = np.array(variables[f'C_H2_agdl_{int(np.ceil(nb_gdl / 2))}'])[mask]
    C_H2_ampl_t = np.array(variables[f'C_H2_ampl_{int(np.ceil(nb_mpl / 2))}'])[mask]
    C_H2_acl_t = np.array(variables['C_H2_acl'])[mask]

    # Plot the hydrogen concentration at different spatial localisations: C_H2
    ax.plot(t, C_H2_agc_t, color=colors(0))
    ax.plot(t, C_H2_agdl_t, color=colors(1))
    ax.plot(t, C_H2_ampl_t, color=colors(2))
    ax.plot(t, C_H2_acl_t, color=colors(3))
    ax.legend([r'$\mathregular{C_{H_{2},agc}}$', r'$\mathregular{C_{H_{2},agdl}}$', r'$\mathregular{C_{H_{2},ampl}}$',
               r'$\mathregular{C_{H_{2},acl}}$'], loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Hydrogen}$ $\mathbf{concentration}$ $\mathbf{C_{H_{2}}}$ $\mathbf{\left( mol.m^{-3} \right)}$',
                  labelpad=3)

    # Plot instructions
    plot_general_instructions(ax)

plot_C_N2(variables, parameters, ax)

This function plots the nitrogen concentration as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • ax (Axes) –

    Axes on which the nitrogen concentration will be plotted.

Source code in modules/display_modules.py
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
def plot_C_N2(variables, parameters, ax):
    """This function plots the nitrogen concentration as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    ax : matplotlib.axes.Axes
        Axes on which the nitrogen concentration will be plotted.
    """

    # Extraction of the parameters
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    C_N2_a_t = np.array(variables['C_N2_a'])[mask]
    C_N2_c_t = np.array(variables['C_N2_c'])[mask]

    # Plot C_N2
    ax.plot(t, C_N2_a_t, color=colors(6))
    ax.plot(t, C_N2_c_t, color=colors(6))
    ax.legend([r'$\mathregular{C_{N_{2},a}}$', r'$\mathregular{C_{N_{2},c}}$'], loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Nitrogen}$ $\mathbf{concentration}$ $\mathbf{C_{N_{2}}}$ $\mathbf{\left( mol.m^{-3} \right)}$',
                  labelpad=3)

    # Plot instructions
    plot_general_instructions(ax)

plot_C_O2(variables, parameters, ax)

This function plots the oxygen concentration at different spatial localisations, as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the oxygen concentration will be plotted.

Source code in modules/display_modules.py
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
def plot_C_O2(variables, parameters, ax):
    """This function plots the oxygen concentration at different spatial localisations, as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the oxygen concentration will be plotted.
    """

    # Extraction of the parameters
    nb_gc, nb_gdl, nb_mpl, type_current, type_plot = parameters['nb_gc'], parameters['nb_gdl'], parameters['nb_mpl'], parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    C_O2_ccl_t = np.array(variables['C_O2_ccl'])[mask]
    C_O2_cmpl_t = np.array(variables[f'C_O2_cmpl_{int(np.ceil(nb_mpl / 2))}'])[mask]
    C_O2_cgdl_t = np.array(variables[f'C_O2_cgdl_{int(np.ceil(nb_gdl / 2))}'])[mask]
    C_O2_cgc_t = np.array(variables[f'C_O2_cgc_{int(np.ceil(nb_gc / 2))}'])[mask]

    # Plot the oxygen concentration at different spatial localisations: C_O2
    ax.plot(t, C_O2_ccl_t, color=colors(5))
    ax.plot(t, C_O2_cmpl_t, color=colors(6))
    ax.plot(t, C_O2_cgdl_t, color=colors(7))
    ax.plot(t, C_O2_cgc_t, color=colors(8))
    ax.legend([r'$\mathregular{C_{O_{2},ccl}}$', r'$\mathregular{C_{O_{2},cmpl}}$', r'$\mathregular{C_{O_{2},cgdl}}$',
               r'$\mathregular{C_{O_{2},cgc}}$'], loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Oxygen}$ $\mathbf{concentration}$ $\mathbf{C_{O_{2}}}$ $\mathbf{\left( mol.m^{-3} \right)}$',
                  labelpad=3)

    # Plot instructions
    plot_general_instructions(ax)

plot_C_v(variables, parameters, ax)

This function plots the vapor concentrations at different spatial localisations, as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the vapor concentration will be plotted.

Source code in modules/display_modules.py
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
def plot_C_v(variables, parameters, ax):
    """This function plots the vapor concentrations at different spatial localisations, as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the vapor concentration will be plotted.
    """

    # Extraction of the parameter
    nb_gc, nb_gdl, nb_mpl, type_current, type_plot = parameters['nb_gc'], parameters['nb_gdl'], parameters['nb_mpl'], parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    C_v_agc_t = np.array(variables[f'C_v_agc_{int(np.ceil(nb_gc / 2))}'])[mask]
    C_v_agdl_t = np.array(variables[f'C_v_agdl_{int(np.ceil(nb_gdl / 2))}'])[mask]
    C_v_ampl_t = np.array(variables[f'C_v_ampl_{int(np.ceil(nb_mpl / 2))}'])[mask]
    C_v_acl_t = np.array(variables['C_v_acl'])[mask]
    C_v_ccl_t = np.array(variables['C_v_ccl'])[mask]
    C_v_cmpl_t = np.array(variables[f'C_v_cmpl_{int(np.ceil(nb_mpl / 2))}'])[mask]
    C_v_cgdl_t = np.array(variables[f'C_v_cgdl_{int(np.ceil(nb_gdl / 2))}'])[mask]
    C_v_cgc_t = np.array(variables[f'C_v_cgc_{int(np.ceil(nb_gc / 2))}'])[mask]
    T_ccl = np.array(variables['T_ccl'])[mask]

    # Plot the vapor concentrations at different spatial localisations Cv
    C_v_sat_ccl_t = np.array([C_v_sat(T) for T in T_ccl])
    ax.plot(t, C_v_agc_t, color=colors(0))
    ax.plot(t, C_v_agdl_t, color=colors(1))
    ax.plot(t, C_v_ampl_t, color=colors(2))
    ax.plot(t, C_v_acl_t, color=colors(3))
    ax.plot(t, C_v_ccl_t, color=colors(5))
    ax.plot(t, C_v_cmpl_t, color=colors(6))
    ax.plot(t, C_v_cgdl_t, color=colors(7))
    ax.plot(t, C_v_cgc_t, color=colors(8))
    ax.plot(t, C_v_sat_ccl_t, color='k')
    ax.legend([r'$\mathregular{C_{v,agc}}$', r'$\mathregular{C_{v,agdl}}$', r'$\mathregular{C_{v,ampl}}$',
               r'$\mathregular{C_{v,acl}}$', r'$\mathregular{C_{v,ccl}}$', r'$\mathregular{C_{v,cmpl}}$',
               r'$\mathregular{C_{v,cgdl}}$', r'$\mathregular{C_{v,cgc}}$', r'$\mathregular{C_{v,sat,ccl}}$'], loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r"$\mathbf{Vapor}$ $\mathbf{concentration}$ $\mathbf{C_{v}}$ $\mathbf{\left( mol.m^{-3} \right)}$",
                  labelpad=3)

    # Plot instructions
    plot_general_instructions(ax)

plot_EIS_Nyquist_instructions(type_fuel_cell, f_Fourier, x, y, ax)

This function adds the instructions for EIS plots according to the type_input to the ax object.

Parameters:
  • type_fuel_cell (str) –

    Type of fuel cell configuration.

  • f_Fourier (ndarray) –

    Frequency at which the EIS is simulated.

  • x (ndarray) –

    x-axis values for plotting the annotation.

  • y (ndarray) –

    y-axis values for plotting the annotation.

  • ax (Axes) –

    Axes on which the instructions will be added.

Source code in modules/display_modules.py
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
def plot_EIS_Nyquist_instructions(type_fuel_cell, f_Fourier, x, y, ax):
    """This function adds the instructions for EIS plots according to the type_input to the ax object.

    Parameters
    ----------
    type_fuel_cell : str
        Type of fuel cell configuration.
    f_Fourier : numpy.ndarray
        Frequency at which the EIS is simulated.
    x : numpy.ndarray
        x-axis values for plotting the annotation.
    y : numpy.ndarray
        y-axis values for plotting the annotation.
    ax : matplotlib.axes.Axes
        Axes on which the instructions will be added.
    """

    # Commun instructions
    ax.set_aspect('equal', adjustable='box')  # Set orthonormal axis.
    # Configure the appearance of major and minor ticks
    ax.tick_params(axis='both', which='major', size=10, width=1.5, direction='out')
    ax.tick_params(axis='both', which='minor', size=5, width=1.5, direction='out')
    plt.tight_layout()  # Adjust layout to prevent overlap between labels and the figure
    plt.show()  # Show the figure

    # For EH-31 fuel cell
    if type_fuel_cell == "EH-31_1.5" or type_fuel_cell == "EH-31_2.0" or \
            type_fuel_cell == "EH-31_2.25" or type_fuel_cell == "EH-31_2.5":
        # Double charge transfer
        if (f_Fourier >= 70 and f_Fourier <= 80):
            freq_str = str(int(f_Fourier)) + ' Hz'  # Frequency annotation.
            ax.annotate(freq_str, (x, y), textcoords="offset points", xytext=(0, -40), ha='center', fontsize=14,
                        rotation=90, weight='bold')
        # Auxiliary system
        if (f_Fourier >= 0.14 and f_Fourier <= 0.16):
            freq_str = f'{f_Fourier:.2g} Hz'  # Frequency annotation.
            ax.annotate(freq_str, (x, y), textcoords="offset points", xytext=(0, 7), ha='center', fontsize=14,
                        rotation=90, weight='bold')
        if (f_Fourier >= 1.2 and f_Fourier <= 1.4):
            freq_str = f'{f_Fourier:.2g} Hz'  # Frequency annotation.
            ax.annotate(freq_str, (x, y), textcoords="offset points", xytext=(0, 10), ha='center', fontsize=14,
                        rotation=90, weight='bold')
        # Diffusion
        if (f_Fourier >= 0.015 and f_Fourier <= 0.020):
            freq_str = f'{f_Fourier:.2g} Hz'  # Frequency annotation.
            ax.annotate(freq_str, (x, y), textcoords="offset points", xytext=(30, 0), ha='center', fontsize=14,
                        rotation=0, weight='bold')
        if (f_Fourier >= 0.9 and f_Fourier <= 1.1):
            freq_str = f'{f_Fourier:.2g} Hz'  # Frequency annotation.
            ax.annotate(freq_str, (x, y), textcoords="offset points", xytext=(0, 10), ha='center', fontsize=14,
                        rotation=90, weight='bold')
        if (f_Fourier >= 70 and f_Fourier <= 90):
            freq_str = str(int(f_Fourier)) + ' Hz'  # Frequency annotation.
            ax.annotate(freq_str, (x, y), textcoords="offset points", xytext=(0, -40), ha='center', fontsize=14,
                        rotation=90, weight='bold')
        if (f_Fourier >= 10000 and f_Fourier <= 12000):
            freq_str = str(int(f_Fourier)) + ' Hz'  # Frequency annotation.
            ax.annotate(freq_str, (x, y), textcoords="offset points", xytext=(35, 0), ha='center', fontsize=14,
                        rotation=0, weight='bold')
        ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(20))
        ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(20 / 5))
        ax.yaxis.set_major_locator(mpl.ticker.MultipleLocator(10))
        ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(10 / 5))
        ax.set_xlim(30, 200)
        ax.set_ylim(-25, 55)

plot_EIS_curve_Bode_amplitude(parameters, Fourier_results, ax)

This function is used to plot the amplitude Bode diagram of the EIS curves.

Parameters:
  • parameters (dict) –

    Parameters of the fuel cell model.

  • Fourier_results (dict) –

    Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points used in the FT.

  • ax (Axes) –

    Axes on which the amplitude Bode diagram will be plotted.

Source code in modules/display_modules.py
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
def plot_EIS_curve_Bode_amplitude(parameters, Fourier_results, ax):
    """This function is used to plot the amplitude Bode diagram of the EIS curves.

    Parameters
    ----------
    parameters : dict
        Parameters of the fuel cell model.
    Fourier_results : dict
        Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude
        values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the
        perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points
        used in the FT.
    ax : matplotlib.axes.Axes
        Axes on which the amplitude Bode diagram will be plotted.

    """

    # Extraction of the parameters
    i_EIS, ratio_EIS, f_EIS = parameters['i_EIS'], parameters['ratio_EIS'], parameters['f_EIS']
    type_fuel_cell = parameters['type_fuel_cell']
    # Extraction of the Fourier results
    A, f = Fourier_results['A'], Fourier_results['f']

    # Calculation of the impedance of the perturbation
    Z0 = A / (ratio_EIS * (-i_EIS)) * 1e7  # in mΩ.cm². The sign of i is inverted to comply with the standards of EIS,
    #                                        which measure a device under load rather than a current source.

    # Plot the amplitude Bode diagram
    ax.plot(f, np.abs(Z0), 'o', color=colors(1), label='Amplitude Bode diagram')
    ax.set_xlabel(r'$\mathbf{Frequency}$ $\mathbf{(Hz,}$ $\mathbf{logarithmic}$ $\mathbf{scale)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Impedance}$ $\mathbf{amplitude}$ $\mathbf{(m\Omega.cm^{2})}$', labelpad=3)
    #   Plot instructions
    plot_Bode_amplitude_instructions(f_EIS, type_fuel_cell, ax)

plot_EIS_curve_Bode_angle(parameters, Fourier_results, ax)

This function is used to plot the angle Bode diagram. It only works with an entry signal made with a cosinus (not a sinus).

Parameters:
  • Fourier_results (dict) –

    Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points used in the FT.

  • ax (Axes) –

    Axes on which the angle Bode diagram will be plotted.

Source code in modules/display_modules.py
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
def plot_EIS_curve_Bode_angle(parameters, Fourier_results, ax):
    """This function is used to plot the angle Bode diagram. It only works with an entry signal made with a cosinus
    (not a sinus).

    Parameters
    ----------
    Fourier_results : dict
        Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude
        values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the
        perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points
        used in the FT.
    ax : matplotlib.axes.Axes
        Axes on which the angle Bode diagram will be plotted.
    """

    # Extraction of the parameters
    f_EIS, type_fuel_cell = parameters['f_EIS'], parameters['type_fuel_cell']
    # Extraction of the Fourier results
    Ucell_Fourier, ifc_Fourier = Fourier_results['Ucell_Fourier'], Fourier_results['ifc_Fourier']
    A_period_t, A = Fourier_results['A_period_t'], Fourier_results['A']
    f, N = Fourier_results['f'], Fourier_results['N']

    # Calculation of the dephasing values at the frequency of the perturbation
    theta_U_t = np.angle(Ucell_Fourier[0:N // 2])  # Recovery of all dephasing values calculated by fft
    theta_i_t = np.angle(ifc_Fourier[0:N // 2]) + np.pi  # Recovery of all dephasing values calculated by fft.
    #                                                    An angle of pi is added to comply with the standards of EIS,
    #                                                    which measure a device under load rather than a current source.
    theta_U = theta_U_t[np.argmax(A_period_t == A)]  # Dephasing at the frequency of the perturbation
    theta_i = theta_i_t[np.argmax(A_period_t == A)]  # Dephasing at the frequency of the perturbation
    phi_U_i = ((theta_U - theta_i) * 180 / np.pi) % 360 # Dephasing between Ucell and ifc with a value between 0 and 360
    if phi_U_i > 180:
        phi_U_i -= 360 # To have a value between -180 and 180

    # Plot the angle Bode diagram
    ax.plot(f, phi_U_i, 'o', color=colors(2), label='Angle Bode diagram')
    ax.set_xlabel(r'$\mathbf{Frequency}$ $\mathbf{(Hz,}$ $\mathbf{logarithmic}$ $\mathbf{scale)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Phase}$ $\mathbf{(^\circ)}$', labelpad=3)
    #   Plot instructions
    plot_Bode_phase_instructions(f_EIS, type_fuel_cell, ax)

plot_EIS_curve_Nyquist(parameters, Fourier_results, ax)

This function is used to plot the Nyquist diagram of the EIS curves.

Parameters:
  • parameters (dict) –

    Parameters of the fuel cell model.

  • Fourier_results (dict) –

    Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points used in the FT.

  • ax (Axes) –

    Axes on which the Nyquist diagram will be plotted.

Source code in modules/display_modules.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
def plot_EIS_curve_Nyquist(parameters, Fourier_results, ax):
    """
    This function is used to plot the Nyquist diagram of the EIS curves.

    Parameters
    ----------
    parameters : dict
        Parameters of the fuel cell model.
    Fourier_results : dict
        Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude
        values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the
        perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points
        used in the FT.
    ax : matplotlib.axes.Axes
        Axes on which the Nyquist diagram will be plotted.
    """

    # Extraction of the parameters
    i_EIS, ratio_EIS, type_fuel_cell = parameters['i_EIS'], parameters['ratio_EIS'], parameters['type_fuel_cell']
    # Extraction of the Fourier results
    Ucell_Fourier, ifc_Fourier = Fourier_results['Ucell_Fourier'], Fourier_results['ifc_Fourier']
    f_Fourier = Fourier_results['f']
    A_period_t, A, N = Fourier_results['A_period_t'], Fourier_results['A'], Fourier_results['N']

    # Calculation of the real and imaginary component of the impedance for each period
    Z0 = A / (ratio_EIS * (-i_EIS)) * 1e7  # Impedance of the perturbation in mΩ.cm². The sign of i is inverted to
    #                  comply with the standards of EIS, which measure a device under load rather than a current source.
    theta_U_t = np.angle(Ucell_Fourier[0:N // 2])  # Recovery of all dephasing values calculated by fft
    theta_i_t = np.angle(ifc_Fourier[0:N // 2])  # Recovery of all dephasing values calculated by fft
    theta_U = theta_U_t[np.argmax(A_period_t == A)]  # Dephasing at the frequency of the perturbation
    theta_i = theta_i_t[np.argmax(A_period_t == A)]  # Dephasing at the frequency of the perturbation
    Z_real = Z0 * np.cos(theta_U - theta_i)  # Real component of the impedance for each period
    Z_imag = Z0 * np.sin(theta_U - theta_i)  # Imaginary component of the impedance for each period

    # Plot the Nyquist diagram
    ax.plot(Z_real, -Z_imag, 'o', color=colors(0), label='Nyquist diagram')
    ax.set_xlabel(r'$\mathbf{Z_{real}}$ $\mathbf{(m\Omega.cm^{2})}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{-Z_{imag}}$ $\mathbf{(m\Omega.cm^{2})}$', labelpad=3)
    #       Plot instructions
    plot_EIS_Nyquist_instructions(type_fuel_cell, f_Fourier, Z_real, -Z_imag, ax)

plot_EIS_curve_tests(variables, operating_inputs, parameters, Fourier_results)

This function is used to test the accuracy of the EIS results. It compares the reconstructed Ucell_Fourier(t) from the Fourier transformation with the current density ifc(t), and displays Ucell(t) given by the model with the reconstructed Ucell_Fourier(t).

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • Fourier_results (dict) –

    Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points used in the FT.

Source code in modules/display_modules.py
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
def plot_EIS_curve_tests(variables, operating_inputs, parameters, Fourier_results):
    """This function is used to test the accuracy of the EIS results. It compares the reconstructed Ucell_Fourier(t)
    from the Fourier transformation with the current density ifc(t), and displays Ucell(t) given by the model with the
    reconstructed Ucell_Fourier(t).

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    Fourier_results : dict
        Dictionary containing the Fourier transformation (FT) of the cell voltage and the current density, all amplitude
        values of the cell voltage calculated by the FT, the amplitude of the cell voltage at the frequency of the
        perturbation, all frequency values used vy the FT, the frequency of the perturbation, and the number of points
        used in the FT.
    """

    # Extraction of the variables
    t, Ucell_t = np.array(variables['t']), variables['Ucell']
    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    i_EIS, ratio_EIS = parameters['i_EIS'], parameters['ratio_EIS']
    t_EIS, f_EIS = parameters['t_EIS'], parameters['f_EIS']
    # Extraction of the Fourier results
    Ucell_Fourier, ifc_Fourier = Fourier_results['Ucell_Fourier'], Fourier_results['ifc_Fourier']
    A_period_t, A = Fourier_results['A_period_t'], Fourier_results['A']
    f, N = Fourier_results['f'], Fourier_results['N']

    # Reconstructed Ucell with a cosinus form, and comparison of its form with the current density one.
    t0_EIS, t_new_start_EIS, tf_EIS, delta_t_break_EIS, delta_t_measurement_EIS = t_EIS
    f_power_min_EIS, f_power_max_EIS, nb_f_EIS, nb_points_EIS = f_EIS
    n_inf = np.where(t_new_start_EIS <= t[0])[0][-1]  # The number of frequency changes which has been made.
    f_current = np.logspace(f_power_min_EIS, f_power_max_EIS, num=nb_f_EIS)
    theta_U_t = np.angle(Ucell_Fourier[0:N // 2])  # Recovery of all dephasing values calculated by fft
    theta_i_t = np.angle(ifc_Fourier[0:N // 2])  # Recovery of all dephasing values calculated by fft
    theta_U = theta_U_t[np.argmax(A_period_t == A)]  # Dephasing at the frequency of the perturbation
    theta_i = theta_i_t[np.argmax(A_period_t == A)]  # Dephasing at the frequency of the perturbation
    print("Ucell:", round(A_period_t[0], 4), ' + ', round(A, 6), " * np.cos(2*np.pi*", round(f, 4), "*t + ",
          round(theta_U, 4), "). ")
    print("Current:", i_EIS, ' + ', ratio_EIS * i_EIS, " * np.cos(2*np.pi*", round(f_current[n_inf], 4), "*t + ",
          round(theta_i, 4), "). \n")

    # Display ifc(t)
    plt.figure(3)
    plt.subplot(2, 1, 1)
    #   Creation of ifc_t
    n = len(t)
    ifc_t = np.zeros(n)
    for i in range(n):  # Conversion in A/cm²
        ifc_t[i] = current_density(t[i], parameters) / 1e4
    #   Plot of ifc_t
    plt.plot(t, ifc_t, color='blue', label='ifc')
    plt.xlabel('Time (s)')
    plt.ylabel('Current density (A/cm²)')
    plt.title('The current density\nbehaviour over time')

    # Display Ucell(t) and compare it with the reconstructed Ucell_Fourier(t) from the Fourier transformation
    plt.subplot(2, 1, 2)
    Ucell_Fourier = A_period_t[0] + A * np.cos(2 * np.pi * f * t + theta_U)
    plt.plot(t, Ucell_t, color='blue', label='Ucell')
    plt.plot(t, Ucell_Fourier, color='black', label='Ucell_Fourier')
    plt.xlabel('Time (s)')
    plt.ylabel('Cell voltage (V)')
    plt.title('The cell voltage\nbehaviour over time')

plot_J(variables, parameters, ax)

This function plots the sorption and dissolved water flows as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the flows will be plotted.

Source code in modules/display_modules.py
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
def plot_J(variables, parameters, ax):
    """This function plots the sorption and dissolved water flows as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the flows will be plotted.
    """
    # Extraction of the operating inputs and the parameters
    Hacl, Hccl = parameters['Hacl'], parameters['Hccl']
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    S_abs_acl_t = np.array(variables['S_abs_acl'])[mask]
    S_abs_ccl_t = np.array(variables['S_abs_ccl'])[mask]
    J_lambda_acl_mem_t = np.array(variables['J_lambda_acl_mem'])[mask]
    J_lambda_mem_ccl_t = np.array(variables['J_lambda_mem_ccl'])[mask]

    # Plot the sorption and dissolved water flows: J
    J_abs_acl, J_abs_ccl = S_abs_acl_t * Hacl, S_abs_ccl_t * Hccl  # Conversion in mol.m⁻².s⁻¹ for comparison
    ax.plot(t, J_abs_acl, color=colors(2))
    ax.plot(t, J_lambda_acl_mem_t, color=colors(3))
    ax.plot(t, J_abs_ccl, color=colors(4))
    ax.plot(t, J_lambda_mem_ccl_t, color=colors(7))
    ax.legend([r'$\mathregular{J_{abs,acl}}$', r'$\mathregular{J_{\lambda,mem,acl}}$', r'$\mathregular{J_{abs,ccl}}$',
               r'$\mathregular{J_{\lambda,mem,ccl}}$'], loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Flows}$ $\mathbf{J}$ $\mathbf{\left( mol.m^{-2}.s^{-1} \right)}$', labelpad=3)
    ax.ticklabel_format(style='scientific', axis='y', scilimits=(0, 0))

    # Plot instructions
    plot_general_instructions(ax)

plot_P(variables, operating_inputs, parameters, ax)

This function plots the pressure at different spatial localisations as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the pressure will be plotted.

Source code in modules/display_modules.py
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
def plot_P(variables, operating_inputs, parameters, ax):
    """This function plots the pressure at different spatial localisations as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the pressure will be plotted.
    """

    # Extraction of the parameters
    Pa_des, Pc_des = operating_inputs['Pa_des'], operating_inputs['Pc_des']
    nb_gc, type_current, type_plot = parameters['nb_gc'], parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])
    nb_gc_mid = int(np.ceil(nb_gc / 2))
    C_v_agc = np.array(variables[f'C_v_agc_{nb_gc_mid}'])
    C_H2_agc = np.array(variables[f'C_H2_agc_{nb_gc_mid}'])
    C_N2_agc = np.array(variables[f'C_N2_agc_{nb_gc_mid}'])
    T_agc = np.array(variables[f'T_agc_{nb_gc_mid}'])
    C_v_cgc = np.array(variables[f'C_v_cgc_{nb_gc_mid}'])
    C_O2_cgc = np.array(variables[f'C_O2_cgc_{nb_gc_mid}'])
    C_N2_cgc = np.array(variables[f'C_N2_cgc_{nb_gc_mid}'])
    T_cgc = np.array(variables[f'T_cgc_{nb_gc_mid}'])
    Pagc_t = (C_v_agc + C_H2_agc + C_N2_agc) * R * T_agc / 1e5  # Conversion in bar
    Pcgc_t = (C_v_cgc + C_O2_cgc + C_N2_cgc) * R * T_cgc / 1e5 # Conversion in bar
    if parameters['type_auxiliary'] != 'no_auxiliary':
        Pasm_t = np.array(variables['Pasm'])[mask] / 1e5 # Conversion in bar
        Paem_t = np.array(variables['Paem'])[mask] / 1e5 # Conversion in bar
        Pcsm_t = np.array(variables['Pcsm'])[mask] / 1e5 # Conversion in bar
        Pcem_t = np.array(variables['Pcem'])[mask] / 1e5 # Conversion in bar
    else: # parameters['type_auxiliary'] == 'no_auxiliary'
        Pa_in_t = np.array(variables['Pa_in']) / 1e5 # Conversion in bar
        Pa_out_t = np.array([Pa_des] * len(t)) / 1e5 # Conversion in bar
        Pc_in_t = np.array(variables['Pc_in']) / 1e5 # Conversion in bar
        Pc_out_t = np.array([Pc_des] * len(t)) / 1e5 # Conversion in bar

    # Plot the pressure at different spatial localisations: P
    ax.plot(t, Pagc_t, color=colors(0))
    ax.plot(t, Pcgc_t, color=colors(6))
    if parameters['type_auxiliary'] != 'no_auxiliary':
        ax.plot(t, Pasm_t, color=colors(7))
        ax.plot(t, Paem_t, color=colors(8))
        ax.plot(t, Pcsm_t, color=colors(9))
        ax.plot(t, Pcem_t, color=colors(10))
    else: # parameters['type_auxiliary'] == 'no_auxiliary'
        ax.plot(t, Pa_in_t, color=colors(7))
        ax.plot(t, Pa_out_t, color=colors(8))
        ax.plot(t, Pc_in_t, color=colors(9))
        ax.plot(t, Pc_out_t, color=colors(10))
    if parameters['type_auxiliary'] != 'no_auxiliary':
        ax.legend([r'$\mathregular{P_{agc}}$', r'$\mathregular{P_{cgc}}$', r'$\mathregular{P_{asm}}$',
                   r'$\mathregular{P_{aem}}$', r'$\mathregular{P_{csm}}$', r'$\mathregular{P_{cem}}$'], loc='best')
    else: # parameters['type_auxiliary'] == 'no_auxiliary'
        ax.legend([r'$\mathregular{P_{agc}}$', r'$\mathregular{P_{cgc}}$', r'$\mathregular{P_{a,in}}$',
                  r'$\mathregular{P_{a,out}}$', r'$\mathregular{P_{c,in}}$', r'$\mathregular{P_{c,out}}$'], loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Pressure}$ $\mathbf{P}$ $\mathbf{\left( bar \right)}$', labelpad=3)
    ax.ticklabel_format(style='scientific', axis='y', scilimits=(0, 0))

    # Plot instructions
    plot_general_instructions(ax)

plot_Phi_a(variables, operating_inputs, parameters, ax)

This function plots the humidity at the anode side, at different spatial localisations, as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • ax (Axes) –

    Axes on which the humidity will be plotted.

Source code in modules/display_modules.py
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
def plot_Phi_a(variables, operating_inputs, parameters, ax):
    """This function plots the humidity at the anode side, at different spatial localisations, as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    ax : matplotlib.axes.Axes
        Axes on which the humidity will be plotted.
    """

    # Extraction of the operating inputs and parameters
    Phi_a_des = operating_inputs['Phi_a_des']
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    C_v_agc_t = np.array(variables['C_v_agc'])[mask]
    T_agc_t = np.array(variables['T_agc'])[mask]
    Phi_asm_t = np.array(variables['Phi_asm'])[mask]
    Phi_aem_t = np.array(variables['Phi_aem'])[mask]

    # Calculate the humidity Phi
    Phi_agc_t = C_v_agc_t * R * T_agc_t / Psat(T_agc_t)

    # Plot the humidity at different spatial localisations: Phi
    ax.plot(t, Phi_agc_t, color=colors(0), label=r'$\mathregular{\Phi_{agc}}$')
    ax.plot(t, Phi_asm_t, color=colors(1), label=r'$\mathregular{\Phi_{asm}}$')
    ax.plot(t, Phi_aem_t, color=colors(2), label=r'$\mathregular{\Phi_{aem}}$')
    ax.plot(t, np.array([Phi_a_des]*len(t)), color='black', label=r'$\mathregular{\Phi_{a,des}}$')
    ax.legend(loc='center right', bbox_to_anchor=(1, 0.67))
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Humidity}$ $\mathbf{at}$ $\mathbf{the}$ $\mathbf{anode}$ $\mathbf{side}$ $\mathbf{\Phi}$',
                  labelpad=3)

    # Plot instructions
    plot_general_instructions(ax)

plot_Phi_c(variables, operating_inputs, parameters, ax)

This function plots the humidity, at the cathode side, at different spatial localisations as a function of time.

Parameters:
  • ax

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • ax (Axes) –

    Axes on which the humidity will be plotted.

Source code in modules/display_modules.py
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
def plot_Phi_c(variables, operating_inputs, parameters, ax):
    """This function plots the humidity, at the cathode side, at different spatial localisations as a function of time.

    Parameters
    ----------
    ax.plot(t, np.array([Phi_a_des]*len(t)), color='black', label=r'$\mathregular{\Phi_{a,des}}$')
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    ax : matplotlib.axes.Axes
        Axes on which the humidity will be plotted.
    """

    # Extraction of the operating inputs and parameters
    Phi_c_des = operating_inputs['Phi_c_des']
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    C_v_cgc_t = np.array(variables['C_v_cgc'])[mask]
    T_cgc_t = np.array(variables['T_cgc'])[mask]
    Phi_csm_t = np.array(variables['Phi_csm'])[mask]
    Phi_cem_t = np.array(variables['Phi_cem'])[mask]

    # Calculate the humidity Phi
    Phi_cgc_t = C_v_cgc_t * R * T_cgc_t / Psat(T_cgc_t)

    # Plot the humidity at different spatial localisations: Phi
    ax.plot(t, Phi_cgc_t, color=colors(0), label=r'$\mathregular{\Phi_{cgc}}$')
    ax.plot(t, Phi_csm_t, color=colors(1), label=r'$\mathregular{\Phi_{csm}}$')
    ax.plot(t, Phi_cem_t, color=colors(2), label=r'$\mathregular{\Phi_{cem}}$')
    ax.plot(t, np.array([Phi_c_des]*len(t)), color='black', label=r'$\mathregular{\Phi_{c,des}}$')
    ax.legend(loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Humidity}$ $\mathbf{at}$ $\mathbf{the}$ $\mathbf{cathode}$ $\mathbf{side}$ $\mathbf{\Phi}$',
                  labelpad=3)

    # Plot instructions
    plot_general_instructions(ax)

plot_Phi_des(variables, operating_inputs, parameters, ax)

This function plots the controlled or uncontrolled desired humidity at the anode and cathode as a function of the current density.

Parameters ax.plot(t, np.array([Phi_c_des]*len(t)), color='black', label=r'$\mathregular{\Phi_{c,des}}$') variables : dict Variables calculated by the solver. They correspond to the fuel cell internal states. operating_inputs : dict Operating inputs of the fuel cell. parameters : dict Parameters of the fuel cell model. ax : matplotlib.axes.Axes Axes on which the humidity will be plotted.

Source code in modules/display_modules.py
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
def plot_Phi_des(variables, operating_inputs, parameters, ax):
    """This function plots the controlled or uncontrolled desired humidity at the anode and cathode as a function of the
    current density.

    Parameters
    ax.plot(t, np.array([Phi_c_des]*len(t)), color='black', label=r'$\mathregular{\Phi_{c,des}}$')
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the humidity will be plotted.
    """

    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    pola_current_parameters = parameters['pola_current_parameters']
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    if parameters['type_control'] == "Phi_des":
        Phi_a_des_t = variables['Phi_a_des'][mask]
        Phi_c_des_t = variables['Phi_c_des'][mask]
        ax.set_ylabel(r'$\mathbf{Controlled}$ $\mathbf{inlet}$ $\mathbf{humidity}$  $\mathbf{\Phi_{des}}$', labelpad=3)
    else:
        Phi_a_des_t = np.array([operating_inputs['Phi_a_des']] * len(t))
        Phi_c_des_t = np.array([operating_inputs['Phi_c_des']] * len(t))
        ax.set_ylabel(r'$\mathbf{Uncontrolled}$ $\mathbf{inlet}$ $\mathbf{humidity}$ $\mathbf{\Phi_{des}}$', labelpad=3)

    # Plot Phi_des
    n = len(t)
    ifc_t = np.zeros(n)
    for i in range(n):  # Creation of ifc_t
        ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²

    # Recovery of the internal states from the model after each stack stabilisation
    delta_t_ini_pola = pola_current_parameters['delta_t_ini_pola']
    delta_t_load_pola = pola_current_parameters['delta_t_load_pola']
    delta_t_break_pola = pola_current_parameters['delta_t_break_pola']
    nb_loads = int(pola_current_parameters['i_max_pola'] / pola_current_parameters['delta_i_pola'])  # Number of loads
    ifc_discretized_t = np.zeros(nb_loads)
    Phi_a_des_discretized_t, Phi_c_des_discretized_t = np.zeros(nb_loads), np.zeros(nb_loads)
    for i in range(nb_loads):
        t_load = delta_t_ini_pola + (i + 1) * (delta_t_load_pola + delta_t_break_pola)  # time for measurement
        idx = (np.abs(t - t_load)).argmin()  # the corresponding index
        ifc_discretized_t[i] = ifc_t[idx]  # the last value at the end of each load
        Phi_a_des_discretized_t[i] = Phi_a_des_t[idx]  # the last value at the end of each load
        Phi_c_des_discretized_t[i] = Phi_c_des_t[idx]  # the last value at the end of each load

    ax.scatter(ifc_discretized_t, Phi_c_des_discretized_t, color=colors(6), label=r'$\mathregular{\Phi_{c,des}}$')
    ax.set_xlabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                  labelpad=3)
    if parameters['type_auxiliary'] == "forced-convective_cathode_with_flow-through_anode" or \
       parameters['type_auxiliary'] == "no_auxiliary":
        ax.scatter(ifc_discretized_t, Phi_a_des_discretized_t, color=colors(0), label=r'$\mathregular{\Phi_{a,des}}$')
        ax.legend([r'$\mathregular{\Phi_{a,des}}$', r'$\mathregular{\Phi_{c,des}}$'], loc='best')
    else:
        ax.legend([r'$\mathregular{\Phi_{c,des}}$'], loc='best')

    # Plot instructions
    plot_general_instructions(ax)

plot_Re_nb(variables, parameters, ax)

This function plots the Reynold number at the center of the AGC and the CGC as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • ax (Axes) –

    Axes on which the pressure will be plotted.

Source code in modules/display_modules.py
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
def plot_Re_nb(variables, parameters, ax):
    """This function plots the Reynold number at the center of the AGC and the CGC as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    ax : matplotlib.axes.Axes
        Axes on which the pressure will be plotted.
    """

    # Extraction of the parameters
    Hcgc, Wcgc = parameters['Hcgc'], parameters['Wcgc']
    nb_gc, type_current, type_plot = parameters['nb_gc'], parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])
    v_a_in_t = np.array(variables['v_a_in'])
    v_c_in_t = np.array(variables['v_c_in'])
    C_v_agc_t = np.array(variables['C_v_agc_1'])
    C_v_cgc_t = np.array(variables['C_v_cgc_1'])
    C_H2_agc_t = np.array(variables['C_H2_agc_1'])
    C_O2_cgc_t = np.array(variables['C_O2_cgc_1'])
    C_N2_agc_t = np.array(variables['C_N2_agc_1'])
    C_N2_cgc_t = np.array(variables['C_N2_cgc_1'])
    T_agc_t = np.array(variables['T_agc_1'])
    T_cgc_t = np.array(variables['T_cgc_1'])

    # Calculation of the Reynold Number
    d_pipe = np.sqrt(4 * Hcgc * Wcgc / np.pi)
    P_agc = (C_v_agc_t + C_H2_agc_t + C_N2_agc_t) * R * T_agc_t
    P_cgc = (C_v_cgc_t + C_O2_cgc_t + C_N2_cgc_t) * R * T_cgc_t
    M_agc = C_v_agc_t * R * T_agc_t / P_agc * M_H2O + \
            C_H2_agc_t * R * T_agc_t / P_agc * M_H2 + \
            C_N2_agc_t * R * T_agc_t / P_agc * M_N2
    M_cgc = C_v_cgc_t * R * T_cgc_t / P_cgc * M_H2O + \
            C_O2_cgc_t * R * T_cgc_t / P_cgc * M_O2 + \
            C_N2_cgc_t * R * T_cgc_t / P_cgc * M_N2
    rho_agc = P_agc / (R * T_agc_t) * M_agc
    rho_cgc = P_cgc / (R * T_cgc_t) * M_cgc
    x_H2O_v_agc = C_v_agc_t / (C_v_agc_t + C_H2_agc_t + C_N2_agc_t)
    x_H2O_v_cgc = C_v_cgc_t / (C_v_cgc_t + C_O2_cgc_t + C_N2_cgc_t)
    y_H2_agc = C_H2_agc_t / (C_H2_agc_t + C_N2_agc_t)
    y_O2_cgc = C_O2_cgc_t / (C_O2_cgc_t + C_N2_cgc_t)
    mu_agc = mu_mixture_gases(['H2O_v', 'H2', 'N2'],
                              [x_H2O_v_agc, y_H2_agc * (1 - x_H2O_v_agc), (1 - y_H2_agc) * (1 - x_H2O_v_agc)],
                              T_agc_t)
    mu_cgc = mu_mixture_gases(['H2O_v', 'O2', 'N2'],
                              [x_H2O_v_cgc, y_O2_cgc * (1 - x_H2O_v_cgc), (1 - y_O2_cgc) * (1 - x_H2O_v_cgc)],
                              T_cgc_t)
    Re_nb_a_t = (rho_agc * v_a_in_t * d_pipe) / mu_agc  # Reynolds number at the anode side
    Re_nb_c_t = (rho_cgc * v_c_in_t * d_pipe) / mu_cgc  # Reynolds number at the anode side

    # Plot the pressure at different spatial localisations: P
    ax.plot(t, Re_nb_a_t, color=colors(0))
    ax.plot(t, Re_nb_c_t, color=colors(6))
    ax.legend([r'$\mathregular{Re_{a}}$', r'$\mathregular{Re_{c}}$'], loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Reynold}$ $\mathbf{number}$ $\mathbf{at}$ $\mathbf{the}$ $\mathbf{inlet,}$ $\mathbf{Re}$', labelpad=3)
    ax.ticklabel_format(style='scientific', axis='y', scilimits=(0, 0))

    # Plot instructions
    plot_general_instructions(ax)

plot_T(variables, operating_inputs, parameters, ax)

This function plots the vapor concentrations at different spatial localisations, as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the vapor concentration will be plotted.

Source code in modules/display_modules.py
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
def plot_T(variables, operating_inputs, parameters, ax):
    """This function plots the vapor concentrations at different spatial localisations, as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the vapor concentration will be plotted.
    """

    # Extraction of the operating inputs and parameters
    current_density = operating_inputs['current_density']
    T_des = operating_inputs['T_des']
    nb_gc, nb_gdl, nb_mpl = parameters['nb_gc'], parameters['nb_gdl'], parameters['nb_mpl']
    pola_current_parameters = parameters['pola_current_parameters']
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables and the operating inputs
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    T_agc_t = np.array(variables[f'T_agc_{int(np.ceil(nb_gc / 2))}'])[mask] - 273.15 # Conversion in °C.
    T_agdl_t = np.array(variables[f'T_agdl_{int(np.ceil(nb_gdl / 2))}'])[mask] - 273.15 # Conversion in °C.
    T_ampl_t = np.array(variables[f'T_ampl_{int(np.ceil(nb_mpl / 2))}'])[mask] - 273.15 # Conversion in °C.
    T_acl_t = np.array(variables['T_acl'])[mask] - 273.15  # Conversion in °C.
    T_mem_t = np.array(variables['T_mem'])[mask] - 273.15 # Conversion in °C.
    T_ccl_t = np.array(variables['T_ccl'])[mask] - 273.15 # Conversion in °C.
    T_cmpl_t = np.array(variables[f'T_cmpl_{int(np.ceil(nb_mpl / 2))}'])[mask] - 273.15  # Conversion in °C.
    T_cgdl_t = np.array(variables[f'T_cgdl_{int(np.ceil(nb_gdl / 2))}'])[mask] - 273.15 # Conversion in °C.
    T_cgc_t = np.array(variables[f'T_cgc_{int(np.ceil(nb_gc / 2))}'])[mask] - 273.15 # Conversion in °C.

    # Plot the temperature at different spatial localisations
    if type_current == "polarization":
        n = len(t)
        ifc_t = np.zeros(n)
        for i in range(n):  # Creation of i_fc
            ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²
        # Recovery of the internal states from the model after each stack stabilisation
        delta_t_ini_pola = pola_current_parameters['delta_t_ini_pola']
        delta_t_load_pola = pola_current_parameters['delta_t_load_pola']
        delta_t_break_pola = pola_current_parameters['delta_t_break_pola']
        nb_loads = int(pola_current_parameters['i_max_pola'] / pola_current_parameters['delta_i_pola']) # Number of loads
        ifc_discretized_t = np.zeros(nb_loads)
        T_agc_discretized_t, T_agdl_discretized_t, T_ampl_discretized_t, T_acl_discretized_t = [np.zeros(nb_loads)] * 4
        T_mem_discretized_t, T_ccl_discretized_t, T_cmpl_discretized_t, T_cgdl_discretized_t = [np.zeros(nb_loads)] * 4
        T_cgc_discretized_t = np.zeros(nb_loads)
        for i in range(nb_loads):
            t_load = delta_t_ini_pola + (i + 1) * (delta_t_load_pola + delta_t_break_pola)  # time for measurement
            idx = (np.abs(t - t_load)).argmin()  # the corresponding index
            ifc_discretized_t[i] = ifc_t[idx]  # the last value at the end of each load
            T_agc_discretized_t[i] = T_agc_t[idx] # the last value at the end of each load
            T_agdl_discretized_t[i] = T_agdl_t[idx]  # the last value at the end of each load
            T_ampl_discretized_t[i] = T_ampl_t[idx]  # the last value at the end of each load
            T_acl_discretized_t[i] = T_acl_t[idx]  # the last value at the end of each load
            T_mem_discretized_t[i] = T_mem_t[idx]  # the last value at the end of each load
            T_ccl_discretized_t[i] = T_ccl_t[idx]  # the last value at the end of each load
            T_cmpl_discretized_t[i] = T_cmpl_t[idx]  # the last value at the end of each load
            T_cgdl_discretized_t[i] = T_cgdl_t[idx]  # the last value at the end of each load
            T_cgc_discretized_t[i] = T_cgc_t[idx]  # the last value at the end of each load
        T_des_discretized_t = np.array([T_des - 273.15] * len(ifc_discretized_t))
        ax.scatter(ifc_discretized_t, T_agc_discretized_t, marker='o', color=colors(0))
        ax.scatter(ifc_discretized_t, T_agdl_discretized_t, marker='o', color=colors(1))
        ax.scatter(ifc_discretized_t, T_ampl_discretized_t, marker='o', color=colors(2))
        ax.scatter(ifc_discretized_t, T_acl_discretized_t, marker='o', color=colors(3))
        ax.scatter(ifc_discretized_t, T_mem_discretized_t, marker='o', color=colors(4))
        ax.scatter(ifc_discretized_t, T_ccl_discretized_t, marker='o', color=colors(5))
        ax.scatter(ifc_discretized_t, T_cmpl_discretized_t, marker='o', color=colors(6))
        ax.scatter(ifc_discretized_t, T_cgdl_discretized_t, marker='o', color=colors(7))
        ax.scatter(ifc_discretized_t, T_cgc_discretized_t, marker='o', color=colors(8))
        ax.scatter(ifc_discretized_t, T_des_discretized_t, marker='o', color='k')
        ax.set_xlabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                      labelpad=3)
    else:
        T_des_t = np.array([T_des - 273.15] * len(t))
        ax.plot(t, T_agc_t, color=colors(0))
        ax.plot(t, T_agdl_t, color=colors(1))
        ax.plot(t, T_ampl_t, color=colors(2))
        ax.plot(t, T_acl_t, color=colors(3))
        ax.plot(t, T_mem_t, color=colors(4))
        ax.plot(t, T_ccl_t, color=colors(5))
        ax.plot(t, T_cmpl_t, color=colors(6))
        ax.plot(t, T_cgdl_t, color=colors(7))
        ax.plot(t, T_cgc_t, color=colors(8))
        ax.plot(t, T_des_t, color='k')
        ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.legend([r'$\mathregular{T_{agc}}$', r'$\mathregular{T_{agdl}}$', r'$\mathregular{T_{ampl}}$',
               r'$\mathregular{T_{acl}}$', r'$\mathregular{T_{mem}}$', r'$\mathregular{T_{ccl}}$',
               r'$\mathregular{T_{cmpl}}$', r'$\mathregular{T_{cgdl}}$', r'$\mathregular{T_{cgc}}$',
               r'$\mathregular{T_{des}}$'], loc='best')
    ax.set_ylabel(r"$\mathbf{Temperature}$ $\mathbf{T}$ $\mathbf{\left( °C \right)}$", labelpad=3)

    # Plot instructions
    plot_general_instructions(ax)

plot_Ucell(variables, parameters, ax)

This function plots the cell voltage as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • ax (Axes) –

    Axes on which the cell voltage will be plotted.

Source code in modules/display_modules.py
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
def plot_Ucell(variables, parameters, ax):
    """This function plots the cell voltage as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    ax : matplotlib.axes.Axes
        Axes on which the cell voltage will be plotted.
    """

    # Extraction of the parameters
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    Ucell_t = np.array(variables['Ucell'])[mask]

    # Plot the cell voltage: Ucell
    ax.plot(t, Ucell_t, color=colors(0), label=r'$\mathregular{U_{cell}}$')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Cell}$ $\mathbf{voltage}$ $\mathbf{U_{cell}}$ $\mathbf{\left( V \right)}$', labelpad=3)
    ax.legend([r'$\mathregular{U_{cell}}$'], loc='best')

    # Plot instructions
    plot_general_instructions(ax)

plot_cell_efficiency(variables, operating_inputs, parameters, n, ax)

This function plots the fuel cell efficiency eta_fc as a function of the current density.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • n (int) –

    Number of points used to plot the fuel cell efficiency.

  • ax (Axes) –

    Axes on which the fuel cell efficiency will be plotted.

Source code in modules/display_modules.py
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
def plot_cell_efficiency(variables, operating_inputs, parameters, n, ax):
    """This function plots the fuel cell efficiency eta_fc as a function of the current density.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    n : int
        Number of points used to plot the fuel cell efficiency.
    ax : matplotlib.axes.Axes
        Axes on which the fuel cell efficiency will be plotted.
    """

    # Extraction of the variables
    t, Ucell_t, lambda_mem_t = variables['t'], variables['Ucell'], variables['lambda_mem']
    C_H2_acl_t, C_O2_ccl_t = variables['C_H2_acl'], variables['C_O2_ccl']
    T_acl_t, T_mem_t, T_ccl_t = variables['T_acl'], variables['T_mem'], variables['T_ccl']
    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    Hmem, Hacl, Hccl, kappa_co = parameters['Hmem'], parameters['Hacl'], parameters['Hccl'], parameters['kappa_co']
    type_fuel_cell, type_current = parameters['type_fuel_cell'], parameters['type_current']
    type_auxiliary, type_control = parameters['type_auxiliary'], parameters['type_control']

    # Creation of the fuel cell efficiency: eta_fc
    ifc_t, Pfc_t, eta_fc_t = np.zeros(n), np.zeros(n), np.zeros(n)
    for i in range(n):
        ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²
        Pfc_t[i] = Ucell_t[i] * ifc_t[i]
        Ueq = E0 - 8.5e-4 * (T_ccl_t[i] - 298.15) + \
              R * T_ccl_t[i] / (2 * F) * (np.log(R * T_acl_t[i] * C_H2_acl_t[i] / Pref) +
                                          0.5 * np.log(R * T_ccl_t[i] * C_O2_ccl_t[i] / Pref))
        T_acl_mem_ccl = average([T_acl_t[i], T_mem_t[i], T_ccl_t[i]],
                        weights=[Hacl / (Hacl + Hmem + Hccl), Hmem / (Hacl + Hmem + Hccl), Hccl / (Hacl + Hmem + Hccl)])
        i_H2 = 2 * F * R * T_acl_mem_ccl / Hmem * C_H2_acl_t[i] * k_H2(lambda_mem_t[i], T_mem_t[i], kappa_co)
        i_O2 = 4 * F * R * T_acl_mem_ccl / Hmem * C_O2_ccl_t[i] * k_O2(lambda_mem_t[i], T_mem_t[i], kappa_co)
        i_n = (i_H2 + i_O2) / 1e4  # Conversion in A/cm²
        eta_fc_t[i] = Pfc_t[i] / (Ueq * (ifc_t[i] + i_n))

    # Plot of the fuel cell efficiency: eta_fc
    plot_specific_line(ifc_t, eta_fc_t, type_fuel_cell, type_current, type_auxiliary, type_control, None, ax)
    ax.set_xlabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                  labelpad=0)
    ax.set_ylabel(r'$\mathbf{Fuel}$ $\mathbf{cell}$ $\mathbf{efficiency}$ $\mathbf{\eta_{fc}}$', labelpad=0)
    ax.legend(loc='best')

    # Plot instructions
    plot_general_instructions(ax)

plot_general_instructions(ax, set_y=True)

This function adds the common instructions for all the plots displayed by AlphaPEM to the ax object.

Parameters:
  • ax (Axes) –

    Axes on which the instructions will be added.

Source code in modules/display_modules.py
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
def plot_general_instructions(ax, set_y = True):
    """This function adds the common instructions for all the plots displayed by AlphaPEM to the ax object.

    Parameters
    ----------
    ax : matplotlib.axes.Axes
        Axes on which the instructions will be added.
    """
    # Get the current x-axis and y-axis limits
    x_min, x_max = ax.get_xlim()
    y_min, y_max = ax.get_ylim()
    # Calculate the major step for the x-axis and y-axis ticks
    major_step_x = (x_max - x_min) / 5
    major_step_y = (y_max - y_min) / 5
    major_step_x_rounded = round_nice(major_step_x)
    major_step_y_rounded = round_nice(major_step_y)
    # Set the major and minor locators for the x-axis and y-axis
    ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(major_step_x_rounded))
    ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(major_step_x_rounded / 5))
    if set_y:
        ax.yaxis.set_major_locator(mpl.ticker.MultipleLocator(major_step_y_rounded))
        ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(major_step_y_rounded / 5))
    # Configure the appearance of major and minor ticks
    ax.tick_params(axis='both', which='major', size=10, width=1.5, direction='out')
    ax.tick_params(axis='both', which='minor', size=5, width=1.5, direction='out')
    plt.tight_layout() # Adjust layout to prevent overlap between labels and the figure
    plt.show() # Show the figure

plot_ifc(variables, operating_inputs, parameters, ax)

This function plots the current density as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the current density will be plotted.

Source code in modules/display_modules.py
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
def plot_ifc(variables, operating_inputs, parameters, ax):
    """This function plots the current density as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the current density will be plotted.
    """

    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]

    # Plot the current density: ifc
    n = len(t)
    ifc_t = np.zeros(n)
    for i in range(n):  # Creation of ifc_t
        ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²
    ax.plot(t, ifc_t, color=colors(0), label=r'$\mathregular{i_{fc}}$')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                  labelpad=3)
    ax.legend([r'$\mathregular{i_{fc}}$'], loc='best')

    # Plot instructions
    plot_general_instructions(ax)

plot_lambda(variables, operating_inputs, parameters, ax)

This function plots the water content at different spatial localisations, as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the water content will be plotted.

Source code in modules/display_modules.py
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
def plot_lambda(variables, operating_inputs, parameters, ax):
    """This function plots the water content at different spatial localisations, as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the water content will be plotted.
    """

    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    pola_current_parameters, type_current = parameters['pola_current_parameters'], parameters['type_current']
    type_plot = parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    lambda_acl_t = np.array(variables['lambda_acl'])[mask]
    lambda_mem_t = np.array(variables['lambda_mem'])[mask]
    lambda_ccl_t = np.array(variables['lambda_ccl'])[mask]

    # Plot the water content at different spatial localisations: lambda
    if type_current == "polarization":
        n = len(t)
        ifc_t = np.zeros(n)
        for i in range(n):  # Creation of i_fc
            ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²
        # Recovery of the internal states from the model after each stack stabilisation
        delta_t_ini_pola = pola_current_parameters['delta_t_ini_pola']
        delta_t_load_pola = pola_current_parameters['delta_t_load_pola']
        delta_t_break_pola = pola_current_parameters['delta_t_break_pola']
        nb_loads = int(pola_current_parameters['i_max_pola'] / pola_current_parameters['delta_i_pola'])  # Number of loads which are made
        ifc_discretized_t, lambda_acl_discretized_t = np.zeros(nb_loads), np.zeros(nb_loads)
        lambda_mem_discretized_t, lambda_ccl_discretized_t = np.zeros(nb_loads), np.zeros(nb_loads)
        for i in range(nb_loads):
            t_load = delta_t_ini_pola + (i + 1) * (delta_t_load_pola + delta_t_break_pola)  # time for measurement
            idx = (np.abs(t - t_load)).argmin()  # the corresponding index
            ifc_discretized_t[i] = ifc_t[idx]  # the last value at the end of each load
            lambda_acl_discretized_t[i] = lambda_acl_t[idx]  # the last value at the end of each load
            lambda_mem_discretized_t[i] = lambda_mem_t[idx]  # the last value at the end of each load
            lambda_ccl_discretized_t[i] = lambda_ccl_t[idx]  # the last value at the end of each load
        ax.scatter(ifc_discretized_t, lambda_acl_discretized_t, marker='o', color=colors(2))
        ax.scatter(ifc_discretized_t, lambda_mem_discretized_t, marker='o', color=colors(3))
        ax.scatter(ifc_discretized_t, lambda_ccl_discretized_t, marker='o', color=colors(4))
        ax.set_xlabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                      labelpad=3)
    else:
        ax.plot(t, lambda_acl_t, color=colors(3))
        ax.plot(t, lambda_mem_t, color=colors(4))
        ax.plot(t, lambda_ccl_t, color=colors(5))
        ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Water}$ $\mathbf{content}$ $\mathbf{\lambda}$', labelpad=3)
    ax.legend([r'$\mathregular{\lambda_{acl}}$', r'$\mathregular{\lambda_{mem}}$',
               r'$\mathregular{\lambda_{ccl}}$'], loc='best')

    # Plot instructions
    plot_general_instructions(ax)

plot_pola_instructions(type_fuel_cell, ax, show=True)

This function adds the specific instructions for polarisation plots according to the type_input to the ax object.

Parameters:
  • type_fuel_cell (str) –

    Type of fuel cell configuration.

  • ax (Axes) –

    Axes on which the instructions will be added.

  • show (bool, default: True ) –

    If True, the figure will be displayed. Default is True.

Source code in modules/display_modules.py
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
def plot_pola_instructions(type_fuel_cell, ax, show = True):
    """This function adds the specific instructions for polarisation plots according to the type_input to the ax object.

    Parameters
    ----------
    type_fuel_cell : str
        Type of fuel cell configuration.
    ax : matplotlib.axes.Axes
        Axes on which the instructions will be added.
    show : bool, optional
        If True, the figure will be displayed. Default is True.
    """

    # For EH-31 fuel cell
    if type_fuel_cell == "EH-31_1.5" or type_fuel_cell == "EH-31_2.0" or \
            type_fuel_cell == "EH-31_2.25" or type_fuel_cell == "EH-31_2.5":
        ax.xaxis.set_major_locator(mpl.ticker.MultipleLocator(0.5))
        ax.xaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.5 / 5))
        ax.yaxis.set_major_locator(mpl.ticker.MultipleLocator(0.1))
        ax.yaxis.set_minor_locator(mpl.ticker.MultipleLocator(0.1 / 5))
        ax.set_xlim(0, 3.0)
        ax.set_ylim(0.4, 1.04)

    # For other fuel cell
    else:
        pass

    # Configure the appearance of major and minor ticks
    ax.tick_params(axis='both', which='major', size=10, width=1.5, direction='out')
    ax.tick_params(axis='both', which='minor', size=5, width=1.5, direction='out')
    plt.tight_layout()  # Adjust layout to prevent overlap between labels and the figure
    if show:
        plt.show()  # Show the figure

plot_polarisation_curve(variables, operating_inputs, parameters, ax, show=True)

This function plots the model polarisation curve, and compare it to the experimental one (if it exists). The polarisation curve is a classical representation of the cell performances, showing the cell voltage as a function of the current density. To generate it, the current density is increased step by step, and the cell voltage is recorded at each step. The time for which this point is captured is determined using the following approach: at the beginning of each load, a delta_t_load_pola time is needed to raise the current density to its next value. Subsequently, a delta_t_break_pola time is observed to ensure the dynamic stability of the stack's variables before initiating a new load. Finally, each polarisation point is recorded at the end of each delta_t_break_pola time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the polarisation curve will be plotted.

  • show (bool, default: True ) –

    If True, the polarisation curve will be displayed. If False, it will not be displayed.

Source code in modules/display_modules.py
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
def plot_polarisation_curve(variables, operating_inputs, parameters, ax, show=True):
    """
    This function plots the model polarisation curve, and compare it to the experimental one (if it exists). The
    polarisation curve is a classical representation of the cell performances, showing the cell voltage as a function
    of the current density.
    To generate it, the current density is increased step by step, and the cell voltage is recorded at each step.
    The time for which this point is captured is determined using the following approach: at the beginning of each load,
    a delta_t_load_pola time is needed to raise the current density to its next value. Subsequently, a delta_t_break_pola
    time is observed to ensure the dynamic stability of the stack's variables before initiating a new load. Finally,
    each polarisation point is recorded at the end of each delta_t_break_pola time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the polarisation curve will be plotted.
    show : bool, optional
        If True, the polarisation curve will be displayed. If False, it will not be displayed.
    """

    # Extraction of the variables
    t, Ucell_t = np.array(variables['t']), np.array(variables['Ucell'])
    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    pola_current_parameters = parameters['pola_current_parameters']
    delta_t_ini_pola = pola_current_parameters['delta_t_ini_pola']
    delta_t_load_pola = pola_current_parameters['delta_t_load_pola']
    delta_t_break_pola = pola_current_parameters['delta_t_break_pola']
    delta_i_pola, i_max_pola = pola_current_parameters['delta_i_pola'], pola_current_parameters['i_max_pola']
    type_fuel_cell, type_current = parameters['type_fuel_cell'], parameters['type_current']
    voltage_zone, type_auxiliary = parameters['voltage_zone'], parameters['type_auxiliary']
    type_control, type_plot = parameters['type_control'], parameters['type_plot']
    # Extraction of the experimental current density and voltage values.
    i_exp_t, U_exp_t = pola_exp_values(type_fuel_cell, voltage_zone)  # (A.m-2, V).

    if type_plot == "fixed":
        # Creation of ifc_t
        n = len(t)
        ifc_t = np.zeros(n)
        for i in range(n):
            ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²

        # Recovery of ifc and Ucell from the model after each stack stabilisation
        nb_loads = int(i_max_pola / delta_i_pola)  # Number of loads which are made
        ifc_discretized = np.zeros(nb_loads + 1) # One point is taken at ifc = 0, before the first load.
        Ucell_discretized = np.zeros(nb_loads + 1) # One point is taken at ifc = 0, before the first load.
        for i in range(nb_loads+1):
            t_load = delta_t_ini_pola + i * (delta_t_load_pola + delta_t_break_pola) # time for measurement
            idx = (np.abs(t - t_load)).argmin()  # the corresponding index
            ifc_discretized[i] = ifc_t[idx]  # the last value at the end of each load
            Ucell_discretized[i] = Ucell_t[idx]  # the last value at the end of each load

        # Plot the experimental polarization curve and calculate the simulation error compared with experimental data
        if type_fuel_cell != "manual_setup" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode"
                                                 or type_auxiliary == "no_auxiliary"):  # Experimental points are accessible
            # Plot of the experimental polarization curve
            i_exp_t = i_exp_t / 1e4  # Conversion in A/cm²
            plot_experimental_polarisation_curve(type_fuel_cell, i_exp_t, U_exp_t, ax)
            # Calculate the simulation error compared with experimental data
            #       Experimental points are interpolated to correspond to the model points
            Ucell_interpolated = interp1d(ifc_discretized, Ucell_discretized, kind='linear')(i_exp_t)
            sim_error = calculate_simulation_error(Ucell_interpolated, U_exp_t)
        else:
            sim_error = None

        # Plot the model polarisation curve
        plot_specific_line(ifc_discretized, Ucell_discretized, type_fuel_cell, type_current, type_auxiliary,
                           type_control, sim_error, ax)
        plot_pola_instructions(type_fuel_cell, ax, show)

    else:  # type_plot == "dynamic"
        # Plot of the polarisation curve produced by the model
        idx = (np.abs(t - t[-1])).argmin()  # index for polarisation measurement
        ifc = np.array(current_density(t[idx], parameters) / 1e4)  # time for polarisation measurement
        Ucell = np.array(Ucell_t[idx])  # voltage measurement
        ax.plot(ifc, Ucell, 'og', markersize=2)

    # Add the common instructions for the plot
    ax.set_xlabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                  labelpad=3)
    ax.set_ylabel(r'$\mathbf{Cell}$ $\mathbf{voltage}$ $\mathbf{U_{cell}}$ $\mathbf{\left( V \right)}$', labelpad=3)
    if type_plot == "fixed":
        ax.legend(loc='best')

plot_polarisation_curve_for_cali(variables, operating_inputs, parameters, ax)

This function plots the model polarisation curve, and compare it to the experimental one. The polarisation curve is a classical representation of the cell performances, showing the cell voltage as a function of the current density. To generate it, the current density is increased step by step, and the cell voltage is recorded at each step. The time for which this point is captured is determined using the following approach: at the beginning of each load, a delta_t_load_pola time is needed to raise the current density to its next value. Subsequently, a delta_t_break_pola time is observed to ensure the dynamic stability of the stack's variables before initiating a new load. Finally, each polarisation point is recorded at the end of each delta_t_break_pola time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the polarisation curve will be plotted.

Source code in modules/display_modules.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def plot_polarisation_curve_for_cali(variables, operating_inputs, parameters, ax):
    """
    This function plots the model polarisation curve, and compare it to the experimental one. The
    polarisation curve is a classical representation of the cell performances, showing the cell voltage as a function
    of the current density.
    To generate it, the current density is increased step by step, and the cell voltage is recorded at each step.
    The time for which this point is captured is determined using the following approach: at the beginning of each load,
    a delta_t_load_pola time is needed to raise the current density to its next value. Subsequently, a delta_t_break_pola
    time is observed to ensure the dynamic stability of the stack's variables before initiating a new load. Finally,
    each polarisation point is recorded at the end of each delta_t_break_pola time.


    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the polarisation curve will be plotted.
    """

    # Extraction of the variables
    t, Ucell_t = np.array(variables['t']), np.array(variables['Ucell'])
    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    pola_current_for_cali_parameters = parameters['pola_current_for_cali_parameters']
    delta_t_ini_pola_cali = pola_current_for_cali_parameters['delta_t_ini_pola_cali']
    delta_t_load_pola_cali = pola_current_for_cali_parameters['delta_t_load_pola_cali']
    delta_t_break_pola_cali = pola_current_for_cali_parameters['delta_t_break_pola_cali']
    type_fuel_cell, type_current = parameters['type_fuel_cell'], parameters['type_current']
    voltage_zone, type_auxiliary = parameters['voltage_zone'], parameters['type_auxiliary']
    type_control, type_plot = parameters['type_control'], parameters['type_plot']
    # Extraction of the experimental current density and voltage values for the calibration.
    i_exp_cali_t, U_exp_cali_t = pola_exp_values_calibration(type_fuel_cell, voltage_zone)  # (A.m-2, V).

    # Creation of ifc_t
    n = len(t)
    ifc_t = np.zeros(n)
    for i in range(n):
        ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²

    # Recovery of ifc and Ucell from the model after each stack stabilisation
    nb_loads = len(i_exp_cali_t)  # Number of loads which are made
    delta_t_cali = delta_t_load_pola_cali + delta_t_break_pola_cali  # s. It is the time of one load.
    ifc_discretized = np.zeros(nb_loads)
    Ucell_discretized = np.zeros(nb_loads)
    for i in range(nb_loads):
        t_load = delta_t_ini_pola_cali + (i + 1) * delta_t_cali # time for measurement
        idx = (np.abs(t - t_load)).argmin()  # the corresponding index
        ifc_discretized[i] = ifc_t[idx]  # the last value at the end of each load
        Ucell_discretized[i] = Ucell_t[idx]  # the last value at the end of each load

    # Plot the experimental polarization curve
    i_exp_cali_t = i_exp_cali_t / 1e4  # Conversion in A/cm²
    plot_experimental_polarisation_curve(type_fuel_cell, i_exp_cali_t, U_exp_cali_t, ax)

    # Plot the model polarisation curve
    sim_error = calculate_simulation_error(Ucell_discretized, U_exp_cali_t) # Calculate the simulation error
    plot_specific_line(ifc_discretized, Ucell_discretized, type_fuel_cell, type_current, type_auxiliary,
                       type_control, sim_error, ax)
    plot_pola_instructions(type_fuel_cell, ax)

    # Add the common instructions for the plot
    ax.set_xlabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                  labelpad=3)
    ax.set_ylabel(r'$\mathbf{Cell}$ $\mathbf{voltage}$ $\mathbf{U_{cell}}$ $\mathbf{\left( V \right)}$', labelpad=3)
    if type_plot == "fixed":
        ax.legend(loc='best')

plot_power_density_curve(variables, operating_inputs, parameters, n, ax)

This function plots the power density curve Pfc, produced by a cell, as a function of the current density.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • n (int) –

    Number of points used to plot the power density curve.

  • ax (Axes) –

    Axes on which the power density curve will be plotted.

Source code in modules/display_modules.py
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
def plot_power_density_curve(variables, operating_inputs, parameters, n, ax):
    """This function plots the power density curve Pfc, produced by a cell, as a function of the current density.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    n : int
        Number of points used to plot the power density curve.
    ax : matplotlib.axes.Axes
        Axes on which the power density curve will be plotted.
    """

    # Extraction of the variables
    t, Ucell_t = variables['t'], variables['Ucell']
    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    type_fuel_cell, type_current = parameters['type_fuel_cell'], parameters['type_current']
    type_auxiliary, type_control = parameters['type_auxiliary'], parameters['type_control']

    # Creation of the power density function: Pfc
    ifc_t, Pfc_t = np.zeros(n), np.zeros(n)
    for i in range(n):
        ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²
        Pfc_t[i] = Ucell_t[i] * ifc_t[i]

    # Plot of the power density function: Pfc
    plot_specific_line(ifc_t, Pfc_t, type_fuel_cell, type_current, type_auxiliary, type_control, None, ax)
    ax.set_xlabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                  labelpad=0)
    ax.set_ylabel(r'$\mathbf{Fuel}$ $\mathbf{cell}$ $\mathbf{power}$ $\mathbf{density}$ $\mathbf{P_{fc}}$ $\mathbf{\left( W.cm^{-2} \right)}$',
                  labelpad=0)
    ax.legend(loc='best')

    # Plot instructions
    plot_general_instructions(ax)

plot_s(variables, operating_inputs, parameters, ax)

This function plots the liquid water saturation at different spatial localisations, as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • operating_inputs (dict) –

    Operating inputs of the fuel cell.

  • parameters (dict) –

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the liquid water saturation will be plotted.

Source code in modules/display_modules.py
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
def plot_s(variables, operating_inputs, parameters, ax):
    """This function plots the liquid water saturation at different spatial localisations, as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    operating_inputs : dict
        Operating inputs of the fuel cell.
    parameters : dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the liquid water saturation will be plotted.
    """

    # Extraction of the operating inputs and the parameters
    current_density = operating_inputs['current_density']
    nb_gdl, nb_mpl, pola_current_parameters = parameters['nb_gdl'], parameters['nb_mpl'], parameters['pola_current_parameters']
    type_current, type_plot = parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])[mask]
    s_agdl_t = np.array(variables[f's_agdl_{int(np.ceil(nb_gdl / 2))}'])[mask]
    s_ampl_t = np.array(variables[f's_ampl_{int(np.ceil(nb_mpl / 2))}'])[mask]
    s_acl_t = np.array(variables['s_acl'])[mask]
    s_ccl_t = np.array(variables['s_ccl'])[mask]
    s_cmpl_t = np.array(variables[f's_cmpl_{int(np.ceil(nb_mpl / 2))}'])[mask]
    s_cgdl_t = np.array(variables[f's_cgdl_{int(np.ceil(nb_gdl / 2))}'])[mask]

    # Plot the liquid water saturation at different spatial localisations: s
    if type_current == "polarization":
        n = len(t)
        ifc_t = np.zeros(n)
        for i in range(n):  # Creation of i_fc
            ifc_t[i] = current_density(t[i], parameters) / 1e4  # Conversion in A/cm²
        # Recovery of the internal states from the model after each stack stabilisation
        delta_t_ini_pola = pola_current_parameters['delta_t_ini_pola']
        delta_t_load_pola = pola_current_parameters['delta_t_load_pola']
        delta_t_break_pola = pola_current_parameters['delta_t_break_pola']
        nb_loads = int(pola_current_parameters['i_max_pola'] / pola_current_parameters['delta_i_pola']) # Number of loads
        ifc_discretized_t = np.zeros(nb_loads)
        s_agdl_discretized_t, s_ampl_discretized_t, s_acl_discretized_t = [np.zeros(nb_loads)] * 3
        s_ccl_discretized_t, s_cmpl_discretized_t, s_cgdl_discretized_t = [np.zeros(nb_loads)] * 3
        for i in range(nb_loads):
            t_load = delta_t_ini_pola + (i + 1) * (delta_t_load_pola + delta_t_break_pola)  # time for measurement
            idx = (np.abs(t - t_load)).argmin()  # the corresponding index
            ifc_discretized_t[i] = ifc_t[idx]  # the last value at the end of each load
            s_agdl_discretized_t[i] = s_agdl_t[idx]  # the last value at the end of each load
            s_ampl_discretized_t[i] = s_ampl_t[idx]  # the last value at the end of each load
            s_acl_discretized_t[i] = s_acl_t[idx]  # the last value at the end of each load
            s_ccl_discretized_t[i] = s_ccl_t[idx]  # the last value at the end of each load
            s_cmpl_discretized_t[i] = s_cmpl_t[idx]  # the last value at the end of each load
            s_cgdl_discretized_t[i] = s_cgdl_t[idx]  # the last value at the end of each load
        ax.scatter(ifc_discretized_t, s_agdl_discretized_t, marker='o', color=colors(1))
        ax.scatter(ifc_discretized_t, s_ampl_discretized_t, marker='o', color=colors(2))
        ax.scatter(ifc_discretized_t, s_acl_discretized_t, marker='o', color=colors(3))
        ax.scatter(ifc_discretized_t, s_ccl_discretized_t, marker='o', color=colors(5))
        ax.scatter(ifc_discretized_t, s_cmpl_discretized_t, marker='o', color=colors(6))
        ax.scatter(ifc_discretized_t, s_cgdl_discretized_t, marker='o', color=colors(7))
        ax.set_xlabel(r'$\mathbf{Current}$ $\mathbf{density}$ $\mathbf{i_{fc}}$ $\mathbf{\left( A.cm^{-2} \right)}$',
                      labelpad=3)
    else:
        ax.plot(t, s_agdl_t, color=colors(1))
        ax.plot(t, s_ampl_t, color=colors(2))
        ax.plot(t, s_acl_t, color=colors(3))
        ax.plot(t, s_ccl_t, color=colors(5))
        ax.plot(t, s_cmpl_t, color=colors(6))
        ax.plot(t, s_cgdl_t, color=colors(7))
        ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Liquid}$ $\mathbf{water}$ $\mathbf{saturation}$ $\mathbf{s}$', labelpad=3)
    ax.legend([r'$\mathregular{s_{agdl}}$', r'$\mathregular{s_{ampl}}$', r'$\mathregular{s_{acl}}$',
               r'$\mathregular{s_{ccl}}$', r'$\mathregular{s_{cmpl}}$', r'$\mathregular{s_{cgdl}}$'], loc='best')

    # Plot instructions
    plot_general_instructions(ax)

plot_specific_line(x, y, type_fuel_cell, type_current, type_auxiliary, type_control, sim_error, ax)

This function adds the appropriate plot configuration according to the type_input to the ax object.

Parameters:
  • x (ndarray) –

    x-axis values.

  • y (ndarray) –

    y-axis values.

  • type_fuel_cell (str) –

    Type of fuel cell configuration.

  • type_current (str) –

    Type of current density.

  • type_auxiliary (str) –

    Type of auxiliary system.

  • type_control (str) –

    Type of control system.

  • sim_error (float) –

    Simulation error between the simulated cell voltage and the experimental cell voltage (in %).

  • ax (Axes) –

    Axes on which the line will be plotted.

Source code in modules/display_modules.py
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
def plot_specific_line(x, y, type_fuel_cell, type_current, type_auxiliary, type_control, sim_error, ax):
    """ This function adds the appropriate plot configuration according to the type_input to the ax object.

    Parameters
    ----------
    x : numpy.ndarray
        x-axis values.
    y : numpy.ndarray
        y-axis values.
    type_fuel_cell : str
        Type of fuel cell configuration.
    type_current : str
        Type of current density.
    type_auxiliary : str
        Type of auxiliary system.
    type_control : str
        Type of control system.
    sim_error : float
        Simulation error between the simulated cell voltage and the experimental cell voltage (in %).
    ax : matplotlib.axes.Axes
        Axes on which the line will be plotted.
    """

    # For EH-31 fuel cell
    if type_current == "polarization":
        # ZSW fuel cell
        if type_fuel_cell == "ZSW-GenStack" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(0), label='Sim. - nominal operating conditions' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(0), label='Sim. - nominal operating conditions')

        elif type_fuel_cell == "ZSW-GenStack_Pa_1.61_Pc_1.41" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(1), label='Sim. - P$_a$ = 1.61 bar - P$_c$ = 1.41 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_Pa_1.61_Pc_1.41" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(1), label='Sim. - P$_a$ = 1.61 bar - P$_c$ = 1.41 bar')

        elif type_fuel_cell == "ZSW-GenStack_Pa_2.01_Pc_1.81" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(2), label='Sim. - P$_a$ = 2.01 bar - P$_c$ = 1.81 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_Pa_2.01_Pc_1.81" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(2), label='Sim. - P$_a$ = 2.01 bar - P$_c$ = 1.81 bar')

        elif type_fuel_cell == "ZSW-GenStack_Pa_2.4_Pc_2.2" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(3), label='Sim. - P$_a$ = 2.4 bar - P$_c$ = 2.2 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_Pa_2.4_Pc_2.2" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(3), label='Sim. - P$_a$ = 2.4 bar - P$_c$ = 2.2 bar')

        elif type_fuel_cell == "ZSW-GenStack_Pa_2.8_Pc_2.6" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(4), label='Sim. - P$_a$ = 2.8 bar - P$_c$ = 2.6 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_Pa_2.8_Pc_2.6" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(4), label='Sim. - P$_a$ = 2.8 bar - P$_c$ = 2.6 bar')

        elif type_fuel_cell == "ZSW-GenStack_T_62" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(5), label='Sim. - T = 62 °C' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_T_62" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(5), label='Sim. - T = 62 °C')

        elif type_fuel_cell == "ZSW-GenStack_T_76" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(6), label='Sim. - T = 76 °C' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_T_76" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(6), label='Sim. - T = 76 °C')

        elif type_fuel_cell == "ZSW-GenStack_T_84" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(7), label='Sim. - T = 84 °C' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_T_84" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(7), label='Sim. - T = 84 °C')

        # EH-31 fuel cell
        elif type_fuel_cell == "EH-31_1.5" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, color=colors(0), label='Sim. - P = 1.5 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "EH-31_1.5" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(0), label='Sim. - P = 1.5 bar')

        elif type_fuel_cell == "EH-31_2.0" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(1), label='Sim. - P = 2.0 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "EH-31_2.0" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            if type_control == "Phi_des":
                ax.plot(x, y, color=colors(5), label=r'Sim. - P = 2.0 bar - controlled $\mathregular{\Phi_{des}}$')
            else:
                ax.plot(x, y, color=colors(1), label=r'Sim. - P = 2.0 bar - uncontrolled $\mathregular{\Phi_{des}}$')

        elif type_fuel_cell == "EH-31_2.25" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, '--', color=colors(2), label='Sim. - P = 2.25 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "EH-31_2.25" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(2), label='Sim. - P = 2.25 bar')

        elif type_fuel_cell == "EH-31_2.5" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.plot(x, y, color=colors(3), label='Sim - P = 2.5 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "EH-31_2.5" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.plot(x, y, color=colors(3), label='Sim - P = 2.5 bar')

        # For other fuel cell
        else:
            ax.plot(x, y, color=colors(0), label='Simulation')

    elif type_current == "polarization_for_cali":
        # ZSW fuel cell
        if type_fuel_cell == "ZSW-GenStack" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(0), label='Sim. - nominal operating conditions' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(0), label='Sim. - nominal operating conditions')

        elif type_fuel_cell == "ZSW-GenStack_Pa_1.61_Pc_1.41" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(1), label='Sim. - P$_a$ = 1.61 bar - P$_c$ = 1.41 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_Pa_1.61_Pc_1.41" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(1), label='Sim. - P$_a$ = 1.61 bar - P$_c$ = 1.41 bar')

        elif type_fuel_cell == "ZSW-GenStack_Pa_2.01_Pc_1.81" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(2), label='Sim. - P$_a$ = 2.01 bar - P$_c$ = 1.81 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_Pa_2.01_Pc_1.81" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(2), label='Sim. - P$_a$ = 2.01 bar - P$_c$ = 1.81 bar')

        elif type_fuel_cell == "ZSW-GenStack_Pa_2.4_Pc_2.2" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(3), label='Sim. - P$_a$ = 2.4 bar - P$_c$ = 2.2 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_Pa_2.4_Pc_2.2" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(3), label='Sim. - P$_a$ = 2.4 bar - P$_c$ = 2.2 bar')

        elif type_fuel_cell == "ZSW-GenStack_Pa_2.8_Pc_2.6" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(4), label='Sim. - P$_a$ = 2.8 bar - P$_c$ = 2.6 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_Pa_2.8_Pc_2.6" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(4), label='Sim. - P$_a$ = 2.8 bar - P$_c$ = 2.6 bar')

        elif type_fuel_cell == "ZSW-GenStack_T_62" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(5), label='Sim. - T = 62 °C' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_T_62" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(5), label='Sim. - T = 62 °C')

        elif type_fuel_cell == "ZSW-GenStack_T_76" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(6), label='Sim. - T = 76 °C' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_T_76" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(6), label='Sim. - T = 76 °C')

        elif type_fuel_cell == "ZSW-GenStack_T_84" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(7), label='Sim. - T = 84 °C' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "ZSW-GenStack_T_84" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(7), label='Sim. - T = 84 °C')

        # EH-31 fuel cell
        elif type_fuel_cell == "EH-31_1.5" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(0), label='Sim. - P = 1.5 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "EH-31_1.5" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(0), label='Sim. - P = 1.5 bar')

        elif type_fuel_cell == "EH-31_2.0" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(1), label='Sim. - P = 2.0 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "EH-31_2.0" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            if type_control == "Phi_des":
                ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(5), label=r'Sim. - P = 2.0 bar - controlled $\mathregular{\Phi_{des}}$')
            else:
                ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(1), label=r'Sim. - P = 2.0 bar - uncontrolled $\mathregular{\Phi_{des}}$')

        elif type_fuel_cell == "EH-31_2.25" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(2), label='Sim. - P = 2.25 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "EH-31_2.25" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(2), label='Sim. - P = 2.25 bar')

        elif type_fuel_cell == "EH-31_2.5" and (type_auxiliary == "forced-convective_cathode_with_flow-through_anode" or type_auxiliary == "no_auxiliary"):
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(3), label='Sim - P = 2.5 bar' + r' - $ΔU_{max}$ =' f' {sim_error} %')
        elif type_fuel_cell == "EH-31_2.5" and type_auxiliary != "forced-convective_cathode_with_flow-through_anode" and type_auxiliary != "no_auxiliary":
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(3), label='Sim - P = 2.5 bar')

        # For other fuel cell
        else:
            ax.scatter(x, y, marker='o', linewidths=1.5, color=colors(0), label='Simulation')

    else:
        raise ValueError('Only "polarization_current" and "polarization_current_for_cali" are considered here.')

plot_v(variables, parameters, ax)

This function plots the velocity at the anode and the cathode as a function of time.

Parameters:
  • variables (dict) –

    Variables calculated by the solver. They correspond to the fuel cell internal states.

  • parameters

    Parameters of the fuel cell model.

  • ax (Axes) –

    Axes on which the pressure will be plotted.

Source code in modules/display_modules.py
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
def plot_v(variables, parameters, ax):
    """This function plots the velocity at the anode and the cathode as a function of time.

    Parameters
    ----------
    variables : dict
        Variables calculated by the solver. They correspond to the fuel cell internal states.
    parameters: dict
        Parameters of the fuel cell model.
    ax : matplotlib.axes.Axes
        Axes on which the pressure will be plotted.
    """

    # Extraction of the parameters
    nb_gc, type_current, type_plot = parameters['nb_gc'], parameters['type_current'], parameters['type_plot']
    if type_current == 'step':
        delta_t_ini = parameters['step_current_parameters']['delta_t_ini_step']
    elif type_current == 'polarization':
        delta_t_ini = parameters['pola_current_parameters']['delta_t_ini_pola']
    elif type_current == 'polarization_for_cali':
        delta_t_ini = parameters['pola_current_for_cali_parameters']['delta_t_ini_pola_cali']
    else:
        delta_t_ini = 0
    # Extraction of the variables
    if type_plot == "fixed":
        mask = np.array(variables['t']) >= 0.9 * delta_t_ini  # select the time after 0.9*delta_t_ini
    else: # type_plot == "dynamic"
        mask = np.ones_like(variables['t'], dtype=bool)
    t = np.array(variables['t'])
    v_a_in_t = np.array(variables['v_a_in'])
    v_c_in_t = np.array(variables['v_c_in'])

    # Plot the pressure at different spatial localisations: P
    ax.plot(t, v_a_in_t, color=colors(0))
    ax.plot(t, v_c_in_t, color=colors(6))
    ax.legend([r'$\mathregular{v_{a,in}}$', r'$\mathregular{v_{c,in}}$'], loc='best')
    ax.set_xlabel(r'$\mathbf{Time}$ $\mathbf{t}$ $\mathbf{\left( s \right)}$', labelpad=3)
    ax.set_ylabel(r'$\mathbf{Inlet velocities}$ $\mathbf{v}$ $\mathbf{\left( m.s^{-1} \right)}$', labelpad=3)
    ax.ticklabel_format(style='scientific', axis='y', scilimits=(0, 0))

    # Plot instructions
    plot_general_instructions(ax)

round_nice(x)

Round the main step to a "nice" number.

Parameters:
  • x (float) –

    The value to be rounded.

Returns:
  • float

    The value rounded to a "nice" number.

Source code in modules/display_modules.py
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
def round_nice(x):
    """Round the main step to a "nice" number.

    Parameters
    ----------
    x : float
        The value to be rounded.

    Returns
    -------
    float
        The value rounded to a "nice" number.
    """
    exp = np.floor(np.log10(x))
    f = x / 10**exp
    if f < 1.5:
        nice = 1
    elif f < 3:
        nice = 2
    elif f < 7:
        nice = 5
    else:
        nice = 10
    return nice * 10**exp