CorroSim Analysis - Open Source Corrosion Software

CorroSim Analysis

Enterprise Corrosion Simulation Suite

MIT License Python 3.10+ PyQt6 ASTM Standards Production Ready

📌 What is CorroSim Analysis?

CorroSim Analysis is a production-ready PyQt6 desktop application for electrochemical corrosion analysis. It provides a complete workflow from raw data import through Tafel analysis, lifetime prediction, sample comparison, and professional data export.

Target Users

  • Materials Scientists studying alloy corrosion behavior
  • Chemical Engineers designing protective systems
  • Quality Control Labs performing routine corrosion testing
  • Researchers publishing electrochemical data
  • Python Developers building scientific desktop applications

Key Metrics

  • 10,000+ rows import in <2 seconds
  • Tafel analysis in <1 second
  • EIS fitting in <3 seconds
  • PDF report generation in <5 seconds
  • 1,000+ analyses query in <100ms

Architecture

Modular package following MVC principles with separation of concerns:

corrosim/
├── corrosim/                  # Main package
│   ├── main.py                # Entry point
│   ├── app.py                 # Main window controller
│   ├── theme.py               # UI styling & theme
│   ├── database.py            # SQLite database (CRUD)
│   ├── tafel_engine.py        # Tafel analysis engine
│   ├── splash_screen.py       # Splash screen
│   ├── tabs/                  # Tab modules (MVC)
│   │   ├── import_tab.py      # Data import
│   │   ├── tafel_tab.py       # Tafel analysis
│   │   ├── prediction_tab.py  # Lifetime prediction
│   │   └── comparison_tab.py  # Sample comparison
│   └── utils/
│       └── constants.py       # Physical constants
├── tests/
│   └── test_tafel.py          # Validation tests
├── requirements.txt
├── setup.py
└── run.py

Data Import

Excel (.xlsx/.xls), CSV, TXT with auto-detection of instrument formats (Bio-Logic, Gamry, Autolab, Solartron)

Tafel Analysis

Automatic Ecorr detection, Tafel region scanning with R² > 0.995 validation, corrosion rate calculation

EIS Fitting

Equivalent circuit fitting (Randles, Warburg, Two Time Constants) via Levenberg-Marquardt

Lifetime Prediction

Linear, Power Law, and Arrhenius models with 95% confidence intervals

Multi-Sample Comparison

Overlay plots, sortable comparison tables

PDF Reporting

Professional reports with embedded 300 DPI plots, QR codes, ASTM references

Database

SQLite with SQLAlchemy ORM, SHA-256 checksums for data integrity

Settings

JSON-based configuration with validation

⚡ Electrochemical Corrosion Basics

Corrosion is an electrochemical process involving anodic (oxidation) and cathodic (reduction) half-reactions:

Anodic Reaction (Metal Dissolution):
M → Mⁿ⁺ + ne⁻

Cathodic Reactions:
Acidic: 2H⁺ + 2e⁻ → H₂
Neutral: O₂ + 2H₂O + 4e⁻ → 4OH⁻

📐 Tafel Analysis Theory

The Tafel equation describes the relationship between overpotential (η) and current density (i):

η = β · log(i / i₀)

Where:
η = overpotential (V) = E - Ecorr
β = Tafel slope (V/decade)
i = current density (A/cm²)
i₀ = exchange current density (A/cm²)

Corrosion Rate (Faraday's Law):

CR (mm/year) = (i_corr · EW · 3.27 × 10⁻⁶) / (density · area)

📊 EIS (Electrochemical Impedance Spectroscopy)

Randles Circuit Impedance:

Z_total = Rs + 1 / (1/Rct + 1/(Qdl · (jω)ⁿ))
Rs = Solution Resistance Rct = Charge Transfer Resistance Qdl = Constant Phase Element n = CPE exponent (0.5 ≤ n ≤ 1.0)

📈 Prediction Models

Linear Model: CR(t) = CR₀ + k · t
Power Law: CR(t) = CR₀ · tⁿ
Arrhenius Model: CR(T) = A · exp(-Ea / (R · T))

📋 System Requirements

RequirementMinimumRecommended
Python3.103.13
RAM4 GB8 GB
Disk500 MB2 GB
Display1280×7201920×1080

🐍 Dependencies

PyQt6==6.6.1 pandas==2.1.4 numpy==1.26.2 scipy==1.11.4 matplotlib==3.8.2 reportlab==4.0.7 sqlalchemy==2.0.23 qrcode==7.4.2

🚀 Installation Commands

# Clone repository
git clone https://github.com/khadev/CorroSim.git
cd CorroSim

# Create virtual environment (optional)
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or: venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

# Run application
python run.py


#if you installed from PyPI:
pip install corrosim
pip install --upgrade corrosim
corrosim

📦 Standalone Executable (PyInstaller)

pip install pyinstaller

# Generate spec file
pyi-makespec --windowed --onefile --name CorroSim run.py

# Build executable
pyinstaller CorroSim.spec

# Output: dist/CorroSim.exe (Windows)
#         dist/CorroSim (Linux/Mac)

🔧 TafelEngine API

class TafelEngine:
    def detect_ecorr(potential, current) -> float
    def detect_tafel_regions(potential, current, ecorr) -> Tuple
    def calculate_parameters(anodic, cathodic, area, density, eq_weight) -> Dict
    def run_analysis(potential, current) -> Dict
KeyDescriptionUnit
ecorrCorrosion potentialV
icorrCorrosion current densityμA/cm²
beta_aAnodic Tafel slopemV/dec
beta_cCathodic Tafel slopemV/dec
corrosion_rateCorrosion ratemm/year

⚡ EISEngine API

class EISEngine:
    def z_randles(f, Rs, Rct, Qdl, ndl) -> complex
    def z_randles_warburg(f, Rs, Rct, Qdl, ndl, W) -> complex
    def fit_circuit(freq, z_real, z_imag, circuit_type='R(RQ)') -> Tuple[Dict, np.ndarray]

🗄️ Database Schema (SQLite)

┌──────────────────────────────────────────────────────────────────┐
│                          samples                                  │
├──────────────────────────────────────────────────────────────────┤
│ id          TEXT    PRIMARY KEY    - UUID (e.g., "a1b2c3d4")     │
│ name        TEXT                   - Sample identifier            │
│ test_type   TEXT                   - Potentiodynamic / EIS       │
│ date        TEXT                   - Import timestamp             │
│ data        TEXT                   - Raw CSV data (stored as CSV) │
│ ecorr       REAL                   - Corrosion potential (V)     │
│ icorr       REAL                   - Current density (μA/cm²)   │
│ cr          REAL                   - Corrosion rate (mm/yr)     │
│ ba          REAL                   - Anodic Tafel slope (mV/dec)│
│ bc          REAL                   - Cathodic Tafel slope        │
└──────────────────────────────────────────────────────────────────┘

Storage Notes:
• Raw experimental data stored as CSV text in 'data' column
• Tafel results populated after analysis (initially NULL)
• All results in a single flat table for simplicity
• SQLite database file: corrosion.db

🤝 Contribution Guidelines

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 Code Style

  • Follow PEP 8 with 120 character line length
  • Use type hints for all function signatures
  • Add docstrings to all public methods (Google style)
  • Maintain test coverage > 80%

📧 Commit Message Format

type(scope): subject

Types: feat, fix, docs, style, refactor, test, chore

Example:
feat(tafel): add automatic outlier detection
Khaled
Khaled ABOUT THE AUTHOR :
My name is Khaled and I studied chemistry at the University of science in Oran-Algeria I have got a master's degree in Biomolecule engineering. I believe in the philosophy of progression over perfection and that fitness is a lifelong journey with new milestones and achievements along the way. After cultivating a healthier lifestyle and developing a commitment to improving through my own fitness journey i discovered my desire to help others with what method works best for me and gave me the best results. That’s why I made this blog. So if you want to take your workouts and your passion to the next level, you’re in the right place.
When I'm not busy with sports, I fill my downtime spending time coding and building blocks of a website (design front-end developer), hanging with family & friends, spearfishing and cooking healthy food.
Progressive Fitness is a compilation of my workouts and nutrition advice, packaged just for you!

Post a Comment