profile_grid.h

00001 
00005 #pragma once
00006 
00007 #include <usml/ocean/profile_model.h>
00008 
00009 namespace usml {
00010 namespace ocean {
00011 
00014 
00034 template< class DATA_TYPE, int NUM_DIMS > class profile_grid
00035     : public profile_model
00036 {
00037   private:
00038 
00039     //**************************************************
00040     // sound speed model
00041 
00043     data_grid<DATA_TYPE,NUM_DIMS>* _sound_speed ;
00044 
00045   public:
00046 
00055     virtual void sound_speed( const wposition& location,
00056         matrix<double>* speed, wvector* gradient=NULL )
00057     {
00058         switch( NUM_DIMS ) {
00059 
00060             //***************
00061             // 1-D grids
00062 
00063             case 1 :
00064                 if ( gradient ) {
00065                     matrix<double> rho( location.size1(), location.size2() ) ;
00066                     this->_sound_speed->interpolate(
00067                         location.rho(),
00068                         speed, &rho ) ;
00069                     gradient->rho( rho ) ;
00070                 } else {
00071                     this->_sound_speed->interpolate(
00072                         location.rho(),
00073                         speed ) ;
00074                 }
00075                 break ;
00076 
00077             //***************
00078             // 2-D grids
00079 
00080             case 2 :
00081                 if ( gradient ) {
00082                     matrix<double> rho( location.size1(), location.size2() ) ;
00083                     matrix<double> theta( location.size1(), location.size2() ) ;
00084                     this->_sound_speed->interpolate(
00085                         location.rho(), location.theta(),
00086                         speed, &rho, &theta ) ;
00087                     gradient->rho(rho) ;
00088                     gradient->theta(theta) ;
00089                 } else {
00090                     this->_sound_speed->interpolate(
00091                         location.rho(), location.theta(),
00092                         speed ) ;
00093                 }
00094                 break ;
00095 
00096             //***************
00097             // 3-D grids
00098 
00099             case 3 :
00100                 if ( gradient ) {
00101                     matrix<double> rho( location.size1(), location.size2() ) ;
00102                     matrix<double> theta( location.size1(), location.size2() ) ;
00103                     matrix<double> phi( location.size1(), location.size2() ) ;
00104                     this->_sound_speed->interpolate(
00105                         location.rho(), location.theta(), location.phi(),
00106                         speed, &rho, &theta, &phi ) ;
00107                     gradient->rho(rho) ;
00108                     gradient->theta(theta) ;
00109                     gradient->phi(phi) ;
00110                 } else {
00111                     this->_sound_speed->interpolate(
00112                         location.rho(), location.theta(), location.phi(),
00113                         speed ) ;
00114                 }
00115                 break ;
00116 
00117             //***************
00118             // error
00119 
00120             default :
00121                 throw std::invalid_argument(
00122                     "sound speed must be 1-D, 2-D, or 3-D") ;
00123                 break ;
00124         }
00125         this->adjust_speed( location, speed, gradient ) ;
00126     }
00127 
00128     //**************************************************
00129     // initialization
00130 
00141     profile_grid(
00142         data_grid<DATA_TYPE,NUM_DIMS>* speed, attenuation_model* attmodel=NULL)
00143         : profile_model(attmodel), _sound_speed(speed) { }
00144 
00148     virtual ~profile_grid() {
00149         delete _sound_speed ;
00150     }
00151 
00152 };
00153 
00155 }  // end of namespace ocean
00156 }  // end of namespace usml

Generated on 4 May 2015 for USML by  doxygen 1.6.1