Example #1
0
    def spiceLineForConnections(self, compartment):
        """Add a connection between two compartments
        """

        def spiceLine( src, tgt):
            # Write a line for connections.
            spiceLine = 'V{name} {src} {tgt} dc 0'.format(
                    name = self.moosePathToSpiceNode( src+tgt )
                    , src = self.toSpiceNode( src, 'out1' )
                    , tgt = self.toSpiceNode( tgt, 'in1' )
                    )
            return spiceLine

        compPath = compartment.path 
        raxials = compartment.neighbors['raxial']
        axials = compartment.neighbors['axial']

        raxialsPath = [ idPathToObjPath( p.path ) for p in raxials ]
        axialsPath = [ idPathToObjPath( p.path ) for p in axials ]

        for rpath in raxialsPath:
            if (compPath, rpath) not in self.connections:
                self.connections.add( (compPath, rpath) )
                spiceLine = spiceLine( compPath, rpath)
                self.spiceText.append( spiceLine )
            else:               # This connection is already added.
                pass

        for apath in axialsPath:
            if (apath, compPath) not in self.connections:
                self.connections.add( (apath, compPath) )
                spiceLine =  spiceLine( apath, compPath )
                self.spiceText.append( spiceLine )
            else:
                pass
Example #2
0
    def spiceLineForConnections(self, compartment):
        """Add a connection between two compartments
        """
        def spiceLine(src, tgt):
            # Write a line for connections.
            spiceLine = 'V{name} {src} {tgt} dc 0'.format(
                name=self.moosePathToSpiceNode(src + tgt),
                src=self.toSpiceNode(src, 'out1'),
                tgt=self.toSpiceNode(tgt, 'in1'))
            return spiceLine

        compPath = compartment.path
        raxials = compartment.neighbors['raxial']
        axials = compartment.neighbors['axial']

        raxialsPath = [idPathToObjPath(p.path) for p in raxials]
        axialsPath = [idPathToObjPath(p.path) for p in axials]

        for rpath in raxialsPath:
            if (compPath, rpath) not in self.connections:
                self.connections.add((compPath, rpath))
                spiceLine = spiceLine(compPath, rpath)
                self.spiceText.append(spiceLine)
            else:  # This connection is already added.
                pass

        for apath in axialsPath:
            if (apath, compPath) not in self.connections:
                self.connections.add((apath, compPath))
                spiceLine = spiceLine(apath, compPath)
                self.spiceText.append(spiceLine)
            else:
                pass
Example #3
0
    def spiceLineForPulseGen(self, pulseGen):
        """Write spice-line for pulse """
        pulsePath = idPathToObjPath(pulseGen.path)
        pulseName = self.moosePathToSpiceNode(pulsePath)

        td1 = pulseGen.delay[0]
        td2 = pulseGen.delay[1]
        width = pulseGen.width[0]
        level1 = 0.0
        level2 = pulseGen.level[0]

        targets = pulseGen.neighbors['output']
        if not targets:
            debug.dump("WARN",
                       "It seems that pulse `%s` is not connected" % pulsePath)
        for i, t in enumerate(targets):
            spiceLine = "* Fist node is where current enters. A voltage \n"
            spiceLine += "* source is added in series. Useful for reading current\n"
            vtarget = self.toSpiceNode('%s%s' % (pulseName, i), 'x')
            target = self.toSpiceNode(t.path, 'inject')
            spiceLine += 'I{id}{name} GND {vtarget} dc 0 PULSE'.format(
                id=i, name=pulseName, vtarget=vtarget)
            spiceLine += '({level1} {level2} {TD} {TR} {TF} {PW} {PER})'.format(
                level1=level1,
                level2=level2,
                TD=td1,
                TR=0.0,
                TF=0.0,
                PW=width,
                PER=td1 + td2 + width)
            self.spiceText.append(spiceLine)
            # A a voltage source in series
            self.spiceText.append("V{id}{name} {vtarget} {target} dc 0".format(
                id=i, name=pulseName, vtarget=vtarget, target=target))
Example #4
0
    def toSpiceNode(self, moosePath, type):
        """Return spice node name for a given moose-path """
        goodTypes = ["in1", "out1", "inject", 'x']
        if type not in goodTypes:
            debug.dump("ERROR",
                       "Bad node type: Expecting {}".format(goodTypes))
            raise TypeError("Expecting {}, got {}".format(goodTypes, type))

        moosePath = idPathToObjPath(moosePath)
        name = self.moosePathToSpiceNode(moosePath)
        return 'n{}{}'.format(name, type)
Example #5
0
    def toSpiceNode(self, moosePath, type):
        """Return spice node name for a given moose-path """
        goodTypes = ["in1", "out1", "inject", 'x']
        if type not in goodTypes:
            debug.dump("ERROR"
                    , "Bad node type: Expecting {}".format(goodTypes)
                    )
            raise TypeError("Expecting {}, got {}".format(goodTypes, type))

        moosePath = idPathToObjPath( moosePath )
        name = self.moosePathToSpiceNode( moosePath )
        return 'n{}{}'.format(name, type)
Example #6
0
    def spiceLineForPulseGen(self, pulseGen):
        """Write spice-line for pulse """
        pulsePath = idPathToObjPath( pulseGen.path )
        pulseName = self.moosePathToSpiceNode( pulsePath )

        td1 = pulseGen.delay[0]
        td2 = pulseGen.delay[1]
        width = pulseGen.width[0]
        level1 = 0.0
        level2 = pulseGen.level[0]
    
        targets = pulseGen.neighbors['output']
        if not targets:
            debug.dump("WARN"
                    , "It seems that pulse `%s` is not connected" % pulsePath
                    )
        for i, t in enumerate(targets):
            spiceLine = "* Fist node is where current enters. A voltage \n"
            spiceLine += "* source is added in series. Useful for reading current\n"
            vtarget = self.toSpiceNode('%s%s'%(pulseName, i), 'x')
            target = self.toSpiceNode( t.path, 'inject' )
            spiceLine += 'I{id}{name} GND {vtarget} dc 0 PULSE'.format(
                    id = i
                    , name = pulseName 
                    , vtarget = vtarget
                    )
            spiceLine += '({level1} {level2} {TD} {TR} {TF} {PW} {PER})'.format(
                    level1 = level1
                    , level2 = level2 
                    , TD = td1
                    , TR = 0.0
                    , TF = 0.0
                    , PW = width 
                    , PER = td1 + td2 + width
                    )
            self.spiceText.append(spiceLine)
            # A a voltage source in series
            self.spiceText.append(
                    "V{id}{name} {vtarget} {target} dc 0".format(
                        id = i
                        , name = pulseName
                        , vtarget = vtarget
                        , target = target
                        )
                    )