Java Reference
In-Depth Information
new - indata[] array. If the new - indata[] array is actually longer than three
elements, we simply ignore the elements in index positions 3 and 4:
// Obtain new amplitude, omega, and spring constant values
fAmplitude = new - indata[0];
fOmega = new - indata[1];
fSpringCons = new - indata[2];
// new - indata[3] and new - indata[4] are ignored
In this way, we permit the client to use the very same data array in both
initializeSimulation() and when providing new input data during the
running of the simulation.
Suppose the client wishes to cause the simulation to halt before reaching T max .
We already have the halt() method, but it is not callable by the client. Neither
have we provided a remote method in ServerInterface that the client can
use to instruct the simulation to halt early. One way to add this functionality is to
assign special meaning to one of the input data elements. For example, we could
interpret a negative spring constant, which makes no physical sense, to mean the
simulation should be halted. Such overloading of meaning might make sense in
a tightly resource-constrained environment, but doing so is sure to be a source of
confusion.
We find it more convenient and less potentially confusing to add one additional
element to the new input data array. This additional element is a control parameter
that, when set, can be used to terminate the simulation. It must appear in array
index 5 since elements 3 and 4 are already defined even though we don't use
them. So, by convention, whenever new - indata[5] is set to 1, we terminate
the loop by calling halt() . Note that this convention means that the client must
be sure to set the fifth element to 0 when it wants the simulation to continue
normally.
if ((int)indata[5] == 1) halt ();
In this example, we could just as well set fKillMe to true directly. However, it
is best to call the halt() method in order to be sure that any additional clean-up
tasks performed by halt() are run.
Unless the client takes the special action needed to halt the simulation early,
then the simulation should run until fMaxTime is reached. Therefore we need to
check that our simulation time has not exceeded fMaxTime before continuing
with the simulation loop.
Our entire simulation code is extremely simple. A real scientific simulation
will be much more complex and will require substantial CPU time to calculate.
In order to approximate the effects of a more complex simulation, we build in a
fake time delay of 100 ms per loop. Thus
Search WWH ::




Custom Search