# 458887866/gsvit_copy architecture

> Architecture diagram of the GitHub repository 458887866/gsvit_copy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/458887866/gsvit_copy
- Repository: https://github.com/458887866/gsvit_copy

## Overview

##### Project type and purpose
- GSvit is a scientific computing tool (FDTD solver) targeting 2D and 3D electromagnetic simulations on CPU and NVIDIA GPUs.
- It is a command-line core engine (“gsvit”) with optional integration points for GUI frontends (Gwyddion) and a CUDA runtime.

##### File structure
- Top-level: standard GNU autotools build (“configure”, “Makefile.am/in”), meta-files (README, INSTALL, AUTHORS), a “data” directory, and a “tests” directory.
- src2d/ and src3d/: the two main computational modules, each containing:
- core algorithmic units (boundary, source, pool, plan, farfield, etc.)
- platform-specific backends (gpu.c + gpu_kernels.cu for CUDA; plain C routines for CPU)
- I/O layers (output.c/h, settings.c/h)
- 3D only: GUI-stub modules (xs_* files) for future GUIs
- tests/: self-tests organized by numeric IDs; harness Makefiles.
- External dependencies configured via flags: --with-cuda, --with-gwyddion.

##### Extract insights from the README
- Core engine only; GUIs planned later.
- Uses GNU build (./configure; make; make install).
- Optional CUDA and Gwyddion integration.
- Cross-platform build support (Linux, mingw32).

a. Main components
1. Build System (Autotools)
2. CLI Frontend (“gsvit” binary)
3. Computational Core
– 2D Module (src2d)
– 3D Module (src3d)
4. Compute Backends
– CPU routines
– GPU routines (CUDA kernels)
5. I/O Layer
– Input parser (.par files, “data/”)
– Output writer (binary/text, Gwyddion APIs)
6. Tests Harness (tests/)
7. External Services
– NVIDIA CUDA runtime
– Gwyddion library
b. Relationships and data flows
- Build System → compiles → CLI Frontend + Core modules + Tests
- User CLI invocation → Input Parser → Settings → Planner → Compute Core
- Compute Core → selects CPU or GPU backend → executes kernels
- After compute → Output Layer → writes to file (optionally Gwyddion)
- Tests Harness → runs CLI with test inputs → verifies outputs
c. Architectural patterns
- Modular separation of concerns: parsing, planning, compute, output
- Strategy pattern for CPU vs GPU backends
- Clear 2D vs 3D module layering
- Autotools for portability and configuration
d. Key technologies
- C99 codebase
- CUDA for GPU acceleration
- GNU Autotools (autoconf, automake)
- Optional third-party Gwyddion library

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build System
    subgraph "Build System"
        Configure["./configure"]:::build
        ConfigureAC["configure.ac"]:::build
        Automake["Makefile.am / Makefile.in"]:::build
        Aclocal["aclocal.m4"]:::build
        Scripts["install-sh, missing, depcomp, compile"]:::build
    end

    %% CLI Frontends
    subgraph "CLI Frontend"
        SVIT2D["svit2d (2D CLI)"]:::core
        SVIT3D["svit (3D CLI)"]:::core
    end

    %% Computational Core
    subgraph "Computational Core"
        Core2D["2D Module"]:::core
        Core3D["3D Module"]:::core
    end

    %% Compute Backends
    subgraph "Compute Backends"
        CPU2D["CPU Backend (2D)"]:::cpu
        CPU3D["CPU Backend (3D)"]:::cpu
        GPU2D["GPU Backend (2D)"]:::gpu
        GPU3D["GPU Backend (3D)"]:::gpu
    end

    %% I/O Layers
    subgraph "I/O Layer"
        IO2D["I/O 2D"]:::io
        IO3D["I/O 3D"]:::io
    end

    %% GUI Stub Modules
    GUI3D["3D GUI Stubs"]:::external

    %% Tests Harness
    Tests["Tests Harness"]:::tests

    %% External Services
    subgraph "External Services"
        CUDA["NVIDIA CUDA Runtime"]:::external
        Gwyddion["Gwyddion Library"]:::external
    end

    %% Build Flow
    Configure -->|generates| Automake
    Automake -->|creates| ConfigureAC
    Configure -->|prepares| Scripts
    Configure -->|creates| Automake
    Configure -->|drives| SVIT2D
    Configure -->|drives| SVIT3D
    Configure -->|drives| Core2D
    Configure -->|drives| Core3D
    Configure -->|drives| Tests

    %% Runtime Flow
    User["User CLI"]:::external -->|invokes .par| SVIT2D
    User -->|invokes .par| SVIT3D

    subgraph "2D Pipeline"
        SVIT2D -->|parse params| IO2D
        IO2D -->|settings| Core2D
        Core2D -->|select backend| CPU2D
        Core2D -->|select backend| GPU2D
        CPU2D -->|compute field arrays| Core2D
        GPU2D -->|launch kernels| CUDA
        Core2D -->|output arrays| IO2D
        IO2D -->|writes .bin/.txt| FileSystem["File System"]:::external
    end

    subgraph "3D Pipeline"
        SVIT3D -->|parse params| IO3D
        IO3D -->|settings| Core3D
        Core3D -->|select backend| CPU3D
        Core3D -->|select backend| GPU3D
        CPU3D -->|compute field arrays| Core3D
        GPU3D -->|launch kernels| CUDA
        Core3D -->|output arrays| IO3D
        IO3D -->|writes .gwy| Gwyddion
        IO3D -->|writes files| FileSystem
        Core3D -->|future GUI| GUI3D
    end

    %% Tests Flow
    Tests -->|runs CLI| SVIT2D
    Tests -->|runs CLI| SVIT3D
    Tests -->|verify outputs| FileSystem

    %% Click Events
    click Configure "https://github.com/458887866/gsvit_copy/tree/main/./configure"
    click ConfigureAC "https://github.com/458887866/gsvit_copy/blob/main/configure.ac"
    click Aclocal "https://github.com/458887866/gsvit_copy/blob/main/aclocal.m4"
    click Automake "https://github.com/458887866/gsvit_copy/blob/main/Makefile.am"
    click Scripts "https://github.com/458887866/gsvit_copy/tree/main/install-sh"
    click SVIT2D "https://github.com/458887866/gsvit_copy/blob/main/src2d/svit2d.c"
    click SVIT3D "https://github.com/458887866/gsvit_copy/blob/main/src3d/svit.c"
    click Core2D "https://github.com/458887866/gsvit_copy/tree/main/src2d/"
    click Core3D "https://github.com/458887866/gsvit_copy/tree/main/src3d/"
    click CPU2D "https://github.com/458887866/gsvit_copy/tree/main/src2d/"
    click CPU3D "https://github.com/458887866/gsvit_copy/tree/main/src3d/"
    click GPU2D "https://github.com/458887866/gsvit_copy/blob/main/src2d/gpu.c"
    click GPU3D "https://github.com/458887866/gsvit_copy/blob/main/src3d/gpu.c"
    click IO2D "https://github.com/458887866/gsvit_copy/tree/main/src2d/"
    click IO3D "https://github.com/458887866/gsvit_copy/tree/main/src3d/"
    click GUI3D "https://github.com/458887866/gsvit_copy/blob/main/src3d/xs_dialogs.c"
    click Tests "https://github.com/458887866/gsvit_copy/tree/main/tests/"

    %% Styles
    classDef build fill:#dddddd,stroke:#999;
    classDef core fill:#cce5ff,stroke:#4d83ff;
    classDef cpu fill:#d4edda,stroke:#28a745;
    classDef gpu fill:#ffe5b4,stroke:#ff8c00;
    classDef io fill:#e2f0f9,stroke:#17a2b8;
    classDef external fill:#f3e5ff,stroke:#9c27b0,stroke-dasharray: 5 5;
    classDef tests fill:#f8d7da,stroke:#dc3545,stroke-dasharray: 2 2;
```
