Rheolef  7.1
an efficient C++ finite element environment
basis.cc
Go to the documentation of this file.
1 //
4 // Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
5 //
6 // Rheolef is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // Rheolef is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with Rheolef; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // =========================================================================
21 // the basis unix command
22 // author: Pierre.Saramito@imag.fr
23 // date: 11 september 2017
24 //
25 
26 namespace rheolef {
148 } // namespace rheolef
149 
150 #include "rheolef/basis.h"
151 #include "rheolef/basis_raw.h"
152 #include "rheolef/iorheo.h"
153 #include "rheolef/reference_element_face_transformation.h"
154 using namespace rheolef;
155 using namespace std;
156 
157 void usage() {
158  cerr << "basis: usage:" << endl
159  << "basis "
160  << "[approx=P1] "
161  << "[element=t] "
162  << "{-dubiner|-monomial} "
163  << "{-fem|-raw} "
164  << "{-ndof|-poly|-node|-node-side int} "
165  << "[-subdivide int] "
166  << "[-[no]clean] [-[no]execute] [-[no]verbose] "
167  << endl;
168  exit (1);
169 }
170 int main(int argc, char**argv) {
171  // --------------------------------
172  // scan command line
173  // --------------------------------
174  if (argc == 1) usage();
175  typedef enum {
176  show_poly = 0,
177  show_node = 1,
178  show_node_on_side = 2,
179  show_ndof = 3,
180  show_nnod = 4
181  } show_type;
182  show_type show = show_poly;
183  string approx = "P1";
184  char t = 't';
185  reference_element hat_K;
186  hat_K.set_name(t);
187  bool raw = false;
188  size_t nsub = 0;
190  for (int i = 1; i < argc; i++) {
191 
192  // general options:
193  if (strcmp (argv[i], "-clean") == 0) cout << clean;
194  else if (strcmp (argv[i], "-noclean") == 0) cout << noclean;
195  else if (strcmp (argv[i], "-execute") == 0) cout << execute;
196  else if (strcmp (argv[i], "-noexecute") == 0) cout << noexecute;
197  else if (strcmp (argv[i], "-verbose") == 0) cout << verbose;
198  else if (strcmp (argv[i], "-noverbose") == 0) cout << noverbose;
199 
200  // basis options:
201  else if (strcmp (argv[i], "-fem") == 0) raw = false;
202  else if (strcmp (argv[i], "-raw") == 0) raw = true;
203 
204  // view options:
205  else if (strcmp (argv[i], "-ndof") == 0) show = show_ndof;
206  else if (strcmp (argv[i], "-nnod") == 0) show = show_nnod;
207  else if (strcmp (argv[i], "-poly") == 0) show = show_poly;
208  else if (strcmp (argv[i], "-node") == 0) show = show_node;
209  else if (strcmp (argv[i], "-node-side") == 0) {
210  show = show_node_on_side;
211  if (i == argc-1) { cerr << "basis -node-side: option argument missing" << endl; usage(); }
212  sid.loc_isid = atoi(argv[++i]);
213  } else if (strcmp (argv[i], "-subdivide") == 0) {
214  if (i == argc-1) { cerr << "basis -subdivide: option argument missing" << endl; usage(); }
215  nsub = atoi(argv[++i]);
216  cout << setsubdivide (nsub);
217 
218  // reference element spec:
219  } else if (argv[i][0] != '-' && strlen(argv[i]) == 1) {
220  t = argv[i][0];
221  hat_K.set_name(t);
222  // basis spec:
223  } else if (argv[i][0] != '-' && strlen(argv[i]) >= 2) {
224  approx = argv[i];
225  } else {
226  cerr << "unexpected option `" << argv[i]<< endl;
227  usage();
228  }
229  }
230  if (approx[0] == 'M' || approx[0] == 'D') {
231  raw = true;
232  }
233  if (nsub == 0) {
234  nsub = (hat_K.dimension() == 1) ? 1000 : 40;
235  cout << setsubdivide (nsub);
236  }
237  // --------------------------------
238  // show
239  // --------------------------------
240  if (raw) { // raw basis
241  if (show != show_poly) {
242  cerr << "basis: raw basis no not have nodes (HINT: use -poly option instead of -node)" << endl;
243  exit (1);
244  }
245  basis_raw b (approx);
246  b.put (cout, hat_K);
247  return 0;
248  }
249  // fem basis
250  basis b (approx);
251  switch (show) {
252  case show_ndof:
253  cout << b.ndof (hat_K) << endl;
254  break;
255  case show_nnod:
256  cout << b.nnod (hat_K) << endl;
257  break;
258  case show_poly:
259  b.put (cout, hat_K);
260  break;
261  case show_node:
262  b.put_hat_node (cout, hat_K);
263  break;
264  case show_node_on_side:
265  b.put_hat_node_on_side (cout, hat_K, sid);
266  break;
267  }
268 }
void usage()
Definition: basis.cc:157
int main(int argc, char **argv)
Definition: basis.cc:170
show_type
Definition: field.cc:402
see the basis page for the full documentation
see the reference_element page for the full documentation
basis_raw_basic< Float > basis_raw
Definition: basis_raw.h:155
This file is part of Rheolef.