Пример #1
0

    def AuxVars(self, t, xdict, pdict=None, asarray=True):
        """asarray is an unused, dummy argument for compatibility with
        Model.AuxVars"""
        # also, ensure xdict doesn't contain elements like array([4.1]) instead of 4
        x = [float(val) for val in sortedDictValues(filteredDict(self._FScompatibleNames(xdict),
                                                                 self.funcspec.vars))]
        if pdict is None:
            pdict = self.pars
            # internal self.pars already is FS-compatible
            p = sortedDictValues(pdict)
        else:
            p = sortedDictValues(self._FScompatibleNames(pdict))
        i = _pollInputs(sortedDictValues(self.inputs),
                        t, self.checklevel)
        return apply(getattr(self, self.funcspec.auxspec[1]), [t, x, p+i])


    def __del__(self):
        ODEsystem.__del__(self)



# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(Vode_ODEsystem, symbolMapDict, 'python')
Пример #2
0
            raise IOError, e

        # Write the vfield.m file
#        vfdefines = self._prepareVfieldDefines()
#        allfilestr = self._prepareVfieldContents(vfdefines)
        allfilestr = self.funcspec.spec[0] + self._prepareAuxContents()
        vffile = os.path.join(self._target_dir, self._vfield_file)
        try:
            file = open(vffile, 'w')
            file.write(allfilestr)
            file.close()
        except IOError, e:
            print "Error opening file "+self._vfield_file+" for writing"
            raise IOError, e


    # We have omitted methods: RHS, compute, etc. because this
    # class is intended solely to generate code for ADMC++, not do any integrations
    # etc.

    def __del__(self):
        ODEsystem.__del__(self)


# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(ADMC_ODEsystem, symbolMapDict, 'matlab')
Пример #3
0
            i = sortedDictValues(dict([(n, i(t)) for n, i in self.inputs.iteritems()]))
            return apply(eval("self." + self.funcspec.auxfns["Jacobian"][1]), [t, x, p + i])
        else:
            raise PyDSTool_ExistError, "Jacobian not defined"

    def JacobianP(self, t, xdict, pdict):
        if self.haveJacobian_pars():
            x = sortedDictValues(xdict)
            p = sortedDictValues(pdict)
            i = sortedDictValues(dict([(n, i(t)) for n, i in self.inputs.iteritems()]))
            return apply(eval("self." + self.funcspec.auxfns["Jacobian_pars"][1]), [t, x, p + i])
        else:
            raise PyDSTool_ExistError, "Jacobian w.r.t. parameters not defined"

    def AuxVars(self, t, xdict, pdict):
        x = sortedDictValues(xdict)
        p = sortedDictValues(pdict)
        i = sortedDictValues(dict([(n, i(t)) for n, i in self.inputs.iteritems()]))
        return apply(eval("self." + self.funcspec.auxspec[1]), [t, x, p + i])

    def __del__(self):
        discGen.__del__(self)


# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(MapSystem, symbolMapDict, "python")
Пример #4
0
        self.validateSpec()
        self.defined = True

    def compute(self, trajname):
        return Trajectory(trajname, [copy(v) for v in self.variables.values()],
                          self.globalt0, self.checklevel)

    computeTraj = compute

    def validateSpec(self):
        ctsGen.validateSpec(self)
        try:
            assert isoutputcts(self.indepvariable)
            for v in self.variables.values():
                assert isinstance(v, Variable)
            assert not self.inputs
        except AssertionError:
            print 'Invalid system specification'
            raise

    def __del__(self):
        ctsGen.__del__(self)


# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(InterpolateTable, symbolMapDict, 'python')
Пример #5
0
        if self.defined:
            self.validateSpec()
            self.clearWarnings()
            self.clearErrors()
        return Trajectory(trajname, [copy(v) for v in self.variables.values()],
                          self.globalt0, self.checklevel)

    computeTraj = compute

    def validateSpec(self):
        discGen.validateSpec(self)
        try:
            assert isoutputdiscrete(self.indepvariable)
            for v in self.variables.values():
                assert isinstance(v, Variable)
            assert not self.inputs
        except AssertionError:
            print 'Invalid system specification'
            raise

    def __del__(self):
        discGen.__del__(self)


# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(LookupTable, symbolMapDict, 'python')
            # pass up to generic treatment for this
            ctsGen.set(self, checklevel=kw['checklevel'])
        if 'globalt0' in kw:
            # pass up to generic treatment for this
            ctsGen.set(self, globalt0=kw['globalt0'])

    def validateSpec(self):
        ctsGen.validateSpec(self)
        try:
            assert isoutputcts(self.indepvariable)
            for v in self.variables.values():
                assert isinstance(v, Variable)
            assert not self.inputs
        except AssertionError:
            print 'Invalid system specification'
            raise


    def __del__(self):
        ctsGen.__del__(self)




# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(InterpolateTable, symbolMapDict, 'python')
Пример #7
0
                                                               ' at bound')
                        else:
                            raise PyDSTool_ValueError('Parameter value out of'
                                                      ' bounds')
                else:
                    raise PyDSTool_AttributeError('Illegal parameter name')


    def validateSpec(self):
        ctsGen.validateSpec(self)
        try:
            for v in self.variables.values():
                assert isinstance(v, Variable)
            assert not self.inputs
        except AssertionError:
            print 'Invalid system specification'
            raise


    def __del__(self):
        ctsGen.__del__(self)



# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(EmbeddedSysGen, symbolMapDict, 'python', None)
Пример #8
0
            for k, v in kw['algparams'].iteritems():
                self.algparams[k] = v
        if 'solvemethod' in self.algparams:
            if self.algparams['solvemethod'] not in _implicitSolveMethods:
                raise PyDSTool_ValueError('Invalid implicit solver type')


    def validateSpec(self):
        ctsGen.validateSpec(self)
        try:
            for v in self.variables.values():
                assert isinstance(v, Variable)
            assert not self.inputs
        except AssertionError:
            print 'Invalid system specification'
            raise


    def __del__(self):
        ctsGen.__del__(self)




# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(ImplicitFnGen, symbolMapDict, 'python', 'ImpFuncSpec')
            # pass up to generic treatment for this
            ctsGen.set(self, checklevel=kw['checklevel'])
        if 'globalt0' in kw:
            # pass up to generic treatment for this
            ctsGen.set(self, globalt0=kw['globalt0'])

    def validateSpec(self):
        ctsGen.validateSpec(self)
        try:
            assert isoutputcts(self.indepvariable)
            for v in self.variables.values():
                assert isinstance(v, Variable)
            assert not self.inputs
        except AssertionError:
            print 'Invalid system specification'
            raise


    def __del__(self):
        ctsGen.__del__(self)




# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(ExtrapolateTable, symbolMapDict, 'python')
Пример #10
0
                          checklevel=self.checklevel,
                          FScompatibleNames=self._FScompatibleNames,
                          FScompatibleNamesInv=self._FScompatibleNamesInv,
                          modelNames=self.name,
                          modelEventStructs=self.eventstruct)

    def validateSpec(self):
        discGen.validateSpec(self)
        try:
            assert isoutputdiscrete(self.indepvariable)
            for v in self.variables.values():
                assert isinstance(v, Variable)
            assert not self.inputs
        except AssertionError:
            print 'Invalid system specification'
            raise


    def __del__(self):
        discGen.__del__(self)




# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(LookupTable, symbolMapDict, 'python')
Пример #11
0
        if 'algparams' in kw:
            for k, v in kw['algparams'].iteritems():
                self._algparams[k] = v
        if 'solvemethod' in self._algparams:
            if self._algparams['solvemethod'] not in _implicitSolveMethods:
                raise PyDSTool_ValueError, 'Invalid implicit solver type'

    # for backwards compatibility
    setPars = set

    def validateSpec(self):
        ctsGen.validateSpec(self)
        try:
            for v in self.variables.values():
                assert isinstance(v, Variable)
            assert not self.inputs
        except AssertionError:
            print 'Invalid system specification'
            raise

    def __del__(self):
        ctsGen.__del__(self)


# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(ImplicitFnGen, symbolMapDict, 'python', 'ImpFuncSpec')
Пример #12
0
    def JacobianP(self, t, xdict, pdict):
        if self.haveJacobian_pars():
            x = sortedDictValues(xdict)
            p = sortedDictValues(pdict)
            i = sortedDictValues(dict([(n,i(t)) for n,i in self.inputs.iteritems()]))
            return apply(eval("self."+self.funcspec.auxfns["Jacobian_pars"][1]), \
                        [t, x, p+i])
        else:
            raise PyDSTool_ExistError, "Jacobian w.r.t. parameters not defined"


    def AuxVars(self, t, xdict, pdict):
        x = sortedDictValues(xdict)
        p = sortedDictValues(pdict)
        i = sortedDictValues(dict([(n,i(t)) for n,i in self.inputs.iteritems()]))
        return apply(eval("self."+self.funcspec.auxspec[1]), [t, x, p+i])


    def __del__(self):
        discGen.__del__(self)



# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(MapSystem, symbolMapDict, 'python')
Пример #13
0
def _pollInputs(inputVarList, t, checklevel):
    ilist = []
    try:
        for f in inputVarList:
            f.clearWarnings
            ilist.append(f(t, checklevel))
    except AssertionError:
        print 'External input call has t out of range: t = ', t
        print 'Maybe checklevel is 3 and initial time is not', \
                    'completely inside valid time interval'
        raise
    except ValueError:
        print 'External input call has value out of range: t = ', t
        print 'Check beginning and end time of integration'
        for f in inputVarList:
            if len(f.warnings):
                print 'External input %s out of range:' % f.name
                print '   t = ', repr(f.warnings[-1][0]), ', ', \
                      f.name, ' = ', repr(f.warnings[-1][1])
        raise
    return ilist


# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(Vode_ODEsystem, symbolMapDict, 'python')
Пример #14
0
            raise PyDSTool_ExistError("Jacobian w.r.t. parameters not defined")


    def AuxVars(self, t, xdict, pdict=None, asarray=True):
        """asarray is an unused, dummy argument for compatibility with
        Model.AuxVars"""
        x = [float(val) for val in sortedDictValues(filteredDict(self._FScompatibleNames(xdict),
                                                                 self.funcspec.vars))]
        if pdict is None:
            pdict = self.pars
            # internal self.pars already is FS-compatible
            p = sortedDictValues(pdict)
        else:
            p = sortedDictValues(self._FScompatibleNames(pdict))
        i = _pollInputs(sortedDictValues(self.inputs),
                        t, self.checklevel)
        return apply(getattr(self,self.funcspec.auxspec[1]), [t, x, p+i])


    def __del__(self):
        discGen.__del__(self)



# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(MapSystem, symbolMapDict, 'python')
Пример #15
0
            print "Error opening file " + self._set_file + " for writing"
            raise IOError, e

        # Write the vfield.m file
#        vfdefines = self._prepareVfieldDefines()
#        allfilestr = self._prepareVfieldContents(vfdefines)
        allfilestr = self.funcspec.spec[0] + self._prepareAuxContents()
        vffile = os.path.join(self._target_dir, self._vfield_file)
        try:
            file = open(vffile, 'w')
            file.write(allfilestr)
            file.close()
        except IOError, e:
            print "Error opening file " + self._vfield_file + " for writing"
            raise IOError, e

    # We have omitted RHS, computeTraj, etc. because this
    # class is intended solely to generate code for ADMC++, not do any integrations
    # etc.

    def __del__(self):
        ODEsystem.__del__(self)


# Register this Generator with the database

symbolMapDict = {}
# in future, provide appropriate mappings for libraries math,
# random, etc. (for now it's left to FuncSpec)
theGenSpecHelper.add(ADMC_ODEsystem, symbolMapDict, 'matlab')