def calculateBlackHoleLifetimeOperator( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_lifetime: invalid argument' ) mass = calculateBlackHoleMass( measurement ) lifetime = divide( getProduct( [ getPower( mass, 3 ), 5120, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ), getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 4 ) ] ) ) return lifetime.convert( 'seconds' )
def calculateBlackHoleTemperatureOperator( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_temperature: invalid argument' ) mass = calculateBlackHoleMass( measurement ) temperature = divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 3 ) ] ), getProduct( [ mass, 8, getConstant( 'boltzmann_constant' ), pi, getConstant( 'newton_constant' ) ] ) ) return temperature.convert( 'kelvin' )
def calculateOrbitalVelocityOperator( measurement1, measurement2 ): ''' To solve the velocity of a circular orbit, we need Newton's gravitational constant and two of the following three items: G = Newton's gravitational constant m = planetary mass (i.e., mass of the thing being orbited) r = orbit radius (the distance from the center of mass) T = orbital period ---- velocity in terms of mass and radius v = sqrt( G*m/r ) ---- velocity in terms of radius and period v = 2*pi*r/T ---- velocity in terms of mass and period v = ( 2*pi*cbrt( T^2*G*m/4*pi^2 ) ) / T ''' validUnitTypes = [ [ 'mass', 'time' ], [ 'length', 'time' ], [ 'mass', 'length' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'orbital_velocity\' requires specific measurement types (see help)' ) if 'mass' in arguments: mass = arguments[ 'mass' ] if 'length' in arguments: bRadius = True radius = arguments[ 'length' ] else: bRadius = False period = arguments[ 'time' ] else: # radius and period radius = arguments[ 'length' ] period = arguments[ 'time' ] velocity = divide( getProduct( [ 2, pi, radius ] ), period ) return velocity.convert( 'meter/second' ) if bRadius: # mass and radius velocity = getRoot( divide( multiply( getConstant( 'newton_constant' ), mass ), radius ), 2 ) else: # mass and period term = divide( getProduct( [ period, period, getConstant( 'newton_constant' ), mass ] ), getProduct( [ 4, pi, pi ] ) ) velocity = divide( getProduct( [ 2, pi, getRoot( term, 3 ) ] ), period ) return velocity.convert( 'meter/second' )
def calculateOrbitalVelocity( measurement1, measurement2 ): ''' To solve the velocity of a circular orbit, we need Newton's gravitational constant and two of the following three items: G = Newton's gravitational constant m = planetary mass (i.e., mass of the thing being orbited) r = orbit radius (the distance from the center of mass) T = orbital period ---- velocity in terms of mass and radius v = sqrt( G*m/r ) ---- velocity in terms of radius and period v = 2*pi*r/T ---- velocity in terms of mass and period v = ( 2*pi*cbrt( T^2*G*m/4*pi^2 ) ) / T ''' validUnitTypes = [ [ 'mass', 'time' ], [ 'length', 'time' ], [ 'mass', 'length' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'orbital_velocity\' requires specific measurement types (see help)' ) if 'mass' in arguments: mass = arguments[ 'mass' ] if 'length' in arguments: bRadius = True radius = arguments[ 'length' ] else: bRadius = False period = arguments[ 'time' ] else: # radius and period radius = arguments[ 'length' ] period = arguments[ 'time' ] velocity = divide( getProduct( [ 2, pi, radius ] ), period ) return velocity.convert( 'meter/second' ) if bRadius: # mass and radius velocity = getRoot( divide( multiply( getConstant( 'newton_constant' ), mass ), radius ), 2 ) else: # mass and period term = divide( getProduct( [ period, period, getConstant( 'newton_constant' ), mass ] ), getProduct( [ 4, pi, pi ] ) ) velocity = divide( getProduct( [ 2, pi, getRoot( term, 3 ) ] ), period ) return velocity.convert( 'meter/second' )
def calculateOrbitalPeriod( measurement1, measurement2 ): ''' To solve the period of a circular orbit, we need Newton's gravitational constant and two of the following three items: G = Newton's gravitational constant m = planetary mass (i.e., mass of the thing being orbited) r = orbit radius (the distance from the center of mass) v = orbital velocity ---- period in terms of radius and mass T = 2*pi*sqrt( r^3/G*m ) ---- period in terms of radius and velocity T = 2*pi*r/v ---- period in terms of mass and velocity T = 2*pi*G*m/v^3 ''' validUnitTypes = [ [ 'mass', 'length' ], [ 'velocity', 'length' ], [ 'mass', 'velocity' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'orbital_period\' requires specific measurement types (see help)' ) if 'mass' in arguments: mass = arguments[ 'mass' ] if 'length' in arguments: bRadius = True radius = arguments[ 'length' ] else: bRadius = False velocity = arguments[ 'velocity' ] else: # radius and velocity radius = arguments[ 'length' ] velocity = arguments[ 'velocity' ] period = divide( getProduct( [ 2, pi, radius ] ), velocity ) return period.convert( 'second' ) if bRadius: # radius and mass term = divide( getPower( radius, 3 ), multiply( getConstant( 'newton_constant' ), mass ) ) period = getProduct( [ 2, pi, getRoot( term, 2 ) ] ) else: # velocity and mass period = divide( getProduct( [ 2, pi, getConstant( 'newton_constant' ), mass ] ), getPower( velocity, 3 ) ) return period.convert( 'second' )
def calculateOrbitalPeriodOperator( measurement1, measurement2 ): ''' To solve the period of a circular orbit, we need Newton's gravitational constant and two of the following three items: G = Newton's gravitational constant m = planetary mass (i.e., mass of the thing being orbited) r = orbit radius (the distance from the center of mass) v = orbital velocity ---- period in terms of radius and mass T = 2*pi*sqrt( r^3/G*m ) ---- period in terms of radius and velocity T = 2*pi*r/v ---- period in terms of mass and velocity T = 2*pi*G*m/v^3 ''' validUnitTypes = [ [ 'mass', 'length' ], [ 'velocity', 'length' ], [ 'mass', 'velocity' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'orbital_period\' requires specific measurement types (see help)' ) if 'mass' in arguments: mass = arguments[ 'mass' ] if 'length' in arguments: bRadius = True radius = arguments[ 'length' ] else: bRadius = False velocity = arguments[ 'velocity' ] else: # radius and velocity radius = arguments[ 'length' ] velocity = arguments[ 'velocity' ] period = divide( getProduct( [ 2, pi, radius ] ), velocity ) return period.convert( 'second' ) if bRadius: # radius and mass term = divide( getPower( radius, 3 ), multiply( getConstant( 'newton_constant' ), mass ) ) period = getProduct( [ 2, pi, getRoot( term, 2 ) ] ) else: # velocity and mass period = divide( getProduct( [ 2, pi, getConstant( 'newton_constant' ), mass ] ), getPower( velocity, 3 ) ) return period.convert( 'second' )
def calculateOrbitalMassOperator( measurement1, measurement2 ): ''' To solve for the planetary mass for an object in a circular orbit, we need Newton's gravitational constant and two of the following three items: G = Newton's gravitational constant T = orbital period v = orbital velocity r = orbit radius (the distance from the center of mass) ---- mass in terms of period and velocity m = v^3*T/2*pi*G ---- mass in terms of period and radius m = 4*pi^2*r3/G*T^2 ---- mass in terms of velocity and radius m = v^2*r/G ''' validUnitTypes = [ [ 'time', 'length' ], [ 'velocity', 'length' ], [ 'time', 'velocity' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'orbital_mass\' requires specific measurement types (see help)' ) if 'time' in arguments: period = arguments[ 'time' ] if 'length' in arguments: bRadius = True radius = arguments[ 'length' ] else: bRadius = False velocity = arguments[ 'velocity' ] else: # velocity and radius radius = arguments[ 'length' ] velocity = arguments[ 'velocity' ] mass = divide( getProduct( [ velocity, velocity, radius ] ), getConstant( 'newton_constant' ) ) return mass.convert( 'kilogram' ) if bRadius: # radius and period mass = divide( getProduct( [ 4, pi, pi, radius, radius, radius ] ), getProduct( [ getConstant( 'newton_constant' ), period, period ] ) ) else: # velocity and period mass = divide( getProduct( [ velocity, velocity, velocity, period ] ), getProduct( [ 2, pi, getConstant( 'newton_constant' ) ] ) ) return mass.convert( 'kilogram' )
def calculateOrbitalRadius( measurement1, measurement2 ): ''' To solve the radius of a circular orbit, we need Newton's gravitational constant and two of the following three items: G = Newton's gravitational constant m = planetary mass (i.e., mass of the thing being orbited) T = orbital period v = orbital velocity ---- radius in terms of period and mass r = cbrt( T^2*G*m/4*pi^2 ) ---- radius in terms of velocity and mass r = G*m/v^2 ---- radius in terms of velocity and period r = v*T/2*pi ''' validUnitTypes = [ [ 'mass', 'time' ], [ 'velocity', 'time' ], [ 'mass', 'velocity' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'orbital_radius\' requires specific measurement types (see help)' ) if 'mass' in arguments: mass = arguments[ 'mass' ] if 'time' in arguments: bPeriod = True period = arguments[ 'time' ] else: bPeriod = False velocity = arguments[ 'velocity' ] else: # period and velocity period = arguments[ 'time' ] velocity = arguments[ 'velocity' ] radius = divide( multiply( velocity, period ), fmul( 2, pi ) ) return radius.convert( 'meter' ) if bPeriod: # period and mass term = divide( getProduct( [ getPower( period, 2 ), getConstant( 'newton_constant' ), mass ] ), fmul( 4, power( pi, 2 ) ) ) radius = getRoot( term, 3 ) else: # velocity and mass radius = divide( multiply( getConstant( 'newton_constant' ), mass ), getPower( velocity, 2 ) ) return radius.convert( 'meter' )
def calculateOrbitalMass( measurement1, measurement2 ): ''' To solve for the planetary mass for an object in a circular orbit, we need Newton's gravitational constant and two of the following three items: G = Newton's gravitational constant T = orbital period v = orbital velocity r = orbit radius (the distance from the center of mass) ---- mass in terms of period and velocity m = v^3*T/2*pi*G ---- mass in terms of period and radius m = 4*pi^2*r3/G*T^2 ---- mass in terms of velocity and radius m = v^2*r/G ''' validUnitTypes = [ [ 'time', 'length' ], [ 'velocity', 'length' ], [ 'time', 'velocity' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'orbital_mass\' requires specific measurement types (see help)' ) if 'time' in arguments: period = arguments[ 'time' ] if 'length' in arguments: bRadius = True radius = arguments[ 'length' ] else: bRadius = False velocity = arguments[ 'velocity' ] else: # velocity and radius radius = arguments[ 'length' ] velocity = arguments[ 'velocity' ] mass = divide( getProduct( [ velocity, velocity, radius ] ), getConstant( 'newton_constant' ) ) return mass.convert( 'kilogram' ) if bRadius: # radius and period mass = divide( getProduct( [ 4, pi, pi, radius, radius, radius ] ), getProduct( [ getConstant( 'newton_constant' ), period, period ] ) ) else: # velocity and period mass = divide( getProduct( [ velocity, velocity, velocity, period ] ), getProduct( [ 2, pi, getConstant( 'newton_constant' ) ] ) ) return mass.convert( 'kilogram' )
def calculateOrbitalRadiusOperator( measurement1, measurement2 ): ''' To solve the radius of a circular orbit, we need Newton's gravitational constant and two of the following three items: G = Newton's gravitational constant m = planetary mass (i.e., mass of the thing being orbited) T = orbital period v = orbital velocity ---- radius in terms of period and mass r = cbrt( T^2*G*m/4*pi^2 ) ---- radius in terms of velocity and mass r = G*m/v^2 ---- radius in terms of velocity and period r = v*T/2*pi ''' validUnitTypes = [ [ 'mass', 'time' ], [ 'velocity', 'time' ], [ 'mass', 'velocity' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'orbital_radius\' requires specific measurement types (see help)' ) if 'mass' in arguments: mass = arguments[ 'mass' ] if 'time' in arguments: bPeriod = True period = arguments[ 'time' ] else: bPeriod = False velocity = arguments[ 'velocity' ] else: # period and velocity period = arguments[ 'time' ] velocity = arguments[ 'velocity' ] radius = divide( multiply( velocity, period ), fmul( 2, pi ) ) return radius.convert( 'meter' ) if bPeriod: # period and mass term = divide( getProduct( [ getPower( period, 2 ), getConstant( 'newton_constant' ), mass ] ), fmul( 4, power( pi, 2 ) ) ) radius = getRoot( term, 3 ) else: # velocity and mass radius = divide( multiply( getConstant( 'newton_constant' ), mass ), getPower( velocity, 2 ) ) return radius.convert( 'meter' )
def calculateTidalForce( mass, distance, delta ): mass.validateUnits( 'mass' ) distance.validateUnits( 'length' ) delta.validateUnits( 'length' ) tidal_force = divide( getProduct( [ 2, getConstant( 'newton_constant' ), mass, delta ] ), getPower( distance, 3 ) ) return tidal_force.convert( 'meter/second^2' )
def calculateTimeDilationOperator( velocity ): velocity.validateUnits( 'velocity' ) ratio = divide( velocity, getConstant( 'speed_of_light' ) ) if ratio == 1: return inf return fdiv( 1, sqrt( fsub( 1, power( ratio, 2 ) ) ) )
def calculateTidalForceOperator( mass, distance, delta ): mass.validateUnits( 'mass' ) distance.validateUnits( 'length' ) delta.validateUnits( 'length' ) tidalForce = divide( getProduct( [ 2, getConstant( 'newton_constant' ), mass, delta ] ), getPower( distance, 3 ) ) return tidalForce.convert( 'meter/second^2' )
def calculateTimeDilation( velocity ): velocity.validateUnits( 'velocity' ) c_ratio = divide( velocity, getConstant( 'speed_of_light' ) ).value if c_ratio == 1: return inf return fdiv( 1, sqrt( fsub( 1, power( c_ratio, 2 ) ) ) )
def calculateBlackHoleRadiusOperator( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_radius: invalid argument' ) mass = calculateBlackHoleMass( measurement ) radius = getProduct( [ 2, getConstant( 'newton_constant' ), mass ] ). \ divide( getPower( getConstant( 'speed_of_light' ), 2 ) ) return radius.convert( 'meter' )
def calculateBlackHoleSurfaceArea( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_surface_area: invalid argument' ) mass = calculateBlackHoleMass( measurement ) area = divide( getProduct( [ 16, pi, getPower( getConstant( 'newton_constant' ), 2 ), getPower( mass, 2 ) ] ), getPower( getConstant( 'speed_of_light' ), 4 ) ) return area.convert( 'meter^2' )
def calculateBlackHoleSurfaceGravityOperator( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_surface_gravity: invalid argument' ) mass = calculateBlackHoleMass( measurement ) gravity = divide( getPower( getConstant( 'speed_of_light' ), 4 ), getProduct( [ mass, 4, getConstant( 'newton_constant' ) ] ) ) return gravity.convert( 'meter/second^2' )
def calculateBlackHoleLifetime( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_lifetime: invalid argument' ) mass = calculateBlackHoleMass( measurement ) lifetime = divide( getProduct( [ getPower( mass, 3 ), 5120, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ), getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 4 ) ] ) ) return lifetime.convert( 'seconds' )
def calculateBlackHoleTemperature( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_temperature: invalid argument' ) mass = calculateBlackHoleMass( measurement ) temperature = divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 3 ) ] ), getProduct( [ mass, 8, getConstant( 'boltzmann_constant' ), pi, getConstant( 'newton_constant' ) ] ) ) return temperature.convert( 'kelvin' )
def calculateBlackHoleEntropy( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_entropy: invalid argument' ) mass = calculateBlackHoleMass( measurement ) entropy = divide( getProduct( [ getPower( mass, 2 ), 4, pi, getConstant( 'newton_constant' ) ] ), getProduct( [ getConstant( 'reduced_planck_constant' ), getConstant( 'speed_of_light' ), getLog( 10.0 ) ] ) ) return getConstant( 'boltzmann_constant' ).multiply( entropy ).convert( 'bit' )
def calculateBlackHoleEntropyOperator( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_entropy: invalid argument' ) mass = calculateBlackHoleMass( measurement ) entropy = divide( getProduct( [ getPower( mass, 2 ), 4, pi, getConstant( 'newton_constant' ) ] ), getProduct( [ getConstant( 'reduced_planck_constant' ), getConstant( 'speed_of_light' ), ln( 10.0 ) ] ) ) return getConstant( 'boltzmann_constant' ).multiply( entropy ).convert( 'bit' )
def calculateBlackHoleSurfaceGravity( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_surface_gravity: invalid argument' ) mass = calculateBlackHoleMass( measurement ) gravity = divide( getPower( getConstant( 'speed_of_light' ), 4 ), getProduct( [ mass, 4, getConstant( 'newton_constant' ) ] ) ) return gravity.convert( 'meter/second^2' )
def calculateBlackHoleRadius( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_radius: invalid argument' ) mass = calculateBlackHoleMass( measurement ) radius = getProduct( [ 2, getConstant( 'newton_constant' ), mass ] ).divide( getPower( getConstant( 'speed_of_light' ), 2 ) ) return radius.convert( 'meter' )
def calculateSurfaceGravity( measurement1, measurement2 ): validUnitTypes = [ [ 'mass', 'density' ], [ 'mass', 'length' ], [ 'mass', 'volume' ], [ 'density', 'length' ], [ 'density', 'volume' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'surface_gravity\' requires length and mass measurements' ) if 'mass' in arguments: mass = arguments[ 'mass' ] if 'length' in arguments: length = arguments[ 'length' ] elif 'density' in arguments: volume = divide( mass, arguments[ 'density' ] ) length = getKSphereRadius( volume, 3 ) else: length = getKSphereRadius( arguments[ 'volume' ], 3 ) elif 'volume' in arguments: # density, volume volume = arguments[ 'volume' ] mass = multiply( arguments[ 'density' ], volume ) length = getKSphereRadius( volume, 3 ) else: # density, length length = arguments[ 'length' ] volume = getPower( length, 3 ) mass = multiply( arguments[ 'density' ], volume ) gravity = multiply( divide( mass, getPower( length, 2 ) ), getConstant( 'newton_constant' ) ) return gravity.convert( 'meters/seconds^2' )
def calculateSurfaceGravityOperator( measurement1, measurement2 ): validUnitTypes = [ [ 'mass', 'density' ], [ 'mass', 'length' ], [ 'mass', 'volume' ], [ 'density', 'length' ], [ 'density', 'volume' ], ] arguments = matchUnitTypes( [ measurement1, measurement2 ], validUnitTypes ) if not arguments: raise ValueError( '\'surface_gravity\' requires length and mass measurements' ) if 'mass' in arguments: mass = arguments[ 'mass' ] if 'length' in arguments: length = arguments[ 'length' ] elif 'density' in arguments: volume = divide( mass, arguments[ 'density' ] ) length = getKSphereRadius( volume, 3 ) else: length = getKSphereRadius( arguments[ 'volume' ], 3 ) elif 'volume' in arguments: # density, volume volume = arguments[ 'volume' ] mass = multiply( arguments[ 'density' ], volume ) length = getKSphereRadius( volume, 3 ) else: # density, length length = arguments[ 'length' ] volume = getPower( length, 3 ) mass = multiply( arguments[ 'density' ], volume ) gravity = multiply( divide( mass, getPower( length, 2 ) ), getConstant( 'newton_constant' ) ) return gravity.convert( 'meters/seconds^2' )
def calculateMassEquivalence( energy ): energy.validateUnits( 'energy' ) mass = divide( energy, multiply( getConstant( 'speed_of_light' ), getConstant( 'speed_of_light' ) ) ) return mass.convert( 'kilogram' )
def calculateEnergyEquivalence( mass ): mass.validateUnits( 'mass' ) energy = getProduct( [ mass, getConstant( 'speed_of_light' ), getConstant( 'speed_of_light' ) ] ) return energy.convert( 'joule' )
def calculateBlackHoleMass( measurement ): # pylint: disable=line-too-long validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_mass: invalid argument' ) if 'mass' in arguments: return arguments[ 'mass' ].convert( 'kilogram' ) if 'length' in arguments: radius = arguments[ 'length' ] return divide( getProduct( [ getPower( getConstant( 'speed_of_light' ), 2 ), radius ] ), getProduct( [ 2, getConstant( 'newton_constant' ) ] ) ).convert( 'kilogram' ) if 'acceleration' in arguments: gravity = arguments[ 'acceleration' ] return divide( getPower( getConstant( 'speed_of_light' ), 4 ), getProduct( [ 4, getConstant( 'newton_constant' ), gravity ] ) ).convert( 'kilogram' ) if 'area' in arguments: area = arguments[ 'area' ].convert( 'meters^2' ) return getRoot( divide( getProduct( [ getPower( getConstant( 'speed_of_light' ), 4 ), area ] ), getProduct( [ 16, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2 ).convert( 'kilogram' ) if 'temperature' in arguments: temperature = arguments[ 'temperature' ] return divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 3 ) ] ), getProduct( [ temperature, 8, getConstant( 'boltzmann_constant' ), pi, getConstant( 'newton_constant' ) ] ) ).convert( 'kilogram' ) if 'power' in arguments: luminosity = arguments[ 'power' ] return getRoot( divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 6 ) ] ), getProduct( [ luminosity.convert( 'kilogram*meter^2/second^3' ), 15360, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2 ).convert( 'kilogram' ) if 'tidal_force' in arguments: tidalForce = arguments[ 'tidal_force' ] return getRoot( divide( getPower( getConstant( 'speed_of_light' ), 6 ), getProduct( [ 4, tidalForce, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2 ).convert( 'kilogram' ) if 'time' in arguments: lifetime = arguments[ 'time' ] return getRoot( divide( getProduct( [ lifetime, getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 4 ) ] ), getProduct( [ 5120, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 3 ).convert( 'kilogram' ) raise ValueError( 'invalid arguments to black hole operator' )
def calculateEscapeVelocityOperator( mass, radius ): mass.validateUnits( 'mass' ) radius.validateUnits( 'length' ) velocity = getRoot( getProduct( [ 2, getConstant( 'newton_constant' ), mass ] ).divide( radius ), 2 ) return velocity.convert( 'meter/second' )
def calculateEnergyEquivalenceOperator( mass ): mass.validateUnits( 'mass' ) energy = getProduct( [ mass, getConstant( 'speed_of_light' ), getConstant( 'speed_of_light' ) ] ) return energy.convert( 'joule' )
def calculateMassEquivalenceOperator( energy ): energy.validateUnits( 'energy' ) mass = divide( energy, multiply( getConstant( 'speed_of_light' ), getConstant( 'speed_of_light' ) ) ) return mass.convert( 'kilogram' )
def calculateEscapeVelocity( mass, radius ): mass.validateUnits( 'mass' ) radius.validateUnits( 'length' ) velocity = getRoot( getProduct( [ 2, getConstant( 'newton_constant' ), mass ] ).divide( radius ), 2 ) return velocity.convert( 'meter/second' )
def calculateBlackHoleMass( measurement ): validUnitTypes = [ [ 'mass' ], [ 'length' ], [ 'acceleration' ], [ 'area' ], [ 'temperature' ], [ 'power' ], [ 'tidal_force' ], [ 'time' ], ] arguments = matchUnitTypes( [ measurement ], validUnitTypes ) if not arguments: raise ValueError( 'black_hole_mass: invalid argument' ) if 'mass' in arguments: return arguments[ 'mass' ].convert( 'kilogram' ) elif 'length' in arguments: radius = arguments[ 'length' ] return divide( getProduct( [ getPower( getConstant( 'speed_of_light' ), 2 ), radius ] ), getProduct( [ 2, getConstant( 'newton_constant' ) ] ) ).convert( 'kilogram' ) elif 'acceleration' in arguments: gravity = arguments[ 'acceleration' ] return divide( getPower( getConstant( 'speed_of_light' ), 4 ), getProduct( [ 4, getConstant( 'newton_constant' ), gravity ] ) ).convert( 'kilogram' ) elif 'area' in arguments: area = arguments[ 'area' ].convert( 'meters^2' ) return getRoot( divide( getProduct( [ getPower( getConstant( 'speed_of_light' ), 4 ), area ] ), getProduct( [ 16, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2 ).convert( 'kilogram' ) elif 'temperature' in arguments: temperature = arguments[ 'temperature' ] return divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 3 ) ] ), getProduct( [ temperature, 8, getConstant( 'boltzmann_constant' ), pi, getConstant( 'newton_constant' ) ] ) ).convert( 'kilogram' ) elif 'power' in arguments: luminosity = arguments[ 'power' ] return getRoot( divide( getProduct( [ getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 6 ) ] ), getProduct( [ luminosity.convert( 'kilogram*meter^2/second^3' ), 15360, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2 ).convert( 'kilogram' ) elif 'tidal_force' in arguments: tidal_force = arguments[ 'tidal_force' ] return getRoot( divide( getPower( getConstant( 'speed_of_light' ), 6 ), getProduct( [ 4, tidal_force, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 2 ).convert( 'kilogram' ) elif 'time' in arguments: lifetime = arguments[ 'time' ] return getRoot( divide( getProduct( [ lifetime, getConstant( 'reduced_planck_constant' ), getPower( getConstant( 'speed_of_light' ), 4 ) ] ), getProduct( [ 5120, pi, getPower( getConstant( 'newton_constant' ), 2 ) ] ) ), 3 ).convert( 'kilogram' ) raise ValueError( 'invalid arguments to black hole operator' )