PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
Vector.cc
Go to the documentation of this file.
1// Copyright (C) 2009--2017, 2020, 2021, 2022, 2023, 2025 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
26namespace pism {
27namespace array {
28
29Vector::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, *grid }, { sys, "v" + name, *grid } };
36 set_name("vel" + name);
37}
38
39Vector::Vector(std::shared_ptr<const Grid> grid, const std::string &name,
40 unsigned int stencil_width)
41 : Array2D<pism::Vector2d>(grid, name, stencil_width > 0 ? WITH_GHOSTS : WITHOUT_GHOSTS,
42 stencil_width) {
43
44 auto sys = m_impl->grid->ctx()->unit_system();
45 m_impl->metadata = { { sys, "u" + name, *grid }, { sys, "v" + name, *grid } };
46 set_name("vel" + name);
47}
48
49std::shared_ptr<Vector> Vector::duplicate() const {
50
51 auto result = std::make_shared<Vector>(grid(), get_name());
52 result->metadata(0) = this->metadata(0);
53 result->metadata(1) = this->metadata(1);
54
55 return result;
56}
57
58Vector1::Vector1(std::shared_ptr<const Grid> grid, const std::string &name)
59 : Vector(grid, name, 1) {
60 // empty
61}
62
63Vector1::Vector1(std::shared_ptr<const Grid> grid, const std::string &name,
64 unsigned int stencil_width)
65 : Vector(grid, name, stencil_width) {
66 // empty
67}
68
69Vector2::Vector2(std::shared_ptr<const Grid> grid, const std::string &name)
70 : Vector1(grid, name, 2) {
71 // empty
72}
73
74} // end of namespace array
75} // 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:345
const std::string & get_name() const
Get the name of an Array object.
Definition Array.cc:357
std::shared_ptr< const Grid > grid() const
Definition Array.cc:134
Vector1(std::shared_ptr< const Grid > grid, const std::string &name)
Definition Vector.cc:58
Vector2(std::shared_ptr< const Grid > grid, const std::string &name)
Definition Vector.cc:69
std::shared_ptr< Vector > duplicate() const
Definition Vector.cc:49
Vector(std::shared_ptr< const Grid > grid, const std::string &short_name)
Definition Vector.cc:29
std::set< VariableMetadata > metadata(std::initializer_list< const Array * > vecs)
Definition Array.cc:1244
@ WITH_GHOSTS
Definition Array.hh:63
@ WITHOUT_GHOSTS
Definition Array.hh:63
std::vector< VariableMetadata > metadata
Metadata (NetCDF variable attributes)
Definition Array_impl.hh:74
std::shared_ptr< const Grid > grid
The computational grid.
Definition Array_impl.hh:77