libMesh
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::PltLoader Class Reference

This class will read a binary .plt file. More...

#include <plt_loader.h>

Public Types

enum  OldZoneType { BLOCK =0 , POINT , FEBLOCK , FEPOINT }
 Enum defining the zone type in the Tecplot binary file, for use with the old .plt format. More...
 
enum  NewZoneType {
  ORDERED =0 , FELINESEG , FETRIANGLE , FEQUADRILATERAL ,
  FETETRAHEDRON , FEBRICK
}
 Enum defining the zone type in the Tecplot binary file, for use with the new .plt format. More...
 
enum  DataType {
  FLOAT =1 , DOUBLE , LONGINT , SHORTINT ,
  BYTE , BIT
}
 Enum defining the data type of each variable. More...
 
enum  FEType { TRI =0 , QUAD , TET , HEX }
 Enum defining the finite element types. More...
 

Public Member Functions

 PltLoader (const bool v=false)
 Constructor.
 
 PltLoader (const std::string &name, const bool v=false)
 Constructor.
 
 ~PltLoader ()
 Destructor.
 
void clear ()
 Clear all data and return to a pristine state.
 
bool verbose () const
 
void read (const std::string &name)
 Reads the .plt file specified by name.
 
void write_dat (const std::string &name, const unsigned int version=10) const
 Writes an ASCII Tecplot file.
 
const std::string & version () const
 
bool is_foreign () const
 
const std::string & title () const
 
unsigned int n_vars () const
 
const std::string & var_name (const unsigned int v) const
 
unsigned int var_type (const unsigned int v) const
 
unsigned int n_zones () const
 
unsigned int zone_type (const unsigned int z) const
 
const std::string & zone_name (const unsigned int z) const
 
unsigned int zone_pack (const unsigned int z) const
 
unsigned int imax (const unsigned int z) const
 
unsigned int jmax (const unsigned int z) const
 
unsigned int kmax (const unsigned int z) const
 
unsigned int n_nodes (const unsigned int z) const
 
unsigned int n_elem (const unsigned int z) const
 
FEType elem_type (const unsigned int z) const
 
const std::vector< std::vector< std::vector< float > > > & get_data () const
 

Static Public Attributes

static const unsigned int NNodes [4] = {3, 4, 4, 8}
 Enum defining the number of nodes for each element type.
 

Private Member Functions

void read_header (std::istream &in)
 Read the header of the binary file.
 
void read_data (std::istream &in)
 Read data from the binary file.
 
void read_block_data (std::istream &in, const unsigned int zn)
 Read data for the zth zone in BLOCK structured format.
 
void read_point_data (std::istream &in, const unsigned int zn)
 Read data for the zth zone in POINT structured format.
 
void read_feblock_data (std::istream &in, const unsigned int zn)
 Read data for the zth zone in FEBLOCK unstructured format.
 
void read_fepoint_data (std::istream &in, const unsigned int zn)
 Read data for the zth zone in FEPOINT unstructured format.
 
std::string & version ()
 
bool & is_foreign ()
 
std::string & title ()
 
void set_n_vars (const unsigned int nv)
 
std::string & var_name (const unsigned int v)
 
unsigned intvar_type (const unsigned int v)
 
void set_n_zones (const unsigned int nz)
 
unsigned intzone_type (const unsigned int z)
 
std::string & zone_name (const unsigned int z)
 
unsigned intzone_pack (const unsigned int z)
 
unsigned intimax (const unsigned int z)
 
unsigned intjmax (const unsigned int z)
 
unsigned intkmax (const unsigned int z)
 

Private Attributes

const bool _verbose
 Verbosity.
 
std::string _version
 The Tecplot Version number string.
 
bool _is_foreign
 Is the data foreign?
 
std::string _title
 The Tecplot data set title.
 
unsigned int _n_vars
 The number of variables in the data set.
 
std::vector< std::string > _var_names
 The name for each variable.
 
std::vector< unsigned int_var_types
 The type of each variable.
 
unsigned int _n_zones
 The number of zones.
 
std::vector< unsigned int_zone_types
 The type of each zone.
 
std::vector< std::string > _zone_names
 The name of each zone.
 
std::vector< unsigned int_zone_pack
 The data packing for each zone (new version only)
 
std::vector< unsigned int_imax
 The (imax,jmax,kmax) value for each zone.
 
std::vector< unsigned int_jmax
 
std::vector< unsigned int_kmax
 
std::vector< std::vector< std::vector< float > > > _data
 Vector to hold the data.
 
std::vector< std::vector< int > > _conn
 Vectors to hold the connectivity for each zone (only for unstructured files).
 
char buf [512]
 Scratch data & relevant sizes.
 

Detailed Description

This class will read a binary .plt file.

These types of files are for use with Amtec's Tecplot visualization package.

Author
Benjamin S. Kirk
Date
2004

Definition at line 43 of file plt_loader.h.

Member Enumeration Documentation

◆ DataType

Enum defining the data type of each variable.

Enumerator
FLOAT 
DOUBLE 
LONGINT 
SHORTINT 
BYTE 
BIT 

Definition at line 136 of file plt_loader.h.

◆ FEType

Enum defining the finite element types.

Enumerator
TRI 
QUAD 
TET 
HEX 

Definition at line 146 of file plt_loader.h.

◆ NewZoneType

Enum defining the zone type in the Tecplot binary file, for use with the new .plt format.

Enumerator
ORDERED 
FELINESEG 
FETRIANGLE 
FEQUADRILATERAL 
FETETRAHEDRON 
FEBRICK 

Definition at line 126 of file plt_loader.h.

◆ OldZoneType

Enum defining the zone type in the Tecplot binary file, for use with the old .plt format.

Enumerator
BLOCK 
POINT 
FEBLOCK 
FEPOINT 

Definition at line 117 of file plt_loader.h.

Constructor & Destructor Documentation

◆ PltLoader() [1/2]

libMesh::PltLoader::PltLoader ( const bool  v = false)
inline

Constructor.

Initializes data.

Definition at line 449 of file plt_loader.h.

449 :
450 _verbose (v),
451 _is_foreign (false),
452 _n_vars (0),
453 _n_zones (0)
454{
455}
const bool _verbose
Verbosity.
Definition plt_loader.h:367
bool _is_foreign
Is the data foreign?
Definition plt_loader.h:377
unsigned int _n_vars
The number of variables in the data set.
Definition plt_loader.h:387
unsigned int _n_zones
The number of zones.
Definition plt_loader.h:403

◆ PltLoader() [2/2]

libMesh::PltLoader::PltLoader ( const std::string &  name,
const bool  v = false 
)
inline

Constructor.

Reads the file specified by name.

Definition at line 460 of file plt_loader.h.

460 :
461 _verbose (v),
462 _is_foreign (false),
463 _n_vars (0),
464 _n_zones (0)
465{
466 this->read (name);
467}
void read(const std::string &name)
Reads the .plt file specified by name.

References read().

◆ ~PltLoader()

libMesh::PltLoader::~PltLoader ( )
inline

Destructor.

Definition at line 472 of file plt_loader.h.

473{
474}

Member Function Documentation

◆ clear()

void libMesh::PltLoader::clear ( )

Clear all data and return to a pristine state.

Definition at line 37 of file plt_loader.C.

38{
39 // clear vectors & strings. Using .erase() for strings instead of .clear()
40 // since GCC 2.95.3 does not support .clear().
41 _version.erase();
42 _title.erase();
43
44 _var_names.clear();
45 _var_types.clear();
46 _zone_types.clear();
47 _zone_names.clear();
48 _zone_pack.clear();
49 _imax.clear();
50 _jmax.clear();
51 _kmax.clear();
52 _data.clear();
53 _conn.clear();
54
55 // reinitialize
56 _is_foreign = false;
57 _n_vars = 0;
58 _n_zones = 0;
59}
std::vector< unsigned int > _zone_pack
The data packing for each zone (new version only)
Definition plt_loader.h:418
std::vector< std::string > _zone_names
The name of each zone.
Definition plt_loader.h:413
std::vector< unsigned int > _kmax
Definition plt_loader.h:425
std::vector< std::vector< int > > _conn
Vectors to hold the connectivity for each zone (only for unstructured files).
Definition plt_loader.h:436
std::vector< unsigned int > _jmax
Definition plt_loader.h:424
std::string _title
The Tecplot data set title.
Definition plt_loader.h:382
std::vector< unsigned int > _zone_types
The type of each zone.
Definition plt_loader.h:408
std::string _version
The Tecplot Version number string.
Definition plt_loader.h:372
std::vector< std::string > _var_names
The name for each variable.
Definition plt_loader.h:392
std::vector< unsigned int > _var_types
The type of each variable.
Definition plt_loader.h:398
std::vector< std::vector< std::vector< float > > > _data
Vector to hold the data.
Definition plt_loader.h:430
std::vector< unsigned int > _imax
The (imax,jmax,kmax) value for each zone.
Definition plt_loader.h:423

References _conn, _data, _imax, _is_foreign, _jmax, _kmax, _n_vars, _n_zones, _title, _var_names, _var_types, _version, _zone_names, _zone_pack, and _zone_types.

◆ elem_type()

PltLoader::FEType libMesh::PltLoader::elem_type ( const unsigned int  z) const
inline
Returns
The element type for the zth zone (for unstructured meshes).

Definition at line 691 of file plt_loader.h.

692{
693 libmesh_assert_less (z, this->n_zones());
694
695 // Only for unstructured zones!
696 libmesh_assert_greater (this->zone_type(z), 1);
697
698 return static_cast<FEType>(this->kmax(z));
699}
unsigned int n_zones() const
Definition plt_loader.h:195
unsigned int kmax(const unsigned int z) const
Definition plt_loader.h:643
unsigned int zone_type(const unsigned int z) const
Definition plt_loader.h:527
FEType
Enum defining the finite element types.
Definition plt_loader.h:146

References kmax(), n_zones(), and zone_type().

◆ get_data()

const std::vector< std::vector< std::vector< float > > > & libMesh::PltLoader::get_data ( ) const
inline
Returns
A reference to the data read from the file

Definition at line 704 of file plt_loader.h.

705{
706 return _data;
707}

References _data.

◆ imax() [1/2]

unsigned int & libMesh::PltLoader::imax ( const unsigned int  z)
inlineprivate
Returns
imax for zone z.

Definition at line 610 of file plt_loader.h.

611{
612 libmesh_assert_less (z, this->n_zones());
613 libmesh_assert_equal_to (_imax.size(), this->n_zones());
614
615 return _imax[z];
616}

References _imax, and n_zones().

◆ imax() [2/2]

unsigned int libMesh::PltLoader::imax ( const unsigned int  z) const
inline
Returns
imax for zone z.

Definition at line 599 of file plt_loader.h.

600{
601 libmesh_assert_less (z, this->n_zones());
602 libmesh_assert_equal_to (_imax.size(), this->n_zones());
603
604 return _imax[z];
605}

References _imax, and n_zones().

Referenced by n_nodes(), read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), read_point_data(), and write_dat().

◆ is_foreign() [1/2]

bool & libMesh::PltLoader::is_foreign ( )
inlineprivate
Returns
true if the binary type of the file is different than the machine that is reading it. If this is the case we must perform an endian-swap on all input data.

Definition at line 302 of file plt_loader.h.

302{ return _is_foreign; }

References _is_foreign.

◆ is_foreign() [2/2]

bool libMesh::PltLoader::is_foreign ( ) const
inline
Returns
true if the binary type of the file is different than the machine that is reading it. If this is the case we must perform an endian-swap on all input data.

Definition at line 170 of file plt_loader.h.

170{ return _is_foreign; }

References _is_foreign.

Referenced by read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), and read_point_data().

◆ jmax() [1/2]

unsigned int & libMesh::PltLoader::jmax ( const unsigned int  z)
inlineprivate
Returns
jmax for zone z.

Definition at line 632 of file plt_loader.h.

633{
634 libmesh_assert_less (z, this->n_zones());
635 libmesh_assert_equal_to (_jmax.size(), this->n_zones());
636
637 return _jmax[z];
638}

References _jmax, and n_zones().

◆ jmax() [2/2]

unsigned int libMesh::PltLoader::jmax ( const unsigned int  z) const
inline
Returns
jmax for zone z.

Definition at line 621 of file plt_loader.h.

622{
623 libmesh_assert_less (z, this->n_zones());
624 libmesh_assert_equal_to (_jmax.size(), this->n_zones());
625
626 return _jmax[z];
627}

References _jmax, and n_zones().

Referenced by n_elem(), read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), read_point_data(), and write_dat().

◆ kmax() [1/2]

unsigned int & libMesh::PltLoader::kmax ( const unsigned int  z)
inlineprivate
Returns
kmax for zone z.

Definition at line 654 of file plt_loader.h.

655{
656 libmesh_assert_less (z, this->n_zones());
657 libmesh_assert_equal_to (_kmax.size(), this->n_zones());
658
659 return _kmax[z];
660}

References _kmax, and n_zones().

◆ kmax() [2/2]

unsigned int libMesh::PltLoader::kmax ( const unsigned int  z) const
inline
Returns
kmax for zone z.

Definition at line 643 of file plt_loader.h.

644{
645 libmesh_assert_less (z, this->n_zones());
646 libmesh_assert_equal_to (_kmax.size(), this->n_zones());
647
648 return _kmax[z];
649}

References _kmax, and n_zones().

Referenced by elem_type(), read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), read_point_data(), and write_dat().

◆ n_elem()

unsigned int libMesh::PltLoader::n_elem ( const unsigned int  z) const
inline
Returns
The number of elements in the mesh (for unstructured meshes).

Definition at line 678 of file plt_loader.h.

679{
680 libmesh_assert_less (z, this->n_zones());
681
682 // Only for unstructured zones!
683 libmesh_assert_greater (this->zone_type(z), 1);
684
685 return this->jmax(z);
686}
unsigned int jmax(const unsigned int z) const
Definition plt_loader.h:621

References jmax(), n_zones(), and zone_type().

Referenced by read_header().

◆ n_nodes()

unsigned int libMesh::PltLoader::n_nodes ( const unsigned int  z) const
inline
Returns
The number of nodes in the mesh (for unstructured meshes).

Definition at line 665 of file plt_loader.h.

666{
667 libmesh_assert_less (z, this->n_zones());
668
669 // Only for unstructured zones!
670 libmesh_assert_greater (this->zone_type(z), 1);
671
672 return this->imax(z);
673}
unsigned int imax(const unsigned int z) const
Definition plt_loader.h:599

References imax(), n_zones(), and zone_type().

◆ n_vars()

unsigned int libMesh::PltLoader::n_vars ( ) const
inline
Returns
The number of variables in the data set.

Definition at line 180 of file plt_loader.h.

180{ return _n_vars; }

References _n_vars.

Referenced by read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), read_point_data(), set_n_vars(), set_n_zones(), var_name(), var_name(), var_type(), var_type(), and write_dat().

◆ n_zones()

unsigned int libMesh::PltLoader::n_zones ( ) const
inline

◆ read()

void libMesh::PltLoader::read ( const std::string &  name)

Reads the .plt file specified by name.

Definition at line 35 of file plt_loader_read.C.

36{
37 std::ifstream in (name.c_str(), std::ios::in|std::ios::binary);
38
39 libmesh_error_msg_if(!in.good(), "Error reading input file " << name);
40
41 if (this->verbose())
42 libMesh::out << std::endl
43 << "Reading input file " << name
44 << std::endl
45 << "-------------------------------------------------------------------------"
46 << std::endl;
47
48 this->read_header (in);
49 this->read_data (in);
50
51 if (this->verbose())
52 libMesh::out << std::endl
53 << "-------------------------------------------------------------------------"
54 << std::endl;
55
56}
void read_data(std::istream &in)
Read data from the binary file.
bool verbose() const
Definition plt_loader.h:70
void read_header(std::istream &in)
Read the header of the binary file.
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
OStreamProxy out

References libMesh::out, read_data(), read_header(), and verbose().

Referenced by PltLoader().

◆ read_block_data()

void libMesh::PltLoader::read_block_data ( std::istream &  in,
const unsigned int  zn 
)
private

Read data for the zth zone in BLOCK structured format.

Definition at line 821 of file plt_loader_read.C.

822{
823 libmesh_assert (in.good());
824
825
826 // A byte-reverser in case the data is foreign
827 Utility::ReverseBytes rb(this->is_foreign());
828
829
830 for (unsigned int var=0; var<this->n_vars(); var++)
831 {
832
833 switch (this->var_type(var))
834 {
835
836 // Read a single-precision variable
837 case FLOAT:
838 {
839 std::vector<float> & data = _data[zone][var];
840
841 data.clear();
842 data.resize (this->imax(zone)*
843 this->jmax(zone)*
844 this->kmax(zone));
845
846 in.read (reinterpret_cast<char *>(data.data()), LIBMESH_SIZEOF_FLOAT*data.size());
847
848 for (std::size_t i=0; i<data.size(); i++)
849 rb(data[i]);
850
851 break;
852 }
853
854 // Read a double-precision variable
855 case DOUBLE:
856 {
857 std::vector<double> ddata;
858 std::vector<float> & data = _data[zone][var];
859
860 data.clear();
861 data.resize (this->imax(zone)*
862 this->jmax(zone)*
863 this->kmax(zone));
864
865 ddata.resize (this->imax(zone)*
866 this->jmax(zone)*
867 this->kmax(zone));
868
869 in.read (reinterpret_cast<char *>(ddata.data()), LIBMESH_SIZEOF_DOUBLE*ddata.size());
870
871 for (std::size_t i=0; i<data.size(); i++)
872 data[i] = float(rb(ddata[i]));
873
874 break;
875 }
876
877 default:
878 libmesh_error_msg("ERROR: Unsupported data type: " << this->var_type(var));
879 }
880 }
881}
unsigned int var_type(const unsigned int v) const
Definition plt_loader.h:503
bool is_foreign() const
Definition plt_loader.h:170
unsigned int n_vars() const
Definition plt_loader.h:180
libmesh_assert(ctx)

References _data, DOUBLE, FLOAT, imax(), is_foreign(), jmax(), kmax(), libMesh::libmesh_assert(), n_vars(), and var_type().

Referenced by read_data().

◆ read_data()

void libMesh::PltLoader::read_data ( std::istream &  in)
private

Read data from the binary file.

Definition at line 593 of file plt_loader_read.C.

594{
595 libmesh_assert (in.good());
596
597 // A byte-reverser in case the data is foreign
598 Utility::ReverseBytes rb(this->is_foreign());
599
600 //----------------------------------------------------
601 // Read the TECPLOT data for each zone
602 if (this->verbose())
603 {
604 libMesh::out << "Reading Zones";
606 }
607
608
609 for (unsigned int zone=0; zone<this->n_zones(); zone++)
610 {
611 if (this->verbose())
612 {
613 libMesh::out << ".";
615 }
616
617
618 //----------------------------------------------------
619 // Read plt files written by older versions of Tecplot
620 if (Utility::contains(this->version(), "V7"))
621 {
622 float f = 0.;
623
624 // Find the next Zone marker.
625 do
626 {
627 f = 0.;
628 in.read (buf, LIBMESH_SIZEOF_FLOAT);
629 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
630 rb(f);
631 }
632 while ((f != 299.) && in.good());
633
634 // Did we overrun the file?
635 libmesh_error_msg_if(!in.good(), "ERROR: Unexpected end-of-file!");
636
637 // Get the number of repeated vars.
638 unsigned int n_rep_vars=0;
639 std::vector<int> rep_vars;
640
641 {
642 in.read (buf, LIBMESH_SIZEOF_INT);
643 std::memcpy (&n_rep_vars, buf, LIBMESH_SIZEOF_INT);
644 rb(n_rep_vars);
645
646 rep_vars.resize (n_rep_vars);
647
648 // Get the repeated variables number.
649 for (unsigned int v=0; v<n_rep_vars; v++)
650 {
651 libmesh_error_msg("ERROR: I don't understand repeated variables yet!");
652
653 in.read (buf, LIBMESH_SIZEOF_INT);
654 std::memcpy (&rep_vars[v], buf, LIBMESH_SIZEOF_INT);
655 rb(rep_vars[v]);
656 }
657 }
658
659 // Get the variable data type
660 //libMesh::out << "var_types=";
661 for (unsigned int v=0; v<this->n_vars(); v++)
662 {
663 in.read (buf, LIBMESH_SIZEOF_INT);
664 std::memcpy (&this->var_type(v), buf, LIBMESH_SIZEOF_INT);
665 rb(this->var_type(v));
666
667 //libMesh::out << this->var_type(v) << " ";
668 }
669 //libMesh::out << std::endl;
670
671
672
673 // Read the data.
674 switch (this->zone_type(zone) )
675 {
676 // Block-based data. Structured meshes.
677 case BLOCK:
678 {
679 this->read_block_data (in, zone);
680 break;
681 }
682
683 // Point-based data. Structured meshes.
684 case POINT:
685 {
686 this->read_point_data (in, zone);
687 break;
688 }
689
690 // FE block data. Unstructured meshes.
691 case FEBLOCK:
692 {
693 this->read_feblock_data (in, zone);
694
695 if (this->verbose())
696
697 libMesh::out << "Zone " << zone << ":" << std::endl
698 << " nnodes =" << this->imax(zone) << std::endl
699 << " nelem =" << this->jmax(zone) << std::endl
700 << " elem_type=" << this->kmax(zone) << std::endl
701 << std::endl;
702 break;
703 }
704
705 // FE point data. Unstructured meshes.
706 case FEPOINT:
707 {
708 this->read_fepoint_data (in, zone);
709 break;
710 }
711
712 default:
713 libmesh_error_msg("ERROR: Unsupported Zone type: " << this->zone_type(zone));
714 } // end switch on zone type
715 }
716
717
718 //----------------------------------------------------
719 // Read plt files written by newer versions of Tecplot
720 else if (Utility::contains(this->version(), "V1"))
721 {
722 float f = 0.;
723
724 // Find the next Zone marker.
725 do
726 {
727 f = 0.;
728 in.read (buf, LIBMESH_SIZEOF_FLOAT);
729 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
730 rb(f);
731 }
732 while ((f != 299.) && in.good());
733
734 // Did we overrun the file?
735 libmesh_error_msg_if(!in.good(), "ERROR: Unexpected end-of-file!");
736
737 // Get the variable data type
738 for (unsigned int v=0; v<this->n_vars(); v++)
739 {
740 in.read (buf, LIBMESH_SIZEOF_INT);
741 std::memcpy (&this->var_type(v), buf, LIBMESH_SIZEOF_INT);
742 rb(this->var_type(v));
743
744 //libMesh::out << this->var_type(v) << " ";
745 }
746
747 // Get the variable sharing flag
748 {
749 int vs=0;
750 int sv=0;
751
752 in.read (buf, LIBMESH_SIZEOF_INT);
753 std::memcpy (&vs, buf, LIBMESH_SIZEOF_INT);
754 rb(vs);
755
756 if (vs)
757 {
758 for (unsigned int v=0; v<this->n_vars(); v++)
759 {
760 in.read (buf, LIBMESH_SIZEOF_INT);
761 std::memcpy (&sv, buf, LIBMESH_SIZEOF_INT);
762 rb(sv);
763
764 libmesh_error_msg_if(sv != -1, "ERROR: I don't understand variable sharing!");
765 }
766 }
767 }
768
769 // Get zone to share connectivity with
770 {
771 int sc=0;
772 in.read (buf, LIBMESH_SIZEOF_INT);
773 std::memcpy (&sc, buf, LIBMESH_SIZEOF_INT);
774 rb(sc);
775
776 libmesh_assert_equal_to (sc, -1);
777 }
778
779
780 // Read the data.
781 if (this->zone_type(zone) == ORDERED)
782 {
783 // Block-based data. Structured meshes.
784 if (this->zone_pack(zone) == 0)
785 this->read_block_data (in, zone);
786
787 // Point-based data. Structured meshes.
788 else if (this->zone_pack(zone) == 1)
789 this->read_point_data (in, zone);
790
791 else
792 libmesh_error_msg("Unrecognized zone_pack(zone) = " << this->zone_pack(zone));
793 }
794 else
795 {
796 // Block-based data. Unstructured meshes.
797 if (this->zone_pack(zone) == 0)
798 this->read_feblock_data (in, zone);
799
800 // Point-based data. Unstructured meshes.
801 else if (this->zone_pack(zone) == 1)
802 this->read_fepoint_data (in, zone);
803
804 else
805 libmesh_error_msg("Unrecognized zone_pack(zone) = " << this->zone_pack(zone));
806 }
807 }
808
809
810
811 //----------------------------------------------------
812 // Unrecognized Tecplot Version!
813 else
814 libmesh_error_msg("ERROR: This plot file was written by an unrecognized version of Tecplot!:\n" << this->version());
815
816 } // end loop on zones
817}
BasicOStreamProxy & flush()
Flush the associated stream buffer.
void read_point_data(std::istream &in, const unsigned int zn)
Read data for the zth zone in POINT structured format.
void read_feblock_data(std::istream &in, const unsigned int zn)
Read data for the zth zone in FEBLOCK unstructured format.
unsigned int zone_pack(const unsigned int z) const
Definition plt_loader.h:575
const std::string & version() const
Definition plt_loader.h:163
void read_fepoint_data(std::istream &in, const unsigned int zn)
Read data for the zth zone in FEPOINT unstructured format.
void read_block_data(std::istream &in, const unsigned int zn)
Read data for the zth zone in BLOCK structured format.
char buf[512]
Scratch data & relevant sizes.
Definition plt_loader.h:441
bool contains(std::string_view superstring, std::string_view substring)
Look for a substring within a string.
Definition utility.C:205

References BLOCK, buf, libMesh::Utility::contains(), FEBLOCK, FEPOINT, libMesh::BasicOStreamProxy< charT, traits >::flush(), imax(), is_foreign(), jmax(), kmax(), libMesh::libmesh_assert(), n_vars(), n_zones(), ORDERED, libMesh::out, POINT, read_block_data(), read_feblock_data(), read_fepoint_data(), read_point_data(), var_type(), verbose(), version(), zone_pack(), and zone_type().

Referenced by read().

◆ read_feblock_data()

void libMesh::PltLoader::read_feblock_data ( std::istream &  in,
const unsigned int  zn 
)
private

Read data for the zth zone in FEBLOCK unstructured format.

Definition at line 938 of file plt_loader_read.C.

939{
940 libmesh_assert (in.good());
941
942 // A byte-reverser in case the data is foreign
943 Utility::ReverseBytes rb(this->is_foreign());
944
945 // Read the variable values at each node.
946 for (unsigned int var=0; var<this->n_vars(); var++)
947 {
948 switch (this->var_type(var))
949 {
950
951 // Read a single-precision variable
952 case FLOAT:
953 {
954 std::vector<float> & data = _data[zone][var];
955
956 data.clear();
957 data.resize (this->imax(zone));
958
959 in.read (reinterpret_cast<char *>(data.data()), LIBMESH_SIZEOF_FLOAT*data.size());
960
961 for (std::size_t i=0; i<data.size(); i++)
962 rb(data[i]);
963
964 break;
965 }
966
967 // Read a double-precision variable
968 case DOUBLE:
969 {
970 std::vector<double> ddata;
971 std::vector<float> & data = _data[zone][var];
972
973 data.clear();
974 data.resize (this->imax(zone));
975 ddata.resize (this->imax(zone));
976
977 in.read (reinterpret_cast<char *>(ddata.data()), LIBMESH_SIZEOF_DOUBLE*ddata.size());
978
979 for (std::size_t i=0; i<data.size(); i++)
980 data[i] = float(rb(ddata[i]));
981
982 break;
983 }
984
985 default:
986 libmesh_error_msg("ERROR: Unsupported data type: " << this->var_type(var));
987 }
988 }
989
990 // Read the connectivity
991 {
992 // Get the connectivity repetition flag
993 int rep=0;
994 in.read ((char *) &rep, LIBMESH_SIZEOF_INT);
995 rb(rep);
996
997 libmesh_error_msg_if(rep == 1 && this->n_zones() > 1, "ERROR: Repeated connectivity not supported!");
998
999 // Read the connectivity
1000 libmesh_assert_less (zone, _conn.size());
1001 libmesh_assert_less (this->kmax(zone), 4);
1002
1003 _conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]);
1004
1005 in.read (reinterpret_cast<char *>(_conn[zone].data()), LIBMESH_SIZEOF_INT*_conn[zone].size());
1006
1007 for (std::size_t i=0; i<_conn[zone].size(); i++)
1008 rb(_conn[zone][i]);
1009 }
1010}
static const unsigned int NNodes[4]
Enum defining the number of nodes for each element type.
Definition plt_loader.h:250

References _conn, _data, DOUBLE, FLOAT, imax(), is_foreign(), jmax(), kmax(), libMesh::libmesh_assert(), n_vars(), n_zones(), NNodes, and var_type().

Referenced by read_data().

◆ read_fepoint_data()

void libMesh::PltLoader::read_fepoint_data ( std::istream &  in,
const unsigned int  zn 
)
private

Read data for the zth zone in FEPOINT unstructured format.

Definition at line 1014 of file plt_loader_read.C.

1015{
1016 libmesh_assert (in.good());
1017
1018 // A byte-reverser in case the data is foreign
1019 Utility::ReverseBytes rb(this->is_foreign());
1020
1021 // First allocate space
1022 for (unsigned int var=0; var<this->n_vars(); var++)
1023 {
1024 std::vector<float> & data = _data[zone][var];
1025
1026 data.clear();
1027 data.reserve (this->imax(zone));
1028 }
1029
1030
1031 for (unsigned int i=0; i<this->imax(zone); i++)
1032 for (unsigned int var=0; var<this->n_vars(); var++)
1033 if (this->var_type(var) == FLOAT)
1034 {
1035 float f = 0.;
1036
1037 libmesh_assert (in.good());
1038
1039 in.read (buf, LIBMESH_SIZEOF_FLOAT);
1040 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
1041 rb(f);
1042
1043 _data[zone][var].push_back(f);
1044 }
1045 else if (this->var_type(var) == DOUBLE)
1046 {
1047 double d = 0.;
1048
1049 libmesh_assert (in.good());
1050
1051 in.read (buf, LIBMESH_SIZEOF_DOUBLE);
1052 std::memcpy (&d, buf, LIBMESH_SIZEOF_DOUBLE);
1053 rb(d);
1054
1055 _data[zone][var].push_back(float(d));
1056 }
1057 else
1058 libmesh_error_msg("ERROR: unsupported data type: " << this->var_type(var));
1059
1060 // Read the connectivity
1061 {
1062 // Get the connectivity repetition flag
1063 int rep=0;
1064
1065 in.read ((char *) &rep, LIBMESH_SIZEOF_INT);
1066 rb(rep);
1067
1068 libmesh_error_msg_if(rep == 1, "ERROR: Repeated connectivity not supported!");
1069
1070 // Read the connectivity
1071 libmesh_assert_less (zone, _conn.size());
1072 libmesh_assert_less (this->kmax(zone), 4);
1073
1074 _conn[zone].resize (this->jmax(zone)*NNodes[this->kmax(zone)]);
1075
1076 in.read (reinterpret_cast<char *>(_conn[zone].data()), LIBMESH_SIZEOF_INT*_conn[zone].size());
1077
1078 for (std::size_t i=0; i<_conn[zone].size(); i++)
1079 rb(_conn[zone][i]);
1080 }
1081}

References _conn, _data, buf, DOUBLE, FLOAT, imax(), is_foreign(), jmax(), kmax(), libMesh::libmesh_assert(), n_vars(), NNodes, and var_type().

Referenced by read_data().

◆ read_header()

void libMesh::PltLoader::read_header ( std::istream &  in)
private

Read the header of the binary file.

Definition at line 60 of file plt_loader_read.C.

61{
62 libmesh_assert (in.good());
63
64 //----------------------------------------------------
65 // Read the TECPLOT header
66
67 // Read the version number
68 {
69 in.read (buf, 8);
70
71 this->version().clear();
72
73 for (unsigned int i=0; i<8; i++)
74 this->version() += buf[i];
75
76 if (this->verbose())
77 libMesh::out << "Tecplot Version: "
78 << this->version()
79 << std::endl;
80 }
81
82
83 //----------------------------------------------------
84 // Read plt files written by older versions of Tecplot
85 if (Utility::contains(this->version(), "V7"))
86 {
87 if (this->verbose())
88 libMesh::out << "Reading legacy .plt format (<= v9) ..."
89 << std::endl;
90
91 // Read the value of 1 to determine byte ordering
92 {
93 int one = 0;
94 in.read (buf, LIBMESH_SIZEOF_INT);
95 std::memcpy (&one, buf, LIBMESH_SIZEOF_INT);
96
97 if (one != 1)
98 {
99 if (this->verbose())
100 libMesh::out << "Tecplot data is Foreign!"
101 << std::endl;
102 this->is_foreign() = true;
103
104 // Make sure one reversed is one
105 Utility::ReverseBytes rb(this->is_foreign());
106 libmesh_assert_equal_to (rb(one), 1);
107 }
108 }
109
110 // A byte-reverser in case the data is foreign
111 Utility::ReverseBytes rb(this->is_foreign());
112
113 // Read the title
114 {
115 int i=0;
116
117 this->title().clear();
118
119 do
120 {
121 in.read (buf, LIBMESH_SIZEOF_INT);
122 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
123 rb(i);
124
125 // Don't add trailing \0
126 if (i)
127 this->title() += static_cast<char>(i);
128 }
129 while (i);
130 }
131
132 // Read the number of variables in the data set
133 {
134 int nv;
135 in.read (buf, LIBMESH_SIZEOF_INT);
136 std::memcpy (&nv, buf, LIBMESH_SIZEOF_INT);
137 rb(nv);
138
139 this->set_n_vars (nv);
140 }
141
142 // Read the variable names
143 for (unsigned int v=0; v<this->n_vars(); v++)
144 {
145 int i=0;
146
147 this->var_name(v).clear();
148
149 do
150 {
151 in.read (buf, LIBMESH_SIZEOF_INT);
152 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
153 rb(i);
154
155 // Don't add trailing \0
156 if (i)
157 this->var_name(v) += static_cast<char>(i);
158 }
159 while (i);
160 }
161
162
163
164 // Read zones from the header.
165 // Continue reading until the end-of-header
166 // marker (357.) is found.
167 int nz=0;
168 std::vector<std::string> zname;
169 std::vector<int> ztype, zimax, zjmax, zkmax;
170
171 {
172 float f=0.;
173
174 do
175 {
176 // find the next Zone marker
177 do
178 {
179 f = 0.;
180 in.read (buf, LIBMESH_SIZEOF_FLOAT);
181 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
182 rb(f);
183 }
184 while ((f != 299.) &&
185 (f != 357.) &&
186 in.good());
187
188
189 // Did we overrun the file?
190 libmesh_error_msg_if(!in.good(), "ERROR: Unexpected end-of-file!");
191
192 // Found a Zone marker
193 if (f == 299.)
194 {
195 // Increment the Zone counter
196 nz++;
197
198 // Read the zone name
199 {
200 int i=0;
201 std::string name;
202
203 do
204 {
205 in.read (buf, LIBMESH_SIZEOF_INT);
206 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
207 rb(i);
208
209 // Don't add trailing \0
210 if (i)
211 name += static_cast<char>(i);
212 }
213 while (i);
214
215 zname.push_back(name);
216 }
217
218 // Read the zone format
219 {
220 int zt;
221 in.read (buf, LIBMESH_SIZEOF_INT);
222 std::memcpy (&zt, buf, LIBMESH_SIZEOF_INT);
223 rb(zt);
224
225 ztype.push_back(zt);
226 //libMesh::out << "zone type=" << ztype.back() << std::endl;
227 }
228
229 // Read the zone color
230 {
231 int zc=0;
232
233 in.read (buf, LIBMESH_SIZEOF_INT);
234 std::memcpy (&zc, buf, LIBMESH_SIZEOF_INT);
235 rb(zc);
236
237 //libMesh::out << "zone color=" << zc << std::endl;
238 }
239
240 // Read in the block dimensions
241 {
242 int
243 i_max=0,
244 j_max=0,
245 k_max=0;
246
247 in.read (buf, LIBMESH_SIZEOF_INT);
248 std::memcpy (&i_max, buf, LIBMESH_SIZEOF_INT);
249 rb(i_max);
250
251 in.read (buf, LIBMESH_SIZEOF_INT);
252 std::memcpy (&j_max, buf, LIBMESH_SIZEOF_INT);
253 rb(j_max);
254
255 in.read (buf, LIBMESH_SIZEOF_INT);
256 std::memcpy (&k_max, buf, LIBMESH_SIZEOF_INT);
257 rb(k_max);
258
259 zimax.push_back (i_max);
260 zjmax.push_back (j_max);
261 zkmax.push_back (k_max);
262 }
263 } // else if (f == 299.)
264 }
265 while ((f != 357.) && in.good());
266 }
267
268 // Set the header data
269 this->set_n_zones (nz);
270
271 for (unsigned int z=0; z<this->n_zones(); z++)
272 {
273 this->zone_type(z) = ztype[z];
274 this->zone_name(z) = zname[z];
275 this->imax(z) = zimax[z];
276 this->jmax(z) = zjmax[z];
277 this->kmax(z) = zkmax[z];
278 }
279 }
280
281
282 //----------------------------------------------------
283 // Read plt files written by newer versions of Tecplot
284 else if (Utility::contains(this->version(), "V1"))
285 {
286 if (this->verbose())
287 libMesh::out << "Reading new .plt format (>= v10)..."
288 << std::endl;
289
290 // Read the value of 1 to determine byte ordering
291 {
292 int one = 0;
293
294 in.read (buf, LIBMESH_SIZEOF_INT);
295 std::memcpy (&one, buf, LIBMESH_SIZEOF_INT);
296
297 if (one != 1)
298 {
299 if (this->verbose())
300 libMesh::err << "Tecplot data is Foreign!"
301 << std::endl;
302 this->is_foreign() = true;
303
304 // Make sure one reversed is one
305 Utility::ReverseBytes rb(this->is_foreign());
306 libmesh_assert_equal_to (rb(one), 1);
307 }
308 }
309
310 // A byte-reverser in case the data is foreign
311 Utility::ReverseBytes rb(this->is_foreign());
312
313 // Read the title
314 {
315 int i=0;
316
317 this->title().clear();
318 do
319 {
320 in.read (buf, LIBMESH_SIZEOF_INT);
321 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
322 rb(i);
323
324 // Don't add trailing \0
325 if (i)
326 this->title() += static_cast<char>(i);
327 }
328 while (i);
329 }
330
331 // Read the number of variables in the data set
332 {
333 int nv;
334 in.read (buf, LIBMESH_SIZEOF_INT);
335 std::memcpy (&nv, buf, LIBMESH_SIZEOF_INT);
336 rb(nv);
337
338 this->set_n_vars (nv);
339 }
340
341 // Read the variable names
342 for (unsigned int v=0; v<this->n_vars(); v++)
343 {
344 int i=0;
345
346 this->var_name(v).clear();
347
348 do
349 {
350 in.read (buf, LIBMESH_SIZEOF_INT);
351 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
352 rb(i);
353
354 // Don't add trailing \0
355 if (i)
356 this->var_name(v) += static_cast<char>(i);
357 }
358 while (i);
359 }
360
361
362
363 // Read zones from the header.
364 // Continue reading until the end-of-header
365 // marker (357.) is found.
366 int nz=0;
367 std::vector<std::string> zname;
368 std::vector<int> zpack, ztype, zimax, zjmax, zkmax;
369
370 {
371 float f=0.;
372
373 do
374 {
375 // find the next Zone marker
376 do
377 {
378 f = 0.;
379 in.read (buf, LIBMESH_SIZEOF_FLOAT);
380 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
381 rb(f);
382 }
383 while ((f != 299.) &&
384 (f != 357.) &&
385 in.good());
386
387 // Did we overrun the file?
388 libmesh_error_msg_if(!in.good(), "ERROR: Unexpected end-of-file!");
389
390 // Found a Zone marker
391 if (f == 299.)
392 {
393 // Increment the Zone counter
394 nz++;
395
396 // Read the zone name
397 {
398 int i=0;
399 std::string name;
400
401 do
402 {
403 in.read (buf, LIBMESH_SIZEOF_INT);
404 std::memcpy (&i, buf, LIBMESH_SIZEOF_INT);
405 rb(i);
406
407 // Don't add trailing \0
408 if (i)
409 name += static_cast<char>(i);
410 }
411 while (i);
412
413 zname.push_back(name);
414 }
415
416 // Read the zone color
417 {
418 int zc=0;
419 in.read (buf, LIBMESH_SIZEOF_INT);
420 std::memcpy (&zc, buf, LIBMESH_SIZEOF_INT);
421 rb(zc);
422 }
423
424 // Read the zone format
425 {
426 int zt;
427 in.read (buf, LIBMESH_SIZEOF_INT);
428 std::memcpy (&zt, buf, LIBMESH_SIZEOF_INT);
429 rb(zt);
430
431 ztype.push_back(zt);
432 }
433
434 // Read the data packing flag
435 {
436 int dp=0;
437 in.read (buf, LIBMESH_SIZEOF_INT);
438 std::memcpy (&dp, buf, LIBMESH_SIZEOF_INT);
439 rb(dp);
440
441 zpack.push_back (dp);
442 }
443
444 // Will we specify the variable location?
445 {
446 int svl=0;
447 int vl=0;
448 in.read (buf, LIBMESH_SIZEOF_INT);
449 std::memcpy (&svl, buf, LIBMESH_SIZEOF_INT);
450 rb(svl);
451
452 if (svl)
453 for (unsigned int v=0; v<this->n_vars(); v++)
454 {
455 in.read (buf, LIBMESH_SIZEOF_INT);
456 std::memcpy (&vl, buf, LIBMESH_SIZEOF_INT);
457 rb(vl);
458 libmesh_assert_equal_to (vl, 0); // Only know about node-based data
459 // right now
460 }
461
462 }
463
464 // Get the number of user-defined face-neighbors
465 {
466 int fn=0;
467 in.read (buf, LIBMESH_SIZEOF_INT);
468 std::memcpy (&fn, buf, LIBMESH_SIZEOF_INT);
469 rb(fn);
470 }
471
472 // Read in the block dimensions
473 {
474 if (ztype.back() != ORDERED)
475 {
476 int np=0, ne=0;
477
478 in.read (buf, LIBMESH_SIZEOF_INT);
479 std::memcpy (&np, buf, LIBMESH_SIZEOF_INT);
480 rb(np);
481
482 in.read (buf, LIBMESH_SIZEOF_INT);
483 std::memcpy (&ne, buf, LIBMESH_SIZEOF_INT);
484 rb(ne);
485
486 zimax.push_back (np);
487 zjmax.push_back (ne);
488 zjmax.push_back (0);
489 }
490
491 int
492 i_max=0,
493 j_max=0,
494 k_max=0;
495
496 in.read (buf, LIBMESH_SIZEOF_INT);
497 std::memcpy (&i_max, buf, LIBMESH_SIZEOF_INT);
498 rb(i_max);
499
500 in.read (buf, LIBMESH_SIZEOF_INT);
501 std::memcpy (&j_max, buf, LIBMESH_SIZEOF_INT);
502 rb(j_max);
503
504 in.read (buf, LIBMESH_SIZEOF_INT);
505 std::memcpy (&k_max, buf, LIBMESH_SIZEOF_INT);
506 rb(k_max);
507
508 // These are only useful for ordered data. Otherwise
509 // we grabbed the relevant values above.
510 if (ztype.back() != ORDERED)
511 {
512 zimax.push_back (i_max);
513 zjmax.push_back (j_max);
514 zkmax.push_back (k_max);
515 }
516 }
517 } // else if (f == 299.)
518 }
519 while ((f != 357.) && in.good());
520 }
521
522 // Set the header data
523 this->set_n_zones (nz);
524
525 for (unsigned int z=0; z<this->n_zones(); z++)
526 {
527 this->zone_type(z) = ztype[z];
528 this->zone_name(z) = zname[z];
529 this->zone_pack(z) = zpack[z];
530 this->imax(z) = zimax[z];
531 this->jmax(z) = zjmax[z];
532 this->kmax(z) = zkmax[z];
533 }
534 }
535
536
537
538 //----------------------------------------------------
539 // Unrecognized Tecplot Version!
540 else
541 libmesh_error_msg("ERROR: This plot file was written by an unrecognized version of Tecplot!:\n" << this->version());
542
543
544
545
546
547
548
549
550 // Print the data to the screen.
551 if (this->verbose())
552 {
553 libMesh::out << "Tecplot Header: "
554 << this->title() << std::endl;
555
556 libMesh::out << "Variables: ";
557 for (unsigned int v=0; v<this->n_vars(); v++)
558 libMesh::out << "\"" << this->var_name (v) << "\"" << " ";
559 libMesh::out << std::endl;
560
561 libMesh::out << "Variable Types: ";
562 for (unsigned int v=0; v<this->n_vars(); v++)
563 libMesh::out << this->var_type (v) << " ";
564 libMesh::out << std::endl;
565
566 libMesh::out << "Zone Names: ";
567 for (unsigned int z=0; z<this->n_zones(); z++)
568 libMesh::out << "\"" << this->zone_name (z) << "\"" << " ";
569 libMesh::out << std::endl;
570
571 libMesh::out << "Zone Types: ";
572 for (unsigned int z=0; z<this->n_zones(); z++)
573 {
574 libMesh::out << this->zone_type (z) << " ";
575
576 if (this->zone_type (z) != ORDERED)
577 libMesh::out << "(" << this->n_nodes(z) << "," << this->n_elem(z) << ") ";
578 }
579 libMesh::out << std::endl;
580
581 libMesh::out << "Zone Dimensions: " << std::endl;
582 for (unsigned int z=0; z<this->n_zones(); z++)
583 libMesh::out << " ("
584 << this->imax(z) << ","
585 << this->jmax(z) << ","
586 << this->kmax(z) << ")"
587 << std::endl;
588 }
589}
const std::string & title() const
Definition plt_loader.h:175
const std::string & var_name(const unsigned int v) const
Definition plt_loader.h:479
const std::string & zone_name(const unsigned int z) const
Definition plt_loader.h:551
unsigned int n_elem(const unsigned int z) const
Definition plt_loader.h:678
void set_n_zones(const unsigned int nz)
Definition plt_loader.C:85
void set_n_vars(const unsigned int nv)
Definition plt_loader.C:63
OStreamProxy err
const dof_id_type n_nodes
Definition tecplot_io.C:67

References buf, libMesh::Utility::contains(), libMesh::err, imax(), is_foreign(), jmax(), kmax(), libMesh::libmesh_assert(), n_elem(), n_nodes, n_vars(), n_zones(), ORDERED, libMesh::out, set_n_vars(), set_n_zones(), title(), var_name(), var_type(), verbose(), version(), zone_name(), zone_pack(), and zone_type().

Referenced by read().

◆ read_point_data()

void libMesh::PltLoader::read_point_data ( std::istream &  in,
const unsigned int  zn 
)
private

Read data for the zth zone in POINT structured format.

Definition at line 885 of file plt_loader_read.C.

886{
887 libmesh_assert (in.good());
888
889 // A byte-reverser in case the data is foreign
890 Utility::ReverseBytes rb(this->is_foreign());
891
892 // First allocate space
893 for (unsigned int var=0; var<this->n_vars(); var++)
894 {
895 std::vector<float> & data = _data[zone][var];
896
897 data.clear();
898 data.reserve (this->imax(zone)*
899 this->jmax(zone)*
900 this->kmax(zone));
901 }
902
903
904 for (unsigned int k=0; k<this->kmax(zone); k++)
905 for (unsigned int j=0; j<this->jmax(zone); j++)
906 for (unsigned int i=0; i<this->imax(zone); i++)
907 for (unsigned int var=0; var<this->n_vars(); var++)
908 if (this->var_type(var) == FLOAT)
909 {
910 float f = 0.;
911
912 libmesh_assert (in.good());
913
914 in.read (buf, LIBMESH_SIZEOF_FLOAT);
915 std::memcpy (&f, buf, LIBMESH_SIZEOF_FLOAT);
916 rb(f);
917
918 _data[zone][var].push_back(f);
919 }
920 else if (this->var_type(var) == DOUBLE)
921 {
922 double d = 0.;
923
924 libmesh_assert (in.good());
925
926 in.read (buf, LIBMESH_SIZEOF_DOUBLE);
927 std::memcpy (&d, buf, LIBMESH_SIZEOF_DOUBLE);
928 rb(d);
929
930 _data[zone][var].push_back(float(d));
931 }
932 else
933 libmesh_error_msg("ERROR: unsupported data type: " << this->var_type(var));
934}

References _data, buf, DOUBLE, FLOAT, imax(), is_foreign(), jmax(), kmax(), libMesh::libmesh_assert(), n_vars(), and var_type().

Referenced by read_data().

◆ set_n_vars()

void libMesh::PltLoader::set_n_vars ( const unsigned int  nv)
private
Returns
The number of variables in the data set.

Definition at line 63 of file plt_loader.C.

64{
65 _n_vars = nv;
66
67 _var_types.resize (this->n_vars());
68 _var_names.resize (this->n_vars());
69
70 // Default to float data
71 std::fill (_var_types.begin(), _var_types.end(), 1);
72
73 // If the number of zones is set, resize the data.
74 if (this->n_zones())
75 {
76 _data.resize (this->n_zones());
77
78 for (auto z : make_range(this->n_zones()))
79 _data[z].resize (this->n_vars());
80 }
81}
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References _data, _n_vars, _var_names, _var_types, libMesh::make_range(), n_vars(), and n_zones().

Referenced by read_header().

◆ set_n_zones()

void libMesh::PltLoader::set_n_zones ( const unsigned int  nz)
private
Returns
The number of zones.

Definition at line 85 of file plt_loader.C.

86{
87 _n_zones = nz;
88
89 _zone_types.resize (this->n_zones());
90 _zone_names.resize (this->n_zones());
91 _zone_pack.resize (this->n_zones());
92
93 _imax.resize (this->n_zones());
94 _jmax.resize (this->n_zones());
95 _kmax.resize (this->n_zones());
96
97 _data.resize (this->n_zones());
98 _conn.resize (this->n_zones());
99
100 // If the number of variables are set, resize the data.
101 if (this->n_vars())
102 for (auto z : make_range(this->n_zones()))
103 _data[z].resize (this->n_vars());
104}

References _conn, _data, _imax, _jmax, _kmax, _n_zones, _zone_names, _zone_pack, _zone_types, libMesh::make_range(), n_vars(), and n_zones().

Referenced by read_header().

◆ title() [1/2]

std::string & libMesh::PltLoader::title ( )
inlineprivate
Returns
The data set title

Definition at line 307 of file plt_loader.h.

307{ return _title; }

References _title.

◆ title() [2/2]

const std::string & libMesh::PltLoader::title ( ) const
inline
Returns
The data set title

Definition at line 175 of file plt_loader.h.

175{ return _title; }

References _title.

Referenced by read_header(), and write_dat().

◆ var_name() [1/2]

std::string & libMesh::PltLoader::var_name ( const unsigned int  v)
inlineprivate
Returns
The name of variable v.

Definition at line 491 of file plt_loader.h.

492{
493 libmesh_assert_less (v, this->n_vars());
494 libmesh_assert_less (v, _var_names.size());
495 libmesh_assert_equal_to (this->n_vars(), _var_names.size());
496
497 return _var_names[v];
498}

References _var_names, and n_vars().

◆ var_name() [2/2]

const std::string & libMesh::PltLoader::var_name ( const unsigned int  v) const
inline
Returns
The name of variable v.

Definition at line 479 of file plt_loader.h.

480{
481 libmesh_assert_less (v, this->n_vars());
482 libmesh_assert_less (v, _var_names.size());
483 libmesh_assert_equal_to (this->n_vars(), _var_names.size());
484
485 return _var_names[v];
486}

References _var_names, and n_vars().

Referenced by read_header(), and write_dat().

◆ var_type() [1/2]

unsigned int & libMesh::PltLoader::var_type ( const unsigned int  v)
inlineprivate
Returns
The type of variable v

Definition at line 515 of file plt_loader.h.

516{
517 libmesh_assert_less (v, this->n_vars());
518 libmesh_assert_less (v, _var_types.size());
519 libmesh_assert_equal_to (this->n_vars(), _var_types.size());
520
521 return _var_types[v];
522}

References _var_types, and n_vars().

◆ var_type() [2/2]

unsigned int libMesh::PltLoader::var_type ( const unsigned int  v) const
inline
Returns
The type of variable v

Definition at line 503 of file plt_loader.h.

504{
505 libmesh_assert_less (v, this->n_vars());
506 libmesh_assert_less (v, _var_types.size());
507 libmesh_assert_equal_to (this->n_vars(), _var_types.size());
508
509 return _var_types[v];
510}

References _var_types, and n_vars().

Referenced by read_block_data(), read_data(), read_feblock_data(), read_fepoint_data(), read_header(), and read_point_data().

◆ verbose()

bool libMesh::PltLoader::verbose ( ) const
inline
Returns
The verbosity.

Definition at line 70 of file plt_loader.h.

70{ return _verbose; }

References _verbose.

Referenced by read(), read_data(), and read_header().

◆ version() [1/2]

std::string & libMesh::PltLoader::version ( )
inlineprivate
Returns
The Tecplot version number string.

Definition at line 295 of file plt_loader.h.

295{ return _version; }

References _version.

◆ version() [2/2]

const std::string & libMesh::PltLoader::version ( ) const
inline
Returns
The Tecplot version number string. This identifies the version of Tecplot (or preplot) that wrote the binary file. Currently, PltLoader understands versions "#!TDV7X " and "#!TDV1XX"

Definition at line 163 of file plt_loader.h.

163{ return _version; }

References _version.

Referenced by read_data(), and read_header().

◆ write_dat()

void libMesh::PltLoader::write_dat ( const std::string &  name,
const unsigned int  version = 10 
) const

Writes an ASCII Tecplot file.

The optional parameter version specifies the version format to write.

Definition at line 453 of file plt_loader_write.C.

455{
456 std::ofstream out_stream (name.c_str());
457
458 out_stream << "TITLE=\""
459 << this->title()
460 << "\""
461 << '\n';
462
463 out_stream << "VARIABLES = ";
464
465 for (auto v : make_range(this->n_vars()))
466 out_stream << "\"" << this->var_name(v) << "\"\n";
467
468 for (auto z : make_range(this->n_zones()))
469 {
470 out_stream << "ZONE T=\"" << this->zone_name(z) << "\"\n";
471 out_stream << " I=" << this->imax(z)
472 << ", J=" << this->jmax(z)
473 << ", K=" << this->kmax(z);
474
475 // Write BLOCK data for this zone
476 if (this->zone_type(z) == BLOCK)
477 {
478 if (version_in < 10)
479 {
480 out_stream << ", F=BLOCK\n";
481 }
482 else
483 {
484 out_stream << ", ZONETYPE=Ordered\n"
485 << "DATAPACKING=BLOCK\n";
486 }
487
488 out_stream << "DT=(";
489 for (unsigned int v=0; v<this->n_vars(); v++)
490 out_stream << "SINGLE ";
491 out_stream << ")\n";
492
493 out_stream.precision(9);
494
495 for (auto v : make_range(this->n_vars()))
496 {
497 unsigned int l=0;
498
499 for (unsigned int k=0; k<this->kmax(z); k++)
500 for (unsigned int j=0; j<this->jmax(z); j++)
501 for (unsigned int i=0; i<this->imax(z); i++)
502 {
503 out_stream << std::scientific
504 << _data[z][v][l++] << " ";
505
506 // Throw in a newline every 5 entries to
507 // avoid really long lines.
508 if (l%5 == 0)
509 out_stream << '\n';
510 }
511
512 if (l%5 != 0)
513 out_stream << '\n';
514 }
515 } // end if (this->zone_type(z) == BLOCK)
516
517 // Write POINT data for this zone
518 else if (this->zone_type(z) == POINT)
519 {
520 if (version_in < 10)
521 {
522 out_stream << ", F=POINT\n";
523 }
524 else
525 {
526 out_stream << ", ZONETYPE=Ordered\n"
527 << "DATAPACKING=POINT\n";
528 }
529
530 out_stream << "DT=(";
531 for (unsigned int v=0; v<this->n_vars(); v++)
532 out_stream << "SINGLE ";
533 out_stream << ")\n";
534
535 out_stream.precision(9);
536
537 {
538 unsigned int l=0;
539
540 for (unsigned int k=0; k<this->kmax(z); k++)
541 for (unsigned int j=0; j<this->jmax(z); j++)
542 for (unsigned int i=0; i<this->imax(z); i++)
543 {
544 for (auto v : make_range(this->n_vars()))
545 out_stream << std::scientific
546 << _data[z][v][l] << " ";
547
548 out_stream << '\n';
549
550 l++;
551 }
552 }
553 } // end else if (this->zone_type(z) == POINT)
554
555 // Otherwise, unrecognized zone type
556 else
557 libmesh_error_msg("Unrecognized zone type: this->zone_type(z)==" << this->zone_type(z));
558 }
559}

References _data, BLOCK, imax(), jmax(), kmax(), libMesh::make_range(), n_vars(), n_zones(), POINT, title(), var_name(), zone_name(), and zone_type().

◆ zone_name() [1/2]

std::string & libMesh::PltLoader::zone_name ( const unsigned int  z)
inlineprivate
Returns
The name of zone z.

Definition at line 563 of file plt_loader.h.

564{
565 libmesh_assert_less (z, this->n_zones());
566 libmesh_assert_less (z, _zone_names.size());
567 libmesh_assert_equal_to (this->n_zones(), _zone_names.size());
568
569 return _zone_names[z];
570}

References _zone_names, and n_zones().

◆ zone_name() [2/2]

const std::string & libMesh::PltLoader::zone_name ( const unsigned int  z) const
inline
Returns
The name of zone z.

Definition at line 551 of file plt_loader.h.

552{
553 libmesh_assert_less (z, this->n_zones());
554 libmesh_assert_less (z, _zone_names.size());
555 libmesh_assert_equal_to (this->n_zones(), _zone_names.size());
556
557 return _zone_names[z];
558}

References _zone_names, and n_zones().

Referenced by read_header(), and write_dat().

◆ zone_pack() [1/2]

unsigned int & libMesh::PltLoader::zone_pack ( const unsigned int  z)
inlineprivate
Returns
The data pack flag for zone z.

Definition at line 587 of file plt_loader.h.

588{
589 libmesh_assert_less (z, this->n_zones());
590 libmesh_assert_less (z, _zone_pack.size());
591 libmesh_assert_equal_to (this->n_zones(), _zone_pack.size());
592
593 return _zone_pack[z];
594}

References _zone_pack, and n_zones().

◆ zone_pack() [2/2]

unsigned int libMesh::PltLoader::zone_pack ( const unsigned int  z) const
inline
Returns
The data packing flag for zone z.

Definition at line 575 of file plt_loader.h.

576{
577 libmesh_assert_less (z, this->n_zones());
578 libmesh_assert_less (z, _zone_pack.size());
579 libmesh_assert_equal_to (this->n_zones(), _zone_pack.size());
580
581 return _zone_pack[z];
582}

References _zone_pack, and n_zones().

Referenced by read_data(), and read_header().

◆ zone_type() [1/2]

unsigned int & libMesh::PltLoader::zone_type ( const unsigned int  z)
inlineprivate
Returns
The type of zone z

Definition at line 539 of file plt_loader.h.

540{
541 libmesh_assert_less (z, this->n_zones());
542 libmesh_assert_less (z, _zone_types.size());
543 libmesh_assert_equal_to (this->n_zones(), _zone_types.size());
544
545 return _zone_types[z];
546}

References _zone_types, and n_zones().

◆ zone_type() [2/2]

unsigned int libMesh::PltLoader::zone_type ( const unsigned int  z) const
inline
Returns
The type of zone z

Definition at line 527 of file plt_loader.h.

528{
529 libmesh_assert_less (z, this->n_zones());
530 libmesh_assert_less (z, _zone_types.size());
531 libmesh_assert_equal_to (this->n_zones(), _zone_types.size());
532
533 return _zone_types[z];
534}

References _zone_types, and n_zones().

Referenced by elem_type(), n_elem(), n_nodes(), read_data(), read_header(), and write_dat().

Member Data Documentation

◆ _conn

std::vector<std::vector<int> > libMesh::PltLoader::_conn
private

Vectors to hold the connectivity for each zone (only for unstructured files).

Definition at line 436 of file plt_loader.h.

Referenced by clear(), read_feblock_data(), read_fepoint_data(), and set_n_zones().

◆ _data

std::vector<std::vector<std::vector<float> > > libMesh::PltLoader::_data
private

◆ _imax

std::vector<unsigned int> libMesh::PltLoader::_imax
private

The (imax,jmax,kmax) value for each zone.

Definition at line 423 of file plt_loader.h.

Referenced by clear(), imax(), imax(), and set_n_zones().

◆ _is_foreign

bool libMesh::PltLoader::_is_foreign
private

Is the data foreign?

Definition at line 377 of file plt_loader.h.

Referenced by clear(), is_foreign(), and is_foreign().

◆ _jmax

std::vector<unsigned int> libMesh::PltLoader::_jmax
private

Definition at line 424 of file plt_loader.h.

Referenced by clear(), jmax(), jmax(), and set_n_zones().

◆ _kmax

std::vector<unsigned int> libMesh::PltLoader::_kmax
private

Definition at line 425 of file plt_loader.h.

Referenced by clear(), kmax(), kmax(), and set_n_zones().

◆ _n_vars

unsigned int libMesh::PltLoader::_n_vars
private

The number of variables in the data set.

Definition at line 387 of file plt_loader.h.

Referenced by clear(), n_vars(), and set_n_vars().

◆ _n_zones

unsigned int libMesh::PltLoader::_n_zones
private

The number of zones.

Definition at line 403 of file plt_loader.h.

Referenced by clear(), n_zones(), and set_n_zones().

◆ _title

std::string libMesh::PltLoader::_title
private

The Tecplot data set title.

Definition at line 382 of file plt_loader.h.

Referenced by clear(), title(), and title().

◆ _var_names

std::vector<std::string> libMesh::PltLoader::_var_names
private

The name for each variable.

Definition at line 392 of file plt_loader.h.

Referenced by clear(), set_n_vars(), var_name(), and var_name().

◆ _var_types

std::vector<unsigned int> libMesh::PltLoader::_var_types
private

The type of each variable.

Must be one of the enumerated DataType types.

Definition at line 398 of file plt_loader.h.

Referenced by clear(), set_n_vars(), var_type(), and var_type().

◆ _verbose

const bool libMesh::PltLoader::_verbose
private

Verbosity.

Definition at line 367 of file plt_loader.h.

Referenced by verbose().

◆ _version

std::string libMesh::PltLoader::_version
private

The Tecplot Version number string.

Definition at line 372 of file plt_loader.h.

Referenced by clear(), version(), and version().

◆ _zone_names

std::vector<std::string> libMesh::PltLoader::_zone_names
private

The name of each zone.

Definition at line 413 of file plt_loader.h.

Referenced by clear(), set_n_zones(), zone_name(), and zone_name().

◆ _zone_pack

std::vector<unsigned int> libMesh::PltLoader::_zone_pack
private

The data packing for each zone (new version only)

Definition at line 418 of file plt_loader.h.

Referenced by clear(), set_n_zones(), zone_pack(), and zone_pack().

◆ _zone_types

std::vector<unsigned int> libMesh::PltLoader::_zone_types
private

The type of each zone.

Definition at line 408 of file plt_loader.h.

Referenced by clear(), set_n_zones(), zone_type(), and zone_type().

◆ buf

char libMesh::PltLoader::buf[512]
mutableprivate

Scratch data & relevant sizes.

Definition at line 441 of file plt_loader.h.

Referenced by read_data(), read_fepoint_data(), read_header(), and read_point_data().

◆ NNodes

const unsigned int libMesh::PltLoader::NNodes = {3, 4, 4, 8}
static

Enum defining the number of nodes for each element type.

Definition at line 250 of file plt_loader.h.

Referenced by read_feblock_data(), and read_fepoint_data().


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