PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
Vector.cc
Go to the documentation of this file.
1 // Copyright (C) 2009--2017, 2020, 2021, 2022, 2023 Constantine Khroulev
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 #include "pism/util/array/Vector.hh"
20 #include "pism/util/array/Array_impl.hh"
21 
22 #include "pism/util/Grid.hh"
23 #include "pism/util/Context.hh"
24 #include "pism/util/VariableMetadata.hh"
25 
26 namespace pism {
27 namespace array {
28 
29 Vector::Vector(std::shared_ptr<const Grid> grid, const std::string &name)
30  : Array2D<pism::Vector2d>(grid, name, WITHOUT_GHOSTS, 2) {
31  // This constructor uses the stencil width of 2 to make the DM compatible with ghosted
32  // arrays with this wide stencil.
33 
34  auto sys = m_impl->grid->ctx()->unit_system();
35  m_impl->metadata = {{sys, "u" + name}, {sys, "v" + name}};
36  set_name("vel" + name);
37 }
38 
39 Vector::Vector(std::shared_ptr<const Grid> grid, const std::string &name,
40  unsigned int stencil_width)
41  : Array2D<pism::Vector2d>(grid, name,
42  stencil_width > 0 ? WITH_GHOSTS : WITHOUT_GHOSTS,
43  stencil_width) {
44 
45  auto sys = m_impl->grid->ctx()->unit_system();
46  m_impl->metadata = {{sys, "u" + name}, {sys, "v" + name}};
47  set_name("vel" + name);
48 }
49 
50 std::shared_ptr<Vector> Vector::duplicate() const {
51 
52  auto result = std::make_shared<Vector>(grid(), get_name());
53  result->metadata(0) = this->metadata(0);
54  result->metadata(1) = this->metadata(1);
55 
56  return result;
57 }
58 
59 Vector1::Vector1(std::shared_ptr<const Grid> grid, const std::string &name)
60  : Vector(grid, name, 1) {
61  // empty
62 }
63 
64 Vector1::Vector1(std::shared_ptr<const Grid> grid, const std::string &name,
65  unsigned int stencil_width)
66  : Vector(grid, name, stencil_width) {
67  // empty
68 }
69 
70 Vector2::Vector2(std::shared_ptr<const Grid> grid, const std::string &name)
71  : Vector1(grid, name, 2) {
72  // empty
73 }
74 
75 } // end of namespace array
76 } // end of namespace pism
This class represents a 2D vector field (such as ice velocity) at a certain grid point.
Definition: Vector2d.hh:29
A storage vector combining related fields in a struct.
Definition: Array2D.hh:32
void set_name(const std::string &name)
Sets the variable name to name.
Definition: Array.cc:371
const std::string & get_name() const
Get the name of an Array object.
Definition: Array.cc:383
std::shared_ptr< const Grid > grid() const
Definition: Array.cc:132
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition: Array.cc:553
Vector1(std::shared_ptr< const Grid > grid, const std::string &name)
Definition: Vector.cc:59
Vector2(std::shared_ptr< const Grid > grid, const std::string &name)
Definition: Vector.cc:70
std::shared_ptr< Vector > duplicate() const
Definition: Vector.cc:50
Vector(std::shared_ptr< const Grid > grid, const std::string &short_name)
Definition: Vector.cc:29
@ WITH_GHOSTS
Definition: Array.hh:62
@ WITHOUT_GHOSTS
Definition: Array.hh:62
std::shared_ptr< const Grid > grid
The computational grid.
Definition: Array_impl.hh:77
std::vector< SpatialVariableMetadata > metadata
Metadata (NetCDF variable attributes)
Definition: Array_impl.hh:74