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 
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 
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{}, space{};
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 fieldName, word& typeName) const
85  {
86 
87  word fieldTYPENAME = pointField_H<T>::TYPENAME();
88  word flType{},fldType{};
89 
90  if(!pointFieldFileGetType( fieldName, flType))
91  {
92  fatalExit;
93  return false;
94  }
95 
96  if( !pointFieldGetType<T>(fldType) )
97  {
98  fatalExit;
99  return false;
100  }
101 
102 
103  if( flType == fldType )
104  {
105  typeName = flType;
106  return true;
107  }else
108  {
109  typeName.clear();
110  return false;
111  }
112  }
113 
114  template<typename T>
116  {
117  if( !checkForPointStructure() )
118  {
120  "cannot find " << pointStructureFile__ << " in repository "<< repository_.name()<<endl;
121  fatalExit;
122  }
124 
125  word fType;
126  pointFieldGetType<T>(fType);
127  word newName = name + fType;
128 
130  objectFile(
131  name,
132  "",
135  ),
136  pStruct,
137  value
138  );
139 
140  return field;
141 
142  }
143 
144  template<typename T>
146  {
147  if( !checkForPointStructure() )
148  {
150  "cannot find " << pointStructureFile__ << " in repository "<< repository_.name()<<endl;
151  fatalExit;
152  }
154 
156  objectFile(
157  name,
158  "",
161  ),
162  pStruct,
163  T{}
164  );
165 
166  return field;
167 
168  }
169 
170  template<typename T>
172  {
173  if( !checkForPointStructure() )
174  {
176  "cannot find " << pointStructureFile__ << " in repository "<< repository_.name()<<endl;
177  fatalExit;
178  }
180 
182  objectFile(
183  name,
184  "",
187  ),
188  pStruct,
189  T{}
190  );
191 
192  return field;
193  }
194 
195 };
196 
197 } //pFlow
198 
199 
200 
201 #endif //__readFromTimeFolder_hpp__
pFlow::pointStructureFile__
const char * pointStructureFile__
Definition: vocabs.hpp:42
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
pFlow::repository::emplaceReplaceObject
T & emplaceReplaceObject(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:89
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::repository::lookupObject
T & lookupObject(const word &name)
Definition: repositoryTemplates.cpp:146
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:117
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pointFields.hpp
pFlow::readFromTimeFolder::db
auto & db()
Definition: readFromTimeFolder.hpp:52
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:46
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::readFromTimeFolder::pointFieldGetType
bool pointFieldGetType(word &typeName) const
Definition: readFromTimeFolder.hpp:65
pFlow
Definition: demComponent.hpp:28
pFlow::objectFile::WRITE_NEVER
@ WRITE_NEVER
Definition: objectFile.hpp:47
repository.hpp
pFlow::readFromTimeFolder::repository_
repository & repository_
Definition: readFromTimeFolder.hpp:35
pFlow::repository::name
word name() const
Definition: repository.cpp:51
pFlow::readFromTimeFolder::createUniformPointField_H
pointField_H< T > & createUniformPointField_H(word name, T value)
Definition: readFromTimeFolder.hpp:115
pFlow::pointField
Definition: pointField.hpp:35
pFlow::pointStructure
Definition: pointStructure.hpp:44
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::readFromTimeFolder::checkForPointStructure
bool checkForPointStructure() const
Definition: readFromTimeFolder.hpp:37
pFlow::readFromTimeFolder::readPointField_D
pointField_D< T > & readPointField_D(word name)
Definition: readFromTimeFolder.hpp:171
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::readFromTimeFolder::pointFieldGetCheckType
bool pointFieldGetCheckType(word fieldName, word &typeName) const
Definition: readFromTimeFolder.hpp:84
pFlow::repository::path
virtual fileSystem path() const
Definition: repository.cpp:61
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:40
pFlow::utilities::pointFieldGetType
bool pointFieldGetType(std::string TYPENAME, std::string &fieldType, std::string &fieldSpace)
Definition: utilityFunctions.hpp:30
pFlow::repository::emplaceObjectOrGet
T & emplaceObjectOrGet(const objectFile &objf, Args &&... args)
Definition: repositoryTemplates.cpp:62
pFlow::repository
Definition: repository.hpp:34
pFlow::readFromTimeFolder::readPointField_H
pointField_H< T > & readPointField_H(word name)
Definition: readFromTimeFolder.hpp:145
pFlow::objectFile::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: objectFile.hpp:41