SubSystem.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Konstantinos Poulios      (logari81@gmail.com) 2011     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #ifndef FREEGCS_SUBSYSTEM_H
00024 #define FREEGCS_SUBSYSTEM_H
00025 
00026 #undef min
00027 #undef max
00028 
00029 #include <Eigen/Core>
00030 #include "Constraints.h"
00031 
00032 namespace GCS
00033 {
00034 
00035     class SubSystem
00036     {
00037     private:
00038         int psize, csize;
00039         std::vector<Constraint *> clist;
00040         VEC_pD plist;      // pointers to the original parameters
00041         MAP_pD_pD pmap;    // redirection map from the original parameters to pvals
00042         VEC_D pvals;       // current variables vector (psize)
00043 //        JacobianMatrix jacobi;  // jacobi matrix of the residuals
00044         std::map<Constraint *,VEC_pD > c2p; // constraint to parameter adjacency list
00045         std::map<double *,std::vector<Constraint *> > p2c; // parameter to constraint adjacency list
00046         void initialize(VEC_pD &params, MAP_pD_pD &reductionmap); // called by the constructors
00047     public:
00048         SubSystem(std::vector<Constraint *> &clist_, VEC_pD &params);
00049         SubSystem(std::vector<Constraint *> &clist_, VEC_pD &params,
00050                   MAP_pD_pD &reductionmap);
00051         ~SubSystem();
00052 
00053         int pSize() { return psize; };
00054         int cSize() { return csize; };
00055 
00056         void redirectParams();
00057         void revertParams();
00058 
00059         void getParamMap(MAP_pD_pD &pmapOut);
00060         void getParamList(VEC_pD &plistOut);
00061 
00062         void getParams(VEC_pD &params, Eigen::VectorXd &xOut);
00063         void getParams(Eigen::VectorXd &xOut);
00064         void setParams(VEC_pD &params, Eigen::VectorXd &xIn);
00065         void setParams(Eigen::VectorXd &xIn);
00066 
00067         double error();
00068         void calcResidual(Eigen::VectorXd &r);
00069         void calcResidual(Eigen::VectorXd &r, double &err);
00070         void calcJacobi(VEC_pD &params, Eigen::MatrixXd &jacobi);
00071         void calcJacobi(Eigen::MatrixXd &jacobi);
00072         void calcGrad(VEC_pD &params, Eigen::VectorXd &grad);
00073         void calcGrad(Eigen::VectorXd &grad);
00074 
00075         double maxStep(VEC_pD &params, Eigen::VectorXd &xdir);
00076         double maxStep(Eigen::VectorXd &xdir);
00077 
00078         void applySolution();
00079         void analyse(Eigen::MatrixXd &J, Eigen::MatrixXd &ker, Eigen::MatrixXd &img);
00080         void report();
00081 
00082 void printResidual();
00083     };
00084 
00085     double lineSearch(SubSystem *subsys, Eigen::VectorXd &xdir);
00086 
00087 } //namespace GCS
00088 
00089 #endif // FREEGCS_SUBSYSTEM_H

Generated on Wed Nov 23 19:00:41 2011 for FreeCAD by  doxygen 1.6.1