def set_qoi_kernel(self, prob, i): r""" Assuming the QoI is power output, ..math:: J(\mathbf q) = \int_\Omega C_t \|\mathbf u\|^3 \;\mathrm dx, this can be represented as an inner product with :math:`mathbf q` using the kernel function ..math:: \mathbf k(\mathbf q) = (\frac13 C_t \|\mathbf u\|\mathbf u, 0). That is, ..math:: J(\mathbf q) = \int_\Omega \mathbf k(\mathbf q) \cdot \mathbf q \;\mathrm dx. """ prob.kernels[i] = Function(prob.V[i]) u, eta = prob.fwd_solutions[i].split() k_u, k_eta = prob.kernels[i].split() # k_u.interpolate(Constant(1/3)*prob.turbine_densities[i]*speed(u)*u) k_u.interpolate(prob.turbine_densities[i]*speed(u)*u)
with open(os.path.join(ramp_dir, "log"), "w+") as logfile: logfile.write(msg + "\n") op.plot_pvd = True swp.export_state(0, ramp_dir) else: swp.load_state(0, ramp_dir) # --- Plot plot_dir = create_directory(os.path.join(os.path.dirname(__file__), 'plots')) # Get fluid speed and elevation in P1 space q = swp.fwd_solutions[0] u, eta = q.split() speed_proj = interpolate(speed(q), swp.P1[0]) eta_proj = project(eta, swp.P1[0]) # Plot fluid speed fig, axes = plt.subplots(figsize=(14, 6)) cbar = fig.colorbar(tricontourf(speed_proj, axes=axes, levels=50, cmap='coolwarm'), ax=axes) cbar.set_label(r"Fluid speed [$\mathrm{m\,s}^{-1}$]") axes.set_xlim([-L/2, L/2]) axes.set_ylim([-W/2, W/2]) axes.set_xlabel(r"$x$-coordinate $[\mathrm m]$") axes.set_ylabel(r"$y$-coordinate $[\mathrm m]$") axes.set_xticks(np.linspace(-20000, 20000, 3)) axes.set_yticks(np.linspace(-20000, 20000, 5)) plt.tight_layout() for ext in ("png", "pdf"): plt.savefig(os.path.join(plot_dir, ".".join(["speed", ext])))
# --- Solve forward problem tp = AdaptiveSteadyTurbineProblem(op, discrete_turbines=discrete_turbines, callback_dir=op.di) tp.solve_forward() op.print_debug("Power output: {:.4e}MW".format(tp.quantity_of_interest() * 1.030e-03)) # --- Plot fluid speed if plot_any: # Compute fluid speed spd = interpolate(speed(tp.fwd_solution), tp.P1[0]) # Plot fig, axes = plt.subplots(figsize=(12, 6.5)) tc = tricontourf(spd, axes=axes, **tricontourf_kwargs) cbar = fig.colorbar(tc, ax=axes, orientation="horizontal", pad=0.1) cbar.ax.set_yticklabels(cbar.ax.get_yticklabels(), fontsize=fontsizes['cbar']) cbar.set_label(r'Fluid speed [$m\,s^{-1}$]', fontsize=fontsizes['cbar']) axes.set_xlim([0, op.domain_length]) axes.set_ylim([0, op.domain_width]) # axes.xaxis.tick_top() # for axis in (axes.xaxis, axes.yaxis): # for tick in axis.get_major_ticks(): # tick.label.set_fontsize(fontsizes['tick']) axes.set_xticks([])
def set_qoi_kernel(self, prob, i): prob.kernels[i] = Function(prob.V[i]) u, eta = prob.fwd_solutions[i].split() k_u, k_eta = prob.kernels[i].split() # k_u.interpolate(Constant(1/3)*prob.turbine_density*speed(u)*u) k_u.interpolate(prob.turbine_density*speed(u)*u)
fig, axes = plt.subplots(figsize=(8, 3)) hmin = np.floor(h.vector().gather().min()) hmax = np.ceil(h.vector().gather().max()) levels = np.linspace(hmin, hmax, 40) tc = tricontourf(h, axes=axes, levels=levels, cmap='coolwarm') cbar = fig.colorbar(tc, ax=axes, orientation="horizontal", pad=0.1) cbar.set_ticks(np.linspace(hmin, hmax, 5)) axes.axis(False) axes.set_xlim([0, 50]) axes.set_ylim([0, 10]) fname = 'anisotropic_cell_size' if op.anisotropic_stabilisation else 'isotropic_cell_size' savefig(fname, op.di, extensions=["jpg"]) # Calculate stabilisation parameter uv = Constant(as_vector(op.base_velocity)) unorm = speed(uv) tau = 0.5 * h / unorm Pe = 0.5 * h * unorm / op.base_diffusivity tau *= min_value(1, Pe / 3) tau = interpolate(tau, h.function_space()) # Plot stabilisation parameter fig, axes = plt.subplots(figsize=(8, 3)) taumin = np.floor(tau.vector().gather().min()) taumax = np.ceil(tau.vector().gather().max()) levels = np.linspace(taumin, taumax, 40) tc = tricontourf(tau, axes=axes, levels=levels, cmap='coolwarm') cbar = fig.colorbar(tc, ax=axes, orientation="horizontal", pad=0.1) cbar.set_ticks(np.linspace(taumin, taumax, 5)) axes.axis(False) axes.set_xlim([0, 50])