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