GetFEM  5.5
getfem_mesh_im_level_set.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2005-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 /**@file getfem_mesh_im_level_set.h
32  @author Yves Renard <[email protected]>
33  @date February 02, 2005.
34  @brief a subclass of mesh_im which is conformal to a number of level sets.
35 */
36 
37 #ifndef GETFEM_MESH_IM_LEVEL_SET_H__
38 #define GETFEM_MESH_IM_LEVEL_SET_H__
39 
40 #include "getfem_mesh_im.h"
41 #include "getfem_mesh_level_set.h"
42 #include <set>
43 
44 namespace getfem {
45 
46  /**
47  Describe an adaptable integration method linked to a mesh cut by
48  a level set. It is possible to choose to integrate over the
49  whole mesh, or to select integration on the "inside" (the
50  intersection of the negative parts of the levelsets, or any other
51  union, intersection etc of the levelset negative parts), the
52  "outside", or just the levelset boundary.
53  */
54 
55  class mesh_im_level_set : public mesh_im {
56  protected :
57  pintegration_method regular_simplex_pim;
58  pintegration_method base_singular_pim;
59  mesh_level_set *mls;
60 
61  mesh_im cut_im; /* stores an im only for convexes who are crossed
62  by a levelset */
63 
64  dal::bit_vector ignored_im; /* convex list whose integration method is
65  ignored (for instance because
66  INTEGRATE_INSIDE and the convex
67  is outside etc.) */
68  std::vector<pintegration_method> build_methods;
69 
70  mutable bool is_adapted;
71  int integrate_where; // INTEGRATE_INSIDE or INTEGRATE_OUTSIDE
72 
73  void clear_build_methods();
74  void build_method_of_convex(size_type cv);
75 
76  /* CSG (constructive solid geometry) description for the
77  definition of the domain with respect to one or more levelsets.
78  */
79  std::string ls_csg_description;
80  public:
81  struct bool2 {
82  bool in; // true when the point in inside the levelsets
83  unsigned bin; /* 0 when the point is not on the boundary, and
84  (lsindex+1) when it is on the boundary of the
85  lsindex-th levelset */
86  };
87  protected:
88  /* return true when the point is inside the levelsets CSG
89  description */
90  bool2 is_point_in_selected_area
91  (const std::vector<pmesher_signed_distance> &mesherls0,
92  const std::vector<pmesher_signed_distance> &mesherls1, const base_node& P);
93  bool2 is_point_in_selected_area2
94  (const std::vector<pmesher_signed_distance> &mesherls0,
95  const std::vector<pmesher_signed_distance> &mesherls1, const base_node& P);
96 
97  public :
98  enum { INTEGRATE_INSIDE = 1, INTEGRATE_OUTSIDE = 2, INTEGRATE_ALL = 2+1,
99  INTEGRATE_BOUNDARY = 4};
100  void update_from_context(void) const;
101 
102  /** Apply the adequate integration methods. */
103  void adapt(void);
104  void clear(void); // to be modified
105 
106  /** Set the specific integration methods. see the constructor
107  documentation for more details. */
108  void set_simplex_im(pintegration_method reg,
109  pintegration_method sing = 0) {
110  regular_simplex_pim = reg;
111  base_singular_pim = sing;
112  }
113 
114  int location() const { return integrate_where; }
115 
116  size_type memsize() const {
117  return mesh_im::memsize(); // + ... ;
118  }
119 
120  void init_with_mls(mesh_level_set &me,
121  int integrate_where_ = INTEGRATE_ALL,
122  pintegration_method reg = 0,
123  pintegration_method sing = 0);
124 
125  /**
126  @param me the level-set.
127 
128  @param integrate_where : choose between INTEGRATE_ALL,
129  INTEGRATE_BOUNDARY, INTEGRATE_INSIDE and INTEGRATE_OUTSIDE.
130 
131  @param reg the integration method (for simplices) that will be
132  used on the sub-simplices of convexes crossed by the levelset.
133 
134  @param sing the (optional) integration method to use on the crack tips
135  (i.e. when the levelset has a secondary level set), this is
136  generally an IM_QUASI_POLAR method as it provides a good
137  integration of singular XFEM functions.
138  */
139  mesh_im_level_set(mesh_level_set &me,
140  int integrate_where_ = INTEGRATE_ALL,
141  pintegration_method reg = 0,
142  pintegration_method sing = 0);
143  mesh_im_level_set(void);
144 
145  virtual pintegration_method int_method_of_element(size_type cv)
146  const;
147  ~mesh_im_level_set() { clear_build_methods(); }
148 
149 
150  /**
151  Set the boolean operation which define the integration domain
152  when there is more than one levelset.
153 
154  the syntax is very simple, for example if there are 3 different
155  levelset,
156 
157  "a*b*c" is the intersection of the domains defined by each
158  levelset (this is the default behaviour if this function is not
159  called).
160 
161  "a+b+c" is the union of their domains.
162 
163  "c-(a+b)" is the domain of the third levelset minus the union of
164  the domains of the two others.
165 
166  "!a" is the complementary of the domain of a (i.e. it is the
167  domain where a(x)>0)
168 
169  The first levelset is always referred to with "a", the second
170  with "b", and so on..
171  */
172  void set_level_set_boolean_operations(const std::string description) {
173  ls_csg_description = description;
174  }
175  void compute_normal_vector(const fem_interpolation_context &ctx,
176  base_small_vector &vec) const;
177  };
178 
179 
180 
181  /**
182  Describe an adaptable integration method linked to a mesh cut by at
183  least two level sets on the intersection of two level sets.
184  */
186  protected :
187  pintegration_method segment_pim;
188  mesh_level_set *mls;
189 
190  mesh_im cut_im; /* stores an im only for convexes who are crossed
191  by a levelset */
192 
193  dal::bit_vector ignored_im; /* convex list whose integration method is
194  ignored (for instance because
195  INTEGRATE_INSIDE and the convex
196  is outside etc.) */
197  std::vector<pintegration_method> build_methods;
198 
199  mutable bool is_adapted;
200  size_type ind_ls1, ind_ls2;
201 
202  void clear_build_methods();
203  void build_method_of_convex(size_type cv, mesh &global_intersection,
204  bgeot::rtree &rtree_seg);
205 
206  public:
207 
208  enum { INTEGRATE_INSIDE = 1, INTEGRATE_OUTSIDE = 2, INTEGRATE_ALL = 2+1,
209  INTEGRATE_BOUNDARY = 4};
210  void update_from_context(void) const;
211 
212  /** Apply the adequate integration methods. */
213  void adapt(void);
214  void clear(void); // to be modified
215 
216  /** Set the specific integration methods. see the constructor
217  documentation for more details. */
218  void set_segment_im(pintegration_method pim)
219  { segment_pim = pim; }
220 
221  size_type memsize() const {
222  return mesh_im::memsize(); // + ... ;
223  }
224 
225  void init_with_mls(mesh_level_set &me,
226  size_type ind_ls1_, size_type ind_ls2_,
227  pintegration_method pim = 0);
228 
229  mesh_im_cross_level_set(mesh_level_set &me,
230  size_type ind_ls1_, size_type ind_ls2_,
231  pintegration_method pim = 0);
232  mesh_im_cross_level_set(void);
233 
234  virtual pintegration_method int_method_of_element(size_type cv)
235  const;
236  ~mesh_im_cross_level_set() { clear_build_methods(); }
237 
238  };
239 
240 
241 
242 
243 
244 
245 
246 } /* end of namespace getfem. */
247 
248 
249 #endif /* GETFEM_MESH_IM_LEVEL_SET_H__ */
Balanced tree of n-dimensional rectangles.
Definition: bgeot_rtree.h:97
structure passed as the argument of fem interpolation functions.
Definition: getfem_fem.h:749
Describe an adaptable integration method linked to a mesh cut by at least two level sets on the inter...
virtual pintegration_method int_method_of_element(size_type cv) const
return the integration method associated with an element (in no integration is associated,...
void update_from_context(void) const
this function has to be defined and should update the object when the context is modified.
void set_segment_im(pintegration_method pim)
Set the specific integration methods.
void adapt(void)
Apply the adequate integration methods.
Describe an adaptable integration method linked to a mesh cut by a level set.
void set_level_set_boolean_operations(const std::string description)
Set the boolean operation which define the integration domain when there is more than one levelset.
void adapt(void)
Apply the adequate integration methods.
void set_simplex_im(pintegration_method reg, pintegration_method sing=0)
Set the specific integration methods.
virtual pintegration_method int_method_of_element(size_type cv) const
return the integration method associated with an element (in no integration is associated,...
void update_from_context(void) const
this function has to be defined and should update the object when the context is modified.
mesh_im_level_set(mesh_level_set &me, int integrate_where_=INTEGRATE_ALL, pintegration_method reg=0, pintegration_method sing=0)
Describe an integration method linked to a mesh.
Keep informations about a mesh crossed by level-sets.
Describe a mesh (collection of convexes (elements) and points).
Definition: getfem_mesh.h:98
Define the getfem::mesh_im class (integration of getfem::mesh_fem).
Keep informations about a mesh crossed by level-sets.
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:48
GEneric Tool for Finite Element Methods.