@@ -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 }
0 commit comments