Skip to content

Conversation

@djmaxus
Copy link
Collaborator

@djmaxus djmaxus commented Dec 10, 2025

No description provided.

@djmaxus djmaxus self-assigned this Dec 10, 2025
@djmaxus djmaxus added feature Adding a new functionality, small or large optimisation Improvements in the performance of the code labels Dec 10, 2025
Copilot AI review requested due to automatic review settings December 10, 2025 22:41
@djmaxus djmaxus marked this pull request as draft December 10, 2025 22:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds MATLAB Coder MEX compilation support to enable performance optimization of the upscale function and related computations. The changes prepare the codebase for MEX code generation by adding proper type annotations, pre-allocating arrays, refactoring iteration patterns, and introducing a CodeGenMex class to manage the compilation process.

Key Changes:

  • Added MEX compilation configuration class (CodeGenMex.m) with optimization settings for C++ code generation
  • Pre-allocated arrays throughout the codebase for MEX compatibility (idx_adj, map_to_cond, lin_to_sub, h, etc.)
  • Added argument blocks with type constraints to multiple functions for better type inference during compilation
  • Refactored loop patterns from implicit column iteration to explicit indexing for MATLAB Coder compatibility

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/CodeGenMex.m New class for managing MEX compilation with optimization settings (contains syntax errors)
src/upscale.m Added arguments block, early return for scalar case, helper functions, and variable pre-allocation for MEX
src/upscale_permeability.m Pre-allocated arrays (idx_adj, map_to_cond, lin_to_sub, A_ndiag) for MEX compatibility
src/strata_trapper.m Added krw monotonization in reverse direction and removed trailing whitespace
src/calc_percolation.m Pre-allocated h array and refactored loop from column iteration to explicit indexing
src/Options.m Updated validation function from mustBeOfClass to mustBeA
src/CapPressure.m Added explicit type constraints for perm arguments and refactored transform_perm with explicit return
src/export/opm_export.m Added named arguments, default_poro/default_perm support, RUNSPEC file generation, and FIPMIP region
src/export/common/write_perm.m Added default_perm parameter with initialization support

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@djmaxus djmaxus force-pushed the mex-codegen branch 6 times, most recently from 08dda3a to 2476669 Compare December 12, 2025 14:38
@djmaxus djmaxus marked this pull request as ready for review December 12, 2025 14:44
@djmaxus djmaxus force-pushed the mex-codegen branch 5 times, most recently from 00b27f0 to 337842e Compare December 12, 2025 15:32
Introduce `CodeMexGen` class
that can compile the `upscale` function
into MEX-file to accelerate the toolkit.

How to use:
```matlab
% 1. compile MEX functions
codegen_mex = CodeGenMex().config().build();

% 2. use strata_trapper normally
...

% 3. recompile MEX functions when the source code changes
codegen_mex.build();

% 4. delete MEX functions to use the original
codegen_mex.clear();
```
@djmaxus djmaxus merged commit 2afdca7 into main Dec 12, 2025
8 checks passed
@djmaxus djmaxus deleted the mex-codegen branch December 12, 2025 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Adding a new functionality, small or large optimisation Improvements in the performance of the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant