def terminal_velocity(values, radius, k1, k2, k3, r1, r2): k1 = trtc.DVDouble(k1) k2 = trtc.DVDouble(k2) k3 = trtc.DVDouble(k3) r1 = trtc.DVDouble(r1) r2 = trtc.DVDouble(r2) PhysicsMethods.__terminal_velocity_body.launch_n(values.size(), [values, radius, k1, k2, k3, r1, r2])
def sort_pair(data_out, data_in, is_first_in_pair, idx, length): # note: silently assumes that data_out is not permuted (i.e. not part of state) perm_in = trtc.DVPermutation(data_in, idx) trtc.Fill(data_out, trtc.DVDouble(0)) if length > 1: AlgorithmicStepMethods.__sort_pair_body.launch_n( length - 1, [data_out, perm_in, is_first_in_pair])
def normalize(prob, cell_id, cell_start, norm_factor, dt_div_dv): n_cell = cell_start.shape[0] - 1 device_dt_div_dv = trtc.DVDouble(dt_div_dv) AlgorithmicMethods.__normalize_body_0.launch_n( n_cell, [cell_start, norm_factor, device_dt_div_dv]) AlgorithmicMethods.__normalize_body_1.launch_n( prob.shape[0], [prob, cell_id, norm_factor])
def multiply(data, multiplier): if isinstance(multiplier, ThrustRTC.storage): loop = trtc.For(['arr', 'mult'], "i", "arr[i] *= mult[i];") mult = multiplier elif isinstance(multiplier, float): loop = trtc.For(['arr', 'mult'], "i", "arr[i] *= mult;") mult = trtc.DVDouble(multiplier) else: raise NotImplementedError() loop.launch_n(data.size(), [data, mult])
def multiply_out_of_place(output, multiplicand, multiplier): if isinstance(multiplier, StorageMethods.storage): loop = MathsMethods.__multiply_out_of_place_elementwise_body device_multiplier = multiplier elif isinstance(multiplier, float): loop = MathsMethods.__multiply_out_of_place_body device_multiplier = trtc.DVDouble(multiplier) else: raise NotImplementedError() loop.launch_n(output.size(), [output, multiplicand, device_multiplier])
def thrust(obj): if isinstance(obj, list): result = [thrust(o) for o in obj] elif hasattr(obj, 'data'): result = obj.data elif isinstance(obj, float): result = trtc.DVDouble(obj) elif isinstance(obj, int): result = trtc.DVInt64(obj) else: raise ValueError(f"Cannot upload {obj} to device.") return result
def __setitem__(self, key, value): if hasattr(value, 'data'): trtc.Copy(value.data, self.data) else: if isinstance(value, int): dvalue = trtc.DVInt64(value) elif isinstance(value, float): dvalue = trtc.DVDouble(value) else: raise TypeError("Only Storage, int and float are supported.") trtc.Fill(self.data, dvalue) return self
def linear_collection_efficiency(params, output, radii, is_first_in_pair, unit): A, B, D1, D2, E1, E2, F1, F2, G1, G2, G3, Mf, Mg = params dA = trtc.DVDouble(A) dB = trtc.DVDouble(B) dD1 = trtc.DVDouble(D1) dD2 = trtc.DVDouble(D2) dE1 = trtc.DVDouble(E1) dE2 = trtc.DVDouble(E2) dF1 = trtc.DVDouble(F1) dF2 = trtc.DVDouble(F2) dG1 = trtc.DVDouble(G1) dG2 = trtc.DVDouble(G2) dG3 = trtc.DVDouble(G3) dMf = trtc.DVDouble(Mf) dMg = trtc.DVDouble(Mg) dunit = trtc.DVDouble(unit) AlgorithmicMethods.__linear_collection_efficiency_body.launch_n(len(is_first_in_pair) - 1, [dA, dB, dD1, dD2, dE1, dE2, dF1, dF2, dG1, dG2, dG3, dMf, dMg, output.data, radii.data, is_first_in_pair.data, dunit])
def power(output, exponent): if exponent == 1: return device_multiplier = trtc.DVDouble(exponent) MathsMethods.__power_body.launch_n(output.size(), [output, device_multiplier])