# hanishdhanwalkar/topology-optimization-using-python architecture

> Architecture diagram of the GitHub repository hanishdhanwalkar/topology-optimization-using-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hanishdhanwalkar/topology-optimization-using-python
- Repository: https://github.com/hanishdhanwalkar/topology-optimization-using-python

## Overview

This repository implements two closely related Python topology-optimization workflows. A user-defined polygon, boundary constraints, and applied forces feed an optimizer that repeatedly solves a finite-element model, evaluates compliance, and updates material density toward a target volume. The newer workflow also supports interactive thresholding and animation; both workflows plot optimization progress and display density and stress results. The source shows direct calls between the workflow, solver, and plotting code. The README only documents the project topic and a FEniCS installation prerequisite; unsampled assets and runtime behavior are not inferred.

Main entry points: [`main.py`](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/main.py) (Topology optimizer), [`main copy.py`](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/main%20copy.py) (Legacy optimizer), [`frontend.py`](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/frontend.py) (Iteration plots), [`backend2.py`](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/backend2.py) (Simulation model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_optimization["Optimization workflows"]
  node_optimizer["Topology optimizer<br/>[main.py]"]
  node_legacy_optimizer["Legacy optimizer<br/>[main copy.py]"]
end

subgraph group_solver["Finite-element solver"]
  node_simulation["Simulation model<br/>[backend2.py]"]
  node_legacy_simulation["Legacy simulation<br/>[backend.py]"]
end

subgraph group_presentation["Plots and output"]
  node_iteration_plot["Iteration plots<br/>[frontend.py]"]
  node_threshold["Density thresholding<br/>[frontend.py]"]
  node_animation["Density animation<br/>[frontend.py]"]
end

node_user(("User"))

node_user -->|"configures"| node_optimizer
node_user -.->|"configures"| node_legacy_optimizer
node_optimizer -->|"drives solves"| node_simulation
node_optimizer -->|"updates plots"| node_iteration_plot
node_optimizer -->|"sets threshold"| node_threshold
node_optimizer -->|"saves animation"| node_animation
node_legacy_optimizer -->|"drives solves"| node_legacy_simulation
node_legacy_optimizer -->|"updates plots"| node_iteration_plot
node_legacy_optimizer -->|"sets threshold"| node_threshold
node_legacy_optimizer -->|"saves animation"| node_animation

click node_optimizer "https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/main.py"
click node_legacy_optimizer "https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/main%20copy.py"
click node_simulation "https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/backend2.py"
click node_legacy_simulation "https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/backend.py"
click node_iteration_plot "https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/frontend.py"
click node_threshold "https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/frontend.py"
click node_animation "https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/frontend.py"

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_optimizer,node_legacy_optimizer,node_user toneBlue
class node_simulation,node_legacy_simulation toneAmber
class node_iteration_plot,node_threshold,node_animation toneMint
```

## Components

### Optimization workflows

- [Topology optimizer](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/main.py): `main.py`
- [Legacy optimizer](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/main%20copy.py): `main copy.py`

### Finite-element solver

- [Simulation model](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/backend2.py): `backend2.py`
- [Legacy simulation](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/backend.py): `backend.py`

### Plots and output

- [Iteration plots](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/frontend.py): `frontend.py`
- [Density thresholding](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/frontend.py): `frontend.py`
- [Density animation](https://github.com/hanishdhanwalkar/topology-optimization-using-python/blob/main/frontend.py): `frontend.py`

### Other components

- **User**

## Connections

- User → Topology optimizer: configures
- User → Legacy optimizer: configures
- Topology optimizer → Simulation model: drives solves (evidence: `main.py`)
- Topology optimizer → Iteration plots: updates plots (evidence: `main.py`)
- Topology optimizer → Density thresholding: sets threshold (evidence: `main.py`)
- Topology optimizer → Density animation: saves animation (evidence: `main.py`)
- Legacy optimizer → Legacy simulation: drives solves (evidence: `main copy.py`)
- Legacy optimizer → Iteration plots: updates plots (evidence: `main copy.py`)
- Legacy optimizer → Density thresholding: sets threshold (evidence: `main copy.py`)
- Legacy optimizer → Density animation: saves animation (evidence: `main copy.py`)
