General HydroStatics
Ship Stability Software 
Command of the Week
(New or interesting aspects of GHS that you may not know about) 
Counting Time

Time is relative, or at least that is what the physicists tell us. In GHS, you can make time move as quickly, or as slowly, as you wish. All it takes is some understanding of how iterations can be used to count time. To illustrate, let's create a "tank timer" run file.
When using an iterative approach to loading, the "time factor" may be included by considering each iteration as a step in time. For example, if the capacity of a pump is 200 ft^3/hour and the tank is 1000 ft^3, we can decide that 1 iteration is 1 hour. Therefore, it would take 5 iterations, or 5 hours, to fill the tank. This time counting concept may seem like it would be easily understood, but things get more complex when we don't know (or don't wish to know) the tank capacity. Or perhaps we want to know the time it would take to fill to a specific load limit. To answer these types of questions, it really only takes a single macro loop. Behold, macro fill0: 
macro fill0 `%1 is load fraction, %2 is volume rate per MINUTE
set t={t} plus 1 set h={t} divide 60  set h=trunc {h} set q={t} divide 15  set r={q} minus trunc {q} set h0={h} times 60  set m={t} minus {h0} if {r}=0 then \After {2}{ h:0}{7} hours and;; {2}{ m:0}{7} minutes, tank {pname} load fraction is {load:3}.\ if {load}>=%1 then \ ;; \{+b}{4}Tank {pname} load fraction is {load:3}!{b}{7};; Fill time: {2}{h:0}{7} hrs & {2}{m:0}{7} mins\  \  exit load vol:*+%2 exit fill0 %1 %2 / 
All of those SET commands might appear daunting, but fear not, all we are doing is counting minutes and hours. The variable t is simply counting one minute each time the macro loops. The variable h is counting the number of hours elapsed and m is counting the number of minutes beyond each hour. The variable q counts the time every 15 minutes. We use this variable, along with the variable r and some clever arithmetic, to report the current elapsed time and load fraction every 15 minutes. By the way, those double semicolons at the end of lines are line continuations. The macro also has two parameters. The first parameter %1 is the load fraction to which we are filling the tank. The second parameter %2 is the volumetric flow rate per minute. When the load fraction for the tank selection is equal to %1, we write the final load fraction, as well as the total fill time, to the screen and exit the loop. To make things a little more intuitive, we introduce a second macro fill which will call macro fill0: 
macro fill `%1 is load fraction, %2 is volume rate per HOUR
set vpm=%2 divide 60 set t=0 `set time counter to 0 .fill0 %1 {vpm} / 
This macro serves two purposes: it sets the time counter t to zero before calling fill0 and it takes a flow rate input in volume per hour and divides it by 60 to get the volume per minute. Let's test it out: 
read fv
tank WT2.S .fill 0.875 100 tanks off 
In this example, we simply set the tank selection to the tank called WT2.S. We then set the maximum load fraction and fill rate to 100 ft^3/hour when calling the macro fill. Our tank timer says it will take 4 hours and 34 minutes to fill the tank to 0.875 at the given flow rate. 
One can readily extend this concept to simulate complex loading and unloading scenarios that include multiple tanks, different flow rates, and/or multiple tanks being loaded/unloaded simultaneously.
The run file used in this example may be found here. 
Questions, comments, or requests?
Contact Creative Systems, Inc. USA phone: 3603856212 Fax: 3603856213 Office hours: 7:00 am  4:00 pm Pacific Time, Monday  Friday Mailing address: PO Box 1910 Port Townsend, WA 98368 USA Click here for an index to this and previous COWs 