00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _MGSYSTEM_H_
00032 #define _MGSYSTEM_H_
00033
00034 #include <LSsystem.h>
00035 #include <UCBsplineSurface.h>
00036
00133 class MGsystem {
00134
00135
00136 std::vector<double> domain_;
00137 std::vector<LSsystem*> systems_;
00138 GenMatrix<UCBspl_real> r_;
00139 GenMatrix<UCBspl_real> e_refined_;
00140
00141
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_;
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();
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
00167
00168 void relaxAndCorrectVcycle(int noLevelsInVcycle);
00169
00170
00171
00172
00173
00174
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,
00222 shared_map weights = shared_map(new std::map<int, double>) );
00223
00224
00225
00226
00228 void solveFMG();
00229
00231 void solveAscend();
00232
00236
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
00343 void qweInitX(double value) {
00344 systems_[systems_.size()-1]->x_->fill(value);
00345 }
00346
00347
00348
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