Dear all! Thank to all of you for the answers to my previous questions!

I'm solving the convection equation (see PDE solution problem thread for details). My equation looks like

eq = TransientTerm() == PowerLawConvectionTerm(convCoeff)

Now I want to add a VARIABLE SOURCE to it. A constant source is described in manual and works fine. To add a variable source I do the following:
#define a function that describes my source
def S(x):
   E=x
   if E>10:
       return 5e-7*E**alpha*exp(-E/Ecut)
   else:
       return 0
#fipy said it wants a CellVariable for the source term
Source = CellVariable(mesh=mesh)
Source.setValue(S(x))

#change the equation:
eq = TransientTerm() == PowerLawConvectionTerm(convCoeff) + Source

Problems/Questions:
1. Is it correct way to introduce the space variable dependent Source to my problem? 2. I have if/else condition in S(x) function. The script works without if/else with no errors, but with condition the following error appears:
File "conv_s_1208.py", line 59, in <module>
   Source.setValue(S(x))
 File "conv_s_1208.py", line 48, in S
   if E>10:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

It seems that S(x) gets the whole array of x values of the mesh and in this case can't compare. Originally I wouldn't like that S(x) function was designed to take an array argument.

Shouldn't the setValue method take care of it? (i.e. if the function is written for the scalar argument and an array x[] is passed, setValue should make a new array where y[i]=S(x[i]). This new array will be then the Source term.) If setValue method can't take care of it, is there a way to overcome this difficulty and do not change S(x) function? Is there a way in python to check what object (array, float ...) is a passed to the function as an argument?

Thanks to everybody for the answers!


Reply via email to