Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vars.hh
Go to the documentation of this file.
1// Copyright (C) 2009--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#ifndef PISM_VARS_H
20#define PISM_VARS_H
21
22#include <map>
23#include <set>
24#include <string>
25#include <memory>
26
27namespace pism {
28
29
30namespace array {
31class Array3D;
32class Array;
33class CellType;
34class Scalar;
35class Scalar1;
36class Scalar2;
37class Vector;
38} // end of namespace array
39
40//! \brief A class for passing PISM variables from the core to other parts of
41//! the code (such as climate couplers).
42class Vars {
43public:
44 Vars();
45 void add(const array::Array &);
46 void add(const array::Array &, const std::string &name);
47 void remove(const std::string &name);
48 bool is_available(const std::string &name) const;
49
50 const array::Array* get(const std::string &name) const;
51 const array::Scalar* get_2d_scalar(const std::string &name) const;
52 const array::Scalar1* get_2d_scalar1(const std::string &name) const;
53 const array::Scalar2* get_2d_scalar2(const std::string &name) const;
54 const array::Vector* get_2d_vector(const std::string &name) const;
55 const array::CellType* get_2d_cell_type(const std::string &name) const;
56 const array::Array3D* get_3d_scalar(const std::string &name) const;
57
58 std::set<std::string> keys() const;
59
60 void add_shared(std::shared_ptr<array::Array>);
61 void add_shared(std::shared_ptr<array::Array>, const std::string &name);
62
63 bool is_available_shared(const std::string &name) const;
64
65 std::shared_ptr<array::Array> get_shared(const std::string &name) const;
66 std::shared_ptr<array::Scalar> get_2d_scalar_shared(const std::string &name) const;
67 std::shared_ptr<array::Scalar1> get_2d_scalar1_shared(const std::string &name) const;
68 std::shared_ptr<array::Scalar2> get_2d_scalar2_shared(const std::string &name) const;
69 std::shared_ptr<array::Vector> get_2d_vector_shared(const std::string &name) const;
70 std::shared_ptr<array::CellType> get_2d_cell_type_shared(const std::string &name) const;
71 std::shared_ptr<array::Array3D> get_3d_scalar_shared(const std::string &name) const;
72
73 std::set<std::string> keys_shared() const;
74private:
75 const array::Array* get_internal(const std::string &name) const;
76 mutable std::map<std::string, const array::Array*> m_variables;
77 //! stores standard names of variables that
78 //! have standard names, allowing looking them
79 //! up using either short or standard names and
80 //! preserving the one-to-one map from keys
81 //! (strings) to pointers (represented by
82 //! "variables").
83 mutable std::map<std::string, std::string> m_standard_names;
84
85 //! variables in *shared ownership*
86 mutable std::map<std::string, std::shared_ptr<array::Array>> m_variables_shared;
87
88 std::shared_ptr<array::Array> get_internal_shared(const std::string &name) const;
89
90 // Hide copy constructor / assignment operator.
91 Vars(Vars const &);
92 Vars & operator=(Vars const &);
93};
94
95} // end of namespace pism
96
97#endif // PISM_VARS_H
std::map< std::string, std::shared_ptr< array::Array > > m_variables_shared
variables in shared ownership
Definition Vars.hh:86
const array::Array3D * get_3d_scalar(const std::string &name) const
Definition Vars.cc:188
const array::Vector * get_2d_vector(const std::string &name) const
Definition Vars.cc:180
const array::Scalar2 * get_2d_scalar2(const std::string &name) const
Definition Vars.cc:176
std::set< std::string > keys_shared() const
Definition Vars.cc:313
const array::Array * get_internal(const std::string &name) const
Definition Vars.cc:131
std::shared_ptr< array::Array3D > get_3d_scalar_shared(const std::string &name) const
Definition Vars.cc:309
std::set< std::string > keys() const
Returns the set of keys (variable names) in the dictionary.
Definition Vars.cc:200
const array::Scalar1 * get_2d_scalar1(const std::string &name) const
Definition Vars.cc:172
Vars(Vars const &)
const array::CellType * get_2d_cell_type(const std::string &name) const
Definition Vars.cc:184
std::shared_ptr< array::Array > get_shared(const std::string &name) const
Definition Vars.cc:279
std::shared_ptr< array::CellType > get_2d_cell_type_shared(const std::string &name) const
Definition Vars.cc:304
bool is_available_shared(const std::string &name) const
Definition Vars.cc:253
void add_shared(std::shared_ptr< array::Array >)
Definition Vars.cc:215
Vars & operator=(Vars const &)
const array::Scalar * get_2d_scalar(const std::string &name) const
Definition Vars.cc:168
std::shared_ptr< array::Scalar1 > get_2d_scalar1_shared(const std::string &name) const
Definition Vars.cc:291
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:123
void remove(const std::string &name)
Removes a variable with the key name from the dictionary.
Definition Vars.cc:95
bool is_available(const std::string &name) const
Definition Vars.cc:35
std::shared_ptr< array::Array > get_internal_shared(const std::string &name) const
Definition Vars.cc:323
std::shared_ptr< array::Scalar > get_2d_scalar_shared(const std::string &name) const
Definition Vars.cc:287
std::shared_ptr< array::Scalar2 > get_2d_scalar2_shared(const std::string &name) const
Definition Vars.cc:295
std::map< std::string, const array::Array * > m_variables
Definition Vars.hh:76
std::shared_ptr< array::Vector > get_2d_vector_shared(const std::string &name) const
Definition Vars.cc:300
void add(const array::Array &)
Add an array::Array to the dictionary.
Definition Vars.cc:68
std::map< std::string, std::string > m_standard_names
Definition Vars.hh:83
A class for passing PISM variables from the core to other parts of the code (such as climate couplers...
Definition Vars.hh:42
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:207
"Cell type" mask. Adds convenience methods to array::Scalar.
Definition CellType.hh:30
connected_components::details::PISMArray Array