There should be no reason for incompatibility between 1 and var2.

max doesn't know about numpy arrays or FiPy Variables.

numerix.fmax should work, but doesn't. Oddly, numerix.fmax((1-var2), a) does 
work. I vaguely know why, but need to delve deeper 
(https://github.com/usnistgov/fipy/issues/486). 

You should use (1-var2) instead of (1-var2).value or else dfactor will never 
change when var2 changes.

Aniruddha's solution resolves the errors, but gives a static expression. 
.setValue() is a one-time thing; there is no dependency on the value of var2.

I would be inclined to write the dynamic expression:

  a_greater = a > (1 - var2)
  dfactor = a * a_greater + (1 - var2) * ~a_greater




On Jan 23, 2016, at 4:37 PM, Aniruddha Jana <[email protected]> wrote:

> Hi Yun,
> 
> I think the problem is due to conflict of variable types between "1" and 
> "var2" in the computation of (1 - var2).
> 
> The following lines seem to work:
> 
> a = 0.01
> var = CellVariable(mesh=mesh, value=0.)
> var2 = CellVariable(mesh=mesh,value=1.)
> dfactor = CellVariable(mesh=mesh,value=a)
> dfactor.setValue(1-var2,where=((1-var2) > a))
> 
> Regards,
> Aniruddha
> 
> On Fri, Jan 22, 2016 at 3:34 PM, Yun Tao <[email protected]> wrote:
> Hi FiPy community,
> 
> I'm solving a diffusion equation for var on a 2D grid; the diffusion 
> coefficient is set up as a function of another CellVariable var2. Problems 
> pop up when I tried to truncate the coefficient value at each location to a 
> small positive number a:
> ​
> ​a = 0.01​
> dfactor = ​max(​a, 1-​var2​)​
> eq = (TransientTerm() == DiffusionTerm(coeff=​dfactor)
> 
> ​When I then tried solving it, I get the error message
> ValueError: The truth value of an array with more than one element is 
> ambiguous. Use a.any() or a.all()​
>  
> ​Alternatively, I tried
> ​dfactor = numerix.fmax(a, (1-var2).value)
> but got
> ValueError: operands could not be broadcast together with shapes (10000,) 
> (2,2)
> 
> ​Experimenting with, for example, getValue() and other functions such as
> dfactor = (1-var2)[(1-var2).value<a]=a
> also didn't work.
> 
> Does anyone have ideas on the appropriate​​​ syntax to use?
> 
> Thanks,
> Yun​
> 
> 
> -- 
> Yun Tao
> Postdoc 
> Center for Infectious Disease Dynamics
> Pennsylvania State University
> State College, PA 16803
> 
> _______________________________________________
> fipy mailing list
> [email protected]
> http://www.ctcms.nist.gov/fipy
>   [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
> 
> 
> _______________________________________________
> fipy mailing list
> [email protected]
> http://www.ctcms.nist.gov/fipy
>  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


_______________________________________________
fipy mailing list
[email protected]
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to