PISM, A Parallel Ice Sheet Model  stable v2.0.6 committed by Constantine Khrulev on 2023-01-23 15:14:38 -0900
Vars.hh
Go to the documentation of this file.
1 // Copyright (C) 2009, 2010, 2013, 2014, 2015, 2016, 2017 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 class IceModelVec;
30 class IceModelVec2S;
31 class IceModelVec2V;
32 class IceModelVec2Int;
33 class IceModelVec2CellType;
34 class IceModelVec3;
35 
36 //! \brief A class for passing PISM variables from the core to other parts of
37 //! the code (such as climate couplers).
38 class Vars {
39 public:
40  Vars();
41  void add(const IceModelVec &);
42  void add(const IceModelVec &, const std::string &name);
43  void remove(const std::string &name);
44  bool is_available(const std::string &name) const;
45 
46  const IceModelVec* get(const std::string &name) const;
47  const IceModelVec2S* get_2d_scalar(const std::string &name) const;
48  const IceModelVec2V* get_2d_vector(const std::string &name) const;
49  const IceModelVec2Int* get_2d_mask(const std::string &name) const;
50  const IceModelVec2CellType* get_2d_cell_type(const std::string &name) const;
51  const IceModelVec3* get_3d_scalar(const std::string &name) const;
52 
53  std::set<std::string> keys() const;
54 
55  typedef std::shared_ptr<IceModelVec> VecPtr;
56  typedef std::shared_ptr<IceModelVec2S> Vec2SPtr;
57  typedef std::shared_ptr<IceModelVec2V> Vec2VPtr;
58  typedef std::shared_ptr<IceModelVec2Int> Vec2IntPtr;
59  typedef std::shared_ptr<IceModelVec2CellType> Vec2CellTypePtr;
60  typedef std::shared_ptr<IceModelVec3> Vec3Ptr;
61 
62  void add_shared(VecPtr);
63  void add_shared(VecPtr, const std::string &name);
64 
65  bool is_available_shared(const std::string &name) const;
66 
67  VecPtr get_shared(const std::string &name) const;
68  Vec2SPtr get_2d_scalar_shared(const std::string &name) const;
69  Vec2VPtr get_2d_vector_shared(const std::string &name) const;
70  Vec2IntPtr get_2d_mask_shared(const std::string &name) const;
71  Vec2CellTypePtr get_2d_cell_type_shared(const std::string &name) const;
72  Vec3Ptr get_3d_scalar_shared(const std::string &name) const;
73 
74  std::set<std::string> keys_shared() const;
75 private:
76  const IceModelVec* get_internal(const std::string &name) const;
77  mutable std::map<std::string, const IceModelVec*> m_variables;
78  //! stores standard names of variables that
79  //! have standard names, allowing looking them
80  //! up using either short or standard names and
81  //! preserving the one-to-one map from keys
82  //! (strings) to pointers (represented by
83  //! "variables").
84  mutable std::map<std::string, std::string> m_standard_names;
85 
86  //! variables in *shared ownership*
87  mutable std::map<std::string, VecPtr> m_variables_shared;
88 
89  VecPtr get_internal_shared(const std::string &name) const;
90 
91  // Hide copy constructor / assignment operator.
92  Vars(Vars const &);
93  Vars & operator=(Vars const &);
94 };
95 
96 } // end of namespace pism
97 
98 #endif // __Vars_hh
"Cell type" mask. Adds convenience methods to IceModelVec2Int.
A simple class "hiding" the fact that the mask is stored as floating-point scalars (instead of intege...
Definition: iceModelVec.hh:389
A virtual class collecting methods common to ice and bedrock 3D fields.
Definition: iceModelVec.hh:404
Abstract class for reading, writing, allocating, and accessing a DA-based PETSc Vec (2D and 3D fields...
Definition: iceModelVec.hh:202
void add_shared(VecPtr)
Definition: Vars.cc:218
const IceModelVec3 * get_3d_scalar(const std::string &name) const
Definition: Vars.cc:187
std::shared_ptr< IceModelVec2V > Vec2VPtr
Definition: Vars.hh:57
VecPtr get_shared(const std::string &name) const
Definition: Vars.cc:271
std::set< std::string > keys_shared() const
Definition: Vars.cc:324
std::shared_ptr< IceModelVec > VecPtr
Definition: Vars.hh:55
const IceModelVec2CellType * get_2d_cell_type(const std::string &name) const
Definition: Vars.cc:179
void add(const IceModelVec &)
Add an IceModelVec to the dictionary.
Definition: Vars.cc:67
std::set< std::string > keys() const
Returns the set of keys (variable names) in the dictionary.
Definition: Vars.cc:203
std::map< std::string, const IceModelVec * > m_variables
Definition: Vars.hh:77
Vars(Vars const &)
std::shared_ptr< IceModelVec2Int > Vec2IntPtr
Definition: Vars.hh:58
const IceModelVec * get(const std::string &name) const
Returns a pointer to an IceModelVec containing variable name or NULL if that variable was not found.
Definition: Vars.cc:122
std::map< std::string, VecPtr > m_variables_shared
variables in shared ownership
Definition: Vars.hh:87
Vars()
Definition: Vars.cc:31
Vec2VPtr get_2d_vector_shared(const std::string &name) const
Definition: Vars.cc:289
VecPtr get_internal_shared(const std::string &name) const
Definition: Vars.cc:334
Vec2IntPtr get_2d_mask_shared(const std::string &name) const
Definition: Vars.cc:298
bool is_available_shared(const std::string &name) const
Definition: Vars.cc:256
Vec3Ptr get_3d_scalar_shared(const std::string &name) const
Definition: Vars.cc:315
std::shared_ptr< IceModelVec2S > Vec2SPtr
Definition: Vars.hh:56
std::shared_ptr< IceModelVec3 > Vec3Ptr
Definition: Vars.hh:60
void remove(const std::string &name)
Removes a variable with the key name from the dictionary.
Definition: Vars.cc:94
const IceModelVec2S * get_2d_scalar(const std::string &name) const
Definition: Vars.cc:155
const IceModelVec2V * get_2d_vector(const std::string &name) const
Definition: Vars.cc:163
Vars & operator=(Vars const &)
std::shared_ptr< IceModelVec2CellType > Vec2CellTypePtr
Definition: Vars.hh:59
bool is_available(const std::string &name) const
Definition: Vars.cc:34
const IceModelVec2Int * get_2d_mask(const std::string &name) const
Definition: Vars.cc:171
Vec2CellTypePtr get_2d_cell_type_shared(const std::string &name) const
Definition: Vars.cc:306
Vec2SPtr get_2d_scalar_shared(const std::string &name) const
Definition: Vars.cc:280
const IceModelVec * get_internal(const std::string &name) const
Definition: Vars.cc:130
std::map< std::string, std::string > m_standard_names
Definition: Vars.hh:84
A class for passing PISM variables from the core to other parts of the code (such as climate couplers...
Definition: Vars.hh:38