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

Serves as the base class for vectors utilized in finite-element and other PDE evaluations. More...

#include <vtkvmtkDoubleVector.h>

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

Public Types

typedef vtkObject Superclass

Public Member Functions

virtual int IsA (const char *type)
vtkvmtkDoubleVector * NewInstance () const
virtual vtkIdType GetNumberOfElements ()
virtual vtkIdType GetNumberOfElementsPerVariable ()
virtual vtkIdType GetNumberOfVariables ()
void Allocate (vtkIdType numberOfElementsPerVariable, vtkIdType numberOfVariables=1)
void Fill (double value)
void Assign (vtkvmtkDoubleVector *src)
void Assign (vtkIdType numberOfElements, const double *array)
double GetElement (vtkIdType i)
void SetElement (vtkIdType i, double value)
void AddElement (vtkIdType i, double value)
const double * GetArray ()
void CopyIntoArrayComponent (vtkDataArray *array, int component)
void CopyVariableIntoArrayComponent (vtkDataArray *array, int variable, int component)
double ComputeNorm ()
void Add (vtkvmtkDoubleVector *vectorToAdd)
void Subtract (vtkvmtkDoubleVector *vectorToSubtract)
void MultiplyBy (double scalar)
double Dot (vtkvmtkDoubleVector *vectorToDotWith)
void DeepCopy (vtkvmtkDoubleVector *src)
virtual void SetNormType (int)
virtual int GetNormType ()
void SetNormTypeToL2 ()
void SetNormTypeToLInf ()

Static Public Member Functions

static vtkvmtkDoubleVector * New ()
static int IsTypeOf (const char *type)
static vtkvmtkDoubleVector * SafeDownCast (vtkObjectBase *o)

Protected Member Functions

virtual vtkObjectBase * NewInstanceInternal () const
 vtkvmtkDoubleVector ()
 ~vtkvmtkDoubleVector ()

Protected Attributes

vtkIdType NumberOfElements
vtkIdType NumberOfElementsPerVariable
vtkIdType NumberOfVariables
int NormType
double * Array

Detailed Description

Serves as the base class for vectors utilized in finite-element and other PDE evaluations.

vtkvmtkDoubleVector wraps a plain double array with the bookkeeping needed by vmtk's finite-element machinery: it can be Allocate()d for a given number of elements per variable and number of variables (so that, e.g., a solution with several unknowns per node can be stored as one contiguous array, see CopyVariableIntoArrayComponent), and it provides basic linear-algebra operations (Add, Subtract, MultiplyBy, Dot, ComputeNorm) used by iterative linear system solvers. It is used throughout the DifferentialGeometry classes as the concrete type for right-hand-side and solution vectors (see vtkvmtkLinearSystem, vtkvmtkFEAssembler).

See also
vtkvmtkLinearSystem, vtkvmtkFEAssembler, vtkvmtkLinearSystemSolver

Definition at line 45 of file vtkvmtkDoubleVector.h.

Member Typedef Documentation

◆ Superclass

Definition at line 50 of file vtkvmtkDoubleVector.h.

Constructor & Destructor Documentation

◆ vtkvmtkDoubleVector()

vtkvmtkDoubleVector::vtkvmtkDoubleVector ( )
protected

Definition at line 32 of file vtkvmtkDoubleVector.cxx.

33{
35 this->NumberOfElements = 0;
37 this->NumberOfVariables = 0;
38 this->Array = NULL;
39 //this->Locked = NULL;
40}
#define VTK_VMTK_L2_NORM

◆ ~vtkvmtkDoubleVector()

vtkvmtkDoubleVector::~vtkvmtkDoubleVector ( )
protected

Definition at line 42 of file vtkvmtkDoubleVector.cxx.

43{
44 if (this->Array != NULL)
45 {
46 delete [] this->Array;
47 this->Array = NULL;
48 }
49 //if (this->Locked != NULL)
50 // {
51 // delete [] this->Locked;
52 // this->Locked = NULL;
53 // }
54}

Member Function Documentation

◆ New()

vtkvmtkDoubleVector * vtkvmtkDoubleVector::New ( )
static

◆ IsTypeOf()

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

◆ IsA()

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

◆ SafeDownCast()

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

◆ NewInstanceInternal()

virtual vtkObjectBase * vtkvmtkDoubleVector::NewInstanceInternal ( ) const
protectedvirtual

◆ NewInstance()

vtkvmtkDoubleVector * vtkvmtkDoubleVector::NewInstance ( ) const

◆ SetNormType()

virtual void vtkvmtkDoubleVector::SetNormType ( int )
virtual

Set/get the norm type computed by ComputeNorm(): VTK_VMTK_L2_NORM (Euclidean norm, default) or VTK_VMTK_LINF_NORM (maximum element value).

◆ GetNormType()

virtual int vtkvmtkDoubleVector::GetNormType ( )
virtual

Set/get the norm type computed by ComputeNorm(): VTK_VMTK_L2_NORM (Euclidean norm, default) or VTK_VMTK_LINF_NORM (maximum element value).

◆ SetNormTypeToL2()

void vtkvmtkDoubleVector::SetNormTypeToL2 ( )
inline

Set/get the norm type computed by ComputeNorm(): VTK_VMTK_L2_NORM (Euclidean norm, default) or VTK_VMTK_LINF_NORM (maximum element value).

Definition at line 59 of file vtkvmtkDoubleVector.h.

virtual void SetNormType(int)

◆ SetNormTypeToLInf()

void vtkvmtkDoubleVector::SetNormTypeToLInf ( )
inline

Set/get the norm type computed by ComputeNorm(): VTK_VMTK_L2_NORM (Euclidean norm, default) or VTK_VMTK_LINF_NORM (maximum element value).

Definition at line 61 of file vtkvmtkDoubleVector.h.

#define VTK_VMTK_LINF_NORM

◆ GetNumberOfElements()

virtual vtkIdType vtkvmtkDoubleVector::GetNumberOfElements ( )
virtual

Get the total number of elements in the vector, i.e. NumberOfElementsPerVariable * NumberOfVariables.

◆ GetNumberOfElementsPerVariable()

virtual vtkIdType vtkvmtkDoubleVector::GetNumberOfElementsPerVariable ( )
virtual

Get the number of elements per variable, as set by the last call to Allocate().

◆ GetNumberOfVariables()

virtual vtkIdType vtkvmtkDoubleVector::GetNumberOfVariables ( )
virtual

Get the number of variables (i.e. the number of consecutive blocks of NumberOfElementsPerVariable elements), as set by the last call to Allocate().

◆ Allocate()

void vtkvmtkDoubleVector::Allocate ( vtkIdType numberOfElementsPerVariable,
vtkIdType numberOfVariables = 1 )

Allocate the internal array to hold numberOfElementsPerVariable * numberOfVariables elements, discarding any previous content. The array is laid out as numberOfVariables consecutive blocks of numberOfElementsPerVariable elements each (see CopyVariableIntoArrayComponent).

Definition at line 56 of file vtkvmtkDoubleVector.cxx.

57{
58 if ( this->Array != NULL )
59 {
60 delete [] this->Array;
61 this->Array = NULL;
62 }
63
64 this->NumberOfElements = numberOfElementsPerVariable * numberOfVariables;
65 this->NumberOfElementsPerVariable = numberOfElementsPerVariable;
66 this->NumberOfVariables = numberOfVariables;
67 this->Array = new double[this->NumberOfElements];
68 //this->Locked = new bool[this->NumberOfElements];
69}

◆ Fill()

void vtkvmtkDoubleVector::Fill ( double value)

Set every element of the vector to value.

Definition at line 71 of file vtkvmtkDoubleVector.cxx.

72{
73 for (vtkIdType i=0; i<this->NumberOfElements; i++)
74 {
75 this->Array[i] = value;
76 }
77}

◆ Assign() [1/2]

void vtkvmtkDoubleVector::Assign ( vtkvmtkDoubleVector * src)

Copy the contents of src into this vector. The two vectors must already have the same number of elements.

Definition at line 87 of file vtkvmtkDoubleVector.cxx.

88{
89 if (this->NumberOfElements != src->NumberOfElements)
90 {
91 vtkErrorMacro(<< "Vectors have different number of elements.");
92 }
93
95 memcpy(this->Array, src->Array, src->NumberOfElements * sizeof(double));
96}

◆ Assign() [2/2]

void vtkvmtkDoubleVector::Assign ( vtkIdType numberOfElements,
const double * array )

Copy numberOfElements values from the raw C array into this vector's internal array (which must already be allocated with at least that many elements).

Definition at line 98 of file vtkvmtkDoubleVector.cxx.

99{
100 this->NumberOfElements = numberOfElements;
101 memcpy(this->Array, array, numberOfElements * sizeof(double));
102}

◆ GetElement()

double vtkvmtkDoubleVector::GetElement ( vtkIdType i)
inline

Get the value of the i-th element.

Definition at line 109 of file vtkvmtkDoubleVector.h.

109{return this->Array[i];};

◆ SetElement()

void vtkvmtkDoubleVector::SetElement ( vtkIdType i,
double value )
inline

Set the value of the i-th element.

Definition at line 114 of file vtkvmtkDoubleVector.h.

114{this->Array[i] = value;};

◆ AddElement()

void vtkvmtkDoubleVector::AddElement ( vtkIdType i,
double value )
inline

Add value to the current value of the i-th element.

Definition at line 119 of file vtkvmtkDoubleVector.h.

119{this->Array[i] += value;};

◆ GetArray()

const double * vtkvmtkDoubleVector::GetArray ( )
inline

Get direct read-only access to the underlying raw double array.

Definition at line 128 of file vtkvmtkDoubleVector.h.

128{return this->Array;};

◆ CopyIntoArrayComponent()

void vtkvmtkDoubleVector::CopyIntoArrayComponent ( vtkDataArray * array,
int component )

Copy this vector's elements into the given component of array, growing array's number of components and/or tuples as needed to fit.

Definition at line 191 of file vtkvmtkDoubleVector.cxx.

192{
193 vtkIdType i;
194
195 if (array==NULL)
196 {
197 vtkErrorMacro(<<"NULL vtkDoubleArray provided!");
198 return;
199 }
200
201 if (component > array->GetNumberOfComponents()-1)
202 {
203 array->SetNumberOfComponents(component+1);
204 }
205
206 if (this->NumberOfElements>array->GetNumberOfTuples())
207 {
208 array->SetNumberOfTuples(this->NumberOfElements);
209 }
210
211 for (i=0; i<this->NumberOfElements; i++)
212 {
213 array->SetComponent(i,component,this->Array[i]);
214 }
215}

◆ CopyVariableIntoArrayComponent()

void vtkvmtkDoubleVector::CopyVariableIntoArrayComponent ( vtkDataArray * array,
int variable,
int component )

Copy the block of NumberOfElementsPerVariable elements belonging to the given variable index into the given component of array, growing array's number of components and/or tuples as needed to fit.

Definition at line 217 of file vtkvmtkDoubleVector.cxx.

218{
219 vtkIdType i;
220
221 if (array==NULL)
222 {
223 vtkErrorMacro(<<"NULL vtkDoubleArray provided!");
224 return;
225 }
226
227 if (component > array->GetNumberOfComponents()-1)
228 {
229 array->SetNumberOfComponents(component+1);
230 }
231
232 if (this->NumberOfElementsPerVariable > array->GetNumberOfTuples())
233 {
234 array->SetNumberOfTuples(this->NumberOfElementsPerVariable);
235 }
236
237 for (i=0; i<this->NumberOfElementsPerVariable; i++)
238 {
239 array->SetComponent(i,component,this->Array[i+variable*this->NumberOfElementsPerVariable]);
240 }
241}

◆ ComputeNorm()

double vtkvmtkDoubleVector::ComputeNorm ( )

Compute and return the norm of the vector, according to NormType.

Definition at line 104 of file vtkvmtkDoubleVector.cxx.

105{
106 vtkIdType i;
107 double norm = 0.0;
108 double value;
109
110 if (this->NormType==VTK_VMTK_L2_NORM)
111 {
112 norm = 0.0;
113 for (i=0; i<this->NumberOfElements; i++)
114 {
115 value = this->Array[i];
116 norm += value * value;
117 }
118 norm = std::sqrt(norm);
119 }
120 else if (this->NormType==VTK_VMTK_LINF_NORM)
121 {
122 norm = -VTK_VMTK_LARGE_DOUBLE;
123 for (i=0; i<this->NumberOfElements; i++)
124 {
125 value = this->Array[i];
126 if (value>norm)
127 {
128 norm = value;
129 }
130 }
131 }
132
133 return norm;
134}
#define VTK_VMTK_LARGE_DOUBLE

◆ Add()

void vtkvmtkDoubleVector::Add ( vtkvmtkDoubleVector * vectorToAdd)

Add vectorToAdd element-wise to this vector (in place). The two vectors must have the same number of elements.

Definition at line 136 of file vtkvmtkDoubleVector.cxx.

137{
138 if (this->NumberOfElements != vectorToAdd->NumberOfElements)
139 {
140 vtkErrorMacro(<< "Vector to add does not have the same number of elements.");
141 return;
142 }
143
144 for (int i=0; i<this->NumberOfElements; i++)
145 {
146 this->Array[i] += vectorToAdd->GetElement(i);
147 }
148}
double GetElement(vtkIdType i)

◆ Subtract()

void vtkvmtkDoubleVector::Subtract ( vtkvmtkDoubleVector * vectorToSubtract)

Subtract vectorToSubtract element-wise from this vector (in place). The two vectors must have the same number of elements.

Definition at line 150 of file vtkvmtkDoubleVector.cxx.

151{
152 if (this->NumberOfElements != vectorToSubtract->NumberOfElements)
153 {
154 vtkErrorMacro(<< "Vector to add does not have the same number of elements.");
155 return;
156 }
157
158 for (int i=0; i<this->NumberOfElements; i++)
159 {
160 this->Array[i] -= vectorToSubtract->GetElement(i);
161 }
162}

◆ MultiplyBy()

void vtkvmtkDoubleVector::MultiplyBy ( double scalar)

Multiply every element of this vector by scalar (in place).

Definition at line 164 of file vtkvmtkDoubleVector.cxx.

165{
166 for (int i=0; i<this->NumberOfElements; i++)
167 {
168 this->Array[i] *= scalar;
169 }
170}

◆ Dot()

double vtkvmtkDoubleVector::Dot ( vtkvmtkDoubleVector * vectorToDotWith)

Compute and return the dot product of this vector with vectorToDotWith. The two vectors must have the same number of elements.

Definition at line 172 of file vtkvmtkDoubleVector.cxx.

173{
174 double dot;
175
176 if (this->NumberOfElements != vectorToDotWith->NumberOfElements)
177 {
178 vtkErrorMacro(<< "Vector to add does not have the same number of elements.");
179 return 0.0;
180 }
181
182 dot = 0.0;
183 for (int i=0; i<this->NumberOfElements; i++)
184 {
185 dot += this->Array[i] * vectorToDotWith->Array[i];
186 }
187
188 return dot;
189}

◆ DeepCopy()

void vtkvmtkDoubleVector::DeepCopy ( vtkvmtkDoubleVector * src)

Reallocate this vector's internal array and copy into it the size and contents of src.

Definition at line 243 of file vtkvmtkDoubleVector.cxx.

244{
248 if (this->Array != NULL)
249 {
250 delete [] this->Array;
251 this->Array = NULL;
252 }
253
254 this->Array = new double[src->NumberOfElements];
255 memcpy(this->Array, src->Array, src->NumberOfElements * sizeof(double));
256// memcpy(this->Locked, src->Locked, src->NumberOfElements * sizeof(bool));
257}

Member Data Documentation

◆ NumberOfElements

vtkIdType vtkvmtkDoubleVector::NumberOfElements
protected

Definition at line 180 of file vtkvmtkDoubleVector.h.

◆ NumberOfElementsPerVariable

vtkIdType vtkvmtkDoubleVector::NumberOfElementsPerVariable
protected

Definition at line 181 of file vtkvmtkDoubleVector.h.

◆ NumberOfVariables

vtkIdType vtkvmtkDoubleVector::NumberOfVariables
protected

Definition at line 182 of file vtkvmtkDoubleVector.h.

◆ NormType

int vtkvmtkDoubleVector::NormType
protected

Definition at line 184 of file vtkvmtkDoubleVector.h.

◆ Array

double* vtkvmtkDoubleVector::Array
protected

Definition at line 186 of file vtkvmtkDoubleVector.h.


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