tVars.hh - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tVars.hh (3510B)
---
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