Skip to content

Commit

Permalink
Maintenance / Minor changes (JSBSim-Team#952)
Browse files Browse the repository at this point in the history
* Remove useless parameter.
* Increase the sleep time to avoid failures with MSVC.
* Fix the deprecated method `lookup` from pandas.
* A couple of small improvements to `FGPropertyManager::Unbind()`.
* Fix the supported versions of the Python language in `README.md`
* Improvements to some unit tests.
* Fix a number of small details.
  • Loading branch information
bcoconni authored Sep 1, 2023
1 parent e4aa2a9 commit 11146b8
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cpp-python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ jobs:
- name: Upload to Codecov
uses: codecov/codecov-action@v3
with:
working-directory: build/lcov/data/capture
directory: build/lcov/data/capture
files: all_targets.info

Rolling-Release:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ Debian packages for Ubuntu Linux "Bionic" 18.04 LTS and "Focal" 20.04 LTS for 64

* `JSBSim_1.1.13-986.amd64.deb` which installs the executables `JSBSim` and `aeromatic`
* `JSBSim-devel_1.1.13-986.amd64.deb` which installs the development resources (headers and libraries)
* `python3-JSBSim_1.1.13-986.amd64.deb` which installs the Python 3.6 module of JSBSim
* `python3-JSBSim_1.1.13-986.amd64.deb` which installs the Python module of JSBSim

### Python module

JSBSim provides binary wheel packages for its Python module on Windows, Mac OSX and Linux platforms for several Python versions (3.6, 3.7, 3.8, 3.9 and 3.10). These can be installed using either `pip` or `conda`.
JSBSim provides binary wheel packages for its Python module on Windows, Mac OSX and Linux platforms for several Python versions (3.7, 3.8, 3.9, 3.10 and 3.11). These can be installed using either `pip` or `conda`.

#### Installation with `pip`

Expand Down
2 changes: 1 addition & 1 deletion python/jsbsim.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cdef extern from "ExceptionManagement.h":
cdef extern from "initialization/FGInitialCondition.h" namespace "JSBSim":
cdef cppclass c_FGInitialCondition "JSBSim::FGInitialCondition":
c_FGInitialCondition(c_FGInitialCondition* ic)
bool Load(const c_SGPath& rstfile, bool useStoredPath)
bool Load(const c_SGPath& rstfile, bool useAircraftPath)

cdef extern from "initialization/FGLinearization.h" namespace "JSBSim":
cdef cppclass c_FGLinearization "JSBSim::FGLinearization":
Expand Down
8 changes: 4 additions & 4 deletions python/jsbsim.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ cdef class FGFDMExec(FGJSBBase):
model.encode(), add_model_to_path)

def load_script(self, script: str, delta_t: float = 0.0, initfile:str = "") -> bool:
"""@Dox(JSBSim::FGFDMExec::LoadScript) """
"""@Dox(JSBSim::FGFDMExec::LoadScript)"""
scriptfile = os.path.join(self.get_root_dir(), script)
if not os.path.exists(scriptfile):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
Expand Down Expand Up @@ -951,15 +951,15 @@ cdef class FGFDMExec(FGJSBBase):
"""@Dox(JSBSim::FGFDMExec::GetDebugLevel) """
return self.thisptr.GetDebugLevel()

def load_ic(self, rstfile: str, useStoredPath: bool) -> bool:
def load_ic(self, rstfile: str, useAircraftPath: bool) -> bool:
reset_file = _append_xml(rstfile)
if useStoredPath and not os.path.isabs(reset_file):
if useAircraftPath and not os.path.isabs(reset_file):
reset_file = os.path.join(self.get_full_aircraft_path(), reset_file)
if not os.path.exists(reset_file):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
reset_file)
return deref(self.thisptr.GetIC()).Load(c_SGPath(rstfile.encode(), NULL),
useStoredPath)
useAircraftPath)

def get_propagate(self) -> FGPropagate:
"""@Dox(JSBSim::FGFDMExec::GetPropagate)"""
Expand Down
2 changes: 1 addition & 1 deletion src/FGFDMExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ bool FGFDMExec::LoadPlanet(Element* element)
string model = atm_element->GetAttributeValue("model");
if (model == "MSIS") {
// Replace the existing atmosphere model
instance->Unbind(Models[eAtmosphere].get());
instance->Unbind(Models[eAtmosphere]);
Models[eAtmosphere] = std::make_shared<FGMSIS>(this);
Atmosphere = static_cast<FGAtmosphere*>(Models[eAtmosphere].get());

Expand Down
6 changes: 5 additions & 1 deletion src/JSBSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ int main(int argc, char* argv[])
std::cerr << "FATAL ERROR: JSBSim terminated with an exception."
<< std::endl << "The message was: " << msg << std::endl;
return 1;
} catch (const JSBSim::BaseException& e) {
std::cerr << "FATAL ERROR: JSBSim terminated with an exception."
<< std::endl << "The message was: " << e.what() << std::endl;
return 1;
} catch (...) {
std::cerr << "FATAL ERROR: JSBSim terminated with an unknown exception."
<< std::endl;
Expand Down Expand Up @@ -794,7 +798,7 @@ void PrintHelp(void)
cout << " --nice specifies to run at lower CPU usage" << endl;
cout << " --nohighlight specifies that console output should be pure text only (no color)" << endl;
cout << " --suspend specifies to suspend the simulation after initialization" << endl;
cout << " --initfile=<filename> specifies an initilization file" << endl;
cout << " --initfile=<filename> specifies an initialization file" << endl;
cout << " --planet=<filename> specifies a planet definition file" << endl;
cout << " --catalog specifies that all properties for this aircraft model should be printed" << endl;
cout << " (catalog=aircraftname is an optional format)" << endl;
Expand Down
6 changes: 3 additions & 3 deletions src/initialization/FGInitialCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,10 +1002,10 @@ double FGInitialCondition::GetBodyVelFpsIC(int idx) const

//******************************************************************************

bool FGInitialCondition::Load(const SGPath& rstfile, bool useStoredPath)
bool FGInitialCondition::Load(const SGPath& rstfile, bool useAircraftPath)
{
SGPath init_file_name;
if(useStoredPath && rstfile.isRelative()) {
if(useAircraftPath && rstfile.isRelative()) {
init_file_name = fdmex->GetFullAircraftPath()/rstfile.utf8Str();
} else {
init_file_name = rstfile;
Expand All @@ -1022,7 +1022,7 @@ bool FGInitialCondition::Load(const SGPath& rstfile, bool useStoredPath)
throw BaseException(s.str());
}

if (document->GetName() != string("initialize")) {
if (document->GetName() != "initialize") {
stringstream s;
s << "File: " << init_file_name << " is not a reset file.";
cerr << s.str() << endl;
Expand Down
4 changes: 2 additions & 2 deletions src/initialization/FGInitialCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,9 @@ class JSBSIM_API FGInitialCondition : public FGJSBBase

/** Loads the initial conditions.
@param rstname The name of an initial conditions file
@param useStoredPath true if the stored path to the IC file should be used
@param useAircraftPath true if path is given relative to the aircraft path.
@return true if successful */
bool Load(const SGPath& rstname, bool useStoredPath = true );
bool Load(const SGPath& rstname, bool useAircraftPath = true );

/** Is an engine running ?
@param index of the engine to be checked
Expand Down
2 changes: 1 addition & 1 deletion src/input_output/FGPropertyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void FGPropertyManager::Unbind(void)

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void FGPropertyManager::Unbind(void* instance)
void FGPropertyManager::Unbind(const void* instance)
{
auto it = tied_properties.begin();

Expand Down
20 changes: 17 additions & 3 deletions src/input_output/FGPropertyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ INCLUDES

#include <string>
#include <list>
#include <memory>
#include "simgear/props/props.hxx"
#if !PROPS_STANDALONE
# include "simgear/math/SGMath.hxx"
Expand Down Expand Up @@ -437,8 +438,21 @@ class JSBSIM_API FGPropertyManager
*
* Classes should use this function to release control of any
* properties they have bound using this property manager.
* @param instance The instance which properties shall be unbound.
*/
void Unbind(void* instance);
void Unbind(const void* instance);

/**
* Unbind all properties bound by this manager to an instance.
*
* Classes should use this function to release control of any
* properties they have bound using this property manager.
* Helper function for shared_ptr
* @see Unbind(const void*)
*/
template <typename T> void Unbind(const std::shared_ptr<T>& instance) {
Unbind(instance.get());
}

/**
* Tie a property to an external variable.
Expand Down Expand Up @@ -615,10 +629,10 @@ class JSBSIM_API FGPropertyManager
private:
struct PropertyState {
SGPropertyNode_ptr node;
void* BindingInstance = nullptr;
const void* BindingInstance = nullptr;
bool WriteAttribute = true;
bool ReadAttribute = true;
PropertyState(SGPropertyNode* property, void* instance)
PropertyState(SGPropertyNode* property, const void* instance)
: node(property), BindingInstance(instance) {
WriteAttribute = node->getAttribute(SGPropertyNode::WRITE);
ReadAttribute = node->getAttribute(SGPropertyNode::READ);
Expand Down
2 changes: 0 additions & 2 deletions src/math/FGParameterValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

#include <stdexcept>

#include "math/FGRealValue.h"
#include "math/FGPropertyValue.h"
#include "input_output/FGXMLElement.h"
Expand Down
2 changes: 1 addition & 1 deletion src/models/FGInertial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void FGInertial::Debug(int from)
cout << " Semi minor axis: " << b << endl;
cout << " Rotation rate : " << scientific << vOmegaPlanet(eZ) << endl;
cout << " GM : " << GM << endl;
cout << " J2 : " << J2 << endl << defaultfloat;
cout << " J2 : " << J2 << endl << defaultfloat << endl;
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
Expand Down
2 changes: 1 addition & 1 deletion src/models/FGInertial.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class JSBSIM_API FGInertial : public FGModel {
}

/** Set the simulation time.
The elapsed time can be used by the ground callbck to assess the planet
The elapsed time can be used by the ground callback to assess the planet
rotation or the movement of objects.
@param time elapsed time in seconds since the simulation started.
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ set(PYTHON_TESTS ResetOutputFiles

foreach(test ${PYTHON_TESTS})
add_test(NAME ${test}
COMMAND ${Python3_EXECUTABLE} -B ${CMAKE_CURRENT_SOURCE_DIR}/${test}.py)
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test}.py)
endforeach()
5 changes: 2 additions & 3 deletions tests/JSBSim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ def FindDifferences(ref, other, tol):
delta = np.abs(ref - other)

idxmax = delta.idxmax()
ref_max = pd.Series(ref.lookup(idxmax, ref.columns), index=ref.columns)
other_max = pd.Series(other.lookup(idxmax, other.columns),
index=other.columns)
ref_max = pd.Series(np.diag(ref.loc[idxmax]), index=ref.columns)
other_max = pd.Series(np.diag(other.loc[idxmax]), index=other.columns)
diff = pd.concat([idxmax, delta.max(), ref_max, other_max], axis=1)
diff.columns = ['Time', 'delta', 'ref value', 'value']
return diff[diff['delta'] > tol]
2 changes: 1 addition & 1 deletion tests/TestInputSocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def sendCommand(self, command):
return self.getOutput()

def getOutput(self):
time.sleep(0.5) # Wait for the socket to process all the data.
time.sleep(1.0) # Wait for the socket to process all the data.
return self.tn.read_very_eager().decode()

def getPropertyValue(self, property):
Expand Down
5 changes: 2 additions & 3 deletions tests/unit_tests/FGAtmosphereTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class DummyAtmosphere : public FGAtmosphere
}
// Getters for the protected members
static constexpr double GetR(void) { return Reng0; }
static constexpr double GetGamma(void) { return SHRatio; }
static constexpr double GetBeta(void) { return Beta; }
static constexpr double GetSutherlandConstant(void) { return SutherlandConstant; }
static constexpr double GetPSFtoPa(void) { return psftopa; }
Expand All @@ -44,7 +43,7 @@ class DummyAtmosphere : public FGAtmosphere
};

constexpr double R = DummyAtmosphere::GetR();
constexpr double gama = DummyAtmosphere::GetGamma();
constexpr double gama = FGAtmosphere::SHRatio;
constexpr double beta = DummyAtmosphere::GetBeta();
constexpr double k = DummyAtmosphere::GetSutherlandConstant();
constexpr double psftopa = DummyAtmosphere::GetPSFtoPa();
Expand All @@ -58,7 +57,7 @@ class FGAtmosphereTest : public CxxTest::TestSuite

FGAtmosphereTest() {
auto atm = fdmex.GetAtmosphere();
fdmex.GetPropertyManager()->Unbind(atm.get());
fdmex.GetPropertyManager()->Unbind(atm);
}

void testDefaultValuesBeforeInit()
Expand Down
30 changes: 20 additions & 10 deletions tests/unit_tests/FGAuxiliaryTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ class DummyAtmosphere : public FGAtmosphere

constexpr double R = DummyAtmosphere::GetR();

class FGAtmosphereTest : public CxxTest::TestSuite
class FGAuxiliaryTest : public CxxTest::TestSuite
{
public:
static constexpr double gama = FGAtmosphere::SHRatio;

FGFDMExec fdmex;
std::shared_ptr<FGAtmosphere> atm;

FGAuxiliaryTest() {
auto aux = fdmex.GetAuxiliary();
atm = fdmex.GetAtmosphere();
atm->InitModel();
fdmex.GetPropertyManager()->Unbind(aux);
}

void testPitotTotalPressure() {
FGFDMExec fdmex;
auto atm = fdmex.GetAtmosphere();
auto aux = FGAuxiliary(&fdmex);
atm->InitModel();
aux.in.vLocation = fdmex.GetAuxiliary()->in.vLocation;

// Ambient conditions far upstream (i.e. upstream the normal schock
// in supersonic flight)
Expand Down Expand Up @@ -64,13 +72,13 @@ class FGAtmosphereTest : public CxxTest::TestSuite
// energy conservation
TS_ASSERT_DELTA(Cp*t1+0.5*u1*u1, Cp*t2+0.5*u2*u2, epsilon);
}

fdmex.GetPropertyManager()->Unbind(&aux);
}

void testMachFromImpactPressure() {
FGFDMExec fdmex;
auto atm = fdmex.GetAtmosphere();
auto aux = FGAuxiliary(&fdmex);
atm->InitModel();
aux.in.vLocation = fdmex.GetAuxiliary()->in.vLocation;

// Ambient conditions far upstream (i.e. upstream the normal schock
// in supersonic flight)
Expand Down Expand Up @@ -112,14 +120,14 @@ class FGAtmosphereTest : public CxxTest::TestSuite
TS_ASSERT_DELTA(mach1, M1, 1e-7);
TS_ASSERT_DELTA(mach2, M2, 1e-7);
}

fdmex.GetPropertyManager()->Unbind(&aux);
}

void testCASConversion() {
FGFDMExec fdmex;
auto atm = fdmex.GetAtmosphere();
auto aux = FGAuxiliary(&fdmex);
atm->InitModel();
aux.in.StdDaySLsoundspeed = atm->StdDaySLsoundspeed;
aux.in.vLocation = fdmex.GetAuxiliary()->in.vLocation;

// Ambient conditions far upstream (i.e. upstream the normal schock
// in supersonic flight)
Expand Down Expand Up @@ -176,5 +184,7 @@ class FGAtmosphereTest : public CxxTest::TestSuite

TS_ASSERT_DELTA(aux.VcalibratedFromMach(M1, p1)/(mach*asl), 1.0, 1e-8);
}

fdmex.GetPropertyManager()->Unbind(&aux);
}
};
2 changes: 1 addition & 1 deletion tests/unit_tests/FGMSISTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FGMSISTest : public CxxTest::TestSuite, FGJSBBase

FGMSISTest() {
std_atm = fdmex.GetAtmosphere();
fdmex.GetPropertyManager()->Unbind(std_atm.get());
fdmex.GetPropertyManager()->Unbind(std_atm);

const double species_mmol[8] {28.0134, 31.9988, 31.9988/2.0, 4.0, 1.0, 39.948,
28.0134/2.0, 31.9988/2.0};
Expand Down

0 comments on commit 11146b8

Please sign in to comment.