www.cemf.ir
baseShapeNames.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 #include "baseShapeNames.hpp"
22 
24 {
25  hashNames_.clear();
26  hashes_.clear();
27 
28  std::hash<word> hasher;
29 
30  uint32 i=0;
31  for(const auto& nm:shapeNames_)
32  {
33  if(!hashNames_.insertIf(nm, i))
34  {
36  " repeated name in the list of shape names: " << shapeNames_;
37  return false;
38  }
39  hashes_.push_back(hasher(nm));
40  i++;
41  }
42  hashNames_.rehash(0);
43 
44  return true;
45 }
46 
47 
49 {
50 
51  shapeNames_ = getVal<wordVector>("names");
52  numShapes_ = shapeNames_.size();
53 
54  return true;
55 }
56 
57 
59 (
60  const word &fileName,
61  repository *owner
62 )
63 :
65  (
67  (
68  fileName,
69  "",
72  ),
73  owner
74  )
75 {
76 
77  if( !readFromDictionary1() )
78  {
80  fatalExit;
81  }
82 
83  if( !createHashNames())
84  {
86  fatalExit;
87  }
88 
89 }
90 
91 
93 {
94 
95  if( !dict.add("names", shapeNames_) )
96  {
98  " Error in writing names to dictionary "<< dict.globalName()<<endl;
99  return false;
100  }
101 
102  return true;
103 }
104 
106 {
107  dictionary newDict(fileDictionary::dictionary::name(), true);
108 
109  if( !writeToDict(newDict) )
110  {
111  return false;
112  }
113 
114  if( !newDict.write(os) )
115  {
116  fatalErrorInFunction<<"Error in writing dictionary "<< globalName()<<
117  "to stream "<< os.name()<<endl;
118  return false;
119  }
120 
121  return true;
122 }
pFlow::baseShapeNames::hashNames_
wordHashMap< uint32 > hashNames_
Definition: baseShapeNames.hpp:42
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::baseShapeNames::baseShapeNames
baseShapeNames(const word &fileName, repository *owner)
Definition: baseShapeNames.cpp:59
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::baseShapeNames::hashes_
Vector< size_t > hashes_
hash for names
Definition: baseShapeNames.hpp:48
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
baseShapeNames.hpp
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:43
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
add a float dataEntry
Definition: dictionary.cpp:435
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::baseShapeNames::hasher
typename wordHashMap< uint32 >::hasher hasher
Definition: baseShapeNames.hpp:54
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::baseShapeNames::readFromDictionary1
bool readFromDictionary1()
Definition: baseShapeNames.cpp:48
pFlow::objectFile::READ_ALWAYS
@ READ_ALWAYS
Definition: objectFile.hpp:36
pFlow::dictionary::write
bool write(iOstream &os) const override
write to stream
Definition: dictionary.cpp:793
pFlow::baseShapeNames::createHashNames
bool createHashNames()
Definition: baseShapeNames.cpp:23
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::repository
Definition: repository.hpp:34
pFlow::baseShapeNames::shapeNames_
wordVector shapeNames_
list of shape names
Definition: baseShapeNames.hpp:45
pFlow::baseShapeNames::write
bool write(iOstream &os) const override
write to stream
Definition: baseShapeNames.cpp:105
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::baseShapeNames::writeToDict
virtual bool writeToDict(dictionary &dict) const
Definition: baseShapeNames.cpp:92
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67