File: PETSCVIEWERMATLAB.html

package info (click to toggle)
petsc 3.4.2.dfsg1-8.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 129,104 kB
  • ctags: 516,422
  • sloc: ansic: 395,939; cpp: 47,201; python: 34,788; makefile: 17,193; fortran: 16,251; f90: 1,592; objc: 954; sh: 822; xml: 621; java: 381; lisp: 293; csh: 241
file content (63 lines) | stat: -rw-r--r-- 4,333 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML3.2 EN">
<HTML>
<HEAD> <link rel="canonical" href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Viewer/PETSCVIEWERMATLAB.html" />
<META NAME="GENERATOR" CONTENT="DOCTEXT">
<TITLE>PETSCVIEWERMATLAB</TITLE>
</HEAD>
<BODY BGCOLOR="FFFFFF">
   <div id="version" align=right><b>petsc-3.4.2 2013-07-02</b></div>
<A NAME="PETSCVIEWERMATLAB"><H1>PETSCVIEWERMATLAB</H1></A>
A viewer that saves the variables into a MATLAB .mat file that may be read into MATLAB with load('filename'). 
<P>
Note: Currently can only save PETSc vectors to .mat files, not matrices (use the PETSCVIEWERBINARY and
${PETSC_DIR}/bin/matlab/<A HREF="../Sys/PetscBinaryRead.html#PetscBinaryRead">PetscBinaryRead</A>.m to read matrices into matlab).
<P>
For parallel vectors obtained with <A HREF="../DM/DMCreateGlobalVector.html#DMCreateGlobalVector">DMCreateGlobalVector</A>() or <A HREF="../DM/DMGetGlobalVector.html#DMGetGlobalVector">DMGetGlobalVector</A>() the vectors are saved to
the .mat file in natural ordering. You can use <A HREF="../DM/DMView.html#DMView">DMView</A>() to save the <A HREF="../DM/DMDA.html#DMDA">DMDA</A> information to the .mat file
the fields in the MATLAB loaded da variable give the array dimensions so you can reshape the MATLAB
vector to the same multidimensional shape as it had in PETSc for plotting etc. For example,
<P>
<pre>
            In your PETSc C/C++ code (assuming a two dimensional <A HREF="../DM/DMDA.html#DMDA">DMDA</A> with one degree of freedom per node)
</pre>
<pre>
               <A HREF="../Sys/PetscObjectSetName.html#PetscObjectSetName">PetscObjectSetName</A>((<A HREF="../Sys/PetscObject.html#PetscObject">PetscObject</A>)x,"x");
</pre>
<pre>
               <A HREF="../Vec/VecView.html#VecView">VecView</A>(x,<A HREF="../Viewer/PETSC_VIEWER_MATLAB_WORLD.html#PETSC_VIEWER_MATLAB_WORLD">PETSC_VIEWER_MATLAB_WORLD</A>);
</pre>
<pre>
               <A HREF="../Sys/PetscObjectSetName.html#PetscObjectSetName">PetscObjectSetName</A>((<A HREF="../Sys/PetscObject.html#PetscObject">PetscObject</A>)da,"da");
</pre>
<pre>
               <A HREF="../DM/DMView.html#DMView">DMView</A>(x,<A HREF="../Viewer/PETSC_VIEWER_MATLAB_WORLD.html#PETSC_VIEWER_MATLAB_WORLD">PETSC_VIEWER_MATLAB_WORLD</A>);
</pre>
<pre>
            Then from MATLAB
</pre>
<pre>
               load('matlaboutput.mat')   % matlaboutput.mat is the default filename
</pre>
<pre>
               xnew = zeros(da.n,da.m);
</pre>
<pre>
               xnew(:) = x;    % reshape one dimensional vector back to two dimensions
</pre>
<P>
If you wish to put the same variable into the .mat file several times you need to give it a new
name before each call to view.
<P>
Use <A HREF="../Viewer/PetscViewerMatlabPutArray.html#PetscViewerMatlabPutArray">PetscViewerMatlabPutArray</A>() to just put an array of doubles into the .mat file
<P>
<H3><FONT COLOR="#CC3333">See Also</FONT></H3>
  <A HREF="../Viewer/PETSC_VIEWER_MATLAB_.html#PETSC_VIEWER_MATLAB_">PETSC_VIEWER_MATLAB_</A>(),<A HREF="../Viewer/PETSC_VIEWER_MATLAB_SELF.html#PETSC_VIEWER_MATLAB_SELF">PETSC_VIEWER_MATLAB_SELF</A>(), <A HREF="../Viewer/PETSC_VIEWER_MATLAB_WORLD.html#PETSC_VIEWER_MATLAB_WORLD">PETSC_VIEWER_MATLAB_WORLD</A>(),<A HREF="../Viewer/PetscViewerCreate.html#PetscViewerCreate">PetscViewerCreate</A>(),
<BR><A HREF="../Viewer/PetscViewerMatlabOpen.html#PetscViewerMatlabOpen">PetscViewerMatlabOpen</A>(), <A HREF="../Vec/VecView.html#VecView">VecView</A>(), <A HREF="../DM/DMView.html#DMView">DMView</A>(), <A HREF="../Viewer/PetscViewerMatlabPutArray.html#PetscViewerMatlabPutArray">PetscViewerMatlabPutArray</A>(), PETSCVIEWERBINARY,
PETSC_ASCII_VIEWER, <A HREF="../Viewer/PetscViewerFileSetName.html#PetscViewerFileSetName">PetscViewerFileSetName</A>(), <A HREF="../Viewer/PetscViewerFileSetMode.html#PetscViewerFileSetMode">PetscViewerFileSetMode</A>()
<P>
<P><B><P><B><FONT COLOR="#CC3333">Level:</FONT></B>intermediate
<BR><FONT COLOR="#CC3333">Location:</FONT></B><A HREF="../../../src/sys/classes/viewer/impls/matlab/vmatlab.c.html#PETSCVIEWERMATLAB">src/sys/classes/viewer/impls/matlab/vmatlab.c</A>
<BR><A HREF="./index.html">Index of all Viewer routines</A>
<BR><A HREF="../../index.html">Table of Contents for all manual pages</A>
<BR><A HREF="../singleindex.html">Index of all manual pages</A>
</BODY></HTML>