Scripts for MECSim |
Overview
The MECSim format in combination with parameter optimisation tool kit facilitates the implementation of sophisticated forms of experiment-theory comparisons needed to estimate the electrode kinetic and other parameters.
MECSim software is computationally efficient and based on flexible code that can be used in cluster computing as well as on a single machine. Typical simulations take seconds to run on a laptop and automated parameter searches can be completed using simple scripts. Here we detail how to automate MECSim using bash scripts in ubuntu (linux) and Windows 10.
Scripting using windows 10
As of mid 2016 Windows 10 includes a subsystem for linux which can be used to run the same codes in the same way as the bash scripts below.
A guide for how to install the windows linux subsystem (which is basically ubuntu) in Windows 10 can be found here. It is worth noting that this is a beta version by Microsoft, so while it will work it might be quite slow to install (the "few minutes" they mentioned took me over 30 min).
Once "Bash on Ubuntu in Windows" is installed, open a terminal and install some additional software using the following commands:
apt-get install gfortran
|
needed to run MECSim (linux version) |
apt-get install dos2unix
|
needed for .sh |
Bash scripts
The following bash scripts will work in either ubuntu linux or the linux subsystem in Windows 10. They all follow the same stages:
(1) A "skeleton" (or template) file for the "Master.inp" file is created in the working directory. For these script examples it is always named "Master.sk". These examples below should be renamed to "Master.sk" before the script is run.
(2) Parameters to vary using the script file should be given unique labels the script can recognise; here I have used "$para".
(3) The script file, e.g. "LoopAK.sh", is copied into the same directory and can be edited using a text editor. The structure of this file is:
(a) initial parameter values are set
(b) loop over one or more parameters
(c) Replace the $para using a sed in linux; this can be changed to multiple parameters if required.
(d) The output from all files is combined to a single text file (e.g. "results.txt").
|
Note: if a windows based editor is used then sometimes errors occur when the script is executed. In this case the script must be converted to a linux style text file using the command: dos2unix FileName.sh
The following scripts automatically run MECsim and/or plot results. They are intended as easily modified examples to cover most potential uses.
Name | Download | Description |
RunForAllInp | sh | Run MECSim and basic plotter for all input files in directory. Runs MECSim for each "Master*.inp" file in the current directory. Will then run the python script "MECSimPlotter.py" for each input text file and output plots for the current vs time/voltage in PNG format. |
VaryOneParameter | sh, inputA, inputK | Do a parameter search over one parameter. The batch file here runs MECSim over a single parameter, calculates a single number as an evaluation of each run and outputs everything to "results.txt". This script was used for the Langmuir isotherm validation shown here. |
VaryTwoParameters | zip | Do a parameter search over two parameters. Use a quick comparison between two MECSim output files (least squared) which outputs a single number. This is then used two build a x, y, z style "results.txt" file from each set of results. All codes are compiled for ubuntu linux and a plotter is available above. |