RSTT  3.2.0
Regional Seismic Travel Time
All Classes Namespaces Files Functions Variables Typedefs Friends Macros
SlbmInterfaceToJNI.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 SlbmInterfaceToJNI_H
39 #define SlbmInterfaceToJNI_H
40 
41 // **** _SYSTEM INCLUDES_ ******************************************************
42 #include <cmath>
43 
44 using namespace std;
45 
46 // **** _LOCAL INCLUDES_ *******************************************************
47 
48 #include "SLBMGlobals.h"
49 #include "SlbmInterface.h"
50 #include "GridProfile.h"
51 #include "SLBMException.h"
52 
53 // **** _BEGIN SLBM NAMESPACE_ **************************************************
54 
55 namespace slbm {
56 
67 {
68 
69 public:
70 
75 
76  SlbmInterfaceToJNI(const double& earthRadius);
77 
82 
83  string getPhase();
84 
85  void accessGridProfile(const int& nodeId);
86 
88 
89  double getGridLat();
90 
91  double getGridLon();
92 
93  void getGridDepth(vector<double>& depths);
94 
95  void getGridVelocity(const int& waveType, double* velocity);
96 
97  void getGridGradient(double* gradient);
98 
99  //void setGridDepths(const vector<double>& depth);
100 
101  //void setGridVelocity(const int& waveType, const vector<double>& velocity);
102 
103  // setGridGradient(const vector<double>& gradient);
104 
105  void createQueryProfile(const double& lat, const double& lon);
106 
107  void deleteQueryProfile();
108 
109  int getQueryNCoefficients();
110 
111  vector<int>& getQueryNodeId();
112 
113  vector<double>& getQueryCoefficient();
114 
115  double* getQueryDepth();
116 
117  double* getQueryVelocity(const int& waveType);
118 
119  double* getQueryGradient();
120 
121  void computeWeights();
122 
123  void computeWeightsSource();
124 
125  void computeWeightsReceiver();
126 
127  void deleteWeights() { nodeIds.clear(); weights.clear(); };
128 
129  const vector<int>& getWeightNodes() { return nodeIds; };
130 
131  const vector<double>& getWeights() { return weights; };
132 
133  string getGreatCirclePhase();
134 
135  double getActualPathIncrement();
136 
137  void getGreatCircleNeighbors(const int& i, int* nodeIds, int& size);
138 
139  void getGreatCircleCoefficients(const int& i, double* coeff, int& size);
140 
141  void getGreatCircleSourceDepth(double* depths, int& n);
142 
143  void getGreatCircleReceiverDepth(double* depths, int& n);
144 
145  double* getGreatCircleSourceVelocity(int& n);
146 
147  double* getGreatCircleReceiverVelocity(int& n);
148 
149  void getGreatCircleHeadwaveVelocity(vector<double>& velocities);
150 
151  void getGreatCircleHeadwaveGradient(vector<double>& gradients);
152 
153  void computeGreatCirclePoints(
154  const double& aLat,
155  const double& aLon,
156  const double& bLat,
157  const double& bLon,
158  const int& npoints,
159  const bool& onCenters);
160 
161  void computeGreatCircleLocations();
162 
164  { greatCirclePointsLat.clear(); greatCirclePointsLon.clear(); greatCirclePointsDepth.clear(); };
165 
166  const vector<double>& getGreatCirclePointsLat() { return greatCirclePointsLat; };
167 
168  const vector<double>& getGreatCirclePointsLon() { return greatCirclePointsLon; };
169 
170  const vector<double>& getGreatCirclePointsDepth() { return greatCirclePointsDepth; };
171 
172  int getNGridNodes();
173 
174  int getNHeadWavePoints();
175 
176  void accessGridNodeNeighbors(int nid );
177 
178  static bool modelsEqual(const string modelPath1, const string modelPath2);
179 
180 
181 private:
182 
183  QueryProfile* queryProfile;
184 
185  GridProfile* gridProfile;
186 
187  vector<int> nodeIds;
188 
189  vector<double> weights;
190 
191  vector<double> greatCirclePointsLat, greatCirclePointsLon, greatCirclePointsDepth;
192 
193 };
194 
195 inline void SlbmInterfaceToJNI::computeGreatCirclePoints(
196  const double& aLat,
197  const double& aLon,
198  const double& bLat,
199  const double& bLon,
200  const int& npoints,
201  const bool& onCenters)
202 {
203  deleteGreatCirclePoints();
204 
205  Location a(aLat, aLon, 0.);
206  Location b(bLat, bLon, 0.);
207  double delta, delta0;
208 
209  if (onCenters)
210  {
211  delta = a.distance(b)/npoints;
212  delta0 = 0.5*delta;
213  }
214  else
215  {
216  delta = a.distance(b)/(npoints-1);
217  delta0 = 0;
218  }
219 
220  double moveDirection[3];
221  a.vectorTripleProduct(b, moveDirection);
222  for (int i=0; i<npoints; i++)
223  {
224  a.move(moveDirection, delta0+i*delta, b);
225  greatCirclePointsLat.push_back(b.getLat());
226  greatCirclePointsLon.push_back(b.getLon());
227  }
228 }
229 
230 inline void SlbmInterfaceToJNI::computeGreatCircleLocations()
231 {
232  deleteGreatCirclePoints();
233 
234  Location loc;
235  for (int i=0; i<greatCircle->getNProfiles(); i++)
236  {
237  // get the location of this layer profile
238  greatCircle->getLayerProfileLocation(i, loc);
239  greatCirclePointsLat.push_back(loc.getLat());
240  greatCirclePointsLon.push_back(loc.getLon());
241  greatCirclePointsDepth.push_back(loc.getDepth());
242  }
243 }
244 
245 inline string SlbmInterfaceToJNI::getPhase()
246 {
247  if (greatCircle->getPhase() == Pn)
248  return "Pn";
249  if (greatCircle->getPhase() == Sn)
250  return "Sn";
251  if (greatCircle->getPhase() == Pg)
252  return "Pg";
253  if (greatCircle->getPhase() == Lg)
254  return "Lg";
255  return "unknown";
256 }
257 
258 inline void SlbmInterfaceToJNI::accessGridProfile(const int& nodeId)
259 {
260  gridProfile = grid->getProfile(nodeId);
261 }
262 
263 inline double SlbmInterfaceToJNI::getGridLat()
264 {
265  return gridProfile->getLat();
266 }
267 
268 inline double SlbmInterfaceToJNI::getGridLon()
269 {
270  return gridProfile->getLon();
271 }
272 
273 
274 inline void SlbmInterfaceToJNI::getGridDepth(vector<double>& depths)
275 {
276  gridProfile->getInterfaceDepths(depths);
277 }
278 
279 inline void SlbmInterfaceToJNI::getGridVelocity(const int& waveType, double* velocity)
280 {
281  gridProfile->getVelocity(waveType, velocity);
282 }
283 
284 inline void SlbmInterfaceToJNI::getGridGradient(double* gradient)
285 {
286  gridProfile->getMantleGradient(gradient);
287 }
288 
289 //inline void SlbmInterfaceToJNI::setGridDepths(const vector<double>& depth)
290 //{
291 // gridProfile->setDepths(depth);
292 //}
293 //
294 //inline void SlbmInterfaceToJNI::setGridVelocity(const int& waveType,
295 // const vector<double>& velocity)
296 //{
297 // gridProfile->setVelocity(waveType, velocity);
298 //}
299 //
300 //inline void SlbmInterfaceToJNI::setGridGradient(const vector<double>& gradient)
301 //{
302 // gridProfile->setGradient(gradient);
303 //}
304 
305 inline void SlbmInterfaceToJNI::createQueryProfile(const double &lat, const double &lon)
306 {
307  deleteQueryProfile();
308  Location loc(lat, lon, 0.);
309  queryProfile = grid->getQueryProfile(loc);
310 }
311 
312 inline void SlbmInterfaceToJNI::deleteQueryProfile()
313 {
314  if (queryProfile) delete queryProfile;
315  queryProfile = NULL;
316 }
317 
318 inline int SlbmInterfaceToJNI::getQueryNCoefficients()
319 {
320  return queryProfile->getNCoefficients();
321 }
322 
323 inline vector<int>& SlbmInterfaceToJNI::getQueryNodeId()
324 {
325  return queryProfile->getNodeIds();
326 }
327 
328 inline vector<double>& SlbmInterfaceToJNI::getQueryCoefficient()
329 {
330  return queryProfile->getCoefficients();
331 }
332 
333 inline double* SlbmInterfaceToJNI::getQueryDepth()
334 {
335  return queryProfile->getDepth();
336 }
337 
338 inline double* SlbmInterfaceToJNI::getQueryVelocity(const int& waveType)
339 {
340  return queryProfile->getVelocity(waveType);
341 }
342 
343 inline double* SlbmInterfaceToJNI::getQueryGradient()
344 {
345  return queryProfile->getMantleGradient();
346 }
347 
348 inline void SlbmInterfaceToJNI::computeWeights()
349 {
350  SlbmInterface::getWeights(nodeIds, weights);
351 }
352 
353 
354 inline string SlbmInterfaceToJNI::getGreatCirclePhase()
355 {
356  return greatCircle->getPhaseString();
357 }
358 
359 inline double SlbmInterfaceToJNI::getActualPathIncrement()
360 {
361  return greatCircle->getActualPathIncrement();
362 }
363 
364 inline void SlbmInterfaceToJNI::getGreatCircleNeighbors(const int& i, int* nodeids, int& size)
365 {
366  greatCircle->getProfile(i)->getNodeIds(nodeids, size);
367 }
368 
369 inline void SlbmInterfaceToJNI::getGreatCircleCoefficients(const int& i, double* coeff, int& size)
370 {
371  greatCircle->getProfile(i)->getCoefficients(coeff, size);
372 }
373 
374 inline void SlbmInterfaceToJNI::getGreatCircleSourceDepth(double* depths, int& n)
375 {
376  n = greatCircle->getSourceProfile()->getNIntervals();
377  greatCircle->getSourceProfile()->getDepths(depths);
378 }
379 
380 inline void SlbmInterfaceToJNI::getGreatCircleReceiverDepth(double* depths, int& n)
381 {
382  n = greatCircle->getReceiverProfile()->getNIntervals();
383  greatCircle->getReceiverProfile()->getDepths(depths);
384 }
385 
386 inline double* SlbmInterfaceToJNI::getGreatCircleSourceVelocity(int& n)
387 {
388  n = greatCircle->getSourceProfile()->getNIntervals();
389  return greatCircle->getSourceProfile()->getVelocities();
390 }
391 
392 inline double* SlbmInterfaceToJNI::getGreatCircleReceiverVelocity(int& n)
393 {
394  n = greatCircle->getReceiverProfile()->getNIntervals();
395  return greatCircle->getReceiverProfile()->getVelocities();
396 }
397 
398 inline void SlbmInterfaceToJNI::getGreatCircleHeadwaveVelocity(vector<double>& v)
399 {
400  v.clear();
401  for (int i=0; i<greatCircle->getNProfiles(); i++)
402  v.push_back(greatCircle->getProfile(i)->getVelocity());
403 }
404 
405 inline void SlbmInterfaceToJNI::getGreatCircleHeadwaveGradient(vector<double>& g)
406 {
407  g.clear();
408  for (int i=0; i<greatCircle->getNProfiles(); i++)
409  g.push_back(greatCircle->getProfile(i)->getGradient());
410 }
411 
412 inline int SlbmInterfaceToJNI::getNGridNodes()
413 {
414  int n = -1;
415  n = grid->getNNodes();
416  return n;
417 }
418 
419 inline int SlbmInterfaceToJNI::getNHeadWavePoints()
420 {
421  int nHeadWavePoints = -1;
422  nHeadWavePoints = greatCircle->getNProfiles();
423  return nHeadWavePoints;
424 }
425 
426 inline void SlbmInterfaceToJNI::computeWeightsSource()
427 {
428  nodeIds = greatCircle->getSourceProfile()->getNodeIds();
429  weights = greatCircle->getSourceProfile()->getCoefficients();
430 }
431 inline void SlbmInterfaceToJNI::computeWeightsReceiver()
432 {
433  nodeIds = greatCircle->getReceiverProfile()->getNodeIds();
434  weights = greatCircle->getReceiverProfile()->getCoefficients();
435 }
436 bool SlbmInterfaceToJNI::modelsEqual(const string modelPath1, const string modelPath2)
437 {
438  return SlbmInterface::modelsEqual(modelPath1, modelPath2);
439 }
440 
441 } // end slbm namespace
442 
443 #endif
#define SLBM_EXP_IMP
Definition: SLBMGlobals.h:180
Manages all information related to a single node in a Grid object.
Definition: GridProfile.h:71
The Location Class manages a single point in/on the Earth, which is described by the GRS80 ellipsoid.
Definition: Location.h:78
double getLon() const
Retrieve the longitude of this Location. Value will be between -PI and PI radians.
Definition: Location.h:548
double distance(const Location &other) const
Definition: Location.h:583
bool vectorTripleProduct(const Location &other, double vtp[]) const
Compute the vector triple product (this x other) x this, normalized to unit length....
Definition: Location.h:691
void move(const double &azimuth, const double &distance, Location &loc) const
Retrieve a Location that is a specified distance away from this Location, in a specified direction.
Definition: Location.h:638
double getDepth() const
Definition: Location.h:573
double getLat() const
Retrieve the geographic latitude of this Location, radians.
Definition: Location.h:542
An InterpolatedProfile object that also has information about the the P and S wave velocity as a func...
Definition: QueryProfile.h:68
The primary interface to the SLBM library, providing access to all supported functionality.
Definition: SlbmInterface.h:77
Adds functionality to SlbmInterface to support the Java Native Interface (JNI). The JNI allows libSLB...
SlbmInterfaceToJNI()
Default constructor.
const vector< int > & getWeightNodes()
~SlbmInterfaceToJNI()
Destructor.
const vector< double > & getGreatCirclePointsLon()
void accessGridNodeNeighbors(int nid)
const vector< double > & getWeights()
const vector< double > & getGreatCirclePointsLat()
const vector< double > & getGreatCirclePointsDepth()
SlbmInterfaceToJNI(const double &earthRadius)