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