ug4
Loading...
Searching...
No Matches
math_vector_functions.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3 * Author: Sebastian Reiter
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 ��7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., N��gel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef __H__COMMON__MATH_VECTOR_FUNCTIONS__
34#define __H__COMMON__MATH_VECTOR_FUNCTIONS__
35
36#include "math_vector.h"
37
38namespace ug
39{
40
43
46
49template <typename vector_target_t, typename vector_source_t>
50void VecCopy(vector_target_t& target, const vector_source_t& source,
51 typename vector_target_t::value_type fill);
52
54// Append Vector
55
57// vOut += v1
58template <typename vector_t>
59inline
60void
61VecAppend(vector_t& vOut, const vector_t& v1);
62
64// vOut = v1 + v2
65template <typename vector_t>
66inline
67void
68VecAppend(vector_t& vOut, const vector_t& v1, const vector_t& v2);
69
71// vOut += v1 + v2 + v3
72template <typename vector_t>
73inline
74void
75VecAppend(vector_t& vOut, const vector_t& v1, const vector_t& v2,
76 const vector_t& v3);
77
79// vOut += v1 + v2 + v3 + v4
80template <typename vector_t>
81inline
82void
83VecAppend(vector_t& vOut, const vector_t& v1, const vector_t& v2,
84 const vector_t& v3, const vector_t& v4);
85
87// Scale and Append Vectors
88
90// vOut += s1*v1
91template <typename vector_t>
92inline
93void
94VecScaleAppend(vector_t& vOut, typename vector_t::value_type s1, const vector_t& v1);
95
97// vOut += s1*v1 + s2*v2
98template <typename vector_t>
99inline
100void
101VecScaleAppend(vector_t& vOut, typename vector_t::value_type s1, const vector_t& v1,
102 typename vector_t::value_type s2, const vector_t& v2);
103
105// vOut += s1*v1 + s2*v2 + s3*v3
106template <typename vector_t>
107inline
108void
109VecScaleAppend(vector_t& vOut, typename vector_t::value_type s1, const vector_t& v1,
110 typename vector_t::value_type s2, const vector_t& v2,
111 typename vector_t::value_type s3, const vector_t& v3);
112
114// vOut += s1*v1 + s2*v2 + s3*v3 + s4*v4
115template <typename vector_t>
116inline
117void
118VecScaleAppend(vector_t& vOut, typename vector_t::value_type s1, const vector_t& v1,
119 typename vector_t::value_type s2, const vector_t& v2,
120 typename vector_t::value_type s3, const vector_t& v3,
121 typename vector_t::value_type s4, const vector_t& v4);
122
123
125// Addition of Vectors
126
128// vOut = v1 + v2
129template <typename vector_t>
130inline
131void
132VecAdd(vector_t& vOut, const vector_t& v1, const vector_t& v2);
133
135// vOut = v1 + v2 + v3
136template <typename vector_t>
137inline
138void
139VecAdd(vector_t& vOut, const vector_t& v1, const vector_t& v2,
140 const vector_t& v3);
141
143// vOut = v1 + v2 + v3 + v4
144template <typename vector_t>
145inline
146void
147VecAdd(vector_t& vOut, const vector_t& v1, const vector_t& v2,
148 const vector_t& v3, const vector_t& v4);
149
151// Subtraction of Vectors
152
154// vOut = v1 - v2
155template <typename vector_t>
156inline
157void
158VecSubtract(vector_t& vOut, const vector_t& v1, const vector_t& v2);
159
161// Component-wise exponentiation of a vector
162template <typename vector_t>
163inline
164void
165VecPow(vector_t& vOut, const vector_t& v1, typename vector_t::value_type s);
166
167
169// Scaling of a Vector
170
172// vOut = s * v
173template <typename vector_t>
174inline
175void
176VecScale(vector_t& vOut, const vector_t& v, typename vector_t::value_type s);
177
179// Scaled Addition of Vectors
180
182// vOut = s1*v1 + s2*v2
183template <typename vector_t>
184inline
185void
186VecScaleAdd(vector_t& vOut, typename vector_t::value_type s1, const vector_t& v1,
187 typename vector_t::value_type s2, const vector_t& v2);
188
190// vOut = s1*v1 + s2*v2 + s3*v3
191template <typename vector_t>
192inline
193void
194VecScaleAdd(vector_t& vOut, typename vector_t::value_type s1, const vector_t& v1,
195 typename vector_t::value_type s2, const vector_t& v2,
196 typename vector_t::value_type s3, const vector_t& v3);
197
199// vOut = s1*v1 + s2*v2 + s3*v3 + s4*v4
200template <typename vector_t>
201inline
202void
203VecScaleAdd(vector_t& vOut, typename vector_t::value_type s1, const vector_t& v1,
204 typename vector_t::value_type s2, const vector_t& v2,
205 typename vector_t::value_type s3, const vector_t& v3,
206 typename vector_t::value_type s4, const vector_t& v4);
207
209// Interpolation of Vectors
210
211// performs linear interpolation between two Vectors.
212template <typename vector_t>
213inline
214void
215VecInterpolateLinear(vector_t& vOut, const vector_t& v1, const vector_t& v2,
216 typename vector_t::value_type interpAmount);
217
219// Length of Vectors
220
222template <typename vector_t>
223inline
224typename vector_t::value_type
225VecLengthSq(const vector_t& v);
226
228template <typename vector_t>
229inline
230typename vector_t::value_type
231VecLength(const vector_t& v);
232
234// Distance of Vectors
235
237template <typename vector_t>
238inline
239typename vector_t::value_type
240VecDistanceSq(const vector_t& v1, const vector_t& v2);
241
243template <typename vector_t>
244inline
245typename vector_t::value_type
246VecDistance(const vector_t& v1, const vector_t& v2);
247
248
250// Dot Product
252template <typename vector_t>
253inline
254typename vector_t::value_type
255VecDot(const vector_t& v1, const vector_t& v2);
256
258// Angle
260template <typename vector_t>
261inline
262typename vector_t::value_type
263VecAngle(const vector_t& v1, const vector_t& v2);
264
266// Angle
268
270template <typename vector_t>
271inline
272typename vector_t::value_type
273VecAngleNorm(const vector_t& v1, const vector_t& v2);
274
276// Cross Product
278template <typename vector_t>
279inline
280void
281VecCross(vector_t& vOut, const vector_t& v1, const vector_t& v2);
282
284// Generalized cross Product
286template <size_t dim>
287inline void GenVecCross
288(
289 MathVector<dim> & result,
290 const MathVector<dim> & v_1, const MathVector<dim> & v_2
291);
292
294// Normalize a Vector
296template <typename vector_t>
297inline
298void
299VecNormalize(vector_t& vOut, const vector_t& v);
300
302// CalculateTriangleNormalNoNormalize
304//TODO: This method should not be part of the core-math methods.
305// Instead it should be moved to a seperate math-util file.
306template <typename vector_t>
307inline
308void
309CalculateTriangleNormalNoNormalize(vector_t& vOut, const vector_t& v1,
310 const vector_t& v2, const vector_t& v3);
311
313// CalculateTriangleNormal
315//TODO: This method should not be part of the core-math methods.
316// Instead it should be moved to a seperate math-util file.
317template <typename vector_t>
318inline
319void
320CalculateTriangleNormal(vector_t& vOut, const vector_t& v1,
321 const vector_t& v2, const vector_t& v3);
322
323
325// Operations with scalar
326
328template <typename vector_t>
329inline
330void
331VecSet(vector_t& vInOut, typename vector_t::value_type s);
332
334template <typename vector_t>
335inline
336void
337VecAdd(vector_t& vOut, const vector_t& v, typename vector_t::value_type s);
338
340template <typename vector_t>
341inline
342void
343VecSubtract(vector_t& vOut, const vector_t& v, typename vector_t::value_type s);
344
346// Norms
347template <typename vector_t>
348inline
349typename vector_t::value_type
350VecTwoNorm(const vector_t& v);
351
352template <typename vector_t>
353inline
354typename vector_t::value_type
355VecTwoNormSq(const vector_t& v);
356
357template <typename vector_t>
358inline
359typename vector_t::value_type
360VecOneNorm(const vector_t& v);
361
362template <typename vector_t>
363inline
364typename vector_t::value_type
365VecPNorm(const vector_t& v, unsigned int p);
366
367template <typename vector_t>
368inline
369typename vector_t::value_type
370VecMaxNorm(const vector_t& v);
371
372template <typename vector_t>
373inline
374typename vector_t::value_type
375VecInftyNorm(const vector_t& v);
376
377// end group vectors
379
380
382// Elementwise operations
383
385template <typename vector_t>
386inline
387void
388VecElemProd(vector_t& vOut, const vector_t& v1, const vector_t& v2);
389
391template <typename vector_t>
392inline
393void
394VecElemSqrt(vector_t& vOut, const vector_t& v1);
395
397template <typename vector_t>
398inline
399bool
400VecAbsIsLess(const vector_t& v1, const vector_t& v2);
401
403template <typename vector_t>
404inline
405bool
406VecAbsIsLess(const vector_t& v1, const typename vector_t::value_type s);
407
409template <typename vector_t>
410inline
411bool
412VecIsInBB(const vector_t& v, const vector_t& low, const vector_t& high);
413
414}// end of namespace
415
417// include a general, but not very fast implementation of the declared methods above.
419
420#endif /* __H__COMMON__MATH_MathVector_FUNCTIONS__ */
function util fill(N, c)
vector_t::value_type VecLength(const vector_t &v)
returns the length of v. Slower than VecLengthSq.
Definition math_vector_functions_common_impl.hpp:341
void VecScaleAppend(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1)
Scales a Vector and adds it to a second vector.
Definition math_vector_functions_common_impl.hpp:126
void VecCopy(vector_target_t &target, const vector_source_t &source, typename vector_target_t::value_type fill)
Copy contents between vectors of possibly different types.
Definition math_vector_functions_common_impl.hpp:56
vector_t::value_type VecMaxNorm(const vector_t &v)
Definition math_vector_functions_common_impl.hpp:625
void GenVecCross(MathVector< dim > &result, const MathVector< dim > &v_1, const MathVector< dim > &v_2)
calculates the usual cross product in 3d, and the (det, 0) vector as a cross product in 2d
Definition math_vector_functions_common_impl.hpp:465
void VecSet(vector_t &vInOut, typename vector_t::value_type s)
Set each vector component to scalar (componentwise)
Definition math_vector_functions_common_impl.hpp:539
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition math_vector_functions_common_impl.hpp:265
vector_t::value_type VecTwoNormSq(const vector_t &v)
Definition math_vector_functions_common_impl.hpp:585
vector_t::value_type VecOneNorm(const vector_t &v)
Definition math_vector_functions_common_impl.hpp:593
void VecNormalize(vector_t &vOut, const vector_t &v)
scales a vector_t to unit length
Definition math_vector_functions_common_impl.hpp:501
void CalculateTriangleNormalNoNormalize(vector_t &vOut, const vector_t &v1, const vector_t &v2, const vector_t &v3)
Calculates a triangle-normal in 3d (no normalization is performed).
Definition math_vector_functions_common_impl.hpp:514
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition math_vector_functions_common_impl.hpp:226
vector_t::value_type VecAngle(const vector_t &v1, const vector_t &v2)
returns the angle between two vectors in radiants
Definition math_vector_functions_common_impl.hpp:401
vector_t::value_type VecDistanceSq(const vector_t &v1, const vector_t &v2)
returns the squared distance of two vector_ts.
Definition math_vector_functions_common_impl.hpp:351
void CalculateTriangleNormal(vector_t &vOut, const vector_t &v1, const vector_t &v2, const vector_t &v3)
Calculates a triangle-normal in 3d (output has length 1).
Definition math_vector_functions_common_impl.hpp:528
void VecAppend(vector_t &vOut, const vector_t &v1)
adds a MathVector<N> to a second one
Definition math_vector_functions_common_impl.hpp:72
vector_t::value_type VecLengthSq(const vector_t &v)
returns the squared length of v. Faster than VecLength.
Definition math_vector_functions_common_impl.hpp:324
vector_t::value_type VecDistance(const vector_t &v1, const vector_t &v2)
returns the distance of two vector_ts.
Definition math_vector_functions_common_impl.hpp:375
void VecAdd(vector_t &vOut, const vector_t &v1, const vector_t &v2)
adds two MathVector<N>s and stores the result in a third one
Definition math_vector_functions_common_impl.hpp:185
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
scales a MathVector<N>
Definition math_vector_functions_common_impl.hpp:252
vector_t::value_type VecTwoNorm(const vector_t &v)
Definition math_vector_functions_common_impl.hpp:577
void VecCross(vector_t &vOut, const vector_t &v1, const vector_t &v2)
calculates the cross product of two Vectors of dimension 3. It makes no sense to use VecCross for vec...
Definition math_vector_functions_common_impl.hpp:437
void VecPow(vector_t &vOut, const vector_t &v1, typename vector_t::value_type s)
component-wise exponentiation of a vector
Definition math_vector_functions_common_impl.hpp:239
vector_t::value_type VecAngleNorm(const vector_t &v1, const vector_t &v2)
returns the angle between two vectors of length 1 in radiants
Definition math_vector_functions_common_impl.hpp:421
void VecInterpolateLinear(vector_t &vOut, const vector_t &v1, const vector_t &v2, typename vector_t::value_type interpAmount)
Definition math_vector_functions_common_impl.hpp:310
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
returns the dot-product of two vector_ts
Definition math_vector_functions_common_impl.hpp:385
vector_t::value_type VecInftyNorm(const vector_t &v)
Definition math_vector_functions_common_impl.hpp:641
vector_t::value_type VecPNorm(const vector_t &v, unsigned int p)
Definition math_vector_functions_common_impl.hpp:609
the ug namespace
bool VecIsInBB(const vector_t &v, const vector_t &low, const vector_t &high)
checks if the given point is in the bounding box given by two other points
Definition math_vector_functions_common_impl.hpp:701
void VecElemProd(vector_t &vOut, const vector_t &v1, const vector_t &v2)
component-wise product: vOut_i = v1_i*v2_i
Definition math_vector_functions_common_impl.hpp:651
bool VecAbsIsLess(const vector_t &v1, const vector_t &v2)
component-wise comparison of two vectors (in the absolute values)
Definition math_vector_functions_common_impl.hpp:677
void VecElemSqrt(vector_t &vOut, const vector_t &v1)
component-wise square root:
Definition math_vector_functions_common_impl.hpp:664