libMesh::TecplotIO Class Reference

#include <tecplot_io.h>

Inheritance diagram for libMesh::TecplotIO:

Public Member Functions

 TecplotIO (const MeshBase &, const bool binary=false, const double time=0., const int strand_offset=0)
 
virtual void write (const std::string &) libmesh_override
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &) libmesh_override
 
bool & binary ()
 
double & time ()
 
int & strand_offset ()
 
std::string & zone_title ()
 
bool & ascii_append ()
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=libmesh_nullptr)
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 
unsigned int & ascii_precision ()
 

Protected Member Functions

const MeshBasemesh () const
 

Protected Attributes

const bool _is_parallel_format
 
const bool _serial_only_needed_on_proc_0
 

Private Member Functions

void write_ascii (const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
 
void write_binary (const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
 
unsigned elem_dimension ()
 

Private Attributes

bool _binary
 
double _time
 
int _strand_offset
 
std::string _zone_title
 
bool _ascii_append
 
std::set< subdomain_id_type_subdomain_ids
 

Detailed Description

This class implements writing meshes in the Tecplot format.

Author
Benjamin S. Kirk
Date
2004

Definition at line 43 of file tecplot_io.h.

Constructor & Destructor Documentation

libMesh::TecplotIO::TecplotIO ( const MeshBase mesh_in,
const bool  binary = false,
const double  time = 0.,
const int  strand_offset = 0 
)
explicit

Constructor. Takes a reference to a constant mesh object. This constructor will only allow us to write the mesh. The optional parameter binary can be used to switch between ASCII (false, the default) or binary (true) output files.

Definition at line 120 of file tecplot_io.C.

References _subdomain_ids, and libMesh::MeshBase::subdomain_ids().

123  :
124  MeshOutput<MeshBase> (mesh_in),
125  _binary (binary_in),
126  _time (time_in),
127  _strand_offset (strand_offset_in),
128  _zone_title ("zone"),
129  _ascii_append(false)
130 {
131  // Gather a list of subdomain ids in the mesh.
132  // We must do this now, while we have every
133  // processor's attention
134  // (some of the write methods only execute on processor 0).
135  mesh_in.subdomain_ids (_subdomain_ids);
136 }
std::set< subdomain_id_type > _subdomain_ids
Definition: tecplot_io.h:172
std::string _zone_title
Definition: tecplot_io.h:161

Member Function Documentation

bool & libMesh::TecplotIO::ascii_append ( )

Set to true to write multiple solutions to a single file (ASCII only). Tecplot will read multiple zones in a single file, but currently you have to repeat the mesh information each time.

Definition at line 167 of file tecplot_io.C.

References _ascii_append.

168 {
169  return _ascii_append;
170 }
unsigned int& libMesh::MeshOutput< MeshBase >::ascii_precision ( )
inherited

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Referenced by write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

bool & libMesh::TecplotIO::binary ( )

Flag indicating whether or not to write a binary file (if the tecio.a library was found by configure).

Definition at line 140 of file tecplot_io.C.

References _binary.

Referenced by write(), and write_nodal_data().

141 {
142  return _binary;
143 }
unsigned libMesh::TecplotIO::elem_dimension ( )
private

Determines the logical spatial dimension of the elements in the Mesh. Ex: A 1D edge element living in 3D is a logically one-dimensional element as far as Tecplot is concerned. Throws an error if mixed-dimension element types are found, since I'm not sure how to handle that case currently.

Definition at line 203 of file tecplot_io.C.

References libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), end, and libMesh::MeshOutput< MT >::mesh().

Referenced by write_ascii(), and write_binary().

204 {
205  // Get a constant reference to the mesh.
206  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
207 
208  std::vector<unsigned> elem_dims(3);
209 
210  // Loop over all the elements and mark the proper dimension entry in
211  // the elem_dims vector.
212  MeshBase::const_element_iterator it = the_mesh.active_elements_begin();
213  const MeshBase::const_element_iterator end = the_mesh.active_elements_end();
214  for ( ; it != end; ++it)
215  elem_dims[(*it)->dim() - 1] = 1;
216 
217  // Detect and disallow (for now) the writing of mixed dimension meshes.
218  if (std::count(elem_dims.begin(), elem_dims.end(), 1) > 1)
219  libmesh_error_msg("Error, cannot write Mesh with mixed element dimensions to Tecplot file!");
220 
221  if (elem_dims[0])
222  return 1;
223  else if (elem_dims[1])
224  return 2;
225  else if (elem_dims[2])
226  return 3;
227  else
228  libmesh_error_msg("No 1, 2, or 3D elements detected!");
229 }
IterBase * end
const MT & mesh() const
Definition: mesh_output.h:216
int & libMesh::TecplotIO::strand_offset ( )

Strand offset for this file. Each mesh block will be written to (strand_id=block_id+1+strand_offset). Written to newer binary formats that are time-aware, defaults to 0.

Definition at line 154 of file tecplot_io.C.

References _strand_offset.

Referenced by write_binary().

155 {
156  return _strand_offset;
157 }
double & libMesh::TecplotIO::time ( )

Solution time for transient data. Written to newer binary formats that are time-aware.

Definition at line 147 of file tecplot_io.C.

References _time.

148 {
149  return _time;
150 }
void libMesh::TecplotIO::write ( const std::string &  fname)
virtual

This method implements writing a mesh to a specified file.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 173 of file tecplot_io.C.

References binary(), libMesh::MeshOutput< MeshBase >::mesh(), libMesh::processor_id(), write_ascii(), and write_binary().

Referenced by libMesh::NameBasedIO::write().

174 {
175  if (this->mesh().processor_id() == 0)
176  {
177  if (this->binary())
178  this->write_binary (fname);
179  else
180  this->write_ascii (fname);
181  }
182 }
void write_binary(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
Definition: tecplot_io.C:355
const MeshBase & mesh() const
void write_ascii(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
Definition: tecplot_io.C:233
processor_id_type processor_id()
Definition: libmesh_base.h:96
void libMesh::TecplotIO::write_ascii ( const std::string &  fname,
const std::vector< Number > *  v = libmesh_nullptr,
const std::vector< std::string > *  solution_names = libmesh_nullptr 
)
private

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are optionally provided. This will write an ASCII file.

Definition at line 233 of file tecplot_io.C.

References _ascii_append, _time, std::abs(), libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::MeshOutput< MeshBase >::ascii_precision(), elem_dimension(), end, libmesh_nullptr, libMesh::MeshOutput< MT >::mesh(), libMesh::MeshOutput< MeshBase >::mesh(), libMesh::MeshBase::n_active_sub_elem(), libMesh::MeshBase::n_nodes(), n_vars, libMesh::out, libMesh::MeshBase::point(), libMesh::processor_id(), libMesh::TECPLOT, and libMesh::TypeVector< T >::write_unformatted().

Referenced by write(), write_binary(), and write_nodal_data().

236 {
237  // Should only do this on processor 0!
238  libmesh_assert_equal_to (this->mesh().processor_id(), 0);
239 
240  // Create an output stream, possibly in append mode.
241  std::ofstream out_stream(fname.c_str(), _ascii_append ? std::ofstream::app : std::ofstream::out);
242 
243  // Make sure it opened correctly
244  if (!out_stream.good())
245  libmesh_file_error(fname.c_str());
246 
247  // Get a constant reference to the mesh.
248  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
249 
250  // Write header to stream
251  {
252  {
253  // TODO: We used to print out the SVN revision here when we did keyword expansions...
254  out_stream << "# For a description of the Tecplot format see the Tecplot User's guide.\n"
255  << "#\n";
256  }
257 
258  out_stream << "Variables=x,y,z";
259 
260  if (solution_names != libmesh_nullptr)
261  for (std::size_t n=0; n<solution_names->size(); n++)
262  {
263 #ifdef LIBMESH_USE_REAL_NUMBERS
264 
265  // Write variable names for real variables
266  out_stream << "," << (*solution_names)[n];
267 
268 #else
269 
270  // Write variable names for complex variables
271  out_stream << "," << "r_" << (*solution_names)[n]
272  << "," << "i_" << (*solution_names)[n]
273  << "," << "a_" << (*solution_names)[n];
274 
275 #endif
276  }
277 
278  out_stream << '\n';
279 
280  out_stream << "Zone f=fepoint, n=" << the_mesh.n_nodes() << ", e=" << the_mesh.n_active_sub_elem();
281 
282  // We cannot choose the element type simply based on the mesh
283  // dimension... there might be 1D elements living in a 3D mesh.
284  // So look at the elements which are actually in the Mesh, and
285  // choose either "lineseg", "quadrilateral", or "brick" depending
286  // on if the elements are 1, 2, or 3D.
287 
288  // Write the element type we've determined to the header.
289  out_stream << ", et=";
290 
291  switch (this->elem_dimension())
292  {
293  case 1:
294  out_stream << "lineseg";
295  break;
296  case 2:
297  out_stream << "quadrilateral";
298  break;
299  case 3:
300  out_stream << "brick";
301  break;
302  default:
303  libmesh_error_msg("Unsupported element dimension: " << this->elem_dimension());
304  }
305 
306  // Output the time in the header
307  out_stream << ", t=\"T " << _time << "\"";
308 
309  // Use default mesh color = black
310  out_stream << ", c=black\n";
311 
312  } // finished writing header
313 
314  for (unsigned int i=0; i<the_mesh.n_nodes(); i++)
315  {
316  // Print the point without a newline
317  the_mesh.point(i).write_unformatted(out_stream, false);
318 
319  if ((v != libmesh_nullptr) && (solution_names != libmesh_nullptr))
320  {
321  const std::size_t n_vars = solution_names->size();
322 
323 
324  for (std::size_t c=0; c<n_vars; c++)
325  {
326 #ifdef LIBMESH_USE_REAL_NUMBERS
327  // Write real data
328  out_stream << std::setprecision(this->ascii_precision())
329  << (*v)[i*n_vars + c] << " ";
330 
331 #else
332  // Write complex data
333  out_stream << std::setprecision(this->ascii_precision())
334  << (*v)[i*n_vars + c].real() << " "
335  << (*v)[i*n_vars + c].imag() << " "
336  << std::abs((*v)[i*n_vars + c]) << " ";
337 
338 #endif
339  }
340  }
341 
342  // Write a new line after the data for this node
343  out_stream << '\n';
344  }
345 
346  MeshBase::const_element_iterator it = the_mesh.active_elements_begin();
347  const MeshBase::const_element_iterator end = the_mesh.active_elements_end();
348 
349  for ( ; it != end; ++it)
350  (*it)->write_connectivity(out_stream, TECPLOT);
351 }
double abs(double a)
const class libmesh_nullptr_t libmesh_nullptr
unsigned int & ascii_precision()
IterBase * end
const MeshBase & mesh() const
const unsigned int n_vars
Definition: tecplot_io.C:68
unsigned elem_dimension()
Definition: tecplot_io.C:203
OStreamProxy out(std::cout)
processor_id_type processor_id()
Definition: libmesh_base.h:96
void libMesh::TecplotIO::write_binary ( const std::string &  fname,
const std::vector< Number > *  vec = libmesh_nullptr,
const std::vector< std::string > *  solution_names = libmesh_nullptr 
)
private

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are optionally provided. This will write a binary file if the tecio.a library was found at compile time, otherwise a warning message will be printed and an ASCII file will be created.

Definition at line 355 of file tecplot_io.C.

References _subdomain_ids, _time, std::abs(), libMesh::MeshBase::active_elements_begin(), libMesh::MeshBase::active_elements_end(), libMesh::MeshBase::active_subdomain_elements_begin(), libMesh::MeshBase::active_subdomain_elements_end(), elem_dimension(), end, libMesh::err, ierr, libmesh_nullptr, std::max(), libMesh::MeshOutput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::n_active_sub_elem(), libMesh::MeshBase::n_nodes(), n_vars, libMesh::Quality::name(), libMesh::MeshBase::point(), libMesh::processor_id(), strand_offset(), libMesh::MeshBase::subdomain_name(), libMesh::TECPLOT, write_ascii(), and zone_title().

Referenced by write(), and write_nodal_data().

358 {
359  //-----------------------------------------------------------
360  // Call the ASCII output function if configure did not detect
361  // the Tecplot binary API
362 #ifndef LIBMESH_HAVE_TECPLOT_API
363 
364  libMesh::err << "WARNING: Tecplot Binary files require the Tecplot API." << std::endl
365  << "Continuing with ASCII output."
366  << std::endl;
367 
368  if (this->mesh().processor_id() == 0)
369  this->write_ascii (fname, vec, solution_names);
370  return;
371 
372 
373 
374  //------------------------------------------------------------
375  // New binary formats, time aware and whatnot
376 #elif defined(LIBMESH_HAVE_TECPLOT_API_112)
377 
378  // Get a constant reference to the mesh.
379  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
380 
381  // Required variables
382  std::string tecplot_variable_names;
383  int
384  ierr = 0,
385  file_type = 0, // full
386  is_double = 0,
387 #ifdef DEBUG
388  tec_debug = 1,
389 #else
390  tec_debug = 0,
391 #endif
392  cell_type = -1,
393  nn_per_elem = -1;
394 
395  switch (this->elem_dimension())
396  {
397  case 1:
398  cell_type = 1; // FELINESEG
399  nn_per_elem = 2;
400  break;
401 
402  case 2:
403  cell_type = 3; // FEQUADRILATERAL
404  nn_per_elem = 4;
405  break;
406 
407  case 3:
408  cell_type = 5; // FEBRICK
409  nn_per_elem = 8;
410  break;
411 
412  default:
413  libmesh_error_msg("Unsupported element dimension: " << this->elem_dimension());
414  }
415 
416  // Build a string containing all the variable names to pass to Tecplot
417  {
418  tecplot_variable_names += "x, y, z";
419 
420  if (solution_names != libmesh_nullptr)
421  {
422  for (std::size_t name=0; name<solution_names->size(); name++)
423  {
424 #ifdef LIBMESH_USE_REAL_NUMBERS
425 
426  tecplot_variable_names += ", ";
427  tecplot_variable_names += (*solution_names)[name];
428 
429 #else
430 
431  tecplot_variable_names += ", ";
432  tecplot_variable_names += "r_";
433  tecplot_variable_names += (*solution_names)[name];
434  tecplot_variable_names += ", ";
435  tecplot_variable_names += "i_";
436  tecplot_variable_names += (*solution_names)[name];
437  tecplot_variable_names += ", ";
438  tecplot_variable_names += "a_";
439  tecplot_variable_names += (*solution_names)[name];
440 
441 #endif
442  }
443  }
444  }
445 
446  // Instantiate a TecplotMacros interface. In 2D the most nodes per
447  // face should be 4, in 3D it's 8.
448 
449 
450  TecplotMacros tm(the_mesh.n_nodes(),
451 #ifdef LIBMESH_USE_REAL_NUMBERS
452  (3 + ((solution_names == libmesh_nullptr) ? 0 :
453  cast_int<unsigned int>(solution_names->size()))),
454 #else
455  (3 + 3*((solution_names == libmesh_nullptr) ? 0 :
456  cast_int<unsigned int>(solution_names->size()))),
457 #endif
458  the_mesh.n_active_sub_elem(),
459  nn_per_elem
460  );
461 
462 
463  // Copy the nodes and data to the TecplotMacros class. Note that we store
464  // everything as a float here since the eye doesn't require a double to
465  // understand what is going on
466  for (unsigned int v=0; v<the_mesh.n_nodes(); v++)
467  {
468  tm.nd(0,v) = static_cast<float>(the_mesh.point(v)(0));
469  tm.nd(1,v) = static_cast<float>(the_mesh.point(v)(1));
470  tm.nd(2,v) = static_cast<float>(the_mesh.point(v)(2));
471 
472  if ((vec != libmesh_nullptr) &&
473  (solution_names != libmesh_nullptr))
474  {
475  const std::size_t n_vars = solution_names->size();
476 
477  for (std::size_t c=0; c<n_vars; c++)
478  {
479 #ifdef LIBMESH_USE_REAL_NUMBERS
480 
481  tm.nd((3+c),v) = static_cast<float>((*vec)[v*n_vars + c]);
482 #else
483  tm.nd((3+3*c),v) = static_cast<float>((*vec)[v*n_vars + c].real());
484  tm.nd((3+3*c+1),v) = static_cast<float>((*vec)[v*n_vars + c].imag());
485  tm.nd((3+3*c+2),v) = static_cast<float>(std::abs((*vec)[v*n_vars + c]));
486 #endif
487  }
488  }
489  }
490 
491 
492  // Initialize the file
493  ierr = TECINI112 (libmesh_nullptr,
494  const_cast<char *>(tecplot_variable_names.c_str()),
495  const_cast<char *>(fname.c_str()),
496  const_cast<char *>("."),
497  &file_type,
498  &tec_debug,
499  &is_double);
500 
501  if (ierr)
502  libmesh_file_error(fname);
503 
504  // A zone for each subdomain
505  bool firstzone=true;
506  for (std::set<subdomain_id_type>::const_iterator sbd_it=_subdomain_ids.begin();
507  sbd_it!=_subdomain_ids.end(); ++sbd_it)
508  {
509  // Copy the connectivity for this subdomain
510  {
511  MeshBase::const_element_iterator it = the_mesh.active_subdomain_elements_begin (*sbd_it);
512  const MeshBase::const_element_iterator end = the_mesh.active_subdomain_elements_end (*sbd_it);
513 
514  unsigned int n_subcells_in_subdomain=0;
515 
516  for (; it != end; ++it)
517  n_subcells_in_subdomain += (*it)->n_sub_elem();
518 
519  // update the connectivty array to include only the elements in this subdomain
520  tm.set_n_cells (n_subcells_in_subdomain);
521 
522  unsigned int te = 0;
523 
524  for (it = the_mesh.active_subdomain_elements_begin (*sbd_it);
525  it != end; ++it)
526  {
527  std::vector<dof_id_type> conn;
528  for (unsigned int se=0; se<(*it)->n_sub_elem(); se++)
529  {
530  (*it)->connectivity(se, TECPLOT, conn);
531 
532  for (std::size_t node=0; node<conn.size(); node++)
533  tm.cd(node,te) = conn[node];
534 
535  te++;
536  }
537  }
538  }
539 
540 
541  // Ready to call the Tecplot API for this subdomain
542  {
543  int
544  num_nodes = static_cast<int>(the_mesh.n_nodes()),
545  num_cells = static_cast<int>(tm.n_cells),
546  num_faces = 0,
547  i_cell_max = 0,
548  j_cell_max = 0,
549  k_cell_max = 0,
550  strand_id = std::max(*sbd_it,static_cast<subdomain_id_type>(1)) + this->strand_offset(),
551  parent_zone = 0,
552  is_block = 1,
553  num_face_connect = 0,
554  face_neighbor_mode = 0,
555  tot_num_face_nodes = 0,
556  num_connect_boundary_faces = 0,
557  tot_num_boundary_connect = 0,
558  share_connect_from_zone=0;
559 
560  std::vector<int>
561  passive_var_list (tm.n_vars, 0),
562  share_var_from_zone (tm.n_vars, 1); // We only write data for the first zone, all other
563  // zones will share from this one.
564 
565  // get the subdomain name from libMesh, if there is one.
566  std::string subdomain_name = the_mesh.subdomain_name(*sbd_it);
567  std::ostringstream zone_name;
568  zone_name << this->zone_title();
569 
570  // We will title this
571  // "{zone_title()}_{subdomain_name}", or
572  // "{zone_title()}_{subdomain_id}", or
573  // "{zone_title()}"
574  if (subdomain_name.size())
575  {
576  zone_name << "_";
577  zone_name << subdomain_name;
578  }
579  else if (_subdomain_ids.size() > 1)
580  {
581  zone_name << "_";
582  zone_name << *sbd_it;
583  }
584 
585  ierr = TECZNE112 (const_cast<char *>(zone_name.str().c_str()),
586  &cell_type,
587  &num_nodes,
588  &num_cells,
589  &num_faces,
590  &i_cell_max,
591  &j_cell_max,
592  &k_cell_max,
593  &_time,
594  &strand_id,
595  &parent_zone,
596  &is_block,
597  &num_face_connect,
598  &face_neighbor_mode,
599  &tot_num_face_nodes,
600  &num_connect_boundary_faces,
601  &tot_num_boundary_connect,
602  &passive_var_list[0],
603  libmesh_nullptr, // = all are node centered
604  (firstzone) ? libmesh_nullptr : &share_var_from_zone[0],
605  &share_connect_from_zone);
606 
607  if (ierr)
608  libmesh_file_error(fname);
609 
610  // Write *all* the data for the first zone, then share it with the others
611  if (firstzone)
612  {
613  int total = cast_int<int>
614 #ifdef LIBMESH_USE_REAL_NUMBERS
615  ((3 + ((solution_names == libmesh_nullptr) ? 0 : solution_names->size()))*num_nodes);
616 #else
617  ((3 + 3*((solution_names == libmesh_nullptr) ? 0 : solution_names->size()))*num_nodes);
618 #endif
619 
620 
621  ierr = TECDAT112 (&total,
622  &tm.nodalData[0],
623  &is_double);
624 
625  if (ierr)
626  libmesh_file_error(fname);
627  }
628 
629  // Write the connectivity
630  ierr = TECNOD112 (&tm.connData[0]);
631 
632  if (ierr)
633  libmesh_file_error(fname);
634  }
635 
636  firstzone = false;
637  }
638 
639  // Done, close the file.
640  ierr = TECEND112 ();
641 
642  if (ierr)
643  libmesh_file_error(fname);
644 
645 
646 
647 
648  //------------------------------------------------------------
649  // Legacy binary format
650 #else
651 
652  // Get a constant reference to the mesh.
653  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
654 
655  // Tecplot binary output only good for dim=2,3
656  if (the_mesh.mesh_dimension() == 1)
657  {
658  this->write_ascii (fname, vec, solution_names);
659 
660  return;
661  }
662 
663  // Required variables
664  std::string tecplot_variable_names;
665  int is_double = 0,
666  tec_debug = 0,
667  cell_type = ((the_mesh.mesh_dimension()==2) ? (1) : (3));
668 
669  // Build a string containing all the variable names to pass to Tecplot
670  {
671  tecplot_variable_names += "x, y, z";
672 
673  if (solution_names != libmesh_nullptr)
674  {
675  for (std::size_t name=0; name<solution_names->size(); name++)
676  {
677 #ifdef LIBMESH_USE_REAL_NUMBERS
678 
679  tecplot_variable_names += ", ";
680  tecplot_variable_names += (*solution_names)[name];
681 
682 #else
683 
684  tecplot_variable_names += ", ";
685  tecplot_variable_names += "r_";
686  tecplot_variable_names += (*solution_names)[name];
687  tecplot_variable_names += ", ";
688  tecplot_variable_names += "i_";
689  tecplot_variable_names += (*solution_names)[name];
690  tecplot_variable_names += ", ";
691  tecplot_variable_names += "a_";
692  tecplot_variable_names += (*solution_names)[name];
693 
694 #endif
695  }
696  }
697  }
698 
699  // Instantiate a TecplotMacros interface. In 2D the most nodes per
700  // face should be 4, in 3D it's 8.
701 
702 
703  TecplotMacros tm(cast_int<unsigned int>(the_mesh.n_nodes()),
704  cast_int<unsigned int>
705 #ifdef LIBMESH_USE_REAL_NUMBERS
706  (3 + ((solution_names == libmesh_nullptr) ? 0 : solution_names->size())),
707 #else
708  (3 + 3*((solution_names == libmesh_nullptr) ? 0 : solution_names->size())),
709 #endif
710  cast_int<unsigned int>
711  (the_mesh.n_active_sub_elem()),
712  ((the_mesh.mesh_dimension() == 2) ? 4 : 8)
713  );
714 
715 
716  // Copy the nodes and data to the TecplotMacros class. Note that we store
717  // everything as a float here since the eye doesn't require a double to
718  // understand what is going on
719  for (unsigned int v=0; v<the_mesh.n_nodes(); v++)
720  {
721  tm.nd(0,v) = static_cast<float>(the_mesh.point(v)(0));
722  tm.nd(1,v) = static_cast<float>(the_mesh.point(v)(1));
723  tm.nd(2,v) = static_cast<float>(the_mesh.point(v)(2));
724 
725  if ((vec != libmesh_nullptr) &&
726  (solution_names != libmesh_nullptr))
727  {
728  const std::size_t n_vars = solution_names->size();
729 
730  for (std::size_t c=0; c<n_vars; c++)
731  {
732 #ifdef LIBMESH_USE_REAL_NUMBERS
733 
734  tm.nd((3+c),v) = static_cast<float>((*vec)[v*n_vars + c]);
735 #else
736  tm.nd((3+3*c),v) = static_cast<float>((*vec)[v*n_vars + c].real());
737  tm.nd((3+3*c+1),v) = static_cast<float>((*vec)[v*n_vars + c].imag());
738  tm.nd((3+3*c+2),v) = static_cast<float>(std::abs((*vec)[v*n_vars + c]));
739 #endif
740  }
741  }
742  }
743 
744 
745  // Copy the connectivity
746  {
747  unsigned int te = 0;
748 
749  MeshBase::const_element_iterator it = the_mesh.active_elements_begin();
750  const MeshBase::const_element_iterator end = the_mesh.active_elements_end();
751 
752  for ( ; it != end; ++it)
753  {
754  std::vector<dof_id_type> conn;
755  for (unsigned int se=0; se<(*it)->n_sub_elem(); se++)
756  {
757  (*it)->connectivity(se, TECPLOT, conn);
758 
759  for (std::size_t node=0; node<conn.size(); node++)
760  tm.cd(node,te) = conn[node];
761 
762  te++;
763  }
764  }
765  }
766 
767 
768  // Ready to call the Tecplot API
769  {
770  int ierr = 0,
771  num_nodes = static_cast<int>(the_mesh.n_nodes()),
772  num_cells = static_cast<int>(the_mesh.n_active_sub_elem());
773 
774 
775  ierr = TECINI (libmesh_nullptr,
776  (char *) tecplot_variable_names.c_str(),
777  (char *) fname.c_str(),
778  (char *) ".",
779  &tec_debug,
780  &is_double);
781 
782  if (ierr)
783  libmesh_file_error(fname);
784 
785 
786  ierr = TECZNE (libmesh_nullptr,
787  &num_nodes,
788  &num_cells,
789  &cell_type,
790  (char *) "FEBLOCK",
792 
793  if (ierr)
794  libmesh_file_error(fname);
795 
796 
797  int total =
798 #ifdef LIBMESH_USE_REAL_NUMBERS
799  ((3 + ((solution_names == libmesh_nullptr) ? 0 : solution_names->size()))*num_nodes);
800 #else
801  ((3 + 3*((solution_names == libmesh_nullptr) ? 0 : solution_names->size()))*num_nodes);
802 #endif
803 
804 
805  ierr = TECDAT (&total,
806  &tm.nodalData[0],
807  &is_double);
808 
809  if (ierr)
810  libmesh_file_error(fname);
811 
812  ierr = TECNOD (&tm.connData[0]);
813 
814  if (ierr)
815  libmesh_file_error(fname);
816 
817  ierr = TECEND ();
818 
819  if (ierr)
820  libmesh_file_error(fname);
821  }
822 
823 #endif
824 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:39
double abs(double a)
int & strand_offset()
Definition: tecplot_io.C:154
const class libmesh_nullptr_t libmesh_nullptr
IterBase * end
const MeshBase & mesh() const
const unsigned int n_vars
Definition: tecplot_io.C:68
long double max(long double a, double b)
std::set< subdomain_id_type > _subdomain_ids
Definition: tecplot_io.h:172
OStreamProxy err(std::cerr)
void write_ascii(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
Definition: tecplot_io.C:233
unsigned elem_dimension()
Definition: tecplot_io.C:203
PetscErrorCode ierr
processor_id_type processor_id()
Definition: libmesh_base.h:96
std::string & zone_title()
Definition: tecplot_io.C:161
virtual void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  ,
const EquationSystems ,
const std::set< std::string > *  system_names = libmesh_nullptr 
)
virtualinherited

This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.

Reimplemented in libMesh::NameBasedIO.

Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_IO::write_timestep().

void libMesh::TecplotIO::write_nodal_data ( const std::string &  fname,
const std::vector< Number > &  soln,
const std::vector< std::string > &  names 
)
virtual

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented from libMesh::MeshOutput< MeshBase >.

Definition at line 186 of file tecplot_io.C.

References binary(), libMesh::MeshOutput< MeshBase >::mesh(), libMesh::processor_id(), write_ascii(), and write_binary().

Referenced by libMesh::NameBasedIO::write_nodal_data().

189 {
190  LOG_SCOPE("write_nodal_data()", "TecplotIO");
191 
192  if (this->mesh().processor_id() == 0)
193  {
194  if (this->binary())
195  this->write_binary (fname, &soln, &names);
196  else
197  this->write_ascii (fname, &soln, &names);
198  }
199 }
void write_binary(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
Definition: tecplot_io.C:355
const MeshBase & mesh() const
void write_ascii(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
Definition: tecplot_io.C:233
processor_id_type processor_id()
Definition: libmesh_base.h:96
virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const NumericVector< Number > &  ,
const std::vector< std::string > &   
)
virtualinherited

This method should be overridden by "parallel" output formats for writing nodal data. Instead of getting a localized copy of the nodal solution vector, it is passed a NumericVector of type=PARALLEL which is in node-major order i.e. (u0,v0,w0, u1,v1,w1, u2,v2,w2, u3,v3,w3, ...) and contains n_nodes*n_vars total entries. Then, it is up to the individual I/O class to extract the required solution values from this vector and write them in parallel.

If not implemented, localizes the parallel vector into a std::vector and calls the other version of this function.

Reimplemented in libMesh::Nemesis_IO.

std::string & libMesh::TecplotIO::zone_title ( )

The zone title to write.

Definition at line 161 of file tecplot_io.C.

References _zone_title.

Referenced by write_binary().

162 {
163  return _zone_title;
164 }
std::string _zone_title
Definition: tecplot_io.h:161

Member Data Documentation

bool libMesh::TecplotIO::_ascii_append
private

If true, when writing in ASCII format, open the file in std::ofstream::app mode.

Definition at line 167 of file tecplot_io.h.

Referenced by ascii_append(), and write_ascii().

bool libMesh::TecplotIO::_binary
private

Flag to write binary data.

Definition at line 146 of file tecplot_io.h.

Referenced by binary().

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format
protectedinherited

Flag specifying whether this format is parallel-capable. If this is false (default) I/O is only permitted when the mesh has been serialized.

Definition at line 141 of file mesh_output.h.

Referenced by libMesh::FroIO::write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::write().

const bool libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
protectedinherited

Flag specifying whether this format can be written by only serializing the mesh to processor zero

If this is false (default) the mesh will be serialized to all processors

Definition at line 150 of file mesh_output.h.

int libMesh::TecplotIO::_strand_offset
private

Offset for Tecplot's STRANDID.

Definition at line 156 of file tecplot_io.h.

Referenced by strand_offset().

std::set<subdomain_id_type> libMesh::TecplotIO::_subdomain_ids
private

The subdomains in the mesh.

Definition at line 172 of file tecplot_io.h.

Referenced by TecplotIO(), and write_binary().

double libMesh::TecplotIO::_time
private

Solution time.

Definition at line 151 of file tecplot_io.h.

Referenced by time(), write_ascii(), and write_binary().

std::string libMesh::TecplotIO::_zone_title
private

The zone title to write.

Definition at line 161 of file tecplot_io.h.

Referenced by zone_title().


The documentation for this class was generated from the following files: