def _compute_finite_vortex_deriv1(r1, r2, r1_deriv): r1_norm = add_ones_axis(compute_norm(r1)) r2_norm = add_ones_axis(compute_norm(r2)) r1_norm_deriv = compute_norm_deriv(r1, r1_deriv) r1_x_r2 = add_ones_axis(compute_cross(r1, r2)) r1_d_r2 = add_ones_axis(compute_dot(r1, r2)) r1_x_r2_deriv = compute_cross_deriv1(r1_deriv, r2) r1_d_r2_deriv = compute_dot_deriv(r2, r1_deriv) num = (1. / r1_norm + 1. / r2_norm) * r1_x_r2 num_deriv = (-r1_norm_deriv / r1_norm ** 2) * r1_x_r2 \ + (1. / r1_norm + 1. / r2_norm) * r1_x_r2_deriv den = r1_norm * r2_norm + r1_d_r2 den_deriv = r1_norm_deriv * r2_norm + r1_d_r2_deriv result = np.divide( num_deriv * den - num * den_deriv, den ** 2 * 4 * np.pi, out=np.zeros_like(num), where=np.abs(den)>tol ) return result
def compute_partials(self, inputs, partials): surface = self.options['surface'] ny = surface['mesh'].shape[1] P0 = inputs['nodes'][:-1, :] P1 = inputs['nodes'][ 1:, :] P_deriv = np.einsum('i,jk->ijk', np.ones(ny - 1), np.eye(3)) norm = compute_norm(P1 - P0) norm_deriv = compute_norm_deriv(P1 - P0, P_deriv) row0 = (P1 - P0) / norm row0_deriv = P_deriv / add_ones_axis(norm) - add_ones_axis(P1 - P0) / add_ones_axis(norm) ** 2 * norm_deriv cross = compute_cross(row0, self.ref_axis) cross_deriv = compute_cross_deriv1(row0_deriv, self.ref_axis) norm = compute_norm(cross) norm_deriv = compute_norm_deriv(cross, cross_deriv) row1 = cross / norm row1_deriv = cross_deriv / add_ones_axis(norm) - add_ones_axis(cross) / add_ones_axis(norm) ** 2 * norm_deriv cross = compute_cross(row0, row1) cross_deriv = ( compute_cross_deriv1(row0_deriv, row1) + compute_cross_deriv2(row0, row1_deriv) ) row2 = cross row2_deriv = cross_deriv derivs = partials['transform', 'nodes'].reshape((2, ny - 1, 12, 12, 3)) for k in range(4): derivs[0, :, 3*k + 0, 3*k : 3*k + 3, :] = -row0_deriv derivs[1, :, 3*k + 0, 3*k : 3*k + 3, :] = row0_deriv derivs[0, :, 3*k + 1, 3*k : 3*k + 3, :] = -row1_deriv derivs[1, :, 3*k + 1, 3*k : 3*k + 3, :] = row1_deriv derivs[0, :, 3*k + 2, 3*k : 3*k + 3, :] = -row2_deriv derivs[1, :, 3*k + 2, 3*k : 3*k + 3, :] = row2_deriv
def compute_partials(self, inputs, partials): surface = self.options['surface'] ny = surface['mesh'].shape[1] P0 = inputs['nodes'][:-1, :] P1 = inputs['nodes'][1:, :] P_deriv = np.einsum('i,jk->ijk', np.ones(ny - 1), np.eye(3)) norm = compute_norm(P1 - P0) norm_deriv = compute_norm_deriv(P1 - P0, P_deriv) row0 = (P1 - P0) / norm row0_deriv = P_deriv / add_ones_axis(norm) - add_ones_axis( P1 - P0) / add_ones_axis(norm)**2 * norm_deriv cross = compute_cross(row0, self.ref_axis) cross_deriv = compute_cross_deriv1(row0_deriv, self.ref_axis) norm = compute_norm(cross) norm_deriv = compute_norm_deriv(cross, cross_deriv) row1 = cross / norm row1_deriv = cross_deriv / add_ones_axis(norm) - add_ones_axis( cross) / add_ones_axis(norm)**2 * norm_deriv cross = compute_cross(row0, row1) cross_deriv = (compute_cross_deriv1(row0_deriv, row1) + compute_cross_deriv2(row0, row1_deriv)) row2 = cross row2_deriv = cross_deriv derivs = partials['transform', 'nodes'].reshape((2, ny - 1, 12, 12, 3)) for k in range(4): derivs[0, :, 3 * k + 0, 3 * k:3 * k + 3, :] = -row0_deriv derivs[1, :, 3 * k + 0, 3 * k:3 * k + 3, :] = row0_deriv derivs[0, :, 3 * k + 1, 3 * k:3 * k + 3, :] = -row1_deriv derivs[1, :, 3 * k + 1, 3 * k:3 * k + 3, :] = row1_deriv derivs[0, :, 3 * k + 2, 3 * k:3 * k + 3, :] = -row2_deriv derivs[1, :, 3 * k + 2, 3 * k:3 * k + 3, :] = row2_deriv
def _compute_finite_vortex_deriv1(r1, r2, r1_deriv): r1_norm = add_ones_axis(compute_norm(r1)) r2_norm = add_ones_axis(compute_norm(r2)) r1_norm_deriv = compute_norm_deriv(r1, r1_deriv) r1_x_r2 = add_ones_axis(compute_cross(r1, r2)) r1_d_r2 = add_ones_axis(compute_dot(r1, r2)) r1_x_r2_deriv = compute_cross_deriv1(r1_deriv, r2) r1_d_r2_deriv = compute_dot_deriv(r2, r1_deriv) num = (1. / r1_norm + 1. / r2_norm) * r1_x_r2 num_deriv = (-r1_norm_deriv / r1_norm ** 2) * r1_x_r2 \ + (1. / r1_norm + 1. / r2_norm) * r1_x_r2_deriv den = r1_norm * r2_norm + r1_d_r2 den_deriv = r1_norm_deriv * r2_norm + r1_d_r2_deriv result = (num_deriv * den - num * den_deriv) / den**2 / 4 / np.pi result[np.abs(den) < tol] = 0. return result
def _compute_finite_vortex_deriv1(r1, r2, r1_deriv): r1_norm = add_ones_axis(compute_norm(r1)) r2_norm = add_ones_axis(compute_norm(r2)) r1_norm_deriv = compute_norm_deriv(r1, r1_deriv) r1_x_r2 = add_ones_axis(compute_cross(r1, r2)) r1_d_r2 = add_ones_axis(compute_dot(r1, r2)) r1_x_r2_deriv = compute_cross_deriv1(r1_deriv, r2) r1_d_r2_deriv = compute_dot_deriv(r2, r1_deriv) num = (1. / r1_norm + 1. / r2_norm) * r1_x_r2 num_deriv = (-r1_norm_deriv / r1_norm ** 2) * r1_x_r2 \ + (1. / r1_norm + 1. / r2_norm) * r1_x_r2_deriv den = r1_norm * r2_norm + r1_d_r2 den_deriv = r1_norm_deriv * r2_norm + r1_d_r2_deriv result = (num_deriv * den - num * den_deriv) / den ** 2 / 4 / np.pi result[np.abs(den) < tol] = 0. return result
def compute_partials(self, inputs, partials): rho = inputs['rho'][0] horseshoe_circulations = np.outer(inputs['horseshoe_circulations'], np.ones(3)) velocities = inputs['force_pts_velocities'] bound_vecs = inputs['bound_vecs'] horseshoe_circulations_ones = np.einsum('i,jk->ijk', inputs['horseshoe_circulations'], np.ones((3, 3))) deriv_array = np.einsum('i,jk->ijk', np.ones(self.system_size), np.eye(3)) partials['panel_forces', 'rho'] = \ (horseshoe_circulations * compute_cross(velocities, bound_vecs)).flatten() partials['panel_forces', 'horseshoe_circulations'] = \ (rho * compute_cross(velocities, bound_vecs)).flatten() partials['panel_forces', 'force_pts_velocities'] = \ (rho * horseshoe_circulations_ones * compute_cross_deriv1(deriv_array, bound_vecs)).flatten() partials['panel_forces', 'bound_vecs'] = \ (rho * horseshoe_circulations_ones * compute_cross_deriv2(velocities, deriv_array)).flatten()
def compute_partials(self, inputs, partials): system_size = self.system_size rho = inputs['rho'][0] horseshoe_circulations = np.outer(inputs['horseshoe_circulations'], np.ones(3)) velocities = inputs['force_pts_velocities'] bound_vecs = inputs['bound_vecs'] horseshoe_circulations_ones = np.einsum('i,jk->ijk', inputs['horseshoe_circulations'], np.ones((3, 3))) deriv_array = np.einsum('i,jk->ijk', np.ones(self.system_size), np.eye(3)) partials['panel_forces', 'rho'] = \ (horseshoe_circulations * compute_cross(velocities, bound_vecs)).flatten() partials['panel_forces', 'horseshoe_circulations'] = \ (rho * compute_cross(velocities, bound_vecs)).flatten() partials['panel_forces', 'force_pts_velocities'] = \ (rho * horseshoe_circulations_ones * compute_cross_deriv1(deriv_array, bound_vecs)).flatten() partials['panel_forces', 'bound_vecs'] = \ (rho * horseshoe_circulations_ones * compute_cross_deriv2(velocities, deriv_array)).flatten()