diff --git a/docs/build/html/_modules/numerical/ode.html b/docs/build/html/_modules/numerical/ode.html
index b827064..629bed9 100644
--- a/docs/build/html/_modules/numerical/ode.html
+++ b/docs/build/html/_modules/numerical/ode.html
@@ -37,8 +37,8 @@
# -*- coding: utf-8 -*-"""Numerical solver of ordinary differential equations.
-Solves the initial value problem for systems of first order ordinary differential
-equations.
+Solves the initial value problem for systems of first order
+ordinary differential equations.:Date: 2015-09-21
@@ -68,7 +68,8 @@
:type x0: list :param t: time :type t: list
- :param `*p`: parameters of the function (thickness, diameter, ...)
+ :param `*p`: parameters of the function (thickness, diameter,
+ ...) :param verbose: print information (default = False) :type verbose: bool
@@ -83,14 +84,14 @@
.. math :: t_i = t_0 + i h ~,\quad i=1,2,\ldots,n
- The derivative of the solution is approximated as the forward difference
- equation
+ The derivative of the solution is approximated as the forward
+ difference equation .. math :: \dot{x}_i = f(t_i, x_i) = \frac{x_{i+1} - x_i}{t_{i+1}-t_i}
- Therefore one step :math:`h` of the Euler method from :math:`t_i` to
- :math:`t_{i+1}` is
+ Therefore one step :math:`h` of the Euler method from
+ :math:`t_i` to :math:`t_{i+1}` is .. math :: x_{i+1} &= x_i + (t_{i+1}-t_i) f(t_i, x_i) \\
@@ -119,7 +120,8 @@
.. math :: \dot{x} &= f(t,x) \\ \begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &=
- \begin{bmatrix} x_2 \\ m^{-1}(f(t) - d x_2 - k x_1) \end{bmatrix} \\
+ \begin{bmatrix} x_2 \\ m^{-1}(f(t) - d x_2 - k x_1)
+ \end{bmatrix} \\ &= \begin{bmatrix} 0 \\ m^{-1} f(t) \end{bmatrix} + \begin{bmatrix} 0 & 1 \\ -m^{-1} k & -m^{-1} d \end{bmatrix}
@@ -141,32 +143,39 @@
.. math :: \dot{x}_1 &= x_2 \\
- \dot{x}_2 &= m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) \\
+ \dot{x}_2 &=
+ m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) \\ or .. math :: \dot{x} &= f(t,x) \\ \begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &=
- \begin{bmatrix} x_2 \\ m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) \end{bmatrix} \\
+ \begin{bmatrix}
+ x_2 \\ m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1)
+ \end{bmatrix} \\ &= \begin{bmatrix} 0 \\ m^{-1}(x_1) f(t) \end{bmatrix} +
- \begin{bmatrix} 0 & 1 \\ -m^{-1}(x_1) k(x_1) & -m^{-1} d(x_1,x_2) \end{bmatrix}
+ \begin{bmatrix}
+ 0 & 1 \\ -m^{-1}(x_1) k(x_1) & -m^{-1} d(x_1,x_2)
+ \end{bmatrix} \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}
- The Euler method is a first-order method,
- which means that the local error (error per step) is proportional to the
- square of the step size, and the global error (error at a given time) is
+ The Euler method is a first-order method, which means that the
+ local error (error per step) is proportional to the square of
+ the step size, and the global error (error at a given time) is proportional to the step size. """
- x=zeros((len(t),len(x0)))# Preallocate array
- x[0,:]=x0# Initial condition gives solution at first t
- foriinrange(len(t)-1):# Calculation loop
+ x=zeros((len(t),len(x0)))# Preallocate array
+ x[0,:]=x0# Initial condition gives solution at first t
+ foriinrange(len(t)-1):# Calculation loopDt=t[i+1]-t[i]dxdt=array(f(x[i,:],t[i],*p))
- x[i+1,:]=x[i,:]+dxdt*Dt# Approximate solution at next value of x
+ # Approximate solution at next value of x
+ x[i+1,:]=x[i,:]+dxdt*Dtifverbose:
- print('Numerical integration of ODE using explicit first-order method (Euler / Runge-Kutta) was successful.')
+ print('Numerical integration of ODE using explicit '+
+ 'first-order method (Euler / Runge-Kutta) was successful.')returnx
[docs]defe2(f,x0,t,*p,verbose=False):
@@ -178,19 +187,22 @@
:type x0: list :param t: time :type t: list
- :param `*p`: parameters of the function (thickness, diameter, ...)
+ :param `*p`: parameters of the function (thickness, diameter,
+ ...) :param verbose: print information (default = False) :type verbose: bool """
- x=zeros((len(t),len(x0)))# Preallocate array
- x[0,:]=x0# Initial condition gives solution at first t
- foriinrange(len(t)-1):# Calculation loop
+ x=zeros((len(t),len(x0)))# Preallocate array
+ x[0,:]=x0# Initial condition gives solution at first t
+ foriinrange(len(t)-1):# Calculation loopDt=t[i+1]-t[i]k_1=array(f(x[i,:],t[i],*p))k_2=array(f(x[i,:]+0.5*Dt*k_1,t[i]+0.5*Dt,*p))
- x[i+1,:]=x[i,:]+k_2*Dt# Approximate solution at next value of x
+ # Approximate solution at next value of x
+ x[i+1,:]=x[i,:]+k_2*Dtifverbose:
- print('Numerical integration of ODE using explicit 2th-order method (Runge-Kutta) was successful.')
+ print('Numerical integration of ODE using explicit '+
+ '2th-order method (Runge-Kutta) was successful.')returnx
[docs]defe4(f,x0,t,*p,verbose=False):
@@ -202,7 +214,8 @@
:type x0: list :param t: time :type t: list
- :param `*p`: parameters of the function (thickness, diameter, ...)
+ :param `*p`: parameters of the function (thickness, diameter,
+ ...) :param verbose: print information (default = False) :type verbose: bool """
@@ -214,70 +227,64 @@
k_2=array(f(x[i,:]+0.5*Dt*k_1,t[i]+0.5*Dt,*p))k_3=array(f(x[i,:]+0.5*Dt*k_2,t[i]+0.5*Dt,*p))k_4=array(f(x[i,:]+k_3*Dt,t[i]+Dt,*p))
- x[i+1,:]=x[i,:]+1./6*(k_1+2*k_2+2*k_3+k_4)*Dt# Approximate solution at next value of x
+ # Approximate solution at next value of x
+ x[i+1,:]=x[i,:]+1./6*(k_1+2*k_2+2*k_3+k_4)*Dtifverbose:
- print('Numerical integration of ODE using explicit 4th-order method (Runge-Kutta) was successful.')
+ print('Numerical integration of ODE using explicit '+
+ '4th-order method (Runge-Kutta) was successful.')returnx
[docs]defi1(f,x0,t,*p,max_iterations=1000,tol=1e-9,
+ verbose=False):r"""Implicite first-order method / backward Euler method. :param f: the function to solve
@@ -286,7 +293,8 @@
:type x0: list :param t: time :type t: list
- :param `*p`: parameters of the function (thickness, diameter, ...)
+ :param `*p`: parameters of the function (thickness, diameter,
+ ...) :param max_iterations: maximum number of iterations :type max_iterations: int :param tol: tolerance against residuum (default = 1e-9)
@@ -298,26 +306,24 @@
"""iterations=zeros((len(t),1))x=zeros((len(t),len(x0)))# Preallocate array
- x[0,:]=x0# Initial condition gives solution at first t
+ x[0,:]=x0# Initial condition gives solution at first t
+ # x(i+1) = x(i) + f(x(i+1), t(i+1)), exact value of
+ # f(x(i+1), t(i+1)) is not available therefore using
+ # Newton-Raphson methodforiinrange(len(t)-1):Dt=t[i+1]-t[i]xi=x[i,:]
- # x(i+1) = x(i) + f(x(i+1), t(i+1)), exact value of f(x(i+1), t(i+1)) is not
- # available therefor using Newton-Raphson method
- forjinrange(max_iterations):# Fixed-point iteration
- dxdt=array(f(xi,t[i+1],*p))
- xi1=x[i,:]+dxdt*Dt# Approximate solution at next value of x
- residuum=norm(xi1-xi)/norm(xi1)
- xi=xi1
- ifresiduum<tol:
- break
- iterations[i]=j+1
+ xi,iteration=fpi(f,xi,t[i],t[i+1],*p,max_iterations,
+ tol,verbose)x[i+1,:]=xi
+ iterations[i]=iterationifverbose:
- print('Numerical integration of ODE using implicite first-order method (Euler) was successful.')
+ print('Numerical integration of ODE using implicite '+
+ 'first-order method (Euler) was successful.')returnx,iterations
[docs]defnewmark_newtonraphson(f,x0,xp0,xpp0,t,*p,gamma=.5,
+ beta=.25,max_iterations=1000,tol=1e-9,verbose=False):r"""Newmark method. :param f: the function to solve
@@ -330,7 +336,8 @@
:type xpp0: list :param t: time :type t: list
- :param `*p`: parameters of the function (thickness, diameter, ...)
+ :param `*p`: parameters of the function (thickness, diameter,
+ ...) :param gamma: newmark parameter for velocity (default = 0.5) :type gamma: float :param beta: newmark parameter for displacement (default = 0.25)
@@ -346,9 +353,9 @@
x=zeros((len(t),len(x0)))# Preallocate arrayxp=zeros((len(t),len(xp0)))# Preallocate arrayxpp=zeros((len(t),len(xpp0)))# Preallocate array
- x[0,:]=x0# Initial condition gives solution at first t
- xp[0,:]=xp0# Initial condition gives solution at first t
- xpp[0,:]=xpp0# Initial condition gives solution at first t
+ x[0,:]=x0# Initial condition gives solution at first t
+ xp[0,:]=xp0# Initial condition gives solution at first t
+ xpp[0,:]=xpp0# Initial condition gives solution at first tforiinrange(len(t)-1):Dt=t[i+1]-t[i]
@@ -361,7 +368,8 @@
j=0forjinrange(max_iterations):# Fixed-point iteration#dxdt = array(f(t[i+1], x1, p))
- #x11 = x[i,:] + dxdt*Dt # Approximate solution at next value of x
+ # Approximate solution at next value of x
+ #x11 = x[i,:] + dxdt*DtN,dN,dNp,dNpp=f(x1.reshape(-1,).tolist(),xp1.reshape(-1,).tolist(),xpp1.reshape(-1,).tolist(),
@@ -370,7 +378,8 @@
print('divergiert')break
- xpp11=xpp1-dot(inv(dNpp),(N+dot(dN,(x1-xi))+dot(dNp,(xp1-xpi))))
+ xpp11=xpp1-dot(inv(dNpp),(N+dot(dN,(x1-xi))+ \
+ dot(dNp,(xp1-xpi))))xp1=xpi+Dt*((1-gamma)*xppi+gamma*xpp11)x1=xi+Dt*xpi+Dt**2*((.5-beta)*xppi+beta*xpp11)
@@ -384,11 +393,13 @@
xp[i+1,:]=xp1.reshape(-1,).tolist()x[i+1,:]=x1.reshape(-1,).tolist()ifverbose:
- print('Numerical integration of ODE using explicite newmark method was successful.')
+ print('Numerical integration of ODE using explicite '+
+ 'newmark method was successful.')returnx,xp,xpp,iterations
[docs]defnewmark_newtonraphson_rdk(fnm,x0,xp0,xpp0,t,*p,gamma=.5,
+ beta=.25,max_iterations=1000,tol=1e-9,verbose=False):r"""Newmark method. :param f: the function to solve
@@ -401,7 +412,8 @@
:type xpp0: list :param t: time :type t: list
- :param `*p`: parameters of the function (thickness, diameter, ...)
+ :param `*p`: parameters of the function (thickness, diameter,
+ ...) :param gamma: newmark parameter for velocity (default = 0.5) :type gamma: float :param beta: newmark parameter for displacement (default = 0.25)
@@ -417,13 +429,14 @@
x=zeros((len(t),len(x0)))# Preallocate arrayxp=zeros((len(t),len(xp0)))# Preallocate arrayxpp=zeros((len(t),len(xpp0)))# Preallocate array
- x[0,:]=x0# Initial condition gives solution at first t
- xp[0,:]=xp0# Initial condition gives solution at first t
- xpp[0,:]=xpp0# Initial condition gives solution at first t
+ x[0,:]=x0# Initial condition gives solution at first t
+ xp[0,:]=xp0# Initial condition gives solution at first t
+ xpp[0,:]=xpp0# Initial condition gives solution at first tforiinrange(len(t)-1):Dt=t[i+1]-t[i]
- rm,rmx,rmxpp,rd,rdx,rdxp,rk,rkx,f=fnm(x[i,:],xp[i,:],xpp[i,:],t[i],*p)
+ rm,rmx,rmxpp,rd,rdx,rdxp,rk,rkx,f=fnm(x[i,:],
+ xp[i,:],xpp[i,:],t[i],*p)xi=x[i,:].reshape(3,1)xpi=xp[i,:].reshape(3,1)
@@ -432,13 +445,16 @@
xp1=xpixpp1=xppij=0
- forjinrange(maxIterations):# Fixed-point iteration
+ forjinrange(max_iterations):# Fixed-point iteration#dxdt = array(f(t[i+1], x1, p))
- #x11 = x[i,:] + dxdt*Dt # Approximate solution at next value of x
+ # Approximate solution at next value of x
+ #x11 = x[i,:] + dxdt*Dtr=(rmx+rdx+rkx)*Dt**2./4+rdxp*Dt/2+rmxpp
- rp=f-(rm+dot(rmx,(Dt*xpi+Dt**2./4*xppi))-dot(rmxpp,xppi)+ \
- rd+dot(rdx,(Dt*xpi+Dt**2./4*xppi))+dot(rdxp,Dt/2*xppi)+ \
+ rp=f-(rm+dot(rmx,(Dt*xpi+Dt**2./4*xppi))- \
+ dot(rmxpp,xppi)+ \
+ rd+dot(rdx,(Dt*xpi+Dt**2./4*xppi))+ \
+ dot(rdxp,Dt/2*xppi)+ \
rk+dot(rkx,(Dt*xpi+Dt**2./4*xppi)))xpp11=dot(inv(r),rp)xp1=xpi+Dt*((1-gamma)*xppi+gamma*xpp11)
@@ -454,7 +470,8 @@
xp[i+1,:]=xp1.reshape(-1,).tolist()x[i+1,:]=x1.reshape(-1,).tolist()ifverbose:
- print('Numerical integration of ODE using explicite newmark method was successful.')
+ print('Numerical integration of ODE using explicite '+
+ 'newmark method was successful.')returnx,xp,xpp,iterations
[docs]defin_seconds(time):
+ """If time is `time.struct_time` convert to float seconds.
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: the time in seconds
+ :rtype: float
+ """
+ ifisinstance(time,struct_time):
+ time=mktime(time)
+ returntime
+
+
[docs]defseconds(time):
+ """The seconds of the time.
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: seconds, range [0, 60]
+ :rtype: float
+ """
+ returnin_seconds(time)%60
+
+
[docs]defseconds_norm(time):
+ """The seconds normalized to 60 seconds.
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: the normalized seconds, range [0, 1]
+ :rtype: float
+ """
+ returnseconds(time)/60
+
+
[docs]defminutes(time):
+ """The minutes of the time.
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: minutes, range [0, 60]
+ :rtype: float
+ """
+ returnin_seconds(time)/60%60
+
+
[docs]defminutes_norm(time):
+ """The minutes normalized to 60 minutes.
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: the normalized minutes, range [0, 1]
+ :rtype: float
+ """
+ returnminutes(time)/60
+
+
[docs]defhours(time):
+ """The hours of the time.
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: hours, range [0, 24]
+ :rtype: float
+ """
+ returnin_seconds(time)/60/60%24
+
+
[docs]defhours_norm(time):
+ """The hours normalized to 24 hours.
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: the normalized hours, range [0, 1]
+ :rtype: float
+ """
+ returnhours(time)/24
+
+
[docs]defdays(time):
+ """The days of the time (year).
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: hours, range [0, 365.2425]
+ :rtype: float
+ """
+ returnin_seconds(time)/60/60/24%365.2425
+
+
[docs]defdays_norm(time):
+ """The days normalized to 365.2425 (Gregorian, on average) days.
+
+ :param time: the time in seconds
+ :type time: float or `time.struct_time`
+
+ :returns: the normalized days, range [0, 1]
+ :rtype: float
+ """
+ returndays(time)/365.2425
+
+
[docs]deftransform(time_norm,length,offset=0):
+ """Transform normalized time value to new length.
+
+ :param position_norm: the normalized time value to transform
+ :type position_norm: float
+ :param length: the transformation
+ :type length: float
+ :param offset: the offset (default = 0)
+ :type offset: float
+
+ :returns: the transformation value
+ :rtype: float
+ """
+ returntime_norm*length+offset
The Euler method is a first-order method,
-which means that the local error (error per step) is proportional to the
-square of the step size, and the global error (error at a given time) is
+
The Euler method is a first-order method, which means that the
+local error (error per step) is proportional to the square of
+the step size, and the global error (error at a given time) is
proportional to the step size.
@@ -314,7 +305,8 @@ proportional to the step size.
f (function) – the function to solve
x0 (list) – initial condition
t (list) – time
-
*p – parameters of the function (thickness, diameter, …)
+
*p – parameters of the function (thickness, diameter,
+…)
verbose (bool) – print information (default = False)
@@ -331,7 +323,8 @@ proportional to the step size.
f (function) – the function to solve
x0 (list) – initial condition
t (list) – time
-
*p – parameters of the function (thickness, diameter, …)
+
*p – parameters of the function (thickness, diameter,
+…)
verbose (bool) – print information (default = False)
@@ -339,30 +332,37 @@ proportional to the step size.
@@ -425,7 +422,8 @@ proportional to the step size.
xp0 (list) – initial condition
xpp0 (list) – initial condition
t (list) – time
-
*p – parameters of the function (thickness, diameter, …)
+
*p – parameters of the function (thickness, diameter,
+…)
gamma (float) – newmark parameter for velocity (default = 0.5)
beta (float) – newmark parameter for displacement (default = 0.25)
max_iterations (int) – maximum number of iterations
diff --git a/docs/build/html/objects.inv b/docs/build/html/objects.inv
index 710740c..b6e0d3d 100644
--- a/docs/build/html/objects.inv
+++ b/docs/build/html/objects.inv
@@ -2,6 +2,6 @@
# Project: pylib
# Version:
# The remainder of this file is compressed using zlib.
-xڭ0<h!40CAQcGD# A&< ddH4}fL;mŬ&"e2uHZ*Dp/!LQQmV3inQpY
$dfIfv^f{mD%"k:o~7{i%Rj![꼱p[[*X*8NpK0Jl6X"w}aߎ@jPȳZE`%gꢘ
AU
+KRN4H._o{*aglklAo:V(4My;vx'>?AM 3V/G,.Syn
@t1eҨ)IOTsMG]mxFm)HbW35*
\ No newline at end of file
diff --git a/docs/build/html/py-modindex.html b/docs/build/html/py-modindex.html
index df9bb3e..3a2d315 100644
--- a/docs/build/html/py-modindex.html
+++ b/docs/build/html/py-modindex.html
@@ -48,7 +48,8 @@
g |
i |
n |
- o
+ o |
+ t