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 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 __init__( self, subcase, configuration, xysym, xzsym, mach, density_ratio, method, modes, results, f06_units=None, out_units=None, ): """ Parameters ---------- subcase : int the subcase id method : str PK, PKNL, ??? modes : List[int]; (default=None -> all) the modes; typically 1 to N results : varies method = PK List[List[float] * 7] * nmodes kfreq, 1/kfreq, velocity, damping, freq, eigr, eigi method = PKNL List[List[float] * 9] * nmodes kfreq, 1/kfreq, density, mach, velocity, damping, freq, eigr, eigi Units ----- Units are only applicable for quantities that have units (e.g. units on Mach don't do anything). All allowable fields are shown below. f06_units : dict[str] = str (default=None -> no units conversion) The units to to read from the F06. PK method: f06_units = {'velocity' : 'in/s'} The velocity units are the units for the FLFACT card in the BDF PKNL method: f06_units = {'velocity' : 'in/s', 'density' : 'slug/in^3'} The velocity/density units are the units for the FLFACT card in the BDF out_units dict[str] = str (default=None -> no units conversion) The units to store results in. PK method: out_units = {'velocity' : 'ft/s'} PKNL method: out_units = { 'velocity' : 'ft/s', 'eas' : 'knots', 'density' : 'slinch/in^3', 'altitude' : 'ft' } Unused Parameters ----------------- configuration : str AEROSG2D...what is this??? XY-SYMMETRY : str ASYMMETRIC, SYMMETRIC unused XZ-SYMMETRY : str ASYMMETRIC, SYMMETRIC unused """ self.f06_units = f06_units self.out_units = out_units self.subcase = subcase self.configuration = configuration if method == 'PK': self.mach = mach self.xysym = xysym self.xzsym = xzsym self.density_ratio = density_ratio #print('mach=%s' % mach) self.method = method self.modes = np.asarray(modes, dtype='int32') rho_ref = 1. self.ikfreq = 0 self.ikfreq_inv = 1 results = np.asarray(results, dtype='float64') if self.method == 'PK': self.ivelocity = 2 self.idamping = 3 self.ifreq = 4 self.ieigr = 5 self.ieigi = 6 self.results = results kvel = self._get_unit_factor('velocity')[0] results[:, :, self.ivelocity] *= kvel # velocity is the target self.names = [ 'kfreq', '1/kfreq', 'velocity', 'damping', 'freq', 'eigr', 'eigi' ] elif self.method == 'PKNL': # velocity is the target self.names = [ 'kfreq', '1/kfreq', 'density', 'velocity', 'damping', 'freq', 'eigr', 'eigi', 'eas', 'q', 'alt' ] self.idensity = 2 self.imach = 3 self.ivelocity = 4 self.idamping = 5 self.ifreq = 6 self.ieigr = 7 self.ieigi = 8 self.ieas = 9 self.iq = 10 self.ialt = 11 # eas = V * sqrt(rho / rhoSL) vel = results[:, :, self.ivelocity] #.ravel() rho = results[:, :, self.idensity] #.ravel() q = 0.5 * rho * vel**2 #eas = (2 * q / rho_ref)**0.5 eas = vel * np.sqrt(rho / rho_ref) density_units1 = self.f06_units['density'] altitude_units = self.out_units['altitude'] #density_units1 = self.out_units['density'] kdensity = self._get_density_unit_factor(density_units1, 'slug/ft^3') #kdensity = self._get_altitude_unit_factor(density_units2, 'slug/ft^3') kalt = self._get_altitude_unit_factor('ft', altitude_units) kvel = self._get_unit_factor('velocity')[0] #kpressure = self._get_unit_factor('dynamic_pressure')[0] kpressure = kdensity * kvel**2 make_alt = False if make_alt: alt = np.array([ get_alt_for_density(densityi, nmax=20) * kalt for densityi in rho.ravel() * kdensity ], dtype='float64').reshape(vel.shape) self.results = np.dstack([results, eas, q * kpressure, alt]) else: self.results = np.dstack([results, eas, q * kpressure]) else: raise NotImplementedError(method) #print(self.results.shape) # c - cyan # b - black # r - red # g - green # m - magenta # y - yellow #colors = ['b', 'c', 'g', 'k', 'm', 'r'] #, 'y'] # D - wide diamond # h - hexagon # * - star # + - plus # 3 - 3 pointed star # o - circle # d - thin diamond # 1 - Y shape # s - square #shapes = ['D', 'h', '*', 's', 'd', '3', 'o', '1', '2', '4', 'x', '^', '<', '>'] # '+', #symbol_list = [] #for shape in shapes: #for color in colors: #symbol_list.append('%s-%s' % (shape, color)) self.noline = False self._symbols = [] self.generate_symbols()
def __init__(self, subcase, configuration, xysym, xzsym, mach, density_ratio, method, modes, results, f06_units=None, out_units=None, ): """ Parameters ---------- subcase : int the subcase id method : str PK, PKNL, ??? modes : List[int]; (default=None -> all) the modes; typically 1 to N results : varies method = PK List[List[float] * 7] * nmodes kfreq, 1/kfreq, velocity, damping, freq, eigr, eigi method = PKNL List[List[float] * 9] * nmodes kfreq, 1/kfreq, density, mach, velocity, damping, freq, eigr, eigi Units ----- Units are only applicable for quantities that have units (e.g. units on Mach don't do anything). All allowable fields are shown below. f06_units : dict[str] = str (default=None -> no units conversion) The units to to read from the F06. PK method: f06_units = {'velocity' : 'in/s'} The velocity units are the units for the FLFACT card in the BDF PKNL method: f06_units = {'velocity' : 'in/s', 'density' : 'slug/in^3'} The velocity/density units are the units for the FLFACT card in the BDF out_units dict[str] = str (default=None -> no units conversion) The units to store results in. PK method: out_units = {'velocity' : 'ft/s'} PKNL method: out_units = { 'velocity' : 'ft/s', 'eas' : 'knots', 'density' : 'slinch/in^3', 'altitude' : 'ft' } Unused Parameters ----------------- configuration : str AEROSG2D...what is this??? XY-SYMMETRY : str ASYMMETRIC, SYMMETRIC unused XZ-SYMMETRY : str ASYMMETRIC, SYMMETRIC unused """ self.f06_units = f06_units self.out_units = out_units self.subcase = subcase self.configuration = configuration if method == 'PK': self.mach = mach self.xysym = xysym self.xzsym = xzsym self.density_ratio = density_ratio #print('mach=%s' % mach) self.method = method self.modes = np.asarray(modes, dtype='int32') rho_ref = 1. self.ikfreq = 0 self.ikfreq_inv = 1 #print(results) results = np.asarray(results, dtype='float64') if self.method == 'PK': self.ivelocity = 2 self.idamping = 3 self.ifreq = 4 self.ieigr = 5 self.ieigi = 6 self.results = results kvel = self._get_unit_factor('velocity')[0] results[:, :, self.ivelocity] *= kvel # velocity is the target self.names = ['kfreq', '1/kfreq', 'velocity', 'damping', 'freq', 'eigr', 'eigi'] elif self.method == 'PKNL': # velocity is the target self.names = ['kfreq', '1/kfreq', 'density', 'velocity', 'damping', 'freq', 'eigr', 'eigi', 'eas', 'q', 'alt'] self.idensity = 2 self.imach = 3 self.ivelocity = 4 self.idamping = 5 self.ifreq = 6 self.ieigr = 7 self.ieigi = 8 self.ieas = 9 self.iq = 10 self.ialt = 11 # eas = V * sqrt(rho / rhoSL) vel = results[:, :, self.ivelocity]#.ravel() rho = results[:, :, self.idensity]#.ravel() q = 0.5 * rho * vel**2 #eas = (2 * q / rho_ref)**0.5 eas = vel * np.sqrt(rho / rho_ref) density_units1 = self.f06_units['density'] altitude_units = self.out_units['altitude'] #density_units1 = self.out_units['density'] kdensity = self._get_density_unit_factor(density_units1, 'slug/ft^3') #kdensity = self._get_altitude_unit_factor(density_units2, 'slug/ft^3') kalt = self._get_altitude_unit_factor('ft', altitude_units) kvel = self._get_unit_factor('velocity')[0] #kpressure = self._get_unit_factor('dynamic_pressure')[0] kpressure = kdensity * kvel ** 2 make_alt = False if make_alt: alt = np.array( [get_alt_for_density(densityi, nmax=20) * kalt for densityi in rho.ravel() * kdensity], dtype='float64').reshape(vel.shape) self.results = np.dstack([results, eas, q * kpressure, alt]) else: self.results = np.dstack([results, eas, q * kpressure]) else: raise NotImplementedError(method) #print(self.results.shape) # c - cyan # b - black # r - red # g - green # m - magenta # y - yellow #colors = ['b', 'c', 'g', 'k', 'm', 'r'] #, 'y'] # D - wide diamond # h - hexagon # * - star # + - plus # 3 - 3 pointed star # o - circle # d - thin diamond # 1 - Y shape # s - square #shapes = ['D', 'h', '*', 's', 'd', '3', 'o', '1', '2', '4', 'x', '^', '<', '>'] # '+', #symbol_list = [] #for shape in shapes: #for color in colors: #symbol_list.append('%s-%s' % (shape, color)) self.noline = False self._symbols = [] self.generate_symbols()