// This file is part of libhedra, a library for polyhedral mesh processing // // Copyright (C) 2016 Amir Vaxman // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #ifndef HEDRA_CHECK_TRAITS_H #define HEDRA_CHECK_TRAITS_H #include #include #include #include #include namespace hedra { namespace optimization { //This function checks the Jacobian of a traits class that is put for optimization by approximate finite differences, and reports the difference. It is important to use after coding, but it is not for the actual optimization process, since it is really brute-force and slow. template void check_traits(SolverTraits& Traits){ using namespace Eigen; using namespace std; cout<<"WARNING: FE gradient checking, reducing performance!!!"< > GradTris; for (int i=0;i(Traits.JRows(i), Traits.JCols(i), Traits.JVals(i))); SparseMatrix TraitGradient(MaxRow, CurrSolution.size()); TraitGradient.setFromTriplets(GradTris.begin(),GradTris.end()); SparseMatrix FEGradient(MaxRow, CurrSolution.size()); vector > FEGradientTris; for (int i=0;i10e-7) FEGradientTris.push_back(Triplet(j,i,CurrGradient(j))); } FEGradient.setFromTriplets(FEGradientTris.begin(), FEGradientTris.end()); SparseMatrix DiffMat=FEGradient-TraitGradient; double maxcoeff=-32767.0; int Maxi,Maxj; for (int k=0; k::InnerIterator it(DiffMat,k); it; ++it){ if (maxcoeff10e-7){ cout<<"Gradient Discrepancy at: ("<