Vector rotation - #1108
Open
einola wants to merge 15 commits into
Open
Vector rotation#1108einola wants to merge 15 commits into
einola wants to merge 15 commits into
Conversation
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.
Try to stay DRY.
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
force-pushed
the
issue1101_vector_rotation
branch
from
September 14, 2026 04:18
e664f24 to
6c2162d
Compare
einola
removed this pull request from stack #1109
September 14, 2026 04:26
einola
added this pull request to stack #1119
September 14, 2026 04:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vector rotation
Fixes part 3 of #1101 and #1087
Task List
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.