VectorDualAlgorithms.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 
22 #ifndef __VectorDualMath_hpp__
23 #define __VectorDualMath_hpp__
24 
25 
26 
27 #include "baseAlgorithms.hpp"
28 
29 
30 namespace pFlow
31 {
32 
33 
34 
35 // - select the side (HostSide or DeviceSide)
36 template<typename side, typename T, typename MemorySpace>
38 int64 count(const VectorDual<T,MemorySpace>& vec, const T& val)
39 {
40  if constexpr (std::is_same<side,HostSide>::value)
41  {
42  return count( vec.hostVectorAll(), static_cast<size_t>(0), vec.size(), val);
43  }
44  else
45  {
46  return count( vec.deviceVectorAll(), static_cast<size_t>(0), vec.size(), val);
47  }
48 
49  return -1;
50 }
51 
52 // default to device side
53 template<typename T, typename MemorySpace>
55 int64 count(const VectorDual<T,MemorySpace>& vec, const T& val)
56 {
57  return count<DeviceSide>( vec, val);
58 }
59 
60 template<typename side, typename T, typename MemorySpace>
63 {
64  if constexpr (std::is_same<side,HostSide>::value)
65  {
66  return min( vec.hostVectorAll(), static_cast<size_t>(0), vec.size());
67  }
68  else
69  {
70  return min( vec.deviceVectorAll(), static_cast<size_t>(0), vec.size());
71  }
72 
73  return 0.0;
74 }
75 
76 // default to device side
77 template<typename T, typename MemorySpace>
80 {
81  return min<DeviceSide>( vec);
82 }
83 
84 template<typename side, typename T, typename MemorySpace>
87 {
88  if constexpr (std::is_same<side,HostSide>::value)
89  {
90  return max( vec.hostVectorAll(), static_cast<size_t>(0), vec.size());
91  }
92  else
93  {
94  return max( vec.deviceVectorAll(), static_cast<size_t>(0), vec.size());
95  }
96 
97  return 0.0;
98 }
99 
100 // default to device side
101 template<typename T, typename MemorySpace>
104 {
105  return max<DeviceSide>( vec);
106 }
107 
108 
109 
110 } // pFlow
111 
112 
113 #endif // __VectorSingleMath_hpp__
pFlow::VectorDual::hostVectorAll
INLINE_FUNCTION_H hostViewType & hostVectorAll()
Definition: VectorDual.hpp:345
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow
Definition: demComponent.hpp:28
pFlow::VectorDual::deviceVectorAll
INLINE_FUNCTION_H deviceViewType & deviceVectorAll()
Definition: VectorDual.hpp:335
pFlow::VectorDual
Definition: VectorDual.hpp:43
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::count
auto count(const Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:26
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
baseAlgorithms.hpp
pFlow::VectorDual::size
INLINE_FUNCTION_H size_t size() const
Definition: VectorDual.hpp:391
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138