Пример #1
0
 def __init__(self, coeff):
     """
     .. attention:: This class is deprecated. Use `ImplicitDiffusionTerm` instead.
     """
     import warnings
     warnings.warn("ImplicitDiffusionTerm should be used instead of NthOrderDiffusionTerm", DeprecationWarning, stacklevel=2)
     ImplicitDiffusionTerm.__init__(self, coeff = coeff)
Пример #2
0
    def buildThetaEquation(phase, theta):

        phaseMod = phase + (phase < thetaSmallValue) * thetaSmallValue
        phaseModSq = phaseMod * phaseMod
        expo = epsilon * beta * theta.getGrad().getMag()
        expo = (expo < 100.) * (expo - 100.) + 100.
        pFunc = 1. + numerix.exp(-expo) * (mu / epsilon - 1.)

        phaseFace = phase.getArithmeticFaceValue()
        phaseSq = phaseFace * phaseFace
        gradMag = theta.getFaceGrad().getMag()
        eps = 1. / gamma / 10.
        gradMag += (gradMag < eps) * eps
        IGamma = (gradMag > 1. / gamma) * (1 / gradMag - gamma) + gamma
        diffusionCoeff = phaseSq * (s * IGamma + epsilon**2)

        thetaGradDiff = theta.getFaceGrad() - theta.getFaceGradNoMod()
        sourceCoeff = (diffusionCoeff * thetaGradDiff).getDivergence()

        from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
        return TransientTerm(thetaTransientCoeff * phaseModSq * pFunc) == \
                   ImplicitDiffusionTerm(diffusionCoeff) \
                   + sourceCoeff
Пример #3
0
nx = 2

valueLeft = 0.
fluxRight = 1.
timeStepDuration = 1.

L = 1.

dx = L / nx

mesh = Grid2D(dx=dx, nx=nx)

var = CellVariable(name="solution variable", mesh=mesh, value=valueLeft)

x = mesh.getFaceCenters()[:, 0]
middleFaces = numerix.logical_or(x < L / 4., x >= 3. * L / 4.)
diffCoeff = numerix.where(middleFaces, 1., 0.1)

boundaryConditions = (FixedValue(mesh.getFacesLeft(), valueLeft),
                      FixedFlux(mesh.getFacesRight(), fluxRight))

if __name__ == '__main__':
    ImplicitDiffusionTerm(coeff=diffCoeff).solve(
        var, boundaryConditions=boundaryConditions)

    import fipy.viewers
    viewer = fipy.viewers.make(vars=var, limits={'datamax': L + 18. * L / 4.})
    viewer.plot()
    raw_input('finished')
Пример #4
0
from fipy.variables.cellVariable import CellVariable

psi = CellVariable(mesh=mesh, name='stream function')

Xhat=(1,0)
Yhat=(0,1)

u=psi.getGrad().dot(Yhat)
v=-psi.getGrad().dot(Xhat)

U=psi.getFaceGrad()

from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm

eq=ImplicitDiffusionTerm(0.00001) \
	 + u * u.getGrad().dot(Xhat) \
	 + v * u.getGrad().dot(Yhat) \
	 - 2 * u.getGrad().dot(Yhat).getGrad().dot(Yhat)
from fipy.boundaryConditions.nthOrderBoundaryCondition import NthOrderBoundaryCondition

from fipy.boundaryConditions.fixedValue import FixedValue
BC = (NthOrderBoundaryCondition(faces=mesh.getFacesBottom(), value=0,order=1),
      FixedValue(faces=mesh.getFacesBottom(), value=0),
      NthOrderBoundaryCondition(faces=mesh.getFacesLeft(), value=0,order=1),
	
      NthOrderBoundaryCondition(faces=mesh.getFacesTop(), value=1,order=1),
      NthOrderBoundaryCondition(faces=mesh.getFacesTop(), value=0,order=2))

from fipy.boundaryConditions.fixedFlux import FixedFlux
Пример #5
0
velocity=u.getFaceGrad().dot(Xhat) * Xhat + v.getFaceGrad().dot(Yhat) * Yhat

from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm

diffTerm=ImplicitDiffusionTerm(coeff=viscosity)

from fipy.terms.exponentialConvectionTerm import ExponentialConvectionTerm

convTerm = ExponentialConvectionTerm(coeff = velocity,diffusionTerm = diffTerm)

eq1= diffTerm - u * u.getGrad().dot(Xhat) - v * u.getGrad().dot(Yhat)
eq2= velocity.getDivergence()
#eq2= u.getGrad() + v.getGrad()
eq2=u.getFaceGrad().dot(Xhat) * Xhat + v.getFaceGrad().dot(Yhat) * Yhat
eq2= u.getGrad().dot(Xhat) + v.getGrad().dot(Yhat)
eq2= ImplicitDiffusionTerm(1) + u.getGrad().dot(Xhat) + v.getGrad().dot(Yhat)

from fipy.boundaryConditions.fixedValue import FixedValue
BCu = (FixedValue(faces=mesh.getFacesBottom(), value=0),
        FixedValue(faces=mesh.getFacesLeft(), value=1))

BCv = (FixedValue(faces=mesh.getFacesBottom(), value=0),
        FixedValue(faces=mesh.getFacesLeft(), value=0))

from fipy import viewers
viewer = viewers.make(vars=(u,v),limits={'datamin': 0., 'datamax': 1.})

def hit_continue(Prompt='Hit any key to continue'):
	raw_input(Prompt)

steps=10
Пример #6
0
    beta = (1. - PhiSq) / (1. + PhiSq)
    betaPsi = -N * 2 * Phi / (1 + PhiSq)
    A = alpha**2 * c * (1. + c * beta) * betaPsi
    D = alpha**2 * (1. + c * beta)**2
    dxi = phase.getFaceGrad()._take((1, 0), axis=1) * (-1, 1)
    anisotropySource = (A * dxi).getDivergence()
    from fipy.terms.transientTerm import TransientTerm
    from fipy.terms.explicitDiffusionTerm import ExplicitDiffusionTerm
    from fipy.terms.implicitSourceTerm import ImplicitSourceTerm
    phaseEq = TransientTerm(tau) == ExplicitDiffusionTerm(D) + \
        ImplicitSourceTerm(mVar * ((mVar < 0) - phase)) + \
        ((mVar > 0.) * mVar * phase + anisotropySource)

    from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
    temperatureEq = TransientTerm() == \
                    ImplicitDiffusionTerm(tempDiffusionCoeff) + \
                    (phase - phase.getOld()) / timeStepDuration

    bench.stop('terms')

    phase.updateOld()
    temperature.updateOld()
    phaseEq.solve(phase, dt=timeStepDuration)
    temperatureEq.solve(temperature, dt=timeStepDuration)

    steps = 10

    bench.start()

    for i in range(steps):
        phase.updateOld()
Пример #7
0
##viewer5 = Grid3DPyxViewer(var, zvalue = 5.0)
##viewer7 = Grid3DPyxViewer(var, zvalue = 7.0)
##viewer9 = Grid3DPyxViewer(var, zvalue = 9.0)

## from fipy import viewers
## viewer = viewers.make(vars = var)

## viewer.plot()

from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm

ImplicitDiffusionTerm().solve(var,
                              boundaryConditions=(
                                  FixedValue(mesh.getFacesLeft(), valueSides),
                                  FixedValue(mesh.getFacesRight(), valueSides),
                                  FixedValue(mesh.getFacesTop(), valueSides),
                                  FixedValue(mesh.getFacesBottom(),
                                             valueSides),
                                  FixedValue(mesh.getFacesFront(), valueFront),
                                  FixedValue(mesh.getFacesBack(), valueBack),
                              ))

## viewer.plot()

if __name__ == '__main__':
    ##viewer1.plot(resolution = 0.2, xlabel = "X values (Z value = 1)", minval = valueFront, maxval = valueBack)
    ##raw_input("press enter to continue")
    ##viewer3.plot(resolution = 0.2, xlabel = "X values (Z value = 3)", minval = valueFront, maxval = valueBack)
    ##raw_input("press enter to continue")
    ##viewer5.plot(resolution = 0.2, xlabel = "X values (Z value = 5)", minval = valueFront, maxval = valueBack)
    ##raw_input("press enter to continue")
    ##viewer7.plot(resolution = 0.2, xlabel = "X values (Z value = 7)", minval = valueFront, maxval = valueBack)
Пример #8
0
Lx = 1.
nx = 100000
dx = Lx / nx

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

from fipy.tools import numerix
from fipy.variables.cellVariable import CellVariable
var = CellVariable(mesh = mesh)

from fipy.solvers.linearLUSolver import LinearLUSolver
from fipy.boundaryConditions.nthOrderBoundaryCondition import NthOrderBoundaryCondition
from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
from fipy.terms.transientTerm import TransientTerm
     
eq = ImplicitDiffusionTerm((1.0, 1.0))

BCs = (NthOrderBoundaryCondition(mesh.getFacesLeft(), 0., 0),
       NthOrderBoundaryCondition(mesh.getFacesRight(), Lx, 0),
       NthOrderBoundaryCondition(mesh.getFacesLeft(), 0., 2),
       NthOrderBoundaryCondition(mesh.getFacesRight(), 0., 2))

solver = LinearLUSolver(iterations=10)

if __name__ == '__main__':
    eq.solve(var,
             boundaryConditions = BCs,
             solver = solver)
    
    from fipy.viewers import make
    viewer = make(var)
Пример #9
0
TMscCoeff = params['chiT'] * (1 - TCVar - TMVar.getCellVolumeAverage())
TMspCoeff = params['lambdaT'] * (KMVar + params['zetaT'])
TMEq = TransientTerm() - TMscCoeff + ImplicitSourceTerm(TMspCoeff)

TCscCoeff = params['lambdaT'] * (TMVar * KMVar).getCellVolumeAverage()
TCspCoeff = params['lambdaTstar']
TCEq = TransientTerm() - TCscCoeff + ImplicitSourceTerm(TCspCoeff)

PIP2PITP = PN / (PN / params['kappam'] + PN.getCellVolumeAverage() /
                 params['kappac'] + 1) + params['zetaPITP']

P3spCoeff = params['lambda3'] * (TMVar + params['zeta3T'])
P3scCoeff = params['chi3'] * KMVar * (PIP2PITP /
                                      (1 + KMVar / params['kappa3']) +
                                      params['zeta3PITP']) + params['zeta3']
P3Eq = TransientTerm() - ImplicitDiffusionTerm(
    params['diffusionCoeff']) - P3scCoeff + ImplicitSourceTerm(P3spCoeff)

P2scCoeff = scCoeff = params[
    'chi2'] + params['lambda3'] * params['zeta3T'] * P3Var
P2spCoeff = params['lambda2'] * (TMVar + params['zeta2T'])
P2Eq = TransientTerm() - ImplicitDiffusionTerm(
    params['diffusionCoeff']) - P2scCoeff + ImplicitSourceTerm(P2spCoeff)

KCscCoeff = params['alphaKstar'] * params['lambdaK'] * (
    KMVar / (1 + PN / params['kappaK'])).getCellVolumeAverage()
KCspCoeff = params['lambdaKstar'] / (params['kappaKstar'] + KCVar)
KCEq = TransientTerm() - KCscCoeff + ImplicitSourceTerm(KCspCoeff)

eqs = ((KMVar, KMEq), (TMVar, TMEq), (TCVar, TCEq), (P3Var, P3Eq),
       (P2Var, P2Eq), (KCVar, KCEq))
Пример #10
0
# create a field variable, set the initial conditions:
from fipy.variables.cellVariable import CellVariable

var = CellVariable(mesh=mesh, value=0)


def centerCells(cell):
    return abs(cell.getCenter()[0] - L / 2.0) < L / 10


var.setValue(value=1.0, cells=mesh.getCells(filter=centerCells))

# create the equation:
from fipy.terms.transientTerm import TransientTerm
from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm

eq = TransientTerm() - ImplicitDiffusionTerm(coeff=1) == 0

# create a viewer:
from fipy.viewers.gist2DViewer import Gist1DViewer

viewer = Gist1DViewer(vars=(var,), limits=('e', 'e', 0, 1))
viwer.plot()

# solve
for i in range(steps):
    var.updateOld()
    eq.solve()
    viewer.plot()
Пример #11
0
from fipy.variables.cellVariable import CellVariable

u = CellVariable(mesh=mesh, name='X velocity')
v = CellVariable(mesh=mesh, name='Y velocity')

from fipy.variables.vectorFaceVariable import VectorFaceVariable
velocity = VectorFaceVariable(mesh=mesh)

Xhat = (1, 0)
Yhat = (0, 1)
velocity = u.getFaceGrad().dot(Xhat) * Xhat + v.getFaceGrad().dot(Yhat) * Yhat

from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm

diffTerm = ImplicitDiffusionTerm(coeff=viscosity)

from fipy.terms.exponentialConvectionTerm import ExponentialConvectionTerm

convTerm = ExponentialConvectionTerm(coeff=velocity, diffusionTerm=diffTerm)

eq1 = diffTerm - u * u.getGrad().dot(Xhat) - v * u.getGrad().dot(Yhat)
eq2 = velocity.getDivergence()
#eq2= u.getGrad() + v.getGrad()
eq2 = u.getFaceGrad().dot(Xhat) * Xhat + v.getFaceGrad().dot(Yhat) * Yhat
eq2 = u.getGrad().dot(Xhat) + v.getGrad().dot(Yhat)
eq2 = ImplicitDiffusionTerm(1) + u.getGrad().dot(Xhat) + v.getGrad().dot(Yhat)

from fipy.boundaryConditions.fixedValue import FixedValue
BCu = (FixedValue(faces=mesh.getFacesBottom(),
                  value=0), FixedValue(faces=mesh.getFacesLeft(), value=1))
Пример #12
0
                      FixedValue(mesh.getFacesTop(), valueBottomTop),
                      FixedValue(mesh.getFacesBottom(), valueBottomTop))

#do the 2D problem for comparison

nx = 10
ny = 5

dx = 1.
dy = 1.

mesh2 = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)

var2 = CellVariable(name="solution variable 2D",
                    mesh=mesh2,
                    value=valueBottomTop)

boundaryConditions2 = (FixedValue(mesh2.getFacesLeft(), valueLeftRight),
                       FixedValue(mesh2.getFacesRight(), valueLeftRight),
                       FixedValue(mesh2.getFacesTop(), valueBottomTop),
                       FixedValue(mesh2.getFacesBottom(), valueBottomTop))

eqn = ImplicitDiffusionTerm()

if __name__ == '__main__':
    eqn.solve(var2, boundaryConditions=boundaryConditions2)
    from fipy.viewers import make
    viewer = make(var2)
    viewer.plot()
    raw_input("finished")
Пример #13
0
Файл: heat2d.py Проект: ghorn/Eg
	raw_input(Prompt)

nx = 50
ny = nx
dx = 1.
dy = dx
from fipy.meshes.grid2D import Grid2D
mesh = Grid2D(dx=dx, dy=dy, nx=nx, ny=ny)

from fipy.variables.cellVariable import CellVariable
phi = CellVariable(name = "solution variable",mesh = mesh,value = 0)

D = 1.
from fipy.terms.transientTerm import TransientTerm
from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
eq = ImplicitDiffusionTerm(coeff=D)

valueLeft = 1
valueRight = 0

from fipy.boundaryConditions.fixedValue import FixedValue
BCs = (FixedValue(faces=mesh.getFacesLeft(),value=0),
       FixedValue(faces=mesh.getFacesRight(),value=1),
	FixedValue(faces=mesh.getFacesTop(),value=0),
	FixedValue(faces=mesh.getFacesBottom(),value=0))


from fipy import viewers
viewer = viewers.make(vars=phi,
                       limits={'datamin': 0., 'datamax': 1.})
viewer.plot()
Пример #14
0
    bench.start()

    from fipy.variables.cellVariable import CellVariable
    C = CellVariable(mesh=mesh)
    C.setValue(1, where=abs(mesh.getCellCenters()[..., 0] - L / 2.) < L / 10.)

    bench.stop('variables')

    bench.start()

    D = 1.

    from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
    from fipy.terms.transientTerm import TransientTerm
    eq = TransientTerm() == ImplicitDiffusionTerm(coeff=D)

    bench.stop('terms')

    ## from fipy import viewers
    ## viewer = viewers.make(vars = C, limits = {'datamin': 0, 'datamax': 1})
    ## viewer.plot()
    ## raw_input("initial")

    bench.start()

    dt = 1e0
    steps = 1
    for step in range(steps):
        eq.solve(var=C, dt=dt)
    ##     viewer.plot()
Пример #15
0
    1

"""

from fipy.meshes.tri2D import Tri2D
from fipy.boundaryConditions.fixedValue import FixedValue
from fipy.variables.cellVariable import CellVariable
import fipy.viewers
from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm

nx = 50
ny = 50

dx = 1.

valueLeft = 0.
valueRight = 1.

mesh = Tri2D(dx=dx, nx=nx, ny=ny)

var = CellVariable(name="solution variable", mesh=mesh, value=valueLeft)

boundaryConditions = (FixedValue(mesh.getFacesLeft(), valueLeft),
                      FixedValue(mesh.getFacesRight(), valueRight))

if __name__ == '__main__':
    ImplicitDiffusionTerm().solve(var, boundaryConditions=boundaryConditions)
    viewer = fipy.viewers.make(vars=var)
    viewer.plot()
    raw_input("finished")
Пример #16
0
Lx = 1.
nx = 100000
dx = Lx / nx

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

from fipy.tools import numerix
from fipy.variables.cellVariable import CellVariable
var = CellVariable(mesh=mesh)

from fipy.solvers.linearLUSolver import LinearLUSolver
from fipy.boundaryConditions.nthOrderBoundaryCondition import NthOrderBoundaryCondition
from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
from fipy.terms.transientTerm import TransientTerm

eq = ImplicitDiffusionTerm((1.0, 1.0))

BCs = (NthOrderBoundaryCondition(mesh.getFacesLeft(), 0., 0),
       NthOrderBoundaryCondition(mesh.getFacesRight(), Lx, 0),
       NthOrderBoundaryCondition(mesh.getFacesLeft(), 0., 2),
       NthOrderBoundaryCondition(mesh.getFacesRight(), 0., 2))

solver = LinearLUSolver(iterations=10)

if __name__ == '__main__':
    eq.solve(var, boundaryConditions=BCs, solver=solver)

    from fipy.viewers import make
    viewer = make(var)
    viewer.plot()
Пример #17
0
Файл: plank.py Проект: ghorn/Eg
from fipy.meshes.grid1D import Grid1D
mesh = Grid1D(nx = nx, dx = dx)

from fipy.variables.cellVariable import CellVariable
u = CellVariable(name="solution variable",
                    mesh=mesh,
                    value=0,hasOld=1)

from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
from fipy.terms.transientTerm import TransientTerm
a=1

timeStepDuration = 0.01
steps=1000

eq= ImplicitDiffusionTerm(coeff=(a,a))+(u.getOld().getOld() - 2*u.getOld() + u) / timeStepDuration ** 2




from fipy.boundaryConditions.fixedValue import FixedValue
from fipy.boundaryConditions.fixedFlux import FixedFlux
from fipy.boundaryConditions.nthOrderBoundaryCondition import NthOrderBoundaryCondition

BCs = ( NthOrderBoundaryCondition(faces=mesh.getFacesRight(), value=0,order=2),
	NthOrderBoundaryCondition(faces=mesh.getFacesRight(), value=1,order=3),
	FixedValue(faces=mesh.getFacesLeft(), value=0),
	FixedFlux(faces=mesh.getFacesLeft(), value=0))

from fipy import viewers
viewer = viewers.make(vars=(u))
Пример #18
0
diffusionCoeff = 1

from fipy.meshes.grid2D import Grid2D
mesh = Grid2D(dx, dy, nx, ny)

from fipy.variables.cellVariable import CellVariable
from fipy.tools.numerix import random

var = CellVariable(name="phase field", mesh=mesh, value=random.random(nx * ny))

faceVar = var.getArithmeticFaceValue()
doubleWellDerivative = asq * (1 - 6 * faceVar * (1 - faceVar))

from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
from fipy.terms.transientTerm import TransientTerm
diffTerm2 = ImplicitDiffusionTerm(coeff=(diffusionCoeff *
                                         doubleWellDerivative, ))
diffTerm4 = ImplicitDiffusionTerm(coeff=(diffusionCoeff, -epsilon**2))
eqch = TransientTerm() - diffTerm2 - diffTerm4

from fipy.solvers.linearPCGSolver import LinearPCGSolver
from fipy.solvers.linearLUSolver import LinearLUSolver
##solver = LinearLUSolver(tolerance = 1e-15,steps = 1000)
solver = LinearPCGSolver(tolerance=1e-15, steps=1000)

from fipy.boundaryConditions.fixedValue import FixedValue
from fipy.boundaryConditions.fixedFlux import FixedFlux
from fipy.boundaryConditions.nthOrderBoundaryCondition import NthOrderBoundaryCondition
BCs = (FixedFlux(mesh.getFacesRight(), 0), FixedFlux(mesh.getFacesLeft(), 0),
       NthOrderBoundaryCondition(mesh.getFacesLeft(), 0, 3),
       NthOrderBoundaryCondition(mesh.getFacesRight(), 0, 3),
       NthOrderBoundaryCondition(mesh.getFacesTop(), 0, 3),
Пример #19
0
                      FixedValue(mesh.getFacesTop(),valueBottomTop),
                      FixedValue(mesh.getFacesBottom(),valueBottomTop))
                      
#do the 2D problem for comparison

nx = 10
ny = 5

dx = 1.
dy = 1.

mesh2 = Grid2D(dx = dx, dy = dy, nx = nx, ny = ny)

var2 = CellVariable(name = "solution variable 2D",
                    mesh = mesh2,
                    value = valueBottomTop)

boundaryConditions2 = (FixedValue(mesh2.getFacesLeft(),valueLeftRight),
                       FixedValue(mesh2.getFacesRight(),valueLeftRight),
                       FixedValue(mesh2.getFacesTop(),valueBottomTop),
                       FixedValue(mesh2.getFacesBottom(),valueBottomTop))

eqn = ImplicitDiffusionTerm()  

if __name__ == '__main__':
    eqn.solve(var2, boundaryConditions = boundaryConditions2)
    from fipy.viewers import make
    viewer = make(var2)
    viewer.plot()
    raw_input("finished")
Пример #20
0
    RMSErrorList = []

    for i in range(1, 501):
        meshList = meshList + [
            SkewedGrid2D(dx=1.0, dy=1.0, nx=20, ny=20, rand=(0.001 * i))
        ]

    for mesh in meshList:
        var = CellVariable(name="solution variable",
                           mesh=mesh,
                           value=valueLeft)

        from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm

        ImplicitDiffusionTerm().solve(
            var,
            boundaryConditions=(FixedValue(mesh.getFacesLeft(), valueLeft),
                                FixedValue(mesh.getFacesRight(), valueRight)))

        varArray = numerix.array(var)
        x = mesh.getCellCenters()[:, 0]
        analyticalArray = valueLeft + (valueRight - valueLeft) * x / 20
        errorArray = varArray - analyticalArray
        nonOrthoArray = mesh._getNonOrthogonality()
        RMSError = (numerix.add.reduce(errorArray * errorArray) /
                    len(errorArray))**0.5
        RMSNonOrtho = (numerix.add.reduce(nonOrthoArray * nonOrthoArray) /
                       len(nonOrthoArray))**0.5

        RMSNonOrthoList += [RMSNonOrtho]
        RMSErrorList += [RMSError]
Пример #21
0
Файл: plank.py Проект: ghorn/Eg
nx = 50
dx = 1.
from fipy.meshes.grid1D import Grid1D
mesh = Grid1D(nx=nx, dx=dx)

from fipy.variables.cellVariable import CellVariable
u = CellVariable(name="solution variable", mesh=mesh, value=0, hasOld=1)

from fipy.terms.implicitDiffusionTerm import ImplicitDiffusionTerm
from fipy.terms.transientTerm import TransientTerm
a = 1

timeStepDuration = 0.01
steps = 1000

eq = ImplicitDiffusionTerm(coeff=(
    a, a)) + (u.getOld().getOld() - 2 * u.getOld() + u) / timeStepDuration**2

from fipy.boundaryConditions.fixedValue import FixedValue
from fipy.boundaryConditions.fixedFlux import FixedFlux
from fipy.boundaryConditions.nthOrderBoundaryCondition import NthOrderBoundaryCondition

BCs = (NthOrderBoundaryCondition(faces=mesh.getFacesRight(), value=0, order=2),
       NthOrderBoundaryCondition(faces=mesh.getFacesRight(), value=1, order=3),
       FixedValue(faces=mesh.getFacesLeft(),
                  value=0), FixedFlux(faces=mesh.getFacesLeft(), value=0))

from fipy import viewers
viewer = viewers.make(vars=(u))


def hit_continue(Prompt='Hit any key to continue'):