www.cemf.ir
insertion.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 "insertion.hpp"
22 #include "particles.hpp"
23 #include "streams.hpp"
24 #include "systemControl.hpp"
25 #include "vocabs.hpp"
26 
29  objectFile(
31  "",
32  objectFile::READ_IF_PRESENT,
33  objectFile::WRITE_ALWAYS
34  ),
35  &prtcl.time()
36  ),
37  particles_(prtcl)
38 {
39  // this means that insertion file exist in time folder
40  if( IOobject::implyRead() )
41  {
42  readFromFile_ = true;
43 
44  } // look inside the caseSetup folder if it exist
45  else
46  {
47  // read dictionary from caseSetup folder
48  fileDictionary caseFile(
49  objectFile(
51  "",
54  &prtcl.control().caseSetup());
55 
56  // check if read happened
57  if(caseFile.implyRead())
58  {
59  readFromFile_ = true;
60  // assign it to this dictionary
61  fileDictionary::dictionary::operator=(caseFile);
62  }
63  }
64 
65  if( readFromFile_)
66  {
68  }
69 }
70 
73 {
74  return particles_.pStruct();
75 }
76 
77 bool
79 {
80  active_ = getVal<Logical>("active");
81 
82  if (active_)
83  {
84  checkForCollision_ = getVal<Logical>("checkForCollision");
85 
86  REPORT(1) << "Particle insertion mechanism is " << Yellow_Text("active")
87  << " in the simulation." << END_REPORT;
88  }
89  else
90  {
91  REPORT(1) << "Particle insertion mechanism is "
92  << Yellow_Text("not active") << " in the simulation."
93  << END_REPORT;
94  }
95  return true;
96 }
97 
98 bool
100 {
101  if (!dict.add("active", active_))
102  {
103  fatalErrorInFunction <<"Error in writing active to dictionary "
104  <<dict.globalName()<<endl;
105  return false;
106  }
107 
108  if (!dict.add("checkForCollision", checkForCollision_))
109  {
111  "Error in writing checkForCollision to dictionary "<<
112  dict.globalName()<<endl;
113  return false;
114  }
115 
116  return true;
117 }
118 
119 
120 bool pFlow::insertion::write(iOstream & os, const IOPattern & iop) const
121 {
122  dictionary newDict(fileDictionary::dictionary::name(), true);
123  if( iop.thisProcWriteData() )
124  {
125  if( !writeInsertionDict(newDict) ||
126  !newDict.write(os))
127  {
129  " error in writing to dictionary "<< newDict.globalName()<<endl;
130  return false;
131  }
132  }
133 
134  return true;
135 }
136 
137 
138 /*bool
139 pFlow::insertion::read(iIstream& is, const IOPattern& iop)
140 {
141  if (fileDictionary::read(is, iop))
142  {
143  readFromFile_ = true;
144  return true;
145  }
146  else
147  {
148  return false;
149  }
150 }*/
pFlow::insertion::pStruct
const pointStructure & pStruct() const
Definition: insertion.cpp:72
pFlow::objectFile::objectFile
objectFile(const word &name)
Definition: objectFile.cpp:24
pFlow::demComponent::control
const auto & control() const
Const ref to systemControl.
Definition: demComponent.hpp:88
REPORT
#define REPORT(n)
Definition: streams.hpp:39
systemControl.hpp
insertion.hpp
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
particles.hpp
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::insertionFile__
const char *const insertionFile__
Definition: vocabs.hpp:40
Yellow_Text
#define Yellow_Text(text)
Definition: iOstream.hpp:40
pFlow::objectFile::WRITE_NEVER
@ WRITE_NEVER
Definition: objectFile.hpp:44
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::particles
Definition: particles.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::insertion::readFromFile_
bool readFromFile_
Definition: insertion.hpp:58
pFlow::insertion::insertion
insertion(particles &prtcl)
Construct from component.
Definition: insertion.cpp:27
pFlow::insertion::writeInsertionDict
virtual bool writeInsertionDict(dictionary &dict) const
Write to dictionary.
Definition: insertion.cpp:99
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::dictionary::write
bool write(iOstream &os) const override
write to stream
Definition: dictionary.cpp:793
pFlow::IOPattern::thisProcWriteData
bool thisProcWriteData() const
Definition: IOPattern.hpp:146
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::objectFile
Definition: objectFile.hpp:30
streams.hpp
pFlow::IOfileHeader::implyRead
bool implyRead() const
Imply read.
Definition: IOfileHeader.cpp:121
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::objectFile::READ_IF_PRESENT
@ READ_IF_PRESENT
Definition: objectFile.hpp:38
vocabs.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
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
pFlow::insertion::write
bool write(iOstream &os, const IOPattern &iop) const override
write to iOstream
Definition: insertion.cpp:120
pFlow::insertion::readInsertionDict
bool readInsertionDict()
Read from dictionary.
Definition: insertion.cpp:78