HiVector DriftCorrect::Solve(const HiVector &d) { ostringstream hist; _data = d; if ( _skipFit || (!gotGoodLines(d))) { _b2 = _data; _coefs = HiVector(4, 0.0); _uncert = _coefs; _cc = HiVector(2, 0.0); _chisq = 0.0; if ( !gotGoodLines(d) ) { hist << "NotEnoughLines(GoodLines[" << goodLines(d) << "],MinimumLines[" << _minLines << "]);"; } hist << "SkipFit(TRUE: Not using LMFit)"; _history.add(hist.str()); } else { hist << "Fit("; _b2 = HiVector(goodLines(_data)); if ( success(curvefit()) ) { _coefs = coefs(); _uncert = uncert(); hist << "Solved,#Iters[" << nIterations() << "],ChiSq[" << Chisq() << "],DoF[" << DoF() << "])"; _history.add(hist.str()); _history.add("a0("+ToString(_coefs[0])+"+-"+ToString(_uncert[0])+")"); _history.add("a1("+ToString(_coefs[1])+"+-"+ToString(_uncert[1])+")"); _history.add("a2("+ToString(_coefs[2])+"+-"+ToString(_uncert[2])+")"); _history.add("a3("+ToString(_coefs[3])+"+-"+ToString(_uncert[3])+")"); } else { // Punt, fit a straight line to the data _cc = poly_fit(d); HiVector a(4); a[0] = _cc[0]; a[1] = _cc[1]; a[2] = 0.0; a[3] = 0.0; _coefs = a; hist << "Failed::Reason("<< statusstr() << "),#Iters[" << nIterations() << "])"; _history.add(hist.str()); _history.add("a0("+ToString(_coefs[0])+")"); _history.add("a1("+ToString(_coefs[1])+")"); _history.add("a2("+ToString(_coefs[2])+")"); _history.add("a3("+ToString(_coefs[3])+")"); if ( _useLinFit ) { _history.add("OnFailureUse(LinearFit(Zf))"); } else { _skipFit = true; _history.add("OnFailureUse(ZfBuffer)"); } } } return (Yfit()); }
bool Foam::SolverPerformance<Type>::operator!= ( const SolverPerformance<Type>& sp ) const { return ( solverName() != sp.solverName() || fieldName() != sp.fieldName() || initialResidual() != sp.initialResidual() || finalResidual() != sp.finalResidual() || nIterations() != sp.nIterations() || converged() != sp.converged() || singular() != sp.singular() ); }
scalar surfaceOptimizer::optimiseSteepestDescent(const scalar tol) { point& pOpt = pts_[trias_[0][0]]; //- find the bounding box const scalar avgEdge = Foam::mag(pMax_ - pMin_); //- find the minimum value on the 5 x 5 raster scalar K = evaluateStabilisationFactor(); scalar funcBefore, funcAfter(evaluateFunc(K)); //- start with steepest descent optimisation vector gradF; tensor gradGradF; vector disp; disp.z() = 0.0; direction nIterations(0); do { funcBefore = funcAfter; evaluateGradients(K, gradF, gradGradF); //- store data into a matrix matrix2D mat; mat[0][0] = gradGradF.xx(); mat[0][1] = gradGradF.xy(); mat[1][0] = gradGradF.yx(); mat[1][1] = gradGradF.yy(); FixedList<scalar, 2> source; source[0] = gradF.x(); source[1] = gradF.y(); //- calculate the determinant const scalar det = mat.determinant(); if( mag(det) < VSMALL ) { disp = vector::zero; } else { disp.x() = mat.solveFirst(source); disp.y() = mat.solveSecond(source); if( mag(disp) > 0.2 * avgEdge ) { vector dir = disp / mag(disp); disp = dir * 0.2 * avgEdge; } } # ifdef DEBUGSmooth Info << "Second gradient " << gradGradF << endl; Info << "Gradient " << gradF << endl; Info << "Displacement " << disp << endl; Info << "K = " << K << endl; # endif pOpt -= disp; K = evaluateStabilisationFactor(); funcAfter = evaluateFunc(K); if( mag(funcAfter - funcBefore) / funcBefore < tol ) break; #ifdef DEBUGSmooth Info << "New coordinates " << pOpt << endl; # endif } while( ++nIterations < 100 ); return funcAfter; }