Skip to content

Vector rotation - #1108

Open
einola wants to merge 15 commits into
issue1101_bilinearfrom
issue1101_vector_rotation
Open

einola wants to merge 15 commits into
issue1101_bilinearfrom
issue1101_vector_rotation

Conversation

@einola

@einola einola commented Aug 13, 2026

Copy link
Copy Markdown
Member

Vector rotation

Fixes part 3 of #1101 and #1087

Task List

  • Linked an issue above that captures the requirements of this PR
  • Defined the tests that specify a complete and functioning change
  • Implemented the source code change that satisfies the tests
  • Commented all code so that it can be understood without additional context
  • No new warnings are generated or they are mentioned below
  • The documentation has been updated (or an issue has been created to do so)
  • Relevant labels (e.g., enhancement, bug) have been applied to this PR
  • This change conforms to the conventions described in the README

Change Description

Adds a class to perform vector rotations for inputs and outputs between the nextsim, displaced-pole coordinate system and that of an arbitrary input or output grid. The constructor calculates the unit vectors of the input/output grid in the nextsim coordinate system. These are then used to transform input vectors in class member functions. This can handle both grid-aligned vectors and vectors aligned with the east/north directions.


Test Description

Minimal testing so far, but it seems to work.


Documentation Impact

None yet.


Other Details

I've integrated this into the reading part, but we should also do vector rotation on the output.

I've created a GitHub "stack" out of this PR and #1102 (stack is labelled #1109). Let's see how that works.

@einola einola added the enhancement New feature or request label Aug 13, 2026
@einola einola added this to the 3 Stand-alone model milestone Aug 13, 2026
@einola
einola requested a review from timspainNERSC August 13, 2026 05:26
This class takes the input/output grid as an input for the constructor
and calculates the unit vectors in the displaced-pole coordinate system.
It then provides methods to use those unit vectors to transform vectors
to or from the model grid. Based on Thomas' code. Not well tested, but
there's something not right happening around the "dateline" of the
displaced-pole coordinate system.
The original ones were just wrong. I also simplified a bit the logic, so
now we need special treatment for the top row, last column, and upper
right corner only.
It's a nice closed-form solution, with a complicated angle. Needed some
restructuring of the surrounding code, of course.
The loop restructuring makes it run over element id, instead of first y
and then x. Not a huge improvement, but guaranties that we traverse
memory efficiently and is better for parallelisation.
Just aestetics, but I think it's a bit cleaner looking. Also, why did I
use the "this" pointer for initENOrientation?
It's much nicer to use the closed form solution in
VectorRotator::initENOrientation.
Better comments and files should have an empty line at the end.
Changes to CMakeLists.txt to export the project include directories on
nextsimlib as PUBLIC. Unify the use of #includ "include/..." in
ParaGridInputs and VectorRotator.
No need to copy things beforehand.
Nobody knows what ERA5's vector values at the pole are supposed to mean.
Here, we first rotate all the vectors to point towards Greenland; then
we replace the value at the geographic pole with the mean of all the
surrounding values.
It makes more sense to have it there, and also simplifies a bit the
logic.
This throws an exception in the case when a point in the model grid is
not found in the forcing grid. That exception is not yet caught
anywhere, but the model should just stop anyway.
Trying to make sure I don't run into problems with trigonometric
functions when using single precision. May be overkill as it is, but
better safe than sorry. I haven't tested this very much.
Very easy, now that everything else is in place. But the
CheckingModelComponent isn't working the way it should! It reports that
there's negative snowfall around -1e-6, when in reality there's a
round-off error in the netCDF file at -1e-19.
@einola
einola force-pushed the issue1101_vector_rotation branch from e664f24 to 6c2162d Compare September 14, 2026 04:18
@einola
einola removed this pull request from stack #1109 September 14, 2026 04:26
@einola
einola added this pull request to stack #1119 September 14, 2026 04:27
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.

1 participant