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

RSTT 3.1.0 Regional Seismic Travel Time

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 "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
64 #include "DataBuffer.h"
65 #include "MD50.h"
66 #include "CPPUtils.h"
67
68 // **** _BEGIN SLBM NAMESPACE_ **************************************************
69
70 namespace slbm {
71
87 class SLBM_EXP_IMP GridSLBM : public Grid
88 {
89
90 public:
91
95 GridSLBM();
96
100 ~GridSLBM();
101
105 static string class_name() { return "GridSLBM"; };
106
110 void clear();
111
117 void loadFromFile(const string& filename);
118
124 void loadFromDirectory(const string& dirName);
125
126 void loadFromDataBuffer(util::DataBuffer& buffer);
127
137 void saveVelocityModel(const string& destination, const int& format);
138
143 void saveVelocityModel(util::DataBuffer& buffer);
144
145 int getBufferSize() const;
146
153 double getAverageMantleVelocity(const int& waveType) {return V0[waveType]; };
154
161 void setAverageMantleVelocity(const int& waveType, const double& velocity)
162 {V0[waveType] = velocity; };
163
183 virtual bool findProfile(Location& location,
184 vector<GridProfile*>& neighbors, vector<int>& nodeIds,
185 vector<double>& coefficients);
186
192 void getNodeNeighbors(const int& nodeId, int neighbors[], int& nNeighbors);
193
199 void getNodeNeighbors(const int& nodeId, vector<int>& neighbors);
200
201 void getActiveNodeNeighbors(const int& nodeid, int neighbors[], int& nNeighbors);
202
203 void getActiveNodeNeighbors(const int& nodeid, vector<int>& neighbors);
204
205 size_t memSize();
206
207 string getTessId() { return tessId; }
208
209 int addGeoStack(GeoStack* geoStack)
210 { geoStacks.push_back(geoStack); return geoStacks.size(); };
211
212 string toString();
213
214 void setInterpolatorType(const string& interpolatorType);
215
216 string getInterpolatorType() { return "linear"; }
217
218 private:
219
220 int getGeoStacksSize() { return geoStacks.size(); };
221
222 vector<GeoStack*>& getGeoStacks() { return geoStacks; };
223
224 vector<Triangle*>& getTriangles() { return triangles; };
225
226 void readGeoStacks(util::DataBuffer& buffer);
227
228 void readConnectivity(util::DataBuffer& buffer, int& nNodes,
229 vector<float>& elev, vector<float>& waterThick,
230 vector<int>& stackId);
231
232 void readTessellationData(util::DataBuffer& buffer, int nNodes,
233 const vector<float>& elev,
234 const vector<float>& waterThick,
235 const vector<int>& stackId,
236 vector< vector<Triangle*> >& triset);
237
238 void defineTessAdjacency(int nNodes,
239 const vector< vector<Triangle*> >& triset);
240
241 string tessId;
242
243 vector<GeoStack*> geoStacks;
244
245 vector<Triangle*> triangles;
246
247 vector<Triangle*> specialTriangles;
248
249 double cos_min;
250
255 double V0[2];
256
257 Triangle* findTriangle(const Location& location,
258 vector<double>& coefficients);
259
260 void findSpecialTriangles();
261
262 void saveSlbmFile(const string& fileName);
263 void saveSlbmDirectory(const string& directoryName);
264
265 void saveGeotessFile(const string& fileName);
266 void saveGeotessDirectory(const string& directoryName);
267
268 void saveGeotess(const string& path, const string& pathToGrid, const string& gridFilePath);
269
270 };
271
272 inline Triangle* GridSLBM::findTriangle(const Location& location,
273 vector<double>& coefficients)
274 {
275 Triangle* tr = NULL;
276
277 double dot, dmax = -1e30;
278 // iterate over all specialTriangles.
279 for (int i=0; i<(int)specialTriangles.size(); i++)
280 {
281 // find the dot product of special triangle node 0
282 // with desired position.
283 dot = location.dot(*specialTriangles[i]->getNode(0));
284
285 // large dot product corresponds to small separation.
286 // if this is closest special triangle so far, save it
287 if (dot > dmax)
288 {
289 // set best triangle to this special triangle.
290 tr = specialTriangles[i];
291 // if this triangle is closer than about 16 degrees
292 // then no closer triangle will be found, so quit.
293 if (dot > cos_min) break;
294 dmax = dot;
295 }
296 }
297
298 // search for the triangle that contains position, starting
299 // from the triangle identified above.
300 tr = tr->walk(location, coefficients);
301
302 // set first special triangle to the triangle that was just found so that
303 // it will be checked first on the next call to findTriangle().
304 specialTriangles[0] = tr;
305
306 return tr;
307 }
308
309 inline bool GridSLBM::findProfile(Location& location,
310 vector<GridProfile*>& neighbors, vector<int>& nodeIds,
311 vector<double>& coefficients)
312 {
313 neighbors.resize(3);
314 coefficients.resize(3);
315 nodeIds.resize(3);
316
317 Triangle* tr = findTriangle(location, coefficients);
318
319 for (int i=0; i<3; i++)
320 {
321 neighbors[i] = tr->getNode(i);
322 nodeIds[i] = neighbors[i]->getNodeId();
323 }
324
325 return true;
326 }
327
328 inline void GridSLBM::setInterpolatorType(const string& interpolatorType)
329 {
330 if (geotess::CPPUtils::uppercase_string(interpolatorType) != "LINEAR")
331 {
332 ostringstream os;
333 os << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(9);
334 os << endl << "ERROR in GridSLBM::setInterpolatorType()" << endl
335 << interpolatorType << " is not a recognized interpolator type." << endl
336 << "The only interpolator type recognized by the old style SLBM grids is LINEAR"
337 << "Version " << SlbmVersion << " File " << __FILE__ << " line " << __LINE__ << endl << endl;
338 throw SLBMException(os.str(),114);
339 }
340 }
341
342 } // end slbm namespace
343
344 #endif // GRIDSLBM_H
slbm::GridSLBM::GridSLBM
GridSLBM()
Default constructor.
slbm::GridSLBM::class_name
static string class_name()
Definition: GridSLBM.h:105
Triangle.h
slbm::GridSLBM::loadFromFile
void loadFromFile(const string &filename)
Load the depth, velocity and gradient information from an ascii flat file.
CrustalProfileStore.h
GreatCircle.h
slbm::GeoStack
Manages all information related to a single node in a Grid object.
Definition: GeoStack.h:65
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::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::getActiveNodeNeighbors
void getActiveNodeNeighbors(const int &nodeid, int neighbors[], int &nNeighbors)
SLBMException.h
slbm::GridSLBM::saveVelocityModel
void saveVelocityModel(util::DataBuffer &buffer)
Save the Earth model currently in memory, to a DataBuffer.
GreatCircleFactory.h
slbm::GridSLBM::getActiveNodeNeighbors
void getActiveNodeNeighbors(const int &nodeid, vector< int > &neighbors)
CrustalProfile.h
LayerProfile.h
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::GridSLBM::saveVelocityModel
void saveVelocityModel(const string &destination, const int &format)
Save the Earth model currently in memory, to file(s)
slbm::GridProfile::getNodeId
const int getNodeId() const
Retrieve the node index of this node in the model grid.
Definition: GridProfile.h:94
SLBMGlobals.h
slbm::GridSLBM::loadFromDirectory
void loadFromDirectory(const string &dirName)
Load the depth, velocity and gradient information from binary files in specified directory.
slbm::Grid
A 2 dimensional, horizontal grid of GirdProfile objects.
Definition: Grid.h:90
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:161
InterpolatedProfile.h
slbm::GridSLBM::getTessId
string getTessId()
Definition: GridSLBM.h:207
slbm::GridSLBM::getInterpolatorType
string getInterpolatorType()
Definition: GridSLBM.h:216
slbm::GridSLBM::memSize
size_t memSize()
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::toString
string toString()
slbm::GridSLBM::~GridSLBM
~GridSLBM()
Destructor.
slbm::GridSLBM::getBufferSize
int getBufferSize() const
slbm::GridSLBM::clear
void clear()
Clears and releases all memory held by this GridSLBM object.
GridProfile.h
SLBM_EXP_IMP
#define SLBM_EXP_IMP
Definition: SLBMGlobals.h:180
slbm::GridSLBM
A 2 dimensional, horizontal grid of GirdProfile objects.
Definition: GridSLBM.h:88
Location.h
slbm::GridSLBM::loadFromDataBuffer
void loadFromDataBuffer(util::DataBuffer &buffer)
Load the depth, velocity and gradient information from DataBuffer.
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:153
slbm::SLBMException
An Exception class for Grid and related objects.
Definition: SLBMException.h:55
DataBuffer.h
QueryProfile.h
slbm::GridSLBM::addGeoStack
int addGeoStack(GeoStack *geoStack)
Definition: GridSLBM.h:209
LayerProfileG.h
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::Triangle
Definition: Triangle.h:63