Skip to content

Commit dae686b

Browse files
committed
PR Change 3
1 parent 8de3f3f commit dae686b

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/pmpo_MPMesh_assembly.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ void MPMesh::assemblyVtx1() {
157157

158158
//double f_norm=A.frobeniusNorm();
159159
double A_trace = A.trace();
160-
Matrix4d A_new = {v0, v1, v2, v3};
161-
A_new.regularize(A_trace*1e-8);
160+
Matrix4d A_regularized = {v0, v1, v2, v3};
161+
A_regularized.addToDiag(A_trace*1e-8);
162162

163163
double coeff[vec4d_nEntries]={0.0, 0.0, 0.0, 0.0};
164-
CholeskySolve4d(A_new, coeff);
164+
CholeskySolve4d_UnitRHS(A_regularized, coeff);
165165
for (int i=0; i<vec4d_nEntries; i++)
166166
VtxCoeffs(vtx,i)=coeff[i];
167167
});
@@ -174,12 +174,15 @@ void MPMesh::assemblyVtx1() {
174174
int vID = elm2VtxConn(elm,i+1)-1;
175175
double w_vtx=weight(mp,i);
176176
double CoordDiffs[vec4d_nEntries] = {1, (vtxCoords(vID,0) - mpPositions(mp,0))/radius,
177-
(vtxCoords(vID,1) - mpPositions(mp,1))/radius,
178-
(vtxCoords(vID,2) - mpPositions(mp,2))/radius};
177+
(vtxCoords(vID,1) - mpPositions(mp,1))/radius,
178+
(vtxCoords(vID,2) - mpPositions(mp,2))/radius};
179+
180+
auto factor = w_vtx*(VtxCoeffs(vID,0) + VtxCoeffs(vID,1)*CoordDiffs[1] +
181+
VtxCoeffs(vID,2)*CoordDiffs[2] +
182+
VtxCoeffs(vID,3)*CoordDiffs[3]);
183+
179184
for (int k=0; k<numEntries; k++){
180-
auto val = w_vtx*(VtxCoeffs(vID,0) + VtxCoeffs(vID,1)*CoordDiffs[1] +
181-
VtxCoeffs(vID,2)*CoordDiffs[2] +
182-
VtxCoeffs(vID,3)*CoordDiffs[3])*mpData(mp,k);
185+
auto val = factor*mpData(mp,k);
183186
Kokkos::atomic_add(&reconVals(vID,k), val);
184187
}
185188
}

src/pmpo_utils.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ class Matrix4d {
285285

286286
//Function to regularize the matrix
287287
KOKKOS_INLINE_FUNCTION
288-
void regularize(double eps) {
288+
void addToDiag(double eps) {
289289
for (int i = 1; i < rows_; i++) {
290290
data_[i][i]=data_[i][i]+eps;
291291
}
@@ -303,7 +303,7 @@ void initArray(Vec2d* arr, int n, Vec2d fill){
303303

304304

305305
KOKKOS_INLINE_FUNCTION
306-
void CholeskySolve4d(Matrix4d& A, double* x){
306+
void CholeskySolve4d_UnitRHS(Matrix4d& A, double* x){
307307

308308
double a_00=A(0,0);
309309
if (A(0,0)==0){
@@ -355,20 +355,19 @@ void CholeskySolve4d(Matrix4d& A, double* x){
355355
}
356356
else{
357357
x[0]= 1.0/A(0,0);
358-
x[1]= -A(0,1)*x[0]/A(1,1); //- m12 % array(iVertex)*a0(iVertex)/m22 % array(iVertex)
359-
x[2]= -(A(0,2)*x[0]+A(1,2)*x[1])/A(2,2); //-(m13 % array(iVertex)*a0(iVertex) + m23 % array(iVertex)*a1(iVertex))/m33 % array(iVertex)
360-
x[3]= -(A(0,3)*x[0]+A(1,3)*x[1]+A(2,3)*x[2])/A(3,3); //-(m14 % array(iVertex)*a0(iVertex) + m24 % array(iVertex)*a1(iVertex) + m34 % array(iVertex)*a2(iVertex))/m44 % array(iVertex)
358+
x[1]= -A(0,1)*x[0]/A(1,1);
359+
x[2]= -(A(0,2)*x[0]+A(1,2)*x[1])/A(2,2);
360+
x[3]= -(A(0,3)*x[0]+A(1,3)*x[1]+A(2,3)*x[2])/A(3,3);
361361

362362
x[3] = x[3]/A(3,3);
363363
x[2] = ( x[2] - A(2,3)*x[3] )/A(2,2);
364364
x[1] = ( x[1] - A(1,2)*x[2] - A(1,3)*x[3])/A(1,1);
365365
x[0] = ( x[0] - A(0,1)*x[1] - A(0,2)*x[2] - A(0,3)*x[3])/A(0,0);
366-
367366
}
368367
}
369368

370369
KOKKOS_INLINE_FUNCTION
371-
void QR_decomp4d(Matrix4d& A, Matrix4d& Q, Matrix4d& R){
370+
void QRDecomp4d(Matrix4d& A, Matrix4d& Q, Matrix4d& R){
372371
int m_size=4;
373372
for (int i=0; i<m_size; i++){
374373
Vec4d A_column;
@@ -462,6 +461,7 @@ Vec3d xyz_from_lat_lon(double lat, double lon, double r){
462461
return xyz;
463462
}
464463

464+
//Rotate 90 degrees about Y axis
465465
KOKKOS_INLINE_FUNCTION
466466
Vec3d grid_rotation_backward(Vec3d& xyz_input){
467467
Vec3d xyz_output;

test/testFortranMPAdvection.f90

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ subroutine runAdvectionTest2(mpMesh, numPush, latVertex, lonVertex, nEdgesOnCell
6767
integer, dimension(:,:), pointer :: verticesOnCell
6868
real(kind=MPAS_RKIND) :: sphereRadius
6969

70-
PRINT *, "Foward: "
7170
do i = 1, numPush
7271
call calcSurfDispIncr(mpMesh, latVertex, lonVertex, nEdgesOnCell, verticesOnCell, nVertices, sphereRadius)
7372
call polympo_push(mpMesh)
7473
end do
7574

76-
PRINT *, "Backward: "
7775
call calcSurfDispIncr(mpMesh, latVertex, lonVertex, nEdgesOnCell, verticesOnCell, nVertices, sphereRadius, -numPush)
7876
call polympo_push(mpMesh)
7977

test/testFortranMPReconstruction.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ program main
101101
j = verticesOnCell(1,i)
102102
mpLatLon(1,i) = latVertex(j)
103103
mpLatLon(2,i) = lonVertex(j)
104-
mpPosition(1,i) = xCell(i) !xVertex(j)
105-
mpPosition(2,i) = yCell(i) !yVertex(j)
106-
mpPosition(3,i) = zCell(i) !zVertex(j)
104+
mpPosition(1,i) = xCell(i)
105+
mpPosition(2,i) = yCell(i)
106+
mpPosition(3,i) = zCell(i)
107107
end do
108108

109109
call polympo_createMPs(mpMesh,nCells,numMPs,c_loc(mpsPerElm),c_loc(mp2Elm),c_loc(isMPActive))

0 commit comments

Comments
 (0)