Skip to content

Commit 23e56ce

Browse files
authored
Matrix in Linear Reconstruction dynamic array replace by static array (#73)
* Matrix in Linear Reconstruction dynamic array replace by static array * PR Changes 1 * PR Change 2
1 parent 4d9e866 commit 23e56ce

File tree

5 files changed

+19
-36
lines changed

5 files changed

+19
-36
lines changed

src/pmpo_MPMesh.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void MPMesh::calcBasis() {
3434
initArray(basisByArea3d,maxVtxsPerElm,0.0);
3535

3636
// calc basis
37-
getBasisByAreaGblFormSpherical2(position3d, numVtx, v3d, radius, basisByArea3d);
37+
getBasisByAreaGblFormSpherical(position3d, numVtx, v3d, radius, basisByArea3d);
3838

3939
// fill step
4040
for(int i=0; i<= numVtx; i++){
@@ -339,7 +339,7 @@ void MPMesh::push(){
339339
else
340340
p_MPs->rebuild(); //rebuild pumi-pic
341341
p_MPs->updateMPElmID(); //update mpElm IDs slices
342-
reconstructSlices();
342+
reconstructSlices();
343343
}
344344
while (anyIsMigrating);
345345

src/pmpo_MPMesh_assembly.hpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,24 @@ void MPMesh::assemblyVtx1() {
147147
p_MPs->parallel_for(assemble, "assembly");
148148

149149
//Solve Ax=b for each vertex
150-
Kokkos::View<double*[vec4d_nEntries]> VtxCoeffs("VtxMatrices", p_mesh->getNumVertices());
150+
Kokkos::View<double*[vec4d_nEntries]> VtxCoeffs("VtxCoeffs", p_mesh->getNumVertices());
151151
Kokkos::parallel_for("solving Ax=b", numVtx, KOKKOS_LAMBDA(const int vtx){
152152
Vec4d v0 = {VtxMatrices(vtx,0,0), VtxMatrices(vtx,0,1), VtxMatrices(vtx,0,2), VtxMatrices(vtx,0,3)};
153153
Vec4d v1 = {VtxMatrices(vtx,1,0), VtxMatrices(vtx,1,1), VtxMatrices(vtx,1,2), VtxMatrices(vtx,1,3)};
154154
Vec4d v2 = {VtxMatrices(vtx,2,0), VtxMatrices(vtx,2,1), VtxMatrices(vtx,2,2), VtxMatrices(vtx,2,3)};
155155
Vec4d v3 = {VtxMatrices(vtx,3,0), VtxMatrices(vtx,3,1), VtxMatrices(vtx,3,2), VtxMatrices(vtx,3,3)};
156-
Matrix4d A = {v0,v1,v2,v3};
157-
158-
//double f_norm=A.frobeniusNorm();
156+
157+
Matrix4d A = {v0,v1,v2,v3};
159158
double A_trace = A.trace();
160159
Matrix4d A_regularized = {v0, v1, v2, v3};
161160
A_regularized.addToDiag(A_trace*1e-8);
162-
161+
163162
double coeff[vec4d_nEntries]={0.0, 0.0, 0.0, 0.0};
164163
CholeskySolve4d_UnitRHS(A_regularized, coeff);
165164
for (int i=0; i<vec4d_nEntries; i++)
166165
VtxCoeffs(vtx,i)=coeff[i];
167166
});
168-
167+
169168
//Reconstruct
170169
auto reconstruct = PS_LAMBDA(const int& elm, const int& mp, const int& mask) {
171170
if(mask) { //if material point is 'active'/'enabled'
@@ -189,7 +188,7 @@ void MPMesh::assemblyVtx1() {
189188
}
190189
};
191190
p_MPs->parallel_for(reconstruct, "reconstruct");
192-
191+
193192
Kokkos::parallel_for("assigning", numVtx, KOKKOS_LAMBDA(const int vtx){
194193
for(int k=0; k<numEntries; k++)
195194
meshField(vtx, k) = reconVals(vtx,k);

src/pmpo_materialPoints.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class MaterialPoints {
215215
auto tgtPosXYZ = MPs->get<MPF_Tgt_Pos_XYZ>();
216216
auto rotLatLonIncr = MPs->get<MPF_Rot_Lat_Lon_Incr>();
217217

218-
auto is_rotated = getRotatedFlag();
218+
auto is_rotated = getRotatedFlag();
219219
auto updateRotLatLon = PS_LAMBDA(const int& elm, const int& mp, const int& mask){
220220
if(mask){
221221
auto rotLat = curPosRotLatLon(mp,0) + rotLatLonIncr(mp,0); // phi

src/pmpo_utils.hpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -214,37 +214,21 @@ class Matrix4d {
214214

215215
private:
216216

217-
double** data_;
218-
int rows_=4;
219-
int cols_=4;
217+
double data_[4][4];
220218

221219
public:
222220

223221
KOKKOS_INLINE_FUNCTION
224222
Matrix4d(Vec4d v0, Vec4d v1, Vec4d v2, Vec4d v3){
225-
data_ = new double*[rows_];
226223

227-
for (int i=0; i<rows_; i++){
228-
data_[i] = new double[cols_];
229-
}
230-
231-
for (int i=0; i<cols_; i++){
224+
for (int i=0; i<4; i++){
232225
data_[0][i] = v0[i];
233226
data_[1][i] = v1[i];
234227
data_[2][i] = v2[i];
235228
data_[3][i] = v3[i];
236229
}
237230
}
238-
239-
//Destructor
240-
KOKKOS_INLINE_FUNCTION
241-
~Matrix4d(){
242-
for (int i=0; i<4; i++){
243-
delete[] data_[i];
244-
}
245-
delete[] data_;
246-
}
247-
231+
248232
//Retrieval
249233
KOKKOS_INLINE_FUNCTION
250234
double& operator()(int i, int j) { return data_[i][j];}
@@ -253,8 +237,8 @@ class Matrix4d {
253237
KOKKOS_INLINE_FUNCTION
254238
Matrix4d operator/(double scalar) const {
255239
Matrix4d result(Vec4d(0, 0, 0, 0), Vec4d(0, 0, 0, 0), Vec4d(0, 0, 0, 0), Vec4d(0, 0, 0, 0));
256-
for (int i = 0; i < rows_; i++) {
257-
for (int j = 0; j < cols_; j++) {
240+
for (int i = 0; i < 4; i++) {
241+
for (int j = 0; j < 4; j++) {
258242
result(i, j) = data_[i][j] / scalar;
259243
}
260244
}
@@ -265,8 +249,8 @@ class Matrix4d {
265249
KOKKOS_INLINE_FUNCTION
266250
double frobeniusNorm() const {
267251
double sum = 0.0; // Initialize sum of squares
268-
for (int i = 0; i < rows_; i++) {
269-
for (int j = 0; j < cols_; j++) {
252+
for (int i = 0; i < 4; i++) {
253+
for (int j = 0; j < 4; j++) {
270254
sum += data_[i][j]* data_[i][j]; // Sum of squares
271255
}
272256
}
@@ -277,7 +261,7 @@ class Matrix4d {
277261
KOKKOS_INLINE_FUNCTION
278262
double trace() const {
279263
double traceSum = 0.0; // Initialize sum of diagonal elements
280-
for (int i = 0; i < rows_; i++) {
264+
for (int i = 0; i < 4; i++) {
281265
traceSum += data_[i][i]; // Sum diagonal elements
282266
}
283267
return traceSum;
@@ -286,7 +270,7 @@ class Matrix4d {
286270
//Function to regularize the matrix
287271
KOKKOS_INLINE_FUNCTION
288272
void addToDiag(double eps) {
289-
for (int i = 1; i < rows_; i++) {
273+
for (int i = 1; i < 4; i++) {
290274
data_[i][i]=data_[i][i]+eps;
291275
}
292276
}

src/pmpo_wachspressBasis.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void sphericalInterpolation(MPMesh& mpMesh){
342342
initArray(basisByArea3d,maxVtxsPerElm,0.0);
343343

344344
// calc basis
345-
getBasisByAreaGblFormSpherical2(position3d, numVtx, v3d, radius, basisByArea3d);
345+
getBasisByAreaGblFormSpherical(position3d, numVtx, v3d, radius, basisByArea3d);
346346

347347
// interpolation step
348348
for(int entry=0; entry<numEntries; entry++){

0 commit comments

Comments
 (0)