www.cemf.ir
readFromTimeFolder.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 #ifndef __readFromTimeFolder_hpp__
21 #define __readFromTimeFolder_hpp__
22 
23 #include "vocabs.hpp"
24 #include "repository.hpp"
25 #include "pointFields.hpp"
26 #include "utilityFunctions.hpp"
27 
28 namespace pFlow
29 {
30 
32 {
33 protected:
34 
36 
38  {
40  }
41 
42 public:
43 
44 
45  explicit readFromTimeFolder(repository& rep);
46 
47  auto path()const
48  {
49  return repository_.path();
50  }
51 
52  auto& db()
53  {
54  return repository_;
55  }
56 
57  std::pair<bool, IOfileHeader>
58  fieldExists(word fieldName)const;
59 
60 
61 
62  bool pointFieldFileGetType(word fieldName, word& typeName) const;
63 
64  template<typename T>
65  bool pointFieldGetType(word& typeName)const
66  {
67  word fieldTYPENAME = pointField_H<T>::TYPENAME();
68  word fldType{};
69 
71  fieldTYPENAME, fldType, space) )
72  {
74  "error in extracting type from "<<fieldTYPENAME<<endl;
75  return false;
76  }
77 
78  typeName = fldType;
79  return true;
80 
81  }
82 
83  template<typename T>
84  bool pointFieldGetCheckType(word const& fieldName, word& typeName) const
85  {
86 
87  word fieldTYPENAME = pointField_H<T>::TYPENAME();
88 
89  word flType{};
90  if(!pointFieldFileGetType( fieldName, flType))
91  {
92  fatalExit;
93  return false;
94  }
95 
96  word fldType{};
97  if( !pointFieldGetType<T>(fldType) )
98  {
99  fatalExit;
100  return false;
101  }
102 
103 
104  if( flType == fldType )
105  {
106  typeName = flType;
107  return true;
108  }else
109  {
110  typeName.clear();
111  return false;
112  }
113  }
114 
115  template<typename T>
116  uniquePtr<pointField_H<T>> createUniformPointField_H(word const& name, T value, bool regRep = true)
117  {
118  if( !checkForPointStructure() )
119  {
121  "cannot find " << pointStructureFile__ << " in repository "<< repository_.name()<<endl;
122  fatalExit;
123  }
124 
126 
127  if(regRep)
128  {
129  auto Ptr = makeUnique<pointField_H<T>>
130  (
131  objectFile
132  (
133  name,
134  "",
137  ),
138  pStruct,
139  T{},
140  value
141  );
142  return Ptr;
143  }
144  else
145  {
146  auto Ptr = makeUnique<pointField_H<T>>
147  (
148  objectFile
149  (
150  name,
151  "",
154  ),
155  nullptr,
156  pStruct,
157  value
158  );
159  Ptr().fill(value);
160  return Ptr;
161  }
162 
163  return nullptr;
164  }
165 
166  template<typename T>
168  {
169  if( !checkForPointStructure() )
170  {
172  "cannot find " << pointStructureFile__ << " in repository "<< repository_.name()<<endl;
173  fatalExit;
174  }
176 
177  auto Ptr = makeUnique<pointField_H<T>>
178  (
179  objectFile
180  (
181  name,
182  "",
185  ),
186  pStruct,
187  T{}
188  );
189 
190  return Ptr;
191 
192  }
193 
194  template<typename T>
196  {
197  if( !checkForPointStructure() )
198  {
200  "cannot find " << pointStructureFile__ << " in repository "<< repository_.name()<<endl;
201  fatalExit;
202  }
204 
205  auto Ptr = makeUnique<pointField_D<T>>
206  (
207  objectFile
208  (
209  name,
210  "",
213  ),
214  pStruct,
215  T{}
216  );
217 
218  return Ptr;
219  }
220 
221 };
222 
223 } //pFlow
224 
225 
226 
227 #endif //__readFromTimeFolder_hpp__
pFlow::readFromTimeFolder::fieldExists
std::pair< bool, IOfileHeader > fieldExists(word fieldName) const
Definition: readFromTimeFolder.cpp:30
pFlow::readFromTimeFolder::path
auto path() const
Definition: readFromTimeFolder.hpp:47
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::readFromTimeFolder::readPointField_H
uniquePtr< pointField_H< T > > readPointField_H(word const &name)
Definition: readFromTimeFolder.hpp:167
pFlow::repository::lookupObject
T & lookupObject(const word &name)
return a ref to the underlaying data in the object
Definition: repositoryTemplates.cpp:40
pFlow::readFromTimeFolder
Definition: readFromTimeFolder.hpp:31
pFlow::readFromTimeFolder::pointFieldFileGetType
bool pointFieldFileGetType(word fieldName, word &typeName) const
Definition: readFromTimeFolder.cpp:43
pFlow::repository::lookupObjectName
bool lookupObjectName(const word &nm) const
Definition: repository.cpp:157
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pointFields.hpp
pFlow::readFromTimeFolder::db
auto & db()
Definition: readFromTimeFolder.hpp:52
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:43
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::readFromTimeFolder::pointFieldGetType
bool pointFieldGetType(word &typeName) const
Definition: readFromTimeFolder.hpp:65
pFlow
Definition: demGeometry.hpp:27
pFlow::objectFile::WRITE_NEVER
@ WRITE_NEVER
Definition: objectFile.hpp:44
pFlow::readFromTimeFolder::pointFieldGetCheckType
bool pointFieldGetCheckType(word const &fieldName, word &typeName) const
Definition: readFromTimeFolder.hpp:84
repository.hpp
pFlow::readFromTimeFolder::repository_
repository & repository_
Definition: readFromTimeFolder.hpp:35
pFlow::repository::name
word name() const
Definition: repository.cpp:60
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::pointStructureFile__
const char *const pointStructureFile__
Definition: vocabs.hpp:42
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::readFromTimeFolder::checkForPointStructure
bool checkForPointStructure() const
Definition: readFromTimeFolder.hpp:37
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::repository::path
virtual fileSystem path() const
Definition: repository.cpp:70
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::readFromTimeFolder::readFromTimeFolder
readFromTimeFolder(repository &rep)
Definition: readFromTimeFolder.cpp:23
utilityFunctions.hpp
pFlow::objectFile::READ_NEVER
@ READ_NEVER
Definition: objectFile.hpp:37
pFlow::utilities::pointFieldGetType
bool pointFieldGetType(std::string TYPENAME, std::string &fieldType, std::string &fieldSpace)
Definition: utilityFunctions.hpp:30
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
pFlow::repository
Definition: repository.hpp:34
pFlow::objectFile::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: objectFile.hpp:38
vocabs.hpp
pFlow::readFromTimeFolder::readPointField_D
uniquePtr< pointField_D< T > > readPointField_D(word const &name)
Definition: readFromTimeFolder.hpp:195
pFlow::readFromTimeFolder::createUniformPointField_H
uniquePtr< pointField_H< T > > createUniformPointField_H(word const &name, T value, bool regRep=true)
Definition: readFromTimeFolder.hpp:116