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

New cubed sphere 2 grid #245

Merged
merged 40 commits into from
Jan 24, 2025

Conversation

mo-jonasganderton
Copy link
Contributor

Description

Initial implementation of a new cubed sphere grid.

@odlomax and @wdeconinck can both have a look over to recommend any changes - I expect this will have changed once everything else has also been implemented.

Using this implementation generates the following lonlat points - n=12, red=tile0, purple=tile5, darkest point of each colour is tij=0, lightest point is tij=143. This matches the sequence of the points in the LFRic cubed sphere.
CubedSphere_3_0_2

Impact

Once everything else is also implemented, this makes the cubed sphere more maintainable.

Checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have run the unit tests before creating the PR

@FussyDuck
Copy link

FussyDuck commented Nov 22, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@odlomax odlomax left a comment

Choose a reason for hiding this comment

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

Looks good to see a much simpler CS grid! I've added some changes. It's mostly style related. I'm sure @wdeconinck can make some more comments/suggestions.

After this, we should probably plumb the grid into the grid builder.

@wdeconinck, what do you think?

Copy link
Contributor

@odlomax odlomax left a comment

Choose a reason for hiding this comment

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

Just some final nitpicks. Cheers, @mo-jonasganderton!

@mo-jonasganderton mo-jonasganderton marked this pull request as ready for review December 18, 2024 13:51
@odlomax
Copy link
Contributor

odlomax commented Jan 7, 2025

@wdeconinck, would you be able to have a look at this at your earliest convenience?

@odlomax
Copy link
Contributor

odlomax commented Jan 9, 2025

@wdeconinck, would you be able to have a look at this at your earliest convenience?

I'm haunted by the realisation that "earliest convenience" sounds super passive aggressive. What I meant was, "whenever you can spare the time". 🙃

Copy link
Member

@wdeconinck wdeconinck left a comment

Choose a reason for hiding this comment

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

Sorry it has taken me this long @mo-jonasganderton , @odlomax . It looks great! I just have a few minor nitpick-issues to be addressed.

Down the line I hope to remove the number "2" everywhere as in CubedSphere2 :)

@mo-jonasganderton
Copy link
Contributor Author

Thank you @wdeconinck! I've made a series of improvements following your comments, let me know if there's anything else.

Copy link
Member

@wdeconinck wdeconinck left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my suggestions! It looks great now. Just one more thing I had overlooked in my last review.

Copy link
Contributor

@odlomax odlomax left a comment

Choose a reason for hiding this comment

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

Everything looks great from my point of view. We'll excise the number 2 later down the line!

Comment on lines 118 to 126
Vector tan_point(3);
Vector xyz(3);

tan_point << tan_coord[0], tan_coord[1], 1;

xyz = lfric_rotations_transposed_[tile] * tan_point;
xyz.normalize();

return {xyz(0), xyz(1), xyz(2)};
Copy link
Member

Choose a reason for hiding this comment

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

I guess this can be unrolled avoiding any temporary Vector and also removes the need for a maths library.

PointXYZ xyz;
const auto& mat = lfric_rotations_transposed_[tile];
// xyz = mat * Vector{tan_coord[0], tan_coord[1], 1}
xyz[0] = mat(0,0) * tan_coord[0] + mat(0,1) * tan_coord[1] + mat(0,2);
xyz[1] = mat(1,0) * tan_coord[0] + mat(1,1) * tan_coord[1] + mat(1,2);
xyz[2] = mat(2,0) * tan_coord[0] + mat(2,1) * tan_coord[1] + mat(2,2);
xyz.normalize();
return xyz;

Copy link
Member

Choose a reason for hiding this comment

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

Apologies to return to this again. It is just much better to avoid any object that may be causing allocations. I think that's the case when Eigen is not used. Also the Matrix type could now just be in fact a std::array<std::array<double,3>,3> and we don't need to include any eckit/maths or Eigen in CubedSphere2.h

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm on board with this. It's probably my fault for falling into the trap of thinking ahead about things we might not actually need. An array of arrays is more portable and easy enough to invert if needed.

Copy link
Member

Choose a reason for hiding this comment

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

It is also always possible to create a non-owning Eigen Matrix view of std::array<std::array<double,3>,3> if you so desire :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All done!

Copy link
Member

@wdeconinck wdeconinck left a comment

Choose a reason for hiding this comment

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

Fantastic

@wdeconinck wdeconinck force-pushed the feature/cubed_sphere_2_grid branch from a2d9c76 to 2efb785 Compare January 24, 2025 12:43
@wdeconinck wdeconinck merged commit 0f328dd into ecmwf:develop Jan 24, 2025
3 checks passed
wdeconinck added a commit that referenced this pull request Feb 10, 2025
* release/0.41.0: (44 commits)
  Update changelog
  Version 0.41.0
  Suppress more Intel warnings
  Suppress more Intel warnings
  Fix more warnings with gnu 13.2 Release build
  Fix warnings (#256)
  Move SparseMatrixStorage template functions in .cc
  Add atlas-global-matrix sandbox
  Add AssembleGlobalMatrix
  Add SparseMatrixToTriplets
  Fix SparseMatrixStorage constructor from SparseMatrixView
  Fix creation of spectral function space from TransLocal (fixes #249) (#254)
  Fortran: Allow to create MatchingPartitioner with derived FunctionSpaces
  Remove spurios debugging output
  Mesh constructor with Distribution
  New simplified cubed sphere grid (#245)
  Fix for StructuredPartitionPolygon inner bounding box
  Add hicSparse backend to sparse matrix multiply. (#246)
  Update atlas-run runner: remove old aprun command and update slurm (#251)
  Avoid no_discard warning
  ...
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.

4 participants