Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFC_Window_base_IO_tecplot.C
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: RFC_Window_base_IO_tecplot.C,v 1.4 2008/12/06 08:43:28 mtcampbe Exp $
24 
25 #include "RFC_Window_base.h"
26 #include <cstdio>
27 #include <cstdlib>
28 #include <fstream>
29 #include <iostream>
30 #include <cassert>
31 
33 
34 // The main interface for output a pane in Tecplot format.
35 void RFC_Pane_base::
36 write_tec_ascii( std::ostream &os, const COM::Attribute *attr) const {
37  if ( _base->size_of_nodes()==0) return;
38 
39  set_ascii_mode(os);
40  if ( _base->is_structured())
41  write_tec_ij( os, attr); // Structured mesh
42  else { // Unstructured mesh
43  std::vector< const COM::Connectivity*> elems;
44  _base->elements( elems);
45 
46  if ( elems.size() == 1 && elems[0]->size_of_edges_pe() == 3)
47  // Triangular finite element mesh
48  write_tec_tri( os, *elems[0], attr);
49  else
50  // Quadrilateral/mixed finite element mesh
51  write_tec_mixed( os, elems, attr);
52  }
53 }
54 
55 static void write_attr( std::ostream &os, const COM::Attribute *attr, int i) {
56  const int dim = attr->size_of_components();
57  switch ( attr->data_type()) {
58  case COM_DOUBLE:
59  case COM_DOUBLE_PRECISION: {
60  const double *values = reinterpret_cast<const double*>(attr->pointer());
61  for ( int j=0; j<dim; ++j) os << ' ' << values[i*dim+j];
62  break;
63  }
64  case COM_FLOAT:
65  case COM_REAL: {
66  const float *values = reinterpret_cast<const float*>(attr->pointer());
67  for ( int j=0; j<dim; ++j) os << ' ' << values[i*dim+j];
68  break;
69  }
70  case COM_INT:
71  case COM_INTEGER: {
72  const int *values = reinterpret_cast<const int*>(attr->pointer());
73  for ( int j=0; j<dim; ++j) os << ' ' << values[i*dim+j];
74  break;
75  }
76  default:
77  assert(false); abort();
78  }
79 }
80 
81 // Write out an IJ-ordered data in POINT format of Tecplot.
82 void RFC_Pane_base::
83 write_tec_ij( std::ostream &os, const COM::Attribute *attr) const {
84  RFC_assertion( _base != NULL);
85 
86  // Write out the head
87  if ( attr)
88  os << "TITLE = \"" << attr->name() << "\" \n";
89  else
90  os << "TITLE = \"Structured mesh\" \n";
91  os << "VARIABLES = \"X\", \"Y\", \"Z\"";
92  if ( attr) {
93  const int MAXDIM=4, dim=attr->size_of_components();
94  const char vname[MAXDIM+1]="UVWT";
95  RFC_assertion( dim<=MAXDIM);
96  for ( int i=0; i<dim; ++i)
97  os << ", \"" << vname[i] << "\"";
98  }
99  os << "\nZONE I=" << _base->size_i()
100  << ", J=" << _base->size_j() << ", F=POINT\n";
101 
102  // Write out the coordinates
103  const Real *p = _base->coordinates();
104  for ( int i=0, n=_base->size_of_nodes(); i<n; ++i) {
105  os << p[3*i] << ' ' << p[3*i+1] << ' ' << p[3*i+2];
106  if ( attr) write_attr( os, attr, i);
107  os << std::endl;
108  }
109  os << std::endl;
110 }
111 
112 // Write out a triangular finite element mesh in FEPOINT format of Tecplot
113 void RFC_Pane_base::
114 write_tec_tri( std::ostream &os, const COM::Connectivity &ec,
115  const COM::Attribute *attr) const {
116  RFC_assertion( _base != NULL);
117 
118  if ( attr)
119  os << "TITLE = \"" << attr->name() << "\" \n";
120  else
121  os << "TITLE = \"Triangular finite element mesh\" \n";
122  os << "VARIABLES = \"X\", \"Y\", \"Z\"";
123  if ( attr) {
124  const int MAXDIM=4, dim=attr->size_of_components();
125  const char vname[MAXDIM+1]="UVWT";
126  RFC_assertion( dim<=MAXDIM);
127  for ( int i=0; i<dim; ++i)
128  os << ", \"" << vname[i] << "\"";
129  }
130  os << "\nZONE N=" << _base->size_of_nodes() << ", E="
131  << _base->size_of_elements() << ", F=FEPOINT, ET=TRIANGLE\n";
132 
133  // Write out the coordinates
134  const Real *p = _base->coordinates();
135  for ( int i=0, n=_base->size_of_nodes(); i<n; ++i) {
136  os << p[3*i] << ' ' << p[3*i+1] << ' ' << p[3*i+2];
137  if ( attr) write_attr( os, attr, i);
138  os << std::endl;
139  }
140  os << std::endl;
141 
142  // Write out the elements
143  const int *e = ec.pointer();
144  int nn = ec.size_of_nodes_pe();
145  for ( unsigned int i=0, n=_base->size_of_elements(); i<n; ++i)
146  { os << e[nn*i] << ' ' << e[nn*i+1] << ' ' << e[nn*i+2] << std::endl; }
147 }
148 
149 // Write out a triangular finite element mesh in FEPOINT format of Tecplot
150 void RFC_Pane_base::
151 write_tec_mixed( std::ostream &os,
152  const std::vector<const COM::Connectivity*> &elems,
153  const COM::Attribute *attr) const {
154  RFC_assertion( _base != NULL);
155 
156  if ( attr)
157  os << "TITLE = \"" << attr->name() << "\" \n";
158  else
159  os << "TITLE = \"Triangular finite element mesh\" \n";
160  os << "VARIABLES = \"X\", \"Y\", \"Z\"";
161  if ( attr) {
162  const int MAXDIM=4, dim=attr->size_of_components();
163  const char vname[MAXDIM+1]="UVWT";
164  RFC_assertion( dim<=MAXDIM);
165  for ( int i=0; i<dim; ++i)
166  os << ", \"" << vname[i] << "\"";
167  }
168  os << "\nZONE N=" << _base->size_of_nodes() << ", E="
169  << _base->size_of_elements() << ", F=FEPOINT, ET=QUADRILATERAL\n";
170 
171  // Write out the coordinates
172  const Real *p = _base->coordinates();
173  for ( int i=0, n=_base->size_of_nodes(); i<n; ++i) {
174  os << p[3*i] << ' ' << p[3*i+1] << ' ' << p[3*i+2];
175  if ( attr) write_attr( os, attr, i);
176  os << std::endl;
177  }
178  os << std::endl;
179 
180  // Write out the elements
181  for ( std::vector<const COM::Connectivity*>::const_iterator
182  it = elems.begin(); it != elems.end(); ++it) {
183  const int *e = (*it)->pointer();
184  int nn = (*it)->size_of_nodes_pe();
185  switch ( (*it)->size_of_edges_pe()) {
186  case 3:
187  for ( int i=0,n=(*it)->size_of_elements(); i<n; ++i)
188  { os << e[nn*i] << ' ' << e[nn*i+1] << ' '
189  << e[nn*i+2] << ' ' << e[nn*i+2] << std::endl; }
190  break;
191  case 4:
192  for ( int i=0, n=(*it)->size_of_elements(); i<n; ++i)
193  { os << e[nn*i] << ' ' << e[nn*i+1] << ' '
194  << e[nn*i+2] << ' ' << e[nn*i+3] << std::endl; }
195  break;
196  default:
197  RFC_assertion( false);
198  }
199  }
200 }
201 
202 
203 // Write out the subdivision in FEPOINT format of Tecplot
204 void RFC_Pane_base::
205 write_tec_sub( std::ostream &os) const {
206  RFC_assertion( _base != NULL);
207  if ( size_of_subnodes() == 0) return;
208 
209  os << "TITLE = \"Triangular subdivision mesh\" \n";
210  os << "VARIABLES = \"X\", \"Y\", \"Z\"";
211  os << "\nZONE N=" << size_of_subnodes() << ", E="
212  << size_of_subfaces() << ", F=FEPOINT, ET=TRIANGLE\n";
213 
214  // Write out the coordinates, and the node ids start from 1.
215  for ( int i=1, size=size_of_subnodes(); i<=size; ++i) {
217 
218  os << p.x() << ' ' << p.y() << ' ' << p.z() << std::endl;
219  }
220  os << std::endl;
221 
222  // Write out the elements. We directly access the connectivity table
223  // and their indices start from 0.
224  for ( int i=0, size=size_of_subfaces(); i<size; ++i) {
225  os << _subfaces[i][0] << ' ' << _subfaces[i][1]
226  << ' ' << _subfaces[i][2] << std::endl;
227  }
228 }
229 
234 void
235 RFC_Window_base::write_tec_sub( const char *prefix) const {
236  std::ofstream os( (std::string( prefix) + ".plt").c_str()); RFC_assertion(os);
237  os.precision(9);
238  os.setf( std::ios::scientific, std::ios::floatfield);
239  for (Pane_set::const_iterator
240  it=_pane_set.begin(), iend=_pane_set.end(); it != iend; ++it) {
241  RFC_Pane_base &pane = *it->second;
242  if ( pane.is_master()) {
243  pane.write_tec_sub( os);
244  }
245  }
246 }
247 
252 void
253 RFC_Window_base::write_tec_ascii( const char *prefix) const {
254  std::ofstream os( (std::string( prefix) + ".plt").c_str()); RFC_assertion(os);
255  os.precision(9);
256  os.setf( std::ios::scientific, std::ios::floatfield);
257  for (Pane_set::const_iterator
258  it=_pane_set.begin(), iend=_pane_set.end(); it != iend; ++it) {
259  RFC_Pane_base &pane = *it->second;
260  if ( pane.is_master()) {
261  pane.write_tec_ascii( os, 0);
262  }
263  }
264 }
265 
267 
268 
269 
270 
271 
272 
void write_tec_ascii(std::ostream &os, const COM::Attribute *attr=0) const
Base * _base
Reference to its base object.
const RFC_Pane_base & pane(const int pid) const
void write_tec_sub(std::ostream &) const
std::vector< Three_tuple< int > > _subfaces
void write_tec_ascii(const char *prefix) const
Ouptut a mesh in Tecplot format.
bool is_master() const
Is this pane a master copy?
int size_of_subnodes() const
The total number of nodes in the subdivision of the pane.
The base implementation of RFC_Pane.
#define RFC_END_NAME_SPACE
Definition: rfc_basic.h:29
void write_tec_tri(std::ostream &, const COM::Connectivity &, const COM::Attribute *a=0) const
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE knode iend
static void write_attr(std::ostream &os, const COM::Attribute *attr, int i)
blockLoc i
Definition: read.cpp:79
#define RFC_BEGIN_NAME_SPACE
Definition: rfc_basic.h:28
Point_3 get_point_of_subnode(int id) const
void write_tec_ij(std::ostream &, const COM::Attribute *a=0) const
const NT & n
int size_of_subfaces() const
The total number of faces in the subdivision of the pane.
void write_tec_sub(const char *prefix) const
Ouptut a subdivision of a mesh in Tecplot format.
FT x() const
Definition: Point_3.h:129
FT y() const
Definition: Point_3.h:132
Pane_set _pane_set
The set of panes contained in the window.
j indices j
Definition: Indexing.h:6
IO::Mode set_ascii_mode(std::ios &i)
Definition: io.C:70
#define RFC_assertion
Definition: rfc_basic.h:65
void write_tec_mixed(std::ostream &, const std::vector< const COM::Connectivity * > &, const COM::Attribute *a=0) const
FT z() const
Definition: Point_3.h:135