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
SSATestCase.hh
Go to the documentation of this file.
1// Copyright (C) 2009--2017, 2021, 2022, 2023, 2024 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
19#ifndef PISM_SSATESTCASE_H
20#define PISM_SSATESTCASE_H
21
22#include "pism/stressbalance/ssa/SSA.hh"
23#include "pism/geometry/Geometry.hh"
24#include "pism/util/array/Array3D.hh"
25#include "pism/util/array/Scalar.hh"
26#include "pism/util/array/Vector.hh"
27#include <memory>
28
29namespace pism {
30
31class Context;
32class Grid;
33
34namespace stressbalance {
35
36/*! An SSATestCase manages running an SSA instance against a particular
37 test. Subclasses must implement the following abstract methods to define
38 the input to an SSA for a test case:
39
40 1) initializeSSACoefficients (to initialize the ssa coefficients, e.g. ice thickness)
41
42 Additionally, a subclass can implement `report` to handle
43 printing statistics after a run. The default report method relies
44 on subclasses implementing the exactSolution method for comparison.
45
46 A driver uses an SSATestCase by calling 1-3 below and 4,5 as desired:
47
48 1) its constructor
49 2) init (to set coefficients)
50 3) run (to actually solve the ssa)
51 4) report
52 5) write (to save the results of the computation to a file)
53*/
55{
56public:
57 SSATestCase(std::shared_ptr<SSA> ssa);
58
59 virtual ~SSATestCase() = default;
60
61 virtual void init();
62
63 virtual void run();
64
65 virtual void report(const std::string &testname);
66
67 virtual void write(const std::string &filename);
68
69 static std::shared_ptr<Grid> grid(std::shared_ptr<Context> ctx, int Mx, int My, double Lx, double Ly,
70 grid::Registration registration, grid::Periodicity periodicity) {
71 return Grid::Shallow(ctx, Lx, Ly, 0.0, 0.0, Mx, My, registration, periodicity);
72 }
73
74 static std::shared_ptr<SSA> solver(std::shared_ptr<Grid> grid, const std::string &method);
75
76protected:
77
78 //! Set up the coefficient variables as appropriate for the test case.
79 virtual void initializeSSACoefficients() = 0;
80
81 //! Return the value of the exact solution at grid index (i,j) or equivalently
82 //! at coordinates (x,y).
83 virtual void exactSolution(int i, int j,
84 double x, double y, double *u, double *v);
85
86 void report_netcdf(const std::string &testname,
87 double max_vector,
88 double rel_vector,
89 double max_u,
90 double max_v,
91 double avg_u,
92 double avg_v);
93
94 std::shared_ptr<const pism::Grid> m_grid;
95
96 const std::shared_ptr<const Context> m_ctx;
98
100
101 // SSA coefficient variables.
104
107
109
110 std::shared_ptr<SSA> m_ssa;
111};
112
113} // end of namespace stressbalance
114} // end of namespace pism
115
116#endif /* PISM_SSATESTCASE_H */
std::shared_ptr< const Config > ConstPtr
static std::shared_ptr< Grid > Shallow(std::shared_ptr< const Context > ctx, double Lx, double Ly, double x0, double y0, unsigned int Mx, unsigned int My, grid::Registration r, grid::Periodicity p)
Initialize a uniform, shallow (3 z-levels) grid with half-widths (Lx,Ly) and Mx by My nodes.
Definition Grid.cc:134
A virtual class collecting methods common to ice and bedrock 3D fields.
Definition Array3D.hh:33
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
virtual void initializeSSACoefficients()=0
Set up the coefficient variables as appropriate for the test case.
void report_netcdf(const std::string &testname, double max_vector, double rel_vector, double max_u, double max_v, double avg_u, double avg_v)
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 exactSolution(int i, int j, double x, double y, double *u, double *v)
static std::shared_ptr< SSA > solver(std::shared_ptr< Grid > grid, const std::string &method)
virtual void report(const std::string &testname)
Report on the generated solution.
virtual void run()
Solve the SSA.
const Config::ConstPtr m_config
std::shared_ptr< SSA > m_ssa
virtual void write(const std::string &filename)
Save the computation and data to a file.
const std::shared_ptr< const Context > m_ctx
std::shared_ptr< System > Ptr
Definition Units.hh:47
Periodicity
Definition Grid.hh:54
Registration
Definition Grid.hh:56