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