def solve_nonlinear(self, params, unknowns, resids): global nCalls_con nCalls_con += 1 turbineX = params['turbineX'] # turbineX = turbineX-(max(turbineX)+min(turbineX))/2. turbineY = params['turbineY'] # turbienY = turbineY-(max(turbineY)+min(turbineY))/2. rotorDiameter = params['rotorDiameter'] boundaryVertices = params['boundaryVertices'] # bx = params['boundaryVertices'][:,0] # by = params['boundaryVertices'][:,1] # bx = bx + (max(turbineX)+min(turbineX))/2. # by = by + (max(turbineY)+min(turbineY))/2. # boundaryVertices[:,0] = bx[:] # boundaryVertices[:,1] = by[:] boundaryNormals = params['boundaryNormals'] dx = np.eye(self.nTurbines) dy = np.zeros((self.nTurbines,self.nTurbines)) _,ss_dx,_,bd_dx = constraints.constraints_position_dv(turbineX,dx,turbineY,dy, boundaryVertices,boundaryNormals) dx = np.zeros((self.nTurbines,self.nTurbines)) dy = np.eye(self.nTurbines) ss,ss_dy,bd,bd_dy = constraints.constraints_position_dv(turbineX,dx,turbineY,dy, boundaryVertices,boundaryNormals) bounds = np.zeros(nTurbines) index = np.zeros(nTurbines) for i in range(nTurbines): bounds[i] = np.min(bd[i]) index[i] = np.argmin(bd[i]) self.index = index self.ss_dx = ss_dx self.ss_dy = ss_dy self.bd_dx = bd_dx self.bd_dy = bd_dy unknowns['spacing_constraint'] = ss-(2.*rotorDiameter[0])**2 unknowns['boundary_constraint'] = bounds
def solve_nonlinear(self, params, unknowns, resids): # params['nCalls_con'] += 1 turbineX = params['turbineX'] turbineY = params['turbineY'] rotorDiameter = params['rotorDiameter'] boundaryVertices = params['boundaryVertices'] boundaryNormals = params['boundaryNormals'] dx = np.eye(self.nTurbines) dy = np.zeros((self.nTurbines, self.nTurbines)) _, ss_dx, _, bd_dx = constraints.constraints_position_dv( turbineX, dx, turbineY, dy, boundaryVertices, boundaryNormals) dx = np.zeros((self.nTurbines, self.nTurbines)) dy = np.eye(self.nTurbines) ss, ss_dy, bd, bd_dy = constraints.constraints_position_dv( turbineX, dx, turbineY, dy, boundaryVertices, boundaryNormals) bounds = np.zeros(self.nTurbines) bounds_index = np.zeros(self.nTurbines, dtype=int) for i in range(self.nTurbines): bounds[i] = np.min(bd[i]) bounds_index[i] = np.argmin(bd[i]) # seps = np.zeros(self.nTurbines) # seps_index = np.zeros(self.nTurbines) # for i in range(self.nTurbines): # seps[i] = np.min(ss[i]) # seps_index[i] = np.argmin(ss[i]) self.bounds_index = bounds_index # self.seps_index = seps_index self.ss_dx = ss_dx self.ss_dy = ss_dy self.bd_dx = bd_dx self.bd_dy = bd_dy unknowns['spacing_constraint'] = ss - (2. * rotorDiameter[0])**2 # unknowns['spacing_constraint'] = seps-(2.*rotorDiameter[0])**2 unknowns['boundary_constraint'] = bounds
x = np.zeros(nTurbines) y = np.zeros(nTurbines) x[:] = turbineX y[:] = turbineY x[i] += d y[i] += d s_x, b_x = constraints.constraints_position(x, turbineY, boundaryVertices, boundaryNormals) s_y, b_y = constraints.constraints_position(turbineX, y, boundaryVertices, boundaryNormals) s_fd_x[i] = (s_x - s_fortran) / d s_fd_y[i] = (s_y - s_fortran) / d b_fd_x[i] = (b_x - b_fortran) / d b_fd_y[i] = (b_y - b_fortran) / d dx = np.zeros((nTurbines, nTurbines)) dy = np.eye(nTurbines) ss, ss_d, bd, bd_d = constraints.constraints_position_dv( turbineX, dx, turbineY, dy, boundaryVertices, boundaryNormals) print ss_d - s_fd_y print bd_d - b_fd_y dx = np.eye(nTurbines) dy = np.zeros((nTurbines, nTurbines)) ss, ss_d, bd, bd_d = constraints.constraints_position_dv( turbineX, dx, turbineY, dy, boundaryVertices, boundaryNormals) print ss_d - s_fd_x print bd_d - b_fd_x