8.4 KiB
Contributing to OPM Simulators
Thank you for your interest in contributing to the Open Porous Media (OPM) Simulators project! This guide will help you get started with contributing code, documentation, or bug reports.
Table of Contents
- Getting Started
- Development Process
- Code Style and Formatting
- Automated Formatting Tools
- Testing
- Submitting Changes
- Reporting Issues
- Getting Help
Getting Started
Before contributing, please:
- Read the OPM Project Documentation
- Review the OPM Manual
- Ensure you have the necessary prerequisites installed
Development Process
Fork and Clone
-
Fork the repository on GitHub
-
Clone your fork locally:
git clone https://github.com/YOUR-USERNAME/opm-simulators.git cd opm-simulators -
Add the upstream repository:
git remote add upstream https://github.com/OPM/opm-simulators.git
Building
Before making changes, ensure you can build the project successfully. For detailed build instructions, see the OPM build documentation.
Quick build steps:
mkdir build
cd build
cmake ..
make -j$(nproc)
Create a Feature Branch
Always create a new branch for your changes:
git checkout -b feature/your-feature-name
Code Style and Formatting
Maintaining consistent code style is crucial for readability and maintainability. Please follow these guidelines:
C++ Code Style
We use clang-format for C++ code formatting. Key settings include:
- Line length: Maximum 120 characters
- Indentation: 4 spaces (no tabs)
- Braces: Linux style (opening brace on next line for functions and classes)
- Based on: WebKit style with modifications
Apply clang-format to your C++ code:
For new files:
clang-format -i path/to/your/new_file.cpp
For existing files: Only format the lines you modify to avoid creating noisy diffs. Most editors can format selections:
- VS Code: Select code → Right-click → "Format Selection"
- vim: Visual select →
=to format - Command line: Use
git clang-formatto format only staged changes:Note:git add your_modified_file.cpp git clang-formatgit clang-formatis a separate tool (Python script) that usesclang-formatinternally to format only the changed lines. Both tools need to be installed.
This ensures your functional changes aren't obscured by formatting changes elsewhere in the file.
Include File Organization
Organize #include directives in the following order, with blank lines between groups:
-
System headers (C standard library, C++ STL):
#include <algorithm> #include <cmath> #include <iostream> -
External library headers (Dune, etc.):
#include <dune/common/fmatrix.hh> #include <dune/common/fvector.hh> -
OPM headers from other modules:
#include <opm/common/Exceptions.hpp> #include <opm/material/Constants.hpp> -
Local OPM headers (from this module):
#include <opm/models/common/multiphasebaseproperties.hh> #include <opm/models/flash/flashproperties.hh>
Within each group, maintain alphabetical order.
Python, Shell, and YAML Files
- Use 4 spaces for indentation
- Follow PEP 8 for Python code
- Use lowercase with underscores for shell script variables
- Maintain consistent quoting style in YAML
CMake Files
- Use 2 spaces for indentation
- Use lowercase for commands (e.g.,
add_librarynotADD_LIBRARY) - Group related commands together with blank lines for readability
Automated Formatting Tools
We recommend using pre-commit hooks to automatically format your code before commits.
What is Pre-commit?
Pre-commit is a framework for managing git hooks that automatically run code formatters and linters before each commit.
It only modifies files you're about to commit (staged files), not your entire codebase. The hooks fix common issues
like trailing whitespace and missing newlines automatically. When pre-commit makes changes, it will fail the commit
and report which files were modified - you'll need to review the changes, re-stage the files (git add), and commit
again. This ensures you see exactly what was changed before it's committed.
Pre-commit Setup
-
Install pre-commit:
pip install pre-commit # Or: conda install -c conda-forge pre-commit # Or: apt install pre-commit (Ubuntu/Debian) # Or: brew install pre-commit (macOS) -
Install hooks in your local repository:
pre-commit install -
What it does:
- Removes trailing whitespace (preserves Markdown line breaks)
- Ensures files end with exactly one newline
- Runs automatically on every commit
- Supports C/C++, Python, Shell, YAML, CMake, and Markdown files
-
Manual usage:
# Run on all files pre-commit run --all-files # Skip hooks for a specific commit git commit --no-verify # Update hook versions pre-commit autoupdate
Testing
Before submitting your changes:
-
Build the project:
mkdir build && cd build cmake .. make -
Run the test suite:
make test # Or for more verbose output: ctest --output-on-failure -
Run specific tests:
ctest -R test_name -
Ensure your changes don't break existing functionality
Submitting Changes
Commit Messages
Write clear, descriptive commit messages:
- First line: Brief summary (50 characters or less)
- Blank line
- Detailed description (wrap at 72 characters)
- Reference relevant issues:
Fixes #123orRelates to #456
Example:
Add support for polymer flooding in Flow
This commit introduces polymer flooding capabilities to the Flow
simulator, including:
- Polymer concentration tracking
- Viscosity modifications
- Adsorption modeling
Fixes #789
Pull Request Process
-
Update your branch with latest upstream changes:
git fetch upstream git rebase upstream/master -
Push your changes to your fork:
git push origin feature/your-feature-name -
Create a Pull Request on GitHub:
- Provide a clear title and description
- Reference any related issues
- Include test results if applicable
- Be responsive to reviewer feedback
-
Code Review:
- Address reviewer comments promptly
- Add new commits for changes (don't force-push during review)
- Once approved, your PR will be merged
Reporting Issues
When reporting issues, please provide:
- Clear description of the problem
- Steps to reproduce the issue
- Expected behavior vs actual behavior
- System information:
- OS and version
- Compiler and version
- OPM version or commit hash
- Build logs if relevant (see below)
- Input data deck demonstrating the issue, if possible
Capturing Build Logs
To capture a build log for issue reporting:
LOGFILE=$(date +%Y%m%d-%H%M-)build.log
cmake -E cmake_echo_color --cyan --bold "Log file: $LOGFILE"
script -q $LOGFILE -c 'cmake .. -DCMAKE_BUILD_TYPE=Debug' &&
script -q $LOGFILE -a -c 'make -j 4' ||
cat CMakeCache.txt CMakeFiles/CMake*.log >> $LOGFILE
Upload the log file to gist.github.com and include the link in your issue.
Getting Help
Resources
- Documentation: opm-project.org
- Issue Tracker: GitHub Issues
- Mailing List: OPM Mailing List
- Build Instructions: Build Guide
Community Guidelines
- Be respectful and constructive in discussions
- Search existing issues before creating new ones
- Provide context and be specific when asking for help
- Acknowledge contributions from others
License
By contributing to OPM Simulators, you agree that your contributions will be licensed under the GNU General Public License v3.0 or later (GPLv3+).
Thank you for contributing to OPM Simulators! Your efforts help advance open-source reservoir simulation technology.