# canitesc/igapack architecture

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

- Interactive diagram: https://gitdiagram.com/canitesc/igapack
- Repository: https://github.com/canitesc/igapack

## Overview

##### Overall System Breakdown
- Three major “application domains” or layers corresponding to the problem dimensions: 1D, 2D (elasticity2D), and 3D (elasticity3D). Each of these folders contains models (e.g., “Main1D.m”, “CantileverBeam.m”, “Hemisphere.m”) and associated utility subfolders (e.g., “utils1D”, “PHTutils” in the 2D and 3D folders).
- Recognize the central role of the NURBS toolbox. This module is essentially an external library (with its own license and source code) and should be shown as a supporting component that provides core geometry and basis computation routines.

##### Main Components
a. Problem/Model Layer:
– Illustrate the user-accessible MATLAB scripts that define specific benchmark problems (e.g., CantileverBeam, EdgeCrackMultiPatch, Blade, etc.).
– Indicate that each problem file uses underlying modules for mesh generation, analysis, and postprocessing.
b. Geometry, Mesh Generation, and Basis Functions:
– In each dimensional folder, highlight modules that generate geometry and define the mesh (i.e., functions like “initPHTmesh”, “initPHTmeshNoRefine” in 1D and “initPHTmesh” in 2D/3D).
– Display how basis functions are calculated (using Bernstein, Bezier extraction, deCasteljau, etc.), with a clear link to both PHT-spline generation routines and integration with NURBS routines.
c. Assembly and Solver Modules:
– Show the assembly components (for instance, “assembleGalerkin1D.m”, “assembleGalerkinSysGIFTMP.m”, etc.) where the system matrices are built.
– List solver components (such as “solution1d.m”, “stiffness1d.m” in the 1D module and similar routines in higher dimensions) that ultimately solve the discretized equations.
d. Error Estimation and Mesh Refinement:
– Identify the error estimation routines (e.g., “calcError1D.m”, “calcErrNorms1d.m”, “recoverDerivEstGalMPDorfler.m”, etc.) and adaptive refinement methods (like “refineMesh1D.m”, “refineMeshIso.m”, “refineMesh3D.m”) as central to the adaptive analysis process.
e. Visualization and Output:
– Include visualization components (plotting routines like “plotError1D.m”, “plotSolPHTElasticMP.m”, “plotStressDisp3D.m”) and the VTU file export for 3D solutions (e.g., “msh_to_vtu_3d.m”) that interface with external visualization tools such as ParaView.

##### Highlighted Architectural Patterns and Interactions
- Pattern Separation: Emphasize the separation between the core numerical routines (geometry, assembly, error estimation, and solver) and the problem-specific scripts. This separation facilitates reuse and easier testing.
- Performance Enhancements in 3D: In the 3D module, note the usage of mex files for the deCasteljau algorithm (e.g., “deCasteljau3DTP_mex.*”), which should be depicted as an optimized subcomponent that interacts with the MATLAB scripts.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Global External Dependency
    NURBS["NURBS Library"]:::external
    %% IGAPack Toolbox overall label (optional top-level wrapper)
    IGAPack["IGAPack Toolbox"]:::title

    %% 1D Analysis Subgraph
    subgraph "1D Analysis"
        A1["1D Problem/Model"]:::model
        A2["1D Mesh Generation & Basis"]:::utility
        A3["1D Assembly & Solver"]:::utility
        A4["1D Error & Refinement"]:::utility
        A5["1D Visualization"]:::utility
    end

    %% 2D Analysis Subgraph
    subgraph "2D Analysis"
        B1["2D Problem/Model"]:::model
        B2["2D Mesh Generation & Basis"]:::utility
        B3["2D Assembly & Solver"]:::utility
        B4["2D Error & Refinement"]:::utility
        B5["2D Visualization"]:::utility
    end

    %% 3D Analysis Subgraph
    subgraph "3D Analysis"
        C1["3D Problem/Model"]:::model
        C2["3D Mesh Generation & Basis"]:::utility
        C3["3D Assembly & Solver"]:::utility
        C4["3D Error & Refinement"]:::utility
        C5["3D Visualization"]:::utility
        C6["Optimized 3D deCasteljau"]:::optimized
    end

    %% IGAPack overall structure
    IGAPack --> A1
    IGAPack --> B1
    IGAPack --> C1

    %% 1D Layer Flow
    A1 --> A2
    A2 --> A3
    A3 --> A4
    A4 --> A5

    %% 2D Layer Flow
    B1 --> B2
    B2 --> B3
    B3 --> B4
    B4 --> B5

    %% 3D Layer Flow
    C1 --> C2
    C2 --> C3
    C3 --> C4
    C4 --> C5
    %% 3D Optimized Link
    C2 --> C6

    %% External Dependencies: Mesh generation modules depend on NURBS Library
    A2 ---|"uses"| NURBS
    B2 ---|"uses"| NURBS
    C2 ---|"uses"| NURBS

    %% Click Events for 1D Components
    click A1 "https://github.com/canitesc/igapack/blob/master/1D/Main1D.m"
    click A2 "https://github.com/canitesc/igapack/blob/master/1D/utils1D/initPHTmesh1D.m"
    click A3 "https://github.com/canitesc/igapack/blob/master/1D/utils1D/assembleGalerkin1D.m"
    click A4 "https://github.com/canitesc/igapack/blob/master/1D/utils1D/calcError1D.m"
    click A5 "https://github.com/canitesc/igapack/blob/master/1D/utils1D/plotError1D.m"

    %% Click Events for 2D Components
    click B1 "https://github.com/canitesc/igapack/blob/master/elasticity2D/CantileverBeam.m"
    click B2 "https://github.com/canitesc/igapack/blob/master/elasticity2D/PHTutils/initPHTmesh.m"
    click B3 "https://github.com/canitesc/igapack/blob/master/elasticity2D/PHTutils/assembleGalerkinSysGIFTMP.m"
    click B4 "https://github.com/canitesc/igapack/blob/master/elasticity2D/PHTutils/recoverDerivEstGalMP2alphaDorfler.m"
    click B5 "https://github.com/canitesc/igapack/blob/master/elasticity2D/PHTutils/plotSolPHTElasticMP.m"

    %% Click Events for 3D Components
    click C1 "https://github.com/canitesc/igapack/blob/master/elasticity3D/Blade.m"
    click C2 "https://github.com/canitesc/igapack/blob/master/elasticity3D/PHTutils/initPHTmesh3D.m"
    click C3 "https://github.com/canitesc/igapack/blob/master/elasticity3D/PHTutils/assembleGalerkinSysGIFT.m"
    click C4 "https://github.com/canitesc/igapack/blob/master/elasticity3D/PHTutils/recoverDerivEstGalMPDorfler.m"
    click C5 "https://github.com/canitesc/igapack/blob/master/elasticity3D/PHTutils/plotStressDisp3D.m"
    click C6 "https://github.com/canitesc/igapack/blob/master/elasticity3D/PHTutils/deCasteljau3DTP_mex.*"

    %% Click Event for External NURBS Library
    click NURBS "https://github.com/canitesc/igapack/tree/master/nurbs"

    %% Styles
    classDef title fill:#ffd,stroke:#333,stroke-width:2px;
    classDef model fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef utility fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#333,stroke-width:2px;
    classDef optimized fill:#d1ecf1,stroke:#333,stroke-width:2px;
```
