VMTK
Loading...
Searching...
No Matches
vtkvmtkOpenNLLinearSystemSolver.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkOpenNLLinearSystemSolver.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:43 $
7 Version: $Revision: 1.3 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23#include "vtkObjectFactory.h"
24
25extern "C"
26{
27#include "nl.h"
28}
29
30
32
39
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}
119
Serves as the base class for vectors utilized in finite-element and other PDE evaluations.
virtual vtkIdType GetNumberOfElements()
double GetElement(vtkIdType i)
void SetElement(vtkIdType i, double value)
Solve a linear system of equations using open NL.
Represents a single row of a vtkvmtkSparseMatrix: a sparse list of (column id, value) pairs plus a se...
virtual double GetDiagonalElement()
double GetElement(vtkIdType i)
vtkIdType GetElementId(vtkIdType i)
Implements a row-based sparse matrix built from mesh neighborhoods or stencils, supporting basic line...
vtkvmtkSparseMatrixRow * GetRow(vtkIdType i)
virtual vtkIdType GetNumberOfRows()
vtkStandardNewMacro(vtkvmtkOpenNLLinearSystemSolver)