FISH规则
说明的FISH规则,语法和语句在为FISH变量和函数选择名称时,具有很大的灵活性。
下划线字符(_)可以包含在名称中。
名称必须以字母开头(即不能为数字或特殊字符),并且不得包含任何算术运算符(+,-,/,*或^)。
所选名称不能与内置FISH内部函数之一的名称相同。
FISH变量名称不区分大小写,因此aVariable和AVARiable是相同的变量。
除了检查全局符号控制集中的FISH变量/函数名称外,还可以使用fish list命令获取所有当前变量和函数的列表。该命令的结果是产生所有当前值的打印输出,并按名称按字母顺序排序。
FISH的一些变量形式
model new
fish define types
v1 = 2
v2 = 3.4
v3 = 'Have a nice day'
v4 = v1 * v2
v5 = v3 + ', old chap'
v6 = vector(1,2,3)
v7 = matrix(vector(1,1,1))
v8 = true
end
@types
fish list
(注意最后的fish list 可以列出fish函数中的值表格比较有用)
fish基本形式:
fish define fname
abc=22*3+5
end
;after run this we need key @fname in the console ,then the value of abc can be see in the FISH Global Symbols.
[abc]
;use this Print value
model new
fish define abc
hh = 22
abc = hh * 3 + 5
end
[abc=0];abc=0
[hh=0];hh=0
[hh];hh=0
[abc];abc=71
[hh];hh=22
; a variable "hh" hh and a FISH function "abc"
;an alternate syntax to achieve the same effect is given below
fish set @abc = 0 @hh = 0
list @hh
list @abc
list @hh
;test
model new
fish define abc
abc = hh * 3 + 5
end
[hh = 22]
[abc]
[abc = 0]
[hh = 0]
[hh]
[abc]
[hh]
FISH Capturing the history of a FISH variable (捕获FISH变量的历史记录)
model new
zone create brick size 1 2 1
zone cmodel assign mohr-coulomb
zone property shear=1e8 bulk=2e8 cohes=1e5 tens=1e10
zone gridpoint fix velocity range position-y 0.0
zone face apply velocity-y -1e-5 range position-y 2.0
fish define get_ad
ad1 = gp.near(0,2,0)
ad2 = gp.near(1,2,0)
ad3 = gp.near(0,2,1)
ad4 = gp.near(1,2,1)
end
@get_ad
fish define load
load = gp.force.unbal.y(ad1) + gp.force.unbal.y(ad2) ...
+ gp.force.unbal.y(ad3) + gp.force.unbal.y(ad4)
end
fish history load
zone history displacement-y position (0,2,0)
model step 1000
plot item create chart-history history 1 vs 2 reverse on
simple use FISH Function in Edit(一些简单的函数)
model new
fish define derive(y_mod,p_ratio)
s_mod = y_mod / (2.0 * (1.0 + p_ratio))
b_mod = y_mod / (3.0 * (1.0 - 2.0 * p_ratio))
end
[derive(5e8,0.25)]
[b_mod]
[s_mod]
;The result of these operations can be checked by printing bulk and shear in the usual way (e.g., using the zone list property command).
zone create brick size 2,2,2
zone cmodel assign elastic
zone property bulk [b_mod] shear [s_mod]
zone list prop bulk
zone list prop shear
fish list
FISH 循环,有很多种,具体,应该避免简写,合理书写
model new
fish define xxx
sum = 0
prod = 1
loop for (n = 1, n <= 10, n = n + 1)
sum = sum + n
prod = prod * n
end_loop
io.out('The sum is ' + string(sum) + ...
' and the product is ' + string(prod))
end
@xxx
;another example and another way
model new
zone create brick point 0 (0,0,0) point 1 (-10,0,0) ...
point 2 (0,10,0) point 3 (0,0,-10)
zone cmodel assign elastic
fish define install(y_zero,cc)
loop foreach pnt zone.list
z_depth = -zone.pos.z(pnt)
y_mod = y_zero + cc * math.sqrt(z_depth)
zone.prop(pnt,'young') = y_mod
end_loop
end
@install(1e7,1e8)
zone property poisson 0.25
plot item create zone contour property name 'young'
FISH的选择语句
model new
fish define abc(xx)
if xx > 0 then
abc = 33
else
abc = 11
end_if
end
[abc(1)]
[abc(-1)]
FISH使用在Edit Sequence of excavation and cable placement
(编辑开挖和电缆布置顺序)
model new
zone create brick size 10 3 5
zone cmodel assign mohr-coulomb
zone property bulk 1e8 shear 0.3e8 friction 35
zone property cohesion 1e3 tension 1e3
zone initialize density 1000
model gravity 0 0 -10
zone gridpoint fix velocity-x range position-z 0.0
zone gridpoint fix velocity-y range position-z 0.0
zone gridpoint fix velocity-z range position-z 0.0
zone gridpoint fix velocity-y range position-y 0.0
zone gridpoint fix velocity-y range position-y 3.0
zone gridpoint fix velocity-x range position-x 0.0
zone gridpoint fix velocity-x range position-x 10.0
model largestrain on
model history mechanical unbalanced-maximum
model solve
model save 'cab_str'
zone gridpoint initialize displacement-x 0
zone gridpoint initialize displacement-y 0
zone gridpoint initialize displacement-z 0
zone history displacement-x position 0 1 5
fish define place_cables(num,segs)
loop local n (1,num)
local z_d = 5.5 - float(n)
local z_t = z_d + 0.5
local z_b = z_d - 0.5
command
zone gridpoint free velocity-x ...
range position-x 0.0 position-z [z_b] [z_t]
model solve
structure cable create by-line 0.0 0.5 [z_d] 7.0 0.5 [z_d] ...
segments [segs]
structure cable create by-line 0.0 1.5 [z_d] 7.0 1.5 [z_d] ...
segments [segs]
structure cable create by-line 0.0 2.5 [z_d] 7.0 2.5 [z_d] ...
segments [segs]
structure cable property young 2e10 yield-tension 1e8 ...
cross-sectional-area 1.0 ...
grout-stiffness 2e10 ...
grout-cohesion 1e10 grout-perimeter 1.0
end_command
end_loop
end
@place_cables(5,7)
model save 'cab_end'
FISH Arrays and Maps(fish的数组和映射)
model new
fish define array_operation
;create and populate an array with products of 2
arr = array.create(10)
loop local n(1,10)
arr[n] = 2*n
end_loop
;compute the sum and product of elements in the array
sum = 0
prod = 1
local i = 1
loop while (i <= array.size(arr,1))
sum = sum + arr[i]
prod = prod * arr[i]
i = i + 1
end_loop
io.out('The sum is ' + string(sum) + ...
' and the product is ' + string(prod))
end
@array_operation
;MAP
model new
fish define map_operation
;create and populate a map with products of 2
my_map = map(1,2)
loop local n(2,10)
map.add(my_map,n,2*n)
end_loop
;compute the sum and product of elements in the map
sum = 0
prod = 1
loop foreach n my_map
sum = sum + n
prod = prod * n
end_loop
io.out('The sum is ' + string(sum) + ...
' and the product is ' + string(prod))
end
@map_operation