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
Config.hh
Go to the documentation of this file.
1/* Copyright (C) 2014, 2015, 2016, 2017, 2018, 2021, 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
20#ifndef _PISMCONFIG_H_
21#define _PISMCONFIG_H_
22
23#include <string>
24#include <set>
25
26#include "pism/util/ConfigInterface.hh"
27#include "pism/util/VariableMetadata.hh"
28
29namespace pism {
30
31class Logger;
32
33//! A class for reading, writing and accessing PISM configuration flags and parameters.
34class NetCDFConfig : public Config {
35public:
36 NetCDFConfig(MPI_Comm com, const std::string &name, units::System::Ptr unit_system);
38
39protected:
40 void read_impl(const File &file);
41 void write_impl(const File &file) const;
42
43 bool is_set_impl(const std::string &name) const;
44
45 // doubles
47 double get_number_impl(const std::string &name) const;
48 std::vector<double> get_numbers_impl(const std::string &name) const;
49
50 void set_number_impl(const std::string &name, double value);
51 void set_numbers_impl(const std::string &name,
52 const std::vector<double> &values);
53 // strings
55 std::string get_string_impl(const std::string &name) const;
56 void set_string_impl(const std::string &name, const std::string &value);
57
58 // flags
59 Flags all_flags_impl() const;
60 bool get_flag_impl(const std::string& name) const;
61 void set_flag_impl(const std::string& name, bool value);
62protected:
63 MPI_Comm m_com;
65private:
66 //! @brief the name of the file this config database was initialized from
67 std::string m_config_filename;
68};
69
70//! @brief Default PISM configuration database: uses NetCDF files; can be initialized from a file
71//! specified using a command-line option.
73public:
74 DefaultConfig(MPI_Comm com,
75 const std::string &variable_name,
76 const std::string &option,
77 units::System::Ptr unit_system);
78 ~DefaultConfig() = default;
79
80 typedef std::shared_ptr<DefaultConfig> Ptr;
81 typedef std::shared_ptr<const DefaultConfig> ConstPtr;
82
83 //! Initialize (use default path if no option was set).
84 void init_with_default(const Logger &log);
85 //! Initialize (leave empty if no option was set).
86 void init(const Logger &log);
87private:
88 void init(const Logger &log, bool use_default_path);
89 std::string m_option;
90};
91
92} // end of namespace pism
93
94#endif /* _PISMCONFIG_H_ */
std::map< std::string, std::string > Strings
std::map< std::string, std::vector< double > > Doubles
std::map< std::string, bool > Flags
std::string option(const std::string &parameter) const
A class for storing and accessing PISM configuration flags and parameters.
void init_with_default(const Logger &log)
Initialize (use default path if no option was set).
Definition Config.cc:231
std::shared_ptr< DefaultConfig > Ptr
Definition Config.hh:80
std::shared_ptr< const DefaultConfig > ConstPtr
Definition Config.hh:81
~DefaultConfig()=default
std::string m_option
Definition Config.hh:89
void init(const Logger &log)
Initialize (leave empty if no option was set).
Definition Config.cc:235
Default PISM configuration database: uses NetCDF files; can be initialized from a file specified usin...
Definition Config.hh:72
High-level PISM I/O class.
Definition File.hh:55
A basic logging class.
Definition Logger.hh:40
bool get_flag_impl(const std::string &name) const
Definition Config.cc:139
void set_numbers_impl(const std::string &name, const std::vector< double > &values)
Definition Config.cc:86
bool is_set_impl(const std::string &name) const
Definition Config.cc:40
VariableMetadata m_data
Definition Config.hh:64
MPI_Comm m_com
Definition Config.hh:63
void write_impl(const File &file) const
Write a config variable to a file (with all its attributes).
Definition Config.cc:200
Doubles all_doubles_impl() const
Definition Config.cc:72
void set_number_impl(const std::string &name, double value)
Definition Config.cc:82
void set_flag_impl(const std::string &name, bool value)
Set a value of a flag flag.
Definition Config.cc:182
void read_impl(const File &file)
Read flag flags and double parameters from a NetCDF file.
Definition Config.cc:192
std::string get_string_impl(const std::string &name) const
Definition Config.cc:93
double get_number_impl(const std::string &name) const
Definition Config.cc:46
void set_string_impl(const std::string &name, const std::string &value)
Definition Config.cc:125
Strings all_strings_impl() const
Definition Config.cc:106
Flags all_flags_impl() const
Definition Config.cc:165
std::vector< double > get_numbers_impl(const std::string &name) const
Definition Config.cc:59
std::string m_config_filename
the name of the file this config database was initialized from
Definition Config.hh:67
A class for reading, writing and accessing PISM configuration flags and parameters.
Definition Config.hh:34
std::shared_ptr< System > Ptr
Definition Units.hh:47