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
39namespace Nektar
40{
41template <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
51template <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
62template <typename DataType, typename InnerMatrixType>
63NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::NekMatrix(
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
71template <typename DataType, typename InnerMatrixType>
72NekMatrix<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
83template <typename DataType, typename InnerMatrixType>
84typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
85 ScaledMatrixTag>::ConstGetValueType
87 unsigned int row, unsigned int col) const
88{
89 return m_scale * m_matrix->GetValue(row, col, this->GetTransposeFlag());
90}
91
92template <typename DataType, typename InnerMatrixType>
94 ScaledMatrixTag>::GetStorageSize() const
95{
96 return m_matrix->GetStorageSize();
97}
98
99template <typename DataType, typename InnerMatrixType>
101 ScaledMatrixTag>::NumberType
103{
104 return m_scale * m_matrix->Scale();
105}
106
107template <typename DataType, typename InnerMatrixType>
108void NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::SetScale(
109 const NumberType &value)
110{
111 m_scale = value;
112}
113
114template <typename DataType, typename InnerMatrixType>
116 ScaledMatrixTag>::NumberType *
118 const
119{
120 return m_matrix->GetRawPtr();
121}
122
123template <typename DataType, typename InnerMatrixType>
124std::shared_ptr<const typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
125 ScaledMatrixTag>::InnerType>
127 ScaledMatrixTag>::GetOwnedMatrix() const
128{
129 return m_matrix;
130}
131
132template <typename DataType, typename InnerMatrixType>
134 ScaledMatrixTag>::GetNumberOfSubDiagonals() const
135{
136 return m_matrix->GetNumberOfSubDiagonals();
137}
138
139template <typename DataType, typename InnerMatrixType>
141 ScaledMatrixTag>::GetNumberOfSuperDiagonals() const
142{
143 return m_matrix->GetNumberOfSuperDiagonals();
144}
145
146template <typename DataType, typename InnerMatrixType>
148 ScaledMatrixTag>::const_iterator
150{
151 return const_iterator(m_matrix->begin(this->GetTransposeFlag()), m_scale);
152}
153
154template <typename DataType, typename InnerMatrixType>
156 ScaledMatrixTag>::const_iterator
158{
159 return const_iterator(m_matrix->end(this->GetTransposeFlag()), m_scale);
160}
161
162template <typename DataType, typename InnerMatrixType>
164 NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>::
166 ScaledMatrixTag> &rhs)
167{
168 return NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>(
169 rhs);
170}
171
172template <typename DataType, typename InnerMatrixType>
173std::shared_ptr<
174 NekMatrix<NekMatrix<DataType, InnerMatrixType>, ScaledMatrixTag>>
175NekMatrix<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
182template <typename DataType, typename InnerMatrixType>
183typename 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
192template <typename DataType, typename InnerMatrixType>
194 ScaledMatrixTag>::v_GetStorageSize() const
195{
196 return ThisType::GetStorageSize();
197}
198
199template <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
220template <typename DataType>
223{
225 result.Transpose();
226 return result;
227}
228
229template LIB_UTILITIES_EXPORT class NekMatrix<
230 NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag>;
231
232template LIB_UTILITIES_EXPORT NekMatrix<NekMatrix<NekDouble, StandardMatrixTag>,
233 ScaledMatrixTag>
236
237template <typename DataType>
239{
240 v.SetScale(-1.0 * v.Scale());
241}
242
245
246template LIB_UTILITIES_EXPORT class NekMatrix<
248
250 ScaledMatrixTag>
253
256} // namespace Nektar
#define LIB_UTILITIES_EXPORT
std::remove_const< typenameInnerType::NumberType >::type NumberType
void NegateInPlace(NekVector< DataType > &v)
Definition: NekVector.cpp:1160
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)