PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
ElementIterator.cc
Go to the documentation of this file.
1 /* Copyright (C) 2020, 2023 PISM Authors
2  *
3  * This file is part of PISM.
4  *
5  * PISM is free software; you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation; either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with PISM; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include "pism/util/fem/ElementIterator.hh"
21 
22 #include "pism/util/Grid.hh"
23 
24 namespace pism {
25 namespace fem {
26 
28  // Start by assuming ghost elements exist in all directions.
29  // Elements are indexed by their lower left vertex. If there is a ghost
30  // element on the right, its i-index will be the same as the maximum
31  // i-index of a non-ghost vertex in the local grid.
32  xs = grid.xs() - 1; // Start at ghost to the left.
33  int xf = grid.xs() + grid.xm() - 1; // End at ghost to the right.
34  ys = grid.ys() - 1; // Start at ghost at the bottom.
35  int yf = grid.ys() + grid.ym() - 1; // End at ghost at the top.
36 
37  lxs = grid.xs();
38  int lxf = lxs + grid.xm() - 1;
39  lys = grid.ys();
40  int lyf = lys + grid.ym() - 1;
41 
42  // Now correct if needed. The only way there will not be ghosts is if the
43  // grid is not periodic and we are up against the grid boundary.
44 
45  if (!(grid.periodicity() & grid::X_PERIODIC)) {
46  // Leftmost element has x-index 0.
47  if (xs < 0) {
48  xs = 0;
49  }
50  // Rightmost vertex has index grid.Mx-1, so the rightmost element has index grid.Mx-2
51  if (xf > (int)grid.Mx() - 2) {
52  xf = grid.Mx() - 2;
53  lxf = grid.Mx() - 2;
54  }
55  }
56 
57  if (!(grid.periodicity() & grid::Y_PERIODIC)) {
58  // Bottom element has y-index 0.
59  if (ys < 0) {
60  ys = 0;
61  }
62  // Topmost vertex has index grid.My - 1, so the topmost element has index grid.My - 2
63  if (yf > (int)grid.My() - 2) {
64  yf = grid.My() - 2;
65  lyf = grid.My() - 2;
66  }
67  }
68 
69  // Tally up the number of elements in each direction
70  xm = xf - xs + 1;
71  ym = yf - ys + 1;
72  lxm = lxf - lxs + 1;
73  lym = lyf - lys + 1;
74 }
75 
76 } // end of namespace fem
77 } // end of namespace pism
int ys() const
Global starting index of this processor's subset.
Definition: Grid.cc:736
grid::Periodicity periodicity() const
Return grid periodicity.
Definition: Grid.cc:674
unsigned int My() const
Total grid size in the Y direction.
Definition: Grid.cc:756
unsigned int Mx() const
Total grid size in the X direction.
Definition: Grid.cc:751
int xs() const
Global starting index of this processor's subset.
Definition: Grid.cc:731
int xm() const
Width of this processor's sub-domain.
Definition: Grid.cc:741
int ym() const
Width of this processor's sub-domain.
Definition: Grid.cc:746
Describes the PISM grid and the distribution of data across processors.
Definition: Grid.hh:282
int xm
total number of elements to loop over in the x-direction.
int lym
total number local elements in y direction.
int lxm
total number local elements in x direction.
int lxs
x-index of the first local element.
int ym
total number of elements to loop over in the y-direction.
int ys
y-coordinate of the first element to loop over.
int lys
y-index of the first local element.
int xs
x-coordinate of the first element to loop over.
@ Y_PERIODIC
Definition: Grid.hh:51
@ X_PERIODIC
Definition: Grid.hh:51