PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
ssa_test_cfbc.cc
Go to the documentation of this file.
1// Copyright (C) 2010--2018, 2021, 2022, 2023, 2024, 2025, 2026 Ed Bueler, Constantine Khroulev, and David Maxwell
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
19static char help[] =
20 "\nSSA_TESTCFBC\n"
21 " Testing program for PISM's implementations of the SSA.\n"
22 " Does a time-independent calculation. Does not run IceModel or a derived\n"
23 " class thereof. Uses the van der Veen flow-line shelf geometry. Also may be\n"
24 " used in a PISM software (regression) test.\n\n";
25
26#include <petsc.h>
27
28#include "pism/stressbalance/ssa/tests/SSATestCase.hh"
29#include "pism/util/Context.hh"
30#include "pism/util/error_handling.hh"
31#include "pism/util/petscwrappers/PetscInitializer.hh"
32#include "pism/util/pism_options.hh"
33
34namespace pism {
35namespace stressbalance {
36
37// thickness profile in the van der Veen solution
38static double H_exact(double V0, double H0, double C, double x) {
39 const double Q0 = V0*H0;
40 return pow(4 * C / Q0 * x + 1/pow(H0, 4), -0.25);
41}
42
43// velocity profile; corresponds to constant flux
44static double u_exact(double V0, double H0, double C, double x) {
45 const double Q0 = V0*H0;
46 return Q0 / H_exact(V0, H0, C, x);
47}
48
49std::shared_ptr<Grid> ssa_test_cfbc_grid(std::shared_ptr<Context> ctx, int Mx, int My) {
50 return SSATestCase::grid(ctx, Mx, My, 250e3, 250e3, grid::CELL_CENTER, grid::Y_PERIODIC);
51}
52
54public:
55 SSATestCaseCFBC(std::shared_ptr<SSA> ssa)
56 : SSATestCase(ssa) {
57 m_V0 = units::convert(m_sys, 300.0, "m year^-1", "m second^-1");
58 m_H0 = 600.0; // meters
59 m_C = 2.45e-18;
60
62 // 0.01 water fraction
63 m_ice_enthalpy.set(EC.enthalpy(273.15, 0.01, 0.0));
64 }
65
66protected:
68
69 void exactSolution(int i, int j, double x, double y, double *u, double *v);
70
71 double m_V0, //!< grounding line vertically-averaged velocity
72 m_H0, //!< grounding line thickness (meters)
73 m_C; //!< "typical constant ice parameter"
74};
75
77
78 m_tauc.set(0.0); // irrelevant
79 m_geometry.bed_elevation.set(-1000.0); // assures shelf is floating
80
83
84 const double x_min = m_grid->x(0);
85
86 for (auto p : m_grid->points()) {
87 const int i = p.i(), j = p.j();
88
89 const double x = m_grid->x(i);
90
91 if (i != (int)m_grid->Mx() - 1) {
92 m_geometry.ice_thickness(i, j) = H_exact(m_V0, m_H0, m_C, x - x_min);
93 } else {
94 m_geometry.ice_thickness(i, j) = 0.0;
95 }
96
97 if (i == 0) {
98 m_bc_mask(i, j) = 1;
99 m_bc_values(i, j) = {m_V0, 0.0};
100 } else {
101 m_bc_mask(i, j) = 0;
102 m_bc_values(i, j) = {0.0, 0.0};
103 }
104 }
105
106 // communicate what we have set
108
111}
112
113void SSATestCaseCFBC::exactSolution(int i, int /*j*/,
114 double x, double /*y*/,
115 double *u, double *v) {
116 const double x_min = m_grid->x(0);
117
118 if (i != (int)m_grid->Mx() - 1) {
119 *u = u_exact(m_V0, m_H0, m_C, x - x_min);
120 } else {
121 *u = 0;
122 }
123
124 *v = 0;
125}
126
127} // end of namespace stressbalance
128} // end of namespace pism
129
130int main(int argc, char *argv[]) {
131
132 using namespace pism;
133 using namespace pism::stressbalance;
134
135 MPI_Comm com = MPI_COMM_WORLD;
136 petsc::Initializer petsc(argc, argv, help);
137
138 com = PETSC_COMM_WORLD;
139
140 /* This explicit scoping forces destructors to be called before PetscFinalize() */
141 try {
142 std::shared_ptr<Context> ctx = context_from_options(com, "ssa_test_cfbc");
143 auto config = ctx->config();
144
145 std::string usage = "\n"
146 "usage of SSA_TEST_CFBC:\n"
147 " run ssa_test_cfbc -Mx <number> -My <number>\n"
148 "\n";
149
150 bool stop = maybe_show_usage(*ctx->log(), "ssa_test_cfbc", usage);
151
152 if (stop) {
153 return 0;
154 }
155
156 // Parameters that can be overridden by command line options
157 unsigned int Mx = config->get_number("grid.Mx");
158 unsigned int My = config->get_number("grid.My");
159
160 auto method = config->get_string("stress_balance.ssa.method");
161 auto output_file = config->get_string("output.file");
162
163 bool write_output = config->get_string("output.size") != "none";
164
165 // we have to set parameters *before* `ssa` is allocated
166 config->set_number("flow_law.isothermal_Glen.ice_softness",
167 pow(1.9e8, -config->get_number("stress_balance.ssa.Glen_exponent")));
168 config->set_flag("stress_balance.ssa.compute_surface_gradient_inward", false);
169 config->set_flag("stress_balance.calving_front_stress_bc", true);
170 config->set_flag("stress_balance.ssa.fd.flow_line_mode", true);
171 config->set_flag("stress_balance.ssa.fd.extrapolate_at_margins", false);
172 config->set_string("stress_balance.ssa.flow_law", "isothermal_glen");
173
174 auto grid = ssa_test_cfbc_grid(ctx, Mx, My);
175 SSATestCaseCFBC testcase(SSATestCase::solver(grid, method));
176 testcase.init();
177 testcase.run();
178 testcase.report("V");
179 if (write_output) {
180 testcase.write(output_file);
181 }
182 }
183 catch (...) {
184 handle_fatal_errors(com);
185 return 1;
186 }
187
188 return 0;
189}
double enthalpy(double T, double omega, double P) const
Compute enthalpy from absolute temperature, liquid water fraction, and pressure.
Converts between specific enthalpy and temperature or liquid content.
void ensure_consistency(double ice_free_thickness_threshold)
Definition Geometry.cc:116
array::Scalar2 ice_surface_elevation
Definition Geometry.hh:57
array::CellType2 cell_type
Definition Geometry.hh:55
array::Scalar2 ice_thickness
Definition Geometry.hh:51
array::Scalar2 bed_elevation
Definition Geometry.hh:47
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
Definition Array.hh:66
void set(double c)
Result: v[j] <- c for all j.
Definition Array.cc:659
void update_ghosts()
Updates ghost points.
Definition Array.cc:645
double m_V0
grounding line vertically-averaged velocity
void exactSolution(int i, int j, double x, double y, double *u, double *v)
SSATestCaseCFBC(std::shared_ptr< SSA > ssa)
double m_H0
grounding line thickness (meters)
void initializeSSACoefficients()
Set up the coefficient variables as appropriate for the test case.
double m_C
"typical constant ice parameter"
std::shared_ptr< const pism::Grid > m_grid
virtual void init()
Initialize the test case at the start of a run.
const units::System::Ptr m_sys
const std::shared_ptr< const Config > m_config
static std::shared_ptr< Grid > grid(std::shared_ptr< Context > ctx, int Mx, int My, double Lx, double Ly, grid::Registration registration, grid::Periodicity periodicity)
virtual void report(const std::string &testname)
Report on the generated solution.
virtual void run()
Solve the SSA.
virtual void write(const std::string &filename)
Save the computation and data to a file.
#define H0
Definition exactTestM.c:39
static double H_exact(double V0, double H0, double C, double x)
std::shared_ptr< Grid > ssa_test_cfbc_grid(std::shared_ptr< Context > ctx, int Mx, int My)
static double u_exact(double V0, double H0, double C, double x)
Stress balance models and related diagnostics.
Definition Isochrones.hh:31
double convert(System::Ptr system, double input, const std::string &spec1, const std::string &spec2)
Convert a quantity from unit1 to unit2.
Definition Units.cc:70
int main(int argc, char *argv[])
static char help[]