ForceModelList.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: ForceModelList.cpp 3140 2012-06-18 15:03:02Z susancummins $"
00002 
00009 //============================================================================
00010 //
00011 //  This file is part of GPSTk, the GPS Toolkit.
00012 //
00013 //  The GPSTk is free software; you can redistribute it and/or modify
00014 //  it under the terms of the GNU Lesser General Public License as published
00015 //  by the Free Software Foundation; either version 2.1 of the License, or
00016 //  any later version.
00017 //
00018 //  The GPSTk is distributed in the hope that it will be useful,
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021 //  GNU Lesser General Public License for more details.
00022 //
00023 //  You should have received a copy of the GNU Lesser General Public
00024 //  License along with GPSTk; if not, write to the Free Software Foundation,
00025 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
00026 //
00027 //  Wei Yan - Chinese Academy of Sciences . 2009, 2010
00028 //
00029 //============================================================================
00030 
00031 #include "ForceModelList.hpp"
00032 
00033 
00034 namespace gpstk
00035 {
00036 
00037    ForceModelList::ForceModelList()
00038    {
00039       //setFMT.insert(ForceModel::Cd);
00040       //setFMT.insert(ForceModel::Cr);
00041       setFMT.clear();
00042       clear();
00043    }
00044 
00045       // interface implementation for the 'ForceModel'
00046    Vector<double> ForceModelList::getDerivatives(UTCTime utc, EarthBody& bref, Spacecraft& sc)
00047    {
00048       const int np = setFMT.size(); //getNP();
00049 
00050       a.resize(3,0.0);
00051       da_dr.resize(3,3,0.0);
00052       da_dv.resize(3,3,0.0);
00053       da_dp.resize(3,np,0.0);
00054 
00055       da_dcd.resize(3,1,0.0);
00056       da_dcr.resize(3,1,0.0);
00057       
00058       for(std::list<ForceModel*>::iterator it = forceList.begin();
00059          it != forceList.end();
00060          ++it)
00061       {
00062          (*it)->doCompute(utc,bref,sc);
00063 
00064          a      += (*it)->getAccel();
00065          da_dr   += (*it)->partialR();
00066          da_dv   += (*it)->partialV();
00067          //da_dp   += (*it)->partialP();
00068 
00069          //cout<<(*it)->modelName()<<endl;
00070          
00071          da_dcd   += (*it)->partialCd();
00072          da_dcr   += (*it)->partialCr();
00073          
00074       }
00075       
00076       // declare a counter
00077       int i = 0;  
00078 
00079       for(std::set<ForceModel::ForceModelType>::iterator it = setFMT.begin();
00080          it!=setFMT.end();
00081          it++)
00082       {
00083          if((*it)==ForceModel::Cd)
00084          {
00085             da_dp(0,i) = da_dcd(0,0);
00086             da_dp(1,i) = da_dcd(1,0);
00087             da_dp(2,i) = da_dcd(2,0);
00088          }
00089          else if((*it)==ForceModel::Cr)
00090          {
00091             da_dp(0,i) = da_dcr(0,0);
00092             da_dp(1,i) = da_dcr(1,0);
00093             da_dp(2,i) = da_dcr(2,0);
00094          }
00095          else
00096          {
00097             Exception e("Error in ForceModelList::getDerivatives():Unexpect ForceModelType");
00098             GPSTK_THROW(e);
00099          }
00100 
00101          i++;
00102       }  
00103 
00104       /* Transition Matrix (6+np)*(6+np)
00105            |                          |
00106            | dr_dr0   dr_dv0   dr_dp0  |
00107            |                          |
00108       phi= | dv_dr0   dv_dv0   dv_dp0  |
00109            |                          |
00110            | 0         0          I      |
00111            |                          |
00112       */
00113       Matrix<double> phi = sc.getTransitionMatrix();
00114 
00115       /* A Matrix (6+np)*(6+np)
00116           |                       |
00117           | 0         I      0      |
00118           |                       |
00119       A = | da_dr      da_dv   da_dp  |
00120           |                       |
00121           | 0         0      0      |
00122           |                       |
00123       */
00124       Matrix<double> A = getAMatrix();
00125       
00126       /* dphi Matrix
00127              |                          |
00128              | dv_dr0   dv_dv0   dv_dp0 |
00129              |                          |
00130       dphi = | da_dr0   da_dv0   da_dp0 |
00131              |                          |
00132              | 0         0         0    |
00133              |                          |
00134 
00135       da_dr0 = da_dr*dr_dr0 + da_dv*dv_dr0
00136 
00137       da_dv0 = da_dr*dr_dv0 + da_dv*dv_dv0
00138 
00139       da_dp0 = da_dr*dr_dp0 + da_dv*dv_dp0 + da_dp0;
00140       */
00141       Matrix<double> dphi = A * phi;
00142 
00143 
00144       Vector<double> r = sc.R();
00145       Vector<double> v = sc.V();
00146       
00147       gpstk::Vector<double> dy(42+6*np,0.0);   
00148 
00149       dy(0) = v(0);      // v
00150       dy(1) = v(1);
00151       dy(2) = v(2);
00152       dy(3) = a(0);      // a
00153       dy(4) = a(1);
00154       dy(5) = a(2);
00155       
00156       for(int i=0;i<3;i++)
00157       {
00158          for(int j=0;j<3;j++)
00159          {
00160             dy(6+i*3+j) = dphi(i,j);            // dv_dr0
00161             dy(15+i*3+j) = dphi(i,j+3);         // dv_dv0
00162             dy(24+3*np+i*3+j) = dphi(i+3,j);    // da_dr0
00163             dy(33+3*np+i*3+j) = dphi(i+3,j+3);  // da_dv0   
00164          }
00165          for(int k=0;k<np;k++)
00166          {
00167             dy(24+i*np+k) = dphi(i,i*np+k);         // dv_dp0
00168             dy(42+3*np+i*np+k) = dphi(i+3,i*np+k);  // da_dp0
00169          }
00170       }
00171 
00172       return dy;
00173 
00174    }  // End of method 'ForceModelList::getDerivatives()'
00175 
00176 
00177    void ForceModelList::printForceModel(std::ostream& s)
00178    {
00179       // a counter
00180       int i(1);
00181 
00182       for(list<ForceModel*>::iterator it = forceList.begin();
00183          it != forceList.end();
00184          ++it)
00185       {
00186          s << setw(3) << i << " "
00187            << (*it)->forceIndex()<<" "
00188            << (*it)->modelName()<<endl;
00189 
00190          i++;
00191       }
00192 
00193    }  // End of method 'ForceModelList::printForceModel()'
00194 
00195    void ForceModelList::setForceModelType(std::set<ForceModel::ForceModelType> fmt)
00196    {
00197       setFMT.clear();
00198       for(std::set<ForceModel::ForceModelType>::iterator it = fmt.begin();
00199          it != fmt.end();
00200          ++it)
00201       {
00202          setFMT.insert(*it);
00203       }
00204 
00205    }  // End of method ''
00206 
00207 
00208 
00209 }  // End of namespace 'gpstk'
00210 

Generated on Fri May 24 03:31:06 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1