示例#1
0
def chart(x, y, xlabel="", ylabel="", marker='o'):
    import pylab as pl

    fig = pl.figure()
    pl.plot(x, y, marker)
    pl.grid(True)
    pl.xlabel(xlabel)
    pl.ylabel(ylabel)
    fn_chart = pythonlab.tempname("png")
    pl.savefig(fn_chart, dpi=60)
    pl.clf()
    pl.close(fig)

    # show in console
    pythonlab.image(fn_chart)
示例#2
0
def chart(x, y, xlabel = "", ylabel = ""):
    import pylab as pl

    fig = pl.figure()
    pl.plot(x, y)
    pl.grid(True)
    pl.xlabel(xlabel)
    pl.ylabel(ylabel)
    fn_chart = pythonlab.tempname("png")
    pl.savefig(fn_chart, dpi=60)
    pl.clf()
    pl.close(fig)
    
    # show in console
    pythonlab.image(fn_chart)
示例#3
0
def analyse_matrix_and_rhs(filename_matrix, filename_rhs):  
    # read matrix and rhs from file
    mat_object = sio.loadmat(filename_matrix)
    matrix = mat_object["matrix"]
    rhs_object = sio.loadmat(filename_rhs)
    rhs = rhs_object["rhs"]
    
    # size of the matrix
    print("Matrix size: " + str(len(rhs)))
    print("Number of nonzeros: " + str(matrix.getnnz()) + " (" + str(round(float(matrix.getnnz()) / (len(rhs)**2) * 100.0, 3)) + " %)")
    
    # visualize matrix sparsity pattern
    fig = pl.figure()
    pl.spy(matrix, markersize=1)
    fn_pattern = pythonlab.tempname("png")
    pl.savefig(fn_pattern, dpi=60)
    pl.close(fig)   
    # show in console
    pythonlab.image(fn_pattern)
示例#4
0
def analyse_matrix_and_rhs(filename_matrix, filename_rhs):
    # read matrix and rhs from file
    mat_object = sio.loadmat(filename_matrix)
    matrix = mat_object["matrix"]
    rhs_object = sio.loadmat(filename_rhs)
    rhs = rhs_object["rhs"]

    # size of the matrix
    print("Matrix size: " + str(len(rhs)))
    print("Number of nonzeros: " + str(matrix.getnnz()) + " (" +
          str(round(float(matrix.getnnz()) /
                    (len(rhs)**2) * 100.0, 3)) + " %)")

    # visualize matrix sparsity pattern
    fig = pl.figure()
    pl.spy(matrix, markersize=1)
    fn_pattern = pythonlab.tempname("png")
    pl.savefig(fn_pattern, dpi=60)
    pl.close(fig)
    # show in console
    pythonlab.image(fn_pattern)
示例#5
0
geometry.add_label(0.0284191, 0.123601, materials={"electrostatic": "Air"})
a2d.view.zoom_best_fit()

# calculation of capacity
r = []
C = []
print("C = f(r) (F):")
for i in range(15):
    if i > 0:
        geometry.select_edges([6, 7, 8])
        geometry.move_selection(dr, 0, False)

    problem.solve()
    result = electrostatic.volume_integrals([0, 1, 2])
    r.append(r1 + (i * dr))
    C.append(2 * 2 * result["We"] / (U ^ 2))
    print(r[-1], C[-1])

# chart
pl.close()
pl.plot(r, C)
pl.grid(True)
pl.xlabel("r (m)")
pl.ylabel("C (F)")
fn_chart = pythonlab.tempname("png")
pl.savefig(fn_chart, dpi=60)
pl.close()

# show in console
pythonlab.image(fn_chart)
示例#6
0
f4 = interpolate.interp1d(x, y, kind="nearest")
y4 = f4(xi)

pl.figure()
pl.subplot(2, 2, 1)
pl.plot(x, y, '.k', label="original data")
pl.plot(xi, y1, label="linear spline interpolation")
pl.title(r"linear")

pl.subplot(2, 2, 2)
pl.plot(x, y, '.k', label="original data")
pl.plot(xi, y2, label="quadratic spline interpolation")
pl.title(r"quadratic")

pl.subplot(2, 2, 3)
pl.plot(x, y, '.k', label="original data")
pl.plot(xi, y3, label="cubic spline interpolation")
pl.title(r"cubic")

pl.subplot(2, 2, 4)
pl.plot(x, y, '.k', label="original data")
pl.plot(xi, y4, label="nearest interpolation")
pl.title(r"nearest")

chart_file = pythonlab.tempname("png")
pl.savefig(chart_file, dpi=60)
pl.close()

pythonlab.image(chart_file)
示例#7
0
geometry.add_label(0.0284191, 0.123601, materials = {"electrostatic" : "Air"})
a2d.view.zoom_best_fit()

# calculation of capacity
r = []
C = []
print("C = f(r) (F):")
for i in range(15):
	if i > 0:
		geometry.select_edges([6, 7, 8])
		geometry.move_selection(dr, 0, False)

	problem.solve()
	result = electrostatic.volume_integrals([0, 1, 2])
	r.append(r1 + (i*dr))
	C.append(2*2*result["We"]/(U^2))
	print(r[-1], C[-1])

# chart
pl.close()
pl.plot(r, C)
pl.grid(True)
pl.xlabel("r (m)")
pl.ylabel("C (F)")
fn_chart = pythonlab.tempname("png")
pl.savefig(fn_chart, dpi=60)
pl.close()

# show in console
pythonlab.image(fn_chart)
示例#8
0
# static characteristic
pl.close()
pl.figure(figsize = [8, 5])
pl.plot(phi, T_magnetic_torque, 'b', label="0.0 A")
pl.plot(phi, T_torque, 'r', label="0.8 A")
pl.plot([0, 180], [0, 0], '--k')
pl.xlabel("phi (deg.)")
pl.ylabel("T (Nm)")
pl.legend(loc="lower right")
fn_chart_static = pythonlab.tempname("png")
pl.savefig(fn_chart_static, dpi=60)
pl.close()

# show in console
pythonlab.image(fn_chart_static)

J = 7.5e-5;
k = 2e-4
T_f = interp1d(phi, T_torque, kind = "linear")

def func(x, t):      
   dx = [0., 0.]
   dx[0] = x[1] 
   dx[1] = (- T_f((x[0]*180/np.pi) % 180) - k*x[1]) * 1/J       
   return dx
   
x0 = [np.pi/6, 0]
time = np.linspace(0, 2, 1000)
y = odeint(func, x0, time) 
示例#9
0
    #     magnetic.modify_material("Coil +", {"magnetic_current_density_external_real" : -Jext})
    #     magnetic.modify_material("Coil -", {"magnetic_current_density_external_real" : Jext})

phiT = []
T = []
for i in range(N - 1):
    phiT.append((phiWm[i + 1] + phiWm[i]) / 2.0)
    T.append((Wm[i + 1] - Wm[i]) / (phiWm[i + 1] - phiWm[i]))

import pylab as pl

pl.plot(phiWm, Wm)
pl.xlabel("phi (deg.)")
pl.ylabel("Wm (J)")
fn_energy = pythonlab.tempname("png")
pl.savefig(fn_energy, dpi=60)
pl.close()

# show in console
pythonlab.image(fn_energy)

pl.plot(phiT, T)
pl.xlabel("phi (deg.)")
pl.ylabel("T (Nm)")
fn_torque = pythonlab.tempname("png")
pl.savefig(fn_torque, dpi=60)
pl.close()

# show in console
pythonlab.image(fn_torque)
示例#10
0
import pythonlab
from numpy import arange
from scipy.integrate import odeint
import pylab as pl

R = 1e3
L = 1e-3
U0 = 10

# initial condition
y0 = [0]

def func(y, t):
    return [- R/L*y[0] + U0/L]

t = arange(0, 5*L/R, L/R/10)
y = odeint(func, y0, t)

# chart
pl.plot(t, y)
pl.grid(True)
pl.xlabel("$t\,\mathrm{(s)}$")
pl.ylabel("$i\,\mathrm{(A)}$")
fn_diff_equation = pythonlab.tempname("png")
pl.savefig(fn_diff_equation, dpi=60)
pl.close()

# show in console
pythonlab.image(fn_diff_equation)
示例#11
0

# solve model
model()

fn_geometry = pythonlab.tempname("vtk")
a2d.geometry.export_vtk(fn_geometry)
geometry = a2d.vtk_geometry_actor(fn_geometry)

fn_contour = pythonlab.tempname("vtk")
a2d.view.post2d.contour_view_parameters["variable"] = "electrostatic_potential"
a2d.view.post2d.export_contour_vtk(fn_contour)
contours = a2d.vtk_contours_actor(fn_contour, count=15, color=False)

fn_scalar = pythonlab.tempname("vtk")
a2d.view.post2d.scalar_view_parameters[
    "variable"] = "electrostatic_electric_field"
a2d.view.post2d.scalar_view_parameters["component"] = "magnitude"
a2d.view.post2d.export_scalar_vtk(fn_scalar)
scalar = a2d.vtk_scalar_actor(fn_scalar)

fn = pythonlab.tempname("png")
a2d.vtk_figure(output_filename=fn,
               geometry=geometry,
               contours=contours,
               scalar=scalar,
               scalar_colorbar=True,
               width=500,
               height=300)
pythonlab.image(fn)
示例#12
0
f4 = interpolate.interp1d(x, y, kind = "nearest")
y4 = f4(xi)

pl.figure()
pl.subplot(2,2,1)
pl.plot(x, y, '.k', label="original data")
pl.plot(xi, y1, label="linear spline interpolation")
pl.title(r"linear")

pl.subplot(2,2,2)
pl.plot(x, y, '.k', label="original data")
pl.plot(xi, y2, label="quadratic spline interpolation")
pl.title(r"quadratic")

pl.subplot(2,2,3)
pl.plot(x, y, '.k', label="original data")
pl.plot(xi, y3, label="cubic spline interpolation")
pl.title(r"cubic")

pl.subplot(2,2,4)
pl.plot(x, y, '.k', label="original data")
pl.plot(xi, y4, label="nearest interpolation")
pl.title(r"nearest")

chart_file = pythonlab.tempname("png")
pl.savefig(chart_file, dpi=60)
pl.close()

pythonlab.image(chart_file)
示例#13
0
from numpy import arange
from scipy.integrate import odeint
import pylab as pl

R = 1e3
L = 1e-3
U0 = 10

# initial condition
y0 = [0]


def func(y, t):
    return [-R / L * y[0] + U0 / L]


t = arange(0, 5 * L / R, L / R / 10)
y = odeint(func, y0, t)

# chart
pl.plot(t, y)
pl.grid(True)
pl.xlabel("$t\,\mathrm{(s)}$")
pl.ylabel("$i\,\mathrm{(A)}$")
fn_diff_equation = pythonlab.tempname("png")
pl.savefig(fn_diff_equation, dpi=60)
pl.close()

# show in console
pythonlab.image(fn_diff_equation)
示例#14
0
geometry.add_label(0.00380689, 0.151055, materials={"heat": "Air"})
geometry.add_label(0.0112064, 0.0336487, materials={"heat": "Brass"})

a2d.view.zoom_best_fit()
problem.solve()

# current
pl.figure(figsize=[8, 3])
pl.bar(total_time, current, width=problem.time_total / problem.time_steps)
pl.xlabel("time (s)")
pl.ylabel("current (A)")
pl.grid(True)

chart_current = pythonlab.tempname("png")
pl.savefig(chart_current, dpi=60)
pl.close()

pythonlab.image(chart_current)

# temperature
pl.figure(figsize=[8, 3])
pl.plot(total_time, temp, '-')
pl.xlabel("time (s)")
pl.ylabel("temperature (K)")
pl.grid(True)

chart_temp = pythonlab.tempname("png")
pl.savefig(chart_temp, dpi=60)
pl.close()

pythonlab.image(chart_temp)
示例#15
0
import pythonlab
from numpy import arange
from scipy.integrate import odeint
import pylab as pl

R = 1e3
L = 1e-3
U0 = 10

# initial condition
y0 = [0]

def func(y, t):
    return [- R/L*y[0] + U0/L]

t = arange(0, 5*L/R, L/R/10)
y = odeint(func, y0, t)

# chart
pl.close()
pl.plot(t, y)
pl.grid(1)
pl.xlabel("$t\,\mathrm{(s)}$")
pl.ylabel("$i\,\mathrm{(A)}$")
pl.show()
pl.savefig("diff_equation.png", dpi=60)
pl.close()

# show in console
pythonlab.image("diff_equation.png")
geometry.add_label(0.00380689, 0.151055, materials = {"heat" : "Air"})
geometry.add_label(0.0112064, 0.0336487, materials = {"heat" : "Brass"})

a2d.view.zoom_best_fit()
problem.solve()

# current
pl.figure(figsize=[8,3])
pl.bar(total_time, current, width = problem.time_total / problem.time_steps)
pl.xlabel("time (s)")
pl.ylabel("current (A)")
pl.grid(True)

chart_current = pythonlab.tempname("png")
pl.savefig(chart_current, dpi=60)
pl.close()

pythonlab.image(chart_current)

# temperature
pl.figure(figsize=[8,3])
pl.plot(total_time, temp, '-')
pl.xlabel("time (s)")
pl.ylabel("temperature (K)")
pl.grid(True)

chart_temp = pythonlab.tempname("png")
pl.savefig(chart_temp, dpi=60)
pl.close()

pythonlab.image(chart_temp)
示例#17
0
    a2d.view.zoom_best_fit()
    problem.solve()

# solve model
model()

fn_geometry = pythonlab.tempname("vtk")
a2d.geometry.export_vtk(fn_geometry)
geometry = a2d.vtk_geometry_actor(fn_geometry)

fn_contour = pythonlab.tempname("vtk")
a2d.view.post2d.contour_view_parameters["variable"] = "electrostatic_potential"
a2d.view.post2d.export_contour_vtk(fn_contour)
contours = a2d.vtk_contours_actor(fn_contour, count = 15, color = False)

fn_scalar = pythonlab.tempname("vtk")
a2d.view.post2d.scalar_view_parameters["variable"] = "electrostatic_electric_field"
a2d.view.post2d.scalar_view_parameters["component"] = "magnitude"
a2d.view.post2d.export_scalar_vtk(fn_scalar)
scalar = a2d.vtk_scalar_actor(fn_scalar)

fn = pythonlab.tempname("png")
a2d.vtk_figure(output_filename = fn, 
               geometry = geometry,
               contours = contours,
               scalar = scalar,
               scalar_colorbar = True, 
               width = 500, 
               height = 300)
pythonlab.image(fn)