42 | | {{{ |
43 | | cd .. |
44 | | muscle2 --cxa src/cxa/SimpleSubmodelExample.cxa.rb |
45 | | }}} |
46 | | |
47 | | This example has a writer submodel `w` and a reader submodel `r`. The writer sends data to the reader, and the reader prints that data to screen. |
48 | | |
49 | | You can run the simple example by specifying that the current MUSCLE command will run the Simulation Manager with the `--main` flag or its shorthand `-m`, and specifying all submodels that should run in this command: |
50 | | {{{ |
51 | | muscle2 -mc src/cxa/SimpleSubmodelExample.cxa.rb w r |
52 | | }}} |
53 | | |
54 | | Usually, if you want to run all the submodels instances with the current MUSCLE command, specify the `--allinstances` or its shorthand `-a`: |
55 | | {{{ |
56 | | muscle2 -amc src/cxa/SimpleSubmodelExample.cxa.rb |
57 | | }}} |
58 | | |
59 | | So what do we observe? MUSCLE detects that it should start the Simulation Manager and a Simulation. It first starts the manager, which shows its TCP/IP address. Then the Simulation starts and it executes the submodel instances `w` and `r`. These start their respective conduits, and start 'computing'. |
60 | | |
61 | | On local machines, these commands are sufficient to run any MUSCLE model. You can try the other examples in the `src/cxa` directory, just run |
62 | | {{{ |
63 | | muscle2 -amc src/cxa/[...].cxa.rb |
64 | | }}} |
| 42 | {{{ |
| 43 | cd .. |
| 44 | muscle2 --cxa src/cxa/SimpleSubmodelExample.cxa.rb |
| 45 | }}} |
| 46 | |
| 47 | This example has a writer submodel `w` and a reader submodel `r`. The writer sends data to the reader, and the reader prints that data to screen. |
| 48 | |
| 49 | You can run the simple example by specifying that the current MUSCLE command will run the Simulation Manager with the `--main` flag or its shorthand `-m`, and specifying all submodels that should run in this command: |
| 50 | {{{ |
| 51 | muscle2 -mc src/cxa/SimpleSubmodelExample.cxa.rb w r |
| 52 | }}} |
| 53 | |
| 54 | Usually, if you want to run all the submodels instances with the current MUSCLE command, specify the `--allinstances` or its shorthand `-a`: |
| 55 | {{{ |
| 56 | muscle2 -amc src/cxa/SimpleSubmodelExample.cxa.rb |
| 57 | }}} |
| 58 | |
| 59 | So what do we observe? MUSCLE detects that it should start the Simulation Manager and a Simulation. It first starts the manager, which shows its TCP/IP address. Then the Simulation starts and it executes the submodel instances `w` and `r`. These start their respective conduits, and start 'computing'. |
| 60 | |
| 61 | On local machines, these commands are sufficient to run any MUSCLE model. You can try the other examples in the `src/cxa` directory, just run |
| 62 | {{{ |
| 63 | muscle2 -amc src/cxa/[...].cxa.rb |
| 64 | }}} |
67 | | {{{ |
68 | | muscle2 -amc src/cxa/LaplaceExample.cxa.rb |
69 | | }}} |
70 | | |
71 | | It will open two windows that compute temperature dissipation, that are coupled on the boundary. Red is a +1 temparature, blue a -1 temperature, and green a zero temperature. The initial condition, far right and far left correspond to zero temperature, the top to a sine function and the bottom to a cosine. Temperature is dissipated during each time step by taking the average of the four neighboring cells. The adjacent boundary is transmitted each iteration. |
| 67 | {{{ |
| 68 | muscle2 -amc src/cxa/LaplaceExample.cxa.rb |
| 69 | }}} |
| 70 | |
| 71 | It will open two windows that compute temperature dissipation, that are coupled on the boundary. Red is a +1 temparature, blue a -1 temperature, and green a zero temperature. The initial condition, far right and far left correspond to zero temperature, the top to a sine function and the bottom to a cosine. Temperature is dissipated during each time step by taking the average of the four neighboring cells. The adjacent boundary is transmitted each iteration. |
83 | | {{{ |
84 | | . [MUSCLE_DIR]/etc/muscle.profile |
85 | | }}} |
86 | | |
87 | | Then go to the unzipped MUSCLE directory. Now we can run muscle on the same site. In the first terminal window, start the main MUSCLE with the writing submodel w. This is done by typing: |
88 | | {{{ |
89 | | muscle2 -mc src/cxa/SimpleSubmodelExample.cxa.rb w |
90 | | }}} |
91 | | |
92 | | So what do you observe? |
93 | | |
94 | | One of the most important messages is `Started the connection handler, listening on [IPADDRESS:PORT]`. |
95 | | Copy the IP address and port number. |
96 | | In the second terminal, start the reading submodel r, and at the end put the `-M` or `--manager` flag |
97 | | with the IP address and port: |
98 | | {{{ |
99 | | muscle2 -c src/cxa/SimpleSubmodelExample.cxa.rb r -M [IPADDRESS:PORT] |
100 | | }}} |
101 | | |
102 | | What happens in both terminals? |
| 83 | {{{ |
| 84 | . [MUSCLE_DIR]/etc/muscle.profile |
| 85 | }}} |
| 86 | |
| 87 | Then go to the unzipped MUSCLE directory. Now we can run muscle on the same site. In the first terminal window, start the main MUSCLE with the writing submodel w. This is done by typing: |
| 88 | {{{ |
| 89 | muscle2 -mc src/cxa/SimpleSubmodelExample.cxa.rb w |
| 90 | }}} |
| 91 | |
| 92 | So what do you observe? |
| 93 | |
| 94 | One of the most important messages is `Started the connection handler, listening on [IPADDRESS:PORT]`. |
| 95 | Copy the IP address and port number. |
| 96 | In the second terminal, start the reading submodel r, and at the end put the `-M` or `--manager` flag |
| 97 | with the IP address and port: |
| 98 | {{{ |
| 99 | muscle2 -c src/cxa/SimpleSubmodelExample.cxa.rb r -M [IPADDRESS:PORT] |
| 100 | }}} |
| 101 | |
| 102 | What happens in both terminals? |
106 | | In the first terminal window, start the Simulation Manager: |
107 | | {{{ |
108 | | muscle2 -mc src/cxa/SimpleSubmodelExample.cxa.rb |
109 | | }}} |
110 | | |
111 | | In the second terminal, start the submodels. Again, replace the port number |
112 | | with the one that is printed by the Simulation Manager. |
113 | | {{{ |
114 | | muscle2 -ac src/cxa/SimpleSubmodelExample.cxa.rb -M [IPADDRESS:PORT] |
115 | | }}} |
116 | | |
117 | | What happens in both terminals? |
| 106 | In the first terminal window, start the Simulation Manager: |
| 107 | {{{ |
| 108 | muscle2 -mc src/cxa/SimpleSubmodelExample.cxa.rb |
| 109 | }}} |
| 110 | |
| 111 | In the second terminal, start the submodels. Again, replace the port number |
| 112 | with the one that is printed by the Simulation Manager. |
| 113 | {{{ |
| 114 | muscle2 -ac src/cxa/SimpleSubmodelExample.cxa.rb -M [IPADDRESS:PORT] |
| 115 | }}} |
| 116 | |
| 117 | What happens in both terminals? |
120 | | {{{ |
121 | | ssh user@node2 |
122 | | [INSTALL MUSCLE...] |
123 | | . MUSCLE_DIR/etc/muscle.profile |
124 | | }}} |
125 | | |
126 | | And go to the source directory of MUSCLE. We will perform the same experiment, |
127 | | but now on different hosts. So on the first node, for instance run only `w` |
128 | | {{{ |
129 | | muscle2 -mc src/cxa/SimpleSubmodelExample.cxa.rb w |
130 | | }}} |
131 | | |
132 | | On the other node, we now also need to specify which host and port the other |
133 | | MUSCLE instance is running on |
134 | | {{{ |
135 | | muscle -c src/cxa/SimpleSubmodelExample.cxa.rb -M [IPADDRESS:PORT] r |
136 | | }}} |
137 | | |
138 | | What is the output in node one? And on the other? |
| 120 | {{{ |
| 121 | ssh user@node2 |
| 122 | [INSTALL MUSCLE...] |
| 123 | . MUSCLE_DIR/etc/muscle.profile |
| 124 | }}} |
| 125 | |
| 126 | And go to the source directory of MUSCLE. We will perform the same experiment, |
| 127 | but now on different hosts. So on the first node, for instance run only `w` |
| 128 | {{{ |
| 129 | muscle2 -mc src/cxa/SimpleSubmodelExample.cxa.rb w |
| 130 | }}} |
| 131 | |
| 132 | On the other node, we now also need to specify which host and port the other |
| 133 | MUSCLE instance is running on |
| 134 | {{{ |
| 135 | muscle -c src/cxa/SimpleSubmodelExample.cxa.rb -M [IPADDRESS:PORT] r |
| 136 | }}} |
| 137 | |
| 138 | What is the output in node one? And on the other? |
170 | | * add a submodel instance so that you get a coupling between West - Middle - East; |
171 | | * change the filters and see how it affects the computations (see [wiki:Configuration#Filters Filter documentation]); or |
172 | | * modify the file `src/laplace/filter/InvertFilter` to do something additional (see [wiki:Java%20API#Filters Java filter documentation]) |
173 | | * modify the file `src/laplace/terminal/DoubleArraySource.java` to do something additional, such as computing a function instead of sending a fixed number (see [Java terminal documentation][javaterminal]) |
| 170 | * add a submodel instance so that you get a coupling between West - Middle - East; |
| 171 | * change the filters and see how it affects the computations (see [wiki:Configuration#Filters Filter documentation]); or |
| 172 | * modify the file `src/laplace/filter/InvertFilter` to do something additional (see [wiki:Java%20API#Filters Java filter documentation]) |
| 173 | * modify the file `src/laplace/terminal/DoubleArraySource.java` to do something additional, such as computing a function instead of sending a fixed number (see [Java terminal documentation][javaterminal]) |
194 | | message back to Sender.java; modify Sender.java to receive this message. In |
195 | | this example, call both the sending and the receiving port "messages", for |
196 | | example. Test your implementation by running |
197 | | |
198 | | {{{ |
199 | | cd build |
200 | | ./build.sh $MUSCLE_HOME |
201 | | cd .. |
202 | | muscle2 -amc src/cxa/SimpleSubmodelExample.cxa.rb |
203 | | }}} |
204 | | |
205 | | **Spoiler:** |
206 | | |
207 | | * In ConsoleWriter.java |
208 | | * create the method `protected void intermediateObservation()` |
209 | | * send some data over it in `execute()` by adding |
210 | | {{{ |
211 | | double[] msg = {1.0, 0.0, 1.0}; |
212 | | out("messages").send(msg); |
213 | | }}} |
214 | | * In Sender.java |
215 | | * Create the method `protected void solvingStep()` |
216 | | * Receive the data |
217 | | {{{ |
218 | | double[] msg = (double[])in("messages").receive(); |
219 | | }}} |
220 | | * Print the data with |
221 | | {{{ |
222 | | for (double d : msg) { |
223 | | log("Message from ConsoleWriter: " + d); |
224 | | } |
225 | | }}} |
226 | | * In the configuration file `src/cxa/SimpleSubmodelExample.cxa.rb` |
227 | | * Append the lines |
228 | | {{{ |
229 | | cs.attach('r' => 'w') { |
230 | | tie('messages', 'messages') |
231 | | } |
232 | | }}} |
233 | | * Since the names of the ports are equal (`messages`), you can also use the abbreviated form: |
234 | | {{{ |
235 | | cs.attach('r' => 'w') { |
236 | | tie('messages') |
237 | | } |
238 | | }}} |
239 | | * Build it and execute |
| 194 | message back to Sender.java; modify Sender.java to receive this message. In |
| 195 | this example, call both the sending and the receiving port "messages", for |
| 196 | example. Test your implementation by running |
| 197 | |
| 198 | {{{ |
| 199 | cd build |
| 200 | ./build.sh $MUSCLE_HOME |
| 201 | cd .. |
| 202 | muscle2 -amc src/cxa/SimpleSubmodelExample.cxa.rb |
| 203 | }}} |
| 204 | |
| 205 | **Spoiler:** |
| 206 | |
| 207 | * In ConsoleWriter.java |
| 208 | * create the method `protected void intermediateObservation()` |
| 209 | * send some data over it in `execute()` by adding |
| 210 | {{{ |
| 211 | double[] msg = {1.0, 0.0, 1.0}; |
| 212 | out("messages").send(msg); |
| 213 | }}} |
| 214 | * In Sender.java |
| 215 | * Create the method `protected void solvingStep()` |
| 216 | * Receive the data |
| 217 | {{{ |
| 218 | double[] msg = (double[])in("messages").receive(); |
| 219 | }}} |
| 220 | * Print the data with |
| 221 | {{{ |
| 222 | for (double d : msg) { |
| 223 | log("Message from ConsoleWriter: " + d); |
| 224 | } |
| 225 | }}} |
| 226 | * In the configuration file `src/cxa/SimpleSubmodelExample.cxa.rb` |
| 227 | * Append the lines |
| 228 | {{{ |
| 229 | cs.attach('r' => 'w') { |
| 230 | tie('messages', 'messages') |
| 231 | } |
| 232 | }}} |
| 233 | * Since the names of the ports are equal (`messages`), you can also use the abbreviated form: |
| 234 | {{{ |
| 235 | cs.attach('r' => 'w') { |
| 236 | tie('messages') |
| 237 | } |
| 238 | }}} |
| 239 | * Build it and execute |
242 | | {{{ |
243 | | cd build |
244 | | ./build.sh $HOME/muscle |
245 | | muscle2 -amc ../src/cxa/NativeExample2.cxa.rb |
246 | | }}} |
247 | | |
248 | | **Spoiler:** |
| 242 | {{{ |
| 243 | cd build |
| 244 | ./build.sh $HOME/muscle |
| 245 | muscle2 -amc ../src/cxa/NativeExample2.cxa.rb |
| 246 | }}} |
| 247 | |
| 248 | **Spoiler:** |
| 249 | |
| 250 | * In Sender.cpp |
| 251 | * Receive some data after sending by coding in the `main()` function |
| 252 | {{{ |
| 253 | size_t sz; |
| 254 | double* msg = (double *) |
| 255 | muscle::env::receive("messages", (void *)0, sz, MUSCLE_DOUBLE); |
| 256 | }}} |
| 257 | * Print the data with |
| 258 | {{{ |
| 259 | for (size_t j = 0; j < sz; j++) { |
| 260 | logger::info("Message from ConsoleWriter: %f", msg[j]); |
| 261 | } |
| 262 | }}} |
| 263 | * Free the data with |
| 264 | {{{ |
| 265 | muscle::env::free_data(msg, MUSCLE_DOUBLE); |
| 266 | }}} |
| 267 | * In the configuration file `src/cxa/NativeExample2.cxa.rb` |
| 268 | * Change the line |
| 269 | {{{ |
| 270 | cxa.add_kernel('r', 'examples.simplejava.ConsoleWriter') |
| 271 | }}} |
| 272 | to |
| 273 | {{{ |
| 274 | cxa.add_kernel('r', 'examples.simplesubmodel.ConsoleWriter') |
| 275 | }}} |
250 | | * In Sender.cpp |
251 | | * Receive some data after sending by coding in the `main()` function |
252 | | {{{ |
253 | | size_t sz; |
254 | | double* msg = (double *) |
255 | | muscle::env::receive("messages", (void *)0, sz, MUSCLE_DOUBLE); |
256 | | }}} |
257 | | * Print the data with |
258 | | {{{ |
259 | | for (size_t j = 0; j < sz; j++) { |
260 | | logger::info("Message from ConsoleWriter: %f", msg[j]); |
261 | | } |
262 | | }}} |
263 | | * Free the data with |
264 | | {{{ |
265 | | muscle::env::free_data(msg, MUSCLE_DOUBLE); |
266 | | }}} |
267 | | * In the configuration file `src/cxa/NativeExample2.cxa.rb` |
268 | | * Change the line |
269 | | {{{ |
270 | | cxa.add_kernel('r', 'examples.simplejava.ConsoleWriter') |
271 | | }}} |
272 | | to |
273 | | {{{ |
274 | | cxa.add_kernel('r', 'examples.simplesubmodel.ConsoleWriter') |
275 | | }}} |
276 | | |
277 | | * Append the lines |
278 | | {{{ |
279 | | cs.attach('r' => 'w') { |
280 | | tie('messages') |
281 | | } |
282 | | }}} |
| 277 | * Append the lines |
| 278 | {{{ |
| 279 | cs.attach('r' => 'w') { |
| 280 | tie('messages') |
| 281 | } |
| 282 | }}} |