Home Examples Screenshots User manual Bluesky logo YouTube 中文
OghmaNano Simulate organic/Perovskite Solar Cells, OFETs, and OLEDs DOWNLOAD

MATLAB 脚本编写

如第 14.1 节所述,OghmaNano 仿真以 .json 文件形式存储,并在一个 zip 归档中压缩打包。Matlab 同时具备 zip 解压器与 json 解码器。因此,在 MATLAB 中读取、编辑 .oghma 文件中的内容是很直接的。随后你可以使用 MATLAB 执行相当复杂的参数扫描。下面清单 [matlab-example] 中的示例脚本演示了如何运行多次仿真,其中迁移率从 1e-7 扫描到 1e-5 \(m^{2}V^{-1}s^{-1})\)。脚本首先解压 sim.json 文件;如果你已经从 sim.oghma 文件中提取了 sim.json,则不需要这些行。随后代码使用 MATLAB 的 json 解码器 \(jsondecode\) 读取 sim.json。接着创建一个与迁移率数值对应的新目录,并将 sim.oghma 文件复制到该目录中。然后将 \(json\_data.epitaxy.layer0.shape\_dos.mue_y\) 设置为所需的迁移率值,并使用 \(jsonencode\) 以及 \(fopen,fprintf,fclose\) 保存仿真。随后使用 \(system\) 调用运行 \(oghma\_core.exe\) 以执行仿真。输出参数(例如 \(J_{sc}\))会以 json 格式存储在 sim_data.dat 中,见第 4.1.4 节,不过在这个简单脚本中未做此操作。



if exist("sim.oghma", 'file')==false
 sprintf("No sim.oghma file found"); %Check if we have a sim.oghma file
end

if exist("sim.json", 'file')==false
 unzip("sim.oghma")  %if we don't have a sim.json file
                                      %try to extract it
end

A = fileread("sim.json");  %Read the json file.
json_data=jsondecode(A);  %Decode the json file

mobility=1e-7  %Start mobility
origonal_path=pwd  %working with the current dir
base_dir="mobility_scan"  %output directory name
while(mobility<1e-5)
    dir_name=sprintf("%e",mobility);
    full_path=fullfile(origonal_path,base_dir,dir_name)    %join paths
    mkdir(full_path)  %make the dir
    cd(full_path)  %cd to the dir

   %Update the json mobility
    json_data.epitaxy.layer0.shape_dos.mue_y=mobility  %Change mobility
                                                                                                      %of layer0
    
    copyfile(fullfile(origonal_path,"sim.oghma"),\\
           fullfile(origonal_path,base_dir,dir_name,"sim.oghma"))

   %now write the json file back to disk
    out=jsonencode(json_data);
    json_data
    fid = fopen("sim.json",'w');
    fprintf(fid, '%s', out);
    fclose(fid);

   %run oghma - This won't work if you have not added the oghma
   %install directory to your windows paths 
    system("oghma_core.exe")
    
   %Multiply mobility by 10
    mobility=mobility*10;
end

%Move back to the original dir
cd(origonal_path)

内置计算器

OghmaNano 具有一个内置计算器,可用于执行简单的数学运算。该 功能对于设置拟合流程以及在代码的各个部分定义方程很有用。该 计算器基于逆波兰表示法(RPN)。

支持的运算

算术与比较运算符
运算 运算符 示例
幂运算 ^ 2 ^3 = 8
乘法 \(*\) \(2 * 3 = 6\)
除法 \(/\) \(6 / 2 = 3\)
加法 \(+\) \(2 + 3 = 5\)
减法 \(-\) \(5 - 3 = 2\)
大于 \(>\) \(5 > 3\) 为 1
小于 \(<\) \(2 < 5\) 为 1
大于或等于 \(>=\) \(5 >= 5\) 为 1
小于或等于 \(<=\) \(3 <= 4\) 为 1

支持的函数

支持的函数
函数名称 函数 示例
正弦 sin \(\sin(\pi/2) = 1\)
余弦 cos \(\cos(0) = 1\)
绝对值 abs \(\text{abs}(-3) = 3\)
取正值 pos \(\text{pos}(-3) = 0, \text{pos}(3) = 3\)
对数(以 10 为底) log \(\log(100) = 2\)
指数 exp \(\exp(2) = e^2\)
平方根 sqrt \(sqrt(9) = 3\)
最小值 min \(\min(2, 3) = 2\)
最大值 max \(\max(2, 3) = 3\)
随机数 rand \(\text{rand}(a, b)\) 生成一个介于 \(a\)\(b\) 之间的随机数
对数随机数 randlog \(\text{randlog}(a, b)\) 生成一个介于 \(a\)\(b\) 之间的对数随机数