PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
FlowLawFactory.cc
Go to the documentation of this file.
1 // Copyright (C) 2009--2018, 2023 Jed Brown, Ed Bueler and 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 #include <cassert>
20 
21 #include "pism/rheology/FlowLawFactory.hh"
22 #include "pism/util/ConfigInterface.hh"
23 #include "pism/util/error_handling.hh"
24 
25 #include "pism/rheology/IsothermalGlen.hh"
26 #include "pism/rheology/PatersonBudd.hh"
27 #include "pism/rheology/GPBLD.hh"
28 #include "pism/rheology/Hooke.hh"
29 #include "pism/rheology/PatersonBuddCold.hh"
30 #include "pism/rheology/PatersonBuddWarm.hh"
31 #include "pism/rheology/GoldsbyKohlstedt.hh"
32 
33 namespace pism {
34 namespace rheology {
35 
36 FlowLaw* create_isothermal_glen(const std::string &pre,
37  const Config &config, EnthalpyConverter::Ptr EC) {
38  return new (IsothermalGlen)(pre, config, EC);
39 }
40 
41 FlowLaw* create_pb(const std::string &pre,
42  const Config &config, EnthalpyConverter::Ptr EC) {
43  return new (PatersonBudd)(pre, config, EC);
44 }
45 
46 FlowLaw* create_gpbld(const std::string &pre,
47  const Config &config, EnthalpyConverter::Ptr EC) {
48  return new (GPBLD)(pre, config, EC);
49 }
50 
51 FlowLaw* create_hooke(const std::string &pre,
52  const Config &config, EnthalpyConverter::Ptr EC) {
53  return new (Hooke)(pre, config, EC);
54 }
55 
56 FlowLaw* create_arr(const std::string &pre,
57  const Config &config, EnthalpyConverter::Ptr EC) {
58  return new (PatersonBuddCold)(pre, config, EC);
59 }
60 
61 FlowLaw* create_arrwarm(const std::string &pre,
62  const Config &config, EnthalpyConverter::Ptr EC) {
63  return new (PatersonBuddWarm)(pre, config, EC);
64 }
65 
66 FlowLaw* create_goldsby_kohlstedt(const std::string &pre,
67  const Config &config, EnthalpyConverter::Ptr EC) {
68  return new (GoldsbyKohlstedt)(pre, config, EC);
69 }
70 
71 FlowLawFactory::FlowLawFactory(const std::string &prefix,
72  Config::ConstPtr conf,
74  : m_config(conf), m_EC(my_EC) {
75 
76  m_prefix = prefix;
77 
78  assert(not prefix.empty());
79 
80  m_flow_laws.clear();
82  add(ICE_PB, &create_pb);
88 
89  set_default(m_config->get_string(prefix + "flow_law"));
90 }
91 
92 void FlowLawFactory::add(const std::string &name, FlowLawCreator icreate) {
93  m_flow_laws[name] = icreate;
94 }
95 
96 void FlowLawFactory::remove(const std::string &name) {
97  m_flow_laws.erase(name);
98 }
99 
100 void FlowLawFactory::set_default(const std::string &type) {
101  if (m_flow_laws[type] == NULL) {
102  throw RuntimeError::formatted(PISM_ERROR_LOCATION, "Selected ice flow law \"%s\" is not available"
103  " (prefix=\"%s\").",
104  type.c_str(), m_prefix.c_str());
105  }
106 
107  m_type_name = type;
108 }
109 
110 std::shared_ptr<FlowLaw> FlowLawFactory::create() {
111  // find the function that can create selected flow law:
113  if (r == NULL) {
114  throw RuntimeError::formatted(PISM_ERROR_LOCATION, "Selected ice flow law \"%s\" is not available,\n"
115  "but we shouldn't be able to get here anyway",
116  m_type_name.c_str());
117  }
118 
119  // create an FlowLaw instance:
120  return std::shared_ptr<FlowLaw>((*r)(m_prefix, *m_config, m_EC));
121 }
122 
123 } // end of namespace rheology
124 } // end of namespace pism
#define ICE_PB
#define ICE_GOLDSBY_KOHLSTEDT
#define ICE_HOOKE
#define ICE_ARR
#define ICE_ARRWARM
#define ICE_GPBLD
#define ICE_ISOTHERMAL_GLEN
std::shared_ptr< const Config > ConstPtr
A class for storing and accessing PISM configuration flags and parameters.
std::shared_ptr< EnthalpyConverter > Ptr
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
std::map< std::string, FlowLawCreator > m_flow_laws
std::shared_ptr< FlowLaw > create()
void remove(const std::string &name)
const Config::ConstPtr m_config
FlowLawFactory(const std::string &prefix, Config::ConstPtr conf, EnthalpyConverter::Ptr my_EC)
EnthalpyConverter::Ptr m_EC
void set_default(const std::string &name)
void add(const std::string &name, FlowLawCreator)
Glen (1955) and Paterson-Budd (1982) flow law with additional water fraction factor from Lliboutry & ...
Definition: GPBLD.hh:33
A hybrid of Goldsby-Kohlstedt (2001) ice (constitutive form) and Paterson-Budd (1982)-Glen (viscosity...
The Hooke flow law.
Definition: Hooke.hh:29
Isothermal Glen ice allowing extra customization.
Cold case of Paterson-Budd.
Warm case of Paterson-Budd.
Derived class of FlowLaw for Paterson-Budd (1982)-Glen ice.
Definition: PatersonBudd.hh:32
#define PISM_ERROR_LOCATION
FlowLaw * create_gpbld(const std::string &pre, const Config &config, EnthalpyConverter::Ptr EC)
FlowLaw *(* FlowLawCreator)(const std::string &, const Config &, EnthalpyConverter::Ptr)
FlowLaw * create_hooke(const std::string &pre, const Config &config, EnthalpyConverter::Ptr EC)
FlowLaw * create_arr(const std::string &pre, const Config &config, EnthalpyConverter::Ptr EC)
FlowLaw * create_isothermal_glen(const std::string &pre, const Config &config, EnthalpyConverter::Ptr EC)
FlowLaw * create_goldsby_kohlstedt(const std::string &pre, const Config &config, EnthalpyConverter::Ptr EC)
FlowLaw * create_pb(const std::string &pre, const Config &config, EnthalpyConverter::Ptr EC)
FlowLaw * create_arrwarm(const std::string &pre, const Config &config, EnthalpyConverter::Ptr EC)