예제 #1
0
def fpt_poisson_inverselapl (x, t, α, D, σ, fpt):
	mpmath.mp.dps = 30
	x = np.atleast_1d(x)
	t = np.atleast_1d(t)
	P = np.zeros((len(x),len(t)))

	sqrt2 = mpmath.sqrt(2)
	if fpt:
		ret_psr_lp = lambda psr,s: 1 - s*psr  # p(tf) = - d/dt psr
	else:
		ret_psr_lp = lambda psr,s: psr

	for i in range(len(x)):
		if σ == 0:
			def ps0_lp (κ, s):
				return (1 - mpmath.exp(-κ * x[i])) / s
		else:
			b = x[i] / σ
			def ps0_lp (κ, s):
				k = σ * κ
				return (1 - mpmath.exp(k**2/2)/2 * ( mpmath.exp(+κ*x[i]) * mpmath.erfc((b+k)/sqrt2)
				                                   + mpmath.exp(-κ*x[i]) * (1+mpmath.erf((b-k)/sqrt2)) ) ) / s
		def psr_lp (s):
			κ = mpmath.sqrt( (α+s) / D )
			ps0 = ps0_lp(κ, s=α+s)
			psr = ps0 / (1 - α*ps0)
			return ret_psr_lp(psr, s)

		for j in range(len(t)):
			if x[i] < 0:
				P[i,j] = 0
			else:
				P[i,j] = mpmath.invertlaplace(psr_lp, t[j], method='talbot', degree=20)
	return np.squeeze(P)
 def linear_ramp_inv(self, t):
     inv_lap_func=lambda s: 1/(s**2*(s**(-self.nd_param.nd_param_dict["psi"])+self.nd_param.nd_param_dict["tau"]))
     inv_lap_val=mpmath.invertlaplace(inv_lap_func,t,method='talbot')
     if t<self.dim_dict["tr"]:
         return self.nd_param.nd_param_dict["Cdl"]*inv_lap_val
     else:
         return -self.nd_param.nd_param_dict["Cdl"]*inv_lap_val
 def B(self, t):
     inv_lap_func = lambda s: 1 / (s * (self.nd_param.nd_param_dict[
         "tau"] + s**-self.nd_param.nd_param_dict["psi"]))
     inv_lap_val = mpmath.invertlaplace(inv_lap_func, t, method='talbot')
     return inv_lap_val
예제 #4
0
# -*- coding: utf-8 -*-
"""
Created on Wed Feb  6 11:36:46 2019

@author: CatOnTour
"""

import mpmath as mp
import numpy as np
import matplotlib.pyplot as plt


def f(s):
    return 1 / (s - 1)


t = np.linspace(0.01, 10, 20)

G = []

for i in t:
    G.append(mp.invertlaplace(f, i, method='dehoog', dps=10, degree=18))

plt.plot(t, G)
plt.show()
예제 #5
0
x_RLC_func = lambdify(s, x_RLC[0])
x_RCL_func = lambdify(s, x_RCL[0])


#t = np.linspace(0.01,20,20)
t = np.linspace(0.01,20,50)

X_CLR = []
X_LCR = []
X_CRL = []
X_LRC = []
X_RLC = []
X_RCL = []

for i in t:
    X_CRL.append(mp.invertlaplace(x_CRL_func, i, method = 'dehoog', dps = 10, degree = 18))
    X_CLR.append(mp.invertlaplace(x_CLR_func, i, method = 'dehoog', dps = 10, degree = 18))
    
    X_LCR.append(mp.invertlaplace(x_LCR_func, i, method = 'dehoog', dps = 10, degree = 18))
    X_LRC.append(mp.invertlaplace(x_LRC_func, i, method = 'dehoog', dps = 10, degree = 18))
    
    X_RLC.append(mp.invertlaplace(x_RLC_func, i, method = 'dehoog', dps = 10, degree = 18))
    X_RCL.append(mp.invertlaplace(x_RCL_func, i, method = 'dehoog', dps = 10, degree = 18))


U2_func = lambdify(s,U_2)
U2_time = []
for i in t:
    U2_time.append(mp.invertlaplace(U2_func, i, method = 'dehoog', dps = 10, degree = 18))

plt.plot(t, U2_time, "k", label = "U2")
예제 #6
0
x_P_func = lambdify(s, x_P[0])
x_B_func = lambdify(s, x_B[0])

#t = np.linspace(0.01,20,20)
t = np.linspace(0.01, 20, 50)

X_A = []
X_Z = []
X_Y = []
X_H = []
X_P = []
X_B = []

for i in t:
    X_A.append(
        mp.invertlaplace(x_A_func, i, method='dehoog', dps=10, degree=18))
    X_Z.append(
        mp.invertlaplace(x_Z_func, i, method='dehoog', dps=10, degree=18))
    X_Y.append(
        mp.invertlaplace(x_Y_func, i, method='dehoog', dps=10, degree=18))
    X_H.append(
        mp.invertlaplace(x_H_func, i, method='dehoog', dps=10, degree=18))
    X_P.append(
        mp.invertlaplace(x_P_func, i, method='dehoog', dps=10, degree=18))
    X_B.append(
        mp.invertlaplace(x_B_func, i, method='dehoog', dps=10, degree=18))

x_21_func = lambdify(s, x_21)
x_21_time = []
for i in t:
    x_21_time.append(
예제 #7
0
def G(y, x_0, tau, b, a, beta):
    return float(
        invertlaplace(lambda s: Laplace_Transform_G(y, x_0, s, b, a, beta),
                      tau,
                      method='dehoog',
                      dps=10))
예제 #8
0
파일: zad.py 프로젝트: RahimFatih/SPC

def F(s):
    a = 1
    b = 2

    return 1 / (s * (s * s + a * s + b))


start = 0.01
end = 20
step = 0.1
no = (end - start) / step

t = np.linspace(start, end, int(no))

y = []

for i in range(0, len(t)):
    y.append(mp.invertlaplace(F, t[i], method='dehoog'))

#print(t)
#print(y)

fig_reg1, axs_reg1 = plt.subplots()
axs_reg1.plot(t, y, color='black', alpha=0.7)
axs_reg1.set_xlabel(r'$t$', fontsize=30)
axs_reg1.set_ylabel(r'$y$', fontsize=30)
axs_reg1.grid(True)

plt.show()
예제 #9
0
    def visco_template(self, method_class, model_class, region):
        # region.plot()
        # plt.show()
        data = region.all_points

        model = model_class(region=region)

        method = method_class(model=model, basis=quadratic_2d)
        # cache_path = "result.npy"
        # if os.path.exists(cache_path):
        #     result = np.load(cache_path)
        # else:
        #     result = method.solve()
        #     np.save(cache_path, result)
        result = method.solve()
        print("result", result)

        def nearest_indices(t):
            print(".", end="")
            return np.abs(model.s - t).argmin()

        fts = np.array([[
            mp.invertlaplace(lambda t: result[nearest_indices(t)][i][0],
                             x,
                             method='stehfest',
                             degree=model.iterations)
            for x in range(1, model.time + 1)
        ] for i in range(result.shape[1])],
                       dtype=np.float64)

        for point_index, point in enumerate(data):
            analytical_x = num.Function(model.analytical[0],
                                        name="analytical ux(%s)").eval(
                                            point)[::model.iterations].ravel()
            analytical_y = num.Function(model.analytical[1],
                                        name="analytical uy(%s)").eval(
                                            point)[::model.iterations].ravel()
            calculated_x = fts[2 * point_index].ravel()
            calculated_y = fts[2 * point_index + 1].ravel()
            print('point', point)
            print('calculated_x, point diff, analytical', [
                calculated_x,
                np.diff(calculated_x),
                analytical_x,
            ])
            print('calculated_y', calculated_y)

            plt.plot(point[0], point[1], "r^-")
            plt.plot(point[0] + np.diff(calculated_x),
                     point[1] + np.diff(calculated_y), "b^-")
            plt.plot(point[0] + analytical_x, point[1] + analytical_y, "gs-")

        region.plot()
        plt.show()

        for point_index, point in enumerate(data):
            analytical_x = num.Function(model.analytical[0],
                                        name="analytical ux(%s)").eval(
                                            point)[::model.iterations].ravel()
            calculated_x = fts[2 * point_index].ravel()
            print(point)
            t = np.arange(0.5, calculated_x.size - 1)
            # plt.plot(t, 1.5*np.diff(np.diff(calculated_x))[0]+np.diff(calculated_x), "b^-")
            plt.plot(calculated_x, "r^-")
            # plt.plot(np.diff(calculated_x), "b^-")
            plt.plot(analytical_x, "gs-")
            plt.show()