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
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
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}, {sys, "v" + name}};
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,
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
50std::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
59Vector1::Vector1(std::shared_ptr<const Grid> grid, const std::string &name)
60 : Vector(grid, name, 1) {
61 // empty
62}
63
64Vector1::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
70Vector2::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:342
const std::string & get_name() const
Get the name of an Array object.
Definition Array.cc:354
std::shared_ptr< const Grid > grid() const
Definition Array.cc:131
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
Definition Array.cc:476
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:61
@ WITHOUT_GHOSTS
Definition Array.hh:61
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