Fluent Scheme 中 Custom Field Function 相关操作

在 Fluent 中,Custom Field Function(CFF) 对于后处理得到想要间接结果是一个非常有用的工具。Fluent Scheme 中提供了一些 procedure 进行操作。


(1)  定义一个 CFF --- custom-field-function/define


下面定义的是一个求到点 (x,y,z) 距离的一个 CFF,定义起来是蛮繁琐的。


;;
(define (hy-cff-distance-define cffname x y z)
  (if (string? cffname)
    (set! cffname (string->symbol cffname))
    #f
  )
  (define opsym-x "-")
  (define fsym-x 'field--)
  (if (< x 0)
    (begin
      (set! opsym-x "+")
      (set! fsym-x 'field-+)
       (set! x (- x))
    )
    #f
  )
  (define opsym-y "-")
  (define fsym-y 'field--)
  (if (< y 0)
    (begin
      (set! opsym-y "+")
      (set! fsym-y 'field-+)
       (set! y (- y))
    )
    #f
  )
  (define opsym-z "-")
  (define fsym-z 'field--)
  (if (< z 0)
    (begin
      (set! opsym-z "+")
      (set! fsym-z 'field-+)
       (set! z (- z))
    )
    #f
  )
  (custom-field-function/define
    (list
     (list
      (list 'name cffname)
      (list 'display (format #f "sqrt ((x ~a ~a) ^ 2 + (y ~a ~a) ^ 2) + (z ~a ~a) ^ 2)" opsym-x x opsym-y y opsym-z z))
      (list 'syntax-tree
        (list
          "sqrt"
          (list "+"
            (list "+"
              (list "**" (list opsym-x "x-coordinate" x) 2)
              (list "**" (list opsym-y "y-coordinate" y) 2)
            )
            (list "**" (list opsym-z "z-coordinate" z) 2)
          )
        )
      )
      (list 'code
        (list 'field-sqrt
          (list 'field-+
            (list 'field-+
              (list 'field-** (list fsym-x (list 'field-load "x-coordinate") x) 2)
              (list 'field-** (list fsym-y (list 'field-load "y-coordinate") y) 2)
            )
            (list 'field-** (list fsym-z (list 'field-load "z-coordinate") z) 2)
          )
        )
      )
     )
    )
  )
)



(2) 删除 CFF


(define (hy-cff-delete cffname)
  (cx-delete-cf cffname)
)



(3) 其他就是 load/save 之类的功能


你可能感兴趣的:(Fluent Scheme 中 Custom Field Function 相关操作)