VMTK
Loading...
Searching...
No Matches
vtkvmtkUnstructuredGridFEGradientAssembler.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkUnstructuredGridFEGradientAssembler.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
41
50
52{
53 switch (this->AssemblyMode)
54 {
56 this->BuildGradient();
57 break;
60 break;
61 default:
62 vtkErrorMacro("Unsupported AssemblyMode");
63 return;
64 }
65}
66
68{
69 if (!this->ScalarsArrayName)
70 {
71 vtkErrorMacro("ScalarsArrayName not specified!");
72 return;
73 }
74
75 vtkDataArray* scalarsArray = this->DataSet->GetPointData()->GetArray(this->ScalarsArrayName);
76
77 if (!scalarsArray)
78 {
79 vtkErrorMacro("ScalarsArray with name specified does not exist!");
80 return;
81 }
82
83 int numberOfVariables = 3;
84 this->Initialize(numberOfVariables);
85
87 gaussQuadrature->SetOrder(this->QuadratureOrder);
88
90
91 int dimension = 3;
92
93 int numberOfCells = this->DataSet->GetNumberOfCells();
94 int numberOfPoints = this->DataSet->GetNumberOfPoints();
95 int k;
96 for (k=0; k<numberOfCells; k++)
97 {
98 vtkCell* cell = this->DataSet->GetCell(k);
99 if (cell->GetCellDimension() != dimension)
100 {
101 continue;
102 }
103 gaussQuadrature->Initialize(cell->GetCellType());
104 feShapeFunctions->Initialize(cell,gaussQuadrature->GetQuadraturePoints());
105 int numberOfQuadraturePoints = gaussQuadrature->GetNumberOfQuadraturePoints();
106 double quadraturePCoords[3];
107 int numberOfCellPoints = cell->GetNumberOfPoints();
108 int i, j;
109 int q;
110 for (q=0; q<numberOfQuadraturePoints; q++)
111 {
112 gaussQuadrature->GetQuadraturePoint(q,quadraturePCoords);
113 double quadratureWeight = gaussQuadrature->GetQuadratureWeight(q);
114 double jacobian = feShapeFunctions->GetJacobian(q);
115 double phii, phij;
116 double dphii[3];
117 double gradientValue[3];
118 gradientValue[0] = gradientValue[1] = gradientValue[2] = 0.0;
119 for (i=0; i<numberOfCellPoints; i++)
120 {
121 vtkIdType iId = cell->GetPointId(i);
122 feShapeFunctions->GetDPhi(q,i,dphii);
123 double nodalValue = scalarsArray->GetComponent(iId,this->ScalarsComponent);
124 gradientValue[0] += nodalValue * dphii[0];
125 gradientValue[1] += nodalValue * dphii[1];
126 gradientValue[2] += nodalValue * dphii[2];
127 }
128 for (i=0; i<numberOfCellPoints; i++)
129 {
130 vtkIdType iId = cell->GetPointId(i);
131 phii = feShapeFunctions->GetPhi(q,i);
132 double value0 = jacobian * quadratureWeight * gradientValue[0] * phii;
133 double value1 = jacobian * quadratureWeight * gradientValue[1] * phii;
134 double value2 = jacobian * quadratureWeight * gradientValue[2] * phii;
135 this->RHSVector->AddElement(iId,value0);
136 this->RHSVector->AddElement(iId+numberOfPoints,value1);
137 this->RHSVector->AddElement(iId+2*numberOfPoints,value2);
138 for (j=0; j<numberOfCellPoints; j++)
139 {
140 vtkIdType jId = cell->GetPointId(j);
141 phij = feShapeFunctions->GetPhi(q,j);
142 double value = jacobian * quadratureWeight * phii * phij;
143 this->Matrix->AddElement(iId,jId,value);
144 this->Matrix->AddElement(iId+numberOfPoints,jId+numberOfPoints,value);
145 this->Matrix->AddElement(iId+2*numberOfPoints,jId+2*numberOfPoints,value);
146 }
147 }
148 }
149 }
150
151 gaussQuadrature->Delete();
152 feShapeFunctions->Delete();
153}
154
156{
157 if (!this->ScalarsArrayName)
158 {
159 vtkErrorMacro("ScalarsArrayName not specified!");
160 return;
161 }
162
163 vtkDataArray* scalarsArray = this->DataSet->GetPointData()->GetArray(this->ScalarsArrayName);
164
165 if (!scalarsArray)
166 {
167 vtkErrorMacro("ScalarsArray with name specified does not exist!");
168 return;
169 }
170
171 int numberOfVariables = 1;
172 this->Initialize(numberOfVariables);
173
175 gaussQuadrature->SetOrder(this->QuadratureOrder);
176
178
179 int dimension = 3;
180
181 int numberOfCells = this->DataSet->GetNumberOfCells();
182 int k;
183 for (k=0; k<numberOfCells; k++)
184 {
185 vtkCell* cell = this->DataSet->GetCell(k);
186 if (cell->GetCellDimension() != dimension)
187 {
188 continue;
189 }
190 gaussQuadrature->Initialize(cell->GetCellType());
191 feShapeFunctions->Initialize(cell,gaussQuadrature->GetQuadraturePoints());
192 int numberOfQuadraturePoints = gaussQuadrature->GetNumberOfQuadraturePoints();
193 double quadraturePCoords[3];
194 int numberOfCellPoints = cell->GetNumberOfPoints();
195 int i, j;
196 int q;
197 for (q=0; q<numberOfQuadraturePoints; q++)
198 {
199 gaussQuadrature->GetQuadraturePoint(q,quadraturePCoords);
200 double quadratureWeight = gaussQuadrature->GetQuadratureWeight(q);
201 double jacobian = feShapeFunctions->GetJacobian(q);
202 double phii, phij;
203 double dphii[3];
204 double partialDerivativeValue = 0.0;
205 for (i=0; i<numberOfCellPoints; i++)
206 {
207 vtkIdType iId = cell->GetPointId(i);
208 feShapeFunctions->GetDPhi(q,i,dphii);
209 double nodalValue = scalarsArray->GetComponent(iId,this->ScalarsComponent);
210 partialDerivativeValue += nodalValue * dphii[this->Direction];
211 }
212 for (i=0; i<numberOfCellPoints; i++)
213 {
214 vtkIdType iId = cell->GetPointId(i);
215 phii = feShapeFunctions->GetPhi(q,i);
216 double value = jacobian * quadratureWeight * partialDerivativeValue * phii;
217 this->RHSVector->AddElement(iId,value);
218 for (j=0; j<numberOfCellPoints; j++)
219 {
220 vtkIdType jId = cell->GetPointId(j);
221 phij = feShapeFunctions->GetPhi(q,j);
222 double value = jacobian * quadratureWeight * phii * phij;
223 this->Matrix->AddElement(iId,jId,value);
224 }
225 }
226 }
227 }
228
229 gaussQuadrature->Delete();
230 feShapeFunctions->Delete();
231}
232
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 mesh.
vtkStandardNewMacro(vtkvmtkUnstructuredGridFEGradientAssembler)