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

Update on coordinate transform between cubed sphere panels (finished version) #144

Merged
merged 23 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 109 additions & 19 deletions src/exo3/cs_velocity_rotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ void vel_zab_to_zxy(Real *v1, Real *v2, Real *v3, Real a, Real b) {
Real vy = *v3;
Real vz = *v1;

Real delta = sqrt(x * x + y * y + 1);
Real C = sqrt(1 + x * x);
Real D = sqrt(1 + y * y);
Real delta = sqrt(x*x + y*y + 1);
Real C = sqrt(1 + x*x);
Real D = sqrt(1 + y*y);

*v1 = (vz - D * x * vx - C * y * vy) / delta;
*v2 = (x * vz + D * vx) / delta;
*v3 = (y * vz + C * vy) / delta;
*v2 =
(x * vz + D * vx) / delta;
*v3 =
(y * vz + C * vy) / delta;
}

//! Transform local cartesian velocity to cubed sphere velocity
Expand All @@ -29,19 +31,22 @@ void vel_zxy_to_zab(Real *v1, Real *v2, Real *v3, Real a, Real b) {
Real vy = *v3;
Real vz = *v1;

Real delta = sqrt(x * x + y * y + 1);
Real C = sqrt(1 + x * x);
Real D = sqrt(1 + y * y);
Real delta = sqrt(x*x + y*y + 1);
Real C = sqrt(1 + x*x);
Real D = sqrt(1 + y*y);

*v1 = (vz + x * vx + y * vy) / delta;
*v2 = (-x * vz / D + vx * (1 + y * y) / D - vy * x * y / D) / delta;
*v3 = (-y * vz / C - x * y * vx / C + (1 + x * x) * vy / C) / delta;
*v2 =
(-x * vz / D + vx * (1 + y*y) / D - vy * x * y / D) / delta;
*v3 =
(-y * vz / C - x * y * vx / C + (1 + x*x) * vy / C) / delta;
}

//! Transform cubed sphere velocity from panel 1 to panel 2
//! \param a $x = \tan(\xi)$ coordinates
//! \param b $y = \tan(\eta)$ coordinat
void vel_zab_from_p1(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
void vel_zab_from_p1(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel) {
vel_zab_to_zxy(vz, vx, vy, a, b);
Real v1 = *vz;
Real v2 = *vx;
Expand Down Expand Up @@ -79,7 +84,8 @@ void vel_zab_from_p1(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
}
}

void vel_zab_from_p2(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
void vel_zab_from_p2(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel) {
vel_zab_to_zxy(vz, vx, vy, a, b);
Real v1 = *vz;
Real v2 = *vx;
Expand All @@ -92,38 +98,70 @@ void vel_zab_from_p2(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
*vy = v1;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 2:
case 3:
// z->-x, x->-y, y->z
*vz = -v2;
*vx = -v3;
*vy = v1;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 4:
// z->x, x->-z, y->y
*vz = v2;
*vx = -v1;
*vy = v3;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 5:
// z->-y, x->x, y->z
*vz = -v3;
*vx = v2;
*vy = v1;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
}
}

void vel_zab_from_p3(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
void vel_zab_from_p3(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel) {
vel_zab_to_zxy(vz, vx, vy, a, b);
Real v1 = *vz;
Real v2 = *vx;
Real v3 = *vy;
switch (panel) {
case 1:
// z->x, x->-z, y->y
// z->-x, x->z, y->y
*vz = -v2;
*vx = v1;
*vy = v3;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 2:
// z->y, x->-z, y->-x
*vz = v3;
*vx = -v1;
*vy = -v2;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 5:
// z->x, x->-z, y->y
*vz = v2;
*vx = -v1;
*vy = v3;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 6:
// z->-y, x->z, y->-x
*vz = -v3;
*vx = v1;
*vy = -v2;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
}
}

void vel_zab_from_p4(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
void vel_zab_from_p4(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel) {
vel_zab_to_zxy(vz, vx, vy, a, b);
Real v1 = *vz;
Real v2 = *vx;
Expand All @@ -137,32 +175,69 @@ void vel_zab_from_p4(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 2:
// z->-x, x->z, y->y
*vz = -v2;
*vx = v1;
*vy = v3;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 5:
// z->-y, x->z, y->-x
*vz = -v3;
*vx = v1;
*vy = -v2;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 6:
// z->x, x->-z, y->y
*vz = v2;
*vx = -v1;
*vy = v3;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
}
}

void vel_zab_from_p5(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
void vel_zab_from_p5(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel) {
vel_zab_to_zxy(vz, vx, vy, a, b);
Real v1 = *vz;
Real v2 = *vx;
Real v3 = *vy;
switch (panel) {
case 2:
// z->y, x->x, y->-z
*vz = v3;
*vx = v2;
*vy = -v1;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 3:
// z->-x, x->z, y->y
*vz = -v2;
*vx = v1;
*vy = v3;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 4:
// z->x, x->-y, y->-z
*vz = v2;
*vx = -v3;
*vy = -v1;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 6:
// z->-y, x->-x, y->-z
*vz = -v3;
*vx = -v2;
*vy = -v1;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
}
}

void vel_zab_from_p6(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
void vel_zab_from_p6(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel) {
vel_zab_to_zxy(vz, vx, vy, a, b);
Real v1 = *vz;
Real v2 = *vx;
Expand All @@ -176,11 +251,26 @@ void vel_zab_from_p6(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel) {
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 3:
// z->x, x->-y, y->-z
*vz = v2;
*vx = -v3;
*vy = -v1;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 4:
// z->-x, x->z, y->y
*vz = -v2;
*vx = v1;
*vy = v3;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
case 5:
// z->-y, x->-x, y->-z
*vz = -v3;
*vx = -v2;
*vy = -v1;
vel_zxy_to_zab(vz, vx, vy, a, b);
break;
}
}
} // namespace CubedSphereUtility
} // namespace CubedSphereUtility
20 changes: 13 additions & 7 deletions src/exo3/cs_velocity_rotation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ void vel_zxy_to_zab(Real *v1, Real *v2, Real *v3, Real a, Real b);
//! Transform cubed sphere velocity from panel 1 to panel 2
//! \param a $x = \tan(\xi)$ coordinates
//! \param b $y = \tan(\eta)$ coordinat
void vel_zab_from_p1(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel);
void vel_zab_from_p2(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel);
void vel_zab_from_p3(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel);
void vel_zab_from_p4(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel);
void vel_zab_from_p5(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel);
void vel_zab_from_p6(Real *vz, Real *vx, Real *vy, Real a, Real b, int panel);
void vel_zab_from_p1(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel);
void vel_zab_from_p2(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel);
void vel_zab_from_p3(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel);
void vel_zab_from_p4(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel);
void vel_zab_from_p5(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel);
void vel_zab_from_p6(Real *vz, Real *vx, Real *vy, Real a, Real b,
int panel);
} // namespace CubedSphereUtility

#endif // SRC_EXO3_VELOCITY_ROTATION_HPP_
#endif // SRC_EXO3_VELOCITY_ROTATION_HPP_
Loading
Loading