PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
SSATestCase.hh
Go to the documentation of this file.
1 // Copyright (C) 2009--2017, 2021, 2022, 2023 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 _SSATESTCASE_H_
20 #define _SSATESTCASE_H_
21 
22 #include "pism/stressbalance/ssa/SSA.hh"
23 #include "pism/geometry/Geometry.hh"
24 #include "pism/util/EnthalpyConverter.hh"
25 #include "pism/util/array/Array3D.hh"
26 #include "pism/util/array/Scalar.hh"
27 #include "pism/util/array/Vector.hh"
28 
29 namespace pism {
30 
31 class Context;
32 class Grid;
33 
34 namespace 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 {
56 public:
57  SSATestCase(std::shared_ptr<Context> ctx, int Mx, int My,
58  double Lx, double Ly,
59  grid::Registration registration,
60  grid::Periodicity periodicity);
61 
62  virtual ~SSATestCase();
63 
64  virtual void init();
65 
66  virtual void run();
67 
68  virtual void report(const std::string &testname);
69 
70  virtual void write(const std::string &filename);
71 
72 protected:
73 
74  //! Set up the coefficient variables as appropriate for the test case.
75  virtual void initializeSSACoefficients() = 0;
76 
77  //! Return the value of the exact solution at grid index (i,j) or equivalently
78  //! at coordinates (x,y).
79  virtual void exactSolution(int i, int j,
80  double x, double y, double *u, double *v);
81 
82  void report_netcdf(const std::string &testname,
83  double max_vector,
84  double rel_vector,
85  double max_u,
86  double max_v,
87  double avg_u,
88  double avg_v);
89 
90  MPI_Comm m_com;
91  const std::shared_ptr<Context> m_ctx;
93 
94  std::shared_ptr<Grid> m_grid;
95 
97 
98  //! "wide" stencil width
100 
101  // SSA model variables.
103 
104  // SSA coefficient variables.
107 
110 
112 
114 };
115 
116 } // end of namespace stressbalance
117 } // end of namespace pism
118 
119 #endif /* _SSATESTCASE_H_ */
std::shared_ptr< Config > Ptr
std::shared_ptr< EnthalpyConverter > Ptr
A virtual class collecting methods common to ice and bedrock 3D fields.
Definition: Array3D.hh:33
virtual void init()
Initialize the test case at the start of a run.
Definition: SSATestCase.cc:94
EnthalpyConverter::Ptr m_enthalpyconverter
Definition: SSATestCase.hh:102
const units::System::Ptr m_sys
Definition: SSATestCase.hh:96
std::shared_ptr< Grid > m_grid
Definition: SSATestCase.hh:94
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)
Definition: SSATestCase.cc:198
virtual void exactSolution(int i, int j, double x, double y, double *u, double *v)
Definition: SSATestCase.cc:289
int m_stencil_width
"wide" stencil width
Definition: SSATestCase.hh:99
const std::shared_ptr< Context > m_ctx
Definition: SSATestCase.hh:91
SSATestCase(std::shared_ptr< Context > ctx, int Mx, int My, double Lx, double Ly, grid::Registration registration, grid::Periodicity periodicity)
Definition: SSATestCase.cc:31
virtual void report(const std::string &testname)
Report on the generated solution.
Definition: SSATestCase.cc:121
virtual void run()
Solve the SSA.
Definition: SSATestCase.cc:103
virtual void write(const std::string &filename)
Save the computation and data to a file.
Definition: SSATestCase.cc:296
PISM's SSA solver.
Definition: SSA.hh:110
std::shared_ptr< System > Ptr
Definition: Units.hh:47
Periodicity
Definition: Grid.hh:51
Registration
Definition: Grid.hh:53