# shimanek/cpfem_opt architecture

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

- Interactive diagram: https://gitdiagram.com/shimanek/cpfem_opt
- Repository: https://github.com/shimanek/cpfem_opt

## Overview

##### Main Components

a. Core Framework Layer:
- Core modules (crystalPlasticity.py, experimental.py, optimizer.py, etc.)
- How these components interact with the state management and utilities

b. Input/Output Layer:
- Parser.py and writer.py components
- TOML configuration handling
- Experimental data input handling

c. Execution Engines Layer:
- On the right side
- Two main engines: ABAQUS and FEPX
- Their respective extractors and processors

d. Models Layer:
- On the left side
- Two model types: mk_orthoModel and mk_singleModel
- To the core framework

e. Objectives Layer:
- At the bottom
- Objective calculation methods
- How they feed back into the optimization process

##### Component Relationships

- Green for data input/output
- Orange for simulation execution paths

##### Specific Implementation Details

**┌─────────────────────┐**
- Component Name      │
- ┤
- Key Functions       │
- Dependencies        │
- ┘

##### Key Workflows to Highlight

a. Optimization Loop:
1. Input parsing (parser.py)
2. Model selection and setup
3. Engine execution (ABAQUS/FEPX)
4. Objective calculation
5. Parameter adjustment via scikit-optimize
6. Loop back to step 2

b. Parallel Execution:
- How parallel.py manages multiple simulations

##### Important Elements

- scikit-optimize (primary optimization engine)
- ABAQUS/FEPX interfaces
- Python scientific stack (numpy, etc.)

- Configuration Management:
- TOML config flow
- Experimental data input handling
- Parameter file generation

##### Results and Analysis

- Component types
- Special symbols

Keep the focus on the optimization workflow while showing the integration points with the material science simulation aspects, as this is primarily an optimization framework for crystal plasticity parameters.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef io fill:#2ecc71,stroke:#27ae60,color:white
    classDef engine fill:#e67e22,stroke:#d35400,color:white
    classDef model fill:#9b59b6,stroke:#8e44ad,color:white
    classDef objective fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef utility fill:#bdc3c7,stroke:#95a5a6,color:black

    %% Input/Output Layer
    subgraph IO
        Parser["Parser"]
        Writer["Writer"]
        Runner["Runner Interface"]
        Config["TOML Config"]
        ExpData["Experimental Data"]
    end

    %% Core Framework Layer
    subgraph Core
        CrystalPlasticity["Crystal Plasticity"]
        Experimental["Experimental Module"]
        Optimizer["Optimizer"]
        State["State Management"]
        Utilities["Utilities"]
        Parallel["Parallel Processing"]
    end

    %% Models Layer
    subgraph Models
        OrthoModel["Ortho Model"]
        SingleModel["Single Model"]
    end

    %% Execution Engines Layer
    subgraph Engines
        ABAQUS["ABAQUS Engine"]
        ABQExtract["ABAQUS Extractor"]
        FEPX["FEPX Engine"]
    end

    %% Objectives Layer
    subgraph Objectives
        Calculator["Main Calculator"]
        BestRMSE["Best RMSE"]
        MeanStd["Mean/Std Calculator"]
        CombineMean["Mean Combiner"]
        CombineVar["Variance Combiner"]
        Recalculate["Recalculation Tool"]
    end

    %% Relationships
    Config --> Parser
    ExpData --> Parser
    Parser --> State
    State --> Writer
    Writer --> Runner
    Runner --> Parallel
    Parallel --> ABAQUS & FEPX
    ABAQUS --> ABQExtract
    ABQExtract --> Calculator
    FEPX --> Calculator
    
    State --> Optimizer
    Optimizer --> CrystalPlasticity
    CrystalPlasticity --> OrthoModel & SingleModel
    OrthoModel & SingleModel --> Runner
    
    Calculator --> BestRMSE & MeanStd
    BestRMSE & MeanStd --> CombineMean & CombineVar
    CombineMean & CombineVar --> Optimizer
    Recalculate --> Calculator

    %% Click events for component mapping
    click Parser "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/parser.py"
    click Writer "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/writer.py"
    click Runner "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/runner.py"
    click CrystalPlasticity "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/crystalPlasticity.py"
    click Experimental "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/experimental.py"
    click Optimizer "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/optimizer.py"
    click State "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/state.py"
    click Utilities "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/utilities.py"
    click Parallel "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/core/parallel.py"
    click ABAQUS "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/engines/abaqus.py"
    click ABQExtract "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/engines/abaqus_extract.py"
    click FEPX "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/engines/fepx.py"
    click OrthoModel "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/models/mk_orthoModel.py"
    click SingleModel "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/models/mk_singleModel.py"
    click Calculator "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/objectives/calculate.py"
    click BestRMSE "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/objectives/best_rmse.py"
    click MeanStd "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/objectives/mean_std.py"
    click CombineMean "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/objectives/combine_mean.py"
    click CombineVar "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/objectives/combine_variance.py"
    click Recalculate "https://github.com/shimanek/cpfem_opt/blob/master/matmdl/objectives/recalculate.py"

    %% Style applications
    class Parser,Writer,Runner,Config,ExpData io
    class CrystalPlasticity,Experimental,Optimizer,State,Utilities,Parallel core
    class ABAQUS,ABQExtract,FEPX engine
    class OrthoModel,SingleModel model
    class Calculator,BestRMSE,MeanStd,CombineMean,CombineVar,Recalculate objective
```
