Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Static Public Member Functions | List of all members
Nektar::LinearSystemSolver Struct Reference

#include <NekLinSys.hpp>

Static Public Member Functions

template<typename BVectorType , typename XVectorType >
static void Solve (const BVectorType &b, XVectorType &x, MatrixStorage m_matrixType, const Array< OneD, const int > &m_ipivot, unsigned int n, const Array< OneD, const double > &A, char m_transposeFlag, unsigned int m_numberOfSubDiagonals, unsigned int m_numberOfSuperDiagonals)
 
template<typename BVectorType , typename XVectorType >
static void SolveTranspose (const BVectorType &b, XVectorType &x, MatrixStorage m_matrixType, const Array< OneD, const int > &m_ipivot, unsigned int n, const Array< OneD, const double > &A, char m_transposeFlag, unsigned int m_numberOfSubDiagonals, unsigned int m_numberOfSuperDiagonals)
 

Detailed Description

Definition at line 72 of file NekLinSys.hpp.

Member Function Documentation

template<typename BVectorType , typename XVectorType >
static void Nektar::LinearSystemSolver::Solve ( const BVectorType &  b,
XVectorType &  x,
MatrixStorage  m_matrixType,
const Array< OneD, const int > &  m_ipivot,
unsigned int  n,
const Array< OneD, const double > &  A,
char  m_transposeFlag,
unsigned int  m_numberOfSubDiagonals,
unsigned int  m_numberOfSuperDiagonals 
)
inlinestatic

Definition at line 75 of file NekLinSys.hpp.

References ASSERTL0, Nektar::eBANDED, Nektar::eDIAGONAL, ErrorUtil::efatal, Nektar::eFULL, Nektar::eLOWER_TRIANGULAR, Nektar::eLOWER_TRIANGULAR_BANDED, Nektar::ePOSITIVE_DEFINITE_SYMMETRIC, Nektar::ePOSITIVE_DEFINITE_SYMMETRIC_BANDED, Nektar::eSYMMETRIC, Nektar::eSYMMETRIC_BANDED, Nektar::eUPPER_TRIANGULAR, Nektar::eUPPER_TRIANGULAR_BANDED, and NEKERROR.

Referenced by Nektar::LinearSystem::Solve(), and SolveTranspose().

80  {
81  switch(m_matrixType)
82  {
83  case eFULL:
84  {
85  x = b;
86  int info = 0;
87  Lapack::Dgetrs('N',n,1,A.get(),n,(int *)m_ipivot.get(),x.GetRawPtr(),n,info);
88  if( info < 0 )
89  {
90  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dgetrs";
91  ASSERTL0(false, message.c_str());
92  }
93 
94  }
95  break;
96  case eDIAGONAL:
97  for(unsigned int i = 0; i < A.num_elements(); ++i)
98  {
99  x[i] = b[i]*A[i];
100  }
101  break;
102  case eUPPER_TRIANGULAR:
103  {
104  x = b;
105  int info = 0;
106  Lapack::Dtptrs('U', m_transposeFlag, 'N', n, 1, A.get(), x.GetRawPtr(), n, info);
107 
108  if( info < 0 )
109  {
110  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dtrtrs";
111  ASSERTL0(false, message.c_str());
112  }
113  else if( info > 0 )
114  {
115  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th diagonal element of A is 0 for dtrtrs";
116  ASSERTL0(false, message.c_str());
117  }
118  }
119  break;
120  case eLOWER_TRIANGULAR:
121  {
122  x = b;
123  int info = 0;
124  Lapack::Dtptrs('L', m_transposeFlag, 'N', n, 1, A.get(), x.GetRawPtr(), n, info);
125 
126  if( info < 0 )
127  {
128  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dtrtrs";
129  ASSERTL0(false, message.c_str());
130  }
131  else if( info > 0 )
132  {
133  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th diagonal element of A is 0 for dtrtrs";
134  ASSERTL0(false, message.c_str());
135  }
136  }
137  break;
138  case eSYMMETRIC:
139  {
140  x = b;
141  int info = 0;
142  Lapack::Dsptrs('U', n, 1, A.get(), m_ipivot.get(), x.GetRawPtr(), x.GetRows(), info);
143  if( info < 0 )
144  {
145  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dsptrs";
146  ASSERTL0(false, message.c_str());
147  }
148  }
149  break;
151  {
152  x = b;
153  int info = 0;
154  Lapack::Dpptrs('U', n, 1, A.get(), x.GetRawPtr(), x.GetRows(), info);
155  if( info < 0 )
156  {
157  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dpptrs";
158  ASSERTL0(false, message.c_str());
159  }
160  }
161  break;
162  case eBANDED:
163  {
164  x = b;
165  int KL = m_numberOfSubDiagonals;
166  int KU = m_numberOfSuperDiagonals;
167  int info = 0;
168 
169  Lapack::Dgbtrs(m_transposeFlag, n, KL, KU, 1, A.get(), 2*KL+KU+1, m_ipivot.get(), x.GetRawPtr(), n, info);
170 
171  if( info < 0 )
172  {
173  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dgbtrs";
174  ASSERTL0(false, message.c_str());
175  }
176  }
177  break;
179  {
180  x = b;
181  int KU = m_numberOfSuperDiagonals;
182  int info = 0;
183 
184  Lapack::Dpbtrs('U', n, KU, 1, A.get(), KU+1, x.GetRawPtr(), n, info);
185 
186  if( info < 0 )
187  {
188  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dpbtrs";
189  ASSERTL0(false, message.c_str());
190  }
191  }
192  break;
193  case eSYMMETRIC_BANDED:
194  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
195  break;
197  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
198  break;
200  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
201  break;
202 
203  default:
204  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
205  }
206 
207  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:185
template<typename BVectorType , typename XVectorType >
static void Nektar::LinearSystemSolver::SolveTranspose ( const BVectorType &  b,
XVectorType &  x,
MatrixStorage  m_matrixType,
const Array< OneD, const int > &  m_ipivot,
unsigned int  n,
const Array< OneD, const double > &  A,
char  m_transposeFlag,
unsigned int  m_numberOfSubDiagonals,
unsigned int  m_numberOfSuperDiagonals 
)
inlinestatic

Definition at line 210 of file NekLinSys.hpp.

References ASSERTL0, Nektar::eBANDED, Nektar::eDIAGONAL, ErrorUtil::efatal, Nektar::eFULL, Nektar::eLOWER_TRIANGULAR, Nektar::eLOWER_TRIANGULAR_BANDED, Nektar::ePOSITIVE_DEFINITE_SYMMETRIC, Nektar::ePOSITIVE_DEFINITE_SYMMETRIC_BANDED, Nektar::eSYMMETRIC, Nektar::eSYMMETRIC_BANDED, Nektar::eUPPER_TRIANGULAR, Nektar::eUPPER_TRIANGULAR_BANDED, NEKERROR, and Solve().

Referenced by Nektar::LinearSystem::SolveTranspose().

215  {
216  switch(m_matrixType)
217  {
218  case eFULL:
219  {
220  x = b;
221  int info = 0;
222  Lapack::Dgetrs('T',n,1,A.get(),n,(int *)m_ipivot.get(),x.GetRawPtr(), n,info);
223 
224  if( info < 0 )
225  {
226  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dgetrs";
227  ASSERTL0(false, message.c_str());
228  }
229  }
230 
231  break;
232  case eDIAGONAL:
233  Solve(b, x, m_matrixType, m_ipivot, n, A, m_transposeFlag, m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
234  break;
235  case eUPPER_TRIANGULAR:
236  {
237  char trans = m_transposeFlag;
238  if( trans == 'N' )
239  {
240  trans = 'T';
241  }
242  else
243  {
244  trans = 'N';
245  }
246 
247  x = b;
248  int info = 0;
249  Lapack::Dtptrs('U', trans, 'N', n, 1, A.get(), x.GetRawPtr(), n, info);
250 
251  if( info < 0 )
252  {
253  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dtrtrs";
254  ASSERTL0(false, message.c_str());
255  }
256  else if( info > 0 )
257  {
258  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th diagonal element of A is 0 for dtrtrs";
259  ASSERTL0(false, message.c_str());
260  }
261  }
262 
263  break;
264  case eLOWER_TRIANGULAR:
265  {
266  char trans = m_transposeFlag;
267  if( trans == 'N' )
268  {
269  trans = 'T';
270  }
271  else
272  {
273  trans = 'N';
274  }
275  x = b;
276  int info = 0;
277  Lapack::Dtptrs('L', trans, 'N', n, 1, A.get(), x.GetRawPtr(), n, info);
278 
279  if( info < 0 )
280  {
281  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dtrtrs";
282  ASSERTL0(false, message.c_str());
283  }
284  else if( info > 0 )
285  {
286  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th diagonal element of A is 0 for dtrtrs";
287  ASSERTL0(false, message.c_str());
288  }
289  }
290  break;
291  case eSYMMETRIC:
294  Solve(b, x, m_matrixType, m_ipivot, n, A, m_transposeFlag, m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
295  break;
296  case eBANDED:
297  {
298  x = b;
299  int KL = m_numberOfSubDiagonals;
300  int KU = m_numberOfSuperDiagonals;
301  int info = 0;
302 
303  Lapack::Dgbtrs(m_transposeFlag, n, KL, KU, 1, A.get(), 2*KL+KU+1, m_ipivot.get(), x.GetRawPtr(), n, info);
304 
305  if( info < 0 )
306  {
307  std::string message = "ERROR: The " + boost::lexical_cast<std::string>(-info) + "th parameter had an illegal parameter for dgbtrs";
308  ASSERTL0(false, message.c_str());
309  }
310  }
311  break;
312  case eSYMMETRIC_BANDED:
313  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
314  break;
316  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
317  break;
319  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
320  break;
321 
322  default:
323  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
324  }
325  }
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:188
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mod...
Definition: ErrorUtil.hpp:185
static void Solve(const BVectorType &b, XVectorType &x, MatrixStorage m_matrixType, const Array< OneD, const int > &m_ipivot, unsigned int n, const Array< OneD, const double > &A, char m_transposeFlag, unsigned int m_numberOfSubDiagonals, unsigned int m_numberOfSuperDiagonals)
Definition: NekLinSys.hpp:75