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

custom coords #1039

Merged
merged 41 commits into from
Apr 10, 2024
Merged

custom coords #1039

merged 41 commits into from
Apr 10, 2024

Conversation

Yurlungur
Copy link
Collaborator

@Yurlungur Yurlungur commented Mar 29, 2024

PR Summary

This PR is designed to support codes like Phoebus, Artemis, and Assail downstream that uses coordinates that are not the uniform cartesian coordinate system. It lets you tag a mesh variable as a coordinates array. To do say, make your variable a node-centered 3-vector and add the Metadata::CoordinatesVec MetadataFlag to it. Then fill this variable with the x, y, and z coordinates of your nodes as appropriate.

If you do this, the variable will automatically be output in dumps and restarts and the xdmf file will will record this field as your coordinates per meshblock. Tested in parthenon-mhd.

This is also ready for downstream testing and review in downstream codes. Depends on #1019 . I haven't fully cleaned up formatting/linting/docs yet.

PR Checklist

  • Code passes cpplint
  • New features are documented.
  • Adds a test for any bugs fixed. Adds tests for new features.
  • Code is formatted
  • Changes are summarized in CHANGELOG.md
  • Change is breaking (API, behavior, ...)
    • Change is additionally added to CHANGELOG.md in the breaking section
    • PR is marked as breaking
    • Short summary API changes at the top of the PR (plus optionally with an automated update/fix script)
  • CI has been triggered on Darwin for performance regression tests.
  • Docs build
  • (@lanl.gov employees) Update copyright on changed files

@Yurlungur Yurlungur added the enhancement New feature or request label Mar 29, 2024
@Yurlungur Yurlungur self-assigned this Mar 29, 2024
@Yurlungur Yurlungur changed the base branch from jmm/output-nodes-2 to develop April 3, 2024 19:30
@@ -3,11 +3,11 @@
## Current develop

### Added (new features/APIs/variables/...)

- [[PR1039]](https://github.com/parthenon-hpc-lab/parthenon/pull/1039) Add ability to output custom coordinate positions for Visit/Paraview
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 ended up in the changelog for the previous release by accident.

@@ -184,6 +184,88 @@ std::ostream &operator<<(std::ostream &os, const parthenon::Metadata &m) {
return os;
}

// Return true if the flags constraints are satisfied, false otherwise. If throw_on_fail
// is true, throw a descriptive exception when invalid
bool Metadata::IsValid(bool throw_on_fail) const {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved from hpp to cpp

Comment on lines 120 to 142
const int n3_offset = output_coords ? (nx3 > 1) : 1;
const int n2_offset = output_coords ? (nx2 > 1) : 1;
int ndim_mesh;
std::string mesh_type, dimstring;
if (output_coords) {
if (nx3 > 1) {
ndim_mesh = 3;
mesh_type = "3DSMesh";
dimstring = StringPrintf("%d %d %d", nx3 + n3_offset, nx2 + n2_offset, nx1 + 1);
} else if (nx2 > 1) {
ndim_mesh == 2;
mesh_type = "2DSMesh";
dimstring = StringPrintf("%d %d", nx2 + n2_offset, nx1 + 1);
} else {
ndim_mesh == 1;
mesh_type = "Polyline";
dimstring = StringPrintf("%d", nx1 + 1);
}
} else {
mesh_type = "3DRectMesh";
ndim_mesh = 3;
dimstring = StringPrintf("%d %d %d", nx3 + n3_offset, nx2 + n2_offset, nx1 + 1);
}
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 madness merits explanation. The story goes like this:

  • We want Visit/Paraview to use output mesh data (rather than the x*f arrays) as coordinates. This means going to SMesh in 3D and 2D.
  • Paraview/Visit expects coordinate positions to be at nodes. We always output 1 extra face even in trivial directions for the x*f arrays. But we don't for positions of node-centered fields. This necessitates changing the dimension of the data that is read by visit/paraview depedning on output dimension. In other words, in 2D we must use 2DSMesh, not 3DSMesh and it needs an (nx2+1, nx1+1) array, not a (1, nx2+1, nx1+1) array.
  • 1D gets crazier as there is no structured mesh object in 1D in xdmf. Only Polyline.

The remaining changes to this file can be understood as contorting themselves to support the 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.

Ok I am dropping the 1D as it's a lot of contortion for an uncommon use-case.

@Yurlungur Yurlungur disabled auto-merge April 8, 2024 17:09
@Yurlungur Yurlungur enabled auto-merge April 8, 2024 17:09
Copy link
Collaborator

@bprather bprather left a comment

Choose a reason for hiding this comment

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

LGTM, will be great to finally be able to use xdmf outputs for something in KHARMA

Copy link
Collaborator

@lroberts36 lroberts36 left a comment

Choose a reason for hiding this comment

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

LGTM, but I am not sure that I can provide too useful of a review of the xdmf. The fact that it works is good enough for me though.

src/outputs/parthenon_xdmf.cpp Show resolved Hide resolved
@Yurlungur Yurlungur disabled auto-merge April 10, 2024 21:49
@Yurlungur Yurlungur merged commit 5ec8ab5 into develop Apr 10, 2024
49 checks passed
Copy link
Collaborator

@pgrete pgrete left a comment

Choose a reason for hiding this comment

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

Some last minute post-merge comments for potential future clarification.

src/interface/metadata.cpp Show resolved Hide resolved
src/outputs/parthenon_hdf5.cpp Show resolved Hide resolved
src/outputs/parthenon_xdmf.cpp Show resolved Hide resolved
src/outputs/parthenon_xdmf.cpp Show resolved Hide resolved
@Yurlungur
Copy link
Collaborator Author

Thanks @pgrete I'll make these changes and submit a tirival PR to fix

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

Successfully merging this pull request may close these issues.

5 participants