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
factory.cc
Go to the documentation of this file.
1/* Copyright (C) 2017, 2018, 2020, 2021, 2023, 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#include <memory>
21
22#include "pism/regional/SIAFD_Regional.hh"
23#include "pism/stressbalance/SSB_Modifier.hh"
24#include "pism/stressbalance/ShallowStressBalance.hh"
25#include "pism/stressbalance/StressBalance.hh"
26#include "pism/stressbalance/WeertmanSliding.hh"
27#include "pism/stressbalance/blatter/Blatter.hh"
28#include "pism/stressbalance/blatter/BlatterMod.hh"
29#include "pism/stressbalance/sia/SIAFD.hh"
30#include "pism/stressbalance/ssa/SSAFD.hh"
31#include "pism/stressbalance/ssa/SSAFD_SNES.hh"
32#include "pism/stressbalance/ssa/SSAFEM.hh"
33#include "pism/util/Context.hh"
34#include "pism/util/pism_utilities.hh"
35
36namespace pism {
37namespace stressbalance {
38
39std::shared_ptr<StressBalance> create(const std::string &model,
40 std::shared_ptr<const Grid> grid,
41 bool regional) {
42
43 auto config = grid->ctx()->config();
44
45 if (model == "blatter") {
46 int Mz = config->get_number("stress_balance.blatter.Mz");
47 int C = config->get_number("stress_balance.blatter.coarsening_factor");
48
49 auto blatter = std::make_shared<Blatter>(grid, Mz, C);
50 auto mod = std::make_shared<BlatterMod>(blatter);
51
52 return std::make_shared<StressBalance>(grid, blatter, mod);
53 }
54
55 auto ssa_method = config->get_string("stress_balance.ssa.method");
56 std::shared_ptr<ShallowStressBalance> sliding;
57 if (member(model, {"none", "sia"})) {
58 sliding = std::make_shared<ZeroSliding>(grid);
59 } else if (member(model, {"prescribed_sliding", "prescribed_sliding+sia"})) {
60 sliding = std::make_shared<PrescribedSliding>(grid);
61 } else if (member(model, {"weertman_sliding", "weertman_sliding+sia"})) {
62 sliding = std::make_shared<WeertmanSliding>(grid);
63 } else if (member(model, {"ssa", "ssa+sia"})) {
64 if (ssa_method == "fd") {
65 sliding = std::make_shared<SSAFD>(grid, regional);
66 } else if (ssa_method == "fd_snes") {
67 sliding = std::make_shared<SSAFD_SNES>(grid, regional);
68 } else {
69 sliding = std::make_shared<SSAFEM>(grid);
70 }
71 } else {
73 "invalid stress balance model: %s", model.c_str());
74 }
75
76 std::shared_ptr<SSB_Modifier> modifier;
77 if (member(model, {"none", "ssa", "prescribed_sliding", "weertman_sliding"})) {
78 modifier = std::make_shared<ConstantInColumn>(grid);
79 } else if (member(model, {"prescribed_sliding+sia", "weertman_sliding+sia", "ssa+sia", "sia"})) {
80 if (regional) {
81 modifier = std::make_shared<SIAFD_Regional>(grid);
82 } else {
83 modifier = std::make_shared<SIAFD>(grid);
84 }
85 } else {
87 "invalid stress balance model: %s", model.c_str());
88 }
89
90 return std::make_shared<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
#define PISM_ERROR_LOCATION
std::shared_ptr< StressBalance > create(const std::string &model, std::shared_ptr< const Grid > grid, bool regional)
Definition factory.cc:39
bool member(const std::string &string, const std::set< std::string > &set)