Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

Parser.h

00001 /****************************************************************************
00002  *                                                                          *
00003  *  Program: FDDlib                                                         *
00004  *  Version: 1.1                                                            *
00005  *                                                                          *
00006  *  Copyright (C) 2002 - 2004 by Eric Miller and Dana Brooks                *
00007  *  All rights reserved.                                                    *
00008  *                                                                          *
00009  *  This software is Version 1.1 of the fddlib tomography toolbox.          *
00010  *  It is not to be redistributed or used for any commercial purpose        *
00011  *  without the prior written consent of the authors and Northeastern       *
00012  *  University.                                                             *
00013  *                                                                          *
00014  *  This software is provided as is, and any express or implied warranties, *
00015  *  including but not limited to the implied warranty of merchantability    *
00016  *  and the implied warranty of fitness for a particular purpose, are dis-  *
00017  *  claimed.  In no event shall the authors or Northeastern University be   *
00018  *  liable for any direct, indirect, incidental, special, exemplary, or     *
00019  *  consequential damages (including but not limited to procurement of      * 
00020  *  substitute goods or services; loss of use, data, or profits; or busi-   *
00021  *  ness interruption) however caused and on any theory of liability,       *
00022  *  whether in contract, strict liability, or tort (including negligence or *
00023  *  otherwise) arising in any way from the use of this software, even if    *
00024  *  advised of the possibility of such damage.                              *
00025  *                                                                          *
00026  *  Portions of this code benefit from ideas from Kyle Guilbert, Greg       *
00027  *  Boverman, Derek Uluski, David Kaeli, and Jennifer Black                 *
00028  *                                                                          *
00029  ****************************************************************************/
00030 
00031 #ifndef _PARSER_H_
00032 #define _PARSER_H_
00033 
00034 #include <vector>
00035 #include <string>
00036 #include <list>
00037 #include <bitset>
00038 #include <fstream>
00039 #include "Complex.h"
00040 #include "Property.h"
00041 #include "grid_enums.h"
00042 #include "solver.h"
00043 
00045 namespace FDDparse
00046 {
00047 
00054 class Parser {
00055 
00056 // public data
00057 public:
00058  
00060   enum Dimension {D_2D, D_3D};
00061 
00063   enum BoundType {Dirichlet, Neumann, Mixed};
00064 
00066   enum PreconType {Diagonal, ILU0, SSOR};
00067 
00069   enum BackgroundType {Constant, Layered, Mapped, Arbitrary};
00070 
00072   enum GridType {Nebulous, ArbitraryCartesian, RegularCartesian};
00073   
00075   enum TagType {TAG_GRID, TAG_SOURCES, TAG_DETECTORS, TAG_PROPERTIES,
00076                 TAG_MEDIUMSETUP, TAG_ANOMALIES, TAG_BOUNDARIES,
00077                 TAG_OPTIONS, TAG_POINTLIST, TAG_DELTALIST, TAG_NONE };
00078 
00080   // ANOMALIES //
00082 
00084   struct s_sphericalanomaly
00085   {
00087     double xcenter;
00088 
00090     double ycenter;
00091 
00093     double zcenter;
00094 
00096     double radius;
00097 
00099     std::string prop;
00100   };
00101 
00103   struct s_cubicalanomaly
00104   {
00106     double xcenter;
00107 
00109     double ycenter;
00110 
00112     double zcenter;
00113 
00115     double length;
00116 
00118     std::string prop;
00119   };
00120   
00122   struct s_ellipsoidalanomaly
00123   {
00125     double xcenter;
00126     
00128     double ycenter;
00129     
00131     double zcenter;
00132     
00134     double xlen;
00135     
00137     double ylen;
00138     
00140     double zlen;
00141     
00143     double theta1;
00144     
00146     double theta2;
00147     
00149     double theta3;
00150     
00152     std::string prop;
00153   };
00154   
00156   struct s_circularanomaly
00157   {
00159     double xcenter;
00160 
00162     double ycenter;
00163 
00165     double radius;
00166 
00168     std::string prop;
00169   };
00170 
00172   struct s_squareanomaly
00173   {
00175     double xcenter;
00176 
00178     double ycenter;
00179 
00181     double length;
00182 
00184     std::string prop;
00185   };
00186 
00188   // SOURCES //
00190 
00192   struct s_arbitrarysource
00193   {
00195     int id;
00196     
00198     std::vector <double> x;
00199 
00201     std::vector <double> y;
00202 
00204     std::vector <double> z;
00205 
00207     std::vector <FDDlib::Complex <double> > val;
00208 
00210     std::vector<double> frequencies;
00211   };
00212 
00214   struct s_monopolesource
00215   {
00217     int id;
00218     
00220     double xloc;
00221 
00223     double yloc;
00224 
00226     double zloc;
00227 
00229     double magnitude;
00230 
00232     double phase;
00233 
00235     std::vector<double> frequencies;
00236   };
00237 
00239   struct s_dipolesource
00240   {
00242     int id;
00243         
00245     double x[2];
00246 
00248     double y[2];
00249 
00251     double z[2];
00252 
00254     double magnitude[2];
00255 
00257     double phase[2];
00258 
00260     std::vector<double> frequencies;
00261   };
00262 
00264   // DETECTORS //
00266 
00268   struct s_arbitrarydetector
00269   {
00271     int id;
00272 
00274     std::vector <double> x;
00275 
00277     std::vector <double> y;
00278 
00280     std::vector <double> z;
00281 
00283     std::vector < FDDlib::Complex <double> > weight;
00284   };
00285 
00287   struct s_monopoledetector
00288   {
00290     int id;
00291         
00293     double xloc;
00294 
00296     double yloc;
00297 
00299     double zloc;
00300   };
00301 
00303   struct s_dipoledetector
00304   {
00306     int id;
00307 
00309     double x[2];
00310 
00312     double y[2];
00313 
00315     double z[2];
00316 
00318     FDDlib::Complex<double> weight[2];
00319   };
00320 
00322   struct s_nebulousgrid
00323   {
00325     int numnodes;
00326 
00328     char * nodefile;
00329 
00331     double espeed;
00332 
00333   };
00334 
00336   struct s_regcartgrid
00337   {
00339     int xdim;
00340 
00342     int ydim;
00343 
00345     int zdim;
00346 
00348     double stepsize;
00349 
00351     double espeed;
00352 
00353   };
00354 
00356   struct s_arbcartgrid
00357   {
00359     int xdim;
00360 
00362     int ydim;
00363 
00365     int zdim;
00366 
00368     char * deltafile;
00369 
00371     double espeed;
00372     
00374     std::vector<double> deltax;
00375 
00377     std::vector<double> deltay;
00378 
00380     std::vector<double> deltaz;
00381 
00382   };
00383 
00385   struct s_node
00386   {
00388     int id;
00389 
00391     double xloc;
00392 
00394     double yloc;
00395 
00397     double zloc;
00398 
00400     std::vector <int> neighbors;
00401 
00403     std::string property;
00404 
00406     BoundType bcondition;
00407   };
00408   
00410   struct s_boundary
00411   {
00413     BoundType bt;
00414     
00416     double mixedval;
00417   };
00418 
00420   struct s_property
00421   {
00423     std::string name;
00424 
00426     bool active;
00427     
00429     std::string coefs;
00430   };
00431 
00433   struct s_layer
00434   {
00436     int layerzdepth;
00437     
00439     std::string layerpropname;
00440   };
00441 
00443   struct s_precon
00444   {
00446     PreconType type;
00448     double relaxation;
00449   };
00450 
00451 // protected member data and definitions
00452 protected:
00453 
00455   char * filename;
00456   
00458   std::ifstream file;
00459   
00461   Dimension domain;
00462 
00464   bool isContiguouslyBound;
00465 
00467   s_boundary contiguousBoundary;
00468 
00470   std::vector<s_boundary> boundaries;
00471 
00473   std::vector<s_sphericalanomaly> spherical_anomalies;
00474 
00476   std::vector<s_cubicalanomaly>   cubical_anomalies;
00477   
00479   std::vector<s_ellipsoidalanomaly> ellipsoidal_anomalies;
00480 
00482   std::vector<s_circularanomaly> circular_anomalies;
00483   
00485   std::vector<s_squareanomaly> square_anomalies;
00486 
00488   std::vector <s_node> nodes;
00489 
00491   std::vector <s_monopolesource>  monopole_sources;
00492   
00494   std::vector <s_dipolesource>    dipole_sources;
00495   
00497   std::vector <s_arbitrarysource> arbitrary_sources;
00498 
00500   int currSrcId;
00501 
00503   std::vector <s_monopoledetector> monopole_detectors;
00504   
00506   std::vector <s_dipoledetector>   dipole_detectors;
00507   
00509   std::vector <s_arbitrarydetector> arbitrary_detectors;
00510 
00512   int currDetId;
00513 
00518   BackgroundType bg_type;
00519 
00521   char * mapfile_path;
00522   
00524   char * arbitrary_prop_path;
00525   
00527   std::vector<s_layer> layers;
00528   
00530   std::string constantprop_name;
00531 
00532 
00533 
00535   int solver_iterations;
00536   
00538   double solver_residualtol;
00539   
00540   
00542   s_precon solver_conditionertype;
00543   
00545   FDDlib::enum_solver solver_type;
00546   
00548   int n_normalOrder;
00549   
00551   int n_numNeighbors;
00552   
00554   double n_normalTol;
00555 
00556 
00558   std::vector <s_property> props;
00559 
00561   GridType grid_type;
00562 
00564   s_arbcartgrid *acg;
00565 
00567   s_regcartgrid     *rcg;
00568 
00570   s_nebulousgrid    *ng;
00571   
00573   std::bitset<10> parsedTags;
00574 
00575 
00576 // public member functions
00577 public:
00578 
00583   Parser(char *path, Dimension d) throw(std::string);
00584   
00586   void parseFile() throw(std::string);
00587   
00589   Dimension getDomain() const;
00590   
00592   std::string getFilename() const;
00593   
00595   bool querySuccessfulParse() const;
00596   
00598   GridType getGridType() const;
00599   
00601   s_arbcartgrid getArbitraryCartesianGridData() const throw(std::string);
00602   
00604   s_regcartgrid getRegularCartesianGridData() const throw(std::string);
00605   
00607   s_nebulousgrid getNebulousGridData() const throw(std::string);
00608   
00610   std::vector<s_monopolesource> getMonopoleSourceData() const;
00611   
00613   std::vector<s_dipolesource> getDipoleSourceData() const;
00614   
00616   std::vector<s_arbitrarysource> getArbitrarySourceData() const;
00617   
00618   
00620   std::vector<s_monopoledetector> getMonopoleDetectorData() const;
00621   
00623   std::vector<s_dipoledetector> getDipoleDetectorData() const;
00624   
00626   std::vector<s_arbitrarydetector> getArbitraryDetectorData() const;
00627   
00629   std::vector<s_property> getPropertyData() const;
00630   
00632   BackgroundType getBackgroundType() const;
00633   
00635   std::string getConstantBGPropName() const;
00636   
00638   std::vector<s_layer> getBGLayers() const;
00639   
00641   std::string getMapfilePath() const throw(std::string);
00642   
00644   std::string getArbitraryPropPath() const throw(std::string);
00645   
00647   bool queryIsContiguouslyBound() const;
00648   
00650   s_boundary getContiguousBoundaryData() const throw(std::string);
00651   
00653   std::vector<s_boundary> getBoundaryData() const;
00654   
00656   std::vector<s_sphericalanomaly> getSphericalAnomalyData() const;
00657   
00659   std::vector<s_cubicalanomaly> getCubicalAnomalyData() const;
00660   
00662   std::vector<s_ellipsoidalanomaly> getEllipsoidalAnomalyData() const;
00663   
00665   std::vector<s_circularanomaly> getCircularAnomalyData() const;
00666   
00668   std::vector<s_squareanomaly> getSquareAnomalyData() const;
00669   
00671   int getNormalPolyOrder() const;
00672   
00674   int getNormalNumNeighbors() const;
00675   
00677   double getNormalEstTol() const;
00678   
00680   int getSolveMaxIterations() const;
00681   
00683   double getSolveResidualTolerance() const;
00684   
00686   s_precon getPreconditionerData() const;
00687   
00689   FDDlib::enum_solver getSolverType() const;
00690   
00691 // protected member functions
00692 protected:
00693 
00695   void deblank(char *str) const;
00696   
00698   TagType getTagType(char buf[]) const;
00699   
00704   std::list<std::string> parseSeries(std::string series, char del) const;
00705   
00707   void parseGridTag(int pos);
00708   
00710   FDDlib::gridSide3D parseGridSide(char str[]) const;
00711   
00713   void parseSourcesTag(int pos);
00714   
00716   void parseMonopoleSource(int pos);
00717   
00719   void parseDipoleSource(int pos);
00720   
00722   void parseArbitrarySource(int pos);
00723   
00725   void parseDetectorsTag(int pos);
00726   
00728   void parseMonopoleDetector(int pos);
00729   
00731   void parseDipoleDetector(int pos);
00732   
00734   void parseArbitraryDetector(int pos);
00735   
00737   void parsePropertiesTag(int pos);
00738   
00740   void parseMediumSetupTag(int pos);
00741   
00743   void parseAnomaliesTag(int pos);
00744   
00746   void parseBoundariesTag(int pos);
00747   
00749   s_boundary parseBCType(char str[]) const;
00750   
00752   void parseOptionsTag(int pos);
00753   
00755   s_precon parsePreconditionerType(char str[]) const;
00756   
00758   FDDlib::enum_solver parseSolverType(char str[]) const;
00759   
00761   void parseNodeListTag(int pos);
00762   
00764   void parseNodeTag(int pos);
00765   
00767   void parseDeltaListTag(std::ifstream& stream, int pos);
00768   
00770   void parseDeltaFile();
00771 };
00772 
00773 } // end fddparse
00774 
00775 #endif
00776 

Generated on Mon Aug 30 15:41:07 2004 for FDDLib by doxygen1.2.18