Presentation is loading. Please wait.

Presentation is loading. Please wait.

Post-Processing Output with MATLAB Claudia Fricke Institute of Petroleum Engineering, Heriot Watt University.

Similar presentations


Presentation on theme: "Post-Processing Output with MATLAB Claudia Fricke Institute of Petroleum Engineering, Heriot Watt University."— Presentation transcript:

1 Post-Processing Output with MATLAB Claudia Fricke Institute 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? AdvantagesDisadvantages easy to manipulate data analyse and compare data from various calculations by subsequent editing automated batch processing export data in high quality lots and lots of plot options possibility to call MATLAB from C code – lots of other interfaces LOTS of possibilities sometimes extensive preparations so far 3D not implemented in CSMP!

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

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

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

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

8 Export Values for each Time Step … 5.Main calculation loop over different time steps while ( 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... 5.Main calculation loop over different time steps 6.Final output write2DMatlabFile( supergroup, name of output file, CSMP variable, time step := final time ) writeSavedTimeStepsFile(... );

10 Example  CSMP

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

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

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

14 How to read data into MATLAB? variable = load (file name) 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 Command load n x 2 matrix variable (:,1) returns 1 st column of matrix n rowsm rowsm x 3 matrix

15 How to plot in 1D? 1D Command plot(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 ); Stack of Images  Animation (e.g with Movie Maker) compose file name (loop counter j ) ['concentration', num2str(j),'.jpg'] Command print Example print( '-r200', '-djpeg', 'concentration.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 with Batch Function 1.Create basic plot 2.Change various plot options with Property Editor 3.Generate m-Code Function 4.Call this function and pass in new data from 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 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

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

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

25 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); % 1 st column p_x_t_CSMP = u(:,2); % 2 nd 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

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


Download ppt "Post-Processing Output with MATLAB Claudia Fricke Institute of Petroleum Engineering, Heriot Watt University."

Similar presentations


Ads by Google