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>, ScaledMatrixTag>::BaseType(0,0,eFULL),
42  m_matrix(new typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::InnerType()),
43  m_scale(0)
44  {
45  }
46 
47  template<typename DataType, typename InnerMatrixType>
48  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NekMatrix(typename boost::call_traits<NumberType>::const_reference scale,
49  std::shared_ptr<const InnerType> m) :
50  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::BaseType(m->GetRows(), m->GetColumns(),m->GetStorageType()),
51  m_matrix(m),
52  m_scale(scale)
53  {
54  }
55 
56  template<typename DataType, typename InnerMatrixType>
59  m_matrix(rhs.m_matrix),
60  m_scale(rhs.m_scale)
61  {
62  }
63 
64 
65  template<typename DataType, typename InnerMatrixType>
66  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NekMatrix(
67  typename boost::call_traits<typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType>::const_reference scale, const NekMatrix<InnerType, ScaledMatrixTag>& rhs) :
69  m_matrix(rhs.m_matrix),
70  m_scale(scale)
71  {
72  }
73 
74  template<typename DataType, typename InnerMatrixType>
76  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::operator()(unsigned int row, unsigned int col) const
77  {
78  return m_scale*m_matrix->GetValue(row, col, this->GetTransposeFlag());
79  }
80 
81  template<typename DataType, typename InnerMatrixType>
82  unsigned int NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetStorageSize() const
83  {
84  return m_matrix->GetStorageSize();
85  }
86 
87  template<typename DataType, typename InnerMatrixType>
88  typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType
89  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::Scale() const
90  {
91  return m_scale*m_matrix->Scale();
92  }
93 
94  template<typename DataType, typename InnerMatrixType>
95  void NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::SetScale(const NumberType& value)
96  {
97  m_scale = value;
98  }
99 
100  template<typename DataType, typename InnerMatrixType>
101  const typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType*
102  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetRawPtr() const { return m_matrix->GetRawPtr(); }
103 
104  template<typename DataType, typename InnerMatrixType>
105  std::shared_ptr<const typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::InnerType>
106  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetOwnedMatrix() const
107  {
108  return m_matrix;
109  }
110 
111  template<typename DataType, typename InnerMatrixType>
112  unsigned int NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetNumberOfSubDiagonals() const { return m_matrix->GetNumberOfSubDiagonals(); }
113 
114  template<typename DataType, typename InnerMatrixType>
115  unsigned int NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetNumberOfSuperDiagonals() const { return m_matrix->GetNumberOfSuperDiagonals(); }
116 
117  template<typename DataType, typename InnerMatrixType>
118  typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator
119  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::begin() const { return const_iterator(m_matrix->begin(this->GetTransposeFlag()), m_scale); }
120 
121  template<typename DataType, typename InnerMatrixType>
122  typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator
123  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::end() const { return const_iterator(m_matrix->end(this->GetTransposeFlag()), m_scale); }
124 
125  template<typename DataType, typename InnerMatrixType>
126  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>
127  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::CreateWrapper(const NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>& rhs)
128  {
129  return NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>(rhs);
130  }
131 
132  template<typename DataType, typename InnerMatrixType>
133  std::shared_ptr<NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag> >
134  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::CreateWrapper(const std::shared_ptr<NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag> >& rhs)
135  {
136  return std::shared_ptr<ThisType>(new ThisType(*rhs));
137  }
138 
139 
140  template<typename DataType, typename InnerMatrixType>
141  typename boost::call_traits<typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType>::value_type
142  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::v_GetValue(unsigned int row, unsigned int column) const
143  {
144  return ThisType::operator()(row, column);
145  }
146 
147  template<typename DataType, typename InnerMatrixType>
148  unsigned int NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::v_GetStorageSize() const
149  {
150  return ThisType::GetStorageSize();
151  }
152 
153  template<typename DataType, typename InnerMatrixType>
154  char NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::v_GetTransposeFlag() const
155  {
156  if( this->GetRawTransposeFlag() == 'N' )
157  {
158  return m_matrix->GetTransposeFlag();
159  }
160  else
161  {
162  if( m_matrix->GetTransposeFlag() == 'N' )
163  {
164  return 'T';
165  }
166  else
167  {
168  return 'N';
169  }
170  }
171  }
172 
173 
174 
175 
176  template<typename DataType>
179  {
181  result.Transpose();
182  return result;
183  }
184 
185 
186 // template<typename DataType, typename InnerMatrixType>
187 // NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::const_iterator(
188 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::InnerType::const_iterator iter,
189 // const typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType& scale) :
190 // m_iter(iter),
191 // m_scale(scale)
192 // {
193 // }
194 
195 // template<typename DataType, typename InnerMatrixType>
196 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator++(int)
197 // {
198 // const_iterator out = *this;
199 // ++m_iter;
200 // return out;
201 // }
202 
203 // template<typename DataType, typename InnerMatrixType>
204 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator& NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator++()
205 // {
206 // ++m_iter;
207 // return *this;
208 // }
209 
210 // template<typename DataType, typename InnerMatrixType>
211 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType
212 // NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator*()
213 // {
214 // return m_scale*(*m_iter);
215 // }
216 
217 // template<typename DataType, typename InnerMatrixType>
218 // bool NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator==(const NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator& rhs)
219 // {
220 // return m_iter == rhs.m_iter;
221 // }
222 
223 // template<typename DataType, typename InnerMatrixType>
224 // bool NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator!=(const NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator& rhs)
225 // {
226 // return !(*this == rhs);
227 // }
228 
229 
230 
232 
233  template
236 
237  template<typename DataType>
239  {
240  v.SetScale(-1.0*v.Scale());
241  }
242 
244 }
245 
std::remove_const< typename InnerType::NumberType >::type NumberType
#define LIB_UTILITIES_EXPORT
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
void NegateInPlace(NekVector< DataType > &v)
Definition: NekVector.cpp:959