ARTS  2.4.0(git:4fb77825)
field.h
Go to the documentation of this file.
1 /* Copyright (C) 2019 Richard Larsson <ric.larsson@gmail.com>
2 
3  This program is free software; you can redistribute it and/or modify it
4  under the terms of the GNU General Public License as published by the
5  Free Software Foundation; either version 2, or (at your option) any
6  later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16  USA. */
17 
26 #ifndef FIELD_HEADER
27 #define FIELD_HEADER
28 #include <vector>
29 #include "interpolation.h"
30 
32 template <class base>
33 class Field3D {
34  private:
35  size_t mpages, mrows, mcols;
36  std::vector<base> data;
37 
38  public:
44  Field3D(const Field3D& g) = default;
45 
52  Field3D<base>& operator=(const Field3D& g) = default;
53 
60  Field3D<base>& operator=(Field3D&& g) = default;
61 
68  : mpages(std::move(g.mpages)),
69  mrows(std::move(g.mrows)),
70  mcols(std::move(g.mcols)),
71  data(std::move(g.data)) {}
72 
81  Field3D(size_t pages = 0,
82  size_t rows = 0,
83  size_t cols = 0,
84  const base& init = base())
85  : mpages(pages),
86  mrows(rows),
87  mcols(cols),
88  data(cols * rows * pages, init) {}
89 
100  base& operator()(size_t page = 0, size_t row = 0, size_t col = 0) {
101  return data[col + row * mcols + page * mrows * mcols];
102  }
103 
114  const base& operator()(size_t col = 0,
115  size_t row = 0,
116  size_t page = 0) const {
117  return data[col + row * mcols + page * mrows * mcols];
118  }
119 
120 
133  base operator()(const GridPos& page = {0, {0, 1}},
134  const GridPos& row = {0, {0, 1}},
135  const GridPos& col = {0, {0, 1}}) const {
136  const size_t pos[8] = {
137  col.idx + 0 + (row.idx + 0) * mcols + (page.idx + 0) * mrows * mcols,
138  col.idx + 1 + (row.idx + 0) * mcols + (page.idx + 0) * mrows * mcols,
139  col.idx + 0 + (row.idx + 1) * mcols + (page.idx + 0) * mrows * mcols,
140  col.idx + 1 + (row.idx + 1) * mcols + (page.idx + 0) * mrows * mcols,
141  col.idx + 0 + (row.idx + 0) * mcols + (page.idx + 1) * mrows * mcols,
142  col.idx + 1 + (row.idx + 0) * mcols + (page.idx + 1) * mrows * mcols,
143  col.idx + 0 + (row.idx + 1) * mcols + (page.idx + 1) * mrows * mcols,
144  col.idx + 1 + (row.idx + 1) * mcols + (page.idx + 1) * mrows * mcols};
145 
146  const Numeric w[8] = {page.fd[1] * row.fd[1] * col.fd[1],
147  page.fd[1] * row.fd[1] * col.fd[0],
148  page.fd[1] * row.fd[0] * col.fd[1],
149  page.fd[1] * row.fd[0] * col.fd[0],
150  page.fd[0] * row.fd[1] * col.fd[1],
151  page.fd[0] * row.fd[1] * col.fd[0],
152  page.fd[0] * row.fd[0] * col.fd[1],
153  page.fd[0] * row.fd[0] * col.fd[0]};
154 
155  bool any_base = false;
156  base out;
157  for (size_t i = 0; i < 8; i++) {
158  if (w[i] not_eq 0) {
159  if (any_base)
160  out += w[i] * data[pos[i]];
161  else
162  out = w[i] * data[pos[i]];
163  any_base = true;
164  }
165  }
166  return out;
167  }
168 
170  size_t npages() const { return mpages; }
171 
173  size_t nrows() const { return mrows; }
174 
176  size_t ncols() const { return mcols; }
177 };
178 
180 template <class base>
181 inline std::ostream& operator<<(std::ostream& os, const Field3D<base>& v) {
182  for (size_t i = 0; i < v.npages(); i++)
183  for (size_t j = 0; j < v.nrows(); j++)
184  for (size_t k = 0; k < v.ncols(); k++) os << v(i, j, k) << '\n';
185  return os;
186 }
187 
188 #endif // FIELD_HEADER
Field3D::Field3D
Field3D(size_t pages=0, size_t rows=0, size_t cols=0, const base &init=base())
Construct a new Field 3 D object.
Definition: field.h:81
w
Complex w(Complex z) noexcept
The Faddeeva function.
Definition: linefunctions.cc:42
Field3D::Field3D
Field3D(const Field3D &g)=default
Construct a new Field3D object.
interpolation.h
Header file for interpolation.cc.
linalg::std
void std(VectorView std, const Vector &y, const ArrayOfVector &ys, const Index start=0, const Index end=-1)
Compute the standard deviation of the ranged ys.
Definition: raw.cc:66
Field3D::operator=
Field3D< base > & operator=(const Field3D &g)=default
Default assignment operator.
Field3D::mcols
size_t mcols
Definition: field.h:35
GridPos::fd
Numeric fd[2]
Definition: interpolation.h:75
Field3D::npages
size_t npages() const
Number of pages.
Definition: field.h:170
ARTS::Continua::init
Workspace & init(Workspace &ws)
Definition: test_cpp_api.cc:145
Field3D::data
std::vector< base > data
Definition: field.h:36
Field3D::mrows
size_t mrows
Definition: field.h:35
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Field3D::operator()
base & operator()(size_t page=0, size_t row=0, size_t col=0)
Access operator.
Definition: field.h:100
Field3D::nrows
size_t nrows() const
Number of rows.
Definition: field.h:173
operator<<
std::ostream & operator<<(std::ostream &os, const Field3D< base > &v)
Output operator.
Definition: field.h:181
Field3D::ncols
size_t ncols() const
Number of columns.
Definition: field.h:176
GridPos
Structure to store a grid position.
Definition: interpolation.h:73
Field3D::operator=
Field3D< base > & operator=(Field3D &&g)=default
Default move operator.
Field3D
Creates a 3D field of a base unit.
Definition: field.h:33
Field3D::Field3D
Field3D(Field3D &&g)
Construct a new Field3D object.
Definition: field.h:67
Field3D::mpages
size_t mpages
Definition: field.h:35
GridPos::idx
Index idx
Definition: interpolation.h:74
Field3D::operator()
base operator()(const GridPos &page={0, {0, 1}}, const GridPos &row={0, {0, 1}}, const GridPos &col={0, {0, 1}}) const
Weighted access operator by GridPos.
Definition: field.h:133
Field3D::operator()
const base & operator()(size_t col=0, size_t row=0, size_t page=0) const
Access operator.
Definition: field.h:114