From: Bertrand <bco...@us...> - 2017-05-28 19:01:52
|
Update of /cvsroot/jsbsim/JSBSim/src/models In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv1380/src/models Modified Files: FGExternalForce.cpp FGExternalForce.h Log Message: More code clean up and some documentation update. Index: FGExternalForce.cpp =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/src/models/FGExternalForce.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -r1.18 -r1.19 *** FGExternalForce.cpp 26 May 2017 12:25:40 -0000 1.18 --- FGExternalForce.cpp 28 May 2017 19:01:49 -0000 1.19 *************** *** 55,58 **** --- 55,60 ---- #include "FGExternalForce.h" #include "input_output/FGXMLElement.h" + #include "math/FGPropertyValue.h" + #include "math/FGFunction.h" #include <iostream> *************** *** 69,85 **** : FGForce(FDMExec) { - Element* location_element=0; - Element* direction_element=0; - Element* function_element=0; - string sFrame; - string BasePropertyName; - FGColumnVector3 location; - Magnitude_Function = 0; - magnitude = 0.0; - azimuth = 0.0; - FGPropertyManager* PropertyManager = fdmex->GetPropertyManager(); Name = el->GetAttributeValue("name"); ! BasePropertyName = "external_reactions/" + Name; // The value sent to the sim through the external_forces/{force name}/magnitude --- 71,77 ---- : FGForce(FDMExec) { FGPropertyManager* PropertyManager = fdmex->GetPropertyManager(); Name = el->GetAttributeValue("name"); ! string BasePropertyName = "external_reactions/" + Name; // The value sent to the sim through the external_forces/{force name}/magnitude *************** *** 88,104 **** // is specified with the frame attribute. The vector is normalized to magnitude 1. ! function_element = el->FindElement("function"); if (function_element) { ! Magnitude_Function = new FGFunction(PropertyManager, function_element); } else { ! PropertyManager->Tie( BasePropertyName + "/magnitude",(FGExternalForce*)this, &FGExternalForce::GetMagnitude, &FGExternalForce::SetMagnitude); } - // Set frame (from FGForce). ! sFrame = el->GetAttributeValue("frame"); if (sFrame.empty()) { ! cerr << "No frame specified for external force, \"" << Name << "\"." << endl; ! cerr << "Frame set to Body" << endl; ttype = tNone; } else if (sFrame == "BODY") { --- 80,98 ---- // is specified with the frame attribute. The vector is normalized to magnitude 1. ! Element* function_element = el->FindElement("function"); if (function_element) { ! Magnitude = new FGFunction(PropertyManager, function_element); } else { ! string nodeName = BasePropertyName + "/magnitude"; ! FGPropertyNode* node = PropertyManager->GetNode(nodeName, true); ! Magnitude = new FGPropertyValue(node); } // Set frame (from FGForce). ! string sFrame = el->GetAttributeValue("frame"); if (sFrame.empty()) { ! cerr << el->ReadFrom() ! << "No frame specified for external force, \"" << Name << "\"." << endl ! << "Frame set to Body" << endl; ttype = tNone; } else if (sFrame == "BODY") { *************** *** 106,126 **** } else if (sFrame == "LOCAL") { ttype = tLocalBody; - PropertyManager->Tie( BasePropertyName + "/azimuth", (FGExternalForce*)this, &FGExternalForce::GetAzimuth, &FGExternalForce::SetAzimuth); } else if (sFrame == "WIND") { ttype = tWindBody; } else { ! cerr << "Invalid frame specified for external force, \"" << Name << "\"." << endl; ! cerr << "Frame set to Body" << endl; ttype = tNone; } - PropertyManager->Tie( BasePropertyName + "/x", (FGExternalForce*)this, &FGExternalForce::GetX, &FGExternalForce::SetX); - PropertyManager->Tie( BasePropertyName + "/y", (FGExternalForce*)this, &FGExternalForce::GetY, &FGExternalForce::SetY); - PropertyManager->Tie( BasePropertyName + "/z", (FGExternalForce*)this, &FGExternalForce::GetZ, &FGExternalForce::SetZ); ! location_element = el->FindElement("location"); if (!location_element) { ! cerr << "No location element specified in force object." << endl; } else { ! location = location_element->FindElementTripletConvertTo("IN"); SetLocation(location); } --- 100,118 ---- } else if (sFrame == "LOCAL") { ttype = tLocalBody; } else if (sFrame == "WIND") { ttype = tWindBody; } else { ! cerr << el->ReadFrom() ! << "Invalid frame specified for external force, \"" << Name << "\"." ! << endl << "Frame set to Body" << endl; ttype = tNone; } ! Element* location_element = el->FindElement("location"); if (!location_element) { ! cerr << el->ReadFrom() ! << "No location element specified in force object." << endl; } else { ! FGColumnVector3 location = location_element->FindElementTripletConvertTo("IN"); SetLocation(location); } *************** *** 132,138 **** &FGForce::GetLocationZ, &FGForce::SetLocationZ); ! direction_element = el->FindElement("direction"); if (!direction_element) { ! cerr << "No direction element specified in force object. Default is (0,0,0)." << endl; } else { vDirection = direction_element->FindElementTripletConvertTo("IN"); --- 124,132 ---- &FGForce::GetLocationZ, &FGForce::SetLocationZ); ! Element* direction_element = el->FindElement("direction"); if (!direction_element) { ! cerr << el->ReadFrom() ! << "No direction element specified in force object. Default is (0,0,0)." ! << endl; } else { vDirection = direction_element->FindElementTripletConvertTo("IN"); *************** *** 140,143 **** --- 134,144 ---- } + PropertyManager->Tie(BasePropertyName + "/x", (FGExternalForce*)this, + &FGExternalForce::GetDirectionX, &FGExternalForce::SetDirectionX); + PropertyManager->Tie(BasePropertyName + "/y", (FGExternalForce*)this, + &FGExternalForce::GetDirectionY, &FGExternalForce::SetDirectionY); + PropertyManager->Tie(BasePropertyName + "/z", (FGExternalForce*)this, + &FGExternalForce::GetDirectionZ, &FGExternalForce::SetDirectionZ); + Debug(0); } *************** *** 147,151 **** FGExternalForce::~FGExternalForce() { ! delete Magnitude_Function; Debug(1); } --- 148,152 ---- FGExternalForce::~FGExternalForce() { ! delete Magnitude; Debug(1); } *************** *** 153,171 **** //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - void FGExternalForce::SetMagnitude(double mag) - { - magnitude = mag; - vFn = vDirection*mag; - } - - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - const FGColumnVector3& FGExternalForce::GetBodyForces(void) { ! if (Magnitude_Function) { ! double mag = Magnitude_Function->GetValue(); ! SetMagnitude(mag); ! } ! return FGForce::GetBodyForces(); } --- 154,160 ---- //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% const FGColumnVector3& FGExternalForce::GetBodyForces(void) { ! vFn = Magnitude->GetValue() * vDirection; return FGForce::GetBodyForces(); } Index: FGExternalForce.h =================================================================== RCS file: /cvsroot/jsbsim/JSBSim/src/models/FGExternalForce.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** FGExternalForce.h 26 May 2017 12:25:40 -0000 1.15 --- FGExternalForce.h 28 May 2017 19:01:49 -0000 1.16 *************** *** 8,14 **** This program is free software; you can redistribute it and/or modify it under ! the terms of the GNU Lesser General Public License as published by the Free Software ! Foundation; either version 2 of the License, or (at your option) any later ! version. This program is distributed in the hope that it will be useful, but WITHOUT --- 8,14 ---- This program is free software; you can redistribute it and/or modify it under ! the terms of the GNU Lesser General Public License as published by the Free ! Software Foundation; either version 2 of the License, or (at your option) any ! later version. This program is distributed in the hope that it will be useful, but WITHOUT *************** *** 17,26 **** details. ! You should have received a copy of the GNU Lesser General Public License along with ! this program; if not, write to the Free Software Foundation, Inc., 59 Temple ! Place - Suite 330, Boston, MA 02111-1307, USA. ! Further information about the GNU Lesser General Public License can also be found on ! the world wide web at http://www.gnu.org. --- 17,26 ---- details. ! You should have received a copy of the GNU Lesser General Public License along ! with this program; if not, write to the Free Software Foundation, Inc., 59 ! Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! Further information about the GNU Lesser General Public License can also be ! found on the world wide web at http://www.gnu.org. *************** *** 41,50 **** #include <string> - #include "FGFDMExec.h" - #include "FGJSBBase.h" #include "models/propulsion/FGForce.h" - #include "input_output/FGPropertyManager.h" #include "math/FGColumnVector3.h" - #include "math/FGFunction.h" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --- 41,46 ---- *************** *** 60,63 **** --- 56,61 ---- namespace JSBSim { + class FGParameter; + /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS DOCUMENTATION *************** *** 67,71 **** This class encapsulates an individual force applied at the specified location on the vehicle, and oriented as specified in one of three frames: ! - BODY frame is defined with the X axis positive forward, the Y axis positive out the right wing, and the Z axis completing the set --- 65,69 ---- This class encapsulates an individual force applied at the specified location on the vehicle, and oriented as specified in one of three frames: ! - BODY frame is defined with the X axis positive forward, the Y axis positive out the right wing, and the Z axis completing the set *************** *** 81,92 **** from this WIND frame. ! Much of the substance of this class is located in the FGForce base class, from ! which this class is derived. ! Here is the XML definition of a force (optional items are in []): ! @code <force name="name" frame="BODY | LOCAL | WIND"> ! [<function> ... </function>] --- 79,90 ---- from this WIND frame. ! Much of the substance of this class is located in the FGForce base class, ! from which this class is derived. ! Here is the XML definition of a force (optional items are in []): ! @code <force name="name" frame="BODY | LOCAL | WIND"> ! [<function> ... </function>] *************** *** 105,125 **** The initial direction can optionally be set by specifying a unit vector ! in the chosen frame (body, local, or wind). The direction is specified ! at runtime through setting any/all of the following properties: ! ! @code ! external_reactions/{force name}/x ! external_reactions/{force name}/y ! external_reactions/{force name}/z ! @endcode ! As an example, a parachute can be defined oriented in the wind axis frame so the drag always acts in the drag direction - opposite the positive X axis. That does not include the effects of parachute oscillations, but those could be handled in the calling application. ! The force direction is not actually required to be specified as a unit vector, but prior to the force vector being calculated, the direction ! vector is normalized. The location of the force vector, in structural coordinates, can be set at --- 103,134 ---- The initial direction can optionally be set by specifying a unit vector ! in the chosen frame (body, local, or wind). ! As an example, a parachute can be defined oriented in the wind axis frame so the drag always acts in the drag direction - opposite the positive X axis. That does not include the effects of parachute oscillations, but those could be handled in the calling application. ! The force direction is not actually required to be specified as a unit vector, but prior to the force vector being calculated, the direction ! vector is normalized when initialized. ! ! The direction can be specified at runtime through setting any/all of the ! following properties: ! ! @code ! external_reactions/{force name}/x ! external_reactions/{force name}/y ! external_reactions/{force name}/z ! @endcode ! ! However in that case, the direction is no longer normalized. ! ! When no <function> has been provided in the definition, the force magnitude ! can be specified through the following property: ! ! @code ! external_reactions/{force name}/magnitude ! @endcode The location of the force vector, in structural coordinates, can be set at *************** *** 131,135 **** external_reactions/{force name}/location-z-in @endcode ! */ --- 140,144 ---- external_reactions/{force name}/location-z-in @endcode ! */ *************** *** 144,148 **** @param FDMExec pointer to the main executive class. @param el pointer to the XML element defining an individual force. - @param index the position of this force object in the whole list. */ FGExternalForce(FGFDMExec *FDMExec, Element *el); --- 153,156 ---- *************** *** 156,182 **** ~FGExternalForce(); - void SetMagnitude(double mag); - void SetAzimuth(double az) {azimuth = az;} - const FGColumnVector3& GetBodyForces(void); ! double GetMagnitude(void) const {return magnitude;} ! double GetAzimuth(void) const {return azimuth;} ! double GetX(void) const {return vDirection(eX);} ! double GetY(void) const {return vDirection(eY);} ! double GetZ(void) const {return vDirection(eZ);} ! void SetX(double x) {vDirection(eX) = x;} ! void SetY(double y) {vDirection(eY) = y;} ! void SetZ(double z) {vDirection(eZ) = z;} private: std::string Name; ! FGFunction* Magnitude_Function; FGColumnVector3 vDirection; - double magnitude; - double azimuth; void Debug(int from); }; } #endif - --- 164,182 ---- ~FGExternalForce(); const FGColumnVector3& GetBodyForces(void); ! double GetDirectionX(void) const {return vDirection(eX);} ! double GetDirectionY(void) const {return vDirection(eY);} ! double GetDirectionZ(void) const {return vDirection(eZ);} ! void SetDirectionX(double x) {vDirection(eX) = x;} ! void SetDirectionY(double y) {vDirection(eY) = y;} ! void SetDirectionZ(double z) {vDirection(eZ) = z;} private: std::string Name; ! FGParameter* Magnitude; FGColumnVector3 vDirection; void Debug(int from); }; } #endif |