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 // License for the specific language governing rights and limitations under
12 // Permission is hereby granted, free of charge, to any person obtaining a
13 // copy of this software and associated documentation files (the "Software"),
14 // to deal in the Software without restriction, including without limitation
15 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 // and/or sell copies of the Software, and to permit persons to whom the
17 // Software is furnished to do so, subject to the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be included
20 // in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 // DEALINGS IN THE SOFTWARE.
29 //
30 // Description:
31 //
32 ///////////////////////////////////////////////////////////////////////////////
33 
36 
37 namespace Nektar
38 {
39  template<typename DataType, typename InnerMatrixType>
41  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::BaseType(0,0),
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  boost::shared_ptr<const InnerType> m) :
50  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::BaseType(m->GetRows(), m->GetColumns()),
51  m_matrix(m),
52  m_scale(scale)
53  {
54  }
55 
56  template<typename DataType, typename InnerMatrixType>
58  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::BaseType(rhs),
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) :
68  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::BaseType(rhs),
69  m_matrix(rhs.m_matrix),
70  m_scale(scale)
71  {
72  }
73 
74  template<typename DataType, typename InnerMatrixType>
75  typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::ConstGetValueType
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  MatrixStorage NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetType() const { return m_matrix->GetStorageType(); }
89 
90  template<typename DataType, typename InnerMatrixType>
91  typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType
92  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::Scale() const
93  {
94  return m_scale*m_matrix->Scale();
95  }
96 
97  template<typename DataType, typename InnerMatrixType>
98  void NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::SetScale(const NumberType& value)
99  {
100  m_scale = value;
101  }
102 
103  template<typename DataType, typename InnerMatrixType>
104  const typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType*
105  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetRawPtr() const { return m_matrix->GetRawPtr(); }
106 
107  template<typename DataType, typename InnerMatrixType>
108  boost::shared_ptr<const typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::InnerType>
109  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetOwnedMatrix() const
110  {
111  return m_matrix;
112  }
113 
114  template<typename DataType, typename InnerMatrixType>
115  unsigned int NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetNumberOfSubDiagonals() const { return m_matrix->GetNumberOfSubDiagonals(); }
116 
117  template<typename DataType, typename InnerMatrixType>
118  unsigned int NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::GetNumberOfSuperDiagonals() const { return m_matrix->GetNumberOfSuperDiagonals(); }
119 
120  template<typename DataType, typename InnerMatrixType>
121  typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator
122  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::begin() const { return const_iterator(m_matrix->begin(this->GetTransposeFlag()), m_scale); }
123 
124  template<typename DataType, typename InnerMatrixType>
125  typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator
126  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::end() const { return const_iterator(m_matrix->end(this->GetTransposeFlag()), m_scale); }
127 
128  template<typename DataType, typename InnerMatrixType>
129  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>
130  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::CreateWrapper(const NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>& rhs)
131  {
132  return NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>(rhs);
133  }
134 
135  template<typename DataType, typename InnerMatrixType>
136  boost::shared_ptr<NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag> >
137  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::CreateWrapper(const boost::shared_ptr<NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag> >& rhs)
138  {
139  return boost::shared_ptr<ThisType>(new ThisType(*rhs));
140  }
141 
142 
143  template<typename DataType, typename InnerMatrixType>
144  typename boost::call_traits<typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType>::value_type
145  NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::v_GetValue(unsigned int row, unsigned int column) const
146  {
147  return ThisType::operator()(row, column);
148  }
149 
150  template<typename DataType, typename InnerMatrixType>
151  unsigned int NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::v_GetStorageSize() const
152  {
153  return ThisType::GetStorageSize();
154  }
155 
156  template<typename DataType, typename InnerMatrixType>
157  MatrixStorage NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::v_GetStorageType() const
158  {
159  return ThisType::GetType();
160  }
161 
162  template<typename DataType, typename InnerMatrixType>
163  char NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::v_GetTransposeFlag() const
164  {
165  if( this->GetRawTransposeFlag() == 'N' )
166  {
167  return m_matrix->GetTransposeFlag();
168  }
169  else
170  {
171  if( m_matrix->GetTransposeFlag() == 'N' )
172  {
173  return 'T';
174  }
175  else
176  {
177  return 'N';
178  }
179  }
180  }
181 
182 
183 
184 
185  template<typename DataType>
188  {
190  result.Transpose();
191  return result;
192  }
193 
194 
195 // template<typename DataType, typename InnerMatrixType>
196 // NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::const_iterator(
197 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::InnerType::const_iterator iter,
198 // const typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType& scale) :
199 // m_iter(iter),
200 // m_scale(scale)
201 // {
202 // }
203 
204 // template<typename DataType, typename InnerMatrixType>
205 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator++(int)
206 // {
207 // const_iterator out = *this;
208 // ++m_iter;
209 // return out;
210 // }
211 
212 // template<typename DataType, typename InnerMatrixType>
213 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator& NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator++()
214 // {
215 // ++m_iter;
216 // return *this;
217 // }
218 
219 // template<typename DataType, typename InnerMatrixType>
220 // typename NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::NumberType
221 // NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator*()
222 // {
223 // return m_scale*(*m_iter);
224 // }
225 
226 // template<typename DataType, typename InnerMatrixType>
227 // bool NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator==(const NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator& rhs)
228 // {
229 // return m_iter == rhs.m_iter;
230 // }
231 
232 // template<typename DataType, typename InnerMatrixType>
233 // bool NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator::operator!=(const NekMatrix<NekMatrix< DataType, InnerMatrixType>, ScaledMatrixTag>::const_iterator& rhs)
234 // {
235 // return !(*this == rhs);
236 // }
237 
238 
239 
240  template LIB_UTILITIES_EXPORT class NekMatrix<NekMatrix< NekDouble, StandardMatrixTag>, ScaledMatrixTag>;
241 
242  template
243  LIB_UTILITIES_EXPORT NekMatrix< NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag>
244  Transpose(NekMatrix<NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag>& rhs);
245 
246  template<typename DataType>
248  {
249  v.SetScale(-1.0*v.Scale());
250  }
251 
252  template LIB_UTILITIES_EXPORT void NegateInPlace(NekMatrix<NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag>& v);
253 }
254 
boost::remove_const< typename InnerType::NumberType >::type NumberType
#define LIB_UTILITIES_EXPORT
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
void NegateInPlace(NekVector< DataType > &v)
Definition: NekVector.cpp:962