RSTT  3.2.0
Regional Seismic Travel Time
All Classes Namespaces Files Functions Variables Typedefs Friends Macros
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 
61 {
62 public:
63 
65 
69  virtual ~GridGeoTess();
70 
74  static string class_name() { return "GridGeoTess"; };
75 
76  GeoTessModelSLBM* loadModel(const string& filename, const string& relGridPath = "");
77 
81  void clear();
82 
88  void loadFromFile(const string& filename);
89 
95  void loadFromDirectory(const string& dirName);
96 
98 
105  void saveVelocityModel(const string& filename, const int& format);
106 
112 
118  int getBufferSize() const { return model->getBufferSize(); };
119 
126  double getAverageMantleVelocity(const int& waveType)
127  {return model->getAverageMantleVelocity(waveType); };
128 
135  void setAverageMantleVelocity(const int& waveType, const double& velocity)
136  {model->setAverageMantleVelocity(waveType, velocity); };
137 
157  virtual bool findProfile(Location& location,
158  vector<GridProfile*>& neighbors, vector<int>& nodeIds,
159  vector<double>& coefficients);
160 
161 // //! \brief Specify the latitude, longitude range that will define
162 // //! which grid nodes are also active nodes.
163 // //!
164 // //! Specify the latitude, longitude range that will define
165 // //! which grid nodes are also active nodes. Active nodes are defined
166 // //! as follows: Each triangle in the tessellation is visited. If any
167 // //! one of the three nodes which define the triangle is located within
168 // //! the specified latitude, longitude range, then all three of the
169 // //! nodes are active nodes.
170 // void initializeActiveNodes(double activeNodeLatMin,
171 // double activeNodeLonMin,
172 // double activeNodeLatMax,
173 // double activeNodeLonMax);
174 
180  void getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors);
181 
187  void getNodeNeighbors(const int& nodeId, vector<int>& neighbors);
188 
189  void getActiveNodeNeighbors(const int& nodeid, int neighbors[], int& nNeighbors);
190 
191  void getActiveNodeNeighbors(const int& nodeid, vector<int>& neighbors);
192 
200  void getNodeNeighborInfo(const int& nodeid, int neighbors[],
201  double distance[], double azimuth[], int& nNeighbors)
202  {
203  set<int> nbrs;
204  model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
205  nodeid, nbrs);
206 
207  nNeighbors = (int)nbrs.size();
208  int nid, i=0;
209  for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
210  {
211  nid = profiles[*it]->getNodeId();
212 
213  neighbors[i]=nid;
214 
215  distance[i] = GeoTessUtils::angle(model->getGrid().getVertex(nodeid),
216  model->getGrid().getVertex(nid));
217 
218  azimuth[i] = GeoTessUtils::azimuth(model->getGrid().getVertex(nodeid),
219  model->getGrid().getVertex(nid), NA_VALUE);
220 
221  ++i;
222  }
223  }
224 
225  void getNodeNeighborInfo(const int& nodeid, vector<int>& neighbors,
226  vector<double>& distance, vector<double>& azimuth)
227  {
228  set<int> nbrs;
229  model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
230  nodeid, nbrs);
231 
232  int nNeighbors = (int)nbrs.size();
233  neighbors.clear();
234  distance.clear();
235  azimuth.clear();
236  neighbors.reserve(nNeighbors);
237  distance.reserve(nNeighbors);
238  azimuth.reserve(nNeighbors);
239  int nid;
240  for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
241  {
242  nid = profiles[*it]->getNodeId();
243 
244  neighbors.push_back(nid);
245 
246  distance.push_back(GeoTessUtils::angle(model->getGrid().getVertex(nodeid),
247  model->getGrid().getVertex(nid)));
248 
249  azimuth.push_back(GeoTessUtils::azimuth(model->getGrid().getVertex(nodeid),
250  model->getGrid().getVertex(nid), NA_VALUE));
251  }
252  }
253 
255  // grid nodes.
258  // grid nodes.
259  void getNodeSeparation(const int& node1, const int& node2, double& distance);
260 
264  void getNodeAzimuth(const int& node1, const int& node2, double& azimuth);
265 
266  size_t memSize();
267 
268  string getTessId() { return model->getGrid().getGridID(); }
269 
270  int addGeoStack(GeoStack* geoStack)
271  { return 0; };
272 
273  GeoTessModelSLBM* getModel() { return model; }
274 
275  string toString();
276 
277  void setInterpolatorType(const string& interpolatorType);
278 
279  string getInterpolatorType() { return position->getInterpolatorType().toString(); }
280 
281 private:
282 
283  GeoTessModelSLBM* model;
284 
285  GeoTessPosition* position;
286 
287 };
288 
289 inline void GridGeoTess::setInterpolatorType(const string& interpolatorType)
290 {
291  string type = CPPUtils::uppercase_string(interpolatorType);
292  if (position->getInterpolatorType().toString() != type)
293  {
294  if (type == "LINEAR")
295  {
296  delete position;
297  position = model->getPosition(GeoTessInterpolatorType::LINEAR);
298  }
299  else if (type == "NATURAL_NEIGHBOR")
300  {
301  delete position;
302  position = model->getPosition(GeoTessInterpolatorType::NATURAL_NEIGHBOR);
303  }
304  else
305  {
306  ostringstream os;
307  os << endl << "ERROR in GridGeoTess::setInterpolatorType()" << endl
308  << interpolatorType << " is not a recognized interpolator type." << endl
309  << "Must be one of [ LINEAR | NATURAL_NEIGHBOR ]."
310  << "Version " << SlbmVersion << " File " << __FILE__ << " line " << __LINE__ << endl << endl;
311  throw SLBMException(os.str(),114);
312  }
313  }
314 }
315 
316 inline void GridGeoTess::getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors)
317 {
318  set<int> nbrs;
319  model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
320  nodeId, nbrs);
321  nNeighbors = (int)nbrs.size();
322  set<int>::iterator it;
323  int i=0;
324  for (it=nbrs.begin(); it != nbrs.end(); ++it)
325  neighbors[i++] = *it;
326 }
327 
328 inline void GridGeoTess::getNodeNeighbors(const int& nodeId, vector<int>& neighbors)
329 {
330  set<int> nbrs;
331  const int level = model->getGrid().getLastLevel(0);
332  model->getGrid().getVertexNeighbors(0, level, nodeId, nbrs);
333  neighbors.resize(nbrs.size());
334  set<int>::iterator it;
335  int i=0;
336  for (it=nbrs.begin(); it != nbrs.end(); ++it)
337  neighbors[i++] = *it;
338 }
339 
340 inline void GridGeoTess::getActiveNodeNeighbors(const int& activeNodeId, int neighbors[], int& nNeighbors)
341 {
342  int nodeId = getGridNodeId(activeNodeId);
343  if (nodeId < 0)
344  nNeighbors = 0;
345  else
346  {
347  set<int> nbrs;
348  model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
349  nodeId, nbrs);
350  nNeighbors = 0;
351  int id;
352  for (set<int>::iterator it=nbrs.begin(); it != nbrs.end(); it++)
353  {
354  id = getActiveNodeId(profiles[*it]->getNodeId());
355  if (id >= 0)
356  neighbors[nNeighbors++] = id;
357  }
358  }
359 }
360 
361 inline void GridGeoTess::getActiveNodeNeighbors(const int& activeNodeId, vector<int>& neighbors)
362 {
363  neighbors.clear();
364 
365  int nodeId = getGridNodeId(activeNodeId);
366  if (nodeId >= 0)
367  {
368  set<int> nbrs;
369  model->getGrid().getVertexNeighbors(0, model->getGrid().getLastLevel(0),
370  nodeId, nbrs);
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.push_back(id);
377  }
378  }
379 }
380 
381 inline void GridGeoTess::getNodeSeparation(const int& node1, const int& node2, double& distance)
382 {
383  distance = GeoTessUtils::angle(model->getGrid().getVertex(node1),
384  model->getGrid().getVertex(node2));
385 }
386 
387 inline void GridGeoTess::getNodeAzimuth(const int& node1, const int& node2, double& azimuth)
388 {
389  azimuth = GeoTessUtils::azimuth(model->getGrid().getVertex(node1),
390  model->getGrid().getVertex(node2), NaN_DOUBLE);
391 }
392 
393 } /* namespace slbm */
394 #endif /* GRIDGEOTESS_H_ */
#define SLBM_EXP_IMP
Definition: SLBMGlobals.h:180
Manages all information related to a single node in a Grid object.
Definition: GeoStack.h:65
GeoTessModelSLBM * loadModel(const string &filename, const string &relGridPath="")
void loadFromFile(const string &filename)
Load the depth, velocity and gradient information from an ascii flat file.
GeoTessModelSLBM * getModel()
Definition: GridGeoTess.h:273
int addGeoStack(GeoStack *geoStack)
Definition: GridGeoTess.h:270
void clear()
Clears and releases all memory held by this GridSLBM object.
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:225
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:135
int getBufferSize() const
Returns the size of a DataBuffer object required to store this Grid objects model data.
Definition: GridGeoTess.h:118
void saveVelocityModel(util::DataBuffer &buffer)
Save the Earth model currently in memory, to a DataBuffer.
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...
string getInterpolatorType()
Definition: GridGeoTess.h:279
string getTessId()
Definition: GridGeoTess.h:268
static string class_name()
Definition: GridGeoTess.h:74
double getAverageMantleVelocity(const int &waveType)
Retreive the average P or S wave velocity of the mantle, in km/sec.
Definition: GridGeoTess.h:126
void loadFromDataBuffer(util::DataBuffer &buffer)
Load the depth, velocity and gradient information from DataBuffer.
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:200
void loadFromDirectory(const string &dirName)
Load the depth, velocity and gradient information from binary files in specified directory.
virtual ~GridGeoTess()
Destructor.
void saveVelocityModel(const string &filename, const int &format)
Save the Earth model currently in memory, to an ascii flat file.
A 2 dimensional, horizontal grid of GirdProfile objects.
Definition: Grid.h:91
The Location Class manages a single point in/on the Earth, which is described by the GRS80 ellipsoid.
Definition: Location.h:78
An Exception class for Grid and related objects.
Definition: SLBMException.h:55
A byte array container used to hold binary data in the same manner as disk based file system.
Definition: DataBuffer.h:81