tFlowLawFactory.cc - 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
---
tFlowLawFactory.cc (4169B)
---
1 // Copyright (C) 2009--2018 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 "FlowLawFactory.hh"
22 #include "pism/util/ConfigInterface.hh"
23 #include "pism/util/error_handling.hh"
24
25 #include "IsothermalGlen.hh"
26 #include "PatersonBudd.hh"
27 #include "GPBLD.hh"
28 #include "Hooke.hh"
29 #include "PatersonBuddCold.hh"
30 #include "PatersonBuddWarm.hh"
31 #include "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,
73 EnthalpyConverter::Ptr my_EC)
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();
81 add(ICE_ISOTHERMAL_GLEN, &create_isothermal_glen);
82 add(ICE_PB, &create_pb);
83 add(ICE_GPBLD, &create_gpbld);
84 add(ICE_HOOKE, &create_hooke);
85 add(ICE_ARR, &create_arr);
86 add(ICE_ARRWARM, &create_arrwarm);
87 add(ICE_GOLDSBY_KOHLSTEDT, &create_goldsby_kohlstedt);
88
89 set_default(m_config->get_string(prefix + "flow_law"));
90 }
91
92 FlowLawFactory::~FlowLawFactory() {
93 // empty
94 }
95
96 void FlowLawFactory::add(const std::string &name, FlowLawCreator icreate) {
97 m_flow_laws[name] = icreate;
98 }
99
100 void FlowLawFactory::remove(const std::string &name) {
101 m_flow_laws.erase(name);
102 }
103
104 void FlowLawFactory::set_default(const std::string &type) {
105 if (m_flow_laws[type] == NULL) {
106 throw RuntimeError::formatted(PISM_ERROR_LOCATION, "Selected ice flow law \"%s\" is not available"
107 " (prefix=\"%s\").",
108 type.c_str(), m_prefix.c_str());
109 }
110
111 m_type_name = type;
112 }
113
114 std::shared_ptr<FlowLaw> FlowLawFactory::create() {
115 // find the function that can create selected flow law:
116 FlowLawCreator r = m_flow_laws[m_type_name];
117 if (r == NULL) {
118 throw RuntimeError::formatted(PISM_ERROR_LOCATION, "Selected ice flow law \"%s\" is not available,\n"
119 "but we shouldn't be able to get here anyway",
120 m_type_name.c_str());
121 }
122
123 // create an FlowLaw instance:
124 return std::shared_ptr<FlowLaw>((*r)(m_prefix, *m_config, m_EC));
125 }
126
127 } // end of namespace rheology
128 } // end of namespace pism