# mvarga6/lcefe architecture

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

- Interactive diagram: https://gitdiagram.com/mvarga6/lcefe
- Repository: https://github.com/mvarga6/lcefe

## Overview

1. This repository is a CUDA/C++ scientific simulation code for liquid crystal elastomer finite element electrodynamics. The core architecture is a CPU orchestration layer that prepares mesh/material state, and a GPU compute layer that advances the simulation over time.

2. The main executable lives in `src/main.cpp` and is driven by runtime parameters from either command-line arguments or a parameter file. `include/clparse.h`, `src/clparse.cpp`, and the bundled `extlib/cxxopts` provide option parsing; `include/parameters_reader.h` / `src/parameters_reader.cpp` handle parameter-file input, including JSON via the bundled `extlib/jsmn`.

3. Mesh input is an important boundary. The repo contains Gmsh geometry sources in `geo/` and many prebuilt meshes in `Mesh/`. `extlib/gmsh_io` supports reading Gmsh mesh data, and the README points to `getmesh.h` as the entry point for loading and reordering the mesh (`get_mesh`, `gorder_tet`).

4. CPU-side mesh representation is centered on `NodeArray` and `TetArray` in `include/classstruct.h`, with implementations in `src/node_array.cpp` and `src/tet_array.cpp`. These structures are used to optimize mesh ordering and organize node/tetrahedron data before it is transferred to the device.

5. A distinct packing boundary exists between host data and GPU data. The README calls out `packdata.h` as the place where mesh and initial conditions are copied into GPU-friendly arrays. Related headers like `include/pointer.h`, `include/device_helpers.h`, and `include/kernel_constants.h` suggest explicit management of device buffers and constants.

6. The physics layer is separated from orchestration. `include/physics_model.h`, `include/physics_kernels.h`, `src/physics_model.cpp`, `src/physics_kernels.cpp`, and `src/selinger_physics.cpp` encapsulate the material and force models, including the liquid-crystal coupling terms described in the README (`density`, `alpha`, `cxxxx`, `cxxyy`, `cxyxy`).

7. The simulation loop is coordinated by `include/simulation_runner.h` and `src/simulation_runner.cpp`, with the README explicitly noting `rundynamics.h` as the driver of the full dynamics loop. This layer is responsible for stepping time, invoking GPU kernels, and managing when output is produced.

8. GPU computation is split into at least two major kernels. The force path is described in the README as `gpuForce.h`, which depends on `forcecalc.h`, `read_dev_data.h`, `getQ.h`, and `sendForce.h`. The update path is `updateKernel.h`, which uses `update_r.h` and `sumForce.h` to integrate node positions from accumulated forces.

9. Director-field and energy calculations are first-class pieces of the model. Headers like `include/director_field.h`, `include/getQ.h`, `include/getEnergy.h`, `include/getSurface.h`, `include/sumForce.h`, and `include/getAs.h` indicate that the simulation repeatedly derives per-element director orientation, energy, surface terms, and force accumulation from the mesh state.

10. Output, logging, and diagnostics are separate from the solver. `include/output_writer.h`, `include/printVTKframe.h`, and `include/parameters_writer.h` suggest file-based results and visualization export, while `include/logger.h`, `src/logger.cpp`, `src/console_logger.cpp`, and `include/performance_recorder.h` / `src/performance_recorder.cpp` handle runtime logging and timing. The `Performance/` directory stores timing data.

11. The repository is organized for experimentation rather than serving as a library. `params/` contains scenario presets such as `WareCross.json`, `aisin.json`, and `thinfilm4.json`; `scripts/` contains shell and job scripts for running angle, intensity, and rate experiments; and `bin/printgpuinfo` plus `gpuinfo.cu` indicate GPU capability inspection as part of the workflow.

12. `legacy/` contains older implementations of mesh, force, and run-dynamics logic, which suggests the current codebase evolved from an earlier design but keeps historical code around for reference. For architecture diagrams, treat `src/` + `include/` as the active pipeline, `Mesh/` + `geo/` as input assets, `params/` and `scripts/` as experiment control, and `Performance/`/output writers as the observation layer.

Main entry points: [`src/simulation_runner.cpp`](https://github.com/mvarga6/lcefe/blob/main/src/simulation_runner.cpp) (Simulation run), [`src/parameters_reader.cpp`](https://github.com/mvarga6/lcefe/blob/main/src/parameters_reader.cpp) (Param reader), [`include/pointer.h`](https://github.com/mvarga6/lcefe/blob/main/include/pointer.h) (Pack data), [`src/main.cpp`](https://github.com/mvarga6/lcefe/blob/main/src/main.cpp) (Main)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_active["Active solver"]
  node_n_main["Main<br/>executable<br/>[main.cpp]"]
  node_n_cli["CLI parse<br/>runtime config<br/>[clparse.cpp]"]
  node_n_params["Param reader<br/>config I/O"]
  node_n_mesh_io["Mesh IO<br/>mesh import<br/>[getgmsh.h]"]
  node_n_mesh_core[("Mesh arrays<br/>host mesh<br/>[classstruct.h]")]
  node_n_mesh_impl["Mesh ops<br/>mesh processing<br/>[mesh.cpp]"]
  node_n_pack["Pack data<br/>host-device bridge<br/>[pointer.h]"]
  node_n_phys_model["Physics model<br/>material model<br/>[physics_model.h]"]
  node_n_director["Director field<br/>field solve<br/>[director_field.h]"]
  node_n_forces["Force path<br/>gpu kernel<br/>[physics_kernels.h]"]
  node_n_update["Update kernel<br/>gpu kernel<br/>[updateKernel.h]"]
  node_n_runner["Simulation run<br/>time stepping"]
end

subgraph group_g_inputs["Inputs"]
  node_n_mesh_assets["Mesh assets<br/>input assets"]
  node_n_params_assets["Scenarios<br/>input presets<br/>[WareCross.json]"]
end

subgraph group_g_obs["Output and diagnostics"]
  node_n_out["Output writer<br/>results export<br/>[output_writer.h]"]
  node_n_log["Logger<br/>diagnostics<br/>[logger.cpp]"]
  node_n_perf["Timing<br/>profiling"]
end

subgraph group_g_legacy["Legacy layer"]
  node_n_legacy["Legacy solver<br/>legacy pipeline<br/>[rundynamics.h]"]
end

node_n_main -->|"reads args"| node_n_cli
node_n_main -->|"loads config"| node_n_params
node_n_cli -->|"selects file"| node_n_params
node_n_params -->|"builds run"| node_n_runner
node_n_mesh_assets -->|"provide mesh"| node_n_mesh_io
node_n_mesh_io -->|"fills arrays"| node_n_mesh_core
node_n_mesh_core -->|"processed by"| node_n_mesh_impl
node_n_mesh_impl -->|"prepared for device"| node_n_pack
node_n_params_assets -->|"preset input"| node_n_params
node_n_pack -->|"attaches fields"| node_n_phys_model
node_n_phys_model -->|"drives field"| node_n_director
node_n_director -->|"feeds state"| node_n_forces
node_n_forces -->|"accumulates force"| node_n_update
node_n_update -->|"advances step"| node_n_runner
node_n_runner -->|"writes results"| node_n_out
node_n_runner -->|"logs run"| node_n_log
node_n_runner -->|"records timing"| node_n_perf
node_n_legacy -.->|"historical precursor"| node_n_pack
node_n_legacy -.->|"historical precursor"| node_n_runner

click node_n_main "https://github.com/mvarga6/lcefe/blob/main/src/main.cpp"
click node_n_cli "https://github.com/mvarga6/lcefe/blob/main/src/clparse.cpp"
click node_n_params "https://github.com/mvarga6/lcefe/blob/main/src/parameters_reader.cpp"
click node_n_mesh_io "https://github.com/mvarga6/lcefe/blob/main/include/getgmsh.h"
click node_n_mesh_core "https://github.com/mvarga6/lcefe/blob/main/include/classstruct.h"
click node_n_mesh_impl "https://github.com/mvarga6/lcefe/blob/main/src/mesh.cpp"
click node_n_pack "https://github.com/mvarga6/lcefe/blob/main/include/pointer.h"
click node_n_phys_model "https://github.com/mvarga6/lcefe/blob/main/include/physics_model.h"
click node_n_director "https://github.com/mvarga6/lcefe/blob/main/include/director_field.h"
click node_n_forces "https://github.com/mvarga6/lcefe/blob/main/include/physics_kernels.h"
click node_n_update "https://github.com/mvarga6/lcefe/blob/main/include/updateKernel.h"
click node_n_runner "https://github.com/mvarga6/lcefe/blob/main/src/simulation_runner.cpp"
click node_n_out "https://github.com/mvarga6/lcefe/blob/main/include/output_writer.h"
click node_n_log "https://github.com/mvarga6/lcefe/blob/main/src/logger.cpp"
click node_n_perf "https://github.com/mvarga6/lcefe/blob/main/src/performance_recorder.cpp"
click node_n_mesh_assets "https://github.com/mvarga6/lcefe/blob/main/Mesh/SphericalShell1.msh"
click node_n_params_assets "https://github.com/mvarga6/lcefe/blob/main/params/WareCross.json"
click node_n_legacy "https://github.com/mvarga6/lcefe/blob/main/legacy/rundynamics.h"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_main,node_n_cli,node_n_params,node_n_mesh_io,node_n_mesh_core,node_n_mesh_impl,node_n_pack,node_n_phys_model,node_n_director,node_n_forces,node_n_update,node_n_runner toneBlue
class node_n_mesh_assets,node_n_params_assets toneAmber
class node_n_out,node_n_log,node_n_perf toneMint
class node_n_legacy toneRose
```

## Components

### Active solver

Current CPU/GPU simulation pipeline in src/ and include/

- [Main](https://github.com/mvarga6/lcefe/blob/main/src/main.cpp): executable · Program entrypoint and startup orchestration · `src/main.cpp`
- [CLI parse](https://github.com/mvarga6/lcefe/blob/main/src/clparse.cpp): runtime config · Command-line option parsing and parameter-file selection · `src/clparse.cpp`
- [Param reader](https://github.com/mvarga6/lcefe/blob/main/src/parameters_reader.cpp): config I/O · Reads simulation parameter files including JSON · `src/parameters_reader.cpp`
- [Mesh IO](https://github.com/mvarga6/lcefe/blob/main/include/getgmsh.h): mesh import · Loads and reorders mesh data from Gmsh sources · `include/getgmsh.h`
- [Mesh arrays](https://github.com/mvarga6/lcefe/blob/main/include/classstruct.h): host mesh · CPU-side node and tetrahedron containers · `include/classstruct.h`
- [Mesh ops](https://github.com/mvarga6/lcefe/blob/main/src/mesh.cpp): mesh processing · Mesh representation and ordering helpers · `src/mesh.cpp`
- [Pack data](https://github.com/mvarga6/lcefe/blob/main/include/pointer.h): host-device bridge · Prepares mesh and initial conditions for GPU transfer · `include/pointer.h`
- [Physics model](https://github.com/mvarga6/lcefe/blob/main/include/physics_model.h): material model · Material parameters and continuum model definitions · `include/physics_model.h`
- [Director field](https://github.com/mvarga6/lcefe/blob/main/include/director_field.h): field solve · Derives director orientation and related per-element state · `include/director_field.h`
- [Force path](https://github.com/mvarga6/lcefe/blob/main/include/physics_kernels.h): gpu kernel · Computes forces from field, energy, and surface terms · `include/physics_kernels.h`
- [Update kernel](https://github.com/mvarga6/lcefe/blob/main/include/updateKernel.h): gpu kernel · Integrates positions from accumulated forces · `include/updateKernel.h`
- [Simulation run](https://github.com/mvarga6/lcefe/blob/main/src/simulation_runner.cpp): time stepping · Coordinates the full dynamics loop and kernel dispatch · `src/simulation_runner.cpp`

### Inputs

Mesh assets and runtime parameter presets

- [Mesh assets](https://github.com/mvarga6/lcefe/blob/main/Mesh/SphericalShell1.msh): input assets · Prebuilt meshes and geometry sources used for simulation setup · `Mesh/SphericalShell1.msh`
- [Scenarios](https://github.com/mvarga6/lcefe/blob/main/params/WareCross.json): input presets · Preset experiment parameter files · `params/WareCross.json`

### Output and diagnostics

Logging, timing, and exported results

- [Output writer](https://github.com/mvarga6/lcefe/blob/main/include/output_writer.h): results export · Writes simulation outputs and visualization frames · `include/output_writer.h`
- [Logger](https://github.com/mvarga6/lcefe/blob/main/src/logger.cpp): diagnostics · Runtime logging and console reporting · `src/logger.cpp`
- [Timing](https://github.com/mvarga6/lcefe/blob/main/src/performance_recorder.cpp): profiling · Records and stores performance measurements · `src/performance_recorder.cpp`

### Legacy layer

Older implementation kept for reference

- [Legacy solver](https://github.com/mvarga6/lcefe/blob/main/legacy/rundynamics.h): legacy pipeline · Older mesh, packing, force, and dynamics implementation · `legacy/rundynamics.h`

## Connections

- Main → CLI parse: reads args · Startup pulls runtime options from the command line
- Main → Param reader: loads config · Main initializes simulation parameters from file input
- CLI parse → Param reader: selects file · CLI can point to a parameter preset or override input
- Param reader → Simulation run: builds run · Parsed parameters feed the simulation runner
- Mesh assets → Mesh IO: provide mesh · Geometry and mesh files are the source boundary for loading
- Mesh IO → Mesh arrays: fills arrays · Imported mesh is organized into node and tetrahedron storage
- Mesh arrays → Mesh ops: processed by · Host mesh structures are optimized and reordered
- Mesh ops → Pack data: prepared for device · Processed mesh state is packed for GPU consumption
- Scenarios → Param reader: preset input · Scenario JSON files are read by the parameter loader
- Pack data → Physics model: attaches fields · Packed device data is combined with material model parameters
- Physics model → Director field: drives field · Physics model informs director-field calculations
- Director field → Force path: feeds state · Director orientation contributes to force and energy evaluation
- Force path → Update kernel: accumulates force · Force computation supplies inputs for the update kernel
- Update kernel → Simulation run: advances step · Kernel integration is controlled by the simulation loop
- Simulation run → Output writer: writes results · Time stepping triggers file output and visualization export
- Simulation run → Logger: logs run · Runner emits runtime diagnostics and status messages
- Simulation run → Timing: records timing · Execution phases are measured for performance tracking
- Legacy solver → Pack data: historical precursor · Legacy packing logic shows the older host-to-device boundary
- Legacy solver → Simulation run: historical precursor · Legacy run-dynamics code maps to the current simulation loop
