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 121 of file tecplot_io.C.

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

124  :
125  MeshOutput<MeshBase> (mesh_in),
126  _binary (binary_in),
127  _time (time_in),
128  _strand_offset (strand_offset_in),
129  _zone_title ("zone"),
130  _ascii_append(false)
131 {
132  // Gather a list of subdomain ids in the mesh.
133  // We must do this now, while we have every
134  // processor's attention
135  // (some of the write methods only execute on processor 0).
136  mesh_in.subdomain_ids (_subdomain_ids);
137 }
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 168 of file tecplot_io.C.

References _ascii_append.

169 {
170  return _ascii_append;
171 }
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 141 of file tecplot_io.C.

References _binary.

Referenced by write(), and write_nodal_data().

142 {
143  return _binary;
144 }
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 204 of file tecplot_io.C.

References libMesh::MeshBase::active_element_ptr_range(), and libMesh::MeshOutput< MT >::mesh().

Referenced by write_ascii(), and write_binary().

205 {
206  // Get a constant reference to the mesh.
207  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
208 
209  std::vector<unsigned> elem_dims(3);
210 
211  // Loop over all the elements and mark the proper dimension entry in
212  // the elem_dims vector.
213  for (const auto & elem : the_mesh.active_element_ptr_range())
214  elem_dims[elem->dim() - 1] = 1;
215 
216  // Detect and disallow (for now) the writing of mixed dimension meshes.
217  if (std::count(elem_dims.begin(), elem_dims.end(), 1) > 1)
218  libmesh_error_msg("Error, cannot write Mesh with mixed element dimensions to Tecplot file!");
219 
220  if (elem_dims[0])
221  return 1;
222  else if (elem_dims[1])
223  return 2;
224  else if (elem_dims[2])
225  return 3;
226  else
227  libmesh_error_msg("No 1, 2, or 3D elements detected!");
228 }
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 155 of file tecplot_io.C.

References _strand_offset.

Referenced by write_binary().

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

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

Definition at line 148 of file tecplot_io.C.

References _time.

149 {
150  return _time;
151 }
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 174 of file tecplot_io.C.

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

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

175 {
176  if (this->mesh().processor_id() == 0)
177  {
178  if (this->binary())
179  this->write_binary (fname);
180  else
181  this->write_ascii (fname);
182  }
183 }
void write_binary(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
Definition: tecplot_io.C:351
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:232
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 232 of file tecplot_io.C.

References _ascii_append, _time, std::abs(), libMesh::MeshBase::active_element_ptr_range(), libMesh::MeshOutput< MeshBase >::ascii_precision(), elem_dimension(), 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().

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

References _subdomain_ids, _time, std::abs(), libMesh::MeshBase::active_element_ptr_range(), 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().

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

190 {
191  LOG_SCOPE("write_nodal_data()", "TecplotIO");
192 
193  if (this->mesh().processor_id() == 0)
194  {
195  if (this->binary())
196  this->write_binary (fname, &soln, &names);
197  else
198  this->write_ascii (fname, &soln, &names);
199  }
200 }
void write_binary(const std::string &, const std::vector< Number > *=libmesh_nullptr, const std::vector< std::string > *=libmesh_nullptr)
Definition: tecplot_io.C:351
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:232
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 162 of file tecplot_io.C.

References _zone_title.

Referenced by write_binary().

163 {
164  return _zone_title;
165 }
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: