RSTT: rstt/SLBM/include/Grid.h Source File

RSTT 3.1.0 Regional Seismic Travel Time

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 "Uncertainty.h"
64 #include "UncertaintyPathDep.h"
65 #include "GeoTessPolygon.h"
66
67 #include "DataBuffer.h"
68 #include "MD50.h"
69
70 // **** _BEGIN SLBM NAMESPACE_ **************************************************
71
72 namespace slbm {
73
89 class SLBM_EXP_IMP Grid
90 {
91
92 public:
93
97 Grid();
98
102 virtual ~Grid();
103
104 static Grid* getGrid(const string& modelDirectory);
105
106 static Grid* getGrid(util::DataBuffer& buffer);
107
108 static bool fileExists(const string& fileName);
109
113 virtual bool operator == (const Grid& other);
114
118 virtual bool operator != (const Grid& other) {return !(*this == other);};
119
123 static string class_name() {return "Grid"; };
124
128 virtual void clear();
129
135 virtual void loadFromFile(const string& filename) = ABSTRACT;
136
142 virtual void loadFromDirectory(const string& dirName) = ABSTRACT;
143
149 virtual void loadFromDataBuffer(util::DataBuffer& buffer) = ABSTRACT;
150
155 virtual void saveVelocityModel(util::DataBuffer& buffer) = ABSTRACT;
156
163 virtual void saveVelocityModel(const string& filename, const int& format) = ABSTRACT;
164
165 virtual int getBufferSize() const = ABSTRACT;
166
167 virtual bool is_directory(const string& dir);
168
172 virtual int getNNodes() { return profiles.size(); }
173
178 virtual int getNIntervals() { return NLAYERS;};
179
186 virtual GridProfile* getProfile(const int& nodeId);
187
215 virtual GreatCircle* getGreatCircle(
216 const int& phase,
217 const double& latSource,
218 const double& lonSource,
219 const double& depthSource,
220 const double& latReceiver,
221 const double& lonReceiver,
222 const double& depthReceiver,
223 const double& delta,
224 const double& ch_max);
225
243 //CrustalProfile* getCrustalProfile(const int& phase,
244 // const double& lat, const double& lon, const double& depth);
245
246 virtual CrustalProfile* getReceiverProfile(const int& phase,
247 const double& lat, const double& lon, const double& depth);
248
249 virtual CrustalProfile* getSourceProfile(const int& phase,
250 const double& lat, const double& lon, const double& depth);
251
255 virtual void clearCrustalProfiles();
256
274 virtual LayerProfile* getLayerProfile(GreatCircle* greatCircle,
275 Location& location);
276
286 virtual QueryProfile* getQueryProfile(Location& location);
287
293 vector<vector<Uncertainty*> >& getUncertainty() { return uncertainty; }
294
301 Uncertainty& getUncertainty(int phase, int attribute) { return *uncertainty[phase][attribute]; }
302
307 vector<UncertaintyPathDep*>& getUncertaintyPathDep() { return uncertaintyPathDep; }
308
314 UncertaintyPathDep& getUncertaintyPathDep(int phase) { return *uncertaintyPathDep[phase]; }
315
322 virtual double getAverageMantleVelocity(const int& waveType) = ABSTRACT;
323
330 virtual void setAverageMantleVelocity(const int& waveType, const double& velocity) = ABSTRACT;
331
332 virtual int getNCrustalProfiles();
333
353 virtual bool findProfile(Location& location,
354 vector<GridProfile*>& neighbors, vector<int>& nodeIds,
355 vector<double>& coefficients) = ABSTRACT;
356
366 void initializeActiveNodes(double activeNodeLatMin,
367 double activeNodeLonMin,
368 double activeNodeLatMax,
369 double activeNodeLonMax);
370
379 void initializeActiveNodes(GeoTessPolygon* polygon);
380
384 virtual int getNActiveNodes() { return activeNodes.size(); };
385
386 void clearActiveNodes();
387
393 virtual int getGridNodeId(int activeNodeId)
394 { return (activeNodeId < 0 ? -1 : activeNodes[activeNodeId]); };
395
401 virtual int getActiveNodeId(int nodeId)
402 { return profiles[nodeId]->getActiveNodeId(); };
403
409 virtual void getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors) = ABSTRACT;
410
416 virtual void getNodeNeighbors(const int& nodeId, vector<int>& neighbors) = ABSTRACT;
417
425 virtual void getNodeNeighborInfo(const int& nodeId, int neighbors[],
426 double distance[], double azimuth[], int& nNeighbors);
427
435 virtual void getNodeNeighborInfo(const int& nodeId, vector<int>& neighbors,
436 vector<double>& distance, vector<double>& azimuth);
437
438 virtual void getActiveNodeNeighbors(const int& nodeid, int neighbors[], int& nNeighbors) = ABSTRACT;
439
440 virtual void getActiveNodeNeighbors(const int& nodeid, vector<int>& neighbors) = ABSTRACT;
441
442 virtual void getActiveNodeNeighborInfo(const int& nid, int neighbors[],
443 double distance[], double azimuth[], int& nNeighbors);
444
445 virtual void getActiveNodeNeighborInfo(const int& nid, vector<int>& neighbors,
446 vector<double>& distance, vector<double>& azimuth);
447
449 // grid nodes.
452 // grid nodes.
453 virtual void getNodeSeparation(const int& node1, const int& node2, double& distance);
454
458 virtual void getNodeAzimuth(const int& node1, const int& node2, double& azimuth);
459
460 virtual void getNodeHitCount(const int& nodeId, int& hitCount)
461 { hitCount = profiles[nodeId]->getHitCount(); };
462
463 virtual void clearNodeHitCount();
464
465 virtual int addGeoStack(GeoStack* geoStack) = ABSTRACT;
466
467 virtual size_t memSize() = ABSTRACT;
468
469 virtual size_t memSizeCrustalProfiles();
470
471 virtual string getTessId() = ABSTRACT;
472
473 string& getModelPath() { return modelPath; }
474
475 virtual string toString() = ABSTRACT;
476
477 virtual void setInterpolatorType(const string& interpolatorType) = ABSTRACT;
478
479 virtual string getInterpolatorType() = ABSTRACT;
480
481 const string getOutputDirectory() { return outputDirectory; }
482
483 void specifyOutputDirectory(const string& outputDir);
484
485 protected:
486
490 string modelPath;
491
495 vector<GridProfile*> profiles;
496
497 vector<int> activeNodes;
498
499 GeoTessPolygon* polygon;
500
501 CrustalProfileStore* sources;
502 CrustalProfileStore* receivers;
503
504 vector<vector<Uncertainty*> > uncertainty;
505
506 vector<UncertaintyPathDep*> uncertaintyPathDep;
507
508 void writeBufferToFile(util::DataBuffer& buffer, string fileName);
509
510 void reaDataBuffererFromFile(util::DataBuffer& buffer, string dirname,
511 string fileName);
512
513 private:
514
515 string outputDirectory;
516
517
518 };
519
520 inline GridProfile* Grid::getProfile(const int& n)
521 {
522 if (n < 0 || n >= (int)profiles.size())
523 {
524 ostringstream os;
525 os << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(4);
526 os << endl << "ERROR in Grid::getProfile. NodeId "<< n << " is out of range. " << endl
527 << "Valid range is >= 0 and < " << profiles.size() << endl
528 << "Version " << SlbmVersion << " File " << __FILE__ << " line " << __LINE__ << endl << endl;
529 throw SLBMException(os.str(),107);
530 }
531 return profiles[n];
532 }
533
534 inline LayerProfile* Grid::getLayerProfile(GreatCircle* gc,
535 Location& location)
536 {
537 if (gc->getPhase()/2 == 0)
538 // for Pn or Sn, return a LayerProfile with gradient info.
539 return new LayerProfileG(gc, location);
540 else
541 // for Pg or Lg, return a LayerProfile without gradient info.
542 return new LayerProfile(gc, location);
543 }
544
545 inline QueryProfile* Grid::getQueryProfile(Location& location)
546 {
547 return new QueryProfile(*this, location);
548 }
549
550 inline CrustalProfile* Grid::getSourceProfile(const int& phase,
551 const double& lat, const double& lon, const double& depth)
552 {
553 return sources->getCrustalProfile(phase, lat, lon, depth);
554 }
555
556 inline CrustalProfile* Grid::getReceiverProfile(const int& phase,
557 const double& lat, const double& lon, const double& depth)
558 {
559 return receivers->getCrustalProfile(phase, lat, lon, depth);
560 }
561
562 inline void Grid::clearCrustalProfiles()
563 {
564 receivers->clear();
565 sources->clear();
566 }
567
568 inline int Grid::getNCrustalProfiles()
569 {
570 return receivers->getNCrustalProfiles()
571 + sources->getNCrustalProfiles();
572 }
573
574 inline size_t Grid::memSizeCrustalProfiles()
575 {
576 return receivers->memSize() + sources->memSize();
577 }
578
579 inline void Grid::clearNodeHitCount()
580 {
581 for (int i=0; i<(int)profiles.size(); ++i)
582 profiles[i]->clearHitCount();
583 }
584
585 inline bool Grid::fileExists(const string& fileName)
586 {
587 fstream f;
588
589 f.open(fileName.c_str(), ios::in);
590 if (f.is_open())
591 {
592 f.close();
593 return true;
594 }
595 return false;
596 }
597
598
599 } // end slbm namespace
600
601 #endif // GRID_H
slbm::Grid::toString
virtual string toString()
Triangle.h
slbm::Grid::memSize
virtual size_t memSize()
slbm::Grid::getActiveNodeId
virtual int getActiveNodeId(int nodeId)
Retrieve the grid node id that corresponds to a specified active node id.
Definition: Grid.h:401
CrustalProfileStore.h
slbm::Grid::class_name
static string class_name()
Definition: Grid.h:123
slbm::QueryProfile
An InterpolatedProfile object that also has information about the the P and S wave velocity as a func...
Definition: QueryProfile.h:68
GreatCircle.h
slbm::GeoStack
Manages all information related to a single node in a Grid object.
Definition: GeoStack.h:65
slbm::Grid::is_directory
virtual bool is_directory(const string &dir)
slbm::Grid::getActiveNodeNeighbors
virtual void getActiveNodeNeighbors(const int &nodeid, vector< int > &neighbors)
slbm::Grid::getNodeAzimuth
virtual void getNodeAzimuth(const int &node1, const int &node2, double &azimuth)
Retrieve the azimuth in radians from one grid node to another.
slbm::Grid::getNodeNeighbors
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.
slbm::Grid::findProfile
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...
slbm::Location
The Location Class manages a single point in/on the Earth, which is described by the GRS80 ellipsoid.
Definition: Location.h:78
SLBMException.h
slbm::Grid::modelPath
string modelPath
The name of the file or directory from which the velocity model was loaded.
Definition: Grid.h:490
slbm::Grid::getAverageMantleVelocity
virtual double getAverageMantleVelocity(const int &waveType)
Retrieve the average P or S wave velocity of the mantle, in km/sec.
slbm::Grid::getNNodes
virtual int getNNodes()
Retrieve the number of nodes in the model.
Definition: Grid.h:172
slbm::Grid::initializeActiveNodes
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...
UncertaintyPathDep.h
slbm::Grid::Grid
Grid()
Default constructor.
GreatCircleFactory.h
slbm::Grid::clearActiveNodes
void clearActiveNodes()
slbm::Grid::getUncertainty
vector< vector< Uncertainty * > > & getUncertainty()
Definition: Grid.h:293
CrustalProfile.h
slbm::Grid::saveVelocityModel
virtual void saveVelocityModel(const string &filename, const int &format)
Save the Earth model currently in memory, to an ascii flat file.
slbm::LayerProfileG
A LayerProfile with mantle velocity gradient information.
Definition: LayerProfileG.h:64
LayerProfile.h
slbm::Grid::getActiveNodeNeighborInfo
virtual void getActiveNodeNeighborInfo(const int &nid, int neighbors[], double distance[], double azimuth[], int &nNeighbors)
Uncertainty.h
slbm::Grid::specifyOutputDirectory
void specifyOutputDirectory(const string &outputDir)
slbm::Grid::getNIntervals
virtual int getNIntervals()
Retrieve the number of intervals in each Profile.
Definition: Grid.h:178
slbm::Grid::getGrid
static Grid * getGrid(const string &modelDirectory)
slbm::Grid::receivers
CrustalProfileStore * receivers
Definition: Grid.h:502
slbm::Grid::uncertainty
vector< vector< Uncertainty * > > uncertainty
Definition: Grid.h:504
SLBMGlobals.h
slbm::GridProfile
Manages all information related to a single node in a Grid object.
Definition: GridProfile.h:71
slbm::CrustalProfile
A profile through the Earth model that stores interface radius, and interval P or S wave velocity inf...
Definition: CrustalProfile.h:101
slbm::Grid::getUncertaintyPathDep
vector< UncertaintyPathDep * > & getUncertaintyPathDep()
Definition: Grid.h:307
slbm::Grid::loadFromFile
virtual void loadFromFile(const string &filename)
Load the depth, velocity and gradient information from an ascii flat file.
slbm::Grid::getActiveNodeNeighborInfo
virtual void getActiveNodeNeighborInfo(const int &nid, vector< int > &neighbors, vector< double > &distance, vector< double > &azimuth)
slbm::Grid::getNActiveNodes
virtual int getNActiveNodes()
Retrieve the number of active nodes.
Definition: Grid.h:384
slbm::Grid
A 2 dimensional, horizontal grid of GirdProfile objects.
Definition: Grid.h:90
InterpolatedProfile.h
slbm::Grid::uncertaintyPathDep
vector< UncertaintyPathDep * > uncertaintyPathDep
Definition: Grid.h:506
slbm::Grid::getUncertaintyPathDep
UncertaintyPathDep & getUncertaintyPathDep(int phase)
Definition: Grid.h:314
slbm::Grid::loadFromDirectory
virtual void loadFromDirectory(const string &dirName)
Load the depth, velocity and gradient information from binary files in specified directory.
slbm::Grid::reaDataBuffererFromFile
void reaDataBuffererFromFile(util::DataBuffer &buffer, string dirname, string fileName)
slbm::Grid::~Grid
virtual ~Grid()
Destructor.
slbm::LayerProfile
A Profile object based on values interpolated from nearby GridProfile objects.
Definition: LayerProfile.h:76
slbm::Grid::getBufferSize
virtual int getBufferSize() const
slbm::CrustalProfileStore
CrustalProfileStore supports pool allocation for CrustalProfile objects.
Definition: CrustalProfileStore.h:108
slbm::Grid::setAverageMantleVelocity
virtual void setAverageMantleVelocity(const int &waveType, const double &velocity)
Retrieve the average P or S wave velocity of the mantle, in km/sec.
slbm::Grid::getNodeSeparation
virtual void getNodeSeparation(const int &node1, const int &node2, double &distance)
Retrieve the angular separation in radians between any pair of.
slbm::Grid::getInterpolatorType
virtual string getInterpolatorType()
slbm::GreatCircle::getPhase
int getPhase()
Retrieve the phase that this GreatCircle supports. Will be one of SLBMGlobals::Pn,...
Definition: GreatCircle.h:173
slbm::Grid::addGeoStack
virtual int addGeoStack(GeoStack *geoStack)
GridProfile.h
SLBM_EXP_IMP
#define SLBM_EXP_IMP
Definition: SLBMGlobals.h:180
Location.h
slbm::Grid::getGridNodeId
virtual int getGridNodeId(int activeNodeId)
Retrieve the grid node id that corresponds to a specified active node id.
Definition: Grid.h:393
slbm::Grid::profiles
vector< GridProfile * > profiles
The GridProfile objects which constitute the nodes in a Grid object.
Definition: Grid.h:495
slbm::Grid::getGrid
static Grid * getGrid(util::DataBuffer &buffer)
slbm::Grid::getActiveNodeNeighbors
virtual void getActiveNodeNeighbors(const int &nodeid, int neighbors[], int &nNeighbors)
slbm::Uncertainty
A Uncertainty object contains the raw data to calculate a modeling error in seconds as a function of ...
Definition: Uncertainty.h:73
slbm::Grid::sources
CrustalProfileStore * sources
Definition: Grid.h:501
slbm::Grid::polygon
GeoTessPolygon * polygon
Definition: Grid.h:499
slbm::Grid::getUncertainty
Uncertainty & getUncertainty(int phase, int attribute)
Definition: Grid.h:301
slbm::SLBMException
An Exception class for Grid and related objects.
Definition: SLBMException.h:55
slbm::Grid::getNodeHitCount
virtual void getNodeHitCount(const int &nodeId, int &hitCount)
Definition: Grid.h:460
slbm::Grid::saveVelocityModel
virtual void saveVelocityModel(util::DataBuffer &buffer)
Save the Earth model currently in memory, to a DataBuffer.
slbm::Grid::loadFromDataBuffer
virtual void loadFromDataBuffer(util::DataBuffer &buffer)
Load the depth, velocity and gradient information from DataBuffer.
slbm::Grid::getNodeNeighborInfo
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.
slbm::Grid::getNodeNeighbors
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.
slbm::Grid::clear
virtual void clear()
Clears and releases all memory held by this Grid object.
slbm::UncertaintyPathDep
A UncertaintyPathDep object contains the raw data to calculate a path dependent modeling error in sec...
Definition: UncertaintyPathDep.h:78
slbm::Grid::setInterpolatorType
virtual void setInterpolatorType(const string &interpolatorType)
DataBuffer.h
slbm::Grid::getModelPath
string & getModelPath()
Definition: Grid.h:473
slbm::Grid::initializeActiveNodes
void initializeActiveNodes(GeoTessPolygon *polygon)
Specify the Polygon that will define which grid nodes are also active nodes.
QueryProfile.h
slbm::Grid::activeNodes
vector< int > activeNodes
Definition: Grid.h:497
LayerProfileG.h
slbm::Grid::getOutputDirectory
const string getOutputDirectory()
Definition: Grid.h:481
slbm::Grid::writeBufferToFile
void writeBufferToFile(util::DataBuffer &buffer, string fileName)
slbm::GreatCircle
The GreatCircle class manages information related to a great circle path between two Locations on the...
Definition: GreatCircle.h:115
slbm::Grid::getNodeNeighborInfo
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.
slbm::CrustalProfile::memSize
size_t memSize()
slbm
Definition: CrustalProfile.h:59
MD50.h
util::DataBuffer
A byte array container used to hold binary data in the same manner as disk based file system.
Definition: DataBuffer.h:81
slbm::Grid::getGreatCircle
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.
slbm::Grid::getTessId
virtual string getTessId()