Skip to content

List of examples

Joris Borgdorff edited this page Aug 30, 2016 · 1 revision

The examples on this page are all specified in the CxA files in the src/cxa directory of the MUSCLE source package. The implementation of the submodels is spread out over different directories based on the language used.

Java examples

The code for the Java examples is contained in src/java/examples.

Simple Example: The simple example model is specified in src/cxa/SimpleExample.cxa.rb and implemented in src/java/examples/simplejava contains a writer submodel instance w and the reader submodel instance r. Both submodels use the MUSCLE 2's free-form API. Instance w creates some data in the form of an array of doubles, and sends it to instance r, which reads the data and prints it out. The former has a conduit entrance called data, and the latter a conduit exit called data. In the CxA file, a multiplication filter is applied the conduit, with parameter 0.5, so all the data is multiplied by 0.5.

Simple Submodel: The scenario of Simple Submodel is the same as the Simple Example, but it uses the formal MUSCLE 2 Java API.

Macro Micro: The Macro Micro model has two submodels with formal implementation, in a typical loop that Macro Micro models typically exhibit: in its loop, macro initializes the micro model, and the micro model sends its final observation back to the macro model. The macro model continues iterating for as long as there is simulation time.

Terminals: In the Terminals model, a submodel instance proc processes data, by checking whether it is larger than a threshold. Incoming data is from a terminal src, which reads an array of doubles from a file. Outgoing data is an array of booleans for whether the values are larger than a threshold which is stored to file by the terminal sink.

Laplace Example: Runs a Laplace heat flow solver of two connected systems. At each iteration, the boundary condition of the systems is updated with the boundary data of the other.

Ping Pong: Does a benchmark, sending packages from the Ping submodel instance to the Pong submodel instance and back again, with different message sizes. Its parameters are set in src/cxa/PingPong.cxa.rb, and the code is in src/java/examples/pingpong.

C/C++ examples

The MUSCLE C/C++ API is used in the src/cpp/examples directory.

SimpleCpp2: The new MUSCLE 2 C++ API is used in SimpleCpp2, with CxA file src/cxa/NativeExample2.cxa.rb. It is the same scenario as the Simple Example for the MUSCLE 2 Java API, but the sender is now a C++ submodel.

Data Integrity: To ensure the integrity of data sent over a range of connections, the Data Integrity model sends random data with different data types back and forth in different submodels. If you are worried that a non-standard protocol or network mechanism is used, this is the model with which you can be sure that MUSCLE leaves your data intact.

Simple MPI: Similar to SimpleCpp2, SimpleMPI has a C implementation of the sender. This time, however, the sender consists of two MPI processes, that communicate their data with a call to MPI_Bcast.

Ping Pong Cpp: The same model as the Java Ping Pong model, but with a C++ implementation.

Fortran example

The code for the Fortran example is contained in src/fortran/examples.

Simple Fortran: An example Fortran implementation of the writer submodel explained in the Simple Example for Java. The boilerplate code needed to communicate with the C library is included.

Python example

The code for the Python example is contained in src/python/examples.

Simple Python: An example Python implementation of a submodel that sends and receives data to itself. To install the Python module, go to the build/ directory, and run

cmake -DBUILD_PYTHON=ON ..
make install
source $MUSCLE_HOME/etc/muscle.profile

After that, you can try it out by starting python, and typing

import muscle
help(muscle)

Scala example

The code for the Scala example is contained in src/scala/examples.

Simple Scala: An example Scala implementation of the writer submodel explained in the Simple Example for Java. Note that for it to work, you compile the code with the scalac compiler, and the Scala runtime library must be included in the Java classpath during runtime.

Clone this wiki locally