VMTK
Loading...
Searching...
No Matches
vtkvmtkPolyDataFEGradientAssembler.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkPolyDataFEGradientAssembler.cxx,v $
5 Language: C++
6 Date: $Date: 2005/11/15 17:39:25 $
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
25#include "vtkPointData.h"
26#include "vtkDataArray.h"
27#include "vtkCell.h"
28#include "vtkMath.h"
29#include "vtkObjectFactory.h"
30
31
33
39
48
50{
51 if (!this->ScalarsArrayName)
52 {
53 vtkErrorMacro("ScalarsArrayName not specified!");
54 return;
55 }
56
57 vtkDataArray* scalarsArray = this->DataSet->GetPointData()->GetArray(this->ScalarsArrayName);
58
59 if (!scalarsArray)
60 {
61 vtkErrorMacro("ScalarsArray with name specified does not exist!");
62 return;
63 }
64
65 int numberOfVariables = 3;
66 this->Initialize(numberOfVariables);
67
69 gaussQuadrature->SetOrder(this->QuadratureOrder);
70
72
73 int dimension = 2;
74
75 int numberOfCells = this->DataSet->GetNumberOfCells();
76 int numberOfPoints = this->DataSet->GetNumberOfPoints();
77 int k;
78 for (k=0; k<numberOfCells; k++)
79 {
80 vtkCell* cell = this->DataSet->GetCell(k);
81 if (cell->GetCellDimension() != dimension)
82 {
83 continue;
84 }
85 gaussQuadrature->Initialize(cell->GetCellType());
86 feShapeFunctions->Initialize(cell,gaussQuadrature->GetQuadraturePoints());
87 int numberOfQuadraturePoints = gaussQuadrature->GetNumberOfQuadraturePoints();
88 double quadraturePCoords[3];
89 int numberOfCellPoints = cell->GetNumberOfPoints();
90 int i, j;
91 int q;
92 for (q=0; q<numberOfQuadraturePoints; q++)
93 {
94 gaussQuadrature->GetQuadraturePoint(q,quadraturePCoords);
95 double quadratureWeight = gaussQuadrature->GetQuadratureWeight(q);
96 double jacobian = feShapeFunctions->GetJacobian(q);
97 double phii, phij;
98 double dphii[3];
99 double gradientValue[3];
100 gradientValue[0] = gradientValue[1] = gradientValue[2] = 0.0;
101 for (i=0; i<numberOfCellPoints; i++)
102 {
103 vtkIdType iId = cell->GetPointId(i);
104 feShapeFunctions->GetDPhi(q,i,dphii);
105 double nodalValue = scalarsArray->GetComponent(iId,this->ScalarsComponent);
106 gradientValue[0] += nodalValue * dphii[0];
107 gradientValue[1] += nodalValue * dphii[1];
108 gradientValue[2] += nodalValue * dphii[2];
109 }
110 for (i=0; i<numberOfCellPoints; i++)
111 {
112 vtkIdType iId = cell->GetPointId(i);
113 phii = feShapeFunctions->GetPhi(q,i);
114 double value0 = jacobian * quadratureWeight * gradientValue[0] * phii;
115 double value1 = jacobian * quadratureWeight * gradientValue[1] * phii;
116 double value2 = jacobian * quadratureWeight * gradientValue[2] * phii;
117 this->RHSVector->AddElement(iId,value0);
118 this->RHSVector->AddElement(iId+numberOfPoints,value1);
119 this->RHSVector->AddElement(iId+2*numberOfPoints,value2);
120 for (j=0; j<numberOfCellPoints; j++)
121 {
122 vtkIdType jId = cell->GetPointId(j);
123 phij = feShapeFunctions->GetPhi(q,j);
124 double value = jacobian * quadratureWeight * phii * phij;
125 this->Matrix->AddElement(iId,jId,value);
126 this->Matrix->AddElement(iId+numberOfPoints,jId+numberOfPoints,value);
127 this->Matrix->AddElement(iId+2*numberOfPoints,jId+2*numberOfPoints,value);
128 }
129 }
130 }
131 }
132
133 gaussQuadrature->Delete();
134 feShapeFunctions->Delete();
135}
136
vtkvmtkSparseMatrix * Matrix
vtkvmtkDoubleVector * RHSVector
void Initialize(int numberOfVariables)
Provides a set of common utility functions (calculate jacobian, interpolation function,...
void Initialize(vtkCell *cell, vtkDoubleArray *pcoords)
static vtkvmtkFEShapeFunctions * New()
double GetPhi(vtkIdType id, vtkIdType i)
double * GetDPhi(vtkIdType id, vtkIdType i)
Implements a finite element quadrature rule that approximates the definite integral of a function as ...
double * GetQuadraturePoint(vtkIdType id)
virtual vtkDoubleArray * GetQuadraturePoints()
static vtkvmtkGaussQuadrature * New()
void Initialize(vtkIdType cellType)
double GetQuadratureWeight(vtkIdType id)
virtual void SetOrder(int)
Construct a gradient based finite element calculation on a surface.
vtkStandardNewMacro(vtkvmtkPolyDataFEGradientAssembler)