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
Context.cc
Go to the documentation of this file.
1/* Copyright (C) 2014, 2015, 2017, 2019, 2021, 2023, 2024, 2025 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#include "pism/util/Context.hh"
21#include "pism/util/Profiling.hh"
22#include "pism/util/Units.hh"
23#include "pism/util/Time.hh"
24#include "pism/util/Logger.hh"
25#include "pism/util/EnthalpyConverter.hh"
26#include <memory>
27
28namespace pism {
29
31public:
32 Impl(MPI_Comm c,
33 std::shared_ptr<units::System> sys,
34 std::shared_ptr<Config> conf,
35 std::shared_ptr<EnthalpyConverter> EC,
36 std::shared_ptr<Time> t,
37 std::shared_ptr<Logger> log,
38 const std::string &p)
39 : com(c), unit_system(sys), config(conf), enthalpy_converter(EC), time(t), prefix(p),
40 logger(log) {
41 // empty
42 }
43 MPI_Comm com;
44 std::shared_ptr<units::System> unit_system;
45 std::shared_ptr<Config> config;
46 std::shared_ptr<EnthalpyConverter> enthalpy_converter;
47 std::shared_ptr<Time> time;
48 std::string prefix;
50 std::shared_ptr<Logger> logger;
51};
52
53Context::Context(MPI_Comm c, std::shared_ptr<units::System> sys,
54 std::shared_ptr<Config> config, std::shared_ptr<EnthalpyConverter> EC, std::shared_ptr<Time> t,
55 std::shared_ptr<Logger> L,
56 const std::string &p)
57 : m_impl(new Impl(c, sys, config, EC, t, L, p)) {
58 // empty
59}
60
62 delete m_impl;
63}
64
65MPI_Comm Context::com() const {
66 return m_impl->com;
67}
68
69int Context::size() const {
70 int S = 0;
71 MPI_Comm_size(m_impl->com, &S);
72 return S;
73}
74
75int Context::rank() const {
76 int R = 0;
77 MPI_Comm_rank(m_impl->com, &R);
78 return R;
79}
80
81std::shared_ptr<units::System> Context::unit_system() const {
82 return m_impl->unit_system;
83}
84
85std::shared_ptr<Config> Context::config() {
86 return m_impl->config;
87}
88
89std::shared_ptr<const Config> Context::config() const {
90 return m_impl->config;
91}
92
93std::shared_ptr<EnthalpyConverter> Context::enthalpy_converter() const {
95}
96
97std::shared_ptr<Time> Context::time() {
98 return m_impl->time;
99}
100
101std::shared_ptr<const Time> Context::time() const {
102 return m_impl->time;
103}
104
105const std::string& Context::prefix() const {
106 return m_impl->prefix;
107}
108
110 return m_impl->profiling;
111}
112
113std::shared_ptr<const Logger> Context::log() const {
114 return m_impl->logger;
115}
116
117std::shared_ptr<Logger> Context::log() {
118 return m_impl->logger;
119}
120
121std::shared_ptr<Context> context_from_options(MPI_Comm com,
122 const std::string &prefix,
123 bool print) {
124 // unit system
125 auto sys = std::make_shared<units::System>();
126
127 // logger
128 auto logger = logger_from_options(com);
129
130 // configuration parameters
131 auto config = config_from_options(com, *logger, sys);
132
133 if (print) {
134 print_config(*logger, 3, *config);
135 }
136
137 // time manager
138 auto time = std::make_shared<Time>(com, config, *logger, sys);
139
140 // enthalpy converter
141 auto EC = std::make_shared<EnthalpyConverter>(*config);
142
143 return std::make_shared<Context>(com, sys, config, EC, time, logger, prefix);
144}
145
146
147} // end of namespace pism
Profiling profiling
Definition Context.cc:49
std::shared_ptr< Config > config
Definition Context.cc:45
std::shared_ptr< Logger > logger
Definition Context.cc:50
Impl(MPI_Comm c, std::shared_ptr< units::System > sys, std::shared_ptr< Config > conf, std::shared_ptr< EnthalpyConverter > EC, std::shared_ptr< Time > t, std::shared_ptr< Logger > log, const std::string &p)
Definition Context.cc:32
std::string prefix
Definition Context.cc:48
std::shared_ptr< Time > time
Definition Context.cc:47
std::shared_ptr< EnthalpyConverter > enthalpy_converter
Definition Context.cc:46
std::shared_ptr< units::System > unit_system
Definition Context.cc:44
MPI_Comm com() const
Definition Context.cc:65
Context(MPI_Comm c, std::shared_ptr< units::System > sys, std::shared_ptr< Config > conf, std::shared_ptr< EnthalpyConverter > EC, std::shared_ptr< Time > t, std::shared_ptr< Logger > log, const std::string &p)
Definition Context.cc:53
Impl * m_impl
Definition Context.hh:65
std::shared_ptr< const Config > config() const
Definition Context.cc:89
const std::string & prefix() const
Definition Context.cc:105
int size() const
Definition Context.cc:69
const Profiling & profiling() const
Definition Context.cc:109
std::shared_ptr< const Logger > log() const
Definition Context.cc:113
std::shared_ptr< units::System > unit_system() const
Definition Context.cc:81
int rank() const
Definition Context.cc:75
std::shared_ptr< const Time > time() const
Definition Context.cc:101
std::shared_ptr< EnthalpyConverter > enthalpy_converter() const
Definition Context.cc:93
static const double L
Definition exactTestL.cc:40
std::shared_ptr< Context > context_from_options(MPI_Comm com, const std::string &prefix, bool print)
Create a default context using options.
Definition Context.cc:121
Logger::Ptr logger_from_options(MPI_Comm com)
Definition Logger.cc:107
Config::Ptr config_from_options(MPI_Comm com, const Logger &log, units::System::Ptr unit_system)
Create a configuration database using command-line options.
void print_config(const Logger &log, int verbosity_threshhold, const Config &config)
Report configuration parameters to stdout.
static double S(unsigned n)
Definition test_cube.c:58