/* This file has been slightly modified by Hiroshi C. Ito, so that the simulation speed can be controled. 2018.02.01 */ /* * $Id: demo2.i,v 1.1.1.1 2005/09/18 22:05:55 dhmunro Exp $ * Mesh plotting demo */ /* Copyright (c) 2005, The Regents of the University of California. * All rights reserved. * This file is part of yorick (http://yorick.sourceforge.net). * Read the accompanying LICENSE file for details. */ func demo2(which, time_limit,inter_pause=,T=) /* DOCUMENT demo2 Exhibit quadrilateral mesh plots in 3 movies of a drumhead. The drumhead is initially stationary, but has a bump near one edge. Yorick is solving a 2D wave equation to compute the evolution of this bump. The first movie is a filled mesh plot with color "proportional" to the height of the surface of the drum. A few well chosen contour levels (here 3) add a lot to a filled mesh plot. The second movie is a "3D" perspective plot of the height of the drumhead. In this movie, the mesh lines are drawn, which is slightly confusing since the cells are not all the same shape. The second movie is a "3D" shaded plot of the height of the drumhead. Yorick computes surface shading based on the angle of each cell from a light source. As you watch this, you might reflect on the two dimensionality of your retina. What Yorick lacks by way of 3D graphics is really just fancy hidden surface algorithms; the simple painter's algorithm used here and in plwf.i is easy to implement. There are two optional arguments to demo2: the first is the number fo the movie (1, 2, or 3) you want to watch; the second is a time limit on the duration of each movie in seconds (default is 60 seconds each). */ { require, "movie.i"; if(is_void(T))T=500; if(is_void(inter_pause))inter_pause=0.01; /* generate a 30-by-30 cell mesh on the [-1,1] square */ x= span(-1, 1, 31)(,-:1:31); y= transpose(x); /* map the square mesh into a mesh on the unit circle this mesh has more nearly equal area cells than a polar coordinate circle */ scale= max(abs(y),abs(x))/(abs(y,x)+1.e-30); /* note that abs(y,x)=sqrt(x^2+y^2) */ x*= scale; y*= scale; f= f0= exp(-8.*abs(y+.67,x+.25)^2)*(1.-abs(y,x)^2); fdot= 0.0*f(2:-1,2:-1); af= abs(f(2:-1,2:-1)); lf= laplacian(f, y,x); xdz= x(dif,zcen); xzd= x(zcen,dif); ydz= y(dif,zcen); yzd= y(zcen,dif); dt= 0.375*sqrt(min(abs(xdz*yzd - xzd*ydz))); //dt= 0.0375*sqrt(min(abs(xdz*yzd - xzd*ydz))); window, 0, wait=1, style="nobox.gs"; palette, "heat.gp"; limits, -1, 1, -1, 1; /* roll the filled mesh movie */ if (which && which!=1) goto persp; fc= f(zcen,zcen); cmin= cmax= max(abs(fc)); cmin= -cmin; level= cmax/4.; //movie, display_plf, time_limit,0.01; movie, display_plf, time_limit,inter_pause; write,format="%f frames of filled mesh drumhead completed in %f sec\n", movie_timing(4), movie_timing(3); write,format="Rate for filled mesh is %f frames/(CPU sec), %f frames(wall sec)\n", movie_timing(4)/(movie_timing(1)-movie_timing(5)+1.0e-4), movie_timing(4)/(movie_timing(3)-movie_timing(5)+1.0e-4); /* roll the perspective movie */ persp: if (which && which!=2) goto shade; f= f0; limits, -1, 1, -1, 1; movie, display_plm, time_limit,inter_pause; // movie, display_plm, time_limit; write,format="%f frames of wireframe surface drumhead completed in %f sec\n", movie_timing(4), movie_timing(3); write,format="Rate for filled mesh is %f frames/(CPU sec), %f frames(wall sec)\n", movie_timing(4)/(movie_timing(1)-movie_timing(5)+1.0e-4), movie_timing(4)/(movie_timing(3)-movie_timing(5)+1.0e-4); /* roll the shaded movie */ shade: if (which && which!=3) return; f= f0; limits, -1, 1, -1, 1; //movie, display_pl3, time_limit; movie, display_pl3, time_limit,inter_pause; write,format="%f frames of filled surface drumhead completed in %f sec\n", movie_timing(4), movie_timing(3); write,format="Rate for filled mesh is %f frames/(CPU sec), %f frames(wall sec)\n", movie_timing(4)/(movie_timing(1)-movie_timing(5)+1.0e-4), movie_timing(4)/(movie_timing(3)-movie_timing(5)+1.0e-4); fma; limits; } func display_plf(i) { /* display first */ fc= f(zcen,zcen); cmin= cmax= max(abs(fc)); cmin= -cmin; plf, fc, -y, -x, cmin=cmin, cmax=cmax; /* the 0 contour level is too noisy without some smoothing... */ fs= f(zcen,zcen)(pcen,pcen); plc, fs, -y, -x, levs=0., marks=0, color="green", type="solid"; plc, f, -y, -x, levs=level, marks=0, color="black", type="dash"; plc, f, -y, -x, levs=-level, marks=0, color="green", type="dash"; /* then take a step forward in time */ lf= laplacian(f, y,x); af= abs(f(2:-1,2:-1)); fdot+= lf*dt; f(2:-1,2:-1)+= fdot*dt; //return i<200; return i