setFieldEntryTemplates.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 
22 template <typename Type>
24 {
25  word typeName( entry_.firstPart() );
26  return basicTypeName<Type>() == typeName;
27 };
28 
29 template <typename Type>
31 {
32  if( !checkForType<Type>() ) return false;
33 
34  Type defValue = entry_.secondPartVal<Type>();
35  CONSUME_PARAM(defValue);
36  return true;
37 }
38 
39 template <typename Type>
41 (
42  repository& owner,
44  bool verbose
45 )
46 {
47 
48  if( !checkForType<Type>() ) return nullptr;
49 
50  Type defValue = entry_.secondPartVal<Type>();
51 
52  if(verbose)
53  REPORT(2)<<"Creating pointField " << greenText(fieldName())<< " with default value " << cyanText(defValue)<<
54  " in repository "<< owner.name() <<endREPORT;
55 
56 
57  auto& field =
59  (
61  (
62  fieldName(),
63  "",
66  ),
67  pStruct,
68  defValue
69  );
70 
71  return &field;
72 }
73 
74 template <typename Type>
76 (
77  repository& owner,
79  bool verbose
80 )
81 {
82 
83  if( !checkForType<Type>() ) return nullptr;
84 
85  Type defValue = entry_.secondPartVal<Type>();
86 
87  if(verbose)
88  REPORT(2)<<"Creating pointField " << greenText(fieldName())<< " with default value " << cyanText(defValue)<<
89  " in repository "<< owner.name() <<endREPORT;
90 
91  // by default we perform operations on host
92  auto& field =
94  (
96  (
97  fieldName(),
98  "",
101  ),
102  pStruct,
103  defValue
104  );
105 
106  return &field;
107 }
108 
109 template <typename Type>
111 (
112  repository& owner,
113  int32IndexContainer& selected,
114  bool verbose
115 )
116 {
117  if( !checkForType<Type>() ) return nullptr;
118 
119 
120  auto fName = fieldName();
121 
122  if( !owner.lookupObjectName(fName) )
123  {
125  "Cannot find "<< fName << " in repository " << owner.name() << ". \n";
126  return nullptr;
127  }
128 
129  Type value = entry_.secondPartVal<Type>();
130 
131  if(verbose)
132  REPORT(2)<< "Setting selected points of " << greenText(fName)
133  << " to value " << cyanText(value) <<endREPORT;
134 
135 
136  auto fieldTypeName = owner.lookupObjectTypeName(fName);
137 
138  if( pointField<VectorSingle,Type>::TYPENAME() == fieldTypeName )
139  {
140 
141  auto& field = owner.lookupObject<pointField<VectorSingle,Type>>(fName);
142  if(field.insertSetElement(selected, value))
143  return &field;
144  else
145  return nullptr;
146  }
147 
149  {
150 
151  auto& field = owner.lookupObject<pointField<VectorSingle,Type,HostSpace>>(fName);
152  if(field.insertSetElement(selected, value))
153  return &field;
154  else
155  return nullptr;
156  }
157 
158  if( pointField<VectorDual,Type>::TYPENAME() == fieldTypeName )
159  {
160 
161  auto& field = owner.lookupObject<pointField<VectorDual,Type>>(fName);
162  if(field.insertSetElement(selected, value))
163  return &field;
164  else
165  return nullptr;
166  }
167 
169  fieldTypeName<< " is not a supported field type for setFieldEntry.\n";
170  return nullptr;
171 
172 }
173 
174 template <typename Type>
176 (
177  repository& owner,
178  int32IndexContainer& selected,
179  bool verbose
180 )
181 {
182 
183  if( !checkForType<Type>() ) return nullptr;
184 
185 
186  auto fName = fieldName();
187 
188  if( !owner.lookupObjectName(fName) )
189  {
191  " Cannot find "<< fName << " in repository " << owner.name() << ". \n";
192  return nullptr;
193  }
194 
195 
196  Type value = entry_.secondPartVal<Type>();
197 
198  if(verbose)
199  REPORT(2)<< "Setting selected points of " << greenText(fName)
200  << " to value " << cyanText(value) <<endREPORT;
201 
202 
203  auto fieldTypeName = owner.lookupObjectTypeName(fName);
204 
205  if( pointField<Vector, Type, vecAllocator<Type>>::TYPENAME() == fieldTypeName )
206  {
207  auto& field = owner.lookupObject<pointField<Vector,Type, vecAllocator<Type>>>(fName);
208  if(field.insertSetElement(selected, value))
209  return &field;
210  else
211  return nullptr;
212  }
213 
214  return nullptr;
215 }
endREPORT
#define endREPORT
Definition: streams.hpp:41
REPORT
#define REPORT(n)
Definition: streams.hpp:40
cyanText
#define cyanText(text)
Definition: streams.hpp:34
pFlow::repository::lookupObject
T & lookupObject(const word &name)
Definition: repositoryTemplates.cpp:146
pFlow::repository::lookupObjectName
bool lookupObjectName(const word &nm) const
Definition: repository.cpp:117
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:46
pFlow::repository::lookupObjectTypeName
word lookupObjectTypeName(const word &nm) const
Definition: repository.cpp:122
pFlow::repository::emplaceObject
T & emplaceObject(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:38
pFlow::setFieldEntry::setPointFieldSelectedStd
void * setPointFieldSelectedStd(repository &owner, int32IndexContainer &selected, bool verbose=false)
Definition: setFieldEntryTemplates.cpp:176
greenText
#define greenText(text)
Definition: streams.hpp:32
pFlow::vecAllocator
std::allocator< T > vecAllocator
Definition: Vector.hpp:62
pFlow::repository::name
word name() const
Definition: repository.cpp:51
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::setFieldEntry::setPointFieldDefaultValueNew
void * setPointFieldDefaultValueNew(repository &owner, pointStructure &pStruct, bool verbose=false)
Definition: setFieldEntryTemplates.cpp:41
pFlow::setFieldEntry::checkForType
bool checkForType() const
Definition: setFieldEntryTemplates.cpp:23
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::setFieldEntry::setPointFieldSelected
void * setPointFieldSelected(repository &owner, int32IndexContainer &selected, bool verbose=false)
Definition: setFieldEntryTemplates.cpp:111
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::setFieldEntry::checkForTypeAndValue
bool checkForTypeAndValue() const
Definition: setFieldEntryTemplates.cpp:30
pFlow::objectFile::READ_NEVER
@ READ_NEVER
Definition: objectFile.hpp:40
pFlow::setFieldEntry::entry_
twoPartEntry entry_
Definition: setFieldEntry.hpp:37
CONSUME_PARAM
#define CONSUME_PARAM(x)
Definition: pFlowMacros.hpp:38
pFlow::repository
Definition: repository.hpp:34
pFlow::twoPartEntry::firstPart
const word & firstPart() const
Definition: twoPartEntry.hpp:51
pFlow::Vector
Definition: Vector.hpp:46
pFlow::setFieldEntry::setPointFieldDefaultValueStdNew
void * setPointFieldDefaultValueStdNew(repository &owner, pointStructure &pStruct, bool verbose=false)
Definition: setFieldEntryTemplates.cpp:76
pFlow::indexContainer< int32 >