1 / 26

Post-Processing Output with MATLAB

Post-Processing Output with MATLAB. Claudia Fricke Institute of Petroleum Engineering, Heriot Watt University. Overview. How to create MATLAB Output with CSMP? How to use the CSMP Output with MATLAB?. Why MATLAB – not VTK?. General CSMP++ Workflow. Load libraries

knox
Download Presentation

Post-Processing Output with MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Post-Processing Output with MATLAB Claudia FrickeInstitute of Petroleum Engineering, Heriot Watt University

  2. Overview • How to create MATLAB Output with CSMP? • How to use the CSMP Output with MATLAB?

  3. Why MATLAB – not VTK?

  4. General CSMP++ Workflow • Load libraries • Generate SuperGroup (from mesh) and set properties, boundary and start values • Set up FE and FV algorithms • Output initial values • Main calculation loop over different time steps • Final output CSMP or MATLAB Code:essential commands in red or green

  5. Include Header-File • Load libraries #include "CSP_MatlabInterface.h" *) • Generate supergroup (from mesh) and set properties, boundary and start values • … *) in ...\CSMP\source_code\interfaces

  6. name of supergroup name of output files CSMP output variable current time step default output filename current time step CSP_MatlabInterface.h value of CSMP variable to file void write2DMatlabFile(SuperGroup<csp_float,2>& sg, const char* name,const char* variable,long step ); void write2DMatlabFile(SuperGroup<csp_float,2>& sg,const char* groupname,const char* name,const char* variable,long step ); save current time step in file void writeSavedTimeStepsFile( long step, const char* name="saved_time_steps.txt" ); restriction to sub-group extract 1D data from 2D void extractAndWrite1DVariableProfileAlongX( ... ); void extractAndWrite1DVariableProfileAlongY( ... );

  7. Export Initial Values … • Set up FE and FV algorithms • Output initial values write2DMatlabFile (supergroup, name of output file,CSMP variable,time step := start time )writeSavedTimeStepsFile (time step := start time , "filename" ); • Main calculation loop over different time steps …

  8. Export Values for each Time Step … • Main calculation loop over different time stepswhile ( global_time < max_time ) { ...//calculate time step FE / time step FV...write2DMatlabFile(supergroup, name of output file, CSMP variable,time step := current time )writeSavedTimeStepsFile( ... ); //increment global_time ... } …

  9. Export Final Values ... • Main calculation loop over different time steps • Final output write2DMatlabFile(supergroup, name of output file,CSMP variable,time step := final time ) writeSavedTimeStepsFile( ... );

  10. Example  CSMP

  11. 2 5 1 m Finite Elements(here m = 8) n Nodes(here n = 9) 3 1 4 2 4 6 3 8 6 7 5 7 8 9 Finite Element Mesh

  12. 2 1 1 1 3 Generated Output Files one value for each node one file for each time step time steps in extra file t rows x-y-coordinates of nodes nrows t files m rows nrows

  13. Part 2 And now? How to use the CSMP Output with MATLAB?

  14. How to read data into MATLAB? variable = load (file name) Command load • returns matrix variable • each matrix column represents a column from the former data table • each matrix row represents one row from the former data table nrows m rows n x 2 matrix m x 3 matrix variable (:,1)returns 1st column of matrix

  15. How to plot in 1D? 1D Commandplot( nodes on x axis, calculated y-values, plot options) • Plot Options: • multiple plots • plot title • legend • axes markings • change colours • add coordinates grid • size of text • ...

  16. How to plot in 2D? 2D Commands surface plot (for triangular data) trisurf( mx3 matrix of triangular elements, n x-values of nodes, n y-values of nodes, calculated z-values, options) Mesh Plot trimesh ( matrix of triangular elements, x coordinates of nodes, y coordinates of nodes, options) one plot command per time step for animation

  17. How to save plot as image file? print( resolution, file type, file name ); Command print Example print( '-r200', '-djpeg', 'concentration.jpg' ); Stack of Images  Animation (e.g with Movie Maker) compose file name (loop counter j) ['concentration', num2str(j),'.jpg']

  18. 2D Animation Example % start values time_steps = load ('time_steps.txt'); % 1 column j = 1; %loop counter last_time_step = length(time_steps); % load mesh no = load ( 'nodes.txt' ); el = load ( 'elements.txt' ); % loop while j <= last_time_step u = load ( ['concentration', num2str(j),'.txt'] ); trisurf ( el, no(:,1), no(:,2), u, possible options) view ( 2 ) % top view ... % more plot options % save single jpg's print( '-r200', '-djpeg', ['concentration', num2str(j),'.jpg'] ); j = j + 1 ; % time step increment end % see a plot of just the triangles with trimesh ( t, no(:,1), no(:,2) ) % start values time_steps = load ('time_steps.txt'); % 1 column j = 1; %loop counter last_time_step = length(time_steps); % load mesh no = load ( 'nodes.txt' ); el = load ( 'elements.txt' ); % loop while j <= last_time_step u = load ( ['concentration', num2str(j),'.txt'] ); trisurf ( el, no(:,1), no(:,2), u, possible options) view ( 2 ) % top view ... % more plot options % save single jpg's print( '-r200', '-djpeg', ['concentration', num2str(j),'.jpg'] ); j = j + 1 ; % time step increment end % see a plot of just the triangles with trimesh ( t, no(:,1), no(:,2) )

  19. Output  MATLAB

  20. Change Plot Options withBatch Function • Create basic plot • Change various plot options with Property Editor • Generate m-Code Function • Call this function and pass in new datafrom other m-File in main loop • in detail see Youtube video“MATLAB Plot: Interactively Creating Plots in MATLAB”http://www.youtube.com/watch?v=GJVvBqR8Mws

  21. Useful Links to MATLAB Always try Help Manual of MATLAB = easy  MATLAB “homepage” http://www.mathworks.com …/products/featured/videos/ …/academia/student_center/tutorials/launchpad.html Introduction, Tutorials, Documentation, Examples, etc. Some useful tutorials http://www.youtube.com/user/MATLAB Octave (free alternative, mostly compatible with MATLAB) http://www.octave.org/

  22. 1D Output Extract data from 2D void extractAndWrite1DVariableProfileAlongX( SuperGroup<csp_float,2>& sg, csp_float distance, const char* name, const char* variable,long step ); void extractAndWrite1DVariableProfileAlongY(... );

  23. 1D Post-Processing Plot extractAndWrite1DVariableProfileAlongX(..) • 1-dimensional advection & diffusion equation • compare different time stepping schemes • plot 4 results in one figure with MATLAB

  24. 1D Animation Example % start values obs_function = 'fluid_pressure'; time_steps = load ('time_steps.txt'); % 1 column step = time_steps(2) - time_steps(1); max_time = time_steps(length(time_steps)); t = time_steps(1); while t <= max_time % read CSMP data u = load ( [obs_function, num2str(t),'.txt'] ); %2 columns x = u(:,1); % 1st column p_x_t_CSMP = u(:,2); % 2nd column % calculate analytical solution p_x_t_ana = ... %plot figure(1) plot( x, p_x_t_ana, x, p_x_t_CSMP) ... % more plot options t = t + step; end

  25. MATLAB Terms • Environment: • Command Window • Workspace • Current Directory • Command History • Programming • m-code • m-file • script vs. function • plot, figure, surface plot, ...

More Related