LCOV - code coverage report
Current view: top level - models - FGExternalForce.cpp (source / functions) Hit Total Coverage
Test: JSBSim-Coverage-Statistics Lines: 1 96 1.0 %
Date: 2010-08-24 Functions: 3 13 23.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 60 5.0 %

           Branch data     Line data    Source code
       1                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       2                 :            : 
       3                 :            :  Source:       FGExternalForce.cpp
       4                 :            :  Author:       Jon Berndt, Dave Culp
       5                 :            :  Date started: 9/21/07
       6                 :            : 
       7                 :            :  ------------- Copyright (C) 2007  Jon S. Berndt (jon@jsbsim.org) -------------
       8                 :            : 
       9                 :            :  This program is free software; you can redistribute it and/or modify it under
      10                 :            :  the terms of the GNU Lesser General Public License as published by the Free Software
      11                 :            :  Foundation; either version 2 of the License, or (at your option) any later
      12                 :            :  version.
      13                 :            : 
      14                 :            :  This program is distributed in the hope that it will be useful, but WITHOUT
      15                 :            :  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      16                 :            :  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      17                 :            :  details.
      18                 :            : 
      19                 :            :  You should have received a copy of the GNU Lesser General Public License along with
      20                 :            :  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
      21                 :            :  Place - Suite 330, Boston, MA  02111-1307, USA.
      22                 :            : 
      23                 :            :  Further information about the GNU Lesser General Public License can also be found on
      24                 :            :  the world wide web at http://www.gnu.org.
      25                 :            : 
      26                 :            :  HISTORY
      27                 :            : --------------------------------------------------------------------------------
      28                 :            : 9/21/07  JB   Created
      29                 :            : 
      30                 :            : <external_reactions>
      31                 :            : 
      32                 :            :     <!-- Interface properties, a.k.a. property declarations -->
      33                 :            :     <property> ... </property>
      34                 :            :       
      35                 :            :     <force name="name" frame="BODY|LOCAL|WIND">
      36                 :            :       
      37                 :            :       <function> ... </function>
      38                 :            : 
      39                 :            :       <location unit="units"> <!-- location -->
      40                 :            :         <x> value </x>
      41                 :            :         <y> value </y>
      42                 :            :         <z> value </z>
      43                 :            :       </location>
      44                 :            :       <direction> <!-- optional for initial direction vector -->
      45                 :            :         <x> value </x>
      46                 :            :         <y> value </y>
      47                 :            :         <z> value </z>
      48                 :            :       </direction>
      49                 :            :     </force>
      50                 :            : 
      51                 :            : </external_reactions>
      52                 :            : 
      53                 :            : */
      54                 :            : 
      55                 :            : #include "FGExternalForce.h"
      56                 :            : #include "input_output/FGXMLElement.h"
      57                 :            : #include <iostream>
      58                 :            : 
      59                 :            : using namespace std;
      60                 :            : 
      61                 :            : namespace JSBSim {
      62                 :            : 
      63                 :            : static const char *IdSrc = "$Id: FGExternalForce.cpp,v 1.10 2009/10/24 22:59:30 jberndt Exp $";
      64                 :            : static const char *IdHdr = ID_EXTERNALFORCE;
      65                 :            : 
      66                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      67                 :            : 
      68                 :          0 : FGExternalForce::FGExternalForce(FGFDMExec *FDMExec, Element *el, int index): FGForce(FDMExec)
      69                 :            : {
      70                 :          0 :   Element* location_element=0;
      71                 :          0 :   Element* direction_element=0;
      72                 :          0 :   Element* function_element=0;
      73                 :          0 :   string sFrame;
      74                 :          0 :   string BasePropertyName;
      75                 :          0 :   FGColumnVector3 location;
      76                 :          0 :   Magnitude_Function = 0;
      77                 :          0 :   magnitude = 0.0;
      78                 :          0 :   azimuth = 0.0;
      79                 :            : 
      80                 :          0 :   PropertyManager = fdmex->GetPropertyManager();
      81                 :          0 :   Name = el->GetAttributeValue("name");
      82                 :          0 :   BasePropertyName = "external_reactions/" + Name;
      83                 :            : 
      84                 :            :   // The value sent to the sim through the external_forces/{force name}/magnitude
      85                 :            :   // property will be multiplied against the unit vector, which can come in
      86                 :            :   // initially in the direction vector. The frame in which the vector is defined
      87                 :            :   // is specified with the frame attribute. The vector is normalized to magnitude 1.
      88                 :            : 
      89                 :          0 :   function_element = el->FindElement("function");
      90   [ #  #  #  # ]:          0 :   if (function_element) {
      91                 :          0 :     Magnitude_Function = new FGFunction(PropertyManager, function_element);
      92                 :            :   } else {
      93                 :          0 :     PropertyManager->Tie( BasePropertyName + "/magnitude",(FGExternalForce*)this, &FGExternalForce::GetMagnitude, &FGExternalForce::SetMagnitude);
      94                 :          0 :     Magnitude_Node = PropertyManager->GetNode(BasePropertyName + "/magnitude");
      95                 :            :   }
      96                 :            : 
      97                 :            : 
      98                 :            :   // Set frame (from FGForce).
      99                 :          0 :   sFrame = el->GetAttributeValue("frame");
     100   [ #  #  #  # ]:          0 :   if (sFrame.empty()) {
     101                 :          0 :     cerr << "No frame specified for external force, \"" << Name << "\"." << endl;
     102                 :          0 :     cerr << "Frame set to Body" << endl;
     103                 :          0 :     ttype = tNone;
     104   [ #  #  #  # ]:          0 :   } else if (sFrame == "BODY") {
     105                 :          0 :     ttype = tNone;
     106   [ #  #  #  # ]:          0 :   } else if (sFrame == "LOCAL") {
     107                 :          0 :     ttype = tLocalBody;
     108                 :          0 :     PropertyManager->Tie( BasePropertyName + "/azimuth", (FGExternalForce*)this, &FGExternalForce::GetAzimuth, &FGExternalForce::SetAzimuth);
     109   [ #  #  #  # ]:          0 :   } else if (sFrame == "WIND") {
     110                 :          0 :     ttype = tWindBody;
     111                 :            :   } else {
     112                 :          0 :     cerr << "Invalid frame specified for external force, \"" << Name << "\"." << endl;
     113                 :          0 :     cerr << "Frame set to Body" << endl;
     114                 :          0 :     ttype = tNone;
     115                 :            :   }
     116                 :          0 :   PropertyManager->Tie( BasePropertyName + "/x", (FGExternalForce*)this, &FGExternalForce::GetX, &FGExternalForce::SetX);
     117                 :          0 :   PropertyManager->Tie( BasePropertyName + "/y", (FGExternalForce*)this, &FGExternalForce::GetY, &FGExternalForce::SetY);
     118                 :          0 :   PropertyManager->Tie( BasePropertyName + "/z", (FGExternalForce*)this, &FGExternalForce::GetZ, &FGExternalForce::SetZ);
     119                 :            : 
     120                 :          0 :   location_element = el->FindElement("location");
     121   [ #  #  #  # ]:          0 :   if (!location_element) {
     122                 :          0 :     cerr << "No location element specified in force object." << endl;
     123                 :            :   } else {
     124                 :          0 :     location = location_element->FindElementTripletConvertTo("IN");
     125                 :          0 :     SetLocation(location);
     126                 :            :   }
     127                 :            : 
     128                 :          0 :   direction_element = el->FindElement("direction");
     129   [ #  #  #  # ]:          0 :   if (!direction_element) {
     130                 :          0 :     cerr << "No direction element specified in force object. Default is (0,0,0)." << endl;
     131                 :            :   } else {
     132                 :          0 :     vDirection = direction_element->FindElementTripletConvertTo("IN");
     133                 :          0 :     vDirection.Normalize();
     134                 :            :   }
     135                 :            : 
     136                 :          0 :   Debug(0);
     137                 :          0 : }
     138                 :            : 
     139                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     140                 :            : // Copy constructor
     141                 :            : 
     142                 :          0 : FGExternalForce::FGExternalForce(const FGExternalForce& extForce) : FGForce(extForce)
     143                 :            : {
     144                 :          0 :   magnitude = extForce.magnitude;
     145                 :          0 :   Frame = extForce.Frame;
     146                 :          0 :   vDirection = extForce.vDirection;
     147                 :          0 :   Name = extForce.Name;
     148                 :          0 :   BasePropertyName = extForce.BasePropertyName;
     149                 :          0 :   PropertyManager = extForce.PropertyManager;
     150                 :          0 : }
     151                 :            :   
     152                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     153                 :            : 
     154                 :          0 : FGExternalForce::~FGExternalForce()
     155                 :            : {
     156                 :          0 :   unbind( PropertyManager->GetNode("external_reactions"));
     157 [ #  # ][ #  # ]:          0 :   delete Magnitude_Function;
     158                 :          0 :   Debug(1);
     159                 :          0 : }
     160                 :            : 
     161                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     162                 :            : 
     163                 :          0 : void FGExternalForce::SetMagnitude(double mag)
     164                 :            : {
     165                 :          0 :   magnitude = mag;
     166                 :          0 :   vFn = vDirection*mag;
     167                 :          0 : }
     168                 :            : 
     169                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     170                 :            : 
     171                 :          0 : FGColumnVector3& FGExternalForce::GetBodyForces(void)
     172                 :            : {
     173         [ #  # ]:          0 :   if (Magnitude_Function) {
     174                 :          0 :     double mag = Magnitude_Function->GetValue();
     175                 :          0 :     SetMagnitude(mag);
     176                 :            :   }
     177                 :            :   
     178                 :          0 :   return FGForce::GetBodyForces();
     179                 :            : }
     180                 :            : 
     181                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     182                 :            : 
     183                 :          0 : void FGExternalForce::unbind(FGPropertyManager *node)
     184                 :            : {
     185                 :          0 :   int N = node->nChildren();
     186         [ #  # ]:          0 :   for (int i=0; i<N; i++) {
     187         [ #  # ]:          0 :     if (node->getChild(i)->nChildren() ) {
     188                 :          0 :       unbind( (FGPropertyManager*)node->getChild(i) );
     189         [ #  # ]:          0 :     } else if ( node->getChild(i)->isTied() ) {
     190                 :          0 :       node->getChild(i)->untie();
     191                 :            :     }
     192                 :            :   }
     193                 :          0 : }
     194                 :            : 
     195                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     196                 :            : //    The bitmasked value choices are as follows:
     197                 :            : //    unset: In this case (the default) JSBSim would only print
     198                 :            : //       out the normally expected messages, essentially echoing
     199                 :            : //       the config files as they are read. If the environment
     200                 :            : //       variable is not set, debug_lvl is set to 1 internally
     201                 :            : //    0: This requests JSBSim not to output any messages
     202                 :            : //       whatsoever.
     203                 :            : //    1: This value explicity requests the normal JSBSim
     204                 :            : //       startup messages
     205                 :            : //    2: This value asks for a message to be printed out when
     206                 :            : //       a class is instantiated
     207                 :            : //    4: When this value is set, a message is displayed when a
     208                 :            : //       FGModel object executes its Run() method
     209                 :            : //    8: When this value is set, various runtime state variables
     210                 :            : //       are printed out periodically
     211                 :            : //    16: When set various parameters are sanity checked and
     212                 :            : //       a message is printed out when they go out of bounds
     213                 :            : 
     214                 :          0 : void FGExternalForce::Debug(int from)
     215                 :            : {
     216         [ #  # ]:          0 :   if (debug_lvl <= 0) return;
     217                 :            : 
     218         [ #  # ]:          0 :   if (debug_lvl & 1) { // Standard console startup message output
     219         [ #  # ]:          0 :     if (from == 0) { // Constructor
     220                 :          0 :       cout << "    " << Name << endl;
     221                 :          0 :       cout << "    Frame: " << Frame << endl;
     222                 :          0 :       cout << "    Location: (" << vXYZn(eX) << ", " << vXYZn(eY) << ", " << vXYZn(eZ) << ")" << endl;
     223                 :            :     }
     224                 :            :   }
     225         [ #  # ]:          0 :   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
     226         [ #  # ]:          0 :     if (from == 0) cout << "Instantiated: FGExternalForce" << endl;
     227         [ #  # ]:          0 :     if (from == 1) cout << "Destroyed:    FGExternalForce" << endl;
     228                 :            :   }
     229                 :          0 :   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
     230                 :            :   }
     231                 :          0 :   if (debug_lvl & 8 ) { // Runtime state variables
     232                 :            :   }
     233                 :          0 :   if (debug_lvl & 16) { // Sanity checking
     234                 :            :   }
     235         [ #  # ]:          0 :   if (debug_lvl & 64) {
     236         [ #  # ]:          0 :     if (from == 0) { // Constructor
     237                 :          0 :       cout << IdSrc << endl;
     238                 :          0 :       cout << IdHdr << endl;
     239                 :            :     }
     240                 :            :   }
     241                 :            : }
     242 [ +  + ][ +  - ]:         12 : }

Generated by: LCOV version 1.9