OpenLB 1.7
Loading...
Searching...
No Matches
norm.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2012 Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program 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
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
28#ifndef NORM_H
29#define NORM_H
30
31namespace olb{
32
33namespace util{
34
36template<typename T>
37T euklidN2(const T x[], int dim)
38{
39 T euklid = 0;
40 for (int iDim=0; iDim<dim; iDim++) {
41 euklid += x[iDim]*x[iDim];
42 }
43 return euklid;
44}
45
47template<typename T>
48T euklidDistance2(const T x[], const T y[], int dim)
49{
50 T euklid = 0;
51 for (int iDim=0; iDim<dim; iDim++) {
52 euklid += (x[iDim]-y[iDim])*(x[iDim]-y[iDim]);
53 }
54 return euklid;
55}
56
57
59template<typename T>
60T euklidN(const T x[], int dim)
61{
62 return olb::util::sqrt(euklidN2(x,dim));
63}
64
66template<typename T>
67T euklidDistance(const T x[], const T y[], int dim)
68{
69 return olb::util::sqrt(euklidDistance2(x,y,dim));
70}
71
72
74template<typename C>
75auto euklidN2(const C& x)
76{
77 return euklidN2(x.data(), x.size());
78}
79
81template<typename C>
82auto euklidDistance2(const C& x, const C& y)
83{
84 OLB_ASSERT((x.size() == y.size()), "Arrays must have same dimension");
85 return euklidDistance2(x.data(), y.data(), x.size());
86}
87
89template<typename C>
90auto euklidN(const C& x)
91{
92 return euklidN(x.data(), x.size());
93}
94
96template<typename C>
97auto euklidDistance(const C& x, const C& y)
98{
99 OLB_ASSERT((x.size() == y.size()), "Arrays must have same dimension");
100 return euklidDistance(x.data(), y.data(), x.size());
101}
102
103}
104
105}
106
107#endif
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
T euklidN(const T x[], int dim)
Euclidean norm of an array.
Definition norm.h:60
T euklidDistance(const T x[], const T y[], int dim)
Euclidean distance between two arrays.
Definition norm.h:67
T euklidN2(const T x[], int dim)
Squared Euclidean norm of an array.
Definition norm.h:37
T euklidDistance2(const T x[], const T y[], int dim)
Squared Euclidean distance between two arrays.
Definition norm.h:48
Top level namespace for all of OpenLB.
#define OLB_ASSERT(COND, MESSAGE)
Definition olbDebug.h:45