예제 #1
0
파일: inputGold.py 프로젝트: ghorn/Eg
def runGold(faradaysConstant=9.6e4,
            consumptionRateConstant=2.6e+6,
            molarVolume=10.21e-6,
            charge=1.0,
            metalDiffusion=1.7e-9,
            metalConcentration=20.0,
            catalystCoverage=0.15,
            currentDensity0=3e-2 * 16,
            currentDensity1=6.5e-1 * 16,
            cellSize=0.1e-7,
            trenchDepth=0.2e-6,
            aspectRatio=1.47,
            trenchSpacing=0.5e-6,
            boundaryLayerDepth=90.0e-6,
            numberOfSteps=10,
            taperAngle=6.0,
            displayViewers=True):

    cflNumber = 0.2
    numberOfCellsInNarrowBand = 20
    cellsBelowTrench = 10

    from fipy.tools import numerix
    from fipy import TrenchMesh
    mesh = TrenchMesh(cellSize=cellSize,
                      trenchSpacing=trenchSpacing,
                      trenchDepth=trenchDepth,
                      boundaryLayerDepth=boundaryLayerDepth,
                      aspectRatio=aspectRatio,
                      angle=numerix.pi * taperAngle / 180.,
                      bowWidth=0.,
                      overBumpRadius=0.,
                      overBumpWidth=0.)

    narrowBandWidth = numberOfCellsInNarrowBand * cellSize

    from fipy.models.levelSet.distanceFunction.distanceVariable import DistanceVariable
    distanceVar = DistanceVariable(name='distance variable',
                                   mesh=mesh,
                                   value=-1,
                                   narrowBandWidth=narrowBandWidth)

    distanceVar.setValue(1, where=mesh.getElectrolyteMask())
    distanceVar.calcDistanceFunction(narrowBandWidth=1e10)

    from fipy.models.levelSet.surfactant.surfactantVariable import SurfactantVariable
    catalystVar = SurfactantVariable(name="catalyst variable",
                                     value=catalystCoverage,
                                     distanceVar=distanceVar)

    from fipy.variables.cellVariable import CellVariable
    metalVar = CellVariable(name='metal variable',
                            mesh=mesh,
                            value=metalConcentration)

    exchangeCurrentDensity = currentDensity0 + currentDensity1 * catalystVar.getInterfaceVar(
    )

    currentDensity = metalVar / metalConcentration * exchangeCurrentDensity

    depositionRateVariable = currentDensity * molarVolume / charge / faradaysConstant

    extensionVelocityVariable = CellVariable(name='extension velocity',
                                             mesh=mesh,
                                             value=depositionRateVariable)

    from fipy.models.levelSet.surfactant.adsorbingSurfactantEquation \
                import AdsorbingSurfactantEquation

    catalystSurfactantEquation = AdsorbingSurfactantEquation(
        catalystVar,
        distanceVar=distanceVar,
        bulkVar=0,
        rateConstant=0,
        consumptionCoeff=consumptionRateConstant * extensionVelocityVariable)

    from fipy.models.levelSet.advection.higherOrderAdvectionEquation \
                   import buildHigherOrderAdvectionEquation

    advectionEquation = buildHigherOrderAdvectionEquation(
        advectionCoeff=extensionVelocityVariable)

    from fipy.boundaryConditions.fixedValue import FixedValue
    from fipy.models.levelSet.electroChem.metalIonDiffusionEquation \
                         import buildMetalIonDiffusionEquation

    metalEquation = buildMetalIonDiffusionEquation(
        ionVar=metalVar,
        distanceVar=distanceVar,
        depositionRate=depositionRateVariable,
        diffusionCoeff=metalDiffusion,
        metalIonMolarVolume=molarVolume)

    metalEquationBCs = FixedValue(mesh.getTopFaces(), metalConcentration)

    if displayViewers:

        try:

            from fipy.viewers.mayaviViewer.mayaviSurfactantViewer import MayaviSurfactantViewer
            viewers = (MayaviSurfactantViewer(distanceVar,
                                              catalystVar.getInterfaceVar(),
                                              zoomFactor=1e6,
                                              limits={
                                                  'datamax': 1.0,
                                                  'datamin': 0.0
                                              },
                                              smooth=1,
                                              title='catalyst coverage'), )

        except:

            class PlotVariable(CellVariable):
                def __init__(self, var=None, name=''):
                    CellVariable.__init__(self,
                                          mesh=mesh.getFineMesh(),
                                          name=name)
                    self.var = self._requires(var)

                def _calcValue(self):
                    return numerix.array(
                        self.var[:self.mesh.getNumberOfCells()])

            from fipy.viewers import make
            viewers = (make(PlotVariable(var=distanceVar),
                            limits={
                                'datamax': 1e-9,
                                'datamin': -1e-9
                            }),
                       make(PlotVariable(var=catalystVar.getInterfaceVar())))

    else:
        viewers = ()
    levelSetUpdateFrequency = int(0.7 * narrowBandWidth / cellSize /
                                  cflNumber / 2)
    step = 0

    while step < numberOfSteps:

        if step % 10 == 0:
            for viewer in viewers:
                viewer.plot()

        if step % levelSetUpdateFrequency == 0:

            distanceVar.calcDistanceFunction(deleteIslands=True)

        extensionVelocityVariable.setValue(
            numerix.array(depositionRateVariable))
        argmax = numerix.argmax(extensionVelocityVariable)
        dt = cflNumber * cellSize / extensionVelocityVariable[argmax]
        distanceVar.extendVariable(extensionVelocityVariable,
                                   deleteIslands=True)

        distanceVar.updateOld()
        catalystVar.updateOld()
        metalVar.updateOld()

        advectionEquation.solve(distanceVar, dt=dt)
        catalystSurfactantEquation.solve(catalystVar, dt=dt)
        metalEquation.solve(metalVar,
                            boundaryConditions=metalEquationBCs,
                            dt=dt)

        step += 1

    try:
        from fipy.tools import dump
        import os
        import examples.levelSet.electroChem
        data = dump.read(
            os.path.join(examples.levelSet.electroChem.__path__[0],
                         'goldData.gz'))
        n = mesh.getFineMesh().getNumberOfCells()
        print numerix.allclose(catalystVar[:n], data[:n], atol=1.0)
    except:
        return 0
예제 #2
0
파일: adsorption.py 프로젝트: ghorn/Eg
## set up the comparison arrays

theta = surfactantVar.getInterfaceVar()[1]
    

if __name__ == "__main__":

    ## set up the viewers

    import fipy.viewers

    ## start time stepping

    currentTime = 0.

    for i in range(totalTimeSteps):

        ## evaluate the analytical and numerical solution and plot

        theta = surfactantVar.getInterfaceVar()[1]
        print "theta:",theta

        ## do a time step
        surfactantVar.updateOld()
        bulkVar.updateOld()
        surfEqn.solve(surfactantVar, dt = dt)
        bulkEqn.solve(bulkVar, dt = dt, boundaryConditions = bcs)
        currentTime += dt

    raw_input("finished")
예제 #3
0
def runSimpleTrenchSystem(faradaysConstant=9.6e4,
                          gasConstant=8.314,
                          transferCoefficient=0.5,
                          rateConstant0=1.76,
                          rateConstant3=-245e-6,
                          catalystDiffusion=1e-9,
                          siteDensity=9.8e-6,
                          molarVolume=7.1e-6,
                          charge=2,
                          metalDiffusion=5.6e-10,
                          temperature=298.,
                          overpotential=-0.3,
                          metalConcentration=250.,
                          catalystConcentration=5e-3,
                          catalystCoverage=0.,
                          currentDensity0=0.26,
                          currentDensity1=45.,
                          cellSize=0.1e-7,
                          trenchDepth=0.5e-6,
                          aspectRatio=2.,
                          trenchSpacing=0.6e-6,
                          boundaryLayerDepth=0.3e-6,
                          numberOfSteps=5,
                          displayViewers=True):

    cflNumber = 0.2
    numberOfCellsInNarrowBand = 10
    cellsBelowTrench = 10

    yCells = cellsBelowTrench \
             + int((trenchDepth + boundaryLayerDepth) / cellSize)

    xCells = int(trenchSpacing / 2 / cellSize)

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

    narrowBandWidth = numberOfCellsInNarrowBand * cellSize
    from fipy.models.levelSet.distanceFunction.distanceVariable import \
         DistanceVariable

    distanceVar = DistanceVariable(name='distance variable',
                                   mesh=mesh,
                                   value=-1,
                                   narrowBandWidth=narrowBandWidth,
                                   hasOld=1)

    bottomHeight = cellsBelowTrench * cellSize
    trenchHeight = bottomHeight + trenchDepth
    trenchWidth = trenchDepth / aspectRatio
    sideWidth = (trenchSpacing - trenchWidth) / 2

    x, y = mesh.getCellCenters()[..., 0], mesh.getCellCenters()[..., 1]
    distanceVar.setValue(1,
                         where=(y > trenchHeight) |
                         ((y > bottomHeight) &
                          (x < xCells * cellSize - sideWidth)))

    distanceVar.calcDistanceFunction(narrowBandWidth=1e10)

    from fipy.models.levelSet.surfactant.surfactantVariable import \
         SurfactantVariable

    catalystVar = SurfactantVariable(name="catalyst variable",
                                     value=catalystCoverage,
                                     distanceVar=distanceVar)

    from fipy.variables.cellVariable import CellVariable

    bulkCatalystVar = CellVariable(name='bulk catalyst variable',
                                   mesh=mesh,
                                   value=catalystConcentration)

    metalVar = CellVariable(name='metal variable',
                            mesh=mesh,
                            value=metalConcentration)

    expoConstant = -transferCoefficient * faradaysConstant \
                   / (gasConstant * temperature)

    tmp = currentDensity1 * catalystVar.getInterfaceVar()

    exchangeCurrentDensity = currentDensity0 + tmp

    import fipy.tools.numerix as numerix
    expo = numerix.exp(expoConstant * overpotential)
    currentDensity = expo * exchangeCurrentDensity * metalVar \
                     / metalConcentration

    depositionRateVariable = currentDensity * molarVolume \
                             / (charge * faradaysConstant)

    extensionVelocityVariable = CellVariable(name='extension velocity',
                                             mesh=mesh,
                                             value=depositionRateVariable)

    from fipy.models.levelSet.surfactant.adsorbingSurfactantEquation \
                import AdsorbingSurfactantEquation

    surfactantEquation = AdsorbingSurfactantEquation(
        surfactantVar=catalystVar,
        distanceVar=distanceVar,
        bulkVar=bulkCatalystVar,
        rateConstant=rateConstant0 + rateConstant3 * overpotential**3)

    from fipy.models.levelSet.advection.higherOrderAdvectionEquation \
                   import buildHigherOrderAdvectionEquation

    advectionEquation = buildHigherOrderAdvectionEquation(
        advectionCoeff=extensionVelocityVariable)

    from fipy.boundaryConditions.fixedValue import FixedValue
    from fipy.models.levelSet.electroChem.metalIonDiffusionEquation \
                         import buildMetalIonDiffusionEquation

    metalEquation = buildMetalIonDiffusionEquation(
        ionVar=metalVar,
        distanceVar=distanceVar,
        depositionRate=depositionRateVariable,
        diffusionCoeff=metalDiffusion,
        metalIonMolarVolume=molarVolume,
    )

    metalEquationBCs = FixedValue(mesh.getFacesTop(), metalConcentration)

    from fipy.models.levelSet.surfactant.surfactantBulkDiffusionEquation \
                    import buildSurfactantBulkDiffusionEquation

    bulkCatalystEquation = buildSurfactantBulkDiffusionEquation(
        bulkVar=bulkCatalystVar,
        distanceVar=distanceVar,
        surfactantVar=catalystVar,
        diffusionCoeff=catalystDiffusion,
        rateConstant=rateConstant0 * siteDensity)

    catalystBCs = FixedValue(mesh.getFacesTop(), catalystConcentration)

    if displayViewers:
        try:
            from fipy.viewers.mayaviViewer.mayaviSurfactantViewer import MayaviSurfactantViewer
            viewers = (MayaviSurfactantViewer(distanceVar,
                                              catalystVar.getInterfaceVar(),
                                              zoomFactor=1e6,
                                              limits={
                                                  'datamax': 0.5,
                                                  'datamin': 0.0
                                              },
                                              smooth=1,
                                              title='catalyst coverage'), )
        except:
            from fipy.viewers import make
            viewers = (make(distanceVar,
                            limits={
                                'datamin': -1e-9,
                                'datamax': 1e-9
                            }), make(catalystVar.getInterfaceVar()))
    else:
        viewers = ()

    levelSetUpdateFrequency = int(0.8 * narrowBandWidth \
                                  / (cellSize * cflNumber * 2))

    for step in range(numberOfSteps):

        if step % 5 == 0:
            for viewer in viewers:
                viewer.plot()

        if step % levelSetUpdateFrequency == 0:
            distanceVar.calcDistanceFunction()

        extensionVelocityVariable.setValue(depositionRateVariable())

        distanceVar.updateOld()
        catalystVar.updateOld()
        metalVar.updateOld()
        bulkCatalystVar.updateOld()

        distanceVar.extendVariable(extensionVelocityVariable)
        dt = cflNumber * cellSize / numerix.max(extensionVelocityVariable)

        advectionEquation.solve(distanceVar, dt=dt)
        surfactantEquation.solve(catalystVar, dt=dt)
        metalEquation.solve(metalVar,
                            dt=dt,
                            boundaryConditions=metalEquationBCs)
        bulkCatalystEquation.solve(bulkCatalystVar,
                                   dt=dt,
                                   boundaryConditions=catalystBCs)

    try:
        import os
        import examples.levelSet.electroChem
        filepath = os.path.join(examples.levelSet.electroChem.__path__[0],
                                'test.gz')

        from fipy.tools import dump
        from fipy.tools import numerix
        print catalystVar.allclose(numerix.array(dump.read(filepath)),
                                   rtol=1e-4)
    except:
        return 0
예제 #4
0
        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

    thetaEq = buildThetaEquation(phase, theta)

    bench.stop('terms')

    theta.updateOld()
    phase.updateOld()
    thetaEq.solve(theta, dt = timeStepDuration)
    phaseEq.solve(phase, dt = timeStepDuration)

    bench.start()

    ##from profiler import Profiler
    ##from profiler import calibrate_profiler
    ##fudge = calibrate_profiler(10000)
    ##profile = Profiler('profile-HEAD-i686', fudge=fudge)

    for i in range(steps):
        theta.updateOld()
        phase.updateOld()
        thetaEq.solve(theta, dt = timeStepDuration)
        phaseEq.solve(phase, dt = timeStepDuration)
예제 #5
0
파일: anisotropy.py 프로젝트: ghorn/Eg
    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()
        temperature.updateOld()
        phaseEq.solve(phase, dt=timeStepDuration)
        temperatureEq.solve(temperature, dt=timeStepDuration)

    bench.stop('solve')
예제 #6
0
    bench.stop('BCs')

    levelSetUpdateFrequency = int(0.8 * narrowBandWidth \
                                  / (cellSize * cflNumber * 2))

    step = 0

    if step % levelSetUpdateFrequency == 0:
        distanceVar.calcDistanceFunction()

    extensionVelocityVariable.setValue(depositionRateVariable())

    distanceVar.updateOld()
    catalystVar.updateOld()
    metalVar.updateOld()
    bulkCatalystVar.updateOld()
    distanceVar.extendVariable(extensionVelocityVariable)
    dt = cflNumber * cellSize / numerix.max(extensionVelocityVariable)
    advectionEquation.solve(distanceVar, dt=dt)
    surfactantEquation.solve(catalystVar, dt=dt)
    metalEquation.solve(metalVar, dt=dt, boundaryConditions=metalEquationBCs)
    bulkCatalystEquation.solve(bulkCatalystVar,
                               dt=dt,
                               boundaryConditions=catalystBCs)

    bench.start()

    for step in range(numberOfSteps):

        if step % levelSetUpdateFrequency == 0:
예제 #7
0
파일: plank.py 프로젝트: ghorn/Eg
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'):
	raw_input(Prompt)


for step in range(steps):
	u.updateOld()
	eq.solve(var=u,boundaryConditions=BCs,dt=timeStepDuration)
	eq= ImplicitDiffusionTerm(coeff=(a,a))+(u.getOld().getOld() - 2*u.getOld() + u) / timeStepDuration ** 2
	viewer.plot()
	hit_continue()

#getOld seems to be not working
예제 #8
0
def runSimpleTrenchSystem(faradaysConstant=9.6e4,
                          gasConstant=8.314,
                          transferCoefficient=0.5,
                          rateConstant0=1.76,
                          rateConstant3=-245e-6,
                          catalystDiffusion=1e-9,
                          siteDensity=9.8e-6,
                          molarVolume=7.1e-6,
                          charge=2,
                          metalDiffusion=5.6e-10,
                          temperature=298.,
                          overpotential=-0.3,
                          metalConcentration=250.,
                          catalystConcentration=5e-3,
                          catalystCoverage=0.,
                          currentDensity0=0.26,
                          currentDensity1=45.,
                          cellSize=0.1e-7,
                          trenchDepth=0.5e-6,
                          aspectRatio=2.,
                          trenchSpacing=0.6e-6,
                          boundaryLayerDepth=0.3e-6,
                          numberOfSteps=5,
                          displayViewers=True):

    cflNumber = 0.2
    numberOfCellsInNarrowBand = 10
    cellsBelowTrench = 10
    
    yCells = cellsBelowTrench \
             + int((trenchDepth + boundaryLayerDepth) / cellSize)

    xCells = int(trenchSpacing / 2 / cellSize)

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

    narrowBandWidth = numberOfCellsInNarrowBand * cellSize
    from fipy.models.levelSet.distanceFunction.distanceVariable import \
         DistanceVariable        

    distanceVar = DistanceVariable(
        name = 'distance variable',
        mesh = mesh,
        value = -1,
        narrowBandWidth = narrowBandWidth,
        hasOld = 1)

    bottomHeight = cellsBelowTrench * cellSize
    trenchHeight = bottomHeight + trenchDepth
    trenchWidth = trenchDepth / aspectRatio
    sideWidth = (trenchSpacing - trenchWidth) / 2

    x, y = mesh.getCellCenters()[...,0], mesh.getCellCenters()[...,1]
    distanceVar.setValue(1, where=(y > trenchHeight) | ((y > bottomHeight) & (x < xCells * cellSize - sideWidth)))

    distanceVar.calcDistanceFunction(narrowBandWidth = 1e10)

    from fipy.models.levelSet.surfactant.surfactantVariable import \
         SurfactantVariable
    
    catalystVar = SurfactantVariable(
        name = "catalyst variable",
        value = catalystCoverage,
        distanceVar = distanceVar)
    
    from fipy.variables.cellVariable import CellVariable

    bulkCatalystVar = CellVariable(
        name = 'bulk catalyst variable',
        mesh = mesh,
        value = catalystConcentration)

    metalVar = CellVariable(
        name = 'metal variable',
        mesh = mesh,
        value = metalConcentration)
    
    expoConstant = -transferCoefficient * faradaysConstant \
                   / (gasConstant * temperature)
    
    tmp = currentDensity1 * catalystVar.getInterfaceVar()

    exchangeCurrentDensity = currentDensity0 + tmp

    import fipy.tools.numerix as numerix
    expo = numerix.exp(expoConstant * overpotential)
    currentDensity = expo * exchangeCurrentDensity * metalVar \
                     / metalConcentration

    depositionRateVariable = currentDensity * molarVolume \
                             / (charge * faradaysConstant)

    extensionVelocityVariable = CellVariable(
        name = 'extension velocity',
        mesh = mesh,
        value = depositionRateVariable)   

    from fipy.models.levelSet.surfactant.adsorbingSurfactantEquation \
                import AdsorbingSurfactantEquation

    surfactantEquation = AdsorbingSurfactantEquation(
        surfactantVar = catalystVar,
        distanceVar = distanceVar,
        bulkVar = bulkCatalystVar,
        rateConstant = rateConstant0 + rateConstant3 * overpotential**3)

    from fipy.models.levelSet.advection.higherOrderAdvectionEquation \
                   import buildHigherOrderAdvectionEquation

    advectionEquation = buildHigherOrderAdvectionEquation(
        advectionCoeff = extensionVelocityVariable)

    from fipy.boundaryConditions.fixedValue import FixedValue
    from fipy.models.levelSet.electroChem.metalIonDiffusionEquation \
                         import buildMetalIonDiffusionEquation

    metalEquation = buildMetalIonDiffusionEquation(
        ionVar = metalVar,
        distanceVar = distanceVar,
        depositionRate = depositionRateVariable,
        diffusionCoeff = metalDiffusion,
        metalIonMolarVolume = molarVolume,
    )

    metalEquationBCs = FixedValue(mesh.getFacesTop(), metalConcentration)

    from fipy.models.levelSet.surfactant.surfactantBulkDiffusionEquation \
                    import buildSurfactantBulkDiffusionEquation

    bulkCatalystEquation = buildSurfactantBulkDiffusionEquation(
        bulkVar = bulkCatalystVar,
        distanceVar = distanceVar,
        surfactantVar = catalystVar,
        diffusionCoeff = catalystDiffusion,
        rateConstant = rateConstant0 * siteDensity
    )

    catalystBCs = FixedValue(mesh.getFacesTop(), catalystConcentration)

    if displayViewers:
        try:
            from fipy.viewers.mayaviViewer.mayaviSurfactantViewer import MayaviSurfactantViewer
            viewers = (MayaviSurfactantViewer(distanceVar, catalystVar.getInterfaceVar(), zoomFactor = 1e6, limits = { 'datamax' : 0.5, 'datamin' : 0.0 }, smooth = 1, title = 'catalyst coverage'),)
        except:
            from fipy.viewers import make
            viewers = (
                make(distanceVar, limits = { 'datamin' :-1e-9 , 'datamax' : 1e-9 }),
                make(catalystVar.getInterfaceVar()))
    else:
        viewers = ()

    levelSetUpdateFrequency = int(0.8 * narrowBandWidth \
                                  / (cellSize * cflNumber * 2))

    for step in range(numberOfSteps):

        if step % 5 == 0:
            for viewer in viewers:
                viewer.plot()

        if step % levelSetUpdateFrequency == 0:
            distanceVar.calcDistanceFunction()
            
        extensionVelocityVariable.setValue(depositionRateVariable())

        distanceVar.updateOld()
        catalystVar.updateOld()
        metalVar.updateOld()
        bulkCatalystVar.updateOld()

        distanceVar.extendVariable(extensionVelocityVariable)
        dt = cflNumber * cellSize / numerix.max(extensionVelocityVariable)

        advectionEquation.solve(distanceVar, dt = dt) 
        surfactantEquation.solve(catalystVar, dt = dt)
        metalEquation.solve(metalVar, dt = dt, 
                            boundaryConditions = metalEquationBCs)
        bulkCatalystEquation.solve(bulkCatalystVar, dt = dt,
                                   boundaryConditions = catalystBCs)

    try:
        import os
        import examples.levelSet.electroChem
        filepath = os.path.join(examples.levelSet.electroChem.__path__[0], 'test.gz')
        
        from fipy.tools import dump
        from fipy.tools import numerix
        print catalystVar.allclose(numerix.array(dump.read(filepath)), rtol = 1e-4)
    except:
        return 0
예제 #9
0
파일: inputGold.py 프로젝트: ghorn/Eg
def runGold(faradaysConstant=9.6e4,
            consumptionRateConstant=2.6e+6,
            molarVolume=10.21e-6,
            charge=1.0,
            metalDiffusion=1.7e-9,
            metalConcentration=20.0,
            catalystCoverage=0.15,
            currentDensity0=3e-2 * 16,
            currentDensity1=6.5e-1 * 16,
            cellSize=0.1e-7,
            trenchDepth=0.2e-6,
            aspectRatio=1.47,
            trenchSpacing=0.5e-6,
            boundaryLayerDepth=90.0e-6,
            numberOfSteps=10,
            taperAngle=6.0,
            displayViewers=True):
    
    cflNumber = 0.2
    numberOfCellsInNarrowBand = 20
    cellsBelowTrench = 10
    
    from fipy.tools import numerix
    from fipy import TrenchMesh
    mesh = TrenchMesh(cellSize = cellSize,
                      trenchSpacing = trenchSpacing,
                      trenchDepth = trenchDepth,
                      boundaryLayerDepth = boundaryLayerDepth,
                      aspectRatio = aspectRatio,
                      angle = numerix.pi * taperAngle / 180.,
                      bowWidth = 0.,
                      overBumpRadius = 0.,
                      overBumpWidth = 0.)

    narrowBandWidth = numberOfCellsInNarrowBand * cellSize

    from fipy.models.levelSet.distanceFunction.distanceVariable import DistanceVariable        
    distanceVar = DistanceVariable(
       name = 'distance variable',
       mesh = mesh,
       value = -1,
       narrowBandWidth = narrowBandWidth)

    distanceVar.setValue(1, where=mesh.getElectrolyteMask())
    distanceVar.calcDistanceFunction(narrowBandWidth = 1e10)

    from fipy.models.levelSet.surfactant.surfactantVariable import SurfactantVariable
    catalystVar = SurfactantVariable(
        name = "catalyst variable",
        value = catalystCoverage,
        distanceVar = distanceVar)

    from fipy.variables.cellVariable import CellVariable
    metalVar = CellVariable(
        name = 'metal variable',
        mesh = mesh,
        value = metalConcentration)

    exchangeCurrentDensity = currentDensity0 + currentDensity1 * catalystVar.getInterfaceVar()
    
    currentDensity = metalVar / metalConcentration * exchangeCurrentDensity

    depositionRateVariable = currentDensity * molarVolume / charge / faradaysConstant

    extensionVelocityVariable = CellVariable(
        name = 'extension velocity',
        mesh = mesh,
        value = depositionRateVariable)   

    from fipy.models.levelSet.surfactant.adsorbingSurfactantEquation \
                import AdsorbingSurfactantEquation

    catalystSurfactantEquation = AdsorbingSurfactantEquation(
        catalystVar,
        distanceVar = distanceVar,
        bulkVar = 0,
        rateConstant = 0,
        consumptionCoeff = consumptionRateConstant * extensionVelocityVariable)

    from fipy.models.levelSet.advection.higherOrderAdvectionEquation \
                   import buildHigherOrderAdvectionEquation

    advectionEquation = buildHigherOrderAdvectionEquation(
        advectionCoeff = extensionVelocityVariable)

    from fipy.boundaryConditions.fixedValue import FixedValue
    from fipy.models.levelSet.electroChem.metalIonDiffusionEquation \
                         import buildMetalIonDiffusionEquation

    metalEquation = buildMetalIonDiffusionEquation(
        ionVar = metalVar,
        distanceVar = distanceVar,
        depositionRate = depositionRateVariable,
        diffusionCoeff = metalDiffusion,
        metalIonMolarVolume = molarVolume)

    metalEquationBCs = FixedValue(mesh.getTopFaces(), metalConcentration)

    if displayViewers:

        try:
            
            from fipy.viewers.mayaviViewer.mayaviSurfactantViewer import MayaviSurfactantViewer
            viewers = (
                MayaviSurfactantViewer(distanceVar, catalystVar.getInterfaceVar(), zoomFactor = 1e6, limits = { 'datamax' : 1.0, 'datamin' : 0.0 }, smooth = 1, title = 'catalyst coverage'),)
            
        except:
            
            class PlotVariable(CellVariable):
                def __init__(self, var = None, name = ''):
                    CellVariable.__init__(self, mesh = mesh.getFineMesh(), name = name)
                    self.var = self._requires(var)

                def _calcValue(self):
                    return numerix.array(self.var[:self.mesh.getNumberOfCells()])

            from fipy.viewers import make
            viewers = (
                make(PlotVariable(var = distanceVar), limits = {'datamax' : 1e-9, 'datamin' : -1e-9}),
                make(PlotVariable(var = catalystVar.getInterfaceVar())))

    else:
        viewers = ()
    levelSetUpdateFrequency = int(0.7 * narrowBandWidth / cellSize / cflNumber / 2)
    step = 0
    
    while step < numberOfSteps:

        if step % 10 == 0:
            for viewer in viewers:
                viewer.plot()

        if step % levelSetUpdateFrequency == 0:
            
            distanceVar.calcDistanceFunction(deleteIslands = True)
            
        extensionVelocityVariable.setValue(numerix.array(depositionRateVariable))
        argmax = numerix.argmax(extensionVelocityVariable)
        dt = cflNumber * cellSize / extensionVelocityVariable[argmax]
        distanceVar.extendVariable(extensionVelocityVariable, deleteIslands = True)
        
        distanceVar.updateOld()
        catalystVar.updateOld()
        metalVar.updateOld()

        advectionEquation.solve(distanceVar, dt = dt)
        catalystSurfactantEquation.solve(catalystVar, dt = dt)
        metalEquation.solve(metalVar, boundaryConditions = metalEquationBCs, dt = dt)

        step += 1

    try:
        from fipy.tools import dump
        import os
        import examples.levelSet.electroChem
        data = dump.read(os.path.join(examples.levelSet.electroChem.__path__[0], 'goldData.gz'))
        n = mesh.getFineMesh().getNumberOfCells()
        print numerix.allclose(catalystVar[:n], data[:n], atol=1.0)
    except:
        return 0
예제 #10
0
        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

    thetaEq = buildThetaEquation(phase, theta)

    bench.stop('terms')

    theta.updateOld()
    phase.updateOld()
    thetaEq.solve(theta, dt=timeStepDuration)
    phaseEq.solve(phase, dt=timeStepDuration)

    bench.start()

    ##from profiler import Profiler
    ##from profiler import calibrate_profiler
    ##fudge = calibrate_profiler(10000)
    ##profile = Profiler('profile-HEAD-i686', fudge=fudge)

    for i in range(steps):
        theta.updateOld()
        phase.updateOld()
        thetaEq.solve(theta, dt=timeStepDuration)
        phaseEq.solve(phase, dt=timeStepDuration)
예제 #11
0
파일: superfill.py 프로젝트: ghorn/Eg
    bench.stop('BCs')

    levelSetUpdateFrequency = int(0.8 * narrowBandWidth \
                                  / (cellSize * cflNumber * 2))

    step = 0

    if step % levelSetUpdateFrequency == 0:
        distanceVar.calcDistanceFunction()

    extensionVelocityVariable.setValue(depositionRateVariable())

    distanceVar.updateOld()
    catalystVar.updateOld()
    metalVar.updateOld()
    bulkCatalystVar.updateOld()
    distanceVar.extendVariable(extensionVelocityVariable)
    dt = cflNumber * cellSize / numerix.max(extensionVelocityVariable)
    advectionEquation.solve(distanceVar, dt = dt)
    surfactantEquation.solve(catalystVar, dt = dt)
    metalEquation.solve(metalVar, dt = dt,
                        boundaryConditions = metalEquationBCs)
    bulkCatalystEquation.solve(bulkCatalystVar, dt = dt,
                               boundaryConditions = catalystBCs)

    bench.start()
      
    for step in range(numberOfSteps):

        if step % levelSetUpdateFrequency == 0:
예제 #12
0
## set up the comparison arrays

theta = surfactantVar.getInterfaceVar()[1]

if __name__ == "__main__":

    ## set up the viewers

    import fipy.viewers

    ## start time stepping

    currentTime = 0.

    for i in range(totalTimeSteps):

        ## evaluate the analytical and numerical solution and plot

        theta = surfactantVar.getInterfaceVar()[1]
        print "theta:", theta

        ## do a time step
        surfactantVar.updateOld()
        bulkVar.updateOld()
        surfEqn.solve(surfactantVar, dt=dt)
        bulkEqn.solve(bulkVar, dt=dt, boundaryConditions=bcs)
        currentTime += dt

    raw_input("finished")
예제 #13
0
파일: plank.py 프로젝트: ghorn/Eg
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'):
    raw_input(Prompt)


for step in range(steps):
    u.updateOld()
    eq.solve(var=u, boundaryConditions=BCs, dt=timeStepDuration)
    eq = ImplicitDiffusionTerm(coeff=(a, a)) + (
        u.getOld().getOld() - 2 * u.getOld() + u) / timeStepDuration**2
    viewer.plot()
    hit_continue()

#getOld seems to be not working
예제 #14
0
파일: input2D.py 프로젝트: ghorn/Eg
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),
       NthOrderBoundaryCondition(mesh.getFacesBottom(), 0, 3))

if __name__ == '__main__':

    import fipy.viewers
    viewer = fipy.viewers.make(vars = var, limits = {'datamin': 0., 'datamax': 1.0})
    viewer.plot()
    
dexp=-5

for step in range(steps):
    dt = numerix.exp(dexp)
    dt = min(100, dt)
    dexp += 0.01
    var.updateOld()
    eqch.solve(var, boundaryConditions = BCs, solver = solver, dt = dt)

    if __name__ == '__main__':
        viewer.plot()
        print 'step',step,'dt',dt
	
def _run():
    pass
            
예제 #15
0
파일: input2D.py 프로젝트: ghorn/Eg
       NthOrderBoundaryCondition(mesh.getFacesRight(), 0, 3),
       NthOrderBoundaryCondition(mesh.getFacesTop(), 0, 3),
       NthOrderBoundaryCondition(mesh.getFacesBottom(), 0, 3))

if __name__ == '__main__':

    import fipy.viewers
    viewer = fipy.viewers.make(vars=var,
                               limits={
                                   'datamin': 0.,
                                   'datamax': 1.0
                               })
    viewer.plot()

dexp = -5

for step in range(steps):
    dt = numerix.exp(dexp)
    dt = min(100, dt)
    dexp += 0.01
    var.updateOld()
    eqch.solve(var, boundaryConditions=BCs, solver=solver, dt=dt)

    if __name__ == '__main__':
        viewer.plot()
        print 'step', step, 'dt', dt


def _run():
    pass
예제 #16
0
파일: anisotropy.py 프로젝트: ghorn/Eg
    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()
        temperature.updateOld()
        phaseEq.solve(phase, dt=timeStepDuration)
        temperatureEq.solve(temperature, dt=timeStepDuration)

    bench.stop('solve')
예제 #17
0
eqI = TransientTerm() == ImplicitDiffusionTerm(coeff = D) + ImplicitSourceTerm(a * phi - a * phi * phi)
#eqCN = eqX + eqI

###
## Define Boundary Conditions
###
from fipy.boundaryConditions.fixedValue import FixedValue
BCs = (FixedValue(mesh.getFacesLeft(),valueLeft),
        FixedValue(faces = mesh.getFacesRight(), value=valueRight),
        FixedValue(mesh.getFacesTop(),valueTop),
        FixedValue(mesh.getFacesBottom(),valueBottom))


###
## Create a viewer
###
from fipy import Viewer
viewer = Viewer(vars = phi, datamin=0., datamax=1.0)


###
## Solve; Iterate
###
for step in range(steps):
    phi.updateOld()
    eqI.solve(var = phi, boundaryConditions = BCs, dt = timeStepDuration)
    print max(phi.value)
    viewer.plot()