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