MGsystem.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 _MGSYSTEM_H_
00032 #define _MGSYSTEM_H_
00033 
00034 #include <LSsystem.h>
00035 #include <UCBsplineSurface.h>
00036 
00133 class MGsystem {
00134 
00135     // Common temporaries for both FMG and V-cycle (but not for solveAscend)
00136     std::vector<double> domain_;    // defailt is umin, vmin, umax, vmax (see also LSsystem)
00137     std::vector<LSsystem*> systems_;
00138     GenMatrix<UCBspl_real> r_;
00139     GenMatrix<UCBspl_real> e_refined_;
00140   
00141     // Array of solution vectors (pointers)
00142     typedef boost::shared_ptr<GenMatrix<UCBspl_real> > shared_gm;
00143     std::vector<shared_gm> e_arr_;
00144 
00145     int noIter_;
00146     int noIterCoarsest_;
00147 
00148     double lambdaFac_;
00149 
00150     int m0_, n0_; // given to init multilevel 
00151     void calculateStartVector() const;
00152 
00153     double umin() const {return domain_[0];}
00154     double vmin() const {return domain_[1];}
00155     double umax() const {return domain_[2];}
00156     double vmax() const {return domain_[3];}
00157 
00158     void reserveResidual(); // assumes that init has been done
00159 
00160     void residual(const LSsystem& lssys, GenMatrix<UCBspl_real>& r) const;
00161     void residual_restrictionInjection(const LSsystem& lssys, GenMatrix<UCBspl_real>& r) const;
00162     void residual_restrictionFullWeightingLaplace(const LSsystem& lssys, 
00163                                                   GenMatrix<UCBspl_real>& r) const;
00164     void residual_restrictionSplines(const LSsystem& lssys, GenMatrix<UCBspl_real>& r) const;
00165 
00166     // Can also be used with a start vector (e.g. to adjust smoothness)
00167     // ???? Is not using private members now
00168     void relaxAndCorrectVcycle(int noLevelsInVcycle);
00169 
00170     // Used to control allocation of right hand side (RHS) at the finest level.
00171     // This is used to avoid building the RHS again if a solveVcycle or relax is
00172     // run afterwards to improve the solution (or adjust smoothness)
00173     // false = initial status before any solvers have been run
00174     // true  = the RHS at the finest level has been calculated
00175     bool rhsFinestLevel_;
00176 
00177 public:
00179     MGsystem() {lambdaFac_=1.0; noIter_=10; noIterCoarsest_=50; rhsFinestLevel_=false;}
00180     ~MGsystem() {cleanup();}
00181   
00216     typedef boost::shared_ptr<std::map<int, double> > shared_map;
00217     void initMultilevel(int m0, int n0, int h,
00218                         boost::shared_ptr<std::vector<double> > U,
00219                         boost::shared_ptr<std::vector<double> > V,
00220                         boost::shared_ptr<std::vector<double> > Z,
00221                         boost::shared_ptr<GenMatrix<UCBspl_real> > x, // solution vector
00222                         shared_map weights = shared_map(new std::map<int, double>) );
00223     //boost::shared_ptr<std::map<int, double> > weights = boost::shared_ptr<std::map<int, double> >(new std::map<int, double>) );
00224 
00225   
00226               
00228     void solveFMG();
00229   
00231     void solveAscend();
00232 
00236     //void solveAscend(double err);
00237 
00239     void solveVcycle();
00240 
00249     void relax(int numberOfIterations, int relaxType = 3);
00250 
00252     UCBspl::SplineSurface getSplineSurface() const;
00253 
00258     double residual_l2(bool scaled=false) const;
00262     double residual_linf() const;
00263 
00276     void setDomain(double umin, double vmin, double umax, double vmax);
00277 
00279     void getDomain(double& umin, double& vmin, double& umax, double& vmax);
00280 
00311     void setSmoothingFactor(double smoothingFac);
00312 
00326     bool addPoint(double u, double v, double z, double weight=1.0);
00327 
00331     void setWeight(int pointIndex, double weight);
00332   
00334     void setNumberOfIterations(int noIter) {noIter_=noIter;}
00335 
00337     void setNumberOfIterationsCoarsest(int noIter) {noIterCoarsest_ = noIter;}
00338   
00340     void cleanup();
00341 
00342     /* ??? Initialize solution vector with \e value */
00343     void qweInitX(double value) {
00344         systems_[systems_.size()-1]->x_->fill(value);
00345     }
00346 
00347     // ??? temporary function for use in LSsystem::CGPrecond
00348     /* Set right hand side in equation system. */
00349     void qweSetRHS(const GenMatrix<UCBspl_real>& t_k) {
00350         systems_[systems_.size()-1]->b_.init(t_k);
00351         rhsFinestLevel_ = true;
00352     }
00353 
00354 };
00355 
00356 #endif

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