# pak9819/femai architecture

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

- Interactive diagram: https://gitdiagram.com/pak9819/femai
- Repository: https://github.com/pak9819/femai
- Video tour (about a minute): https://gitdiagram.com/pak9819/femai/video

## Overview

FEMAI is a MATLAB finite-element application centered on classic and AI-driven linear/nonlinear quad4 elements, with Python training and verification workflows for learned element models. The main user workflow runs an example, builds a model, solves it through element dispatch and assembly, then computes and plots results. The README documents the training/deployment branches; sampled source supports the energy-based training and reference-verification details, but most MATLAB runtime wiring was not sampled.

Main entry points: [`sourcecode/solver/solve_nonlinear_FE.m`](https://github.com/pak9819/femai/blob/master/sourcecode/solver/solve_nonlinear_FE.m) (Nonlinear solve), [`sourcecode/elements/element_library.m`](https://github.com/pak9819/femai/blob/master/sourcecode/elements/element_library.m) (Element library), [`examples`](https://github.com/pak9819/femai/tree/master/examples) (Example entry), [`sourcecode/elements/quad4`](https://github.com/pak9819/femai/tree/master/sourcecode/elements/quad4) (Deployed networks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["MATLAB Runtime"]
  node_model_setup["Model setup"]
  node_rectangle_mesh["Rectangle mesh"]
  node_linear_solver["Linear solve<br/>[solve_linear_FE.m]"]
  node_nonlinear_solver["Nonlinear solve"]
  node_newton["Newton method<br/>[newton.m]"]
  node_system_solver["System solve<br/>[solve_system.m]"]
  node_assembly["Global assembly<br/>[assemble.m]"]
  node_results["Result evaluation"]
  node_reactions["Reaction forces"]
  node_plots["Result plots<br/>[plot_results.m]"]
end

subgraph group_elements["Quad4 Elements"]
  node_element_dispatch["Element dispatch<br/>[element_routine.m]"]
  node_element_library["Element library<br/>[element_library.m]"]
  node_quad4_linear["Linear quad4"]
  node_quad4_linear_ai["AI linear quad4"]
  node_quad4_nonlinear["Nonlinear quad4<br/>[element_quad4_nl.m]"]
  node_quad4_nonlinear_ai["AI nonlinear quad4"]
  node_energy_model["Energy network"]
  node_material["Material laws"]
  node_network_files[("Deployed networks")]
end

subgraph group_training["Training and Verification"]
  node_training_data["Training trajectories"]
  node_reference["Analytical reference<br/>[quad4_nl_ref.py]"]
  node_train_energy["StVenant training"]
  node_train_neo["Neo-Hooke training"]
  node_oracle_export["MATLAB oracle export<br/>[export_nh_oracle.m]"]
end

subgraph group_examples["Examples and Results"]
  node_examples_entry["Example entry"]
end

node_user(("Engineer"))

node_user -->|"runs"| node_examples_entry
node_examples_entry -->|"sets up"| node_model_setup
node_model_setup -->|"creates mesh"| node_rectangle_mesh
node_examples_entry -->|"selects linear"| node_linear_solver
node_examples_entry -->|"selects nonlinear"| node_nonlinear_solver
node_linear_solver -->|"solves system"| node_system_solver
node_nonlinear_solver -->|"uses iterations"| node_newton
node_nonlinear_solver -->|"solves system"| node_system_solver
node_system_solver -->|"assembles"| node_assembly
node_assembly -->|"requests elements"| node_element_dispatch
node_element_dispatch -->|"dispatches"| node_element_library
node_element_library -->|"selects classic"| node_quad4_linear
node_element_library -->|"selects AI"| node_quad4_linear_ai
node_element_library -->|"selects classic"| node_quad4_nonlinear
node_element_library -->|"selects AI"| node_quad4_nonlinear_ai
node_quad4_linear -->|"uses laws"| node_material
node_quad4_nonlinear -->|"uses laws"| node_material
node_quad4_nonlinear_ai -->|"evaluates energy"| node_energy_model
node_quad4_linear_ai -.->|"loads weights"| node_network_files
node_energy_model -->|"loads weights"| node_network_files
node_nonlinear_solver -->|"computes results"| node_results
node_nonlinear_solver -->|"computes reactions"| node_reactions
node_results -->|"plots results"| node_plots
node_user -.->|"generates data"| node_training_data
node_training_data -.->|"supplies trajectories"| node_train_energy
node_reference -->|"provides targets"| node_train_energy
node_reference -->|"provides base math"| node_train_neo
node_oracle_export -.->|"exports oracle data"| node_train_neo
node_train_energy -->|"deploys StVenant"| node_network_files
node_train_neo -.->|"deploys Neo-Hooke"| node_network_files

click node_examples_entry "https://github.com/pak9819/femai/tree/master/examples"
click node_model_setup "https://github.com/pak9819/femai/tree/master/sourcecode/model"
click node_rectangle_mesh "https://github.com/pak9819/femai/blob/master/sourcecode/mesh/create_model_data_rectangle.m"
click node_linear_solver "https://github.com/pak9819/femai/blob/master/sourcecode/solver/solve_linear_FE.m"
click node_nonlinear_solver "https://github.com/pak9819/femai/blob/master/sourcecode/solver/solve_nonlinear_FE.m"
click node_newton "https://github.com/pak9819/femai/blob/master/sourcecode/solver/newton.m"
click node_system_solver "https://github.com/pak9819/femai/blob/master/sourcecode/solver/solve_system.m"
click node_assembly "https://github.com/pak9819/femai/blob/master/sourcecode/solver/assemble.m"
click node_element_dispatch "https://github.com/pak9819/femai/blob/master/sourcecode/elements/element_routine.m"
click node_element_library "https://github.com/pak9819/femai/blob/master/sourcecode/elements/element_library.m"
click node_quad4_linear "https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/element_quad4_lin.m"
click node_quad4_linear_ai "https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/element_quad4_lin_ai.m"
click node_quad4_nonlinear "https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/element_quad4_nl.m"
click node_quad4_nonlinear_ai "https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/element_quad4_nl_ai.m"
click node_energy_model "https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/quad4_nl_ai_model.m"
click node_material "https://github.com/pak9819/femai/blob/master/sourcecode/material/material_elasticity.m"
click node_results "https://github.com/pak9819/femai/blob/master/sourcecode/postprocessing/compute_model_results.m"
click node_reactions "https://github.com/pak9819/femai/blob/master/sourcecode/postprocessing/compute_reaction_forces.m"
click node_plots "https://github.com/pak9819/femai/blob/master/sourcecode/postprocessing/plot_results.m"
click node_training_data "https://github.com/pak9819/femai/blob/master/training/quad4/generate_newton_trajectories.m"
click node_reference "https://github.com/pak9819/femai/blob/master/training/quad4/quad4_nl_ref.py"
click node_train_energy "https://github.com/pak9819/femai/blob/master/training/quad4/train_quad4_nl_W_network.py"
click node_train_neo "https://github.com/pak9819/femai/blob/master/training/quad4/train_quad4_nl_W_network_neohooke.py"
click node_oracle_export "https://github.com/pak9819/femai/blob/master/training/quad4/export_nh_oracle.m"
click node_network_files "https://github.com/pak9819/femai/tree/master/sourcecode/elements/quad4"

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_model_setup,node_rectangle_mesh,node_linear_solver,node_nonlinear_solver,node_newton,node_system_solver,node_assembly,node_results,node_reactions,node_plots toneBlue
class node_element_dispatch,node_element_library,node_quad4_linear,node_quad4_linear_ai,node_quad4_nonlinear,node_quad4_nonlinear_ai,node_energy_model,node_material,node_network_files toneAmber
class node_training_data,node_reference,node_train_energy,node_train_neo,node_oracle_export toneMint
class node_examples_entry toneRose
class node_user toneIndigo
```

## Components

### MATLAB Runtime

- [Model setup](https://github.com/pak9819/femai/tree/master/sourcecode/model): `sourcecode/model`
- [Rectangle mesh](https://github.com/pak9819/femai/blob/master/sourcecode/mesh/create_model_data_rectangle.m): `sourcecode/mesh/create_model_data_rectangle.m`
- [Linear solve](https://github.com/pak9819/femai/blob/master/sourcecode/solver/solve_linear_FE.m): `sourcecode/solver/solve_linear_FE.m`
- [Nonlinear solve](https://github.com/pak9819/femai/blob/master/sourcecode/solver/solve_nonlinear_FE.m): `sourcecode/solver/solve_nonlinear_FE.m`
- [Newton method](https://github.com/pak9819/femai/blob/master/sourcecode/solver/newton.m): `sourcecode/solver/newton.m`
- [System solve](https://github.com/pak9819/femai/blob/master/sourcecode/solver/solve_system.m): `sourcecode/solver/solve_system.m`
- [Global assembly](https://github.com/pak9819/femai/blob/master/sourcecode/solver/assemble.m): `sourcecode/solver/assemble.m`
- [Result evaluation](https://github.com/pak9819/femai/blob/master/sourcecode/postprocessing/compute_model_results.m): `sourcecode/postprocessing/compute_model_results.m`
- [Reaction forces](https://github.com/pak9819/femai/blob/master/sourcecode/postprocessing/compute_reaction_forces.m): `sourcecode/postprocessing/compute_reaction_forces.m`
- [Result plots](https://github.com/pak9819/femai/blob/master/sourcecode/postprocessing/plot_results.m): `sourcecode/postprocessing/plot_results.m`

### Quad4 Elements

- [Element dispatch](https://github.com/pak9819/femai/blob/master/sourcecode/elements/element_routine.m): `sourcecode/elements/element_routine.m`
- [Element library](https://github.com/pak9819/femai/blob/master/sourcecode/elements/element_library.m): `sourcecode/elements/element_library.m`
- [Linear quad4](https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/element_quad4_lin.m): `sourcecode/elements/quad4/element_quad4_lin.m`
- [AI linear quad4](https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/element_quad4_lin_ai.m): `sourcecode/elements/quad4/element_quad4_lin_ai.m`
- [Nonlinear quad4](https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/element_quad4_nl.m): `sourcecode/elements/quad4/element_quad4_nl.m`
- [AI nonlinear quad4](https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/element_quad4_nl_ai.m): `sourcecode/elements/quad4/element_quad4_nl_ai.m`
- [Energy network](https://github.com/pak9819/femai/blob/master/sourcecode/elements/quad4/quad4_nl_ai_model.m): `sourcecode/elements/quad4/quad4_nl_ai_model.m`
- [Material laws](https://github.com/pak9819/femai/blob/master/sourcecode/material/material_elasticity.m): `sourcecode/material/material_elasticity.m`
- [Deployed networks](https://github.com/pak9819/femai/tree/master/sourcecode/elements/quad4): `sourcecode/elements/quad4`

### Training and Verification

- [Training trajectories](https://github.com/pak9819/femai/blob/master/training/quad4/generate_newton_trajectories.m): `training/quad4/generate_newton_trajectories.m`
- [Analytical reference](https://github.com/pak9819/femai/blob/master/training/quad4/quad4_nl_ref.py): `training/quad4/quad4_nl_ref.py`
- [StVenant training](https://github.com/pak9819/femai/blob/master/training/quad4/train_quad4_nl_W_network.py): `training/quad4/train_quad4_nl_W_network.py`
- [Neo-Hooke training](https://github.com/pak9819/femai/blob/master/training/quad4/train_quad4_nl_W_network_neohooke.py): `training/quad4/train_quad4_nl_W_network_neohooke.py`
- [MATLAB oracle export](https://github.com/pak9819/femai/blob/master/training/quad4/export_nh_oracle.m): `training/quad4/export_nh_oracle.m`

### Examples and Results

- [Example entry](https://github.com/pak9819/femai/tree/master/examples): `examples`

### Other components

- **Engineer**

## Connections

- Engineer → Example entry: runs
- Example entry → Model setup: sets up
- Model setup → Rectangle mesh: creates mesh
- Example entry → Linear solve: selects linear
- Example entry → Nonlinear solve: selects nonlinear
- Linear solve → System solve: solves system
- Nonlinear solve → Newton method: uses iterations
- Nonlinear solve → System solve: solves system
- System solve → Global assembly: assembles
- Global assembly → Element dispatch: requests elements
- Element dispatch → Element library: dispatches
- Element library → Linear quad4: selects classic
- Element library → AI linear quad4: selects AI
- Element library → Nonlinear quad4: selects classic
- Element library → AI nonlinear quad4: selects AI
- Linear quad4 → Material laws: uses laws
- Nonlinear quad4 → Material laws: uses laws
- AI nonlinear quad4 → Energy network: evaluates energy
- AI linear quad4 → Deployed networks: loads weights
- Energy network → Deployed networks: loads weights
- Nonlinear solve → Result evaluation: computes results
- Nonlinear solve → Reaction forces: computes reactions
- Result evaluation → Result plots: plots results
- Engineer → Training trajectories: generates data
- Training trajectories → StVenant training: supplies trajectories
- Analytical reference → StVenant training: provides targets
- Analytical reference → Neo-Hooke training: provides base math
- MATLAB oracle export → Neo-Hooke training: exports oracle data
- StVenant training → Deployed networks: deploys StVenant
- Neo-Hooke training → Deployed networks: deploys Neo-Hooke
