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

Slides:



Advertisements
Similar presentations
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Advertisements

StatLab Workshop Yale University Maximiliano Appendino, Economics October 18 th, 2013.
Introduction to MATLAB The language of Technical Computing.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Matrix Manipulation and 2D Plotting
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Flow Charts, Loop Structures
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
Soft Computing 1 Matlab Tutorial Kai Goebel, Bill Cheetham RPI/GE CRD
Graphics in MATLAB Week 15 – 5/5/09 Kate Musgrave
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Digital Image Processing Lecture3: Introduction to MATLAB.
259 Lecture 15 Introduction to MATLAB. 2 What is MATLAB?  MATLAB, which stands for “MATrix LABoratory” is a high- performance language for technical.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
Matlab tutorial course Lesson 5: Loading and writing data, producing visual output
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
TCL/Tk Based Environment for Mixed-Signal Circuit Design System Description Software Architecture Examples Future Directions Summary.
Math 15 Lecture 10 University of California, Merced Scilab Programming – No. 1.
GUI development with Matlab: GUI Front Panel Components 1 GUI front panel components In this section, we will look at -GUI front panel components -Programming.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
Eng Ship Structures 1 Introduction to Matlab.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Flow Control and Functions ● Script files ● If's and For's ● Basics of writing functions ● Checking input arguments ● Variable input arguments ● Output.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
MEGN 537 – Probabilistic Biomechanics Applying the AMV Method with a Finite Element Model Anthony J Petrella, PhD.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Scientific Computing Introduction to Matlab Programming.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Introduction to MATLAB adapted from Dr. Rolf Lakaemper.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Introduction to Matlab & Data Analysis 2015 In this tutorial we will: Build a practical application using GUIDE Learn more about graphical user interface.
Introduction to MATLAB 7 MATLAB Programming for Engineer Hassan Migdadi Spring 2013.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2012.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
An Introduction to Programming in Matlab Emily Blumenthal
Beginning Programming for Engineers Animation. Special matrix functions >> clear >> ones(2,3) >> zeros(3,5) >> ones(2) >> zeros(3) >> eye(4) >> magic(4)
MAE 421 Matlab review Prof. Mark Glauser Created by: David Marr.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Reading and Writing Image Files
Introduction to Matlab
Computer Application in Engineering Design
Lecture 25: Exploring data
Matlab Workshop 9/22/2018.
Use of Mathematics using Technology (Maltlab)
MATLAB Tutorial Dr. David W. Graham.
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
MATLAB How to use (using M-files)
Digital Image Processing
Introduction to Advanced UNIX
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Presentation transcript:

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? 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!

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

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

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

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 …

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...} …

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(... );

Example  CSMP

Finite Element Mesh m Finite Elements (here m = 8) n Nodes (here n = 9)

Generated Output Files 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

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

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

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...

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

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' );

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) )

Output  MATLAB

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”

Useful Links to MATLAB Always try Help Manual of MATLAB = easy MATLAB “homepage” …/products/featured/videos/ …/academia/student_center/tutorials/launchpad.html Introduction, Tutorials, Documentation, Examples, etc. Some useful tutorials Octave (free alternative, mostly compatible with MATLAB)

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

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

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

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