Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nonorthogonal with minimal differential operators MMS test. #285

Open
wants to merge 59 commits into
base: master
Choose a base branch
from

Conversation

mrhardman
Copy link
Collaborator

@mrhardman mrhardman commented Jan 24, 2025

Fixes to the Div_a_Grad_perp_nonorthog(a, f) operator (commit 3d11cb7, commit 2e5e827), merge with master, and new automatic tests integrated with ctest showing a correct implementation. Theses tests are hermes-3/tests/mms/orthogonal_test.py and hermes-3/tests/mms/nonorthogonal_test.py, and may be run interactively by, e.g.,

cd hermes-3/build-path/tests/mms/
python3 orthogonal_test.py

or

cd hermes-3/build-path/
ctest -I 12

These tests can be readily extended to test new nonorthogonal operators and the other existing operators in the Hermes-3 code base.

See /hermes-3/tests/mmsREADME.md for some documentation. Comments and requests appreciated.

Thanks to @dschwoerer for providing an initial MMS test to develop. Thanks to @johnomotani for numerous suggestions and bugfixes.

Below is the plot output from the tests, showing the error (blue), the expected (orange), and the fit of the error (green). Increase the range of $\Delta$ by increasing ntest in the test_input dictionary in hermes-3/tests/mms/orthogonal_test.py and hermes-3/tests/mms/nonorthogonal_test.py. Note that since the number of grid points $N_x = N_y = N_z$, the cost of the test rapidly increases with ntest.

FV::Div_a_Grad_perp(a, f) with orthogonal metric
fig_0
Div_a_Grad_perp_nonorthog(a, f) with orthogonal metric
fig_1
Div_a_Grad_perp_nonorthog(a, f) with nonorthogonal metric
fig_0_non

bendudson and others added 30 commits November 28, 2022 22:54
A version of FV::Div_a_Grad_perp that includes all metric components,
including g12 (X-Y non-orthogonal) and g13 (X-Z nonorthogonal) terms.

Aim to test and then merge upstream into BOUT++
Testing, using operator that includes nonorthogonal mesh corrections
…ile as this causes problems when loading from xbout.
… of convergence for orthogonal grid operator with a simple metric constant in x, y, z.
@dschwoerer
Copy link
Collaborator

Can you either change this PR to go into master or open a new one that goes into master:
https://github.com/bendudson/hermes-3/compare/bendudson:master...bendudson:nonorthogonal-divops-mms-test-minimal?expand=1

Like this it is hard to see the changes you introduced.

Unfortunately I cannot do that, as I am not a collaborator :-(

@mrhardman mrhardman changed the base branch from nonorthogonal to master January 24, 2025 13:41
@mrhardman
Copy link
Collaborator Author

mrhardman commented Jan 24, 2025

Changed base to master in response to @dschwoerer's review. Making master the base obscures slightly the changes made in div_ops.cxx. The changes to this with respect to #88 are simply commit 3d11cb7 and commit 2e5e827.

@mrhardman mrhardman requested a review from dschwoerer January 24, 2025 13:42
Copy link
Owner

@bendudson bendudson left a comment

Choose a reason for hiding this comment

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

Amazing work. Thanks @mrhardman !

CMakeLists.txt Outdated Show resolved Hide resolved
Comment on lines +72 to +73
BoutReal BOUTMIN(const BoutReal& a, const BoutReal& b, const BoutReal& c,
const BoutReal& d) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
BoutReal BOUTMIN(const BoutReal& a, const BoutReal& b, const BoutReal& c,
const BoutReal& d) {
BoutReal BOUTMIN(const BoutReal a, const BoutReal b, const BoutReal c,
const BoutReal d) {

Copy link
Collaborator Author

@mrhardman mrhardman Jan 27, 2025

Choose a reason for hiding this comment

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

This seems orthogonal to this PR -- can you please explain what the suggested change does here? I don't know for sure whether or not this line is covered by a test.

Comment on lines 74 to 76
BoutReal r1 = (a < b) ? a : b;
BoutReal r2 = (c < d) ? c : d;
return (r1 < r2) ? r1 : r2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Which I think should be equivalent to

Suggested change
BoutReal r1 = (a < b) ? a : b;
BoutReal r2 = (c < d) ? c : d;
return (r1 < r2) ? r1 : r2;
return std::min({a, b, c, d});

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems orthogonal to this PR -- can you please explain what the suggested change does here? I don't know for sure whether or not this line is covered by a test.

aup = a.yup();
adown = a.ydown();

mesh->communicate(fddx_xhigh);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that this does not work for fci.
for fci the right thing would be to do the above calculation also for the parallel slices.

Suggested change
mesh->communicate(fddx_xhigh);
if (f.isFci()) {
throw BoutException("This is not implemented for FCI.\n"
"The above calculation needs to be done for the parallel slices as well");
}
mesh->communicate(fddx_xhigh);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

f.isFci() appears not be be a valid call in this branch, errors appear on compilation. Could you please make a PR into this PR with valid changes?

src/div_ops.cxx Outdated Show resolved Hide resolved
Comment on lines +1227 to +1233
for (int i = mesh->xstart - 1; i <= mesh->xend; i++) {
for (int j = mesh->ystart; j <= mesh->yend; j++) {
for (int k = 0; k < mesh->LocalNz; k++) {
// Calculate flux from i to i+1

const int kp = (k + 1) % mesh->LocalNz;
const int km = (k - 1 + mesh->LocalNz) % mesh->LocalNz;
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you please be more specific with a code suggestion? I do not understand the code-base well enough to guess what you mean here.

mrhardman and others added 5 commits January 27, 2025 13:50
David Bold correction making sure appropriate error message is present if FCI is used.

Co-authored-by: David Bold <[email protected]>
Co-authored-by: David Bold <[email protected]>
@mrhardman
Copy link
Collaborator Author

@dschwoerer Could you please make a PR with your suggestions into this PR? It looks like some of the functions that you expect to be available are not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants