1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGExternalReactions.cpp
6 Purpose: Manages the External Forces
9 ------------- Copyright (C) 2006 David P. Culp (davidculp2@comcast.net) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
32 --------------------------------------------------------------------------------
35 /%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 #include "FGExternalReactions.h"
40 #include "input_output/FGXMLElement.h"
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 static const char *IdSrc = "$Id: FGExternalReactions.cpp,v 1.8 2009/11/12 13:08:11 jberndt Exp $";
57 static const char *IdHdr = ID_EXTERNALREACTIONS;
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex)
69 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71 bool FGExternalReactions::Load(Element* el)
73 FGModel::Load(el); // Call the base class Load() function to load interface properties.
77 // Parse force elements
80 Element* force_element = el->FindElement("force");
81 while (force_element) {
82 Forces.push_back( new FGExternalForce(FDMExec, force_element, index) );
85 force_element = el->FindNextElement("force");
88 FGModel::PostLoad(el);
93 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95 FGExternalReactions::~FGExternalReactions()
97 for (unsigned int i=0; i<Forces.size(); i++) delete Forces[i];
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 bool FGExternalReactions::InitModel(void)
107 if (!FGModel::InitModel()) return false;
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 bool FGExternalReactions::Run()
116 if (FGModel::Run()) return true;
117 if (FDMExec->Holding()) return false; // if paused don't execute
118 if (NoneDefined) return true;
122 vTotalForces.InitMatrix();
123 vTotalMoments.InitMatrix();
125 for (unsigned int i=0; i<Forces.size(); i++) {
126 vTotalForces += Forces[i]->GetBodyForces();
127 vTotalMoments += Forces[i]->GetMoments();
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 // The bitmasked value choices are as follows:
137 // unset: In this case (the default) JSBSim would only print
138 // out the normally expected messages, essentially echoing
139 // the config files as they are read. If the environment
140 // variable is not set, debug_lvl is set to 1 internally
141 // 0: This requests JSBSim not to output any messages
143 // 1: This value explicity requests the normal JSBSim
145 // 2: This value asks for a message to be printed out when
146 // a class is instantiated
147 // 4: When this value is set, a message is displayed when a
148 // FGModel object executes its Run() method
149 // 8: When this value is set, various runtime state variables
150 // are printed out periodically
151 // 16: When set various parameters are sanity checked and
152 // a message is printed out when they go out of bounds
154 void FGExternalReactions::Debug(int from)
156 if (debug_lvl <= 0) return;
158 if (debug_lvl & 1) { // Standard console startup message output
159 if (from == 0) { // Constructor - loading and initialization
161 if (from == 2) { // Loading
162 cout << endl << " External Reactions: " << endl;
165 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
166 if (from == 0) cout << "Instantiated: FGExternalReactions" << endl;
167 if (from == 1) cout << "Destroyed: FGExternalReactions" << endl;
169 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
171 if (debug_lvl & 8 ) { // Runtime state variables
173 if (debug_lvl & 16) { // Sanity checking
175 if (debug_lvl & 64) {
176 if (from == 0) { // Constructor
177 cout << IdSrc << endl;
178 cout << IdHdr << endl;
183 } // namespace JSBSim