Example #1
0
 def __init__(self, Name, PortType, Model, Description=""):
     dae.daePort.__init__(self, Name, PortType, Model, Description)
     self.c_lyte = dae.daeVariable(
         "c_lyte", mole_frac_t, self,
         "Concentration in the electrolyte")
     self.phi_lyte = dae.daeVariable(
         "phi_lyte", elec_pot_t, self,
         "Electric potential in the electrolyte")
Example #2
0
    def __init__(self,
                 Name,
                 Parent=None,
                 Description="",
                 ndD=None,
                 ndD_s=None):
        dae.daeModel.__init__(self, Name, Parent, Description)
        if (ndD is None) or (ndD_s is None):
            raise Exception("Need input parameter dictionary")
        self.ndD = ndD
        self.ndD_s = ndD_s

        # Domain
        self.Dmn = dae.daeDomain("discretizationDomain", self, dae.unit(),
                                 "discretization domain")

        # Variables
        self.c1 = dae.daeVariable(
            "c1", mole_frac_t, self,
            "Concentration in 'layer' 1 of active particle", [self.Dmn])
        self.c2 = dae.daeVariable(
            "c2", mole_frac_t, self,
            "Concentration in 'layer' 2 of active particle", [self.Dmn])
        self.cbar = dae.daeVariable(
            "cbar", mole_frac_t, self,
            "Average concentration in active particle")
        self.c1bar = dae.daeVariable(
            "c1bar", mole_frac_t, self,
            "Average concentration in 'layer' 1 of active particle")
        self.c2bar = dae.daeVariable(
            "c2bar", mole_frac_t, self,
            "Average concentration in 'layer' 2 of active particle")
        self.dcbardt = dae.daeVariable("dcbardt", dae.no_t, self,
                                       "Rate of particle filling")
        if ndD["type"] not in ["ACR2"]:
            self.Rxn1 = dae.daeVariable("Rxn1", dae.no_t, self,
                                        "Rate of reaction 1")
            self.Rxn2 = dae.daeVariable("Rxn2", dae.no_t, self,
                                        "Rate of reaction 2")
        else:
            self.Rxn1 = dae.daeVariable("Rxn1", dae.no_t, self,
                                        "Rate of reaction 1", [self.Dmn])
            self.Rxn2 = dae.daeVariable("Rxn2", dae.no_t, self,
                                        "Rate of reaction 2", [self.Dmn])

        #Get reaction rate function from dictionary name
        self.calc_rxn_rate = getattr(reactions, ndD["rxnType"])

        # Ports
        self.portInLyte = ports.portFromElyte("portInLyte", dae.eInletPort,
                                              self,
                                              "Inlet port from electrolyte")
        self.portInBulk = ports.portFromBulk(
            "portInBulk", dae.eInletPort, self,
            "Inlet port from e- conducting phase")
        self.phi_lyte = self.portInLyte.phi_lyte
        self.c_lyte = self.portInLyte.c_lyte
        self.phi_m = self.portInBulk.phi_m
Example #3
0
    def __init__(self,
                 Name,
                 Parent=None,
                 Description="",
                 ndD=None,
                 ndD_s=None):
        dae.daeModel.__init__(self, Name, Parent, Description)

        if (ndD is None) or (ndD_s is None):
            raise Exception("Need input parameter dictionary")
        self.ndD = ndD
        self.ndD_s = ndD_s

        # Domain
        self.Dmn = dae.daeDomain("discretizationDomain", self, dae.unit(),
                                 "discretization domain")

        # Define some variable types
        mole_frac_t = dae.daeVariableType(name="mole_frac_t",
                                          units=dae.unit(),
                                          lowerBound=0,
                                          upperBound=1,
                                          initialGuess=0.25,
                                          absTolerance=ndD_s["absTol"])
        # Variables
        self.c = dae.daeVariable("c", mole_frac_t, self,
                                 "Concentration in active particle",
                                 [self.Dmn])
        self.cbar = dae.daeVariable(
            "cbar", mole_frac_t, self,
            "Average concentration in active particle")
        self.dcbardt = dae.daeVariable("dcbardt", dae.no_t, self,
                                       "Rate of particle filling")
        if ndD["type"] not in ["ACR"]:
            self.Rxn = dae.daeVariable("Rxn", dae.no_t, self,
                                       "Rate of reaction")
        else:
            self.Rxn = dae.daeVariable("Rxn", dae.no_t, self,
                                       "Rate of reaction", [self.Dmn])

        # Ports
        self.portInLyte = ports.portFromElyte("portInLyte", dae.eInletPort,
                                              self,
                                              "Inlet port from electrolyte")
        self.portInBulk = ports.portFromBulk(
            "portInBulk", dae.eInletPort, self,
            "Inlet port from e- conducting phase")
        self.phi_lyte = self.portInLyte.phi_lyte()
        self.c_lyte = self.portInLyte.c_lyte()
        self.phi_m = self.portInBulk.phi_m()
 def __init__(self, name, model):
     """
     :param name: string
     :param model: daeModel-derived object
         
     :raises: RuntimeError
     """
     self.Ports        = []
     self.Name         = name
     self.Model        = model
     self.portVariable = daet.daeVariable(self.Name, dae_nineml_t, self.Model, "")
    def __init__(self, spiketimes, Name, Parent = None, Description = ""):
        nineml_daetools_bridge.__init__(self, Name, None, Parent, Description)

        # A dummy variable
        self.event = daet.daeVariable("event", daet.time_t, self, "")
        
        # Add one 'send' event port
        self.spikeoutput = daet.daeEventPort("spikeoutput", daet.eOutletPort, self, "Spike outlet event port")
        self.nineml_event_ports.append(self.spikeoutput)
        
        # A list of spike event times
        self.spiketimes = list(spiketimes)
Example #6
0
 def __init__(self, name, model):
     """
     :param name: string
     :param model: daeModel-derived object
         
     :raises: RuntimeError
     """
     self.Ports = []
     self.Name = name
     self.Model = model
     self.portVariable = daet.daeVariable(self.Name, dae_nineml_t,
                                          self.Model, "")
Example #7
0
    def __init__(self, spiketimes, Name, Parent=None, Description=""):
        nineml_daetools_bridge.__init__(self, Name, None, Parent, Description)

        # A dummy variable
        self.event = daet.daeVariable("event", daet.time_t, self, "")

        # Add one 'send' event port
        self.spikeoutput = daet.daeEventPort("spikeoutput", daet.eOutletPort,
                                             self, "Spike outlet event port")
        self.nineml_event_ports.append(self.spikeoutput)

        # A list of spike event times
        self.spiketimes = list(spiketimes)
    def __init__(self, Name, PortType, Model, Description = ''):
        """
        :param Name: string
        :param PortType: daetools port type (eInlet, eOutlet, eInletOutlet)
        :param Model: daeModel-derived object
        :param Description: string
            
        :raises: RuntimeError
        """
        daet.daePort.__init__(self, Name, PortType, Model, Description)

        # NineML ports always contain only one variable, and that variable is referred to by the port name
        # Here we name this variable 'value'
        self.value = daet.daeVariable("value", dae_nineml_t, self, "")
Example #9
0
    def __init__(self, Name, PortType, Model, Description=''):
        """
        :param Name: string
        :param PortType: daetools port type (eInlet, eOutlet, eInletOutlet)
        :param Model: daeModel-derived object
        :param Description: string
            
        :raises: RuntimeError
        """
        daet.daePort.__init__(self, Name, PortType, Model, Description)

        # NineML ports always contain only one variable, and that variable is referred to by the port name
        # Here we name this variable 'value'
        self.value = daet.daeVariable("value", dae_nineml_t, self, "")
Example #10
0
    def __init__(self,
                 Name,
                 Parent=None,
                 Description="",
                 ndD_s=None,
                 ndD_e=None):
        dae.daeModel.__init__(self, Name, Parent, Description)

        if (ndD_s is None) or (ndD_e is None):
            raise Exception("Need input parameter dictionaries")
        self.ndD = ndD_s
        self.profileType = ndD_s['profileType']
        Nvol = ndD_s["Nvol"]
        Npart = ndD_s["Npart"]
        self.trodes = trodes = ndD_s["trodes"]

        # Domains where variables are distributed
        self.DmnCell = {}  # domains over full cell dimensions
        self.DmnPart = {}  # domains over particles in each cell volume
        if Nvol["s"] >= 1:  # If we have a separator
            self.DmnCell["s"] = dae.daeDomain(
                "DmnCell_s", self, dae.unit(),
                "Simulated volumes in the separator")
        for trode in trodes:
            self.DmnCell[trode] = dae.daeDomain(
                "DmnCell_{trode}".format(trode=trode), self, dae.unit(),
                "Simulated volumes in electrode {trode}".format(trode=trode))
            self.DmnPart[trode] = dae.daeDomain(
                "Npart_{trode}".format(trode=trode), self, dae.unit(),
                "Particles sampled in each control " +
                "volume in electrode {trode}".format(trode=trode))

        # Variables
        self.c_lyte = {}
        self.phi_lyte = {}
        self.phi_bulk = {}
        self.phi_part = {}
        self.R_Vp = {}
        self.ffrac = {}
        for trode in trodes:
            # Concentration/potential in electrode regions of elyte
            self.c_lyte[trode] = dae.daeVariable(
                "c_lyte_{trode}".format(trode=trode), conc_t, self,
                "Concentration in the elyte in electrode {trode}".format(
                    trode=trode), [self.DmnCell[trode]])
            self.phi_lyte[trode] = dae.daeVariable(
                "phi_lyte_{trode}".format(trode=trode), elec_pot_t, self,
                "Electric potential in elyte in electrode {trode}".format(
                    trode=trode), [self.DmnCell[trode]])
            self.phi_bulk[trode] = dae.daeVariable(
                "phi_bulk_{trode}".format(trode=trode), elec_pot_t, self,
                "Electrostatic potential in the bulk solid",
                [self.DmnCell[trode]])
            self.phi_part[trode] = dae.daeVariable(
                "phi_part_{trode}".format(trode=trode), elec_pot_t, self,
                "Electrostatic potential at each particle",
                [self.DmnCell[trode], self.DmnPart[trode]])
            self.R_Vp[trode] = dae.daeVariable(
                "R_Vp_{trode}".format(trode=trode), dae.no_t, self,
                "Rate of reaction of positives per electrode volume",
                [self.DmnCell[trode]])
            self.ffrac[trode] = dae.daeVariable(
                "ffrac_{trode}".format(trode=trode), mole_frac_t, self,
                "Overall filling fraction of solids in electrodes")
        if Nvol["s"] >= 1:  # If we have a separator
            self.c_lyte["s"] = dae.daeVariable(
                "c_lyte_s", conc_t, self,
                "Concentration in the electrolyte in the separator",
                [self.DmnCell["s"]])
            self.phi_lyte["s"] = dae.daeVariable(
                "phi_lyte_s", elec_pot_t, self,
                "Electrostatic potential in electrolyte in separator",
                [self.DmnCell["s"]])
        # Note if we're doing a single electrode volume simulation
        # It will be in a perfect bath of electrolyte at the applied
        # potential.
        if Nvol["a"] == 0 and Nvol["s"] == 0 and Nvol["c"] == 1:
            self.SVsim = True
        else:
            self.SVsim = False
        if not self.SVsim:
            # Ghost points (GP) to aid in boundary condition (BC) implemenation
            self.c_lyteGP_L = dae.daeVariable("c_lyteGP_L", conc_t, self,
                                              "c_lyte left BC GP")
            self.phi_lyteGP_L = dae.daeVariable("phi_lyteGP_L", elec_pot_t,
                                                self, "phi_lyte left BC GP")
        self.phi_applied = dae.daeVariable(
            "phi_applied", elec_pot_t, self,
            "Overall battery voltage (at anode current collector)")
        self.phi_cell = dae.daeVariable(
            "phi_cell", elec_pot_t, self,
            "Voltage between electrodes (phi_applied less series resistance)")
        self.current = dae.daeVariable("current", dae.no_t, self,
                                       "Total current of the cell")
        self.endCondition = dae.daeVariable(
            "endCondition", dae.no_t, self,
            "A nonzero value halts the simulation")

        # Create models for representative particles within electrode
        # volumes and ports with which to talk to them.
        self.portsOutLyte = {}
        self.portsOutBulk = {}
        self.particles = {}
        for trode in trodes:
            Nv = Nvol[trode]
            Np = Npart[trode]
            self.portsOutLyte[trode] = np.empty(Nv, dtype=object)
            self.portsOutBulk[trode] = np.empty((Nv, Np), dtype=object)
            self.particles[trode] = np.empty((Nv, Np), dtype=object)
            for vInd in range(Nv):
                self.portsOutLyte[trode][vInd] = ports.portFromElyte(
                    "portTrode{trode}vol{vInd}".format(trode=trode, vInd=vInd),
                    dae.eOutletPort, self, "Electrolyte port to particles")
                for pInd in range(Np):
                    self.portsOutBulk[trode][vInd, pInd] = ports.portFromBulk(
                        "portTrode{trode}vol{vInd}part{pInd}".format(
                            trode=trode, vInd=vInd, pInd=pInd),
                        dae.eOutletPort, self,
                        "Bulk electrode port to particles")
                    solidType = ndD_e[trode]["indvPart"][vInd, pInd]['type']
                    if solidType in ndD_s["2varTypes"]:
                        pMod = mod_electrodes.Mod2var
                    elif solidType in ndD_s["1varTypes"]:
                        pMod = mod_electrodes.Mod1var
                    else:
                        raise NotImplementedError("unknown solid type")
                    self.particles[trode][vInd, pInd] = pMod(
                        "partTrode{trode}vol{vInd}part{pInd}".format(
                            trode=trode, vInd=vInd, pInd=pInd),
                        self,
                        ndD=ndD_e[trode]["indvPart"][vInd, pInd],
                        ndD_s=ndD_s)
                    self.ConnectPorts(
                        self.portsOutLyte[trode][vInd],
                        self.particles[trode][vInd, pInd].portInLyte)
                    self.ConnectPorts(
                        self.portsOutBulk[trode][vInd, pInd],
                        self.particles[trode][vInd, pInd].portInBulk)
    def __init__(self, Name, ninemlComponent, Parent = None, Description = ""):
        """
        Iterates over *Parameters*, *State variables*, *Aliases*, *Analogue ports*, *Event ports*, 
        *Sub-nodes* and *Port connections* and creates corresponding daetools objects.
        
        :param Name: string
        :param ninemlComponent: AL component object
        :param Parent: daeModel-derived object
        :param Description: string
            
        :raises: RuntimeError
        """
        #start = time()
        
        daet.daeModel.__init__(self, Name, Parent, Description)
        
        #print('    daeModel.__init__({0}) = {1}'.format(Name, time() - start))

        start = time()

        self.ninemlComponent        = ninemlComponent
        self.nineml_parameters      = []
        self.nineml_state_variables = []
        self.nineml_aliases         = []
        self.nineml_analog_ports    = []
        self.nineml_reduce_ports    = []
        self.nineml_event_ports     = []
        self.ninemlSubComponents    = []

        # AL component may be None (useful in certain cases); therefore do not raise an exception
        if not self.ninemlComponent:
            return
        
        # 1) Create parameters
        for param in self.ninemlComponent.parameters:
            self.nineml_parameters.append( daet.daeParameter(param.name, daet.unit(), self, "") )

        # 2) Create state-variables (diff. variables)
        for var in self.ninemlComponent.state_variables:
            self.nineml_state_variables.append( daet.daeVariable(var.name, dae_nineml_t, self, "") )

        # 3) Create alias variables (algebraic)
        for alias in self.ninemlComponent.aliases:
            self.nineml_aliases.append( daet.daeVariable(alias.lhs, dae_nineml_t, self, "") )

        # 4) Create analog-ports and reduce-ports
        for analog_port in self.ninemlComponent.analog_ports:
            if analog_port.mode == 'send':
                self.nineml_analog_ports.append( ninemlAnalogPort(analog_port.name, daet.eOutletPort, self, "") )
            elif analog_port.mode == 'recv':
                self.nineml_analog_ports.append( ninemlAnalogPort(analog_port.name, daet.eInletPort, self, "") )
            elif analog_port.mode == 'reduce':
                self.nineml_reduce_ports.append( ninemlReduceAnalogPort(analog_port.name, self) )
            else:
                raise RuntimeError("")

        # 5) Create event-ports
        for event_port in self.ninemlComponent.event_ports:
            if event_port.mode == 'send':
                self.nineml_event_ports.append( daet.daeEventPort(event_port.name, daet.eOutletPort, self, "") )
            elif event_port.mode == 'recv':
                self.nineml_event_ports.append( daet.daeEventPort(event_port.name, daet.eInletPort, self, "") )
            else:
                raise RuntimeError("")

        # 6) Create sub-nodes
        for name, subcomponent in list(self.ninemlComponent.subnodes.items()):
            self.ninemlSubComponents.append( nineml_daetools_bridge(name, subcomponent, self, '') )

        # 7) Create port connections
        for port_connection in self.ninemlComponent.portconnections:
            #print 'try to connect {0} to {1}'.format(port_connection[0].getstr('.'), port_connection[1].getstr('.'))
            portFrom = getObjectFromNamespaceAddress(self, port_connection[0], look_for_ports = True, look_for_reduceports = True)
            portTo   = getObjectFromNamespaceAddress(self, port_connection[1], look_for_ports = True, look_for_reduceports = True)
            #print '  {0} -> {1}\n'.format(type(portFrom), type(portTo))
            connectPorts(portFrom, portTo, self)
Example #12
0
 def __init__(self, Name, PortType, Model, Description=""):
     dae.daePort.__init__(self, Name, PortType, Model, Description)
     self.phi_m = dae.daeVariable(
         "phi_m", elec_pot_t, self,
         "Electric potential in the e- conducting phase")
Example #13
0
    def __init__(self, Name, ninemlComponent, Parent=None, Description=""):
        """
        Iterates over *Parameters*, *State variables*, *Aliases*, *Analogue ports*, *Event ports*, 
        *Sub-nodes* and *Port connections* and creates corresponding daetools objects.
        
        :param Name: string
        :param ninemlComponent: AL component object
        :param Parent: daeModel-derived object
        :param Description: string
            
        :raises: RuntimeError
        """
        #start = time()

        daet.daeModel.__init__(self, Name, Parent, Description)

        #print('    daeModel.__init__({0}) = {1}'.format(Name, time() - start))

        start = time()

        self.ninemlComponent = ninemlComponent
        self.nineml_parameters = []
        self.nineml_state_variables = []
        self.nineml_aliases = []
        self.nineml_analog_ports = []
        self.nineml_reduce_ports = []
        self.nineml_event_ports = []
        self.ninemlSubComponents = []

        # AL component may be None (useful in certain cases); therefore do not raise an exception
        if not self.ninemlComponent:
            return

        # 1) Create parameters
        for param in self.ninemlComponent.parameters:
            self.nineml_parameters.append(
                daet.daeParameter(param.name, daet.unit(), self, ""))

        # 2) Create state-variables (diff. variables)
        for var in self.ninemlComponent.state_variables:
            self.nineml_state_variables.append(
                daet.daeVariable(var.name, dae_nineml_t, self, ""))

        # 3) Create alias variables (algebraic)
        for alias in self.ninemlComponent.aliases:
            self.nineml_aliases.append(
                daet.daeVariable(alias.lhs, dae_nineml_t, self, ""))

        # 4) Create analog-ports and reduce-ports
        for analog_port in self.ninemlComponent.analog_ports:
            if analog_port.mode == 'send':
                self.nineml_analog_ports.append(
                    ninemlAnalogPort(analog_port.name, daet.eOutletPort, self,
                                     ""))
            elif analog_port.mode == 'recv':
                self.nineml_analog_ports.append(
                    ninemlAnalogPort(analog_port.name, daet.eInletPort, self,
                                     ""))
            elif analog_port.mode == 'reduce':
                self.nineml_reduce_ports.append(
                    ninemlReduceAnalogPort(analog_port.name, self))
            else:
                raise RuntimeError("")

        # 5) Create event-ports
        for event_port in self.ninemlComponent.event_ports:
            if event_port.mode == 'send':
                self.nineml_event_ports.append(
                    daet.daeEventPort(event_port.name, daet.eOutletPort, self,
                                      ""))
            elif event_port.mode == 'recv':
                self.nineml_event_ports.append(
                    daet.daeEventPort(event_port.name, daet.eInletPort, self,
                                      ""))
            else:
                raise RuntimeError("")

        # 6) Create sub-nodes
        for name, subcomponent in list(self.ninemlComponent.subnodes.items()):
            self.ninemlSubComponents.append(
                nineml_daetools_bridge(name, subcomponent, self, ''))

        # 7) Create port connections
        for port_connection in self.ninemlComponent.portconnections:
            #print 'try to connect {0} to {1}'.format(port_connection[0].getstr('.'), port_connection[1].getstr('.'))
            portFrom = getObjectFromNamespaceAddress(self,
                                                     port_connection[0],
                                                     look_for_ports=True,
                                                     look_for_reduceports=True)
            portTo = getObjectFromNamespaceAddress(self,
                                                   port_connection[1],
                                                   look_for_ports=True,
                                                   look_for_reduceports=True)
            #print '  {0} -> {1}\n'.format(type(portFrom), type(portTo))
            connectPorts(portFrom, portTo, self)