def point_integral_step(self, model):
        # Set-up forms
        mesh = UnitSquareMesh(10, 10)
        V = FunctionSpace(mesh, "CG", 1)
        S = state_space(mesh, model.num_states())
        Me = MixedElement((V.ufl_element(), S.ufl_element()))
        VS = FunctionSpace(mesh, Me)
        vs = Function(VS)
        vs.assign(project(model.initial_conditions(), VS))
        (v, s) = split(vs)
        (w, r) = TestFunctions(VS)
        rhs = inner(model.F(v, s), r) + inner(-model.I(v, s), w)
        form = rhs * dP

        # Set-up scheme
        time = Constant(0.0)
        scheme = BackwardEuler(form, vs, time)
        scheme.t().assign(float(time))

        # Create and step solver
        solver = PointIntegralSolver(scheme)
        solver.parameters["newton_solver"]["relative_tolerance"] = 1e-6
        solver.parameters["newton_solver"]["report"] = False
        dt = 0.1
        solver.step(dt)
        return vs
예제 #2
0
def ode_test_form(request):
    Model = eval(request.param)
    model = Model()
    mesh = UnitSquareMesh(10, 10)
    V = FunctionSpace(mesh, "CG", 1)
    S = state_space(mesh, model.num_states())
    Mx = MixedElement((V.ufl_element(), S.ufl_element()))
    VS = FunctionSpace(mesh, Mx)
    vs = Function(VS)
    vs.assign(project(model.initial_conditions(), VS))
    (v, s) = split(vs)
    (w, r) = TestFunctions(VS)
    rhs = inner(model.F(v, s), r) + inner(-model.I(v, s), w)
    form = rhs * dP
    return form
예제 #3
0
    def __init__(self, mesh, time, model, I_s=None, params=None):

        # Store input
        self._mesh = mesh
        self._time = time
        self._model = model

        # Extract some information from cell model
        self._F = self._model.F
        self._I_ion = self._model.I
        self._num_states = self._model.num_states()

        # Handle stimulus
        self._I_s = handle_markerwise(I_s, GenericFunction)

        # Initialize and update parameters if given
        self.parameters = self.default_parameters()
        if params is not None:
            self.parameters.update(params)

        # Create (mixed) function space for potential + states
        v_family = self.parameters["V_polynomial_family"]
        v_degree = self.parameters["V_polynomial_degree"]
        s_family = self.parameters["S_polynomial_family"]
        s_degree = self.parameters["S_polynomial_degree"]

        if (v_family == s_family and s_degree == v_degree):
            self.VS = VectorFunctionSpace(self._mesh,
                                          v_family,
                                          v_degree,
                                          dim=self._num_states + 1)
        else:
            V = FunctionSpace(self._mesh, v_family, v_degree)
            S = state_space(self._mesh, self._num_states, s_family, s_degree)
            #Mx = MixedElement(V.ufl_element(), S.ufl_element())
            #self.VS = FunctionSpace(self._mesh, Mx)
            self.VS = MixedFunctionSpace(V, S)

        # Initialize solution fields
        self.vs_ = Function(self.VS, name="vs_")
        self.vs = Function(self.VS, name="vs")