ITK  4.6.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 <vector>
26 
30 typedef long integer;
31 typedef double doublereal;
32 
33 extern "C" {
34 typedef
35 int ( *ItkItpackSolverFunction )(integer *, integer *, integer *, doublereal *, doublereal *, doublereal *, integer *,
36  integer *, doublereal *,
37  integer *, doublereal *, integer *);
38 }
39 
40 namespace itk
41 {
42 namespace fem
43 {
52 {
53 public:
54 
57 
60 
63 
65  typedef std::vector<MatrixRepresentation> MatrixHolder;
66 
67  /* auto pointer to vector of matrices typedef */
68  /* typedef std::auto_ptr<MatrixHolder> MatrixArrayPtr; */
69 
71  /* typedef std::auto_ptr<double> VectorRepresentation; */
72  typedef double *VectorRepresentation;
73 
75  typedef std::vector<VectorRepresentation> VectorHolder;
76 
77  /* auto pointer to vector of vectors typedef */
78  /* typedef std::auto_ptr<VectorHolder> VectorArrayPtr; */
79 
80  /* pointer to array of unsigned int typedef */
81  /* typedef std::auto_ptr<unsigned int> UnsignedIntegerArrayPtr; */
82 
83  /* -----------------------------------------------------------------
84  *
85  * Routines for setting/reporting itpack parameters
86  *
87  * -----------------------------------------------------------------
88  */
89 
95  {
96  m_IPARM[0] = i;
97  }
98 
103  {
104  return m_IPARM[0];
105  }
106 
107  // void SetErrorReportingLevel(int i) { m_IPARM[1] = i; }
108 
113  {
114  return m_IPARM[1];
115  }
116 
122  {
123  m_IPARM[2] = i;
124  }
125 
130  {
131  return m_IPARM[2];
132  }
133 
134  // void SetOutputNumber(int i) { m_IPARM[3] = i; }
135 
139  int GetOutputNumber() const
140  {
141  return m_IPARM[3];
142  }
143 
149  {
150  m_IPARM[4] = i;
151  }
152 
157  {
158  return m_IPARM[4];
159  }
160 
165  void SetAdaptiveSwitch(int i)
166  {
167  m_IPARM[5] = i;
168  }
169 
173  int GetAdaptiveSwitch() const
174  {
175  return m_IPARM[5];
176  }
177 
183  {
184  m_IPARM[6] = i;
185  }
186 
191  {
192  return m_IPARM[6];
193  }
194 
200  void SetWorkspaceUsed(int i)
201  {
202  m_IPARM[7] = i;
203  }
204 
210  {
211  return m_IPARM[7];
212  }
213 
219  {
220  m_IPARM[8] = i;
221  }
222 
227  {
228  return m_IPARM[8];
229  }
230 
235  void SetRemoveSwitch(int i)
236  {
237  m_IPARM[9] = i;
238  }
239 
244  {
245  return m_IPARM[9];
246  }
247 
252  void SetTimingSwitch(int i)
253  {
254  m_IPARM[10] = i;
255  }
256 
261  {
262  return m_IPARM[10];
263  }
264 
270  {
271  m_IPARM[11] = i;
272  }
273 
278  {
279  return m_IPARM[11];
280  }
281 
286  void SetAccuracy(double i)
287  {
288  m_RPARM[0] = i;
289  }
290 
294  double GetAccuracy() const
295  {
296  return m_RPARM[0];
297  }
298 
304  {
305  m_RPARM[1] = i;
306  }
307 
312  {
313  return m_RPARM[1];
314  }
315 
321  {
322  m_RPARM[2] = i;
323  }
324 
329  {
330  return m_RPARM[2];
331  }
332 
337  void SetDampingFactor(double i)
338  {
339  m_RPARM[3] = i;
340  }
341 
345  double GetDampingFactor() const
346  {
347  return m_RPARM[3];
348  }
349 
355  {
356  m_RPARM[4] = i;
357  }
358 
363  {
364  return m_RPARM[4];
365  }
366 
372  {
373  m_RPARM[5] = i;
374  }
375 
380  {
381  return m_RPARM[5];
382  }
383 
389  {
390  m_RPARM[6] = i;
391  }
392 
397  {
398  return m_RPARM[6];
399  }
400 
405  void SetTolerance(double i)
406  {
407  m_RPARM[7] = i;
408  }
409 
413  double GetTolerance()
414  {
415  return m_RPARM[7];
416  }
417 
422  void SetTimeToConvergence(double i)
423  {
424  m_RPARM[8] = i;
425  }
426 
431  {
432  return m_RPARM[8];
433  }
434 
439  void SetTimeForCall(double i)
440  {
441  m_RPARM[9] = i;
442  }
443 
447  double GetTimeForCall()
448  {
449  return m_RPARM[9];
450  }
451 
456  void SetDigitsInError(double i)
457  {
458  m_RPARM[10] = i;
459  }
460 
464  double GetDigitsInError() const
465  {
466  return m_RPARM[10];
467  }
468 
473  void SetDigitsInResidual(double i)
474  {
475  m_RPARM[11] = i;
476  }
477 
481  double GetDigitsInResidual() const
482  {
483  return m_RPARM[11];
484  }
485 
490  {
491  m_Method = 0;
492  }
493 
498  {
499  m_Method = 1;
500  }
501 
506  {
507  m_Method = 2;
508  }
509 
515  {
516  m_Method = 3;
517  }
518 
524  {
525  m_Method = 4;
526  }
527 
532  {
533  m_Method = 5;
534  }
535 
539  {
540  m_Method = 6;
541  }
542 
555  virtual void SetMaximumNonZeroValuesInMatrix(unsigned int maxNonZeroValues)
556  {
558  maxNonZeroValues;
559  }
560 
561  virtual void ScaleMatrix(Float scale, unsigned int matrixIndex) ITK_OVERRIDE;
562 
574 
579 
580  /* memory management routines */
581  virtual void InitializeMatrix(unsigned int matrixIndex) ITK_OVERRIDE;
582 
583  virtual bool IsMatrixInitialized(unsigned int matrixIndex) ITK_OVERRIDE;
584 
585  virtual void DestroyMatrix(unsigned int matrixIndex) ITK_OVERRIDE;
586 
587  virtual void InitializeVector(unsigned int vectorIndex) ITK_OVERRIDE;
588 
589  virtual bool IsVectorInitialized(unsigned int vectorIndex) ITK_OVERRIDE;
590 
591  virtual void DestroyVector(unsigned int vectorIndex) ITK_OVERRIDE;
592 
593  virtual void InitializeSolution(unsigned int solutionIndex) ITK_OVERRIDE;
594 
595  virtual bool IsSolutionInitialized(unsigned int solutionIndex) ITK_OVERRIDE;
596 
597  virtual void DestroySolution(unsigned int solutionIndex) ITK_OVERRIDE;
598 
599  /* assembly & solving routines */
600  virtual Float GetMatrixValue(unsigned int i, unsigned int j, unsigned int matrixIndex) const ITK_OVERRIDE;
601 
602  virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE;
603 
604  virtual void AddMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE;
605 
606  virtual void GetColumnsOfNonZeroMatrixElementsInRow(unsigned int row, ColumnArray & cols, unsigned int matrixIndex) ITK_OVERRIDE;
607 
608  virtual Float GetVectorValue(unsigned int i, unsigned int vectorIndex) const ITK_OVERRIDE;
609 
610  virtual void SetVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE;
611 
612  virtual void AddVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE;
613 
614  virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const ITK_OVERRIDE;
615 
616  virtual void SetSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE;
617 
618  virtual void AddSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE;
619 
620  virtual void Solve(void) ITK_OVERRIDE;
621 
622  /* matrix & vector manipulation routines */
623  virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE;
624 
625  virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE;
626 
627  virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE;
628 
629  virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE;
630 
631  virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE;
632 
633  virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex,
634  unsigned int rightMatrixIndex) ITK_OVERRIDE;
635 
636  virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE;
637 
644  virtual void MultiplyMatrixSolution(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int solutionIndex) ITK_OVERRIDE;
645 
646 private:
647 
650 
653 
656 
659  // UnsignedIntegerArrayPtr m_MaximumNonZeroValues;
661 
664 
667 
670 
673 };
674 
682 class ITK_ABI_EXPORT FEMExceptionItpackSolver : public FEMException
683 {
684 public:
685 
687  typedef long integer;
688 
694  FEMExceptionItpackSolver(const char *file, unsigned int lineNumber, std::string location, integer errorCode);
695 
698  throw ( )
699  {
700  }
701 
703  itkTypeMacro(FEMExceptionItpackSolver, FEMException);
704 };
705 }
706 } // end namespace itk::fem
707 
708 #endif // #ifndef __itkFEMLinearSystemWrapperItpack_h
virtual void MultiplyMatrixMatrix(unsigned int resultMatrixIndex, unsigned int leftMatrixIndex, unsigned int rightMatrixIndex) ITK_OVERRIDE
virtual void ScaleMatrix(Float scale, unsigned int matrixIndex) ITK_OVERRIDE
virtual void SetVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE
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
virtual void AddSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE
virtual void MultiplyMatrixVector(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int vectorIndex) ITK_OVERRIDE
virtual void SwapSolutions(unsigned int solutionIndex1, unsigned int solutionIndex2) ITK_OVERRIDE
virtual void SwapVectors(unsigned int vectorIndex1, unsigned int vectorIndex2) ITK_OVERRIDE
a compressed row sparse matrix representation that makes use of itpack to dynamically assemble the ma...
virtual void InitializeVector(unsigned int vectorIndex) ITK_OVERRIDE
std::vector< VectorRepresentation > VectorHolder
virtual void DestroyVector(unsigned int vectorIndex) ITK_OVERRIDE
virtual void Solve(void) ITK_OVERRIDE
std::vector< unsigned int > ColumnArray
Defines all functions required by Solver class to allocate, assemble and solve a linear system of equ...
virtual void CopyVector2Solution(unsigned int vectorIndex, unsigned int solutionIndex) ITK_OVERRIDE
virtual void InitializeMatrix(unsigned int matrixIndex) ITK_OVERRIDE
virtual Float GetSolutionValue(unsigned int i, unsigned int solutionIndex) const ITK_OVERRIDE
virtual bool IsVectorInitialized(unsigned int vectorIndex) ITK_OVERRIDE
virtual void SetSolutionValue(unsigned int i, Float value, unsigned int solutionIndex) ITK_OVERRIDE
virtual bool IsSolutionInitialized(unsigned int solutionIndex) ITK_OVERRIDE
virtual bool IsMatrixInitialized(unsigned int matrixIndex) ITK_OVERRIDE
virtual Float GetVectorValue(unsigned int i, unsigned int vectorIndex) const ITK_OVERRIDE
virtual void AddVectorValue(unsigned int i, Float value, unsigned int vectorIndex) ITK_OVERRIDE
virtual Float GetMatrixValue(unsigned int i, unsigned int j, unsigned int matrixIndex) const ITK_OVERRIDE
virtual void SetMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE
virtual void InitializeSolution(unsigned int solutionIndex) ITK_OVERRIDE
virtual void CopySolution2Vector(unsigned solutionIndex, unsigned int vectorIndex) ITK_OVERRIDE
virtual void DestroySolution(unsigned int solutionIndex) ITK_OVERRIDE
virtual void DestroyMatrix(unsigned int matrixIndex) ITK_OVERRIDE
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 AddMatrixValue(unsigned int i, unsigned int j, Float value, unsigned int matrixIndex) ITK_OVERRIDE
virtual void GetColumnsOfNonZeroMatrixElementsInRow(unsigned int row, ColumnArray &cols, unsigned int matrixIndex) ITK_OVERRIDE
virtual void SetMaximumNonZeroValuesInMatrix(unsigned int maxNonZeroValues)
virtual void MultiplyMatrixSolution(unsigned int resultVectorIndex, unsigned int matrixIndex, unsigned int solutionIndex) ITK_OVERRIDE
virtual void SwapMatrices(unsigned int matrixIndex1, unsigned int matrixIndex2) ITK_OVERRIDE