t8  UNKNOWN
t8code is a C library to manage a forest of adaptive space-trees of general element classes in parallel.
t8_vec.h
Go to the documentation of this file.
1 /*
2  This file is part of t8code.
3  t8code is a C library to manage a collection (a forest) of multiple
4  connected adaptive space-trees of general element classes in parallel.
5 
6  Copyright (C) 2015 the developers
7 
8  t8code is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  t8code is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with t8code; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
27 #ifndef T8_VEC_H
28 #define T8_VEC_H
29 
30 #include <t8.h>
31 
32 T8_EXTERN_C_BEGIN ();
33 
38 static inline double
39 t8_vec_norm (const double vec[3])
40 {
41  double norm = 0;
42 
43  for (int i = 0; i < 3; i++) {
44  norm += vec[i] * vec[i];
45  }
46  return sqrt (norm);
47 }
48 
55 static inline double
56 t8_vec_dist (const double vec_x[3], const double vec_y[3])
57 {
58  double dist = 0;
59 
60  for (int i = 0; i < 3; i++) {
61  dist += SC_SQR (vec_x[i] - vec_y[i]);
62  }
63  return sqrt (dist);
64 }
65 
70 static inline void
71 t8_vec_ax (double vec_x[3], const double alpha)
72 {
73  for (int i = 0; i < 3; i++) {
74  vec_x[i] *= alpha;
75  }
76 }
77 
83 static inline void
84 t8_vec_axy (const double vec_x[3], double vec_y[3], const double alpha)
85 {
86  for (int i = 0; i < 3; i++) {
87  vec_y[i] = vec_x[i] * alpha;
88  }
89 }
90 
99 static inline void
100 t8_vec_axb (const double vec_x[3], double vec_y[3], const double alpha, const double b)
101 {
102  for (int i = 0; i < 3; i++) {
103  vec_y[i] = alpha * vec_x[i] + b;
104  }
105 }
106 
113 static inline void
114 t8_vec_axpy (const double vec_x[3], double vec_y[3], const double alpha)
115 {
116  for (int i = 0; i < 3; i++) {
117  vec_y[i] += alpha * vec_x[i];
118  }
119 }
120 
126 static inline void
127 t8_vec_axpyz (const double vec_x[3], const double vec_y[3], double vec_z[3], const double alpha)
128 {
129  for (int i = 0; i < 3; i++) {
130  vec_z[i] = vec_y[i] + alpha * vec_x[i];
131  }
132 }
133 
139 static inline double
140 t8_vec_dot (const double vec_x[3], const double vec_y[3])
141 {
142  double dot = 0;
143 
144  for (int i = 0; i < 3; i++) {
145  dot += vec_x[i] * vec_y[i];
146  }
147  return dot;
148 }
149 
155 static inline void
156 t8_vec_cross (const double vec_x[3], const double vec_y[3], double cross[3])
157 {
158  for (int i = 0; i < 3; i++) {
159  cross[i] = vec_x[(i + 1) % 3] * vec_y[(i + 2) % 3] - vec_x[(i + 2) % 3] * vec_y[(i + 1) % 3];
160  }
161 }
162 
168 static inline void
169 t8_vec_diff (const double vec_x[3], const double vec_y[3], double diff[3])
170 {
171  for (int i = 0; i < 3; i++) {
172  diff[i] = vec_x[i] - vec_y[i];
173  }
174 }
175 
176 T8_EXTERN_C_END ();
177 
178 #endif /* !T8_VEC_H! */
This is the administrative header file for t8code.