dj_df.columns = columns_dJ # merge opt_df = pd.merge(params_df, dj_df, on='J', how='outer') return opt_df reduced_functional = fenics.ReducedFunctional( J, controls, derivative_cb_post=derivative_cb_post, eval_cb_post=eval_cb_post) dJdu = fenics.compute_gradient(J, controls) bounds = [[0.05, 0.01, 0.05], [0.5, 0.2, 0.05]] m_opt = fenics.minimize(reduced_functional, bounds=bounds, method='SLSQP', options={'disp': True}) opt_df = create_opt_progress_df(opt_param_progress_post, opt_dj_progress_post, ['D', 'rho', 'c']) opt_df.to_excel(os.path.join(output_path, 'optimization.xls')) opt_df.to_pickle(os.path.join(output_path, 'optimization.pkl')) # ============================================================================== # Plotting # ============================================================================== plott.show_img_seg_f(function=m_target, path=os.path.join(output_path, 'disp_target_orig.png')) plott.show_img_seg_f(function=w_target, path=os.path.join(output_path, 'conc_target_orig.png'))
thresh(w_target, thresh_1), # thresholded concentration thresh(w, thresh_1) - thresh(w_target, thresh_1)) * sim.subdomains.dx) controls = [fenics.ConstantControl(param) for param in params_init] def eval_cb(j, a): params = [param.values() for param in a] print(j, *params) reduced_functional = fenics.ReducedFunctional(J, controls, eval_cb_post=eval_cb) m_opt = fenics.minimize(reduced_functional) for var in m_opt: print(var.values()) # ============================================================================== # RESULTS # ============================================================================== # Plot when adjoint computation has finished to avoid recording of function projections # sim.plotting.plot_all(sim_time) # # output_path = os.path.join(test_config.output_path, 'test_case_simulation_tumor_growth_2D_uniform_adjoint') # fu.ensure_dir_exists(output_path) # # sim.init_postprocess(os.path.join(output_path, 'postprocess', 'plots')) #
params_df.columns = columns_params dj_df = pd.DataFrame(opt_dj_list) dj_df.columns = columns_dJ # merge opt_df = pd.merge(params_df, dj_df, on='J', how='outer') return opt_df reduced_functional = fenics.ReducedFunctional( J, controls, derivative_cb_post=derivative_cb_post, eval_cb_post=eval_cb_post) dJdu = fenics.compute_gradient(J, controls) bounds = [[0.05, 0.01, 0.05], [0.5, 0.2, 0.5]] m_opt = fenics.minimize(reduced_functional, bounds=bounds, options={ 'disp': True, 'gtol': 1e-10 }, tol=1e-10) opt_df = create_opt_progress_df(opt_param_progress_post, opt_dj_progress_post, ['D', 'rho', 'c']) opt_df.to_excel(os.path.join(output_path, 'optimization.xls')) opt_df.to_pickle(os.path.join(output_path, 'optimization.pkl')) for var in m_opt: print(var.values())