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/grid/tempgrid.cpp

    rd24c2f rac6d04  
    2727  global = rhs.Global();
    2828  extent = rhs.Extent();
    29 
    3029  iterators.SetSubgrids(rhs.Local());
    31 
    3230  level = rhs.Level();
    33 
    3431  Allocate();
    3532}
     
    4037  global = global_;
    4138  extent = extent_;
    42 
    4339  iterators.SetSubgrids(local_);
    44 
    45   Allocate();
    46 }
    47 
    48 void TempGrid::SetPropertiesToGlobalCoarseGrid()
    49 {
    50   Interface* interface = MG::GetInterface();
    51 
    52   global = interface->Global().back();
    53   extent = interface->Extent().back();
     40  Allocate();
     41}
     42
     43void TempGrid::SetPropertiesToFiner(const Grid& grid, const Boundary& boundary)
     44{
     45  assert(grid.Father() != NULL);
     46  assert(grid.Level() < grid.Father()->MaxLevel());
     47
     48  const Grid& grid_finer = (*grid.Father())(grid.Level()+1);
     49  const Index off = GridIndexTranslations::EndOffset(boundary);
     50
     51  level = grid.Level() + 1;
     52
     53  global.GlobalFinerBegin() = 0;
     54  global.GlobalFinerEnd() = 0;
     55  global.GlobalFinerSize() = 0;
     56
     57  global.LocalFinerBegin() = 0;
     58  global.LocalFinerEnd() = 0;
     59  global.LocalFinerSize() = 0;
     60
     61  global.FinestAbsBegin() = grid_finer.Global().FinestAbsBegin();
     62  global.FinestAbsEnd() = grid_finer.Global().FinestAbsEnd();
     63  global.FinestAbsSize() = grid_finer.Global().FinestAbsSize();
     64
     65  global.GlobalSize() = 2 * (grid.Global().GlobalFinerSize() - off) + off;
     66  global.BoundaryType() = grid_finer.Global().BoundaryType();
     67
     68  global.LocalBegin() = 2 * grid.Global().LocalBegin().Clamp(grid.Global().GlobalFinerBegin(), grid.Global().GlobalFinerEnd());
     69  global.LocalEnd() = 2 * grid.Global().LocalEnd().Clamp(grid.Global().GlobalFinerBegin(), grid.Global().GlobalFinerEnd()) - off;
     70
     71  global.LocalSize() = global.LocalEnd() - global.LocalBegin();
     72  if (global.LocalSize().Product() == 0) {
     73    global.LocalBegin() = 0;
     74    global.LocalEnd() = 0;
     75    global.LocalSize() = 0;
     76    global.BoundaryType() = EmptyGrid;
     77  }
     78
     79  local.FinerBeginFoo() = 0;
     80  local.FinerEndFoo() = 0;
     81  local.FinerSizeFoo() = 0;
     82
     83  local.Begin() = 0;
     84  local.End() = global.LocalSize();
     85  local.Size() = global.LocalSize();
     86  local.SizeTotal() = global.LocalSize();
     87
     88  local.HaloBegin1() = 0;
     89  local.HaloEnd1() = 0;
     90  local.HaloBegin2() = 0;
     91  local.HaloEnd2() = 0;
     92
     93  local.BoundaryBegin1() = 0;
     94  local.BoundaryEnd1() = 0;
     95  local.BoundaryBegin2() = 0;
     96  local.BoundaryEnd2() = 0;
    5497
    5598  for (int i=0; i<3; ++i) {
    5699
    57     if (interface->BoundaryConditions()[i] == Dirichlet ||
    58         interface->BoundaryConditions()[i] == Open) {
    59 
    60       local.Size()[i] = global.SizeGlobal()[i] - 2;
    61       local.SizeTotal()[i] = global.SizeGlobal()[i];
    62       local.Begin()[i] = 1;
    63       local.End()[i] = local.SizeTotal()[i] - 1;
     100    if (grid.Local().HaloSize1()[i] > 0) {
     101      local.Begin()[i] += grid.Local().HaloSize1()[i];
     102      local.End()[i] += grid.Local().HaloSize1()[i];
     103      local.HaloEnd1()[i] = grid.Local().HaloSize1()[i];
     104    }
     105
     106    if (grid.Local().BoundarySize1()[i] > 0) {
     107      local.Begin()[i] += grid.Local().BoundarySize1()[i];
     108      local.BoundaryEnd1()[i] = grid.Local().BoundarySize1()[i];
     109    }
     110
     111    if (grid.Local().HaloSize2()[i] > 0) {
     112      local.HaloBegin2()[i] = local.End()[i];
     113      local.HaloEnd2()[i] = local.End()[i] + grid.Local().HaloSize2()[i];
     114    }
     115
     116    if (grid.Local().BoundarySize2()[i] > 0) {
     117      local.End()[i] -= grid.Local().BoundarySize2()[i];
     118      local.BoundaryBegin2()[i] = local.End()[i];
     119      local.BoundaryEnd2()[i] = local.End()[i]+grid.Local().BoundarySize2()[i];
     120    }
     121
     122  }
     123
     124  local.HaloSize1() = local.HaloEnd1() - local.HaloBegin1();
     125  local.HaloSize2() = local.HaloEnd2() - local.HaloBegin2();
     126  local.BoundarySize1() = local.BoundaryEnd1() - local.BoundaryBegin1();
     127  local.BoundarySize2() = local.BoundaryEnd2() - local.BoundaryBegin2();
     128  local.Size() = local.End() - local.Begin();
     129  local.SizeTotal() = local.Size() +
     130    local.HaloSize1() + local.HaloSize2() +
     131    local.BoundarySize1() + local.BoundarySize2();
     132
     133  extent.Size() = grid.Extent().Size();
     134  extent.Begin() = grid.Extent().Begin();
     135  extent.End() = grid.Extent().End();
     136  extent.MeshWidth() = 0.5 * grid.Extent().MeshWidth();
     137
     138  iterators.SetSubgrids(local);
     139
     140  Allocate();
     141}
     142
     143void TempGrid::SetPropertiesToCoarser(const Grid& grid, const Boundary& boundary)
     144{
     145  assert(grid.Father() != NULL);
     146  assert(grid.Level() > grid.Father()->MinLevel());
     147
     148  const Grid& grid_coarser = (*grid.Father())(grid.Level()-1);
     149  const Index off = GridIndexTranslations::EndOffset(boundary);
     150
     151  level = grid.Level() - 1;
     152
     153  global.GlobalFinerBegin() = grid_coarser.Global().GlobalFinerBegin();
     154  global.GlobalFinerEnd() = grid_coarser.Global().GlobalFinerEnd();
     155  global.GlobalFinerSize() = grid_coarser.Global().GlobalFinerSize();
     156
     157  global.FinestAbsBegin() = grid.Global().FinestAbsBegin();
     158  global.FinestAbsEnd() = grid.Global().FinestAbsEnd();
     159  global.FinestAbsSize() = grid.Global().FinestAbsSize();
     160
     161  global.GlobalSize() = (grid.Global().GlobalSize() - off)/2 + off;
     162  global.BoundaryType() = grid_coarser.Global().BoundaryType();
     163
     164  global.LocalBegin() = grid.Global().LocalBegin();
     165  global.LocalEnd() = grid.Global().LocalEnd();
     166  GridIndexTranslations::FineToCoarse(global.LocalBegin(), global.LocalEnd());
     167
     168  global.LocalBegin() += grid_coarser.Global().GlobalFinerBegin();
     169  global.LocalEnd() += grid_coarser.Global().GlobalFinerBegin();
     170
     171  global.LocalSize() = global.LocalEnd() - global.LocalBegin();
     172
     173  if (global.LocalSize().Product() == 0) {
     174    global.LocalBegin() = 0;
     175    global.LocalEnd() = 0;
     176    global.LocalSize() = 0;
     177    global.BoundaryType() = EmptyGrid;
     178  }
     179
     180  global.LocalFinerBegin() = global.LocalBegin();
     181  global.LocalFinerEnd() = global.LocalEnd();
     182  global.LocalFinerSize() = global.LocalSize();
     183
     184  local.SizeTotal() = global.LocalSize();
     185  local.Size() = global.LocalSize();
     186  local.Begin() = 0;
     187  local.End() = global.LocalSize();
     188
     189  for (int i=0; i<3; ++i) {
     190
     191    if (grid.Local().HaloSize1()[i] > 0) {
     192      local.SizeTotal()[i] += grid.Local().HaloSize1()[i];
     193      local.Begin()[i] += grid.Local().HaloSize1()[i];
     194      local.End()[i] += grid.Local().HaloSize1()[i];
     195      local.HaloBegin1()[i] = 0;
     196      local.HaloEnd1()[i] = grid.Local().HaloSize1()[i];
     197    }else {
    64198      local.HaloBegin1()[i] = 0;
    65199      local.HaloEnd1()[i] = 0;
     200    }
     201
     202    if (grid.Local().BoundarySize1()[i]> 0) {
     203      local.Size()[i] -= grid.Local().BoundarySize1()[i];
     204      local.Begin()[i] += grid.Local().BoundarySize1()[i];
     205      local.BoundaryBegin1()[i] = 0;
     206      local.BoundaryEnd1()[i] = grid.Local().BoundarySize1()[i];
     207    }else {
     208      local.BoundaryBegin1()[i] = 0;
     209      local.BoundaryEnd1()[i] = 0;
     210    }
     211
     212    if (grid.Local().HaloSize2()[i] > 0) {
     213      local.SizeTotal()[i] += grid.Local().HaloSize2()[i];
     214      local.HaloBegin2()[i] = local.End()[i];
     215      local.HaloEnd2()[i] = local.End()[i] + grid.Local().HaloSize2()[i];
     216    }else {
    66217      local.HaloBegin2()[i] = 0;
    67218      local.HaloEnd2()[i] = 0;
    68       local.BoundaryBegin1()[i] = 0;
    69       local.BoundaryEnd1()[i] = 1;
    70       local.BoundaryBegin2()[i] = local.SizeTotal()[i] - 1;
    71       local.BoundaryEnd2()[i] = local.SizeTotal()[i];
    72 
    73     }else if (interface->BoundaryConditions()[i] == Periodic) {
    74 
    75       local.Size()[i] = global.SizeGlobal()[i];
    76       local.SizeTotal()[i] = global.SizeGlobal()[i];
    77       local.Begin()[i] = 0;
    78       local.End()[i] = global.SizeGlobal()[i];
    79       local.HaloBegin1()[i] = 0;
    80       local.HaloEnd1()[i] = 0;
    81       local.HaloBegin2()[i] = 0;
    82       local.HaloEnd2()[i] = 0;
    83       local.BoundaryBegin1()[i] = 0;
    84       local.BoundaryEnd1()[i] = 0;
     219    }
     220
     221    if (grid.Local().BoundarySize2()[i] > 0) {
     222      local.Size()[i] -= grid.Local().BoundarySize2()[i];
     223      local.End()[i] -= grid.Local().BoundarySize2()[i];
     224      local.BoundaryBegin2()[i] = local.End()[i];
     225      local.BoundaryEnd2()[i] = local.End()[i] + grid.Local().BoundarySize2()[i];
     226    }else {
    85227      local.BoundaryBegin2()[i] = 0;
    86228      local.BoundaryEnd2()[i] = 0;
    87 
    88     }
    89 
    90   }
    91 
    92   level = interface->MinLevel();
     229    }
     230
     231  }
     232
     233  local.HaloSize1() = local.HaloEnd1() - local.HaloBegin1();
     234  local.HaloSize2() = local.HaloEnd2() - local.HaloBegin2();
     235  local.BoundarySize1() = local.BoundaryEnd1() - local.BoundaryBegin1();
     236  local.BoundarySize2() = local.BoundaryEnd2() - local.BoundaryBegin2();
     237
     238  local.FinerBeginFoo() = local.Begin();
     239  local.FinerEndFoo() = local.End();
     240  local.FinerSizeFoo() = local.Size();
     241
     242  Extent().Size() = grid.Extent().Size();
     243  Extent().Begin() = grid.Extent().Begin();
     244  Extent().End() = grid.Extent().End();
     245  Extent().MeshWidth() = 2.0 * grid.Extent().MeshWidth();
    93246
    94247  iterators.SetSubgrids(local);
    95 
    96   Allocate();
    97 }
    98 
    99 void TempGrid::SetPropertiesToFiner(const Grid& grid, const Boundary& boundary)
    100 {
    101   assert(grid.Father() != NULL);
    102   assert(grid.Level() < grid.Father()->MaxLevel());
    103 
    104   const Index off = GridIndexTranslations::EndOffset(boundary);
    105 
    106   this->Global().BeginFinest() = grid.Global().BeginFinest();
    107   this->Global().EndFinest() = grid.Global().EndFinest();
    108   this->Global().SizeFinest() = grid.Global().SizeFinest();
    109   this->Global().SizeGlobal() = 2 * (grid.Global().SizeGlobal()-off) + off;
    110   this->Global().BeginLocal() = grid.Global().BeginLocal();
    111   this->Global().EndLocal() = grid.Global().EndLocal();
    112 
    113   GridIndexTranslations::CoarseToFine(this->Global().BeginLocal(), this->Global().EndLocal(), this->Global().SizeGlobal());
    114 
    115   this->Global().SizeLocal() = this->Global().EndLocal() - this->Global().BeginLocal();
    116   this->Global().BoundaryType() = (*(grid.Father()))(grid.Level()+1).Global().BoundaryType();
    117 
    118   this->Local().Size() = this->Global().SizeLocal();
    119   this->Local().SizeTotal() = this->Global().SizeLocal();
    120   this->Local().Begin() = 0;
    121   this->Local().End() = this->Global().SizeLocal();
    122 
    123   for (int i=0; i<3; ++i) {
    124 
    125     if (grid.Local().HaloEnd1()[i] - grid.Local().HaloBegin1()[i] > 0) {
    126       this->Local().SizeTotal()[i] += 1;
    127       this->Local().Begin()[i] += 1;
    128       this->Local().End()[i] += 1;
    129       this->Local().HaloBegin1()[i] = 0;
    130       this->Local().HaloEnd1()[i] = 1;
    131     }else {
    132       this->Local().HaloBegin1()[i] = 0;
    133       this->Local().HaloEnd1()[i] = 0;
    134     }
    135 
    136     if (grid.Local().BoundaryEnd1()[i] - grid.Local().BoundaryBegin1()[i] > 0) {
    137       this->Local().Size()[i] -= 1;
    138       this->Local().Begin()[i] += 1;
    139       this->Local().BoundaryBegin1()[i] = 0;
    140       this->Local().BoundaryEnd1()[i] = 1;
    141     }else {
    142       this->Local().BoundaryBegin1()[i] = 0;
    143       this->Local().BoundaryEnd1()[i] = 0;
    144     }
    145 
    146     if (grid.Local().HaloEnd2()[i] - grid.Local().HaloBegin2()[i] > 0) {
    147       this->Local().SizeTotal()[i] += 1;
    148       this->Local().HaloBegin2()[i] = this->Local().End()[i];
    149       this->Local().HaloEnd2()[i] = this->Local().End()[i] + 1;
    150     }else {
    151       this->Local().HaloBegin2()[i] = 0;
    152       this->Local().HaloEnd2()[i] = 0;
    153     }
    154 
    155     if (grid.Local().BoundaryEnd2()[i] - grid.Local().BoundaryBegin2()[i] > 0) {
    156       this->Local().Size()[i] -= 1;
    157       this->Local().End()[i] -= 1;
    158       this->Local().BoundaryBegin2()[i] = this->Local().End()[i];
    159       this->Local().BoundaryEnd2()[i] = this->Local().End()[i]+1;
    160     }else {
    161       this->Local().BoundaryBegin2()[i] = 0;
    162       this->Local().BoundaryEnd2()[i] = 0;
    163     }
    164 
    165   }
    166 
    167   this->Local().AlignmentBegin() = this->Local().Begin();
    168   this->Local().AlignmentEnd() = this->local.End();
    169 
    170   this->Extent().Size() = grid.Extent().Size();
    171   this->Extent().SizeFactor() = grid.Extent().SizeFactor();
    172   this->Extent().Begin() = grid.Extent().Begin();
    173   this->Extent().End() = grid.Extent().End();
    174   this->Extent().MeshWidth() = 0.5 * grid.Extent().MeshWidth();
    175 
    176   this->level = grid.Level() + 1;
    177 
    178   iterators.SetSubgrids(local);
    179 
    180   Allocate();
    181 }
    182 
    183 void TempGrid::SetPropertiesToCoarser(const Grid& grid, const Boundary& boundary)
    184 {
    185   assert(grid.Father() != NULL);
    186   assert(grid.Level() > grid.Father()->MinLevel());
    187 
    188   const Index off = GridIndexTranslations::EndOffset(boundary);
    189 
    190   this->level = grid.Level() - 1;
    191 
    192   this->Global().BeginFinest() = grid.Global().BeginFinest();
    193   this->Global().EndFinest() = grid.Global().EndFinest();
    194   this->Global().SizeFinest() = grid.Global().SizeFinest();
    195 
    196   this->Global().BeginLocal() = grid.Global().BeginLocal();
    197   this->Global().EndLocal() = grid.Global().EndLocal();
    198 
    199   GridIndexTranslations::FineToCoarse(this->Global().BeginLocal(), this->Global().EndLocal());
    200 
    201   this->Global().SizeLocal() = this->Global().EndLocal() - this->Global().BeginLocal();
    202   this->Global().SizeGlobal() = (grid.Global().SizeGlobal()-off)/2 + off;
    203   this->Global().BoundaryType() = (*(grid.Father()))(grid.Level()-1).Global().BoundaryType();
    204 
    205   this->Local().SizeTotal() = this->Global().SizeLocal();
    206   this->Local().Size() = this->Global().SizeLocal();
    207   this->Local().Begin() = 0;
    208   this->Local().End() = this->Global().SizeLocal();
    209 
    210   for (int i=0; i<3; ++i) {
    211 
    212     if (grid.Local().HaloEnd1()[i] - grid.Local().HaloBegin1()[i] > 0) {
    213       this->Local().SizeTotal()[i] += 1;
    214       this->Local().Begin()[i] += 1;
    215       this->Local().End()[i] += 1;
    216       this->Local().HaloBegin1()[i] = 0;
    217       this->Local().HaloEnd1()[i] = 1;
    218     }else {
    219       this->Local().HaloBegin1()[i] = 0;
    220       this->Local().HaloEnd1()[i] = 0;
    221     }
    222 
    223     if (grid.Local().BoundaryEnd1()[i] - grid.Local().BoundaryBegin1()[i] > 0) {
    224       this->Local().Size()[i] -= 1;
    225       this->Local().Begin()[i] += 1;
    226       this->Local().BoundaryBegin1()[i] = 0;
    227       this->Local().BoundaryEnd1()[i] = 1;
    228     }else {
    229       this->Local().BoundaryBegin1()[i] = 0;
    230       this->Local().BoundaryEnd1()[i] = 0;
    231     }
    232 
    233     if (grid.Local().HaloEnd2()[i] - grid.Local().HaloBegin2()[i] > 0) {
    234       this->Local().SizeTotal()[i] += 1;
    235       this->Local().HaloBegin2()[i] = this->Local().End()[i];
    236       this->Local().HaloEnd2()[i] = this->Local().End()[i] + 1;
    237     }else {
    238       this->Local().HaloBegin2()[i] = 0;
    239       this->Local().HaloEnd2()[i] = 0;
    240     }
    241 
    242     if (grid.Local().BoundaryEnd2()[i] - grid.Local().BoundaryBegin2()[i] > 0) {
    243       this->Local().Size()[i] -= 1;
    244       this->Local().End()[i] -= 1;
    245       this->Local().BoundaryBegin2()[i] = this->Local().End()[i];
    246       this->Local().BoundaryEnd2()[i] = this->Local().End()[i]+1;
    247     }else {
    248       this->Local().BoundaryBegin2()[i] = 0;
    249       this->Local().BoundaryEnd2()[i] = 0;
    250     }
    251 
    252   }
    253 
    254   this->Local().AlignmentBegin() = this->Local().Begin();
    255   this->Local().AlignmentEnd() = this->local.End();
    256 
    257   this->Extent().Size() = grid.Extent().Size();
    258   this->Extent().SizeFactor() = grid.Extent().SizeFactor();
    259   this->Extent().Begin() = grid.Extent().Begin();
    260   this->Extent().End() = grid.Extent().End();
    261   this->Extent().MeshWidth() = 2.0 * grid.Extent().MeshWidth();
    262 
    263   iterators.SetSubgrids(local);
    264 
    265248  Allocate();
    266249}
     
    268251void TempGrid::ImportFromResidual(Grid& sol, Grid& rhs)
    269252{
    270 #ifdef DEBUG
    271   this->IsCompatible(sol);
    272   this->IsCompatible(rhs);
    273 #endif
    274 
    275   Grid::iterator grid_iter;
    276   Stencil::iterator stencil_iter;
    277   vmg_float residual;
    278   Index i;
     253  Grid::iterator iter;
    279254
    280255  const vmg_float prefactor = MG::GetDiscretization()->OperatorPrefactor(sol);
     
    285260  MG::GetComm()->CommToGhosts(sol);
    286261
    287   for (grid_iter=Iterators().Local().Begin(); grid_iter!=Iterators().Local().End(); ++grid_iter) {
    288     residual = rhs.GetVal(*grid_iter) - prefactor * A.GetDiag() * sol.GetVal(*grid_iter);
    289     for (stencil_iter=A.begin(); stencil_iter!=A.end(); ++stencil_iter)
    290       residual -= prefactor * stencil_iter->Val() * sol.GetVal(grid_iter->X() + stencil_iter->Disp().X(),
    291                                                                grid_iter->Y() + stencil_iter->Disp().Y(),
    292                                                                grid_iter->Z() + stencil_iter->Disp().Z());
    293     (*this)(*grid_iter) = residual;
    294   }
    295 
    296   MG::GetComm()->CommToGhosts(*this);
     262  for (iter=Iterators().Local().Begin(); iter!=Iterators().Local().End(); ++iter)
     263    (*this)(*iter) = rhs.GetVal(*iter) - prefactor * A.Apply(sol, *iter);
    297264}
    298265
Note: See TracChangeset for help on using the changeset viewer.