def testOutputRate(self): self.fdm.load_script(self.script_path) # Check that the output is enabled by default self.assertEqual(self.fdm.get_property_value("simulation/output/enabled"), 1.0) # Check that the rate is consistent with the values extracted from the # script and the aircraft definition self.assertAlmostEqual(self.fdm.get_property_value("simulation/output/log_rate_hz"), self.rateHz, delta=1e-5) self.fdm.run_ic() for i in xrange(self.rate): self.fdm.run() output = Table() output.ReadCSV(self.output_file) # According to the settings, the output file must contain 2 lines in # addition to the headers : # 1. The initial conditions # 2. The output after 'rate' iterations self.assertEqual(output.get_column(0)[1], 0.0) self.assertEqual(output.get_column(0)[2], self.rate * self.dt) self.assertEqual(output.get_column(0)[2], self.fdm.get_property_value("simulation/sim-time-sec"))
def testOutputRate(self): self.fdm.load_script(self.script_path) # Check that the output is enabled by default self.assertEqual(self.fdm.get_property_value("simulation/output/enabled"), 1.0) # Check that the rate is consistent with the values extracted from the # script and the aircraft definition self.assertAlmostEqual(self.fdm.get_property_value("simulation/output/log_rate_hz"), self.rateHz, delta=1E-5) self.fdm.run_ic() for i in xrange(self.rate): self.fdm.run() output = Table() output.ReadCSV(self.output_file) # According to the settings, the output file must contain 2 lines in # addition to the headers : # 1. The initial conditions # 2. The output after 'rate' iterations self.assertEqual(output.get_column(0)[1], 0.0) self.assertEqual(output.get_column(0)[2], self.rate * self.dt) self.assertEqual(output.get_column(0)[2], self.fdm.get_property_value("simulation/sim-time-sec"))
def test_moments_update(self): script_path = self.sandbox.path_to_jsbsim_file('scripts', 'weather-balloon.xml') self.fdm = CreateFDM(self.sandbox) self.fdm.load_script(script_path) self.fdm.set_output_directive( self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) self.fdm.run_ic() self.CheckCGPosition() dt = self.fdm.get_property_value('simulation/dt') ExecuteUntil(self.fdm, 1.0 - 2.0 * dt) self.CheckCGPosition() # Moves the radio sonde to modify the CG location self.fdm.set_property_value('inertia/pointmass-location-X-inches', 5.0) # Check that the moment is immediately updated accordingly self.fdm.run() self.CheckCGPosition() Fbx = self.fdm.get_property_value('forces/fbx-buoyancy-lbs') Fbz = self.fdm.get_property_value('forces/fbz-buoyancy-lbs') CGx = self.fdm.get_property_value( 'inertia/cg-x-in') / 12.0 # Converts from in to ft CGz = self.fdm.get_property_value('inertia/cg-z-in') / 12.0 Mby = self.fdm.get_property_value('moments/m-buoyancy-lbsft') self.assertAlmostEqual( Fbx * CGz - Fbz * CGx, Mby, delta=1E-7, msg="Fbx*CGz-Fbz*CGx = %f and Mby = %f do not match" % (Fbx * CGz - Fbz * CGx, Mby)) # One further step to log the same results in the output file self.fdm.run() self.CheckCGPosition() csv = Table() csv.ReadCSV(self.sandbox('output.csv')) Mby = csv.get_column('M_{Buoyant} (ft-lbs)')[-1] Fbx = csv.get_column('F_{Buoyant x} (lbs)')[-1] Fbz = csv.get_column('F_{Buoyant z} (lbs)')[-1] self.assertAlmostEqual( Fbx * CGz - Fbz * CGx, Mby, delta=1E-7, msg="Fbx*CGz-Fbz*CGx = %f and Mby = %f do not match" % (Fbx * CGz - Fbz * CGx, Mby))
def testDisablingOutputInScript(self): property = et.SubElement(self.run_tag, 'property') property.text = 'simulation/output/enabled' property.attrib['value'] = "0.0" self.tree.write(self.sandbox('c1722_0.xml')) self.fdm.load_script('c1722_0.xml') # Check that the output is disabled self.assertEqual(self.fdm.get_property_value("simulation/output/enabled"), 0.0) self.fdm.run_ic() self.fdm.set_property_value("simulation/output/enabled", 1.0) for i in xrange(self.rate): self.fdm.run() output = Table() output.ReadCSV(self.output_file) # According to the settings, the output file must contain 1 line in # addition to the headers : # 1. The output after 'rate' iterations self.assertEqual(output.get_column(0)[1], self.fdm.get_property_value("simulation/sim-time-sec"))
def testTrimRestoresOutputSettings(self): self.fdm.load_script(self.script_path) # Disables the output during the initialization self.fdm.set_property_value("simulation/output/enabled", 0.0) self.fdm.run_ic() # Check that the output remains disabled even after the trim is # executed while self.fdm.get_property_value("simulation/sim-time-sec") < self.trim_date + 2.0*self.dt: self.fdm.run() self.assertEqual(self.fdm.get_property_value("simulation/output/enabled"), 0.0) # Re-enable the output and check that the output rate is unaffected by # the previous operations self.fdm.set_property_value("simulation/output/enabled", 1.0) frame = int(self.fdm.get_property_value("simulation/frame")) for i in xrange(self.rate): self.fdm.run() output = Table() output.ReadCSV(self.output_file) # The frame at which the data is logged must be the next multiple of # the output rate self.assertEqual(int(output.get_column(0)[1]/self.dt), (1 + frame/self.rate)*self.rate)
def testTrimRestoresOutputSettings(self): self.fdm.load_script(self.script_path) # Disables the output during the initialization self.fdm.set_property_value("simulation/output/enabled", 0.0) self.fdm.run_ic() # Check that the output remains disabled even after the trim is # executed while self.fdm.get_property_value("simulation/sim-time-sec") < self.trim_date + 2.0 * self.dt: self.fdm.run() self.assertEqual(self.fdm.get_property_value("simulation/output/enabled"), 0.0) # Re-enable the output and check that the output rate is unaffected by # the previous operations self.fdm.set_property_value("simulation/output/enabled", 1.0) frame = int(self.fdm.get_property_value("simulation/frame")) for i in xrange(self.rate): self.fdm.run() output = Table() output.ReadCSV(self.output_file) # The frame at which the data is logged must be the next multiple of # the output rate self.assertEqual(int(output.get_column(0)[1] / self.dt), (1 + frame / self.rate) * self.rate)
def test_moments_update(self): script_path = self.sandbox.path_to_jsbsim_file('scripts', 'weather-balloon.xml') self.fdm = CreateFDM(self.sandbox) self.fdm.load_script(script_path) self.fdm.set_output_directive(self.sandbox.path_to_jsbsim_file('tests', 'output.xml')) self.fdm.run_ic() self.CheckCGPosition() dt = self.fdm.get_property_value('simulation/dt') ExecuteUntil(self.fdm, 1.0-2.0*dt) self.CheckCGPosition() # Moves the radio sonde to modify the CG location self.fdm.set_property_value('inertia/pointmass-location-X-inches', 5.0) # Check that the moment is immediately updated accordingly self.fdm.run() self.CheckCGPosition() Fbx = self.fdm.get_property_value('forces/fbx-buoyancy-lbs') Fbz = self.fdm.get_property_value('forces/fbz-buoyancy-lbs') CGx = self.fdm.get_property_value('inertia/cg-x-in') / 12.0 # Converts from in to ft CGz = self.fdm.get_property_value('inertia/cg-z-in') / 12.0 Mby = self.fdm.get_property_value('moments/m-buoyancy-lbsft') self.assertAlmostEqual(Fbx * CGz - Fbz * CGx, Mby, delta=1E-7, msg="Fbx*CGz-Fbz*CGx = %f and Mby = %f do not match" % (Fbx*CGz-Fbz*CGx, Mby)) # One further step to log the same results in the output file self.fdm.run() self.CheckCGPosition() csv = Table() csv.ReadCSV(self.sandbox('output.csv')) Mby = csv.get_column('M_{Buoyant} (ft-lbs)')[-1] Fbx = csv.get_column('F_{Buoyant x} (lbs)')[-1] Fbz = csv.get_column('F_{Buoyant z} (lbs)')[-1] self.assertAlmostEqual(Fbx * CGz - Fbz * CGx, Mby, delta=1E-7, msg="Fbx*CGz-Fbz*CGx = %f and Mby = %f do not match" % (Fbx*CGz-Fbz*CGx, Mby))
def testDisablingOutput(self): self.fdm.load_script(self.script_path) # Disables the output during the initialization self.fdm.set_property_value("simulation/output/enabled", 0.0) self.fdm.run_ic() self.fdm.set_property_value("simulation/output/enabled", 1.0) for i in xrange(self.rate): self.fdm.run() output = Table() output.ReadCSV(self.output_file) # According to the settings, the output file must contain 1 line in # addition to the headers : # 1. The output after 'rate' iterations self.assertEqual(output.get_column(0)[1], self.fdm.get_property_value("simulation/sim-time-sec"))
def testDisablingOutputInScript(self): property = et.SubElement(self.run_tag, "property") property.text = "simulation/output/enabled" property.attrib["value"] = "0.0" self.tree.write(self.sandbox("c1722_0.xml")) self.fdm.load_script("c1722_0.xml") # Check that the output is disabled self.assertEqual(self.fdm.get_property_value("simulation/output/enabled"), 0.0) self.fdm.run_ic() self.fdm.set_property_value("simulation/output/enabled", 1.0) for i in xrange(self.rate): self.fdm.run() output = Table() output.ReadCSV(self.output_file) # According to the settings, the output file must contain 1 line in # addition to the headers : # 1. The output after 'rate' iterations self.assertEqual(output.get_column(0)[1], self.fdm.get_property_value("simulation/sim-time-sec"))
def test_IC_override(self): # Run the script c1724.xml script_path = self.sandbox.path_to_jsbsim_file('scripts', 'c1724.xml') fdm = CreateFDM(self.sandbox) fdm.load_script(script_path) vt0 = fdm.get_property_value('ic/vt-kts') fdm.run_ic() self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0) self.assertAlmostEqual(fdm.get_property_value('velocities/vt-fps'), vt0 / fpstokts, delta=1E-7) ExecuteUntil(fdm, 1.0) # Check that the total velocity exported in the output file matches the # IC defined in the initialization file ref = Table() ref.ReadCSV(self.sandbox('JSBout172B.csv')) self.assertEqual(ref.get_column('Time')[1], 0.0) self.assertAlmostEqual(ref.get_column('V_{Total} (ft/s)')[1], vt0 / fpstokts, delta=1E-7) # Now, we will re-run the same test but the IC will be overridden in the # script. The initial total velocity is increased by 1 ft/s vt0 += 1.0 # The script c1724.xml is loaded and the following line is added in it: # <property value="..."> ic/vt-kts </property> # The modified script is then saved with the named 'c1724_0.xml' tree = et.parse(self.sandbox.elude(script_path)) run_tag = tree.getroot().find("./run") property = et.SubElement(run_tag, 'property') property.text = 'ic/vt-kts' property.attrib['value'] = str(vt0) tree.write(self.sandbox('c1724_0.xml')) # Re-run the same check than above. This time we are making sure than # the total initial velocity is increased by 1 ft/s self.sandbox.delete_csv_files() # Because JSBSim internals use static pointers, we cannot rely on Python # garbage collector to decide when the FDM is destroyed otherwise we can # get dangling pointers. del fdm fdm = CreateFDM(self.sandbox) fdm.load_script('c1724_0.xml') self.assertAlmostEqual(fdm.get_property_value('ic/vt-kts'), vt0, delta=1E-6) fdm.run_ic() self.assertEqual(fdm.get_property_value('simulation/sim-time-sec'), 0.0) self.assertAlmostEqual(fdm.get_property_value('velocities/vt-fps'), vt0 / fpstokts, delta=1E-6) ExecuteUntil(fdm, 1.0) mod = Table() mod.ReadCSV(self.sandbox('JSBout172B.csv')) self.assertAlmostEqual(mod.get_column('V_{Total} (ft/s)')[1], vt0 / fpstokts, delta=1E-6)