On Mon, Jul 2, 2012 at 10:08 AM, Daniel Wheeler <[email protected]>wrote:
> On Mon, Jul 2, 2012 at 6:56 AM, Yun Tao <[email protected]> wrote: > >> >> 1. In Equation [1], when I set the coefficient of the ConvectionTerm to a >> function of psi, it returns >> >> *TypeError*: unsupported operand type(s) for *: 'binOp' and 'unOp' >> >> >> I gather this may due to me multiplying a FaceVariable to a CellVariable >> as a consequence of me using a position-dependent convection term. However, >> when I tested what happens if I remove the space-dependence, I get >> >> *VectorCoeffError*: The coefficient must be a vector value. >> >> >> Of course, when I take out the dependence on psi altogether, everything's >> fine. >> > > The coefficient does need to be a vector value. Unfortunately, a function > of psi alone is not a vector field, but a scalar field. Multiply it by a > vector. For example, > > >>> import fipy as fp > >>> fp.Grid1D(nx=2) > >>> v = fp.CellVariable(mesh=m) > >>> (v * [[1]]).rank > 1 > >>> (v * [[1]]).shape > (1, 2) > That worked! However, when trying to incorporate the spatial coordinate, the TypeError from above remains: >>> eq1 = (TransientTerm(var=phi) == DiffusionTerm(coeff = D, var=phi) + convection(coeff=(c / (psi *[[1]]) ), var=phi) ) RUNS >>> pos = FaceVariable(mesh=mesh, value=mesh.getFaceCenters(), rank=1) >>> eq1 = (TransientTerm(var=phi) == DiffusionTerm(coeff = D, var=phi) + convection(coeff=(c ** numerix.tanh(40*pos)* / (psi *[[1]]) ), var=phi) ) *TypeError*: unsupported operand type(s) for *: 'binOp' and 'unOp' > >> 2. In Equation [2], what is the proper way to assign the variables? I >> could have >> >> eq2 = (TransientTerm(var=psi) == ImplicitSourceTerm(var=phi) + >>> ImplicitSourceTerm(coeff=c**phi*, var=*psi*) >> >> >> or, equally, >> >> eq2 = (TransientTerm(var=psi) == ImplicitSourceTerm(var=phi) + >>> ImplicitSourceTerm(coeff=c**psi*, var=*phi*) >> >> >> Does it even make any difference? >> > > Shouldn't do, but I'm not entirely sure. Try it and see. I would say that > the former is probably better. > > So after trying both configs, I got two different solutions. At time-step 150: >>> print phi_uno.allclose(phi_dos, atol = 2e-3) False >>> print phi_uno.allclose(phi_dos, atol = 2e-2) True >>> print psi_uno.allclose(psi_dos, atol = 2e-1) False >>> print psi_uno.allclose(psi_dos, atol = 2e0) True Is there a rule to decide on which config is more appropriate? > >> Can't say it enough, but thank you again for all your kind and generous >> help. >> > > No problem. > > Cheers > > -- > Daniel Wheeler > > _______________________________________________ > fipy mailing list > [email protected] > http://www.ctcms.nist.gov/fipy > [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ] > > -- Graduate Group of Ecology Doctoral Candidate Department of Environmental Science and Policy Center for Population Biology University of California, Davis
_______________________________________________ fipy mailing list [email protected] http://www.ctcms.nist.gov/fipy [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
