FISH Syntax Example Data File

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
; fname : ballexample.dat
;
;  Illustrate basic usage of the ball.pos FISH intrinsic function
; =============================================================================
model new

fish define get_ball_position_vector(bid)
  ; retrieve the vector position of the ball with ID bid
  local b = ball.find(bid) ; get address of ball with ID bid
  local v = ball.pos(b)   ; read access to the position of ball with address b
  get_ball_position_vector = v
end

fish define set_ball_position_component(bid,idir,val)
  ; retrieve the idir component vector position of the ball with ID bid
  local b = ball.find(bid) ; get address of ball with ID bid
  ball.pos(b,idir) = val ; write access to the idir-component position
end

; set the model domain and create a ball
model domain extent -1 1
ball create id 1 position-x 0.0 position-y 0.0 radius 0.1

; create the global FISH variable vp1, execute the get_ball_position_vector 
; function and store the return value in vp1
fish create vp1 = @get_ball_position_vector(1)
list @vp1  ; output the value of vp1 in the console pane

; execute the set_ball_position_component function to assign a new x-component
@set_ball_position_component(1,1,0.1)

; execute the set_ball_position_component function to assign a new y-component
@set_ball_position_component(1,2,0.2)

; use inline FISH to create the global FISH variable vp2, execute the 
; get_ball_position_vector function and store the return value in vp2
[vp2 = get_ball_position_vector(1)]
list @vp2  ; output the value of vp2 in the console pane

return