0

I know that we can set the parameter 'underRelaxation' if we use 'sweep' to solve the equation. eg:

xVelocity_eq.sweep(dt=dt, underRelaxation = 0.5)

But how to set this parameter to coupled equation. eg:

coupled_eq = xVelocity_eq & yVelocity_eq & zVelocity

coupled_eq.sweep(dt=dt,underRelaxation = ?)

I have tried set underRelaxtion = 0.5 and set underRelaxation as a array like following code:

relaxation = np.zeros(len(self.yVelocity) + len(self.zVelocity) + len(self.xVelocity)) relaxation[:] = velocityRelaxation

coupled_eq.sweep(dt=dt,underRelaxation = relaxation)

However, it does not work correctly with an IndexError(indices out of range).If i do not set the underRelaxation, the error will not appear and the codes can run.

File "C:\Program Files\Itasca\PFC500\exe64\python27\lib\site-packages\fipy\terms\term.py", line 237, in sweep solver._applyUnderRelaxation(underRelaxation=underRelaxation)

File "C:\Program Files\Itasca\PFC500\exe64\python27\lib\site-packages\fipy\solvers\solver.py", line 133, in _applyUnderRelaxation self.matrix.putDiagonal(self.matrix.takeDiagonal() / underRelaxation)

File "C:\Program Files\Itasca\PFC500\exe64\python27\lib\site-packages\fipy\matrices\pysparseMatrix.py", line 223, in putDiagonal self.put(vector, ids, ids)

File "C:\Program Files\Itasca\PFC500\exe64\python27\lib\site-packages\fipy\matrices\offsetSparseMatrix.py", line 55, in put SparseMatrix.put(self, vector, id1 + self.mesh.numberOfCells * self.equationIndex, id2 + self.mesh.numberOfCells * self.varIndex)

File "C:\Program Files\Itasca\PFC500\exe64\python27\lib\site-packages\fipy\matrices\pysparseMatrix.py", line 198, in put self.matrix.put(vector, id1, id2)

IndexError: indices out of range

1 Answers1

1

The underRelaxation argument takes a single float value greater than 0 up to 1. Setting the underRelaxation=0.9 works fine in this example.

import numpy as np
from fipy import (
    CellVariable,
    TransientTerm,
    DiffusionTerm,
    Grid1D,
)

nx = 10

mesh = Grid1D(nx=nx, dx=1.0)

var_a = CellVariable(mesh=mesh, value=1.0)
var_b = CellVariable(mesh=mesh, value=0.0)

eqn_a = TransientTerm(var=var_a) == DiffusionTerm(var=var_a)
eqn_b = TransientTerm(var=var_b) == DiffusionTerm(var=var_b)

eqn = eqn_a & eqn_b

#underRelaxation = np.arange(nx * 2) / nx / 4. + 0.1
underRelaxation = 0.9

eqn.sweep(dt=1., underRelaxation=underRelaxation)

It seems that the underRelaxation argument can also be an array of the same length as the diagonal of the matrix (2 * nx in this case) although this may never have been how it was intended to be used. Anyway, underRelaxation = np.arange(nx * 2) / nx / 4. + 0.1 works as well.

wd15
  • 1,068
  • 5
  • 8
  • Thank you for your patient reply. I tried again, it works fine when I program in jupyter. But it does not work when I program in PFC (a software which include Python console). Maybe the problem is with the software. – Xiukai Wang Jun 25 '20 at 00:30
  • Interesting. I can't imagine why the environment would matter just for this one parameter. Did you install FiPy in PFC or is it included as part of the package? If the latter, perhaps they provide an old version? – jeguyer Jun 25 '20 at 21:20