Skip to content

Commit c4dfd4c

Browse files
committed
Fixed the bug where corners are adjusted incorrectly
1 parent 5fee84d commit c4dfd4c

File tree

2 files changed

+29
-55
lines changed

2 files changed

+29
-55
lines changed

constructSolve.cpp

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,19 @@ void linearSysVars::constructMat(Eigen::VectorXd levelCoefs, Eigen::MatrixXd fir
314314
//if the index is at one of the corners:
315315
if (corner) {
316316
if (! (bc.natural)) {
317-
matList.push_back(Trip(i,i, 1.0/totalBound * totalChange));
317+
matList.push_back(Trip(i,i, -1.0 ));
318+
319+
for (int n = (state_vars.N - 1); n >=0; --n ) {
320+
321+
//check whether it's at upper or lower boundary
322+
if ( std::abs(state_vars.stateMat(i,n) - state_vars.upperLims(n)) < state_vars.dVec(n) / 2.0 ) { //upper boundary
323+
matList.push_back(Trip(i, i - state_vars.increVec(n), 1.0 / state_vars.N ) );
324+
325+
} else if ( std::abs(state_vars.stateMat(i,n) - state_vars.lowerLims(n)) < state_vars.dVec(n) / 2.0 ) { //lower boundary
326+
matList.push_back(Trip(i, i + state_vars.increVec(n), 1.0 / state_vars.N ) );
327+
}
328+
329+
}
318330
}
319331
corners.push_back(i);
320332
}
@@ -371,19 +383,7 @@ void linearSysVars::constructMat(Eigen::VectorXd levelCoefs, Eigen::MatrixXd fir
371383

372384
}
373385

374-
if (!atBound) {
375386

376-
//add elements to the vector of triplets for matrix construction
377-
for (int n = (state_vars.N - 1); n >= 0; --n) {
378-
379-
//handle level and the first and second deriv terms for each dim
380-
381-
382-
}
383-
384-
}
385-
386-
387387
}
388388

389389

@@ -419,23 +419,10 @@ void linearSysVars::solveT(int T, const bc & bc, stateVars & state_vars, Eigen::
419419
phiAll.col(t) = solver.solve(phiAll.col(t));
420420

421421
//adjust corners
422-
422+
423423
for (int i = 0; i < corners.size(); ++i) {
424-
double count = 0.0;
425-
double num = 0.0;
426-
427-
//compute the average for corners
428-
for (int n = 0; n < state_vars.N; ++n ) {
429-
if (state_vars.stateMat(corners[i],n) == state_vars.upperLims(n)) {
430-
count = count + 1.0;
431-
num = num + phiAll(corners[i] - state_vars.increVec(n), t);
432-
} else if (state_vars.stateMat(corners[i],n) == state_vars.lowerLims(n)) {
433-
count = count + 1.0;
434-
num = num + phiAll(corners[i] + state_vars.increVec(n), t);
435-
}
436-
}
437424

438-
phiAll(corners[i],t) = num / count;
425+
phiAll(corners[i],t) = 0.0;
439426

440427
}
441428
}

constructSolvePardiso.cpp

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,19 @@ void linearSysVars::constructMat(Eigen::VectorXd levelCoefs, Eigen::MatrixXd fir
314314
//if the index is at one of the corners:
315315
if (corner) {
316316
if (! (bc.natural)) {
317-
matList.push_back(Trip(i,i, 1.0/totalBound * totalChange));
317+
matList.push_back(Trip(i,i, -1.0 ));
318+
319+
for (int n = (state_vars.N - 1); n >=0; --n ) {
320+
321+
//check whether it's at upper or lower boundary
322+
if ( std::abs(state_vars.stateMat(i,n) - state_vars.upperLims(n)) < state_vars.dVec(n) / 2.0 ) { //upper boundary
323+
matList.push_back(Trip(i, i - state_vars.increVec(n), 1.0 / state_vars.N ) );
324+
325+
} else if ( std::abs(state_vars.stateMat(i,n) - state_vars.lowerLims(n)) < state_vars.dVec(n) / 2.0 ) { //lower boundary
326+
matList.push_back(Trip(i, i + state_vars.increVec(n), 1.0 / state_vars.N ) );
327+
}
328+
329+
}
318330
}
319331
corners.push_back(i);
320332
}
@@ -371,18 +383,6 @@ void linearSysVars::constructMat(Eigen::VectorXd levelCoefs, Eigen::MatrixXd fir
371383

372384
}
373385

374-
if (!atBound) {
375-
376-
//add elements to the vector of triplets for matrix construction
377-
for (int n = (state_vars.N - 1); n >= 0; --n) {
378-
379-
//handle level and the first and second deriv terms for each dim
380-
381-
382-
}
383-
384-
}
385-
386386

387387
}
388388

@@ -481,21 +481,8 @@ void linearSysVars::solveT(int T, const bc & bc, stateVars & state_vars, Eigen::
481481
//adjust corners
482482

483483
for (int i = 0; i < corners.size(); ++i) {
484-
double count = 0.0;
485-
double num = 0.0;
486-
487-
//compute the average for corners
488-
for (int n = 0; n < state_vars.N; ++n ) {
489-
if (state_vars.stateMat(corners[i],n) == state_vars.upperLims(n)) {
490-
count = count + 1.0;
491-
num = num + phiAll(corners[i] - state_vars.increVec(n), t);
492-
} else if (state_vars.stateMat(corners[i],n) == state_vars.lowerLims(n)) {
493-
count = count + 1.0;
494-
num = num + phiAll(corners[i] + state_vars.increVec(n), t);
495-
}
496-
}
497484

498-
phiAll(corners[i],t) = num / count;
485+
phiAll(corners[i],t) = 0.0;
499486

500487
}
501488
}

0 commit comments

Comments
 (0)