Storing the output data

Running the code in this notebook (under Mott-Schottky conditions with real data) takes approximately 2 minutes (iMac with 4 Ghz i7 processor).

The suggested way to store the calculation output is to use a pd.DataFrame. Example storage is shown below.

In [1]:
from pyscses.defect_species import DefectSpecies
from pyscses.set_of_sites import Set_of_Sites
from pyscses.constants import boltzmann_eV
from pyscses.calculation import Calculation, calculate_activation_energies
from pyscses.set_up_calculation import calculate_grid_offsets
from pyscses.grid import Grid

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
boundary_conditions = 'periodic'
site_charge = False
system = 'mott-schottky'
core_model = False
site_model = 'site_explicit'
In [3]:
alpha = 0.0005
conv = 1e-8
grid_x_min = -6.094e-9
grid_x_max = 5.16e-9
bulk_x_min = -5.783e-9
bulk_x_max = -2.502e-9

dielectric = 55

index = 111
b = 7.65327e-10
c = 7.65327e-10

temp = [673, 773, 873, 973, 1000, 1173, 1273, 1373]
In [4]:
valence = [ +2.0, -1.0 ]
site_labels = [ 'O', 'Ce' ]
defect_labels = ['Vo', 'Gd']
mole_fractions = np.array([ [ 0.05, 0.2 ] ])
initial_guess = [ [ 0.05, 0.2 ] ]
mobilities = [ 1.0, 0.0 ]
In [5]:
data = '../input_data/Gd_CeO2_111_data.txt'

Empty DataFrames are created and appended to at the end of each calculation

In [6]:
dtype = { 'core_model':str, 
          'site_model':str, 
          'MS_GC':str, 
          'site_charge':bool, 
          'resistivity_scaling':bool, 
          'temperature':str, 
          'input_mole_fraction':str,
          'x':np.float64,
          'phi':np.float64,
          'rho':np.float64,
          'Vo_mole_fraction':np.float64,
          'Gd_mole_fraction':np.float64}

labels=[ 'core_model', 'site_model', 'MS_GC', 'site_charge', 'temperature', 'input_mole_fractions', 'x', 'phi', 'rho', 'Vo_mole_fraction', 'Gd_mole_fraction']
all_data = pd.DataFrame( columns=labels )
filename = 'theory_paper_data.csv'
all_data.to_csv(filename, index=False)

labels_1 = ['core_model', 'site_model', 'MS_GC', 'site_charge', 'temperature', 'mole_fraction', 'space_charge_potential', 'parallel_resistivity_ratio', 'perpendicular_resistivity_ratio', 'MS_space_charge_potential', 'activation_energy' ]
key_data = pd.DataFrame( columns=labels_1 )
filename_1 = 'space_charge_properties_{}.csv'.format(index)
key_data.to_csv(filename_1, index = False )
In [7]:
limits, laplacian_limits = calculate_grid_offsets( data, grid_x_min, grid_x_max, 'single' )

for m in mole_fractions:
    
    parallel_resistivity_ratios = []
    perpendicular_resisitivity_ratios = []
    temperatures = []
    mole_fraction_list = []
    space_charge_potentials =[]
    ms_space_charge_potentials = []
    c_m = []
    s_m = []
    t_m = []
    s_c = []

    key_data_read_in = pd.read_csv(filename_1)
    for t in temp:
    
        defect_species = { l : DefectSpecies( l, v, m, mob ) for l, v, m, mob in zip( defect_labels, valence, m, mobilities ) }

        all_sites = Set_of_Sites.set_of_sites_from_input_data( data, [grid_x_min, grid_x_max], defect_species, site_charge, core_model, t )
        if site_model == 'continuum':
            all_sites, limits = Set_of_Sites.form_continuum_sites( all_sites, grid_x_min, grid_x_max, 1000, b, c, defect_species, laplacian_limits, site_labels, defect_labels )
        if system == 'mott-schottky':
            for site in all_sites.subset( 'Ce' ):
                site.defect_with_label('Gd').fixed = True
        if system == 'gouy-chapman':
            for site in all_sites.subset( 'Ce' ):
                site.defect_with_label('Gd').fixed = False
        grid = Grid.grid_from_set_of_sites( all_sites, limits, laplacian_limits, b, c )
        
        all_data = pd.DataFrame( columns=labels )
        all_data_read_in = pd.read_csv(filename, dtype=dtype)
        
        c_o = Calculation( grid, bulk_x_min, bulk_x_max, alpha, conv, dielectric, t, boundary_conditions )
        c_o.form_subgrids( site_labels )
        if system == 'gouy-chapman':
            c_o.mole_fraction_correction( m, system, initial_guess )
        c_o.solve(system)
        c_o.mole_fractions()
        c_o.calculate_resistivity_ratio( 'positive', 2e-2 )
        c_o.solve_MS_approx_for_phi( valence[0] )
        
        all_data['x'] = grid.x
        all_data['phi'] = c_o.phi
        all_data['rho'] = c_o.rho
        all_data['Vo_mole_fraction'] = c_o.mf[site_labels[0]]
        all_data['Gd_mole_fraction'] = c_o.mf[site_labels[1]]
        all_data['core_model'] = str(core_model)
        all_data['site_model'] = str(site_model)
        all_data['MS_GC'] = str(system)
        all_data['site_charge'] = str(site_charge)
        all_data['temperature'] = t
        all_data['input_mole_fractions'] = str(m)
        all_data_appended = all_data_read_in.append(all_data, ignore_index=True)
        all_data_appended.to_csv(filename, index=False)
        
        temperatures.append(t)
        mole_fraction_list.append(str(m))
        if site_charge == True:
            space_charge_potentials.append( (max(c_o.phi) - c_o.phi[0] ) )
        else:
            space_charge_potentials.append(max(c_o.phi))
        parallel_resistivity_ratios.append(c_o.parallel_resistivity_ratio)
        perpendicular_resisitivity_ratios.append(c_o.perpendicular_resistivity_ratio)
        ms_space_charge_potentials.append(c_o.ms_phi)
        c_m.append(str(core_model))
        s_m.append(str(site_model))
        t_m.append(str(system))
        s_c.append(str(site_charge))
        
    activation_energies = calculate_activation_energies( perpendicular_resisitivity_ratios, temp)
    key_data_array = np.column_stack(( temperatures[1:-1], mole_fraction_list[1:-1], space_charge_potentials[1:-1], parallel_resistivity_ratios[1:-1], perpendicular_resisitivity_ratios[1:-1], ms_space_charge_potentials[1:-1], activation_energies[1:-1], c_m[1:-1], s_m[1:-1], t_m[1:-1], s_c[1:-1] ))
                
    key_data =  pd.DataFrame( key_data_array, columns=labels_1 )
    
    key_data_appended = key_data_read_in.append( key_data, ignore_index=True )
    key_data_appended.to_csv( filename_1, index=False)
                    
In [8]:
plt.plot(grid.x, c_o.phi)
plt.xlabel( '$x$ $\mathrm{coordinate}$' )
plt.ylabel('$\Phi$ $\mathrm{( eV )}$')
plt.savefig('phi.pdf')
plt.show()

plt.plot(grid.x, c_o.rho)
plt.xlabel( '$x$ $\mathrm{coordinate}$'  )
plt.ylabel(' $\mathrm{charge density}$ $(\mathrm{C m}^{-1})$')
plt.savefig('rho.pdf')
plt.show()

plt.plot(grid.x, c_o.mf[site_labels[0]], label = '$\mathrm{Vo}$')
plt.plot(grid.x, c_o.mf[site_labels[1]], label = '$\mathrm{Gd}$')
plt.xlabel( '$x$ $\mathrm{coordinate}$'  )
plt.ylabel('$x_{i}$')
plt.legend()
plt.savefig('mf.pdf')
plt.show()

print('key_data')
print()
print(key_data_appended)
print('all_data')
print()
print(all_data_appended)
print()
print('perpendicular grain boundary resistivity = ', c_o.perpendicular_resistivity_ratio)
print('parallel grain boundary resistivity = ', c_o.parallel_resistivity_ratio)
print('space charge potential = ', max(c_o.phi))
print('Mott-Schottky approximated space charge potential = ', c_o.ms_phi)
key_data

  core_model   site_model     MS_GC site_charge temperature  \
0        773  [0.05 0.2 ]   0.33517  0.00963335      221569   
1        873  [0.05 0.2 ]   0.32801  0.00966261     61133.1   
2        973  [0.05 0.2 ]  0.321155  0.00968779     22115.6   
3       1000  [0.05 0.2 ]  0.319353  0.00969412     17424.4   
4       1173  [0.05 0.2 ]  0.308277  0.00837419     5550.74   
5       1273  [0.05 0.2 ]  0.302223  0.00837756     3187.59   

       mole_fraction space_charge_potential parallel_resistivity_ratio  \
0  0.524870661512625                0.75023                      False   
1  0.540890287355384               0.746274                      False   
2  0.556897814968529               0.741121                      False   
3  0.561233609511401               0.728981                      False   
4  0.595437038124449               0.699566                      False   
5  0.612871542996122               0.704616                      False   

  perpendicular_resistivity_ratio MS_space_charge_potential activation_energy  
0                   site_explicit             mott-schottky             False  
1                   site_explicit             mott-schottky             False  
2                   site_explicit             mott-schottky             False  
3                   site_explicit             mott-schottky             False  
4                   site_explicit             mott-schottky             False  
5                   site_explicit             mott-schottky             False  
all_data

    core_model     site_model          MS_GC site_charge temperature  \
0        False  site_explicit  mott-schottky       False         673   
1        False  site_explicit  mott-schottky       False         673   
2        False  site_explicit  mott-schottky       False         673   
3        False  site_explicit  mott-schottky       False         673   
4        False  site_explicit  mott-schottky       False         673   
5        False  site_explicit  mott-schottky       False         673   
6        False  site_explicit  mott-schottky       False         673   
7        False  site_explicit  mott-schottky       False         673   
8        False  site_explicit  mott-schottky       False         673   
9        False  site_explicit  mott-schottky       False         673   
10       False  site_explicit  mott-schottky       False         673   
11       False  site_explicit  mott-schottky       False         673   
12       False  site_explicit  mott-schottky       False         673   
13       False  site_explicit  mott-schottky       False         673   
14       False  site_explicit  mott-schottky       False         673   
15       False  site_explicit  mott-schottky       False         673   
16       False  site_explicit  mott-schottky       False         673   
17       False  site_explicit  mott-schottky       False         673   
18       False  site_explicit  mott-schottky       False         673   
19       False  site_explicit  mott-schottky       False         673   
20       False  site_explicit  mott-schottky       False         673   
21       False  site_explicit  mott-schottky       False         673   
22       False  site_explicit  mott-schottky       False         673   
23       False  site_explicit  mott-schottky       False         673   
24       False  site_explicit  mott-schottky       False         673   
25       False  site_explicit  mott-schottky       False         673   
26       False  site_explicit  mott-schottky       False         673   
27       False  site_explicit  mott-schottky       False         673   
28       False  site_explicit  mott-schottky       False         673   
29       False  site_explicit  mott-schottky       False         673   
..         ...            ...            ...         ...         ...   
834      False  site_explicit  mott-schottky       False        1373   
835      False  site_explicit  mott-schottky       False        1373   
836      False  site_explicit  mott-schottky       False        1373   
837      False  site_explicit  mott-schottky       False        1373   
838      False  site_explicit  mott-schottky       False        1373   
839      False  site_explicit  mott-schottky       False        1373   
840      False  site_explicit  mott-schottky       False        1373   
841      False  site_explicit  mott-schottky       False        1373   
842      False  site_explicit  mott-schottky       False        1373   
843      False  site_explicit  mott-schottky       False        1373   
844      False  site_explicit  mott-schottky       False        1373   
845      False  site_explicit  mott-schottky       False        1373   
846      False  site_explicit  mott-schottky       False        1373   
847      False  site_explicit  mott-schottky       False        1373   
848      False  site_explicit  mott-schottky       False        1373   
849      False  site_explicit  mott-schottky       False        1373   
850      False  site_explicit  mott-schottky       False        1373   
851      False  site_explicit  mott-schottky       False        1373   
852      False  site_explicit  mott-schottky       False        1373   
853      False  site_explicit  mott-schottky       False        1373   
854      False  site_explicit  mott-schottky       False        1373   
855      False  site_explicit  mott-schottky       False        1373   
856      False  site_explicit  mott-schottky       False        1373   
857      False  site_explicit  mott-schottky       False        1373   
858      False  site_explicit  mott-schottky       False        1373   
859      False  site_explicit  mott-schottky       False        1373   
860      False  site_explicit  mott-schottky       False        1373   
861      False  site_explicit  mott-schottky       False        1373   
862      False  site_explicit  mott-schottky       False        1373   
863      False  site_explicit  mott-schottky       False        1373   

    input_mole_fractions             x           phi           rho  \
0            [0.05 0.2 ] -5.938769e-09  7.533900e-04  8.766165e+08   
1            [0.05 0.2 ] -5.860658e-09 -1.667642e-02 -2.801518e+09   
2            [0.05 0.2 ] -5.782546e-09  3.251067e-04  8.887471e+08   
3            [0.05 0.2 ] -5.626324e-09  1.610345e-04  8.931088e+08   
4            [0.05 0.2 ] -5.548213e-09 -1.708674e-02 -2.801518e+09   
5            [0.05 0.2 ] -5.470102e-09  9.683374e-05  8.948466e+08   
6            [0.05 0.2 ] -5.313880e-09  6.705316e-05  8.954279e+08   
7            [0.05 0.2 ] -5.235769e-09 -1.715722e-02 -2.801518e+09   
8            [0.05 0.2 ] -5.157658e-09  4.985988e-05  8.956394e+08   
9            [0.05 0.2 ] -5.001436e-09  3.733608e-05  8.957137e+08   
10           [0.05 0.2 ] -4.923325e-09 -1.718365e-02 -2.801518e+09   
11           [0.05 0.2 ] -4.845214e-09  2.670102e-05  8.957323e+08   
12           [0.05 0.2 ] -4.688992e-09  1.725049e-05  8.957162e+08   
13           [0.05 0.2 ] -4.610881e-09 -1.720226e-02 -2.801518e+09   
14           [0.05 0.2 ] -4.532770e-09  9.584396e-06  8.957946e+08   
15           [0.05 0.2 ] -4.376548e-09  7.598021e-07  8.957600e+08   
16           [0.05 0.2 ] -4.298436e-09 -1.721926e-02 -2.801518e+09   
17           [0.05 0.2 ] -4.220325e-09 -7.926324e-06  8.957214e+08   
18           [0.05 0.2 ] -4.064103e-09 -1.502395e-05  8.957831e+08   
19           [0.05 0.2 ] -3.985992e-09 -1.723461e-02 -2.801518e+09   
20           [0.05 0.2 ] -3.907881e-09 -2.284490e-05  8.957190e+08   
21           [0.05 0.2 ] -3.751659e-09 -2.898746e-05  8.957526e+08   
22           [0.05 0.2 ] -3.673548e-09 -1.724752e-02 -2.801518e+09   
23           [0.05 0.2 ] -3.595437e-09 -3.471356e-05  8.957739e+08   
24           [0.05 0.2 ] -3.439215e-09 -4.082882e-05  8.958067e+08   
25           [0.05 0.2 ] -3.361104e-09 -1.726037e-02 -2.801518e+09   
26           [0.05 0.2 ] -3.282993e-09 -4.856371e-05  8.957401e+08   
27           [0.05 0.2 ] -3.126771e-09 -5.541646e-05  8.957946e+08   
28           [0.05 0.2 ] -3.048660e-09 -1.727509e-02 -2.801518e+09   
29           [0.05 0.2 ] -2.970549e-09 -6.341818e-05  8.957358e+08   
..                   ...           ...           ...           ...   
834          [0.05 0.2 ]  2.187091e-09  2.432909e-03  9.144405e+08   
835          [0.05 0.2 ]  2.265203e-09 -1.487427e-02 -2.801518e+09   
836          [0.05 0.2 ]  2.343314e-09  2.417243e-03  9.148179e+08   
837          [0.05 0.2 ]  2.499536e-09  2.414706e-03  9.150023e+08   
838          [0.05 0.2 ]  2.577647e-09 -1.488284e-02 -2.801518e+09   
839          [0.05 0.2 ]  2.655758e-09  2.418292e-03  9.150966e+08   
840          [0.05 0.2 ]  2.811980e-09  2.424434e-03  9.151534e+08   
841          [0.05 0.2 ]  2.890091e-09 -1.487162e-02 -2.801518e+09   
842          [0.05 0.2 ]  2.968202e-09  2.431012e-03  9.151302e+08   
843          [0.05 0.2 ]  3.124424e-09  2.438915e-03  9.151610e+08   
844          [0.05 0.2 ]  3.202535e-09 -1.485638e-02 -2.801518e+09   
845          [0.05 0.2 ]  3.280646e-09  2.447009e-03  9.151890e+08   
846          [0.05 0.2 ]  3.436868e-09  2.454253e-03  9.151560e+08   
847          [0.05 0.2 ]  3.514979e-09 -1.484127e-02 -2.801518e+09   
848          [0.05 0.2 ]  3.593091e-09  2.461887e-03  9.151908e+08   
849          [0.05 0.2 ]  3.749313e-09  2.468605e-03  9.151656e+08   
850          [0.05 0.2 ]  3.827424e-09 -1.482737e-02 -2.801518e+09   
851          [0.05 0.2 ]  3.905535e-09  2.475348e-03  9.152135e+08   
852          [0.05 0.2 ]  4.061757e-09  2.480319e-03  9.152139e+08   
853          [0.05 0.2 ]  4.139868e-09 -1.481743e-02 -2.801518e+09   
854          [0.05 0.2 ]  4.217979e-09  2.483499e-03  9.153143e+08   
855          [0.05 0.2 ]  4.374201e-09  2.481133e-03  9.154962e+08   
856          [0.05 0.2 ]  4.452312e-09 -1.482558e-02 -2.801518e+09   
857          [0.05 0.2 ]  4.530423e-09  2.466400e-03  9.157867e+08   
858          [0.05 0.2 ]  4.686645e-09  2.428367e-03  9.164940e+08   
859          [0.05 0.2 ]  4.764756e-09 -1.491498e-02 -2.801518e+09   
860          [0.05 0.2 ]  4.842867e-09  2.340365e-03  9.179389e+08   
861          [0.05 0.2 ]  4.999089e-09  2.147905e-03  9.209306e+08   
862          [0.05 0.2 ]  5.077200e-09 -1.535611e-02 -2.801518e+09   
863          [0.05 0.2 ]  5.155312e-09  1.738558e-03  9.271567e+08   

     Vo_mole_fraction  Gd_mole_fraction  
0            0.046936               0.0  
1            0.000000               0.2  
2            0.047586               0.0  
3            0.047819               0.0  
4            0.000000               0.2  
5            0.047912               0.0  
6            0.047943               0.0  
7            0.000000               0.2  
8            0.047955               0.0  
9            0.047959               0.0  
10           0.000000               0.2  
11           0.047960               0.0  
12           0.047959               0.0  
13           0.000000               0.2  
14           0.047963               0.0  
15           0.047961               0.0  
16           0.000000               0.2  
17           0.047959               0.0  
18           0.047962               0.0  
19           0.000000               0.2  
20           0.047959               0.0  
21           0.047961               0.0  
22           0.000000               0.2  
23           0.047962               0.0  
24           0.047964               0.0  
25           0.000000               0.2  
26           0.047960               0.0  
27           0.047963               0.0  
28           0.000000               0.2  
29           0.047960               0.0  
..                ...               ...  
834          0.048961               0.0  
835          0.000000               0.2  
836          0.048981               0.0  
837          0.048991               0.0  
838          0.000000               0.2  
839          0.048996               0.0  
840          0.048999               0.0  
841          0.000000               0.2  
842          0.048998               0.0  
843          0.049000               0.0  
844          0.000000               0.2  
845          0.049001               0.0  
846          0.049000               0.0  
847          0.000000               0.2  
848          0.049001               0.0  
849          0.049000               0.0  
850          0.000000               0.2  
851          0.049003               0.0  
852          0.049003               0.0  
853          0.000000               0.2  
854          0.049008               0.0  
855          0.049018               0.0  
856          0.000000               0.2  
857          0.049033               0.0  
858          0.049071               0.0  
859          0.000000               0.2  
860          0.049149               0.0  
861          0.049309               0.0  
862          0.000000               0.2  
863          0.049642               0.0  

[864 rows x 11 columns]

perpendicular grain boundary resistivity =  2006.9356535584202
parallel grain boundary resistivity =  0.008381304778692202
space charge potential =  0.29640540295079343
Mott-Schottky approximated space charge potential =  0.630885754688719