How to change gravity vector as a function of time?


In some cases (e.g. fuel tank sloshing) one might need to change the
gravity vector as a function of time. Furthermore, one might want to provide
the time variation of the gravity vector through a text file that contains
4 columns of numbers, the first being time and the other three being
the xyz components of the gravity vector at that time instant.

Use the following scheme file. See the comments at the top of the scheme file
for usage directions.

--------Cut below this line and save in a text file entitled gravity-table.scm--------------------
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Scheme file for use with Fluent6.0
;;
;; Developed By:
;; Sandeep Sovani
;; Technical Support Engineer
;; Fluent Inc, 220 E Huron St, Ann Arbor MI 48197
;; sds@fluent.com
;;
;; November 14th, 2002
;;
;; If there are any questions about the use of this scheme
;; file please contact your support engineer
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; BASIC NOTES:
;;; The purpose of this scheme file is to allow the user to
;;; change the gravity vector as a function of time.
;;; The user specifies the x, y, z components of the gravity
;;; vector at different times in a ASCII text file having the
;;; following format:

;;; First line of the file should contain an integer that
;;; indicated the total number of samples in the file.
;;; Each of the subsequent lines should have four numbers
;;; on it representing time, gx, gy, gz (where gx is the
;;; x component of the gravity vector at that time, etc.)

;;; Example of a valid input file:

;;; 3
;;; 0.001 0.1 20.1 0.974679434
;;; 0.002 0.11 20.3 0.971493695
;;; 0.005 0.12 20.5 0.968090905

;;; (remove the ";;;" before using the above lines)

;;; Note that the data should be arranged in this file such
;;; that flow time increases from one row to the next.

;;; The difference between the flow times in two adjacent
;;; rows may or may not be constant through out the file
;;; (i.e. the sampling duration need not be constant)

;;; !! If the input file does not verify
;;; this type of format, erroneous results
;;; will be obtained

;;; Make sure that the input file is in the DOS format
;;; if working on Windows platform and in the unix format
;;; if working in unix

;;; USAGE NOTES:

;;; 1) Read case and data files.

;;; 2) Have a copy of the ASCII input file in the working directory.

;;; 3) File>Read>Scheme .. this file (gravity-table.scm)
;;; or through TUI command
;;; (load "gravity-table.scm")

;;; 4) Type the following command in the TUI (including the brackets):
;;; (readfile "input.txt")
;;; where input.txt is the name of the input ascii file holding the
;;; the gravity vector table

;;; 5) Under Solve->Execute Commands in the GUI, select 1 command.
;;; Select it to be executed once every timestep
;;; Type the following command in the command panel (including the brackets):
;;; (accelerate)

;;; ADDITIONAL NOTES:

;;; If the flow time is lesser than that on the first row of the input file,
;;; the gravity vector will be set to the values specified on the first row

;;; If the flow time is greater than that on the last row of the input file,
;;; the gravity vector will be set to the values specified on the last row

;;; If the flow time falls between any two time values on two subsequent
;;; rows of the input file, then the gravity vector components will interpolated
;;; to the flow time.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define tin '())
(define xin '())
(define yin '())
(define zin '())
(define imax)
(define indx)
(define tim)
(define t1)
(define x1)
(define y1)
(define z1)
(define t2)
(define x2)
(define y2)
(define z2)
(define gx)
(define gy)
(define gz)


(define (readfile file-name)
(let ((pt)(t)(x)(y)(z))
(set! pt (open-input-file file-name))
(display "Opening transient gravity vector data file: ")
(display file-name)
(display "n")
(set! imax (read pt))
(display "Number of data lines in file: ")
(display imax)
(display "n")

(let loop ((i 0))
(if (< i imax)
(begin
(display "Row no. ")
(display (+ i 1))
(display " ")
(set! t (read pt))
(display t)
(display " ")
(set! tin (append tin (list t)))
(set! x (read pt))
(display x)
(display " ")
(set! xin (append xin (list x)))
(set! y (read pt))
(display y)
(display " ")
(set! yin (append yin (list y)))
(set! z (read pt))
(display z)
(display " ")
(set! zin (append zin (list z)))
(display "n")
(loop (+ i 1))
)
)
)
)
)

(define (accelerate)

(set! tim (rpgetvar 'flow-time))
(display "n")
(display "Current flow time: ")
(display tim)
(display "n")
(set! indx 0)
(set! gx (list-ref xin 0))
(set! gy (list-ref yin 0))
(set! gz (list-ref zin 0))

(let loop ((i 0))
(if (< i imax)
(begin
(if (> tim (list-ref tin i))
(begin
(set! indx (+ i 1))
)
)
(loop (+ i 1))
)
)
)

(if (= indx 0)
(begin
(set! gx (list-ref xin 0))
(set! gy (list-ref yin 0))
(set! gz (list-ref zin 0))
)
( if (= indx imax)
(begin
(set! gx (list-ref xin (- imax 1)))
(set! gy (list-ref yin (- imax 1)))
(set! gz (list-ref zin (- imax 1)))
)
(begin
(set! t1 (list-ref tin (- indx 1)))
(set! t2 (list-ref tin indx))
(set! x1 (list-ref xin (- indx 1)))
(set! x2 (list-ref xin indx))
(set! y1 (list-ref yin (- indx 1)))
(set! y2 (list-ref yin indx))
(set! z1 (list-ref zin (- indx 1)))
(set! z2 (list-ref zin indx))
(set! gx (+ x1 (* (- x2 x1) (/ (- tim t1) (- t2 t1)))))
(set! gy (+ y1 (* (- y2 y1) (/ (- tim t1) (- t2 t1)))))
(set! gz (+ z1 (* (- z2 z1) (/ (- tim t1) (- t2 t1)))))
)
)
)
(rpsetvar 'gravity/x gx)
(rpsetvar 'gravity/y gy)
(rpsetvar 'gravity/z gz)
(display "Gravity vector set to gx = ")
(display gx)
(display ", gy = ")
(display gy)
(display ", gz = ")
(display gz)
(display "n")

(models-changed)
)





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