GetFEM  5.4.2
getfem_mesh_fem_level_set.cc
1 /*===========================================================================
2 
3  Copyright (C) 2004-2020 Yves Renard
4 
5  This file is a part of GetFEM
6 
7  GetFEM is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Lesser General Public License as published
9  by the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version along with the GCC Runtime Library
11  Exception either version 3.1 or (at your option) any later version.
12  This program is distributed in the hope that it will be useful, but
13  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15  License and GCC Runtime Library Exception for more details.
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program; if not, write to the Free Software Foundation,
18  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20 ===========================================================================*/
21 
23 
24 namespace getfem {
25 
26  void mesh_fem_level_set::clear_build_methods() {
27  for (size_type i = 0; i < build_methods.size(); ++i)
28  del_stored_object(build_methods[i]);
29  build_methods.clear();
30  }
31  void mesh_fem_level_set::clear(void) {
32  mesh_fem::clear();
33  clear_build_methods();
34  is_adapted = false;
35  }
36 
37  mesh_fem_level_set::mesh_fem_level_set(const mesh_level_set &me,
38  const mesh_fem &mef)
39  : mesh_fem(mef.linked_mesh()), mls(me), mf(mef) {
40  xfem_index = reserve_xfem_index();
41  GMM_ASSERT1(mf.get_qdim() == 1, "base mesh_fem for mesh_fem_level_set has "
42  "to be of qdim one for the moment ...");
43  this->add_dependency(mls);
44  is_adapted = false;
45  }
46 
47 
48  DAL_SIMPLE_KEY(special_mfls_key, pfem);
49 
50  void mesh_fem_level_set::build_method_of_convex(size_type cv) {
51  pfem pf = std::make_shared<fem_level_set>
52  (gmm::index_ref_iterator(dof_enrichments.begin(),
53  mf.ind_basic_dof_of_element(cv).begin()) ,
54  mf.fem_of_element(cv), mls, xfem_index);
55  dal::pstatic_stored_object_key
56  pk = std::make_shared<special_mfls_key>(pf);
57  dal::add_stored_object(pk, pf, pf->ref_convex(0), pf->node_tab(0));
58  build_methods.push_back(pf);
59  set_finite_element(cv, pf);
60  }
61 
62  void mesh_fem_level_set::adapt(void) {
63  context_check();
64  clear();
65  GMM_ASSERT1(!mf.is_reduced(), "Mesh fem level set not defined for reduced "
66  "mesh fems (difficult or impossible to define it in the "
67  "general case)");
68  enriched_dofs.clear(); enriched_elements.clear();
69  dof_enrichments.resize(0);
70  dof_enrichments.resize(mf.nb_basic_dof(), 0);
71 
72  for (size_type i = 0; i < mf.nb_basic_dof(); ++i) {
73  const mesh::ind_cv_ct &ct = mf.convex_to_basic_dof(i);
74  bool touch_cut = false;
75  for (mesh::ind_cv_ct::const_iterator it = ct.begin();
76  it != ct.end(); ++it)
77  if (mls.is_convex_cut(*it)) { touch_cut = true; break; }
78 
79 
80  if (touch_cut) {
81  mesh_level_set::zoneset zones;
82 
83  for (mesh::ind_cv_ct::const_iterator it = ct.begin();
84  it != ct.end(); ++it) {
85  if (mls.is_convex_cut(*it)) {
86  mls.merge_zoneset(zones, mls.zoneset_of_convex(*it));
87  }
88  else {
89  mls.merge_zoneset(zones, mls.primary_zone_of_convex(*it));
90  }
91  }
92 
93  if (zones.size() != 1) {
94  dof_enrichments[i] = &(*(enrichments.insert(zones).first));
95  enriched_dofs.add(i);
96  for (mesh::ind_cv_ct::const_iterator it = ct.begin();
97  it != ct.end(); ++it) enriched_elements.add(*it);
98  }
99  }
100  }
101 
102  // cout << "Enriched convexes : " << enriched_elements << endl;
103  // cout << "Enriched dofs : " << enriched_dofs << endl;
104 
105  for (dal::bv_visitor i(mf.convex_index()); !i.finished(); ++i) {
106  if (enriched_elements[i]) build_method_of_convex(i); else
107  set_finite_element(i, mf.fem_of_element(i));
108  }
109  is_adapted = true; touch();
110  }
111 
112 
113 } /* end of namespace getfem. */
114 
bgeot::size_type
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
gmm::clear
void clear(L &l)
clear (fill with zeros) a vector or matrix.
Definition: gmm_blas.h:59
getfem_mesh_fem_level_set.h
a subclass of mesh_fem which is conformal to a number of level sets.
dal::del_stored_object
void del_stored_object(const pstatic_stored_object &o, bool ignore_unstored)
Delete an object and the object which depend on it.
Definition: dal_static_stored_objects.cc:369
getfem
GEneric Tool for Finite Element Methods.
Definition: getfem_accumulated_distro.h:46
getfem::pfem
std::shared_ptr< const getfem::virtual_fem > pfem
type of pointer on a fem description
Definition: getfem_fem.h:244
dal::add_stored_object
void add_stored_object(pstatic_stored_object_key k, pstatic_stored_object o, permanence perm)
Add an object with two optional dependencies.
Definition: dal_static_stored_objects.cc:284
dal::add_dependency
void add_dependency(pstatic_stored_object o1, pstatic_stored_object o2)
Add a dependency, object o1 will depend on object o2.
Definition: dal_static_stored_objects.cc:230