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