1- from solvers import Solver , Adaptive
1+ from . solvers import Solver , Adaptive
22import numpy as np
33
44def _calculate_order_1_level (coefficients ):
@@ -134,7 +134,7 @@ def middle(x,y,z): # Auxilary function
134134 k = np .zeros ((k_len , self .neq ), self .dtype ) # intern stages
135135
136136 if self .verbose > 0 :
137- print 'advance solution in [%s, %s], h=%g' % (t_n , t_next , h )
137+ print ( 'advance solution in [%s, %s], h=%g' % (t_n , t_next , h ) )
138138
139139 # Loop until next time point is reached
140140 while (abs (t - t_n ) < abs (t_next - t_n )):
@@ -150,7 +150,7 @@ def middle(x,y,z): # Auxilary function
150150
151151 self .info ['rejected' ] += 1 # reduced below if accepted
152152 if self .verbose > 0 :
153- print ' u(t=%g)=%g: ' % (t + h , u_new ),
153+ print ( ' u(t=%g)=%g: ' % (t + h , u_new ), end = ' ' )
154154
155155 # local error between 2 levels
156156 error = h * np .abs (np .dot (factors_error , k ))
@@ -171,18 +171,18 @@ def middle(x,y,z): # Auxilary function
171171 self .info ['rejected' ] -= 1
172172
173173 if self .verbose > 0 :
174- print 'accepted, ' ,
174+ print ( 'accepted, ' , end = ' ' )
175175 else :
176176 if self .verbose > 0 :
177- print 'rejected, ' ,
177+ print ( 'rejected, ' , end = ' ' )
178178
179179 if self .verbose > 0 :
180- print 'err=%s, ' % str (error ),
180+ print ( 'err=%s, ' % str (error ), end = ' ' )
181181 if hasattr (self , 'u_exact' ) and callable (self .u_exact ):
182- print 'exact-err=%s, ' % \
183- (np .asarray (self .u_exact (t + h ))- u_new ),
182+ print ( 'exact-err=%s, ' % \
183+ (np .asarray (self .u_exact (t + h ))- u_new ), end = ' ' )
184184 if h <= self .min_step :
185- print 'h=min_step!! ' ,
185+ print ( 'h=min_step!! ' , end = ' ' )
186186
187187
188188 # Replace 0 values by 1e-16 since we will divide by error
@@ -209,7 +209,7 @@ def middle(x,y,z): # Auxilary function
209209 h = min (h , t_next - t_intermediate [- 1 ])
210210
211211 if self .verbose > 0 :
212- print 'new h=%g' % h
212+ print ( 'new h=%g' % h )
213213
214214 if h == 0 :
215215 break
@@ -367,16 +367,16 @@ def validate_data(self):
367367 # Check for dimension of user-defined butcher table.
368368 array_shape = self .butcher_tableau .shape
369369 if len (array_shape ) is not 2 :
370- raise ValueError , '''
371- Illegal input! Your input butcher_tableau should be a 2d-array!'''
370+ raise ValueError ( '''
371+ Illegal input! Your input butcher_tableau should be a 2d-array!''' )
372372 else :
373373 m ,n = array_shape
374374 if m not in (n , n + 1 ):
375- raise ValueError , '''\
375+ raise ValueError ( '''\
376376 The dimension of 2d-array <method_yours_array> should be:
377377 1. Either (n, n), --> For 1-level RungeKutta methods
378378 2. Or (n+1, n), --> For 2-levels RungeKutta methods
379- The shape of your input array is (%d, %d).''' % (m ,n )
379+ The shape of your input array is (%d, %d).''' % (m ,n ))
380380 self ._butcher_tableau = self .butcher_tableau
381381
382382 # Check for user-defined order,
@@ -393,19 +393,19 @@ def validate_data(self):
393393 if array_shape [0 ] == array_shape [1 ] + 1 :
394394 # 2-level RungeKutta methods
395395 if type (self .method_order ) is int :
396- raise ValueError , error_2level
396+ raise ValueError ( error_2level )
397397 try :
398398 order1 , order2 = self .method_order
399399 if abs (order1 - order2 ) != 1 or \
400400 order1 < 1 or order2 < 1 :
401- raise ValueError , error_2level
401+ raise ValueError ( error_2level )
402402 except :
403- raise ValueError , error_2level
403+ raise ValueError ( error_2level )
404404 else :
405405 # 1-level RungeKutta methods
406406 if type (self .method_order ) is not int or \
407407 self .method_order < 1 :
408- raise ValueError , error_1level
408+ raise ValueError ( error_1level )
409409 self ._method_order = self .method_order
410410
411411 else : # method_order is not specified
@@ -418,14 +418,14 @@ def validate_data(self):
418418 for i in range (1 ,array_shape [1 ] - 1 ):
419419 if not np .allclose (self .butcher_tableau [i ][0 ],\
420420 sum (self .butcher_tableau [i ][1 :])):
421- raise ValueError , '''
421+ raise ValueError ( '''
422422 Inconsistent data in Butcher_Tableau!
423423 In each lines of stage-coefficients, first number should be
424424 equal to the sum of other numbers.
425425 That is, for a butcher_table with K columns,
426426 a[i][0] == a[i][1] + a[i][2] + ... + a[i][K - 1]
427427 where 1 <= i <= K - 1
428428 Your input for line %d is :%s
429- ''' % (i ,str (self .butcher_tableau [i ]))
429+ ''' % (i ,str (self .butcher_tableau [i ])))
430430
431431 return True
0 commit comments