# ryujimiya/ivyfem architecture

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

- Interactive diagram: https://gitdiagram.com/ryujimiya/ivyfem
- Repository: https://github.com/ryujimiya/ivyfem

## Overview

Based on our analysis of the file tree and README, IvyFEM is a .NET CAE (Computer-Aided Engineering) library that implements Finite Element Method (FEM) simulations for a wide variety of physics domains (structural mechanics, fluid dynamics, electromagnetics, etc.). It is intended to be used within a .NET WPF application (as shown by the references in the README and sample app links) and is delivered as a compiled DLL (with releases available in the “publish” folder) while all of its source code is under the “src/IvyFEM” folder.

##### Project Type and Purpose
- Recognize that IvyFEM is not a full “end-to-end” application but rather a comprehensive simulation library. It is structured as a tool that provides mesh generation, CAD-utilities, finite element assembly, solver routines (using LAPACKE, Lis, and custom solvers), and various physics-specific simulation modules.
- The library is modular and supports many different types of FEM analyses (2D/3D structural analysis, fluid flow, electromagnetic wave propagation, and more) with multiple classes dedicated to different methods and element types.

##### Major Components to Identify
- Core FEM Engine:
– FEWorld and FE classes that manage simulation domains.
– Mesh Generation: Classes like Mesher2D, Mesher3D (and associated Drawers for 2D/3D drawings), MeshPoint, MeshTri2D/3D, MeshTet, etc.
– CAD / Geometry Handling: Cad2D, Cad3D, and utilities (CadUtils2D/3D, CadEdge2DPolyline, etc.) that facilitate creation and manipulation of geometries.
- Physics Simulation Modules:
– Elasticity Modules: Numerous classes for different elasticity formulations (e.g., Elastic2DFEM, Elastic3DFEM, variants for eigen analysis and time domain, plus various material models like BeamMaterial, CorotationalFrameMaterial, MooneyRivlin, Ogden, etc.).
– Fluid Dynamics Modules: Classes for different formulations (e.g., Fluid2DFEM, Fluid3DFEM, variants with SUPG stabilization, Standard, Stokes, FIC formulations, etc.).
– Electromagnetic Analysis: FEM classes for electromagnetic waveguide problems, Helmholtz equations, photonic crystal simulations, etc.
– Other Problem Types: Additional modules for Poisson, Diffusion, Advection-Diffusion equations, and eddy current analysis.
- Solver Subsystem:
– Linear algebra solvers (files in “Linear” such as Linear.DoubleSparseMatrix, EquationSolver implementations, and LAPACK wrappers).
– Interfaces to third-party libraries.
- Utility and Infrastructure Components:
– Supporting classes for integration (IntegrationPoints.cs), file serialization (Serializer.cs), and general drawing (IDrawer, IFieldDrawer, etc.).
– External dependency note: OpenTK.GLControl is required for parts of visualization and rendering.

##### Relationships and Interactions
- The client application (WPF) will call into the IvyFEM DLL.
- Within the library, the FEWorld component acts as the orchestrator: it pulls together CAD data, passes it to the meshing components, then triggers the FE assembly via FEM-related classes.
- The assembled matrices and system equations are solved by the Solver Subsystem, which makes use of Linear algebra components (custom solvers or LAPACKE/Lis-based ones).
- Post-solution, result data are passed to result/visualization components (ColorMap, ColorLegend, various Drawer classes) that are likely rendered by the UI.
- Each physics module (elastic, fluid, electromagnetic) uses common core components (mesh, solver, CAD) and then applies its own specific formulation.

##### Architectural Patterns/Design Principles
- Modular and layered design – the project is organized by clear separation of concerns (geometry vs. meshing vs. assembly vs. solving vs. visualization).
- Object-oriented design with many specialized classes that implement various FEM formulations.
- Extensible interfaces (such as IColorMap, IDrawer, IEquationSolver) encourage the introduction of new simulation types or solver methods with minimal disruption.

##### Elements
- Clear component labels: For example, “CAD & Geometry Handling (Cad2D/Cad3D, CadUtils)”, “Mesh Generation (Mesher2D/Mesher3D, MeshPoint, …)”, “FEM Assembly (FE, FEWorld)”, “Solver Subsystem (Linear, LAPACK wrappers, Lis solvers)”, “Simulation Modules – Elasticity / Fluid / EM”, and “Visualization Helpers (Drawer classes, ColorMap).”
- Notation for external dependencies: Show the dependency to OpenTK.GLControl for rendering and the use of third-party libraries for solver support.

## Diagram (Mermaid)

```mermaid
flowchart TD
    UI["WPF/Client Application"]:::ui
    Art["IvyFEM DLL (publish)"]:::deploy
    UI --> Art

    subgraph "Core FEM Engine"
        FE["FE"]:::core
        FEW["FEWorld"]:::core
    end
    Art --> FEW

    subgraph "Mesh Generation"
        subgraph "2D Mesh Generation"
            M2["Mesher2D"]:::mesh
            M2DP["Mesher2DDrawPart"]:::mesh
            M2DDr["Mesher2DDrawer"]:::mesh
            MT2D["MeshTri2D"]:::mesh
            MP2D["MeshPoint2D"]:::mesh
        end
        subgraph "3D Mesh Generation"
            M3["Mesher3D"]:::mesh
            M3DP["Mesher3DDrawPart"]:::mesh
            M3DDr["Mesher3DDrawer"]:::mesh
            MT3D["MeshTri3D"]:::mesh
            MP3D["MeshPoint3D"]:::mesh
            MTet["MeshTet"]:::mesh
        end
    end
    FEW --> M2
    FEW --> M3

    subgraph "CAD & Geometry Handling"
        C2D["Cad2D"]:::cad
        C3D["Cad3D"]:::cad
        CU["CadUtils"]:::cad
        CU2D["CadUtils2D"]:::cad
        CU3D["CadUtils3D"]:::cad
        C2DDP["Cad2DDrawPart"]:::cad
        C2DDr["Cad2DDrawer"]:::cad
        C3DDP["Cad3DDrawPart"]:::cad
        C3DDr["Cad3DDrawer"]:::cad
        CEdge["CadEdge2DPolyline"]:::cad
    end
    FEW --> C2D
    FEW --> C3D

    subgraph "Physics Simulation Modules"
        E2D["Elastic2DFEM"]:::phys
        E3D["Elastic3DFEM"]:::phys
        F2D["Fluid2DFEM"]:::phys
        F3D["Fluid3DFEM"]:::phys
        EM3D["EMWaveguide3DFEM"]:::phys
        EM2D["EMWaveguide2DHPlaneFEM"]:::phys
        P2D["Poisson2DFEM"]:::phys
        P3D["Poisson3DFEM"]:::phys
        AD2D["AdvectionDiffusion2DFEM"]:::phys
    end
    FEW --> E2D
    FEW --> E3D
    FEW --> F2D
    FEW --> F3D
    FEW --> EM3D
    FEW --> EM2D
    FEW --> P2D
    FEW --> P3D
    FEW --> AD2D

    subgraph "Solver Subsystem"
        DSM["DoubleSparseMatrix"]:::solver
        IES["IEquationSolver"]:::solver
        IVDS["IvyFEMEquationSolver.Double"]:::solver
        IVCS["IvyFEMEquationSolver.Complex"]:::solver
        LAPDM["Lapack.DoubleMatrix"]:::solver
        LAPF["Lapack.Functions"]:::solver
        LISS["LisSolver"]:::solver
        LISM["LisMatrix"]:::solver
    end
    E2D --> DSM
    E3D --> IES
    F2D --> IVDS
    F3D --> IVCS
    EM3D --> LAPDM
    EM2D --> LAPF
    P2D --> LISS
    P3D --> LISM
    AD2D --> IES

    subgraph "Utility and Infrastructure"
        INTG["IntegrationPoints"]:::util
        SER["Serializer"]:::util
        IDRW["IDrawer"]:::util
        IFD["IFieldDrawer"]:::util
        ICM["IColorMap"]:::util
        CMAP["ColorMap"]:::util
        CLG["ColorLegend"]:::util
        CAM["Camera"]:::util
        CAM2D["Camera2D"]:::util
        CAM3D["Camera3D"]:::util
        EXT["OpenTK.GLControl"]:::external
    end
    DSM --> INTG
    IVCS --> SER
    LISS --> IDRW
    LISM --> IFD
    LAPF --> ICM
    IVDS --> CMAP
    IES --> CLG
    CAM --> CLG
    CAM2D --> CAM
    CAM3D --> CAM

    CLG --> UI
    SER --> UI
    EXT -.-> CMAP

    classDef ui fill:#FFCC00,stroke:#000,stroke-width:2px;
    classDef core fill:#87CEFA,stroke:#000,stroke-width:2px;
    classDef mesh fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef cad fill:#FFA07A,stroke:#000,stroke-width:2px;
    classDef phys fill:#DDA0DD,stroke:#000,stroke-width:2px;
    classDef solver fill:#F4A460,stroke:#000,stroke-width:2px;
    classDef util fill:#EEE8AA,stroke:#000,stroke-width:2px;
    classDef deploy fill:#E6E6FA,stroke:#000,stroke-width:2px;
    classDef external fill:#FFC0CB,stroke:#000,stroke-width:2px;

    click FE "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/FE.cs"
    click FEW "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/FEWorld.cs"
    click M2 "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Mesher2D.cs"
    click M2DP "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Mesher2DDrawPart.cs"
    click M2DDr "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Mesher2DDrawer.cs"
    click MT2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/MeshTri2D.cs"
    click MP2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/MeshPoint2D.cs"
    click M3 "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Mesher3D.cs"
    click M3DP "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Mesher3DDrawPart.cs"
    click M3DDr "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Mesher3DDrawer.cs"
    click MTet "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/MeshTet.cs"
    click MP3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/MeshPoint3D.cs"
    click MT3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/MeshTri3D.cs"
    click C2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Cad2D.cs"
    click C3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Cad3D.cs"
    click CU "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/CadUtils.cs"
    click CU2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/CadUtils2D.cs"
    click CU3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/CadUtils3D.cs"
    click C2DDP "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Cad2DDrawPart.cs"
    click C2DDr "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Cad2DDrawer.cs"
    click C3DDP "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Cad3DDrawPart.cs"
    click C3DDr "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Cad3DDrawer.cs"
    click CEdge "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/CadEdge2DPolyline.cs"
    click E2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Elastic2DFEM.cs"
    click E3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Elastic3DFEM.cs"
    click F2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Fluid2DFEM.cs"
    click F3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Fluid3DFEM.cs"
    click EM3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/EMWaveguide3DFEM.cs"
    click EM2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/EMWaveguide2DHPlaneFEM.cs"
    click P2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Poisson2DFEM.cs"
    click P3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Poisson3DFEM.cs"
    click AD2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/AdvectionDiffusion2DFEM.cs"
    click DSM "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Linear.DoubleSparseMatrix.cs"
    click IES "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Linear.IEquationSolver.cs"
    click IVDS "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Linear.IvyFEMEquationSolver.Double.cs"
    click IVCS "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Linear.IvyFEMEquationSolver.Complex.cs"
    click LAPDM "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Lapack.DoubleMatrix.cs"
    click LAPF "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Lapack.Functions.cs"
    click LISS "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Lis.LisSolver.cs"
    click LISM "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Lis.LisMatrix.cs"
    click INTG "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/IntegrationPoints.cs"
    click SER "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Serializer.cs"
    click IDRW "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/IDrawer.cs"
    click IFD "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/IFieldDrawer.cs"
    click ICM "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/IColorMap.cs"
    click CMAP "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/ColorMap.cs"
    click CLG "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/ColorLegend.cs"
    click CAM "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Camera.cs"
    click CAM2D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Camera2D.cs"
    click CAM3D "https://github.com/ryujimiya/ivyfem/blob/master/src/IvyFEM/IvyFEM/Camera3D.cs"
    click Art "https://github.com/ryujimiya/ivyfem/blob/master/publish/IvyFEM0.0.0.XX.zip"
```
