Regimes in Dynamics definitions

This example introduces the Regime, Transition and OnEntry elements within a Dynamics block. Rather than having a single state instance, the entity can be on one of the defined regimes at any given time. The Transition element occurring inside a condition block serves to move it from one regime to another. The OnEntry block inside a regime can contain initialization directives that apply each time the entity enters that regime.

<ComponentType name="refractiaf">     
   <Parameter name="threshold" dimension="voltage" />     
   <Parameter name="refractoryPeriod" dimension="time" />     
   <Parameter name="capacitance" dimension="capacitance" />     
   <Parameter name="vleak" dimension="voltage" />     
   <Parameter name="gleak" dimension="conductance" />          
   <Parameter name="current" dimension="current" />     
   <Parameter name="vreset" dimension="voltage" />     
   <Parameter name="deltaV" dimension="voltage" />     
   <Parameter name="v0" dimension="voltage" />             
   <EventPort name="out" direction="out" />     
   <EventPort name="in" direction="in" />   
   <Dynamics>    
      <StateVariable name="v" dimension="voltage" />            
      <OnStart>     
         <StateAssignment variable="v" value="v0" />    
      </OnStart>         
      <Regime name="refr">                
         <StateVariable name="tin" dimension="time" />       
         <OnEntry>                       
            <StateAssignment variable="tin" value="t" />                       
            <StateAssignment variable="v" value="vreset" />                 
         </OnEntry>                          
         <OnCondition test="t .gt. tin + refractoryPeriod">                            
            <Transition regime="int" />                    
         </OnCondition>             
      </Regime>                  
      <Regime name="int" initial="true">                
         <TimeDerivative variable="v" value="(current + gleak * (vleak - v)) / capacitance" />                
         <OnCondition test="v .gt. threshold">                       
            <EventOut port="out" />                       
            <Transition regime="refr" />                
         </OnCondition>                
         <OnEvent port="in">         
            <StateAssignment variable="v" value="v + deltaV" />       
         </OnEvent>        
      </Regime>
   </Dynamics>
</ComponentType>

Full listing:

example8.xml (xml)
<Lems>  
   <Target component="simset" />       
   <Include file="ex2dims.xml" />
   <Include file="spikegenerators.xml" />
   <Include file="misciaf.xml" />
   <ComponentType name="refractiaf">     
      <Parameter name="threshold" dimension="voltage" />     
      <Parameter name="refractoryPeriod" dimension="time" />     
      <Parameter name="capacitance" dimension="capacitance" />     
      <Parameter name="vleak" dimension="voltage" />     
      <Parameter name="gleak" dimension="conductance" />          
      <Parameter name="current" dimension="current" />     
      <Parameter name="vreset" dimension="voltage" />     
      <Parameter name="deltaV" dimension="voltage" />     
      <Parameter name="v0" dimension="voltage" />             
      <EventPort name="out" direction="out" />     
      <EventPort name="in" direction="in" />          
      <Exposure name="v" dimension="voltage" />   
      <Dynamics>         
         <StateVariable name="v" exposure="v" dimension="voltage" />            
         <OnStart>     
            <StateAssignment variable="v" value="v0" />    
         </OnStart>         
         <Regime name="refr">                
            <StateVariable name="tin" dimension="time" />       
            <OnEntry>                       
               <StateAssignment variable="tin" value="t" />                       
               <StateAssignment variable="v" value="vreset" />                 
            </OnEntry>                          
            <OnCondition test="t .gt. tin + refractoryPeriod">                            
               <Transition regime="int" />                    
            </OnCondition>             
         </Regime>                  
         <Regime name="int" initial="true">                
            <TimeDerivative variable="v" value="(current + gleak * (vleak - v)) / capacitance" />                
            <OnCondition test="v .gt. threshold">                       
               <EventOut port="out" />                       
               <Transition regime="refr" />                
            </OnCondition>                
            <OnEvent port="in">         
               <StateAssignment variable="v" value="v + deltaV" />       
            </OnEvent>        
         </Regime>
      </Dynamics>
   </ComponentType>  

   <Component id="gen1" type="spikeGenerator" period="7ms" />  

   <Component id="multiregime" type="refractiaf" threshold="-50mV" v0="-80mV" refractoryPeriod="20ms" capacitance="1pF" vreset="-80mV" vleak="-90mV" gleak="5pS" current="0.00001nA" deltaV="5mV" />    
   <ComponentType name="Network">     
      <Children name="populations" type="Population" />     
      <Children name="connectivities" type="EventConnectivity" />
   </ComponentType>
   <ComponentType name="Population">     
      <ComponentReference name="component" type="Component" />     
      <Parameter name="size" dimension="none" />   
      <Structure>             
         <MultiInstantiate number="size" component="component" />
      </Structure>
   </ComponentType>
   <ComponentType name="EventConnectivity">     
      <Link name="source" type="Population" />     
      <Link name="target" type="Population" />     
      <Child name="Connections" type="ConnectionPattern" />
   </ComponentType>
   <ComponentType name="ConnectionPattern" />
   <ComponentType name="AllAll" extends="ConnectionPattern">     
      <Structure>             
         <ForEach instances="../source" as="a">                  
            <ForEach instances="../target" as="b">                       
               <EventConnection from="a" to="b" />                  
            </ForEach>             
         </ForEach>         
      </Structure>      
   </ComponentType>

   <Network id="net1">     
      <Population id="p1" component="gen1" size="1" />     
      <Population id="p3" component="multiregime" size="2" />           
      <EventConnectivity id="p1-p3" source="p1" target="p3">         
         <Connections type="AllAll" />     
      </EventConnectivity>
   </Network>
   <Include file="MultiRunSimulation.xml" />  
   <SimulationSet id="simset">
      <Display id="disp1" title="Example 8: Regimes in dynamics definitions" xmin="0" xmax="80" ymin="-80" ymax="50" />  

      <Simulation id="sim1" length="80ms" step="0.05ms" target="net1" display="disp1">  
         <DisplayList timeScale="1ms" title="">          
            <Line id="gen_vmr" quantity="p3[0]/v" scale="1mV" timeScale="1ms" color="#00c000" />             
            <Line id="gen_sv" quantity="p1[0]/tsince" scale="1ms" timeScale="1ms" color="#f00000" />              
         </DisplayList>     
      </Simulation>
   </SimulationSet>    
</Lems>