def TaskSetup(timestep):
    """Setup the task."""

    vd_r = LinearVertexDistribution(
        int((r_out_domain - r_in_domain) * grid_division_r) + 1)
    vd_phi = LinearVertexDistribution(int(phi_domain * grid_division_phi) + 1)

    p0 = (r_in_domain, Qty('0deg'))
    p1 = (r_out_domain, phi_domain)

    grid = GridPatchPolar(p0, p1, vd_r, vd_phi)

    grid.SetMaterial(
        Rectangle((r_in_iron, Qty("0deg")), (r_out_iron, phi_domain)), mat)

    potential_out = flux_density * (r_out_iron - r_in_iron)

    grid.west_boundary.SetBoundaryCondition(
        DirichletCondition(lambda position, time: potential_out * sin(
            2. * pi * (time * frequency))))
    grid.east_boundary.SetBoundaryCondition(DirichletCondition())

    grid_compiler = GridCompiler(grid)

    return grid_compiler(timestep)
Exemple #2
0
def TaskSetup():
    """Setup the task."""

    ndx = LinearVertexDistribution(int(domain_width * grid_division) + 1)
    ndy = LinearVertexDistribution(int(domain_height * grid_division) + 1)

    p0 = (Qty('0m'), Qty('0m'))
    p1 = (domain_width, domain_height)

    grid = GridPatchCartesian(p0, p1, ndx, ndy)

    grid.SetLoad(c_geo.Rectangle(coil1_llc, coil_dim_x, coil_dim_y),
                 current_density)
    grid.SetLoad(c_geo.Rectangle(coil2_llc, coil_dim_x, coil_dim_y),
                 -current_density)

    grid.SetMaterial(
        c_geo.Rectangle(iron1_llc, iron_width, iron1_height + .1 * iron_width),
        mat)
    grid.SetMaterial(c_geo.Rectangle(iron2_llc, iron2_width, iron_width), mat)

    dbc = DirichletCondition()

    grid.north_boundary.SetBoundaryCondition(dbc)
    grid.east_boundary.SetBoundaryCondition(dbc)

    grid_compiler = GridCompiler(grid)

    return grid_compiler()
Exemple #3
0
def TaskSetup():
    # Grid definitions

    gp1_width = gp1_urc[0] - gp1_llc[0]
    gp1_height = gp1_urc[1] - gp1_llc[1]
    gp1_ndx = LinearVertexDistribution(int(gp1_width * grid_division) + 1)
    gp1_ndy = LinearVertexDistribution(int(gp1_height * grid_division) + 1)
    gp1 = GridPatchCartesian(gp1_llc, gp1_urc, gp1_ndx, gp1_ndy)

    gp2_nd_phi = LinearVertexDistribution(30)
    gp2 = GridPatchPolar(gp2_llc, gp2_urc, gp1_ndx, gp2_nd_phi)

    gp3_ndx = LinearVertexDistribution(int(iron_len_2 * grid_division) + 1)
    gp3 = GridPatchCartesian(gp3_llc, gp3_urc, gp3_ndx, gp1_ndx)

    # Grid couplings
    gp2.south_boundary.SetBoundaryCoupling(gp1.north_boundary)
    gp3.east_boundary.SetBoundaryCoupling(gp2.north_boundary)

    # Boundary condition
    bc_dc0 = DirichletCondition()
    gp1.east_boundary.SetBoundaryCondition(bc_dc0)
    gp2.east_boundary.SetBoundaryCondition(bc_dc0)
    gp3.north_boundary.SetBoundaryCondition(bc_dc0)
    gp3.south_boundary.SetBoundaryCondition(bc_dc0)

    # Load definition
    a_amplitude = peak_flux_density * iron_width
    bc_source_field = DirichletCondition(
        lambda pos, t: a_amplitude * cos(2 * pi * (frequency * t)))
    gp1.west_boundary.SetBoundaryCondition(bc_source_field)
    gp2.west_boundary.SetBoundaryCondition(bc_source_field)
    gp3.south_boundary.SetBoundaryCondition(bc_source_field)

    # Material definition
    gp1.SetMaterial(
        c_geo.Rectangle((iron_r_in, -iron_len_1), iron_width, iron_len_1),
        mat1)
    gp2.SetMaterial(
        p_geo.Rectangle((iron_r_in, Qty("0rad")), iron_width,
                        Qty(pi / 2, "rad")), mat1)
    gp3.SetMaterial(
        c_geo.Rectangle((-iron_len_2, iron_r_in), iron_len_2 * 1.1,
                        iron_width), mat2)

    grid_assembly = GridAssembly([gp1, gp2, gp3])
    grid_compiler = GridCompiler(grid_assembly)

    return grid_compiler(time_step)
    def target_func(b):
        b = Qty(b, "T")
        reluct = mat.EvaluateReluctivity(b, Axis.first)[0]

        return (reluct*b
                -current_density*coil_area/average_iron_path_length
        ).to_base_units().magnitude
Exemple #5
0
def AnalyticalSolution(radius):
    I = Qty(2*pi, "rad")/domain_phi*current
    J1 = I/r1/r1/pi
    mu0 = Qty(1., "mu_0")

    A1 = lambda r: mu0*J1/4.*r*r
    A2 = lambda r: mu0*J1*r1*r1/2*(.5+log(r/r1))
    A3 = lambda r: mu0*J1*r1*r1/2*(
        .5+log(r2/r1)+log(r/r2)*(1+r2*r2/(r3*r3-r2*r2))+(
        r2*r2-r*r)/(2.*(r3*r3-r2*r2)))

    A0 = A3(r3)

    if radius <= r1:
        return A0-A1(radius)
    elif radius > r1 and radius <= r2:
        return A0-A2(radius)
    elif radius > r2 and radius <= r3:
        return A0-A3(radius)
    else:
        return A0-A3(r3)
Exemple #6
0
def PlotMaterialCharaceristic():
    """Plot the material's characteristic."""

    mu0 = Qty(1., "mu0").inBaseUnits()
    nu0 = 1. / mu0

    brange = [Qty(x, "T") for x in sp.arange(.2, 3.8, .02)]
    nurange = [mat.EvaluateReluctivity1(x)[0] for x in brange]
    diff_nu = [mat.EvaluateReluctivity1(x)[1] for x in brange]

    plt.subplot(2, 1, 1)
    plt.semilogy([x.getValue() for x in brange],
                 [y.getValue() for y in nurange],
                 label="Interp. Data")

    m400_50A_B = [x[1] + mu0 * x[0] for x in sp.c_[m400_50A_H, m400_50A_J]]
    m400_50A_nu = [
        x[0] / (x[1] + mu0 * x[0]) for x in sp.c_[m400_50A_H, m400_50A_J]
    ]
    nu_eff = [
        x * nu0 / (iron_fill_factor * nu0 - iron_fill_factor * x + x)
        for x in m400_50A_nu
    ]

    plt.semilogy([x.getValue() for x in m400_50A_B],
                 [y.getValue() for y in nu_eff],
                 "*",
                 label="Orig. Data")

    plt.legend(loc=2)
    plt.ylabel(u"ν*H/m")
    plt.grid()

    plt.subplot(2, 1, 2)
    plt.semilogy([x.getValue() for x in brange],
                 [y.getValue() + 200. for y in diff_nu])
    plt.xlabel("B/T")
    plt.ylabel(u"ν'*H/m + 200")
    plt.grid()
    plt.show()
Exemple #7
0
def NumericalSolution():
    nd_r = LinearVertexDistribution(51)
    nd_phi = LinearVertexDistribution(13)

    p1 = (r1/(nd_r.number_of_vertices-1), Qty("0rad"))
    p2 = (r1, domain_phi)
    gp1 = GridPatchPolar(p1, p2, nd_r, nd_phi)
    gp1.SetLoad(PRectangle(p1, p2), current)

    gp2 = GridPatchPolar(
        (r1, Qty("0rad")), (r2, domain_phi), nd_r, nd_phi)

    p3 = (r2, Qty("0rad"))
    p4 = (r3, domain_phi)
    gp3 = GridPatchPolar(p3, p4, nd_r, nd_phi)
    gp3.SetLoad(PRectangle(p3, p4), -current)

    gp4 = GridPatchPolar(
        (r3, Qty("0rad")), (r4, domain_phi), nd_r, nd_phi)
    gp4.east_boundary.SetBoundaryCondition(DirichletCondition())

    gp1.east_boundary.SetBoundaryCoupling(gp2.west_boundary)
    gp2.east_boundary.SetBoundaryCoupling(gp3.west_boundary)
    gp3.east_boundary.SetBoundaryCoupling(gp4.west_boundary)

    grid_assembly = GridAssembly( [gp1, gp2, gp3, gp4] )
    grid_compiler = GridCompiler(grid_assembly)
    grid_graph = grid_compiler()
    LinearSolve(grid_graph)

    return PathInGridGraph(
        grid_graph, ((r1/10., Qty("0m")), (r4, Qty("0m"))))
def VerifyResult():
    """Use a simple model to verify the result."""

    average_iron_path_length = (r_in_iron + r_out_iron) / 2 * phi_domain

    def target_func(b):
        b = Qty(b, "T")
        reluct = mat.EvaluateReluctivity(b, Axis.second)[0]

        return (reluct * b - current_density * coil_area /
                average_iron_path_length).to_base_units().magnitude

    def target_func_deriv(b):
        b = Qty(b, "T")
        rrd = mat.EvaluateReluctivity(b, Axis.second)

        return (rrd[0] + b * rrd[1]).to_base_units().magnitude

    return Qty(opt.newton(target_func, 1., target_func_deriv), "T")
Exemple #9
0
def VerifyResult():
    """Use a simple model to verify the result."""

    average_iron_path_length = (coil_dim_x + 2 * coil_space_side + iron_width +
                                coil_dim_y + coil_space_top)

    def target_func(b):
        b = Qty(b, "T")
        reluct = mat.EvaluateReluctivity(b, Axis.first)[0]

        return (reluct * b - current_density * coil_area /
                average_iron_path_length).to_base_units().magnitude

    def target_func_deriv(b):
        b = Qty(b, "T")
        rrd = mat.EvaluateReluctivity(b, Axis.first)

        return (rrd[0] + b * rrd[1]).to_base_units().magnitude

    return Qty(opt.newton(target_func, 1., target_func_deriv), "T")
Exemple #10
0
def main(options, args):
    path = NumericalSolution()

    path_x = sp.array(
        [x[0].to("m").magnitude for x in path.positions])
    num_solution = sp.array(
        [x.to("Wb/m").magnitude for x in path.potentials])
    interpolator = Spline(path_x, num_solution)
    x_values = sp.linspace(path_x[0], path_x[-1], 13)
    y_values = interpolator(x_values)
    sym_solution = sp.array(
        [AnalyticalSolution(Qty(x, "m")).to("Wb/m").magnitude
         for x in x_values])

    if options.plot:
        PlotResult(x_values, y_values, sym_solution)

    if options.filename:
        SaveData(
            options.filename,
            sp.c_[1e3*x_values, 1e6*interpolator(x_values), 1e6*sym_solution],
             ["x", "NumA", "SymA"])
def TaskSetup(time_step):
    """Setup the task."""

    ndx = LinearVertexDistribution(int(domain_width*grid_division)+1)
    ndy = LinearVertexDistribution(int(domain_height*grid_division)+1)

    p0 = (Qty('0m'), Qty('0m'))
    p1 = (domain_width, domain_height)

    grid = GridPatchCartesian(p0, p1, ndx, ndy)

    coil_llc = (iron_width+coil_space_left_side, Qty("0 m"))
    grid.SetLoad(
        c_geo.Rectangle(coil_llc, coil_dim_x, coil_dim_y),
        lambda t: current_density*sin(2*pi*(frequency*t)))

    iron_height_in = coil_dim_y + coil_space_top
    iron_width_total = (2*iron_width+ coil_space_left_side
                        +coil_space_right_side+coil_dim_x)
    iron_rects =[
        c_geo.Rectangle(
            (Qty("0m"), Qty("0m")), iron_width, iron_height_in),
        c_geo.Rectangle(
            (iron_width+coil_dim_x+coil_space_left_side
             +coil_space_right_side, Qty("0m")), iron_width, iron_height_in),
        c_geo.Rectangle(
            (Qty("0m"), iron_height_in), iron_width_total, iron_width)]

    for rect in iron_rects:
        grid.SetMaterial(rect, mat)

    dbc = DirichletCondition()

    grid.west_boundary.SetBoundaryCondition(dbc)
    grid.north_boundary.SetBoundaryCondition(dbc)
    grid.east_boundary.SetBoundaryCondition(dbc)

    grid_compiler = GridCompiler(grid)

    return grid_compiler(time_step)
Exemple #12
0
from ulphi import Qty
from ulphi.geometry import cartesian as c_geo
from ulphi.analysis.magnetostatic import *
from ulphi.materials import Material, ComboReluctivityFluxPar, ConstantReluctivity, SplineReluctivity as NonlinearReluctivity, Axis
import scipy as sp
from scipy import interpolate as ip
from scipy import optimize as opt
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import csv
from optparse import OptionParser

### Parameters

# Geometry
domain_depth = Qty(3., "cm")
coil_dim_x = Qty(5., "mm")
coil_dim_y = Qty(2.4, "cm")
coil_area = coil_dim_x * coil_dim_y
iron_width = Qty(2.5, "cm")
coil_space_top = Qty(5., "mm")
coil_space_side = Qty(5., "mm")
coil1_llc = (coil_space_side, Qty("0 m"))
coil2_llc = (3 * coil_space_side + iron_width + coil_dim_x, Qty('0m'))
iron1_llc = (2 * coil_space_side + coil_dim_x, Qty('0m'))
iron1_height = coil_dim_y + coil_space_top
iron2_llc = (Qty('0m'), coil_dim_y + coil_space_top)
iron2_width = 2 * coil_space_side + coil_dim_x + iron_width
domain_height = coil_dim_y + coil_space_top + 2 * iron_width
domain_width = 3 * coil_space_side + 2 * coil_dim_x + 2 * iron_width
grid_division = Qty(20, "1/cm")
Exemple #13
0
# <http://www.gnu.org/licenses/>.
#

from ulphi import Qty
from ulphi.geometry.polar import Rectangle as PRectangle
from ulphi.analysis.magnetostatic import *
import scipy as sp
from scipy.interpolate import InterpolatedUnivariateSpline as Spline
import matplotlib.pyplot as plt
from math import pi, log
import csv
from optparse import OptionParser


# outer radius inner conductor
r1 = Qty(5., "mm")
# inner radius outer conductor
r2 = 2.5*r1
# outer radius outer conductor
r3 = 3.5*r1
# outer domain radius
r4 = 4*r1
# angle
domain_phi = Qty(pi/8, "rad")

current = Qty(16, "A")


def PlotResult(x, y1, y2):
    plt.plot(x*1e3, y1*1e6, label="num. solution")
    plt.plot(x*1e3, y2*1e6, label="sym. solution")
from ulphi.materials import Material, ComboReluctivityFluxPar, ConstantReluctivity, SplineReluctivity as NonlinearReluctivity, Axis
import scipy as sp
from scipy import interpolate as ip
from scipy import optimize as opt
from scipy.fftpack import fft, fftshift
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import csv
from optparse import OptionParser
from math import pi, sin


### Parameters

# Geometry
domain_depth = Qty(3., "cm")
air_surround = Qty(2., "cm")
coil_dim_x = Qty(10., "mm")
coil_dim_y = Qty(4, "cm")
coil_area = coil_dim_x*coil_dim_y
iron_width = Qty(2., "cm")
coil_space_top = Qty(5., "mm")
coil_space_left_side = Qty(3., "mm")
coil_space_right_side = Qty(7., "mm")
domain_height = coil_dim_y+coil_space_top+iron_width+air_surround
domain_width = (2*iron_width+coil_dim_x+coil_space_left_side
                +coil_space_right_side+air_surround)
grid_division = Qty(12, "1/cm")

# Electro - magnetic
current_density = Qty(2.5, 'MA/m**2')
    def target_func_deriv(b):
        b = Qty(b, "T")
        rrd = mat.EvaluateReluctivity(b, Axis.second)

        return (rrd[0] + b * rrd[1]).to_base_units().magnitude
from ulphi.geometry.polar import *
from ulphi.analysis.magnetostatic import *
from ulphi.materials import Material, ComboReluctivityFluxPar, ComboReluctivityFluxPerp, ConstantReluctivity, SplineReluctivity as NonlinearReluctivity, Axis
from math import pi, sin
import scipy as sp
from scipy import interpolate as ip
from scipy import optimize as opt
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import csv
from optparse import OptionParser

### Parameters

# Geometry
r_in_iron = Qty("9cm")
r_out_iron = Qty("12cm")
r_in_domain = r_in_iron - Qty("5mm")
r_out_domain = r_out_iron + Qty("5mm")
phi_domain = Qty("90deg")
grid_division_r = Qty(24, "1/cm")
grid_division_phi = Qty(.1, "1/deg")

# Electro - magnetic
flux_density = Qty("1.65T")
frequency = Qty("50Hz")
m400_50A_H = [
    Qty(x, 'A/m') for x in [
        75., 84., 93., 104., 117., 134., 159., 199., 282., 505., 1284., 3343.,
        6787., 11712., 19044
    ]
Exemple #17
0
from ulphi.geometry import polar as p_geo
from ulphi.analysis.magnetostatic import *
from ulphi.materials import *
from math import pi, sin, cos

import scipy as sp
from scipy import interpolate as ip
from scipy import optimize as opt
from scipy.fftpack import fft, fftshift
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from optparse import OptionParser
import csv

# Geometry
iron_r_in = Qty(1., "cm")
iron_width = Qty(2.2, "cm")
iron_len_1 = Qty(5., "cm")
iron_len_2 = Qty(3., "cm")
space_out = 1 * iron_width
grid_division = Qty(15, "1/cm")

gp1_llc = (iron_r_in / 2., -iron_len_1)
gp1_urc = (iron_r_in + iron_width + space_out, Qty("0m"))
gp2_llc = (iron_r_in / 2., Qty("0 rad"))
gp2_urc = (iron_r_in + iron_width + space_out, Qty("90deg"))
gp3_llc = (-iron_len_2, iron_r_in / 2)
gp3_urc = (Qty("0m"), iron_r_in + iron_width + space_out)

# Electro - magnetic
peak_flux_density = Qty(1.85, "T")