Exemple #1
0
def GetAz(Bx, By, Jz, Nc, dl):

    mesh = Grid2D(dx=dl[0], dy=dl[1], nx=Nc[0], ny=Nc[1])

    _Az = CellVariable(mesh=mesh, value=0.0)

    _Bx = CellVariable(mesh=mesh)
    _Bx.value = np.reshape(Bx, Nc[0] * Nc[1], order='F')

    _By = CellVariable(mesh=mesh)
    _By.value = np.reshape(By, Nc[0] * Nc[1], order='F')

    _Jz = CellVariable(mesh=mesh)
    _Jz.value = np.reshape(Jz, Nc[0] * Nc[1], order='F')

    _Az.equation = (DiffusionTerm(coeff=1.0) + _Jz == 0)

    # beware of the sign of the flux : always consider outward direction
    BCs = [
        FixedFlux(value=_By.getFaceValue(), faces=mesh.getFacesLeft()),
        FixedFlux(value=-_By.getFaceValue(), faces=mesh.getFacesRight()),
        FixedFlux(value=-_Bx.getFaceValue(), faces=mesh.getFacesBottom()),
        FixedFlux(value=_Bx.getFaceValue(), faces=mesh.getFacesTop())
    ]

    _Az.equation.solve(var=_Az, boundaryConditions=BCs)

    Az = np.reshape(_Az.value, Nc, order='F')

    return Az
Exemple #2
0
def GetAz(Bx, By, Jz, Nc, dl):

    mesh = Grid2D(dx=dl[0], dy=dl[1], nx=Nc[0], ny=Nc[1])

    _Az = CellVariable(mesh=mesh, value=0.0)

    _Bx = CellVariable(mesh=mesh)
    _Bx.value = np.reshape(Bx, Nc[0] * Nc[1], order='F')

    _By = CellVariable(mesh=mesh)
    _By.value = np.reshape(By, Nc[0] * Nc[1], order='F')

    _Jz = CellVariable(mesh=mesh)
    _Jz.value = np.reshape(Jz, Nc[0] * Nc[1], order='F')

    _Az.equation = (DiffusionTerm(coeff=1.0) + _Jz == 0)

    #diffcoeff = CellVariable(mesh=mesh, value = 1.0)
    #diffTerm = DiffusionTerm(coeff = diffcoeff)
    #diffTerm = DiffusionTerm(coeff = 1.0)
    #diffcoeff.constrain(0., mesh.exteriorFaces)

    # beware of the sign of the flux : always consider outward direction
    _Az.faceGrad.constrain(_By.arithmeticFaceValue, where=mesh.facesLeft)
    _Az.faceGrad.constrain(-_By.arithmeticFaceValue, where=mesh.facesRight)
    _Az.faceGrad.constrain(-_Bx.arithmeticFaceValue, where=mesh.facesBottom)
    _Az.faceGrad.constrain(_Bx.arithmeticFaceValue, where=mesh.facesTop)

    #_Az.faceGrad.constrain( _By.arithmeticFaceValue[mesh.facesLeft] , where=mesh.facesLeft)
    #_Az.faceGrad.constrain(-_By.arithmeticFaceValue[mesh.facesRight] , where=mesh.facesRight)
    #_Az.faceGrad.constrain(-_Bx.arithmeticFaceValue[mesh.facesBottom] , where=mesh.facesBottom)
    #_Az.faceGrad.constrain( _Bx.arithmeticFaceValue[mesh.facesTop] , where=mesh.facesTop)

    #_Az.equation = (diffTerm+_Jz == 0)
    #_Az.equation = (DiffusionTerm(diffcoeff)+ (mesh.exteriorFaces*exteriorFlux).divergence + _Jz== 0)
    #_Az.equation = (diffTerm + _Jz == 0)

    #BCs = [FixedFlux(value= _By.getFaceValue(), faces=mesh.getFacesLeft()),
    #       FixedFlux(value=-_By.getFaceValue(), faces=mesh.getFacesRight()),
    #       FixedFlux(value=-_Bx.getFaceValue(), faces=mesh.getFacesBottom()),
    #       FixedFlux(value= _Bx.getFaceValue(), faces=mesh.getFacesTop())]

    #_Az.equation.solve(var=_Az, boundaryConditions=BCs)
    _Az.equation.solve(var=_Az)

    Az = np.reshape(_Az.value, Nc, order='F')

    return Az
Exemple #3
0
Pion = CellVariable(mesh=mesh,
                    name='Positive ion Charge Density',
                    value=y01(mesh.x))
Nion = CellVariable(mesh=mesh,
                    name='Negative ion Charge Density',
                    value=y02(mesh.x))
potential = CellVariable(mesh=mesh, name='Potential', value=y03(mesh.x))
Jp = CellVariable(mesh=mesh, name='Positive ion Current Density', value=0.)
Jn = CellVariable(mesh=mesh, name='Negative ion Current Density', value=0.)

Jp.value = -mu_p * Pion * potential.arithmeticFaceValue.divergence + Dn * Pion.arithmeticFaceValue.divergence
Jn.value = -mu_n * Nion * potential.arithmeticFaceValue.divergence + Dn * Pion.arithmeticFaceValue.divergence

Pion.equation = TransientTerm(
    coeff=1,
    var=Pion) == -k_rec * Pion * Nion + (Jp.arithmeticFaceValue).divergence
Nion.equation = TransientTerm(
    coeff=1,
    var=Nion) == -k_rec * Pion * Nion - (Jn.arithmeticFaceValue).divergence
potential.equation = DiffusionTerm(coeff=epsilon, var=potential) == Pion - Nion

Pion.constrain(0., where=mesh.facesLeft)
Pion.constrain(0., where=mesh.facesRight)
Nion.constrain(0., where=mesh.facesLeft)
Nion.constrain(0., where=mesh.facesRight)
potential.constrain(0., where=mesh.facesLeft)
potential.constrain(0., where=mesh.facesRight)

eq = Pion.equation & Nion.equation & potential.equation
'''Equations to solve for each varible must be defined:
  -TransientTerm = dvar/dt
  -ConvectionTerm = dvar/dx
  -DiffusionTerm = d^2var/dx^2
  -Source terms can be described as they would appear mathematically
Notes:  coeff = terms that are multiplied by the Term.. must be rank-1 FaceVariable for ConvectionTerm
        "var" must be defined for each Term if they are not all the variable being solved for,
        otherwise will see "fipy.terms.ExplicitVariableError: Terms with explicit Variables cannot mix with Terms with implicit Variables." '''

#In English:  dPion/dt = -1/q * divergence.Jp(x,t) - k_rec * Nion(x,t) * Pion(x,t) where
#             Jp = q * mu_p * E(x,t) * Pion(x,t) - q * Dp * grad.Pion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation

Pion.equation = TransientTerm(
    coeff=1,
    var=Pion) == mu_p * (ConvectionTerm(coeff=potential.faceGrad, var=Pion) +
                         Pion * potential.faceGrad.divergence) + DiffusionTerm(
                             coeff=Dp, var=Pion) - k_rec * Pion * Nion

#In English:  dNion/dt = 1/q * divergence.Jn(x,t) - k_rec * Nion(x,t) * Pion(x,t)   where
#             Jn = q * mu_n * E(x,t) * Nion(x,t) - q * Dn * grad.Nion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation

Nion.equation = TransientTerm(
    coeff=1, var=Nion
) == -mu_n * (ConvectionTerm(coeff=potential.faceGrad, var=Nion) +
              Nion * potential.faceGrad.divergence) + DiffusionTerm(
                  coeff=Dn, var=Nion) - k_rec * Pion * Nion

#In English:  d^2potential/dx^2 = -q/epsilon * Charge_Density      and     Charge Density = Pion + Nion
# Poisson's Equation
Exemple #5
0
D_Zohm = (D_max + D_min) / 2.0 + ((D_max - D_min) * numerix.tanh(Z)) / 2.0
# Stap's Model
alpha_sup = 0.5
D_Staps = D_min + (D_max - D_min) / (1.0 +
                                     alpha_sup * numerix.dot(Z.grad, Z.grad))
# Flow-Shear Model
a1, a3 = 1.0, 0.5  # ASSUMES a2 = 0
D_Shear = D_min + (D_max - D_min) / (1.0 + a1 *
                                     (Z)**2 + a3 * numerix.dot(Z.grad, Z.grad))

# CHOOSE DIFFUSIVITY HERE!
D_choice = D_Staps

# If Diffusivity is a Cell/Face variable
Diffusivity.setValue(D_choice)
Diffusivity.equation = (ImplicitSourceTerm(1.0))

# ----------------- Boundary Conditions -------------------
"""
	Density Boundary Conditions:
	d/dx(n(0)) == n / lambda_n
	d/dx(n(L)) == -Gamma_c / Diffusivity
"""
density.faceGrad.constrain(density.faceValue / lambda_n, mesh.facesLeft)

density.faceGrad.constrain(-Gamma_c / Diffusivity.faceValue, mesh.facesRight)
"""
	Temperature Boundary Conditions:
	d/dx(T(0)) = T / lambda_T
	d/dx(T(L)) = zeta*(Gamma_c*T - q_c*(gamma - 1)) / (Diffusivity * n)
"""
Exemple #6
0
#!/usr/bin/env python

from fipy import Grid2D, CellVariable, TransientTerm, DiffusionTerm, FixedValue
import pylab
import sys

nx = 300
dx = 0.05
L = nx * dx
mesh = Grid2D(dx=dx,dy=dx,nx=nx,ny=nx)
x,y = mesh.getCellCenters()
x0,y0 = L/2,L/2
X,Y = mesh.getFaceCenters()

potential = CellVariable(mesh=mesh, name='potential', value=0.)
potential.equation = (DiffusionTerm(coeff = 1.) == 0.)

bcs = (
    FixedValue(value=5,faces=mesh.getFacesLeft() & (Y<y0) ),
    FixedValue(value=0,faces=mesh.getFacesRight() & (Y<y0) ),
    FixedValue(value=2,faces=mesh.getFacesTop() ),
)

potential.equation.solve(var=potential, boundaryConditions=bcs)

# The follow evaluation of the solution is only
# possible with "common" meshes.
result = pylab.array(potential)
result = result.reshape((nx,nx))
xx,yy = pylab.array(x), pylab.array(y)
xx,yy = xx.reshape((nx,nx)), yy.reshape((nx,nx))
Exemple #7
0
#!/usr/bin/env python

from fipy import Grid2D, CellVariable, TransientTerm, DiffusionTerm, FixedValue
import pylab
import sys

nx = 300
dx = 0.05
L = nx * dx
mesh = Grid2D(dx=dx, dy=dx, nx=nx, ny=nx)
x, y = mesh.getCellCenters()
x0, y0 = L / 2, L / 2
X, Y = mesh.getFaceCenters()

potential = CellVariable(mesh=mesh, name='potential', value=0.)
potential.equation = (DiffusionTerm(coeff=1.) == 0.)

bcs = (
    FixedValue(value=5, faces=mesh.getFacesLeft() & (Y < y0)),
    FixedValue(value=0, faces=mesh.getFacesRight() & (Y < y0)),
    FixedValue(value=2, faces=mesh.getFacesTop()),
)

potential.equation.solve(var=potential, boundaryConditions=bcs)

# The follow evaluation of the solution is only
# possible with "common" meshes.
result = pylab.array(potential)
result = result.reshape((nx, nx))
xx, yy = pylab.array(x), pylab.array(y)
xx, yy = xx.reshape((nx, nx)), yy.reshape((nx, nx))
Exemple #8
0
# EQUATION SETUP BASIC DESCRIPTION
'''Equations to solve for each variable must be defined:
  -TransientTerm = dvar/dt
  -ConvectionTerm = dvar/dx
  -DiffusionTerm = d^2var/dx^2
  -Source terms can be described as they would appear mathematically
Notes:  coeff = terms that are multiplied by the Term.. must be rank-1 FaceVariable for ConvectionTerm
        "var" must be defined for each Term if they are not all the variable being solved for,
        otherwise will see "fipy.terms.ExplicitVariableError: Terms with explicit Variables cannot mix with Terms with implicit Variables." '''

# In English:  dPion/dt = -1/q * divergence.Jp(x,t) - k_rec * Nion(x,t) * Pion(x,t) where
#             Jp = q * mu_p * E(x,t) * Pion(x,t) - q * Dp * grad.Pion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation

# Pion.equation = TransientTerm(coeff=1, var=Pion) == mu_p * (ConvectionTerm(coeff=potential.faceGrad,var=Pion) + Pion * potential.faceGrad.divergence) + DiffusionTerm(coeff=Dp,var=Pion) - k_rec*Pion*Nion
Pion.equation = TransientTerm(coeff=1, var=Pion) == mu_p * (ConvectionTerm(coeff=potential.faceGrad, var=Pion) + Pion * potential.faceGrad.divergence)

# In English:  dNion/dt = 1/q * divergence.Jn(x,t) - k_rec * Nion(x,t) * Pion(x,t)   where
#             Jn = q * mu_n * E(x,t) * Nion(x,t) - q * Dn * grad.Nion(x,t)         and     E(x,t) = -grad.potential(x,t)
# Continuity Equation

# Nion.equation = TransientTerm(coeff=1, var=Nion) == -mu_n * (ConvectionTerm(coeff=potential.faceGrad,var=Nion) + Nion * potential.faceGrad.divergence) + DiffusionTerm(coeff=Dn,var=Nion) - k_rec*Pion*Nion


# In English:  d^2potential/dx^2 = -q/epsilon * Charge_Density      and     Charge Density = Pion + Nion
# Poisson's Equation

# potential.equation = DiffusionTerm(coeff=1, var=potential) == (-q/epsilon)*(Pion + Nion)
potential.equation = DiffusionTerm(coeff=1, var=potential) == (-q/epsilon)*Pion