コード例 #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
コード例 #2
0
ファイル: new.py プロジェクト: rochSmets/pywi
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
コード例 #3
0
    return a1 * np.sin(b1 * x + c1) + a2 * np.sin(b2 * x + c2)


mesh = Grid1D(dx=dx, nx=nx)

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)
コード例 #4
0
ファイル: ex2c.py プロジェクト: pavaninguva/pde-Solver-Course
import glob as glob
import re
import os

# Setting up a mesh
nx = 50
dx = 0.02
L = nx * dx
mesh = Grid1D(nx=nx, dx=dx)

# Defining the cell variable
c = CellVariable(mesh=mesh, name=r"$c$")

# Initialise c with a funky profile
x = mesh.cellCenters[0]
c.value = 0.0
c.setValue((0.3 * numerix.sin(2.0 * x * numerix.pi)) + 0.5)

# Setting up the no-flux boundary conditions
c.faceGrad.constrain(0.0, where=mesh.facesLeft)
c.faceGrad.constrain(0.0, where=mesh.facesRight)

# Provide value for diffusion and reaction coefficient
D = 1.0
k = -2.0

# Specifying our alpha value. We will only use backwards Euler going forward
alpha = 1

# Defining the equation with the reaction term.
eq = TransientTerm() == DiffusionTerm(coeff=D) + ImplicitSourceTerm(coeff=k)
コード例 #5
0
from fipy import CellVariable, GaussianNoiseVariable, DiffusionTerm, TransientTerm, ImplicitSourceTerm, VTKCellViewer, LinearLUSolver,  PeriodicGrid1D, Viewer, UniformNoiseVariable, Grid1D
from fipy.tools import numerix
from math import log

nx = 100
dx = 0.3

mesh = Grid1D(dx=dx, nx=nx)
phi = CellVariable(name=r"$\phi$", mesh=mesh)
psi = CellVariable(name=r"$\psi$", mesh=mesh)

# noise = GaussianNoiseVariable(mesh=mesh, mean=0.8, variance=0.002).value
# phi[:] = noise

x = mesh.cellCenters[0]
phi.value = 0.1
phi.setValue(0.2, where=x < 0.3*(nx*dx))
phi.setValue(0.6, where=x > 0.3*(nx*dx))
phi.setValue(0.2, where=x > 0.32*(nx*dx))
phi.setValue(0.6, where=x > 0.7*(nx*dx))
phi.setValue(0.2, where=x > 0.72*(nx*dx))



D = a = epsilon = 1.
N_A = 500
N_B = 500
chi_AB = 0.015
kappa = 2*chi_AB / 3.0

dfdphi = ((1.0/N_A) - (1.0/N_B)) + (1.0/N_A)*numerix.log(phi) - (1.0/N_B)*numerix.log(1.0 - phi) + chi_AB*(1.0 - 2*phi)