GetFEM++  5.3
bgeot_convex_structure.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 1999-2017 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  */
126  inline ref_convex_ind_ct ind_dir_points_of_face(short_type i) const {
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  */
139  bool is_product(pconvex_structure *pprod1=0,
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();
154  friend pconvex_structure basic_structure(pconvex_structure cv);
155  };
156 
157  /// Original structure (if concerned)
158  inline pconvex_structure basic_structure(pconvex_structure cv)
159  { if (cv->auto_basic) return cv; else return cv->basic_pcvs; }
160 
161  inline std::shared_ptr<convex_structure> new_convex_structure()
162  { return std::make_shared<convex_structure>(false); }
163 
164  /** @name functions on convex structures
165  */
166  //@{
167 
168  /** Print the details of the convex structure cvs to the output stream o.
169  * For debuging purpose.
170  */
171  std::ostream &operator << (std::ostream &o,
172  const convex_structure &cv);
173 
174  /// Give a pointer on the structures of a simplex of dimension d.
175  pconvex_structure simplex_structure(dim_type d);
176  /// Give a pointer on the structures of a parallelepiped of dimension d.
177  pconvex_structure parallelepiped_structure(dim_type d, dim_type k = 1);
178  /// Give a pointer on the structures of a polygon with n vertex.
179  pconvex_structure polygon_structure(short_type);
180  /** Give a pointer on the structures of a incomplete Q2
181  quadrilateral/hexahedral of dimension d = 2 or 3.
182  */
183  pconvex_structure Q2_incomplete_structure(dim_type d);
184  /** Give a pointer on the structures of a convex which is the direct
185  * product of the convexes represented by *pcvs1 and *pcvs2.
186  */
187  pconvex_structure convex_product_structure(pconvex_structure,
188  pconvex_structure);
189  /** Give a pointer on the structures of a prism of dimension d.
190  * i.e. the direct product of a simplex of dimension d-1 and a segment.
191  */
192  inline pconvex_structure prism_P1_structure(dim_type nc) {
193  return convex_product_structure(simplex_structure(dim_type(nc-1)),
194  simplex_structure(1));
195  }
196  /// Give a pointer on the 3D quadratic incomplete prism structure.
197  pconvex_structure prism_incomplete_P2_structure();
198  /// Give a pointer on the 3D pyramid structure for a degree k = 1 or 2.
199  pconvex_structure pyramid_QK_structure(short_type k);
200  /// Give a pointer on the 3D quadratic incomplete pyramid structure.
201  pconvex_structure pyramid_Q2_incomplete_structure();
202 
203  IS_DEPRECATED inline pconvex_structure
204  prism_structure(dim_type nc) { return prism_P1_structure(nc); }
205  IS_DEPRECATED inline pconvex_structure
206  pyramid_structure(short_type k) { return pyramid_QK_structure(k); }
207 
208 
209  /** Simplex structure with the Lagrange grid of degree k.
210  @param n the simplex dimension.
211  @param k the simplex degree.
212  */
213  pconvex_structure simplex_structure(dim_type n, short_type k);
214 
215  /// Generic convex with n global nodes
216  pconvex_structure generic_dummy_structure(dim_type nc, size_type n,
217  short_type nf);
218 
219  //@}
220 
221  /*@}*/
222 } /* end of namespace bgeot. */
223 
224 
225 #endif /* BGEOT_CONVEX_STRUCTURE_H__ */
friend pconvex_structure basic_structure(pconvex_structure cv)
Original structure (if concerned)
indexed array reference (given a container X, and a set of indexes I, this class provides a pseudo-co...
Definition: gmm_ref.h:289
base class for static stored objects
Stores interdependent getfem objects.
std::ostream & operator<<(std::ostream &o, const convex_structure &cv)
Print the details of the convex structure cvs to the output stream o.
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.
pconvex_structure prism_P1_structure(dim_type nc)
Give a pointer on the structures of a prism of dimension d.
Multivariate polynomials.
std::shared_ptr< const convex_structure > pconvex_structure
Pointer on a convex structure description.
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
pconvex_structure pyramid_QK_structure(dim_type k)
Give a pointer on the 3D pyramid structure for a degree k = 1 or 2.
Provide some simple pseudo-containers.
pconvex_structure prism_incomplete_P2_structure()
Give a pointer on the 3D quadratic incomplete prism 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 ...
short_type nb_points() const
Number of vertices.
Structure of a convex.
gmm::uint16_type short_type
used as the common short type integer in the library
Definition: bgeot_config.h:79
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.
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...
const convex_structure_faces_ct & faces_structure() const
Give a pointer array on the structures of the faces.
tensor class, used in mat_elem computations.
pconvex_structure simplex_structure(dim_type nc)
Give a pointer on the structures of a simplex of dimension d.
dim_type dim() const
Dimension of the convex.
short_type nb_faces() const
Number of faces.
const convex_ind_ct & ind_points_of_face(short_type i) const
Give an array of the indexes of the vertices of a face.
Basic Geometric Tools.
const convex_ind_ct & ind_dir_points() const
Return "direct" points indexes.
defines and typedefs for namespace bgeot
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.
pconvex_structure polygon_structure(short_type nbt)
Give a pointer on the structures of a polygon with n vertex.
short_type nb_points_of_face(short_type i) const
Number of vertices of a face.
pconvex_structure pyramid_Q2_incomplete_structure()
Give a pointer on the 3D quadratic incomplete pyramid structure.