www.cemf.ir
internalField.cpp
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 template<class T, class MemorySpace>
23 {
24  const word eventName = message::eventName(message::ITEM_INSERT);
25 
26  const auto& indices = varList.getObject<uint32IndexContainer>(
27  eventName);
28  bool success = false;
29 
30  if(varList.contains(name()))
31  {
32  // a single value is assigned
33  T val = varList.getObject<T>(name());
34  success = field_.insertSetElement(indices, val);
35 
36  }
37  else if(varList.contains(name()+"Vector"))
38  {
39  // a vector of values is going to be assigned
40  const auto& valVec = varList.getObject<Vector<T>>(name()+"Vector");
41  success = field_.insertSetElement(indices,valVec);
42  }
43  else
44  {
45  success = field_.insertSetElement(indices, defaultValue_);
46  }
47 
48  if(!success)
49  {
51  return false;
52  }
53 
54  return true;
55 }
56 
57 template<class T, class MemorySpace>
59 {
60  const word eventName = message::eventName(message::ITEM_REARRANGE);
61 
62  const auto& indices = varList.getObject<uint32IndexContainer>(
63  eventName);
64 
65  field_.reserve( internalPoints_.capacity());
66  field_.resize(internalPoints_.size());
67  if(!field_.reorderItems(indices))
68  {
70  "cannot reorder items in field "<< name()<<endl;
71  return false;
72  }
73 
74  return true;
75 }
76 
77 
78 template<class T, class MemorySpace>
80 (
81  const word& name,
82  const internalPoints& internal,
83  const T& defVal
84 )
85 :
86  observer
87  (
88  &internal,
89  defaultMessage_
90  ),
91  field_
92  (
93  name,
94  "ineternalField",
95  internal.capacity(),
96  internal.size(),
97  RESERVE()
98  ),
99  defaultValue_(defVal),
100  internalPoints_(internal)
101 {}
102 
103 template<class T, class MemorySpace>
105 (
106  const word &name,
107  const internalPoints &internal,
108  const T& defVal,
109  const T &val
110 )
111 :
112  observer
113  (
114  &internal,
115  defaultMessage_
116  ),
117  field_
118  (
119  name,
120  "ineternalField",
121  internal.capacity(),
122  internal.size(),
123  RESERVE()
124  ),
125  defaultValue_(defVal),
126  internalPoints_(internal)
127 {
128  fillInternal(val);
129 }
130 
131 
132 template <class T, class MemorySpace>
135 {
136  auto maskH = internalPoints_.activePointsMaskHost();
137  auto fieldH = field_.hostView();
138 
139  FieldTypeHost aField
140  (
141  field_.name(),
142  field_.fieldKey(),
143  maskH.numActive(),
144  maskH.numActive(),
145  RESERVE()
146  );
147 
148  auto aRange = maskH.activeRange();
149 
150  uint32 n = 0;
151  for(auto i=aRange.start(); i<aRange.end(); i++)
152  {
153  if( maskH.isActive(i) )
154  {
155  aField[n] = fieldH[i];
156  n++;
157  }
158  }
159  return aField;
160 }
161 
162 template <class T, class MemorySpace>
164 (
165  real t,
166  real dt,
167  uint32 iter,
168  const message& msg,
169  const anyList& varList
170 )
171 {
172  if(msg.equivalentTo(message::CAP_CHANGED))
173  {
174  auto newCap = varList.getObject<uint32>(
175  message::eventName(message::CAP_CHANGED));
176 
177  field_.reserve(newCap);
178  }
179  if(msg.equivalentTo(message::SIZE_CHANGED))
180  {
181  auto newSize = varList.getObject<uint32>(
182  message::eventName(message::SIZE_CHANGED));
183  field_.resize(newSize);
184  }
185  if(msg.equivalentTo(message::ITEM_DELETE))
186  {
187  // do nothing
188  }
189  if(msg.equivalentTo(message::ITEM_INSERT))
190  {
191  return insert(varList);
192  }
193  if(msg.equivalentTo(message::ITEM_REARRANGE))
194  {
195  return rearrange(varList);
196 
197  }
198  return true;
199 }
200 
201 template<class T, class MemorySpace>
203 (
204  iOstream& os,
205  const IOPattern& iop
206 )const
207 {
208  auto aField = activeValuesHost();
209  return aField.write(os, iop);
210 }
pFlow::message::equivalentTo
bool equivalentTo(EVENT evnt) const
Definition: message.hpp:131
pFlow::observer
Definition: observer.hpp:33
pFlow::internalField::internalField
internalField(const word &name, const internalPoints &internal, const T &defVal)
Definition: internalField.cpp:80
pFlow::internalPoints
Definition: internalPoints.hpp:38
pFlow::message
Definition: message.hpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::anyList::getObject
T & getObject(size_t i)
Get the reference to variable by index.
Definition: anyList.hpp:134
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::anyList::contains
bool contains(const word &name) const
Does container contain this variable name?
Definition: anyList.cpp:35
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::Field
Definition: Field.hpp:36
pFlow::internalField::hearChanges
bool hearChanges(real t, real dt, uint32 iter, const message &msg, const anyList &varList) override
Definition: internalField.cpp:164
RESERVE
Definition: Vector.hpp:40
pFlow::anyList
Definition: anyList.hpp:35
pFlow::internalField::rearrange
bool rearrange(const anyList &varList)
Definition: internalField.cpp:58
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::VectorSingle::hostView
INLINE_FUNCTION_H auto hostView() const
Return a view accessible on Host in range [0,size)
Definition: VectorSingle.cpp:281
pFlow::IOPattern
Definition: IOPattern.hpp:32
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::internalField::insert
bool insert(const anyList &varList)
Definition: internalField.cpp:22
pFlow::internalField::write
bool write(iOstream &os, const IOPattern &iop) const
Definition: internalField.cpp:203
pFlow::internalField::activeValuesHost
FieldTypeHost activeValuesHost() const
Definition: internalField.cpp:134
pFlow::Vector
Definition: Vector.hpp:48
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::indexContainer
It holds two vectors of indecis on Host and Device.
Definition: indexContainer.hpp:39