Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tecplotwriter.cpp
Go to the documentation of this file.
1 #include "tecplotwriter.h"
2 
3 /*
4  * Base class for objects that write data out to
5  * tecplot data files
6  */
7 
8 /*
9  * Default constructor
10  */
12  mFilename = "";
13 }
14 
15 /*
16  * Constructor
17  * @param rFilename Output filename
18  */
19 TecplotWriter::TecplotWriter(string rFilename){
20  setOutputFilename(rFilename);
21 }
22 
23 /*
24  * Destructor
25  */
27 
28  //Close the file handle
29  if(mFileHandle.is_open())
30  mFileHandle.close();
31 
32  return;
33 }
34 
35 /*
36  * Set filename
37  * @param rFilename Output filename
38  */
39 void TecplotWriter::setOutputFilename(string rFilename){
40  mFilename = rFilename;
41 }
42 
43 /*
44  * Get filename
45  * @return Output filename
46  */
48  return mFilename;
49 }
50 
51 /*
52  * Initialize writer
53  */
55  mFileHandle.open(mFilename.c_str(), ofstream::out);
56  return mFileHandle.is_open();
57 }
58 
59 
60 
61 /*
62  * Handles outputing indexed_points data to tecplot
63  * ordered file
64  */
65 
66 /*
67  * Default constructor
68  */
70  return;
71 }
72 
73 /*
74  * Constructor
75  * @param rFilename Output filename
76  */
78  return;
79 }
80 
81 /*
82  * Destructor
83  */
85  return;
86 }
87 
88 /*
89  * Write all information to file
90  * @param rTitle Dataset Title
91  * @param rVariableNames Variable names for header
92  * @return True if write is successful, otherwise false
93  */
94 bool TecplotOrderedWriter::writeFile(string rTitle, std::vector<string> rVariableNames){
95 
96  //Check file handle
97  if(!mFileHandle.is_open())
98  return false;
99 
100  //Check to make sure the number of variables match
101  if(mPartitionPoints.size() != 0){
102  if(rVariableNames.size() != mPartitionPoints[0]->get_num_vars())
103  return false;
104  }
105 
106  mFileHandle << "TITLE = \"" << rTitle << "\"" << endl;
107 
108  //Write variable names to file
109  mFileHandle << "VARIABLES = ";
110 
111  for(int var_num = 0; var_num < rVariableNames.size(); var_num++){
112  mFileHandle << "\"" << rVariableNames[var_num] << "\"" << endl;
113  }
114 
115  //Write partitions to file
116  for(int partition_num = 0; partition_num < mPartitionPoints.size(); partition_num++){
117  writePartition(partition_num);
118  }
119 
120  return false;
121 }
122 
123 /*
124  * Add ordered partition of points to the file write queue
125  * @param rpPoints Datapoints to write to file
126  */
127 bool TecplotOrderedWriter::addOrderedPartition(string rTitle, indexed_points *rpPoints, int rPartitionVariable){
128 
129  if(rpPoints == NULL)
130  return false;
131 
132  if(mPartitionPoints.size() != 0){
133 
134  //Calculate the number of vars in the supplied dataset
135  int curr_num_vars = -1;
136  if(rPartitionVariable == -1)
137  curr_num_vars = rpPoints->get_num_vars();
138  else
139  curr_num_vars = rpPoints->get_num_indep_vars() + 1;
140 
141  //Calculate the number of vars in the previous dataset
142  int prev_var = mPartitionVariable.back();
143  int prev_num_vars = -1;
144  if(prev_var == -1)
145  prev_num_vars = mPartitionPoints.back()->get_num_vars();
146  else
147  prev_num_vars = mPartitionPoints.back()->get_num_indep_vars() + 1;
148 
149  //Check variable consistency
150  if(curr_num_vars != prev_num_vars)
151  return false;
152  }
153 
154  mPartitionPoints.push_back(rpPoints);
155  mPartitionTitles.push_back(rTitle);
156  mPartitionVariable.push_back(rPartitionVariable);
157  return true;
158 }
159 
160 /*
161  * Write partition to file
162  * @param rPartitionPoints Partition datapoints
163  * @return True if write is successful, otherwise false
164  */
165 bool TecplotOrderedWriter::writePartition(int rPartitionNum){
166 
167  //Sanity check
168  if(rPartitionNum >= mPartitionPoints.size() || rPartitionNum > mPartitionTitles.size())
169  return false;
170 
171  indexed_points *curr_points = mPartitionPoints[rPartitionNum];
172 
173  //Zone and title
174  mFileHandle << "ZONE ";
175  mFileHandle << "T = \"" << mPartitionTitles[rPartitionNum] << "\"" << endl;
176 
177  //Don't know what this is...
178  mFileHandle << "STRANDID=0, SOLUTIONTIME=0" << endl;
179 
180  if(curr_points->get_dim().size() < 3)
181  return false;
182 
183  //Write i,j,k values
184  int i = curr_points->get_dim()[0];
185  int j = curr_points->get_dim()[1];
186  int k = curr_points->get_dim()[2];
187 
188  mFileHandle << "I=" << i << ", ";
189  mFileHandle << "J=" << j << ", ";
190  mFileHandle << "K=" << k << ", ";
191 
192  //Write other properties
193  mFileHandle << "ZONETYPE=Ordered" << endl;
194  mFileHandle << "DATAPACKING=BLOCK" << endl;
195 
196  mFileHandle << "DT=(SINGLE SINGLE SINGLE SINGLE )" << endl;
197 
198 
199  return writePoints(rPartitionNum);
200 }
201 
202 /*
203  * Write the points of the specified partition.
204  * @param rPartitionNum is the number of the local storage of the partition's points
205  * @return True on success, otherwise false
206  */
207 bool TecplotOrderedWriter::writePoints(int rPartitionNum){
208 
209  if(mPartitionPoints.size() <= rPartitionNum)
210  return false;
211 
212  indexed_points *curr_points = mPartitionPoints[rPartitionNum];
213 
214  int num_pts = curr_points->get_num_points();
215  int vars = curr_points->get_num_vars();
216 
217  int values_printed = 0;
218 
219  //Loop through and write points
220  for(int var_num = 0; var_num < vars; var_num++){
221 
222  if(mPartitionVariable[rPartitionNum] != -1 && var_num >= curr_points->get_num_indep_vars()){
223  if(var_num != mPartitionVariable[rPartitionNum])
224  continue;
225  }
226 
227  for(int z = 0; z < curr_points->get_dim()[2]; z++){
228  for(int y = 0; y < curr_points->get_dim()[1]; y++){
229  for(int x = 0; x < curr_points->get_dim()[0]; x++){
230 
231  //Line break after every POINT_WIDTH values are written
232  if(values_printed == POINT_WIDTH){
233  mFileHandle << endl;
234  values_printed = 0;
235  }
236 
237  //Calculate value index (see tecplot docs)
238  int index = x * curr_points->get_dim()[1]
239  + y * curr_points->get_dim()[2]
240  + z;
241 
242  mFileHandle << " " << std::uppercase << std::scientific << curr_points->get_point(index).vals[var_num];
243 
244  values_printed++;
245 
246  }
247  }
248  }
249  }
250 
251  mFileHandle << std::endl;
252 
253  return false;
254 
255 }
256 
~TecplotWriter()
Destructor.
int get_num_vars()
Definition: points.cpp:121
j indices k indices k
Definition: Indexing.h:6
void int int REAL REAL * y
Definition: read.cpp:74
bool writePoints(int rPartitionNum)
Write the points of the partition specified to file.
string mFilename
Definition: tecplotwriter.h:72
long double * vals
Definition: datatypedef.h:69
std::vector< indexed_points * > mPartitionPoints
virtual std::vector< int > get_dim()
Definition: points.cpp:512
bool writeFile(string rTitle, std::vector< string > rVariableNames)
Write all information to file.
pnt get_point(int n)
Definition: points.cpp:183
ofstream mFileHandle
Definition: tecplotwriter.h:74
void int int int REAL REAL REAL * z
Definition: write.cpp:76
TecplotOrderedWriter()
Default constructor.
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
std::vector< int > mPartitionVariable
virtual ~TecplotOrderedWriter()
Destructor.
TecplotWriter()
Default constructor.
void setOutputFilename(string rFilename)
Set filename.
j indices j
Definition: Indexing.h:6
int get_num_indep_vars()
Definition: points.cpp:125
string getOutputFilename()
Get filename.
bool init()
Initialize writer.
bool addOrderedPartition(string rTitle, indexed_points *rpPoints, int rPartitionVariable)
Add ordered partition of points to the file write queue Points are written after WriteFile call Parti...
std::vector< string > mPartitionTitles
bool writePartition(int rPartitionNum)
Write partition to file.
int get_num_points()
Definition: points.cpp:117
static const int POINT_WIDTH
Number of points per line.