Changes between Version 2 and Version 3 of Java API
- Timestamp:
- 09/04/12 13:22:01 (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Java API
v2 v3 3 3 == About the API == 4 4 5 The Multiscale Modeling Language (MML) defines several computational elements. The names of these elements are: 6 * conduit; 7 * submodel; 8 * mapper; 9 * filter; and 10 * terminal. 5 There are two ways to exploit the MUSCLE API: either by using these defined by the Multiscale Modeling Language, or by writing free-form code, where all orchestration and deadlock detection is your own responsibility. The former gives code that is easy to read and to debug, while the latter makes it possible to optimally exploit any parallelism in the model. This page section is split in two parts, one for each approach. With care, it is also possible to combine these approaches in a model, choosing the more appropriate form per submodel. 11 6 12 These elements are all supported in the MUSCLE API. 7 The computational elements that the Multiscale Modeling Language (MML) defines are: 8 * the conduit, for sending messages; 9 * submodel, for modeling phenomena at certain scales; 10 * mapper, for dimensionless mappings of data; 11 * filter, for time and datatype filtering; and 12 * terminal, for terminating empty conduits. 13 13 14 There are two ways to exploit the MUSCLE API: either by using these constructs, or by writing free-form code, where all orchestration and deadlock detection is your own responsibility. The former gives code that is easy to read and to debug, while the latter makes it possible to optimally exploit any parallelism in the model. This page section is split in two parts, one for each approach. With care, it is also possible to combine these approaches in a model, choosing the more appropriate form per submodel. 15 16 In both cases, conduits are defined the same, and parameters are passed in the same way. 14 These elements are all supported in the MUSCLE API. Conduits and parameters are used the same in MML-based or free-form code. 17 15 18 16 === Conduits === … … 56 54 Timestamp time = obsA.getTimestamp(); 57 55 }}} 56 If receive is called and the submodel on the other end has stopped, a MUSCLEConduitExhaustedException is thrown. To prevent this, it is possible to first call exitA.hasNext(), which is also blocking but returns a boolean. 57 58 If a lot of conduit exits are used and the order in which they are received is not important, it is possible to loop over multiple conduits and call the ready() method. This is non-blocking, and it will return true when hasNext() will return an answer without blocking. 58 59 59 60 A ConduitEntrance has several different send functions. The most basic send(data) sends the data and deduces the timestamp at which the data is sent, by adding delta T of the timescale to the previous timestamp. If the instance is dimensionless, or if required, you can explicitly set the timestamp of the data, and the timestamp at which you send the next message with send(data, time, nextTime): … … 69 70 }}} 70 71 71 Although the entrance is automatically closed once the instance is finished, it is also possible to close the conduit earlier .72 Although the entrance is automatically closed once the instance is finished, it is also possible to close the conduit earlier with the close() method, if it is not going to be used again. 72 73 73 74 === Parameters === … … 110 111 } 111 112 }}} 112 Step by step, a submodel can be restarted any number of times depending on the couplings, this is what the outer loop does. Next, each time a submodel is run, it has an initialization phase where it determines the initial state and what the simulation time of this initial state should be. Then it enters a while loop while some end condition is not met. Each iteration it sends some observation of the state, and it computes the next state. When the end condition is met, it is possible to do some cleaning and to send a final observation. At the end of the submodel it decides whether it should restart.113 Reading this code step by step, a submodel can be restarted any number of times depending on the couplings, this is what the outer loop does. Next, each time a submodel is started, it has an initialization phase where it determines the initial state and what the simulation time of this initial state should be. Then it enters a while loop while some end condition is not met. Each iteration it sends some observation of the state, and it computes the next state. When the end condition is met, it is possible to do some cleaning and to send a final observation. At the end of the submodel it decides whether it should restart. 113 114 114 In MUSCLE, endCondition is implemented as the willStop() method, which looks at all the messages sent and received and the message with the highest simulation time is compared with the total time in the timescale of the submodel, with parameter "submodelName:T". 115 In MUSCLE, endCondition is implemented as the willStop() method, which looks at all the messages sent and received and the message with the highest simulation time is compared with the total time in the timescale of the submodel, with parameter "submodelName:T". Restart submodel returns false by default, but could depend on whether one of the conduits will receive more messages. 115 116 116 117 == MUSCLE free-form API ==