$extrastylesheet
00001 // Copyright (C) 2002-2007 Benjamin S. Kirk 00002 00003 // This library is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public 00005 // License as published by the Free Software Foundation; either 00006 // version 2.1 of the License, or (at your option) any later version. 00007 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // Lesser General Public License for more details. 00012 00013 // You should have received a copy of the GNU Lesser General Public 00014 // License along with this library; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 00017 00018 00019 #ifndef LIBMESH_PLT_LOADER_H 00020 #define LIBMESH_PLT_LOADER_H 00021 00022 // Local includes 00023 #include "libmesh/libmesh_common.h" 00024 00025 // C++ includes 00026 #include <string> 00027 #include <vector> 00028 00029 namespace libMesh 00030 { 00031 00032 00033 00041 class PltLoader 00042 { 00043 public: 00044 00048 PltLoader (const bool v=false); 00049 00053 PltLoader (const std::string& name, const bool v=false); 00054 00058 ~PltLoader (); 00059 00063 void clear (); 00064 00068 bool verbose () const { return _verbose; } 00069 00073 void read (const std::string& name); 00074 00079 void write_dat (const std::string& name, 00080 const unsigned int version=10) const; 00081 00082 // BSK - this functionality requires FORTRAN subrouitine calls, 00083 // and there is no need to "dirty up" \p libMesh with FORTRAN 00084 // just to enable these methods. 00085 // /** 00086 // * Writes a plot3d files. The grid will be in basename.g and 00087 // * the solution will be in basename.q. It is assumed that the 00088 // * first three variables from the .plt file are the (x,y,z) 00089 // * locations of the grid points. The optional parameter \p reverse 00090 // * specifies if the output file will have reversed byte ordering. 00091 // */ 00092 // void write_plot3d (const std::string& basename, 00093 // const bool reverse=false, 00094 // const bool gridonly=false) const; 00095 00096 // /** 00097 // * Writes a Cart3D .tri component file. The number of components 00098 // * will be the number of zones in the .plt file. 00099 // */ 00100 // void write_tri (const std::string& name, 00101 // const bool reverse=false, 00102 // const bool gridonly=false) const; 00103 00104 00105 00106 //-------------------------------------------------------------- 00107 // Data access 00108 00109 00110 00115 enum OldZoneType { BLOCK=0, 00116 POINT, 00117 FEBLOCK, 00118 FEPOINT }; 00119 00124 enum NewZoneType { ORDERED=0, 00125 FELINESEG, 00126 FETRIANGLE, 00127 FEQUADRILATERAL, 00128 FETETRAHEDRON, 00129 FEBRICK }; 00130 00134 enum DataType { FLOAT=1, 00135 DOUBLE, 00136 LONGINT, 00137 SHORTINT, 00138 BYTE, 00139 BIT}; 00140 00144 enum FEType { TRI=0, 00145 QUAD, 00146 TET, 00147 HEX }; 00148 00149 00150 00151 //-------------------------------------------------------------- 00152 // Public Data Access 00153 00154 00155 00161 const std::string & version () const { return _version; } 00162 00168 bool is_foreign () const { return _is_foreign; } 00169 00173 const std::string & title () const { return _title; } 00174 00178 unsigned int n_vars () const { return _n_vars; } 00179 00183 const std::string & var_name (const unsigned int v) const; 00184 00188 unsigned int var_type (const unsigned int v) const; 00189 00193 unsigned int n_zones () const { return _n_zones; } 00194 00198 unsigned int zone_type (const unsigned int z) const; 00199 00203 const std::string & zone_name (const unsigned int z) const; 00204 00208 unsigned int zone_pack (const unsigned int z) const; 00209 00213 unsigned int imax (const unsigned int z) const; 00214 00218 unsigned int jmax (const unsigned int z) const; 00219 00223 unsigned int kmax (const unsigned int z) const; 00224 00228 unsigned int n_nodes (const unsigned int z) const; 00229 00233 unsigned int n_elem (const unsigned int z) const; 00234 00238 FEType elem_type (const unsigned int z) const; 00239 00243 const std::vector<std::vector<std::vector<float> > > & get_data () const; 00244 00248 static const unsigned int NNodes[4]; 00249 00250 00251 private: 00252 00253 00257 void read_header (std::istream& in); 00258 00262 void read_data (std::istream& in); 00263 00267 void read_block_data (std::istream& in, const unsigned int zn); 00268 00272 void read_point_data (std::istream& in, const unsigned int zn); 00273 00277 void read_feblock_data (std::istream& in, const unsigned int zn); 00278 00282 void read_fepoint_data (std::istream& in, const unsigned int zn); 00283 00284 00285 //-------------------------------------------------------------- 00286 // Private Data Access 00287 00288 00289 00293 std::string & version () { return _version; } 00294 00300 bool & is_foreign () { return _is_foreign; } 00301 00305 std::string & title () { return _title; } 00306 00310 void set_n_vars (const unsigned int nv); 00311 00315 std::string & var_name (const unsigned int v); 00316 00320 unsigned int & var_type (const unsigned int v); 00321 00325 void set_n_zones (const unsigned int nz); 00326 00330 unsigned int & zone_type (const unsigned int z); 00331 00335 std::string & zone_name (const unsigned int z); 00336 00340 unsigned int & zone_pack (const unsigned int z); 00341 00345 unsigned int & imax (const unsigned int z); 00346 00350 unsigned int & jmax (const unsigned int z); 00351 00355 unsigned int & kmax (const unsigned int z); 00356 00357 00358 //-------------------------------------------------------------- 00359 // Private Data 00360 00361 00365 const bool _verbose; 00366 00370 std::string _version; 00371 00375 bool _is_foreign; 00376 00380 std::string _title; 00381 00385 unsigned int _n_vars; 00386 00390 std::vector<std::string> _var_names; 00391 00396 std::vector<unsigned int> _var_types; 00397 00401 unsigned int _n_zones; 00402 00406 std::vector<unsigned int> _zone_types; 00407 00411 std::vector<std::string> _zone_names; 00412 00416 std::vector<unsigned int> _zone_pack; 00417 00421 std::vector<unsigned int> _imax; 00422 std::vector<unsigned int> _jmax; 00423 std::vector<unsigned int> _kmax; 00424 00428 std::vector<std::vector<std::vector<float> > > _data; 00429 00434 std::vector<std::vector<int> > _conn; 00435 00439 mutable char buf[512]; 00440 }; 00441 00442 00443 00444 //--------------------------------------------------------- 00445 // PltLoader inline members 00446 inline 00447 PltLoader::PltLoader (const bool v) : 00448 _verbose (v), 00449 _is_foreign (false), 00450 _n_vars (0), 00451 _n_zones (0) 00452 { 00453 } 00454 00455 00456 00457 inline 00458 PltLoader::PltLoader (const std::string& name, const bool v) : 00459 _verbose (v), 00460 _is_foreign (false), 00461 _n_vars (0), 00462 _n_zones (0) 00463 { 00464 this->read (name); 00465 } 00466 00467 00468 00469 inline 00470 PltLoader::~PltLoader() 00471 { 00472 } 00473 00474 00475 00476 inline 00477 const std::string & PltLoader::var_name (const unsigned int v) const 00478 { 00479 libmesh_assert_less (v, this->n_vars()); 00480 libmesh_assert_less (v, _var_names.size()); 00481 libmesh_assert_equal_to (this->n_vars(), _var_names.size()); 00482 00483 return _var_names[v]; 00484 } 00485 00486 00487 00488 inline 00489 std::string & PltLoader::var_name (const unsigned int v) 00490 { 00491 libmesh_assert_less (v, this->n_vars()); 00492 libmesh_assert_less (v, _var_names.size()); 00493 libmesh_assert_equal_to (this->n_vars(), _var_names.size()); 00494 00495 return _var_names[v]; 00496 } 00497 00498 00499 00500 inline 00501 unsigned int PltLoader::var_type (const unsigned int v) const 00502 { 00503 libmesh_assert_less (v, this->n_vars()); 00504 libmesh_assert_less (v, _var_types.size()); 00505 libmesh_assert_equal_to (this->n_vars(), _var_types.size()); 00506 00507 return _var_types[v]; 00508 } 00509 00510 00511 00512 inline 00513 unsigned int & PltLoader::var_type (const unsigned int v) 00514 { 00515 libmesh_assert_less (v, this->n_vars()); 00516 libmesh_assert_less (v, _var_types.size()); 00517 libmesh_assert_equal_to (this->n_vars(), _var_types.size()); 00518 00519 return _var_types[v]; 00520 } 00521 00522 00523 00524 inline 00525 unsigned int PltLoader::zone_type (const unsigned int z) const 00526 { 00527 libmesh_assert_less (z, this->n_zones()); 00528 libmesh_assert_less (z, _zone_types.size()); 00529 libmesh_assert_equal_to (this->n_zones(), _zone_types.size()); 00530 00531 return _zone_types[z]; 00532 } 00533 00534 00535 00536 inline 00537 unsigned int & PltLoader::zone_type (const unsigned int z) 00538 { 00539 libmesh_assert_less (z, this->n_zones()); 00540 libmesh_assert_less (z, _zone_types.size()); 00541 libmesh_assert_equal_to (this->n_zones(), _zone_types.size()); 00542 00543 return _zone_types[z]; 00544 } 00545 00546 00547 00548 inline 00549 const std::string & PltLoader::zone_name (const unsigned int z) const 00550 { 00551 libmesh_assert_less (z, this->n_zones()); 00552 libmesh_assert_less (z, _zone_names.size()); 00553 libmesh_assert_equal_to (this->n_zones(), _zone_names.size()); 00554 00555 return _zone_names[z]; 00556 } 00557 00558 00559 00560 inline 00561 std::string & PltLoader::zone_name (const unsigned int z) 00562 { 00563 libmesh_assert_less (z, this->n_zones()); 00564 libmesh_assert_less (z, _zone_names.size()); 00565 libmesh_assert_equal_to (this->n_zones(), _zone_names.size()); 00566 00567 return _zone_names[z]; 00568 } 00569 00570 00571 00572 inline 00573 unsigned int PltLoader::zone_pack (const unsigned int z) const 00574 { 00575 libmesh_assert_less (z, this->n_zones()); 00576 libmesh_assert_less (z, _zone_pack.size()); 00577 libmesh_assert_equal_to (this->n_zones(), _zone_pack.size()); 00578 00579 return _zone_pack[z]; 00580 } 00581 00582 00583 00584 inline 00585 unsigned int & PltLoader::zone_pack (const unsigned int z) 00586 { 00587 libmesh_assert_less (z, this->n_zones()); 00588 libmesh_assert_less (z, _zone_pack.size()); 00589 libmesh_assert_equal_to (this->n_zones(), _zone_pack.size()); 00590 00591 return _zone_pack[z]; 00592 } 00593 00594 00595 00596 inline 00597 unsigned int PltLoader::imax (const unsigned int z) const 00598 { 00599 libmesh_assert_less (z, this->n_zones()); 00600 libmesh_assert_equal_to (_imax.size(), this->n_zones()); 00601 00602 return _imax[z]; 00603 } 00604 00605 00606 00607 inline 00608 unsigned int & PltLoader::imax (const unsigned int z) 00609 { 00610 libmesh_assert_less (z, this->n_zones()); 00611 libmesh_assert_equal_to (_imax.size(), this->n_zones()); 00612 00613 return _imax[z]; 00614 } 00615 00616 00617 00618 inline 00619 unsigned int PltLoader::jmax (const unsigned int z) const 00620 { 00621 libmesh_assert_less (z, this->n_zones()); 00622 libmesh_assert_equal_to (_jmax.size(), this->n_zones()); 00623 00624 return _jmax[z]; 00625 } 00626 00627 00628 00629 inline 00630 unsigned int & PltLoader::jmax (const unsigned int z) 00631 { 00632 libmesh_assert_less (z, this->n_zones()); 00633 libmesh_assert_equal_to (_jmax.size(), this->n_zones()); 00634 00635 return _jmax[z]; 00636 } 00637 00638 00639 00640 inline 00641 unsigned int PltLoader::kmax (const unsigned int z) const 00642 { 00643 libmesh_assert_less (z, this->n_zones()); 00644 libmesh_assert_equal_to (_kmax.size(), this->n_zones()); 00645 00646 return _kmax[z]; 00647 } 00648 00649 00650 00651 inline 00652 unsigned int & PltLoader::kmax (const unsigned int z) 00653 { 00654 libmesh_assert_less (z, this->n_zones()); 00655 libmesh_assert_equal_to (_kmax.size(), this->n_zones()); 00656 00657 return _kmax[z]; 00658 } 00659 00660 00661 00662 inline 00663 unsigned int PltLoader::n_nodes (const unsigned int z) const 00664 { 00665 libmesh_assert_less (z, this->n_zones()); 00666 00667 // Only for unstructured zones! 00668 libmesh_assert_greater (this->zone_type(z), 1); 00669 00670 return this->imax(z); 00671 } 00672 00673 00674 00675 inline 00676 unsigned int PltLoader::n_elem (const unsigned int z) const 00677 { 00678 libmesh_assert_less (z, this->n_zones()); 00679 00680 // Only for unstructured zones! 00681 libmesh_assert_greater (this->zone_type(z), 1); 00682 00683 return this->jmax(z); 00684 } 00685 00686 00687 00688 inline 00689 PltLoader::FEType PltLoader::elem_type (const unsigned int z) const 00690 { 00691 libmesh_assert_less (z, this->n_zones()); 00692 00693 // Only for unstructured zones! 00694 libmesh_assert_greater (this->zone_type(z), 1); 00695 00696 return static_cast<FEType>(this->kmax(z)); 00697 } 00698 00699 00700 inline 00701 const std::vector<std::vector<std::vector<float> > > & 00702 PltLoader::get_data () const 00703 { 00704 return _data; 00705 } 00706 00707 00708 00709 00710 } // namespace libMesh 00711 00712 00713 #endif // LIBMESH_PLT_LOADER_H