Re: fipy diffusion setup

2016-04-20 Thread Daniel Wheeler
On Tue, Apr 19, 2016 at 4:10 PM, Phil Battle  wrote:
> Hi Daniel
> Thank you for following up-
> I did try your suggestion, ( C is my concentration dependent Cell variable)
>
> Dx=Dpe_x*(a_x+((1.-a_x)/(b_x*C+g_x)))
> Dz=Dpe_z*(a_z+((1.-a_z)/(b_z*C+g_z)))
> diff = Dx.dot([[1,0],[0,0]])+Dz.dot([[0,0],[0,1]])
>
> and program runs and "looks correct" so good to go!!

Great news.

> But before your suggestion I was trying to create the suggested rank 2
> diffusion coefficient a different way and I did not get far before hitting a
> road block- If you have time to answer this specific question it may help
> with understanding the structure of variables in this program
>
> I created a 2x2 Cell Variable on a 2x2 2Dim mesh.  I can show that code if
> necessary, but the result for the initialized CellVariable is shown below
>
> print(D.value)
>
> [[[ 0.  2.  4.  6.]
>   [ 1.  1.  1.  1.]]
>
>  [[ 1.  1.  1.  1.]
>   [ 1.  1.  1.  1.]]]
>
>
> Now the part that I am having trouble with. How can I change the 6 to a 0.?

I think you just need to do

D[0, 0, 3] = 6.

However, it isn't always a good practice to access the spatial index
since if the grid changes then the index has a different spatial
location

> The closet I can come is changing all the values at that mesh position to 0.
> that is using
>
> D.setValue(0,where=[[0,0,0,1]])

I'm not sure why the [[0, 0, 0, 1]] does what it does. Numpy does the following:

~~~
In [9]:  a = np.arange(16).reshape([2, 2, 4])

In [10]: a
Out[10]:
array([[[ 0,  1,  2,  3],
[ 4,  5,  6,  7]],

   [[ 8,  9, 10, 11],
[12, 13, 14, 15]]])

In [12]: a[[[0, 0, 0, 1]]] = -1

In [13]: print a
[[[-1 -1 -1 -1]
  [-1 -1 -1 -1]]

 [[-1 -1 -1 -1]
  [-1 -1 -1 -1]]]
~~~

If you're trying to do fancy indexing with FiPy, you might want check
with Numpy first so that you can trust the FiPy result.

-- 
Daniel Wheeler
___
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


Re: fipy diffusion setup

2016-04-19 Thread Phil Battle

Hi Daniel
Thank you for following up-
I did try your suggestion, ( C is my concentration dependent Cell variable)

Dx=Dpe_x*(a_x+((1.-a_x)/(b_x*C+g_x)))
Dz=Dpe_z*(a_z+((1.-a_z)/(b_z*C+g_z)))
diff = Dx.dot([[1,0],[0,0]])+Dz.dot([[0,0],[0,1]])

and program runs and "looks correct" so good to go!!

But before your suggestion I was trying to create the suggested rank 2 
diffusion coefficient a different way and I did not get far before 
hitting a road block- If you have time to answer this specific question 
it may help with understanding the structure of variables in this program


I created a 2x2 Cell Variable on a 2x2 2Dim mesh.  I can show that code 
if necessary, but the result for the initialized CellVariable is shown below


print(D.value)

[[[ 0.  2.  4.  6.]
  [ 1.  1.  1.  1.]]

 [[ 1.  1.  1.  1.]
  [ 1.  1.  1.  1.]]]


Now the part that I am having trouble with. How can I change the 6 to a 0.?
The closet I can come is changing all the values at that mesh position to 0.
that is using

D.setValue(0,where=[[0,0,0,1]])
print(D.value)

[[[ 0.  2.  4.  0.]
  [ 1.  1.  1.  0.]]

 [[ 1.  1.  1.  0.]
  [ 1.  1.  1.  0.]]]


again what I was angling for was an output that looked like

[[[ 0.  2.  4.  0.]
  [ 1.  1.  1.  1.]]

 [[ 1.  1.  1.  1.]
  [ 1.  1.  1.  1.]]]


thanks for your help
Phil





On 4/19/2016 6:51 AM, Daniel Wheeler wrote:

Phil, just to follow up and complete the answer. I neglected to
explain how to create a rank 2 CellVariable from two rank 0
CellVariables to preserve the dependency. The dot operator helps with
that. Given two rank 0 CellVariables, v00 and v11, then to get the
rank 2 CellVariable use,

 vv = v00.dot([[1, 0], [0, 0]]) + v11.dot([[0, 0], [0, 1]])

On Mon, Apr 18, 2016 at 3:33 PM, Daniel Wheeler
 wrote:

On Mon, Apr 18, 2016 at 12:33 PM, Phil Battle  wrote:

Ok, below works as I would expect ( note Dx and Dz are constants)

Thanks for that. I can confirm that it's broken in Python 2.7 as well
when the diffusion coefficient is [[Dx, Dy]].


--
Daniel Wheeler





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


Re: fipy diffusion setup

2016-04-19 Thread Daniel Wheeler
Phil, just to follow up and complete the answer. I neglected to
explain how to create a rank 2 CellVariable from two rank 0
CellVariables to preserve the dependency. The dot operator helps with
that. Given two rank 0 CellVariables, v00 and v11, then to get the
rank 2 CellVariable use,

vv = v00.dot([[1, 0], [0, 0]]) + v11.dot([[0, 0], [0, 1]])

On Mon, Apr 18, 2016 at 3:33 PM, Daniel Wheeler
 wrote:
> On Mon, Apr 18, 2016 at 12:33 PM, Phil Battle  wrote:
>> Ok, below works as I would expect ( note Dx and Dz are constants)
>
> Thanks for that. I can confirm that it's broken in Python 2.7 as well
> when the diffusion coefficient is [[Dx, Dy]].
>
>
> --
> Daniel Wheeler



-- 
Daniel Wheeler
___
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


Re: fipy diffusion setup

2016-04-18 Thread Daniel Wheeler
On Mon, Apr 18, 2016 at 12:33 PM, Phil Battle  wrote:
> Ok, below works as I would expect ( note Dx and Dz are constants)

Thanks for that. I can confirm that it's broken in Python 2.7 as well
when the diffusion coefficient is [[Dx, Dy]].


-- 
Daniel Wheeler
___
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


Re: fipy diffusion setup

2016-04-18 Thread Guyer, Jonathan E. Dr. (Fed)

> On Apr 18, 2016, at 10:54 AM, Daniel Wheeler  
> wrote:
> 
> On Fri, Apr 15, 2016 at 9:29 AM, Phil  wrote:

>> I see questions posted on this list, Gist and stack overflow - is there a 
>> preference for posting ?
> 
> I prefer Stackoverflow, but depends on the nature of the question.
> Stackoverflow isn't good for very open ended questions or
> conversations.

We monitor both our own list (obviously!) and StackOverflow. There's really no 
way to monitor gist, but it's a good place to put code snippets referenced from 
the list or SO. As Daniel says, SO isn't very good for open-ended 
conversations. On the other hand, it's easier to search and has a lower barrier 
to entry (you don't need to subscribe) than the mailing list. Really, it's 
whatever you feel most comfortable with.
___
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]


Re: fipy diffusion setup

2016-04-18 Thread Daniel Wheeler
On Fri, Apr 15, 2016 at 9:29 AM, Phil  wrote:
>
> But when written like
>
>  TransientTerm() == DiffusionTerm([[1.,5.]]), which I think the
> manual said was equivalent ( under freq asked questions)
> I get an assertion error, which I can post but before posting should
> these two diffusion terms be equivalent?

My feeling is that [[1., 5.]] shoud be equivalent to [[[1., 0.], [0.,
5.]]]. I'm not sure why that isn't working correctly.

> Sticking with the complete matrix form of the diffusion Coefficient
> for Dx and Dz ( both similar functions of the cellVariable C)
>
> when I use this form
>
>  TransientTerm() == DiffusionTerm([[[Dx,0],[0,Dz]]])
>
> I get the following traceback error

That's not surprising. Use a single FaceVariable or CellVariable of
rank 2 for the diffusion coefficient. It's safer to do that for
anisotropy.

> I see questions posted on this list, Gist and stack overflow - is there a 
> preference for posting ?

I prefer Stackoverflow, but depends on the nature of the question.
Stackoverflow isn't good for very open ended questions or
conversations.

-- 
Daniel Wheeler
___
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]