def functional_partial_second_derivative(self, adjointer, J, timestep, m_dot): form = J.get_form(adjointer, timestep) if form is None: return None for coeff in ufl.algorithms.extract_coefficients(form): try: mesh = coeff.function_space().mesh() fn_space = backend.FunctionSpace(mesh, "R", 0) break except: pass dparam = backend.Function(fn_space) dparam.vector()[:] = 1.0 * float(self.coeff) d = backend.derivative(form, get_constant(self.a), dparam) d = ufl.algorithms.expand_derivatives(d) d2param = backend.Function(fn_space) d2param.vector()[:] = 1.0 * float(self.coeff) * m_dot d = backend.derivative(d, get_constant(self.a), d2param) d = ufl.algorithms.expand_derivatives(d) if len(d.integrals()) != 0: return backend.assemble(d) else: return None
def equation_partial_second_derivative(self, adjointer, adjoint, i, variable, m_dot): form = adjresidual.get_residual(i) if form is not None: form = -form mesh = ufl.algorithms.extract_arguments(form)[0].function_space().mesh() fn_space = backend.FunctionSpace(mesh, "R", 0) dparam = backend.Function(fn_space) dparam.vector()[:] = 1.0 * float(self.coeff) d2param = backend.Function(fn_space) d2param.vector()[:] = 1.0 * float(self.coeff) * m_dot diff_form = ufl.algorithms.expand_derivatives(backend.derivative(form, get_constant(self.a), dparam)) if diff_form is None: return None diff_form = ufl.algorithms.expand_derivatives(backend.derivative(diff_form, get_constant(self.a), d2param)) if diff_form is None: return None # Let's see if the form actually depends on the parameter m if len(diff_form.integrals()) != 0: dFdm = backend.assemble(diff_form) # actually - dF/dm assert isinstance(dFdm, backend.GenericVector) out = dFdm.inner(adjoint.vector()) return out else: return None # dF/dm is zero, return None
def __init__(self, player='sat', log_level=logging.INFO): self.game_coordinates = get_constant('GAME_BOX_COORDINATES', player) self.ammo_coordinates = get_constant('AMMO_PIXEL_COORDINATES', player) self.clip_button_coordinates = get_constant( 'POSITION_CLIP_SIZE_INCREASE', player) self.done_button_coordinates = get_constant( 'POSITION_DONE_MENU_BUTTON', player) self.sniper_button_coordinates = get_constant('POSITION_SNIPER_RIFLE', player) pyautogui.PAUSE = PYAUTOGUI_ACTION_DELAY self.startTime = time.time() self.logger = logging.getLogger() ElapsedFormatter.add_handler(self.logger) self.logger.setLevel(log_level)
def functional_partial_derivative(self, adjointer, J, timestep): form = J.get_form(adjointer, timestep) if form is None: return None # OK. Now that we have the form for the functional at this timestep, let's differentiate it with respect to # my dear Constant, and be done. for coeff in ufl.algorithms.extract_coefficients(form): try: mesh = coeff.function_space().mesh() fn_space = backend.FunctionSpace(mesh, "R", 0) break except: pass dparam = backend.Function(fn_space) dparam.vector()[:] = 1.0 * float(self.coeff) d = backend.derivative(form, get_constant(self.a), dparam) d = ufl.algorithms.expand_derivatives(d) # Add the derivatives of Expressions wrt to the Constant d = self.expression_derivative(form, d) if len(d.integrals()) != 0: return backend.assemble(d) else: return None
def __call__(self, adjointer, i, dependencies, values, variable): form = adjresidual.get_residual(i) if form is not None: form = -form fn_space = ufl.algorithms.extract_arguments(form)[0].function_space() dparam = backend.Function(backend.FunctionSpace(fn_space.mesh(), "R", 0)) dparam.vector()[:] = 1.0 * float(self.coeff) diff_form = ufl.algorithms.expand_derivatives(backend.derivative(form, get_constant(self.a), dparam)) return adjlinalg.Vector(diff_form) else: return None
def data(self): return get_constant(self.a)