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"
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 static const char *IdSrc = "$Id$";
53 static const char *IdHdr = ID_EXTERNALREACTIONS;
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
59 FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex)
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 bool FGExternalReactions::Load(Element* el)
69 FGModel::Load(el); // Call the base class Load() function to load interface properties.
73 // Parse force elements
76 Element* force_element = el->FindElement("force");
77 while (force_element) {
78 Forces.push_back( new FGExternalForce(FDMExec, force_element, index) );
81 force_element = el->FindNextElement("force");
87 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 FGExternalReactions::~FGExternalReactions()
91 for (unsigned int i=0; i<Forces.size(); i++) delete Forces[i];
97 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 bool FGExternalReactions::InitModel(void)
101 if (!FGModel::InitModel()) return false;
106 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 bool FGExternalReactions::Run()
110 if (FGModel::Run()) return true;
111 if (FDMExec->Holding()) return false; // if paused don't execute
112 if (NoneDefined) return true;
114 vTotalForces.InitMatrix();
115 vTotalMoments.InitMatrix();
117 for (unsigned int i=0; i<Forces.size(); i++) {
118 vTotalForces += Forces[i]->GetBodyForces();
119 vTotalMoments += Forces[i]->GetMoments();
125 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 // The bitmasked value choices are as follows:
127 // unset: In this case (the default) JSBSim would only print
128 // out the normally expected messages, essentially echoing
129 // the config files as they are read. If the environment
130 // variable is not set, debug_lvl is set to 1 internally
131 // 0: This requests JSBSim not to output any messages
133 // 1: This value explicity requests the normal JSBSim
135 // 2: This value asks for a message to be printed out when
136 // a class is instantiated
137 // 4: When this value is set, a message is displayed when a
138 // FGModel object executes its Run() method
139 // 8: When this value is set, various runtime state variables
140 // are printed out periodically
141 // 16: When set various parameters are sanity checked and
142 // a message is printed out when they go out of bounds
144 void FGExternalReactions::Debug(int from)
146 if (debug_lvl <= 0) return;
148 if (debug_lvl & 1) { // Standard console startup message output
149 if (from == 0) { // Constructor - loading and initialization
151 if (from == 2) { // Loading
152 cout << endl << " External Reactions: " << endl;
155 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
156 if (from == 0) cout << "Instantiated: FGExternalReactions" << endl;
157 if (from == 1) cout << "Destroyed: FGExternalReactions" << endl;
159 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
161 if (debug_lvl & 8 ) { // Runtime state variables
163 if (debug_lvl & 16) { // Sanity checking
165 if (debug_lvl & 64) {
166 if (from == 0) { // Constructor
167 cout << IdSrc << endl;
168 cout << IdHdr << endl;
173 } // namespace JSBSim