LSsystem.h

00001 //===========================================================================
00002 // SINTEF LSMG library - version 1.1
00003 //
00004 // Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway.
00005 //
00006 // This program is free software; you can redistribute it and/or          
00007 // modify it under the terms of the GNU General Public License            
00008 // as published by the Free Software Foundation version 2 of the License. 
00009 //
00010 // This program is distributed in the hope that it will be useful,        
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00013 // GNU General Public License for more details.                           
00014 //
00015 // You should have received a copy of the GNU General Public License      
00016 // along with this program; if not, write to the Free Software            
00017 // Foundation, Inc.,                                                      
00018 // 59 Temple Place - Suite 330,                                           
00019 // Boston, MA  02111-1307, USA.                                           
00020 //
00021 // Contact information: e-mail: tor.dokken@sintef.no                      
00022 // SINTEF ICT, Department of Applied Mathematics,                         
00023 // P.O. Box 124 Blindern,                                                 
00024 // 0314 Oslo, Norway.                                                     
00025 //
00026 // Other licenses are also available for this software, notably licenses
00027 // for:
00028 // - Building commercial software.                                        
00029 // - Building software whose source code you wish to keep private.        
00030 //===========================================================================
00031 #ifndef _LSSYSTEM_H_
00032 #define _LSSYSTEM_H_
00033 
00034 #include <MatSparse.h>
00035 #include <GenMatrix.h>
00036 #include <UCBtypedef.h>
00037 
00038 #include <map>
00039 
00040 #include <boost/shared_ptr.hpp>
00041 
00074 class LSsystem {
00075   friend class MGsystem;
00076   
00077 
00078   // Equation system A_ x_ = b_
00079   MatSparse A_;                                  // The system matrix, with smoothing term included
00080   boost::shared_ptr<GenMatrix<UCBspl_real> > x_; // The unknown B-spline coefficient matrix (corresponds to PHI_ in MBA)
00081   GenMatrix<UCBspl_real> b_;                     // Right hand side (also as a matrix) built from z-values
00082 
00083   int n1_, n2_;      // size of spline coefficient matrix: x_.noX(), x_.noY() in A_ x_= b_
00084   int K_,   L_;      // order of spline surface
00085   
00086   double lambda_;    // calculated from the l_2 norms of the matrices: 
00087   double lambdaFac_; // a factor multiplied with lambda (default = 1)
00088   
00089   // The scattered data
00090   boost::shared_ptr<std::vector<double> > U_;
00091   boost::shared_ptr<std::vector<double> > V_;
00092   boost::shared_ptr<std::vector<double> > Zvals_;
00093   boost::shared_ptr<std::map<int, double, std::less<int> > > weights_;
00094 
00095 
00096   std::vector<double> domain_;   // defaults is umin, vmin, umax, vmax
00097     
00098   // Internal (private) functions
00099   void   calculateDomain();
00100   double umin() const {return domain_[0];}
00101   double vmin() const {return domain_[1];}
00102   double umax() const {return domain_[2];}
00103   double vmax() const {return domain_[3];}
00104   void   buildSparseStructure();
00105   void   addSmoothingTerm(double lambdaVal); // (= regularization term) (to A_)
00106   void   setLimits();
00107   void   calcLambda(); // for smoothing term
00108 
00109   void buildRHS(); // Build right hand side from data (this is also optionally done in buildEqSystem)
00110 
00111   void residual(GenMatrix<UCBspl_real>& r) const;
00112 
00113 public:
00114   
00123   LSsystem(boost::shared_ptr<std::vector<double> > U,
00124            boost::shared_ptr<std::vector<double> > V,
00125            boost::shared_ptr<std::vector<double> > Zvals,
00126            int noX, int noY,       // grid size and number of unknowns is noX*noY
00127            boost::shared_ptr<GenMatrix<UCBspl_real> > PHI, // solution vector
00128            double smoothingFac = 1.0);
00129 
00130   ~LSsystem(){}
00131   
00132   void setWeights(boost::shared_ptr<std::map<int, double, std::less<int> > > weights) {weights_ = weights;}
00133 
00137   void buildEqSystem(bool buildRHS = true); // A_ and b_ (and smoothing term)
00138   
00140   void relaxGaussSeidel(int noIterations);
00141   
00143   void relaxCG(int noIterations);
00144 
00146   void relaxCGPrecond(int noIterations);
00147 
00149   void relaxJacobi(int noIterations, double omega=2./3.);
00150 
00163   void setDomain(double umin, double vmin, double umax, double vmax);
00164 
00166   void getDomain(double& umin, double& vmin, double& umax, double& vmax);
00167 
00169   int  numberOfUnknowns() const {return x_->noX() * x_->noY();} // Which is the same as n1_*n2_
00170 
00180   void setSmoothingFactor(double smoothingFac);
00181 
00189   bool addPoint(double u, double v, double z, double weight=1.0, bool addToRHS=true);
00190     
00192   double currentSolutionNorm() const;
00193 
00195   double residual_l2(bool scaled=false) const;
00197   double residual_linf() const;
00198 
00199   static double rowMatVecMult(int row_no, const MatSparse& A, const GenMatrix<UCBspl_real>& x);
00200 };
00201 
00202 #endif
00203 

Generated on Wed Nov 28 12:27:29 2007 for LSMG by  doxygen 1.5.1