PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
factory.cc
Go to the documentation of this file.
1 /* Copyright (C) 2017, 2018, 2020, 2021, 2023 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 <memory>
21 
22 #include "pism/stressbalance/StressBalance.hh"
23 #include "pism/stressbalance/ShallowStressBalance.hh"
24 #include "pism/stressbalance/WeertmanSliding.hh"
25 #include "pism/stressbalance/SSB_Modifier.hh"
26 #include "pism/regional/SSAFD_Regional.hh"
27 #include "pism/regional/SIAFD_Regional.hh"
28 #include "pism/stressbalance/blatter/Blatter.hh"
29 #include "pism/stressbalance/blatter/BlatterMod.hh"
30 
31 #include "pism/util/pism_utilities.hh"
32 #include "pism/util/Context.hh"
33 #include "pism/stressbalance/ssa/SSAFEM.hh"
34 
35 namespace pism {
36 namespace stressbalance {
37 
38 std::shared_ptr<StressBalance> create(const std::string &model,
39  std::shared_ptr<const Grid> grid,
40  bool regional) {
41 
42  auto config = grid->ctx()->config();
43 
44  if (model == "blatter") {
45  int Mz = config->get_number("stress_balance.blatter.Mz");
46  int C = config->get_number("stress_balance.blatter.coarsening_factor");
47 
48  std::shared_ptr<Blatter> blatter(new Blatter(grid, Mz, C));
49  std::shared_ptr<BlatterMod> mod(new BlatterMod(blatter));
50 
51  return std::shared_ptr<StressBalance>(new StressBalance(grid, blatter, mod));
52  }
53 
55  if (config->get_string("stress_balance.ssa.method") == "fd") {
56  SSA = regional ? SSAFD_RegionalFactory : SSAFDFactory;
57  } else {
59  }
60 
61  std::shared_ptr<ShallowStressBalance> sliding;
62  if (member(model, {"none", "sia"})) {
63  sliding.reset(new ZeroSliding(grid));
64  } else if (member(model, {"prescribed_sliding", "prescribed_sliding+sia"})) {
65  sliding.reset(new PrescribedSliding(grid));
66  } else if (member(model, {"weertman_sliding", "weertman_sliding+sia"})) {
67  sliding.reset(new WeertmanSliding(grid));
68  } else if (member(model, {"ssa", "ssa+sia"})) {
69  sliding.reset(SSA(grid));
70  } else {
72  "invalid stress balance model: %s", model.c_str());
73  }
74 
75  std::shared_ptr<SSB_Modifier> modifier;
76 
77  if (member(model, {"none", "ssa", "prescribed_sliding", "weertman_sliding"})) {
78  modifier.reset(new ConstantInColumn(grid));
79  } else if (member(model, {"prescribed_sliding+sia", "weertman_sliding+sia", "ssa+sia", "sia"})) {
80  if (regional) {
81  modifier.reset(new SIAFD_Regional(grid));
82  } else {
83  modifier.reset(new SIAFD(grid));
84  }
85  } else {
87  "invalid stress balance model: %s", model.c_str());
88  }
89 
90  return std::shared_ptr<StressBalance>(new StressBalance(grid, sliding, modifier));
91 }
92 
93 } // end of namespace stressbalance
94 } // end of namespace pism
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
The trivial Shallow Stress Balance modifier.
Definition: SSB_Modifier.hh:74
A version of the SIA stress balance with tweaks for outlet glacier simulations.
PISM's SSA solver.
Definition: SSA.hh:110
The class defining PISM's interface to the shallow stress balance code.
Returns zero velocity field, zero friction heating, and zero for D^2.
#define PISM_ERROR_LOCATION
SSA * SSAFDFactory(std::shared_ptr< const Grid > g)
Constructs a new SSAFD.
Definition: SSAFD.cc:49
SSA *(* SSAFactory)(std::shared_ptr< const Grid >)
Definition: SSA.hh:77
std::shared_ptr< StressBalance > create(const std::string &model, std::shared_ptr< const Grid > grid, bool regional)
Definition: factory.cc:38
SSA * SSAFEMFactory(std::shared_ptr< const Grid > g)
Factory function for constructing a new SSAFEM.
Definition: SSAFEM.cc:112
SSA * SSAFD_RegionalFactory(std::shared_ptr< const Grid > grid)
bool member(const std::string &string, const std::set< std::string > &set)
const int C[]
Definition: ssafd_code.cc:44