Is Variable Time shared between the "solver" and the user defined function while it (Variable Time) changes continuously

Numerical methods and mathematical models of Elmer
Post Reply
ScientistRenzo
Posts: 57
Joined: 14 Mar 2021, 21:01
Antispam: Yes

Is Variable Time shared between the "solver" and the user defined function while it (Variable Time) changes continuously

Post by ScientistRenzo »

When Variable Time is passed to a user defined function, is time shared between the "solver" and the user defined function while it (Variable Time) changes continuously?

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
Thanks a bunch I've made a lot of progress :)
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Is Variable Time shared between the "solver" and the user defined function while it (Variable Time) changes continuo

Post by raback »

Yes, there "variable" statements are reevaluated every time they are called. -Peter
Post Reply