RSTT  3.2.0
Regional Seismic Travel Time
All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Grid.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 National Technology & Engineering Solutions of Sandia, LLC
4 //- (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
5 //- Government retains certain rights in this software.
6 //-
7 //- BSD Open Source License
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- 1. Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //-
16 //- 2. Redistributions in binary form must reproduce the above copyright
17 //- notice, this list of conditions and the following disclaimer in the
18 //- documentation and/or other materials provided with the distribution.
19 //-
20 //- 3. Neither the name of the copyright holder nor the names of its
21 //- contributors may be used to endorse or promote products derived from
22 //- this software without specific prior written permission.
23 //-
24 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 //- POSSIBILITY OF SUCH DAMAGE.
35 //-
36 //- ****************************************************************************
37 
38 #ifndef SLBM_GRID_H
39 #define SLBM_GRID_H
40 
41 // **** _SYSTEM INCLUDES_ ******************************************************
42 #include <vector>
43 #include <map>
44 #include <cmath>
45 
46 using namespace std;
47 
48 // **** _LOCAL INCLUDES_ *******************************************************
49 
50 #include "SLBMGlobals.h"
51 #include "GridProfile.h"
52 #include "InterpolatedProfile.h"
53 #include "LayerProfile.h"
54 #include "LayerProfileG.h"
55 #include "QueryProfile.h"
56 #include "CrustalProfile.h"
57 #include "CrustalProfileStore.h"
58 #include "GreatCircle.h"
59 #include "GreatCircleFactory.h"
60 #include "Location.h"
61 #include "SLBMException.h"
62 #include "Triangle.h"
63 #include "UncertaintyPIU.h"
64 #include "UncertaintyPDU.h"
65 #include "GeoTessPolygon.h"
66 #include "GeoTessModelSLBM.h"
67 
68 #include "DataBuffer.h"
69 #include "MD50.h"
70 
71 // **** _BEGIN SLBM NAMESPACE_ **************************************************
72 
73 namespace slbm {
74 
91 {
92 
93 public:
94 
98  Grid();
99 
103  virtual ~Grid();
104 
105  static Grid* getGrid(const string& modelDirectory);
106 
107  static Grid* getGrid(util::DataBuffer& buffer);
108 
109  static bool fileExists(const string& fileName);
110 
114  virtual bool operator == (const Grid& other);
115 
119  virtual bool operator != (const Grid& other) {return !(*this == other);};
120 
124  static string class_name() {return "Grid"; };
125 
129  virtual void clear();
130 
136  virtual void loadFromFile(const string& filename) = ABSTRACT;
137 
143  virtual void loadFromDirectory(const string& dirName) = ABSTRACT;
144 
150  virtual void loadFromDataBuffer(util::DataBuffer& buffer) = ABSTRACT;
151 
156  virtual void saveVelocityModel(util::DataBuffer& buffer) = ABSTRACT;
157 
164  virtual void saveVelocityModel(const string& filename, const int& format) = ABSTRACT;
165 
166  virtual int getBufferSize() const = ABSTRACT;
167 
168  virtual bool is_directory(const string& dir);
169 
173  virtual int getNNodes() { return profiles.size(); }
174 
179  virtual int getNIntervals() { return NLAYERS;};
180 
187  virtual GridProfile* getProfile(const int& nodeId);
188 
217  const int& phase,
218  const double& latSource,
219  const double& lonSource,
220  const double& depthSource,
221  const double& latReceiver,
222  const double& lonReceiver,
223  const double& depthReceiver,
224  const double& delta,
225  const double& ch_max);
226 
244  //CrustalProfile* getCrustalProfile(const int& phase,
245  // const double& lat, const double& lon, const double& depth);
246 
247  virtual CrustalProfile* getReceiverProfile(const int& phase,
248  const double& lat, const double& lon, const double& depth);
249 
250  virtual CrustalProfile* getSourceProfile(const int& phase,
251  const double& lat, const double& lon, const double& depth);
252 
256  virtual void clearCrustalProfiles();
257 
275  virtual LayerProfile* getLayerProfile(GreatCircle* greatCircle,
276  Location& location);
277 
287  virtual QueryProfile* getQueryProfile(Location& location);
288 
294  vector<vector<UncertaintyPIU*> >& getUncertainty() { return piu; }
295  vector<vector<UncertaintyPIU*> >& getUncertaintyPIU() { return piu; }
296 
303  UncertaintyPIU& getUncertaintyPIU(int phase, int attribute) { return *piu[phase][attribute]; }
304 
309  vector<UncertaintyPDU*>& getUncertaintyPDU() { return pdu; }
310 
316  UncertaintyPDU& getUncertaintyPDU(int phase) { return *pdu[phase]; }
317 
324  virtual double getAverageMantleVelocity(const int& waveType) = ABSTRACT;
325 
332  virtual void setAverageMantleVelocity(const int& waveType, const double& velocity) = ABSTRACT;
333 
334  virtual int getNCrustalProfiles();
335 
355  virtual bool findProfile(Location& location,
356  vector<GridProfile*>& neighbors, vector<int>& nodeIds,
357  vector<double>& coefficients) = ABSTRACT;
358 
368  void initializeActiveNodes(double activeNodeLatMin,
369  double activeNodeLonMin,
370  double activeNodeLatMax,
371  double activeNodeLonMax);
372 
381  void initializeActiveNodes(GeoTessPolygon* polygon);
382 
386  virtual int getNActiveNodes() { return activeNodes.size(); };
387 
389 
395  virtual int getGridNodeId(int activeNodeId)
396  { return (activeNodeId < 0 ? -1 : activeNodes[activeNodeId]); };
397 
403  virtual int getActiveNodeId(int nodeId)
404  { return profiles[nodeId]->getActiveNodeId(); };
405 
411  virtual void getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors) = ABSTRACT;
412 
418  virtual void getNodeNeighbors(const int& nodeId, vector<int>& neighbors) = ABSTRACT;
419 
427  virtual void getNodeNeighborInfo(const int& nodeId, int neighbors[],
428  double distance[], double azimuth[], int& nNeighbors);
429 
437  virtual void getNodeNeighborInfo(const int& nodeId, vector<int>& neighbors,
438  vector<double>& distance, vector<double>& azimuth);
439 
440  virtual void getActiveNodeNeighbors(const int& nodeid, int neighbors[], int& nNeighbors) = ABSTRACT;
441 
442  virtual void getActiveNodeNeighbors(const int& nodeid, vector<int>& neighbors) = ABSTRACT;
443 
444  virtual void getActiveNodeNeighborInfo(const int& nid, int neighbors[],
445  double distance[], double azimuth[], int& nNeighbors);
446 
447  virtual void getActiveNodeNeighborInfo(const int& nid, vector<int>& neighbors,
448  vector<double>& distance, vector<double>& azimuth);
449 
451  // grid nodes.
454  // grid nodes.
455  virtual void getNodeSeparation(const int& node1, const int& node2, double& distance);
456 
460  virtual void getNodeAzimuth(const int& node1, const int& node2, double& azimuth);
461 
462  virtual void getNodeHitCount(const int& nodeId, int& hitCount)
463  { hitCount = profiles[nodeId]->getHitCount(); };
464 
465  virtual void clearNodeHitCount();
466 
467  virtual int addGeoStack(GeoStack* geoStack) = ABSTRACT;
468 
469  virtual size_t memSize() = ABSTRACT;
470 
471  virtual size_t memSizeCrustalProfiles();
472 
473  virtual string getTessId() = ABSTRACT;
474 
475  string& getModelPath() { return modelPath; }
476 
477  virtual string toString() = ABSTRACT;
478 
479  virtual void setInterpolatorType(const string& interpolatorType) = ABSTRACT;
480 
481  virtual string getInterpolatorType() = ABSTRACT;
482 
483  const string getOutputDirectory() { return outputDirectory; }
484 
485  void specifyOutputDirectory(const string& outputDir);
486 
487  virtual GeoTessModelSLBM* getModel() { return model; }
488 
489 protected:
490 
494  string modelPath;
495 
499  vector<GridProfile*> profiles;
500 
501  vector<int> activeNodes;
502 
504 
505  GeoTessPolygon* polygon;
506 
509 
510  vector<vector<UncertaintyPIU*> > piu;
511 
512  vector<UncertaintyPDU*> pdu;
513 
514  void writeBufferToFile(util::DataBuffer& buffer, string fileName);
515 
516  void reaDataBuffererFromFile(util::DataBuffer& buffer, string dirname,
517  string fileName);
518 
519 private:
520 
521  string outputDirectory;
522 
523 };
524 
525 inline GridProfile* Grid::getProfile(const int& n)
526 {
527  if (n < 0 || n >= (int)profiles.size())
528  {
529  ostringstream os;
530  os << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(4);
531  os << endl << "ERROR in Grid::getProfile. NodeId "<< n << " is out of range. " << endl
532  << "Valid range is >= 0 and < " << profiles.size() << endl
533  << "Version " << SlbmVersion << " File " << __FILE__ << " line " << __LINE__ << endl << endl;
534  throw SLBMException(os.str(),107);
535  }
536  return profiles[n];
537 }
538 
539 inline LayerProfile* Grid::getLayerProfile(GreatCircle* gc,
540  Location& location)
541 {
542  if (gc->getPhase()/2 == 0)
543  // for Pn or Sn, return a LayerProfile with gradient info.
544  return new LayerProfileG(gc, location);
545  else
546  // for Pg or Lg, return a LayerProfile without gradient info.
547  return new LayerProfile(gc, location);
548 }
549 
550 inline QueryProfile* Grid::getQueryProfile(Location& location)
551 {
552  return new QueryProfile(*this, location);
553 }
554 
555 inline CrustalProfile* Grid::getSourceProfile(const int& phase,
556  const double& lat, const double& lon, const double& depth)
557 {
558  return sources->getCrustalProfile(phase, lat, lon, depth);
559 }
560 
561 inline CrustalProfile* Grid::getReceiverProfile(const int& phase,
562  const double& lat, const double& lon, const double& depth)
563 {
564  return receivers->getCrustalProfile(phase, lat, lon, depth);
565 }
566 
567 inline void Grid::clearCrustalProfiles()
568 {
569  receivers->clear();
570  sources->clear();
571 }
572 
573 inline int Grid::getNCrustalProfiles()
574 {
575  return receivers->getNCrustalProfiles()
576  + sources->getNCrustalProfiles();
577 }
578 
579 inline size_t Grid::memSizeCrustalProfiles()
580 {
581  return receivers->memSize() + sources->memSize();
582 }
583 
584 inline void Grid::clearNodeHitCount()
585 {
586  for (int i=0; i<(int)profiles.size(); ++i)
587  profiles[i]->clearHitCount();
588 }
589 
590 inline bool Grid::fileExists(const string& fileName)
591 {
592  fstream f;
593 
594  f.open(fileName.c_str(), ios::in);
595  if (f.is_open())
596  {
597  f.close();
598  return true;
599  }
600  return false;
601 }
602 
603 
604 } // end slbm namespace
605 
606 #endif // GRID_H
#define SLBM_EXP_IMP
Definition: SLBMGlobals.h:180
A profile through the Earth model that stores interface radius, and interval P or S wave velocity inf...
CrustalProfileStore supports pool allocation for CrustalProfile objects.
Manages all information related to a single node in a Grid object.
Definition: GeoStack.h:65
The GreatCircle class manages information related to a great circle path between two Locations on the...
Definition: GreatCircle.h:114
int getPhase()
Retrieve the phase that this GreatCircle supports. Will be one of SLBMGlobals::Pn,...
Definition: GreatCircle.h:178
A 2 dimensional, horizontal grid of GirdProfile objects.
Definition: Grid.h:91
void writeBufferToFile(util::DataBuffer &buffer, string fileName)
virtual void getNodeNeighbors(const int &nodeId, int neighbors[], int &nNeighbors)
Retrieve the grid node id of the nodes that are direct neighbors of the specified grid node.
static Grid * getGrid(const string &modelDirectory)
virtual void getNodeHitCount(const int &nodeId, int &hitCount)
Definition: Grid.h:462
virtual void saveVelocityModel(util::DataBuffer &buffer)
Save the Earth model currently in memory, to a DataBuffer.
virtual void setInterpolatorType(const string &interpolatorType)
virtual void getActiveNodeNeighborInfo(const int &nid, vector< int > &neighbors, vector< double > &distance, vector< double > &azimuth)
vector< vector< UncertaintyPIU * > > piu
Definition: Grid.h:510
void reaDataBuffererFromFile(util::DataBuffer &buffer, string dirname, string fileName)
GeoTessPolygon * polygon
Definition: Grid.h:505
virtual int getActiveNodeId(int nodeId)
Retrieve the grid node id that corresponds to a specified active node id.
Definition: Grid.h:403
virtual void saveVelocityModel(const string &filename, const int &format)
Save the Earth model currently in memory, to an ascii flat file.
Grid()
Default constructor.
virtual int addGeoStack(GeoStack *geoStack)
virtual double getAverageMantleVelocity(const int &waveType)
Retrieve the average P or S wave velocity of the mantle, in km/sec.
virtual void clear()
Clears and releases all memory held by this Grid object.
virtual void getNodeNeighborInfo(const int &nodeId, vector< int > &neighbors, vector< double > &distance, vector< double > &azimuth)
Retrieve the grid node id of the nodes that are direct neighbors of the specified grid node.
virtual void loadFromFile(const string &filename)
Load the depth, velocity and gradient information from an ascii flat file.
virtual int getNActiveNodes()
Retrieve the number of active nodes.
Definition: Grid.h:386
virtual void getActiveNodeNeighbors(const int &nodeid, vector< int > &neighbors)
virtual GeoTessModelSLBM * getModel()
Definition: Grid.h:487
GeoTessModelSLBM * model
Definition: Grid.h:503
UncertaintyPIU & getUncertaintyPIU(int phase, int attribute)
Definition: Grid.h:303
CrustalProfileStore * sources
Definition: Grid.h:507
virtual void loadFromDataBuffer(util::DataBuffer &buffer)
Load the depth, velocity and gradient information from DataBuffer.
virtual ~Grid()
Destructor.
virtual void getNodeNeighborInfo(const int &nodeId, int neighbors[], double distance[], double azimuth[], int &nNeighbors)
Retrieve the grid node id of the nodes that are direct neighbors of the specified grid node.
vector< GridProfile * > profiles
The GridProfile objects which constitute the nodes in a Grid object.
Definition: Grid.h:499
virtual void loadFromDirectory(const string &dirName)
Load the depth, velocity and gradient information from binary files in specified directory.
virtual bool is_directory(const string &dir)
vector< UncertaintyPDU * > & getUncertaintyPDU()
Definition: Grid.h:309
virtual int getNNodes()
Retrieve the number of nodes in the model.
Definition: Grid.h:173
vector< int > activeNodes
Definition: Grid.h:501
const string getOutputDirectory()
Definition: Grid.h:483
string modelPath
The name of the file or directory from which the velocity model was loaded.
Definition: Grid.h:494
void initializeActiveNodes(GeoTessPolygon *polygon)
Specify the Polygon that will define which grid nodes are also active nodes.
string & getModelPath()
Definition: Grid.h:475
vector< vector< UncertaintyPIU * > > & getUncertaintyPIU()
Definition: Grid.h:295
virtual void getNodeNeighbors(const int &nodeId, vector< int > &neighbors)
Retrieve the grid node ids of the nodes that are direct neighbors of the specified grid node.
virtual void getNodeSeparation(const int &node1, const int &node2, double &distance)
Retrieve the angular separation in radians between any pair of.
virtual string toString()
virtual string getTessId()
virtual int getGridNodeId(int activeNodeId)
Retrieve the grid node id that corresponds to a specified active node id.
Definition: Grid.h:395
virtual size_t memSize()
virtual void setAverageMantleVelocity(const int &waveType, const double &velocity)
Retrieve the average P or S wave velocity of the mantle, in km/sec.
virtual bool findProfile(Location &location, vector< GridProfile * > &neighbors, vector< int > &nodeIds, vector< double > &coefficients)
Find the neighboring GridProfile objects and associated interpolation coefficients at a specified Loc...
virtual int getNIntervals()
Retrieve the number of intervals in each Profile.
Definition: Grid.h:179
UncertaintyPDU & getUncertaintyPDU(int phase)
Definition: Grid.h:316
static Grid * getGrid(util::DataBuffer &buffer)
static string class_name()
Definition: Grid.h:124
vector< UncertaintyPDU * > pdu
Definition: Grid.h:512
void clearActiveNodes()
virtual void getActiveNodeNeighbors(const int &nodeid, int neighbors[], int &nNeighbors)
virtual GreatCircle * getGreatCircle(const int &phase, const double &latSource, const double &lonSource, const double &depthSource, const double &latReceiver, const double &lonReceiver, const double &depthReceiver, const double &delta, const double &ch_max)
Retrieve a GreatCircle object between a source and a receiver.
void initializeActiveNodes(double activeNodeLatMin, double activeNodeLonMin, double activeNodeLatMax, double activeNodeLonMax)
Specify the latitude, longitude range in radians that will define which grid nodes are also active no...
virtual string getInterpolatorType()
virtual int getBufferSize() const
virtual void getNodeAzimuth(const int &node1, const int &node2, double &azimuth)
Retrieve the azimuth in radians from one grid node to another.
CrustalProfileStore * receivers
Definition: Grid.h:508
virtual void getActiveNodeNeighborInfo(const int &nid, int neighbors[], double distance[], double azimuth[], int &nNeighbors)
vector< vector< UncertaintyPIU * > > & getUncertainty()
Definition: Grid.h:294
void specifyOutputDirectory(const string &outputDir)
Manages all information related to a single node in a Grid object.
Definition: GridProfile.h:71
A LayerProfile with mantle velocity gradient information.
Definition: LayerProfileG.h:64
A Profile object based on values interpolated from nearby GridProfile objects.
Definition: LayerProfile.h:76
The Location Class manages a single point in/on the Earth, which is described by the GRS80 ellipsoid.
Definition: Location.h:78
An InterpolatedProfile object that also has information about the the P and S wave velocity as a func...
Definition: QueryProfile.h:68
An Exception class for Grid and related objects.
Definition: SLBMException.h:55
A UncertaintyPDU object contains the raw data to calculate a path dependent modeling error in seconds...
A UncertaintyPIU object contains the raw data to calculate a modeling error in seconds as a function ...
A byte array container used to hold binary data in the same manner as disk based file system.
Definition: DataBuffer.h:81