comparison inst/ufl.m @ 225:72af6354bf02

Compile right away after ufl end
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Thu, 22 May 2014 12:34:47 +0200
parents a108a0bfe201
children 043120f071de
comparison
equal deleted inserted replaced
224:a108a0bfe201 225:72af6354bf02
18 ## 18 ##
19 ## Writes the given line to a ufl file. Optional commands are: 19 ## Writes the given line to a ufl file. Optional commands are:
20 ## @itemize @bullet 20 ## @itemize @bullet
21 ## @item start: opens an ufl file. It is possible to specify a name for it, 21 ## @item start: opens an ufl file. It is possible to specify a name for it,
22 ## otherwise 'default.ufl' will be used. 22 ## otherwise 'default.ufl' will be used.
23 ## @item end: closes an ufl file. 23 ## @item end: closes the ufl file and compiles it. It is possible to
24 ## specify its @var{content}, otherwise a complete problem is assumed.
25 ## Possible options are: BilinearForm, Functional, FunctionSpace, LinearForm
26 ## and Problem.
24 ## @end itemize 27 ## @end itemize
25 ## 28 ##
29 ## @example
30 ## @code{ufl start fs.ufl}
31 ## @code{ufl element = FunctionSpace ("Lagrange", triangle, 1)}
32 ## @code{ufl end FunctionSpace}
33 ## This way you can write a ufl file and compile it obtaining a FunctionSpace.
34 ## @end example
35 ##
36 ## @seealso{import_ufl_Problem, import_ufl_BilinearForm, import_ufl_Functional,
37 ## import_ufl_FunctionSpace, import_ufl_LinearForm}
26 ## @end deftypefn 38 ## @end deftypefn
27 39
28 function ufl (varargin) 40 function ufl (varargin)
29 41
30 persistent fid = -1; 42 persistent fid = -1;
31 filename = "default.ufl"; 43 persistent filename = "default.ufl";
44 persistent opts = {"BilinearForm",
45 "Functional",
46 "FunctionSpace",
47 "LinearForm",
48 "Problem"};
32 49
33 if (numel (varargin) < 1) 50 if (numel (varargin) < 1)
34 if (! is_valid_file_id (fid)) 51 if (! is_valid_file_id (fid))
35 print_usage (); 52 print_usage ();
36 endif 53 endif
63 error ("ufl: no open file"); 80 error ("ufl: no open file");
64 else 81 else
65 fclose (fid); 82 fclose (fid);
66 fid = -1; 83 fid = -1;
67 endif 84 endif
85 compile = "Problem";
86 if (numel (varargin) > 1)
87 compile = validatestring (varargin{2}, opts, "ufl", "content");
88 endif
89 eval (["import_ufl_", compile, "(\"", filename(1:end-4), "\");"]);
90 filename = "default.ufl";
68 elseif (! is_valid_file_id (fid)) 91 elseif (! is_valid_file_id (fid))
69 error ("ufl: no open file"); 92 error ("ufl: no open file");
70 else 93 else
71 if (is_valid_file_id (fid)) 94 if (is_valid_file_id (fid))
72 fprintf (fid, "%s ", varargin{:}); 95 fprintf (fid, "%s ", varargin{:});