Mercurial > fem-fenics-eugenio
annotate inst/generate_rhs.m @ 124:2191111a1cad
Maint: add copyright notice
author | gedeone-octave <marcovass89@hotmail.it> |
---|---|
date | Mon, 02 Sep 2013 23:51:28 +0200 |
parents | 9e7035e0494b |
children | 1dbe146bff03 |
rev | line source |
---|---|
124
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
1 ## Copyright (C) 2013 Marco Vassallo |
68
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
2 |
124
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
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:
93
diff
changeset
|
4 ## the terms of the GNU General Public License as published by the Free Software |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
5 ## Foundation; either version 2 of the License, or (at your option) any later |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
6 ## version. |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
7 |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
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:
93
diff
changeset
|
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
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:
93
diff
changeset
|
11 ## details. |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
12 |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
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:
93
diff
changeset
|
14 ## this program; if not, see <http://www.gnu.org/licenses/>. |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
15 |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
16 |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
17 ## -*- texinfo -*- |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
18 ## function for internal usage only |
2191111a1cad
Maint: add copyright notice
gedeone-octave <marcovass89@hotmail.it>
parents:
93
diff
changeset
|
19 ## @end deftypefn |
68
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
20 function output = generate_rhs (ufl_name) |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
21 |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
22 STRING ="\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
23 #include ""@@UFL_NAME@@.h""\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
24 #include ""functionspace.h""\n\ |
93
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
25 #include ""form.h""\n\ |
68
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
26 #include ""coefficient.h""\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
27 #include ""function.h""\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
28 \n\ |
93
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
29 DEFUN_DLD (@@UFL_NAME@@_BilinearForm, args, , ""A = fem_rhs_@@UFL_NAME@@ (FUNCTIONAL SPACE, COEFF)"")\n\ |
68
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
30 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
31 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
32 int nargin = args.length ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
33 octave_value retval;\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
34 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
35 if (nargin < 1)\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
36 print_usage ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
37 else\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
38 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
39 if (! functionspace_type_loaded)\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
40 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
41 functionspace::register_type ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
42 functionspace_type_loaded = true;\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
43 mlock ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
44 }\n\ |
93
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
45 if (! form_type_loaded)\n\ |
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
46 {\n\ |
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
47 form::register_type ();\n\ |
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
48 form_type_loaded = true;\n\ |
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
49 mlock ();\n\ |
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
50 }\n\ |
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
51 \n\ |
68
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
52 if (args(0).type_id () == functionspace::static_type_id ())\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
53 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
54 const functionspace & fspo\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
55 = static_cast<const functionspace&> (args(0).get_rep ());\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
56 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
57 if (! error_state)\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
58 {\n\ |
93
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
59 const dolfin::FunctionSpace & V = fspo.get_fsp ();\n\ |
68
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
60 @@UFL_NAME@@::BilinearForm a (V, V);\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
61 std::size_t ncoef = a.num_coefficients (), nc = 0;\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
62 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
63 if (! coefficient_type_loaded)\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
64 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
65 coefficient::register_type ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
66 coefficient_type_loaded = true;\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
67 mlock ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
68 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
69 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
70 if (! function_type_loaded)\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
71 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
72 function::register_type ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
73 function_type_loaded = true;\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
74 mlock ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
75 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
76 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
77 for (std::size_t i = 1; i < nargin; ++i)\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
78 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
79 if (args(i).type_id () == coefficient::static_type_id ())\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
80 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
81 const coefficient & cf\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
82 = static_cast <const coefficient&> (args(i).get_rep ());\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
83 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
84 std::size_t n = a.coefficient_number (cf.get_str ());\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
85 const boost::shared_ptr<const expression> & pexp = cf.get_expr ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
86 a.set_coefficient (n, pexp);\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
87 ++nc;\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
88 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
89 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
90 if (args(i).type_id () == function::static_type_id ())\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
91 {\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
92 const function & fun\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
93 = static_cast <const function&> (args(i).get_rep ());\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
94 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
95 std::size_t n = a.coefficient_number (fun.get_str ());\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
96 const boost::shared_ptr<const dolfin::Function> & pfun = fun.get_pfun ();\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
97 a.set_coefficient (n, pfun);\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
98 ++nc;\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
99 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
100 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
101 \n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
102 if (nc != ncoef)\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
103 error (""Wrong number of coefficient"");\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
104 else\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
105 {\n\ |
93
9e7035e0494b
Return an object of type form.
gedeone-octave <marcovass89@hotmail.it>
parents:
82
diff
changeset
|
106 retval = new form (a);\n\ |
68
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
107 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
108 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
109 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
110 }\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
111 return retval;\n\ |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
112 }"; |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
113 |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
114 STRING = strrep (STRING, "@@UFL_NAME@@", ufl_name); |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
115 |
82
5a4371f45fc4
Create the corresponding function following new naming convention.
gedeone-octave <marcovass89@hotmail.it>
parents:
74
diff
changeset
|
116 fid = fopen (sprintf ("%s_BilinearForm.cc", ufl_name), 'w'); |
68
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
117 if (fid >= 0) |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
118 fputs (fid, STRING); |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
119 output = fclose (fid); |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
120 else |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
121 error ("cannot open file"); |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
122 output = 1; |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
123 endif |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
124 |
4ef8dbafcdfc
New octave script for creation of function on the fly
gedeone-octave <marco.vassallo@outlook.com>
parents:
diff
changeset
|
125 endfunction |