PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
Array_impl.hh
Go to the documentation of this file.
1 /* Copyright (C) 2020, 2021, 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 #ifndef PISM_ARRAY_IMPL_HH
20 #define PISM_ARRAY_IMPL_HH
21 
22 #include <map>
23 #include <memory>
24 #include <string>
25 #include <vector>
26 
27 #include "pism/util/array/Array.hh"
28 
29 #include <gsl/gsl_interp.h>
30 
31 #include "pism/util/petscwrappers/Vec.hh"
32 #include "pism/util/interpolation.hh"
33 #include "pism/util/VariableMetadata.hh"
34 
35 namespace pism {
36 namespace array {
37 
38 struct Array::Impl {
39  Impl() {
40  access_counter = 0;
41 
42  da.reset();
43 
44  da_stencil_width = 1;
45  dof = 1;
46  begin_access_use_dof = false;
47 
48  ghosted = true;
49 
50  report_range = true;
51 
52  name = "uninitialized variable";
53 
54  zlevels = {0.0};
55 
56  state_counter = 0;
58 
59  bsearch_accel = nullptr;
60  }
61  //! If true, report range when regridding.
63 
64  //! The array itself
65  //!
66  //! Note: do not access this directly (via `m_impl->v`). Use `vec()` instead.
68 
69  //! Name of the field. In general this is *not* the name of the corresponding NetCDF
70  //! variable.
71  std::string name;
72 
73  //! Metadata (NetCDF variable attributes)
74  std::vector<SpatialVariableMetadata> metadata;
75 
76  //! The computational grid
77  std::shared_ptr<const Grid> grid;
78 
79  //! number of "degrees of freedom" per grid point
80  unsigned int dof;
81 
82  //! stencil width supported by the DA
83  unsigned int da_stencil_width;
84 
85  //! true if this Array is ghosted
86  bool ghosted;
87 
88  //! distributed mesh manager (DM)
89  std::shared_ptr<petsc::DM> da;
90 
91  //! If true, use DMDAVecGetArrayDOF() in begin_access()
93 
94  //! Map plane viewers. It is a map because a temporary Array can be used to view
95  //! different quantities
96  std::map<std::string,std::shared_ptr<petsc::Viewer> > map_viewers;
97 
98  // used in begin_access() and end_access()
100 
101  //! Internal array::Array "revision number"
103 
104  // 2D Interpolation type (used by regrid())
106 
107  //! Vertical levels (for 3D fields)
108  std::vector<double> zlevels;
109 
110  // binary search accelerator (used for interpolation in a column in 3D fields)
111  gsl_interp_accel *bsearch_accel;
112 };
113 
114 void global_to_local(petsc::DM &dm, Vec source, Vec destination);
115 
116 // set default value or stop with an error message (during regridding)
117 void set_default_value_or_stop(const std::string &filename, const VariableMetadata &variable,
118  io::Default default_value, const Logger &log,
119  Vec output);
120 
121 } // end of namespace array
122 } // end of namespace pism
123 
124 #endif /* PISM_ARRAY_IMPL_HH */
A basic logging class.
Definition: Logger.hh:40
void set_default_value_or_stop(const std::string &filename, const VariableMetadata &variable, io::Default default_value, const Logger &log, Vec output)
Definition: Array.cc:387
void global_to_local(petsc::DM &dm, Vec source, Vec destination)
Definition: Array.cc:49
InterpolationType
bool begin_access_use_dof
If true, use DMDAVecGetArrayDOF() in begin_access()
Definition: Array_impl.hh:92
int state_counter
Internal array::Array "revision number".
Definition: Array_impl.hh:102
bool ghosted
true if this Array is ghosted
Definition: Array_impl.hh:86
std::shared_ptr< const Grid > grid
The computational grid.
Definition: Array_impl.hh:77
InterpolationType interpolation_type
Definition: Array_impl.hh:105
std::map< std::string, std::shared_ptr< petsc::Viewer > > map_viewers
Definition: Array_impl.hh:96
bool report_range
If true, report range when regridding.
Definition: Array_impl.hh:62
gsl_interp_accel * bsearch_accel
Definition: Array_impl.hh:111
unsigned int da_stencil_width
stencil width supported by the DA
Definition: Array_impl.hh:83
std::vector< SpatialVariableMetadata > metadata
Metadata (NetCDF variable attributes)
Definition: Array_impl.hh:74
std::vector< double > zlevels
Vertical levels (for 3D fields)
Definition: Array_impl.hh:108
std::shared_ptr< petsc::DM > da
distributed mesh manager (DM)
Definition: Array_impl.hh:89
unsigned int dof
number of "degrees of freedom" per grid point
Definition: Array_impl.hh:80