示例#1
0
    def checkEvents(self, maxevtpts, eventActive, eventDir, eventTerm,
                    eventInt, eventDelay, eventTol, maxbisect, eventNearCoef):

        if not self.initBasic:
            raise InitError('You must initialize the integrator before ' + \
                            'checking events. (initBasic)')

        verify_nonneg('maxevtpts', maxevtpts, _all_int)

        list_len_val = (self.nEvents, 'nEvents')

        verify_intbool('eventActive', eventActive,
                      list_ok=True, list_len=list_len_val)

        verify_values('eventDir', eventDir, [-1, 0, 1], list_ok=True,
                      list_len=list_len_val)

        verify_intbool('eventTerm', eventTerm,
                       list_ok=True, list_len=list_len_val)

        verify_nonneg('eventInt', eventInt, _real_types,
                      list_ok=True, list_len=list_len_val)

        verify_nonneg('eventDelay', eventDelay, _real_types,
                      list_ok=True, list_len=(self.nEvents, 'nEvents'))

        verify_pos('eventTol', eventTol, _real_types,
                   list_ok=True, list_len=list_len_val)

        verify_nonneg('maxbisect', maxbisect, _all_int,
                      list_ok=True, list_len=list_len_val)

        verify_pos('eventNearCoef', eventNearCoef, _real_types)
示例#2
0
 def checkBasic(self, rhs, phaseDim, paramDim, nAux, nEvents, nExtInputs,
                hasJac, hasJacP, hasMass, extraSpace):
     # Check that inputs to this function are correct
     try:
         if not isinstance(rhs, str):
             raise TypeError("right hand side rhs must be a string")
         verify_nonneg('phaseDim', phaseDim, _all_int)
         verify_nonneg('paramDim', paramDim, _all_int)
         verify_intbool('hasJac', hasJac)
         verify_intbool('hasJacP', hasJacP)
         verify_intbool('hasMass', hasMass)
         verify_nonneg('nAux', nAux, _all_int)
         verify_nonneg('nEvents', nEvents, _all_int)
         verify_nonneg('nExtInputs', nExtInputs, _all_int)
         verify_nonneg('extraSpace', extraSpace, _all_int)
     except:
         print sys.exc_info()[0], sys.exc_info()[1]
         raise InitError('Integrator initialization failed!')
示例#3
0
    def checkRunParams(self, ic, params, t0, tend, gt0, refine, specTimes,
                       bounds):
        if not self.initBasic:
            raise InitError('You must initialize the integrator before checking run params. (initBasic)')

        if not isinstance(ic, list):
            raise TypeError("ic must be list")
        if len(ic) != self.phaseDim:
            print "IC length %i didn't match phaseDim %i"%(len(ic), self.phaseDim), ic
            raise ValueError('ic must have length equal to phaseDim')
        for x in ic:
            if not isinstance(x, _real_types):
                raise TypeError("ic entries must be real values")

        if not isinstance(params, list):
            raise TypeError("params must be list")
        if len(params) != self.paramDim:
            raise ValueError("params must have length equal to phaseDim")
        if len(params) > 0:
            for x in params:
                if not isinstance(x, _real_types):
                    raise TypeError("params entries must be real values")

        verify_nonneg('refine', refine, _all_int)

        if not isinstance(t0, _real_types):
            raise TypeError("t0 must be real valued")
        if not isinstance(tend, _real_types):
            raise TypeError("tend must be real valued")
        if t0 == tend:
            raise ValueError("t0 must differ from tend")
        if t0 < tend:
            direction = 1
        else:
            direction = -1

        try:
            specTimes = list(specTimes)
        except:
            raise TypeError("specTimes must be a sequence type")
        if len(specTimes) > 0:
            if not isinstance(specTimes[0], _real_types):
                raise TypeError("specTimes entries must be real valued")
            if direction == 1:
                if specTimes[0] < t0 or specTimes[0] > tend:
                    raise ValueError("specTimes entries must be within [%.8f,%.8f]"%(t0,tend))
            else:
                if specTimes[0] > t0 or specTimes[0] < tend:
                    raise ValueError("specTimes entries must be within [%.8f,%.8f]"%(tend,t0))

        if len(specTimes) > 1:
            for x in range(len(specTimes)-1):
                if not isinstance(specTimes[x], _real_types):
                    raise TypeError("specTimes entries must be real valued")
            if direction == 1:
                if specTimes[x] < t0 or specTimes[x] > tend:
                    raise ValueError("specTimes entries must be within [%.8f,%.8f]"%(t0,tend))
                if specTimes[x] > specTimes[x+1]:
                    raise ValueError("specTimes must be non-decreasing")
            else:
                if specTimes[x] > t0 or specTimes[x] < tend:
                    raise ValueError("specTimes entries must be within [%.8f,%.8f]"%(tend,t0))
                if specTimes[x] < specTimes[x+1]:
                    raise ValueError("specTimes must be non-increasing")


        # Check the parameter, phase space bounds
        if not isinstance(bounds, list):
            raise TypeError("bounds must be list")
        if bounds != []:
            if len(bounds) != 2:
                raise TypeError("non-empty bounds must be a 2-list")
            for i in range(2):
                if type(bounds[i]) is not list:
                    raise TypeError("non-empty bounds must be a 2-list")
                if len(bounds[i]) != self.phaseDim + self.paramDim:
                    raise ValueError("bounds have incorrect size")
                for j in range(self.phaseDim + self.paramDim):
                    if not isinstance(bounds[i][j], _real_types):
                        raise TypeError("bounds entries must be real valued")