66 #include "FGFDMExec.h"
67 #include "FGExternalForce.h"
68 #include "input_output/FGXMLElement.h"
76 FGPropertyVector3::FGPropertyVector3(FGPropertyManager* pm,
77 const std::string& baseName,
78 const std::string& xcmp,
79 const std::string& ycmp,
80 const std::string& zcmp)
82 data[0] = pm->CreatePropertyObject<
double>(baseName +
"/" + xcmp);
83 data[1] = pm->CreatePropertyObject<
double>(baseName +
"/" + ycmp);
84 data[2] = pm->CreatePropertyObject<
double>(baseName +
"/" + zcmp);
89 FGParameter* FGExternalForce::bind(Element *el,
const string& magName,
93 string sFrame = el->GetAttributeValue(
"frame");
95 cerr << el->ReadFrom()
96 <<
"No frame specified for external " << el->GetName() <<
", \""
97 << Name <<
"\"." << endl
98 <<
"Frame set to Body" << endl;
100 }
else if (sFrame ==
"BODY") {
102 }
else if (sFrame ==
"LOCAL") {
104 }
else if (sFrame ==
"WIND") {
107 cerr << el->ReadFrom()
108 <<
"Invalid frame specified for external " << el->GetName() <<
", \""
109 << Name <<
"\"." << endl
110 <<
"Frame set to Body" << endl;
114 Element* direction_element = el->FindElement(
"direction");
115 if (!direction_element) {
116 cerr << el->ReadFrom()
117 <<
"No direction element specified in " << el->GetName()
118 <<
" object. Default is (0,0,0)." << endl;
120 FGColumnVector3 direction = direction_element->FindElementTripletConvertTo(
"IN");
121 direction.Normalize();
131 Element* function_element = el->FindElement(
"function");
132 if (function_element) {
133 return new FGFunction(fdmex, function_element);
135 FGPropertyManager* pm = fdmex->GetPropertyManager();
136 FGPropertyNode* node = pm->GetNode(magName,
true);
137 return new FGPropertyValue(node);
143 void FGExternalForce::setForce(Element *el)
145 FGPropertyManager* PropertyManager = fdmex->GetPropertyManager();
146 Name = el->GetAttributeValue(
"name");
147 string BasePropertyName =
"external_reactions/" + Name;
149 forceDirection = FGPropertyVector3(PropertyManager, BasePropertyName,
151 forceMagnitude = bind(el, BasePropertyName +
"/magnitude", forceDirection);
153 Element* location_element = el->FindElement(
"location");
154 if (!location_element) {
155 cerr << el->ReadFrom()
156 <<
"No location element specified in force object." << endl;
158 FGColumnVector3 location = location_element->FindElementTripletConvertTo(
"IN");
159 SetLocation(location);
161 PropertyManager->Tie( BasePropertyName +
"/location-x-in", (FGForce*)
this,
162 &FGForce::GetLocationX, &FGForce::SetLocationX);
163 PropertyManager->Tie( BasePropertyName +
"/location-y-in", (FGForce*)
this,
164 &FGForce::GetLocationY, &FGForce::SetLocationY);
165 PropertyManager->Tie( BasePropertyName +
"/location-z-in", (FGForce*)
this,
166 &FGForce::GetLocationZ, &FGForce::SetLocationZ);
171 void FGExternalForce::setMoment(Element *el)
173 FGPropertyManager* PropertyManager = fdmex->GetPropertyManager();
174 Name = el->GetAttributeValue(
"name");
175 string BasePropertyName =
"external_reactions/" + Name;
177 momentDirection = FGPropertyVector3(PropertyManager, BasePropertyName,
179 momentMagnitude = bind(el, BasePropertyName +
"/magnitude-lbsft",
185 FGExternalForce::~FGExternalForce()
187 delete forceMagnitude;
188 delete momentMagnitude;
197 vFn = forceMagnitude->GetValue() * forceDirection;
200 vMn = Transform() * (momentMagnitude->GetValue() * momentDirection);
202 return FGForce::GetBodyForces();
224 void FGExternalForce::Debug(
int from)
226 if (debug_lvl <= 0)
return;
230 cout <<
" " << Name << endl;
243 cout <<
"ERROR/UNKNOWN";
245 cout << endl <<
" Location: (" << vXYZn(eX) <<
", " << vXYZn(eY) <<
", " << vXYZn(eZ) <<
")" << endl;
248 if (debug_lvl & 2 ) {
249 if (from == 0) cout <<
"Instantiated: FGExternalForce" << endl;
250 if (from == 1) cout <<
"Destroyed: FGExternalForce" << endl;
252 if (debug_lvl & 4 ) {
254 if (debug_lvl & 8 ) {
256 if (debug_lvl & 16) {
258 if (debug_lvl & 64) {