[1dbe14]: inst / generate_rhs.m Maximize Restore History

Download this file

generate_rhs.m    126 lines (119 with data), 4.1 kB

  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
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
## Copyright (C) 2013 Marco Vassallo <gedeone-octave@users.sourceforge.net>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## function for internal usage only
## @end deftypefn
function output = generate_rhs (ufl_name)
STRING ="\n\
#include ""@@UFL_NAME@@.h""\n\
#include ""functionspace.h""\n\
#include ""form.h""\n\
#include ""coefficient.h""\n\
#include ""function.h""\n\
\n\
DEFUN_DLD (@@UFL_NAME@@_BilinearForm, args, , ""A = fem_rhs_@@UFL_NAME@@ (FUNCTIONAL SPACE, COEFF)"")\n\
{\n\
\n\
int nargin = args.length ();\n\
octave_value retval;\n\
\n\
if (nargin < 1)\n\
print_usage ();\n\
else\n\
{\n\
if (! functionspace_type_loaded)\n\
{\n\
functionspace::register_type ();\n\
functionspace_type_loaded = true;\n\
mlock ();\n\
}\n\
if (! form_type_loaded)\n\
{\n\
form::register_type ();\n\
form_type_loaded = true;\n\
mlock ();\n\
}\n\
\n\
if (args(0).type_id () == functionspace::static_type_id ())\n\
{\n\
const functionspace & fspo\n\
= static_cast<const functionspace&> (args(0).get_rep ());\n\
\n\
if (! error_state)\n\
{\n\
const dolfin::FunctionSpace & V = fspo.get_fsp ();\n\
@@UFL_NAME@@::BilinearForm a (V, V);\n\
std::size_t ncoef = a.num_coefficients (), nc = 0;\n\
\n\
if (! coefficient_type_loaded)\n\
{\n\
coefficient::register_type ();\n\
coefficient_type_loaded = true;\n\
mlock ();\n\
}\n\
\n\
if (! function_type_loaded)\n\
{\n\
function::register_type ();\n\
function_type_loaded = true;\n\
mlock ();\n\
}\n\
\n\
for (std::size_t i = 1; i < nargin; ++i)\n\
{\n\
if (args(i).type_id () == coefficient::static_type_id ())\n\
{\n\
const coefficient & cf\n\
= static_cast <const coefficient&> (args(i).get_rep ());\n\
\n\
std::size_t n = a.coefficient_number (cf.get_str ());\n\
const boost::shared_ptr<const expression> & pexp = cf.get_expr ();\n\
a.set_coefficient (n, pexp);\n\
++nc;\n\
}\n\
\n\
if (args(i).type_id () == function::static_type_id ())\n\
{\n\
const function & fun\n\
= static_cast <const function&> (args(i).get_rep ());\n\
\n\
std::size_t n = a.coefficient_number (fun.get_str ());\n\
const boost::shared_ptr<const dolfin::Function> & pfun = fun.get_pfun ();\n\
a.set_coefficient (n, pfun);\n\
++nc;\n\
}\n\
}\n\
\n\
if (nc != ncoef)\n\
error (""Wrong number of coefficient"");\n\
else\n\
{\n\
retval = new form (a);\n\
}\n\
}\n\
}\n\
}\n\
return retval;\n\
}";
STRING = strrep (STRING, "@@UFL_NAME@@", ufl_name);
fid = fopen (sprintf ("%s_BilinearForm.cc", ufl_name), 'w');
if (fid >= 0)
fputs (fid, STRING);
output = fclose (fid);
else
error ("cannot open file");
output = 1;
endif
endfunction