def __iadd__(self, other): if not isinstance(other, DiffusionTerm): return DiffusionTerm.__add__(self, other) elif isinstance(other, _CollectedDiffusionTerm): for term in other.orders: self += term elif other.order == 0: if self.orders[0] is None: self.orders[0] = other elif other.order == 2: # index is order / 2 if self.orders[1] is None: self.orders[1] = other else: self.orders[1] += other else: self.orders.append(other) return self
def _buildMatrix(self, var, SparseMatrix, boundaryConditions=(), dt=1.0, equation=None): L, b = DiffusionTerm._buildMatrix( self, var.getOld(), SparseMatrix, boundaryConditions=boundaryConditions, dt=dt, equation=equation ) return (0, b - L * var.getValue())
# Define solution variable concentration = CellVariable(name="solution variable", mesh=mesh, value=0.0) ## x dir concentration.constrain(valueLow, mesh.facesLeft) concentration.constrain(valueHigh, mesh.facesRight) ### y dir #concentration.constrain(valueLow, mesh.facesBottom) #concentration.constrain(valueHigh, mesh.facesTop) print("C before:") print(concentration) #Define and solve steady state diffusion equation diffTerm = DiffusionTerm(coeff=D) diffTerm.solve(var=concentration, solver=LinearBicgstabSolver(tolerance=1.0e-6, iterations=int(1e8))) #DiffusionTerm(coeff=D).solve(var=concentration, solver=LinearGMRESSolver(tolerance=1.0e-6, iterations=int(1e9))) ##DiffusionTerm(coeff=D).solve(var=concentration, solver=LinearLUSolver()) print("C solved:") print(concentration) #Post-process to calculate tortuosity in x direction concentration[where(phase == 1.0)[0]] = 0 #dp = average(phase[where(x == min(x))]) #selection = where(x == min(x))
t7 = time.time() x, y, z = mesh.cellCenters # Boundary conditions valueHigh = 1.0 valueLow = 0.0 # Define solution variable concentration = CellVariable(name="solution variable", mesh=mesh, value=0.0) concentration.constrain(valueLow, mesh.facesLeft) concentration.constrain(valueHigh, mesh.facesRight) #Define and solve steady state diffusion equation DiffusionTerm(coeff=D).solve(var=concentration, solver=LinearGMRESSolver(tolerance=1.0e-6, iterations=int(1e9))) #Post-process to calculate tortuosity in x direction concentration[where(phase == 1.0)[0]] = 0 dp = average(phase[where(x == min(x))]) dc1 = average(concentration.value[where(x == min(x))]) dc2 = average(concentration.value[where(x == min(x))]) * (1. - dp) xtortuosity = dx * porosity / dc1 / (dx * nx) / 2 xtortuosity2 = dx * porosity / dc2 / (dx * nx) / 2 t8 = time.time() # Write results to file results = open(args.output + '/' + filename + '.tor', 'w') results.write('porosity %g' % porosity)