GetFEM  5.5
bgeot_convex_structure.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 1999-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 #ifndef BGEOT_CONVEX_STRUCTURE_H__
32 #define BGEOT_CONVEX_STRUCTURE_H__
33 
34 /** @file bgeot_convex_structure.h
35  @author Yves Renard <[email protected]>
36  @date December 20, 1999.
37  @brief Definition of convex structures
38  */
39 
40 #include "gmm/gmm_ref.h"
41 #include "bgeot_config.h"
42 #include "bgeot_tensor.h"
43 #include "bgeot_poly.h"
45 
46 namespace bgeot {
47  /** @defgroup convex_structure Convex Structure */
48  /*@{*/
49 
50  // The number of faces for a convex is limited in certain applications
51 # define MAX_FACES_PER_CV 31
52 
53  class convex_structure;
54 
55  /// Pointer on a convex structure description.
56  typedef std::shared_ptr<const convex_structure> pconvex_structure;
57 
58  typedef std::vector<pconvex_structure> convex_structure_faces_ct;
59  typedef std::vector<short_type> convex_ind_ct;
60  typedef gmm::tab_ref_index_ref< convex_ind_ct::const_iterator,
61  convex_ind_ct::const_iterator> ref_convex_ind_ct;
62 
63  /** Structure of a convex.
64  *
65  * This class is not to be manipulated by itself. Use
66  * pconvex_structure and the functions written to produce the
67  * convex structures from classicals convexes (simplexes, polygonals
68  * ...). The reason is that there is no need for having more than
69  * one convex structure for the same type of convex.
70  */
72  protected :
73 
74  dim_type Nc;
75  short_type nbpt, nbf;
76  convex_structure_faces_ct faces_struct;
77  std::vector<convex_ind_ct> faces;
78  convex_ind_ct dir_points_;
79  pconvex_structure basic_pcvs;
80  bool auto_basic;
81 
82  pconvex_structure prod_a, prod_b; /* only filled for convex structures */
83  /* product. */
84 
85  mutable std::map<std::vector<short_type>, convex_ind_ct> intersection_points;
86 
87  public :
88 
89  /// Number of faces.
90  inline short_type nb_faces() const { return nbf; }
91  /// Dimension of the convex.
92  inline dim_type dim() const { return Nc; }
93  /// Number of vertices.
94  inline short_type nb_points() const { return nbpt; }
95  /** Number of vertices of a face.
96  * @param i the face number.
97  */
99  { return short_type(faces[i].size()); }
100  /** Give an array of the indexes of the vertices of a face.
101  * The indexes are "local" to the convex.
102  * @param i the face number.
103  */
104  inline const convex_ind_ct &ind_points_of_face(short_type i) const
105  { return faces[i]; }
106  /** Give an array of the indexes of the vertices at the intersection
107  * of a set of faces. The indexes are "local" to the convex.
108  * @param i the face number.
109  */
110  const convex_ind_ct &
111  ind_common_points_of_faces(const std::vector<short_type> &ftab) const;
112  /** Return "direct" points indexes. These are the subset of points that
113  * can be used to build a direct vector basis. (rarely used)
114  */
115  inline const convex_ind_ct &ind_dir_points() const
116  { return dir_points_; }
117  /** Give a pointer array on the structures of the faces.
118  * faces_structure()[i] is a pointer on the structure of the face i.
119  */
120  inline const convex_structure_faces_ct &faces_structure() const
121  { return faces_struct; }
122  /** Return "direct" points indexes for a given face.
123  * @param i the face number.
124  */
126  return ref_convex_ind_ct(faces[i].begin(),
127  faces_struct[i]->ind_dir_points().begin(),
128  faces_struct[i]->ind_dir_points().end());
129  }
130 
131  void init_for_adaptative(pconvex_structure cvs);
132  void add_point_adaptative(short_type i, short_type f);
133  /** Return true if the convex structure is indeed a direct product
134  * of two convex structures.
135  * @param pprod1 the first sub-structure (optional)
136  * @param pprod2 the second sub-structure (optional)
137  */
139  pconvex_structure *pprod2=0) const {
140  if (pprod1) *pprod1 = prod_a;
141  if (pprod2) *pprod2 = prod_b;
142  return prod_a ? true : false;
143  }
144  explicit convex_structure(bool auto_b)
145  : auto_basic(auto_b), prod_a(0), prod_b(0)
146  { DAL_STORED_OBJECT_DEBUG_CREATED(this, "Convex structure"); }
147  virtual ~convex_structure()
148  { DAL_STORED_OBJECT_DEBUG_DESTROYED(this, "Convex structure"); }
149  protected:
150  convex_structure() : auto_basic(false), prod_a(0), prod_b(0)
151  { DAL_STORED_OBJECT_DEBUG_CREATED(this, "Convex structure"); }
152  friend std::shared_ptr<convex_structure> new_convex_structure();
154  };
155 
156  /**
157  * Stored objects must be compared by keys, because there is a possibility that
158  * they are duplicated in storages of multiple threads and pointers to them are
159  * never equal
160  */
161  bool operator==(const pconvex_structure &p1, const pconvex_structure &p2);
162  bool operator!=(const pconvex_structure &p1, const pconvex_structure &p2);
163 
164  //!these operators still use comparison by addresses against nullptr
165  bool operator==(const pconvex_structure &p1, std::nullptr_t);
166  bool operator==(std::nullptr_t, const pconvex_structure &p2);
167  bool operator!=(const pconvex_structure &p1, std::nullptr_t);
168  bool operator!=(std::nullptr_t, const pconvex_structure &p2);
169 
170  /// Original structure (if concerned)
172  { if (cv->auto_basic) return cv; else return cv->basic_pcvs; }
173 
174  inline std::shared_ptr<convex_structure> new_convex_structure()
175  { return std::make_shared<convex_structure>(false); }
176 
177  /** @name functions on convex structures
178  */
179  //@{
180 
181  /** Print the details of the convex structure cvs to the output stream o.
182  * For debuging purpose.
183  */
184  std::ostream &operator << (std::ostream &o,
185  const convex_structure &cv);
186 
187  /// Give a pointer on the structures of a simplex of dimension d.
189  /// Give a pointer on the structures of a parallelepiped of dimension d.
190  pconvex_structure parallelepiped_structure(dim_type d, dim_type k = 1);
191  /// Give a pointer on the structures of a polygon with n vertex.
193  /** Give a pointer on the structures of a incomplete Q2
194  quadrilateral/hexahedral of dimension d = 2 or 3.
195  */
197  /** Give a pointer on the structures of a convex which is the direct
198  * product of the convexes represented by *pcvs1 and *pcvs2.
199  */
202  /** Give a pointer on the structures of a prism of dimension d.
203  * i.e. the direct product of a simplex of dimension d-1 and a segment.
204  */
205  inline pconvex_structure prism_P1_structure(dim_type nc) {
206  return convex_product_structure(simplex_structure(dim_type(nc-1)),
207  simplex_structure(1));
208  }
209  /// Give a pointer on the 3D quadratic incomplete prism structure.
211  /// Give a pointer on the 3D pyramid structure for a degree k = 1 or 2.
213  /// Give a pointer on the 3D quadratic incomplete pyramid structure.
215 
216  IS_DEPRECATED inline pconvex_structure
217  prism_structure(dim_type nc) { return prism_P1_structure(nc); }
218  IS_DEPRECATED inline pconvex_structure
219  pyramid_structure(short_type k) { return pyramid_QK_structure(k); }
220 
221 
222  /** Simplex structure with the Lagrange grid of degree k.
223  @param n the simplex dimension.
224  @param k the simplex degree.
225  */
227 
228  /// Generic convex with n global nodes
230  short_type nf);
231 
232  //@}
233 
234  /*@}*/
235 } /* end of namespace bgeot. */
236 
237 
238 #endif /* BGEOT_CONVEX_STRUCTURE_H__ */
defines and typedefs for namespace bgeot
Multivariate polynomials.
tensor class, used in mat_elem computations.
Structure of a convex.
const convex_ind_ct & ind_points_of_face(short_type i) const
Give an array of the indexes of the vertices of a face.
const convex_structure_faces_ct & faces_structure() const
Give a pointer array on the structures of the faces.
dim_type dim() const
Dimension of the convex.
const convex_ind_ct & ind_common_points_of_faces(const std::vector< short_type > &ftab) const
Give an array of the indexes of the vertices at the intersection of a set of faces.
const convex_ind_ct & ind_dir_points() const
Return "direct" points indexes.
friend pconvex_structure basic_structure(pconvex_structure cv)
Original structure (if concerned)
short_type nb_points_of_face(short_type i) const
Number of vertices of a face.
short_type nb_points() const
Number of vertices.
short_type nb_faces() const
Number of faces.
bool is_product(pconvex_structure *pprod1=0, pconvex_structure *pprod2=0) const
Return true if the convex structure is indeed a direct product of two convex structures.
ref_convex_ind_ct ind_dir_points_of_face(short_type i) const
Return "direct" points indexes for a given face.
base class for static stored objects
indexed array reference (given a container X, and a set of indexes I, this class provides a pseudo-co...
Definition: gmm_ref.h:303
Stores interdependent getfem objects.
Provide some simple pseudo-containers.
Basic Geometric Tools.
pconvex_structure prism_incomplete_P2_structure()
Give a pointer on the 3D quadratic incomplete prism structure.
pconvex_structure pyramid_Q2_incomplete_structure()
Give a pointer on the 3D quadratic incomplete pyramid structure.
gmm::uint16_type short_type
used as the common short type integer in the library
Definition: bgeot_config.h:72
pconvex_structure pyramid_QK_structure(dim_type k)
Give a pointer on the 3D pyramid structure for a degree k = 1 or 2.
std::ostream & operator<<(std::ostream &o, const convex_structure &cv)
Print the details of the convex structure cvs to the output stream o.
std::shared_ptr< const convex_structure > pconvex_structure
Pointer on a convex structure description.
pconvex_structure parallelepiped_structure(dim_type nc, dim_type k)
Give a pointer on the structures of a parallelepiped of dimension d.
pconvex_structure generic_dummy_structure(dim_type nc, size_type n, short_type nf)
Generic convex with n global nodes.
bool operator==(const pconvex_structure &p1, const pconvex_structure &p2)
Stored objects must be compared by keys, because there is a possibility that they are duplicated in s...
pconvex_structure Q2_incomplete_structure(dim_type nc)
Give a pointer on the structures of a incomplete Q2 quadrilateral/hexahedral of dimension d = 2 or 3.
pconvex_structure prism_P1_structure(dim_type nc)
Give a pointer on the structures of a prism of dimension d.
pconvex_structure simplex_structure(dim_type nc)
Give a pointer on the structures of a simplex of dimension d.
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:48
pconvex_structure polygon_structure(short_type nbt)
Give a pointer on the structures of a polygon with n vertex.
pconvex_structure convex_product_structure(pconvex_structure a, pconvex_structure b)
Give a pointer on the structures of a convex which is the direct product of the convexes represented ...
pconvex_structure basic_structure(pconvex_structure cv)
Original structure (if concerned)