OpenLB 1.7
Loading...
Searching...
No Matches
arithmetic.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 UTILITY_ARITHMETIC_H
25#define UTILITY_ARITHMETIC_H
26
27#include "utilities/omath.h"
28#include <functional>
29
30namespace olb {
31
32namespace util {
33
35
43template <typename T>
44struct minus {
46 static const char symbol = '-';
47
48 constexpr T operator() (const T& lhs, const T& rhs) const
49 {
50 return std::minus<T>()(lhs, rhs);
51 }
52};
53
55
59template <>
60constexpr bool minus<bool>::operator() (const bool& lhs, const bool& rhs) const
61{
62 return lhs && !rhs;
63}
64
66template <typename T>
67struct plus : public std::plus<T> {
69 static const char symbol = '+';
70};
71
73template <typename T>
74struct multiplies : public std::multiplies<T> {
76 static const char symbol = '*';
77};
78
80template <typename T>
81struct divides : public std::divides<T> {
83 static const char symbol = '/';
84};
85
87template <typename T>
88struct power {
90 static const char symbol = '^';
91
92 constexpr T operator() (const T& base, const T& exponent) const
93 {
94 return util::pow(base, exponent);
95 }
96};
97
99// imitates stl definition of std::plus
100template<class T = void> struct maxOp {
102 static const char symbol = 'M';
103
104 constexpr T operator()(const T& x, const T& y) const {
105 return util::max(x, y);
106 }
107};
108
109template<> struct maxOp<void> {
111 static const char symbol = 'M';
112
113 template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
114 -> decltype(util::max(std::forward<T>(t), std::forward<U>(u))) {
115 return util::max(std::forward<T>(t), std::forward<U>(u));
116 }
117
118 using is_transparent = void;
119};
120
122// imitates stl definition of std::plus
123template<class T = void> struct minOp {
125 static const char symbol = 'm';
126
127 constexpr T operator()(const T& x, const T& y) const {
128 return util::min(x, y);
129 }
130};
131
132template<> struct minOp<void> {
134 static const char symbol = 'm';
135
136 template<class T, class U> constexpr auto operator()(T&& t, U&& u) const
137 -> decltype(util::min(std::forward<T>(t), std::forward<U>(u))) {
138 return util::min(std::forward<T>(t), std::forward<U>(u));
139 }
140
141 using is_transparent = void;
142};
143
144} // end namespace util
145
146} // end namespace olb
147
148#endif
cpu::simd::Pack< T > min(cpu::simd::Pack< T > rhs, cpu::simd::Pack< T > lhs)
Definition pack.h:124
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
Top level namespace for all of OpenLB.
Wrapper of function object std::divides.
Definition arithmetic.h:81
static const char symbol
symbol character for functor naming
Definition arithmetic.h:83
constexpr auto operator()(T &&t, U &&u) const -> decltype(util::max(std::forward< T >(t), std::forward< U >(u)))
Definition arithmetic.h:113
Wrapper function object for util::max.
Definition arithmetic.h:100
static const char symbol
symbol character for functor naming
Definition arithmetic.h:102
constexpr T operator()(const T &x, const T &y) const
Definition arithmetic.h:104
constexpr auto operator()(T &&t, U &&u) const -> decltype(util::min(std::forward< T >(t), std::forward< U >(u)))
Definition arithmetic.h:136
Wrapper function object for util::min.
Definition arithmetic.h:123
constexpr T operator()(const T &x, const T &y) const
Definition arithmetic.h:127
static const char symbol
symbol character for functor naming
Definition arithmetic.h:125
Wrapper of function object std::minus with special handling for bool.
Definition arithmetic.h:44
constexpr T operator()(const T &lhs, const T &rhs) const
Definition arithmetic.h:48
static const char symbol
symbol character for functor naming
Definition arithmetic.h:46
Wrapper of function object std::multiplies.
Definition arithmetic.h:74
static const char symbol
symbol character for functor naming
Definition arithmetic.h:76
Wrapper of function object std::plus.
Definition arithmetic.h:67
static const char symbol
symbol character for functor naming
Definition arithmetic.h:69
Power function object.
Definition arithmetic.h:88
static const char symbol
symbol character for functor naming
Definition arithmetic.h:90
constexpr T operator()(const T &base, const T &exponent) const
Definition arithmetic.h:92