Ignore:
Timestamp:
Apr 10, 2012, 1:55:49 PM (14 years ago)
Author:
Julian Iseringhausen <isering@…>
Children:
a40eea
Parents:
d24c2f
Message:

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1666 5161e1c8-67bf-11de-9fd5-51895aff932f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/level/level_operator_cs.cpp

    rd24c2f rac6d04  
    2222using namespace VMG;
    2323
    24 void LevelOperatorCS::Restrict(Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)
     24void LevelOperatorCS::Restrict(Multigrid& sol, Multigrid& rhs)
    2525{
    26 #ifdef DEBUG_MATRIX_CHECKS
    27   sol_f.IsConsistent();
    28   rhs_f.IsConsistent();
    29 #endif
     26  Grid::iterator iter_f, iter_c;
    3027
    31 #ifdef DEBUG
    32   sol_f.IsCompatible(rhs_f);
    33 #endif
     28  Comm& comm = *MG::GetComm();
    3429
    35   Grid::iterator iter_f, iter_c;
    36   Stencil::iterator stencil_iter;
    37   vmg_float res;
     30  Grid& sol_f = sol(sol.Level());
     31  Grid& rhs_f = rhs(rhs.Level());
     32
     33  Grid& sol_c_dist = sol(sol.Level()-1);
     34  Grid& rhs_c_dist = rhs(rhs.Level()-1);
     35
     36  Grid& sol_c_undist = comm.GetCoarserGrid(sol);
     37  Grid& rhs_c_undist = comm.GetCoarserGrid(rhs);
    3838
    3939  const Stencil& op = OperatorRestrict();
    4040
    41   Index begin_f = rhs_f.Local().Begin() + 2*rhs_c.Global().BeginLocal() - rhs_f.Global().BeginLocal();
    42   Index end_f = rhs_f.Local().End();
     41  const Index begin_f_global = rhs_f.Global().LocalBegin() + rhs_f.Global().LocalBegin() % 2;
     42  const Index end_f_global = rhs_f.Global().LocalEnd() - (rhs_f.Global().LocalEnd() - 1) % 2;
     43
     44  assert(begin_f_global % 2 == 0);
     45  assert(end_f_global % 2 == 1);
     46
     47  Index begin_f = begin_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin();
     48  Index end_f = end_f_global - rhs_f.Global().LocalBegin() + rhs_f.Local().Begin();
    4349
    4450  /* Modify fine begin/end to align the points on both levels correctly */
    45   if (rhs_c.Global().BoundaryType() == GlobalCoarsened)
    46     for (int i=0; i<3; ++i) {
     51  if (rhs_c_undist.Global().BoundaryType() == GlobalCoarsened) {
     52    begin_f += rhs_f.Local().BoundarySize1();
     53    end_f -= rhs_f.Local().BoundarySize2();
     54  }
    4755
    48       if (rhs_c.Local().HasBoundary1()[i])
    49         ++begin_f[i];
    50 
    51       if (rhs_c.Local().HasBoundary2()[i])
    52         --end_f[i];
    53 
    54     }
     56  const Index begin_c = rhs_c_undist.Local().Begin() + begin_f_global / 2 - rhs_c_undist.Global().LocalBegin();
     57  const Index end_c = rhs_c_undist.Local().Begin() + end_f_global / 2 - rhs_c_undist.Global().LocalBegin() + 1;
    5558
    5659  const GridIteratorSet bounds_f(begin_f, end_f);
    57   const GridIteratorSet bounds_c(rhs_c.Local().AlignmentBegin(), rhs_c.Local().AlignmentEnd());
     60  const GridIteratorSet bounds_c(begin_c, end_c);
    5861
    5962  // Compute residual
     
    6164  temp->SetProperties(sol_f);
    6265  temp->ImportFromResidual(sol_f, rhs_f);
     66  comm.CommToGhosts(*temp);
    6367
    64   if (rhs_c.Global().BoundaryType() == GlobalCoarsened)
    65     rhs_c.ClearBoundary();
     68  for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_f!=bounds_f.End(); iter_f+=2, ++iter_c)
     69    rhs_c_undist(*iter_c) = op.Apply(*temp, *iter_f);
    6670
    67   for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
     71  comm.CommSubgrid(rhs_c_undist, rhs_c_dist, 1);
    6872
    69     res = op.GetDiag() * temp->GetVal(*iter_f);
     73  if (rhs_c_dist.Global().BoundaryType() == GlobalCoarsened)
     74    rhs_c_dist.ClearBoundary();
    7075
    71     for (stencil_iter=op.begin(); stencil_iter!=op.end(); ++stencil_iter)
    72       res += stencil_iter->Val() * temp->GetVal(iter_f->X() + stencil_iter->Disp().X(),
    73                                                 iter_f->Y() + stencil_iter->Disp().Y(),
    74                                                 iter_f->Z() + stencil_iter->Disp().Z());
    75 
    76     rhs_c(*iter_c) = res;
    77 
    78   }
    79 
    80 #ifdef DEBUG_MATRIX_CHECKS
    81   rhs_c.IsConsistent();
    82 #endif
     76  sol.ToCoarserLevel();
     77  rhs.ToCoarserLevel();
    8378}
    8479
    85 void LevelOperatorCS::Prolongate(Grid& sol_f, Grid& rhs_f, Grid& sol_c, Grid& rhs_c)
     80void LevelOperatorCS::Prolongate(Multigrid& sol, Multigrid& rhs)
    8681{
    87 #ifdef DEBUG_MATRIX_CHECKS
    88   sol_c.IsConsistent();
    89   rhs_c.IsConsistent();
    90   sol_f.IsConsistent();
    91   rhs_f.IsConsistent();
    92 #endif
    93 
    94 #ifdef DEBUG
    95   sol_c.IsCompatible(rhs_c);
    96   sol_f.IsCompatible(rhs_f);
    97 #endif
    98 
    9982  Grid::iterator iter_f, iter_c;
    10083  Stencil::iterator stencil_iter;
    10184  vmg_float val;
    10285
     86  Comm& comm = *MG::GetComm();
     87
     88  Grid& sol_c = sol(sol.Level());
     89  Grid& rhs_c = rhs(rhs.Level());
     90
     91  Grid& sol_f_dist = sol(sol.Level()+1);
     92  Grid& rhs_f_dist = rhs(rhs.Level()+1);
     93
     94  Grid& sol_f_undist = comm.GetFinerGrid(sol);
     95  Grid& rhs_f_undist = comm.GetFinerGrid(rhs);
     96
    10397  const Stencil& op = OperatorProlongate();
    104   Comm* comm = MG::GetComm();
    10598
    106   Index begin_f = sol_f.Local().Begin() + 2*sol_c.Global().BeginLocal() - sol_f.Global().BeginLocal();
    107   Index end_f = sol_f.Local().End();
     99  Index begin_f = sol_f_undist.Local().Begin() + 2*sol_c.Global().LocalBegin() - sol_f_undist.Global().LocalBegin();
     100  Index end_f = sol_f_undist.Local().End();
    108101
    109   if (sol_c.Global().BoundaryType() == GlobalCoarsened)
    110     for (int i=0; i<3; ++i) {
    111 
    112       if (rhs_f.Local().HasBoundary1()[i])
    113         ++begin_f[i];
    114 
    115       if (rhs_f.Local().HasBoundary2()[i])
    116         --end_f[i];
    117 
    118     }
     102  if (sol_c.Global().BoundaryType() == GlobalCoarsened) {
     103    begin_f += rhs_f_undist.Local().BoundarySize1();
     104    end_f -= rhs_f_undist.Local().BoundarySize2();
     105  }
    119106
    120107  const GridIteratorSet bounds_f(begin_f, end_f);
    121   const GridIteratorSet bounds_c(sol_c.Local().AlignmentBegin(), sol_c.Local().AlignmentEnd());
     108  const GridIteratorSet bounds_c(sol_c.Local().FinerBeginFoo(), sol_c.Local().FinerEndFoo());
    122109
    123   Index apply_stencil_begin, apply_stencil_end;
     110  sol_f_undist.ClearHalo();
    124111
    125   for (int i=0; i<3; ++i) {
    126     apply_stencil_begin[i] = (sol_f.Local().HasBoundary1()[i] ? 1 : 0);
    127     apply_stencil_end[i] = (sol_f.Local().HasBoundary2()[i] ? sol_f.Local().End()[i] : sol_f.Local().SizeTotal()[i]);
    128   }
    129 
    130   sol_f.ClearHalo();
     112  comm.CommSubgrid(sol_f_dist, sol_f_undist, 0);
    131113
    132114  for (iter_f=bounds_f.Begin(), iter_c=bounds_c.Begin(); iter_c!=bounds_c.End(); iter_f+=2, ++iter_c) {
    133115    val = sol_c.GetVal(*iter_c);
    134     sol_f(*iter_f) += op.GetDiag() * val;
     116    sol_f_undist(*iter_f) += op.GetDiag() * val;
    135117    for (stencil_iter = op.begin(); stencil_iter != op.end(); ++stencil_iter)
    136       sol_f(iter_f->X() + stencil_iter->Disp().X(),
    137             iter_f->Y() + stencil_iter->Disp().Y(),
    138             iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
     118      sol_f_undist(iter_f->X() + stencil_iter->Disp().X(),
     119                   iter_f->Y() + stencil_iter->Disp().Y(),
     120                   iter_f->Z() + stencil_iter->Disp().Z()) += stencil_iter->Val() * val;
    139121  }
    140122
    141   comm->CommFromGhosts(sol_f);
     123  comm.CommFromGhosts(sol_f_undist);
     124  comm.CommSubgrid(sol_f_undist, sol_f_dist, 1);
     125
     126  sol.ToFinerLevel();
     127  rhs.ToFinerLevel();
    142128}
Note: See TracChangeset for help on using the changeset viewer.