def test_density(self): """tests density at various altitudes""" self.assertEqual(atm_density(299., alt_units='ft'), 0.0023600367621627013) self.assertEqual(atm_density(299. / 1000., alt_units='kft'), 0.0023600367621627013) rho2 = atm_density(0., alt_units='m', density_units='kg/m^3') assert np.allclose(rho2, 1.22699081123), rho2 rho1 = atm_density(0.) assert np.allclose(rho1, 0.00238075522), rho1 rho2 = atm_density(0., alt_units='ft', density_units='slinch/in^3') assert np.allclose(rho2, 0.00238075522 / 12.**4), rho2
def test_density(self): """tests density at various altitudes""" self.assertEqual(atm_density(299.), 0.0023600367621627013) self.assertEqual(atm_density2(299., alt_units='ft'), 0.0023600367621627013) self.assertEqual(atm_density2(299. / 1000., alt_units='kft'), 0.0023600367621627013)
def make_flfacts_alt_sweep(self, model: BDF, mach, alts, eas_limit: float = 1000., alt_units: str = 'm', velocity_units: str = 'm/s', density_units: str = 'kg/m^3', eas_units: str = 'm/s') -> Tuple[Any, Any, Any]: """makes an altitude sweep""" alts.sort() alts = alts[::-1] rho, mach, velocity = make_flfacts_alt_sweep( mach, alts, eas_limit=eas_limit, alt_units=alt_units, velocity_units=velocity_units, density_units=density_units, eas_units=eas_units) flfact_rho = self.sid + 1 flfact_mach = self.sid + 2 flfact_velocity = self.sid + 3 flfact_eas = self.sid + 4 flfact_alt = self.sid + 5 alts2 = alts[:len(rho)] assert len(rho) == len(alts2) comment = ' density: min=%.3e max=%.3e %s; alt min=%.0f max=%.0f %s' % ( rho.min(), rho.max(), density_units, alts2.min(), alts2.max(), alt_units, ) model.add_flfact(flfact_rho, rho, comment=comment) model.add_flfact(flfact_mach, mach, comment=' Mach: %s' % mach.min()) comment = ' velocity: min=%.3f max=%.3f %s' % ( velocity.min(), velocity.max(), velocity_units) model.add_flfact(flfact_velocity, velocity, comment=comment) # eas in velocity units rho0 = atm_density(0., alt_units=alt_units, density_units=density_units) eas = velocity * np.sqrt(rho / rho0) kvel = _velocity_factor(velocity_units, eas_units) eas_in_eas_units = eas * kvel comment = ' EAS: min=%.3f max=%.3f %s' % ( eas_in_eas_units.min(), eas_in_eas_units.max(), eas_units) model.add_flfact(flfact_eas, eas_in_eas_units, comment=comment) comment = ' Alt: min=%.3f max=%.3f %s' % (alts2.min(), alts2.max(), alt_units) model.add_flfact(flfact_alt, alts2, comment=comment)
def set_pknl_results(self, results): density_units_in = self.f06_units['density'] # in/s vel = results[:, :, self.ivelocity] #.ravel() # slinch/in^3 - in_units rho = results[:, :, self.idensity] #.ravel() # good rho_ref = atm_density(0., R=1716., alt_units='ft', density_units=density_units_in) q = 0.5 * rho * vel**2 #eas = (2 * q / rho_ref)**0.5 # eas = V * sqrt(rho / rhoSL) keas = self._get_unit_factor('eas')[0] eas = vel * np.sqrt(rho / rho_ref) * keas #density_units2 = self.out_units['density'] altitude_units = self.out_units['altitude'] #print('density_units_in=%r density_units2=%r' % (density_units_in, density_units2)) kdensityi = convert_density(1., density_units_in, 'slug/ft^3') kvel = self._get_unit_factor('velocity')[0] kdensity = self._get_unit_factor('density')[0] kpressure = kdensityi * kvel**2 vel *= kvel if self.make_alt: rho_in_slug_ft3 = rho * kdensityi alt_ft = [ get_alt_for_density(densityi, density_units='slug/ft^3', alt_units='ft', nmax=20) for densityi in rho_in_slug_ft3.ravel() ] ft_to_alt_unit = convert_altitude(1., 'ft', altitude_units) alt = np.array(alt_ft, dtype='float64').reshape( vel.shape) * ft_to_alt_unit rho *= kdensity results2 = np.dstack([results, eas, q * kpressure, alt]) else: #kpressure = 1. rho *= kdensity results2 = np.dstack([results, eas, q * kpressure]) results2[:, :, self.idensity] = rho results2[:, :, self.ivelocity] = vel self.results = results2
def make_flfacts_mach_sweep(self, model, alt, machs, eas_limit=1000., alt_units='m', velocity_units='m/s', density_units='kg/m^3', eas_units='m/s'): """makes a mach sweep""" machs.sort() machs = machs[::-1] rho, mach, velocity = make_flfacts_mach_sweep( alt, machs, eas_limit=eas_limit, alt_units=alt_units, velocity_units=velocity_units, density_units=density_units, eas_units=eas_units) machs2 = machs[:len(rho)] assert len(rho) == len(machs2) flfact_rho = self.sid + 1 flfact_mach = self.sid + 2 flfact_velocity = self.sid + 3 flfact_eas = self.sid + 4 comment = ' density: min=%.3e max=%.3e %s; alt %.0f %s' % ( rho.min(), rho.max(), density_units, alt, alt_units, ) model.add_flfact(flfact_rho, rho, comment=comment) comment = ' Mach: min=%s max=%s' % (mach.min(), mach.max()) model.add_flfact(flfact_mach, mach, comment=comment) comment = ' velocity: min=%.3f max=%.3f %s' % ( velocity.min(), velocity.max(), velocity_units) model.add_flfact(flfact_velocity, velocity, comment=comment) # eas in velocity units rho0 = atm_density(0., alt_units=alt_units, density_units=density_units) eas = velocity * np.sqrt(rho / rho0) kvel = _velocity_factor(velocity_units, eas_units) eas_in_eas_units = eas * kvel comment = ' EAS: min=%.3f max=%.3f %s' % ( eas_in_eas_units.min(), eas_in_eas_units.max(), eas_units) model.add_flfact(flfact_eas, eas_in_eas_units, comment=comment)
def test_get_alt_for_density(self): """tests ``get_alt_for_density``""" alt_targets = [0., 10., 20., 30., 40., 50.] for alt_target in alt_targets: rho1 = atm_density(alt_target * 1000.) alt1 = get_alt_for_density(rho1) #self.assertAlmostEqual(alt, alt_target) assert np.allclose( alt1, alt_target * 1000, atol=1.), 'alt1=%s alt_target=%s' % (alt1, alt_target * 1000) rho2 = atm_density(alt_target, alt_units='kft', density_units='kg/m^3') tol = 0.005 # 5 feet alt2 = get_alt_for_density(rho2, density_units='kg/m^3', alt_units='kft', tol=tol) #self.assertAlmostEqual(alt, alt_target) assert np.allclose( alt2, alt_target, atol=1e-3), 'alt2=%s alt_target=%s' % (alt2, alt_target)
def test_density(self): self.assertEqual(atm_density(299.), 0.0023600367621627013) self.assertEqual(atm_density2(299., alt_units='ft'), 0.0023600367621627013) self.assertEqual(atm_density2(299./1000., alt_units='kft'), 0.0023600367621627013)
def test_density(self): self.assertEqual(atm_density(299.), 0.0023600367621627013) self.assertEqual(atm_density2(299., alt_units='ft'), 0.0023600367621627013) self.assertEqual(atm_density2(299. / 1000., alt_units='kft'), 0.0023600367621627013)