##################################################################################
##################################################################################
# An R script with a function for the continuous and differentiable
# approximation of a Heavyside step function.
# The step function is equal to 1, except between time_begin and
# time_end, when it is equal to some value, which we call "scale" here.
# Note that I made this function have a period of one year, such that it
# can be used to calculate a scale factor for the transmission rate
# when kids take their annual summer vacation.
#
# Author: Sherry Towers
# smtowers@asu.edu
# Created: Dec 12th, 2012
#
# Copyright Sherry Towers, 2012
#
# This script is not guaranteed to be free of bugs and/or errors.
#
# This script can be freely used and shared, as long as the author information
# and copyright in the header remains intact.
##################################################################################
heavyside=function(t,time_begin,time_end,scale){
sharpness = 5 # This is a parameter that controls the "sharpness" of turnon of the step function
# The larger the value, the sharper the turnon of the step function
# It is generally kinder to ODE solution software to not have the turnon
# excessively sharp (because it makes the ODE problem "stiff")
heavy = 1.0/(1.0+exp(-2*sharpness*(t%%365-time_begin))) -1.0/(1.0+exp(-2*sharpness*(t%%365-time_end)))
heavy = 1-(1-scale)*heavy
return(heavy)
}