Your suggestion certainly works and I appreciate the quick response.

However, in general, I would like to define more complicated functions of
time that are best
implemented in a function. So I am still interested in WHY the function
approach doesn't
work. Is there a way to tell FiPy to call that function whenever the time
Variable is changed?
If there is a manual section you can point me to, that would be great.

(I changed the function to return a floating point number instead of an
integer but it is still
being treated as a constant.)

Thanks,

Bill

On Fri, Feb 1, 2019 at 9:40 AM Guyer, Jonathan E. Dr. (Fed) via fipy <
fipy@nist.gov> wrote:

> `time` is a Variable as FiPy understands it, but stepFunc() simply returns
> an integer, so eqI is defined with a source that is the integer 0.
>
> I'd try
>
> eqI = fipy.TransientTerm(coeff=1.) == ((time < 0.1) * 0. + (time >= 0.1) *
> 1.)
>
> > On Feb 1, 2019, at 6:05 AM, Bill Greene <w.h.gre...@gmail.com> wrote:
> >
> > I am trying to solve an equation where the source term is
> > a discontinuous function of time. I have followed examples
> > where the source term is a simple, continuous function of time
> > and these appear to work correctly.
> >
> > The key parts of my code are shown below:
> >
> > def stepFunc(t):
> >   if(t.value<.1):
> >     s = 0
> >   else:
> >     s=1
> >   print('t=', t, 's=', s)
> >   return s
> >
> > time = fipy.Variable(0., cached=1)
> > eqI = fipy.TransientTerm(coeff=1.) == stepFunc(time)
> >
> > t = 0
> > for step in range(steps):
> >   time.setValue(t+dt/2.)
> >   eqI.solve(var=u, dt=dt)
> >   t += dt
> >
> > The function stepFunc appears to be called only once and the solution
> > indicates that s=0 for the entire solution time.
> >
> > I thought that the cached option on the Variable object might affect this
> > behavior but when I set it to zero, I get an error message that I don't
> understand.
> >
> > Any help will be much appreciated.
> >
> > Bill Greene
> >
> > _______________________________________________
> > fipy mailing list
> > fipy@nist.gov
> > http://www.ctcms.nist.gov/fipy
> >  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
>
>
> _______________________________________________
> fipy mailing list
> fipy@nist.gov
> http://www.ctcms.nist.gov/fipy
>   [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]
>
_______________________________________________
fipy mailing list
fipy@nist.gov
http://www.ctcms.nist.gov/fipy
  [ NIST internal ONLY: https://email.nist.gov/mailman/listinfo/fipy ]

Reply via email to