How To Use the GUI to Create Geometry and Boundary M-File: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 02/22/01-02/24/01 by Matthias K. Gobbert A geometry m-file contains information about the size and shape of the domain. It is needed to create the initial mesh, if you want to use Matlab's initmesh function, and to refine a given mesh. The point is that it is possible to create an initial mesh by hand (avoiding initmesh); actually, you may want to do this, if you want to ensure that you get a uniform mesh. But you would not be able to refine the mesh using refinemesh; for that, you will need a geometry m-file. One can of course write this oneself, but it is much easier, in particular for complex geometries, to make use of Matlab's graphical user interface (GUI), create the domain and set boundary conditions by pointing and clicking, and then exporting the needed data to the command line. At the same time, you can generate a boundary condition m-file that takes care of those. (0) Start the GUI by >> pdetool A large graphics window will come up. (1) Under Options: (a) Choose axis limits (choose slightly larger than domain to be drawn). (b) Set Snap. (c) Set Grid. (2) Draw domain: For our test cases, choose rectangle and draw appropriate domain. Watch info bar at bottom for hints on how to draw. (3) Set boundary conditions: (a) Under Boundary, click on Boundary Mode to get a picture showing different colors for the boundary edges and their orientation by arrows. You can click on Show Edge Labels and Show Subdomain Labels to check the labels for everything. (b) If you can click on Specify Boundary Conditions without selecting a particular boundary edge, *all* boundaries can be set at once; this makes only sense, if you have the same conditions on all boundary segments! (c) To set conditions for just one segment, double-click on it to get the dialog box. Caution: This clicking is tricky; make sure that conditions are set correctly. One pointer: A selected segment shows in black, a Dirichlet in red, and von Neumann type in blue. You can select, say, two segments together by clicking once on the first and then middle-mouse button click on the second; then select Specify Boundary Conditions under Boundary. (d) Export boundary information: Under Boundary, choose Export Decomposed Geometry; click OK in dialog box. (4) Write geometry m-file: (a) At the Matlab command line, you can use whos to check that you have the variables g and b, for instance: >> whos Name Size Bytes Class b 10x4 320 double array g 7x4 224 double array b holds the boundary condition information in the format discussed before; you can use this procedure to also to generate b, but it may not look exactly the same as if you had created it by hand. g is the geometry information needed to write the geometry m-file. (b) Use the functions wgeom and wbound to write the geometry and geometry specification m-files, respectively. Let's use the filenames 'largedom' and 'largebc', respectively. You would enter: >> mndom = 'largedom'; >> fid = wgeom (g, mndom); >> if (fid<0), disp('problem writing file!'); end; >> mnbc = 'largebc'; >> fid = wbound (b, mnbc); >> if (fid<0), disp('problem writing file!'); end; Now, you should have a files largedom.m and largebc.m (5) How to create a mesh and refine it twice: Set g to hold the filename of the geometry m-file: >> g = 'largedom'; >> [p,e,t] = initmesh (g); >> figure; pdemesh (p,e,t); >> [p,e,t] = refinemesh (g, p,e,t); >> figure; pdemesh (p,e,t); >> [p,e,t] = refinemesh (g, p,e,t); >> figure; pdemesh (p,e,t); The plots in between will result in three figures that demonstrate that the refinement is working; they are not needed in practice, of course.