Nektar++
ScaledMatrix.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ScaledMatrix.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description:
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
38 
39 namespace Nektar
40 {
41 template <typename DataType, typename InnerMatrixType>
43  : NekMatrix<NekMatrix<DataType, InnerMatrixType>,
44  ScaledMatrixTag>::BaseType(0, 0, eFULL),
45  m_matrix(new typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
46  ScaledMatrixTag>::InnerType()),
47  m_scale(0)
48 {
49 }
50 
51 template <typename DataType, typename InnerMatrixType>
53  typename boost::call_traits<NumberType>::const_reference scale,
54  std::shared_ptr<const InnerType> m)
55  : NekMatrix<NekMatrix<DataType, InnerMatrixType>,
56  ScaledMatrixTag>::BaseType(m->GetRows(), m->GetColumns(),
57  m->GetStorageType()),
58  m_matrix(m), m_scale(scale)
59 {
60 }
61 
62 template <typename DataType, typename InnerMatrixType>
64  const NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag> &rhs)
65  : NekMatrix<NekMatrix<DataType, InnerMatrixType>,
66  ScaledMatrixTag>::BaseType(rhs),
67  m_matrix(rhs.m_matrix), m_scale(rhs.m_scale)
68 {
69 }
70 
71 template <typename DataType, typename InnerMatrixType>
72 NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::NekMatrix(
73  typename boost::call_traits<
74  typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
75  ScaledMatrixTag>::NumberType>::const_reference scale,
76  const NekMatrix<InnerType, ScaledMatrixTag> &rhs)
77  : NekMatrix<NekMatrix<DataType, InnerMatrixType>,
78  ScaledMatrixTag>::BaseType(rhs),
79  m_matrix(rhs.m_matrix), m_scale(scale)
80 {
81 }
82 
83 template <typename DataType, typename InnerMatrixType>
84 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
85  ScaledMatrixTag>::ConstGetValueType
86 NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::operator()(
87  unsigned int row, unsigned int col) const
88 {
89  return m_scale * m_matrix->GetValue(row, col, this->GetTransposeFlag());
90 }
91 
92 template <typename DataType, typename InnerMatrixType>
94  ScaledMatrixTag>::GetStorageSize() const
95 {
96  return m_matrix->GetStorageSize();
97 }
98 
99 template <typename DataType, typename InnerMatrixType>
101  ScaledMatrixTag>::NumberType
102 NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::Scale() const
103 {
104  return m_scale * m_matrix->Scale();
105 }
106 
107 template <typename DataType, typename InnerMatrixType>
108 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::SetScale(
109  const NumberType &value)
110 {
111  m_scale = value;
112 }
113 
114 template <typename DataType, typename InnerMatrixType>
116  ScaledMatrixTag>::NumberType *
118  const
119 {
120  return m_matrix->GetRawPtr();
121 }
122 
123 template <typename DataType, typename InnerMatrixType>
124 std::shared_ptr<const typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
125  ScaledMatrixTag>::InnerType>
127  ScaledMatrixTag>::GetOwnedMatrix() const
128 {
129  return m_matrix;
130 }
131 
132 template <typename DataType, typename InnerMatrixType>
134  ScaledMatrixTag>::GetNumberOfSubDiagonals() const
135 {
136  return m_matrix->GetNumberOfSubDiagonals();
137 }
138 
139 template <typename DataType, typename InnerMatrixType>
141  ScaledMatrixTag>::GetNumberOfSuperDiagonals() const
142 {
143  return m_matrix->GetNumberOfSuperDiagonals();
144 }
145 
146 template <typename DataType, typename InnerMatrixType>
148  ScaledMatrixTag>::const_iterator
149 NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::begin() const
150 {
151  return const_iterator(m_matrix->begin(this->GetTransposeFlag()), m_scale);
152 }
153 
154 template <typename DataType, typename InnerMatrixType>
156  ScaledMatrixTag>::const_iterator
158 {
159  return const_iterator(m_matrix->end(this->GetTransposeFlag()), m_scale);
160 }
161 
162 template <typename DataType, typename InnerMatrixType>
164  NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::
166  ScaledMatrixTag> &rhs)
167 {
168  return NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>(
169  rhs);
170 }
171 
172 template <typename DataType, typename InnerMatrixType>
173 std::shared_ptr<
174  NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>>
175 NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::CreateWrapper(
176  const std::shared_ptr<
177  NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>> &rhs)
178 {
179  return std::shared_ptr<ThisType>(new ThisType(*rhs));
180 }
181 
182 template <typename DataType, typename InnerMatrixType>
183 typename boost::call_traits<
184  typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
185  ScaledMatrixTag>::NumberType>::value_type
187  unsigned int row, unsigned int column) const
188 {
189  return ThisType::operator()(row, column);
190 }
191 
192 template <typename DataType, typename InnerMatrixType>
194  ScaledMatrixTag>::v_GetStorageSize() const
195 {
196  return ThisType::GetStorageSize();
197 }
198 
199 template <typename DataType, typename InnerMatrixType>
201  ScaledMatrixTag>::v_GetTransposeFlag() const
202 {
203  if (this->GetRawTransposeFlag() == 'N')
204  {
205  return m_matrix->GetTransposeFlag();
206  }
207  else
208  {
209  if (m_matrix->GetTransposeFlag() == 'N')
210  {
211  return 'T';
212  }
213  else
214  {
215  return 'N';
216  }
217  }
218 }
219 
220 template <typename DataType>
223 {
225  result.Transpose();
226  return result;
227 }
228 
229 // template<typename DataType, typename InnerMatrixType>
230 // NekMatrix<NekMatrix< DataType, InnerMatrixType>,
231 // ScaledMatrixTag>::const_iterator::const_iterator(
232 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>,
233 // ScaledMatrixTag>::InnerType::const_iterator iter, const typename
234 // NekMatrix<NekMatrix< DataType, InnerMatrixType>,
235 // ScaledMatrixTag>::NumberType& scale) :
236 // m_iter(iter),
237 // m_scale(scale)
238 // {
239 // }
240 
241 // template<typename DataType, typename InnerMatrixType>
242 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>,
243 // ScaledMatrixTag>::const_iterator NekMatrix<NekMatrix< DataType,
244 // InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator++(int)
245 // {
246 // const_iterator out = *this;
247 // ++m_iter;
248 // return out;
249 // }
250 
251 // template<typename DataType, typename InnerMatrixType>
252 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>,
253 // ScaledMatrixTag>::const_iterator& NekMatrix<NekMatrix< DataType,
254 // InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator++()
255 // {
256 // ++m_iter;
257 // return *this;
258 // }
259 
260 // template<typename DataType, typename InnerMatrixType>
261 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>,
262 // ScaledMatrixTag>::NumberType NekMatrix<NekMatrix< DataType,
263 // InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator*()
264 // {
265 // return m_scale*(*m_iter);
266 // }
267 
268 // template<typename DataType, typename InnerMatrixType>
269 // bool NekMatrix<NekMatrix< DataType, InnerMatrixType>,
270 // ScaledMatrixTag>::const_iterator::operator==(const NekMatrix<NekMatrix<
271 // DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator& rhs)
272 // {
273 // return m_iter == rhs.m_iter;
274 // }
275 
276 // template<typename DataType, typename InnerMatrixType>
277 // bool NekMatrix<NekMatrix< DataType, InnerMatrixType>,
278 // ScaledMatrixTag>::const_iterator::operator!=(const NekMatrix<NekMatrix<
279 // DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator& rhs)
280 // {
281 // return !(*this == rhs);
282 // }
283 
284 template LIB_UTILITIES_EXPORT class NekMatrix<
285  NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag>;
286 
287 template LIB_UTILITIES_EXPORT NekMatrix<NekMatrix<NekDouble, StandardMatrixTag>,
288  ScaledMatrixTag>
290  NekMatrix<NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag> &rhs);
291 
292 template <typename DataType>
294 {
295  v.SetScale(-1.0 * v.Scale());
296 }
297 
300 
301 template LIB_UTILITIES_EXPORT class NekMatrix<
302  NekMatrix<NekSingle, StandardMatrixTag>, ScaledMatrixTag>;
303 
305  ScaledMatrixTag>
307  NekMatrix<NekMatrix<NekSingle, StandardMatrixTag>, ScaledMatrixTag> &rhs);
308 
311 } // namespace Nektar
#define LIB_UTILITIES_EXPORT
std::remove_const< typename InnerType::NumberType >::type NumberType
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
void NegateInPlace(NekVector< DataType > &v)
Definition: NekVector.cpp:1160