Cantera  2.1.2
vcs_DoubleStarStar.cpp
Go to the documentation of this file.
1 /**
2  * @file vcs_DoubleStarStar.cpp
3  *
4  * Implementation file for class DoubleStarStar
5  */
7 
8 namespace VCSnonideal
9 {
10 
12  m_nrows(0),
13  m_ncols(0)
14 {
15  m_data.clear();
16  m_colAddr.clear();
17 }
18 
19 DoubleStarStar::DoubleStarStar(size_t m, size_t n, double v) :
20  m_nrows(n),
21  m_ncols(m)
22 {
23  m_data.resize(n*m);
24  std::fill(m_data.begin(), m_data.end(), v);
25  m_colAddr.resize(m);
26  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
27  m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
28  }
29 }
30 
32 {
33  m_nrows = y.m_nrows;
34  m_ncols = y.m_ncols;
35  m_data.resize(m_nrows*m_ncols);
36  m_data = y.m_data;
37  m_colAddr.resize(m_ncols);
38  if (!m_data.empty()) {
39  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
40  m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
41  }
42  }
43 }
44 
45 DoubleStarStar& DoubleStarStar::operator=(const DoubleStarStar& y)
46 {
47  if (&y == this) {
48  return *this;
49  }
50  m_nrows = y.m_nrows;
51  m_ncols = y.m_ncols;
52  m_data.resize(m_nrows*m_ncols);
53  m_data = y.m_data;
54  m_colAddr.resize(m_ncols);
55  if (!m_data.empty()) {
56  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
57  m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
58  }
59  }
60  return *this;
61 }
62 
63 void DoubleStarStar::resize(size_t m, size_t n, double v)
64 {
65  std::vector<double> old_data;
66  bool doCopy = false;
67  if (m_nrows > 0 && m_ncols > 0) {
68  if (m_nrows != n) {
69  doCopy = true;
70  old_data = m_data;
71  }
72  }
73  m_data.resize(n*m, v);
74  if (doCopy) {
75  if (n >= m_nrows && m >= m_ncols) {
76  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
77  for (size_t irow = 0; irow < m_nrows; irow++) {
78  m_data[jcol*n + irow] = old_data[jcol*m_nrows + irow];
79  }
80  for (size_t irow = m_nrows; irow < n; irow++) {
81  m_data[jcol*n + irow] = v;
82  }
83  }
84  for (size_t jcol = m_ncols; jcol < m; jcol++) {
85  for (size_t irow = 0; irow < n; irow++) {
86  m_data[jcol*n + irow] = v;
87  }
88  }
89  } else {
90  std::fill(m_data.begin(), m_data.end(), v);
91  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
92  for (size_t irow = 0; irow < m_nrows; irow++) {
93  m_data[jcol*n + irow] = old_data[jcol*m_nrows + irow];
94  }
95  }
96  }
97  }
98  m_nrows = n;
99  m_ncols = m;
100  m_colAddr.resize(m_ncols);
101  if (!m_data.empty()) {
102  for (size_t jcol = 0; jcol < m_ncols; jcol++) {
103  m_colAddr[jcol] = &(m_data[jcol*m_nrows]);
104  }
105  }
106 }
107 
108 double* DoubleStarStar::operator[](size_t jcol)
109 {
110  return m_colAddr[jcol];
111 }
112 
113 const double* DoubleStarStar::operator[](size_t jcol) const
114 {
115  return (const double*) m_colAddr[jcol];
116 }
117 
119 {
120  return (double* const*) &(m_colAddr[0]);
121 }
122 
123 double const* const* DoubleStarStar::constBaseDataAddr() const
124 {
125  return (double const* const*) &(m_colAddr[0]);
126 }
127 
128 size_t DoubleStarStar::nRows() const
129 {
130  return m_nrows;
131 }
132 
134 {
135  return m_ncols;
136 }
137 
138 }
DoubleStarStar()
Default constructor. Create an empty array.
size_t nColumns() const
Number of columns.
double *const * baseDataAddr()
Returns a double** pointer to the base address.
Header file for class DoubleStarStar.
void resize(size_t mcol, size_t nrow, double v=0.0)
Resize the array, and fill the new entries with v
std::vector< double * > m_colAddr
Vector of addresses for the top of the columns.
double * operator[](size_t jcol)
Pointer to the top of the column.
size_t m_ncols
number of columns
double const *const * constBaseDataAddr() const
Returns a const double** pointer to the base address.
size_t m_nrows
number of rows
size_t nRows() const
Number of rows.
A class for 2D double arrays stored in column-major (Fortran-compatible) form.
std::vector< double > m_data
Storage area.