/Users/jack/Code/basso_dev/inc/GmshVer1Input.h

Go to the documentation of this file.
00001 
00011 #ifndef _GMSH_VER1_INPUT_BASSO_H_
00012 #define _GMSH_VER1_INPUT_BASSO_H_
00013 
00014 // I/O includes
00015 #include <iostream>
00016 #include <iomanip>
00017 #include <fstream>
00018 
00019 // STL includes
00020 #include <vector>
00021 #include <list>
00022 #include <set>
00023 #include <map>
00024 
00025 // Basso includes
00026 #include "basso.h"
00027 #include "FEInput.h"
00028 
00029 namespace basso {
00030 
00047 class GmshVer1Input : public FEInput {
00048         
00049 public:
00050         
00052 
00055                 GmshVer1Input( ) : FEInput( ) { }
00056                 GmshVer1Input( const String &file ) : FEInput(file) {  }
00059         virtual ~GmshVer1Input() {}
00060         
00061         // MEMEBER FUNCTIONS
00062         
00066         virtual void ReadNodes( Array<Node> &nodes );
00067         
00075         virtual void AddElements( list<Element> &elem, int pid=-999 ) const;
00076         
00083         virtual void AddNodeSet( set<int> &nid, int pid ) const;
00084 
00085 protected:
00086         
00090         BasisType GetBasisType( int etype ) const;
00091         
00092 protected:
00093 
00094                 
00095 };
00096 
00097 
00098 void GmshVer1Input::ReadNodes( Array<Node> &node )  
00099 {
00100 
00101         // open msh file
00102         std::ifstream inFile;
00103         if ( OpenFile(inFile) ) 
00104                 WarningMessage("GmshVer1Input::ReadNodes","could not open file");
00105 
00106         // look for node section 
00107         GotoSection(inFile,"$NOD");
00108 
00109         //  get the number of nodes
00110         int nn;
00111         inFile >> nn;
00112 
00113         if ( node.size()!=nn )
00114                 resize( node, nn );
00115 
00116         // fill node
00117         for ( int i=0; i<nn; ++i ) 
00118         {
00119                 int id;
00120                 Numeric x, y, z;
00121                 inFile >> id >> x >> y >> z;
00122                 node[i]=Node(i,x,y,z);
00123                 mNodeMap[id]=i;
00124         }
00125         CloseFile(inFile);
00126         
00127 }
00128 
00129 void GmshVer1Input::AddElements( list<Element> &elem, int pid ) const
00130 {
00131         // open msh file
00132         std::ifstream inFile;
00133         if ( OpenFile(inFile) ) 
00134                 WarningMessage("GmshVer1Input::ReadElements","could not open file");
00135         
00136 
00137         // look for element section 
00138         GotoSection(inFile,"$ELM");
00139 
00140         //  get the number of elements
00141         int ne;
00142         inFile >> ne;
00143 
00144         // fill element
00145         for ( int e=0; e<ne; ++e ) 
00146         {
00147                 int eid, etype, nne, epid, egid, nid;
00148                 map<int,int>::const_iterator mItr;
00149                 inFile >> eid >> etype >> epid >> egid >> nne;
00150                 iArray econn(nne);
00151                 for ( int n=0; n<nne; ++n )  
00152                         inFile >> econn[n];
00153                 if ( pid==epid || pid==-999 ) 
00154                 {
00155                         for ( int n=0; n<nne; ++n ) 
00156                         {
00157                                 mItr = mNodeMap.find( econn[n] );
00158                                 econn[n] = mItr->second;   // renumber conn
00159                         }
00160                                 
00161                         elem.push_back( Element( eid, epid, GetBasisType(etype), econn ) );
00162                 }
00163         }
00164         CloseFile(inFile);
00165          
00166 }
00167 
00168 void GmshVer1Input::AddNodeSet( set<int> &nset, int pid ) const
00169 {
00170         // open msh file
00171         std::ifstream inFile;
00172         if ( OpenFile(inFile) ) 
00173                 WarningMessage("GmshVer1Input::ReadNodeSet","could not open file");
00174          
00175 
00176         // look for element section 
00177         GotoSection(inFile,"$ELM");     
00178 
00179         //  get the number of elements
00180         int ne;
00181         inFile >> ne;
00182 
00183         // fill element
00184         for ( int e=0; e<ne; ++e ) 
00185         {
00186                 int eid, etype, nne, epid, egid;
00187                 map<int,int>::const_iterator mItr;
00188                 inFile >> eid >> etype >> epid >> egid >> nne;
00189                 iArray econn(nne);
00190                 for ( int n=0; n<nne; ++n )
00191                         inFile >> econn[n];
00192                 if ( pid==epid )
00193                         for ( int n=0; n<nne; ++n )
00194                         {
00195                                 mItr = mNodeMap.find( econn[n] );
00196                                 nset.insert( mItr->second );
00197                         }
00198         }
00199 
00200         CloseFile(inFile);
00201 }
00202 
00203         
00204 
00205 BasisType GmshVer1Input::GetBasisType( int etype ) const
00206 {
00207         switch (etype) {
00208                 
00209                 case 1:
00210                 return kLINE2;
00211                 
00212                 case 2:
00213                 return kTRIA3;
00214                 
00215                 case 3:
00216                 return kQUAD4;
00217                 
00218                 case 4:
00219                 return kTETRA4;
00220                 
00221                 case 5:
00222                 return kHEXA8;
00223                 
00224                 case 6:
00225                 return kPRISM6;
00226                 
00227                 case 7:
00228                 return kPYRAMID5;
00229                 
00230                 case 8:
00231                 return kLINE3;
00232                 
00233                 case 9:
00234                 return kTRIA6;
00235                 
00236                 case 10:
00237                 return kQUAD9;
00238                 
00239                 case 11:
00240                 return kTETRA10;
00241                 
00242                 case 12:
00243                 return kHEXA27;
00244                 
00245                 case 13:
00246                 return kPRISM18;
00247                 
00248                 case 14:
00249                 return kPYRAMID14;
00250                 
00251                 case 15:
00252                 return kPOINT1;
00253                 
00254                 case 16:
00255                 return kQUAD8;
00256                 
00257                 case 17:
00258                 return kHEXA20;
00259                 
00260                 case 18:
00261                 return kPRISM15;
00262                 
00263                 case 19:
00264                 return kPYRAMID13;
00265                 
00266                 default:
00267                 WarningMessage("BasisType GmshVer1Input::GetBasisType( int etype )","Unknown etype");
00268                 return kNONE;
00269         }
00270 }
00271 
00272 
00273 
00274 
00275 
00276 } // end Basso namepsace 
00277 #endif  

Generated on Sat Jan 19 09:03:57 2008 for Basso by  doxygen 1.5.2