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

Go to the documentation of this file.
00001 
00011 #ifndef _GMSH_INPUT_BASSO_H_
00012 #define _GMSH_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 
00045 class GmshInput : public FEInput {
00046         
00047 public:
00048         
00050 
00053                 GmshInput( ) : FEInput( ) { }
00054                 GmshInput( const String &file ) : FEInput(file) {  }
00057         virtual ~GmshInput() {}
00058         
00059         // MEMEBER FUNCTIONS
00060         
00064         virtual void ReadNodes( Array<Node> &nodes );
00065         
00073         virtual void AddElements( list<Element> &elem, int pid=-999 ) const;
00074         
00081         virtual void AddNodeSet( set<int> &nid, int pid ) const;
00082 
00083 protected:
00084         
00088         BasisType GetBasisType( int etype ) const;
00089         
00093         int NumNodesElement( int etype ) const;
00094         
00095 protected:
00096 
00097                 
00098 };
00099 
00100 
00101 void GmshInput::ReadNodes( Array<Node> &node )  
00102 {
00103 
00104         // open msh file
00105         std::ifstream inFile;
00106         if ( OpenFile(inFile) ) 
00107                 WarningMessage("GmshInput::ReadNodes","could not open file");
00108 
00109         // look for node section 
00110         GotoSection(inFile,"$Nodes");
00111 
00112         //  get the number of nodes
00113         int nn;
00114         inFile >> nn;
00115 
00116         if ( node.size()!=nn )
00117                 resize( node, nn );
00118 
00119         // fill node
00120         for ( int i=0; i<nn; ++i ) 
00121         {
00122                 int id;
00123                 Numeric x, y, z;
00124                 inFile >> id >> x >> y >> z;
00125                 node[i]=Node(i,x,y,z);
00126                 mNodeMap[id]=i;
00127         }
00128         CloseFile(inFile);
00129         
00130 }
00131 
00132 void GmshInput::AddElements( list<Element> &elem, int pid ) const
00133 {
00134         // open msh file
00135         std::ifstream inFile;
00136         if ( OpenFile(inFile) ) 
00137                 WarningMessage("GmshInput::ReadElements","could not open file");
00138         
00139 
00140         // look for element section 
00141         GotoSection(inFile,"$Elements");
00142 
00143         //  get the number of elements
00144         int ne;
00145         inFile >> ne;
00146 
00147         // fill element
00148         map<int,int>::const_iterator mItr;
00149         for ( int e=0; e<ne; ++e ) 
00150         {
00151                 int eid, etype, epid, nid, ntag;
00152                 
00153                 inFile >> eid >> etype >> ntag;
00154                 iArray tags(ntag);
00155                 for ( int t=0; t<ntag; ++t )
00156                         inFile >> tags[t];
00157                 epid=tags[0]; 
00158                         
00159                 int nne=NumNodesElement(etype);
00160                 iArray econn(nne);
00161                 for ( int n=0; n<nne; ++n )  
00162                         inFile >> econn[n];
00163                 if ( pid==epid || pid==-999 ) 
00164                 {
00165                         for ( int n=0; n<nne; ++n ) 
00166                         {
00167                                 mItr = mNodeMap.find( econn[n] );
00168                                 econn[n] = mItr->second;   // renumber conn
00169                         }
00170                                 
00171                         elem.push_back( Element( eid, epid, GetBasisType(etype), econn ) );
00172                 }
00173         }
00174         CloseFile(inFile);
00175          
00176 }
00177 
00178 void GmshInput::AddNodeSet( set<int> &nset, int pid ) const
00179 {
00180         // open msh file
00181         std::ifstream inFile;
00182         if ( OpenFile(inFile) ) 
00183                 WarningMessage("GmshInput::AddNodeSet","could not open file");
00184          
00185 
00186         // look for element section 
00187         GotoSection(inFile,"$Elements");        
00188 
00189         //  get the number of elements
00190         int ne;
00191         inFile >> ne;
00192 
00193         // fill element
00194         map<int,int>::const_iterator mItr;
00195         for ( int e=0; e<ne; ++e ) 
00196         {
00197                 int eid, etype, epid, nid, ntag;
00198                 
00199                 inFile >> eid >> etype >> ntag;
00200                 iArray tags(ntag);
00201                 for ( int t=0; t<ntag; ++t )
00202                         inFile >> tags[t];
00203                 epid=tags[0]; 
00204                         
00205                 int nne=NumNodesElement(etype);
00206                 iArray econn(nne);
00207                 for ( int n=0; n<nne; ++n )
00208                         inFile >> econn[n];
00209                 if ( pid==epid )
00210                         for ( int n=0; n<nne; ++n )
00211                         {
00212                                 mItr = mNodeMap.find( econn[n] );
00213                                 nset.insert( mItr->second );
00214                         }
00215         }
00216 
00217         CloseFile(inFile);
00218 }
00219 
00220 int GmshInput::NumNodesElement( int etype ) const
00221 {
00222         switch (etype) {
00223                 
00224                 case 1:
00225                 return 2;
00226                 
00227                 case 2:
00228                 return 3;
00229                 
00230                 case 3:
00231                 return 4;
00232                 
00233                 case 4:
00234                 return 4;
00235                 
00236                 case 5:
00237                 return 8;
00238                 
00239                 case 6:
00240                 return 6;
00241                 
00242                 case 7:
00243                 return 5;
00244                 
00245                 case 8:
00246                 return 3;
00247                 
00248                 case 9:
00249                 return 6;
00250                 
00251                 case 10:
00252                 return 9;
00253                 
00254                 case 11:
00255                 return 10;
00256                 
00257                 case 12:
00258                 return 27;
00259                 
00260                 case 13:
00261                 return 18;
00262                 
00263                 case 14:
00264                 return 14;
00265                 
00266                 case 15:
00267                 return 1;
00268                 
00269                 case 16:
00270                 return 8;
00271                 
00272                 case 17:
00273                 return 20;
00274                 
00275                 case 18:
00276                 return 15;
00277                 
00278                 case 19:
00279                 return 13;
00280                 
00281                 default:
00282                 WarningMessage("BasisType GmshInput::NumNodesElement( int etype )","Unknown etype");
00283                 return 1;
00284         }
00285 }
00286         
00287 
00288 BasisType GmshInput::GetBasisType( int etype ) const
00289 {
00290         switch (etype) {
00291                 
00292                 case 1:
00293                 return kLINE2;
00294                 
00295                 case 2:
00296                 return kTRIA3;
00297                 
00298                 case 3:
00299                 return kQUAD4;
00300                 
00301                 case 4:
00302                 return kTETRA4;
00303                 
00304                 case 5:
00305                 return kHEXA8;
00306                 
00307                 case 6:
00308                 return kPRISM6;
00309                 
00310                 case 7:
00311                 return kPYRAMID5;
00312                 
00313                 case 8:
00314                 return kLINE3;
00315                 
00316                 case 9:
00317                 return kTRIA6;
00318                 
00319                 case 10:
00320                 return kQUAD9;
00321                 
00322                 case 11:
00323                 return kTETRA10;
00324                 
00325                 case 12:
00326                 return kHEXA27;
00327                 
00328                 case 13:
00329                 return kPRISM18;
00330                 
00331                 case 14:
00332                 return kPYRAMID14;
00333                 
00334                 case 15:
00335                 return kPOINT1;
00336                 
00337                 case 16:
00338                 return kQUAD8;
00339                 
00340                 case 17:
00341                 return kHEXA20;
00342                 
00343                 case 18:
00344                 return kPRISM15;
00345                 
00346                 case 19:
00347                 return kPYRAMID13;
00348                 
00349                 default:
00350                 WarningMessage("BasisType GmshInput::GetBasisType( int etype )","Unknown etype");
00351                 return kNONE;
00352         }
00353 }
00354 
00355 
00356 
00357 
00358 
00359 } // end Basso namepsace 
00360 #endif  

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