ProcessField.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 __ProcessField_hpp__
22 #define __ProcessField_hpp__
23 
24 
25 #include "processField.hpp"
26 #include "rectMeshFields.hpp"
27 #include "twoPartEntry.hpp"
28 #include "fieldOperations.hpp"
29 #include "rectMeshFieldToVTK.hpp"
30 
31 namespace pFlow
32 {
33 
34 
35 template<typename T>
37 :
38  public processField
39 {
40 
41 protected:
42 
44 
45 
47 
48 public:
49 
50  TypeInfoTemplate("ProcessField", T);
51 
52 
54  const dictionary& dict,
55  pointRectCell& pToCell,
56  repository& rep)
57  :
58  processField(dict, pToCell, rep),
59  field_(
60  this->isUniform()?
61  timeFolder().createUniformPointField_H(this->fieldName(), getUniformValue() ):
62  timeFolder().readPointField_H<T>(this->fieldName())
63  ),
65  (
66  processedRepository().emplaceObject<rectMeshField_H<T>>
67  (
69  (
71  "",
72  objectFile::READ_NEVER,
73  objectFile::WRITE_ALWAYS
74  ),
75  mesh(),
77  T{}
78  )
79  )
80  {
81 
82  }
83 
84  add_vCtor(
87  dictionary);
88 
89 
90  T getUniformValue()const
91  {
92  const dataEntry& entry = dict().dataEntryRef("field");
93  twoPartEntry tpEntry(entry);
94  return tpEntry.secondPartVal<T>();
95  }
96 
97  virtual bool process() override
98  {
99 
100  const includeMask& incMask = includeMask_();
101 
102  auto numerator = sumMaksOp( field_ , this->pointToCell(), incMask);
103 
104  rectMeshField_H<real> denomerator( this->mesh(), real{} );
105 
106  if(operation() == "sum")
107  {
108  denomerator = rectMeshField_H<real>(this->mesh(), static_cast<real>(1.0));
109 
110  }else if(operation() == "average")
111  {
112 
113  pointField_H<real> oneFld(field_.pStruct(), static_cast<real>(1.0), static_cast<real>(1.0));
114 
115  denomerator = sumOp(oneFld, this->pointToCell());
116 
117  }else if(operation() == "averageMask")
118  {
119  pointField_H<real> oneFld(field_.pStruct(), static_cast<real>(1.0), static_cast<real>(1.0));
120 
121  denomerator = sumMaksOp(oneFld, this->pointToCell(), incMask);
122  }else
123  {
124  fatalErrorInFunction<<"operation is not known: "<< operation()<<endl;
125  fatalExit;
126  }
127 
128 
129  for(int32 i=0; i<this->mesh().nx(); i++ )
130  {
131  for(int32 j=0; j<this->mesh().ny(); j++ )
132  {
133  for(int32 k=0; k<this->mesh().nz(); k++ )
134  {
135  if( pointToCell().nPointInCell(i,j,k)>= threshold() )
136  {
137  processedField_(i,j,k) = numerator(i,j,k)/denomerator(i,j,k);
138  }
139  else
140  {
141  processedField_(i,j,k) = T{};
142  }
143  }
144  }
145  }
146 
147 
148  return true;
149  }
150 
151 
152  bool writeToVTK(iOstream& os)const override
153  {
155  }
156 
157 };
158 
159 
160 } // pFlow
161 
162 
163 
164 #endif //__ProcessField_hpp__
twoPartEntry.hpp
pFlow::ProcessField::field_
pointField_H< T > & field_
Definition: ProcessField.hpp:43
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::rectMeshField
Definition: rectMeshField.hpp:31
pFlow::twoPartEntry
Definition: twoPartEntry.hpp:36
pFlow::processField::isUniform
bool isUniform() const
Definition: processField.hpp:123
pFlow::processField::processedFieldName
const word & processedFieldName() const
Definition: processField.hpp:148
fieldOperations.hpp
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::includeMask
Definition: includeMask.hpp:33
pFlow::processField::operation
const word & operation() const
Definition: processField.hpp:128
pFlow::processField::includeMask_
uniquePtr< includeMask > includeMask_
Definition: processField.hpp:59
pFlow
Definition: demComponent.hpp:28
pFlow::ProcessField::add_vCtor
add_vCtor(processField, ProcessField, dictionary)
pFlow::convertRectMeshField
bool convertRectMeshField(iOstream &os, rectMeshField_H< T > &field)
Definition: rectMeshFieldToVTK.hpp:29
pFlow::pointField
Definition: pointField.hpp:35
pFlow::ProcessField::writeToVTK
bool writeToVTK(iOstream &os) const override
Definition: ProcessField.hpp:152
pFlow::dataEntry
Definition: dataEntry.hpp:40
processField.hpp
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
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
pFlow::processField::processField
processField(const dictionary &dict, pointRectCell &pToCell, repository &rep)
Definition: processField.cpp:27
rectMeshFields.hpp
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::processField
Definition: processField.hpp:37
pFlow::ProcessField::ProcessField
ProcessField(const dictionary &dict, pointRectCell &pToCell, repository &rep)
Definition: ProcessField.hpp:53
pFlow::ProcessField::process
virtual bool process() override
Definition: ProcessField.hpp:97
pFlow::ProcessField::TypeInfoTemplate
TypeInfoTemplate("ProcessField", T)
pFlow::processField::processedRepository
auto & processedRepository()
Definition: processField.hpp:108
pFlow::ProcessField::processedField_
rectMeshField_H< T > & processedField_
Definition: ProcessField.hpp:46
pFlow::ProcessField::getUniformValue
T getUniformValue() const
Definition: ProcessField.hpp:90
pFlow::sumMaksOp
rectMeshField_H< T > sumMaksOp(const pointField_H< T > field, const pointRectCell &pointToCell, const incMask &mask)
Definition: fieldOperations.hpp:65
pFlow::processField::threshold
auto threshold() const
Definition: processField.hpp:143
pFlow::processField::fieldName
const word & fieldName() const
Definition: processField.hpp:118
pFlow::repository
Definition: repository.hpp:34
pFlow::processField::mesh
const auto & mesh() const
Definition: processField.hpp:83
rectMeshFieldToVTK.hpp
pFlow::processField::dict
auto & dict()
Definition: processField.hpp:93
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::ProcessField
Definition: ProcessField.hpp:36
pFlow::twoPartEntry::secondPartVal
T secondPartVal() const
Definition: twoPartEntry.hpp:62
pFlow::processField::pointToCell
const auto & pointToCell() const
Definition: processField.hpp:88
pFlow::timeFolder
Definition: timeFolder.hpp:32