Exemple #1
0
# 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)