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