Jose -
What's surprising to me is how infrequently this question has come up. I don't
think there's anything wrong with what you've done, but understand your feeling
that you've "hacked" FiPy. It's quite possible that you can just write `T =
bellLinT(Sigma)`. Depending on what's in bellLinT, this often just works to
provide an appropriate OperatorVariable.
Another option, and there are several examples of this in fipy/variables/, is
to create a subclass that does what you need. Something like:
class BellLinTVariable(CellVariable):
def __init__(self, sigma):
self.sigma = self._requires(sigma)
def _calcValue(self):
return bellLinT(self.sigma)
T = BellLinTVariable(Sigma)
I'd try the simple, explicit statement first.
I agree that this would be a good area for us to provide some examples.
- Jon
On Oct 2, 2015, at 1:42 PM, Jose Garmilla <[email protected]> wrote:
> Dear FiPy developers and users,
>
> Thank you for your work! It's helped me a lot in my projects.
>
> I used FiPy to solve an equation that models an accretion disk in 1D. I wrote
> the equation in the form:
>
> transient term = convection term.
>
> The problem I encountered is that the velocity coefficient in the convection
> term is a complicated function of the dependent variable. The function can't
> be written in terms of the built-in FiPy functions. In fact, the way I
> calculate this function is by numerically pre-computing the values in a grid
> and then interpolate for points in between.
>
> I didn't find anything in the documentation to create operator variables with
> user-defined functions. To go around this, I defined an operator variable as
> follows:
>
> T = Sigma._UnaryOperatorVariable(lambda x: bellLinT(x))
>
> where `Sigma` is the dependent varible, `T.faceGrad` goes into the velocity
> coefficient, and `bellLin()` is the interpolating function that takes an
> array with the values of `Sigma` and returns the corresponding values for `T`.
>
> This seems to have worked, but I felt that I was somehow hacking FiPy and was
> never comfortable with it. Should I be concerned? Is there a proper way of
> doing this that I missed?
>
> If this should work in general, and is not in the documentation already.
> Wouldn't it be useful to put in there a way of building operator variables
> with user-defined functions?
>
> Best,
>
> Jose
> _______________________________________________
> 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 ]