67#include "FGExternalForce.h"
68#include "input_output/FGXMLElement.h"
69#include "input_output/FGLog.h"
77FGPropertyVector3::FGPropertyVector3(FGPropertyManager* pm,
78 const std::string& baseName,
79 const std::string& xcmp,
80 const std::string& ycmp,
81 const std::string& zcmp)
83 data[0] = pm->GetNode(baseName +
"/" + xcmp,
true);
84 data[1] = pm->GetNode(baseName +
"/" + ycmp,
true);
85 data[2] = pm->GetNode(baseName +
"/" + zcmp,
true);
90FGParameter* FGExternalForce::bind(Element *el,
const string& magName,
94 string sFrame = el->GetAttributeValue(
"frame");
96 FGXMLLogging log(el, LogLevel::WARN);
97 log <<
"No frame specified for external " << el->GetName() <<
", \""
98 << Name <<
"\".\nFrame set to Body\n";
100 }
else if (sFrame ==
"BODY") {
102 }
else if (sFrame ==
"LOCAL") {
104 }
else if (sFrame ==
"WIND") {
106 }
else if (sFrame ==
"INERTIAL") {
107 ttype = tInertialBody;
109 FGXMLLogging log(el, LogLevel::WARN);
110 log <<
"Invalid frame specified for external " << el->GetName() <<
", \""
111 << Name <<
"\".\nFrame set to Body\n";
115 Element* direction_element = el->FindElement(
"direction");
116 if (!direction_element) {
117 FGXMLLogging log(el, LogLevel::WARN);
118 log <<
"No direction element specified in " << el->GetName()
119 <<
" object. Default is (0,0,0).\n";
121 FGColumnVector3 direction = direction_element->FindElementTripletConvertTo(
"IN");
122 direction.Normalize();
132 Element* function_element = el->FindElement(
"function");
133 if (function_element) {
134 return new FGFunction(fdmex, function_element);
138 return new FGPropertyValue(node);
144void FGExternalForce::setForce(Element *el)
147 Name = el->GetAttributeValue(
"name");
148 string BasePropertyName =
"external_reactions/" + Name;
150 forceDirection = FGPropertyVector3(PropertyManager.get(), BasePropertyName,
152 forceMagnitude = bind(el, BasePropertyName +
"/magnitude", forceDirection);
154 Element* location_element = el->FindElement(
"location");
155 if (!location_element) {
156 FGXMLLogging log(el, LogLevel::WARN);
157 log <<
"No location element specified in force object.\n";
159 FGColumnVector3 location = location_element->FindElementTripletConvertTo(
"IN");
160 SetLocation(location);
162 PropertyManager->Tie( BasePropertyName +
"/location-x-in", (FGForce*)
this,
163 &FGForce::GetLocationX, &FGForce::SetLocationX);
164 PropertyManager->Tie( BasePropertyName +
"/location-y-in", (FGForce*)
this,
165 &FGForce::GetLocationY, &FGForce::SetLocationY);
166 PropertyManager->Tie( BasePropertyName +
"/location-z-in", (FGForce*)
this,
167 &FGForce::GetLocationZ, &FGForce::SetLocationZ);
172void FGExternalForce::setMoment(Element *el)
175 Name = el->GetAttributeValue(
"name");
176 string BasePropertyName =
"external_reactions/" + Name;
178 momentDirection = FGPropertyVector3(PropertyManager.get(), BasePropertyName,
180 momentMagnitude = bind(el, BasePropertyName +
"/magnitude-lbsft",
188 delete forceMagnitude;
189 delete momentMagnitude;
198 vFn = forceMagnitude->GetValue() * forceDirection;
201 vMn = Transform() * (momentMagnitude->GetValue() * momentDirection);
203 return FGForce::GetBodyForces();
225void FGExternalForce::Debug(
int from)
227 if (debug_lvl <= 0)
return;
231 FGLogging log(LogLevel::DEBUG);
248 log <<
"ERROR/UNKNOWN";
250 log <<
"\n Location: (" << fixed << vXYZn(eX) <<
", " << vXYZn(eY)
251 <<
", " << vXYZn(eZ) <<
")\n";
254 if (debug_lvl & 2 ) {
255 FGLogging log(LogLevel::DEBUG);
256 if (from == 0) log <<
"Instantiated: FGExternalForce\n";
257 if (from == 1) log <<
"Destroyed: FGExternalForce\n";
259 if (debug_lvl & 4 ) {
261 if (debug_lvl & 8 ) {
263 if (debug_lvl & 16) {
265 if (debug_lvl & 64) {
This class implements a 3 element column vector.
~FGExternalForce() override
Destructor.
std::shared_ptr< FGPropertyManager > GetPropertyManager(void) const
Returns a pointer to the property manager object.
A node in a property tree.
Main namespace for the JSBSim Flight Dynamics Model.