VMTK
Loading...
Searching...
No Matches
vtkvmtkOpenNLLinearSystemSolver Class Reference

Solve a linear system of equations using open NL. More...

#include <vtkvmtkOpenNLLinearSystemSolver.h>

Inheritance diagram for vtkvmtkOpenNLLinearSystemSolver:
[legend]
Collaboration diagram for vtkvmtkOpenNLLinearSystemSolver:
[legend]

Public Types

enum  { VTK_VMTK_OPENNL_SOLVER_CG , VTK_VMTK_OPENNL_SOLVER_GMRES , VTK_VMTK_OPENNL_SOLVER_BICGSTAB }
enum  { VTK_VMTK_OPENNL_PRECONDITIONER_NONE , VTK_VMTK_OPENNL_PRECONDITIONER_JACOBI , VTK_VMTK_OPENNL_PRECONDITIONER_SSOR }
typedef vtkvmtkLinearSystemSolver Superclass
Public Types inherited from vtkvmtkLinearSystemSolver
typedef vtkObject Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkOpenNLLinearSystemSolver * NewInstance () const
int Solve () override
virtual void SetSolverType (int)
virtual int GetSolverType ()
void SetSolverTypeToCG ()
void SetSolverTypeToGMRES ()
void SetSolverTypeToBiCGStab ()
virtual void SetPreconditionerType (int)
virtual int GetPreconditionerType ()
void SetPreconditionerTypeToNone ()
void SetPreconditionerTypeToJacobi ()
void SetPreconditionerTypeToSSOR ()
virtual void SetOmega (double)
virtual double GetOmega ()
Public Member Functions inherited from vtkvmtkLinearSystemSolver
vtkvmtkLinearSystemSolver * NewInstance () const
virtual void SetLinearSystem (vtkvmtkLinearSystem *)
virtual vtkvmtkLinearSystem * GetLinearSystem ()
virtual void SetMaximumNumberOfIterations (int)
virtual int GetMaximumNumberOfIterations ()
virtual void SetConvergenceTolerance (double)
virtual double GetConvergenceTolerance ()

Static Public Member Functions

static vtkvmtkOpenNLLinearSystemSolver * New ()
static int IsTypeOf (const char *type)
static vtkvmtkOpenNLLinearSystemSolver * SafeDownCast (vtkObjectBase *o)
Static Public Member Functions inherited from vtkvmtkLinearSystemSolver
static vtkvmtkLinearSystemSolver * New ()
static int IsTypeOf (const char *type)
static vtkvmtkLinearSystemSolver * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkOpenNLLinearSystemSolver ()
 ~vtkvmtkOpenNLLinearSystemSolver ()
Protected Member Functions inherited from vtkvmtkLinearSystemSolver
 vtkvmtkLinearSystemSolver ()
 ~vtkvmtkLinearSystemSolver ()

Protected Attributes

int SolverType
int PreconditionerType
double Omega
Protected Attributes inherited from vtkvmtkLinearSystemSolver
vtkvmtkLinearSystem * LinearSystem
int MaximumNumberOfIterations
double ConvergenceTolerance
int NumberOfIterations
double Residual

Detailed Description

Solve a linear system of equations using open NL.

vtkvmtkOpenNLLinearSystemSolver implements vtkvmtkLinearSystemSolver::Solve() on top of the OpenNL (Open Numerical Library) sparse linear solver. It converts the vtkvmtkSparseMatrix / vtkvmtkDoubleVector representation held by LinearSystem (see the base class) into an OpenNL context, runs the requested iterative solver up to MaximumNumberOfIterations or ConvergenceTolerance (both inherited from vtkvmtkLinearSystemSolver), and copies the result back into the solution vector. It is used internally by finite-element/stencil based filters in this module (e.g. vtkvmtkPolyDataGradientFilter, vtkvmtkPolyDataHarmonicMappingFilter) to solve the sparse systems they assemble.

There are a number of different solver types that can be used:

  • VTK_VMTK_OPENNL_SOLVER_BICGSTAB = Biconjugate gradient stabilized method
  • VTK_VMTK_OPENNL_SOLVER_GMRES = Generalized minimal residual method
  • VTK_VMTK_OPENNL_SOLVER_CG = Iterative conjugate gradient solver

and a number of different preconditioner types:

  • VTK_VMTK_OPENNL_PRECONDITIONER_NONE = no preconditioning
  • VTK_VMTK_OPENNL_PRECONDITIONER_JACOBI = Jacobi (diagonal) preconditioning
  • VTK_VMTK_OPENNL_PRECONDITIONER_SSOR = symmetric successive over-relaxation preconditioning
See also
vtkvmtkLinearSystemSolver

Definition at line 51 of file vtkvmtkOpenNLLinearSystemSolver.h.

Member Typedef Documentation

◆ Superclass

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
VTK_VMTK_OPENNL_SOLVER_CG 
VTK_VMTK_OPENNL_SOLVER_GMRES 
VTK_VMTK_OPENNL_SOLVER_BICGSTAB 

Definition at line 110 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ anonymous enum

anonymous enum
Enumerator
VTK_VMTK_OPENNL_PRECONDITIONER_NONE 
VTK_VMTK_OPENNL_PRECONDITIONER_JACOBI 
VTK_VMTK_OPENNL_PRECONDITIONER_SSOR 

Definition at line 119 of file vtkvmtkOpenNLLinearSystemSolver.h.

Constructor & Destructor Documentation

◆ vtkvmtkOpenNLLinearSystemSolver()

◆ ~vtkvmtkOpenNLLinearSystemSolver()

vtkvmtkOpenNLLinearSystemSolver::~vtkvmtkOpenNLLinearSystemSolver ( )
inlineprotected

Definition at line 129 of file vtkvmtkOpenNLLinearSystemSolver.h.

129{};

Member Function Documentation

◆ New()

vtkvmtkOpenNLLinearSystemSolver * vtkvmtkOpenNLLinearSystemSolver::New ( )
static

◆ IsTypeOf()

int vtkvmtkOpenNLLinearSystemSolver::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkOpenNLLinearSystemSolver::IsA ( const char * type)
virtual

Reimplemented from vtkvmtkLinearSystemSolver.

◆ SafeDownCast()

vtkvmtkOpenNLLinearSystemSolver * vtkvmtkOpenNLLinearSystemSolver::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkOpenNLLinearSystemSolver::NewInstanceInternal ( ) const
protectedvirtual

Reimplemented from vtkvmtkLinearSystemSolver.

◆ NewInstance()

vtkvmtkOpenNLLinearSystemSolver * vtkvmtkOpenNLLinearSystemSolver::NewInstance ( ) const

◆ Solve()

int vtkvmtkOpenNLLinearSystemSolver::Solve ( )
overridevirtual

Assemble and solve the linear system currently set on LinearSystem (see vtkvmtkLinearSystemSolver::SetLinearSystem) using OpenNL, with the solver and preconditioner selected by SolverType and PreconditionerType. Returns 0 on success, -1 if no linear system (or an incomplete one) has been set.

Reimplemented from vtkvmtkLinearSystemSolver.

Definition at line 40 of file vtkvmtkOpenNLLinearSystemSolver.cxx.

41{
42 vtkvmtkSparseMatrix *system;
43 vtkvmtkDoubleVector *solution, *rhs;
44
45 if (this->Superclass::Solve()==-1)
46 {
47 return -1;
48 }
49
50 system = this->LinearSystem->GetA();
51 rhs = this->LinearSystem->GetB();
52 solution = this->LinearSystem->GetX();
53
54 nlNewContext();
55
56 nlSolverParameteri(NL_SOLVER,NL_CG);
57
58 switch (this->SolverType)
59 {
61 nlSolverParameteri(NL_SOLVER,NL_CG);
62 break;
64 nlSolverParameteri(NL_SOLVER,NL_BICGSTAB);
65 break;
67 nlSolverParameteri(NL_SOLVER,NL_GMRES);
68 break;
69 }
70
71 switch (this->PreconditionerType)
72 {
74 nlSolverParameteri(NL_PRECONDITIONER,NL_PRECOND_NONE);
75 break;
77 nlSolverParameteri(NL_PRECONDITIONER,NL_PRECOND_JACOBI);
78 break;
80 nlSolverParameteri(NL_PRECONDITIONER,NL_PRECOND_SSOR);
81 break;
82 }
83
84 nlSolverParameteri(NL_NB_VARIABLES,rhs->GetNumberOfElements());
85 nlSolverParameteri(NL_LEAST_SQUARES,NL_FALSE);
86 nlSolverParameteri(NL_MAX_ITERATIONS,this->MaximumNumberOfIterations);
87 nlSolverParameterd(NL_THRESHOLD,this->ConvergenceTolerance);
88
89 nlBegin(NL_SYSTEM);
90 nlBegin(NL_MATRIX);
91
92 int i, j;
93 for (i=0; i<system->GetNumberOfRows(); i++)
94 {
95 nlRowParameterd(NL_RIGHT_HAND_SIDE,-rhs->GetElement(i));
96 vtkvmtkSparseMatrixRow* row = system->GetRow(i);
97 nlBegin(NL_ROW);
98 for (j=0; j<row->GetNumberOfElements(); j++)
99 {
100 nlCoefficient(row->GetElementId(j),row->GetElement(j));
101 }
102 nlCoefficient(i,row->GetDiagonalElement());
103 nlEnd(NL_ROW);
104 }
105
106 nlEnd(NL_MATRIX);
107 nlEnd(NL_SYSTEM);
108 nlSolve();
109
110 for (i=0; i<solution->GetNumberOfElements(); i++)
111 {
112 solution->SetElement(i,nlGetVariable(i));
113 }
114
115 nlDeleteContext(nlGetCurrent());
116
117 return 0;
118}
virtual vtkIdType GetNumberOfElements()
double GetElement(vtkIdType i)
void SetElement(vtkIdType i, double value)
virtual double GetDiagonalElement()
double GetElement(vtkIdType i)
vtkIdType GetElementId(vtkIdType i)
vtkvmtkSparseMatrixRow * GetRow(vtkIdType i)
virtual vtkIdType GetNumberOfRows()

◆ SetSolverType()

virtual void vtkvmtkOpenNLLinearSystemSolver::SetSolverType ( int )
virtual

Set/get the OpenNL iterative solver algorithm used by Solve(): VTK_VMTK_OPENNL_SOLVER_CG (conjugate gradient, the default), VTK_VMTK_OPENNL_SOLVER_GMRES (generalized minimal residual), or VTK_VMTK_OPENNL_SOLVER_BICGSTAB (biconjugate gradient stabilized). CG requires the system matrix to be symmetric positive definite; use GMRES or BiCGStab for non-symmetric systems.

◆ GetSolverType()

virtual int vtkvmtkOpenNLLinearSystemSolver::GetSolverType ( )
virtual

Set/get the OpenNL iterative solver algorithm used by Solve(): VTK_VMTK_OPENNL_SOLVER_CG (conjugate gradient, the default), VTK_VMTK_OPENNL_SOLVER_GMRES (generalized minimal residual), or VTK_VMTK_OPENNL_SOLVER_BICGSTAB (biconjugate gradient stabilized). CG requires the system matrix to be symmetric positive definite; use GMRES or BiCGStab for non-symmetric systems.

◆ SetSolverTypeToCG()

void vtkvmtkOpenNLLinearSystemSolver::SetSolverTypeToCG ( )
inline

Set/get the OpenNL iterative solver algorithm used by Solve(): VTK_VMTK_OPENNL_SOLVER_CG (conjugate gradient, the default), VTK_VMTK_OPENNL_SOLVER_GMRES (generalized minimal residual), or VTK_VMTK_OPENNL_SOLVER_BICGSTAB (biconjugate gradient stabilized). CG requires the system matrix to be symmetric positive definite; use GMRES or BiCGStab for non-symmetric systems.

Definition at line 74 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ SetSolverTypeToGMRES()

void vtkvmtkOpenNLLinearSystemSolver::SetSolverTypeToGMRES ( )
inline

Set/get the OpenNL iterative solver algorithm used by Solve(): VTK_VMTK_OPENNL_SOLVER_CG (conjugate gradient, the default), VTK_VMTK_OPENNL_SOLVER_GMRES (generalized minimal residual), or VTK_VMTK_OPENNL_SOLVER_BICGSTAB (biconjugate gradient stabilized). CG requires the system matrix to be symmetric positive definite; use GMRES or BiCGStab for non-symmetric systems.

Definition at line 76 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ SetSolverTypeToBiCGStab()

void vtkvmtkOpenNLLinearSystemSolver::SetSolverTypeToBiCGStab ( )
inline

Set/get the OpenNL iterative solver algorithm used by Solve(): VTK_VMTK_OPENNL_SOLVER_CG (conjugate gradient, the default), VTK_VMTK_OPENNL_SOLVER_GMRES (generalized minimal residual), or VTK_VMTK_OPENNL_SOLVER_BICGSTAB (biconjugate gradient stabilized). CG requires the system matrix to be symmetric positive definite; use GMRES or BiCGStab for non-symmetric systems.

Definition at line 78 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ SetPreconditionerType()

virtual void vtkvmtkOpenNLLinearSystemSolver::SetPreconditionerType ( int )
virtual

Set/get the preconditioner applied by Solve(): VTK_VMTK_OPENNL_PRECONDITIONER_NONE (the default), VTK_VMTK_OPENNL_PRECONDITIONER_JACOBI (diagonal scaling), or VTK_VMTK_OPENNL_PRECONDITIONER_SSOR (symmetric successive over-relaxation, using Omega as the relaxation factor). A suitable preconditioner can significantly reduce the number of iterations needed to reach ConvergenceTolerance.

◆ GetPreconditionerType()

virtual int vtkvmtkOpenNLLinearSystemSolver::GetPreconditionerType ( )
virtual

Set/get the preconditioner applied by Solve(): VTK_VMTK_OPENNL_PRECONDITIONER_NONE (the default), VTK_VMTK_OPENNL_PRECONDITIONER_JACOBI (diagonal scaling), or VTK_VMTK_OPENNL_PRECONDITIONER_SSOR (symmetric successive over-relaxation, using Omega as the relaxation factor). A suitable preconditioner can significantly reduce the number of iterations needed to reach ConvergenceTolerance.

◆ SetPreconditionerTypeToNone()

void vtkvmtkOpenNLLinearSystemSolver::SetPreconditionerTypeToNone ( )
inline

Set/get the preconditioner applied by Solve(): VTK_VMTK_OPENNL_PRECONDITIONER_NONE (the default), VTK_VMTK_OPENNL_PRECONDITIONER_JACOBI (diagonal scaling), or VTK_VMTK_OPENNL_PRECONDITIONER_SSOR (symmetric successive over-relaxation, using Omega as the relaxation factor). A suitable preconditioner can significantly reduce the number of iterations needed to reach ConvergenceTolerance.

Definition at line 92 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ SetPreconditionerTypeToJacobi()

void vtkvmtkOpenNLLinearSystemSolver::SetPreconditionerTypeToJacobi ( )
inline

Set/get the preconditioner applied by Solve(): VTK_VMTK_OPENNL_PRECONDITIONER_NONE (the default), VTK_VMTK_OPENNL_PRECONDITIONER_JACOBI (diagonal scaling), or VTK_VMTK_OPENNL_PRECONDITIONER_SSOR (symmetric successive over-relaxation, using Omega as the relaxation factor). A suitable preconditioner can significantly reduce the number of iterations needed to reach ConvergenceTolerance.

Definition at line 94 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ SetPreconditionerTypeToSSOR()

void vtkvmtkOpenNLLinearSystemSolver::SetPreconditionerTypeToSSOR ( )
inline

Set/get the preconditioner applied by Solve(): VTK_VMTK_OPENNL_PRECONDITIONER_NONE (the default), VTK_VMTK_OPENNL_PRECONDITIONER_JACOBI (diagonal scaling), or VTK_VMTK_OPENNL_PRECONDITIONER_SSOR (symmetric successive over-relaxation, using Omega as the relaxation factor). A suitable preconditioner can significantly reduce the number of iterations needed to reach ConvergenceTolerance.

Definition at line 96 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ SetOmega()

virtual void vtkvmtkOpenNLLinearSystemSolver::SetOmega ( double )
virtual

Set/get the relaxation factor used by the SSOR preconditioner (ignored for other PreconditionerType values). Default: 0.0.

◆ GetOmega()

virtual double vtkvmtkOpenNLLinearSystemSolver::GetOmega ( )
virtual

Set/get the relaxation factor used by the SSOR preconditioner (ignored for other PreconditionerType values). Default: 0.0.

Member Data Documentation

◆ SolverType

int vtkvmtkOpenNLLinearSystemSolver::SolverType
protected

Definition at line 131 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ PreconditionerType

int vtkvmtkOpenNLLinearSystemSolver::PreconditionerType
protected

Definition at line 132 of file vtkvmtkOpenNLLinearSystemSolver.h.

◆ Omega

double vtkvmtkOpenNLLinearSystemSolver::Omega
protected

Definition at line 133 of file vtkvmtkOpenNLLinearSystemSolver.h.


The documentation for this class was generated from the following files: