GetFEM  5.4.2
getfem_level_set.cc
1 /*===========================================================================
2 
3  Copyright (C) 1999-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 
22 
24 
25 namespace getfem {
26 
27  level_set::level_set(const mesh &msh, dim_type deg,
28  bool with_secondary_)
29  : degree_(deg), mf(&classical_mesh_fem(msh, deg)),
30  with_secondary(with_secondary_) {
31  shift_ls = scalar_type(0);
32  primary_.resize(mf->nb_dof());
33  if (has_secondary()) secondary_.resize(mf->nb_dof());
34  this->add_dependency(*mf);
35  }
36 
37  void level_set::copy_from(const level_set &ls) {
38  degree_ = ls.degree_;
39  mf = ls.mf;
40  primary_ = ls.primary_;
41  secondary_ = ls.secondary_;
42  with_secondary = ls.with_secondary;
43  shift_ls = ls.shift_ls;
44  this->add_dependency(*mf);
45  }
46 
47 
48  level_set::level_set(const level_set &ls) : context_dependencies() {
49  copy_from(ls);
50  }
51 
52  level_set &level_set::operator =(const level_set &ls) {
53  this->sup_dependency(*mf);
54  copy_from(ls);
55  return *this;
56  }
57 
58  level_set::~level_set() { }
59 
60  void level_set::reinit(void) {
61  primary_.resize(mf->nb_dof());
62  if (has_secondary()) secondary_.resize(mf->nb_dof());
63  touch();
64  }
65 
66  pmesher_signed_distance level_set::mls_of_convex(size_type cv, unsigned lsnum,
67  bool inverted) const {
68  assert(this); assert(mf);
69  GMM_ASSERT1(mf->linked_mesh().convex_index().is_in(cv), "convex " << cv
70  << " is not in the level set mesh!");
71  GMM_ASSERT1(mf->fem_of_element(cv), "Internal error");
72  GMM_ASSERT1(!mf->is_reduced(), "Internal error");
73  std::vector<scalar_type> coeff(mf->nb_basic_dof_of_element(cv));
74  GMM_ASSERT1(values(lsnum).size() == mf->nb_dof(),
75  "Inconsistent state in the levelset: nb_dof=" <<
76  mf->nb_dof() << ", values(" << lsnum << ").size=" <<
77  values(lsnum).size());
78  for (size_type i = 0; i < coeff.size(); ++i)
79  coeff[i] = (!inverted ? scalar_type(1) : scalar_type(-1)) *
80  values(lsnum)[mf->ind_basic_dof_of_element(cv)[i]];
81  return new_mesher_level_set(mf->fem_of_element(cv), coeff, shift_ls);
82  }
83 
84  size_type level_set::memsize() const {
85  return sizeof(*this) +
86  primary_.capacity() * sizeof(scalar_type) +
87  secondary_.capacity() * sizeof(scalar_type);
88  }
89 
90  void level_set::simplify(scalar_type eps) {
91  for (dal::bv_visitor cv(mf->linked_mesh().convex_index());
92  !cv.finished(); ++cv) {
93  scalar_type h = mf->linked_mesh().convex_radius_estimate(cv);
94  for (size_type i = 0; i < mf->nb_basic_dof_of_element(cv); ++i) {
95  size_type dof = mf->ind_basic_dof_of_element(cv)[i];
96  if (gmm::abs(primary_[dof]) < h*eps) {
97  primary_[dof] = scalar_type(0);
98  // cout << "Simplify dof " << dof << " : " << mf->point_of_dof(dof) << endl;
99  }
100  if (has_secondary() && gmm::abs(secondary_[dof]) < h*eps)
101  secondary_[dof] = scalar_type(0);
102  }
103 
104  }
105  touch();
106  }
107 
108 
109  struct dummy_level_set_ {
110  level_set ls;
111  dummy_level_set_() : ls(dummy_mesh()) {}
112  };
113 
114  const level_set &dummy_level_set()
116 
117 
118 
119 } /* end of namespace getfem. */
120 
dal::singleton::instance
static T & instance()
Instance from the current thread.
Definition: dal_singleton.h:165
bgeot::size_type
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
getfem
GEneric Tool for Finite Element Methods.
Definition: getfem_accumulated_distro.h:46
getfem_level_set.h
Define level-sets.
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
getfem::classical_mesh_fem
const mesh_fem & classical_mesh_fem(const mesh &mesh, dim_type degree, dim_type qdim=1, bool complete=false)
Gives the descriptor of a classical finite element method of degree K on mesh.
Definition: getfem_mesh_fem.cc:862