OpenLB 1.7
Loading...
Searching...
No Matches
latticeIntegralCommon.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2017 Adrian Kummerlaender
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
24#ifndef LATTICE_INTEGRAL_COMMON_H
25#define LATTICE_INTEGRAL_COMMON_H
26
27namespace olb {
28
29
31
34template <typename T, typename W, int P>
35struct LpNormImpl {
36 inline W operator()(W output, W tmp, T weight);
37 inline W enclose(W output);
38};
39
40template <typename T, typename W, int P>
41inline W LpNormImpl<T,W,P>::operator()(W output, W tmp, T weight)
42{
43 return output + util::pow(util::fabs(tmp), P)*weight;
44}
45
46template <typename T, typename W, int P>
48{
49 return util::pow(output, 1. / P);
50}
51
53template <typename T, typename W>
54struct LpNormImpl<T,W,0> {
55 inline W operator()(W output, W tmp, T weight)
56 {
57 return util::max(output, util::fabs(tmp));
58 }
59 inline W enclose(W output)
60 {
61 return output;
62 }
63};
64
66template <typename T, typename W>
67struct LpNormImpl<T,W,1> {
68 inline W operator()(W output, W tmp, T weight)
69 {
70 return output + util::fabs(tmp)*weight;
71 }
72 inline W enclose(W output)
73 {
74 return output;
75 }
76};
77
79template <typename T, typename W>
80struct LpNormImpl<T,W,2> {
81 inline W operator()(W output, W tmp, T weight)
82 {
83 return output + tmp*tmp*weight;
84 }
85 inline W enclose(W output)
86 {
87 return util::sqrt(output);
88 }
89};
90
91
92} // end namespace olb
93
94#endif
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
Definition pack.h:100
cpu::simd::Pack< T > max(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:130
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
Definition pack.h:112
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
Definition pack.h:106
Top level namespace for all of OpenLB.
W operator()(W output, W tmp, T weight)
W operator()(W output, W tmp, T weight)
W operator()(W output, W tmp, T weight)
Lp norm functor implementation details specific to the P parameter.
W operator()(W output, W tmp, T weight)