GetFEM++  5.3
getfem_interpolated_fem.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2004-2017 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 /**@file getfem_interpolated_fem.h
32  @author Yves Renard <Yves.Renard@insa-lyon.fr>
33  @date October 29, 2004.
34  @brief FEM which interpolates a mesh_fem on a different mesh.
35 
36  To be corrected : dependencies. The mesh fem using this fem will
37  not depend on the mesh fem arguments.
38 */
39 
40 
41 #ifndef GETFEM_INTERPOLATED_FEM_H__
42 #define GETFEM_INTERPOLATED_FEM_H__
43 
44 #include "getfem_fem.h"
45 #include "getfem_mesh_fem.h"
46 #include "getfem_mesh_im.h"
47 #include "bgeot_rtree.h"
48 #include "bgeot_geotrans_inv.h"
49 
50 namespace getfem {
51 
52  // Object representing global transformation. To be derived.
53 
54  struct virtual_interpolated_func {
55  virtual void val(const base_node&, base_node &) const
56  { GMM_ASSERT1(false, "this interpolated_func has no value"); }
57  virtual void grad(const base_node&, base_matrix &) const
58  { GMM_ASSERT1(false, "this interpolated_func has no gradient"); }
59  virtual void hess(const base_node&, base_matrix &) const
60  { GMM_ASSERT1(false, "this interpolated_func has no hessian"); }
61  virtual ~virtual_interpolated_func() {}
62  };
63 
64 
65  typedef const virtual_interpolated_func *pinterpolated_func;
66 
67 
68  struct gausspt_interpolation_data {
69  size_type elt; // convex of the interpolated mesh_fem under the gauss point
70  size_type iflags; // flags & 1 : there is an element or not
71  // flags & 2 : base_val is stored
72  // flags & 4 : grad_val is stored
73  base_node ptref; // coords on reference element of mf1 element
74  base_tensor base_val; // optional storage of the base values
75  base_tensor grad_val; // optional storage of the grad base values
76  std::vector<size_type> local_dof; // correspondance between dof of the
77  // mf1 element and dof of the interpolated element.
78  gausspt_interpolation_data() : elt(size_type(-1)), iflags(size_type(-1)) {}
79  };
80 
81  /** FEM which interpolates a mesh_fem on a different mesh.
82 
83  Note that the memory cost of this method is extremely high!
84  */
86 
87  protected :
88 
89  struct elt_interpolation_data {
90  size_type nb_dof;
91  std::vector<gausspt_interpolation_data> gausspt;
92  std::vector<size_type> inddof;
93  pintegration_method pim; // for DEBUG
94  elt_interpolation_data() : nb_dof(0), pim(0) {}
95  };
96 
97  const mesh_fem &mf; // mf represents the original finite element method
98  // to be interpolated.
99  const mesh_im &mim; // mesh on which mf1 is interpolated. contains
100  // also the integration method.
101  pinterpolated_func pif; // optional transformation
102 
103  bool store_values;
104  dal::bit_vector blocked_dof;
105 
106  // auxiliary variables
107  mutable std::vector<elt_interpolation_data> elements;
108  mutable bgeot::rtree boxtree; // Tree containing the bounding box
109  // of mf1 elements
110  mutable std::vector<size_type> ind_dof; /* all functions using this work
111  array should keep it full of
112  size_type(-1) */
113  mutable size_type cv_stored;
114  mutable bgeot::rtree::pbox_set boxlst;
115  mutable bgeot::geotrans_inv_convex gic;
116  mutable base_tensor taux;
117  mutable fem_interpolation_context fictx;
118  mutable size_type fictx_cv;
119  mutable base_matrix G;
120  mutable bgeot::pstored_point_tab pspt_override;
121  mutable bgeot::multi_index mi2, mi3;
122  mutable base_node ptref;
123  mutable gmm::dense_matrix<scalar_type> trans;
124 
125  void build_rtree(void) const;
126 
127  bool find_a_point(base_node pt, base_node &ptr,
128  size_type &cv) const;
129 
130  virtual void update_from_context(void) const;
131  inline void actualize_fictx(pfem pf, size_type cv,
132  const base_node &ptr) const;
133 
134  public :
135 
136  virtual size_type nb_dof(size_type cv) const;
137  virtual size_type index_of_global_dof(size_type cv, size_type i) const;
138  virtual bgeot::pconvex_ref ref_convex(size_type cv) const;
139  virtual const bgeot::convex<base_node> &node_convex(size_type cv) const;
140  virtual bgeot::pstored_point_tab node_tab(size_type) const
141  { return pspt_override; }
142  void base_value(const base_node &, base_tensor &) const;
143  void grad_base_value(const base_node &, base_tensor &) const;
144  void hess_base_value(const base_node &, base_tensor &) const;
145  void real_base_value(const fem_interpolation_context& c,
146  base_tensor &t, bool = true) const;
147  void real_grad_base_value(const fem_interpolation_context& c,
148  base_tensor &t, bool = true) const;
149  void real_hess_base_value(const fem_interpolation_context&,
150  base_tensor &, bool = true) const;
151 
152  /** return the list of convexes of the interpolated mesh_fem which
153  * contain at least one gauss point (should be all convexes)! */
154  dal::bit_vector interpolated_convexes() const;
155 
156  /** return the min/max/mean number of gauss points in the convexes
157  * of the interpolated mesh_fem */
158  void gauss_pts_stats(unsigned &ming, unsigned &maxg,
159  scalar_type &meang) const;
160  size_type memsize() const;
161  interpolated_fem(const mesh_fem &mef, const mesh_im &meim,
162  pinterpolated_func pif_ = 0,
163  dal::bit_vector blocked_dof = dal::bit_vector(),
164  bool store_val = true);
165  virtual ~interpolated_fem()
166  { DAL_STORED_OBJECT_DEBUG_DESTROYED(this, "Interpolated fem"); }
167  };
168 
169 
170  /** create a new interpolated FEM.
171  @param mef the mesh_fem that will be interpolated.
172  @param mim the integration method on the final mesh (not the mesh
173  of mef!).
174  @param pif an optional geometric transformation applied to
175  mef.linked_mesh() (used for getfem::spider_fem)
176  @param blocked_dof list of dof of mef which won't be interpolated.
177  @param store_val if true, the values/gradients of interpolated base
178  function are cached at each gauss point (eats much memory).
179  */
180  pfem new_interpolated_fem(const mesh_fem &mef, const mesh_im &mim,
181  pinterpolated_func pif = 0,
182  dal::bit_vector blocked_dof = dal::bit_vector(),
183  bool store_val = true);
184 
185  /** release an interpolated fem */
186  inline void del_interpolated_fem(const pfem &pf)
187  { dal::del_stored_object(pf); }
188 
189 
190 } /* end of namespace getfem. */
191 
192 #endif
193 
Base class for finite element description.
Definition: getfem_fem.h:250
Define the getfem::mesh_im class (integration of getfem::mesh_fem).
Define the getfem::mesh_fem class.
does the inversion of the geometric transformation for a given convex
void del_stored_object(const pstatic_stored_object &o, bool ignore_unstored)
Delete an object and the object which depend on it.
Describe an integration method linked to a mesh.
void del_interpolated_fem(const pfem &pf)
release an interpolated fem
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
Inversion of geometric transformations.
structure passed as the argument of fem interpolation functions.
Definition: getfem_fem.h:741
Deal with interdependencies of objects.
GEneric Tool for Finite Element Methods.
std::shared_ptr< const getfem::virtual_fem > pfem
type of pointer on a fem description
Definition: getfem_fem.h:239
Describe a finite element method linked to a mesh.
pfem new_interpolated_fem(const mesh_fem &mef, const mesh_im &mim, pinterpolated_func pif=0, dal::bit_vector blocked_dof=dal::bit_vector(), bool store_val=true)
create a new interpolated FEM.
Definition of the finite element methods.
FEM which interpolates a mesh_fem on a different mesh.
Balanced tree of n-dimensional rectangles.
Definition: bgeot_rtree.h:66
region-tree for window/point search on a set of rectangles.