GetFEM  5.5
bgeot_poly_composite.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2002-2026 Yves Renard
5 
6  This file is a part of GetFEM
7 
8  GetFEM is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Lesser General Public License as published
10  by the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version along with the GCC Runtime Library
12  Exception either version 3.1 or (at your option) any later version.
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  License and GCC Runtime Library Exception for more details.
17  You should have received a copy of the GNU Lesser General Public License
18  along with this program. If not, see https://www.gnu.org/licenses/.
19 
20  As a special exception, you may use this file as it is a part of a free
21  software library without restriction. Specifically, if other files
22  instantiate templates or use macros or inline functions from this file,
23  or you compile this file and link it with other files to produce an
24  executable, this file does not by itself cause the resulting executable
25  to be covered by the GNU Lesser General Public License. This exception
26  does not however invalidate any other reasons why the executable file
27  might be covered by the GNU Lesser General Public License.
28 
29 ===========================================================================*/
30 
31 /**@file bgeot_poly_composite.h
32  @author Yves Renard <Yves.Renard@insa-lyon.fr>
33  @date August 26, 2002.
34  @brief Handle composite polynomials.
35 
36  Composite polynomials are used in hierarchical FEM, composite geometric
37  transformations and composite fems.
38 */
39 
40 #ifndef BGEOT_POLY_COMPOSITE_H__
41 #define BGEOT_POLY_COMPOSITE_H__
42 
43 #include "bgeot_poly.h"
44 #include "bgeot_mesh.h"
45 #include "bgeot_rtree.h"
46 
47 // TODO : Use of rtree instead of dal::dynamic_tree_sorted<base_node,
48 // imbricated_box_less>
49 
50 
51 namespace bgeot {
52 
53  /// A comparison function for bgeot::base_node
55  {
56  mutable int exp_max, exp_min;
57  mutable scalar_type c_max;
58  unsigned base;
59 
60  /// comparaison function
61  int operator()(const base_node &x, const base_node &y) const;
62 
63  imbricated_box_less(unsigned ba = 10, int emi = -15, int ema = -2) {
64  base = ba; exp_max = ema; exp_min = emi;
65  c_max = pow(double(base), double(-exp_max));
66  }
67  };
68 
69 
70 
71  struct mesh_precomposite {
72 
73  typedef dal::dynamic_tree_sorted<base_node, imbricated_box_less> PTAB;
74 
75  const basic_mesh *msh;
76  PTAB vertices;
77  rtree box_tree;
78  std::map<size_type, std::vector<size_type>> box_to_convexes_map;
79  std::vector<base_matrix> gtrans, gtransinv;
80  std::vector<scalar_type> det;
81  std::vector<base_node> orgs;
82 
83  const basic_mesh &linked_mesh(void) const { return *msh; }
84  size_type nb_convex(void) const { return gtrans.size(); }
85  dim_type dim(void) const { return msh->dim(); }
86  pgeometric_trans trans_of_convex(size_type ic) const
87  { return msh->trans_of_convex(ic); }
88  void initialise(const basic_mesh &m);
89 
90  mesh_precomposite(const basic_mesh &m);
91  mesh_precomposite(void) : msh(0), box_tree(1e-13) {}
92  };
93 
94  typedef const mesh_precomposite *pmesh_precomposite;
95 
96  struct stored_base_poly : base_poly, public dal::static_stored_object {
97  stored_base_poly(const base_poly &p) : base_poly(p) {}
98  };
99  typedef std::shared_ptr<const stored_base_poly> pstored_base_poly;
100 
101 
102  class polynomial_composite {
103 
104  protected :
105  const mesh_precomposite *mp;
106  std::map<size_type, pstored_base_poly> polytab;
107  bool local_coordinate; // Local coordinates on each sub-element for
108  // polynomials or global coordinates ?
109  bool faces_first; // If true try to evaluate on faces before on the
110  // interior, usefull for HHO elements.
111  std::vector<base_poly> default_polys;
112 
113  public :
114  scalar_type eval(const base_node &p, size_type l) const;
115 
116  template <class ITER> scalar_type eval(const ITER &it,
117  size_type l = -1) const;
118  void derivative(short_type k);
119  void set_poly_of_subelt(size_type l, const base_poly &poly);
120  const base_poly &poly_of_subelt(size_type l) const;
121  size_type nb_subelt() const { return polytab.size(); }
122 
123  polynomial_composite(bool lc = true, bool ff = false)
124  : local_coordinate(lc), faces_first(ff) {}
125  polynomial_composite(const mesh_precomposite &m, bool lc = true,
126  bool ff = false);
127 
128  };
129 
130  inline std::ostream &operator <<
131  (std::ostream &o, const polynomial_composite& P) {
132  o << "poly_composite [";
133  for (size_type i = 0; i < P.nb_subelt(); ++i) {
134  if (i != 0) o << ", " << P.poly_of_subelt(i);
135  }
136  o << "]";
137  return o;
138  }
139 
140  template <class ITER>
141  scalar_type polynomial_composite::eval(const ITER &it, size_type l) const {
142  base_node p(mp->dim());
143  std::copy(it, it+mp->dim(), p.begin());
144  return eval(p,l);
145  }
146 
147  void structured_mesh_for_convex(pconvex_ref cvr, short_type k,
148  pbasic_mesh &pm, pmesh_precomposite &pmp,
149  bool force_simplexification=false);
150 
151  /** simplexify a convex_ref.
152  @param cvr the convex_ref.
153  @param k the refinement level.
154  @return a pointer to a statically allocated mesh. Do no free it!
155  */
156  const basic_mesh *
157  refined_simplex_mesh_for_convex(pconvex_ref cvr, short_type k);
158 
159  /** simplexify the faces of a convex_ref
160 
161  @param cvr the convex_ref.
162 
163  @param k the refinement level.
164 
165  @return vector of pointers to a statically allocated
166  mesh_structure objects. Do no free them! The point numbers in
167  the mesh_structure refer to the points of the mesh given by
168  refined_simplex_mesh_for_convex.
169  */
170  const std::vector<std::unique_ptr<mesh_structure>>&
172 } /* end of namespace bgeot. */
173 
174 
175 #endif
Basic mesh definition.
Multivariate polynomials.
region-tree for window/point search on a set of rectangles.
Balanced tree of n-dimensional rectangles.
Definition: bgeot_rtree.h:97
base class for static stored objects
Basic Geometric Tools.
gmm::uint16_type short_type
used as the common short type integer in the library
Definition: bgeot_config.h:72
const basic_mesh * refined_simplex_mesh_for_convex(pconvex_ref cvr, short_type k)
simplexify a convex_ref.
void structured_mesh_for_convex(pconvex_ref cvr, short_type k, pbasic_mesh &pm, pmesh_precomposite &pmp, bool force_simplexification)
This function returns a mesh in pm which contains a refinement of the convex cvr if force_simplexific...
const std::vector< std::unique_ptr< mesh_structure > > & refined_simplex_mesh_for_convex_faces(pconvex_ref cvr, short_type k)
simplexify the faces of a convex_ref
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:48
std::shared_ptr< const bgeot::geometric_trans > pgeometric_trans
pointer type for a geometric transformation
A comparison function for bgeot::base_node.
int operator()(const base_node &x, const base_node &y) const
comparaison function