ug4
Loading...
Searching...
No Matches
vec_functions.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 * Author: Martin Rupp
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 VEC_VEC_FUNCTIONS_H_
34#define VEC_VEC_FUNCTIONS_H_
35#include "common/error.h"
36
38// T, T functions
39template<typename T>
40inline void VecAdd(double a1, T &v1, double a2, const T &v2)
41{
42 ASSERT_EQUAL(v1.size(), v2.size());
43 for(size_t i=0; i<v1.size(); i++)
44 v1[i] = a1*v1[i] + a2*v2[i];
45}
46
47template<typename T>
48inline void VecAdd(double a1, T &v1, double a2, const T &v2, double a3, const T &v3)
49{
50 ASSERT_EQUAL_3(v1.size(), v2.size(), v3.size());
51 for(size_t i=0; i<v1.size(); i++)
52 v1[i] = a1*v1[i] + a2*v2[i] + a3*v3[i];
53}
54
55template<typename T>
56inline void VecAdd(double a1, T &v1, double a2, const T &v2, double a3, const T &v3, double a4, const T &v4)
57{
58 ASSERT_EQUAL_4(v1.size(), v2.size(), v3.size(), v4.size());
59 for(size_t i=0; i<v1.size(); i++)
60 v1[i] = a1*v1[i] + a2*v2[i] + a3*v3[i] + a4*v4[i];
61}
62
63template<typename T>
64inline double VecProd(T &v1, T &v2)
65{
66 ASSERT_EQUAL(v1.size(), v2.size());
67 double s=0;
68 for(size_t i=0; i<v1.size(); i++)
69 s += v1[i]*v2[i];
70 return s;
71}
72
73template<typename T>
74inline double VecNorm2(T &v)
75{
76 double s=0;
77 for(size_t i=0; i<v.size(); i++)
78 s += v[i]*v[i];
79 return s;
80}
81
82
83#endif /* VEC_VEC_FUNCTIONS_H_ */
parameterString s
#define ASSERT_EQUAL(s1, s2)
Definition error.h:185
#define ASSERT_EQUAL_4(s1, s2, s3, s4)
Definition error.h:187
#define ASSERT_EQUAL_3(s1, s2, s3)
Definition error.h:186
double VecNorm2(T &v)
Definition vec_functions.h:74
double VecProd(T &v1, T &v2)
Definition vec_functions.h:64
void VecAdd(double a1, T &v1, double a2, const T &v2)
Definition vec_functions.h:40