ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkFEMLinearSystemWrapperItpack.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef itkFEMLinearSystemWrapperItpack_h
20 #define itkFEMLinearSystemWrapperItpack_h
21 
22 #include "itkFEMSolution.h"
25 #include "ITKFEMExport.h"
26 #include <vector>
27 
31 typedef long integer;
32 typedef double doublereal;
33 
34 extern "C" {
35 typedef
36 int ( *ItkItpackSolverFunction )(integer *, integer *, integer *, doublereal *, doublereal *, doublereal *, integer *,
37  integer *, doublereal *,
38  integer *, doublereal *, integer *);
39 }
40 
41 namespace itk
42 {
43 namespace fem
44 {
52 class ITKFEM_EXPORT LinearSystemWrapperItpack : public LinearSystemWrapper
53 {
54 public:
55 
58 
61 
64 
66  typedef std::vector<MatrixRepresentation> MatrixHolder;
67 
68  /* auto pointer to vector of matrices typedef */
69  /* typedef std::auto_ptr<MatrixHolder> MatrixArrayPtr; */
70 
72  /* typedef std::auto_ptr<double> VectorRepresentation; */
73  typedef double *VectorRepresentation;
74 
76  typedef std::vector<VectorRepresentation> VectorHolder;
77 
78  /* auto pointer to vector of vectors typedef */
79  /* typedef std::auto_ptr<VectorHolder> VectorArrayPtr; */
80 
81  /* pointer to array of unsigned int typedef */
82  /* typedef std::auto_ptr<unsigned int> UnsignedIntegerArrayPtr; */
83 
84  /* -----------------------------------------------------------------
85  *
86  * Routines for setting/reporting itpack parameters
87  *
88  * -----------------------------------------------------------------
89  */
90 
96  {
97  m_IPARM[0] = i;
98  }
99 
104  {
105  return m_IPARM[0];
106  }
107 
108  // void SetErrorReportingLevel(int i) { m_IPARM[1] = i; }
109 
114  {
115  return m_IPARM[1];
116  }
117 
123  {
124  m_IPARM[2] = i;
125  }
126 
131  {
132  return m_IPARM[2];
133  }
134 
135  // void SetOutputNumber(int i) { m_IPARM[3] = i; }
136 
140  int GetOutputNumber() const
141  {
142  return m_IPARM[3];
143  }
144 
150  {
151  m_IPARM[4] = i;
152  }
153 
158  {
159  return m_IPARM[4];
160  }
161 
166  void SetAdaptiveSwitch(int i)
167  {
168  m_IPARM[5] = i;
169  }
170 
174  int GetAdaptiveSwitch() const
175  {
176  return m_IPARM[5];
177  }
178 
184  {
185  m_IPARM[6] = i;
186  }
187 
192  {
193  return m_IPARM[6];
194  }
195 
201  void SetWorkspaceUsed(int i)
202  {
203  m_IPARM[7] = i;
204  }
205 
211  {
212  return m_IPARM[7];
213  }
214 
220  {
221  m_IPARM[8] = i;
222  }
223 
228  {
229  return m_IPARM[8];
230  }
231 
236  void SetRemoveSwitch(int i)
237  {
238  m_IPARM[9] = i;
239  }
240 
245  {
246  return m_IPARM[9];
247  }
248 
253  void SetTimingSwitch(int i)
254  {
255  m_IPARM[10] = i;
256  }
257 
262  {
263  return m_IPARM[10];
264  }
265 
271  {
272  m_IPARM[11] = i;
273  }
274 
279  {
280  return m_IPARM[11];
281  }
282 
287  void SetAccuracy(double i)
288  {
289  m_RPARM[0] = i;
290  }
291 
295  double GetAccuracy() const
296  {
297  return m_RPARM[0];
298  }
299 
305  {
306  m_RPARM[1] = i;
307  }
308 
313  {
314  return m_RPARM[1];
315  }
316 
322  {
323  m_RPARM[2] = i;
324  }
325 
330  {
331  return m_RPARM[2];
332  }
333 
338  void SetDampingFactor(double i)
339  {
340  m_RPARM[3] = i;
341  }
342 
346  double GetDampingFactor() const
347  {
348  return m_RPARM[3];
349  }
350 
356  {
357  m_RPARM[4] = i;
358  }
359 
364  {
365  return m_RPARM[4];
366  }
367 
373  {
374  m_RPARM[5] = i;
375  }
376 
381  {
382  return m_RPARM[5];
383  }
384 
390  {
391  m_RPARM[6] = i;
392  }
393 
398  {
399  return m_RPARM[6];
400  }
401 
406  void SetTolerance(double i)
407  {
408  m_RPARM[7] = i;
409  }
410 
414  double GetTolerance()
415  {
416  return m_RPARM[7];
417  }
418 
423  void SetTimeToConvergence(double i)
424  {
425  m_RPARM[8] = i;
426  }
427 
432  {
433  return m_RPARM[8];
434  }
435 
440  void SetTimeForCall(double i)
441  {
442  m_RPARM[9] = i;
443  }
444 
448  double GetTimeForCall()
449  {
450  return m_RPARM[9];
451  }
452 
457  void SetDigitsInError(double i)
458  {
459  m_RPARM[10] = i;
460  }
461 
465  double GetDigitsInError() const
466  {
467  return m_RPARM[10];
468  }
469 
474  void SetDigitsInResidual(double i)
475  {
476  m_RPARM[11] = i;
477  }
478 
482  double GetDigitsInResidual() const
483  {
484  return m_RPARM[11];
485  }
486 
491  {
492  m_Method = 0;
493  }
494 
499  {
500  m_Method = 1;
501  }
502 
507  {
508  m_Method = 2;
509  }
510 
516  {
517  m_Method = 3;
518  }
519 
525  {
526  m_Method = 4;
527  }
528 
533  {
534  m_Method = 5;
535  }
536 
540  {
541  m_Method = 6;
542  }
543 
556  virtual void SetMaximumNonZeroValuesInMatrix(unsigned int maxNonZeroValues)
557  {
558  m_MaximumNonZeroValues =
559  maxNonZeroValues;
560  }
561 
562  virtual void ScaleMatrix(Float scale, unsigned int matrixIndex) ITK_OVERRIDE;
563 
575 
580 
581  /* memory management routines */
582  virtual void InitializeMatrix(unsigned int matrixIndex) ITK_OVERRIDE;
583 
584  virtual bool IsMatrixInitialized(unsigned int matrixIndex) ITK_OVERRIDE;
585 
586  virtual void DestroyMatrix(unsigned int matrixIndex) ITK_OVERRIDE;
587 
588  virtual void InitializeVector(unsigned int vectorIndex) ITK_OVERRIDE;
589 
590  virtual bool IsVectorInitialized(unsigned int vectorIndex) ITK_OVERRIDE;
591 
592  virtual void DestroyVector(unsigned int vectorIndex) ITK_OVERRIDE;
593 
594  virtual void InitializeSolution(unsigned int solutionIndex) ITK_OVERRIDE;
595 
596  virtual bool IsSolutionInitialized(unsigned int solutionIndex) ITK_OVERRIDE;
597 
598  virtual void DestroySolution(unsigned int solutionIndex) ITK_OVERRIDE;
599 
600  /* assembly & solving routines */
601  virtual Float GetMatrixValue(unsigned int i, unsigned int j, unsigned int matrixIndex) const ITK_OVERRIDE;
602 
603  virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE;
604 
605  virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE;
606 
607  virtual void GetColumnsOfNonZeroMatrixElementsInRow(unsigned int row, ColumnArray & cols, unsigned int matrixIndex) ITK_OVERRIDE;
608 
609  virtual Float GetVectorValue(unsigned int i, unsigned int vectorIndex) const ITK_OVERRIDE;
610 
611  virtual void SetVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE;
612 
613  virtual void AddVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE;
614 
615  virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const ITK_OVERRIDE;
616 
617  virtual void SetSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE;
618 
619  virtual void AddSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE;
620 
621  virtual void Solve(void) ITK_OVERRIDE;
622 
623  /* matrix & vector manipulation routines */
624  virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE;
625 
626  virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE;
627 
628  virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE;
629 
630  virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE;
631 
632  virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE;
633 
634  virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex,
635  unsigned int rightMatrixIndex) ITK_OVERRIDE;
636 
637  virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE;
638 
645  virtual void MultiplyMatrixSolution(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int solutionIndex) ITK_OVERRIDE;
646 
647 private:
648 
650  MatrixHolder *m_Matrices;
651 
653  VectorHolder *m_Vectors;
654 
656  VectorHolder *m_Solutions;
657 
660  // UnsignedIntegerArrayPtr m_MaximumNonZeroValues;
661  unsigned int m_MaximumNonZeroValues;
662 
665 
667  integer m_Method;
668 
670  integer m_IPARM[12];
671 
673  doublereal m_RPARM[12];
674 };
675 
683 class ITK_ABI_EXPORT FEMExceptionItpackSolver : public FEMException
684 {
685 public:
686 
688  typedef long integer;
689 
695  FEMExceptionItpackSolver(const char *file, unsigned int lineNumber, std::string location, integer errorCode);
696 
698  virtual ~FEMExceptionItpackSolver() ITK_NOEXCEPT
699  {
700  }
701 
703  itkTypeMacro(FEMExceptionItpackSolver, FEMException);
704 };
705 }
706 } // end namespace itk::fem
707 
708 #endif // #ifndef itkFEMLinearSystemWrapperItpack_h
int(* ItkItpackSolverFunction)(integer *, integer *, integer *, doublereal *, doublereal *, doublereal *, integer *, integer *, doublereal *, integer *, doublereal *, integer *)
handles errors that occur in itpack solving routines
std::vector< MatrixRepresentation > MatrixHolder
a compressed row sparse matrix representation that makes use of itpack to dynamically assemble the ma...
std::vector< VectorRepresentation > VectorHolder
Defines all functions required by Solver class to allocate, assemble and solve a linear system of equ...
LinearSystemWrapper class that uses Itpack numeric library functions to define and solve a sparse lin...
Base class for all exception&#39;s that can occur within FEM classes.
virtual void SetMaximumNonZeroValuesInMatrix(unsigned int maxNonZeroValues)