Rheolef  7.1
an efficient C++ finite element environment
basis_get.cc
Go to the documentation of this file.
1 //
22 // input basis from string or files
23 //
24 // author: Pierre.Saramito@imag.fr
25 //
26 // date: 2 october 2017
27 //
28 // Note:
29 // - some technical stuff with bison & flex
30 // - some others for distributed issues:
31 // * lecture du fichier sur proc=0 -> spec sur proc=0
32 // * lecture ecriture spec sur stringstream sur proc=0
33 // * broadcast string sur ts procs
34 // * lecture du stringstream sur ts les proc -> spec
35 // * conversion spec en basis sur ts les procs
36 //
37 
38 //
39 #include <sstream> // flex include it, but in namespace rheolef
40 #include <cstring>
41 #include "rheolef/basis.h"
42 #include "rheolef/basis_get.h"
43 
44 namespace rheolef {
45 
46 // ================================================================================
47 // part 1 : basis specification
48 // ================================================================================
49 
50 static family_index_option_type _current_fio;
51 
52 } // namespace rheolef
53 
54 // ================================================================================
55 // part 2 : read from istream and build family_index_option_type basis specification
56 // ================================================================================
57 /* AIX requires this to be the first thing in the file. */
58 #ifndef __GNUC__
59 # if _RHEOLEF_HAVE_ALLOCA_H
60 # include <alloca.h>
61 # else
62 # ifdef _AIX
63 #pragma alloca
64 # else
65 # ifndef alloca /* predefined by HP cc +Olibcalls */
66 char *alloca ();
67 # endif
68 # endif
69 # endif
70 #endif
71 
72 namespace rheolef {
73 
74 using namespace std;
75 
76 typedef size_t size_type;
77 
80 static std::string basis_input_string;
81 
82 extern int basis_lex();
83 void basis_error (const char* msg) {
84  std::string near;
85  error_macro("invalid basis name: \"" << basis_input_string << "\"");
86  basis_n_error++;
87 }
88 int basis_wrap () { return 1; }
89 
90 static std::vector<std::string> symbol_table;
91 static const std::string& symbol (size_t i) { return symbol_table[i]; }
92 static size_t insert (const std::string& str) {
93  size_t i = symbol_table.size();
94  symbol_table.push_back (str);
95  return i;
96 }
97 #pragma GCC diagnostic push
98 #pragma GCC diagnostic ignored "-Weffc++" // avoid FlexLexer warnings
99 #define YYMALLOC ::malloc
100 #define YYFREE ::free
101 #include "basis_yacc.cc"
102 // avoid re-definition of YY_NULL within flex
103 #ifdef YY_NULL
104 #undef YY_NULL
105 #endif
106 #include "basis_lex.cc"
107 #pragma GCC diagnostic pop
108 
109 static yyFlexLexer input_basis;
110 
111 int basis_lex() { return input_basis.yylex(); }
112 
113 static void basis_get_pass_2 (std::string& str);
114 
115 // ================================================================================
116 // read from string via istrstream
117 // ================================================================================
118 // parse from string on all procs and re-build result_ptr available on all procs
119 static
120 void
121 internal_build_fio_from_string (const std::string& str)
122 {
123  std::istringstream istrstr;
124  // force reading until end of string
125  // otherwise skip all optional terms as "d" and "{...}" !
126  std::string str_eol = str + ";";
127  istrstr.str (str_eol);
128  input_basis.yyrestart(istrstr);
129  symbol_table.clear();
130  _current_fio = family_index_option_type();
131  basis_line_no = 1;
132  basis_n_error = 0;
133  basis_input_string = str; // for error msg
134  if (basis_parse() != 0 || basis_n_error != 0) {
135  _current_fio = family_index_option_type();
136  error_macro ("invalid basis name: \"" << str << "\"");
137  }
138  symbol_table.clear();
139  // then _current_fio is available on all procs
140 }
141 void
142 basis_parse_from_string (const std::string& str, family_index_option_type& fio)
143 {
144  internal_build_fio_from_string (str);
145  fio = _current_fio;
146 }
147 // the same for raw basis, without options:
148 template<class T>
149 void
150 basis_raw_basic<T>::reset (std::string& str)
151 {
152  if (str == "") {
153  base::operator= (0);
154  return;
155  }
156  internal_build_fio_from_string (str);
157  std::string name = _current_fio.family + itos(_current_fio.index);
158  base::operator= (basis_raw_rep<T>::make_ptr(name));
159  _clear();
161 }
162 // -----------------------------------------------------------------------------
163 // instanciation in library
164 // -----------------------------------------------------------------------------
165 #define _RHEOLEF_instanciate(T) \
166 template void basis_raw_basic<T>::reset (std::string&); \
167 
169 
170 #undef _RHEOLEF_instanciate
171 
172 } // namespace rheolef
rheolef::basis_raw_basic::reset
void reset(std::string &name)
Definition: basis_get.cc:150
rheolef::input_basis
static yyFlexLexer input_basis
Definition: basis_get.cc:109
rheolef::_current_fio
static family_index_option_type _current_fio
Definition: basis_get.cc:50
rheolef::basis_line_no
static size_type basis_line_no
Definition: basis_get.cc:78
rheolef::basis_error
void basis_error(const char *msg)
Definition: basis_get.cc:83
rheolef::size_type
size_t size_type
Definition: basis_get.cc:76
rheolef::basis_lex
int basis_lex()
Definition: basis_get.cc:111
rheolef::family_index_option_type
Definition: basis_get.h:31
rheolef::basis_n_error
static size_type basis_n_error
Definition: basis_get.cc:79
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
error_macro
#define error_macro(message)
Definition: dis_macros.h:49
rheolef::basis_raw_rep
Definition: basis_raw.h:36
Float
see the Float page for the full documentation
rheolef::basis_wrap
int basis_wrap()
Definition: basis_get.cc:88
rheolef::symbol_table
static std::vector< std::string > symbol_table
Definition: basis_get.cc:90
rheolef::basis_parse_from_string
void basis_parse_from_string(const std::string &str, family_index_option_type &fio)
Definition: basis_get.cc:142
rheolef::basis_input_string
static std::string basis_input_string
Definition: basis_get.cc:80
rheolef::_RHEOLEF_instanciate
_RHEOLEF_instanciate(Float, sequential) _RHEOLEF_instanciate(Float
rheolef::itos
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation
mkgeo_contraction.name
string name
Definition: mkgeo_contraction.sh:133