Mercurial > fem-fenics-eugenio
annotate inst/private/generate_fun.m @ 268:61830a4f9ab9
Improve formatting
author | Eugenio Gianniti <eugenio.gianniti@mail.polimi.it> |
---|---|
date | Thu, 14 Aug 2014 12:26:55 +0200 |
parents | 5e9b5bbdc56b |
children |
rev | line source |
---|---|
152
1dbe146bff03
Update license to gpl v3
gedeone-octave <marcovass89@hotmail.it>
parents:
124
diff
changeset
|
1 ## Copyright (C) 2013 Marco Vassallo <gedeone-octave@users.sourceforge.net> |
1dbe146bff03
Update license to gpl v3
gedeone-octave <marcovass89@hotmail.it>
parents:
124
diff
changeset
|
2 ## |
124
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
3 ## This program is free software; you can redistribute it and/or modify it under |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
4 ## the terms of the GNU General Public License as published by the Free Software |
152
1dbe146bff03
Update license to gpl v3
gedeone-octave <marcovass89@hotmail.it>
parents:
124
diff
changeset
|
5 ## Foundation; either version 3 of the License, or (at your option) any later |
124
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
6 ## version. |
152
1dbe146bff03
Update license to gpl v3
gedeone-octave <marcovass89@hotmail.it>
parents:
124
diff
changeset
|
7 ## |
124
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
8 ## This program is distributed in the hope that it will be useful, but WITHOUT |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
11 ## details. |
152
1dbe146bff03
Update license to gpl v3
gedeone-octave <marcovass89@hotmail.it>
parents:
124
diff
changeset
|
12 ## |
124
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
13 ## You should have received a copy of the GNU General Public License along with |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
14 ## this program; if not, see <http://www.gnu.org/licenses/>. |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
15 |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
16 |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
17 ## -*- texinfo -*- |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
18 ## function for internal usage only |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
109
diff
changeset
|
19 ## @end deftypefn |
268
61830a4f9ab9
Improve formatting
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
253
diff
changeset
|
20 |
109
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
21 function output = generate_fun (ufl_name) |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
22 |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
23 STRING ="\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
24 #include ""@@UFL_NAME@@.h""\n\ |
154
262c9d7bda1c
Call the header file from the /include directories
gedeone-octave <marcovass89@hotmail.it>
parents:
153
diff
changeset
|
25 #include <fem-fenics/mesh.h>\n\ |
262c9d7bda1c
Call the header file from the /include directories
gedeone-octave <marcovass89@hotmail.it>
parents:
153
diff
changeset
|
26 #include <fem-fenics/form.h>\n\ |
262c9d7bda1c
Call the header file from the /include directories
gedeone-octave <marcovass89@hotmail.it>
parents:
153
diff
changeset
|
27 #include <fem-fenics/coefficient.h>\n\ |
262c9d7bda1c
Call the header file from the /include directories
gedeone-octave <marcovass89@hotmail.it>
parents:
153
diff
changeset
|
28 #include <fem-fenics/function.h>\n\ |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
155
diff
changeset
|
29 #include <fem-fenics/dolfin_compat.h>\n\ |
109
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
30 \n\ |
268
61830a4f9ab9
Improve formatting
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
253
diff
changeset
|
31 DEFUN_DLD (@@UFL_NAME@@_Functional, args, ,\ |
61830a4f9ab9
Improve formatting
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
253
diff
changeset
|
32 ""A = fem_rhs_@@UFL_NAME@@ (FUNCTIONAL SPACE, COEFF)"")\n\ |
109
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
33 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
34 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
35 int nargin = args.length ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
36 octave_value retval;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
37 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
38 if (nargin < 1)\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
39 print_usage ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
40 else\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
41 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
42 if (! mesh_type_loaded)\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
43 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
44 mesh::register_type ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
45 mesh_type_loaded = true;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
46 mlock ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
47 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
48 if (! form_type_loaded)\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
49 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
50 form::register_type ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
51 form_type_loaded = true;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
52 mlock ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
53 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
54 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
55 if (args(0).type_id () == mesh::static_type_id ())\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
56 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
57 const mesh & msho\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
58 = static_cast<const mesh&> (args(0).get_rep ());\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
59 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
60 if (! error_state)\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
61 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
62 const dolfin::Mesh & mesh = msho.get_msh ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
63 @@UFL_NAME@@::Functional M (mesh);\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
64 std::size_t ncoef = M.num_coefficients (), nc = 0;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
65 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
66 if (! coefficient_type_loaded)\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
67 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
68 coefficient::register_type ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
69 coefficient_type_loaded = true;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
70 mlock ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
71 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
72 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
73 if (! function_type_loaded)\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
74 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
75 function::register_type ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
76 function_type_loaded = true;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
77 mlock ();\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
78 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
79 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
80 for (std::size_t i = 1; i < nargin; ++i)\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
81 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
82 if (args(i).type_id () == coefficient::static_type_id ())\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
83 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
84 const coefficient & cf\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
85 = static_cast <const coefficient&> (args(i).get_rep ());\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
86 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
87 std::size_t n = M.coefficient_number (cf.get_str ());\n\ |
253
5e9b5bbdc56b
Support both DOLFIN 1.3.0 and 1.4.0
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
155
diff
changeset
|
88 const SHARED_PTR <const expression> & pexp = cf.get_expr ();\n\ |
109
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
89 M.set_coefficient (n, pexp);\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
90 ++nc;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
91 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
92 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
93 if (args(i).type_id () == function::static_type_id ())\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
94 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
95 const function & fun\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
96 = static_cast <const function&> (args(i).get_rep ());\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
97 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
98 std::size_t n = M.coefficient_number (fun.get_str ());\n\ |
268
61830a4f9ab9
Improve formatting
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
253
diff
changeset
|
99 const SHARED_PTR <const dolfin::Function> & pfun =\ |
61830a4f9ab9
Improve formatting
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
253
diff
changeset
|
100 fun.get_pfun ();\n\ |
109
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
101 M.set_coefficient (n, pfun);\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
102 ++nc;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
103 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
104 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
105 \n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
106 if (nc != ncoef)\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
107 error (""Wrong number of coefficient"");\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
108 else\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
109 {\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
110 retval = new form (M);\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
111 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
112 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
113 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
114 }\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
115 return retval;\n\ |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
116 }"; |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
117 |
268
61830a4f9ab9
Improve formatting
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
253
diff
changeset
|
118 STRING = strrep (STRING, "@@UFL_NAME@@", ufl_name); |
109
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
119 |
268
61830a4f9ab9
Improve formatting
Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
parents:
253
diff
changeset
|
120 fid = fopen (sprintf ("%s_Functional.cc", ufl_name), "w"); |
109
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
121 if (fid >= 0) |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
122 fputs (fid, STRING); |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
123 output = fclose (fid); |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
124 else |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
125 error ("cannot open file"); |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
126 output = 1; |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
127 endif |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
128 |
50753c3cb0b6
New function for dealing with form of rank 0.
gedeone-octave <marcovass89@hotmail.it>
parents:
diff
changeset
|
129 endfunction |