RSTT  3.1.0
Regional Seismic Travel Time
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 
179 private:
180 
181  QueryProfile* queryProfile;
182 
183  GridProfile* gridProfile;
184 
185  vector<int> nodeIds;
186 
187  vector<double> weights;
188 
189  vector<double> greatCirclePointsLat, greatCirclePointsLon, greatCirclePointsDepth;
190 
191 };
192 
193 inline void SlbmInterfaceToJNI::computeGreatCirclePoints(
194  const double& aLat,
195  const double& aLon,
196  const double& bLat,
197  const double& bLon,
198  const int& npoints,
199  const bool& onCenters)
200 {
201  deleteGreatCirclePoints();
202 
203  Location a(aLat, aLon, 0.);
204  Location b(bLat, bLon, 0.);
205  double delta, delta0;
206 
207  if (onCenters)
208  {
209  delta = a.distance(b)/npoints;
210  delta0 = 0.5*delta;
211  }
212  else
213  {
214  delta = a.distance(b)/(npoints-1);
215  delta0 = 0;
216  }
217 
218  double moveDirection[3];
219  a.vectorTripleProduct(b, moveDirection);
220  for (int i=0; i<npoints; i++)
221  {
222  a.move(moveDirection, delta0+i*delta, b);
223  greatCirclePointsLat.push_back(b.getLat());
224  greatCirclePointsLon.push_back(b.getLon());
225  }
226 }
227 
228 inline void SlbmInterfaceToJNI::computeGreatCircleLocations()
229 {
230  deleteGreatCirclePoints();
231 
232  Location loc;
233  for (int i=0; i<greatCircle->getNProfiles(); i++)
234  {
235  // get the location of this layer profile
236  greatCircle->getLayerProfileLocation(i, loc);
237  greatCirclePointsLat.push_back(loc.getLat());
238  greatCirclePointsLon.push_back(loc.getLon());
239  greatCirclePointsDepth.push_back(loc.getDepth());
240  }
241 }
242 
243 inline string SlbmInterfaceToJNI::getPhase()
244 {
245  if (greatCircle->getPhase() == Pn)
246  return "Pn";
247  if (greatCircle->getPhase() == Sn)
248  return "Sn";
249  if (greatCircle->getPhase() == Pg)
250  return "Pg";
251  if (greatCircle->getPhase() == Lg)
252  return "Lg";
253  return "unknown";
254 }
255 
256 inline void SlbmInterfaceToJNI::accessGridProfile(const int& nodeId)
257 {
258  gridProfile = grid->getProfile(nodeId);
259 }
260 
261 inline double SlbmInterfaceToJNI::getGridLat()
262 {
263  return gridProfile->getLat();
264 }
265 
266 inline double SlbmInterfaceToJNI::getGridLon()
267 {
268  return gridProfile->getLon();
269 }
270 
271 
272 inline void SlbmInterfaceToJNI::getGridDepth(vector<double>& depths)
273 {
274  gridProfile->getInterfaceDepths(depths);
275 }
276 
277 inline void SlbmInterfaceToJNI::getGridVelocity(const int& waveType, double* velocity)
278 {
279  gridProfile->getVelocity(waveType, velocity);
280 }
281 
282 inline void SlbmInterfaceToJNI::getGridGradient(double* gradient)
283 {
284  gridProfile->getMantleGradient(gradient);
285 }
286 
287 //inline void SlbmInterfaceToJNI::setGridDepths(const vector<double>& depth)
288 //{
289 // gridProfile->setDepths(depth);
290 //}
291 //
292 //inline void SlbmInterfaceToJNI::setGridVelocity(const int& waveType,
293 // const vector<double>& velocity)
294 //{
295 // gridProfile->setVelocity(waveType, velocity);
296 //}
297 //
298 //inline void SlbmInterfaceToJNI::setGridGradient(const vector<double>& gradient)
299 //{
300 // gridProfile->setGradient(gradient);
301 //}
302 
303 inline void SlbmInterfaceToJNI::createQueryProfile(const double &lat, const double &lon)
304 {
305  deleteQueryProfile();
306  Location loc(lat, lon, 0.);
307  queryProfile = grid->getQueryProfile(loc);
308 }
309 
310 inline void SlbmInterfaceToJNI::deleteQueryProfile()
311 {
312  if (queryProfile) delete queryProfile;
313  queryProfile = NULL;
314 }
315 
316 inline int SlbmInterfaceToJNI::getQueryNCoefficients()
317 {
318  return queryProfile->getNCoefficients();
319 }
320 
321 inline vector<int>& SlbmInterfaceToJNI::getQueryNodeId()
322 {
323  return queryProfile->getNodeIds();
324 }
325 
326 inline vector<double>& SlbmInterfaceToJNI::getQueryCoefficient()
327 {
328  return queryProfile->getCoefficients();
329 }
330 
331 inline double* SlbmInterfaceToJNI::getQueryDepth()
332 {
333  return queryProfile->getDepth();
334 }
335 
336 inline double* SlbmInterfaceToJNI::getQueryVelocity(const int& waveType)
337 {
338  return queryProfile->getVelocity(waveType);
339 }
340 
341 inline double* SlbmInterfaceToJNI::getQueryGradient()
342 {
343  return queryProfile->getMantleGradient();
344 }
345 
346 inline void SlbmInterfaceToJNI::computeWeights()
347 {
348  SlbmInterface::getWeights(nodeIds, weights);
349 }
350 
351 
352 inline string SlbmInterfaceToJNI::getGreatCirclePhase()
353 {
354  return greatCircle->getPhaseString();
355 }
356 
357 inline double SlbmInterfaceToJNI::getActualPathIncrement()
358 {
359  return greatCircle->getActualPathIncrement();
360 }
361 
362 inline void SlbmInterfaceToJNI::getGreatCircleNeighbors(const int& i, int* nodeids, int& size)
363 {
364  greatCircle->getProfile(i)->getNodeIds(nodeids, size);
365 }
366 
367 inline void SlbmInterfaceToJNI::getGreatCircleCoefficients(const int& i, double* coeff, int& size)
368 {
369  greatCircle->getProfile(i)->getCoefficients(coeff, size);
370 }
371 
372 inline void SlbmInterfaceToJNI::getGreatCircleSourceDepth(double* depths, int& n)
373 {
374  n = greatCircle->getSourceProfile()->getNIntervals();
375  greatCircle->getSourceProfile()->getDepths(depths);
376 }
377 
378 inline void SlbmInterfaceToJNI::getGreatCircleReceiverDepth(double* depths, int& n)
379 {
380  n = greatCircle->getReceiverProfile()->getNIntervals();
381  greatCircle->getReceiverProfile()->getDepths(depths);
382 }
383 
384 inline double* SlbmInterfaceToJNI::getGreatCircleSourceVelocity(int& n)
385 {
386  n = greatCircle->getSourceProfile()->getNIntervals();
387  return greatCircle->getSourceProfile()->getVelocities();
388 }
389 
390 inline double* SlbmInterfaceToJNI::getGreatCircleReceiverVelocity(int& n)
391 {
392  n = greatCircle->getReceiverProfile()->getNIntervals();
393  return greatCircle->getReceiverProfile()->getVelocities();
394 }
395 
396 inline void SlbmInterfaceToJNI::getGreatCircleHeadwaveVelocity(vector<double>& v)
397 {
398  v.clear();
399  for (int i=0; i<greatCircle->getNProfiles(); i++)
400  v.push_back(greatCircle->getProfile(i)->getVelocity());
401 }
402 
403 inline void SlbmInterfaceToJNI::getGreatCircleHeadwaveGradient(vector<double>& g)
404 {
405  g.clear();
406  for (int i=0; i<greatCircle->getNProfiles(); i++)
407  g.push_back(greatCircle->getProfile(i)->getGradient());
408 }
409 
410 inline int SlbmInterfaceToJNI::getNGridNodes()
411 {
412  int n = -1;
413  n = grid->getNNodes();
414  return n;
415 }
416 
417 inline int SlbmInterfaceToJNI::getNHeadWavePoints()
418 {
419  int nHeadWavePoints = -1;
420  nHeadWavePoints = greatCircle->getNProfiles();
421  return nHeadWavePoints;
422 }
423 
424 inline void SlbmInterfaceToJNI::computeWeightsSource()
425 {
426  nodeIds = greatCircle->getSourceProfile()->getNodeIds();
427  weights = greatCircle->getSourceProfile()->getCoefficients();
428 }
429 inline void SlbmInterfaceToJNI::computeWeightsReceiver()
430 {
431  nodeIds = greatCircle->getReceiverProfile()->getNodeIds();
432  weights = greatCircle->getReceiverProfile()->getCoefficients();
433 }
434 
435 } // end slbm namespace
436 
437 #endif
slbm::SlbmInterfaceToJNI::getGreatCirclePointsLat
const vector< double > & getGreatCirclePointsLat()
Definition: SlbmInterfaceToJNI.h:166
slbm::QueryProfile
An InterpolatedProfile object that also has information about the the P and S wave velocity as a func...
Definition: QueryProfile.h:68
slbm::Location
The Location Class manages a single point in/on the Earth, which is described by the GRS80 ellipsoid.
Definition: Location.h:78
SlbmInterface.h
slbm::SlbmInterfaceToJNI::getWeights
const vector< double > & getWeights()
Definition: SlbmInterfaceToJNI.h:131
SLBMException.h
slbm::Location::vectorTripleProduct
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
slbm::SlbmInterfaceToJNI::~SlbmInterfaceToJNI
~SlbmInterfaceToJNI()
Destructor.
slbm::Location::getLat
double getLat() const
Retrieve the geographic latitude of this Location, radians.
Definition: Location.h:542
slbm::Location::getLon
double getLon() const
Retrieve the longitude of this Location. Value will be between -PI and PI radians.
Definition: Location.h:548
slbm::SlbmInterfaceToJNI::getGreatCirclePointsLon
const vector< double > & getGreatCirclePointsLon()
Definition: SlbmInterfaceToJNI.h:168
slbm::SlbmInterfaceToJNI
Adds functionality to SlbmInterface to support the Java Native Interface (JNI). The JNI allows libSLB...
Definition: SlbmInterfaceToJNI.h:67
SLBMGlobals.h
slbm::GridProfile
Manages all information related to a single node in a Grid object.
Definition: GridProfile.h:71
slbm::SlbmInterfaceToJNI::SlbmInterfaceToJNI
SlbmInterfaceToJNI()
Default constructor.
slbm::SlbmInterfaceToJNI::accessGridNodeNeighbors
void accessGridNodeNeighbors(int nid)
slbm::SlbmInterfaceToJNI::deleteGreatCirclePoints
void deleteGreatCirclePoints()
Definition: SlbmInterfaceToJNI.h:163
slbm::SlbmInterfaceToJNI::SlbmInterfaceToJNI
SlbmInterfaceToJNI(const double &earthRadius)
slbm::SlbmInterface
The primary interface to the SLBM library, providing access to all supported functionality.
Definition: SlbmInterface.h:77
GridProfile.h
SLBM_EXP_IMP
#define SLBM_EXP_IMP
Definition: SLBMGlobals.h:180
slbm::SlbmInterfaceToJNI::getGreatCirclePointsDepth
const vector< double > & getGreatCirclePointsDepth()
Definition: SlbmInterfaceToJNI.h:170
slbm::SlbmInterfaceToJNI::deleteWeights
void deleteWeights()
Definition: SlbmInterfaceToJNI.h:127
slbm::Location::move
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
slbm::SlbmInterfaceToJNI::deleteGridProfile
void deleteGridProfile()
slbm::Location::distance
double distance(const Location &other) const
Definition: Location.h:583
slbm::SlbmInterfaceToJNI::getWeightNodes
const vector< int > & getWeightNodes()
Definition: SlbmInterfaceToJNI.h:129
slbm::Location::getDepth
double getDepth() const
Definition: Location.h:573
slbm
Definition: CrustalProfile.h:59