For example, I made a user defined function for a heat source square wave that turns off after 100 seconds.
1. Will time2_ change continously with time_? time_ is the variable assigned to Variable Time from the .sif file.
2. Does the code look good Will it work
Code: Select all
function heatsourcefunction(Model, n, i, time_) result(output_heatsource)
use DefUtils
use Types
use iso_fortran_env, only: RK => real64
implicit none
real(RK) :: time_, time2_,output_heatsource, Period = 10.123_RK, time_high = 4.456_RK, time_end = 100_RK
type(Model_t) :: Model
integer :: n, i = 0
!set oscillation timer
time2_ = time_ - (i*Period) //time2_ changes continuously with time_
!evaluate timer and output corresponding heat
if ((time2_ < time_high) .and. (time_ < time_end)) then
output_heatsource = 1 !high
else if ((time2_ >= time_high).and. (time2_ < Period) .and. (time_ < time_end)) then
output_heatsource = 0 !low
else if ((time2_ >= Period) .and. (time_ < time_end)) then
i = i + 1 !This will allow time2_ to change continuously with time_, and time2_ stay within 0 to Period.
else
output_heatsource = 0 !after 100 seconds
endif
end function heatsourcefunction