# FISH Error Handling

FLAC3D has a built-in error-handling facility that is invoked when some part of the program detects an error. There is a scheme for returning control to the user in an orderly fashion, no matter where the error may have been detected. The logic may be accessed by a user-written FISH function that accesses the system.error FISH function. If a FISH function assigns a string to system.error, then the error-handling facility of FLAC3D is invoked immediately, and a message containing the string assigned to system.error is printed. Stepping and FISH processing stop as soon as system.error is set.

The error-handling mechanism may also be used in situations that do not involve “errors.” For example, stepping may be halted when a certain condition is detected, as illustrated below. The run will stop when the unbalanced force is less than the set value. Note that, in this example, the test of global.step is necessary because the unbalanced force is zero at the start of stepping.

;fname: fishr13.dat
model new
model large-strain on
model domain extent -10 10
contact cmat default model linearpbond
;
fish define unbal_met
while_stepping
io.out('unbal = '+string(mech.solve('unbalanced')))
if mech.solve('unbalanced') < 5000.0 then
if global.step > 5 then
system.error = ' Unbalanced force is now: ' + ...
string(mech.solve('unbalanced'))
end_if
end_if
end
;                                      next: create 5 balls in a line
ball create id=1 position-x=0.0 position-y=0.0 position-z=0.0 rad=0.5
ball create id=2 position-x=1.0 position-y=0.0 position-z=0.0 rad=0.5
ball create id=3 position-x=2.0 position-y=0.0 position-z=0.0 rad=0.5
ball create id=4 position-x=3.0 position-y=0.0 position-z=0.0 rad=0.5
ball create id=5 position-x=4.0 position-y=0.0 position-z=0.0 rad=0.5
ball attribute density=2000 damp 0.7
ball property 'kn' 1e8 'ks' 1e8
model clean
; bond them into a beam using pbonds
contact method bond gap 0.1
contact property pb_rmul=1.0 pb_kn=1e10 pb_ks=1e10 pb_ten=1e20 pb_coh=1e20
ball fix velocity spin range id=1 ; fix ball at left end

The example above is for illustration only, in reality you would really prefer to use the fish-halt keyword to the model solve command.