Adding Rappture to MATLAB Applications Michael Mc Lennan

Adding Rappture to MATLAB Applications Michael Mc. Lennan HUBzero® Platform for Scientific Collaboration Purdue University This work licensed under Creative Commons See license online: by-nc-sa/3. 0

Example: Matlab/Octave Tool The usual way… % matlab -nodisplay -r fermi Enter the Fermi level (e. V): Ef = 2. 4 Enter the temperature (K): T = 77 The Rappture way… % more out. dat FERMI-DIRAC FUNCTION F 1/2 f 1/2 ------0. 999955 0. 999944 Energy (e. V) ------2. 33365 2. 33431 2. 33498 https: //nanohub. org/infrastructure/rappture source code: rappture/examples/app-fermi

What is the interface? disp('Enter the Fermi level (e. V): '); Ef = input(' Ef = '); number disp('Enter the temperature (K): '); T = input(' T = '); k. T = 8. 61734 e-5 * T; Emin = Ef - 10*k. T; Emax = Ef + 10*k. T; number physics E = linspace(Emin, Emax, 200); f = 1. 0. / (1. 0 + exp((E - Ef)/k. T)); fid = fopen('out. dat', 'w'); fprintf(fid, 'FERMI-DIRAC FUNCTION F 1/2nn'); fprintf(fid, ‘f 1/2 Energy (e. V)n'); fprintf(fid, '------n'); fprintf(fid, '%12 gn', [f; E]); fclose(fid); quit; curve

Build the interface: Temperature input Define this input

Build the interface: Ef input Define this input

Build the interface: Curve output Define this output

Build the interface: Use MATLAB/Octave Define tool info

Add physics to the generated code Generated script: main. m … % get input value for input. number(temperature) and convert to K str = rp. Lib. Get. String(io, 'input. number(temperature). current'); [temperature, err] = rp. Units. Convert. Dbl(str, 'K'); % get input value for input. number(Ef) and convert to e. V str = rp. Lib. Get. String(io, 'input. number(Ef). current'); [Ef, err] = rp. Units. Convert. Dbl(str, 'e. V'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%% k. T = 8. 61734 e-5 * T; % Add your code here for the main body of your program Emin = Ef - 10*k. T; %%%%%%%%%%%%%%%%%%%%%%%%%%%%% physics Emax = Ef + 10*k. T; E = linspace(Emin, Emax, 200); %%%%%%%%%%%%%%%%%%%%%%%%%%%%% f to = 1. 0. / (1. 0 + exp((E - Ef)/k. T)); % Save output values back Rappture %%%%%%%%%%%%%%%%%%%%%%%%%%%%% % save output value for output. curve(f 12) % this assumes a vector 'x' and a vector 'y' xydata = [x; y]; str = sprintf('%12 gn', xydata); rp. Lib. Put. String(io, 'output. curve(f 12). component. xy', str, 0); …

Add physics to the generated code Final script: main. m … % get input value for input. number(temperature) and convert to K str = rp. Lib. Get. String(io, 'input. number(temperature). current'); [temperature, err] = rp. Units. Convert. Dbl(str, 'K'); % get input value for input. number(Ef) and convert to e. V str = rp. Lib. Get. String(io, 'input. number(Ef). current'); [Ef, err] = rp. Units. Convert. Dbl(str, 'e. V'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%% k. T = 8. 61734 e-5 * temperature; Emin = Ef - 10*k. T; Emax = Ef + 10*k. T; E = linspace(Emin, Emax, 200); f = 1. 0. / (1. 0 + exp((E - Ef)/k. T)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%% % save output value for output. curve(f 12) % this assumes a vector 'x' and a vector 'y' xydata = [f; E]; str = sprintf('%12 gn', xydata); rp. Lib. Put. String(io, 'output. curve(f 12). component. xy', str, 0); …

Running the code Builder Runner <? xml version="1. 0"? > <run> … <output> <curve id="f 12"> … <component> <xy> 0. 999955 2. 33365 0. 99995 2. 33431 <XML> 0. 999944 2. 33498 … </output> </run> tool. xml <XML> driver 1827. xml k. T = 8. 61734 e-5 * temperature; Emin = Ef - 10*k. T; Emax = Ef + 10*k. T; physics E = linspace(Emin, Emax, 200); f = 1. 0. / (1. 0 + exp((E - Ef)/k. T)); <XML> run 12703129102. xml

Debugging If something goes wrong, MATLAB goes into “debug” mode: Waiting for you to type a MATLAB command Click Abort instead Run it by hand: $ ls driver 1529. xml fermi. m tool. xml $ use rappture $ matlab –r infile=’driver 1529. xml’, main
- Slides: 11