www.cemf.ir
fieldOperations.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 #ifndef __fieldOperations_hpp__
22 #define __fieldOperations_hpp__
23 
24 #include "rectMeshFields.hpp"
25 #include "pointFields.hpp"
26 #include "pointRectCell.hpp"
27 #include "includeMask.hpp"
28 
29 namespace pFlow
30 {
31 
32 
33 template<typename T>
35 {
36  // create field
37  auto& mesh = pointToCell.mesh();
38  auto iterator = pointToCell.getCellIterator();
39  auto f = field.deviceView();
40 
41  auto resultsPtr = makeUnique<rectMeshField_H<T>>(mesh, T(0));
42  auto& results = resultsPtr();
43  for(int32 i=0; i<mesh.nx(); i++)
44  {
45  for(int32 j=0; j<mesh.ny(); j++)
46  {
47  for(int32 k=0; k<mesh.nz(); k++)
48  {
49  uint32 n = iterator.start(i,j,k);
50  T res (0);
51  while(n != cellMapper::NoPos)
52  {
53  res += f[n];
54  n = iterator.getNext(n);
55  }
56 
57  results(i,j,k) = res;
58  }
59  }
60  }
61 
62  return resultsPtr;
63 }
64 
65 template<typename T, typename incMask>
66 uniquePtr<rectMeshField_H<T>> sumMaksOp( pointField_H<T>& field, pointRectCell& pointToCell, const incMask& mask)
67 {
68  // create field
69  auto& mesh = pointToCell.mesh();
70  auto iterator = pointToCell.getCellIterator();
71  auto f = field.deviceView();
72 
73  auto resultsPtr = makeUnique<rectMeshField_H<T>>(mesh, T(0));
74  auto& results = resultsPtr();
75 
76  for(int32 i=0; i<mesh.nx(); i++)
77  {
78  for(int32 j=0; j<mesh.ny(); j++)
79  {
80  for(int32 k=0; k<mesh.nz(); k++)
81  {
82  //auto [loop, n] = pointToCell.startLoop(i,j,k);
83  uint32 n = iterator.start(i,j,k);
84  T res (0);
85 
86  while(n!= cellMapper::NoPos)
87  {
88 
89  if(mask(n))
90  {
91  res += f[n];
92  }
93 
94  n = iterator.getNext(n);
95  }
96 
97  results(i,j,k) = res;
98  }
99  }
100  }
101 
102  return resultsPtr;
103 }
104 
105 
106 
107 
108 }
109 
110 
111 #endif //__fieldOperations_hpp__
112 
pFlow::pointRectCell::mesh
auto & mesh()
Definition: pointRectCell.hpp:81
includeMask.hpp
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::sumMaksOp
uniquePtr< rectMeshField_H< T > > sumMaksOp(pointField_H< T > &field, pointRectCell &pointToCell, const incMask &mask)
Definition: fieldOperations.hpp:66
pointFields.hpp
pFlow::pointRectCell::getCellIterator
auto getCellIterator() const
Definition: pointRectCell.hpp:127
pointRectCell.hpp
pFlow
Definition: demGeometry.hpp:27
pFlow::pointField
Definition: pointField.hpp:33
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::pointRectCell
Definition: pointRectCell.hpp:32
rectMeshFields.hpp
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::cellMapper::NoPos
static constexpr uint32 NoPos
Definition: cellMapper.hpp:42
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
pFlow::sumOp
uniquePtr< rectMeshField_H< T > > sumOp(pointField_H< T > &field, pointRectCell &pointToCell)
Definition: fieldOperations.hpp:34
pFlow::internalField< T, void >::deviceView
auto deviceView() const
Definition: internalField.hpp:97