PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
Vars.hh
Go to the documentation of this file.
1 // Copyright (C) 2009, 2010, 2013, 2014, 2015, 2016, 2017, 2022 Constantine Khroulev
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 __Vars_hh
20 #define __Vars_hh
21 
22 #include <map>
23 #include <set>
24 #include <string>
25 #include <memory>
26 
27 namespace pism {
28 
29 
30 namespace array {
31 class Array3D;
32 class Array;
33 class CellType;
34 class Scalar;
35 class Vector;
36 } // end of namespace array
37 
38 //! \brief A class for passing PISM variables from the core to other parts of
39 //! the code (such as climate couplers).
40 class Vars {
41 public:
42  Vars();
43  void add(const array::Array &);
44  void add(const array::Array &, const std::string &name);
45  void remove(const std::string &name);
46  bool is_available(const std::string &name) const;
47 
48  const array::Array* get(const std::string &name) const;
49  const array::Scalar* get_2d_scalar(const std::string &name) const;
50  const array::Scalar* get_2d_mask(const std::string &name) const;
51  const array::Vector* get_2d_vector(const std::string &name) const;
52  const array::CellType* get_2d_cell_type(const std::string &name) const;
53  const array::Array3D* get_3d_scalar(const std::string &name) const;
54 
55  std::set<std::string> keys() const;
56 
57  typedef std::shared_ptr<array::Array> VecPtr;
58  typedef std::shared_ptr<array::Scalar> Vec2SPtr;
59  typedef std::shared_ptr<array::Scalar> Vec2IntPtr;
60  typedef std::shared_ptr<array::Vector> Vec2VPtr;
61  typedef std::shared_ptr<array::CellType> Vec2CellTypePtr;
62  typedef std::shared_ptr<array::Array3D> Vec3Ptr;
63 
64  void add_shared(VecPtr);
65  void add_shared(VecPtr, const std::string &name);
66 
67  bool is_available_shared(const std::string &name) const;
68 
69  VecPtr get_shared(const std::string &name) const;
70  Vec2SPtr get_2d_scalar_shared(const std::string &name) const;
71  Vec2VPtr get_2d_vector_shared(const std::string &name) const;
72  Vec2IntPtr get_2d_mask_shared(const std::string &name) const;
73  Vec2CellTypePtr get_2d_cell_type_shared(const std::string &name) const;
74  Vec3Ptr get_3d_scalar_shared(const std::string &name) const;
75 
76  std::set<std::string> keys_shared() const;
77 private:
78  const array::Array* get_internal(const std::string &name) const;
79  mutable std::map<std::string, const array::Array*> m_variables;
80  //! stores standard names of variables that
81  //! have standard names, allowing looking them
82  //! up using either short or standard names and
83  //! preserving the one-to-one map from keys
84  //! (strings) to pointers (represented by
85  //! "variables").
86  mutable std::map<std::string, std::string> m_standard_names;
87 
88  //! variables in *shared ownership*
89  mutable std::map<std::string, VecPtr> m_variables_shared;
90 
91  VecPtr get_internal_shared(const std::string &name) const;
92 
93  // Hide copy constructor / assignment operator.
94  Vars(Vars const &);
95  Vars & operator=(Vars const &);
96 };
97 
98 } // end of namespace pism
99 
100 #endif // __Vars_hh
Vec2IntPtr get_2d_mask_shared(const std::string &name) const
Definition: Vars.cc:299
const array::Array3D * get_3d_scalar(const std::string &name) const
Definition: Vars.cc:188
void add_shared(VecPtr)
Definition: Vars.cc:219
const array::Vector * get_2d_vector(const std::string &name) const
Definition: Vars.cc:163
std::shared_ptr< array::Array3D > Vec3Ptr
Definition: Vars.hh:62
std::set< std::string > keys_shared() const
Definition: Vars.cc:326
const array::Array * get_internal(const std::string &name) const
Definition: Vars.cc:130
Vec3Ptr get_3d_scalar_shared(const std::string &name) const
Definition: Vars.cc:317
std::set< std::string > keys() const
Returns the set of keys (variable names) in the dictionary.
Definition: Vars.cc:204
std::shared_ptr< array::Scalar > Vec2SPtr
Definition: Vars.hh:58
Vars(Vars const &)
std::shared_ptr< array::Vector > Vec2VPtr
Definition: Vars.hh:60
const array::CellType * get_2d_cell_type(const std::string &name) const
Definition: Vars.cc:179
VecPtr get_shared(const std::string &name) const
Definition: Vars.cc:272
std::map< std::string, VecPtr > m_variables_shared
variables in shared ownership
Definition: Vars.hh:89
Vars()
Definition: Vars.cc:31
Vec2CellTypePtr get_2d_cell_type_shared(const std::string &name) const
Definition: Vars.cc:307
bool is_available_shared(const std::string &name) const
Definition: Vars.cc:257
std::shared_ptr< array::Array > VecPtr
Definition: Vars.hh:57
const array::Scalar * get_2d_mask(const std::string &name) const
Definition: Vars.cc:171
const array::Scalar * get_2d_scalar(const std::string &name) const
Definition: Vars.cc:155
const array::Array * get(const std::string &name) const
Returns a pointer to an array::Array containing variable name or NULL if that variable was not found.
Definition: Vars.cc:122
void remove(const std::string &name)
Removes a variable with the key name from the dictionary.
Definition: Vars.cc:94
Vars & operator=(Vars const &)
std::shared_ptr< array::CellType > Vec2CellTypePtr
Definition: Vars.hh:61
bool is_available(const std::string &name) const
Definition: Vars.cc:34
VecPtr get_internal_shared(const std::string &name) const
Definition: Vars.cc:336
Vec2SPtr get_2d_scalar_shared(const std::string &name) const
Definition: Vars.cc:281
std::shared_ptr< array::Scalar > Vec2IntPtr
Definition: Vars.hh:59
std::map< std::string, const array::Array * > m_variables
Definition: Vars.hh:79
Vec2VPtr get_2d_vector_shared(const std::string &name) const
Definition: Vars.cc:290
void add(const array::Array &)
Add an array::Array to the dictionary.
Definition: Vars.cc:67
std::map< std::string, std::string > m_standard_names
Definition: Vars.hh:86
A class for passing PISM variables from the core to other parts of the code (such as climate couplers...
Definition: Vars.hh:40
A virtual class collecting methods common to ice and bedrock 3D fields.
Definition: Array3D.hh:33
Abstract class for reading, writing, allocating, and accessing a DA-based PETSc Vec (2D and 3D fields...
Definition: Array.hh:208
"Cell type" mask. Adds convenience methods to array::Scalar.
Definition: CellType.hh:30