VMTK
Loading...
Searching...
No Matches
vtkvmtkUnstructuredGridFEGradientAssembler Class Reference

Construct a gradient based finite element calculation on a mesh. More...

#include <vtkvmtkUnstructuredGridFEGradientAssembler.h>

Inheritance diagram for vtkvmtkUnstructuredGridFEGradientAssembler:
[legend]
Collaboration diagram for vtkvmtkUnstructuredGridFEGradientAssembler:
[legend]

Public Types

enum  { VTKVMTK_GRADIENTASSEMBLY , VTKVMTK_PARTIALDERIVATIVEASSEMBLY }
typedef vtkvmtkFEAssembler Superclass
Public Types inherited from vtkvmtkFEAssembler
typedef vtkObject Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkUnstructuredGridFEGradientAssembler * NewInstance () const
virtual void Build () override
void SetAssemblyModeToGradient ()
void SetAssemblyModeToPartialDerivative ()
virtual void SetScalarsArrayName (const char *)
virtual char * GetScalarsArrayName ()
virtual void SetScalarsComponent (int)
virtual int GetScalarsComponent ()
virtual void SetDirection (int)
virtual int GetDirection ()
virtual void SetAssemblyMode (int)
virtual int GetAssemblyMode ()
Public Member Functions inherited from vtkvmtkFEAssembler
vtkvmtkFEAssembler * NewInstance () const
virtual int GetNumberOfVariables ()
void DeepCopy (vtkvmtkFEAssembler *src)
void ShallowCopy (vtkvmtkFEAssembler *src)
virtual void SetDataSet (vtkDataSet *)
virtual vtkDataSet * GetDataSet ()
virtual void SetMatrix (vtkvmtkSparseMatrix *)
virtual vtkvmtkSparseMatrix * GetMatrix ()
virtual void SetRHSVector (vtkvmtkDoubleVector *)
virtual vtkvmtkDoubleVector * GetRHSVector ()
virtual void SetSolutionVector (vtkvmtkDoubleVector *)
virtual vtkvmtkDoubleVector * GetSolutionVector ()
virtual void SetQuadratureOrder (int)
virtual int GetQuadratureOrder ()

Static Public Member Functions

static vtkvmtkUnstructuredGridFEGradientAssembler * New ()
static int IsTypeOf (const char *type)
static vtkvmtkUnstructuredGridFEGradientAssembler * SafeDownCast (vtkObjectBase *o)
Static Public Member Functions inherited from vtkvmtkFEAssembler
static int IsTypeOf (const char *type)
static vtkvmtkFEAssembler * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkUnstructuredGridFEGradientAssembler ()
 ~vtkvmtkUnstructuredGridFEGradientAssembler ()
void BuildGradient ()
void BuildPartialDerivative ()
Protected Member Functions inherited from vtkvmtkFEAssembler
 vtkvmtkFEAssembler ()
 ~vtkvmtkFEAssembler ()
void Initialize (int numberOfVariables)

Protected Attributes

char * ScalarsArrayName
int ScalarsComponent
int AssemblyMode
int Direction
Protected Attributes inherited from vtkvmtkFEAssembler
vtkDataSet * DataSet
vtkvmtkSparseMatrix * Matrix
vtkvmtkDoubleVector * RHSVector
vtkvmtkDoubleVector * SolutionVector
int NumberOfVariables
int QuadratureOrder

Detailed Description

Construct a gradient based finite element calculation on a mesh.

Assembles, over a vtkUnstructuredGrid, the finite-element mass matrix and right-hand side vector needed to L2-project either the full gradient (AssemblyMode = VTKVMTK_GRADIENTASSEMBLY) or a single partial derivative along Direction (VTKVMTK_PARTIALDERIVATIVEASSEMBLY) of the scalar point data array named ScalarsArrayName (component ScalarsComponent). Used internally by vtkvmtkUnstructuredGridGradientFilter; solving the assembled system (e.g. with vtkvmtkOpenNLLinearSystemSolver) yields the smoothed nodal gradient.

See also
vtkvmtkFEAssembler, vtkvmtkUnstructuredGridGradientFilter

Definition at line 38 of file vtkvmtkUnstructuredGridFEGradientAssembler.h.

Member Typedef Documentation

◆ Superclass

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Values for AssemblyMode.

Enumerator
VTKVMTK_GRADIENTASSEMBLY 
VTKVMTK_PARTIALDERIVATIVEASSEMBLY 

Definition at line 99 of file vtkvmtkUnstructuredGridFEGradientAssembler.h.

Constructor & Destructor Documentation

◆ vtkvmtkUnstructuredGridFEGradientAssembler()

◆ ~vtkvmtkUnstructuredGridFEGradientAssembler()

vtkvmtkUnstructuredGridFEGradientAssembler::~vtkvmtkUnstructuredGridFEGradientAssembler ( )
protected

Definition at line 42 of file vtkvmtkUnstructuredGridFEGradientAssembler.cxx.

43{
44 if (this->ScalarsArrayName)
45 {
46 delete[] this->ScalarsArrayName;
47 this->ScalarsArrayName = NULL;
48 }
49}

Member Function Documentation

◆ New()

vtkvmtkUnstructuredGridFEGradientAssembler * vtkvmtkUnstructuredGridFEGradientAssembler::New ( )
static

◆ IsTypeOf()

int vtkvmtkUnstructuredGridFEGradientAssembler::IsTypeOf ( const char * type)
static

◆ IsA()

virtual int vtkvmtkUnstructuredGridFEGradientAssembler::IsA ( const char * type)
virtual

Reimplemented from vtkvmtkFEAssembler.

◆ SafeDownCast()

vtkvmtkUnstructuredGridFEGradientAssembler * vtkvmtkUnstructuredGridFEGradientAssembler::SafeDownCast ( vtkObjectBase * o)
static

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkUnstructuredGridFEGradientAssembler::NewInstanceInternal ( ) const
protectedvirtual

Reimplemented from vtkvmtkFEAssembler.

◆ NewInstance()

vtkvmtkUnstructuredGridFEGradientAssembler * vtkvmtkUnstructuredGridFEGradientAssembler::NewInstance ( ) const

◆ Build()

void vtkvmtkUnstructuredGridFEGradientAssembler::Build ( )
overridevirtual

Assemble the mass matrix and RHS vector (see AssemblyMode).

Implements vtkvmtkFEAssembler.

Definition at line 51 of file vtkvmtkUnstructuredGridFEGradientAssembler.cxx.

52{
53 switch (this->AssemblyMode)
54 {
56 this->BuildGradient();
57 break;
60 break;
61 default:
62 vtkErrorMacro("Unsupported AssemblyMode");
63 return;
64 }
65}

◆ SetScalarsArrayName()

virtual void vtkvmtkUnstructuredGridFEGradientAssembler::SetScalarsArrayName ( const char * )
virtual

Set/Get the name of the point data array whose gradient/partial derivative is assembled for.

◆ GetScalarsArrayName()

virtual char * vtkvmtkUnstructuredGridFEGradientAssembler::GetScalarsArrayName ( )
virtual

Set/Get the name of the point data array whose gradient/partial derivative is assembled for.

◆ SetScalarsComponent()

virtual void vtkvmtkUnstructuredGridFEGradientAssembler::SetScalarsComponent ( int )
virtual

Set/Get the component of ScalarsArrayName to use, for multi-component input arrays. Default: 0.

◆ GetScalarsComponent()

virtual int vtkvmtkUnstructuredGridFEGradientAssembler::GetScalarsComponent ( )
virtual

Set/Get the component of ScalarsArrayName to use, for multi-component input arrays. Default: 0.

◆ SetDirection()

virtual void vtkvmtkUnstructuredGridFEGradientAssembler::SetDirection ( int )
virtual

Set/Get the coordinate direction (0=x, 1=y, 2=z) whose partial derivative is assembled for when AssemblyMode is VTKVMTK_PARTIALDERIVATIVEASSEMBLY.

◆ GetDirection()

virtual int vtkvmtkUnstructuredGridFEGradientAssembler::GetDirection ( )
virtual

Set/Get the coordinate direction (0=x, 1=y, 2=z) whose partial derivative is assembled for when AssemblyMode is VTKVMTK_PARTIALDERIVATIVEASSEMBLY.

◆ SetAssemblyMode()

virtual void vtkvmtkUnstructuredGridFEGradientAssembler::SetAssemblyMode ( int )
virtual

Set/Get whether Build() assembles the full gradient (VTKVMTK_GRADIENTASSEMBLY, default) or a single partial derivative along Direction (VTKVMTK_PARTIALDERIVATIVEASSEMBLY). See also SetAssemblyModeToGradient / SetAssemblyModeToPartialDerivative.

◆ GetAssemblyMode()

virtual int vtkvmtkUnstructuredGridFEGradientAssembler::GetAssemblyMode ( )
virtual

Set/Get whether Build() assembles the full gradient (VTKVMTK_GRADIENTASSEMBLY, default) or a single partial derivative along Direction (VTKVMTK_PARTIALDERIVATIVEASSEMBLY). See also SetAssemblyModeToGradient / SetAssemblyModeToPartialDerivative.

◆ SetAssemblyModeToGradient()

void vtkvmtkUnstructuredGridFEGradientAssembler::SetAssemblyModeToGradient ( )
inline

Convenience method: set AssemblyMode to assemble the full gradient (default).

Definition at line 87 of file vtkvmtkUnstructuredGridFEGradientAssembler.h.

◆ SetAssemblyModeToPartialDerivative()

void vtkvmtkUnstructuredGridFEGradientAssembler::SetAssemblyModeToPartialDerivative ( )
inline

Convenience method: set AssemblyMode to assemble a single partial derivative along Direction.

Definition at line 92 of file vtkvmtkUnstructuredGridFEGradientAssembler.h.

◆ BuildGradient()

void vtkvmtkUnstructuredGridFEGradientAssembler::BuildGradient ( )
protected

Definition at line 67 of file vtkvmtkUnstructuredGridFEGradientAssembler.cxx.

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
86 vtkvmtkGaussQuadrature* gaussQuadrature = vtkvmtkGaussQuadrature::New();
87 gaussQuadrature->SetOrder(this->QuadratureOrder);
88
89 vtkvmtkFEShapeFunctions* feShapeFunctions = vtkvmtkFEShapeFunctions::New();
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}
vtkvmtkSparseMatrix * Matrix
vtkvmtkDoubleVector * RHSVector
void Initialize(int numberOfVariables)
void Initialize(vtkCell *cell, vtkDoubleArray *pcoords)
static vtkvmtkFEShapeFunctions * New()
double GetPhi(vtkIdType id, vtkIdType i)
double * GetDPhi(vtkIdType id, vtkIdType i)
double * GetQuadraturePoint(vtkIdType id)
virtual vtkDoubleArray * GetQuadraturePoints()
static vtkvmtkGaussQuadrature * New()
void Initialize(vtkIdType cellType)
double GetQuadratureWeight(vtkIdType id)
virtual void SetOrder(int)

◆ BuildPartialDerivative()

void vtkvmtkUnstructuredGridFEGradientAssembler::BuildPartialDerivative ( )
protected

Definition at line 155 of file vtkvmtkUnstructuredGridFEGradientAssembler.cxx.

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
174 vtkvmtkGaussQuadrature* gaussQuadrature = vtkvmtkGaussQuadrature::New();
175 gaussQuadrature->SetOrder(this->QuadratureOrder);
176
177 vtkvmtkFEShapeFunctions* feShapeFunctions = vtkvmtkFEShapeFunctions::New();
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}

Member Data Documentation

◆ ScalarsArrayName

char* vtkvmtkUnstructuredGridFEGradientAssembler::ScalarsArrayName
protected

◆ ScalarsComponent

int vtkvmtkUnstructuredGridFEGradientAssembler::ScalarsComponent
protected

◆ AssemblyMode

int vtkvmtkUnstructuredGridFEGradientAssembler::AssemblyMode
protected

◆ Direction

int vtkvmtkUnstructuredGridFEGradientAssembler::Direction
protected

The documentation for this class was generated from the following files: