TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Vecteur3.h
1/****************************************************************************
2* Copyright (c) 2024, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15#ifndef Vecteur3_included
16#define Vecteur3_included
17#include <assert.h>
18#include <TRUSTTab.h>
19
20// Attention: le constructeur par defaut n'initialise pas le vecteur !
22{
23public:
26 {
27 for (int i = 0; i < 3; i++)
28 v[i] = w.v[i];
29 }
30 Vecteur3(double x, double y, double z)
31 {
32 v[0] = x;
33 v[1] = y;
34 v[2] = z;
35 }
36 void set(double x, double y, double z)
37 {
38 v[0] = x;
39 v[1] = y;
40 v[2] = z;
41 }
42
43 void set(const DoubleTab& tab, int i)
44 {
45 assert(tab.line_size() == 3);
46 assert(i >= 0 && i < tab.dimension_tot(0));
47 const double *ptr = tab.addr() + i * 3;
48 for (int j = 0; j < 3; j++)
49 v[j] = ptr[j];
50 }
51 double length() const
52 {
53 return sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);
54 };
55 Vecteur3(const DoubleTab& tab, int i)
56 {
57 assert(tab.line_size() == 3);
58 assert(i >= 0 && i < tab.dimension_tot(0));
59 const double *ptr = tab.addr() + i * 3;
60 for (int j = 0; j < 3; j++)
61 v[j] = ptr[j];
62 }
63 Vecteur3(const ArrOfDouble& arr)
64 {
65 assert(arr.size_array() == 3);
66 for (int i = 0; i < 3; i++)
67 v[i] = arr[i];
68 }
70 {
71 for (int i = 0; i < 3; i++)
72 v[i] = x;
73 return *this;
74 }
76 {
77 for (int i = 0; i < 3; i++)
78 v[i] *= x;
79 return *this;
80 }
82 {
83 for (int i = 0; i < 3; i++)
84 v[i] += x[i];
85 return *this;
86 }
87
89 {
90 for (int i = 0; i < 3; i++)
91 v[i] = w[i];
92 return *this;
93 }
94 double operator[](int i) const
95 {
96 assert(i>=0 && i<3);
97 return v[i];
98 }
99 double& operator[](int i)
100 {
101 assert(i>=0 && i<3);
102 return v[i];
103 }
104 inline double norme_Linfini();
105 static inline void produit_vectoriel(const Vecteur3& x, const Vecteur3& y, Vecteur3& resu);
106 static inline double produit_scalaire(const Vecteur3& x, const Vecteur3& y);
107 friend class Matrice33;
108 friend Vecteur3 operator-(const Vecteur3&, const Vecteur3&);
109protected:
110 double v[3];
111 void init()
112 {
113 for (int i = 0; i < 3; i++)
114 v[i] = 0.;
115 }
116};
117
118inline Vecteur3 operator-(const Vecteur3&, const Vecteur3&);
119
120#endif
_SIZE_ size_array() const
_TYPE_ * addr()
_SIZE_ dimension_tot(int) const override
Definition TRUSTTab.tpp:160
int line_size() const
Definition TRUSTVect.tpp:67
static double produit_scalaire(const Vecteur3 &x, const Vecteur3 &y)
Vecteur3()
Definition Vecteur3.h:24
void set(const DoubleTab &tab, int i)
Definition Vecteur3.h:43
Vecteur3 & operator=(double x)
Definition Vecteur3.h:69
static void produit_vectoriel(const Vecteur3 &x, const Vecteur3 &y, Vecteur3 &resu)
Vecteur3 & operator*=(double x)
Definition Vecteur3.h:75
double operator[](int i) const
Definition Vecteur3.h:94
Vecteur3(double x, double y, double z)
Definition Vecteur3.h:30
double norme_Linfini()
norme L_infini, c'est le max des abs(v[i])
friend Vecteur3 operator-(const Vecteur3 &, const Vecteur3 &)
void set(double x, double y, double z)
Definition Vecteur3.h:36
double v[3]
Definition Vecteur3.h:110
void init()
Definition Vecteur3.h:111
Vecteur3(const Vecteur3 &w)
Definition Vecteur3.h:25
Vecteur3(const ArrOfDouble &arr)
Definition Vecteur3.h:63
Vecteur3 & operator+=(const Vecteur3 &x)
Definition Vecteur3.h:81
double length() const
Definition Vecteur3.h:51
double & operator[](int i)
Definition Vecteur3.h:99
friend class Matrice33
Definition Vecteur3.h:107
Vecteur3(const DoubleTab &tab, int i)
Definition Vecteur3.h:55
Vecteur3 & operator=(const Vecteur3 &w)
Definition Vecteur3.h:88