[R-sig-dyn-mod] Limiting State Value to remain below a maximum value

Derek van der Kamp derek.vanderkamp at gmail.com
Mon Jul 27 21:30:38 CEST 2015


I'm running a model where one of the state variables is required to remain
below some maximum value (0.6).

I went ahead and wrote an event and root function:

cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc

      subroutine fmcevent(neq, t, y)
      integer :: neq
      double precision :: t, y(neq)

      y(2) = 0.58

      return
      end

cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c     Event function for keeping moisture below M_MAX

      subroutine fmcroot(neq, t, y, ng, gout, out, IP)
      integer :: neq, ng, IP(*)
      double precision :: t, y(neq), gout(ng), out(*)

      gout(1) = y(2) - 0.6

      return
      end

However, this increases the computation time by two orders of magnitude.
The computation time decreases if I set y(2) to some smaller number, say
0.2, in the event function.

My guess is that when I knock the y(2) variable down to just below its
maximum value, it keeps on hitting that ceiling on subsequent time steps,
the event function keeps getting called, and this slows everything down.

Is there a more efficient way to keep a state value below some maximum
value?

Cheers,

Derek

	[[alternative HTML version deleted]]



More information about the R-sig-dynamic-models mailing list