# ============================================================================== output_path = os.path.join( test_config.output_path, 'test_case_simulation_tumor_growth_2D_subdomains_adjoint', 'adjoint') fu.ensure_dir_exists(output_path) D = fenics.Constant(0.1) rho = fenics.Constant(0.01) coupling = fenics.Constant(0.1) u = sim.run_for_adjoint([D, rho, coupling], output_dir=output_path) J = fenics.Functional( fenics.inner(u - u_target, u - u_target) * sim.subdomains.dx) controls = [ fenics.ConstantControl(D), fenics.ConstantControl(rho), fenics.ConstantControl(coupling) ] def eval_cb(j, a): D, rho, coupling = a print(j, D.values(), rho.values(), coupling.values()) reduced_functional = fenics.ReducedFunctional(J, controls, eval_cb_post=eval_cb) m_opt = fenics.minimize(reduced_functional)
f_thresh = 0.5 * (fenics.tanh((f - thresh) / smooth_f) + 1) return f_thresh m_target, w_target = fenics.split(u_target) m, w = fenics.split(u) J = fenics.Functional( fenics.inner(m - m_target, m - m_target) * sim.subdomains.dx + # displacements fenics.inner( thresh(w, thresh_1) - 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())
# disp_target_noise = add_noise(m_target, 0.005) # conc_target_noise = add_noise(w_target, 0.02) # disp_target_noise = add_noise(m_target, 0.01) conc_target_noise = add_noise(w_target, 0.1) disp_target_noise = add_noise(m_target, 0.05) disp, conc = fenics.split(u) alpha = 0.5 J = fenics.Functional( fenics.inner(conc - conc_target_noise, conc - conc_target_noise) * sim.subdomains.dx + fenics.inner(disp - disp_target_noise, disp - disp_target_noise) * sim.subdomains.dx + alpha * fenics.inner(u, u) * sim.subdomains.dx) controls = [ fenics.ConstantControl(D), fenics.ConstantControl(rho), fenics.ConstantControl(c) ] # # class ParameterEstimation(): # # def __init__(self, sim): # self.sim = sim # # def set import pandas as pd opt_param_progress_post = []