def Jhat(ic):
     print("Perturbed initial condition: ", ic.vector().array())
     u = main(model(), ics=ic)
     print("Perturbed functional value: ", assemble(inner(u, u) * dx))
     print("Perturbed solution: ", u.vector().array())
     return assemble(inner(u, u) * dx)
 def Jhat(ic):
     print "Perturbed initial condition: ", ic.vector().array()
     u = main(model(), ics=ic)
     print "Perturbed functional value: ", assemble(inner(u, u)*dx)
     print "Perturbed solution: ", u.vector().array()
     return assemble(inner(u, u)*dx)
from dolfin_adjoint import *
import ufl.algorithms

if not hasattr(MultiStageScheme, "to_tlm"):
    info_red("Need dolfin > 1.2.0 for ode_solver test.")
    import sys
    sys.exit(0)

# Import cell model (rhs, init_values, default_parameters)
from beatadjoint.cellmodels.fitzhughnagumo import Fitzhughnagumo as model

set_log_level(ERROR)

domain = UnitIntervalMesh(1)
num_states = len(model().initial_conditions()((0.0, )))
V = None


def main(model, ics=None, annotate=False):

    params = BasicCardiacODESolver.default_parameters()
    params["theta"] = 1.0
    params["V_polynomial_family"] = "CG"
    params["S_polynomial_family"] = "CG"
    params["V_polynomial_degree"] = 1
    params["S_polynomial_degree"] = 1
    params["enable_adjoint"] = annotate
    solver = BasicCardiacODESolver(domain,
                                   None,
                                   model.num_states(),
    import sys; sys.exit(0)

from dolfin_adjoint import *
import ufl.algorithms

if not hasattr(MultiStageScheme, "to_tlm"):
    info_red("Need dolfin > 1.2.0 for ode_solver test.")
    import sys; sys.exit(0)

# Import cell model (rhs, init_values, default_parameters)
from beatadjoint.cellmodels.fitzhughnagumo import Fitzhughnagumo as model

set_log_level(ERROR)

domain = UnitIntervalMesh(1)
num_states = len(model().initial_conditions()((0.0,)))
V = None

def main(model, ics=None, annotate=False):

    params = BasicCardiacODESolver.default_parameters()
    params["theta"] = 1.0
    params["V_polynomial_family"] = "CG"
    params["S_polynomial_family"] = "CG"
    params["V_polynomial_degree"] = 1
    params["S_polynomial_degree"] = 1
    params["enable_adjoint"] = annotate
    solver = BasicCardiacODESolver(domain, None, model.num_states(), model.F, model.I, I_s=model.stimulus, params=params)

    if ics is None:
        global V