Skip to content

New curl2D implementation#373

Merged
mdumett merged 8 commits into
mainfrom
mdumett/curl2D_octave
May 27, 2026
Merged

New curl2D implementation#373
mdumett merged 8 commits into
mainfrom
mdumett/curl2D_octave

Conversation

@Tony-Drummond
Copy link
Copy Markdown
Collaborator

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Example
  • Documentation

Description

Implements the 2D curl operator as a matrix instead of functions

Related Issues & Documents

QA Instructions, Screenshots, Recordings

tests/matlab_octave/testCurl2D.m

Added/updated tests?

_We encourage you to test all code included with MOLE, including examples.

  • Yes
  • No, and this is why: work in progress
  • I need help with writing tests

Read Contributing Guide and Code of Conduct

[optional] Are there any post deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

@Tony-Drummond
Copy link
Copy Markdown
Collaborator Author

testCurl2D.m works now.

Comment thread src/matlab_octave/curl2D.m Outdated
f = f + 1;
end
end
Dx = full(div(k, m, dx));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

full makes this untenable for large matrices.

Copy link
Copy Markdown
Collaborator Author

@Tony-Drummond Tony-Drummond May 21, 2026

Choose a reason for hiding this comment

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

That is correct, we don't need to build the full matrices, we can just copy the divergence operator in the center of matrix with the two extra columns,
Dx = div(k, m, dx);
Dx = Dx(2:end-1,:);

Comment thread tests/matlab_octave/testCurl2D.m Outdated
ks=[2,4,6,8];
tolcomp12 = [5e-2,5e-4,5e-14,5e-14];
tolcomp3 = [6e-2,3e-3,6e-14,6e-14];
tolglob = [e-1,4e-3,8e-14,8e-14];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test generates an error "e not found"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I had fixed this error in line 61, I re-commit the test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There was an indexing issue in the testCurl2D.m, it has been fixed and tests are now running fine.

Copy link
Copy Markdown
Contributor

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 refactors the MATLAB/Octave curl2D operator to return a sparse matrix-based 2D curl operator (instead of computing curl from function handles), aligning with the “matrix operator” approach used elsewhere and supporting parity work for the C++ implementation (Issue #343).

Changes:

  • Replaced curl2D.m implementation with a sparse matrix assembly using 1D divergence operators and Kronecker products.
  • Added a MATLAB unit test (testCurl2D.m) intended to validate all three curl components against analytic derivatives.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/matlab_octave/curl2D.m Reimplements curl2D as a sparse matrix operator assembled from div-based stencils (via kron).
tests/matlab_octave/testCurl2D.m Adds a unit test to compare the operator output against analytic curl components on a staggered grid.

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

Comment thread tests/matlab_octave/testCurl2D.m Outdated
ks=[2,4,6,8];
tolcomp12 = [5e-2,5e-4,5e-14,5e-14];
tolcomp3 = [6e-2,3e-3,6e-14,6e-14];
tolglob = [e-1,4e-3,8e-14,8e-14];
Comment thread tests/matlab_octave/testCurl2D.m Outdated
Comment on lines +63 to +67
for k = ks
% tolerances
tolc12 = tolcomp12(k);
tolc3 = tolcomp3(k);
tolg = tolglob(k);
Comment thread tests/matlab_octave/testCurl2D.m Outdated
tolg = tolglob(k);

% 2D curl operator
C = curl2D(k, m, dx, n, dy); % need to modify the last component of 2D curl
Comment thread src/matlab_octave/curl2D.m Outdated
@@ -1,62 +1,43 @@
function C = curl2D(k, m, dx, n, dy, west, east, south, north, U, V)
% PURPOSE
% SPDX-License-Identifier: GPL-3.0-only
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The header is different:

% ----------------------------------------------------------------------------
% SPDX-License-Identifier: GPL-3.0-or-later
% © 2008-2024 San Diego State University Research Foundation (SDSURF).
% See LICENSE file or https://www.gnu.org/licenses/gpl-3.0.html for details.
% ----------------------------------------------------------------------------

Comment thread src/matlab_octave/curl2D.m Outdated
Comment on lines +31 to +34
Dx = full(div(k, m, dx));
Dx = sparse(Dx(2:end-1,:));
Dy = full(div(k, n, dy));
Dy = sparse(Dy(2:end-1,:));
@Tony-Drummond Tony-Drummond requested a review from jbrzensk May 27, 2026 04:37
Copy link
Copy Markdown
Collaborator

@jbrzensk jbrzensk left a comment

Choose a reason for hiding this comment

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

The code seems fine, the header though, is different from all of the matlab files.

Comment thread src/matlab_octave/curl2D.m Outdated
@@ -1,62 +1,43 @@
function C = curl2D(k, m, dx, n, dy, west, east, south, north, U, V)
% PURPOSE
% SPDX-License-Identifier: GPL-3.0-only
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The header is different:

% ----------------------------------------------------------------------------
% SPDX-License-Identifier: GPL-3.0-or-later
% © 2008-2024 San Diego State University Research Foundation (SDSURF).
% See LICENSE file or https://www.gnu.org/licenses/gpl-3.0.html for details.
% ----------------------------------------------------------------------------

@Tony-Drummond
Copy link
Copy Markdown
Collaborator Author

Tony-Drummond commented May 27, 2026

I noticed this discrepancy too, but rather than manually editing the file, we have now an automatic mechanism in place which should have placed the standard license and texts.

If you look at PR #342, the standardization for the license should have been automatically taken care of. The new labels are part of @deepanshu-zade's work that extends the work that @pritkc did.

Now that Deepanshu is out for the Summer, @pritkc is helping us review this work. The goal is to automate the license standardization and propagation (for now to all MATLAB/Octave scripts and C++ Source files). In the future, we will have to move that work to other MOLE language modules.

@pritkc is reviewing this work and will update the contributing guidelines.

To comply with new contribution guidelines, the curl2D.m file has a new header comment which uses the documentation labels (PURPOSE, DESCRIPTION, SYNTAX, etc). The License is automatically included in the file.
@Tony-Drummond
Copy link
Copy Markdown
Collaborator Author

@jbrzensk, I added the new documentation labels to the curl2D.m script file. The license is already automatically included. Let me know if you see it differently. Thanks!

@Tony-Drummond Tony-Drummond requested a review from mdumett May 27, 2026 21:54
@mdumett mdumett merged commit cae36a5 into main May 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement the curl2D operator in C++ (as a matrix not a function)

5 participants