www.cemf.ir
pointFieldToVTK.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 
21 #ifndef __pointFieldToVTK_hpp__
22 #define __pointFieldToVTK_hpp__
23 
24 #include "systemControl.hpp"
25 #include "pointStructure.hpp"
26 #include "pointFields.hpp"
27 #include "vtkByteSwapper.hpp"
28 
29 extern bool bindaryOutput__;
30 
31 namespace pFlow::PFtoVTK
32 {
33 
35  systemControl &control,
36  const fileSystem &destPath,
37  const word &bName,
38  word& filename);
39 
41  systemControl &control,
42  const fileSystem &destPath,
43  const word &bName,
44  const wordVector &fieldsName,
45  bool mustExist,
46  word& filename);
47 
49  Ostream &os,
50  realx3 *position,
51  uint32 numPoints);
52 
54  Ostream &os,
55  const IOfileHeader &header,
56  pointStructure &pStruct);
57 
59  Ostream &os,
60  const IOfileHeader &header,
61  pointStructure &pStruct);
62 
63  template <typename IntType>
64  bool addIntPointField(
65  Ostream &os,
66  const word &fieldName,
67  IntType *field,
68  uint32 numData);
69 
70  bool addRealPointField(
71  Ostream &os,
72  const word &fieldName,
73  const real *field,
74  uint32 numData);
75 
77  Ostream &os,
78  const word &fieldName,
79  const realx3 *field,
80  uint32 numData);
81 
82  template <typename Type>
83  bool checkFieldType(word objectType);
84 
85  bool regexCheck(const word &TYPENAME, const word &fieldType);
86 
87  template <typename Type>
88  inline bool checkFieldType(word objectType)
89  {
90  return regexCheck(pointField<Type>::TYPENAME(), objectType);
91  }
92 
93  template <typename IntType>
94  inline bool convertIntPointField(
95  Ostream &os,
96  const IOfileHeader &header,
98  {
99 
100  using PointFieldType = pointField<IntType, HostSpace>;
101 
102  word objectType = header.objectType();
103 
104  if (!checkFieldType<IntType>(objectType))
105  {
106  return false;
107  }
108 
109  REPORT(1);
110  auto field = PointFieldType(
111  header,
112  pStruct,
113  static_cast<IntType>(0));
114 
115  const IntType *data = field.deviceViewAll().data();
116 
117  REPORT(2) << ">>> Writing " << Green_Text(header.objectName()) << " field to vtk.\n";
118 
119  return addIntPointField(
120  os,
121  header.objectName(),
122  data,
123  pStruct.numActive());
124  }
125 
126  template <typename IntType>
127  inline bool addIntPointField(
128  Ostream &os,
129  const word &fieldName,
130  IntType *field,
131  uint32 numData)
132  {
133 
134  if (numData == 0)
135  return true;
136 
137  if(std::is_same_v<IntType, int> || std::is_same_v<IntType, const int> )
138  {
139  os << "FIELD FieldData 1\n"
140  << fieldName << " 1 " << numData << " int\n";
141  }
142  else if( std::is_same_v<IntType, unsigned int>|| std::is_same_v<IntType, const unsigned int>)
143  {
144  os << "FIELD FieldData 1\n"
145  << fieldName << " 1 " << numData << " unsigned_int\n";
146  }
147  else
148  {
149  WARNING<<"Field "<< fieldName<< " has invalid data type for conversion. Type is "
150  <<getTypeName<IntType>()<<END_WARNING;
151  return false;
152  }
153 
154  if(bindaryOutput__)
155  {
156  for (uint32 i = 0; i < numData; ++i)
157  {
158  IntType val = byteSwaper(field[i]);
159  os.stdStream().write(reinterpret_cast<const char*>(&val), sizeof(IntType));
160  }
161  os<<'\n';
162  }
163  else
164  {
165  for (uint32 i = 0; i < numData; ++i)
166  {
167  os << field[i] << '\n';
168  }
169  }
170 
171  return true;
172  }
173 
174 }
175 
176 #endif
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::PFtoVTK::regexCheck
bool regexCheck(const word &TYPENAME, const word &fieldType)
Definition: pointFieldToVTK.cpp:396
pFlow::IOfileHeader::objectType
const word & objectType() const
Definition: IOfileHeader.hpp:75
bindaryOutput__
bool bindaryOutput__
Definition: pFlowToVTK.cpp:33
pFlow::real
float real
Definition: builtinTypes.hpp:45
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::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pointFields.hpp
pFlow::realx3
triple< real > realx3
Definition: types.hpp:43
pFlow::PFtoVTK::convertIntPointField
bool convertIntPointField(Ostream &os, const IOfileHeader &header, pointStructure &pStruct)
Definition: pointFieldToVTK.hpp:94
pFlow::pointField
Definition: pointField.hpp:33
pFlow::pointStructure
Definition: pointStructure.hpp:34
END_WARNING
#define END_WARNING
Definition: streams.hpp:44
pFlow::PFtoVTK::checkFieldType
bool checkFieldType(word objectType)
Definition: pointFieldToVTK.hpp:88
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::Ostream::stdStream
virtual std::ostream & stdStream()
Access to underlying std::ostream.
Definition: Ostream.hpp:177
pFlow::wordVector
Vector< word > wordVector
Definition: Vectors.hpp:52
pFlow::IOfileHeader
Definition: IOfileHeader.hpp:35
pFlow::PFtoVTK::addUndstrcuturedGridField
bool addUndstrcuturedGridField(Ostream &os, realx3 *position, uint32 numPoints)
Definition: pointFieldToVTK.cpp:200
pFlow::IOfileHeader::objectName
const word & objectName() const
Definition: IOfileHeader.hpp:69
pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected
bool convertTimeFolderPointFieldsSelected(systemControl &control, const fileSystem &destPath, const word &bName, const wordVector &fieldsName, bool mustExist, word &filename)
Definition: pointFieldToVTK.cpp:95
vtkByteSwapper.hpp
pFlow::PFtoVTK::convertRealTypePointField
bool convertRealTypePointField(Ostream &os, const IOfileHeader &header, pointStructure &pStruct)
Definition: pointFieldToVTK.cpp:270
pFlow::PFtoVTK::convertRealx3TypePointField
bool convertRealx3TypePointField(Ostream &os, const IOfileHeader &header, pointStructure &pStruct)
Definition: pointFieldToVTK.cpp:298
pFlow::PFtoVTK::addIntPointField
bool addIntPointField(Ostream &os, const word &fieldName, IntType *field, uint32 numData)
Definition: pointFieldToVTK.hpp:127
pFlow::Ostream
Standard output stream for BINARY and ASCII formats.
Definition: Ostream.hpp:39
pointStructure.hpp
pFlow::byteSwaper
T byteSwaper(const T &p)
Definition: vtkByteSwapper.hpp:81
pFlow::PFtoVTK::addRealPointField
bool addRealPointField(Ostream &os, const word &fieldName, const real *field, uint32 numData)
Definition: pointFieldToVTK.cpp:326
pFlow::PFtoVTK
Definition: fileSeries.hpp:11
pFlow::PFtoVTK::addRealx3PointField
bool addRealx3PointField(Ostream &os, const word &fieldName, const realx3 *field, uint32 numData)
Definition: pointFieldToVTK.cpp:357
WARNING
#define WARNING
Definition: streams.hpp:43