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>
34 rectMeshField_H<T> sumOp( const pointField_H<T> field, const pointRectCell& pointToCell)
35 {
36  // create field
37  const auto& mesh = pointToCell.mesh();
38  auto iterator = pointToCell.getCellIterator();
39 
40  rectMeshField_H<T> results(mesh, T(0));
41 
42  for(int32 i=0; i<mesh.nx(); i++)
43  {
44  for(int32 j=0; j<mesh.ny(); j++)
45  {
46  for(int32 k=0; k<mesh.nz(); k++)
47  {
48  auto n = iterator.start(i,j,k);
49  T res (0);
50  while(n>-1)
51  {
52  res += field[n];
53  n = iterator.getNext(n);
54  }
55 
56  results(i,j,k) = res;
57  }
58  }
59  }
60 
61  return results;
62 }
63 
64 template<typename T, typename incMask>
65 rectMeshField_H<T> sumMaksOp( const pointField_H<T> field, const pointRectCell& pointToCell, const incMask& mask)
66 {
67  // create field
68  const auto& mesh = pointToCell.mesh();
69  auto iterator = pointToCell.getCellIterator();
70 
71  rectMeshField_H<T> results(mesh, T(0));
72 
73  for(int32 i=0; i<mesh.nx(); i++)
74  {
75  for(int32 j=0; j<mesh.ny(); j++)
76  {
77  for(int32 k=0; k<mesh.nz(); k++)
78  {
79  //auto [loop, n] = pointToCell.startLoop(i,j,k);
80  auto n = iterator.start(i,j,k);
81  T res (0);
82 
83  while(n>-1)
84  {
85 
86  if(mask(n))
87  {
88  res += field[n];
89  }
90 
91  n = iterator.getNext(n);
92  }
93 
94  results(i,j,k) = res;
95  }
96  }
97  }
98 
99  return results;
100 }
101 
102 
103 
104 
105 }
106 
107 
108 #endif //__fieldOperations_hpp__
109 
includeMask.hpp
pFlow::rectMeshField
Definition: rectMeshField.hpp:31
pointFields.hpp
pFlow::pointRectCell::getCellIterator
auto getCellIterator() const
Definition: pointRectCell.hpp:134
pointRectCell.hpp
pFlow
Definition: demComponent.hpp:28
pFlow::pointField
Definition: pointField.hpp:35
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::sumOp
rectMeshField_H< T > sumOp(const pointField_H< T > field, const pointRectCell &pointToCell)
Definition: fieldOperations.hpp:34
pFlow::pointRectCell
Definition: pointRectCell.hpp:32
rectMeshFields.hpp
pFlow::pointRectCell::mesh
const auto & mesh() const
Definition: pointRectCell.hpp:91
pFlow::sumMaksOp
rectMeshField_H< T > sumMaksOp(const pointField_H< T > field, const pointRectCell &pointToCell, const incMask &mask)
Definition: fieldOperations.hpp:65