Ejemplo n.º 1
0
 def append(self, current, q):
     self.data[self.i, 0] = q
     self.data[self.i, 1] = current.cost
     if self.par_fid is not None:
         self.par_fid << vector2Function(
             current.m, self.Vh[PARAMETER], name="parameter")
     if self.state_fid is not None:
         self.state_fid << vector2Function(
             current.u, self.Vh[STATE], name="state")
     self.i += 1
Ejemplo n.º 2
0
 def solveFwd(self, state, x, tol):
     """ Solve the possibly nonlinear Fwd Problem:
     Given a, find u such that
     \delta_p F(u,a,p;\hat_p) = 0 \for all \hat_p"""
     if self.is_fwd_linear:
         u = dl.TrialFunction(self.Vh[STATE])
         a = vector2Function(x[PARAMETER], self.Vh[PARAMETER])
         p = dl.TestFunction(self.Vh[ADJOINT])
         res_form = self.varf_handler(u, a, p)
         A_form = dl.lhs(res_form)
         b_form = dl.rhs(res_form)
         A, b = dl.assemble_system(A_form, b_form, bcs=self.bc)
         solver = dl.PETScLUSolver()
         solver.set_operator(A)
         solver.solve(state, b)
     else:
         u = vector2Function(x[STATE], self.Vh[STATE])
         a = vector2Function(x[PARAMETER], self.Vh[PARAMETER])
         p = dl.TestFunction(self.Vh[ADJOINT])
         res_form = self.varf_handler(u, a, p)
         dl.solve(res_form == 0, u, self.bc)
         state.zero()
         state.axpy(1., u.vector())