# mfjamao/unified-solar-cell-simulation architecture

> Architecture diagram of the GitHub repository mfjamao/unified-solar-cell-simulation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mfjamao/unified-solar-cell-simulation
- Repository: https://github.com/mfjamao/unified-solar-cell-simulation

## Overview

##### Project Type and Purpose
- UniSolar is a simulation framework designed to streamline and “unify” multidimensional solar cell simulations.
- Its purpose is to allow users to generate process, optical, and electrical simulation workflows (all driven by 11 common simulation steps) simply by tuning variable values in a plain text configuration file.
- It leverages external commercial software (Sentaurus TCAD) to perform the heavy-duty simulation while managing the entire process via Tcl scripts.

##### File Structure
- Core script files at the root include key Tcl files:
- 11ctrlsim.tcl (the main control/driver script), which orchestrates the simulation workflow.
- 12savetpl.tcl and 13loadtpl.tcl (for archiving and retrieving simulation “templates” or prior run files in .tgz format).
- Other helper scripts (e.g., svisual_vis.tcl, sdevice.par, various *.cmd files) which support device simulation parameters, visualization, and process commands.
- The .mfj directory contains modules such as:
- mfjGrm.tcl (grammar checking),
- mfjIntrpr.tcl (interpreter),
- mfjProc.tcl and mfjST.tcl – all of which form the backbone for processing and validating the simulation input (i.e., the “grammar” and variable configuration).
- Configuration files like 10variables.txt and 10variables-brief.txt define simulation parameters and DOE settings.
- Directories such as 07tpl store templates and examples (often with demo files and archived simulation files) that illustrate the use case scenarios.
- Some auxiliary or experimental files (e.g., 04code, randtexture.tcl) and documentation (README.md) also exist.

##### README for Additional Insights
- The README clearly lists the simulation workflow, describing how key files are used to check grammar, convert variables, interface with Sentaurus, execute simulations, and save/load configurations.
- It also mentions the importance of adjusting Sentaurus connection parameters (hosts, paths, licensing, etc.), which points toward an external dependency integration.
- The document explains the “11-step” simulation control approach and hints that the design should reflect the separation between simulation control, configuration, processing, and external execution (via Sentaurus).

##### Main Components
- Input/Configuration Layer:
- The DOE / User Input files: 10variables.txt and 10variables-brief.txt.
- Additional input files such as Molefraction.txt, datexcodes.txt.
- Processing & Validation Layer:
- The .mfj modules (mfjGrm.tcl, mfjIntrpr.tcl, mfjProc.tcl, mfjST.tcl) responsible for grammar checking and interpretation.
- The main control file, 11ctrlsim.tcl, that calls these modules.
- Simulation Execution Layer:
- The interface to the external simulation package Sentaurus TCAD, which is invoked by 11ctrlsim.tcl after processing the input.
- Supporting files (such as sdevice.par, sde_dvs.cmd etc.) provide simulation-specific parameters.
- Template Management / Archiving Layer:
- 12savetpl.tcl and 13loadtpl.tcl, which manage saving and reloading simulation configurations and results.
- The 07tpl directory contains archived runs and demo cases.
- Auxiliary/Utility Components:
- Other TCL scripts like svisual_vis.tcl for visualization.
- Command scripts (sprocess_fps.cmd, sdevice_des.cmd) that might play roles in process or device simulation.

- The input configuration is read by 11ctrlsim.tcl – the central orchestrator.
- 11ctrlsim.tcl invokes the grammar and processing modules from the .mfj folder (mfjGrm.tcl, mfjIntrpr.tcl, etc.) to validate and prepare simulation parameters.
- Once validated, 11ctrlsim.tcl manages the simulation job – sending instructions to Sentaurus TCAD (conceptually represented as an external simulation engine).
- Results from Sentaurus TCAD are then handled (stored in an output directory, e.g., the “06out” directory referenced in the README even if not present in the file tree) and may be further processed or visualized using auxiliary scripts.
- The template management scripts (12savetpl.tcl and 13loadtpl.tcl) allow saving the current state or reloading a saved simulation “template.”

##### Overall Strategy
- Then drill down to show how the 11ctrlsim.tcl file acts as the hub, interfacing with both the grammar-check modules (.mfj) and the external Sentaurus.
- Finally, indicate the role of auxiliary modules like saving/loading operations for experiments (via 12savetpl.tcl and 13loadtpl.tcl).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input/Configuration Layer
    subgraph "Input/Configuration Layer"
        A1("10variables.txt"):::input
        A2("10variables-brief.txt"):::input
        A3("Molefraction.txt"):::input
        A4("datexcodes.txt"):::input
    end

    %% Control & Processing Layer
    subgraph "Control & Processing Layer"
        B1("11ctrlsim.tcl"):::processing
        subgraph "Processing Modules"
            B2("mfjGrm.tcl"):::processing
            B3("mfjIntrpr.tcl"):::processing
            B4("mfjProc.tcl"):::processing
            B5("mfjST.tcl"):::processing
        end
    end

    %% Simulation Execution Layer
    subgraph "Simulation Execution Layer"
        C1("Sentaurus TCAD"):::external
        C2("sdevice.par"):::simulation
        C3("sde_dvs.cmd"):::simulation
        C4("sdevice_des.cmd"):::simulation
        C5("sprocess_fps.cmd"):::simulation
    end

    %% Template Management / Archiving
    subgraph "Template Management / Archiving"
        D1("12savetpl.tcl"):::template
        D2("13loadtpl.tcl"):::template
        D3("07tpl"):::template
    end

    %% Auxiliary/Utility Components
    subgraph "Auxiliary/Utility Components"
        E1("svisual_vis.tcl"):::auxiliary
        E2("randtexture.tcl"):::auxiliary
    end

    %% Connections: Input to Main Controller
    A1 ---|"reads"| B1
    A2 ---|"reads"| B1
    A3 ---|"reads"| B1
    A4 ---|"reads"| B1

    %% Main Controller calls Processing Modules
    B1 ---|"calls"| B2
    B1 ---|"calls"| B3
    B1 ---|"calls"| B4
    B1 ---|"calls"| B5

    %% Main Controller initiates Simulation Execution
    B1 ---|"executes"| C1
    %% Main Controller provides simulation parameters to supporting files
    B1 ---|"configures"| C2
    B1 ---|"configures"| C3
    B1 ---|"configures"| C4
    B1 ---|"configures"| C5

    %% Simulation Execution outputs to Auxiliary Visualization
    C1 ---|"outputs"| E1

    %% Template Management interactions
    B1 ---|"saves state"| D1
    B1 ---|"loads template"| D2

    %% Click Events for Input/Configuration Files
    click A1 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/10variables.txt"
    click A2 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/10variables-brief.txt"
    click A3 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/Molefraction.txt"
    click A4 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/datexcodes.txt"

    %% Click Events for Control & Processing Layer
    click B1 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/11ctrlsim.tcl"
    click B2 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/.mfj/mfjGrm.tcl"
    click B3 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/.mfj/mfjIntrpr.tcl"
    click B4 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/.mfj/mfjProc.tcl"
    click B5 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/.mfj/mfjST.tcl"

    %% Click Events for Template Management / Archiving
    click D1 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/12savetpl.tcl"
    click D2 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/13loadtpl.tcl"
    click D3 "https://github.com/mfjamao/unified-solar-cell-simulation/tree/main/07tpl"

    %% Click Events for Simulation Execution Supporting Files
    click C2 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/sdevice.par"
    click C3 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/sde_dvs.cmd"
    click C4 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/sdevice_des.cmd"
    click C5 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/sprocess_fps.cmd"

    %% Click Events for Auxiliary/Utility Components
    click E1 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/svisual_vis.tcl"
    click E2 "https://github.com/mfjamao/unified-solar-cell-simulation/blob/main/04code/randtexture.tcl"

    %% Styles
    classDef input fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef processing fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef simulation fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef template fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef auxiliary fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA07A,stroke:#333,stroke-width:2px;
```
