src/MOIRA.py
def modified_equation(self, nterms):
        '''
        Computes the values of the modified equation coefficients a_{ijk} where i, j and k represent
        the order of derivatives in the <indep var1\> , <indep var2\>, and <indep var3\> directions, respectively. These are written as
        a_ijk * u_{ijk}.

        Parameters:
            nterms (int):Number of terms to compute in the modified equation

        Returns:
             bool: true if finished without error, false otherwise

        Examples:
            >>> <DE>.modified_equation(nterms=2)
        '''
        try:
            A = symbols('A')
            # compute the amplification factor
            lhs1 = simplify(self.lhs / self.function(self.t['index'], **self.indicies))
            rhs1 = simplify(self.rhs / self.function(self.t['index'], **self.indicies))
            eq = lhs1 - rhs1
            eq = eq.subs(exp(self.t['ampFactor'] * self.t['variation']), A)
            eq = eq.subs(exp(self.t['variation'] * self.t['ampFactor']), A)
            eq = expand(eq)
            eq = collect(eq, A)
            logEqdt = simplify(solve(eq, A)[0])
            q =  log(logEqdt) / self.t['variation']  # amplification factor
            couples = [i for i in product(list(range(0, nterms + 1)), repeat=len(self.__independentVars)) if
                       (sum(i) <= nterms and sum(i) > 0)]

            coefs = {}
            derivs = {}
            for couple in couples:
                wrt_vars = []
                wrt_wave_num = []
                waveNum = {}
                fac = 1
                N = 0
                ies = ''

                for num, var in enumerate(self.__independentVars):
                    wrt_wave_num.append(self.vars[var]['waveNum'])
                    waveNum[self.vars[var]['waveNum']] = 0
                    wrt_wave_num.append(couple[num])
                    wrt_vars.append(self.vars[var]['sym'])
                    wrt_vars.append(couple[num])
                    N = sum(couple)
                    fac *= factorial(couple[num])
                    ies += str(couple[num])

                diff_ = diff(q, *wrt_wave_num).subs(waveNum)
                frac = ratsimp(1 / (fac * I ** N))
                coefficient = simplify(frac * diff_)
                if coefficient != 0:
                    coefs['a{}'.format(ies)] = nsimplify(coefficient)
                    derivs['a{}'.format(ies)] = Derivative(self.dependentVar, *wrt_vars)

            me_lhs = Derivative(self.dependentVar, self.t['sym'], 1)
            me_rhs = 0
            self.latex_ME['lhs'] += latex(me_lhs)
            for key in coefs.keys():
                me_rhs += coefs[key] * derivs[key]
                self.latex_ME['rhs'][key[1:]] = latex(coefs[key] * derivs[key])
            self.ME = Eq(me_lhs, me_rhs)
            return True
        except:
            return False

        Computes the values of the modified equation coefficients a_{ijk} where i, j and k represent
        the order of derivatives in the <indep var1\> , <indep var2\>, and <indep var3\> directions, respectively. These are written as
        a_ijk * u_{ijk}.

        Parameters:
            nterms (int):Number of terms to compute in the modified equation

        Returns:
             bool: true if finished without error, false otherwise

        Examples:
            >>> <DE>.modified_equation(nterms=2)
        
Computes the values of the modified equation coefficients a_{ijk} where i, j and k represent
the order of derivatives in the  , , and  directions, respectively. These are written as
a_ijk * u_{ijk}.
Computes the values of the modified equation coefficients a_ { ijk } where i j and k represent the order of derivatives in the and directions respectively . These are written as a_ijk * u_ { ijk } .
def modified_equation(self, nterms):
        try:
            A = symbols('A')
            lhs1 = simplify(self.lhs / self.function(self.t['index'], **self.indicies))
            rhs1 = simplify(self.rhs / self.function(self.t['index'], **self.indicies))
            eq = lhs1 - rhs1
            eq = eq.subs(exp(self.t['ampFactor'] * self.t['variation']), A)
            eq = eq.subs(exp(self.t['variation'] * self.t['ampFactor']), A)
            eq = expand(eq)
            eq = collect(eq, A)
            logEqdt = simplify(solve(eq, A)[0])
            q =  log(logEqdt) / self.t['variation']  
            couples = [i for i in product(list(range(0, nterms + 1)), repeat=len(self.__independentVars)) if
                       (sum(i) <= nterms and sum(i) > 0)]
            coefs = {}
            derivs = {}
            for couple in couples:
                wrt_vars = []
                wrt_wave_num = []
                waveNum = {}
                fac = 1
                N = 0
                ies = ''
                for num, var in enumerate(self.__independentVars):
                    wrt_wave_num.append(self.vars[var]['waveNum'])
                    waveNum[self.vars[var]['waveNum']] = 0
                    wrt_wave_num.append(couple[num])
                    wrt_vars.append(self.vars[var]['sym'])
                    wrt_vars.append(couple[num])
                    N = sum(couple)
                    fac *= factorial(couple[num])
                    ies += str(couple[num])
                diff_ = diff(q, *wrt_wave_num).subs(waveNum)
                frac = ratsimp(1 / (fac * I ** N))
                coefficient = simplify(frac * diff_)
                if coefficient != 0:
                    coefs['a{}'.format(ies)] = nsimplify(coefficient)
                    derivs['a{}'.format(ies)] = Derivative(self.dependentVar, *wrt_vars)
            me_lhs = Derivative(self.dependentVar, self.t['sym'], 1)
            me_rhs = 0
            self.latex_ME['lhs'] += latex(me_lhs)
            for key in coefs.keys():
                me_rhs += coefs[key] * derivs[key]
                self.latex_ME['rhs'][key[1:]] = latex(coefs[key] * derivs[key])
            self.ME = Eq(me_lhs, me_rhs)
            return True
        except:
            return False
def modified_equation ( self , nterms ) : try : A = symbols ( 'A' ) lhs1 = simplify ( self . lhs / self . function ( self . t [ 'index' ] , ** self . indicies ) ) rhs1 = simplify ( self . rhs / self . function ( self . t [ 'index' ] , ** self . indicies ) ) eq = lhs1 - rhs1 eq = eq . subs ( exp ( self . t [ 'ampFactor' ] * self . t [ 'variation' ] ) , A ) eq = eq . subs ( exp ( self . t [ 'variation' ] * self . t [ 'ampFactor' ] ) , A ) eq = expand ( eq ) eq = collect ( eq , A ) logEqdt = simplify ( solve ( eq , A ) [ 0 ] ) q = log ( logEqdt ) / self . t [ 'variation' ] couples = [ i for i in product ( list ( range ( 0 , nterms + 1 ) ) , repeat = len ( self . __independentVars ) ) if ( sum ( i ) <= nterms and sum ( i ) > 0 ) ] coefs = { } derivs = { } for couple in couples : wrt_vars = [ ] wrt_wave_num = [ ] waveNum = { } fac = 1 N = 0 ies = '' for num , var in enumerate ( self . __independentVars ) : wrt_wave_num . append ( self . vars [ var ] [ 'waveNum' ] ) waveNum [ self . vars [ var ] [ 'waveNum' ] ] = 0 wrt_wave_num . append ( couple [ num ] ) wrt_vars . append ( self . vars [ var ] [ 'sym' ] ) wrt_vars . append ( couple [ num ] ) N = sum ( couple ) fac *= factorial ( couple [ num ] ) ies += str ( couple [ num ] ) diff_ = diff ( q , * wrt_wave_num ) . subs ( waveNum ) frac = ratsimp ( 1 / ( fac * I ** N ) ) coefficient = simplify ( frac * diff_ ) if coefficient != 0 : coefs [ 'a{}' . format ( ies ) ] = nsimplify ( coefficient ) derivs [ 'a{}' . format ( ies ) ] = Derivative ( self . dependentVar , * wrt_vars ) me_lhs = Derivative ( self . dependentVar , self . t [ 'sym' ] , 1 ) me_rhs = 0 self . latex_ME [ 'lhs' ] += latex ( me_lhs ) for key in coefs . keys ( ) : me_rhs += coefs [ key ] * derivs [ key ] self . latex_ME [ 'rhs' ] [ key [ 1 : ] ] = latex ( coefs [ key ] * derivs [ key ] ) self . ME = Eq ( me_lhs , me_rhs ) return True except : return False
Computes the values of the modified equation coefficients a_{ijk} where i, j and k represent
the order of derivatives in the <indep var1\> , <indep var2\>, and <indep var3\> directions, respectively.
Computes the values of the modified equation coefficients a_ { ijk } where i j and k represent the order of derivatives in the <indep var1 \ > <indep var2 \ > and <indep var3 \ > directions respectively .
'''
        Computes the values of the modified equation coefficients a_{ijk} where i, j and k represent
        the order of derivatives in the <indep var1\> , <indep var2\>, and <indep var3\> directions, respectively. These are written as
        a_ijk * u_{ijk}.

        Parameters:
            nterms (int):Number of terms to compute in the modified equation

        Returns:
             bool: true if finished without error, false otherwise

        Examples:
            >>> <DE>.modified_equation(nterms=2)
        ''' # compute the amplification factor # amplification factor
true if finished without error, false otherwise
true if finished without error false otherwise
bool
self
nterms
Number of terms to compute in the modified equation
Number of terms to compute in the modified equation
examples
None