NeoPZ
pznumeric.cpp
Go to the documentation of this file.
1 
6 #include "pznumeric.h"
7 #include <iostream>
8 #include <cmath>
9 #include <algorithm>
10 #include <numeric>
11 #include <functional>
12 
13 using namespace std;
14 
15 template <class Tvar>
16 Tvar TPZNumeric::Norm(const TPZVec<Tvar> &vetor){
17  const int size = vetor.NElements();
18  Tvar norma=0;
19  for (int i=0; i<size; i++) {
20  norma += vetor[i]*vetor[i];
21  }
22  return sqrt(norma);
23 }
24 
25 template <class Tvar>
27  int i;
28  Tvar norma = TPZNumeric::Norm(vetor);
29  for(i=0; i<3; i++) vetor[i] = vetor[i]/norma;
30 }
31 
32 template <class Tvar>
34  int i,n;
35  n = vetor.NElements();
36  Tvar norma = TPZNumeric::Norm(vetor);
37  for(i=0; i< n; i++) vetor[i] = vetor[i]/norma;
38 }
39 
41 }
43 }
44 
46 template <class Tvar>
47 void TPZNumeric::SortArray3(const TPZVec<Tvar> &array,int ordem[3]){
48  int i;
49  Tvar vetor[3];
50  for(i=0; i<3; i++) vetor[i]=fabs(array[i]);
51 
52  if (vetor[0] >= vetor[1]) {
53  if (vetor[1] >= vetor[2]) {
54  ordem[0] = 0;
55  ordem[1] = 1;
56  ordem[2] = 2;
57  }
58  else if (vetor[2] >= vetor[0]) {
59  ordem[0] = 2;
60  ordem[1] = 0;
61  ordem[2] = 1;
62  }
63  else{
64  ordem[0] = 0;
65  ordem[1] = 2;
66  ordem[2] = 1;
67  }
68  }
69  else {
70  if (vetor[0] >= vetor[2]) {
71  ordem[0] = 1;
72  ordem[1] = 0;
73  ordem[2] = 2;
74  }
75  else if (vetor[2] >= vetor[1]) {
76  ordem[0] = 2;
77  ordem[1] = 1;
78  ordem[2] = 0;
79  }
80  else {
81  ordem[0] = 1;
82  ordem[1] = 2;
83  ordem[2] = 0;
84  }
85  }
86 }
87 
88 template <class Tvar>
90  int size = array.NElements();
91  sort(&array[0], &array[size], greater<Tvar>());
92 }
93 
95 template <class Tvar>
97  int i;
98  Tvar aux[3];
99  for(i=0; i<3; i++){
100  aux[i]= u[(i+1)%3]*v[(i+2)%3] - u[(i+2)%3]*v[(i+1)%3];
101  }
102  for(i=0; i<3; i++){
103  result[i]= aux[i];
104  }
105 }
106 
107 template
108 void TPZNumeric::SortArray3<REAL>(const TPZVec<REAL> &array, int ordem[3]);
109 template
110 void TPZNumeric::SortArray3<REAL>(TPZVec<REAL> &array);
111 template
112 void TPZNumeric::ProdVetorial<REAL>(TPZVec<REAL> &u, TPZVec<REAL> &v, TPZVec<REAL> &result);
113 template
114 void TPZNumeric::NormalizeVetor3<REAL>(TPZVec<REAL> &vetor);
115 template
116 void TPZNumeric::NormalizeVetor<REAL>(TPZVec<REAL> &vetor);
117 template
118 REAL TPZNumeric::Norm(const TPZVec<REAL> &vetor);
119 
120 
121 #ifdef _AUTODIFF
122 template
123 void TPZNumeric::SortArray3<Fad<REAL>>(const TPZVec<Fad<REAL>> &array, int ordem[3]);
124 template
125 void TPZNumeric::SortArray3<Fad<REAL>>(TPZVec<Fad<REAL>> &array);
126 template
127 void TPZNumeric::ProdVetorial<Fad<REAL>>(TPZVec<Fad<REAL>> &u, TPZVec<Fad<REAL>> &v, TPZVec<Fad<REAL>> &result);
128 template
129 void TPZNumeric::NormalizeVetor3<Fad<REAL>>(TPZVec<Fad<REAL>> &vetor);
130 template
131 void TPZNumeric::NormalizeVetor<Fad<REAL>>(TPZVec<Fad<REAL>> &vetor);
132 template
134 #endif
135 
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
Definition: tfadfunc.h:140
Definition: fad.h:54
This class implements a simple vector storage scheme for a templated class T. Utility.
Definition: pzgeopoint.h:19
static void NormalizeVetor3(TPZVec< Tvar > &vetor)
Normalizes the vector with 3 elements.
Definition: pznumeric.cpp:26
static void ProdVetorial(TPZVec< Tvar > &u, TPZVec< Tvar > &v, TPZVec< Tvar > &result)
Computes the vectorial product u x v.
Definition: pznumeric.cpp:96
static void SortArray3(const TPZVec< Tvar > &array, int ordem[3])
Sorts in descending order, in absolute value and stores the indexes in ordem.
Definition: pznumeric.cpp:47
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ sqrt
Definition: tfadfunc.h:120
static Tvar Norm(const TPZVec< Tvar > &vetor)
Returns the L2-norm of the vector.
Definition: pznumeric.cpp:16
int64_t NElements() const
Returns the number of elements of the vector.
Definition: pzvec.h:190
static void NormalizeVetor(TPZVec< Tvar > &vetor)
Normalizes the vector.
Definition: pznumeric.cpp:33
Contains declaration of the TPZNumeric class which implements several methods to calculation.