RSTT 3.2.1 Regional Seismic Travel Time

Loading...
Searching...
No Matches
GridSLBM.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 GRIDSLBM_H
39#define GRIDSLBM_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 "Grid.h"
52#include "GridProfile.h"
53#include "InterpolatedProfile.h"
54#include "LayerProfile.h"
55#include "LayerProfileG.h"
56#include "QueryProfile.h"
57#include "CrustalProfile.h"
58#include "CrustalProfileStore.h"
59#include "GreatCircle.h"
60#include "GreatCircleFactory.h"
61#include "Location.h"
62#include "SLBMException.h"
63#include "Triangle.h"
64
65#include "DataBuffer.h"
66#include "MD50.h"
67#include "CPPUtils.h"
68
69// **** _BEGIN SLBM NAMESPACE_ **************************************************
70
71 namespace slbm {
72
88 class SLBM_EXP_IMP GridSLBM : public Grid
89{
90
91 public:
92
96 GridSLBM();
97
101 // GridSLBM(const GridSLBM &other);
102
106 // Grid *clone() { return new GridSLBM(*this); }
107
108
112 ~GridSLBM();
113
117 static string class_name() { return "GridSLBM"; };
118
122 string getGridType() { return class_name(); };
123
127 void clear();
128
134 void loadFromFile(const string& filename);
135
141 void loadFromDirectory(const string& dirName);
142
143 void loadFromDataBuffer(util::DataBuffer& buffer);
144
154 void saveVelocityModel(const string& destination, const int& format);
155
160 void saveVelocityModel(util::DataBuffer& buffer);
161
162 int getBufferSize() const;
163
170 double getAverageMantleVelocity(const int& waveType) {return V0[waveType]; };
171
178 void setAverageMantleVelocity(const int& waveType, const double& velocity)
179 {V0[waveType] = velocity; };
180
200 virtual bool findProfile(Location& location,
201 vector<GridProfile*>& neighbors, vector<int>& nodeIds,
202 vector<double>& coefficients);
203
209 void getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors);
210
216 void getNodeNeighbors(const int& nodeId, vector<int>& neighbors);
217
218 void getActiveNodeNeighbors(const int& nodeid, int neighbors[], int& nNeighbors);
219
220 void getActiveNodeNeighbors(const int& nodeid, vector<int>& neighbors);
221
222 size_t memSize();
223
224 string getTessId() { return tessId; }
225
226 int addGeoStack(GeoStack* geoStack)
227 { geoStacks.push_back(geoStack); return geoStacks.size(); };
228
229 string toString();
230
231 void setInterpolatorType(const string& interpolatorType);
232
233 string getInterpolatorType() { return "linear"; }
234
235 GeoTessPosition* getPosition() { return NULL; }
236
237 private:
238
239 int getGeoStacksSize() { return geoStacks.size(); };
240
241 vector<GeoStack*>& getGeoStacks() { return geoStacks; };
242
243 vector<Triangle*>& getTriangles() { return triangles; };
244
245 void readGeoStacks(util::DataBuffer& buffer);
246
247 void readConnectivity(util::DataBuffer& buffer, int& nNodes,
248 vector<float>& elev, vector<float>& waterThick,
249 vector<int>& stackId);
250
251 void readTessellationData(util::DataBuffer& buffer, int nNodes,
252 const vector<float>& elev,
253 const vector<float>& waterThick,
254 const vector<int>& stackId,
255 vector< vector<Triangle*> >& triset);
256
257 void defineTessAdjacency(int nNodes,
258 const vector< vector<Triangle*> >& triset);
259
260 string tessId;
261
262 vector<GeoStack*> geoStacks;
263
264 vector<Triangle*> triangles;
265
266 vector<Triangle*> specialTriangles;
267
268 double cos_min;
269
274 double V0[2];
275
276 Triangle* findTriangle(const Location& location,
277 vector<double>& coefficients);
278
279 void findSpecialTriangles();
280
281 void saveSlbmFile(const string& fileName);
282 void saveSlbmDirectory(const string& directoryName);
283
284 void saveGeotessFile(const string& fileName);
285 void saveGeotessDirectory(const string& directoryName);
286
287 void saveGeotess(const string& path, const string& pathToGrid, const string& gridFilePath);
288
289};
290
291 inline Triangle* GridSLBM::findTriangle(const Location& location,
292 vector<double>& coefficients)
293{
294 Triangle* tr = NULL;
295
296 double dot, dmax = -1e30;
297 // iterate over all specialTriangles.
298 for (int i=0; i<(int)specialTriangles.size(); i++)
299 {
300 // find the dot product of special triangle node 0
301 // with desired position.
302 dot = location.dot(*specialTriangles[i]->getNode(0));
303
304 // large dot product corresponds to small separation.
305 // if this is closest special triangle so far, save it
306 if (dot > dmax)
307 {
308 // set best triangle to this special triangle.
309 tr = specialTriangles[i];
310 // if this triangle is closer than about 16 degrees
311 // then no closer triangle will be found, so quit.
312 if (dot > cos_min) break;
313 dmax = dot;
314 }
315 }
316
317 // search for the triangle that contains position, starting
318 // from the triangle identified above.
319 tr = tr->walk(location, coefficients);
320
321 // set first special triangle to the triangle that was just found so that
322 // it will be checked first on the next call to findTriangle().
323 specialTriangles[0] = tr;
324
325 return tr;
326}
327
328 inline bool GridSLBM::findProfile(Location& location,
329 vector<GridProfile*>& neighbors, vector<int>& nodeIds,
330 vector<double>& coefficients)
331{
332 neighbors.resize(3);
333 coefficients.resize(3);
334 nodeIds.resize(3);
335
336 Triangle* tr = findTriangle(location, coefficients);
337
338 for (int i=0; i<3; i++)
339 {
340 neighbors[i] = tr->getNode(i);
341 nodeIds[i] = neighbors[i]->getNodeId();
342 }
343
344 return true;
345}
346
347 inline void GridSLBM::setInterpolatorType(const string& interpolatorType)
348{
349 if (geotess::CPPUtils::uppercase_string(interpolatorType) != "LINEAR")
350 {
351 ostringstream os;
352 os << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(9);
353 os << endl << "ERROR in GridSLBM::setInterpolatorType()" << endl
354 << interpolatorType << " is not a recognized interpolator type." << endl
355 << "The only interpolator type recognized by the old style SLBM grids is LINEAR"
356 << "Version " << SlbmVersion << " File " << __FILE__ << " line " << __LINE__ << endl << endl;
357 throw SLBMException(os.str(),114);
358 }
359}
360
361} // end slbm namespace
362
363#endif // GRIDSLBM_H
CrustalProfile.h
CrustalProfileStore.h
DataBuffer.h
GreatCircle.h
GreatCircleFactory.h
Grid.h
GridProfile.h
InterpolatedProfile.h
LayerProfile.h
LayerProfileG.h
Location.h
MD50.h
QueryProfile.h
SLBMException.h
SLBMGlobals.h
SLBM_EXP_IMP
#define SLBM_EXP_IMP
Definition SLBMGlobals.h:180
Triangle.h
slbm::GeoStack
Manages all information related to a single node in a Grid object.
Definition GeoStack.h:65
slbm::Grid::Grid
Grid()
Default constructor.
slbm::GridProfile::getNodeId
const int getNodeId() const
Retrieve the node index of this node in the model grid.
Definition GridProfile.h:99
slbm::GridSLBM::class_name
static string class_name()
Returns the class name.
Definition GridSLBM.h:117
slbm::GridSLBM::setAverageMantleVelocity
void setAverageMantleVelocity(const int &waveType, const double &velocity)
Retreive the average P or S wave velocity of the mantle, in km/sec.
Definition GridSLBM.h:178
slbm::GridSLBM::getGridType
string getGridType()
Returns the type of Grid.
Definition GridSLBM.h:122
slbm::GridSLBM::toString
string toString()
slbm::GridSLBM::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...
Definition GridSLBM.h:328
slbm::GridSLBM::~GridSLBM
~GridSLBM()
Copy constructor.
slbm::GridSLBM::getTessId
string getTessId()
Definition GridSLBM.h:224
slbm::GridSLBM::getNodeNeighbors
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::GridSLBM::getInterpolatorType
string getInterpolatorType()
Definition GridSLBM.h:233
slbm::GridSLBM::loadFromDataBuffer
void loadFromDataBuffer(util::DataBuffer &buffer)
Load the depth, velocity and gradient information from DataBuffer.
slbm::GridSLBM::saveVelocityModel
void saveVelocityModel(util::DataBuffer &buffer)
Save the Earth model currently in memory, to a DataBuffer.
slbm::GridSLBM::saveVelocityModel
void saveVelocityModel(const string &destination, const int &format)
Save the Earth model currently in memory, to file(s).
slbm::GridSLBM::getActiveNodeNeighbors
void getActiveNodeNeighbors(const int &nodeid, int neighbors[], int &nNeighbors)
slbm::GridSLBM::getPosition
GeoTessPosition * getPosition()
Definition GridSLBM.h:235
slbm::GridSLBM::clear
void clear()
Clears and releases all memory held by this GridSLBM object.
slbm::GridSLBM::getActiveNodeNeighbors
void getActiveNodeNeighbors(const int &nodeid, vector< int > &neighbors)
slbm::GridSLBM::memSize
size_t memSize()
slbm::GridSLBM::getNodeNeighbors
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::GridSLBM::getAverageMantleVelocity
double getAverageMantleVelocity(const int &waveType)
Retreive the average P or S wave velocity of the mantle, in km/sec.
Definition GridSLBM.h:170
slbm::GridSLBM::setInterpolatorType
void setInterpolatorType(const string &interpolatorType)
Definition GridSLBM.h:347
slbm::GridSLBM::loadFromFile
void loadFromFile(const string &filename)
Load the depth, velocity and gradient information from an ascii flat file.
slbm::GridSLBM::addGeoStack
int addGeoStack(GeoStack *geoStack)
Definition GridSLBM.h:226
slbm::GridSLBM::loadFromDirectory
void loadFromDirectory(const string &dirName)
Load the depth, velocity and gradient information from binary files in specified directory.
slbm::GridSLBM::getBufferSize
int getBufferSize() const
slbm::GridSLBM::GridSLBM
GridSLBM()
Default constructor.
slbm::Location
The Location Class manages a single point in/on the Earth, which is described by the GRS80 ellipsoid.
Definition Location.h:78
slbm::SLBMException
An Exception class for Grid and related objects.
Definition SLBMException.h:55
slbm::Triangle
Definition Triangle.h:63
slbm::Triangle::getNode
GridProfile * getNode(const int &i)
Retrieve a handle to one of the 3 nodes that defines the corners of this triangle.
Definition Triangle.h:98
slbm::Triangle::walk
Triangle * walk(const Location &position, vector< double > &coefficients)
Definition Triangle.h:161
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
Definition CrustalProfile.h:59