Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. void VCycle::Solve(ublas::matrix<double> & inout_u, ublas::matrix<double> & output_r, ublas::matrix<double> & input_f) {
  2.  
  3.     unsigned int size = inout_u.size1();
  4.  
  5.     //printMatrix(inout_u);
  6.  
  7.     //relax first
  8.     RelaxError(m_nInitIterations, input_f, inout_u, output_r);
  9.  
  10.     //printMatrix(inout_u);
  11.  
  12.     //restrict
  13.     ublas::matrix<double> restrictedResid = Restrict(output_r);
  14.  
  15.     //new size
  16.     unsigned int new_size = restrictedResid.size1();
  17.  
  18.     ublas::matrix<double> error;
  19.     //if further restriction makes sense, go to coarser grid
  20.     if (new_size >= 3) {
  21.  
  22.         //new (zero) initial guess
  23.         ublas::matrix<double> * new_U = new ublas::matrix<double>(new_size,new_size,0);
  24.  
  25.         //new residuals of correct size
  26.         ublas::matrix<double> * new_residuals = new ublas::matrix<double>(new_size,new_size,0);
  27.  
  28.         //go to coarser grid
  29.         Solve(*new_U,*new_residuals,restrictedResid);
  30.        
  31.         //prolong error afterwards
  32.         error = Prolong(*new_U);
  33.     } else {
  34.         error = ublas::matrix<double>(size,size,0.0);
  35.     }
  36.  
  37.     //correct
  38.     inout_u = inout_u + error;
  39.  
  40.     //relax again
  41.     RelaxError(m_nEndIterations,input_f,inout_u,output_r);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement