proj dynlim
clear
`--- INTACT CONDITION ---
read fv
we 250,-2,0,8
so
report
\\{+B}Run file to find the angle of dynamic limit for damage cases.\
\\\{+B}Intact Condition\ | \

st

`--- FLOODING CASE MACRO---
macro fldset1
page
\\{+B}Finding the angle of dynamic limit\
\{+B}Condition with flooding in tanks: %1\ | \
type (*) int
type (%1) flood
so
st
/


`--- MACRO TO FIND THE ANGLE WHERE THE AREA UNDER THE CURVE EQUALS ZERO ---
macro dynlim
so
if {heel} > -0.1 then if {heel} < 0.1 then \{+B}Calculation not applicable. ,,
     Damaged equilibrium angle too small. | exit
vari a, b, low, mid, high=50`adjust high to be larger than the largest possible solution
vari limatt1, limatt2, limatt3

set low = {heel} plus 0.001
set mid = {low} plus {high} div 2
limit(1) residual ratio from abs 0 to abs {low} > 1
limit(2) residual ratio from abs 0 to abs {mid} > 1
limit(3) residual ratio from abs 0 to abs {high} > 1
ra /lim:att /noprint `comment out the /noprint to see the initial RA setup

macro binfind
if {limatt2} > 1 then set high = {mid} else set low = {mid}
set mid = {low} plus {high} div 2
limit(1) residual ratio from abs 0 to abs {low} > 1
limit(2) residual ratio from abs 0 to abs {mid} > 1
limit(3) residual ratio from abs 0 to abs {high} > 1
ra /lim:att /noprint`comment out the /noprint to see the binary search
if {limatt2} < 1 then exit .binfind
if {limatt2} > 1 then if {limatt2} < 1.005 then exit else exit .binfind
//
.binfind
limit(1) off
limit(3) off
ra /lim
\{+B}The angle where the residual ratio = 1, is {mid}\
/

.fldset1 "WT1.S, WT2.S"
.dynlim

.fldset1 "FOREPEAK.C"
.dynlim

print preview
report off