AQUAgpusph 5.0.4
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
22
23#define vec float2
24#define dvec double2
25#define ivec int2
26#define lvec long2
27#define uivec uint2
28#define ulvec ulong2
29#define svec usize2
30#define ssvec ssize2
31#define matrix float4
32
35#define VEC_ZERO ((float2)(0.f,0.f))
38#define VEC_ONE ((float2)(1.f, 1.f))
41#define VEC_ALL_ONE VEC_ONE
44#define VEC_INFINITY ((float2)(INFINITY, INFINITY))
47#define VEC_ALL_INFINITY VEC_INFINITY
50#define VEC_NEG_INFINITY (-VEC_INFINITY)
53#define VEC_ALL_NEG_INFINITY (-VEC_ALL_INFINITY)
54
57#define MAT_ZERO ((float4)(0.f, 0.f, \
58 0.f, 0.f))
59
61#define MAT_ONE ((float4)(1.f, 1.f, \
62 1.f, 1.f))
63
65#define MAT_ALL_ONE MAT_ONE
70#define MAT_EYE ((float4)(1.f, 0.f, \
71 0.f, 1.f))
72
74#define MAT_ALL_EYE MAT_EYE
75
86#define vec_xyz vec2
87#define dvec_xyz dvec2
88#define ivec_xyz ivec2
89#define lvec_xyz lvec2
90#define uivec_xyz uivec2
91#define ulvec_xyz ulvec2
92#define svec_xyz svec2
93#define ssvec_xyz ssvec2
95
102#define XYZ xy
103
126#define BEGIN_LOOP_OVER_NEIGHS() \
127 C_I(); \
128 for(int ci = -1; ci <= 1; ci++) { \
129 for(int cj = -1; cj <= 1; cj++) { \
130 const usize c_j = c_i + \
131 ci + \
132 cj * n_cells.x; \
133 usize j = ihoc[c_j]; \
134 while((j < N) && (icell[j] == c_j)) {
135
140#define END_LOOP_OVER_NEIGHS() \
141 j++; \
142 } \
143 } \
144 }
145
174#define BEGIN_NEIGHS(CELL, NPARTS, NCELLS, ICELL, IHOC) \
175 for(int __ci = -1; __ci <= 1; __ci++) { \
176 for(int __cj = -1; __cj <= 1; __cj++) { \
177 const usize __c_j = CELL + \
178 __ci + \
179 __cj * NCELLS.x; \
180 usize j = IHOC[__c_j]; \
181 while((j < NPARTS) && (ICELL[j] == __c_j)) {
182
189#define END_NEIGHS() \
190 j++; \
191 } \
192 } \
193 }
194
197#define MATRIX_DOT(_M, _V) \
198 ((float2)(dot(_M.s01, _V), \
199 dot(_M.s23, _V)))
200
203#define MATRIX_DOT_ALL MATRIX_DOT
204
207#define MATRIX_MUL(_M1, _M2) \
208 ((float4)(dot(_M1.s01, _M2.s02), dot(_M1.s01, _M2.s13), \
209 dot(_M1.s23, _M2.s02), dot(_M1.s23, _M2.s13)))
210
213#define MATRIX_MUL_ALL MATRIX_MUL
214
217#define TRANSPOSE s0213
218
221#define DIAG s03
222
225#define MATRIX_FROM_DIAG(_V) \
226 ((float4)(_V.x, 0.f, \
227 0.f, _V.y))
228
233#define MATRIX_TRACE(_M) (_M.s0 + _M.s3)
234
241matrix outer(const vec v1, const vec v2)
242{
243 matrix m;
244 m.s01 = v1.x * v2;
245 m.s23 = v1.y * v2;
246 return m;
247}
248
254float det(const matrix m)
255{
256 return m.s0 * m.s3 - m.s1 * m.s2;
257}
258
267{
268 const float d = 1.f / det(m);
269 if(fabs(d) > 1.e16f) {
270 return MAT_ALL_EYE;
271 }
272 return ((matrix)( m.s3, -m.s1,
273 -m.s2, m.s0)) * d;
274}
275
281#define MATRIX_INV(_M) \
282 MATRIX_MUL(inv(MATRIX_MUL(_M.TRANSPOSE, _M)), _M.TRANSPOSE)
float det(const matrix m)
Determinant of a matrix.
Definition 2D.h:254
#define MAT_ALL_EYE
MAT_EYE.
Definition 2D.h:74
matrix inv(const matrix m)
Inverse of a matrix.
Definition 2D.h:266
matrix outer(const vec v1, const vec v2)
Perform the outer product of two vectors.
Definition 2D.h:241