Mercurial > fem-fenics-eugenio
annotate src/plot_mesh.cc @ 253:5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
* src/dolfin_compat.h: use a macro to set the correct shared_ptr (std or boost)
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Tue, 29 Jul 2014 18:05:56 +0200 |
parents | 66071811eef8 |
children |
rev | line source |
---|---|
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
1 /* |
151 | 2 Copyright (C) 2013 Marco Vassallo <gedeone-octave@users.sourceforge.net> |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
3 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
4 This program is free software; you can redistribute it and/or modify it under |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
5 the terms of the GNU General Public License as published by the Free Software |
151 | 6 Foundation; either version 3 of the License, or (at your option) any later |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
7 version. |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
8 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
12 details. |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
13 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
14 You should have received a copy of the GNU General Public License along with |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
15 this program; if not, see <http://www.gnu.org/licenses/>. |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
16 */ |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
17 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
18 #include "function.h" |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
19 #include "mesh.h" |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
20 #include "Plot_2d.h" |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
21 #include "Plot_3d.h" |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
22 #include "dolfin_compat.h" |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
23 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
24 DEFUN_DLD (plot, args, , "-*- texinfo -*-\n\ |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
25 @deftypefn {Function File} \ |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
26 plot (@var{Mesh}, @var{Nodal_Values}(OPTIONAL))\n\ |
184
66071811eef8
Improve the documentation for the pkg releae.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
27 Plot a Mesh. \n\ |
66071811eef8
Improve the documentation for the pkg releae.
gedeone-octave <marcovass89@hotmail.it>
parents:
173
diff
changeset
|
28 The input parameter is the Mesh and optionally also a vector representing \ |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
29 the values of a function at each node.\n\ |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
30 @seealso{Mesh, save}\n\ |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
31 @end deftypefn") |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
32 { |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
33 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
34 int nargin = args.length (); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
35 octave_value retval; |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
36 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
37 if (nargin < 1 || nargin > 2) |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
38 print_usage (); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
39 else |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
40 { |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
41 if (! mesh_type_loaded) |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
42 { |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
43 mesh::register_type (); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
44 mesh_type_loaded = true; |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
45 mlock (); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
46 } |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
47 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
48 if (args(0).type_id () == mesh::static_type_id ()) |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
49 { |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
50 const mesh & msho = static_cast<const mesh&> (args(0).get_rep ()); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
51 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
52 if (nargin == 1) |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
53 { |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
54 if (!error_state) |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
55 { |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
56 const SHARED_PTR <const dolfin::Mesh> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
57 & mshd = msho.get_pmsh (); |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
58 dolfin::plot (*mshd); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
59 dolfin::interactive (); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
60 retval = 0; |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
61 } |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
62 } |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
63 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
64 else if (nargin == 2) |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
65 { |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
66 Array <double> myu = args(1).array_value (); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
67 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
68 if (!error_state) |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
69 { |
129
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
70 const dolfin::Mesh & mshd = msho.get_msh (); |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
71 SHARED_PTR <const dolfin::FunctionSpace> V; |
129
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
72 uint D = mshd.topology ().dim (); |
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
73 if (D == 2) |
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
74 { |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
75 SHARED_PTR <const dolfin::FunctionSpace> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
76 Vt (new Plot_2d::FunctionSpace (mshd)); |
129
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
77 V = Vt; |
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
78 } |
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
79 |
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
80 else if(D == 3) |
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
81 { |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
82 SHARED_PTR <const dolfin::FunctionSpace> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
83 Vt (new Plot_3d::FunctionSpace (mshd)); |
129
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
84 V = Vt; |
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
85 } |
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
86 |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
87 else |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
88 error ("Plot: The size of the mesh must be 2 or 3"); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
89 |
129
d003a8d6ac58
Fix error made in the previous commit.
gedeone-octave <marcovass89@hotmail.it>
parents:
128
diff
changeset
|
90 |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
91 if (V->dim () != myu.length ()) |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
92 error ("Plot: The size of the functional space\ |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
93 and the size of the vector must agree"); |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
94 else |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
95 { |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
96 #ifdef LATEST_DOLFIN |
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
97 dolfin::Vector du (MPI_COMM_WORLD, myu.length ()); |
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
98 #else |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
99 dolfin::Vector du(myu.length ()); |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
100 #endif |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
101 for (std::size_t i = 0; i < myu.length (); ++i) |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
102 du.setitem (i, myu(i)); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
103 |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
104 SHARED_PTR <dolfin::Vector> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
105 uu (new dolfin::Vector(du)); |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
106 |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
184
diff
changeset
|
107 SHARED_PTR <const dolfin::Function> |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
108 u (new dolfin::Function(V, uu)); |
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
109 |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
110 dolfin::plot (*u); |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
111 dolfin::interactive (); |
173
9e944b0d0fc8
Some Formatting improvements (?)
gedeone-octave <marcovass89@hotmail.it>
parents:
151
diff
changeset
|
112 |
128
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
113 retval = 0; |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
114 } |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
115 } |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
116 } |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
117 } |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
118 |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
119 } |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
120 return retval; |
d3c29e38e5d2
New naming convention adopted and Polymorphism for plot and save.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
121 } |