Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from __future__ import division
import numpy as np
from dymos.glm.ozone.methods.runge_kutta.runge_kutta import RungeKutta
class BackwardEuler(RungeKutta):
def __init__(self):
self.order = 1
super(BackwardEuler, self).__init__(A=1., B=1.)
class ImplicitMidpoint(RungeKutta):
def __init__(self):
self.order = 2
super(ImplicitMidpoint, self).__init__(A=1. / 2., B=1.)
class TrapezoidalRule(RungeKutta):
def __init__(self):
self.order = 2
super(TrapezoidalRule, self).__init__(A=np.array([[0., 0.], [1 / 2, 1 / 2]]),
B=np.array([1 / 2, 1 / 2]))
def __init__(self):
self.order = 1
super(BackwardEuler, self).__init__(A=1., B=1.)
class ImplicitMidpoint(RungeKutta):
def __init__(self):
self.order = 2
super(ImplicitMidpoint, self).__init__(A=1. / 2., B=1.)
class TrapezoidalRule(RungeKutta):
def __init__(self):
self.order = 2
super(TrapezoidalRule, self).__init__(A=np.array([[0., 0.], [1 / 2, 1 / 2]]),
B=np.array([1 / 2, 1 / 2]))
def get_KuttaThirdOrder():
KuttaThirdOrder_A = np.array([
[0., 0., 0.],
[1 / 2, 0., 0.],
[-1., 2., 0.],
])
KuttaThirdOrder_B = np.array([
[1 / 6, 4 / 6, 1 / 6],
])
return KuttaThirdOrder_A, KuttaThirdOrder_B
class KuttaThirdOrder(RungeKutta):
def __init__(self):
self.order = 3
KuttaThirdOrder_A, KuttaThirdOrder_B = get_KuttaThirdOrder()
A = np.array(KuttaThirdOrder_A)
B = np.array(KuttaThirdOrder_B)
super(KuttaThirdOrder, self).__init__(A=A, B=B)
def get_RK4():
RK4_A = np.array([
[0., 0., 0., 0.],
[1 / 2, 0., 0., 0.],
RK6_A[3, :3] = [ (-15 + 7 * r) / 20, (-1 + r) / 4, (15 - 7 * r) / 10]
RK6_A[4, 0] = (5 - r) / 60
RK6_A[4, 2:4] = [ 1 / 6, (15 + 7 * r) / 60]
RK6_A[5, 0] = (5 + r) / 60
RK6_A[5, 2:5] = [ (9 - 5 * r) / 12, 1 / 6, (-5 + 3 * r) / 10]
RK6_A[6, 0] = 1 / 6
RK6_A[6, 2:6] = [ (-55 + 25 * r) / 12, (-25 - 7 * r) / 12, 5 - 2 * r, (5 + r) / 2]
RK6_B = np.zeros((1, 7))
RK6_B[0, 0] = 1 / 12
RK6_B[0, 4:7] = [ 5 / 12, 5 / 12, 1 / 12]
return RK6_A, RK6_B
class RK6(RungeKutta):
def __init__(self, s=1.):
self.order = 6
RK6_A, RK6_B = get_RK6(s)
A = np.array(RK6_A)
B = np.array(RK6_B)
super(RK6, self).__init__(A=A, B=B)
def __init__(self, A, B):
A = np.atleast_2d(A)
B = np.atleast_2d(B)
U = np.ones((A.shape[0], 1))
V = np.array([[1.]])
abscissa = np.sum(A, 1)
starting_method = None
super(RungeKutta, self).__init__(A, B, U, V, abscissa, starting_method)
def __init__(self):
self.order = 2
super(HeunsMethod, self).__init__(
A=np.array([
[0., 0.],
[1., 0.],
]),
B=np.array([
[1. / 2., 1. / 2.],
])
)
class RalstonsMethod(RungeKutta):
def __init__(self):
self.order = 2
super(RalstonsMethod, self).__init__(
A=np.array([
[0., 0.],
[2 / 3, 0.],
]),
B=np.array([
[1 / 4, 3 / 4],
])
)
def get_KuttaThirdOrder():
class ExplicitMidpoint(RungeKutta):
def __init__(self):
self.order = 2
ExplicitMidpoint_A, ExplicitMidpoint_B = get_ExplicitMidpoint()
A = np.array(ExplicitMidpoint_A)
B = np.array(ExplicitMidpoint_B)
super(ExplicitMidpoint, self).__init__(A=A, B=B)
class HeunsMethod(RungeKutta):
def __init__(self):
self.order = 2
super(HeunsMethod, self).__init__(
A=np.array([
[0., 0.],
[1., 0.],
]),
B=np.array([
[1. / 2., 1. / 2.],
])
)
class RalstonsMethod(RungeKutta):
from __future__ import division
import numpy as np
from dymos.glm.ozone.methods.runge_kutta.runge_kutta import RungeKutta
class ForwardEuler(RungeKutta):
def __init__(self):
self.order = 1
super(ForwardEuler, self).__init__(A=0., B=1.)
def get_ExplicitMidpoint():
ExplicitMidpoint_A = np.array([
[ 0., 0.],
[1. / 2., 0.],
])
ExplicitMidpoint_B = np.array([
[0., 1.],
])
def get_ExplicitMidpoint():
ExplicitMidpoint_A = np.array([
[ 0., 0.],
[1. / 2., 0.],
])
ExplicitMidpoint_B = np.array([
[0., 1.],
])
return ExplicitMidpoint_A, ExplicitMidpoint_B
class ExplicitMidpoint(RungeKutta):
def __init__(self):
self.order = 2
ExplicitMidpoint_A, ExplicitMidpoint_B = get_ExplicitMidpoint()
A = np.array(ExplicitMidpoint_A)
B = np.array(ExplicitMidpoint_B)
super(ExplicitMidpoint, self).__init__(A=A, B=B)
class HeunsMethod(RungeKutta):
def __init__(self):
self.order = 2
from __future__ import division
import numpy as np
from dymos.glm.ozone.methods.runge_kutta.runge_kutta import RungeKutta
class BackwardEuler(RungeKutta):
def __init__(self):
self.order = 1
super(BackwardEuler, self).__init__(A=1., B=1.)
class ImplicitMidpoint(RungeKutta):
def __init__(self):
self.order = 2
super(ImplicitMidpoint, self).__init__(A=1. / 2., B=1.)
class TrapezoidalRule(RungeKutta):