VMTK
Loading...
Searching...
No Matches
vtkvmtkUnstructuredGridGradientFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkUnstructuredGridGradientFilter.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:44 $
7 Version: $Revision: 1.7 $
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 "vtkUnstructuredGrid.h"
24#include "vtkPointData.h"
25#include "vtkDoubleArray.h"
26#include "vtkvmtkDoubleVector.h"
28#include "vtkvmtkSparseMatrix.h"
29#include "vtkvmtkLinearSystem.h"
31
32#include "vtkInformation.h"
33#include "vtkInformationVector.h"
34#include "vtkObjectFactory.h"
35
36#include <iostream>
37
39
48
50{
51 if (this->InputArrayName)
52 {
53 delete[] this->InputArrayName;
54 this->InputArrayName = NULL;
55 }
56 if (this->GradientArrayName)
57 {
58 delete[] this->GradientArrayName;
59 this->GradientArrayName = NULL;
60 }
61}
62
64 vtkInformation *vtkNotUsed(request),
65 vtkInformationVector **inputVector,
66 vtkInformationVector *outputVector)
67{
68 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
69 vtkInformation *outInfo = outputVector->GetInformationObject(0);
70
71 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
72 inInfo->Get(vtkDataObject::DATA_OBJECT()));
73 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
74 outInfo->Get(vtkDataObject::DATA_OBJECT()));
75
76 if (!this->InputArrayName)
77 {
78 vtkErrorMacro(<<"InputArrayName not set.");
79 return 1;
80 }
81
82 if (!this->GradientArrayName)
83 {
84 vtkErrorMacro(<<"GradientArrayName not set.");
85 return 1;
86 }
87
88 int numberOfInputPoints = input->GetNumberOfPoints();
89
90 vtkDataArray* inputArray = input->GetPointData()->GetArray(this->InputArrayName);
91
92 if (!inputArray)
93 {
94 vtkErrorMacro("InputArray with name specified doesn not exist!");
95 return 0;
96 }
97
98 int numberOfInputComponents = inputArray->GetNumberOfComponents();
99
100 vtkDoubleArray* gradientArray = vtkDoubleArray::New();
101 gradientArray->SetName(this->GradientArrayName);
102 gradientArray->SetNumberOfComponents(3*numberOfInputComponents);
103 gradientArray->SetNumberOfTuples(numberOfInputPoints);
104
105 int i;
106 for (i=0; i<numberOfInputComponents; i++)
107 {
109
111 rhsVector->SetNormTypeToLInf();
112
114 solutionVector->SetNormTypeToLInf();
115
117 {
119 assembler->SetDataSet(input);
120 assembler->SetScalarsArrayName(this->InputArrayName);
121 assembler->SetScalarsComponent(i);
122 assembler->SetMatrix(sparseMatrix);
123 assembler->SetRHSVector(rhsVector);
124 assembler->SetSolutionVector(solutionVector);
125 assembler->SetQuadratureOrder(this->QuadratureOrder);
126 assembler->SetAssemblyModeToGradient();
127 std::cout<<"Assembling system"<<endl;
128 assembler->Build();
129 std::cout<<"Done"<<endl;
130
132 linearSystem->SetA(sparseMatrix);
133 linearSystem->SetB(rhsVector);
134 linearSystem->SetX(solutionVector);
135
137 solver->SetLinearSystem(linearSystem);
139 solver->SetMaximumNumberOfIterations(numberOfInputPoints);
140 solver->SetSolverTypeToCG();
142 std::cout<<"Solving system"<<endl;
143 solver->Solve();
144 std::cout<<"Done"<<endl;
145
146 solutionVector->CopyVariableIntoArrayComponent(gradientArray,0,3*i+0);
147 solutionVector->CopyVariableIntoArrayComponent(gradientArray,1,3*i+1);
148 solutionVector->CopyVariableIntoArrayComponent(gradientArray,2,3*i+2);
149
150 assembler->Delete();
151 linearSystem->Delete();
152 solver->Delete();
153 }
154 else
155 {
156 int j;
157 for (j=0; j<3; j++)
158 {
160 assembler->SetDataSet(input);
161 assembler->SetScalarsArrayName(this->InputArrayName);
162 assembler->SetScalarsComponent(i);
163 assembler->SetMatrix(sparseMatrix);
164 assembler->SetRHSVector(rhsVector);
165 assembler->SetSolutionVector(solutionVector);
166 assembler->SetQuadratureOrder(this->QuadratureOrder);
168 assembler->SetDirection(j);
169 std::cout<<"Assembling system"<<endl;
170 assembler->Build();
171 std::cout<<"Done"<<endl;
172
174 linearSystem->SetA(sparseMatrix);
175 linearSystem->SetB(rhsVector);
176 linearSystem->SetX(solutionVector);
177
179 solver->SetLinearSystem(linearSystem);
181 solver->SetMaximumNumberOfIterations(numberOfInputPoints);
182 solver->SetSolverTypeToCG();
184 std::cout<<"Solving system"<<endl;
185 solver->Solve();
186 std::cout<<"Done"<<endl;
187
188 solutionVector->CopyIntoArrayComponent(gradientArray,3*i+j);
189
190 assembler->Delete();
191 linearSystem->Delete();
192 solver->Delete();
193 }
194 }
195
196 solutionVector->Delete();
197 rhsVector->Delete();
198 sparseMatrix->Delete();
199 }
200
201 output->DeepCopy(input);
202 output->GetPointData()->AddArray(gradientArray);
203
204 gradientArray->Delete();
205
206 return 1;
207}
Serves as the base class for vectors utilized in finite-element and other PDE evaluations.
void CopyVariableIntoArrayComponent(vtkDataArray *array, int variable, int component)
static vtkvmtkDoubleVector * New()
void CopyIntoArrayComponent(vtkDataArray *array, int component)
virtual void SetSolutionVector(vtkvmtkDoubleVector *)
virtual void SetDataSet(vtkDataSet *)
virtual void SetRHSVector(vtkvmtkDoubleVector *)
virtual void SetMatrix(vtkvmtkSparseMatrix *)
virtual void SetQuadratureOrder(int)
virtual void SetConvergenceTolerance(double)
virtual void SetMaximumNumberOfIterations(int)
virtual void SetLinearSystem(vtkvmtkLinearSystem *)
Serves as the base container holding sparse matrix objects that represent a linear system of equation...
virtual void SetX(vtkvmtkDoubleVector *)
virtual void SetA(vtkvmtkSparseMatrix *)
virtual void SetB(vtkvmtkDoubleVector *)
static vtkvmtkLinearSystem * New()
Solve a linear system of equations using open NL.
static vtkvmtkOpenNLLinearSystemSolver * New()
Implements a row-based sparse matrix built from mesh neighborhoods or stencils, supporting basic line...
static vtkvmtkSparseMatrix * New()
Construct a gradient based finite element calculation on a mesh.
static vtkvmtkUnstructuredGridFEGradientAssembler * New()
virtual void SetScalarsArrayName(const char *)
Compute the gradient of data stored within an unstructured grid mesh.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkStandardNewMacro(vtkvmtkUnstructuredGridGradientFilter)