RSTT 3.2.1 Regional Seismic Travel Time

Loading...
Searching...
No Matches
GridGeoTess.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/*
39 * GridGeoTess.h
40 *
41 * Created on: Sep 25, 2012
42 * Author: sballar
43 */
44
45#ifndef GRIDGEOTESS_H_
46#define GRIDGEOTESS_H_
47
48#include <map>
49
50#include "Grid.h"
51#include "GeoTessModelSLBM.h"
52#include "GeoTessPosition.h"
53#include "GridProfileGeoTess.h"
54
55 using namespace std;
56 using namespace geotess;
57
58 namespace slbm {
59
60 class SLBM_EXP_IMP GridGeoTess: public Grid
61{
62 public:
63
67 GridGeoTess();
68
72 // GridGeoTess(const GridGeoTess &other);
73
77 // Grid *clone() { return new GridGeoTess(*this); }
78
82 virtual ~GridGeoTess();
83
87 static string class_name() { return "GridGeoTess"; };
88
92 string getGridType() { return class_name(); };
93
94 GeoTessModelSLBM* loadModel(const string& filename, const string& relGridPath = "");
95
99 void clear();
100
106 void loadFromFile(const string& filename);
107
113 void loadFromDirectory(const string& dirName);
114
115 void loadFromDataBuffer(util::DataBuffer& buffer);
116
123 void saveVelocityModel(const string& filename, const int& format);
124
129 void saveVelocityModel(util::DataBuffer& buffer);
130
136 int getBufferSize() const { return model->getBufferSize(); };
137
144 double getAverageMantleVelocity(const int& waveType)
145 {return model->getAverageMantleVelocity(waveType); };
146
153 void setAverageMantleVelocity(const int& waveType, const double& velocity)
154 {model->setAverageMantleVelocity(waveType, velocity); };
155
175 virtual bool findProfile(Location& location,
176 vector<GridProfile*>& neighbors, vector<int>& nodeIds,
177 vector<double>& coefficients);
178
179// //! \brief Specify the latitude, longitude range that will define
180// //! which grid nodes are also active nodes.
181// //!
182// //! Specify the latitude, longitude range that will define
183// //! which grid nodes are also active nodes. Active nodes are defined
184// //! as follows: Each triangle in the tessellation is visited. If any
185// //! one of the three nodes which define the triangle is located within
186// //! the specified latitude, longitude range, then all three of the
187// //! nodes are active nodes.
188// void initializeActiveNodes(double activeNodeLatMin,
189// double activeNodeLonMin,
190// double activeNodeLatMax,
191// double activeNodeLonMax);
192
198 void getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors);
199
205 void getNodeNeighbors(const int& nodeId, vector<int>& neighbors);
206
207 void getActiveNodeNeighbors(const int& nodeid, int neighbors[], int& nNeighbors);
208
209 void getActiveNodeNeighbors(const int& nodeid, vector<int>& neighbors);
210
218 void getNodeNeighborInfo(const int& nodeid, int neighbors[],
219 double distance[], double azimuth[], int& nNeighbors)
220 {
221 set<int> nbrs;
222 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
223 nodeid, nbrs);
224
225 nNeighbors = (int)nbrs.size();
226 int nid, i=0;
227 for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
228 {
229 nid = profiles[*it]->getNodeId();
230
231 neighbors[i]=nid;
232
233 distance[i] = GeoTessUtils::angle(model->getGrid().getVertex(nodeid),
234 model->getGrid().getVertex(nid));
235
236 azimuth[i] = GeoTessUtils::azimuth(model->getGrid().getVertex(nodeid),
237 model->getGrid().getVertex(nid), NA_VALUE);
238
239 ++i;
240 }
241 }
242
243 void getNodeNeighborInfo(const int& nodeid, vector<int>& neighbors,
244 vector<double>& distance, vector<double>& azimuth)
245 {
246 set<int> nbrs;
247 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
248 nodeid, nbrs);
249
250 int nNeighbors = (int)nbrs.size();
251 neighbors.clear();
252 distance.clear();
253 azimuth.clear();
254 neighbors.reserve(nNeighbors);
255 distance.reserve(nNeighbors);
256 azimuth.reserve(nNeighbors);
257 int nid;
258 for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
259 {
260 nid = profiles[*it]->getNodeId();
261
262 neighbors.push_back(nid);
263
264 distance.push_back(GeoTessUtils::angle(model->getGrid().getVertex(nodeid),
265 model->getGrid().getVertex(nid)));
266
267 azimuth.push_back(GeoTessUtils::azimuth(model->getGrid().getVertex(nodeid),
268 model->getGrid().getVertex(nid), NA_VALUE));
269 }
270 }
271
273 // grid nodes.
276 // grid nodes.
277 void getNodeSeparation(const int& node1, const int& node2, double& distance);
278
282 void getNodeAzimuth(const int& node1, const int& node2, double& azimuth);
283
284 size_t memSize();
285
286 string getTessId() { return model->getGrid().getGridID(); }
287
288 int addGeoStack(GeoStack* geoStack)
289 { return 0; };
290
291 GeoTessModelSLBM* getModel() { return model; }
292
293 string toString();
294
295 void setInterpolatorType(const string& interpolatorType);
296
297 string getInterpolatorType() { return position->getInterpolatorType().toString(); }
298
299 GeoTessPosition* getPosition() { return position; }
300
301 private:
302
303 GeoTessModelSLBM* model;
304
305 GeoTessPosition* position;
306
307};
308
309 inline void GridGeoTess::setInterpolatorType(const string& interpolatorType)
310{
311 string type = CPPUtils::uppercase_string(interpolatorType);
312 if (position->getInterpolatorType().toString() != type)
313 {
314 if (type == "LINEAR")
315 {
316 delete position;
317 position = model->getPosition(GeoTessInterpolatorType::LINEAR);
318 }
319 else if (type == "NATURAL_NEIGHBOR")
320 {
321 delete position;
322 position = model->getPosition(GeoTessInterpolatorType::NATURAL_NEIGHBOR);
323 }
324 else
325 {
326 ostringstream os;
327 os << endl << "ERROR in GridGeoTess::setInterpolatorType()" << endl
328 << interpolatorType << " is not a recognized interpolator type." << endl
329 << "Must be one of [ LINEAR | NATURAL_NEIGHBOR ]."
330 << "Version " << SlbmVersion << " File " << __FILE__ << " line " << __LINE__ << endl << endl;
331 throw SLBMException(os.str(),114);
332 }
333 }
334}
335
336 inline void GridGeoTess::getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors)
337{
338 set<int> nbrs;
339 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
340 nodeId, nbrs);
341 nNeighbors = (int)nbrs.size();
342 set<int>::iterator it;
343 int i=0;
344 for (it=nbrs.begin(); it != nbrs.end(); ++it)
345 neighbors[i++] = *it;
346}
347
348 inline void GridGeoTess::getNodeNeighbors(const int& nodeId, vector<int>& neighbors)
349{
350 set<int> nbrs;
351 const int level = model->getGrid().getLastLevel(0);
352 model->getGrid().getVertexNeighbors(0, level, nodeId, nbrs);
353 neighbors.resize(nbrs.size());
354 set<int>::iterator it;
355 int i=0;
356 for (it=nbrs.begin(); it != nbrs.end(); ++it)
357 neighbors[i++] = *it;
358}
359
360 inline void GridGeoTess::getActiveNodeNeighbors(const int& activeNodeId, int neighbors[], int& nNeighbors)
361{
362 int nodeId = getGridNodeId(activeNodeId);
363 if (nodeId < 0)
364 nNeighbors = 0;
365 else
366 {
367 set<int> nbrs;
368 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
369 nodeId, nbrs);
370 nNeighbors = 0;
371 int id;
372 for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
373 {
374 id = getActiveNodeId(profiles[*it]->getNodeId());
375 if (id >= 0)
376 neighbors[nNeighbors++] = id;
377 }
378 }
379}
380
381 inline void GridGeoTess::getActiveNodeNeighbors(const int& activeNodeId, vector<int>& neighbors)
382{
383 neighbors.clear();
384
385 int nodeId = getGridNodeId(activeNodeId);
386 if (nodeId >= 0)
387 {
388 set<int> nbrs;
389 model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
390 nodeId, nbrs);
391 int id;
392 for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
393 {
394 id = getActiveNodeId(profiles[*it]->getNodeId());
395 if (id >= 0)
396 neighbors.push_back(id);
397 }
398 }
399}
400
401 inline void GridGeoTess::getNodeSeparation(const int& node1, const int& node2, double& distance)
402{
403 distance = GeoTessUtils::angle(model->getGrid().getVertex(node1),
404 model->getGrid().getVertex(node2));
405}
406
407 inline void GridGeoTess::getNodeAzimuth(const int& node1, const int& node2, double& azimuth)
408{
409 azimuth = GeoTessUtils::azimuth(model->getGrid().getVertex(node1),
410 model->getGrid().getVertex(node2), NaN_DOUBLE);
411}
412
413} /* namespace slbm */
414#endif /* GRIDGEOTESS_H_ */
GeoTessModelSLBM.h
Grid.h
GridProfileGeoTess.h
SLBM_EXP_IMP
#define SLBM_EXP_IMP
Definition SLBMGlobals.h:180
slbm::GeoStack
Manages all information related to a single node in a Grid object.
Definition GeoStack.h:65
slbm::GeoTessModelSLBM
Definition GeoTessModelSLBM.h:84
slbm::GridGeoTess::loadFromFile
void loadFromFile(const string &filename)
Load the depth, velocity and gradient information from an ascii flat file.
slbm::GridGeoTess::addGeoStack
int addGeoStack(GeoStack *geoStack)
Definition GridGeoTess.h:288
slbm::GridGeoTess::getActiveNodeNeighbors
void getActiveNodeNeighbors(const int &nodeid, int neighbors[], int &nNeighbors)
Definition GridGeoTess.h:360
slbm::GridGeoTess::clear
void clear()
Clears and releases all memory held by this GridSLBM object.
slbm::GridGeoTess::getNodeNeighborInfo
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.
Definition GridGeoTess.h:243
slbm::GridGeoTess::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.
Definition GridGeoTess.h:336
slbm::GridGeoTess::memSize
size_t memSize()
slbm::GridGeoTess::setAverageMantleVelocity
void setAverageMantleVelocity(const int &waveType, const double &velocity)
Retreive the average P or S wave velocity of the mantle, in km/sec.
Definition GridGeoTess.h:153
slbm::GridGeoTess::getGridType
string getGridType()
Returns the type of Grid.
Definition GridGeoTess.h:92
slbm::GridGeoTess::getBufferSize
int getBufferSize() const
Returns the size of a DataBuffer object required to store this Grid objects model data.
Definition GridGeoTess.h:136
slbm::GridGeoTess::loadModel
GeoTessModelSLBM * loadModel(const string &filename, const string &relGridPath="")
slbm::GridGeoTess::saveVelocityModel
void saveVelocityModel(util::DataBuffer &buffer)
Save the Earth model currently in memory, to a DataBuffer.
slbm::GridGeoTess::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::GridGeoTess::getInterpolatorType
string getInterpolatorType()
Definition GridGeoTess.h:297
slbm::GridGeoTess::setInterpolatorType
void setInterpolatorType(const string &interpolatorType)
Definition GridGeoTess.h:309
slbm::GridGeoTess::getTessId
string getTessId()
Definition GridGeoTess.h:286
slbm::GridGeoTess::class_name
static string class_name()
Returns the class name.
Definition GridGeoTess.h:87
slbm::GridGeoTess::getNodeSeparation
void getNodeSeparation(const int &node1, const int &node2, double &distance)
Retrieve the angular separation in radians between any pair of.
Definition GridGeoTess.h:401
slbm::GridGeoTess::GridGeoTess
GridGeoTess()
Constructor.
slbm::GridGeoTess::getAverageMantleVelocity
double getAverageMantleVelocity(const int &waveType)
Retreive the average P or S wave velocity of the mantle, in km/sec.
Definition GridGeoTess.h:144
slbm::GridGeoTess::loadFromDataBuffer
void loadFromDataBuffer(util::DataBuffer &buffer)
Load the depth, velocity and gradient information from DataBuffer.
slbm::GridGeoTess::getNodeNeighborInfo
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.
Definition GridGeoTess.h:218
slbm::GridGeoTess::getModel
GeoTessModelSLBM * getModel()
Definition GridGeoTess.h:291
slbm::GridGeoTess::loadFromDirectory
void loadFromDirectory(const string &dirName)
Load the depth, velocity and gradient information from binary files in specified directory.
slbm::GridGeoTess::~GridGeoTess
virtual ~GridGeoTess()
Copy constructor.
slbm::GridGeoTess::saveVelocityModel
void saveVelocityModel(const string &filename, const int &format)
Save the Earth model currently in memory, to an ascii flat file.
slbm::GridGeoTess::getNodeAzimuth
void getNodeAzimuth(const int &node1, const int &node2, double &azimuth)
Retrieve the azimuth in radians from one grid node to another.
Definition GridGeoTess.h:407
slbm::GridGeoTess::toString
string toString()
slbm::GridGeoTess::getPosition
GeoTessPosition * getPosition()
Definition GridGeoTess.h:299
slbm::Grid::getActiveNodeId
virtual int getActiveNodeId(int nodeId)
Retrieve the grid node id that corresponds to a specified active node id.
Definition Grid.h:414
slbm::Grid::Grid
Grid()
Default constructor.
slbm::Grid::profiles
vector< GridProfile * > profiles
The GridProfile objects which constitute the nodes in a Grid object.
Definition Grid.h:520
slbm::Grid::getGridNodeId
virtual int getGridNodeId(int activeNodeId)
Retrieve the grid node id that corresponds to a specified active node id.
Definition Grid.h:406
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
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