本文整理汇总了Python中fipy.variables.variable.Variable.setValue方法的典型用法代码示例。如果您正苦于以下问题:Python Variable.setValue方法的具体用法?Python Variable.setValue怎么用?Python Variable.setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fipy.variables.variable.Variable
的用法示例。
在下文中一共展示了Variable.setValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setValue
# 需要导入模块: from fipy.variables.variable import Variable [as 别名]
# 或者: from fipy.variables.variable.Variable import setValue [as 别名]
def setValue(self, value, unit = None, where = None):
if where is not None:
shape = numerix.getShape(where)
if shape != self.shape \
and shape == self._getShapeFromMesh(mesh=self.getMesh()):
for dim in self.elementshape:
where = numerix.repeat(where[numerix.newaxis, ...], repeats=dim, axis=0)
return Variable.setValue(self, value=value, unit=unit, where=where)
示例2: AdsorbingSurfactantEquation
# 需要导入模块: from fipy.variables.variable import Variable [as 别名]
# 或者: from fipy.variables.variable.Variable import setValue [as 别名]
#.........这里部分代码省略.........
- `otherBulkVar`: The value of the `otherVar` in the bulk.
- `otherRateConstant`: The adsorption rate of the `otherVar`.
- `consumptionCoeff`: The rate that the `surfactantVar` is consumed during deposition.
"""
self.eq = TransientTerm(coeff = 1) - ExplicitUpwindConvectionTerm(SurfactantConvectionVariable(distanceVar))
self.dt = Variable(0.)
mesh = distanceVar.mesh
adsorptionCoeff = self.dt * bulkVar * rateConstant
spCoeff = adsorptionCoeff * distanceVar._cellInterfaceFlag
scCoeff = adsorptionCoeff * distanceVar.cellInterfaceAreas / mesh.cellVolumes
self.eq += ImplicitSourceTerm(spCoeff) - scCoeff
if otherVar is not None:
otherSpCoeff = self.dt * otherBulkVar * otherRateConstant * distanceVar._cellInterfaceFlag
otherScCoeff = -otherVar.interfaceVar * scCoeff
self.eq += ImplicitSourceTerm(otherSpCoeff) - otherScCoeff
vars = (surfactantVar, otherVar)
else:
vars = (surfactantVar,)
total = 0
for var in vars:
total += var.interfaceVar
maxVar = (total > 1) * distanceVar._cellInterfaceFlag
val = distanceVar.cellInterfaceAreas / mesh.cellVolumes
for var in vars[1:]:
val -= distanceVar._cellInterfaceFlag * var
spMaxCoeff = 1e20 * maxVar
scMaxCoeff = spMaxCoeff * val * (val > 0)
self.eq += ImplicitSourceTerm(spMaxCoeff) - scMaxCoeff - 1e-40
if consumptionCoeff is not None:
self.eq += ImplicitSourceTerm(consumptionCoeff)
def solve(self, var, boundaryConditions=(), solver=None, dt=None):
"""
Builds and solves the `AdsorbingSurfactantEquation`'s linear system once.
:Parameters:
- `var`: A `SurfactantVariable` to be solved for. Provides the initial condition, the old value and holds the solution on completion.
- `solver`: The iterative solver to be used to solve the linear system of equations.
- `boundaryConditions`: A tuple of boundaryConditions.
- `dt`: The time step size.
"""
self.dt.setValue(dt)
if solver is None:
import fipy.solvers.solver
if fipy.solvers.solver == 'pyamg':
from fipy.solvers.pyAMG.linearGeneralSolver import LinearGeneralSolver
solver = LinearGeneralSolver(tolerance=1e-15, iterations=2000)
else:
from fipy.solvers import LinearPCGSolver
solver = LinearPCGSolver()
if type(boundaryConditions) not in (type(()), type([])):
boundaryConditions = (boundaryConditions,)
var.constrain(0, var.mesh.exteriorFaces)
self.eq.solve(var,
boundaryConditions=boundaryConditions,
solver = solver,
dt=1.)
def sweep(self, var, solver=None, boundaryConditions=(), dt=None, underRelaxation=None, residualFn=None):
r"""
Builds and solves the `AdsorbingSurfactantEquation`'s linear
system once. This method also recalculates and returns the
residual as well as applying under-relaxation.
:Parameters:
- `var`: The variable to be solved for. Provides the initial condition, the old value and holds the solution on completion.
- `solver`: The iterative solver to be used to solve the linear system of equations.
- `boundaryConditions`: A tuple of boundaryConditions.
- `dt`: The time step size.
- `underRelaxation`: Usually a value between `0` and `1` or `None` in the case of no under-relaxation
"""
self.dt.setValue(dt)
if solver is None:
from fipy.solvers import DefaultAsymmetricSolver
solver = DefaultAsymmetricSolver()
if type(boundaryConditions) not in (type(()), type([])):
boundaryConditions = (boundaryConditions,)
var.constrain(0, var.mesh.exteriorFaces)
return self.eq.sweep(var, solver=solver, boundaryConditions=boundaryConditions, underRelaxation=underRelaxation, residualFn=residualFn, dt=1.)