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
InputInterpolation.hh
Go to the documentation of this file.
1/* Copyright (C) 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#ifndef PISM_INPUT_INTERPOLATION_H
21#define PISM_INPUT_INTERPOLATION_H
22
23#include <memory>
24#include <vector>
25
26#include "pism/util/Interpolation1D.hh" // InterpolationType
27
28namespace pism {
29
30class File;
31class SpatialVariableMetadata;
32class Grid;
33class LocalInterpCtx;
34
35namespace petsc {
36class Vec;
37}
38
39/*!
40 * Interpolation from a grid corresponding to a variable in an input file to a PISM's
41 * internal grid.
42 */
44public:
45 virtual ~InputInterpolation() = default;
46
47 static std::shared_ptr<InputInterpolation>
48 create(const Grid &target_grid, const std::vector<double> &levels, const File &input_file,
49 const std::string &variable_name, InterpolationType type);
50
51 /*!
52 * Read a record `record_index` of the variable corresponding to the provided `metadata`
53 * from a `file` and interpolate onto the target grid. Store results in `output`.
54 *
55 * Set `record_index` to -1 to read the last record available in `file`.
56 *
57 */
58 double regrid(const SpatialVariableMetadata &metadata, const pism::File &file, int record_index,
59 const Grid &grid, petsc::Vec &output) const;
60
61protected:
63 virtual double regrid_impl(const SpatialVariableMetadata &metadata, const pism::File &file,
64 int record_index, const Grid &grid, petsc::Vec &output) const = 0;
65};
66
67/*!
68 * Legacy 2D and 3D interpolation code used to "regrid" (read with interpolation) inputs.
69 *
70 */
72public:
73 InputInterpolation3D(const Grid &target_grid, const std::vector<double> &levels,
74 const File &input_file, const std::string &variable_name,
76
77private:
78 double regrid_impl(const SpatialVariableMetadata &metadata, const pism::File &file,
79 int record_index, const Grid &grid, petsc::Vec &output) const;
80
81 std::shared_ptr<LocalInterpCtx> m_interp_context;
82};
83
84} // namespace pism
85
86#endif /* PISM_INPUT_INTERPOLATION_H */
High-level PISM I/O class.
Definition File.hh:55
Describes the PISM grid and the distribution of data across processors.
Definition Grid.hh:290
double regrid_impl(const SpatialVariableMetadata &metadata, const pism::File &file, int record_index, const Grid &grid, petsc::Vec &output) const
std::shared_ptr< LocalInterpCtx > m_interp_context
virtual ~InputInterpolation()=default
virtual double regrid_impl(const SpatialVariableMetadata &metadata, const pism::File &file, int record_index, const Grid &grid, petsc::Vec &output) const =0
double regrid(const SpatialVariableMetadata &metadata, const pism::File &file, int record_index, const Grid &grid, petsc::Vec &output) const
static std::shared_ptr< InputInterpolation > create(const Grid &target_grid, const std::vector< double > &levels, const File &input_file, const std::string &variable_name, InterpolationType type)
Spatial NetCDF variable (corresponding to a 2D or 3D scalar field).