def __init__(self, trenchDepth=None, trenchSpacing=None, boundaryLayerDepth=None, cellSize=None, aspectRatio=None, angle=0., communicator=parallelComm): """ `trenchDepth` - Depth of the trench. `trenchSpacing` - The distance between the trenches. `boundaryLayerDepth` - The depth of the hydrodynamic boundary layer. `cellSize` - The cell Size. `aspectRatio` - trenchDepth / trenchWidth `angle` - The angle for the taper of the trench. The trench mesh takes the parameters generally used to define a trench region and recasts then for the general `GapFillMesh`. """ heightBelowTrench = cellSize * 10. heightAboveTrench = trenchDepth / 1. fineRegionHeight = heightBelowTrench + trenchDepth + heightAboveTrench transitionHeight = fineRegionHeight * 3. domainWidth = trenchSpacing / 2. domainHeight = heightBelowTrench + trenchDepth + boundaryLayerDepth super(TrenchMesh, self).__init__(cellSize=cellSize, desiredDomainWidth=domainWidth, desiredDomainHeight=domainHeight, desiredFineRegionHeight=fineRegionHeight, transitionRegionHeight=transitionHeight, communicator=parallelComm) trenchWidth = trenchDepth / aspectRatio x, y = self.cellCenters Y = (y - (heightBelowTrench + trenchDepth / 2)) taper = numerix.tan(angle) * Y self.electrolyteMask = numerix.where(y > trenchDepth + heightBelowTrench, 1, numerix.where(y < heightBelowTrench, 0, numerix.where(x > trenchWidth / 2 + taper, 0, 1)))
def getElectrolyteMask(self): x, y = self.getCellCenters() Y = (y - (self.heightBelowTrench + self.trenchDepth / 2)) ## taper taper = numerix.tan(self.angle) * Y ## bow if abs(self.bowWidth) > 1e-12 and (-self.trenchDepth / 2 < Y < self.trenchDepth / 2): param1 = self.trenchDepth**2 / 8 / self.bowWidth param2 = self.bowWidth / 2 bow = -numerix.sqrt((param1 + param2)**2 - Y**2) + param1 - param2 else: bow = 0 ## over hang Y = y - (self.heightBelowTrench + self.trenchDepth - self.overBumpRadius) overBump = 0 if self.overBumpRadius > 1e-12: overBump += numerix.where(Y > -self.overBumpRadius, self.overBumpWidth / 2 * (1 + numerix.cos(Y * numerix.pi / self.overBumpRadius)), 0) tmp = self.overBumpRadius**2 - Y**2 tmp = (tmp > 0) * tmp overBump += numerix.where((Y > -self.overBumpRadius) & (Y > 0), numerix.where(Y > self.overBumpRadius, -self.overBumpRadius, -(self.overBumpRadius - numerix.sqrt(tmp))), 0) return numerix.where(y > self.trenchDepth + self.heightBelowTrench, 1, numerix.where(y < self.heightBelowTrench, 0, numerix.where(x > self.trenchWidth / 2 + taper - bow - overBump, 0, 1)))
value=initialTemperature, hasOld=1 ) bench.stop('variables') bench.start() from fipy.tools import numerix mVar = phase - 0.5 - kappa1 / numerix.pi * \ numerix.arctan(kappa2 * temperature) phaseY = phase.getFaceGrad().dot((0, 1)) phaseX = phase.getFaceGrad().dot((1, 0)) psi = theta + numerix.arctan2(phaseY, phaseX) Phi = numerix.tan(N * psi / 2) PhiSq = Phi**2 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
def tan(self): return self._UnaryOperatorVariable(lambda a: numerix.tan(a))
mesh=mesh, value=initialTemperature, hasOld=1) bench.stop('variables') bench.start() from fipy.tools import numerix mVar = phase - 0.5 - kappa1 / numerix.pi * \ numerix.arctan(kappa2 * temperature) phaseY = phase.getFaceGrad().dot((0, 1)) phaseX = phase.getFaceGrad().dot((1, 0)) psi = theta + numerix.arctan2(phaseY, phaseX) Phi = numerix.tan(N * psi / 2) PhiSq = Phi**2 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