Changeset 1588
- Timestamp:
- 10/11/2005 03:59:16 PM (3 years ago)
- Location:
- trunk/examples/levelSet/electroChem
- Files:
-
- 3 modified
-
inputSimpleTrenchSystem.py (modified) (6 diffs)
-
inputWriteScriptHowTo.py (modified) (12 diffs)
-
test.gz (modified) (previous)
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/levelSet/electroChem/inputSimpleTrenchSystem.py
r1585 r1588 230 230 231 231 from fipy.variables.cellVariable import CellVariable 232 232 233 bulkCatalystVar = CellVariable( 233 234 name = 'bulk catalyst variable', 234 235 mesh = mesh, 235 236 value = catalystConcentration) 236 237 from fipy.variables.cellVariable import CellVariable 237 238 238 metalVar = CellVariable( 239 239 name = 'metal variable', … … 267 267 surfactantVar = catalystVar, 268 268 distanceVar = distanceVar, 269 bulkVar = catalystConcentration,269 bulkVar = bulkCatalystVar, 270 270 rateConstant = rateConstant0 + rateConstant3 * overpotential**3) 271 271 … … 322 322 for step in range(numberOfSteps): 323 323 324 if not runAsTest: 325 if step % levelSetUpdateFrequency == 0: 326 distanceVar.calcDistanceFunction() 327 328 extensionVelocityVariable.setValue(depositionRateVariable()) 324 if step % levelSetUpdateFrequency == 0: 325 distanceVar.calcDistanceFunction() 326 327 extensionVelocityVariable.setValue(depositionRateVariable()) 329 328 330 329 distanceVar.updateOld() … … 332 331 metalVar.updateOld() 333 332 bulkCatalystVar.updateOld() 333 334 334 distanceVar.extendVariable(extensionVelocityVariable) 335 if not runAsTest: 336 dt = cflNumber * cellSize / max(extensionVelocityVariable) 337 else: 338 dt = 0.1 335 dt = cflNumber * cellSize / max(extensionVelocityVariable) 336 339 337 advectionEquation.solve(distanceVar, dt = dt) 340 338 surfactantEquation.solve(catalystVar, dt = dt) … … 342 340 boundaryConditions = metalEquationBCs) 343 341 bulkCatalystEquation.solve(bulkCatalystVar, dt = dt, 344 boundaryConditions = catalystBCs)342 boundaryConditions = catalystBCs) 345 343 346 344 if not runAsTest: … … 349 347 350 348 if runAsTest: 349 351 350 import os 352 testFile = 'test.gz'353 351 import examples.levelSet.electroChem 354 import gzip 355 filepath = os.path.join(examples.levelSet.electroChem.__path__[0], 356 testFile) 357 358 filestream = gzip.open(filepath,'r') 359 import cPickle 360 testData = cPickle.load(filestream) 361 filestream.close() 362 print catalystVar.allclose(testData) 352 filepath = os.path.join(examples.levelSet.electroChem.__path__[0], 'test.gz') 353 354 from fipy.tools import dump 355 print catalystVar.allclose(dump.read(filepath)) 356 363 357 else: 364 358 raw_input("finished") -
trunk/examples/levelSet/electroChem/inputWriteScriptHowTo.py
r1587 r1588 82 82 >>> transferCoefficient = 0.5 83 83 84 properties associated with the acceleratorspecies,85 86 >>> rateConstant = 1.7687 >>> overpotentialDependence= -245e-688 >>> acceleratorDiffusionCoefficient= 1e-984 properties associated with the catalyst species, 85 86 >>> rateConstant0 = 1.76 87 >>> rateConstant3 = -245e-6 88 >>> catalystDiffusion = 1e-9 89 89 >>> siteDensity = 9.8e-6 90 90 … … 100 100 >>> overpotential = -0.3 101 101 >>> bulkMetalConcentration = 250. 102 >>> bulkAcceleratorConcentration = 5e-3103 >>> initialAcceleratorCoverage = 0.102 >>> catalystConcentration = 5e-3 103 >>> catalystCoverage = 0. 104 104 105 105 parameters obtained from experiments on flat copper electrodes, 106 106 107 >>> c onstantCurrentDensity= 0.26108 >>> acceleratorDependenceCurrentDensity= 45.107 >>> currentDensity0 = 0.26 108 >>> currentDensity1 = 45. 109 109 110 110 general simulation control parameters, … … 211 211 .. raw:: latex 212 212 213 Create the acceleratorsurfactant coverage, $\theta$, variable.213 Create the catalyst surfactant coverage, $\theta$, variable. 214 214 215 215 This variable influences the deposition rate. … … 217 217 >>> from fipy.models.levelSet.surfactant.surfactantVariable import \ 218 218 ... SurfactantVariable 219 >>> acceleratorVar = SurfactantVariable(220 ... name = " acceleratorvariable",221 ... value = initialAcceleratorCoverage,219 >>> catalystVar = SurfactantVariable( 220 ... name = "catalyst variable", 221 ... value = catalystCoverage, 222 222 ... distanceVar = distanceVar) 223 223 224 224 .. raw:: latex 225 225 226 Create the bulk acceleratorconcentration, $c_{\theta}$,226 Create the bulk catalyst concentration, $c_{\theta}$, 227 227 228 228 in the electrolyte, 229 229 230 230 >>> from fipy.variables.cellVariable import CellVariable 231 >>> bulk AcceleratorVar = CellVariable(232 ... name = 'bulk acceleratorvariable',231 >>> bulkCatalystVar = CellVariable( 232 ... name = 'bulk catalyst variable', 233 233 ... mesh = mesh, 234 ... value = bulkAcceleratorConcentration)234 ... value = catalystConcentration) 235 235 236 236 Create the bulk metal ion concentration, … … 271 271 constant, $T$ is the temperature and $\eta$ is the 272 272 overpotential. The exchange current density is an empirical 273 function of acceleratorcoverage,273 function of catalyst coverage, 274 274 275 275 $$ i_0(\theta) = b_0 + b_1 \theta $$ … … 279 279 >>> expoConstant = -transferCoefficient * faradaysConstant \ 280 280 ... / (gasConstant * temperature) 281 >>> tmp = acceleratorDependenceCurrentDensity\282 ... * acceleratorVar.getInterfaceVar()283 >>> exchangeCurrentDensity = c onstantCurrentDensity+ tmp281 >>> tmp = currentDensity1 \ 282 ... * catalystVar.getInterfaceVar() 283 >>> exchangeCurrentDensity = currentDensity0 + tmp 284 284 >>> expo = numerix.exp(expoConstant * overpotential) 285 285 >>> currentDensity = expo * exchangeCurrentDensity * metalVar \ … … 309 309 $$ \dot{\theta} = J v \theta + k c_{\theta}^i (1 - \theta) $$ 310 310 311 where $\theta$ is the coverage of acceleratorat the interface,311 where $\theta$ is the coverage of catalyst at the interface, 312 312 $J$ is the curvature of the interface, $v$ is the normal velocity 313 313 of the interface, $c_{\theta}^i$ is the concentration of 314 acceleratorin the bulk at the interface. The value $k$ is given314 catalyst in the bulk at the interface. The value $k$ is given 315 315 by an empirical function of overpotential, 316 316 … … 323 323 ... import AdsorbingSurfactantEquation 324 324 >>> surfactantEquation = AdsorbingSurfactantEquation( 325 ... surfactantVar = acceleratorVar,325 ... surfactantVar = catalystVar, 326 326 ... distanceVar = distanceVar, 327 ... bulkVar = bulk AcceleratorConcentration,328 ... rateConstant = rateConstant \329 ... + overpotentialDependence* overpotential**3)327 ... bulkVar = bulkCatalystVar, 328 ... rateConstant = rateConstant0 \ 329 ... + rateConstant3 * overpotential**3) 330 330 331 331 .. raw:: latex … … 417 417 >>> from fipy.models.levelSet.surfactant.surfactantBulkDiffusionEquation \ 418 418 ... import buildSurfactantBulkDiffusionEquation 419 >>> bulk AcceleratorEquation = buildSurfactantBulkDiffusionEquation(420 ... bulkVar = bulk AcceleratorVar,419 >>> bulkCatalystEquation = buildSurfactantBulkDiffusionEquation( 420 ... bulkVar = bulkCatalystVar, 421 421 ... distanceVar = distanceVar, 422 ... surfactantVar = acceleratorVar,423 ... diffusionCoeff = acceleratorDiffusionCoefficient,424 ... rateConstant = rateConstant * siteDensity422 ... surfactantVar = catalystVar, 423 ... diffusionCoeff = catalystDiffusion, 424 ... rateConstant = rateConstant0 * siteDensity 425 425 ... ) 426 426 427 >>> acceleratorBCs = (427 >>> catalystBCs = ( 428 428 ... FixedValue( 429 429 ... mesh.getFacesTop(), 430 ... bulkAcceleratorConcentration430 ... catalystConcentration 431 431 ... ),) 432 432 … … 436 436 ... from fipy.viewers import make 437 437 ... distanceViewer = make(distanceVar, limits = { 'datamin' :-1e-9 , 'datamax' : 1e-9 }) 438 ... acceleratorViewer = make(acceleratorVar.getInterfaceVar())438 ... catalystViewer = make(catalystVar.getInterfaceVar()) 439 439 440 440 The `levelSetUpdateFrequency` defines how often to call the … … 458 458 >>> for step in range(numberOfSteps): 459 459 ... 460 ... if __name__ == '__main__': 461 ... if step % levelSetUpdateFrequency == 0: 462 ... distanceVar.calcDistanceFunction() 460 ... if step % levelSetUpdateFrequency == 0: 461 ... distanceVar.calcDistanceFunction() 463 462 ... 464 ... extensionVelocityVariable.setValue(depositionRateVariable())463 ... extensionVelocityVariable.setValue(depositionRateVariable()) 465 464 ... 466 465 ... distanceVar.updateOld() 467 ... acceleratorVar.updateOld()466 ... catalystVar.updateOld() 468 467 ... metalVar.updateOld() 469 ... bulk AcceleratorVar.updateOld()468 ... bulkCatalystVar.updateOld() 470 469 ... distanceVar.extendVariable(extensionVelocityVariable) 471 ... if __name__ == '__main__': 472 ... dt = cflNumber * cellSize / max(extensionVelocityVariable) 473 ... else: 474 ... dt = 0.1 470 ... dt = cflNumber * cellSize / max(extensionVelocityVariable) 475 471 ... advectionEquation.solve(distanceVar, dt = dt) 476 ... surfactantEquation.solve( acceleratorVar, dt = dt)472 ... surfactantEquation.solve(catalystVar, dt = dt) 477 473 ... metalEquation.solve(metalVar, dt = dt, 478 474 ... boundaryConditions = metalEquationBCs) 479 ... bulk AcceleratorEquation.solve(bulkAcceleratorVar, dt = dt,480 ... boundaryConditions = acceleratorBCs)475 ... bulkCatalystEquation.solve(bulkCatalystVar, dt = dt, 476 ... boundaryConditions = catalystBCs) 481 477 ... 482 478 ... if __name__ == '__main__': 483 479 ... distanceViewer.plot() 484 ... acceleratorViewer.plot()480 ... catalystViewer.plot() 485 481 486 482 >>> if __name__ == '__main__': … … 492 488 493 489 >>> import os 494 >>> testFile = 'test.gz'495 490 >>> import examples.levelSet.electroChem 496 >>> import gzip497 491 >>> filepath = os.path.join(examples.levelSet.electroChem.__path__[0], 498 ... testFile) 499 >>> filestream = gzip.open(filepath,'r') 500 >>> import cPickle 501 >>> testData = cPickle.load(filestream) 502 >>> filestream.close() 503 >>> print acceleratorVar.allclose(testData) 492 ... 'test.gz') 493 494 >>> from fipy.tools import dump 495 >>> print catalystVar.allclose(dump.read(filepath)) 504 496 1 505 497
FiPy: A Finite Volume PDE Solver Using Python