www.cemf.ir
pFlowToVTK.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 "vocabs.hpp"
22 #include "systemControl.hpp"
23 #include "timeFolder.hpp"
24 #include "commandLine.hpp"
25 #include "ranges.hpp"
26 #include "Vectors.hpp"
27 #include "phasicFlowKokkos.hpp"
28 #include "pointFieldToVTK.hpp"
29 #include "triSurfaceFieldToVTK.hpp"
30 #include "fileSeries.hpp"
31 //#include "readControlDict.hpp"
32 
34 
35 int main(int argc, char** argv )
36 {
37  pFlow::word outFolder = (pFlow::CWD()/pFlow::word("VTK")).wordPath();
38 
39  pFlow::commandLine cmds(
40  "pFlowToVTK",
41  "Convrtes the saved pointField and geometry"
42  " date in time folders into vtk file format.");
43 
44  pFlow::wordVector times;
45 
46  bool noGoem = false;
47  cmds.add_flag(
48  "--no-geometry",
49  noGoem,
50  "Do not convert geometry to VTK file");
51 
52  bool noParticle = false;
53  cmds.add_flag("--no-particles",
54  noParticle,
55  "Do not convert particle fields to VTK file");
56 
57  bindaryOutput__ = false;
58  cmds.add_flag("-b, --binary",
60  "Wrtie vtk file (for particles only) in binary format. Default is ASCII");
61 
62  cmds.addOption("-o,--out-folder",
63  outFolder,
64  "path to output folder of VTK",
65  "path");
66 
67  bool separateSurfaces = false;
68  cmds.add_flag(
69  "-s,--separate-surfaces",
70  separateSurfaces,
71  "use this when you want to have sub-surfaces in separate files");
72 
73  pFlow::wordVector fields;
74  bool allFields = true;
75  cmds.addOption("-f,--fields",
76  fields.vectorField(),
77  "a space-separated list of fields names to be converted to VTK",
78  "word");
79 
80  cmds.addOption(
81  "-t,--time",
82  times.vectorField(),
83  "a space separated lists of time folders, or a strided range begin:stride:end, or an interval begin:end",
84  " ");
85 
86  //bool isCoupling = false;
87 
88  if(!cmds.parse(argc, argv)) return 0;
89 
90 
91 // this should be palced in each main
92 #include "initialize_Control.hpp"
93 
94 
95  if(!bindaryOutput__)
96  {
97  INFORMATION<<"Writing vtk file in binray format will accelerate the conversion (5~10x)"<<
98  " and visualization in paraview."<<
99  " Consider addig flag -b or --binary in the command line."<<END_INFO;
100  }
101 
102  pFlow::word formatName = bindaryOutput__?"binary":"ascii";
103 
104  pFlow::timeFolder folders(Control);
105  auto destFolderGeometry = pFlow::fileSystem(outFolder)/pFlow::word(pFlow::geometryFolder__);
106  auto destFolderField = pFlow::fileSystem(outFolder)/pFlow::word("particles");
107  pFlow::wordList geomfiles{"triSurface"};
108 
109 
110  if(cmds.count("--fields"))
111  {
112  allFields = false;
113  }
114 
115  pFlow::realCombinedRange validRange;
116  if( cmds.count("--time") )
117  {
118  if(!validRange.addRanges(times))
119  {
120  fatalExit;
121  }
122  }
123  else
124  {
125  validRange.addIntervalRange(folders.startTime(), folders.endTime());
126  }
127 
128  {
129 
130  pFlow::PFtoVTK::fileSeries timeSeries{pFlow::fileSystem(outFolder)};
131  pFlow::word fileName;
132  pFlow::wordList geomFileNames;
133  pFlow::wordList surfNames;
134  do
135  {
136  Control.time().setTime(folders.time());
137  if( !validRange.isMember( folders.time() ) )continue;
138 
139  pFlow::output<< "time: " << Cyan_Text( folders.time() )<<" s" <<pFlow::endl;
140  if(!noGoem)
141  {
142 
144  Control, destFolderGeometry, "surface", separateSurfaces, surfNames, geomFileNames))
145  {
146  fatalExit;
147  return 1;
148  }
149 
150  timeSeries.addTimeFile(surfNames, folders.time(), geomFileNames);
151  }
152 
153  if(!noParticle)
154  {
155  REPORT(1)<< "Converting pointFields to vtk file in "<< formatName<< " format ..."<<END_REPORT;
156  if(allFields)
157  {
159  Control,
160  destFolderField,
161  "particles",
162  fileName
163  )
164  )
165  {
166  fatalExit;
167  }
168  }else
169  {
171  Control,
172  destFolderField,
173  "particles",
174  fields,
175  !pFlow::equal(folders.time(),static_cast<pFlow::real>(0.0)),
176  fileName
177  )
178  )
179  {
180  fatalExit;
181  }
182  }
183 
184  timeSeries.addTimeFile("particles", folders.time(), fileName);
185 
186  }
187 
189 
190  }
191  while( folders++ );
192 
193  }
194 
195 
196  pFlow::output<< "\nFinished successfully.\n";
197 
198 
199 // this should be palced in each main
200 #include "finalize.hpp"
201  return 0;
202 }
initialize_Control.hpp
pFlow::timeFolder::time
real time() const
Definition: timeFolder.hpp:57
pFlow::List< word >
pFlow::Vector::vectorField
const vectorType & vectorField() const
Definition: Vector.hpp:227
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
Cyan_Text
#define Cyan_Text(text)
Definition: iOstream.hpp:44
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::PFtoVTK::convertTimeFolderPointFields
bool convertTimeFolderPointFields(systemControl &control, const fileSystem &destPath, const word &bName, word &filename)
Definition: pointFieldToVTK.cpp:8
systemControl.hpp
pFlow::commandLine::addOption
Option * addOption(word optionName, word description, word opText="")
pFlow::equal
INLINE_FUNCTION_HD bool equal(const box &b1, const box &b2, real tol=smallValue)
Definition: box.hpp:135
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::PFtoVTK::fileSeries
Definition: fileSeries.hpp:14
pFlow::commandLine
Definition: commandLine.hpp:36
Vectors.hpp
pointFieldToVTK.hpp
fileSeries.hpp
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
main
int main(int argc, char **argv)
Definition: pFlowToVTK.cpp:35
pFlow::timeFolder::startTime
real startTime() const
Definition: timeFolder.hpp:105
pFlow::combinedRange
Definition: combinedRange.hpp:36
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
triSurfaceFieldToVTK.hpp
phasicFlowKokkos.hpp
pFlow::combinedRange::addIntervalRange
bool addIntervalRange(const word &strRange)
Definition: combinedRange.hpp:97
pFlow::geometryFolder__
const char *const geometryFolder__
Definition: vocabs.hpp:32
pFlow::commandLine::parse
bool parse(int argc, char **argv)
Definition: commandLine.cpp:50
pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields
bool convertTimeFolderTriSurfaceFields(systemControl &control, const fileSystem &destPath, const word &bName, bool separate, wordList &surfNames, wordList &fileNames)
Definition: triSurfaceFieldToVTK.cpp:5
pFlow::output
Ostream output
pFlow::combinedRange::addRanges
bool addRanges(const std::vector< word > &strRanges)
Definition: combinedRange.hpp:64
bindaryOutput__
bool bindaryOutput__
Definition: pFlowToVTK.cpp:33
ranges.hpp
pFlow::combinedRange::isMember
bool isMember(T val) const
Definition: combinedRange.hpp:131
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::CWD
fileSystem CWD()
Free function to reture current working directory.
Definition: fileSystem.hpp:221
pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected
bool convertTimeFolderPointFieldsSelected(systemControl &control, const fileSystem &destPath, const word &bName, const wordVector &fieldsName, bool mustExist, word &filename)
Definition: pointFieldToVTK.cpp:95
pFlow::timeFolder::endTime
real endTime() const
Definition: timeFolder.hpp:111
vocabs.hpp
pFlow::Vector< word >
END_INFO
#define END_INFO
Definition: streams.hpp:37
commandLine.hpp
Control
auto & Control
Definition: initialize_Control.hpp:47
INFORMATION
#define INFORMATION
Definition: streams.hpp:36
timeFolder.hpp
pFlow::timeFolder
Definition: timeFolder.hpp:32
finalize.hpp