15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

13.5. SIMULATION OF CONTINUOUS FIELD MODELS 253* Dt/(2*Dh)- wy * config[x, (y-1)%n])\config, nextconfig = nextconfig, configimport pycxsimula<strong>to</strong>rpycxsimula<strong>to</strong>r.GUI(stepSize = 50).start(func=[initialize, observe, update])In this example, we simulate <strong>the</strong> transport equation with (w x , w y ) = (0.01, 0.03) in a 2-D[0, 1] × [0, 1] space with periodic boundary conditions, starting from an initial configurationthat has a peak in <strong>the</strong> middle <strong>of</strong> <strong>the</strong> space:c(x, y, 0) = exp(− (x − )0.5)2 + (y − 0.5) 2(13.43)0.2 2The temporal <strong>and</strong> spatial resolutions are set <strong>to</strong> ∆t = 0.01 <strong>and</strong> ∆h = 0.01, respectively(so that <strong>the</strong> size <strong>of</strong> <strong>the</strong> grid is 100 × 100). This is a very slow simulation process, so <strong>the</strong>stepSize is set <strong>to</strong> 50 <strong>to</strong> skip unnecessary visualizations (see <strong>the</strong> last line). The surfaceplot is used <strong>to</strong> visualize <strong>the</strong> configuration in 3-D axes. Note that you need <strong>to</strong> call <strong>the</strong> showcomm<strong>and</strong> at <strong>the</strong> end <strong>of</strong> <strong>the</strong> observe function, because changes made <strong>to</strong> 3-D axes arenot au<strong>to</strong>matically reflected <strong>to</strong> <strong>the</strong> visualization (at least in <strong>the</strong> current implementation <strong>of</strong>matplotlib).The result <strong>of</strong> this simulation is shown in Fig. 13.13, where you can clearly see <strong>the</strong> peakbeing transported <strong>to</strong> a direction given by (w x , w y ). Moreover, thanks <strong>to</strong> <strong>the</strong> interactivenature <strong>of</strong> pycxsimula<strong>to</strong>r.py, this 3-D visualization is now interactively manipulatable evenif you are not running it from Anaconda Spyder, Enthought Canopy, or o<strong>the</strong>r interactiveenvironments. You can click <strong>and</strong> drag on it <strong>to</strong> rotate <strong>the</strong> surface <strong>to</strong> observe its 3-D structurefrom various angles.If you don’t need a 3-D surface plot, you can use imshow instead. This makes <strong>the</strong> codea bit simpler, <strong>and</strong> yet <strong>the</strong> result can be as good as before (Fig. 13.14):Code 13.6: transport-ca-imshow.pyimport matplotlibmatplotlib.use(’TkAgg’)from pylab import *n = 100 # size <strong>of</strong> grid: n * nDh = 1. / n # spatial resolution, assuming space is [0,1] * [0,1]Dt = 0.01 # temporal resolution

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!