plt_loader.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_PLT_LOADER_H
21 #define LIBMESH_PLT_LOADER_H
22 
23 // Local includes
24 #include "libmesh/libmesh_common.h"
25 
26 // C++ includes
27 #include <string>
28 #include <vector>
29 
30 namespace libMesh
31 {
32 
33 
34 
43 class PltLoader
44 {
45 public:
46 
50  PltLoader (const bool v=false);
51 
55  PltLoader (const std::string & name, const bool v=false);
56 
60  ~PltLoader ();
61 
65  void clear ();
66 
70  bool verbose () const { return _verbose; }
71 
75  void read (const std::string & name);
76 
81  void write_dat (const std::string & name,
82  const unsigned int version=10) const;
83 
84  // BSK - this functionality requires FORTRAN subroutine calls,
85  // and there is no need to "dirty up" \p libMesh with FORTRAN
86  // just to enable these methods.
87  // /**
88  // * Writes a plot3d files. The grid will be in basename.g and
89  // * the solution will be in basename.q. It is assumed that the
90  // * first three variables from the .plt file are the (x,y,z)
91  // * locations of the grid points. The optional parameter \p reverse
92  // * specifies if the output file will have reversed byte ordering.
93  // */
94  // void write_plot3d (const std::string & basename,
95  // const bool reverse=false,
96  // const bool gridonly=false) const;
97 
98  // /**
99  // * Writes a Cart3D .tri component file. The number of components
100  // * will be the number of zones in the .plt file.
101  // */
102  // void write_tri (const std::string & name,
103  // const bool reverse=false,
104  // const bool gridonly=false) const;
105 
106 
107 
108  //--------------------------------------------------------------
109  // Data access
110 
111 
112 
117  enum OldZoneType { BLOCK=0,
121 
132 
136  enum DataType { FLOAT=1,
141  BIT};
142 
146  enum FEType { TRI=0,
149  HEX };
150 
151 
152 
153  //--------------------------------------------------------------
154  // Public Data Access
155 
156 
157 
163  const std::string & version () const { return _version; }
164 
170  bool is_foreign () const { return _is_foreign; }
171 
175  const std::string & title () const { return _title; }
176 
180  unsigned int n_vars () const { return _n_vars; }
181 
185  const std::string & var_name (const unsigned int v) const;
186 
190  unsigned int var_type (const unsigned int v) const;
191 
195  unsigned int n_zones () const { return _n_zones; }
196 
200  unsigned int zone_type (const unsigned int z) const;
201 
205  const std::string & zone_name (const unsigned int z) const;
206 
210  unsigned int zone_pack (const unsigned int z) const;
211 
215  unsigned int imax (const unsigned int z) const;
216 
220  unsigned int jmax (const unsigned int z) const;
221 
225  unsigned int kmax (const unsigned int z) const;
226 
230  unsigned int n_nodes (const unsigned int z) const;
231 
235  unsigned int n_elem (const unsigned int z) const;
236 
240  FEType elem_type (const unsigned int z) const;
241 
245  const std::vector<std::vector<std::vector<float>>> & get_data () const;
246 
250  static const unsigned int NNodes[4];
251 
252 
253 private:
254 
255 
259  void read_header (std::istream & in);
260 
264  void read_data (std::istream & in);
265 
269  void read_block_data (std::istream & in, const unsigned int zn);
270 
274  void read_point_data (std::istream & in, const unsigned int zn);
275 
279  void read_feblock_data (std::istream & in, const unsigned int zn);
280 
284  void read_fepoint_data (std::istream & in, const unsigned int zn);
285 
286 
287  //--------------------------------------------------------------
288  // Private Data Access
289 
290 
291 
295  std::string & version () { return _version; }
296 
302  bool & is_foreign () { return _is_foreign; }
303 
307  std::string & title () { return _title; }
308 
312  void set_n_vars (const unsigned int nv);
313 
317  std::string & var_name (const unsigned int v);
318 
322  unsigned int & var_type (const unsigned int v);
323 
327  void set_n_zones (const unsigned int nz);
328 
332  unsigned int & zone_type (const unsigned int z);
333 
337  std::string & zone_name (const unsigned int z);
338 
342  unsigned int & zone_pack (const unsigned int z);
343 
347  unsigned int & imax (const unsigned int z);
348 
352  unsigned int & jmax (const unsigned int z);
353 
357  unsigned int & kmax (const unsigned int z);
358 
359 
360  //--------------------------------------------------------------
361  // Private Data
362 
363 
367  const bool _verbose;
368 
372  std::string _version;
373 
378 
382  std::string _title;
383 
387  unsigned int _n_vars;
388 
392  std::vector<std::string> _var_names;
393 
398  std::vector<unsigned int> _var_types;
399 
403  unsigned int _n_zones;
404 
408  std::vector<unsigned int> _zone_types;
409 
413  std::vector<std::string> _zone_names;
414 
418  std::vector<unsigned int> _zone_pack;
419 
423  std::vector<unsigned int> _imax;
424  std::vector<unsigned int> _jmax;
425  std::vector<unsigned int> _kmax;
426 
430  std::vector<std::vector<std::vector<float>>> _data;
431 
436  std::vector<std::vector<int>> _conn;
437 
441  mutable char buf[512];
442 };
443 
444 
445 
446 //---------------------------------------------------------
447 // PltLoader inline members
448 inline
449 PltLoader::PltLoader (const bool v) :
450  _verbose (v),
451  _is_foreign (false),
452  _n_vars (0),
453  _n_zones (0)
454 {
455 }
456 
457 
458 
459 inline
460 PltLoader::PltLoader (const std::string & name, const bool v) :
461  _verbose (v),
462  _is_foreign (false),
463  _n_vars (0),
464  _n_zones (0)
465 {
466  this->read (name);
467 }
468 
469 
470 
471 inline
473 {
474 }
475 
476 
477 
478 inline
479 const std::string & PltLoader::var_name (const unsigned int v) const
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 }
487 
488 
489 
490 inline
491 std::string & PltLoader::var_name (const unsigned int v)
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 }
499 
500 
501 
502 inline
503 unsigned int PltLoader::var_type (const unsigned int v) const
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 }
511 
512 
513 
514 inline
515 unsigned int & PltLoader::var_type (const unsigned int v)
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 }
523 
524 
525 
526 inline
527 unsigned int PltLoader::zone_type (const unsigned int z) const
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 }
535 
536 
537 
538 inline
539 unsigned int & PltLoader::zone_type (const unsigned int z)
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 }
547 
548 
549 
550 inline
551 const std::string & PltLoader::zone_name (const unsigned int z) const
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 }
559 
560 
561 
562 inline
563 std::string & PltLoader::zone_name (const unsigned int z)
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 }
571 
572 
573 
574 inline
575 unsigned int PltLoader::zone_pack (const unsigned int z) const
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 }
583 
584 
585 
586 inline
587 unsigned int & PltLoader::zone_pack (const unsigned int z)
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 }
595 
596 
597 
598 inline
599 unsigned int PltLoader::imax (const unsigned int z) const
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 }
606 
607 
608 
609 inline
610 unsigned int & PltLoader::imax (const unsigned int z)
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 }
617 
618 
619 
620 inline
621 unsigned int PltLoader::jmax (const unsigned int z) const
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 }
628 
629 
630 
631 inline
632 unsigned int & PltLoader::jmax (const unsigned int z)
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 }
639 
640 
641 
642 inline
643 unsigned int PltLoader::kmax (const unsigned int z) const
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 }
650 
651 
652 
653 inline
654 unsigned int & PltLoader::kmax (const unsigned int z)
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 }
661 
662 
663 
664 inline
665 unsigned int PltLoader::n_nodes (const unsigned int z) const
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 }
674 
675 
676 
677 inline
678 unsigned int PltLoader::n_elem (const unsigned int z) const
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 }
687 
688 
689 
690 inline
691 PltLoader::FEType PltLoader::elem_type (const unsigned int z) const
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 }
700 
701 
702 inline
703 const std::vector<std::vector<std::vector<float>>> &
705 {
706  return _data;
707 }
708 
709 
710 
711 
712 } // namespace libMesh
713 
714 
715 #endif // LIBMESH_PLT_LOADER_H
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
bool & is_foreign()
Definition: plt_loader.h:302
Manages the family, order, etc. parameters for a given FE.
Definition: fe_type.h:179
void set_n_zones(const unsigned int nz)
Definition: plt_loader.C:83
FEType elem_type(const unsigned int z) const
Definition: plt_loader.h:691
unsigned int n_vars() const
Definition: plt_loader.h:180
std::vector< std::vector< int > > _conn
Definition: plt_loader.h:436
std::vector< std::string > _zone_names
Definition: plt_loader.h:413
std::vector< std::vector< std::vector< float > > > _data
Definition: plt_loader.h:430
std::vector< unsigned int > _zone_pack
Definition: plt_loader.h:418
std::vector< unsigned int > _kmax
Definition: plt_loader.h:425
void read_point_data(std::istream &in, const unsigned int zn)
std::vector< unsigned int > _var_types
Definition: plt_loader.h:398
std::string & title()
Definition: plt_loader.h:307
void set_n_vars(const unsigned int nv)
Definition: plt_loader.C:61
const bool _verbose
Definition: plt_loader.h:367
std::vector< unsigned int > _zone_types
Definition: plt_loader.h:408
const std::string & var_name(const unsigned int v) const
Definition: plt_loader.h:479
std::vector< unsigned int > _jmax
Definition: plt_loader.h:424
std::vector< unsigned int > _imax
Definition: plt_loader.h:423
bool is_foreign() const
Definition: plt_loader.h:170
void read(const std::string &name)
static const unsigned int NNodes[4]
Definition: plt_loader.h:250
unsigned int imax(const unsigned int z) const
Definition: plt_loader.h:599
const std::string & zone_name(const unsigned int z) const
Definition: plt_loader.h:551
std::vector< std::string > _var_names
Definition: plt_loader.h:392
unsigned int jmax(const unsigned int z) const
Definition: plt_loader.h:621
unsigned int zone_pack(const unsigned int z) const
Definition: plt_loader.h:575
PltLoader(const bool v=false)
Definition: plt_loader.h:449
std::string _title
Definition: plt_loader.h:382
unsigned int _n_vars
Definition: plt_loader.h:387
void read_fepoint_data(std::istream &in, const unsigned int zn)
unsigned int n_nodes(const unsigned int z) const
Definition: plt_loader.h:665
std::string _version
Definition: plt_loader.h:372
const std::vector< std::vector< std::vector< float > > > & get_data() const
Definition: plt_loader.h:704
unsigned int var_type(const unsigned int v) const
Definition: plt_loader.h:503
const std::string & title() const
Definition: plt_loader.h:175
unsigned int n_zones() const
Definition: plt_loader.h:195
unsigned int kmax(const unsigned int z) const
Definition: plt_loader.h:643
void read_header(std::istream &in)
void read_block_data(std::istream &in, const unsigned int zn)
const std::string & version() const
Definition: plt_loader.h:163
unsigned int _n_zones
Definition: plt_loader.h:403
unsigned int n_elem(const unsigned int z) const
Definition: plt_loader.h:678
void read_data(std::istream &in)
void read_feblock_data(std::istream &in, const unsigned int zn)
bool verbose() const
Definition: plt_loader.h:70
std::string & version()
Definition: plt_loader.h:295
void write_dat(const std::string &name, const unsigned int version=10) const
unsigned int zone_type(const unsigned int z) const
Definition: plt_loader.h:527