PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
Staggered.hh
Go to the documentation of this file.
1 /* Copyright (C) 2022, 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 #ifndef PISM_STAGGERED_H
21 #define PISM_STAGGERED_H
22 
23 #include "pism/util/array/Array3D.hh"
24 #include "pism/util/stencils.hh"
25 
26 namespace pism {
27 
28 namespace array {
29 class CellType1;
30 class Vector;
31 
32 //! @brief A class for storing and accessing internal staggered-grid 2D fields.
33 //! Uses dof=2 storage. This class is identical to array::Vector, except that
34 //! components are not called `u` and `v` (to avoid confusion).
35 class Staggered : public Array {
36 public:
37  Staggered(std::shared_ptr<const Grid> grid, const std::string &name);
38 
39  inline double& operator() (int i, int j, int k);
40  inline const double& operator() (int i, int j, int k) const;
41 
42  void copy_from(const array::Staggered &input);
43 protected:
44  Staggered(std::shared_ptr<const Grid> grid, const std::string &name,
45  unsigned int stencil_width);
46 };
47 
48 inline double& array::Staggered::operator() (int i, int j, int k) {
49 #if (Pism_DEBUG==1)
50  check_array_indices(i, j, k);
51 #endif
52  return static_cast<double***>(m_array)[j][i][k];
53 }
54 
55 inline const double& array::Staggered::operator() (int i, int j, int k) const {
56 #if (Pism_DEBUG==1)
57  check_array_indices(i, j, k);
58 #endif
59  return static_cast<double***>(m_array)[j][i][k];
60 }
61 
62 class Staggered1 : public Staggered {
63 public:
64  Staggered1(std::shared_ptr<const Grid> grid, const std::string &name);
65 
66  //! Returns the values at interfaces of the cell i,j using the staggered grid.
67  /*! The ij member of the return value is set to 0, since it has no meaning in
68  this context.
69  */
70  inline stencils::Star<double> star(int i, int j) const;
71 };
72 
73 inline stencils::Star<double> Staggered1::star(int i, int j) const {
74  const Staggered1 &self = *this;
75 
77 
78  result.c = 0.0; // has no meaning in this context
79  result.e = self(i, j, 0);
80  result.w = self(i-1, j, 0);
81  result.n = self(i, j, 1);
82  result.s = self(i, j-1, 1);
83 
84  return result;
85 }
86 
87 /*!
88  * Computes maximums of absolute values of both components.
89  */
90 std::array<double,2> absmax(const array::Staggered &input);
91 
92 /*!
93  * Average a scalar field from the staggered grid onto the regular grid by considering
94  * only ice-covered grid.
95  *
96  * If `include_floating_ice` is true, include floating ice, otherwise consider grounded
97  * icy cells only.
98  */
99 void staggered_to_regular(const array::CellType1 &cell_type,
100  const array::Staggered1 &input,
101  bool include_floating_ice,
102  array::Scalar &result);
103 
104 /*!
105  * Average a vector field from the staggered grid onto the regular grid by considering
106  * only ice-covered grid.
107  *
108  * If `include_floating_ice` is true, include floating ice, otherwise consider grounded
109  * icy cells only.
110  */
111 void staggered_to_regular(const array::CellType1 &cell_type,
112  const array::Staggered1 &input,
113  bool include_floating_ice,
114  array::Vector &result);
115 
116 } // end of namespace array
117 
118 } // end of namespace pism
119 
120 #endif /* PISM_STAGGERED_H */
std::shared_ptr< const Grid > grid() const
Definition: Array.cc:132
unsigned int stencil_width() const
Get the stencil width of the current Array. Returns 0 if ghosts are not available.
Definition: Array.cc:331
Abstract class for reading, writing, allocating, and accessing a DA-based PETSc Vec (2D and 3D fields...
Definition: Array.hh:208
Staggered1(std::shared_ptr< const Grid > grid, const std::string &name)
Definition: Staggered.cc:64
stencils::Star< double > star(int i, int j) const
Returns the values at interfaces of the cell i,j using the staggered grid.
Definition: Staggered.hh:73
double & operator()(int i, int j, int k)
Definition: Staggered.hh:48
void copy_from(const array::Staggered &input)
Definition: Staggered.cc:42
Staggered(std::shared_ptr< const Grid > grid, const std::string &name)
Definition: Staggered.cc:31
A class for storing and accessing internal staggered-grid 2D fields. Uses dof=2 storage....
Definition: Staggered.hh:35
void staggered_to_regular(const array::CellType1 &cell_type, const array::Staggered1 &input, bool include_floating_ice, array::Scalar &result)
Definition: Staggered.cc:87
double absmax(const array::Scalar &input)
Finds maximum over all the absolute values in an array::Scalar object. Ignores ghosts.
Definition: Scalar.cc:179
static const double k
Definition: exactTestP.cc:42
Star stencil points (in the map-plane).
Definition: stencils.hh:30