Instructor Notes

This is a placeholder file. Please add content here.

Introduction to model coupling


Model coupling theory: the Multiscale Modelling and Simulation Framework


Instructor Note

  • Where process takes place
  • When process starts and ends (convergence, repetition)
  • Partly a modelling decision


Instructor Note

  • Collect in shared document
  • Discuss questions


Instructor Note

  • Grain and extent
  • Again, partly modelling decision


Instructor Note

  • Add to shared document


Instructor Note

  • Time horizontal, space vertical
  • Plotting scales, so sizes, not locations!
  • Timestep and extent, grid spacing and size


Instructor Note

  • All together in class


Instructor Note

  • Model of a computational model
  • Explain operators
  • Begin/end vs. inside state update loop
  • Filled output vs. open input
  • Quite flexible


Instructor Note

  • How to connect two SELs?
  • Time scales and domains are the most interesting part
  • Update shared document with SEL connections, but after giving everyone a bit of time to think
  • Three scenarios
    • Adjacent or separated time domains
    • Overlapping domains and same time scale
    • Overlapping domains and time scale separation


Instructor Note

  • Three scenarios use four coupling templates
  • Explain them, see picture
  • These are all the possibilities!


Instructor Note

  • Space is also important of course
  • Again three scenarios
    • Same domain and scale
      • May be best to make a single program
    • Same spatial domain, adjacent or separated scales
      • Multiple instances of the small one!
    • Adjacent spatial domains, same or overlapping spatial scales
      • For time-scale separation, the fast model needs to keep state!
  • These determine:
    • How many instances there are of each model
    • Whether state or boundary conditions are exchanged
  • Challenge 5: Find examples in the shared document


Instructor Note

  • There’s a diagram language for showing coupled models: gMMSL
  • Explain the diagram together (in the shared document)


MUSCLE3 - connecting a model to MUSCLE


Instructor Note

  • MUSCLE3 makes coupled simulations easy
  • Made by UvA-CSL and NLeSC
  • Example model: 1D reaction-diffusion
    • Concentration of a chemical in a 1D container
    • Time-scale separated -> call and release
    • Same spatial domain -> exchange state
  • MUSCLE3 has three components: libmuscle, manager, ymmsl-python
  • Connect model to libmuscle, here the (fast) micromodel (reaction)


Instructor Note

  • Reaction function is a very small (but typical) model code
    • Copy the state from the input to avoid overwriting it
  • Challenge 1: Edit your local reaction.py


Instructor Note

  • Instance represents this model instance to the coupled simulation
  • Send and receive messages on ports (don’t know what’s connected!)
  • Challenge (in the shared document, then discuss)
    • What are good names for the ports?
    • Which operators do they need to be associated with?


Instructor Note

  • Sometimes a model needs to run many times, depending on how it’s connected
  • MUSCLE3 can figure that out, but we do need to add a loop to implement it
  • Challenge 2: Add an Instance and a reuse loop


Instructor Note

  • Handy to have all the settings together in one place
  • Models get them via the instance object (see syntax)
    • Optionally type check (not so optionally in C++ and Fortran)
  • Challenge 3: individually: get your settings from MUSCLE3 instead of hard-coding them


Instructor Note

  • Now, we need to receive our initial state from the appropriate port
  • msg.data will be a MUSCLE3 Grid object, an array with annotated indices
  • Explain syntax in example
    • Need to copy here too, as the received message is read-only
    • Timestamp has simulation time the data corresponds to


Instructor Note

  • We won’t try to connect anything to our O_i and S
    • No ports
    • No need to receive or send there
  • It’s good to keep time carefully, for debugging alone
    • Use received timestamp to init current time, then run from there
    • How should you adjust the final time?
  • Challenge 4: Receive initial state and track time


Instructor Note

  • At the end of the run, we need to send the final state
  • Create a Message
  • Use a Grid object (show and explain example code)
    • Second timestamp is for advanced cases, not needed here
  • Challenge 5: Send the final state


MUSCLE3 - coupling and running


Instructor Note

  • Write differences between diffusion.py and reaction.py in shared document
    • Besides the model, of course


Instructor Note

  • Time to connect the two models together, see diagram
  • Computers don’t read diagrams very well, so there is yMMSL, based on YAML
  • MUSCLE3 is configured using a yMMSL file
  • Challenge 2: Translate diagram into text, based on given template
    • See reaction_diffusion.ymmsl in ZIP


Instructor Note

  • Remember that we’re getting our settings from MUSCLE3, they need to be added
  • It’s a YAML dict, but look at the names of the settings, does anything stand out?


Instructor Note

  • Resources are a bit of an advance topic, so we’re not going into it here
  • We need to specify something, which is that our components are single-threaded


Instructor Note

  • To connect, need model functions and configuration, then tie together
  • Show code snippets
  • Challenge 3
    • Add the settings and the resources section to your yMMSL file
    • Look at coupled_model.py and try to run it!


Instructor Note

  • This one may be a bit more difficult, but needed for C++, Fortran and HPC
  • Manager lets you use programs instead of Python functions to create instances
  • Component, Instance, Implementation
  • Challenge 4
    • Turn reaction model into a separate Python program
    • Tell MUSCLE3 how to start the submodels
    • Run simulation using manager