PowerShell scripting
1. Introduction
In OghmaNano, PowerShell scripting works by directly editing the simulation configuration files on disk
and then invoking the simulation engine (oghma_core.exe) to run the model.
This section describes this workflow in detail.
2. Running simulation files with PowerShell
An OghmaNano simulation is defined entirely by a single JSON configuration file,
sim.json.
This file contains the complete state of the simulation, including the device structure,
material parameters, numerical settings, and output configuration.
In many cases, sim.json already exists as a normal file inside the simulation directory.
When driving OghmaNano from PowerShell, the script reads sim.json into memory, modifies one or more
parameters, and writes the updated JSON back to disk.
Crucially, PowerShell must run oghma_core.exe with its working directory set to the
simulation directory — that is, the directory containing sim.json (and
sim.oghma).
The simulation engine always reads its input files from the current working directory,
so if the working directory is incorrect, the simulation will fail or run the wrong model.
This separation of responsibilities is intentional and explicit: PowerShell is responsible for defining what changes in the simulation, while OghmaNano is responsible for running the physics using the files present in the current directory.
The example below demonstrates this process by loading sim.json, modifying the carrier
mobility of the first device layer, writing the updated configuration back to disk, and then
executing the simulation from the simulation directory.
# Set this to your simulation folder (must contain sim.json / sim.oghma)
$sim_dir = "C:\path\to\your\simulation"
# Read sim.json
$sim_path = Join-Path $sim_dir "sim.json"
$txt = Get-Content -Path $sim_path -Raw
$data = $txt | ConvertFrom-Json
# Edit a value: mobility of segment1 (same JSON path as the Python/MATLAB pages)
$data.epitaxy.segment1.shape_dos.mue_y = 1.0
# Write sim.json back to disk
$out = $data | ConvertTo-Json -Depth 200
Set-Content -Path $sim_path -Value $out -Encoding UTF8
# Run the simulation (working directory must be the simulation folder)
$orig_dir = Get-Location
Set-Location $sim_dir
& "oghma_core.exe"
Set-Location $orig_dir
If the simulation in sim.json is set up to run a J–V curve, OghmaNano will write output files into the
simulation directory containing quantities such as PCE, fill factor, \(J_{sc}\) and
\(V_{oc}\).
3. Extracting results
Many OghmaNano output files are written in JSON format. A common pattern is to read
sim_info.dat, extract a scalar figure of merit (for example Voc),
and append it to a text file for later analysis.
The example below reads sim_info.dat and appends the value of
\(V_{oc}\) to a separate text file.
# Must be run from (or pointed at) a completed simulation directory
$sim_dir = "C:\path\to\your\simulation"
$info_path = Join-Path $sim_dir "sim_info.dat"
$txt = Get-Content -Path $info_path -Raw
$info = $txt | ConvertFrom-Json
$voc = $info.Voc
# Append to a text file (one Voc per line)
$out_path = Join-Path $sim_dir "out.dat"
Add-Content -Path $out_path -Value ("{0}" -f $voc)
3. More complex simulations
In many scripting workflows you will want to run the same base simulation multiple times with different parameter values and keep each run isolated in its own directory. This is the simplest way to keep outputs clean and to avoid accidentally overwriting results.
The example below creates a set of directories corresponding to four mobilities
(1e-5, 1e-6, 1e-7, 1e-8). For each directory it:
- Creates the directory (if it does not already exist).
- Copies the current
sim.jsoninto that directory. - Edits the copied
sim.jsonto set the target mobility. - Changes the working directory to that directory.
- Runs the solver in that directory, producing outputs local to that run.
This pattern is the basis of batch scripting in OghmaNano: one directory per run, one configuration file per run, and a clean output folder for each parameter value.
# The script should be started in the base simulation directory
# (i.e. the directory containing the reference sim.json).
$base_dir = (Get-Location).Path
$mobilities = @(1e-5, 1e-6, 1e-7, 1e-8)
$src_sim = Join-Path $base_dir "sim.json"
foreach ($mu in $mobilities) {
$run_name = ("mu_{0:0e}" -f $mu)
$run_dir = Join-Path $base_dir $run_name
if (-not (Test-Path -Path $run_dir -PathType Container)) {
New-Item -ItemType Directory -Path $run_dir | Out-Null
}
# Copy the base sim.json into the run directory
$dst_sim = Join-Path $run_dir "sim.json"
Copy-Item -Path $src_sim -Destination $dst_sim -Force
# Load the copied sim.json and edit the mobility in THAT copy
$txt = Get-Content -Path $dst_sim -Raw
$data = $txt | ConvertFrom-Json
$data.epitaxy.segment1.shape_dos.mue_y = [double]$mu
$out = $data | ConvertTo-Json -Depth 200
Set-Content -Path $dst_sim -Value $out -Encoding UTF8
# Change into the run directory and execute the solver there
Push-Location $run_dir
& "oghma_core.exe"
Pop-Location
}
4. Extracting results
After running a batch of simulations in separate run directories (for example mu_1e-05,
mu_1e-06, ...), the next step is to extract a key figure of merit from each run and visualize the trend.
A common example is to read the open-circuit voltage \(V_{oc}\) from
sim_info.dat in each directory and plot it against inverse mobility \(1/\mu\).
The script below scans a fixed set of run directories corresponding to mobilities
1e-5, 1e-6, 1e-7, 1e-8 and for each directory:
- Loads
sim_info.datas JSON. - Extracts
Voc. - Computes \(1/\mu\) using the mobility associated with that directory.
- Writes a small summary file (
voc_vs_inv_mobility.dat). - Plots \(V_{oc}\) vs \(1/\mu\).
# Run this from the BASE directory that contains the run folders
# (mu_1e-05, mu_1e-06, ...). If not, set base_dir explicitly.
$base_dir = (Get-Location).Path
$mobilities = @(1e-5, 1e-6, 1e-7, 1e-8)
$inv_mu = @()
$vocs = @()
foreach ($mu in $mobilities) {
$run_dir = Join-Path $base_dir ("mu_{0:0e}" -f $mu)
$info_path = Join-Path $run_dir "sim_info.dat"
if (-not (Test-Path -Path $info_path -PathType Leaf)) {
throw ("Missing sim_info.dat in: {0}" -f $run_dir)
}
$txt = Get-Content -Path $info_path -Raw
$info = $txt | ConvertFrom-Json
$vocs += [double]$info.Voc
$inv_mu += (1.0 / [double]$mu)
}
# Write a small summary table to disk
$out_path = Join-Path $base_dir "voc_vs_inv_mobility.dat"
"# inv_mobility(1/mu) Voc(V)" | Set-Content -Path $out_path -Encoding UTF8
for ($i = 0; $i -lt $mobilities.Count; $i++) {
("{0:e6} {1}" -f $inv_mu[$i], $vocs[$i]) | Add-Content -Path $out_path -Encoding UTF8
}
# Plot Voc vs inverse mobility
# PowerShell does not have a built-in plotting window. The simplest workflow is to
# load voc_vs_inv_mobility.dat into your plotting tool of choice (MATLAB, Python, Excel, etc.).