Rheolef  7.1
an efficient C++ finite element environment
basis_rep.cc
Go to the documentation of this file.
1 #include "rheolef/basis.h"
22 #include "rheolef/basis_get.h"
23 
24 namespace rheolef {
25 using namespace std;
26 
27 // =========================================================================
28 // naming scheme for standard FEM families
29 // =========================================================================
30 static
31 bool
32 is_family_no_index (const std::string& family_name)
33 {
34  // TODO: how to merge this keywords list with basis_lex.flex ?
35  // basis::have_index_parameter() givzes the response, but requires a
36  // previously builded basis
37  if (family_name == "bubble") return true;
38  if (family_name == "P1qd") return true;
39  if (family_name == "empty") return true;
40  return false;
41 }
42 template <class T>
43 std::string
45  std::string family_name,
46  size_type index,
47  const basis_option& sopt)
48 {
49  string opt_d = (sopt.is_continuous() || (family_name == "P" && index == 0)) ? "" : "d";
50  string basename = is_family_no_index (family_name) ? family_name : family_name + itos(index) + opt_d;
51  string scalar_name = basename + sopt.stamp();
52  if (sopt.valued_tag() == space_constant::scalar) {
53  trace_macro("standard_naming("<<family_name<<","<<index<<",opts)=\""<<scalar_name<<"\"");
54  if (! sopt.is_restricted_to_sides()) {
55  return scalar_name;
56  } else {
57  return "trace(" + scalar_name + ")";
58  }
59  }
60  const size_type unset = std::numeric_limits<basis_option::size_type>::max();
61  string opt_dim = (sopt.dimension() == unset) ? "" : "d=" + itos(sopt.dimension());
62  string opt_sc = (sopt.valued_tag() == space_constant::vector || sopt.coordinate_system() == space_constant::cartesian) ?
64  string coma = (opt_dim == "" || opt_sc == "") ? "" : ",";
65  string opt_valued = (opt_dim == "" && opt_sc == "") ? "" : "[" + opt_dim + coma + opt_sc + "]";
66  string braced_name = sopt.valued() + opt_valued + "(" + scalar_name + ")";
67  if (! sopt.is_restricted_to_sides()) {
68  return braced_name;
69  } else {
70  return "trace(" + braced_name + ")";
71  }
72 }
73 // =========================================================================
74 // basis members (should be inlined)
75 // =========================================================================
76 template<class T>
77 void
78 basis_basic<T>::reset (std::string& name_in)
79 {
80  if (name_in == "") {
81  base::operator= (0);
82  } else {
83  // strip name_in as name: drop "scalar(Pk)" as "Pk" or "P0d" as "P0", to get unique name scheme
85  basis_parse_from_string (name_in, fio);
86  std::string name = basis_rep<T>::standard_naming (fio.family, fio.index, fio.option);
87  base::operator= (persistent_table<basis_basic<T>>::load (name));
88  _clear();
89  }
90 }
91 template<class T>
92 void
94 {
95  std::string fname = family_name();
96  basis_option bopt = option();
97  std::string name = basis_rep<T>::standard_naming (fname, k, bopt); \
98  reset (name);
99 }
100 template <class T>
102 {
103  persistent_table<basis_basic<T>>::unload (_name);
104 }
105 template<class T>
107 : _name(""),
108  _sopt(sopt),
109  _piola_fem(),
110  _have_initialize_data(),
111  _ndof_on_subgeo(),
112  _nnod_on_subgeo(),
113  _first_idof_by_dimension(),
114  _first_inod_by_dimension()
115 {
116  _clear();
117 }
118 template<class T>
119 void
121 {
122  _have_initialize_data.fill (false);
123 }
124 template <class T>
125 void
127 {
128  if (_have_initialize_data [hat_K.variant()]) return;
129  _have_initialize_data [hat_K.variant()] = true;
130  _initialize_data (hat_K);
131 }
132 // inplace change nxxx_on_subgeo for discontinuous elements
133 template <class T>
134 void
136  bool is_continuous,
137  std::array<
138  std::array<
139  size_type
141  ,4>& nxxx_on_subgeo)
142 {
143  std::array<
144  std::array<
145  size_type
147  ,4> nxxx_on_subgeo_d;
148  for (size_type map_dim = 0; map_dim < 4; ++map_dim) {
149  nxxx_on_subgeo_d [map_dim].fill (0);
150  }
151  if (is_continuous) return; // no changes
152  for (size_type variant = 0;
154  variant++)
155  {
156  reference_element hat_K (variant);
157  size_type map_dim = hat_K.dimension();
158  size_type sum = 0;
159  for (size_type subgeo_variant = 0;
161  subgeo_variant++)
162  {
163  size_type n_subgeo = hat_K.n_subgeo_by_variant (subgeo_variant);
164  sum += n_subgeo*nxxx_on_subgeo [map_dim][subgeo_variant];
165  }
166  nxxx_on_subgeo_d [map_dim][variant] = sum;
167  }
168  nxxx_on_subgeo = nxxx_on_subgeo_d;
169 }
170 // deduce automatically first_ixxx_by_dimension from nxxx_on_subgeo
171 template <class T>
172 void
174  const std::array<
175  std::array<
176  size_type
178  ,4>& nxxx_on_subgeo,
179  std::array<
180  std::array<
181  size_type
182  ,5>
183  ,reference_element::max_variant>& first_ixxx_by_dimension)
184 {
185  for (size_type variant = 0;
187  variant++)
188  {
189  reference_element hat_K (variant);
190  size_type map_dim = hat_K.dimension();
191  first_ixxx_by_dimension [variant].fill(0);
192  for (size_type subgeo_dim = 0; subgeo_dim <= map_dim; ++subgeo_dim) {
193  size_type sum = first_ixxx_by_dimension [variant][subgeo_dim];
194  for (size_type subgeo_variant = reference_element::first_variant_by_dimension(subgeo_dim);
195  subgeo_variant < reference_element:: last_variant_by_dimension(subgeo_dim);
196  subgeo_variant++)
197  {
198  size_type n_subgeo = hat_K.n_subgeo_by_variant (subgeo_variant);
199  sum += n_subgeo*nxxx_on_subgeo [map_dim][subgeo_variant];
200  }
201  first_ixxx_by_dimension [variant][subgeo_dim+1] = sum;
202  }
203  }
204 }
205 // ----------------------------------------------------------------------------
206 // instanciation in library
207 // ----------------------------------------------------------------------------
208 #define _RHEOLEF_instanciation(T) \
209 template class basis_rep<T>; \
210 template void basis_basic<T>::reset (std::string&); \
211 template void basis_basic<T>::reset_family_index (size_type); \
212 
214 
215 }// namespace rheolef
rheolef::reference_element::last_variant_by_dimension
static variant_type last_variant_by_dimension(size_type dim)
Definition: reference_element.h:150
rheolef::space_constant::coordinate_system_name
std::string coordinate_system_name(coordinate_type i)
Definition: space_constant.cc:69
rheolef::basis_option::valued
const std::string & valued() const
Definition: basis_option.h:251
rheolef::basis_option::is_restricted_to_sides
bool is_restricted_to_sides() const
Definition: basis_option.h:239
rheolef::family_index_option_type::family
std::string family
Definition: basis_get.h:34
rheolef::basis_basic::reset
void reset(std::string &name)
Definition: basis_rep.cc:78
rheolef::basis_rep::_initialize_data_guard
void _initialize_data_guard(reference_element hat_K) const
Definition: basis_rep.cc:126
rheolef::basis_option::is_continuous
bool is_continuous() const
Definition: basis_option.h:227
rheolef::family_index_option_type::index
size_t index
Definition: basis_get.h:35
rheolef::basis_rep::_helper_discontinuous_ndof_on_subgeo_inplace_change
static void _helper_discontinuous_ndof_on_subgeo_inplace_change(bool is_continuous, std::array< std::array< size_type, reference_element::max_variant >, 4 > &nxxx_on_subgeo)
Definition: basis_rep.cc:135
rheolef::basis_option::stamp
std::string stamp() const
Definition: basis_option.cc:124
rheolef::_RHEOLEF_instanciation
_RHEOLEF_instanciation(Float, sequential, std::allocator< Float >) _RHEOLEF_instanciation(Float
rheolef::space_constant::cartesian
Definition: space_constant.h:122
rheolef::basis_rep::_helper_initialize_first_ixxx_by_dimension_from_nxxx_on_subgeo
static void _helper_initialize_first_ixxx_by_dimension_from_nxxx_on_subgeo(const std::array< std::array< size_type, reference_element::max_variant >, 4 > &_nxxx_on_subgeo, std::array< std::array< size_type, 5 >, reference_element::max_variant > &_first_ixxx_by_dimension)
Definition: basis_rep.cc:173
rheolef::size_type
size_t size_type
Definition: basis_get.cc:76
rheolef::basis_option
see the basis_option page for the full documentation
Definition: basis_option.h:93
rheolef::basis_rep::size_type
reference_element::size_type size_type
Definition: basis.h:214
rheolef::reference_element::first_variant_by_dimension
static variant_type first_variant_by_dimension(size_type dim)
Definition: reference_element.h:148
rheolef::basis_basic
Definition: basis.h:206
rheolef::persistent_table
see the persistent_table page for the full documentation
Definition: persistent_table.h:84
rheolef::reference_element
see the reference_element page for the full documentation
Definition: reference_element.h:66
mkgeo_ball.variant
variant
Definition: mkgeo_ball.sh:149
rheolef::space_constant::scalar
Definition: space_constant.h:136
rheolef::basis_rep::basis_rep
basis_rep(const basis_option &sopt)
Definition: basis_rep.cc:106
rheolef::basis_option::coordinate_system
coordinate_type coordinate_system() const
Definition: basis_option.h:139
rheolef::basis_rep::_clear
void _clear() const
Definition: basis_rep.cc:120
rheolef::reference_element::variant
variant_type variant() const
Definition: reference_element.h:99
rheolef::basis_rep::~basis_rep
virtual ~basis_rep()
Definition: basis_rep.cc:101
rheolef::family_index_option_type
Definition: basis_get.h:31
rheolef::basis_basic::reset_family_index
void reset_family_index(size_type k)
Definition: basis_rep.cc:93
rheolef::basis_basic::size_type
rep::size_type size_type
Definition: basis.h:539
mkgeo_couette.basename
basename
Definition: mkgeo_couette.sh:73
rheolef
This file is part of Rheolef.
Definition: compiler_eigen.h:37
rheolef::basis_option::dimension
size_type dimension() const
Definition: basis_option.h:138
Float
see the Float page for the full documentation
rheolef::reference_element::max_variant
static const variant_type max_variant
Definition: reference_element.h:82
rheolef::reference_element::dimension
size_type dimension() const
Definition: reference_element.h:101
rheolef::family_index_option_type::option
basis_option option
Definition: basis_get.h:36
load
void load(idiststream &in, Float &p, field &uh)
Definition: p_laplacian_post.cc:64
rheolef::space_constant::vector
Definition: space_constant.h:137
rheolef::basis_rep::standard_naming
static std::string standard_naming(std::string family_name, size_t degree, const basis_option &sopt)
Definition: basis_rep.cc:44
rheolef::basis_parse_from_string
void basis_parse_from_string(const std::string &str, family_index_option_type &fio)
Definition: basis_get.cc:142
mkgeo_ball.map_dim
map_dim
Definition: mkgeo_ball.sh:337
rheolef::reference_element::n_subgeo_by_variant
size_type n_subgeo_by_variant(size_type subgeo_variant) const
Definition: reference_element.h:107
rheolef::itos
std::string itos(std::string::size_type i)
itos: see the rheostream page for the full documentation
mkgeo_contraction.name
name
Definition: mkgeo_contraction.sh:133
trace_macro
#define trace_macro(message)
Definition: dis_macros.h:111
rheolef::basis_option::valued_tag
valued_type valued_tag() const
Definition: basis_option.h:245