Dear Jonathan,

Many thanks for going through the script and explaining the underlying data 
structures to me. Much appreciated. I also understand that other people in the 
group want to simulate similar systems, so I reckon my questions have been 
well-timed.

Since you know about the underlying-data structures, what would be the best way 
to go about writing automatic differentiation rules for the solution structure 
after a state solve. For example, in my script, I have a field, V. If I were to 
construct the gradient of V w.r.t to let's say g_Na there are typically two 
ways - Newton type approximate gradient or using automatic differentiation 
(like adolc). Are the solution data structures amenable to automatic 
differentiation tools? If yes, do you guys have some examples?

Best,
Biswa

On 2 Jun 2011, at 15:01, Jonathan Guyer wrote:

> 
> On Jun 2, 2011, at 5:41 AM, Biswa Sengupta wrote:
> 
>> As per your advice I tried to pose my set of PDE-ODE system as a PDE + 3 
>> degenerate PDEs (i.e., the ODEs without the space term). I have tried to 
>> work along the examples for time marching but certainly I am not getting 
>> something right. I attach herewith the code that I am trying to use. Can you 
>> spot some obvious mistake. I get the following error:
>> 
>> 4565:src biswasengupta$ python cable.py 
>> Traceback (most recent call last):
>> File "cable.py", line 63, in <module>
>>  mEq = TransientTerm(coeff=taum(V)) == ImplicitSourceTerm(minfy(V) - m)
>> File "/Users/biswasengupta/Desktop/finelPDE/python/cable/src/actinact.py", 
>> line 3, in taum
>>  am = 0.1*(V + 40) / (1-exp(-(V+40)/10.0))
>> File 
>> "/Library/Frameworks/EPD64.framework/Versions/7.0/lib/python2.7/site-packages/FiPy-2.1.2-py2.7.egg/fipy/variables/variable.py",
>>  line 1146, in __float__
>>  return float(self.getValue())
>> TypeError: only length-1 arrays can be converted to Python scalars
> 
> 
> In your actinact.py, replace all instances of
> 
>  from math import exp
> 
> with
> 
>  from fipy.tools.numerix import exp
> 
> The Python math module only understands single floating point numbers and 
> should never be used with FiPy. FiPy's numerix, based on NumPy, can deal with 
> arrays of floats.
> 
> ----
> 
> In cable.py, you should remove
> 
>  from math import *
> 
> for the same reason. Also 
> 
>  from numpy import *
> 
> is not necessary because all of the same code (with appropriate 
> modifications) is obtained when you import fipy. By importing numpy directly, 
> you override some changes that FiPy requires. Finally, 
> 
>    from scipy import *
> 
> doesn't do anything. You must import the specific submodules you want from 
> SciPy.
> 
> ----
> 
> Once you're past that, you will encounter a few more issues before your 
> script will run, some of them quite obscure:
> 
> * TypeError: unsupported operand type(s) for *: 'function' and 'float'
> 
> This turns out to be caused by 
> 
>   return ninfy
> 
> on actinact.py line 41. Change this to 
> 
>   return ninit
> 
> and likewise for minfy and hinfy.
> 
> *     self.matrix.matvec(other, y)
>   ValueError: arg 1 must be a 1-dimensional double array of appropriate size.
> 
>  This is because V holds an array of integers and it needs to be floats. 
> Change cable.py    
>  line 42 to 
> 
>   restvol = -65.
> 
>  Probably a good idea to change valueLeft and valueRight (but not absolutely 
> necessary).
> 
> * Finally, the problem runs, but doesn't show anything. This is because
> 
>    axonlen = 1
>    dx = axonlen/nx
> 
>  gives a grid spacing of zero because of integer math. Change to 
> 
>    axonlen = 1.
> 
> The problem now runs. Whether it gives sensible answers is up to you to 
> figure out! 8^)  
> 
> I've attached my modified scripts.
> 
> 
> 
> <cable.py><actinact.py>



Reply via email to