Hello again,
>> 1.I have a dependent variable phi(x,y,t). Is it possible to solve the
below
>> type of equation for this variable:
> >
> >TransientTerm == DiffusionTerm_x + ConvectionTerm_x + DiffusionTerm_y +
> >ConvectionTerm_y,
>Use "DiffusionTerm( [ (a, 0), (0, b) ] )" and "ConvectionTerm((c,
>d))". There is FAQ in the manual that addresses this.
Sorry, it's not very clear to me. So, the diffusion term turns to be
DiffusionTerm([[[D, 0], [0, 0]]]) OR DiffusionTerm([[D,0]]) if i want d/dx D
d/dx phi in 2D mesh
and convection term
<Some>ConvectionTerm([[U,0],[0,0]]) OR <Some>ConvectionTerm([U,0]) if i want
d/dx U phi in 2D mesh?
I tried the above and all other examples from the FAQ in the manual and I keep
getting the errors:
File "pspec2d.py", line 32, in <module>
eq = TransientTerm() == diffTerm + convTerm + Source
File "/usr/local/Python26/lib/python2.6/site-packages/fipy/terms/term.py",
line 438, in __eq__
return self - other
File "/usr/local/Python26/lib/python2.6/site-packages/fipy/terms/term.py",
line 388, in __sub__
return self + (-other)
File
"/usr/local/Python26/lib/python2.6/site-packages/fipy/terms/equation.py", line
182, in __neg__
dup.terms[key] = -term
File
"/usr/local/Python26/lib/python2.6/site-packages/fipy/terms/diffusionTerm.py",
line 115, in __neg__
negatedCoeff[0] = -negatedCoeff[0]
TypeError: bad operand type for unary -: 'list'
If I just use some normal coeff (i.e, DiffusionTerm(1)) the script works fine.
from fipy import *
Xmax=1.
Ymax=1.
nsteps=100
dx = Xmax / float(nsteps)
dy = Ymax / float(nsteps)
mesh_xy = Grid2D(dx = dx, dy = dy, nx = nsteps, ny = nsteps)
x,y = mesh_xy.getCellCenters()
phi = CellVariable(mesh=mesh_xy, name = "none", value=1.0)
valueLeft = 0
valueRight = 0
BCs = (FixedValue(faces=mesh_xy.getFacesLeft(), value=valueLeft),
FixedValue(faces=mesh_xy.getFacesRight(), value=valueRight))
Source = CellVariable(mesh=mesh_xy)
Source.setValue(1)
convTerm = PowerLawConvectionTerm(1)
diffTerm = DiffusionTerm([[[5,0], [0,0]]])
eq = TransientTerm() == diffTerm + convTerm + Source
timeStepDuration = 1
time = 1
viewer = Viewer(vars=(phi), limits={'datamin': 1e-15, 'datamax': 1e1})
while time <= 20
timeStep = timeStepDuration
eq.solve(var=phi, boundaryConditions=BCs, dt=timeStep)
time=time+timeStep
viewer.plot()