VMTK
Loading...
Searching...
No Matches
vtkvmtkDirichletBoundaryConditions.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkDirichletBoundaryConditions.cxx,v $
5 Language: C++
6 Date: $Date: 2005/03/04 11:07:29 $
7 Version: $Revision: 1.2 $
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 "vtkvmtkSparseMatrix.h"
24#include "vtkvmtkDoubleVector.h"
26#include "vtkObjectFactory.h"
27
28
30
32{
33 vtkIdType i, j, k;
34 vtkIdType systemSize;
35 vtkIdType numberOfRowElements;
36 vtkIdType boundaryNode, numberOfBoundaryNodes;
37 vtkvmtkSparseMatrix* systemMatrix;
38 vtkvmtkDoubleVector* rhsVector;
40 double boundaryValue;
41 double element;
42 double vectorElement;
43
44 this->Superclass::Apply();
45
46 systemSize = this->LinearSystem->GetX()->GetNumberOfElements();
47 numberOfBoundaryNodes = this->BoundaryNodes->GetNumberOfIds();
48
50 systemMatrix = this->LinearSystem->GetA();
51 rhsVector = this->LinearSystem->GetB();
52
53 for (i=0; i<numberOfBoundaryNodes; i++)
54 {
55 boundaryNode = this->BoundaryNodes->GetId(i);
56 boundaryValue = this->BoundaryValues->GetComponent(i,0);
57
58 for (j=0; j<systemSize; j++)
59 {
60 if (j==boundaryNode)
61 {
62 systemMatrix->GetRow(j)->Initialize();
63 systemMatrix->GetRow(j)->SetDiagonalElement(1.0);
64 rhsVector->SetElement(j,boundaryValue);
65 //rhsVector->SetLocked(j,true);
66 }
67 else
68 {
69 row = systemMatrix->GetRow(j);
70 numberOfRowElements = row->GetNumberOfElements();
71 for (k=0; k<numberOfRowElements; k++)
72 {
73 if (row->GetElementId(k) == boundaryNode)
74 {
75 element = row->GetElement(k);
76 row->SetElement(k,0.0);
77 vectorElement = rhsVector->GetElement(j);
78 vectorElement -= element * boundaryValue;
79 rhsVector->SetElement(j,vectorElement);
80 }
81 }
82 }
83 }
84 }
85}
86
Set up Dirichlet (or first-type) boundary conditions that a linear system needs to take along the bou...
Serves as the base class for vectors utilized in finite-element and other PDE evaluations.
double GetElement(vtkIdType i)
void SetElement(vtkIdType i, double value)
Represents a single row of a vtkvmtkSparseMatrix: a sparse list of (column id, value) pairs plus a se...
void SetElement(vtkIdType i, double element)
virtual void SetDiagonalElement(double)
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)
vtkStandardNewMacro(vtkvmtkDirichletBoundaryConditions)