PSCF v1.1
FMatrix.h
1#ifndef UTIL_F_MATRIX_H
2#define UTIL_F_MATRIX_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/containers/Matrix.h>
12
13namespace Util
14{
15
27 template <typename Data, int M, int N>
28 class FMatrix : public Matrix<Data>
29 {
30
31 using Matrix<Data>::data_;
32 using Matrix<Data>::capacity1_;
33 using Matrix<Data>::capacity2_;
34
35 public:
36
41
46
51
56
63 template <class Archive>
64 void serialize(Archive& ar, const unsigned int version);
65
66 private:
67
69 Data fixedArray_[M*N];
70
71 };
72
73 /*
74 * Default constructor.
75 */
76 template <typename Data, int M, int N>
78 : Matrix<Data>()
79 {
80 data_ = fixedArray_;
81 capacity1_ = M;
82 capacity2_ = N;
83 }
84
85 /*
86 * Copy constructor.
87 */
88 template <typename Data, int M, int N>
90 : Matrix<Data>()
91 {
92 data_ = fixedArray_;
93 capacity1_ = M;
94 capacity2_ = N;
95 for (int i = 0; i < M*N; ++i) {
96 fixedArray_[i] = other.fixedArray_[i];
97 }
98 }
99
100 /*
101 * Destructor.
102 */
103 template <typename Data, int M, int N>
105 {}
106
107 /*
108 * Assignment.
109 */
110 template <typename Data, int M, int N>
113 {
114 // Check for self assignment
115 if (this == &other) return *this;
116
117 // Copy all elements
118 for (int i = 0; i < M*N; ++i) {
119 fixedArray_[i] = other.fixedArray_[i];
120 }
121
122 return *this;
123 }
124
125 /*
126 * Serialize a FMatrix to/from an Archive.
127 */
128 template <class Data, int M, int N>
129 template <class Archive>
130 void
131 FMatrix<Data, M, N>::serialize(Archive& ar, const unsigned int version)
132 {
133 for (int i = 0; i < M*N; ++i) {
134 ar & fixedArray_[i];
135 }
136 }
137
138}
139#endif
Fixed Size Matrix.
Definition: FMatrix.h:29
~FMatrix()
Destructor.
Definition: FMatrix.h:104
FMatrix< Data, M, N > & operator=(FMatrix< Data, M, N > const &other)
Assignment.
Definition: FMatrix.h:112
FMatrix(FMatrix< Data, M, N > const &other)
Copy constructor.
Definition: FMatrix.h:89
void serialize(Archive &ar, const unsigned int version)
Serialize an FMatrix to/from an Archive.
Definition: FMatrix.h:131
FMatrix()
Default constructor.
Definition: FMatrix.h:77
Two-dimensional array container template (abstract).
Definition: Matrix.h:32
Data * data_
Pointer to 1D C array of all elements.
Definition: Matrix.h:84
int capacity2_
Number of columns (range of first index).
Definition: Matrix.h:90
int capacity1_
Number of rows (range of first index).
Definition: Matrix.h:87
Utility classes for scientific computation.
Definition: accumulators.mod:1