AQUAgpusph 4.1.2
Loading...
Searching...
No Matches
2D.h
Go to the documentation of this file.
1/*
2 * This file is part of AQUAgpusph, a free CFD program based on SPH.
3 * Copyright (C) 2012 Jose Luis Cercos Pita <jl.cercos@upm.es>
4 *
5 * AQUAgpusph is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * AQUAgpusph is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with AQUAgpusph. If not, see <http://www.gnu.org/licenses/>.
17 */
18
23#ifndef INFINITY
24 #define INFINITY FLT_MAX
25#endif
26
27#define unit unsigned int
28#define vec2 float2
29#define vec3 float3
30#define vec4 float4
31#define ivec2 int2
32#define ivec3 int3
33#define ivec4 int4
34#define uivec2 uint2
35#define uivec3 uint3
36#define uivec4 uint4
37
38#define vec float2
39#define ivec int2
40#define uivec uint2
41#define matrix float4
42
50#define _CONVERT(TYPE) convert_ ## TYPE
51
63#define CONVERT(TYPE, v) _CONVERT(TYPE)(v)
64
67#define VEC_ZERO ((float2)(0.f,0.f))
70#define VEC_ONE ((float2)(1.f, 1.f))
73#define VEC_ALL_ONE VEC_ONE
76#define VEC_INFINITY ((float2)(INFINITY, INFINITY))
79#define VEC_ALL_INFINITY VEC_INFINITY
82#define VEC_NEG_INFINITY (-VEC_INFINITY)
85#define VEC_ALL_NEG_INFINITY (-VEC_ALL_INFINITY)
86
89#define MAT_ZERO ((float4)(0.f, 0.f, \
90 0.f, 0.f))
93#define MAT_ONE ((float4)(1.f, 1.f, \
94 1.f, 1.f))
97#define MAT_ALL_ONE MAT_ONE
102#define MAT_EYE ((float4)(1.f, 0.f, \
103 0.f, 1.f))
106#define MAT_ALL_EYE MAT_EYE
107
117#define vec_xyz vec2
118
128#define ivec_xyz ivec2
129
139#define uivec_xyz uivec2
140
147#define XYZ xy
148
156#define C_I() const uint c_i = icell[i]
157
180#define BEGIN_LOOP_OVER_NEIGHS() \
181 C_I(); \
182 for(int ci = -1; ci <= 1; ci++) { \
183 for(int cj = -1; cj <= 1; cj++) { \
184 const uint c_j = c_i + \
185 ci + \
186 cj * n_cells.x; \
187 uint j = ihoc[c_j]; \
188 while((j < N) && (icell[j] == c_j)) {
189
194#define END_LOOP_OVER_NEIGHS() \
195 j++; \
196 } \
197 } \
198 }
199
202#define MATRIX_DOT(_M, _V) \
203 ((float2)(dot(_M.s01, _V), \
204 dot(_M.s23, _V)))
205
208#define MATRIX_DOT_ALL MATRIX_DOT
209
212#define MATRIX_MUL(_M1, _M2) \
213 ((float4)(dot(_M1.s01, _M2.s02), dot(_M1.s01, _M2.s13), \
214 dot(_M1.s23, _M2.s02), dot(_M1.s23, _M2.s13)))
215
218#define MATRIX_MUL_ALL MATRIX_MUL
219
222#define TRANSPOSE s0213
223
226#define DIAG s03
227
230#define MATRIX_FROM_DIAG(_V) \
231 ((float4)(_V.x, 0.f, \
232 0.f, _V.y))
233
238#define MATRIX_TRACE(_M) (_M.s0 + _M.s3)
239
246matrix outer(const vec v1, const vec v2)
247{
248 matrix m;
249 m.s01 = v1.x * v2;
250 m.s23 = v1.y * v2;
251 return m;
252}
253
259float det(const matrix m)
260{
261 return m.s0 * m.s3 - m.s1 * m.s2;
262}
263
272{
273 const float d = 1.f / det(m);
274 if(fabs(d) > 1.e16f) {
275 return MAT_ALL_EYE;
276 }
277 return ((matrix)( m.s3, -m.s1,
278 -m.s2, m.s0)) * d;
279}
280
286#define MATRIX_INV(_M) \
287 MATRIX_MUL(inv(MATRIX_MUL(_M.TRANSPOSE, _M)), _M.TRANSPOSE)
float det(const matrix m)
Determinant of a matrix.
Definition: 2D.h:259
#define MAT_ALL_EYE
MAT_EYE.
Definition: 2D.h:106
matrix inv(const matrix m)
Inverse of a matrix.
Definition: 2D.h:271
matrix outer(const vec v1, const vec v2)
Perform the outer product of two vectors.
Definition: 2D.h:246
#define vec
Definition: 2D.h:38
#define matrix
Definition: 2D.h:41