def dJhat(turbine_density): farm = Farm(domain, turbine, function_space=V, site_ids=1) farm.turbine_density.assign(turbine_density) prob_params.tidal_farm = farm problem = SteadySWProblem(prob_params) sol_params = CoupledSWSolver.default_parameters() sol_params.dump_period = 1 solver = CoupledSWSolver(problem, sol_params) functional = PowerFunctional(problem) control = Control(farm.turbine_density) rf = FenicsReducedFunctional(functional, control, solver) return rf.derivative()
def moola_problem(): adj_reset() mesh = UnitSquareMesh(256, 256) V = FunctionSpace(mesh, "CG", 1) f = interpolate(Constant(1), V) u = Function(V) phi = TestFunction(V) F = inner(grad(u), grad(phi)) * dx - f * phi * dx bc = DirichletBC(V, Constant(0), "on_boundary") solve(F == 0, u, bc) J = Functional(inner(u, u) * dx) m = Control(f) rf = ReducedFunctional(J, m) obj = rf.moola_problem().obj pf = moola.DolfinPrimalVector(f) return obj, pf
args.turbines, args.optimize, args.withcuts, args.cost) sol_params.cache_forward_state = False solver = CoupledSWSolver(problem, sol_params) # Define the functional #if args.withcuts: # power_functional = PowerFunctional(problem, cut_in_speed=1.0, cut_out_speed=3.) #else: # power_functional = PowerFunctional(problem) #cost_functional = args.cost * CostFunctional(problem) #functional = power_functional - cost_functional functional = PowerFunctional(problem) # Define the control control = Control(farm.friction_function) rf = FenicsReducedFunctional(functional, control, solver) # define optimization problem (link to optizelle) opt_problem = MaximizationProblem( rf, bounds=(0., model_turbine.maximum_smeared_friction)) parameters = { "maximum_iterations": 100, "optizelle_parameters": { "msg_level": 10, "algorithm_class": Optizelle.AlgorithmClass.TrustRegion, "H_type": Optizelle.Operators.BFGS, "dir": Optizelle.LineSearchDirection.BFGS, "ipm": Optizelle.InteriorPointMethod.LogBarrier, "sigma": 0.5,
problem = SteadySWProblem(prob_params) sol_params = CoupledSWSolver.default_parameters() sol_params.dump_period = 1 solver = CoupledSWSolver(problem, sol_params) functional = PowerFunctional(problem) control = Control(farm.turbine_density) rf = FenicsReducedFunctional(functional, control, solver) return rf.derivative() # Friction function 1 turbine_density = Constant(0.1) # Friction function 2 turbine_density = interpolate( Expression("1e-05*(1 + x[0]*x[0] + 2*x[1]*x[1])"), V) # Fricyion function 3 turbine_density = interpolate( Expression("1e-02*(sin(2*pi*x[0]) - cos(2*pi*x[1]))"), V) # Set control to turbine density farm = Farm(domain, turbine, function_space=V, site_ids=1) farm.turbine_density.assign(turbine_density) control = Control(farm.turbine_density) # Compute reduced funtional and its derivative J_dens = Jhat(turbine_density) dJ_dens = dJhat(turbine_density) # Compute convergence rates using imported method from dolfin_adjoint conv_rate = taylor_test(Jhat, control, J_dens, dJ_dens)