How to set the parameter 'underRelaxation' to a coupled equation?

让人想犯罪 __ 提交于 2021-02-11 13:25:04

问题


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:


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.



来源:https://stackoverflow.com/questions/62493994/how-to-set-the-parameter-underrelaxation-to-a-coupled-equation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!