GetFEM++  5.3
getfem_mesh_level_set.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2005-2017 Julien Pommier
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 /**@file getfem_mesh_level_set.h
33  @author Julien Pommier <Julien.Pommier@insa-toulouse.fr>
34  @author Yves Renard <Yves.Renard@insa-toulouse.fr>
35  @date March 04, 2005.
36  @brief Keep informations about a mesh crossed by level-sets.
37 */
38 #ifndef GETFEM_MESH_LEVEL_SET_H__
39 #define GETFEM_MESH_LEVEL_SET_H__
40 
41 #include "getfem_integration.h"
42 #include "getfem_level_set.h"
43 #include "getfem_fem.h"
44 
45 
46 namespace getfem {
47  /** @brief Keep informations about a mesh crossed by level-sets.
48  Cut convexes with respect to the level sets.
49 
50  Note that the cutting won't be conformal.
51  */
53  virtual public dal::static_stored_object {
54  public:
55  typedef std::string subzone;
56  typedef std::set<const subzone *> zone;
57  typedef std::set<const zone*> zoneset;
58 
59  protected :
60 
61  mutable std::set<subzone> allsubzones;
62  mutable std::set<zone> allzones;
63 
65  mesh *linked_mesh_;
66  mutable bool is_adapted_;
67 
68  typedef level_set *plevel_set;
69  std::vector<plevel_set> level_sets; // set of level set
70 
71  typedef std::shared_ptr<mesh> pmesh;
72 
73  struct convex_info {
74  pmesh pmsh;
75  zoneset zones;
76  mesh_region ls_border_faces;
77  convex_info() : pmsh(0) {}
78  };
79 
80  std::map<size_type, convex_info> cut_cv;
81 
82  mutable dal::bit_vector crack_tip_convexes_;
83 
84  public :
85  /// Get number of level-sets referenced in this object.
86  size_type nb_level_sets(void) const { return level_sets.size(); }
87  plevel_set get_level_set(size_type i) const { return level_sets[i]; }
88  void update_from_context(void) const { is_adapted_= false; }
89  bool is_convex_cut(size_type i) const
90  { return (cut_cv.find(i) != cut_cv.end()); }
91  const mesh& mesh_of_convex(size_type i) const {
92  if (is_convex_cut(i)) return *((cut_cv.find(i))->second.pmsh);
93  GMM_ASSERT1(false, "This element is not cut !");
94  }
95 
96  const dal::bit_vector &crack_tip_convexes() const;
97 
98  /// Gives a reference to the linked mesh of type mesh.
99  mesh &linked_mesh(void) const { return *linked_mesh_; }
100  void clear(void);
101 
102  size_type memsize() const {
103  size_type res = sizeof(mesh_level_set)
104  + level_sets.size() * sizeof(plevel_set);
105  for (std::map<size_type, convex_info>::const_iterator it=cut_cv.begin();
106  it != cut_cv.end(); ++it) {
107  res += sizeof(convex_info)
108  + it->second.pmsh->memsize()
109  + it->second.zones.size()
110  * (level_sets.size() + sizeof(std::string *) + sizeof(std::string));
111  }
112  return res;
113  }
114  /** add a new level set. Only a reference is kept, no copy done. */
116  if (std::find(level_sets.begin(), level_sets.end(), &ls)
117  == level_sets.end()) {
118  level_sets.push_back(&ls); touch();
119  is_adapted_ = false;
120  }
121  }
122  void sup_level_set(level_set &ls) {
123  std::vector<plevel_set>::iterator
124  it = std::find(level_sets.begin(), level_sets.end(), &ls);
125  if (it != level_sets.end()) {
126  level_sets.erase(it);
127  is_adapted_ = false;
128  touch();
129  }
130  }
131 
132  /** fill m with the (non-conformal) "cut" mesh. */
133  void global_cut_mesh(mesh &m) const;
134  /** do all the work (cut the convexes wrt the levelsets) */
135  void adapt(void);
136  void merge_zoneset(zoneset &zones1, const zoneset &zones2) const;
137  void merge_zoneset(zoneset &zones1, const std::string &subz) const;
138  const std::string &primary_zone_of_convex(size_type cv) const
139  { return *(zones_of_convexes[cv]); }
140  const zoneset &zoneset_of_convex(size_type cv) const {
141  std::map<size_type, convex_info>::const_iterator it = cut_cv.find(cv);
142  if (it != cut_cv.end()) return (*it).second.zones;
143  GMM_ASSERT1(false, "You cannot call this function for uncut convexes");
144  }
145  // detect the intersection of two or more level sets and the convexes
146  // where the intersection occurs. To be called after adapt.
147  void find_level_set_potential_intersections
148  (std::vector<size_type> &icv, std::vector<dal::bit_vector> &ils);
149 
150  void init_with_mesh(mesh &me);
151  mesh_level_set(mesh &me);
152  mesh_level_set(void);
153  virtual ~mesh_level_set();
155  GMM_ASSERT1(linked_mesh_ == 0 && mls.linked_mesh_ == 0,
156  "Copy constructor is not allowed for mesh_level_set");
157  }
158  mesh_level_set & operator=(const mesh_level_set &mls) {
159  GMM_ASSERT1(linked_mesh_ == 0 && mls.linked_mesh_ == 0,
160  "Copy operator is not allowed for mesh_level_set");
161  return *this;
162  }
163 
164 
165  private:
166  void cut_element(size_type cv, const dal::bit_vector &primary,
167  const dal::bit_vector &secondary, scalar_type radius);
168  int is_not_crossed_by(size_type c, plevel_set ls, unsigned lsnum,
169  scalar_type radius);
170  int sub_simplex_is_not_crossed_by(size_type cv, plevel_set ls,
171  size_type sub_cv, scalar_type radius);
172  void find_zones_of_element(size_type cv, std::string &prezone,
173  scalar_type radius);
174 
175  /** For each levelset, if the convex cv is crossed, add the levelset number
176  into 'prim' (and 'sec' is the levelset has a secondary part).
177  zone is also filled with '0', '+', and '-'.
178  */
179  void find_crossing_level_set(size_type cv,
180  dal::bit_vector &prim,
181  dal::bit_vector &sec, std::string &zone,
182  scalar_type radius);
183  void run_delaunay(std::vector<base_node> &fixed_points,
184  gmm::dense_matrix<size_type> &simplexes,
185  std::vector<dal::bit_vector> &fixed_points_constraints);
186 
187  void update_crack_tip_convexes();
188  };
189 
190  void getfem_mesh_level_set_noisy(void);
191 
192  std::ostream &operator<<(std::ostream &os, const mesh_level_set::zone &z);
193  std::ostream &operator<<(std::ostream &os, const mesh_level_set::zoneset &zs);
194 
195 } /* end of namespace getfem. */
196 
197 
198 #endif /* GETFEM_MESH_LEVEL_SET_H__ */
structure used to hold a set of convexes and/or convex faces.
void add_level_set(level_set &ls)
add a new level set.
base class for static stored objects
Describe a mesh (collection of convexes (elements) and points).
Definition: getfem_mesh.h:95
void adapt(void)
do all the work (cut the convexes wrt the levelsets)
Integration methods (exact and approximated) on convexes.
Define a level-set.
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
void global_cut_mesh(mesh &m) const
fill m with the (non-conformal) "cut" mesh.
Deal with interdependencies of objects.
GEneric Tool for Finite Element Methods.
size_type nb_level_sets(void) const
Get number of level-sets referenced in this object.
void update_from_context(void) const
this function has to be defined and should update the object when the context is modified.
Definition of the finite element methods.
Define level-sets.
mesh & linked_mesh(void) const
Gives a reference to the linked mesh of type mesh.
Keep informations about a mesh crossed by level-sets.