def _handle_input(self, domain, time, M_i, M_e, cell_models, stimulus=None, applied_current=None): # Check input and store attributes msg = "Expecting domain to be a Mesh instance, not %r" % domain assert isinstance(domain, Mesh), msg self._domain = domain msg = "Expecting time to be a Constant instance, not %r." % time assert isinstance(time, Constant) or time is None, msg self._time = time self._intracellular_conductivity = M_i self._extracellular_conductivity = M_e # Handle cell_models self._cell_models = handle_markerwise(cell_models, CardiacCellModel) if isinstance(self._cell_models, Markerwise): msg = "Different cell_models are currently not supported." error(msg) # Handle stimulus self._stimulus = handle_markerwise(stimulus, GenericFunction) # Handle applied current ac = applied_current self._applied_current = handle_markerwise(ac, GenericFunction)
def handle_markerwise(g, classtype): # Handle stimulus if (g is None \ or isinstance(g, classtype) \ or isinstance(g, Markerwise) \ or isinstance(g, object)): ## HAHAHA return g else: msg = "Expecting stimulus to be a %s or Markerwise, not %r " \ % (str(classtype), g) error(msg)
def set_initial_conditions(self, **init): "Update initial_conditions in model" for init_name, init_value in init.items(): if init_name not in self._initial_conditions: error("'%s' is not a parameter in %s" %(init_name, self)) if not isinstance(init_value, (float, int, GenericFunction)): error("'%s' is not a scalar or a GenericFunction" % init_name) if isinstance(init_value, GenericFunction) and \ init_value.value_size() != 1: error("expected the value_size of '%s' to be 1" % init_name) self._initial_conditions[init_name] = init_value
def set_parameters(self, **params): "Update parameters in model" for param_name, param_value in params.items(): if param_name not in self._parameters: error("'%s' is not a parameter in %s" %(param_name, self)) if not isinstance(param_value, (float, int, GenericFunction)): error("'%s' is not a scalar or a GenericFunction" % param_name) if isinstance(param_value, GenericFunction) and \ param_value.value_size() != 1: error("expected the value_size of '%s' to be 1" % param_name) self._parameters[param_name] = param_value
def I(self, v, s, time=None, index=None): if index is None: error("(Domain) index must be specified for multi cell models") # Extract which cell model index (given by index in incoming tuple) k = self._key_to_cell_model[index] return self._cell_models[k].I(v, s, time)
def num_states(self): """Return number of state variables (in addition to the membrane potential).""" error("Must overload num_states")
def I(self, v, s, time=None): "Return the ionic current." error("Must define I = I(v, s)")
def F(self, v, s, time=None): "Return right-hand side for state variable evolution." error("Must define F = F(v, s)")