plt_loader.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2007 Benjamin S. Kirk
2 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 
17 
18 
19 #ifndef LIBMESH_PLT_LOADER_H
20 #define LIBMESH_PLT_LOADER_H
21 
22 // Local includes
23 #include "libmesh/libmesh_common.h"
24 
25 // C++ includes
26 #include <string>
27 #include <vector>
28 
29 namespace libMesh
30 {
31 
32 
33 
41 class PltLoader
42 {
43 public:
44 
48  PltLoader (const bool v=false);
49 
53  PltLoader (const std::string& name, const bool v=false);
54 
58  ~PltLoader ();
59 
63  void clear ();
64 
68  bool verbose () const { return _verbose; }
69 
73  void read (const std::string& name);
74 
79  void write_dat (const std::string& name,
80  const unsigned int version=10) const;
81 
82 // BSK - this functionality requires FORTRAN subrouitine calls,
83 // and there is no need to "dirty up" \p libMesh with FORTRAN
84 // just to enable these methods.
85 // /**
86 // * Writes a plot3d files. The grid will be in basename.g and
87 // * the solution will be in basename.q. It is assumed that the
88 // * first three variables from the .plt file are the (x,y,z)
89 // * locations of the grid points. The optional parameter \p reverse
90 // * specifies if the output file will have reversed byte ordering.
91 // */
92 // void write_plot3d (const std::string& basename,
93 // const bool reverse=false,
94 // const bool gridonly=false) const;
95 
96 // /**
97 // * Writes a Cart3D .tri component file. The number of components
98 // * will be the number of zones in the .plt file.
99 // */
100 // void write_tri (const std::string& name,
101 // const bool reverse=false,
102 // const bool gridonly=false) const;
103 
104 
105 
106  //--------------------------------------------------------------
107  // Data access
108 
109 
110 
115  enum OldZoneType { BLOCK=0,
119 
130 
134  enum DataType { FLOAT=1,
139  BIT};
140 
144  enum FEType { TRI=0,
147  HEX };
148 
149 
150 
151  //--------------------------------------------------------------
152  // Public Data Access
153 
154 
155 
161  const std::string & version () const { return _version; }
162 
168  bool is_foreign () const { return _is_foreign; }
169 
173  const std::string & title () const { return _title; }
174 
178  unsigned int n_vars () const { return _n_vars; }
179 
183  const std::string & var_name (const unsigned int v) const;
184 
188  unsigned int var_type (const unsigned int v) const;
189 
193  unsigned int n_zones () const { return _n_zones; }
194 
198  unsigned int zone_type (const unsigned int z) const;
199 
203  const std::string & zone_name (const unsigned int z) const;
204 
208  unsigned int zone_pack (const unsigned int z) const;
209 
213  unsigned int imax (const unsigned int z) const;
214 
218  unsigned int jmax (const unsigned int z) const;
219 
223  unsigned int kmax (const unsigned int z) const;
224 
228  unsigned int n_nodes (const unsigned int z) const;
229 
233  unsigned int n_elem (const unsigned int z) const;
234 
238  FEType elem_type (const unsigned int z) const;
239 
243  const std::vector<std::vector<std::vector<float> > > & get_data () const;
244 
248  static const unsigned int NNodes[4];
249 
250 
251 private:
252 
253 
257  void read_header (std::istream& in);
258 
262  void read_data (std::istream& in);
263 
267  void read_block_data (std::istream& in, const unsigned int zn);
268 
272  void read_point_data (std::istream& in, const unsigned int zn);
273 
277  void read_feblock_data (std::istream& in, const unsigned int zn);
278 
282  void read_fepoint_data (std::istream& in, const unsigned int zn);
283 
284 
285  //--------------------------------------------------------------
286  // Private Data Access
287 
288 
289 
293  std::string & version () { return _version; }
294 
300  bool & is_foreign () { return _is_foreign; }
301 
305  std::string & title () { return _title; }
306 
310  void set_n_vars (const unsigned int nv);
311 
315  std::string & var_name (const unsigned int v);
316 
320  unsigned int & var_type (const unsigned int v);
321 
325  void set_n_zones (const unsigned int nz);
326 
330  unsigned int & zone_type (const unsigned int z);
331 
335  std::string & zone_name (const unsigned int z);
336 
340  unsigned int & zone_pack (const unsigned int z);
341 
345  unsigned int & imax (const unsigned int z);
346 
350  unsigned int & jmax (const unsigned int z);
351 
355  unsigned int & kmax (const unsigned int z);
356 
357 
358  //--------------------------------------------------------------
359  // Private Data
360 
361 
365  const bool _verbose;
366 
370  std::string _version;
371 
376 
380  std::string _title;
381 
385  unsigned int _n_vars;
386 
390  std::vector<std::string> _var_names;
391 
396  std::vector<unsigned int> _var_types;
397 
401  unsigned int _n_zones;
402 
406  std::vector<unsigned int> _zone_types;
407 
411  std::vector<std::string> _zone_names;
412 
416  std::vector<unsigned int> _zone_pack;
417 
421  std::vector<unsigned int> _imax;
422  std::vector<unsigned int> _jmax;
423  std::vector<unsigned int> _kmax;
424 
428  std::vector<std::vector<std::vector<float> > > _data;
429 
434  std::vector<std::vector<int> > _conn;
435 
439  mutable char buf[512];
440 };
441 
442 
443 
444 //---------------------------------------------------------
445 // PltLoader inline members
446 inline
447 PltLoader::PltLoader (const bool v) :
448  _verbose (v),
449  _is_foreign (false),
450  _n_vars (0),
451  _n_zones (0)
452 {
453 }
454 
455 
456 
457 inline
458 PltLoader::PltLoader (const std::string& name, const bool v) :
459  _verbose (v),
460  _is_foreign (false),
461  _n_vars (0),
462  _n_zones (0)
463 {
464  this->read (name);
465 }
466 
467 
468 
469 inline
471 {
472 }
473 
474 
475 
476 inline
477 const std::string & PltLoader::var_name (const unsigned int v) const
478 {
479  libmesh_assert_less (v, this->n_vars());
480  libmesh_assert_less (v, _var_names.size());
481  libmesh_assert_equal_to (this->n_vars(), _var_names.size());
482 
483  return _var_names[v];
484 }
485 
486 
487 
488 inline
489 std::string & PltLoader::var_name (const unsigned int v)
490 {
491  libmesh_assert_less (v, this->n_vars());
492  libmesh_assert_less (v, _var_names.size());
493  libmesh_assert_equal_to (this->n_vars(), _var_names.size());
494 
495  return _var_names[v];
496 }
497 
498 
499 
500 inline
501 unsigned int PltLoader::var_type (const unsigned int v) const
502 {
503  libmesh_assert_less (v, this->n_vars());
504  libmesh_assert_less (v, _var_types.size());
505  libmesh_assert_equal_to (this->n_vars(), _var_types.size());
506 
507  return _var_types[v];
508 }
509 
510 
511 
512 inline
513 unsigned int & PltLoader::var_type (const unsigned int v)
514 {
515  libmesh_assert_less (v, this->n_vars());
516  libmesh_assert_less (v, _var_types.size());
517  libmesh_assert_equal_to (this->n_vars(), _var_types.size());
518 
519  return _var_types[v];
520 }
521 
522 
523 
524 inline
525 unsigned int PltLoader::zone_type (const unsigned int z) const
526 {
527  libmesh_assert_less (z, this->n_zones());
528  libmesh_assert_less (z, _zone_types.size());
529  libmesh_assert_equal_to (this->n_zones(), _zone_types.size());
530 
531  return _zone_types[z];
532 }
533 
534 
535 
536 inline
537 unsigned int & PltLoader::zone_type (const unsigned int z)
538 {
539  libmesh_assert_less (z, this->n_zones());
540  libmesh_assert_less (z, _zone_types.size());
541  libmesh_assert_equal_to (this->n_zones(), _zone_types.size());
542 
543  return _zone_types[z];
544 }
545 
546 
547 
548 inline
549 const std::string & PltLoader::zone_name (const unsigned int z) const
550 {
551  libmesh_assert_less (z, this->n_zones());
552  libmesh_assert_less (z, _zone_names.size());
553  libmesh_assert_equal_to (this->n_zones(), _zone_names.size());
554 
555  return _zone_names[z];
556 }
557 
558 
559 
560 inline
561 std::string & PltLoader::zone_name (const unsigned int z)
562 {
563  libmesh_assert_less (z, this->n_zones());
564  libmesh_assert_less (z, _zone_names.size());
565  libmesh_assert_equal_to (this->n_zones(), _zone_names.size());
566 
567  return _zone_names[z];
568 }
569 
570 
571 
572 inline
573 unsigned int PltLoader::zone_pack (const unsigned int z) const
574 {
575  libmesh_assert_less (z, this->n_zones());
576  libmesh_assert_less (z, _zone_pack.size());
577  libmesh_assert_equal_to (this->n_zones(), _zone_pack.size());
578 
579  return _zone_pack[z];
580 }
581 
582 
583 
584 inline
585 unsigned int & PltLoader::zone_pack (const unsigned int z)
586 {
587  libmesh_assert_less (z, this->n_zones());
588  libmesh_assert_less (z, _zone_pack.size());
589  libmesh_assert_equal_to (this->n_zones(), _zone_pack.size());
590 
591  return _zone_pack[z];
592 }
593 
594 
595 
596 inline
597 unsigned int PltLoader::imax (const unsigned int z) const
598 {
599  libmesh_assert_less (z, this->n_zones());
600  libmesh_assert_equal_to (_imax.size(), this->n_zones());
601 
602  return _imax[z];
603 }
604 
605 
606 
607 inline
608 unsigned int & PltLoader::imax (const unsigned int z)
609 {
610  libmesh_assert_less (z, this->n_zones());
611  libmesh_assert_equal_to (_imax.size(), this->n_zones());
612 
613  return _imax[z];
614 }
615 
616 
617 
618 inline
619 unsigned int PltLoader::jmax (const unsigned int z) const
620 {
621  libmesh_assert_less (z, this->n_zones());
622  libmesh_assert_equal_to (_jmax.size(), this->n_zones());
623 
624  return _jmax[z];
625 }
626 
627 
628 
629 inline
630 unsigned int & PltLoader::jmax (const unsigned int z)
631 {
632  libmesh_assert_less (z, this->n_zones());
633  libmesh_assert_equal_to (_jmax.size(), this->n_zones());
634 
635  return _jmax[z];
636 }
637 
638 
639 
640 inline
641 unsigned int PltLoader::kmax (const unsigned int z) const
642 {
643  libmesh_assert_less (z, this->n_zones());
644  libmesh_assert_equal_to (_kmax.size(), this->n_zones());
645 
646  return _kmax[z];
647 }
648 
649 
650 
651 inline
652 unsigned int & PltLoader::kmax (const unsigned int z)
653 {
654  libmesh_assert_less (z, this->n_zones());
655  libmesh_assert_equal_to (_kmax.size(), this->n_zones());
656 
657  return _kmax[z];
658 }
659 
660 
661 
662 inline
663 unsigned int PltLoader::n_nodes (const unsigned int z) const
664 {
665  libmesh_assert_less (z, this->n_zones());
666 
667  // Only for unstructured zones!
668  libmesh_assert_greater (this->zone_type(z), 1);
669 
670  return this->imax(z);
671 }
672 
673 
674 
675 inline
676 unsigned int PltLoader::n_elem (const unsigned int z) const
677 {
678  libmesh_assert_less (z, this->n_zones());
679 
680  // Only for unstructured zones!
681  libmesh_assert_greater (this->zone_type(z), 1);
682 
683  return this->jmax(z);
684 }
685 
686 
687 
688 inline
689 PltLoader::FEType PltLoader::elem_type (const unsigned int z) const
690 {
691  libmesh_assert_less (z, this->n_zones());
692 
693  // Only for unstructured zones!
694  libmesh_assert_greater (this->zone_type(z), 1);
695 
696  return static_cast<FEType>(this->kmax(z));
697 }
698 
699 
700 inline
701 const std::vector<std::vector<std::vector<float> > > &
703 {
704  return _data;
705 }
706 
707 
708 
709 
710 } // namespace libMesh
711 
712 
713 #endif // LIBMESH_PLT_LOADER_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo