Autosave at specified time intervals

In some cases, especially when adaptive time stepping is used, it may be desirable to write autosave files at specified time intervals instead of every N time steps.

It is possible to do this, in a LIMITED capacity, using a scheme function. Be very careful ... the procedure described below may not work in every application. Autosave files can be written when the actual flow-time is close to the time for which it is desired to write the file, but it is not possible (using this approach) to adjust the time step size so that the flow time in the autosave files exactly matches the desired flow time.

Therefore, if it is important to have files at, for instance, 1.0 seconds, 2.0 seconds, 3.0 seconds, and so on .. the following approach should NOT be used.

The scheme function has no effect on the time step size selected by the adaptive time stepping algorithm. Therefore, they are unable to write autosave files at the exact moment in time dictated by the time interval. What they do is start with the time interval, which we will assume is 0.25 seconds, for demonstration purposes. Ideally, files should be written at 0.25s, 0.50s, 0.75s, and so on. However, as noted before, when using adaptive time stepping, there is no control over the actual flow time at the end of a given time step. The way the functions work is that they look at the last time a file was written, then they look at the current flow time and determine whether a file would have been written between the two times. If so, a new file is written at the current time. If not, no file is written. To make the example more concrete, assume that the interval is 0.25s and a simulation is run with a fixed time step of 0.2 seconds. The results of the attached scheme functions would be:

time step 1, flow-time 0.2 seconds, no file written
time step 2, flow-time 0.4 seconds, file written because 0.4 > 0.25
time step 3, flow-time 0.6 seconds, file written because 0.6 > 0.50
time step 4, flow-time 0.8 seconds, file written because 0.8 > 0.75
time step 5, flow-time 1.0 seconds, file written because 1.0 = 1.0
time step 6, flow-time 1.2 seconds, no file written because 1.2 < 1.25
time step 7, flow-time 1.4 seconds, file written because 1.4 > 1.25
and so on.

Obviously, it might be a bit silly to use the scheme functions with a constant time step size, but it makes the example easier to describe.

To use the scheme file, copy and paste the text from the resolution field into a text file. Be sure to include all lines from the resolution field, including the final line with two parentheses. The instructions for using the scheme file itself are located near the top of the scheme file. Before using the scheme file on a real case, it is recommended to try it with a small case, like the 2D elbow tutorial, in order to make sure that it is understood how the method works and especially that the files are written in the proper directory with the proper name.
;; Scheme file to autosave files at a particular time interval
;; This is an unsupported scheme function. It has been tested for
;; correct execution on a single test case, and it is believed it
;; will work for all cases, but it cannot be guaranteed to work
;; properly under all possible scenarios. Please report any problems
;; encountered while using this function.
;; Usage:
;; To use the scheme file to save files at a given time interval,
;; 0. Read case and data files, then read autosave.scm through File > Read > Scheme
;; 1. Open the Execute Commands panel in the GUI (Solve>Execute Commands)
;; 2. Increase the number of Defined Commands by 1
;; 3. Click ON next to the most recent command and select Time Step
;; next to the drop down arrow under When
;; 4. Enter the following text in the field under Command:
;; (autowrite 0.25)
;; The parentheses must be included. The value of 0.25 should be replaced
;; with the desired interval for the current case
;; 5. Select the type of autosave in the command below. Change only the
;; text between the quotation marks
;; "wd " for data files only
;; "wcd " for case and data files

(define text1 "wd ")

;; 6. Enter the directory path below to the directory where the files
;; are to be saved. Change only the text between the quotation marks
;; To save in the current directory, in Unix use "./"
;; in Windows use "."

(define pathname ".")

;; 7. Enter the file name below. The hyphen should be included to make the
;; files easier to identify, i.e. "filename-%t"
;; Change only the text between the quotation marks
;; but do not remove the %t or there will be no association
;; between the autosave file and the flow time

(define filename "test-%t")

;; 8. Enter the compression status below. Change only the
;; text between the quotation marks.
;; For compressed files use ".gz"
;; For uncompressed files use ""

(define zip "")

;; Do not modify anything below this statement

(define (writefiles current-time)
(let* ((time-string)
(rpsetvar 'autowrite/last-file-time current-time)
(set! writecommand (string-append text1 pathname filename zip))
(ti-menu-load-string writecommand)

(define (autowrite interval)
(let* ( (current-time)
(if (not (rp-var-object 'autowrite/last-file-time))
(rp-var-define 'autowrite/last-file-time (rpgetvar 'flow-time) 'real #f))
(set! current-time (rpgetvar 'flow-time))
(set! last-write (rpgetvar 'autowrite/last-file-time))
(set! overlap (- last-write (* interval (truncate (/ last-write interval)))))
(set! file-write-time (+ interval (- last-write overlap)))
(if (> current-time file-write-time)
(writefiles current-time)


Show Form
No comments yet. Be the first to add a comment!